Area.mjs 2.5 KB

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