@qiyin/select-product 1.0.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.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # @qiyin/select-product
2
+
3
+ 货品树形选择组件,支持分类展开、图片预览悬浮、关键词搜索高亮。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @qiyin/select-product
9
+ ```
10
+
11
+ ## 注册
12
+
13
+ ### 全局注册
14
+ ```js
15
+ import { createApp } from 'vue'
16
+ import SelectProduct from '@qiyin/select-product'
17
+
18
+ const app = createApp(App)
19
+ app.use(SelectProduct) // 注册为 <QySelectProduct>
20
+ ```
21
+
22
+ ### 局部引入
23
+ ```js
24
+ import { SelectProduct } from '@qiyin/select-product'
25
+ ```
26
+
27
+ ## 基础用法
28
+
29
+ ```vue
30
+ <template>
31
+ <div style="height: 600px; width: 280px;">
32
+ <QySelectProduct :data="productTree" @select="handleSelect" />
33
+ </div>
34
+ </template>
35
+
36
+ <script setup>
37
+ import { ref } from 'vue'
38
+
39
+ const productTree = ref([
40
+ {
41
+ cateName: '礼盒类',
42
+ cateProductCode: 'CAT-001',
43
+ children: [
44
+ {
45
+ finishedProductCode: 'P-001',
46
+ finishedProductName: '天地盖礼盒',
47
+ displayImage: 'https://example.com/img/p001.jpg'
48
+ },
49
+ {
50
+ finishedProductCode: 'P-002',
51
+ finishedProductName: '翻盖礼盒',
52
+ displayImage: 'https://example.com/img/p002.jpg'
53
+ }
54
+ ]
55
+ },
56
+ {
57
+ finishedProductCode: 'P-003',
58
+ finishedProductName: '手提袋',
59
+ displayImage: 'https://example.com/img/p003.jpg'
60
+ }
61
+ ])
62
+
63
+ function handleSelect([code, ...rest]) {
64
+ console.log('选中货品编号:', code)
65
+ }
66
+ </script>
67
+ ```
68
+
69
+ ## Props
70
+
71
+ | 参数 | 类型 | 默认值 | 说明 |
72
+ |------|------|--------|------|
73
+ | `data` | `Array` | `[]` | 货品树数据,见下方数据结构 |
74
+
75
+ ## Events
76
+
77
+ | 事件名 | 参数 | 说明 |
78
+ |--------|------|------|
79
+ | `select` | `[finishedProductCode, ...menuArgs]` | 点击某个货品时触发,第一个参数为货品编号 |
80
+
81
+ ## Slots
82
+
83
+ | 插槽名 | 说明 |
84
+ |--------|------|
85
+ | `header` | 搜索栏下方、列表上方的自定义内容区 |
86
+
87
+ ## 数据结构
88
+
89
+ ```ts
90
+ type ProductNode = CategoryNode | ProductLeaf
91
+
92
+ // 分类节点(有 cateName 字段)
93
+ interface CategoryNode {
94
+ cateProductCode: string // 分类唯一编码,作为菜单 index
95
+ cateName: string // 分类显示名称
96
+ children?: ProductNode[] // 子节点(分类或货品)
97
+ }
98
+
99
+ // 货品节点(无 cateName 字段)
100
+ interface ProductLeaf {
101
+ finishedProductCode: string // 货品编号,作为菜单 index,select 事件返回此值
102
+ finishedProductName: string // 货品名称
103
+ displayImage?: string // 封面图 URL,悬浮显示大图
104
+ }
105
+ ```
106
+
107
+ ## 搜索
108
+
109
+ 组件内置搜索栏,支持按**货品名称**或**货品编号**模糊匹配。搜索时:
110
+ - 自动展开所有命中分类
111
+ - 匹配关键词高亮显示
112
+ - 无结果时显示空状态
113
+
114
+ ## 样式定制
115
+
116
+ 组件使用 `border-box` 布局,需要父容器指定高度。常见场景:
117
+
118
+ ```vue
119
+ <!-- 固定高度侧边栏 -->
120
+ <div style="height: 100vh; width: 260px;">
121
+ <QySelectProduct :data="tree" @select="onSelect" />
122
+ </div>
123
+
124
+ <!-- 弹窗内使用 -->
125
+ <el-dialog width="360px">
126
+ <div style="height: 500px;">
127
+ <QySelectProduct :data="tree" @select="onSelect" />
128
+ </div>
129
+ </el-dialog>
130
+ ```
131
+
132
+ ## 对等依赖(peerDependencies)
133
+
134
+ | 包 | 版本 |
135
+ |----|------|
136
+ | `vue` | `^3.4` |
137
+ | `element-plus` | `^2.0` |
138
+ | `@element-plus/icons-vue` | `^2.0` |
@@ -0,0 +1,282 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".cate-title[data-v-4cd996d7]{font-size:13px;font-weight:600}.product-item[data-v-4cd996d7]{height:auto!important;min-height:44px}.product-item__inner[data-v-4cd996d7]{display:flex;align-items:center;gap:10px;width:100%;padding:4px 0}.product-item__thumb[data-v-4cd996d7]{width:44px;height:44px;border-radius:4px;border:1px solid #eee;flex-shrink:0;overflow:hidden;cursor:pointer}.product-item__thumb--placeholder[data-v-4cd996d7]{display:flex;align-items:center;justify-content:center;background:#f5f5f5;color:#c0c4cc}.product-item__thumb-error[data-v-4cd996d7]{width:100%;height:100%;display:flex;align-items:center;justify-content:center;background:#f5f7fa;color:#c0c4cc}.product-item__name[data-v-4cd996d7]{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;font-size:13px;color:#303133;line-height:1.4;word-break:break-all}.product-item__code[data-v-4cd996d7]{font-size:11px;color:#909399}.preview-error[data-v-4cd996d7]{display:flex;flex-direction:column;align-items:center;justify-content:center;height:120px;color:#c0c4cc;gap:6px;font-size:12px}mark.highlight[data-v-4cd996d7]{background:#fef08a;color:inherit;padding:0;border-radius:2px}[data-v-4cd996d7] .el-menu-item *{vertical-align:middle}.qy-select-product[data-v-33a92b09]{display:flex;flex-direction:column;height:100%;background:#fff;border:1px solid #e4e7ed;border-radius:6px;overflow:hidden}.qy-select-product__search[data-v-33a92b09]{padding:10px 12px 8px;border-bottom:1px solid #f0f0f0;background:#fff}.qy-select-product__body[data-v-33a92b09]{flex:1;min-height:0}.qy-select-product__menu[data-v-33a92b09]{border-right:none!important}.qy-select-product__empty[data-v-33a92b09]{display:flex;align-items:center;justify-content:center;height:200px}[data-v-33a92b09] .el-menu{border-right:none}[data-v-33a92b09] .el-sub-menu__title{font-weight:600;font-size:13px;color:#303133}[data-v-33a92b09] .el-sub-menu__title:hover,[data-v-33a92b09] .el-menu-item:hover,[data-v-33a92b09] .el-menu-item.is-active{background-color:#ecf5ff!important}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ import { ElSubMenu as B, ElMenuItem as D, ElPopover as j, ElImage as A, ElIcon as F, ElInput as R, ElScrollbar as U, ElMenu as G, ElEmpty as H } from "element-plus/es";
3
+ import "element-plus/es/components/base/style/css";
4
+ import "element-plus/es/components/scrollbar/style/css";
5
+ import "element-plus/es/components/empty/style/css";
6
+ import "element-plus/es/components/menu/style/css";
7
+ import "element-plus/es/components/input/style/css";
8
+ import { ref as $, computed as q, resolveComponent as J, createBlock as y, openBlock as t, withCtx as n, createElementBlock as c, Fragment as b, renderList as L, createElementVNode as p, toDisplayString as P, createVNode as l, unref as I, renderSlot as K } from "vue";
9
+ import { Picture as N, Search as W } from "@element-plus/icons-vue";
10
+ import "element-plus/es/components/menu-item/style/css";
11
+ import "element-plus/es/components/popover/style/css";
12
+ import "element-plus/es/components/image/style/css";
13
+ import "element-plus/es/components/icon/style/css";
14
+ import "element-plus/es/components/sub-menu/style/css";
15
+ const V = (m, e) => {
16
+ const v = m.__vccOpts || m;
17
+ for (const [C, _] of e)
18
+ v[C] = _;
19
+ return v;
20
+ }, X = { class: "cate-title" }, Y = { class: "product-item__inner" }, Z = { class: "product-item__thumb-error" }, ee = { class: "preview-error" }, te = { class: "product-item__thumb-error" }, oe = {
21
+ key: 1,
22
+ class: "product-item__thumb product-item__thumb--placeholder"
23
+ }, re = { class: "product-item__name" }, ne = { key: 0 }, se = {
24
+ key: 0,
25
+ class: "highlight"
26
+ }, ce = { key: 1 }, le = { key: 1 }, ie = { class: "product-item__code" }, ue = {
27
+ __name: "menuItem",
28
+ props: {
29
+ item: { type: Object, default: null },
30
+ index: { type: Number, default: 0 },
31
+ openCode: { type: String, default: "" },
32
+ searchQuery: { type: String, default: "" }
33
+ },
34
+ setup(m) {
35
+ const e = m, v = $(!1), C = q(() => {
36
+ const _ = e.item.finishedProductName || "", u = e.searchQuery;
37
+ if (!u) return [_];
38
+ const a = new RegExp(
39
+ `(${u.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")})`,
40
+ "gi"
41
+ );
42
+ return _.split(a);
43
+ });
44
+ return (_, u) => {
45
+ const a = J("menu-item", !0), E = B, g = F, k = A, Q = j, S = D;
46
+ return e.item.cateName ? (t(), y(E, {
47
+ key: 0,
48
+ index: e.item.cateProductCode
49
+ }, {
50
+ title: n(() => [
51
+ p("span", X, P(e.item.cateName), 1)
52
+ ]),
53
+ default: n(() => [
54
+ (t(!0), c(b, null, L(e.item.children || [], (s) => (t(), y(a, {
55
+ key: s.cateProductCode,
56
+ item: s,
57
+ openCode: e.openCode,
58
+ searchQuery: e.searchQuery
59
+ }, null, 8, ["item", "openCode", "searchQuery"]))), 128)),
60
+ (t(!0), c(b, null, L(e.item.productList || [], (s, x) => (t(), y(a, {
61
+ key: s.finishedProductCode,
62
+ item: s,
63
+ openCode: e.openCode,
64
+ searchQuery: e.searchQuery,
65
+ index: x
66
+ }, null, 8, ["item", "openCode", "searchQuery", "index"]))), 128))
67
+ ]),
68
+ _: 1
69
+ }, 8, ["index"])) : (t(), y(S, {
70
+ key: 1,
71
+ index: e.item.finishedProductCode,
72
+ class: "product-item"
73
+ }, {
74
+ title: n(() => [
75
+ p("div", Y, [
76
+ e.item.displayImage ? (t(), c(b, { key: 0 }, [
77
+ v.value ? (t(), y(Q, {
78
+ key: 0,
79
+ placement: "right",
80
+ width: 320,
81
+ trigger: "hover",
82
+ teleported: !0
83
+ }, {
84
+ reference: n(() => [
85
+ l(k, {
86
+ class: "product-item__thumb",
87
+ src: e.item.displayImage,
88
+ fit: "cover",
89
+ lazy: ""
90
+ }, {
91
+ error: n(() => [
92
+ p("div", Z, [
93
+ l(g, null, {
94
+ default: n(() => [
95
+ l(I(N))
96
+ ]),
97
+ _: 1
98
+ })
99
+ ])
100
+ ]),
101
+ _: 1
102
+ }, 8, ["src"])
103
+ ]),
104
+ default: n(() => [
105
+ l(k, {
106
+ src: e.item.displayImage,
107
+ class: "w-full",
108
+ style: { "max-height": "200px" },
109
+ fit: "contain"
110
+ }, {
111
+ error: n(() => [
112
+ p("div", ee, [
113
+ l(g, { size: "24" }, {
114
+ default: n(() => [
115
+ l(I(N))
116
+ ]),
117
+ _: 1
118
+ }),
119
+ u[1] || (u[1] = p("span", null, "加载失败", -1))
120
+ ])
121
+ ]),
122
+ _: 1
123
+ }, 8, ["src"])
124
+ ]),
125
+ _: 1
126
+ })) : (t(), y(k, {
127
+ key: 1,
128
+ class: "product-item__thumb",
129
+ src: e.item.displayImage,
130
+ fit: "cover",
131
+ lazy: "",
132
+ onMouseenter: u[0] || (u[0] = (s) => v.value = !0)
133
+ }, {
134
+ error: n(() => [
135
+ p("div", te, [
136
+ l(g, null, {
137
+ default: n(() => [
138
+ l(I(N))
139
+ ]),
140
+ _: 1
141
+ })
142
+ ])
143
+ ]),
144
+ _: 1
145
+ }, 8, ["src"]))
146
+ ], 64)) : (t(), c("div", oe, [
147
+ l(g, null, {
148
+ default: n(() => [
149
+ l(I(N))
150
+ ]),
151
+ _: 1
152
+ })
153
+ ])),
154
+ p("div", re, [
155
+ e.searchQuery && C.value.length > 1 ? (t(), c("span", ne, [
156
+ (t(!0), c(b, null, L(C.value, (s, x) => (t(), c(b, { key: x }, [
157
+ x % 2 === 1 ? (t(), c("mark", se, P(s), 1)) : (t(), c("span", ce, P(s), 1))
158
+ ], 64))), 128))
159
+ ])) : (t(), c("span", le, P(e.item.finishedProductName), 1)),
160
+ p("span", ie, P(e.item.finishedProductCode), 1)
161
+ ])
162
+ ])
163
+ ]),
164
+ _: 1
165
+ }, 8, ["index"]));
166
+ };
167
+ }
168
+ }, ae = /* @__PURE__ */ V(ue, [["__scopeId", "data-v-4cd996d7"]]), de = { class: "qy-select-product" }, pe = { class: "qy-select-product__search" }, me = {
169
+ key: 1,
170
+ class: "qy-select-product__empty"
171
+ }, _e = {
172
+ __name: "index",
173
+ props: {
174
+ data: {
175
+ type: Array,
176
+ default: () => []
177
+ }
178
+ },
179
+ emits: ["select"],
180
+ setup(m, { emit: e }) {
181
+ const v = m, C = e, _ = $(""), u = $(""), a = $("");
182
+ let E = null;
183
+ function g(o) {
184
+ clearTimeout(E), E = setTimeout(() => {
185
+ a.value = o;
186
+ }, 300);
187
+ }
188
+ function k(o, r) {
189
+ var i, h;
190
+ return ((i = o.finishedProductName) == null ? void 0 : i.toLowerCase().includes(r)) || ((h = o.finishedProductCode) == null ? void 0 : h.toLowerCase().includes(r));
191
+ }
192
+ function Q(o, r) {
193
+ if (!r) return o;
194
+ const i = r.toLowerCase();
195
+ return o.reduce((h, f) => {
196
+ if (f.cateName) {
197
+ const w = Q(f.children || [], r), d = (f.productList || []).filter(
198
+ (T) => k(T, i)
199
+ );
200
+ (w.length || d.length) && h.push({
201
+ ...f,
202
+ children: w,
203
+ productList: d
204
+ });
205
+ } else
206
+ k(f, i) && h.push(f);
207
+ return h;
208
+ }, []);
209
+ }
210
+ function S(o) {
211
+ return o.reduce((r, i) => (i.cateName && (r.push(i.cateProductCode), r.push(...S(i.children || []))), r), []);
212
+ }
213
+ const s = q(() => Q(v.data, a.value)), x = q(
214
+ () => a.value ? S(s.value) : []
215
+ ), M = (...o) => {
216
+ C("select", o);
217
+ }, O = (o) => {
218
+ _.value = o;
219
+ };
220
+ return (o, r) => {
221
+ const i = R, h = G, f = H, w = U;
222
+ return t(), c("div", de, [
223
+ p("div", pe, [
224
+ l(i, {
225
+ modelValue: u.value,
226
+ "onUpdate:modelValue": r[0] || (r[0] = (d) => u.value = d),
227
+ placeholder: "搜索货品名称 / 编号",
228
+ clearable: "",
229
+ "prefix-icon": I(W),
230
+ size: "small",
231
+ onInput: g,
232
+ onClear: r[1] || (r[1] = (d) => g(""))
233
+ }, null, 8, ["modelValue", "prefix-icon"])
234
+ ]),
235
+ K(o.$slots, "header", {}, void 0, !0),
236
+ l(w, {
237
+ class: "qy-select-product__body",
238
+ "wrap-class": "scrollbar-wrapper"
239
+ }, {
240
+ default: n(() => [
241
+ s.value.length ? (t(), y(h, {
242
+ key: 0,
243
+ "background-color": "#f7f8fa",
244
+ class: "qy-select-product__menu",
245
+ onSelect: M,
246
+ onOpen: O,
247
+ "unique-opened": !a.value,
248
+ "default-openeds": x.value,
249
+ style: {
250
+ "--el-menu-item-height": "44px",
251
+ "--el-menu-sub-item-height": "44px"
252
+ }
253
+ }, {
254
+ default: n(() => [
255
+ (t(!0), c(b, null, L(s.value, (d) => (t(), y(ae, {
256
+ key: d.cateProductCode || d.finishedProductCode,
257
+ item: d,
258
+ openCode: _.value,
259
+ searchQuery: a.value
260
+ }, null, 8, ["item", "openCode", "searchQuery"]))), 128))
261
+ ]),
262
+ _: 1
263
+ }, 8, ["unique-opened", "default-openeds"])) : (t(), c("div", me, [
264
+ l(f, {
265
+ description: "暂无匹配货品",
266
+ "image-size": 60
267
+ })
268
+ ]))
269
+ ]),
270
+ _: 1
271
+ })
272
+ ]);
273
+ };
274
+ }
275
+ }, z = /* @__PURE__ */ V(_e, [["__scopeId", "data-v-33a92b09"]]);
276
+ z.install = (m) => {
277
+ m.component("QySelectProduct", z);
278
+ };
279
+ export {
280
+ z as SelectProduct,
281
+ z as default
282
+ };
@@ -0,0 +1,2 @@
1
+ (function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".cate-title[data-v-4cd996d7]{font-size:13px;font-weight:600}.product-item[data-v-4cd996d7]{height:auto!important;min-height:44px}.product-item__inner[data-v-4cd996d7]{display:flex;align-items:center;gap:10px;width:100%;padding:4px 0}.product-item__thumb[data-v-4cd996d7]{width:44px;height:44px;border-radius:4px;border:1px solid #eee;flex-shrink:0;overflow:hidden;cursor:pointer}.product-item__thumb--placeholder[data-v-4cd996d7]{display:flex;align-items:center;justify-content:center;background:#f5f5f5;color:#c0c4cc}.product-item__thumb-error[data-v-4cd996d7]{width:100%;height:100%;display:flex;align-items:center;justify-content:center;background:#f5f7fa;color:#c0c4cc}.product-item__name[data-v-4cd996d7]{flex:1;min-width:0;display:flex;flex-direction:column;gap:2px;font-size:13px;color:#303133;line-height:1.4;word-break:break-all}.product-item__code[data-v-4cd996d7]{font-size:11px;color:#909399}.preview-error[data-v-4cd996d7]{display:flex;flex-direction:column;align-items:center;justify-content:center;height:120px;color:#c0c4cc;gap:6px;font-size:12px}mark.highlight[data-v-4cd996d7]{background:#fef08a;color:inherit;padding:0;border-radius:2px}[data-v-4cd996d7] .el-menu-item *{vertical-align:middle}.qy-select-product[data-v-33a92b09]{display:flex;flex-direction:column;height:100%;background:#fff;border:1px solid #e4e7ed;border-radius:6px;overflow:hidden}.qy-select-product__search[data-v-33a92b09]{padding:10px 12px 8px;border-bottom:1px solid #f0f0f0;background:#fff}.qy-select-product__body[data-v-33a92b09]{flex:1;min-height:0}.qy-select-product__menu[data-v-33a92b09]{border-right:none!important}.qy-select-product__empty[data-v-33a92b09]{display:flex;align-items:center;justify-content:center;height:200px}[data-v-33a92b09] .el-menu{border-right:none}[data-v-33a92b09] .el-sub-menu__title{font-weight:600;font-size:13px;color:#303133}[data-v-33a92b09] .el-sub-menu__title:hover,[data-v-33a92b09] .el-menu-item:hover,[data-v-33a92b09] .el-menu-item.is-active{background-color:#ecf5ff!important}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
2
+ (function(r,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("element-plus/es"),require("element-plus/es/components/base/style/css"),require("element-plus/es/components/scrollbar/style/css"),require("element-plus/es/components/empty/style/css"),require("element-plus/es/components/menu/style/css"),require("element-plus/es/components/input/style/css"),require("vue"),require("@element-plus/icons-vue"),require("element-plus/es/components/menu-item/style/css"),require("element-plus/es/components/popover/style/css"),require("element-plus/es/components/image/style/css"),require("element-plus/es/components/icon/style/css"),require("element-plus/es/components/sub-menu/style/css")):typeof define=="function"&&define.amd?define(["exports","element-plus/es","element-plus/es/components/base/style/css","element-plus/es/components/scrollbar/style/css","element-plus/es/components/empty/style/css","element-plus/es/components/menu/style/css","element-plus/es/components/input/style/css","vue","@element-plus/icons-vue","element-plus/es/components/menu-item/style/css","element-plus/es/components/popover/style/css","element-plus/es/components/image/style/css","element-plus/es/components/icon/style/css","element-plus/es/components/sub-menu/style/css"],s):(r=typeof globalThis<"u"?globalThis:r||self,s(r.QySelectProduct={},r.es,null,null,null,null,null,r.Vue,r.ElementPlusIconsVue))})(this,function(r,s,H,J,K,W,X,e,g){"use strict";const b=(p,t)=>{const h=p.__vccOpts||p;for(const[f,d]of t)h[f]=d;return h},w={class:"cate-title"},V={class:"product-item__inner"},S={class:"product-item__thumb-error"},q={class:"preview-error"},I={class:"product-item__thumb-error"},$={key:1,class:"product-item__thumb product-item__thumb--placeholder"},Q={class:"product-item__name"},L={key:0},T={key:0,class:"highlight"},D={key:1},F={key:1},M={class:"product-item__code"},z=b({__name:"menuItem",props:{item:{type:Object,default:null},index:{type:Number,default:0},openCode:{type:String,default:""},searchQuery:{type:String,default:""}},setup(p){const t=p,h=e.ref(!1),f=e.computed(()=>{const d=t.item.finishedProductName||"",i=t.searchQuery;if(!i)return[d];const a=new RegExp(`(${i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi");return d.split(a)});return(d,i)=>{const a=e.resolveComponent("menu-item",!0),E=s.ElSubMenu,y=s.ElIcon,k=s.ElImage,x=s.ElPopover,N=s.ElMenuItem;return t.item.cateName?(e.openBlock(),e.createBlock(E,{key:0,index:t.item.cateProductCode},{title:e.withCtx(()=>[e.createElementVNode("span",w,e.toDisplayString(t.item.cateName),1)]),default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.item.children||[],l=>(e.openBlock(),e.createBlock(a,{key:l.cateProductCode,item:l,openCode:t.openCode,searchQuery:t.searchQuery},null,8,["item","openCode","searchQuery"]))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.item.productList||[],(l,B)=>(e.openBlock(),e.createBlock(a,{key:l.finishedProductCode,item:l,openCode:t.openCode,searchQuery:t.searchQuery,index:B},null,8,["item","openCode","searchQuery","index"]))),128))]),_:1},8,["index"])):(e.openBlock(),e.createBlock(N,{key:1,index:t.item.finishedProductCode,class:"product-item"},{title:e.withCtx(()=>[e.createElementVNode("div",V,[t.item.displayImage?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[h.value?(e.openBlock(),e.createBlock(x,{key:0,placement:"right",width:320,trigger:"hover",teleported:!0},{reference:e.withCtx(()=>[e.createVNode(k,{class:"product-item__thumb",src:t.item.displayImage,fit:"cover",lazy:""},{error:e.withCtx(()=>[e.createElementVNode("div",S,[e.createVNode(y,null,{default:e.withCtx(()=>[e.createVNode(e.unref(g.Picture))]),_:1})])]),_:1},8,["src"])]),default:e.withCtx(()=>[e.createVNode(k,{src:t.item.displayImage,class:"w-full",style:{"max-height":"200px"},fit:"contain"},{error:e.withCtx(()=>[e.createElementVNode("div",q,[e.createVNode(y,{size:"24"},{default:e.withCtx(()=>[e.createVNode(e.unref(g.Picture))]),_:1}),i[1]||(i[1]=e.createElementVNode("span",null,"加载失败",-1))])]),_:1},8,["src"])]),_:1})):(e.openBlock(),e.createBlock(k,{key:1,class:"product-item__thumb",src:t.item.displayImage,fit:"cover",lazy:"",onMouseenter:i[0]||(i[0]=l=>h.value=!0)},{error:e.withCtx(()=>[e.createElementVNode("div",I,[e.createVNode(y,null,{default:e.withCtx(()=>[e.createVNode(e.unref(g.Picture))]),_:1})])]),_:1},8,["src"]))],64)):(e.openBlock(),e.createElementBlock("div",$,[e.createVNode(y,null,{default:e.withCtx(()=>[e.createVNode(e.unref(g.Picture))]),_:1})])),e.createElementVNode("div",Q,[t.searchQuery&&f.value.length>1?(e.openBlock(),e.createElementBlock("span",L,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.value,(l,B)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:B},[B%2===1?(e.openBlock(),e.createElementBlock("mark",T,e.toDisplayString(l),1)):(e.openBlock(),e.createElementBlock("span",D,e.toDisplayString(l),1))],64))),128))])):(e.openBlock(),e.createElementBlock("span",F,e.toDisplayString(t.item.finishedProductName),1)),e.createElementVNode("span",M,e.toDisplayString(t.item.finishedProductCode),1)])])]),_:1},8,["index"]))}}},[["__scopeId","data-v-4cd996d7"]]),O={class:"qy-select-product"},j={class:"qy-select-product__search"},A={key:1,class:"qy-select-product__empty"},C=b({__name:"index",props:{data:{type:Array,default:()=>[]}},emits:["select"],setup(p,{emit:t}){const h=p,f=t,d=e.ref(""),i=e.ref(""),a=e.ref("");let E=null;function y(n){clearTimeout(E),E=setTimeout(()=>{a.value=n},300)}function k(n,o){var c,u;return((c=n.finishedProductName)==null?void 0:c.toLowerCase().includes(o))||((u=n.finishedProductCode)==null?void 0:u.toLowerCase().includes(o))}function x(n,o){if(!o)return n;const c=o.toLowerCase();return n.reduce((u,_)=>{if(_.cateName){const P=x(_.children||[],o),m=(_.productList||[]).filter(G=>k(G,c));(P.length||m.length)&&u.push({..._,children:P,productList:m})}else k(_,c)&&u.push(_);return u},[])}function N(n){return n.reduce((o,c)=>(c.cateName&&(o.push(c.cateProductCode),o.push(...N(c.children||[]))),o),[])}const l=e.computed(()=>x(h.data,a.value)),B=e.computed(()=>a.value?N(l.value):[]),R=(...n)=>{f("select",n)},U=n=>{d.value=n};return(n,o)=>{const c=s.ElInput,u=s.ElMenu,_=s.ElEmpty,P=s.ElScrollbar;return e.openBlock(),e.createElementBlock("div",O,[e.createElementVNode("div",j,[e.createVNode(c,{modelValue:i.value,"onUpdate:modelValue":o[0]||(o[0]=m=>i.value=m),placeholder:"搜索货品名称 / 编号",clearable:"","prefix-icon":e.unref(g.Search),size:"small",onInput:y,onClear:o[1]||(o[1]=m=>y(""))},null,8,["modelValue","prefix-icon"])]),e.renderSlot(n.$slots,"header",{},void 0,!0),e.createVNode(P,{class:"qy-select-product__body","wrap-class":"scrollbar-wrapper"},{default:e.withCtx(()=>[l.value.length?(e.openBlock(),e.createBlock(u,{key:0,"background-color":"#f7f8fa",class:"qy-select-product__menu",onSelect:R,onOpen:U,"unique-opened":!a.value,"default-openeds":B.value,style:{"--el-menu-item-height":"44px","--el-menu-sub-item-height":"44px"}},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.value,m=>(e.openBlock(),e.createBlock(z,{key:m.cateProductCode||m.finishedProductCode,item:m,openCode:d.value,searchQuery:a.value},null,8,["item","openCode","searchQuery"]))),128))]),_:1},8,["unique-opened","default-openeds"])):(e.openBlock(),e.createElementBlock("div",A,[e.createVNode(_,{description:"暂无匹配货品","image-size":60})]))]),_:1})])}}},[["__scopeId","data-v-33a92b09"]]);C.install=p=>{p.component("QySelectProduct",C)},r.SelectProduct=C,r.default=C,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
package/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import SelectProduct from './lib/selectProduct/index.vue'
2
+
3
+ SelectProduct.install = (app) => {
4
+ app.component('QySelectProduct', SelectProduct)
5
+ }
6
+
7
+ export { SelectProduct }
8
+ export { SelectProduct as default }
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@qiyin/select-product",
3
+ "version": "1.0.0",
4
+ "description": "起印货品选择组件",
5
+ "author": "qy",
6
+ "license": "MIT",
7
+ "main": "./dist/select-product.umd.js",
8
+ "module": "./dist/select-product.es.js",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/select-product.es.js",
12
+ "require": "./dist/select-product.umd.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "dist"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "scripts": {
23
+ "dev": "vite",
24
+ "build": "vite build",
25
+ "preview": "vite preview",
26
+ "release": "npm run build && npm publish --registry=https://registry.npmjs.org"
27
+ },
28
+ "peerDependencies": {
29
+ "vue": "^3.4.21",
30
+ "element-plus": "^2.0.0",
31
+ "@element-plus/icons-vue": "^2.0.0"
32
+ },
33
+ "devDependencies": {
34
+ "@vitejs/plugin-vue": "^5.0.0",
35
+ "@vitejs/plugin-vue-jsx": "^3.1.0",
36
+ "unplugin-vue-components": "^0.26.0",
37
+ "vite": "^5.0.0",
38
+ "vite-plugin-css-injected-by-js": "^3.5.2"
39
+ }
40
+ }