shared.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. exports.__esModule = true;
  4. exports.TimePickerMixin = exports.sharedProps = void 0;
  5. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  6. var _utils = require("./utils");
  7. var _string = require("../utils/format/string");
  8. var _shared = require("../picker/shared");
  9. var _picker = _interopRequireDefault(require("../picker"));
  10. var sharedProps = (0, _extends2.default)({}, _shared.pickerProps, {
  11. value: null,
  12. filter: Function,
  13. columnsOrder: Array,
  14. showToolbar: {
  15. type: Boolean,
  16. default: true
  17. },
  18. formatter: {
  19. type: Function,
  20. default: function _default(type, value) {
  21. return value;
  22. }
  23. }
  24. });
  25. exports.sharedProps = sharedProps;
  26. var TimePickerMixin = {
  27. data: function data() {
  28. return {
  29. innerValue: this.formatValue(this.value)
  30. };
  31. },
  32. computed: {
  33. originColumns: function originColumns() {
  34. var _this = this;
  35. return this.ranges.map(function (_ref) {
  36. var type = _ref.type,
  37. rangeArr = _ref.range;
  38. var values = (0, _utils.times)(rangeArr[1] - rangeArr[0] + 1, function (index) {
  39. var value = (0, _string.padZero)(rangeArr[0] + index);
  40. return value;
  41. });
  42. if (_this.filter) {
  43. values = _this.filter(type, values);
  44. }
  45. return {
  46. type: type,
  47. values: values
  48. };
  49. });
  50. },
  51. columns: function columns() {
  52. var _this2 = this;
  53. return this.originColumns.map(function (column) {
  54. return {
  55. values: column.values.map(function (value) {
  56. return _this2.formatter(column.type, value);
  57. })
  58. };
  59. });
  60. }
  61. },
  62. watch: {
  63. columns: 'updateColumnValue',
  64. innerValue: function innerValue(val, oldVal) {
  65. if (!oldVal) {
  66. this.$emit('input', null);
  67. } else {
  68. this.$emit('input', val);
  69. }
  70. }
  71. },
  72. mounted: function mounted() {
  73. var _this3 = this;
  74. this.updateColumnValue();
  75. this.$nextTick(function () {
  76. _this3.updateInnerValue();
  77. });
  78. },
  79. methods: {
  80. // @exposed-api
  81. getPicker: function getPicker() {
  82. return this.$refs.picker;
  83. },
  84. onConfirm: function onConfirm() {
  85. this.$emit('input', this.innerValue);
  86. this.$emit('confirm', this.innerValue);
  87. },
  88. onCancel: function onCancel() {
  89. this.$emit('cancel');
  90. }
  91. },
  92. render: function render() {
  93. var _this4 = this;
  94. var h = arguments[0];
  95. var props = {};
  96. Object.keys(_shared.pickerProps).forEach(function (key) {
  97. props[key] = _this4[key];
  98. });
  99. return h(_picker.default, {
  100. "ref": "picker",
  101. "attrs": {
  102. "columns": this.columns,
  103. "readonly": this.readonly
  104. },
  105. "scopedSlots": this.$scopedSlots,
  106. "on": {
  107. "change": this.onChange,
  108. "confirm": this.onConfirm,
  109. "cancel": this.onCancel
  110. },
  111. "props": (0, _extends2.default)({}, props)
  112. });
  113. }
  114. };
  115. exports.TimePickerMixin = TimePickerMixin;