Area.js 3.6 KB

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