@xmszm/core 0.0.1 → 0.0.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.
- package/README.md +178 -0
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +1037 -787
- package/dist/style.css +1 -1
- package/docs/.vitepress/config.mjs +82 -0
- package/docs/components/dataform.md +1 -1
- package/docs/components/datatable.md +45 -8
- package/docs/components/dialog.md +3 -3
- package/docs/components/options.md +1 -1
- package/docs/components/query.md +48 -2
- package/docs/components/utils.md +6 -6
- package/docs/guide/config.md +178 -0
- package/docs/guide/demo.md +2 -2
- package/docs/guide/local-development.md +109 -0
- package/docs/guide/quickstart.md +15 -11
- package/docs/index.md +2 -2
- package/docs/usage.md +15 -4
- package/package.json +4 -1
- package/src/dialog/commonDialog.jsx +34 -2
- package/src/dialog/useCommonDialog.js +41 -0
- package/src/directives/auto-register.js +57 -0
- package/src/directives/permission.js +67 -0
- package/src/form/DataForm.vue +8 -0
- package/src/index.js +16 -5
- package/src/options/Options.jsx +53 -40
- package/src/plugin/index.js +20 -0
- package/src/query/CommonQuery.vue +8 -1
- package/src/table/DataTable.vue +24 -3
- package/src/table/opr/useDataColumn.jsx +125 -90
- package/src/table/opr/useQRCode.js +40 -0
- package/src/utils/config.js +178 -0
- package/src/utils/dialog.js +110 -0
- package/src/utils/upload.js +19 -12
- package/types/auto-imports.d.ts +78 -0
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.filter-box[data-v-2aba8b9e]{padding:20px;margin:-16px -28px -20px;box-sizing:border-box}.filter-main[data-v-2aba8b9e]{display:flex;align-content:flex-start;flex-wrap:wrap;min-height:500px;max-height:700px;overflow-y:auto;row-gap:20px;padding:0 0 15px;box-sizing:border-box}.filter-main .filter-item[data-v-2aba8b9e]{--info-color: var(--e0ecc754);--n-border-checked: 1px solid var(--info-color) !important;--n-border-focus: 1px solid var(--info-color) !important;--n-color-checked: var(--info-color) !important;--n-box-shadow-focus: 0 0 0 2px #6a1f7403 !important;width:calc(100% / 3)}.filter-footer[data-v-2aba8b9e]{display:flex;justify-content:space-between;align-items:center}.filter-footer .submit-btn[data-v-2aba8b9e]{width:80px}[data-v-
|
|
1
|
+
.filter-box[data-v-2aba8b9e]{padding:20px;margin:-16px -28px -20px;box-sizing:border-box}.filter-main[data-v-2aba8b9e]{display:flex;align-content:flex-start;flex-wrap:wrap;min-height:500px;max-height:700px;overflow-y:auto;row-gap:20px;padding:0 0 15px;box-sizing:border-box}.filter-main .filter-item[data-v-2aba8b9e]{--info-color: var(--e0ecc754);--n-border-checked: 1px solid var(--info-color) !important;--n-border-focus: 1px solid var(--info-color) !important;--n-color-checked: var(--info-color) !important;--n-box-shadow-focus: 0 0 0 2px #6a1f7403 !important;width:calc(100% / 3)}.filter-footer[data-v-2aba8b9e]{display:flex;justify-content:space-between;align-items:center}.filter-footer .submit-btn[data-v-2aba8b9e]{width:80px}[data-v-d6710561] .n-data-table-tr--summary{position:sticky;bottom:0;left:0;right:0;z-index:2}[data-v-d6710561] .n-data-table-tr--summary .n-data-table-td--summary{border-top:1px solid var(--n-merged-border-color)}.upload-box[data-v-54e2cc87]{width:auto}.upload-box[data-v-54e2cc87] .n-upload-file-list.n-upload-file-list--grid{display:flex;flex-wrap:wrap}.upload-box[data-v-54e2cc87] .n-upload-file.n-upload-file--image-card-type{width:var(--image-w);height:var(--image-h)}.upload-box[data-v-54e2cc87] .n-upload-file.n-upload-file--image-card-type .n-image img{object-fit:var(--image-mode)!important}.upload-box[data-v-54e2cc87] .n-upload-trigger--image-card{width:var(--image-w);height:var(--image-h)}.upload-box[data-v-54e2cc87] .n-upload-file--error-status:not(:hover) .n-upload-file-info,.upload-box[data-v-54e2cc87] .n-upload-file--info-status:not(:hover) .n-upload-file-info{position:relative}.upload-box[data-v-54e2cc87] .n-upload-file--error-status:not(:hover) .n-upload-file-info:after,.upload-box[data-v-54e2cc87] .n-upload-file--info-status:not(:hover) .n-upload-file-info:after{content:"";position:absolute;top:0;left:0;right:0;bottom:0;z-index:5;display:block;background-color:#0006}.upload-box[data-v-54e2cc87] .n-upload-file--error-status:not(:hover):after{font-size:12px;white-space:nowrap;content:"上传失败~";position:absolute;color:#ffffffbf;top:50%;left:50%;transform:translate(-50%,-50%);z-index:5;display:block}.upload-box[data-v-54e2cc87] .n-upload-file--info-status:not(:hover):after{font-size:12px;white-space:nowrap;content:"加载中~";position:absolute;color:#ffffffbf;top:50%;left:50%;transform:translate(-50%,-50%);z-index:5;display:block}.svg-icon[data-v-9dbe5f10]{width:inherit;height:inherit;fill:currentColor;vertical-align:middle}.core-dialog-main,.core-dialog-content{box-sizing:border-box;display:flex;align-items:flex-start}.core-dialog-main{min-height:300px}.core-dialog .n-dialog__content{overflow-y:auto;margin:10px -28px 0;box-sizing:border-box;flex:1;border-top:1px solid #91919147;border-bottom:1px solid #91919147;padding:28px}.core-dialog .n-dialog__action{padding:20px 0 0;box-sizing:border-box}.core-dialog-read .n-dialog__content{border-bottom:unset}.select-text[data-v-6ef17b7a]{min-width:100px;max-width:240px;text-align:center}.select-line-text[data-v-6ef17b7a]{text-align:center;white-space:nowrap;display:inline}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { defineConfig } from 'vitepress'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
6
|
+
|
|
7
|
+
export default defineConfig({
|
|
8
|
+
title: '@xmszm/core',
|
|
9
|
+
description: 'naiveui core 组件与工具库 - Vue 3 + Naive UI 的表单、表格、弹窗与工具集合',
|
|
10
|
+
lang: 'zh-CN',
|
|
11
|
+
lastUpdated: true,
|
|
12
|
+
base: '/core/',
|
|
13
|
+
themeConfig: {
|
|
14
|
+
nav: [
|
|
15
|
+
{ text: '首页', link: '/' },
|
|
16
|
+
{ text: '指南', link: '/guide/quickstart' },
|
|
17
|
+
{ text: '组件', link: '/components/dataform' },
|
|
18
|
+
{ text: '工具', link: '/components/utils' },
|
|
19
|
+
{ text: '示例 Demo', link: '/guide/demo' },
|
|
20
|
+
],
|
|
21
|
+
sidebar: {
|
|
22
|
+
'/guide/': [
|
|
23
|
+
{
|
|
24
|
+
text: '指南',
|
|
25
|
+
items: [
|
|
26
|
+
{ text: '快速开始', link: '/guide/quickstart' },
|
|
27
|
+
{ text: '配置指南', link: '/guide/config' },
|
|
28
|
+
{ text: '本地开发', link: '/guide/local-development' },
|
|
29
|
+
{ text: '示例 Demo 说明', link: '/guide/demo' },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
'/components/': [
|
|
34
|
+
{
|
|
35
|
+
text: '表单',
|
|
36
|
+
items: [
|
|
37
|
+
{ text: 'DataForm', link: '/components/dataform' },
|
|
38
|
+
{ text: 'Options(动态项)', link: '/components/options' },
|
|
39
|
+
{ text: 'CommonQuery', link: '/components/query' },
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
text: '表格',
|
|
44
|
+
items: [{ text: 'DataTable', link: '/components/datatable' }],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
text: '弹窗',
|
|
48
|
+
items: [{ text: 'commonDialogMethod', link: '/components/dialog' }],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
text: '工具',
|
|
52
|
+
items: [
|
|
53
|
+
{ text: '操作列/排序/省略', link: '/components/utils' },
|
|
54
|
+
{ text: '上传', link: '/components/utils#上传工具' },
|
|
55
|
+
{ text: '权限与路由', link: '/components/utils#权限与路由' },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
socialLinks: [
|
|
61
|
+
{ icon: 'github', link: 'https://github.com/xmszm/core' },
|
|
62
|
+
],
|
|
63
|
+
outline: [2, 3],
|
|
64
|
+
docFooter: {
|
|
65
|
+
prev: '上一页',
|
|
66
|
+
next: '下一页',
|
|
67
|
+
},
|
|
68
|
+
footer: {
|
|
69
|
+
message: 'Released under the UNLICENSED License.',
|
|
70
|
+
copyright: 'Copyright © 2024-present',
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
vite: {
|
|
74
|
+
resolve: {
|
|
75
|
+
alias: {
|
|
76
|
+
'@xmszm/core': path.resolve(__dirname, '../../src'),
|
|
77
|
+
core: path.resolve(__dirname, '../../src'),
|
|
78
|
+
'@': path.resolve(__dirname, '../../src'),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
})
|
|
@@ -8,7 +8,7 @@ title: DataTable
|
|
|
8
8
|
```vue
|
|
9
9
|
<script setup>
|
|
10
10
|
import { ref } from 'vue'
|
|
11
|
-
import { DataTable } from 'core'
|
|
11
|
+
import { DataTable } from '@xmszm/core'
|
|
12
12
|
|
|
13
13
|
const columns = [
|
|
14
14
|
{ title: '名称', key: 'name', width: 160 },
|
|
@@ -29,20 +29,21 @@ const data = ref([
|
|
|
29
29
|
- `data: Array` 数据源。
|
|
30
30
|
- `columns: Array` 列定义,支持 `label`/`title`、`key`、`width`、`ellipsis`、`sorter` 等。
|
|
31
31
|
- `pagination: Object | null` 透传 `n-data-table` 分页。
|
|
32
|
-
- `oprColumns: Object | null`
|
|
33
|
-
- `selectColumns: Object | null`
|
|
34
|
-
- `defaultColumns: Array`
|
|
35
|
-
- `summaryColumns: Function`
|
|
32
|
+
- `oprColumns: Object | null` 右侧操作列配置(模板中使用 `opr-columns`)。
|
|
33
|
+
- `selectColumns: Object | null` 选择列(模板中使用 `select-columns`)。
|
|
34
|
+
- `defaultColumns: Array` 默认可见列键(模板中使用 `default-columns`)。
|
|
35
|
+
- `summaryColumns: Function` 汇总行(模板中使用 `summary-columns`)。
|
|
36
36
|
- `isFilter: boolean` 是否启用列筛选。
|
|
37
37
|
- `isEllipsis: boolean` 默认开启省略,使用内置 `ellipsis` tooltip。
|
|
38
38
|
- `virtual: boolean` 虚拟滚动,默认数据量大时自动开启。
|
|
39
|
+
- `rowKey: Function | String` 行键,用于标识每一行数据。
|
|
39
40
|
|
|
40
41
|
## 排序(orderEnum 内置工具)
|
|
41
42
|
`orderEnum` 专为 `DataTable` 列排序提供,离开表格场景单独调用无意义。
|
|
42
43
|
|
|
43
44
|
用法示例(结合后端查询参数与分页刷新):
|
|
44
|
-
```
|
|
45
|
-
import { orderEnum } from 'core'
|
|
45
|
+
```javascript
|
|
46
|
+
import { orderEnum } from '@xmszm/core'
|
|
46
47
|
|
|
47
48
|
const listQuery = reactive({ sortFieldName: '', desc: false })
|
|
48
49
|
const pageState = {
|
|
@@ -68,10 +69,46 @@ const columns = [
|
|
|
68
69
|
- 弹窗使用 `FilterDialog` 组件记录用户选择,结果存储于 `localStorage`,Key 为 `filter_key + 路由全路径`。
|
|
69
70
|
|
|
70
71
|
## 省略
|
|
71
|
-
- 默认对列开启 `ellipsis`,使用
|
|
72
|
+
- 默认对列开启 `ellipsis`,使用 `@xmszm/core/table/utils/ellipsis` 配置 tooltip 样式。
|
|
72
73
|
- 可通过列的 `ellipsisProp` 自定义。
|
|
73
74
|
|
|
74
75
|
## 操作列
|
|
75
76
|
- 可搭配 `createActionColumnJsx` 快速生成操作列,或直接传入 `oprColumns`。
|
|
76
77
|
- `useDataColumnButton` / `useDataColumnPop` 组合了按钮与二次确认的通用场景。
|
|
77
78
|
|
|
79
|
+
### 使用示例
|
|
80
|
+
|
|
81
|
+
```vue
|
|
82
|
+
<script setup>
|
|
83
|
+
import { DataTable, createActionColumnJsx } from '@xmszm/core'
|
|
84
|
+
|
|
85
|
+
const columns = [
|
|
86
|
+
{ title: '名称', key: 'name', width: 160 },
|
|
87
|
+
{ title: '类型', key: 'type', width: 120 },
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
const opr = createActionColumnJsx([
|
|
91
|
+
{
|
|
92
|
+
label: '编辑',
|
|
93
|
+
type: 'primary',
|
|
94
|
+
onClick: (row) => handleEdit(row),
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: '删除',
|
|
98
|
+
type: 'error',
|
|
99
|
+
mode: 'pop',
|
|
100
|
+
onClick: (row) => handleDelete(row),
|
|
101
|
+
},
|
|
102
|
+
])
|
|
103
|
+
</script>
|
|
104
|
+
|
|
105
|
+
<template>
|
|
106
|
+
<DataTable
|
|
107
|
+
:data="tableData"
|
|
108
|
+
:columns="columns"
|
|
109
|
+
:opr-columns="opr"
|
|
110
|
+
:row-key="row => row?.id"
|
|
111
|
+
/>
|
|
112
|
+
</template>
|
|
113
|
+
```
|
|
114
|
+
|
|
@@ -6,8 +6,8 @@ title: commonDialogMethod
|
|
|
6
6
|
|
|
7
7
|
## 基础用法(用函数包裹触发)
|
|
8
8
|
`commonDialogMethod` 调用即会创建并打开弹窗,推荐用一个函数包裹,在需要时再触发:
|
|
9
|
-
```
|
|
10
|
-
import { commonDialogMethod } from 'core'
|
|
9
|
+
```javascript
|
|
10
|
+
import { commonDialogMethod } from '@xmszm/core'
|
|
11
11
|
|
|
12
12
|
function openEditDialog(row) {
|
|
13
13
|
const { cancel, model } = commonDialogMethod(
|
|
@@ -54,7 +54,7 @@ openEditDialog(currentRow)
|
|
|
54
54
|
- `modeEnum` 默认模式枚举。
|
|
55
55
|
|
|
56
56
|
## 自定义动作
|
|
57
|
-
```
|
|
57
|
+
```javascript
|
|
58
58
|
commonDialogMethod({
|
|
59
59
|
action: [
|
|
60
60
|
{ label: '关闭', mode: 'cancel' },
|
package/docs/components/query.md
CHANGED
|
@@ -8,7 +8,7 @@ title: CommonQuery
|
|
|
8
8
|
```vue
|
|
9
9
|
<script setup>
|
|
10
10
|
import { ref } from 'vue'
|
|
11
|
-
import { CommonQuery } from 'core'
|
|
11
|
+
import { CommonQuery } from '@xmszm/core'
|
|
12
12
|
|
|
13
13
|
const query = ref({})
|
|
14
14
|
const options = [
|
|
@@ -22,7 +22,53 @@ function onSubmit() {
|
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
24
|
<template>
|
|
25
|
-
<CommonQuery v-model:query="query" :options="options" @submit="onSubmit" />
|
|
25
|
+
<CommonQuery v-model:query="query" :options="options" @submit="onSubmit" @reset="onReset" />
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 完整示例(结合分页)
|
|
30
|
+
|
|
31
|
+
```vue
|
|
32
|
+
<script setup>
|
|
33
|
+
import { reactive } from 'vue'
|
|
34
|
+
import { CommonQuery } from '@xmszm/core'
|
|
35
|
+
|
|
36
|
+
const listQuery = reactive({
|
|
37
|
+
page: 1,
|
|
38
|
+
pageSize: 10,
|
|
39
|
+
likeQuery: {
|
|
40
|
+
keyword: '',
|
|
41
|
+
type: '',
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const queryOptions = [
|
|
46
|
+
{ label: '关键词', key: 'keyword', queryType: 'likeQuery', way: 'input' },
|
|
47
|
+
{ label: '类型', key: 'type', queryType: 'likeQuery', way: 'select', options: [
|
|
48
|
+
{ label: '类型A', value: 'A' },
|
|
49
|
+
{ label: '类型B', value: 'B' }
|
|
50
|
+
]},
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
function handleSearch() {
|
|
54
|
+
listQuery.page = 1
|
|
55
|
+
fetchData()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function handleReset() {
|
|
59
|
+
listQuery.likeQuery = { keyword: '', type: '' }
|
|
60
|
+
listQuery.page = 1
|
|
61
|
+
fetchData()
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
64
|
+
|
|
65
|
+
<template>
|
|
66
|
+
<CommonQuery
|
|
67
|
+
:query="listQuery"
|
|
68
|
+
:options="queryOptions"
|
|
69
|
+
@submit="handleSearch"
|
|
70
|
+
@reset="handleReset"
|
|
71
|
+
/>
|
|
26
72
|
</template>
|
|
27
73
|
```
|
|
28
74
|
|
package/docs/components/utils.md
CHANGED
|
@@ -7,8 +7,8 @@ title: 工具与常量
|
|
|
7
7
|
### createActionColumnJsx
|
|
8
8
|
快速生成表格操作列。
|
|
9
9
|
|
|
10
|
-
```
|
|
11
|
-
import { createActionColumnJsx } from 'core'
|
|
10
|
+
```javascript
|
|
11
|
+
import { createActionColumnJsx } from '@xmszm/core'
|
|
12
12
|
|
|
13
13
|
const oprColumn = createActionColumnJsx(
|
|
14
14
|
[
|
|
@@ -27,13 +27,13 @@ const oprColumn = createActionColumnJsx(
|
|
|
27
27
|
|
|
28
28
|
### ellipsis
|
|
29
29
|
表格省略 tooltip 配置:
|
|
30
|
-
```
|
|
31
|
-
import { ellipsis } from 'core/table/utils/ellipsis'
|
|
30
|
+
```javascript
|
|
31
|
+
import { ellipsis } from '@xmszm/core/table/utils/ellipsis'
|
|
32
32
|
```
|
|
33
33
|
|
|
34
34
|
## 上传工具
|
|
35
|
-
```
|
|
36
|
-
import { registryUpload, customUpload, getFileUrl } from 'core'
|
|
35
|
+
```javascript
|
|
36
|
+
import { registryUpload, customUpload, getFileUrl } from '@xmszm/core'
|
|
37
37
|
|
|
38
38
|
registryUpload((config) => axios.request(config)) // 注册实际上传实现
|
|
39
39
|
await customUpload({ url: '/upload', data: file })
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# 配置指南
|
|
2
|
+
|
|
3
|
+
## 统一配置系统
|
|
4
|
+
|
|
5
|
+
`@xmszm/core` 提供了统一的配置系统,用于管理外部依赖和业务配置。
|
|
6
|
+
|
|
7
|
+
## 初始化配置
|
|
8
|
+
|
|
9
|
+
在应用启动时,使用 `setupConfig` 进行统一配置:
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
import { setupConfig } from '@xmszm/core'
|
|
13
|
+
import axios from 'axios'
|
|
14
|
+
|
|
15
|
+
// 初始化配置
|
|
16
|
+
setupConfig({
|
|
17
|
+
// API 基础地址(用于文件 URL 拼接)
|
|
18
|
+
baseURL: 'https://api.example.com',
|
|
19
|
+
|
|
20
|
+
// 权限检查函数
|
|
21
|
+
hasPermission: (permission) => {
|
|
22
|
+
// 你的权限检查逻辑
|
|
23
|
+
const permissions = getPermissions() // 从 store、context 等获取权限列表
|
|
24
|
+
return permissions.includes(permission)
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// 上传方法
|
|
28
|
+
uploadMethod: (config) => {
|
|
29
|
+
// 你的上传实现
|
|
30
|
+
return axios.request(config)
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 配置项说明
|
|
36
|
+
|
|
37
|
+
### baseURL
|
|
38
|
+
|
|
39
|
+
API 基础地址,用于 `getFileUrl` 函数拼接文件 URL。
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import { setupConfig, getFileUrl } from '@xmszm/core'
|
|
43
|
+
|
|
44
|
+
setupConfig({
|
|
45
|
+
baseURL: 'https://api.example.com'
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
// 使用
|
|
49
|
+
const url = getFileUrl('/images/avatar.jpg')
|
|
50
|
+
// => 'https://api.example.com/images/avatar.jpg'
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### hasPermission
|
|
54
|
+
|
|
55
|
+
权限检查函数,用于表格操作列的权限过滤。
|
|
56
|
+
|
|
57
|
+
```javascript
|
|
58
|
+
import { setupConfig } from '@xmszm/core'
|
|
59
|
+
|
|
60
|
+
setupConfig({
|
|
61
|
+
hasPermission: (permission) => {
|
|
62
|
+
// 从 Vuex/Pinia store 获取权限
|
|
63
|
+
const store = useStore()
|
|
64
|
+
return store.state.permissions.includes(permission)
|
|
65
|
+
|
|
66
|
+
// 或从 localStorage 获取
|
|
67
|
+
// const permissions = JSON.parse(localStorage.getItem('permissions') || '[]')
|
|
68
|
+
// return permissions.includes(permission)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
// 在 createActionColumnJsx 中使用
|
|
73
|
+
const opr = createActionColumnJsx([
|
|
74
|
+
{
|
|
75
|
+
label: '编辑',
|
|
76
|
+
permission: 'user:edit', // 会调用 hasPermission('user:edit')
|
|
77
|
+
onClick: (row) => edit(row)
|
|
78
|
+
}
|
|
79
|
+
])
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### uploadMethod
|
|
83
|
+
|
|
84
|
+
上传方法实现,用于 `customUpload` 函数。
|
|
85
|
+
|
|
86
|
+
```javascript
|
|
87
|
+
import { setupConfig, customUpload } from '@xmszm/core'
|
|
88
|
+
import axios from 'axios'
|
|
89
|
+
|
|
90
|
+
setupConfig({
|
|
91
|
+
uploadMethod: (config) => {
|
|
92
|
+
return axios.request({
|
|
93
|
+
...config,
|
|
94
|
+
headers: {
|
|
95
|
+
'Authorization': `Bearer ${getToken()}`,
|
|
96
|
+
...config.headers
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// 使用
|
|
103
|
+
await customUpload({
|
|
104
|
+
url: '/upload',
|
|
105
|
+
method: 'POST',
|
|
106
|
+
data: formData
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 兼容旧版 API
|
|
111
|
+
|
|
112
|
+
为了向后兼容,仍然支持旧的 API:
|
|
113
|
+
|
|
114
|
+
```javascript
|
|
115
|
+
import { registryUpload } from '@xmszm/core'
|
|
116
|
+
|
|
117
|
+
// 旧版方式(仍然可用,但不推荐)
|
|
118
|
+
registryUpload((config) => axios.request(config))
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 获取配置
|
|
122
|
+
|
|
123
|
+
如果需要获取当前配置:
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
import { getConfig, getBaseURL, getHasPermission, getUploadMethod } from '@xmszm/core'
|
|
127
|
+
|
|
128
|
+
// 获取所有配置
|
|
129
|
+
const config = getConfig()
|
|
130
|
+
|
|
131
|
+
// 获取单个配置
|
|
132
|
+
const baseURL = getBaseURL()
|
|
133
|
+
const hasPermission = getHasPermission()
|
|
134
|
+
const uploadMethod = getUploadMethod()
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 完整示例
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
// main.js
|
|
141
|
+
import { createApp } from 'vue'
|
|
142
|
+
import { setupConfig } from '@xmszm/core'
|
|
143
|
+
import App from './App.vue'
|
|
144
|
+
import axios from 'axios'
|
|
145
|
+
import { useStore } from './store'
|
|
146
|
+
|
|
147
|
+
const app = createApp(App)
|
|
148
|
+
|
|
149
|
+
// 配置库
|
|
150
|
+
setupConfig({
|
|
151
|
+
baseURL: import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000',
|
|
152
|
+
|
|
153
|
+
hasPermission: (permission) => {
|
|
154
|
+
const store = useStore()
|
|
155
|
+
return store.state.user.permissions?.includes(permission) ?? false
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
uploadMethod: (config) => {
|
|
159
|
+
return axios.request({
|
|
160
|
+
...config,
|
|
161
|
+
headers: {
|
|
162
|
+
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
|
163
|
+
...config.headers
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
app.mount('#app')
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## 注意事项
|
|
173
|
+
|
|
174
|
+
1. **配置时机**:建议在应用启动时(如 `main.js`)进行配置
|
|
175
|
+
2. **权限检查**:如果未配置 `hasPermission`,默认返回 `true`(会显示警告)
|
|
176
|
+
3. **BASE_URL**:如果未配置 `baseURL`,`getFileUrl` 会返回原始 URL(会显示警告)
|
|
177
|
+
4. **上传方法**:如果未配置 `uploadMethod`,调用 `customUpload` 会抛出错误
|
|
178
|
+
|
package/docs/guide/demo.md
CHANGED
|
@@ -14,7 +14,7 @@ npm install
|
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
2) 在你的宿主工程中引入该组件文件(或复制内容),确保存在以下 alias:
|
|
17
|
-
```
|
|
17
|
+
```javascript
|
|
18
18
|
// vite / webpack 示例
|
|
19
19
|
resolve: {
|
|
20
20
|
alias: {
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
CommonQuery,
|
|
56
56
|
createActionColumnJsx,
|
|
57
57
|
DataTable,
|
|
58
|
-
} from 'core'
|
|
58
|
+
} from '@xmszm/core'
|
|
59
59
|
|
|
60
60
|
// 列表数据与查询管理
|
|
61
61
|
const { pageState, listQuery } = useNaivePage(() => {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# 本地开发配置
|
|
2
|
+
|
|
3
|
+
## npm/pnpm link 时的路径解析问题
|
|
4
|
+
|
|
5
|
+
当使用 `npm link` 或 `pnpm link` 进行本地开发时,Vite 可能无法正确解析链接包的路径。这是因为:
|
|
6
|
+
|
|
7
|
+
1. **符号链接解析问题**:npm/pnpm link 创建的是符号链接,Vite 的模块解析在处理符号链接时可能失败
|
|
8
|
+
2. **package.json exports**:链接包的 `exports` 字段路径解析可能不生效
|
|
9
|
+
3. **CSS 文件路径**:样式文件的路径解析尤其容易出问题
|
|
10
|
+
|
|
11
|
+
## 最小化配置方案
|
|
12
|
+
|
|
13
|
+
在测试项目的 `vite.config.js` 中添加以下配置即可:
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { defineConfig } from 'vite'
|
|
17
|
+
import vue from '@vitejs/plugin-vue'
|
|
18
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
19
|
+
import path from 'path'
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [vue(), vueJsx()],
|
|
23
|
+
resolve: {
|
|
24
|
+
alias: {
|
|
25
|
+
'@': path.resolve(__dirname, 'src'),
|
|
26
|
+
// 解决 npm/pnpm link 时的路径解析问题
|
|
27
|
+
'@xmszm/core': path.resolve(__dirname, '..'), // 指向库项目根目录
|
|
28
|
+
'@xmszm/core/dist/style.css': path.resolve(__dirname, '../dist/style.css'),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
server: {
|
|
32
|
+
port: 3000,
|
|
33
|
+
open: true
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 为什么需要这个配置?
|
|
39
|
+
|
|
40
|
+
### 问题 1: 模块无法解析
|
|
41
|
+
|
|
42
|
+
**错误信息**:
|
|
43
|
+
```
|
|
44
|
+
Failed to resolve import "@xmszm/core" from "src/App.vue"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**原因**:
|
|
48
|
+
- npm/pnpm link 创建的符号链接路径可能无法被 Vite 正确识别
|
|
49
|
+
- 链接路径如 `link:C:/Users/admin/AppData/Local/pnpm/global/5/node_modules/@xmszm/core` 可能解析失败
|
|
50
|
+
|
|
51
|
+
**解决方案**:
|
|
52
|
+
```javascript
|
|
53
|
+
'@xmszm/core': path.resolve(__dirname, '..')
|
|
54
|
+
```
|
|
55
|
+
直接指向源项目根目录,绕过符号链接解析问题。
|
|
56
|
+
|
|
57
|
+
### 问题 2: 样式文件无法解析
|
|
58
|
+
|
|
59
|
+
**错误信息**:
|
|
60
|
+
```
|
|
61
|
+
Failed to resolve import "@xmszm/core/dist/style.css"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**原因**:
|
|
65
|
+
- CSS 文件的路径解析在链接包中更容易失败
|
|
66
|
+
- `exports` 字段对 CSS 文件的处理可能不一致
|
|
67
|
+
|
|
68
|
+
**解决方案**:
|
|
69
|
+
```javascript
|
|
70
|
+
'@xmszm/core/dist/style.css': path.resolve(__dirname, '../dist/style.css')
|
|
71
|
+
```
|
|
72
|
+
直接指向源项目的样式文件。
|
|
73
|
+
|
|
74
|
+
## 生产环境使用
|
|
75
|
+
|
|
76
|
+
在生产环境中(通过 npm 安装),**不需要**这些配置,因为:
|
|
77
|
+
|
|
78
|
+
1. 正常安装的包路径解析没有问题
|
|
79
|
+
2. `package.json` 的 `exports` 字段会正确工作
|
|
80
|
+
3. Vite 可以正确解析 `node_modules` 中的包
|
|
81
|
+
|
|
82
|
+
## 完整示例
|
|
83
|
+
|
|
84
|
+
```javascript
|
|
85
|
+
// vite.config.js
|
|
86
|
+
import { defineConfig } from 'vite'
|
|
87
|
+
import vue from '@vitejs/plugin-vue'
|
|
88
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
|
89
|
+
import path from 'path'
|
|
90
|
+
|
|
91
|
+
export default defineConfig({
|
|
92
|
+
plugins: [vue(), vueJsx()],
|
|
93
|
+
resolve: {
|
|
94
|
+
alias: {
|
|
95
|
+
'@': path.resolve(__dirname, 'src'),
|
|
96
|
+
// 仅在使用 npm/pnpm link 时需要
|
|
97
|
+
'@xmszm/core': path.resolve(__dirname, '..'),
|
|
98
|
+
'@xmszm/core/dist/style.css': path.resolve(__dirname, '../dist/style.css'),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## 注意事项
|
|
105
|
+
|
|
106
|
+
1. **仅本地开发需要**:这个配置只在本地开发(使用 link)时需要
|
|
107
|
+
2. **相对路径**:`path.resolve(__dirname, '..')` 假设测试项目在库项目的 `test-app` 目录下
|
|
108
|
+
3. **路径调整**:如果目录结构不同,需要相应调整路径
|
|
109
|
+
|
package/docs/guide/quickstart.md
CHANGED
|
@@ -5,17 +5,21 @@ title: 快速开始
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install core
|
|
8
|
+
npm install @xmszm/core
|
|
9
|
+
# 或
|
|
10
|
+
pnpm add @xmszm/core
|
|
11
|
+
# 或
|
|
12
|
+
yarn add @xmszm/core
|
|
9
13
|
```
|
|
10
14
|
|
|
11
15
|
同时请在项目中安装(或确保已存在)以下 peer 依赖(版本可按你项目统一):
|
|
12
16
|
|
|
13
|
-
- vue 3.
|
|
14
|
-
- naive-ui
|
|
15
|
-
- vue-router
|
|
16
|
-
- dayjs
|
|
17
|
-
- lodash-es
|
|
18
|
-
-
|
|
17
|
+
- `vue` >= 3.3.0
|
|
18
|
+
- `naive-ui` >= 2.38.0
|
|
19
|
+
- `vue-router` >= 4.2.0
|
|
20
|
+
- `dayjs` >= 1.11.0
|
|
21
|
+
- `lodash-es` >= 4.17.21
|
|
22
|
+
- `@vicons/ionicons5` >= 0.13.0
|
|
19
23
|
|
|
20
24
|
> 若项目使用 `@` 路径别名,请确认在构建/运行配置中存在相同的 alias。
|
|
21
25
|
|
|
@@ -24,8 +28,8 @@ npm install core
|
|
|
24
28
|
```vue
|
|
25
29
|
<script setup>
|
|
26
30
|
import { ref } from 'vue'
|
|
27
|
-
import { DataForm, DataTable, commonDialogMethod } from 'core'
|
|
28
|
-
import 'core/dist/style.css' // 如需默认样式
|
|
31
|
+
import { DataForm, DataTable, commonDialogMethod } from '@xmszm/core'
|
|
32
|
+
import '@xmszm/core/dist/style.css' // 如需默认样式
|
|
29
33
|
|
|
30
34
|
const formValue = ref({})
|
|
31
35
|
const formOptions = [
|
|
@@ -62,7 +66,7 @@ function openDialog() {
|
|
|
62
66
|
|
|
63
67
|
## 目录结构建议
|
|
64
68
|
|
|
65
|
-
```
|
|
69
|
+
```text
|
|
66
70
|
docs/ # VitePress 文档
|
|
67
71
|
examples/demo.vue # 可运行的最小示例
|
|
68
72
|
src/ # 组件与工具源码
|
|
@@ -72,6 +76,6 @@ types/ # 类型定义
|
|
|
72
76
|
## 常见问题
|
|
73
77
|
|
|
74
78
|
- 找不到 `@/utils/...`:请在宿主项目配置 `@` 别名或提供对应实现。
|
|
75
|
-
- 样式缺失:如需库内 less 默认样式,确保引入
|
|
79
|
+
- 样式缺失:如需库内 less 默认样式,确保引入 `@xmszm/core/dist/style.css`。
|
|
76
80
|
- TS 类型:库内已内置 `types/index.d.ts`,可直接获得基础提示。
|
|
77
81
|
|