@lemon30_npm/csit-vue3 0.0.19 → 0.0.20
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
CHANGED
|
@@ -18,7 +18,7 @@ pnpm add csit-vue3
|
|
|
18
18
|
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
⚠️ 注意:该组件库依赖以下环境,请确保你的项目已安装(如果你使用Vue 3项目脚手架,请忽略)
|
|
22
22
|
|
|
23
23
|
> 版本可自行升级,无影响
|
|
24
24
|
|
|
@@ -121,8 +121,6 @@ import CiBlueLineTitle from 'csit-vue3/ci-blue-line-title'
|
|
|
121
121
|
</style>
|
|
122
122
|
```
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
124
|
#### 按需导入规则和建议
|
|
127
125
|
|
|
128
126
|
相信细心的小伙伴们会有疑问了❓ 按需导入时 import xxx from 'csit-vue3/yyy'; 后面的yyy是什么值呢❓
|
|
@@ -165,6 +163,144 @@ import "csit-vue3/dist/index.css";
|
|
|
165
163
|
| snake_case | ci_blue_line_title | Python变量、文件名、数据库字段 |
|
|
166
164
|
| kebab-case | ci-blue-line-title | 文件/文件夹、HTML/CSS 类名、自定义组件名 |
|
|
167
165
|
|
|
166
|
+
### "优雅的"按需导入(自动导入)【!!!推荐】
|
|
167
|
+
|
|
168
|
+
> 为你使用的 csit-vue3 组件库提供一个 unplugin-vue-components 的 Resolver,就像 ElementPlusResolver 一样,支持按名称自动引入组件。
|
|
169
|
+
|
|
170
|
+
#### 背景介绍
|
|
171
|
+
|
|
172
|
+
`Element Plus`按需导入之自动导入写法(点击查看[官方文档🔗](https://element-plus.org/zh-CN/guide/quickstart.html#%E6%8C%89%E9%9C%80%E5%AF%BC%E5%85%A5))
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// 官网中有这么一句, 但是我们项目中不能 从 unplugin-vue-components 插件中导出 csit-vue3 的解析器
|
|
176
|
+
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
##### 为什么ElementPlusResolver能直接用?
|
|
180
|
+
|
|
181
|
+
因为:
|
|
182
|
+
|
|
183
|
+
- `unplugin-vue-components` 官方内置了 **对主流 UI 框架(如 `Element Plus`、`Ant Design Vue`、`Vuetify`)的解析器**
|
|
184
|
+
- 这些内置的 resolver 都在 `unplugin-vue-components/resolvers` 中暴露了出来
|
|
185
|
+
- `Element Plus` 官方团队也专门配合封装了 ElementPlusResolver
|
|
186
|
+
|
|
187
|
+
🔗 官方文档:<https://github.com/antfu/unplugin-vue-components#resolvers>
|
|
188
|
+
|
|
189
|
+
##### 如何让你自己使用的 csit-vue3 组件库也能像ElementPlusResolver那样?
|
|
190
|
+
|
|
191
|
+
- 很简单,你只需要自己手动写一个 Resolver
|
|
192
|
+
|
|
193
|
+
#### 实战代码示例
|
|
194
|
+
|
|
195
|
+
完成如下步骤即可:
|
|
196
|
+
|
|
197
|
+
1. 你需要使用额外的插件来导入要使用的组件,你需要安装`unplugin-vue-components` 这款插件。
|
|
198
|
+
2. 你需要手写一个 Resolver。
|
|
199
|
+
3. 把`unplugin-vue-components`插件配置到 `Vite` 的配置文件中
|
|
200
|
+
|
|
201
|
+
##### 1. 安装插件
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
npm install -D unplugin-vue-components
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
##### 2. 在你的项目中手写 Resolver
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
/**
|
|
211
|
+
* 自定义组件库解析器:CsitComponentResolver
|
|
212
|
+
* 用于配合 unplugin-vue-components 实现按名称自动导入
|
|
213
|
+
* 比如:使用 <CiUpload /> 会自动解析为 csit-vue3/ci-upload
|
|
214
|
+
*/
|
|
215
|
+
export function CsitComponentResolver() {
|
|
216
|
+
return {
|
|
217
|
+
type: 'component',
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* name 是你在模板中写的组件名,比如 <CiUpload />,这里接收到的是 "CiUpload"
|
|
221
|
+
*/
|
|
222
|
+
resolve(name: string) {
|
|
223
|
+
// 判断组件名是否符合 ci- 开头的组件,比如:CiUpload -> ci-upload
|
|
224
|
+
if (!/^Ci[A-Z]/.test(name)) return
|
|
225
|
+
|
|
226
|
+
// 将 PascalCase 转为 kebab-case(CiUpload → ci-upload)
|
|
227
|
+
const kebabName = name
|
|
228
|
+
.replace(/^Ci/, 'ci-') // 去掉首字母 Ci
|
|
229
|
+
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') // 大写转短横线
|
|
230
|
+
.toLowerCase()
|
|
231
|
+
|
|
232
|
+
// 返回路径:配合 exports 字段实现自动导入
|
|
233
|
+
return {
|
|
234
|
+
name, // 保持原组件名
|
|
235
|
+
from: `csit-vue3/${kebabName}`, // 自动解析导入路径
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
##### 3. 把`unplugin-vue-components`插件配置到 `Vite` 的配置文件中
|
|
243
|
+
|
|
244
|
+
```ts
|
|
245
|
+
import { defineConfig } from 'vite'
|
|
246
|
+
import Components from 'unplugin-vue-components/vite'
|
|
247
|
+
import { CsitComponentResolver } from './path/to/your-resolver' // 你定义的 Resolver 放在哪里了就从哪里导入
|
|
248
|
+
|
|
249
|
+
export default defineConfig({
|
|
250
|
+
plugins: [
|
|
251
|
+
Components({
|
|
252
|
+
resolvers: [CsitComponentResolver()],
|
|
253
|
+
}),
|
|
254
|
+
],
|
|
255
|
+
})
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
⚠️ 注意:样式文件我们就不支持按需导入了,我们建议:在 main.ts 中全量引入所有组件样式
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
// 样式不建议按需导入, 建议 main.ts 中直接全量导入, 清晰且不易出现问题
|
|
262
|
+
|
|
263
|
+
// main.ts
|
|
264
|
+
import "csit-vue3/dist/index.css";
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
至此结束,你应该在某个页面写下:
|
|
268
|
+
|
|
269
|
+
```vue
|
|
270
|
+
<template>
|
|
271
|
+
<CiUpload />
|
|
272
|
+
<CiBlueLineTitle />
|
|
273
|
+
</template>
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
> ❗注意:
|
|
277
|
+
>
|
|
278
|
+
> 不要在当前vue页面手动 import,不要在当前vue页面手动注册。
|
|
279
|
+
>
|
|
280
|
+
> 不要在main.ts中全量注册组件,按需注册组件。
|
|
281
|
+
>
|
|
282
|
+
> 运行后应该不报错且能渲染。至此 验证结束 大功告成✅。
|
|
283
|
+
|
|
284
|
+
**当然,我们会把解析器内置到 `csit-vue3`中,开发者无需关心解析器实现,因为解析器实现要遵循一定的组件库设计规则,开发者只需从 `csit-vue3`中导出使用即可。**
|
|
285
|
+
|
|
286
|
+
如果使用`csit-vue3`内置解析器,实战第二步不需要你做,第三步参考如下。
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { defineConfig } from 'vite'
|
|
290
|
+
import Components from 'unplugin-vue-components/vite'
|
|
291
|
+
|
|
292
|
+
// 导出 csit-vue3 解析器
|
|
293
|
+
import { CsitComponentResolver } from 'csit-vue3/resolvers'
|
|
294
|
+
|
|
295
|
+
export default defineConfig({
|
|
296
|
+
plugins: [
|
|
297
|
+
Components({
|
|
298
|
+
resolvers: [CsitComponentResolver()],
|
|
299
|
+
}),
|
|
300
|
+
],
|
|
301
|
+
})
|
|
302
|
+
```
|
|
303
|
+
|
|
168
304
|
## 🧩 示例组件使用
|
|
169
305
|
|
|
170
306
|
```html
|
package/dist/csit-vue3.js
CHANGED
|
@@ -2863,6 +2863,24 @@ const f0 = {
|
|
|
2863
2863
|
h1.install = (e) => {
|
|
2864
2864
|
e.component(h1.name, h1);
|
|
2865
2865
|
};
|
|
2866
|
+
function z0() {
|
|
2867
|
+
return {
|
|
2868
|
+
type: "component",
|
|
2869
|
+
/**
|
|
2870
|
+
* name 是你在模板中写的组件名,比如 <CiUpload />,这里接收到的是 "CiUpload"
|
|
2871
|
+
*/
|
|
2872
|
+
resolve(e) {
|
|
2873
|
+
if (!/^Ci[A-Z]/.test(e)) return;
|
|
2874
|
+
const t = e.replace(/^Ci/, "ci-").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
2875
|
+
return {
|
|
2876
|
+
name: e,
|
|
2877
|
+
// 保持原组件名
|
|
2878
|
+
from: `@lemon30_npm/csit-vue3/${t}`
|
|
2879
|
+
// 自动解析导入路径
|
|
2880
|
+
};
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2866
2884
|
const I0 = [
|
|
2867
2885
|
// 蓝色竖线、标题组件
|
|
2868
2886
|
s1,
|
|
@@ -2898,7 +2916,7 @@ const I0 = [
|
|
|
2898
2916
|
I0.forEach((t) => {
|
|
2899
2917
|
e.component(t.name, t);
|
|
2900
2918
|
});
|
|
2901
|
-
},
|
|
2919
|
+
}, q0 = { install: D0 };
|
|
2902
2920
|
export {
|
|
2903
2921
|
s1 as CiBlueLineTitle,
|
|
2904
2922
|
p1 as CiCommonListLayout,
|
|
@@ -2915,6 +2933,7 @@ export {
|
|
|
2915
2933
|
i1 as CiSvgIcon,
|
|
2916
2934
|
n1 as CiTimelineList,
|
|
2917
2935
|
h1 as CiUpload,
|
|
2918
|
-
z0 as
|
|
2936
|
+
z0 as CsitComponentResolver,
|
|
2937
|
+
q0 as default,
|
|
2919
2938
|
D0 as install
|
|
2920
2939
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CiBlueLineTitle as
|
|
1
|
+
import { CiBlueLineTitle as t } from "../ci-blue-line-title/index.js";
|
|
2
2
|
import "../ci-svg-icon/index.js";
|
|
3
3
|
import "../ci-echarts/ci-echart-pie/index.js";
|
|
4
4
|
import "../ci-echarts/ci-echart-bar/index.js";
|
|
@@ -13,15 +13,16 @@ import "../ci-common-list/ci-common-list-pagination/index.js";
|
|
|
13
13
|
import "../ci-common-list/ci-common-list-start-end-datepicker/index.js";
|
|
14
14
|
import "../ci-page-header/index.js";
|
|
15
15
|
import "../ci-upload/index.js";
|
|
16
|
-
import
|
|
16
|
+
import { CsitComponentResolver as Y } from "./resolvers/index.js";
|
|
17
|
+
import m from "../ci-svg-icon/index.vue.js";
|
|
17
18
|
import r from "../ci-echarts/ci-echart-pie/index.vue.js";
|
|
18
19
|
import p from "../ci-echarts/ci-echart-bar/index.vue.js";
|
|
19
20
|
import a from "../ci-echarts/ci-echart-ChinaMap/index.vue.js";
|
|
20
|
-
import
|
|
21
|
-
import
|
|
21
|
+
import e from "../ci-element-plus/ci-el-date-picker-daterange/index.vue.js";
|
|
22
|
+
import n from "../ci-time-line-list/index.vue.js";
|
|
22
23
|
import C from "../ci-no-data-status/index.vue.js";
|
|
23
|
-
import
|
|
24
|
-
import
|
|
24
|
+
import s from "../ci-dictionary-select/index.vue.js";
|
|
25
|
+
import f from "../ci-common-list/ci-common-list-layout/index.vue.js";
|
|
25
26
|
import c from "../ci-common-list/ci-common-list-query/index.vue.js";
|
|
26
27
|
import l from "../ci-common-list/ci-common-list-pagination/index.vue.js";
|
|
27
28
|
import u from "../ci-common-list/ci-common-list-start-end-datepicker/index.vue.js";
|
|
@@ -29,9 +30,9 @@ import L from "../ci-page-header/index.vue.js";
|
|
|
29
30
|
import E from "../ci-upload/index.vue.js";
|
|
30
31
|
const _ = [
|
|
31
32
|
// 蓝色竖线、标题组件
|
|
32
|
-
m,
|
|
33
|
-
// svg图标组件
|
|
34
33
|
t,
|
|
34
|
+
// svg图标组件
|
|
35
|
+
m,
|
|
35
36
|
// echarts 饼图组件
|
|
36
37
|
r,
|
|
37
38
|
// echarts 柱状图组件
|
|
@@ -39,15 +40,15 @@ const _ = [
|
|
|
39
40
|
// echarts 中国地图组件
|
|
40
41
|
a,
|
|
41
42
|
// elementPlus 日期:选择一段时间 组件
|
|
42
|
-
n,
|
|
43
|
-
// 时间线组件
|
|
44
43
|
e,
|
|
44
|
+
// 时间线组件
|
|
45
|
+
n,
|
|
45
46
|
// 没有数据状态时展示效果组件
|
|
46
47
|
C,
|
|
47
48
|
// 字典项组件
|
|
48
|
-
f,
|
|
49
|
-
// 公共列表布局组件
|
|
50
49
|
s,
|
|
50
|
+
// 公共列表布局组件
|
|
51
|
+
f,
|
|
51
52
|
// 公共列表布局组件 - 查询条件
|
|
52
53
|
c,
|
|
53
54
|
// 公共列表布局组件 - 分页
|
|
@@ -64,21 +65,22 @@ const _ = [
|
|
|
64
65
|
});
|
|
65
66
|
}, V = { install: d };
|
|
66
67
|
export {
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
t as CiBlueLineTitle,
|
|
69
|
+
f as CiCommonListLayout,
|
|
69
70
|
l as CiCommonListPagination,
|
|
70
71
|
c as CiCommonListQuery,
|
|
71
72
|
u as CiCommonListStartEndDatePicker,
|
|
72
|
-
|
|
73
|
+
s as CiDictionarySelect,
|
|
73
74
|
p as CiEchartBar,
|
|
74
75
|
a as CiEchartChinaMap,
|
|
75
76
|
r as CiEchartPie,
|
|
76
|
-
|
|
77
|
+
e as CiElDatePickerDaterange,
|
|
77
78
|
C as CiNoDataStatus,
|
|
78
79
|
L as CiPageHeader,
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
m as CiSvgIcon,
|
|
81
|
+
n as CiTimelineList,
|
|
81
82
|
E as CiUpload,
|
|
83
|
+
Y as CsitComponentResolver,
|
|
82
84
|
V as default,
|
|
83
85
|
d as install
|
|
84
86
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
function o() {
|
|
2
|
+
return {
|
|
3
|
+
type: "component",
|
|
4
|
+
/**
|
|
5
|
+
* name 是你在模板中写的组件名,比如 <CiUpload />,这里接收到的是 "CiUpload"
|
|
6
|
+
*/
|
|
7
|
+
resolve(e) {
|
|
8
|
+
if (!/^Ci[A-Z]/.test(e)) return;
|
|
9
|
+
const t = e.replace(/^Ci/, "ci-").replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
10
|
+
return {
|
|
11
|
+
name: e,
|
|
12
|
+
// 保持原组件名
|
|
13
|
+
from: `@lemon30_npm/csit-vue3/${t}`
|
|
14
|
+
// 自动解析导入路径
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
o as CsitComponentResolver
|
|
21
|
+
};
|
|
@@ -16,6 +16,7 @@ import { default as CiPageHeader } from './components-project/ci-page-header/ind
|
|
|
16
16
|
import { default as CiUpload } from './components-project/ci-upload/index';
|
|
17
17
|
declare const install: (app: App) => void;
|
|
18
18
|
export { install, CiBlueLineTitle, CiSvgIcon, CiEchartPie, CiEchartBar, CiEchartChinaMap, CiElDatePickerDaterange, CiTimelineList, CiNoDataStatus, CiDictionarySelect, CiCommonListLayout, CiCommonListQuery, CiCommonListPagination, CiCommonListStartEndDatePicker, CiPageHeader, CiUpload, };
|
|
19
|
+
export * from './resolvers/index';
|
|
19
20
|
declare const _default: {
|
|
20
21
|
install: (app: App) => void;
|
|
21
22
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 自定义组件库解析器:CsitComponentResolver
|
|
3
|
+
* 用于配合 unplugin-vue-components 实现按名称自动导入
|
|
4
|
+
* 比如:使用 <CiUpload /> 会自动解析为 csit-vue3/ci-upload
|
|
5
|
+
*/
|
|
6
|
+
export declare function CsitComponentResolver(): {
|
|
7
|
+
type: string;
|
|
8
|
+
/**
|
|
9
|
+
* name 是你在模板中写的组件名,比如 <CiUpload />,这里接收到的是 "CiUpload"
|
|
10
|
+
*/
|
|
11
|
+
resolve(name: string): {
|
|
12
|
+
name: string;
|
|
13
|
+
from: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon30_npm/csit-vue3",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "cuiwq",
|
|
6
6
|
"license": "MIT",
|
|
@@ -120,6 +120,10 @@
|
|
|
120
120
|
},
|
|
121
121
|
"./ci-upload/style/index.css": {
|
|
122
122
|
"default": "./dist/lib/ci-upload/index.css"
|
|
123
|
+
},
|
|
124
|
+
"./resolvers": {
|
|
125
|
+
"import": "./dist/src/components/resolvers/index.js",
|
|
126
|
+
"types": "./dist/types/src/components/resolvers/index.d.ts"
|
|
123
127
|
}
|
|
124
128
|
},
|
|
125
129
|
"scripts": {
|