zxt-table 0.3.0 → 0.3.2

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 (3) hide show
  1. package/README.md +31 -3
  2. package/package.json +6 -3
  3. package/resolver.js +35 -0
package/README.md CHANGED
@@ -28,7 +28,33 @@ npm install zxt-table
28
28
 
29
29
  ## 使用
30
30
 
31
- ### 全局注册
31
+ ### 方式一:自动按需引入(推荐)
32
+
33
+ 如果您使用了 `unplugin-vue-components` 和 `unplugin-auto-import`,可以使用我们提供的 Resolver 自动引入组件和样式(包括 Element Plus 的样式)。
34
+
35
+ 1. 在 `vite.config.js` 中配置:
36
+
37
+ ```javascript
38
+ import { defineConfig } from 'vite'
39
+ import Components from 'unplugin-vue-components/vite'
40
+ import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
41
+ import { ZxtTableResolver } from 'zxt-table/resolver' // 引入 Resolver
42
+
43
+ export default defineConfig({
44
+ plugins: [
45
+ Components({
46
+ resolvers: [
47
+ // Element Plus 自动引入
48
+ ElementPlusResolver(),
49
+ // ZxtTable 自动引入 (会自动处理 ZxtTable 和 Element Plus 的样式依赖)
50
+ ZxtTableResolver()
51
+ ],
52
+ }),
53
+ ],
54
+ })
55
+ ```
56
+
57
+ ### 方式二:全局注册
32
58
 
33
59
  在您的 `main.js` 文件中引入组件库:
34
60
 
@@ -36,11 +62,13 @@ npm install zxt-table
36
62
  import { createApp } from 'vue'
37
63
  import App from './App.vue'
38
64
  import ElementPlus from 'element-plus'
65
+ // ❗ 重要:如果您没有使用 Resolver,必须手动引入 Element Plus 样式
39
66
  import 'element-plus/dist/index.css'
40
67
 
41
68
  // 引入 zxt-table
42
69
  import ZxtTable from 'zxt-table'
43
- import 'zxt-table/dist/style.css'
70
+ // 引入组件库样式
71
+ import 'zxt-table/style.css'
44
72
 
45
73
  const app = createApp(App)
46
74
  app.use(ElementPlus)
@@ -48,7 +76,7 @@ app.use(ZxtTable)
48
76
  app.mount('#app')
49
77
  ```
50
78
 
51
- ### 按需引入
79
+ ### 方式三:手动按需引入
52
80
 
53
81
  您也可以按需引入单个组件:
54
82
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zxt-table",
3
3
  "private": false,
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "type": "module",
6
6
  "description": "一个基于 Vue 3 和 Element Plus 的高级表格、表单组件库",
7
7
  "keywords": [
@@ -25,11 +25,14 @@
25
25
  "import": "./dist/zxt-table.es.js",
26
26
  "require": "./dist/zxt-table.umd.js"
27
27
  },
28
- "./dist/style.css": "./dist/zxt-table.css"
28
+ "./style.css": "./dist/zxt-table.css",
29
+ "./dist/style.css": "./dist/zxt-table.css",
30
+ "./resolver": "./resolver.js"
29
31
  },
30
32
  "files": [
31
33
  "dist",
32
- "README.md"
34
+ "README.md",
35
+ "resolver.js"
33
36
  ],
34
37
  "peerDependencies": {
35
38
  "element-plus": "^2.0.0",
package/resolver.js ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * ZxtTable Resolver for unplugin-vue-components
3
+ *
4
+ * 使用方法 (vite.config.js):
5
+ * import { ZxtTableResolver } from 'zxt-table/resolver'
6
+ *
7
+ * Components({
8
+ * resolvers: [
9
+ * ZxtTableResolver()
10
+ * ]
11
+ * })
12
+ */
13
+ function ZxtTableResolver(options = {}) {
14
+ return {
15
+ type: "component",
16
+ resolve: (name) => {
17
+ // 匹配以 Zxt 开头的组件 (ZxtTable, ZxtGrid, ZxtForm, ZxtPagination 等)
18
+ if (name.startsWith("Zxt")) {
19
+ return {
20
+ name: name,
21
+ from: "zxt-table",
22
+ sideEffects: [
23
+ // 自动引入 ZxtTable 样式
24
+ "zxt-table/style.css",
25
+ // 自动引入 Element Plus 全量样式 (解决样式丢失问题)
26
+ // 如果用户明确配置了 importStyle: false,则不自动引入 Element 样式
27
+ options.importStyle !== false ? "element-plus/dist/index.css" : "",
28
+ ].filter(Boolean),
29
+ };
30
+ }
31
+ },
32
+ };
33
+ }
34
+
35
+ module.exports = { ZxtTableResolver };