el-plus 0.0.87 → 0.0.88
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/CHANGELOG.md +6 -0
- package/dist/index.full.js +43 -39
- package/dist/index.full.min.js +4 -4
- package/dist/index.full.min.js.map +1 -1
- package/dist/index.full.min.mjs +4 -4
- package/dist/index.full.min.mjs.map +1 -1
- package/dist/index.full.mjs +43 -39
- package/docs/components/buttons.md +66 -19
- package/docs/components/form.md +24 -5
- package/docs/components/header.md +23 -0
- package/docs/components/search-list-page.md +11 -1
- package/docs/components/table.md +2 -1
- package/docs/components/use-form-dialog.md +4 -5
- package/docs/hooks/use-navigation.md +131 -0
- package/docs/hooks/use-utils.md +144 -0
- package/docs/index.md +11 -11
- package/docs/overview.md +99 -0
- package/docs/pages/detail.md +1 -1
- package/docs/pages/list.md +1 -1
- package/docs/pages/router.md +151 -0
- package/es/components/uni-vue/index.d.ts +7 -17
- package/es/components/uni-vue/src/uni-vue.vue.d.ts +3 -7
- package/es/components/uni-vue/src/uni-vue.vue2.mjs +1 -3
- package/es/components/uni-vue/src/uni-vue.vue2.mjs.map +1 -1
- package/es/components/uni-vue/src/use-uni-vue.d.ts +1 -1
- package/es/components/uni-vue/src/use-uni-vue.mjs +40 -34
- package/es/components/uni-vue/src/use-uni-vue.mjs.map +1 -1
- package/es/package.json.mjs +1 -1
- package/lib/components/uni-vue/index.d.ts +7 -17
- package/lib/components/uni-vue/src/uni-vue.vue.d.ts +3 -7
- package/lib/components/uni-vue/src/uni-vue.vue2.js +1 -3
- package/lib/components/uni-vue/src/uni-vue.vue2.js.map +1 -1
- package/lib/components/uni-vue/src/use-uni-vue.d.ts +1 -1
- package/lib/components/uni-vue/src/use-uni-vue.js +40 -34
- package/lib/components/uni-vue/src/use-uni-vue.js.map +1 -1
- package/lib/package.json.js +1 -1
- package/package.json +4 -2
- package/docs/components/index.md +0 -23
package/dist/index.full.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! ElPlus v0.0.
|
|
1
|
+
/*! ElPlus v0.0.88 */
|
|
2
2
|
|
|
3
3
|
import { useAttrs, getCurrentInstance, inject, provide, ref, nextTick, defineComponent, computed, createVNode, Fragment, withDirectives, resolveComponent, mergeProps, resolveDirective, useTemplateRef, reactive, onBeforeUpdate, createTextVNode, h, mergeModels, useModel, createElementBlock, openBlock, normalizeStyle, normalizeClass, unref, createCommentVNode, withCtx, renderSlot, renderList, createBlock, vShow, toDisplayString, useSlots, watch, onMounted, createSlots, normalizeProps, guardReactiveProps, markRaw, Transition, shallowReactive, isVNode, render, createElementVNode, toRaw } from 'vue';
|
|
4
4
|
import { buttonProps, useLocale as useLocale$1, ElLoading, ElMessage, ElMessageBox, formProps as formProps$1, formEmits as formEmits$1, ElTooltip, formItemProps as formItemProps$1, ElFormItem, ElForm, ElRow, ElCol, inputProps as inputProps$1, inputEmits as inputEmits$1, configProviderContextKey, ElConfigProvider, ElDialog, ElButton, ElTable, ElIcon, selectProps as selectProps$1, selectEmits as selectEmits$1, ElPageHeader, datePickerProps, linkProps as linkProps$1, ElSkeleton } from 'element-plus';
|
|
@@ -4084,7 +4084,7 @@ const uniVueProps = {
|
|
|
4084
4084
|
// 组件类型 bpm、 address
|
|
4085
4085
|
};
|
|
4086
4086
|
|
|
4087
|
-
const useUniVue = (props,
|
|
4087
|
+
const useUniVue = (props, _emit) => {
|
|
4088
4088
|
const uniVue = useTemplateRef("uniVue");
|
|
4089
4089
|
const { type } = props;
|
|
4090
4090
|
const loading = ref(true);
|
|
@@ -4195,7 +4195,7 @@ const useUniVue = (props, emit) => {
|
|
|
4195
4195
|
const cssPromises = [];
|
|
4196
4196
|
if (!isBpm) {
|
|
4197
4197
|
cssPromises.push(
|
|
4198
|
-
http.request("/
|
|
4198
|
+
http.request("/index.css", {
|
|
4199
4199
|
responseReturn: "raw",
|
|
4200
4200
|
baseURL: ""
|
|
4201
4201
|
}).then((res) => res.data)
|
|
@@ -4230,6 +4230,12 @@ const useUniVue = (props, emit) => {
|
|
|
4230
4230
|
const style = document.createElement("style");
|
|
4231
4231
|
style.textContent = css;
|
|
4232
4232
|
shadowRoot.appendChild(style);
|
|
4233
|
+
if (isAddress && !document.querySelector("style[data-hx-address-style]")) {
|
|
4234
|
+
const headStyle = document.createElement("style");
|
|
4235
|
+
headStyle.textContent = css;
|
|
4236
|
+
headStyle.setAttribute("data-hx-address-style", "true");
|
|
4237
|
+
document.head.appendChild(headStyle);
|
|
4238
|
+
}
|
|
4233
4239
|
} catch (error) {
|
|
4234
4240
|
console.log(error);
|
|
4235
4241
|
} finally {
|
|
@@ -4237,55 +4243,55 @@ const useUniVue = (props, emit) => {
|
|
|
4237
4243
|
}
|
|
4238
4244
|
}
|
|
4239
4245
|
shadowRoot.appendChild(container);
|
|
4240
|
-
console.log(prepareVueAttributes());
|
|
4241
|
-
const baseEvents = {
|
|
4242
|
-
...prepareVueAttributes().on,
|
|
4243
|
-
"input": (newVal) => {
|
|
4244
|
-
console.log(newVal, "input", props.name);
|
|
4245
|
-
emit("update:modelValue", newVal);
|
|
4246
|
-
},
|
|
4247
|
-
"update:dialogFormData": (newVal) => {
|
|
4248
|
-
console.log(newVal, "update:dialogFormData");
|
|
4249
|
-
emit("update:dialogFormData", newVal);
|
|
4250
|
-
},
|
|
4251
|
-
"update:visible": (newVal) => {
|
|
4252
|
-
console.log(newVal, "update:visible");
|
|
4253
|
-
emit("update:visible", newVal);
|
|
4254
|
-
}
|
|
4255
|
-
};
|
|
4256
4246
|
instance = new Vue2({
|
|
4257
4247
|
el: container,
|
|
4258
4248
|
// @ts-expect-error 缺少类型定义
|
|
4259
4249
|
router: new VueRouter3(),
|
|
4260
|
-
render: (h) =>
|
|
4261
|
-
props:
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4250
|
+
render: (h) => {
|
|
4251
|
+
const { on: vue2Events, props: vue2Props } = prepareVueAttributes();
|
|
4252
|
+
return h(props.name, {
|
|
4253
|
+
props: vue2Props,
|
|
4254
|
+
on: vue2Events
|
|
4255
|
+
});
|
|
4256
|
+
}
|
|
4266
4257
|
});
|
|
4267
4258
|
};
|
|
4259
|
+
const updateVue2Instance = () => {
|
|
4260
|
+
if (!instance) return;
|
|
4261
|
+
const child = instance.$children[0];
|
|
4262
|
+
if (child) {
|
|
4263
|
+
const { props: vue2Props } = prepareVueAttributes();
|
|
4264
|
+
Object.assign(child.$options.propsData, vue2Props);
|
|
4265
|
+
if (child._props) {
|
|
4266
|
+
Object.keys(vue2Props).forEach((key) => {
|
|
4267
|
+
const newValue = vue2Props[key];
|
|
4268
|
+
const oldValue = child._props[key];
|
|
4269
|
+
if (newValue === oldValue && typeof newValue === "object" && newValue !== null) {
|
|
4270
|
+
const temp = {};
|
|
4271
|
+
child._props[key] = temp;
|
|
4272
|
+
}
|
|
4273
|
+
child._props[key] = newValue;
|
|
4274
|
+
});
|
|
4275
|
+
}
|
|
4276
|
+
child.$forceUpdate();
|
|
4277
|
+
}
|
|
4278
|
+
instance.$forceUpdate();
|
|
4279
|
+
};
|
|
4268
4280
|
Object.keys(attrs).forEach((key) => {
|
|
4269
|
-
console.log(key, 8);
|
|
4270
4281
|
if (!key.startsWith("on")) {
|
|
4271
4282
|
watch(
|
|
4272
4283
|
() => attrs[key],
|
|
4273
|
-
(
|
|
4284
|
+
() => {
|
|
4285
|
+
console.log(key, "key");
|
|
4274
4286
|
nextTick(() => {
|
|
4275
4287
|
try {
|
|
4276
|
-
|
|
4277
|
-
let vue2Prop = key;
|
|
4278
|
-
if (key === "modelValue") {
|
|
4279
|
-
vue2Prop = "value";
|
|
4280
|
-
}
|
|
4281
|
-
instance.$children[0][vue2Prop] = newVal;
|
|
4288
|
+
updateVue2Instance();
|
|
4282
4289
|
} catch (e) {
|
|
4283
4290
|
}
|
|
4284
4291
|
});
|
|
4285
4292
|
},
|
|
4286
4293
|
{
|
|
4287
|
-
deep: true
|
|
4288
|
-
immediate: true
|
|
4294
|
+
deep: true
|
|
4289
4295
|
}
|
|
4290
4296
|
);
|
|
4291
4297
|
}
|
|
@@ -4305,12 +4311,10 @@ var _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
4305
4311
|
},
|
|
4306
4312
|
__name: "uni-vue",
|
|
4307
4313
|
props: uniVueProps,
|
|
4308
|
-
emits: ["update:modelValue", "update:dialogFormData", "update:visible"],
|
|
4309
4314
|
setup(__props, { emit: __emit }) {
|
|
4310
4315
|
const bem = createNameSpace("uni-vue");
|
|
4311
4316
|
const props = __props;
|
|
4312
|
-
const
|
|
4313
|
-
const { loading } = useUniVue(props, emit);
|
|
4317
|
+
const { loading } = useUniVue(props);
|
|
4314
4318
|
return (_ctx, _cache) => {
|
|
4315
4319
|
return openBlock(), createElementBlock(Fragment, null, [
|
|
4316
4320
|
createVNode(unref(ElSkeleton), {
|
|
@@ -4461,7 +4465,7 @@ var components = [
|
|
|
4461
4465
|
EpFooterInfo
|
|
4462
4466
|
];
|
|
4463
4467
|
|
|
4464
|
-
var version = "0.0.
|
|
4468
|
+
var version = "0.0.88";
|
|
4465
4469
|
|
|
4466
4470
|
var globalProperties = {
|
|
4467
4471
|
install(app) {
|
|
@@ -14,19 +14,55 @@ const buttons = [
|
|
|
14
14
|
{
|
|
15
15
|
name: '新增',
|
|
16
16
|
prop: 'add',
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
onClick: () => {
|
|
18
|
+
// 新增逻辑
|
|
19
|
+
},
|
|
19
20
|
},
|
|
20
21
|
{
|
|
21
22
|
name: '删除',
|
|
22
23
|
prop: 'delete',
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
onClick: () => {
|
|
25
|
+
// 删除逻辑
|
|
26
|
+
},
|
|
25
27
|
},
|
|
26
28
|
]
|
|
27
29
|
</script>
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
## 在 Form 中使用
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
const formItemList = ref<FormProps['formItemList']>([
|
|
36
|
+
{
|
|
37
|
+
col: 24,
|
|
38
|
+
type: 'EpButtons',
|
|
39
|
+
props: {
|
|
40
|
+
list: [
|
|
41
|
+
{
|
|
42
|
+
name: '提交审批',
|
|
43
|
+
type: 'primary',
|
|
44
|
+
onClick: () => {
|
|
45
|
+
// 提交审批逻辑
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: '取消审批',
|
|
50
|
+
onClick: () => {
|
|
51
|
+
// 取消审批逻辑
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: '作废',
|
|
56
|
+
onClick: () => {
|
|
57
|
+
// 作废逻辑
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
])
|
|
64
|
+
```
|
|
65
|
+
|
|
30
66
|
## Props
|
|
31
67
|
|
|
32
68
|
| 属性 | 说明 | 类型 | 默认值 |
|
|
@@ -38,18 +74,19 @@ const buttons = [
|
|
|
38
74
|
|
|
39
75
|
## ButtonProps 配置
|
|
40
76
|
|
|
41
|
-
| 属性 | 说明 | 类型 |
|
|
42
|
-
|
|
43
|
-
| name | 按钮文本 | `string` |
|
|
44
|
-
| prop | 唯一标识 | `string` |
|
|
45
|
-
| type | 按钮类型 | `'primary' \| 'success' \| 'warning' \| 'danger' \| 'info'` |
|
|
46
|
-
| plain | 朴素按钮 | `boolean` |
|
|
47
|
-
| disabled | 是否禁用 | `boolean \| () => boolean` |
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
52
|
-
|
|
|
77
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
78
|
+
|------|------|------|--------|
|
|
79
|
+
| name | 按钮文本 | `string` | - |
|
|
80
|
+
| prop | 唯一标识 | `string` | - |
|
|
81
|
+
| type | 按钮类型 | `'primary' \| 'success' \| 'warning' \| 'danger' \| 'info'` | - |
|
|
82
|
+
| plain | 朴素按钮 | `boolean` | `false` |
|
|
83
|
+
| disabled | 是否禁用 | `boolean \| () => boolean` | `false` |
|
|
84
|
+
| show | 是否显示(支持函数) | `boolean \| () => boolean` | `true` |
|
|
85
|
+
| hide | 是否隐藏(支持函数) | `boolean \| () => boolean` | `false` |
|
|
86
|
+
| permission | 权限标识 | `string` | - |
|
|
87
|
+
| confirm | 是否需要确认 | `boolean` | `false` |
|
|
88
|
+
| confirmText | 确认提示文本 | `string` | `'确定要${name}吗?'` |
|
|
89
|
+
| onClick | 点击回调 | `(e: MouseEvent \| TableScope) => void` | - |
|
|
53
90
|
|
|
54
91
|
## 带确认弹窗
|
|
55
92
|
|
|
@@ -58,9 +95,7 @@ const buttons = [
|
|
|
58
95
|
{
|
|
59
96
|
name: '删除',
|
|
60
97
|
prop: 'delete',
|
|
61
|
-
type: 'danger',
|
|
62
98
|
confirm: true,
|
|
63
|
-
confirmText: '确定要删除吗?',
|
|
64
99
|
onClick: () => {
|
|
65
100
|
// 删除逻辑
|
|
66
101
|
},
|
|
@@ -68,6 +103,18 @@ const buttons = [
|
|
|
68
103
|
]
|
|
69
104
|
```
|
|
70
105
|
|
|
106
|
+
> **⚠️ 注意:需要确认弹窗时,必须使用 `confirm: true` 属性,禁止手动编写 `ElMessageBox.confirm`**
|
|
107
|
+
>
|
|
108
|
+
> **正确做法**:
|
|
109
|
+
> ```tsx
|
|
110
|
+
> { name: '取消审批', confirm: true, onClick: () => { ElMessage.success('成功') } }
|
|
111
|
+
> ```
|
|
112
|
+
>
|
|
113
|
+
> **错误做法**:
|
|
114
|
+
> ```tsx
|
|
115
|
+
> { name: '取消审批', onClick: () => { ElMessageBox.confirm(...).then(...) } }
|
|
116
|
+
> ```
|
|
117
|
+
|
|
71
118
|
## 权限控制
|
|
72
119
|
|
|
73
120
|
```tsx
|
|
@@ -101,7 +148,7 @@ const buttons = [
|
|
|
101
148
|
{
|
|
102
149
|
name: '审核',
|
|
103
150
|
prop: 'audit',
|
|
104
|
-
|
|
151
|
+
show: () => formData.status === 'pending',
|
|
105
152
|
onClick: () => {},
|
|
106
153
|
},
|
|
107
154
|
]
|
package/docs/components/form.md
CHANGED
|
@@ -42,10 +42,28 @@ const formItemList = ref<FormProps['formItemList']>([
|
|
|
42
42
|
```
|
|
43
43
|
## 表单数据
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
**不需要预定义表单字段**,`reactive({})` 即可,组件会自动管理字段值。
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// ✅ 正确:无需预定义字段
|
|
49
|
+
const formData = reactive({})
|
|
50
|
+
|
|
51
|
+
// ❌ 错误:不需要提前声明所有字段
|
|
52
|
+
const formData = reactive({
|
|
53
|
+
name: '',
|
|
54
|
+
status: '',
|
|
55
|
+
applicant: '',
|
|
56
|
+
// ...
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**仅需预定义以下特殊字段:**
|
|
61
|
+
|
|
62
|
+
| 场景 | 需预定义的字段 | 示例 |
|
|
63
|
+
|------|---------------|------|
|
|
64
|
+
| 日期范围 | 开始和结束两个独立字段 | `orderDateStart: ''`, `orderDateEnd: ''` |
|
|
65
|
+
| 表格数组 | 空数组 | `detailList: []` |
|
|
66
|
+
| 附件数组 | 空数组 | `fileList: []` |
|
|
49
67
|
|
|
50
68
|
## Props
|
|
51
69
|
|
|
@@ -72,7 +90,8 @@ const formItemList = ref<FormProps['formItemList']>([
|
|
|
72
90
|
| label | 标签文本 | `string` | - |
|
|
73
91
|
| col | 占用列数 | `number` | - |
|
|
74
92
|
| disabled | 是否禁用 | `boolean` | `false` |
|
|
75
|
-
|
|
|
93
|
+
| show | 是否显示(支持函数) | `boolean \| () => boolean` | `true` |
|
|
94
|
+
| hide | 是否隐藏(支持函数) | `boolean \| () => boolean` | `false` |
|
|
76
95
|
| required | 是否必填 | `boolean` | `false` |
|
|
77
96
|
| rules | 校验规则 | `FormItemRule[]` | - |
|
|
78
97
|
| props | 传递给组件的属性 | `object` | - |
|
|
@@ -92,3 +92,26 @@ const attachmentProps: HeaderProps['attachmentProps'] = {
|
|
|
92
92
|
}
|
|
93
93
|
</script>
|
|
94
94
|
```
|
|
95
|
+
|
|
96
|
+
## 在 Form 中使用
|
|
97
|
+
|
|
98
|
+
EpHeader 也可以作为表单项放入 EpForm 中,作为表单的一部分:
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
const formItemList = ref<FormProps['formItemList']>([
|
|
102
|
+
{
|
|
103
|
+
col: 24,
|
|
104
|
+
type: 'EpHeader',
|
|
105
|
+
props: {
|
|
106
|
+
buttons: [
|
|
107
|
+
{ name: '提交审批', type: 'primary', onClick: () => {} },
|
|
108
|
+
{ name: '取消审批', onClick: () => {} },
|
|
109
|
+
{ name: '作废', onClick: () => {} },
|
|
110
|
+
],
|
|
111
|
+
isShowAttachmentButton: true,
|
|
112
|
+
fileList: formData.fileList,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
// 其他表单项...
|
|
116
|
+
])
|
|
117
|
+
```
|
|
@@ -57,7 +57,7 @@ const handleAdd = () => {}
|
|
|
57
57
|
| reqParams | URL 参数 | `object` | `{}` |
|
|
58
58
|
| reqBefore | 请求前处理 | `(reqData) => reqData` | - |
|
|
59
59
|
| reqAfter | 响应后处理 | `(res) => data` | - |
|
|
60
|
-
| formData |
|
|
60
|
+
| formData | 表单数据,参考 [EpForm 表单数据说明](./form.md#表单数据) | `object` | `{}` |
|
|
61
61
|
| formItemList | 搜索表单配置 | [`FormItemProps[]`](./form.md#formitemprops-配置) | `[]` |
|
|
62
62
|
| columns | 表格列配置(有customColumnModule就不需要定义列) | [`TableColumn[]`](./table.md#tablecolumn-配置) | `[]` |
|
|
63
63
|
| leftButtons | 左侧按钮 | [`ButtonProps[]`](./buttons.md#buttonprops-配置) | `[]` |
|
|
@@ -77,5 +77,15 @@ const handleAdd = () => {}
|
|
|
77
77
|
| buttonsProps | 按钮组额外属性 | `object` | - |
|
|
78
78
|
| name | 权限前缀 | `string` | - |
|
|
79
79
|
| customColumnModule | 自定义列模块 | `string \| number` | - |
|
|
80
|
+
|
|
81
|
+
::: warning 互斥关系
|
|
82
|
+
`customColumnModule` 和以下配置是**互斥**的:
|
|
83
|
+
- `columns`:设置了 `customColumnModule` 后会忽略 `columns`
|
|
84
|
+
- `leftButtons` 中的"自定义列设置"按钮:组件会自动内置该按钮
|
|
85
|
+
|
|
86
|
+
**正确用法**:
|
|
87
|
+
- 启用自定义列:`customColumnModule: "moduleName"`(无需配 columns 和自定义列按钮)
|
|
88
|
+
- 固定列模式:不设置 `customColumnModule`,使用 `columns` 配置
|
|
89
|
+
:::
|
|
80
90
|
| customColumnApi | 自定义列接口 | `string` | - |
|
|
81
91
|
| customColumnSaveApi | 自定义列保存接口 | `string` | - |
|
package/docs/components/table.md
CHANGED
|
@@ -78,7 +78,8 @@ const actionButtons = [
|
|
|
78
78
|
| headerRender | 自定义表头渲染 | `() => VNode` |
|
|
79
79
|
| required | 是否必填 | `boolean \| () => boolean` |
|
|
80
80
|
| disabled | 是否禁用 | `boolean \| (scope) => boolean` |
|
|
81
|
-
|
|
|
81
|
+
| show | 是否显示(支持函数) | `boolean \| () => boolean` |
|
|
82
|
+
| hide | 是否隐藏(支持函数) | `boolean \| () => boolean` |
|
|
82
83
|
| filter | 显示筛选 | `boolean` |
|
|
83
84
|
| editable | 可批量编辑 | `boolean` |
|
|
84
85
|
|
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
<script setup lang="tsx">
|
|
14
14
|
import { useFormDialog } from 'el-plus'
|
|
15
15
|
|
|
16
|
-
const formItemList = [
|
|
17
|
-
{ prop: 'name', label: '姓名', required: true },
|
|
18
|
-
{ prop: 'age', label: '年龄' },
|
|
19
|
-
]
|
|
20
16
|
|
|
21
17
|
const FormDialog = useFormDialog({
|
|
22
18
|
title: '用户信息',
|
|
23
|
-
formItemList
|
|
19
|
+
formItemList:[
|
|
20
|
+
{ prop: 'name', label: '姓名', required: true },
|
|
21
|
+
{ prop: 'age', label: '年龄' },
|
|
22
|
+
],
|
|
24
23
|
dialogProps: {
|
|
25
24
|
destroyOnClose: true, // 关闭时销毁对话框内容
|
|
26
25
|
},
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# useNavigation 导航
|
|
2
|
+
|
|
3
|
+
提供路由导航、标签页管理和页面模式控制等功能。
|
|
4
|
+
|
|
5
|
+
## 基本用法
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<template>
|
|
9
|
+
<div>
|
|
10
|
+
<el-button @click="handleEdit">编辑</el-button>
|
|
11
|
+
<el-button @click="handleGoto">跳转新页面</el-button>
|
|
12
|
+
<el-button @click="handleClose">关闭当前页</el-button>
|
|
13
|
+
</div>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script setup lang="ts">
|
|
17
|
+
import { useNavigation } from 'el-plus'
|
|
18
|
+
|
|
19
|
+
const { $goto, $closeTag, mode, setMode, isBrowse, isEdit, isAdd } = useNavigation({
|
|
20
|
+
onModeChange: (newMode) => {
|
|
21
|
+
console.log('模式变化:', newMode)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
// 编辑模式
|
|
26
|
+
const handleEdit = () => {
|
|
27
|
+
setMode('edit')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 跳转到新页面
|
|
31
|
+
const handleGoto = () => {
|
|
32
|
+
$goto({
|
|
33
|
+
name: 'detail',
|
|
34
|
+
query: { id: '123' }
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 关闭当前标签页
|
|
39
|
+
const handleClose = () => {
|
|
40
|
+
$closeTag()
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 参数
|
|
46
|
+
|
|
47
|
+
### Config 配置
|
|
48
|
+
|
|
49
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
50
|
+
|------|------|------|--------|
|
|
51
|
+
| onModeChange | 模式变化时的回调函数 | `(mode: PageMode) => void` | - |
|
|
52
|
+
|
|
53
|
+
## 返回值
|
|
54
|
+
|
|
55
|
+
| 属性 | 说明 | 类型 |
|
|
56
|
+
|------|------|------|
|
|
57
|
+
| $goto | 打开新窗口或跳转路由 | `(config: NavigationConfig) => void` |
|
|
58
|
+
| $closeTag | 关闭当前标签页 | `() => void` |
|
|
59
|
+
| mode | 当前页面模式 | `ComputedRef<PageMode>` |
|
|
60
|
+
| isBrowse | 是否为浏览模式 | `ComputedRef<boolean>` |
|
|
61
|
+
| isEdit | 是否为编辑模式 | `ComputedRef<boolean>` |
|
|
62
|
+
| isAdd | 是否为新增模式 | `ComputedRef<boolean>` |
|
|
63
|
+
| setMode | 设置页面模式 | `(mode: PageMode, callback?: (mode: PageMode) => void) => void` |
|
|
64
|
+
|
|
65
|
+
## 类型定义
|
|
66
|
+
|
|
67
|
+
### PageMode
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
type PageMode = 'add' | 'edit' | 'browse'
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### NavigationConfig
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
interface NavigationConfig {
|
|
77
|
+
id?: number | string // 菜单id
|
|
78
|
+
name?: string // 路由模块name,适用于内部跳转
|
|
79
|
+
title?: string // 菜单名称,适用于传外部url跳转
|
|
80
|
+
url?: string // 菜单url
|
|
81
|
+
query?: Record<string, any> // url参数
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## 功能说明
|
|
86
|
+
|
|
87
|
+
### $goto 路由跳转
|
|
88
|
+
|
|
89
|
+
支持两种跳转方式:
|
|
90
|
+
|
|
91
|
+
**内部路由跳转**
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
$goto({
|
|
95
|
+
name: 'userDetail',
|
|
96
|
+
query: { id: '123', mode: 'browse' }
|
|
97
|
+
})
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**外部URL跳转**
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
$goto({
|
|
104
|
+
url: 'https://example.com',
|
|
105
|
+
title: '外部链接'
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### setMode 模式切换
|
|
110
|
+
|
|
111
|
+
用于详情页的模式切换,自动更新URL参数并触发回调。
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// 切换到编辑模式
|
|
115
|
+
setMode('edit')
|
|
116
|
+
|
|
117
|
+
// 切换并执行回调
|
|
118
|
+
setMode('edit', (mode) => {
|
|
119
|
+
console.log('已切换到编辑模式')
|
|
120
|
+
})
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### $closeTag 关闭标签页
|
|
124
|
+
|
|
125
|
+
关闭当前标签页并自动切换到前一个标签页,需要在支持标签页管理的环境中使用。
|
|
126
|
+
|
|
127
|
+
## 注意事项
|
|
128
|
+
|
|
129
|
+
- 该 hook 依赖 `vue-router`,必须在路由环境中使用
|
|
130
|
+
- `$closeTag` 方法依赖父窗口的标签页管理功能
|
|
131
|
+
- `setMode` 会修改URL的query参数,刷新页面后模式会保持
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# useUtils 工具函数
|
|
2
|
+
|
|
3
|
+
提供常用的工具函数集合,包括时间处理、文件操作、Cookie管理等。
|
|
4
|
+
|
|
5
|
+
## 基本用法
|
|
6
|
+
|
|
7
|
+
```vue
|
|
8
|
+
<script setup lang="ts">
|
|
9
|
+
import { useUtils } from 'el-plus'
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
getUnifyTime,
|
|
13
|
+
dayjs,
|
|
14
|
+
importFile,
|
|
15
|
+
downloadFile,
|
|
16
|
+
previewFile,
|
|
17
|
+
Cookies
|
|
18
|
+
} = useUtils()
|
|
19
|
+
|
|
20
|
+
// 时间格式化
|
|
21
|
+
const time = getUnifyTime('2024-01-01')
|
|
22
|
+
const formatted = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
23
|
+
|
|
24
|
+
// 文件导入
|
|
25
|
+
importFile().then(file => {
|
|
26
|
+
console.log('导入的文件:', file)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
// 文件下载
|
|
30
|
+
downloadFile({ url: '/api/download', filename: 'test.xlsx' })
|
|
31
|
+
|
|
32
|
+
// 文件预览
|
|
33
|
+
previewFile('/files/document.pdf')
|
|
34
|
+
|
|
35
|
+
// Cookie 操作
|
|
36
|
+
Cookies.set('token', 'xxx')
|
|
37
|
+
const token = Cookies.get('token')
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 返回值
|
|
42
|
+
|
|
43
|
+
| 属性 | 说明 | 类型 |
|
|
44
|
+
|------|------|------|
|
|
45
|
+
| getUnifyTime | 统一时间处理函数 | `(time: string \| number \| Date) => string` |
|
|
46
|
+
| dayjs | Day.js 实例 | `typeof dayjs` |
|
|
47
|
+
| importFile | 文件导入函数 | `() => Promise<File>` |
|
|
48
|
+
| downloadFile | 文件下载函数 | `(config: DownloadConfig) => void` |
|
|
49
|
+
| previewFile | 文件预览函数 | `(url: string) => void` |
|
|
50
|
+
| Cookies | Cookie 操作对象 | `CookiesStatic` |
|
|
51
|
+
|
|
52
|
+
## 功能说明
|
|
53
|
+
|
|
54
|
+
### getUnifyTime 时间处理
|
|
55
|
+
|
|
56
|
+
统一时间格式处理函数。
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
// 时间戳转格式化字符串
|
|
60
|
+
const time1 = getUnifyTime(1609459200000)
|
|
61
|
+
|
|
62
|
+
// Date对象转格式化字符串
|
|
63
|
+
const time2 = getUnifyTime(new Date())
|
|
64
|
+
|
|
65
|
+
// 字符串转格式化字符串
|
|
66
|
+
const time3 = getUnifyTime('2024-01-01')
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### dayjs 日期处理
|
|
70
|
+
|
|
71
|
+
提供 Day.js 的所有功能,用于日期格式化和计算。
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
// 格式化当前时间
|
|
75
|
+
const now = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
76
|
+
|
|
77
|
+
// 日期计算
|
|
78
|
+
const tomorrow = dayjs().add(1, 'day')
|
|
79
|
+
const lastMonth = dayjs().subtract(1, 'month')
|
|
80
|
+
|
|
81
|
+
// 日期比较
|
|
82
|
+
const isBefore = dayjs('2024-01-01').isBefore(dayjs())
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### importFile 文件导入
|
|
86
|
+
|
|
87
|
+
打开文件选择器,返回选择的文件对象。
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
importFile().then(file => {
|
|
91
|
+
console.log('文件名:', file.name)
|
|
92
|
+
console.log('文件大小:', file.size)
|
|
93
|
+
console.log('文件类型:', file.type)
|
|
94
|
+
})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### downloadFile 文件下载
|
|
98
|
+
|
|
99
|
+
触发文件下载。
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
downloadFile({
|
|
103
|
+
url: '/api/export',
|
|
104
|
+
filename: '导出数据.xlsx',
|
|
105
|
+
params: { id: '123' } // 可选的请求参数
|
|
106
|
+
})
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### previewFile 文件预览
|
|
110
|
+
|
|
111
|
+
在新窗口中预览文件。
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
// PDF预览
|
|
115
|
+
previewFile('/files/document.pdf')
|
|
116
|
+
|
|
117
|
+
// 图片预览
|
|
118
|
+
previewFile('/images/photo.jpg')
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Cookies Cookie管理
|
|
122
|
+
|
|
123
|
+
提供 Cookie 的增删改查操作。
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
// 设置 Cookie
|
|
127
|
+
Cookies.set('token', 'xxx', { expires: 7 }) // 7天后过期
|
|
128
|
+
|
|
129
|
+
// 获取 Cookie
|
|
130
|
+
const token = Cookies.get('token')
|
|
131
|
+
|
|
132
|
+
// 删除 Cookie
|
|
133
|
+
Cookies.remove('token')
|
|
134
|
+
|
|
135
|
+
// 获取所有 Cookie
|
|
136
|
+
const allCookies = Cookies.get()
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 注意事项
|
|
140
|
+
|
|
141
|
+
- `importFile` 会打开系统文件选择器
|
|
142
|
+
- `downloadFile` 支持跨域下载,会自动处理 blob 响应
|
|
143
|
+
- `previewFile` 会打开新窗口或标签页
|
|
144
|
+
- `Cookies` 基于 js-cookie 库,支持所有其配置选项
|