Area.js 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. areaProps: () => areaProps,
  21. default: () => stdin_default
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_utils = require("../utils");
  26. var import_Picker = require("../picker/Picker");
  27. var import_utils2 = require("./utils");
  28. var import_use_expose = require("../composables/use-expose");
  29. var import_picker = require("../picker");
  30. const [name, bem] = (0, import_utils.createNamespace)("area");
  31. const areaProps = (0, import_utils.extend)({}, (0, import_utils.pick)(import_Picker.pickerSharedProps, import_utils2.INHERIT_PROPS), {
  32. modelValue: String,
  33. columnsNum: (0, import_utils.makeNumericProp)(3),
  34. columnsPlaceholder: (0, import_utils.makeArrayProp)(),
  35. areaList: {
  36. type: Object,
  37. default: () => ({})
  38. }
  39. });
  40. var stdin_default = (0, import_vue.defineComponent)({
  41. name,
  42. props: areaProps,
  43. emits: ["change", "confirm", "cancel", "update:modelValue"],
  44. setup(props, {
  45. emit,
  46. slots
  47. }) {
  48. const codes = (0, import_vue.ref)([]);
  49. const picker = (0, import_vue.ref)();
  50. const columns = (0, import_vue.computed)(() => (0, import_utils2.formatDataForCascade)(props));
  51. const onChange = (...args) => emit("change", ...args);
  52. const onCancel = (...args) => emit("cancel", ...args);
  53. const onConfirm = (...args) => emit("confirm", ...args);
  54. (0, import_vue.watch)(codes, (newCodes) => {
  55. const lastCode = newCodes.length ? newCodes[newCodes.length - 1] : "";
  56. if (lastCode && lastCode !== props.modelValue) {
  57. emit("update:modelValue", lastCode);
  58. }
  59. }, {
  60. deep: true
  61. });
  62. (0, import_vue.watch)(() => props.modelValue, (newCode) => {
  63. if (newCode) {
  64. const lastCode = codes.value.length ? codes.value[codes.value.length - 1] : "";
  65. if (newCode !== lastCode) {
  66. codes.value = [`${newCode.slice(0, 2)}0000`, `${newCode.slice(0, 4)}00`, newCode].slice(0, +props.columnsNum);
  67. }
  68. } else {
  69. codes.value = [];
  70. }
  71. }, {
  72. immediate: true
  73. });
  74. (0, import_use_expose.useExpose)({
  75. confirm: () => {
  76. var _a;
  77. return (_a = picker.value) == null ? void 0 : _a.confirm();
  78. },
  79. getSelectedOptions: () => {
  80. var _a;
  81. return ((_a = picker.value) == null ? void 0 : _a.getSelectedOptions()) || [];
  82. }
  83. });
  84. return () => (0, import_vue.createVNode)(import_picker.Picker, (0, import_vue.mergeProps)({
  85. "ref": picker,
  86. "modelValue": codes.value,
  87. "onUpdate:modelValue": ($event) => codes.value = $event,
  88. "class": bem(),
  89. "columns": columns.value,
  90. "onChange": onChange,
  91. "onCancel": onCancel,
  92. "onConfirm": onConfirm
  93. }, (0, import_utils.pick)(props, import_utils2.INHERIT_PROPS)), (0, import_utils.pick)(slots, import_utils2.INHERIT_SLOTS));
  94. }
  95. });