Area.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue";
  2. import { ref, watch, computed, defineComponent } from "vue";
  3. import { pick, extend, makeArrayProp, makeNumericProp, createNamespace } from "../utils/index.mjs";
  4. import { pickerSharedProps } from "../picker/Picker.mjs";
  5. import { INHERIT_PROPS, INHERIT_SLOTS, formatDataForCascade } from "./utils.mjs";
  6. import { useExpose } from "../composables/use-expose.mjs";
  7. import { Picker } from "../picker/index.mjs";
  8. const [name, bem] = createNamespace("area");
  9. const areaProps = extend({}, pickerSharedProps, {
  10. modelValue: String,
  11. columnsNum: makeNumericProp(3),
  12. columnsPlaceholder: makeArrayProp(),
  13. areaList: {
  14. type: Object,
  15. default: () => ({})
  16. }
  17. });
  18. var stdin_default = defineComponent({
  19. name,
  20. props: areaProps,
  21. emits: ["change", "confirm", "cancel", "update:modelValue"],
  22. setup(props, {
  23. emit,
  24. slots
  25. }) {
  26. const codes = ref([]);
  27. const picker = ref();
  28. const columns = computed(() => formatDataForCascade(props));
  29. const onChange = (...args) => emit("change", ...args);
  30. const onCancel = (...args) => emit("cancel", ...args);
  31. const onConfirm = (...args) => emit("confirm", ...args);
  32. watch(codes, (newCodes) => {
  33. const lastCode = newCodes.length ? newCodes[newCodes.length - 1] : "";
  34. if (lastCode && lastCode !== props.modelValue) {
  35. emit("update:modelValue", lastCode);
  36. }
  37. }, {
  38. deep: true
  39. });
  40. watch(() => props.modelValue, (newCode) => {
  41. if (newCode) {
  42. const lastCode = codes.value.length ? codes.value[codes.value.length - 1] : "";
  43. if (newCode !== lastCode) {
  44. codes.value = [`${newCode.slice(0, 2)}0000`, `${newCode.slice(0, 4)}00`, newCode].slice(0, +props.columnsNum);
  45. }
  46. } else {
  47. codes.value = [];
  48. }
  49. }, {
  50. immediate: true
  51. });
  52. useExpose({
  53. confirm: () => {
  54. var _a;
  55. return (_a = picker.value) == null ? void 0 : _a.confirm();
  56. },
  57. getSelectedOptions: () => {
  58. var _a;
  59. return ((_a = picker.value) == null ? void 0 : _a.getSelectedOptions()) || [];
  60. }
  61. });
  62. return () => _createVNode(Picker, _mergeProps({
  63. "ref": picker,
  64. "modelValue": codes.value,
  65. "onUpdate:modelValue": ($event) => codes.value = $event,
  66. "class": bem(),
  67. "columns": columns.value,
  68. "onChange": onChange,
  69. "onCancel": onCancel,
  70. "onConfirm": onConfirm
  71. }, pick(props, INHERIT_PROPS)), pick(slots, INHERIT_SLOTS));
  72. }
  73. });
  74. export {
  75. areaProps,
  76. stdin_default as default
  77. };