@me-framework/me-sku-editor 1.0.1

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.
@@ -0,0 +1,292 @@
1
+ # 快速开始指南
2
+
3
+ 本指南将帮助你在 5 分钟内快速上手 SkuEditor 组件。
4
+
5
+ ## 目录
6
+
7
+ - [环境准备](#环境准备)
8
+ - [运行项目](#运行项目)
9
+ - [最小化示例](#最小化示例)
10
+ - [核心概念](#核心概念)
11
+ - [下一步](#下一步)
12
+
13
+ ---
14
+
15
+ ## 环境准备
16
+
17
+ ### 必需条件
18
+
19
+ - Node.js 16+
20
+ - npm 或 pnpm
21
+
22
+ ### 安装依赖
23
+
24
+ ```bash
25
+ # 使用 npm
26
+ npm install
27
+
28
+ # 或使用 pnpm(推荐)
29
+ pnpm install
30
+ ```
31
+
32
+ ---
33
+
34
+ ## 运行项目
35
+
36
+ ### 启动开发服务器
37
+
38
+ ```bash
39
+ npm run dev
40
+ ```
41
+
42
+ 项目将在 `http://localhost:5173` 启动。
43
+
44
+ ### 构建生产版本
45
+
46
+ ```bash
47
+ npm run build
48
+ ```
49
+
50
+ 构建产物将输出到 `dist` 目录。
51
+
52
+ ---
53
+
54
+ ## 最小化示例
55
+
56
+ ### 示例 1:最简单的用法
57
+
58
+ ```vue
59
+ <!-- App.vue -->
60
+ <script setup lang="ts">
61
+ import SkuEditor from './components/sku/SkuEditor.vue'
62
+ </script>
63
+
64
+ <template>
65
+ <div class="app-container" style="padding: 20px;">
66
+ <h1>商品规格编辑器</h1>
67
+ <SkuEditor />
68
+ </div>
69
+ </template>
70
+ ```
71
+
72
+ 这个示例使用组件的内部数据管理模式,无需任何配置即可使用。
73
+
74
+ ### 示例 2:带初始数据的用法
75
+
76
+ ```vue
77
+ <!-- App.vue -->
78
+ <script setup lang="ts">
79
+ import { ref } from 'vue'
80
+ import SkuEditor from './components/sku/SkuEditor.vue'
81
+ import type { Spec, SkuRow } from './types/sku'
82
+ import { generateSkuData } from './composables/sku/useSkuGenerator'
83
+
84
+ // 准备初始规格数据
85
+ const specs = ref<Spec[]>([
86
+ {
87
+ id: 'spec-1',
88
+ name: '颜色',
89
+ type: 'color',
90
+ sort: 0,
91
+ attributes: [
92
+ { id: 'attr-1-1', name: '红色', color: '#ff0000', image: '', sort: 0, content: '' },
93
+ { id: 'attr-1-2', name: '蓝色', color: '#0000ff', image: '', sort: 1, content: '' },
94
+ { id: 'attr-1-3', name: '绿色', color: '#00ff00', image: '', sort: 2, content: '' }
95
+ ]
96
+ },
97
+ {
98
+ id: 'spec-2',
99
+ name: '尺码',
100
+ type: 'text',
101
+ sort: 1,
102
+ attributes: [
103
+ { id: 'attr-2-1', name: 'S', color: '', image: '', sort: 0, content: '' },
104
+ { id: 'attr-2-2', name: 'M', color: '', image: '', sort: 1, content: '' },
105
+ { id: 'attr-2-3', name: 'L', color: '', image: '', sort: 2, content: '' },
106
+ { id: 'attr-2-4', name: 'XL', color: '', image: '', sort: 3, content: '' }
107
+ ]
108
+ }
109
+ ])
110
+
111
+ // 生成 SKU 数据
112
+ const skuData = ref<SkuRow[]>(generateSkuData(specs.value))
113
+ </script>
114
+
115
+ <template>
116
+ <div class="app-container" style="padding: 20px;">
117
+ <h1>商品规格编辑器</h1>
118
+ <div style="margin-bottom: 16px;">
119
+ <span style="margin-right: 24px;">规格数:{{ specs.length }}</span>
120
+ <span>SKU数:{{ skuData.length }}</span>
121
+ </div>
122
+ <SkuEditor
123
+ v-model:specs="specs"
124
+ v-model:sku-data="skuData"
125
+ />
126
+ </div>
127
+ </template>
128
+ ```
129
+
130
+ ### 示例 3:使用外部格式数据(推荐)
131
+
132
+ 使用 `spec_json` 格式的数据,这是推荐的存储和交互格式:
133
+
134
+ ```vue
135
+ <script setup lang="ts">
136
+ import { ref } from 'vue'
137
+ import SkuEditor from './components/sku/SkuEditor.vue'
138
+ import type { Spec, SkuRow } from './types/sku'
139
+ import { generateSkuData, toInternalFormat } from './composables/sku/useSkuGenerator'
140
+
141
+ // 规格数据
142
+ const specs = ref<Spec[]>([
143
+ {
144
+ id: 'spec-1',
145
+ name: '颜色',
146
+ type: 'color',
147
+ sort: 0,
148
+ attributes: [
149
+ { id: 'attr-1-1', name: '白色', color: '#ffffff', image: '', sort: 0, content: '' },
150
+ { id: 'attr-1-2', name: '黑色', color: '#000000', image: '', sort: 1, content: '' }
151
+ ]
152
+ },
153
+ {
154
+ id: 'spec-2',
155
+ name: '尺寸',
156
+ type: 'text',
157
+ sort: 1,
158
+ attributes: [
159
+ { id: 'attr-2-1', name: '小', color: '', image: '', sort: 0, content: '' },
160
+ { id: 'attr-2-2', name: '中', color: '', image: '', sort: 1, content: '' },
161
+ { id: 'attr-2-3', name: '大', color: '', image: '', sort: 2, content: '' }
162
+ ]
163
+ }
164
+ ])
165
+
166
+ // 你的业务数据(使用规格名称和属性名称)
167
+ const myData: SkuRow[] = [
168
+ {
169
+ spec_json: { '颜色': '白色', '尺寸': '小' },
170
+ skuNo: 'PROD-WHITE-S',
171
+ skuName: '产品-白色-小',
172
+ salePrice: 99,
173
+ marketPrice: 199,
174
+ status: 1
175
+ },
176
+ {
177
+ spec_json: { '颜色': '白色', '尺寸': '中' },
178
+ skuNo: 'PROD-WHITE-M',
179
+ skuName: '产品-白色-中',
180
+ salePrice: 109,
181
+ marketPrice: 199,
182
+ status: 1
183
+ }
184
+ ]
185
+
186
+ // 转换并生成完整数据
187
+ const existingData = toInternalFormat(myData, specs.value)
188
+ const skuData = ref<SkuRow[]>(generateSkuData(specs.value, existingData))
189
+ </script>
190
+
191
+ <template>
192
+ <SkuEditor
193
+ v-model:specs="specs"
194
+ v-model:sku-data="skuData"
195
+ />
196
+ </template>
197
+ ```
198
+
199
+ ---
200
+
201
+ ## 核心概念
202
+
203
+ ### 两种使用模式
204
+
205
+ #### 1. 内部管理模式
206
+
207
+ 组件内部管理数据,适合简单场景:
208
+
209
+ ```vue
210
+ <SkuEditor />
211
+ ```
212
+
213
+ #### 2. 外部控制模式
214
+
215
+ 父组件控制数据,适合需要自定义处理的场景:
216
+
217
+ ```vue
218
+ <SkuEditor
219
+ v-model:specs="specs"
220
+ v-model:sku-data="skuData"
221
+ />
222
+ ```
223
+
224
+ ### 数据结构关系
225
+
226
+ ```
227
+ Spec(规格)
228
+ ├── id
229
+ ├── name(如"颜色")
230
+ ├── type('text' | 'color' | 'image')
231
+ └── attributes[]
232
+ ├── SpecAttribute(属性)
233
+ │ ├── id
234
+ │ ├── name(如"红色")
235
+ │ ├── color
236
+ │ ├── image
237
+ │ └── ...
238
+ └── ...
239
+
240
+ SkuRow(SKU)
241
+ ├── id
242
+ ├── specs: { specId: attrId }(内部格式)
243
+ ├── spec_json: { specName: attrName }(外部格式,推荐)
244
+ ├── skuNo
245
+ ├── skuName
246
+ ├── salePrice
247
+ └── ...
248
+ ```
249
+
250
+ ### 规格类型
251
+
252
+ | 类型 | 说明 | 示例 |
253
+ |------|------|------|
254
+ | `text` | 文字规格 | 尺码:S、M、L |
255
+ | `color` | 颜色规格 | 颜色:红、蓝、绿 |
256
+ | `image` | 图片规格 | 款式:图片1、图片2 |
257
+
258
+ ### 两种数据格式
259
+
260
+ | 格式 | 字段名 | 说明 | 使用场景 |
261
+ |------|--------|------|----------|
262
+ | 外部格式 | `spec_json` | `{ '颜色': '红色', '尺码': 'S' }` | 存储、后端交互、用户界面 |
263
+ | 内部格式 | `specs` | `{ 'spec-1': 'attr-1-1', 'spec-2': 'attr-2-1' }` | 组件内部计算、快速查找 |
264
+
265
+ **推荐做法**:始终使用 `spec_json` 格式与组件交互,组件会自动处理转换。
266
+
267
+ ---
268
+
269
+ ## 下一步
270
+
271
+ 现在你已经了解了基本用法,可以:
272
+
273
+ 1. 查看完整的 [使用文档](./使用文档.md) 了解所有功能
274
+ 2. 了解 [开发指南](./开发指南.md) 进行二次开发
275
+ 3. 运行项目中的示例 `src/App.vue` 进行实践
276
+ 4. 尝试导出导入 Excel 文件体验数据交换功能
277
+ 5. 体验新增的数据校验功能
278
+
279
+ ---
280
+
281
+ ## 获取帮助
282
+
283
+ 如果在使用过程中遇到问题:
284
+
285
+ 1. 查看 [常见问题](./使用文档.md#常见问题) 章节
286
+ 2. 检查项目的 `README.md`
287
+ 3. 查看组件源码中的注释和类型定义
288
+ 4. 查看 `src/types/sku/` 目录下的类型定义
289
+
290
+ ---
291
+
292
+ 祝你使用愉快!
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@me-framework/me-sku-editor",
3
+ "version": "1.0.1",
4
+ "description": "A powerful Vue 3 SKU editor component",
5
+ "type": "module",
6
+ "main": "./dist/lib/me-sku-editor.umd.js",
7
+ "module": "./dist/lib/me-sku-editor.mjs",
8
+ "types": "./dist/lib/types/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/lib/me-sku-editor.mjs",
12
+ "require": "./dist/lib/me-sku-editor.umd.js",
13
+ "types": "./dist/lib/types/index.d.ts"
14
+ },
15
+ "./style.css": "./dist/lib/me-sku-editor.css"
16
+ },
17
+ "files": [
18
+ "dist/lib",
19
+ "dist/demo",
20
+ "document",
21
+ "README.md",
22
+ "LICENSE",
23
+ "package.json"
24
+ ],
25
+ "keywords": [
26
+ "vue",
27
+ "vue3",
28
+ "sku",
29
+ "editor",
30
+ "component",
31
+ "商品规格",
32
+ "sku-editor"
33
+ ],
34
+ "author": "",
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "https://github.com/your-username/me-sku-editor.git"
39
+ },
40
+ "homepage": "https://github.com/your-username/me-sku-editor",
41
+ "bugs": {
42
+ "url": "https://github.com/your-username/me-sku-editor/issues"
43
+ },
44
+ "scripts": {
45
+ "dev": "vite",
46
+ "build": "npm run build:lib && npm run build:demo",
47
+ "build:lib": "vue-tsc -b && vite build --config vite.config.lib.ts",
48
+ "build:demo": "vite build",
49
+ "preview": "vite preview",
50
+ "prepublishOnly": "npm run build",
51
+ "pub": "npx auto-version && npm publish --access public"
52
+ },
53
+ "peerDependencies": {
54
+ "@element-plus/icons-vue": "^2.3.0",
55
+ "element-plus": "^2.14.0",
56
+ "vue": "^3.4.0",
57
+ "vxe-pc-ui": "^4.15.0",
58
+ "vxe-table": "^4.19.0"
59
+ },
60
+ "dependencies": {
61
+ "sortablejs": "^1.15.7",
62
+ "xlsx": "^0.18.5"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^24.13.2",
66
+ "@types/sortablejs": "^1.15.9",
67
+ "@vitejs/plugin-vue": "^6.0.7",
68
+ "@vue/tsconfig": "^0.9.1",
69
+ "auto-version-js": "^1.0.0",
70
+ "page-agent": "^1.11.0",
71
+ "typescript": "~6.0.2",
72
+ "vite": "^8.1.0",
73
+ "vite-plugin-dts": "^5.0.3",
74
+ "vue-tsc": "^3.3.5"
75
+ }
76
+ }