general-basic-form 2.0.61 → 2.0.63
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.assets/image-20210820173738506.png +0 -0
- package/README.md +16 -2
- package/package.json +55 -64
- package/script/link.ts +36 -0
- package/script/unlink.ts +45 -0
- package/src/Descriptions.vue +107 -0
- package/src/GeneralBasicForm.vue +240 -0
- package/src/InfiniteScrollList.vue +163 -0
- package/src/assets/image-20210820173037871.png +0 -0
- package/src/assets/logo.png +0 -0
- package/src/components/CustomCom/img-mask/index.vue +79 -0
- package/src/components/CustomCom/input-graphic-verification/index.vue +81 -0
- package/src/components/CustomCom/input-mobile-verification/index.vue +56 -0
- package/src/components/CustomCom/input-mobile-verification/verification-button.vue +82 -0
- package/src/components/VABasic/input/index.vue +75 -0
- package/src/components/VBasic/cascader/index.vue +32 -0
- package/src/components/VBasic/checkbox/index.vue +37 -0
- package/src/components/VBasic/date-picker/index.vue +31 -0
- package/src/components/VBasic/divider/index.vue +53 -0
- package/src/components/VBasic/input/index.vue +67 -0
- package/src/components/VBasic/input-number/index.vue +31 -0
- package/src/components/VBasic/radio/index.vue +37 -0
- package/src/components/VBasic/select/index.vue +37 -0
- package/src/components/setting.ts +28 -0
- package/src/index.ts +30 -0
- package/src/injectKey.ts +2 -0
- package/src/types/basicFrom.ts +63 -0
- package/src/types/componentType.ts +6 -0
- package/src/types/componentsProps.ts +18 -0
- package/tsconfig.json +14 -0
- package/vite.config.js +123 -0
- package/dist/index.js +0 -1012
- package/dist/index.umd.cjs +0 -1
- package/dist/style.css +0 -1
- /package/{dist → public}/index.d.ts +0 -0
|
Binary file
|
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
| VInputMobilecVerification | | √ | √ | √ | |
|
|
12
12
|
| VInputGraphicVerification | | √ | √ | √ | |
|
|
13
13
|
| VTreeTransfer | √ | | | | √ |
|
|
14
|
+
| VTabs | √ | | | | √ |
|
|
14
15
|
|
|
15
16
|
示例:
|
|
16
17
|
|
|
@@ -117,7 +118,7 @@ getList会传出默认的参数,首次请求时会有页数和分页大小,重
|
|
|
117
118
|
const params = VGeneralBasicFormRef.value['queryParams']
|
|
118
119
|
resolve(params)
|
|
119
120
|
} else {
|
|
120
|
-
|
|
121
|
+
reject()
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
)
|
|
@@ -126,17 +127,30 @@ getList会传出默认的参数,首次请求时会有页数和分页大小,重
|
|
|
126
127
|
|
|
127
128
|

|
|
128
129
|
|
|
130
|
+
parametersType类型介绍
|
|
131
|
+
|
|
132
|
+
| parametersType形式 | 支持页面刷新 | 参数改变引起路由跳转 | 组件间共享数据 | 存储上限 | 浏览器兼容性 |
|
|
133
|
+
| ------------------ | ------------ | -------------------- | -------------- | -------- | ------------ |
|
|
134
|
+
| url | 是 | 是 | 是 | 中 | 高 |
|
|
135
|
+
| data | 否 | 否 | 否 | 高 | 高 |
|
|
136
|
+
| indexDB | 是 | 否 | 是 | 高 | 中 |
|
|
137
|
+
|
|
129
138
|
数据示例:
|
|
130
139
|
|
|
131
140
|
showSearch: true, // 显示搜索条件
|
|
132
141
|
getList(); // 请求数据的函数
|
|
133
142
|
afterReset(); // 在重置按钮点击完后但还没重新请求时触发的的函数
|
|
134
143
|
formOnly:true // 只展示表单不展示按钮
|
|
135
|
-
|
|
144
|
+
parametersType:"url" // 见parametersType类型介绍
|
|
136
145
|
loading:false // 加载动画
|
|
137
146
|
formData:{} // 注意,因为可能出现的性能问题在组件watch formData的变化时没有使用deep,所以有时候深度的修改会不生效,导致表单数据不完整
|
|
138
147
|
noInputBlank: true //校验input框不能仅输入空格
|
|
139
148
|
//例子:formData.value.x=y ✘ | formData.value={...formData.value,x:y} ✔
|
|
149
|
+
currentPageKey:"page", //当前页数key
|
|
150
|
+
pageSizeKey:"limit", //每页显示个数key
|
|
151
|
+
defCurrentPage:1, //默认的页数
|
|
152
|
+
defPageSize:10, //默认的每页显示个数
|
|
153
|
+
queryWhenReady:false,//初始化完成后自动触发查找数据函数,建议用这个this.$refs["VGeneralBasicFormRef"].handleQuery({ defaultPageFirst: false })
|
|
140
154
|
formItem: [
|
|
141
155
|
{
|
|
142
156
|
label: '',
|
package/package.json
CHANGED
|
@@ -1,64 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "general-basic-form",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "./
|
|
6
|
-
"type": "module",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "cross-env CURRENT_ENV=prod run-p type-check build-only",
|
|
9
|
-
"test:e2e": "playwright test",
|
|
10
|
-
"build-only": "vite build",
|
|
11
|
-
"type-check": "tsc --noEmit -p tsconfig.json --composite false",
|
|
12
|
-
"link": "tsx script/link.ts && yarn link",
|
|
13
|
-
"unlink": "tsx script/unlink.ts && yarn unlink && run-p build",
|
|
14
|
-
"unlinkSetting": "tsx script/unlink.ts"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"general-basic-form",
|
|
18
|
-
"form",
|
|
19
|
-
"vue",
|
|
20
|
-
"vue2",
|
|
21
|
-
"vue3",
|
|
22
|
-
"element-plus"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@vitejs/plugin-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"./style": "./dist/style.css"
|
|
57
|
-
},
|
|
58
|
-
"files": [
|
|
59
|
-
"/dist"
|
|
60
|
-
],
|
|
61
|
-
"dependencies": {
|
|
62
|
-
"network-spanner": "^1.2.8"
|
|
63
|
-
}
|
|
64
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "general-basic-form",
|
|
3
|
+
"version": "2.0.63",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "cross-env CURRENT_ENV=prod run-p type-check build-only",
|
|
9
|
+
"test:e2e": "playwright test",
|
|
10
|
+
"build-only": "vite build",
|
|
11
|
+
"type-check": "tsc --noEmit -p tsconfig.json --composite false",
|
|
12
|
+
"link": "tsx script/link.ts && yarn link",
|
|
13
|
+
"unlink": "tsx script/unlink.ts && yarn unlink && run-p build",
|
|
14
|
+
"unlinkSetting": "tsx script/unlink.ts"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"general-basic-form",
|
|
18
|
+
"form",
|
|
19
|
+
"vue",
|
|
20
|
+
"vue2",
|
|
21
|
+
"vue3",
|
|
22
|
+
"element-plus",
|
|
23
|
+
"element-ui",
|
|
24
|
+
"Ant Design Vue"
|
|
25
|
+
],
|
|
26
|
+
"author": "chendeli419287484@qq.com",
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/Alan1034/GeneralBasicForm.git"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@playwright/test": "^1.36.1",
|
|
34
|
+
"@types/node": "^20.8.10",
|
|
35
|
+
"@vitejs/plugin-legacy": "^4.1.1",
|
|
36
|
+
"@vitejs/plugin-vue": "^4.2.3",
|
|
37
|
+
"@vitejs/plugin-vue-jsx": "^3.0.1",
|
|
38
|
+
"chalk": "^2.4.2",
|
|
39
|
+
"cross-env": "^7.0.3",
|
|
40
|
+
"less": "^4.2.0",
|
|
41
|
+
"npm-run-all": "^4.1.5",
|
|
42
|
+
"tsx": "^4.0.0",
|
|
43
|
+
"typescript": "^5.2.2",
|
|
44
|
+
"vite-plugin-image-optimizer": "^1.1.6"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"element-plus": ">=2.6.0",
|
|
48
|
+
"vue": ">=3.3.4",
|
|
49
|
+
"vue-router": ">=4.2.4"
|
|
50
|
+
},
|
|
51
|
+
"typings": "./publish/index.d.ts",
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"network-spanner": "^1.2.14"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/script/link.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 陈德立*******419287484@qq.com
|
|
3
|
+
* @Date: 2023-11-10 09:39:59
|
|
4
|
+
* @LastEditTime: 2023-11-15 18:04:19
|
|
5
|
+
* @LastEditors: 陈德立*******419287484@qq.com
|
|
6
|
+
* @Github: https://github.com/Alan1034
|
|
7
|
+
* @Description: link处理流程
|
|
8
|
+
* @FilePath: \GeneralBasicForm\script\link.ts
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import path from "path";
|
|
12
|
+
import fs from 'fs'
|
|
13
|
+
import chalk from 'chalk'
|
|
14
|
+
import { fileURLToPath } from 'url'
|
|
15
|
+
const __filenameNew = fileURLToPath(import.meta.url)
|
|
16
|
+
const __dirnameNew = path.dirname(__filenameNew)
|
|
17
|
+
const updateMain = () => {
|
|
18
|
+
try {
|
|
19
|
+
const packageTxt = fs.readFileSync(path.join(__dirnameNew, '../package.json'), 'utf8');
|
|
20
|
+
const packageJson = JSON.parse(packageTxt);
|
|
21
|
+
const mainDir = "./src/index.ts"
|
|
22
|
+
delete packageJson.files
|
|
23
|
+
delete packageJson.module
|
|
24
|
+
delete packageJson.exports
|
|
25
|
+
packageJson.typings = "./publish/index.d.ts"
|
|
26
|
+
packageJson.main = mainDir
|
|
27
|
+
const versionData = JSON.stringify(packageJson, null, 2);
|
|
28
|
+
fs.writeFileSync(path.join(__dirnameNew, '../package.json'), versionData, 'utf8');
|
|
29
|
+
console.log(chalk.green.bold('修改入口配置成功!当前入口路径为为:' + mainDir));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.log(chalk.red.bold('修改入口配置出错:', error.toString()));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
updateMain()
|
package/script/unlink.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @Author: 陈德立*******419287484@qq.com
|
|
3
|
+
* @Date: 2023-11-10 09:39:59
|
|
4
|
+
* @LastEditTime: 2023-11-16 15:09:53
|
|
5
|
+
* @LastEditors: 陈德立*******419287484@qq.com
|
|
6
|
+
* @Github: https://github.com/Alan1034
|
|
7
|
+
* @Description: unlink处理流程
|
|
8
|
+
* @FilePath: \GeneralBasicForm\script\unlink.ts
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
import path from "path";
|
|
12
|
+
import fs from 'fs'
|
|
13
|
+
import chalk from 'chalk'
|
|
14
|
+
import { fileURLToPath } from 'url'
|
|
15
|
+
const __filenameNew = fileURLToPath(import.meta.url)
|
|
16
|
+
const __dirnameNew = path.dirname(__filenameNew)
|
|
17
|
+
const updateMain = () => {
|
|
18
|
+
try {
|
|
19
|
+
const packageTxt = fs.readFileSync(path.join(__dirnameNew, '../package.json'), 'utf8');
|
|
20
|
+
const packageJson = JSON.parse(packageTxt);
|
|
21
|
+
const umdDir = "./dist/index.umd.cjs"
|
|
22
|
+
const esDir = "./dist/index.js"
|
|
23
|
+
packageJson.main = umdDir
|
|
24
|
+
packageJson.module = esDir
|
|
25
|
+
packageJson.exports = {
|
|
26
|
+
".": {
|
|
27
|
+
"import": esDir,
|
|
28
|
+
"require": umdDir
|
|
29
|
+
},
|
|
30
|
+
"./style": "./dist/style.css"
|
|
31
|
+
}
|
|
32
|
+
packageJson.typings = "./dist/index.d.ts"
|
|
33
|
+
packageJson.files = [
|
|
34
|
+
"/dist"
|
|
35
|
+
]
|
|
36
|
+
const versionData = JSON.stringify(packageJson, null, 2);
|
|
37
|
+
fs.writeFileSync(path.join(__dirnameNew, '../package.json'), versionData, 'utf8');
|
|
38
|
+
console.log(chalk.green.bold('修改入口配置成功!当前入口路径为为:' + umdDir));
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log(chalk.red.bold('修改入口配置出错:', error.toString()));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
updateMain()
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: 陈德立*******419287484@qq.com
|
|
3
|
+
* @Date: 2023-12-08 17:45:01
|
|
4
|
+
* @LastEditTime: 2024-09-25 18:16:46
|
|
5
|
+
* @LastEditors: 陈德立*******419287484@qq.com
|
|
6
|
+
* @Github: https://github.com/Alan1034
|
|
7
|
+
* @Description: 对展示描述列表的封装
|
|
8
|
+
* @FilePath: \GeneralBasicForm\src\Descriptions.vue
|
|
9
|
+
*
|
|
10
|
+
-->
|
|
11
|
+
<template>
|
|
12
|
+
<component :is="descriptions" :column="1" border class="form-width" v-bind="$attrs">
|
|
13
|
+
<component :is="descriptionsItem" v-for="(item, i) in renderFormItem" :key="item.prop" :label="item.label"
|
|
14
|
+
v-bind="item.descriptionsItemProps">
|
|
15
|
+
<RenderComponent v-if="item.render" :i="i" :render="item.render" :formData="formData"></RenderComponent>
|
|
16
|
+
<span v-else>
|
|
17
|
+
{{ formData[item.prop] }}
|
|
18
|
+
</span>
|
|
19
|
+
</component>
|
|
20
|
+
</component>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script lang="ts" setup>
|
|
24
|
+
import type { PropType, FunctionalComponent, VNode } from "vue";
|
|
25
|
+
import { shallowRef, watch, ref } from "vue";
|
|
26
|
+
import type { ComponentType } from "./types/componentType"
|
|
27
|
+
import type { ItemType } from "./types/basicFrom";
|
|
28
|
+
const props = defineProps({
|
|
29
|
+
formData: {
|
|
30
|
+
type: Object,
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
formItem: {
|
|
34
|
+
type: Array as unknown as PropType<ItemType[]>,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
componentType: {
|
|
38
|
+
type: String as unknown as PropType<ComponentType>,
|
|
39
|
+
default: "Element Plus"
|
|
40
|
+
},
|
|
41
|
+
strict: {
|
|
42
|
+
// 使用strict参数后,如果formData内的某个字段没有值,对应的描述元素将不会展示(包括标签文字),但有render的字段仍然会展示
|
|
43
|
+
type: Boolean,
|
|
44
|
+
default: false
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const renderFormItem = ref<ItemType[]>([])
|
|
48
|
+
watch(
|
|
49
|
+
() => [props.formData, props.formItem],
|
|
50
|
+
([NewFormData = {}, NewFormItem = <any>[]]) => {
|
|
51
|
+
let PhasedFormItem = NewFormItem
|
|
52
|
+
if (props.strict) {
|
|
53
|
+
// strict严格模式过滤formItem
|
|
54
|
+
// console.log(NewFormData)
|
|
55
|
+
// console.log(PhasedFormItem)
|
|
56
|
+
for (const key in NewFormData) {
|
|
57
|
+
if (Object.prototype.hasOwnProperty.call(NewFormData, key)) {
|
|
58
|
+
const element = NewFormData[key];
|
|
59
|
+
if (!element) {
|
|
60
|
+
PhasedFormItem = PhasedFormItem.filter((item) => {
|
|
61
|
+
return ((item.prop !== key) || (item.render))
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
// console.log(PhasedFormItem)
|
|
70
|
+
renderFormItem.value = PhasedFormItem
|
|
71
|
+
},
|
|
72
|
+
{ immediate: true }
|
|
73
|
+
);
|
|
74
|
+
const descriptions = shallowRef("el-descriptions-item")
|
|
75
|
+
const descriptionsItem = shallowRef("descriptions-item")
|
|
76
|
+
switch (props.componentType) {
|
|
77
|
+
case "Element Plus":
|
|
78
|
+
descriptions.value = "el-descriptions-item"
|
|
79
|
+
descriptionsItem.value = "el-descriptions-item"
|
|
80
|
+
break;
|
|
81
|
+
case "Ant Design Vue":
|
|
82
|
+
descriptions.value = "a-descriptions"
|
|
83
|
+
descriptionsItem.value = "a-descriptions-item"
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
type RenderComponentProps = {
|
|
89
|
+
i: any;
|
|
90
|
+
formData: Object;
|
|
91
|
+
render: (item: any) => VNode | String;
|
|
92
|
+
};
|
|
93
|
+
type Events = {};
|
|
94
|
+
// 函数直接返回VNode模板会识别成[object Promise],因此需要转换成函数式组件
|
|
95
|
+
const RenderComponent: FunctionalComponent<RenderComponentProps, Events> = (
|
|
96
|
+
props,
|
|
97
|
+
context
|
|
98
|
+
) => {
|
|
99
|
+
const { i, render, formData } = props;
|
|
100
|
+
return render({
|
|
101
|
+
row: formData,
|
|
102
|
+
$index: i,
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<style></style>
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: 陈德立*******419287484@qq.com
|
|
3
|
+
* @Date: 2021-08-20 17:14:53
|
|
4
|
+
* @LastEditTime: 2025-03-10 21:02:58
|
|
5
|
+
* @LastEditors: 陈德立*******419287484@qq.com
|
|
6
|
+
* @Github: https://github.com/Alan1034
|
|
7
|
+
* @Description:
|
|
8
|
+
* @FilePath: \GeneralBasicForm\src\GeneralBasicForm.vue
|
|
9
|
+
*
|
|
10
|
+
-->
|
|
11
|
+
/** 通用基本表单。用在表单页面搜索栏 */
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<el-form :model="queryParams" ref="queryFormRef" v-show="showSearch" inline label-position="left"
|
|
15
|
+
:label-width="labelWidth" v-bind="$attrs">
|
|
16
|
+
<el-form-item v-for="item in formItem" :label="item.label" :prop="item.prop" :key="item.prop"
|
|
17
|
+
:rules="getItemRules(item)">
|
|
18
|
+
<Input v-if="/^input$/i.test(item.type)" :item="item" />
|
|
19
|
+
<Radio v-if="/^radio$/i.test(item.type)" :item="item" />
|
|
20
|
+
<Select v-if="/^select$/i.test(item.type)" :item="item" />
|
|
21
|
+
<Divider v-if="/^divider$/i.test(item.type)" :item="item" />
|
|
22
|
+
<Cascader v-if="/^cascader$/i.test(item.type)" :item="item" />
|
|
23
|
+
<Checkbox v-if="/^checkbox$/i.test(item.type)" :item="item" />
|
|
24
|
+
<DatePicker v-if="/^date-picker$/i.test(item.type)" :item="item" />
|
|
25
|
+
<InputNumber v-if="/^input-number$/i.test(item.type)" :item="item" />
|
|
26
|
+
<slot v-if="/^form-item-slot$/i.test(item.type)" :name="item.name"></slot>
|
|
27
|
+
<InputMobileVerification v-if="/^input-mobile-verification$/i.test(item.type)" :item="item" />
|
|
28
|
+
<InputGraphicVerification v-if="/^input-graphic-verification$/i.test(item.type)" :item="item" :key="item.key" />
|
|
29
|
+
</el-form-item>
|
|
30
|
+
<slot></slot>
|
|
31
|
+
<el-form-item v-if="!formOnly">
|
|
32
|
+
<el-button type="primary" :size="size" @click="handleQuery" v-loading="formLoading">查询</el-button>
|
|
33
|
+
<el-button :size="size" @click="resetQuery">重置</el-button>
|
|
34
|
+
</el-form-item>
|
|
35
|
+
<slot name="behind-the-button" />
|
|
36
|
+
</el-form>
|
|
37
|
+
</template>
|
|
38
|
+
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
import { provide, ref, PropType, defineComponent, computed } from "vue";
|
|
41
|
+
import type { ItemType } from "./types/basicFrom";
|
|
42
|
+
// import { useRoute } from "vue-router";
|
|
43
|
+
import Input from "./components/VBasic/input/index.vue";
|
|
44
|
+
import InputNumber from "./components/VBasic/input-number/index.vue";
|
|
45
|
+
import InputGraphicVerification from "./components/CustomCom/input-graphic-verification/index.vue";
|
|
46
|
+
import InputMobileVerification from "./components/CustomCom/input-mobile-verification/index.vue";
|
|
47
|
+
import Divider from "./components/VBasic/divider/index.vue";
|
|
48
|
+
import Radio from "./components/VBasic/radio/index.vue";
|
|
49
|
+
import Checkbox from "./components/VBasic/checkbox/index.vue";
|
|
50
|
+
import DatePicker from "./components/VBasic/date-picker/index.vue";
|
|
51
|
+
import Select from "./components/VBasic/select/index.vue";
|
|
52
|
+
import Cascader from "./components/VBasic/cascader/index.vue";
|
|
53
|
+
import { formLoadingKey } from "./injectKey";
|
|
54
|
+
import { HandleParamsData } from "network-spanner"
|
|
55
|
+
export default defineComponent({
|
|
56
|
+
name: "GeneralBasicForm",
|
|
57
|
+
components: {
|
|
58
|
+
Input,
|
|
59
|
+
InputNumber,
|
|
60
|
+
InputGraphicVerification,
|
|
61
|
+
InputMobileVerification,
|
|
62
|
+
Divider,
|
|
63
|
+
Radio,
|
|
64
|
+
Checkbox,
|
|
65
|
+
DatePicker,
|
|
66
|
+
Select,
|
|
67
|
+
Cascader,
|
|
68
|
+
},
|
|
69
|
+
props: {
|
|
70
|
+
showSearch: {
|
|
71
|
+
// 是否展示所有元素
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: true,
|
|
74
|
+
},
|
|
75
|
+
loading: {
|
|
76
|
+
// 加载动画
|
|
77
|
+
type: Boolean,
|
|
78
|
+
default: false,
|
|
79
|
+
},
|
|
80
|
+
formOnly: {
|
|
81
|
+
// 是否只展示表单不展示按钮
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: false,
|
|
84
|
+
},
|
|
85
|
+
getList: {
|
|
86
|
+
// 查找数据调用的函数
|
|
87
|
+
type: Function,
|
|
88
|
+
default: () => { },
|
|
89
|
+
},
|
|
90
|
+
afterReset: {
|
|
91
|
+
// 在重置按钮点击完后但还没重新请求时触发的的函数
|
|
92
|
+
type: Function,
|
|
93
|
+
default: () => { },
|
|
94
|
+
},
|
|
95
|
+
formItem: {
|
|
96
|
+
// 定义表单的数据
|
|
97
|
+
type: Array as unknown as PropType<ItemType[]>,
|
|
98
|
+
default: () => [],
|
|
99
|
+
},
|
|
100
|
+
size: {
|
|
101
|
+
// 控制按钮大小
|
|
102
|
+
type: String,
|
|
103
|
+
default: "default",
|
|
104
|
+
},
|
|
105
|
+
labelWidth: {
|
|
106
|
+
// 表单文字宽度
|
|
107
|
+
type: String,
|
|
108
|
+
default: "90px",
|
|
109
|
+
},
|
|
110
|
+
parametersType: {
|
|
111
|
+
type: String,
|
|
112
|
+
default: "url",
|
|
113
|
+
},
|
|
114
|
+
DBPrimaryKey: {
|
|
115
|
+
// indexDB的primaryKey,一般配合parametersType==="indexDB"使用
|
|
116
|
+
type: [String, Number],
|
|
117
|
+
required: false,
|
|
118
|
+
},
|
|
119
|
+
formData: {
|
|
120
|
+
// 外部传入的表单数据,用于回填
|
|
121
|
+
type: Object,
|
|
122
|
+
default: () => { },
|
|
123
|
+
},
|
|
124
|
+
noInputBlank: {
|
|
125
|
+
// 用于判断input框是否校验仅空格
|
|
126
|
+
type: Boolean,
|
|
127
|
+
default: () => false,
|
|
128
|
+
},
|
|
129
|
+
currentPageKey: {
|
|
130
|
+
type: String,
|
|
131
|
+
default: "page",
|
|
132
|
+
},
|
|
133
|
+
pageSizeKey: {
|
|
134
|
+
type: String,
|
|
135
|
+
default: "limit",
|
|
136
|
+
},
|
|
137
|
+
defCurrentPage: {
|
|
138
|
+
type: Number,
|
|
139
|
+
default: 1,
|
|
140
|
+
},
|
|
141
|
+
defPageSize: {
|
|
142
|
+
type: Number,
|
|
143
|
+
default: 10,
|
|
144
|
+
},
|
|
145
|
+
queryWhenReady: {
|
|
146
|
+
// 初始化完成后自动触发查找数据函数
|
|
147
|
+
type: Boolean,
|
|
148
|
+
default: () => false,
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
data() {
|
|
152
|
+
return {
|
|
153
|
+
formLoading: this.loading || false,
|
|
154
|
+
queryParams: HandleParamsData.initQueryParams({
|
|
155
|
+
vm: this
|
|
156
|
+
}), // form表单数据
|
|
157
|
+
};
|
|
158
|
+
},
|
|
159
|
+
provide() {
|
|
160
|
+
return {
|
|
161
|
+
// 显式提供一个计算属性
|
|
162
|
+
[formLoadingKey]: {
|
|
163
|
+
formLoading: computed(() => this.formLoading),
|
|
164
|
+
updateFormLoading: (val) => {
|
|
165
|
+
this.formLoading = val;
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
// 使用computed保持响应性
|
|
169
|
+
queryParams: computed(() => this.queryParams),
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
setup(props) {
|
|
173
|
+
const { size, getList } = props;
|
|
174
|
+
provide(/* 注入名 */ "size", /* 值 */ size);
|
|
175
|
+
provide(/* 注入名 */ "getList", /* 值 */ getList);
|
|
176
|
+
},
|
|
177
|
+
watch: {
|
|
178
|
+
formData: {
|
|
179
|
+
handler(val, oldVal) {
|
|
180
|
+
if (JSON.stringify(val) !== JSON.stringify(this.queryParams)) {
|
|
181
|
+
this.queryParams = {
|
|
182
|
+
...this.queryParams,
|
|
183
|
+
...val,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
// console.log(this.queryParams);
|
|
187
|
+
},
|
|
188
|
+
// watch 默认是懒执行的:仅当数据源变化时,才会执行回调。但在某些场景中,我们希望在创建侦听器时,立即执行一遍回调。举例来说,我们想请求一些初始数据,然后在相关状态更改时重新请求数据。
|
|
189
|
+
// https://cn.vuejs.org/guide/essentials/watchers.html#deep-watchers
|
|
190
|
+
immediate: true,
|
|
191
|
+
deep: true,
|
|
192
|
+
},
|
|
193
|
+
queryParams: {
|
|
194
|
+
handler(val) {
|
|
195
|
+
this.$emit("update:formData", { ...val });
|
|
196
|
+
},
|
|
197
|
+
deep: true,
|
|
198
|
+
},
|
|
199
|
+
loading(val) {
|
|
200
|
+
// console.log("loading", val);
|
|
201
|
+
if (this.formLoading === val) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
this.formLoading = val;
|
|
205
|
+
},
|
|
206
|
+
formLoading(val) {
|
|
207
|
+
// console.log("formLoading", val);
|
|
208
|
+
if (this.loading === val) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
this.$emit("update:loading", val);
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
methods: {
|
|
216
|
+
/** 搜索按钮操作 */
|
|
217
|
+
handleQuery(queryParameter = <any>{}) {
|
|
218
|
+
HandleParamsData.handleQuery({
|
|
219
|
+
queryParameter, vm: this
|
|
220
|
+
})
|
|
221
|
+
},
|
|
222
|
+
/** 重置按钮操作 */
|
|
223
|
+
resetQuery() {
|
|
224
|
+
HandleParamsData.resetQuery({
|
|
225
|
+
vm: this
|
|
226
|
+
})
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
getItemRules(item: any) {
|
|
230
|
+
const newRules = HandleParamsData.getItemRules({
|
|
231
|
+
item,
|
|
232
|
+
vm: this
|
|
233
|
+
})
|
|
234
|
+
return newRules;
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
</script>
|
|
239
|
+
|
|
240
|
+
<style scoped></style>
|