@bdsoft/element 1.1.0
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 +90 -0
- package/global/index.ts +6 -0
- package/global/register-properties.ts +10 -0
- package/index.html +13 -0
- package/index.js +84 -0
- package/package-form/core/components/formCreate.js +274 -0
- package/package-form/core/components/fragment.js +12 -0
- package/package-form/core/factory/context.js +257 -0
- package/package-form/core/factory/creator.js +63 -0
- package/package-form/core/factory/maker.js +17 -0
- package/package-form/core/factory/manager.js +79 -0
- package/package-form/core/factory/node.js +85 -0
- package/package-form/core/factory/parser.js +28 -0
- package/package-form/core/frame/api.js +599 -0
- package/package-form/core/frame/attrs.js +12 -0
- package/package-form/core/frame/dataDriver.js +76 -0
- package/package-form/core/frame/fetch.js +119 -0
- package/package-form/core/frame/formCreate.js +274 -0
- package/package-form/core/frame/index.js +760 -0
- package/package-form/core/frame/provider.js +288 -0
- package/package-form/core/frame/util.js +274 -0
- package/package-form/core/handler/context.js +380 -0
- package/package-form/core/handler/effect.js +122 -0
- package/package-form/core/handler/index.js +111 -0
- package/package-form/core/handler/inject.js +145 -0
- package/package-form/core/handler/input.js +197 -0
- package/package-form/core/handler/lifecycle.js +43 -0
- package/package-form/core/handler/loader.js +373 -0
- package/package-form/core/handler/page.js +46 -0
- package/package-form/core/handler/render.js +29 -0
- package/package-form/core/index.js +12 -0
- package/package-form/core/package.json +15 -0
- package/package-form/core/parser/html.js +17 -0
- package/package-form/core/render/cache.js +47 -0
- package/package-form/core/render/index.js +31 -0
- package/package-form/core/render/render.js +393 -0
- package/package-form/element-form/components/checkbox/package.json +17 -0
- package/package-form/element-form/components/checkbox/src/component.jsx +110 -0
- package/package-form/element-form/components/checkbox/src/index.js +3 -0
- package/package-form/element-form/components/frame/package.json +17 -0
- package/package-form/element-form/components/frame/src/IconCircleClose.vue +14 -0
- package/package-form/element-form/components/frame/src/IconDelete.vue +12 -0
- package/package-form/element-form/components/frame/src/IconDocument.vue +12 -0
- package/package-form/element-form/components/frame/src/IconFolderOpened.vue +12 -0
- package/package-form/element-form/components/frame/src/IconView.vue +12 -0
- package/package-form/element-form/components/frame/src/component.jsx +349 -0
- package/package-form/element-form/components/frame/src/index.js +3 -0
- package/package-form/element-form/components/frame/src/style.css +66 -0
- package/package-form/element-form/components/group/package.json +17 -0
- package/package-form/element-form/components/group/src/component.jsx +314 -0
- package/package-form/element-form/components/group/src/index.js +3 -0
- package/package-form/element-form/components/group/src/style.css +125 -0
- package/package-form/element-form/components/index.js +22 -0
- package/package-form/element-form/components/radio/package.json +17 -0
- package/package-form/element-form/components/radio/src/component.jsx +101 -0
- package/package-form/element-form/components/radio/src/index.js +3 -0
- package/package-form/element-form/components/select/package.json +17 -0
- package/package-form/element-form/components/select/src/component.jsx +52 -0
- package/package-form/element-form/components/select/src/index.js +3 -0
- package/package-form/element-form/components/subform/package.json +14 -0
- package/package-form/element-form/components/subform/src/component.jsx +76 -0
- package/package-form/element-form/components/subform/src/index.js +3 -0
- package/package-form/element-form/components/tree/package.json +17 -0
- package/package-form/element-form/components/tree/src/component.jsx +62 -0
- package/package-form/element-form/components/tree/src/index.js +3 -0
- package/package-form/element-form/components/upload/package.json +17 -0
- package/package-form/element-form/components/upload/src/IconUpload.vue +12 -0
- package/package-form/element-form/components/upload/src/component.jsx +129 -0
- package/package-form/element-form/components/upload/src/index.js +3 -0
- package/package-form/element-form/components/upload/src/style.css +11 -0
- package/package-form/element-form/index.js +8 -0
- package/package-form/element-form/package.json +16 -0
- package/package-form/element-form/src/components/icon/IconWarning.vue +12 -0
- package/package-form/element-form/src/components/index.js +22 -0
- package/package-form/element-form/src/core/alias.js +34 -0
- package/package-form/element-form/src/core/api.js +208 -0
- package/package-form/element-form/src/core/config.js +62 -0
- package/package-form/element-form/src/core/index.js +60 -0
- package/package-form/element-form/src/core/maker.js +76 -0
- package/package-form/element-form/src/core/manager.js +315 -0
- package/package-form/element-form/src/core/provider.js +79 -0
- package/package-form/element-form/src/parsers/datePicker.js +31 -0
- package/package-form/element-form/src/parsers/hidden.js +12 -0
- package/package-form/element-form/src/parsers/index.js +17 -0
- package/package-form/element-form/src/parsers/input.js +21 -0
- package/package-form/element-form/src/parsers/row.js +10 -0
- package/package-form/element-form/src/parsers/select.js +15 -0
- package/package-form/element-form/src/parsers/slider.js +21 -0
- package/package-form/element-form/src/parsers/timePicker.js +17 -0
- package/package-form/element-form/src/style/index.css +52 -0
- package/package.json +17 -0
- package/src/App.vue +28 -0
- package/src/assets/css/element.scss +179 -0
- package/src/assets/css/layout.scss +215 -0
- package/src/assets/css/tailwind.scss +67 -0
- package/src/assets/images/banner.gif +0 -0
- package/src/assets/images/banner.png +0 -0
- package/src/assets/images/bg1.svg +22 -0
- package/src/assets/images/bg2.png +0 -0
- package/src/assets/images/ff.png +0 -0
- package/src/assets/images/home-file1.png +0 -0
- package/src/assets/images/ky.png +0 -0
- package/src/assets/images/menu/add.png +0 -0
- package/src/assets/images/menu/del.png +0 -0
- package/src/assets/images/menu/down.png +0 -0
- package/src/assets/images/menu/dr.png +0 -0
- package/src/assets/images/menu/edit.png +0 -0
- package/src/assets/images/menu/kx.png +0 -0
- package/src/assets/images/menu/mb.png +0 -0
- package/src/assets/images/menu/pz.png +0 -0
- package/src/assets/images/menu/save.png +0 -0
- package/src/assets/images/menu/sj.png +0 -0
- package/src/assets/images/menu/sjk.png +0 -0
- package/src/assets/images/menu/up.png +0 -0
- package/src/assets/images/po-i.png +0 -0
- package/src/assets/images/po1-i1.png +0 -0
- package/src/assets/images/po1-i2.png +0 -0
- package/src/assets/images/po1-i3.png +0 -0
- package/src/assets/images/po1-i4.png +0 -0
- package/src/assets/images/po1-i5.png +0 -0
- package/src/assets/images/po1-i6.png +0 -0
- package/src/assets/images/po1-i7.png +0 -0
- package/src/assets/images/po1-i8.png +0 -0
- package/src/assets/images/po2-i1.png +0 -0
- package/src/assets/images/po2-i2.png +0 -0
- package/src/assets/images/po3-i1.png +0 -0
- package/src/assets/images/po4-i1.png +0 -0
- package/src/assets/images/po5-i1.png +0 -0
- package/src/assets/images/po6-i1.png +0 -0
- package/src/assets/images/po6-i2.png +0 -0
- package/src/assets/images/po7-i1.png +0 -0
- package/src/assets/images/tj1.png +0 -0
- package/src/assets/images/tj2.png +0 -0
- package/src/assets/images/tj3.png +0 -0
- package/src/components/3dcloudwords/index.js +346 -0
- package/src/components/3dcloudwords/index.vue +99 -0
- package/src/components/3dcloudwords/readme.md +66 -0
- package/src/components/badge/index.js +167 -0
- package/src/components/badge/index.scss +166 -0
- package/src/components/badge/index.vue +98 -0
- package/src/components/badge/readme.md +18 -0
- package/src/components/basic/Finish.vue +107 -0
- package/src/components/basic/button.vue +19 -0
- package/src/components/basic/readme.md +7 -0
- package/src/components/button/index.vue +48 -0
- package/src/components/button/readme.md +62 -0
- package/src/components/carousel/index.vue +104 -0
- package/src/components/carousel/readme.md +12 -0
- package/src/components/chartconfig/index.vue +141 -0
- package/src/components/chartconfig/readme.md +25 -0
- package/src/components/contextMenu/hookContxtMenu.js +41 -0
- package/src/components/contextMenu/index.vue +245 -0
- package/src/components/contextMenu/readme.md +55 -0
- package/src/components/contextMenu/useElementBounding.js +40 -0
- package/src/components/countup/countUp.js +196 -0
- package/src/components/countup/index.vue +112 -0
- package/src/components/countup/readme.md +9 -0
- package/src/components/empty/assets/build.png +0 -0
- package/src/components/empty/assets/emptybg.gif +0 -0
- package/src/components/empty/assets/emptybg.png +0 -0
- package/src/components/empty/assets/emptybg2.jpg +0 -0
- package/src/components/empty/assets/emptybg3.jpg +0 -0
- package/src/components/empty/assets/wuxiao.png +0 -0
- package/src/components/empty/assets/wuxiao.webp +0 -0
- package/src/components/empty/building.vue +117 -0
- package/src/components/empty/empty.vue +120 -0
- package/src/components/empty/index.js +12 -0
- package/src/components/empty/invalid.vue +56 -0
- package/src/components/error/Error.vue +79 -0
- package/src/components/error/readme.md +20 -0
- package/src/components/form/Form.vue +84 -0
- package/src/components/form/FormItem.vue +143 -0
- package/src/components/form/data.js +52 -0
- package/src/components/form/readme.md +69 -0
- package/src/components/layout/banner.vue +412 -0
- package/src/components/layout/bar.vue +43 -0
- package/src/components/layout/layout1.vue +60 -0
- package/src/components/layout/layout2.vue +134 -0
- package/src/components/layout/layout3.vue +107 -0
- package/src/components/layout/layout4.vue +66 -0
- package/src/components/layout/nav.vue +333 -0
- package/src/components/layout/readme.md +61 -0
- package/src/components/loading/index.vue +122 -0
- package/src/components/loading/readme.md +6 -0
- package/src/components/notice/NoticeList.vue +198 -0
- package/src/components/notice/NoticeListPaging.vue +281 -0
- package/src/components/notice/NoticeView.vue +92 -0
- package/src/components/notice/readme.md +1 -0
- package/src/components/pagination/index.vue +100 -0
- package/src/components/pagination/readme.md +19 -0
- package/src/components/pagination/scroll-to.js +51 -0
- package/src/components/progress/bar.vue +72 -0
- package/src/components/progress/progress.vue +58 -0
- package/src/components/screenfull/index.js +3 -0
- package/src/components/screenfull/index.vue +65 -0
- package/src/components/screenfull/package.json +15 -0
- package/src/components/screenfull/readme.md +6 -0
- package/src/components/statisticalCount/index.vue +80 -0
- package/src/components/statisticalCount/readme.md +21 -0
- package/src/components/username/index.vue +79 -0
- package/src/components/username/readme.md +22 -0
- package/src/components/username//346/225/210/346/236/234/345/233/276.png +0 -0
- package/src/index.js +82 -0
- package/src/utils/index.js +32 -0
- package/src/xm_components/HeadSearch/hook/hookSearch.js +96 -0
- package/src/xm_components/HeadSearch/index.vue +206 -0
- package/src/xm_components/HeadSearch/readme.md +12 -0
- package/src/xm_components/HeadSearch//346/220/234/347/264/242/345/210/227/350/241/250.png +0 -0
- package/src/xm_components/Milestone/index.vue +212 -0
- package/src/xm_components/Milestone/readme.md +15 -0
- package/src/xm_components/readme.md +1 -0
- package/utils/coms/load.jsx +10 -0
- package/utils/func.js +32 -0
- package/utils/hookDialog.js +38 -0
- package/utils/hookPage.js +49 -0
- package/utils/index.js +5 -0
- package/utils/lib/console.js +39 -0
- package/utils/lib/debounce.js +19 -0
- package/utils/lib/deepextend.js +51 -0
- package/utils/lib/deepset.js +14 -0
- package/utils/lib/extend.js +28 -0
- package/utils/lib/index.js +13 -0
- package/utils/lib/json.js +90 -0
- package/utils/lib/mergeprops.js +62 -0
- package/utils/lib/mitt.js +43 -0
- package/utils/lib/modify.js +8 -0
- package/utils/lib/slot.js +19 -0
- package/utils/lib/toarray.js +5 -0
- package/utils/lib/tocase.js +11 -0
- package/utils/lib/todate.js +10 -0
- package/utils/lib/toline.js +10 -0
- package/utils/lib/tostring.js +7 -0
- package/utils/lib/type.js +45 -0
- package/utils/lib/unique.js +6 -0
- package/utils/message.js +166 -0
- package/utils/package.json +16 -0
- package/utils/type.js +45 -0
- package/vite.config.js +51 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取表单配置的函数
|
|
3
|
+
* @returns {Object} 包含表单、行、提交按钮和重置按钮配置的对象
|
|
4
|
+
*/
|
|
5
|
+
export default function getConfig() {
|
|
6
|
+
return {
|
|
7
|
+
// 表单的配置
|
|
8
|
+
form: {
|
|
9
|
+
// 是否为内联表单
|
|
10
|
+
inline: false,
|
|
11
|
+
// 标签的位置
|
|
12
|
+
labelPosition: 'right',
|
|
13
|
+
// 标签的宽度
|
|
14
|
+
labelWidth: '125px',
|
|
15
|
+
// 表单是否禁用
|
|
16
|
+
disabled: false,
|
|
17
|
+
// 表单的尺寸
|
|
18
|
+
size: undefined,
|
|
19
|
+
},
|
|
20
|
+
// 行的配置
|
|
21
|
+
row: {
|
|
22
|
+
// 是否显示行
|
|
23
|
+
show: true,
|
|
24
|
+
// 行的间距
|
|
25
|
+
gutter: 0,
|
|
26
|
+
},
|
|
27
|
+
// 提交按钮的配置
|
|
28
|
+
submitBtn: {
|
|
29
|
+
// 按钮的类型
|
|
30
|
+
type: 'primary',
|
|
31
|
+
// 按钮是否处于加载状态
|
|
32
|
+
loading: false,
|
|
33
|
+
// 按钮是否禁用
|
|
34
|
+
disabled: false,
|
|
35
|
+
// 按钮的内部文本
|
|
36
|
+
innerText: '',
|
|
37
|
+
// 按钮是否显示
|
|
38
|
+
show: true,
|
|
39
|
+
// 按钮所在的列配置
|
|
40
|
+
col: undefined,
|
|
41
|
+
// 按钮的点击事件处理函数
|
|
42
|
+
click: undefined,
|
|
43
|
+
},
|
|
44
|
+
// 重置按钮的配置
|
|
45
|
+
resetBtn: {
|
|
46
|
+
// 按钮的类型
|
|
47
|
+
type: 'default',
|
|
48
|
+
// 按钮是否处于加载状态
|
|
49
|
+
loading: false,
|
|
50
|
+
// 按钮是否禁用
|
|
51
|
+
disabled: false,
|
|
52
|
+
// 按钮的内部文本
|
|
53
|
+
innerText: '',
|
|
54
|
+
// 按钮是否显示
|
|
55
|
+
show: false,
|
|
56
|
+
// 按钮所在的列配置
|
|
57
|
+
col: undefined,
|
|
58
|
+
// 按钮的点击事件处理函数
|
|
59
|
+
click: undefined,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import components from '../components';
|
|
2
|
+
import parsers from '../parsers';
|
|
3
|
+
import alias from './alias';
|
|
4
|
+
import manager from './manager';
|
|
5
|
+
import FormCreateFactory from '../../../core/frame/index.js';
|
|
6
|
+
// import makers from './maker';
|
|
7
|
+
import '../style/index.css';
|
|
8
|
+
import extendApi from './api';
|
|
9
|
+
import required from './provider';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 安装插件的函数,用于在 FormCreate 实例上注册组件、别名、解析器等
|
|
13
|
+
* @param {Object} FormCreate - FormCreate 实例
|
|
14
|
+
*/
|
|
15
|
+
function install(FormCreate) {
|
|
16
|
+
// 批量为组件设置别名,方便在表单配置中使用更简洁的名称引用组件
|
|
17
|
+
FormCreate.componentAlias(alias);
|
|
18
|
+
// 引入表单组件并注册到 FormCreate 实例中,使这些组件可以在表单中使用
|
|
19
|
+
components.forEach(component => {
|
|
20
|
+
FormCreate.component(component.name, component);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// 注册 required 提供者,用于处理表单字段的必填验证逻辑
|
|
24
|
+
FormCreate.register(required);
|
|
25
|
+
|
|
26
|
+
// 遍历解析器数组,将每个解析器注册到 FormCreate 实例中,用于解析表单配置
|
|
27
|
+
parsers.forEach((parser) => {
|
|
28
|
+
FormCreate.parser(parser);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// 以下代码被注释掉,若需要使用 makers 功能,可取消注释
|
|
32
|
+
// Object.keys(makers).forEach(name => {
|
|
33
|
+
// FormCreate.maker[name] = makers[name];
|
|
34
|
+
// });
|
|
35
|
+
|
|
36
|
+
// 检查是否在浏览器环境中,并且是否已经引入了 ElementPlus
|
|
37
|
+
if (typeof window !== 'undefined' && window.ElementPlus) {
|
|
38
|
+
// 使用 FormCreate 的 useApp 方法,在应用初始化时安装 ElementPlus
|
|
39
|
+
FormCreate.useApp((_, app) => {
|
|
40
|
+
app.use(window.ElementPlus);
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export default function elmFormCreate() {
|
|
48
|
+
return FormCreateFactory({
|
|
49
|
+
ui: 'process.env.UI',
|
|
50
|
+
version: 'process.env.VERSION',
|
|
51
|
+
manager,
|
|
52
|
+
extendApi,
|
|
53
|
+
install,
|
|
54
|
+
attrs: {
|
|
55
|
+
normal: ['col', 'wrap'],
|
|
56
|
+
array: ['className'],
|
|
57
|
+
key: ['title', 'info'],
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {creatorFactory} from '@bdsoft-element/formcore/index';
|
|
2
|
+
|
|
3
|
+
const maker = {};
|
|
4
|
+
|
|
5
|
+
useAlias(maker);
|
|
6
|
+
useSelect(maker);
|
|
7
|
+
useTree(maker);
|
|
8
|
+
useUpload(maker);
|
|
9
|
+
useFrame(maker);
|
|
10
|
+
|
|
11
|
+
function useAlias(maker) {
|
|
12
|
+
['group', 'tree', 'switch', 'upload', 'autoComplete', 'checkbox', 'cascader', 'colorPicker', 'datePicker', 'frame', 'inputNumber', 'radio', 'rate'].forEach(name => {
|
|
13
|
+
maker[name] = creatorFactory(name);
|
|
14
|
+
});
|
|
15
|
+
maker.auto = maker.autoComplete;
|
|
16
|
+
maker.number = maker.inputNumber;
|
|
17
|
+
maker.color = maker.colorPicker;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function useSelect(maker) {
|
|
21
|
+
const select = 'select';
|
|
22
|
+
const multiple = 'multiple';
|
|
23
|
+
maker['selectMultiple'] = creatorFactory(select, {[multiple]: true});
|
|
24
|
+
maker['selectOne'] = creatorFactory(select, {[multiple]: false});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function useTree(maker) {
|
|
28
|
+
const name = 'tree';
|
|
29
|
+
const types = {'treeSelected': 'selected', 'treeChecked': 'checked'};
|
|
30
|
+
|
|
31
|
+
Object.keys(types).reduce((m, key) => {
|
|
32
|
+
m[key] = creatorFactory(name, {type: types[key]});
|
|
33
|
+
return m;
|
|
34
|
+
}, maker);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function useUpload(maker) {
|
|
38
|
+
const name = 'upload';
|
|
39
|
+
const types = {
|
|
40
|
+
image: ['image', 0],
|
|
41
|
+
file: ['file', 0],
|
|
42
|
+
uploadFileOne: ['file', 1],
|
|
43
|
+
uploadImageOne: ['image', 1],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
Object.keys(types).reduce((m, key) => {
|
|
47
|
+
m[key] = creatorFactory(name, m => m.props({uploadType: types[key][0], maxLength: types[key][1]}));
|
|
48
|
+
return m
|
|
49
|
+
}, maker);
|
|
50
|
+
|
|
51
|
+
maker.uploadImage = maker.image;
|
|
52
|
+
maker.uploadFile = maker.file;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function useFrame(maker) {
|
|
56
|
+
const types = {
|
|
57
|
+
frameInputs: ['input', 0],
|
|
58
|
+
frameFiles: ['file', 0],
|
|
59
|
+
frameImages: ['image', 0],
|
|
60
|
+
frameInputOne: ['input', 1],
|
|
61
|
+
frameFileOne: ['file', 1],
|
|
62
|
+
frameImageOne: ['image', 1]
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
Object.keys(types).reduce((maker, key) => {
|
|
66
|
+
maker[key] = creatorFactory('frame', m => m.props({type: types[key][0], maxLength: types[key][1]}));
|
|
67
|
+
return maker
|
|
68
|
+
}, maker);
|
|
69
|
+
|
|
70
|
+
maker.frameInput = maker.frameInputs;
|
|
71
|
+
maker.frameFile = maker.frameFiles;
|
|
72
|
+
maker.frameImage = maker.frameImages;
|
|
73
|
+
return maker;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default maker;
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import getConfig from './config';
|
|
2
|
+
import mergeProps from '@bdsoft-element/utils/lib/mergeprops';
|
|
3
|
+
import is, {hasProperty} from '@bdsoft-element/utils/lib/type';
|
|
4
|
+
import toString from '@bdsoft-element/utils/lib/tostring';
|
|
5
|
+
import extend from '@bdsoft-element/utils/lib/extend';
|
|
6
|
+
|
|
7
|
+
// 检查给定的信息对象是否为工具提示类型
|
|
8
|
+
function isTooltip(info) {
|
|
9
|
+
return info.type === 'tooltip';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 清理 props 对象中的指定名称属性,如果该属性是字符串,则将其转换为对象形式
|
|
13
|
+
function tidy(props, name) {
|
|
14
|
+
if (!hasProperty(props, name)) return;
|
|
15
|
+
if (is.String(props[name])) {
|
|
16
|
+
props[name] = {[name]: props[name], show: true};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// 检查给定的值是否为 false
|
|
21
|
+
function isFalse(val) {
|
|
22
|
+
return val === false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 清理选项中的布尔属性,如果属性不是对象,则将其转换为对象形式
|
|
26
|
+
function tidyBool(opt, name) {
|
|
27
|
+
if (hasProperty(opt, name) && !is.Object(opt[name])) {
|
|
28
|
+
opt[name] = {show: !!opt[name]};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 清理规则对象,删除 children 属性并返回新的规则对象
|
|
33
|
+
function tidyRule(rule) {
|
|
34
|
+
const _rule = {...rule};
|
|
35
|
+
delete _rule.children;
|
|
36
|
+
return _rule;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
// 验证整个表单
|
|
41
|
+
validate() {
|
|
42
|
+
const form = this.form();
|
|
43
|
+
if (form) {
|
|
44
|
+
return form.validate();
|
|
45
|
+
} else {
|
|
46
|
+
return new Promise(v => v());
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
// 验证表单中的单个字段
|
|
50
|
+
validateField(field) {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
const form = this.form();
|
|
53
|
+
if (form) {
|
|
54
|
+
form.validateField(field, (res, err) => {
|
|
55
|
+
err ? reject(err) : resolve(res);
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
resolve();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
// 清除指定字段的验证状态
|
|
63
|
+
clearValidateState(ctx) {
|
|
64
|
+
const fItem = this.vm.refs[ctx.wrapRef];
|
|
65
|
+
if (fItem) {
|
|
66
|
+
fItem.clearValidate();
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
// 清理选项中的特定属性
|
|
70
|
+
tidyOptions(options) {
|
|
71
|
+
['submitBtn', 'resetBtn', 'row', 'info', 'wrap', 'col', 'title'].forEach(name => {
|
|
72
|
+
tidyBool(options, name);
|
|
73
|
+
})
|
|
74
|
+
return options;
|
|
75
|
+
},
|
|
76
|
+
// 清理规则中的 title 和 info 属性
|
|
77
|
+
tidyRule({prop}) {
|
|
78
|
+
tidy(prop, 'title');
|
|
79
|
+
tidy(prop, 'info');
|
|
80
|
+
return prop;
|
|
81
|
+
},
|
|
82
|
+
// 合并 props 对象中的默认值
|
|
83
|
+
mergeProp(ctx) {
|
|
84
|
+
const def = {
|
|
85
|
+
info: {
|
|
86
|
+
trigger: 'hover',
|
|
87
|
+
placement: 'top-start',
|
|
88
|
+
icon: true,
|
|
89
|
+
},
|
|
90
|
+
title: {},
|
|
91
|
+
col: {span: 24},
|
|
92
|
+
wrap: {},
|
|
93
|
+
};
|
|
94
|
+
['info', 'wrap', 'col', 'title'].forEach(name => {
|
|
95
|
+
ctx.prop[name] = mergeProps([this.options[name] || {}, ctx.prop[name] || {}], def[name]);
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
// 获取默认配置选项
|
|
99
|
+
getDefaultOptions() {
|
|
100
|
+
return getConfig();
|
|
101
|
+
},
|
|
102
|
+
// 更新规则对象
|
|
103
|
+
update() {
|
|
104
|
+
const form = this.options.form;
|
|
105
|
+
this.rule = {
|
|
106
|
+
props: {...form},
|
|
107
|
+
on: {
|
|
108
|
+
submit: (e) => {
|
|
109
|
+
e.preventDefault();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
class: [form.className, form.class, 'form-create', this.$handle.preview ? 'is-preview' : ''],
|
|
113
|
+
style: form.style,
|
|
114
|
+
type: 'form',
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
// 渲染前准备规则对象
|
|
118
|
+
beforeRender() {
|
|
119
|
+
const {key, ref, $handle} = this;
|
|
120
|
+
extend(this.rule, {key, ref});
|
|
121
|
+
extend(this.rule.props, {
|
|
122
|
+
model: $handle.formData,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
// 渲染表单组件
|
|
126
|
+
render(children) {
|
|
127
|
+
if (children.slotLen() && !this.$handle.preview) {
|
|
128
|
+
children.setSlot(undefined, () => this.makeFormBtn());
|
|
129
|
+
}
|
|
130
|
+
return this.$r(this.rule, isFalse(this.options.row.show) ? children.getSlots() : [this.makeRow(children)]);
|
|
131
|
+
},
|
|
132
|
+
// 创建包裹组件
|
|
133
|
+
makeWrap(ctx, children) {
|
|
134
|
+
const rule = ctx.prop;
|
|
135
|
+
const uni = `${this.key}${ctx.key}`;
|
|
136
|
+
const col = rule.col;
|
|
137
|
+
const isTitle = this.isTitle(rule) && rule.wrap.title !== false;
|
|
138
|
+
const labelWidth = (!col.labelWidth && !isTitle) ? 0 : col.labelWidth;
|
|
139
|
+
const {inline, col: _col} = this.rule.props;
|
|
140
|
+
delete rule.wrap.title;
|
|
141
|
+
const item = isFalse(rule.wrap.show) ? children : this.$r(mergeProps([rule.wrap, {
|
|
142
|
+
props: {
|
|
143
|
+
labelWidth: labelWidth === void 0 ? labelWidth : toString(labelWidth),
|
|
144
|
+
label: isTitle ? rule.title.title : undefined,
|
|
145
|
+
...tidyRule(rule.wrap || {}),
|
|
146
|
+
prop: ctx.id,
|
|
147
|
+
rules: ctx.injectValidate(),
|
|
148
|
+
},
|
|
149
|
+
class: this.$render.mergeClass(rule.className, 'fc-form-item'),
|
|
150
|
+
key: `${uni}fi`,
|
|
151
|
+
ref: ctx.wrapRef,
|
|
152
|
+
type: 'formItem',
|
|
153
|
+
}]), {default: () => children, ...(isTitle ? {label: () => this.makeInfo(rule, uni, ctx)} : {})});
|
|
154
|
+
return (inline === true || isFalse(_col) || isFalse(col.show)) ? item : this.makeCol(rule, uni, [item]);
|
|
155
|
+
},
|
|
156
|
+
// 检查是否显示标题
|
|
157
|
+
isTitle(rule) {
|
|
158
|
+
if (this.options.form.title === false) return false;
|
|
159
|
+
const title = rule.title;
|
|
160
|
+
return !((!title.title && !title.native) || isFalse(title.show))
|
|
161
|
+
},
|
|
162
|
+
// 创建信息组件
|
|
163
|
+
makeInfo(rule, uni, ctx) {
|
|
164
|
+
const titleProp = {...rule.title};
|
|
165
|
+
const infoProp = {...rule.info};
|
|
166
|
+
const isTip = isTooltip(infoProp);
|
|
167
|
+
const form = this.options.form;
|
|
168
|
+
const titleSlot = this.getSlot('title');
|
|
169
|
+
const children = [titleSlot ? titleSlot({
|
|
170
|
+
title: ctx.refRule?.__$title.value,
|
|
171
|
+
rule: ctx.rule,
|
|
172
|
+
options: this.options
|
|
173
|
+
}) : ((ctx.refRule?.__$title.value) + (form.labelSuffix || form['label-suffix'] || ''))];
|
|
174
|
+
|
|
175
|
+
if (!isFalse(infoProp.show) && (infoProp.info || infoProp.native) && !isFalse(infoProp.icon)) {
|
|
176
|
+
const prop = {
|
|
177
|
+
type: infoProp.type || 'popover',
|
|
178
|
+
props: tidyRule(infoProp),
|
|
179
|
+
key: `${uni}pop`
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
delete prop.props.icon;
|
|
183
|
+
delete prop.props.show;
|
|
184
|
+
delete prop.props.info;
|
|
185
|
+
delete prop.props.align;
|
|
186
|
+
delete prop.props.native;
|
|
187
|
+
|
|
188
|
+
const field = 'content';
|
|
189
|
+
if (infoProp.info && !hasProperty(prop.props, field)) {
|
|
190
|
+
prop.props[field] = ctx.refRule?.__$info.value;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
children[infoProp.align !== 'left' ? 'unshift' : 'push'](this.$r(mergeProps([infoProp, prop]), {
|
|
194
|
+
[titleProp.slot || (isTip ? 'default' : 'reference')]: () => this.$r({
|
|
195
|
+
type: 'ElIcon',
|
|
196
|
+
style: 'top:2px',
|
|
197
|
+
key: `${uni}i`
|
|
198
|
+
}, {
|
|
199
|
+
default: () => this.$r({
|
|
200
|
+
type: infoProp.icon === true ? 'icon-warning' : infoProp.icon
|
|
201
|
+
})
|
|
202
|
+
}, true)
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
const _prop = mergeProps([titleProp, {
|
|
206
|
+
props: tidyRule(titleProp),
|
|
207
|
+
key: `${uni}tit`,
|
|
208
|
+
class: 'fc-form-title',
|
|
209
|
+
type: titleProp.type || 'span',
|
|
210
|
+
}]);
|
|
211
|
+
|
|
212
|
+
delete _prop.props.show;
|
|
213
|
+
delete _prop.props.title;
|
|
214
|
+
delete _prop.props.native;
|
|
215
|
+
|
|
216
|
+
return this.$r(_prop, children);
|
|
217
|
+
},
|
|
218
|
+
// 创建列组件
|
|
219
|
+
makeCol(rule, uni, children) {
|
|
220
|
+
const col = rule.col;
|
|
221
|
+
return this.$r({
|
|
222
|
+
class: this.$render.mergeClass(col.class, 'fc-form-col'),
|
|
223
|
+
type: 'col',
|
|
224
|
+
props: col || {span: 24},
|
|
225
|
+
key: `${uni}col`
|
|
226
|
+
}, children);
|
|
227
|
+
},
|
|
228
|
+
// 创建行组件
|
|
229
|
+
makeRow(children) {
|
|
230
|
+
const row = this.options.row || {};
|
|
231
|
+
return this.$r({
|
|
232
|
+
type: 'row',
|
|
233
|
+
props: row,
|
|
234
|
+
class: this.$render.mergeClass(row.class, 'fc-form-row'),
|
|
235
|
+
key: `${this.key}row`
|
|
236
|
+
}, children)
|
|
237
|
+
},
|
|
238
|
+
// 创建表单按钮
|
|
239
|
+
makeFormBtn() {
|
|
240
|
+
let vn = [];
|
|
241
|
+
if (!isFalse(this.options.submitBtn.show)) {
|
|
242
|
+
vn.push(this.makeSubmitBtn())
|
|
243
|
+
}
|
|
244
|
+
if (!isFalse(this.options.resetBtn.show)) {
|
|
245
|
+
vn.push(this.makeResetBtn())
|
|
246
|
+
}
|
|
247
|
+
if (!vn.length) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const item = this.$r({
|
|
251
|
+
type: 'formItem',
|
|
252
|
+
class: 'fc-form-item',
|
|
253
|
+
key: `${this.key}fb`
|
|
254
|
+
}, vn);
|
|
255
|
+
|
|
256
|
+
return this.rule.props.inline === true
|
|
257
|
+
? item
|
|
258
|
+
: this.$r({
|
|
259
|
+
type: 'col',
|
|
260
|
+
class: 'fc-form-col fc-form-footer',
|
|
261
|
+
props: {span: 24},
|
|
262
|
+
key: `${this.key}fc`
|
|
263
|
+
}, [item]);
|
|
264
|
+
},
|
|
265
|
+
|
|
266
|
+
// 创建重置按钮
|
|
267
|
+
makeResetBtn() {
|
|
268
|
+
const resetBtn = {...this.options.resetBtn};
|
|
269
|
+
const innerText = resetBtn.innerText || this.$handle.api.t('reset') || '重置';
|
|
270
|
+
delete resetBtn.innerText;
|
|
271
|
+
delete resetBtn.click;
|
|
272
|
+
delete resetBtn.col;
|
|
273
|
+
delete resetBtn.show;
|
|
274
|
+
return this.$r({
|
|
275
|
+
type: 'button',
|
|
276
|
+
props: resetBtn,
|
|
277
|
+
class: 'fc-reset-btn',
|
|
278
|
+
style: {width: resetBtn.width},
|
|
279
|
+
on: {
|
|
280
|
+
click: () => {
|
|
281
|
+
const fApi = this.$handle.api;
|
|
282
|
+
this.options.resetBtn.click
|
|
283
|
+
? this.options.resetBtn.click(fApi)
|
|
284
|
+
: fApi.resetFields();
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
key: `${this.key}b2`,
|
|
288
|
+
}, [innerText]);
|
|
289
|
+
},
|
|
290
|
+
// 创建提交按钮
|
|
291
|
+
makeSubmitBtn() {
|
|
292
|
+
const submitBtn = {...this.options.submitBtn};
|
|
293
|
+
const innerText = submitBtn.innerText || this.$handle.api.t('submit') || '提交';
|
|
294
|
+
delete submitBtn.innerText;
|
|
295
|
+
delete submitBtn.click;
|
|
296
|
+
delete submitBtn.col;
|
|
297
|
+
delete submitBtn.show;
|
|
298
|
+
return this.$r({
|
|
299
|
+
type: 'button',
|
|
300
|
+
props: submitBtn,
|
|
301
|
+
class: 'fc-submit-btn',
|
|
302
|
+
style: {width: submitBtn.width},
|
|
303
|
+
on: {
|
|
304
|
+
click: () => {
|
|
305
|
+
const fApi = this.$handle.api;
|
|
306
|
+
this.options.submitBtn.click
|
|
307
|
+
? this.options.submitBtn.click(fApi)
|
|
308
|
+
: fApi.submit().catch(() => {
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
key: `${this.key}b1`,
|
|
313
|
+
}, [innerText]);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import is from '@bdsoft-element/utils/lib/type'
|
|
2
|
+
|
|
3
|
+
const required = {
|
|
4
|
+
name: 'required',
|
|
5
|
+
/**
|
|
6
|
+
* 加载验证规则的方法
|
|
7
|
+
* @param {Object} inject - 注入对象,包含获取值、清除属性等方法
|
|
8
|
+
* @param {Object} rule - 当前字段的规则对象
|
|
9
|
+
* @param {Object} api - 表单 API 对象,包含同步、清除验证状态等方法
|
|
10
|
+
*/
|
|
11
|
+
load(inject, rule, api) {
|
|
12
|
+
// 解析注入的值
|
|
13
|
+
const val = parseVal(inject.getValue())
|
|
14
|
+
// 如果解析后的值中 required 为 false
|
|
15
|
+
if (val.required === false) {
|
|
16
|
+
// 清除注入的属性
|
|
17
|
+
inject.clearProp()
|
|
18
|
+
// 清除指定字段的验证状态
|
|
19
|
+
api.clearValidateState([rule.field])
|
|
20
|
+
} else {
|
|
21
|
+
// 定义验证规则对象
|
|
22
|
+
const validate = {
|
|
23
|
+
// 字段为必填项
|
|
24
|
+
required: true,
|
|
25
|
+
/**
|
|
26
|
+
* 自定义验证函数
|
|
27
|
+
* @param {Object} _ - 表单数据对象(此处未使用)
|
|
28
|
+
* @param {any} v - 当前字段的值
|
|
29
|
+
* @param {Function} call - 验证回调函数,用于返回验证结果
|
|
30
|
+
*/
|
|
31
|
+
validator(_, v, call) {
|
|
32
|
+
// 如果值为空,则调用回调函数并传入错误信息
|
|
33
|
+
is.empty(v) ? call(validate.message) : call()
|
|
34
|
+
},
|
|
35
|
+
// 合并解析后的值
|
|
36
|
+
...val
|
|
37
|
+
}
|
|
38
|
+
// 获取字段的标题
|
|
39
|
+
const title = rule.__fc__.refRule.__$title.value
|
|
40
|
+
// 如果验证规则中没有定义错误信息
|
|
41
|
+
if (!validate.message) {
|
|
42
|
+
// 尝试从 API 中获取国际化的错误信息,如果没有则使用默认信息
|
|
43
|
+
validate.message = api.t('required', { title }) || title + (api.getLocale() === 'en' ? ' is required' : '不能为空')
|
|
44
|
+
} else {
|
|
45
|
+
// 检查错误信息是否为国际化占位符
|
|
46
|
+
const match = validate.message.match(/^\{\{\s*\$t\.(.+)\s*\}\}$/)
|
|
47
|
+
if (match) {
|
|
48
|
+
// 如果是占位符,则从 API 中获取国际化的错误信息
|
|
49
|
+
validate.message = api.t(match[1], { title })
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
// 将验证规则添加到注入属性的 validate 数组中
|
|
53
|
+
inject.getProp().validate = [validate]
|
|
54
|
+
}
|
|
55
|
+
// 同步表单规则
|
|
56
|
+
api.sync(rule)
|
|
57
|
+
},
|
|
58
|
+
watch(...args) {
|
|
59
|
+
required.load(...args)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parseVal(val) {
|
|
64
|
+
if (is.Boolean(val)) {
|
|
65
|
+
return { required: val }
|
|
66
|
+
} else if (is.String(val)) {
|
|
67
|
+
return { message: val }
|
|
68
|
+
} else if (is.Undef(val)) {
|
|
69
|
+
return { required: false }
|
|
70
|
+
} else if (is.Function(val)) {
|
|
71
|
+
return { validator: val }
|
|
72
|
+
} else if (!is.Object(val)) {
|
|
73
|
+
return {}
|
|
74
|
+
} else {
|
|
75
|
+
return val
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export default required
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {creatorFactory} from '@bdsoft-element/formcore/index';
|
|
2
|
+
|
|
3
|
+
const DEFAULT_FORMATS = {
|
|
4
|
+
date: 'YYYY-MM-DD',
|
|
5
|
+
month: 'YYYY-MM',
|
|
6
|
+
week: 'YYYY-wo',
|
|
7
|
+
datetime: 'YYYY-MM-DD HH:mm:ss',
|
|
8
|
+
timerange: 'HH:mm:ss',
|
|
9
|
+
daterange: 'YYYY-MM-DD',
|
|
10
|
+
monthrange: 'YYYY-MM',
|
|
11
|
+
datetimerange: 'YYYY-MM-DD HH:mm:ss',
|
|
12
|
+
year: 'YYYY'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const name = 'datePicker';
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
name,
|
|
19
|
+
maker: (function () {
|
|
20
|
+
return ['year', 'month', 'date', 'dates', 'week', 'datetime', 'datetimeRange', 'dateRange', 'monthRange'].reduce((initial, type) => {
|
|
21
|
+
initial[type] = creatorFactory(name, {type: type.toLowerCase()});
|
|
22
|
+
return initial
|
|
23
|
+
}, {});
|
|
24
|
+
}()),
|
|
25
|
+
mergeProp(ctx) {
|
|
26
|
+
const props = ctx.prop.props;
|
|
27
|
+
if (!props.valueFormat) {
|
|
28
|
+
props.valueFormat = DEFAULT_FORMATS[props.type] || DEFAULT_FORMATS['date'];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import datePicker from './datePicker';
|
|
2
|
+
import hidden from './hidden';
|
|
3
|
+
import input from './input';
|
|
4
|
+
import slider from './slider';
|
|
5
|
+
import timePicker from './timePicker';
|
|
6
|
+
import row from './row';
|
|
7
|
+
import select from './select';
|
|
8
|
+
|
|
9
|
+
export default [
|
|
10
|
+
datePicker,
|
|
11
|
+
hidden,
|
|
12
|
+
input,
|
|
13
|
+
slider,
|
|
14
|
+
timePicker,
|
|
15
|
+
row,
|
|
16
|
+
select
|
|
17
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {creatorFactory} from '@bdsoft-element/formcore/index';
|
|
2
|
+
|
|
3
|
+
const name = 'input';
|
|
4
|
+
export default {
|
|
5
|
+
name,
|
|
6
|
+
maker: (function () {
|
|
7
|
+
const maker = ['password', 'url', 'email', 'text', 'textarea'].reduce((maker, type) => {
|
|
8
|
+
maker[type] = creatorFactory(name, {type});
|
|
9
|
+
return maker;
|
|
10
|
+
}, {});
|
|
11
|
+
|
|
12
|
+
maker.idate = creatorFactory(name, {type:'date'});
|
|
13
|
+
return maker;
|
|
14
|
+
}()),
|
|
15
|
+
mergeProp(ctx) {
|
|
16
|
+
let {props} = ctx.prop;
|
|
17
|
+
if (props && props.autosize && props.autosize.minRows) {
|
|
18
|
+
props.rows = props.autosize.minRows || 2;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|