TimePicker.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default,
  21. timePickerProps: () => timePickerProps
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_vue2 = require("vue");
  26. var import_utils = require("../utils");
  27. var import_utils2 = require("../date-picker/utils");
  28. var import_picker = require("../picker");
  29. const [name] = (0, import_utils.createNamespace)("time-picker");
  30. const timePickerProps = (0, import_utils.extend)({}, import_utils2.sharedProps, {
  31. minHour: (0, import_utils.makeNumericProp)(0),
  32. maxHour: (0, import_utils.makeNumericProp)(23),
  33. minMinute: (0, import_utils.makeNumericProp)(0),
  34. maxMinute: (0, import_utils.makeNumericProp)(59),
  35. minSecond: (0, import_utils.makeNumericProp)(0),
  36. maxSecond: (0, import_utils.makeNumericProp)(59),
  37. columnsType: {
  38. type: Array,
  39. default: () => ["hour", "minute"]
  40. }
  41. });
  42. var stdin_default = (0, import_vue2.defineComponent)({
  43. name,
  44. props: timePickerProps,
  45. emits: ["confirm", "cancel", "change", "update:modelValue"],
  46. setup(props, {
  47. emit,
  48. slots
  49. }) {
  50. const currentValues = (0, import_vue2.ref)(props.modelValue);
  51. const columns = (0, import_vue2.computed)(() => props.columnsType.map((type) => {
  52. const {
  53. filter,
  54. formatter
  55. } = props;
  56. switch (type) {
  57. case "hour":
  58. return (0, import_utils2.genOptions)(+props.minHour, +props.maxHour, type, formatter, filter);
  59. case "minute":
  60. return (0, import_utils2.genOptions)(+props.minMinute, +props.maxMinute, type, formatter, filter);
  61. case "second":
  62. return (0, import_utils2.genOptions)(+props.minSecond, +props.maxSecond, type, formatter, filter);
  63. default:
  64. if (process.env.NODE_ENV !== "production") {
  65. throw new Error(`[Vant] DatePicker: unsupported columns type: ${type}`);
  66. }
  67. return [];
  68. }
  69. }));
  70. (0, import_vue2.watch)(currentValues, (newValues) => {
  71. if (!(0, import_utils.isSameValue)(newValues, props.modelValue)) {
  72. emit("update:modelValue", newValues);
  73. }
  74. });
  75. (0, import_vue2.watch)(() => props.modelValue, (newValues) => {
  76. newValues = (0, import_utils2.formatValueRange)(newValues, columns.value);
  77. if (!(0, import_utils.isSameValue)(newValues, currentValues.value)) {
  78. currentValues.value = newValues;
  79. }
  80. }, {
  81. immediate: true
  82. });
  83. const onChange = (...args) => emit("change", ...args);
  84. const onCancel = (...args) => emit("cancel", ...args);
  85. const onConfirm = (...args) => emit("confirm", ...args);
  86. return () => (0, import_vue.createVNode)(import_picker.Picker, (0, import_vue.mergeProps)({
  87. "modelValue": currentValues.value,
  88. "onUpdate:modelValue": ($event) => currentValues.value = $event,
  89. "columns": columns.value,
  90. "onChange": onChange,
  91. "onCancel": onCancel,
  92. "onConfirm": onConfirm
  93. }, (0, import_utils.pick)(props, import_utils2.pickerInheritKeys)), slots);
  94. }
  95. });