shared.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. getPicker: function getPicker() {
  81. return this.$refs.picker;
  82. },
  83. // https://github.com/vant-ui/vant/issues/10013
  84. getProxiedPicker: function getProxiedPicker() {
  85. var _this4 = this;
  86. var picker = this.$refs.picker;
  87. if (picker) {
  88. var proxy = function proxy(fn) {
  89. return function () {
  90. picker[fn].apply(picker, arguments);
  91. _this4.updateInnerValue();
  92. };
  93. };
  94. return (0, _extends2.default)({}, picker, {
  95. setValues: proxy('setValues'),
  96. setIndexes: proxy('setIndexes'),
  97. setColumnIndex: proxy('setColumnIndex'),
  98. setColumnValue: proxy('setColumnValue')
  99. });
  100. }
  101. },
  102. onConfirm: function onConfirm() {
  103. this.$emit('input', this.innerValue);
  104. this.$emit('confirm', this.innerValue);
  105. },
  106. onCancel: function onCancel() {
  107. this.$emit('cancel');
  108. }
  109. },
  110. render: function render() {
  111. var _this5 = this;
  112. var h = arguments[0];
  113. var props = {};
  114. Object.keys(_shared.pickerProps).forEach(function (key) {
  115. props[key] = _this5[key];
  116. });
  117. return h(_picker.default, {
  118. "ref": "picker",
  119. "attrs": {
  120. "columns": this.columns,
  121. "readonly": this.readonly
  122. },
  123. "scopedSlots": this.$scopedSlots,
  124. "on": {
  125. "change": this.onChange,
  126. "confirm": this.onConfirm,
  127. "cancel": this.onCancel
  128. },
  129. "props": (0, _extends2.default)({}, props)
  130. });
  131. }
  132. };
  133. exports.TimePickerMixin = TimePickerMixin;