ninemoon-ui 0.0.26 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/dist/assets/dialog-a1b585e9.css +9 -0
  2. package/dist/assets/index-6d2c28a9.css +1210 -0
  3. package/dist/{tabs.css → assets/tabs-d2c8965f.css} +13 -13
  4. package/dist/components/alert/alert.d.ts +3 -11
  5. package/dist/components/alert/alertcomponent.vue.d.ts +22 -11
  6. package/dist/components/badge/badge.vue.d.ts +40 -31
  7. package/dist/components/carousel/carousel.vue.d.ts +47 -8
  8. package/dist/components/carousel/carouselitem.vue.d.ts +4 -2
  9. package/dist/components/carousel/clickbutton.vue.d.ts +29 -0
  10. package/dist/components/check/checkbox.vue.d.ts +39 -22
  11. package/dist/components/check/checkgroup.vue.d.ts +45 -21
  12. package/dist/components/date/datepicker.vue.d.ts +48 -18
  13. package/dist/components/date/datepickerRange.vue.d.ts +35 -12
  14. package/dist/components/dialog/dialog.vue.d.ts +56 -67
  15. package/dist/components/form/form.vue.d.ts +38 -44
  16. package/dist/components/form/formlabel.vue.d.ts +40 -35
  17. package/dist/components/form/type.d.ts +11 -0
  18. package/dist/components/icon/add.vue.d.ts +2 -0
  19. package/dist/components/icon/alertTip.vue.d.ts +2 -0
  20. package/dist/components/icon/arrow.vue.d.ts +2 -0
  21. package/dist/components/icon/calendar.vue.d.ts +2 -0
  22. package/dist/components/icon/close.vue.d.ts +2 -0
  23. package/dist/components/icon/dateArrow.vue.d.ts +2 -0
  24. package/dist/components/icon/dateArrowplus.vue.d.ts +2 -0
  25. package/dist/components/icon/delete.vue.d.ts +2 -0
  26. package/dist/components/icon/ellipsis.vue.d.ts +2 -0
  27. package/dist/components/icon/errTip.vue.d.ts +2 -0
  28. package/dist/components/icon/eye.vue.d.ts +2 -0
  29. package/dist/components/icon/infoTip.vue.d.ts +2 -0
  30. package/dist/components/icon/minus.vue.d.ts +2 -0
  31. package/dist/components/icon/successTip.vue.d.ts +2 -0
  32. package/dist/components/icon/turnleft.vue.d.ts +2 -0
  33. package/dist/components/icon/turnright.vue.d.ts +2 -0
  34. package/dist/components/icon/warnTip.vue.d.ts +2 -0
  35. package/dist/components/image/image.vue.d.ts +39 -29
  36. package/dist/components/input/input.vue.d.ts +59 -50
  37. package/dist/components/loadding/loadcomponent.vue.d.ts +24 -4
  38. package/dist/components/loadding/loadding.d.ts +13 -19
  39. package/dist/components/menu/menu.vue.d.ts +35 -12
  40. package/dist/components/message/message.d.ts +69 -14
  41. package/dist/components/message/messagecomponent.vue.d.ts +8 -15
  42. package/dist/components/numberInput/numberinput.vue.d.ts +51 -59
  43. package/dist/components/pagination/pagination.vue.d.ts +59 -27
  44. package/dist/components/popover/poparrow.d.ts +55 -0
  45. package/dist/components/popover/popover.vue.d.ts +63 -66
  46. package/dist/components/radio/radiobox.vue.d.ts +39 -22
  47. package/dist/components/radio/radiogroup.vue.d.ts +45 -21
  48. package/dist/components/scrollBar/movebar.vue.d.ts +33 -36
  49. package/dist/components/scrollBar/scrollBar.vue.d.ts +41 -40
  50. package/dist/components/scrollloading/scrolllead.d.ts +18 -11
  51. package/dist/components/select/select.vue.d.ts +55 -37
  52. package/dist/components/select/selectoption.vue.d.ts +39 -18
  53. package/dist/components/switch/switch.vue.d.ts +45 -45
  54. package/dist/components/table/table.vue.d.ts +61 -54
  55. package/dist/components/table/tableItem.vue.d.ts +49 -56
  56. package/dist/components/tabs/tabs.vue.d.ts +45 -19
  57. package/dist/components/tabs/tabsPane.vue.d.ts +25 -12
  58. package/dist/components/upload/upload.vue.d.ts +53 -53
  59. package/dist/directives/arrowKeys.d.ts +10 -0
  60. package/dist/directives/drag.d.ts +20 -0
  61. package/dist/directives/escape.d.ts +7 -0
  62. package/dist/directives/outsideclick.d.ts +14 -0
  63. package/dist/directives/watchwindow.d.ts +13 -0
  64. package/dist/directives/wheel.d.ts +12 -0
  65. package/dist/directives/whitespaceclick.d.ts +12 -0
  66. package/dist/index.d.ts +1524 -2210
  67. package/dist/js/arrow-ebe47bd0.js +17 -0
  68. package/dist/js/{badge/badge.js → badge-496028b6.js} +9 -16
  69. package/dist/js/calendar-5c242731.js +87 -0
  70. package/dist/js/carousel-10621aeb.js +155 -0
  71. package/dist/js/{carousel/carouselitem.js → carouselitem-89116745.js} +1 -7
  72. package/dist/js/checkbox-530025c4.js +50 -0
  73. package/dist/js/checkgroup-e4e6adbc.js +58 -0
  74. package/dist/js/dateArrowplus-8181993f.js +25 -0
  75. package/dist/js/datepicker-ef8b7019.js +362 -0
  76. package/dist/js/datepickerRange-4c400f88.js +500 -0
  77. package/dist/js/delete-e898f83c.js +19 -0
  78. package/dist/js/dialog-0127ca01.js +122 -0
  79. package/dist/js/form-6ae96387.js +79 -0
  80. package/dist/js/formlabel-9339bd1c.js +136 -0
  81. package/dist/js/image-76711716.js +300 -0
  82. package/dist/js/index-283810a0.js +6261 -0
  83. package/dist/js/index-b4e420ce.js +958 -0
  84. package/dist/js/index-e12c8d65.js +36 -0
  85. package/dist/js/input-11fe67a5.js +107 -0
  86. package/dist/js/menu-fb9b4a4f.js +86 -0
  87. package/dist/js/numberinput-00fa4429.js +119 -0
  88. package/dist/js/pagination-3bcaa109.js +203 -0
  89. package/dist/js/popover-45f75f86.js +345 -0
  90. package/dist/js/radiobox-8f11e726.js +49 -0
  91. package/dist/js/radiogroup-727923c7.js +33 -0
  92. package/dist/js/scrollBar-07906042.js +252 -0
  93. package/dist/js/select-b5bbb138.js +203 -0
  94. package/dist/js/selectoption-00c8f06d.js +57 -0
  95. package/dist/js/shapeFlag-8cf4bcf1.js +17 -0
  96. package/dist/js/switch-06ae74cc.js +50 -0
  97. package/dist/js/table-9bb52630.js +270 -0
  98. package/dist/js/{table/tableItem.js → tableItem-7d8bf2db.js} +1 -1
  99. package/dist/js/{tabs/tabs.js → tabs-9d7be734.js} +59 -60
  100. package/dist/js/{upload/upload.js → upload-16dbef22.js} +10 -26
  101. package/dist/types/shapeFlag.d.ts +13 -0
  102. package/dist/{components/utils → utils}/tool.d.ts +12 -5
  103. package/package.json +1 -1
  104. package/dist/badge.css +0 -27
  105. package/dist/carousel.css +0 -13
  106. package/dist/checkgroup.css +0 -41
  107. package/dist/components/tree/tree.vue.d.ts +0 -47
  108. package/dist/datepickerRange.css +0 -79
  109. package/dist/image.css +0 -8
  110. package/dist/index.css +0 -917
  111. package/dist/index.es.js +0 -37
  112. package/dist/index.umd.js +0 -6080
  113. package/dist/js/carousel/carousel.js +0 -175
  114. package/dist/js/check/checkbox.js +0 -16
  115. package/dist/js/check/checkgroup.js +0 -68
  116. package/dist/js/date/datepicker.js +0 -373
  117. package/dist/js/date/datepickerRange.js +0 -597
  118. package/dist/js/dialog/dialog.js +0 -140
  119. package/dist/js/form/form.js +0 -87
  120. package/dist/js/form/formlabel.js +0 -167
  121. package/dist/js/getcalendar/getcalendar.js +0 -48
  122. package/dist/js/image/image.js +0 -259
  123. package/dist/js/index/index.js +0 -873
  124. package/dist/js/input/input.js +0 -91
  125. package/dist/js/menu/menu.js +0 -58
  126. package/dist/js/numberInput/numberinput.js +0 -130
  127. package/dist/js/pagination/pagination.js +0 -245
  128. package/dist/js/popover/popover.js +0 -241
  129. package/dist/js/radio/radiobox.js +0 -16
  130. package/dist/js/radio/radiogroup.js +0 -68
  131. package/dist/js/scrollBar/scrollBar.js +0 -208
  132. package/dist/js/select/select.js +0 -117
  133. package/dist/js/select/selectoption.js +0 -16
  134. package/dist/js/switch/switch.js +0 -49
  135. package/dist/js/table/table.js +0 -215
  136. package/dist/js/tree/tree.js +0 -72
  137. package/dist/js/tree/treeleaf.js +0 -118
  138. package/dist/radiogroup.css +0 -44
  139. package/dist/scrollBar.css +0 -37
  140. package/dist/select.css +0 -20
  141. /package/dist/js/{tabs/tabsPane.js → tabsPane-f024a6bf.js} +0 -0
@@ -0,0 +1,203 @@
1
+ import { defineComponent, defineAsyncComponent, computed, inject, ref, watch, provide, toRef, openBlock, createBlock, unref, withCtx, createElementVNode, normalizeClass, createVNode, withDirectives, createElementBlock, renderSlot } from "vue";
2
+ import { A as ArrowIcon } from "./arrow-ebe47bd0.js";
3
+ import "./index-b4e420ce.js";
4
+ const directionMap = {
5
+ ArrowUp: "up",
6
+ Up: "up",
7
+ // IE/Edge 兼容
8
+ ArrowDown: "down",
9
+ Down: "down",
10
+ // IE/Edge 兼容
11
+ ArrowLeft: "left",
12
+ Left: "left",
13
+ // IE/Edge 兼容
14
+ ArrowRight: "right",
15
+ Right: "right"
16
+ // IE/Edge 兼容
17
+ };
18
+ const createArrowKeysDirective = (options) => {
19
+ const config = {
20
+ // 默认配置
21
+ up: () => {
22
+ },
23
+ down: () => {
24
+ },
25
+ left: () => {
26
+ },
27
+ right: () => {
28
+ },
29
+ ...options
30
+ };
31
+ const bindEvents = (el, binding) => {
32
+ const handler = (e) => {
33
+ var _a;
34
+ const direction = directionMap[e.key];
35
+ if (direction && config[direction]) {
36
+ e.preventDefault();
37
+ (_a = config[direction]) == null ? void 0 : _a.call(config, e);
38
+ }
39
+ };
40
+ el._arrowKeysHandler = handler;
41
+ document.addEventListener("keydown", handler);
42
+ };
43
+ const unbindEvents = (el) => {
44
+ if (el._arrowKeysHandler) {
45
+ document.removeEventListener("keydown", el._arrowKeysHandler);
46
+ }
47
+ delete el._arrowKeysHandler;
48
+ };
49
+ return {
50
+ mounted(el, binding) {
51
+ bindEvents(el);
52
+ },
53
+ updated(el, binding) {
54
+ unbindEvents(el);
55
+ bindEvents(el);
56
+ },
57
+ unmounted(el) {
58
+ unbindEvents(el);
59
+ }
60
+ };
61
+ };
62
+ const _hoisted_1 = ["value", "disabled", "readonly", "placeholder"];
63
+ const _sfc_main = /* @__PURE__ */ defineComponent({
64
+ __name: "select",
65
+ props: {
66
+ modelValue: {},
67
+ filter: { type: Boolean, default: false },
68
+ placeHolder: { default: "点击选择" },
69
+ disabled: { type: Boolean, default: false },
70
+ size: { default: "default" }
71
+ },
72
+ emits: ["update:modelValue", "change"],
73
+ setup(__props, { emit: __emit }) {
74
+ const Pop = defineAsyncComponent(() => import("./popover-45f75f86.js"));
75
+ const LibScrollBar = defineAsyncComponent(() => import("./scrollBar-07906042.js"));
76
+ const props = __props;
77
+ const heightClass = computed(() => ({
78
+ "h-8": props.size === "large",
79
+ "h-7": props.size === "default",
80
+ "h-6": props.size === "small"
81
+ }));
82
+ const ParentGetChangeHandle = inject("changHandle", (_params) => null);
83
+ const inputbox = ref();
84
+ const popwidth = computed(() => {
85
+ var _a;
86
+ return ((_a = inputbox.value) == null ? void 0 : _a.clientWidth) || 200;
87
+ });
88
+ const scrollRef = ref();
89
+ const vArrowKeys = createArrowKeysDirective({
90
+ up: () => {
91
+ if (showOption.value) {
92
+ const newIndex = (inputLabelIndex.value - 1 + totalNum.value) % totalNum.value;
93
+ updateModelvalue(selectDataArr.value[newIndex].value);
94
+ }
95
+ },
96
+ down: () => {
97
+ if (showOption.value) {
98
+ const newIndex = (inputLabelIndex.value + 1 + totalNum.value) % totalNum.value;
99
+ updateModelvalue(selectDataArr.value[newIndex].value);
100
+ }
101
+ }
102
+ });
103
+ const emit = __emit;
104
+ const showOption = ref(false);
105
+ const showHandle = () => {
106
+ if (props.disabled === true)
107
+ return;
108
+ showOption.value = !showOption.value;
109
+ };
110
+ const selectDataArr = ref([]);
111
+ const insertData = (data) => {
112
+ selectDataArr.value.push(data);
113
+ };
114
+ watch(showOption, (newval) => {
115
+ if (newval === false) {
116
+ LastChildSelect(props.modelValue);
117
+ }
118
+ });
119
+ const updateModelvalue = (value) => {
120
+ emit("update:modelValue", value);
121
+ emit("change", value);
122
+ LastChildSelect(value);
123
+ ParentGetChangeHandle && ParentGetChangeHandle(value);
124
+ };
125
+ provide("_SelectItemPush_", insertData);
126
+ provide("_UpdateSelectData_", (value) => {
127
+ updateModelvalue(value);
128
+ showOption.value = false;
129
+ });
130
+ provide("_SelectModelValue_", toRef(props, "modelValue"));
131
+ const lastMouseEnterValue = toRef(props.modelValue);
132
+ const LastChildSelect = (value) => {
133
+ lastMouseEnterValue.value = value;
134
+ };
135
+ provide("_LastSelectValue_", lastMouseEnterValue);
136
+ provide("_LastChildSelect_", LastChildSelect);
137
+ const inputLabel = computed(() => {
138
+ const isThis = selectDataArr.value.find((v) => v.value === props.modelValue);
139
+ return isThis ? isThis.label : props.modelValue;
140
+ });
141
+ const inputLabelIndex = computed(() => {
142
+ return selectDataArr.value.findIndex((v) => v.value === props.modelValue);
143
+ });
144
+ const totalNum = computed(() => {
145
+ return selectDataArr.value.length;
146
+ });
147
+ return (_ctx, _cache) => {
148
+ return openBlock(), createBlock(unref(Pop), {
149
+ isselectMode: "",
150
+ trigger: "native",
151
+ modelValue: showOption.value,
152
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => showOption.value = $event),
153
+ width: popwidth.value,
154
+ insertClass: "z-2000 text-sm py-0.5 px-0",
155
+ placement: "bottommiddle"
156
+ }, {
157
+ reference: withCtx(() => [
158
+ createElementVNode("div", {
159
+ ref_key: "inputbox",
160
+ ref: inputbox,
161
+ class: normalizeClass([{
162
+ "bg-gray-100 cursor-default": _ctx.disabled,
163
+ "cursor-pointer": !_ctx.disabled
164
+ }, "relative flex h-full w-full items-center overflow-hidden rounded border border-solid"]),
165
+ onClick: showHandle
166
+ }, [
167
+ createElementVNode("input", {
168
+ value: inputLabel.value,
169
+ type: "text",
170
+ disabled: _ctx.disabled,
171
+ readonly: !_ctx.filter,
172
+ class: normalizeClass(["w-full cursor-pointer appearance-none px-2 text-sm outline-none disabled:cursor-default text-word3", heightClass.value]),
173
+ placeholder: _ctx.placeHolder
174
+ }, null, 10, _hoisted_1),
175
+ createVNode(ArrowIcon, {
176
+ class: normalizeClass(["w-3 h-3 fill-gray-300 inline-block transform transition-all mx-1", { "-rotate-90": showOption.value, "rotate-90": !showOption.value }])
177
+ }, null, 8, ["class"])
178
+ ], 2)
179
+ ]),
180
+ default: withCtx(() => [
181
+ withDirectives((openBlock(), createElementBlock("div", null, [
182
+ createVNode(unref(LibScrollBar), {
183
+ ref_key: "scrollRef",
184
+ ref: scrollRef,
185
+ maxHeight: "274px"
186
+ }, {
187
+ default: withCtx(() => [
188
+ renderSlot(_ctx.$slots, "default")
189
+ ]),
190
+ _: 3
191
+ }, 512)
192
+ ])), [
193
+ [unref(vArrowKeys)]
194
+ ])
195
+ ]),
196
+ _: 3
197
+ }, 8, ["modelValue", "width"]);
198
+ };
199
+ }
200
+ });
201
+ export {
202
+ _sfc_main as default
203
+ };
@@ -0,0 +1,57 @@
1
+ import { defineComponent, ref, inject, computed, useSlots, openBlock, createElementBlock, normalizeClass, toDisplayString, renderSlot } from "vue";
2
+ const _hoisted_1 = { key: 0 };
3
+ const _sfc_main = /* @__PURE__ */ defineComponent({
4
+ __name: "selectoption",
5
+ props: {
6
+ value: {},
7
+ label: {},
8
+ disabled: { type: Boolean, default: false }
9
+ },
10
+ setup(__props, { expose: __expose }) {
11
+ const props = __props;
12
+ const elRef = ref();
13
+ const modelValue = inject("_SelectModelValue_");
14
+ const isSelected = computed(() => modelValue.value === props.value);
15
+ const slots = useSlots();
16
+ const pushData = inject("_SelectItemPush_", (_params) => {
17
+ });
18
+ const selectHandle = inject("_UpdateSelectData_", (_params) => {
19
+ });
20
+ const hoverValue = inject("_LastSelectValue_");
21
+ const hoverHandle = inject("_LastChildSelect_", (_params) => {
22
+ });
23
+ const clickMeHandle = () => {
24
+ if (props.disabled)
25
+ return;
26
+ selectHandle(props.value);
27
+ };
28
+ pushData({ ...props });
29
+ const hasSlot = computed(() => !!slots.default);
30
+ const isHovered = computed(() => hoverValue.value === props.value);
31
+ const moveIn = () => {
32
+ hoverHandle(props.value);
33
+ };
34
+ __expose({
35
+ el: elRef
36
+ });
37
+ return (_ctx, _cache) => {
38
+ return openBlock(), createElementBlock("div", {
39
+ ref_key: "elRef",
40
+ ref: elRef,
41
+ onClick: clickMeHandle,
42
+ onMouseenter: moveIn,
43
+ class: normalizeClass(["px-1 py-2 cursor-pointer", {
44
+ "text-blue-light": isSelected.value,
45
+ "opacity-50 cursor-not-allowed": _ctx.disabled,
46
+ "bg-gray-100": !_ctx.disabled && isHovered.value,
47
+ "bg-inherit": !isHovered.value
48
+ }])
49
+ }, [
50
+ !hasSlot.value ? (openBlock(), createElementBlock("div", _hoisted_1, toDisplayString(_ctx.label || _ctx.value), 1)) : renderSlot(_ctx.$slots, "default", { key: 1 })
51
+ ], 34);
52
+ };
53
+ }
54
+ });
55
+ export {
56
+ _sfc_main as default
57
+ };
@@ -0,0 +1,17 @@
1
+ var ShapeFlags = /* @__PURE__ */ ((ShapeFlags2) => {
2
+ ShapeFlags2[ShapeFlags2["ELEMENT"] = 1] = "ELEMENT";
3
+ ShapeFlags2[ShapeFlags2["FUNCTIONAL_COMPONENT"] = 2] = "FUNCTIONAL_COMPONENT";
4
+ ShapeFlags2[ShapeFlags2["STATEFUL_COMPONENT"] = 4] = "STATEFUL_COMPONENT";
5
+ ShapeFlags2[ShapeFlags2["TEXT_CHILDREN"] = 8] = "TEXT_CHILDREN";
6
+ ShapeFlags2[ShapeFlags2["ARRAY_CHILDREN"] = 16] = "ARRAY_CHILDREN";
7
+ ShapeFlags2[ShapeFlags2["SLOTS_CHILDREN"] = 32] = "SLOTS_CHILDREN";
8
+ ShapeFlags2[ShapeFlags2["TELEPORT"] = 64] = "TELEPORT";
9
+ ShapeFlags2[ShapeFlags2["SUSPENSE"] = 128] = "SUSPENSE";
10
+ ShapeFlags2[ShapeFlags2["COMPONENT_SHOULD_KEEP_ALIVE"] = 256] = "COMPONENT_SHOULD_KEEP_ALIVE";
11
+ ShapeFlags2[ShapeFlags2["COMPONENT_KEPT_ALIVE"] = 512] = "COMPONENT_KEPT_ALIVE";
12
+ ShapeFlags2[ShapeFlags2["COMPONENT"] = 6] = "COMPONENT";
13
+ return ShapeFlags2;
14
+ })(ShapeFlags || {});
15
+ export {
16
+ ShapeFlags as S
17
+ };
@@ -0,0 +1,50 @@
1
+ import { defineComponent, openBlock, createElementBlock, createElementVNode, normalizeStyle, normalizeClass, toDisplayString } from "vue";
2
+ const _hoisted_1 = { class: "inline-block cursor-pointer select-none text-xs relative" };
3
+ const _hoisted_2 = {
4
+ key: 0,
5
+ class: "z-10 font-semibold text-white leading-5 mr-6 pl-1"
6
+ };
7
+ const _hoisted_3 = {
8
+ key: 1,
9
+ class: "z-10 font-semibold text-white leading-5 ml-6 pr-1"
10
+ };
11
+ const _sfc_main = /* @__PURE__ */ defineComponent({
12
+ __name: "switch",
13
+ props: {
14
+ checkedLabel: {},
15
+ uncheckedLabel: {},
16
+ checkedColor: { default: "#25b9e9" },
17
+ uncheckedColor: { default: "#666666" },
18
+ modelValue: { type: Boolean, default: false }
19
+ },
20
+ emits: ["update:modelValue", "switchChange"],
21
+ setup(__props, { emit: __emit }) {
22
+ const props = __props;
23
+ const emit = __emit;
24
+ const togglehandle = () => {
25
+ emit("update:modelValue", !props.modelValue);
26
+ emit("switchChange", !props.modelValue);
27
+ };
28
+ return (_ctx, _cache) => {
29
+ return openBlock(), createElementBlock("label", _hoisted_1, [
30
+ createElementVNode("input", {
31
+ type: "checkbox",
32
+ class: "hidden",
33
+ onChange: togglehandle
34
+ }, null, 32),
35
+ createElementVNode("div", {
36
+ class: "relative box-border block h-5 min-w-10 select-none overflow-hidden rounded-xl outline-0 ring-2 ring-gray-300",
37
+ style: normalizeStyle({ backgroundColor: _ctx.modelValue ? _ctx.checkedColor : _ctx.uncheckedColor })
38
+ }, [
39
+ createElementVNode("div", {
40
+ class: normalizeClass(["absolute top-0 z-10 block h-5 w-5 transform rounded-full bg-slate-50 transition-all", [_ctx.modelValue ? "left-[calc(100%-20px)]" : "left-0"]])
41
+ }, null, 2),
42
+ _ctx.modelValue ? (openBlock(), createElementBlock("div", _hoisted_2, toDisplayString(_ctx.checkedLabel), 1)) : (openBlock(), createElementBlock("div", _hoisted_3, toDisplayString(_ctx.uncheckedLabel), 1))
43
+ ], 4)
44
+ ]);
45
+ };
46
+ }
47
+ });
48
+ export {
49
+ _sfc_main as default
50
+ };
@@ -0,0 +1,270 @@
1
+ import { defineComponent, computed, useSlots, ref, watch, openBlock, createElementBlock, Fragment, createElementVNode, normalizeClass, createVNode, withDirectives, vShow, h, vModelCheckbox, withModifiers } from "vue";
2
+ import { S as ShapeFlags } from "./shapeFlag-8cf4bcf1.js";
3
+ const _hoisted_1 = { class: "text-center text-word6 text-base" };
4
+ const _sfc_main = /* @__PURE__ */ defineComponent({
5
+ __name: "table",
6
+ props: {
7
+ data: {},
8
+ whiteword: { default: "" },
9
+ showHead: { type: Boolean, default: true },
10
+ headclass: {},
11
+ cellclass: {},
12
+ tableclass: {},
13
+ idKey: {}
14
+ },
15
+ emits: ["rowClick", "selectionChange"],
16
+ setup(__props, { expose: __expose, emit: __emit }) {
17
+ const props = __props;
18
+ const hasData = computed(() => {
19
+ return props.data.length > 0;
20
+ });
21
+ const emit = __emit;
22
+ const slots = useSlots();
23
+ const validSlots = computed(() => {
24
+ return slots.default().reduce((pre, cur) => {
25
+ if (cur.shapeFlag & ShapeFlags.ARRAY_CHILDREN) {
26
+ pre = pre.concat(cur.children);
27
+ } else if (cur.shapeFlag & ShapeFlags.STATEFUL_COMPONENT) {
28
+ pre.push(cur);
29
+ }
30
+ return pre;
31
+ }, []);
32
+ });
33
+ const appendSlots = computed(
34
+ () => validSlots.value.filter((slot) => slot.props.type === "append")
35
+ );
36
+ const prependSlots = computed(
37
+ () => validSlots.value.filter((slot) => slot.props.type === "prepend")
38
+ );
39
+ const restSlots = computed(
40
+ () => validSlots.value.filter(
41
+ (slot) => slot.props.type !== "append" && slot.props.type !== "prepend"
42
+ )
43
+ );
44
+ const renderColGroup = () => {
45
+ return h(
46
+ "colgroup",
47
+ null,
48
+ restSlots.value.map((it, _index) => {
49
+ return colitemHandle(it);
50
+ })
51
+ );
52
+ };
53
+ const colitemHandle = (it) => {
54
+ return h("col", {
55
+ width: it.props.width || null
56
+ });
57
+ };
58
+ const renderHead = () => {
59
+ return h(
60
+ "thead",
61
+ {
62
+ class: normalizeClass(["text-word6", [props.headclass]])
63
+ },
64
+ restSlots.value.map((it) => {
65
+ return headitemHandle(it);
66
+ })
67
+ );
68
+ };
69
+ const headitemHandle = (it) => {
70
+ var _a;
71
+ return h(
72
+ "th",
73
+ {
74
+ class: "font-normal h-10 border-b "
75
+ },
76
+ it.children && it.children.head ? it.children.head() : ((_a = it.props) == null ? void 0 : _a.type) && it.props.type === "selection" ? h(
77
+ "label",
78
+ {
79
+ class: "px-1 flex"
80
+ },
81
+ withDirectives(
82
+ h("input", {
83
+ type: "checkbox",
84
+ "onUpdate:modelValue": (value) => allSelect.value = value,
85
+ class: "appearance-none form-tick h-4 w-4 border border-gray-300 rounded checked:border-transparent checked:bg-blue-600 text-red-600 focus:outline-none"
86
+ }),
87
+ [[vModelCheckbox, allSelect.value]]
88
+ )
89
+ ) : it.props.label
90
+ );
91
+ };
92
+ const allSelect = computed({
93
+ set(flag) {
94
+ if (flag) {
95
+ allSelection();
96
+ } else {
97
+ clearSelection();
98
+ }
99
+ },
100
+ get() {
101
+ return hasData.value && choosedKeys.value.length == props.data.length;
102
+ }
103
+ });
104
+ const MapData = computed(() => {
105
+ return props.data.reduce((map, item, index) => {
106
+ const key = props.idKey ? item[props.idKey] : index;
107
+ if (map.has(key)) {
108
+ console.warn(`重复键 ${key},已合并为数组`);
109
+ map.set(key, [...map.get(key), item]);
110
+ } else {
111
+ map.set(key, [item]);
112
+ }
113
+ return map;
114
+ }, /* @__PURE__ */ new Map());
115
+ });
116
+ const choosedSet = ref(/* @__PURE__ */ new Set());
117
+ const choosedKeys = computed(() => Array.from(choosedSet.value));
118
+ const resultArray = computed(() => {
119
+ return choosedKeys.value.map((key) => {
120
+ const mapKey = props.idKey ? key : Number(key);
121
+ return MapData.value.get(mapKey) || [];
122
+ }).flat();
123
+ });
124
+ const clearSelection = () => {
125
+ choosedSet.value = /* @__PURE__ */ new Set();
126
+ };
127
+ const allSelection = () => {
128
+ choosedSet.value = new Set(MapData.value.keys());
129
+ };
130
+ watch(choosedKeys, () => {
131
+ emit("selectionChange", resultArray.value);
132
+ });
133
+ const renderSlotRows = (slots2, row, index, colSpan, modify) => {
134
+ const rowKey = getRowKey(row, index);
135
+ return slots2.map(
136
+ (slot) => h(
137
+ "tr",
138
+ { key: `${modify}-${rowKey}` },
139
+ h("td", { colSpan }, trRenderHandle(row, slot, index))
140
+ )
141
+ );
142
+ };
143
+ const renderMainRow = (row, index) => {
144
+ const rowKey = getRowKey(row, index);
145
+ return h(
146
+ "tr",
147
+ {
148
+ class: "border-b hover:bg-gray-100 transition-colors",
149
+ key: rowKey,
150
+ // 使用唯一键替代索引
151
+ onClick: withModifiers(() => emit("rowClick", { row, index }), ["stop"])
152
+ },
153
+ restSlots.value.map(
154
+ (slot, colIndex) => bodyCellRenderer(row, slot, index, colIndex)
155
+ )
156
+ );
157
+ };
158
+ const bodyCellRenderer = (row, slot, rowIndex, colIndex) => {
159
+ return h(
160
+ "td",
161
+ {
162
+ class: cellClasses(slot.props),
163
+ // 提取样式生成逻辑
164
+ key: `${getRowKey(row, rowIndex)}-${colIndex}`
165
+ // 复合键
166
+ },
167
+ renderCellContent(row, slot, rowIndex)
168
+ );
169
+ };
170
+ const renderCellContent = (row, slot, rowIndex) => {
171
+ var _a;
172
+ return ((_a = slot.props) == null ? void 0 : _a.type) === "selection" ? h(
173
+ "label",
174
+ {
175
+ class: "px-1 flex",
176
+ for: "checkbox"
177
+ },
178
+ h("input", {
179
+ type: "checkbox",
180
+ value: props.idKey ? row[props.idKey] : rowIndex,
181
+ onChange: (event) => {
182
+ const target = event.target;
183
+ const rowKey = props.idKey ? row[props.idKey] : rowIndex;
184
+ target.checked ? choosedSet.value.add(rowKey) : choosedSet.value.delete(rowKey);
185
+ },
186
+ checked: choosedSet.value.has(
187
+ props.idKey ? row[props.idKey] : rowIndex
188
+ ),
189
+ class: "appearance-none form-tick h-4 w-4 border border-gray-300 rounded checked:border-transparent checked:bg-blue-600 text-red-600 focus:outline-none "
190
+ })
191
+ ) : trRenderHandle(row, slot, rowIndex);
192
+ };
193
+ const cellClasses = (props2) => {
194
+ return normalizeClass([
195
+ "text-center py-2",
196
+ props2 == null ? void 0 : props2.cellclass,
197
+ (props2 == null ? void 0 : props2.align) === "right" ? "text-right" : "text-left"
198
+ ]);
199
+ };
200
+ const getRowKey = (row, index) => {
201
+ return props.idKey ? row[props.idKey] : `row-${index}`;
202
+ };
203
+ const renderBody = () => {
204
+ const { data } = props;
205
+ const prepend = prependSlots.value;
206
+ const append = appendSlots.value;
207
+ const rest = restSlots.value;
208
+ const colSpan = rest.length;
209
+ const renderRow = (row, index) => {
210
+ return [
211
+ // 前置插槽渲染
212
+ ...renderSlotRows(prepend, row, index, colSpan, "pre"),
213
+ // 主体行
214
+ renderMainRow(row, index),
215
+ // 后置插槽渲染
216
+ ...renderSlotRows(append, row, index, colSpan, "next")
217
+ ];
218
+ };
219
+ return h("tbody", data.map(renderRow));
220
+ };
221
+ const trRenderHandle = (row, it, i) => {
222
+ return h(
223
+ "div",
224
+ null,
225
+ it.children && it.children.default ? it.children.default({
226
+ row,
227
+ index: i
228
+ }) : row[it.props.prop] || props.whiteword
229
+ );
230
+ };
231
+ __expose({
232
+ clearSelection,
233
+ allSelection,
234
+ toggleSelection: () => {
235
+ if (choosedSet.value.size === MapData.value.size) {
236
+ clearSelection();
237
+ return;
238
+ }
239
+ const newSet = /* @__PURE__ */ new Set();
240
+ for (const key of MapData.value.keys()) {
241
+ if (!choosedSet.value.has(key))
242
+ newSet.add(key);
243
+ }
244
+ choosedSet.value = newSet;
245
+ },
246
+ setSelection: (arr) => {
247
+ choosedSet.value = new Set(arr);
248
+ }
249
+ });
250
+ return (_ctx, _cache) => {
251
+ return openBlock(), createElementBlock(Fragment, null, [
252
+ createElementVNode("table", {
253
+ class: normalizeClass(["w-full text-sm", _ctx.tableclass])
254
+ }, [
255
+ createVNode(renderColGroup),
256
+ withDirectives(createVNode(renderHead, null, null, 512), [
257
+ [vShow, _ctx.showHead]
258
+ ]),
259
+ createVNode(renderBody)
260
+ ], 2),
261
+ withDirectives(createElementVNode("div", _hoisted_1, "暂无数据", 512), [
262
+ [vShow, !hasData.value]
263
+ ])
264
+ ], 64);
265
+ };
266
+ }
267
+ });
268
+ export {
269
+ _sfc_main as default
270
+ };
@@ -6,7 +6,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
6
6
  width: {},
7
7
  label: {},
8
8
  fixed: {},
9
- type: {},
9
+ type: { default: "default" },
10
10
  sortable: { type: Boolean },
11
11
  row: {},
12
12
  index: {}