element-ui-pro-components-test 1.5.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/CHANGELOG.md +0 -0
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/lib/dialog-form.js +1175 -0
- package/lib/editable-pro-table.js +2080 -0
- package/lib/element-ui-pro-components.common.js +193 -0
- package/lib/index.js +1 -0
- package/lib/locale/index.js +44 -0
- package/lib/locale/lang/en.js +46 -0
- package/lib/locale/lang/zh-CN.js +46 -0
- package/lib/pro-form.js +1036 -0
- package/lib/pro-table.js +2779 -0
- package/lib/theme-chalk/editable-pro-table.css +1 -0
- package/lib/theme-chalk/index.css +1 -0
- package/lib/theme-chalk/pro-table.css +1 -0
- package/lib/umd/locale/en.js +67 -0
- package/lib/umd/locale/zh-CN.js +67 -0
- package/lib/utils/breakpoints.js +68 -0
- package/lib/utils/debounce.js +20 -0
- package/lib/utils/form.js +108 -0
- package/package.json +78 -0
- package/packages/dialog-form/index.js +9 -0
- package/packages/dialog-form/src/components/Submitter.vue +47 -0
- package/packages/dialog-form/src/index.vue +404 -0
- package/packages/editable-pro-table/index.js +9 -0
- package/packages/editable-pro-table/src/components/Editable.vue +203 -0
- package/packages/editable-pro-table/src/components/FormItem.vue +193 -0
- package/packages/editable-pro-table/src/components/RecordCreator.vue +43 -0
- package/packages/editable-pro-table/src/components/RenderCell.vue +181 -0
- package/packages/editable-pro-table/src/index.vue +805 -0
- package/packages/pro-form/index.js +9 -0
- package/packages/pro-form/src/components/Submitter.vue +47 -0
- package/packages/pro-form/src/index.vue +309 -0
- package/packages/pro-table/index.js +9 -0
- package/packages/pro-table/src/components/ColumnAlignSettings.vue +77 -0
- package/packages/pro-table/src/components/ColumnSettings.vue +172 -0
- package/packages/pro-table/src/components/ColumnSettingsItem.vue +401 -0
- package/packages/pro-table/src/components/svg/ArrowIcon.vue +16 -0
- package/packages/pro-table/src/components/svg/HolderIcon.vue +17 -0
- package/packages/pro-table/src/components/svg/SettingIcon.vue +20 -0
- package/packages/pro-table/src/components/svg/VerticalAlginBottomIcon.vue +17 -0
- package/packages/pro-table/src/components/svg/VerticalAlginMiddleIcon.vue +17 -0
- package/packages/pro-table/src/components/svg/VerticalAlignTopIcon.vue +17 -0
- package/packages/pro-table/src/index.vue +934 -0
- package/src/components/custom-render/index.vue +16 -0
- package/src/components/pro-form-item/index.vue +129 -0
- package/src/index.js +57 -0
- package/src/locale/index.js +47 -0
- package/src/locale/lang/en.js +46 -0
- package/src/locale/lang/zh-CN.js +46 -0
- package/src/utils/breakpoints.js +61 -0
- package/src/utils/debounce.js +22 -0
- package/src/utils/form.js +94 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-form-item
|
|
3
|
+
v-bind="normalizedFormItem"
|
|
4
|
+
>
|
|
5
|
+
<template v-if="formItem.renderLabel" #label>
|
|
6
|
+
<!-- 自定义 label -->
|
|
7
|
+
<!-- start -->
|
|
8
|
+
<CustomRender :render="formItem.renderLabel" />
|
|
9
|
+
<!-- end -->
|
|
10
|
+
</template>
|
|
11
|
+
<!-- 自定义渲染 -->
|
|
12
|
+
<!-- start -->
|
|
13
|
+
<CustomRender
|
|
14
|
+
v-if="formItem.renderField"
|
|
15
|
+
:render="() => formItem.renderField({ form, formItem })"
|
|
16
|
+
/>
|
|
17
|
+
<slot
|
|
18
|
+
v-else-if="formItem.valueType === 'slot'"
|
|
19
|
+
:name="formItem.prop"
|
|
20
|
+
></slot>
|
|
21
|
+
<!-- end -->
|
|
22
|
+
<!-- 元素渲染 -->
|
|
23
|
+
<!-- start -->
|
|
24
|
+
<component
|
|
25
|
+
v-else
|
|
26
|
+
:is="`el-${formItem.valueType}`"
|
|
27
|
+
v-model="form[formItem.prop]"
|
|
28
|
+
v-bind="formItem.fieldProps"
|
|
29
|
+
v-on="formItem.fieldEvents"
|
|
30
|
+
>
|
|
31
|
+
<!-- Select -->
|
|
32
|
+
<!-- start -->
|
|
33
|
+
<template v-if="formItem.valueType === 'select'">
|
|
34
|
+
<!-- Option Group -->
|
|
35
|
+
<!-- start -->
|
|
36
|
+
<template v-if="isOptionGroup">
|
|
37
|
+
<el-option-group
|
|
38
|
+
v-for="group in formItem.options"
|
|
39
|
+
v-bind="group"
|
|
40
|
+
:key="group.label"
|
|
41
|
+
>
|
|
42
|
+
<el-option
|
|
43
|
+
v-for="option in group.options"
|
|
44
|
+
v-bind="option"
|
|
45
|
+
:key="option.value"
|
|
46
|
+
></el-option>
|
|
47
|
+
</el-option-group>
|
|
48
|
+
</template>
|
|
49
|
+
<!-- end -->
|
|
50
|
+
<!-- Option -->
|
|
51
|
+
<!-- start -->
|
|
52
|
+
<template v-else>
|
|
53
|
+
<el-option
|
|
54
|
+
v-for="option in formItem.options"
|
|
55
|
+
v-bind="option"
|
|
56
|
+
:key="option.value"
|
|
57
|
+
></el-option>
|
|
58
|
+
</template>
|
|
59
|
+
<!-- end -->
|
|
60
|
+
</template>
|
|
61
|
+
<!-- end -->
|
|
62
|
+
<template v-else-if="groups.includes(formItem.valueType)">
|
|
63
|
+
<component
|
|
64
|
+
:is="selection[formItem.valueType]"
|
|
65
|
+
v-for="option in formItem.options"
|
|
66
|
+
:label="option.value"
|
|
67
|
+
:key="option.value"
|
|
68
|
+
>
|
|
69
|
+
{{ option.label }}
|
|
70
|
+
</component>
|
|
71
|
+
</template>
|
|
72
|
+
</component>
|
|
73
|
+
<!-- end -->
|
|
74
|
+
</el-form-item>
|
|
75
|
+
</template>
|
|
76
|
+
|
|
77
|
+
<script>
|
|
78
|
+
import CustomRender from '../custom-render'
|
|
79
|
+
|
|
80
|
+
export default {
|
|
81
|
+
name: 'ProFormItem',
|
|
82
|
+
components: {
|
|
83
|
+
CustomRender,
|
|
84
|
+
},
|
|
85
|
+
props: {
|
|
86
|
+
// formItem 项
|
|
87
|
+
formItem: {
|
|
88
|
+
type: Object,
|
|
89
|
+
required: true
|
|
90
|
+
},
|
|
91
|
+
// 表单数据
|
|
92
|
+
form: {
|
|
93
|
+
type: Object,
|
|
94
|
+
required: true
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
computed: {
|
|
98
|
+
// 过滤 el-form-item 的属性
|
|
99
|
+
normalizedFormItem() {
|
|
100
|
+
const {
|
|
101
|
+
renderLabel,
|
|
102
|
+
valueType,
|
|
103
|
+
renderField,
|
|
104
|
+
fieldProps,
|
|
105
|
+
fieldEvents,
|
|
106
|
+
options,
|
|
107
|
+
valueEnum,
|
|
108
|
+
optionLoader,
|
|
109
|
+
initialValue,
|
|
110
|
+
colProps,
|
|
111
|
+
...keys
|
|
112
|
+
} = this.formItem
|
|
113
|
+
return keys
|
|
114
|
+
},
|
|
115
|
+
isOptionGroup() {
|
|
116
|
+
return this.formItem.options?.[0]?.options
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
data() {
|
|
120
|
+
return {
|
|
121
|
+
groups: ['radio-group', 'checkbox-group'], // valueType
|
|
122
|
+
selection: { // 选项组对应的组件
|
|
123
|
+
'radio-group': 'el-radio',
|
|
124
|
+
'checkbox-group': 'el-checkbox'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
}
|
|
129
|
+
</script>
|
package/src/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 导入所有组件
|
|
2
|
+
import ProForm from 'element-ui-pro-components/packages/pro-form'
|
|
3
|
+
import DialogForm from 'element-ui-pro-components/packages/dialog-form'
|
|
4
|
+
import ProTable from 'element-ui-pro-components/packages/pro-table'
|
|
5
|
+
import EditableProTable from 'element-ui-pro-components/packages/editable-pro-table'
|
|
6
|
+
import locale from 'element-ui-pro-components/src/locale'
|
|
7
|
+
|
|
8
|
+
// 组件列表
|
|
9
|
+
const components = [
|
|
10
|
+
ProForm,
|
|
11
|
+
DialogForm,
|
|
12
|
+
ProTable,
|
|
13
|
+
EditableProTable
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
// ✅ 1. 全局 install 方法 - 支持 Vue.use(ElementUIProComponents)
|
|
17
|
+
const install = function(Vue, opts = {}) {
|
|
18
|
+
// 检查是否已安装
|
|
19
|
+
if (install.installed) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
locale.use(opts.locale)
|
|
24
|
+
locale.i18n(opts.i18n)
|
|
25
|
+
|
|
26
|
+
// 遍历注册所有组件
|
|
27
|
+
components.forEach(component => {
|
|
28
|
+
Vue.component(component.name, component)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// 标记已安装
|
|
32
|
+
install.installed = true
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ✅ 2. 自动安装(当通过 script 标签引入时)
|
|
36
|
+
if (typeof window !== 'undefined' && window.Vue) {
|
|
37
|
+
install(window.Vue)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// ✅ 3. 导出组件和 install 方法
|
|
41
|
+
export default {
|
|
42
|
+
install,
|
|
43
|
+
locale: locale.use,
|
|
44
|
+
i18n: locale.i18n,
|
|
45
|
+
ProForm,
|
|
46
|
+
DialogForm,
|
|
47
|
+
ProTable,
|
|
48
|
+
EditableProTable
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// ✅ 4. 同时也支持按需引入
|
|
52
|
+
export {
|
|
53
|
+
ProForm,
|
|
54
|
+
DialogForm,
|
|
55
|
+
ProTable,
|
|
56
|
+
EditableProTable
|
|
57
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Vue from 'vue'
|
|
2
|
+
import defaultLang from './lang/zh-CN'
|
|
3
|
+
|
|
4
|
+
let lang = defaultLang
|
|
5
|
+
let i18nHandler = function() {
|
|
6
|
+
const vueI18n = Object.getPrototypeOf(this || Vue).$t
|
|
7
|
+
if (typeof vueI18n === 'function') {
|
|
8
|
+
return vueI18n.apply(this, arguments)
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const t = function(path) { // 去掉 options 参数
|
|
13
|
+
// 优先使用自定义 handler
|
|
14
|
+
if (i18nHandler) {
|
|
15
|
+
const value = i18nHandler(path)
|
|
16
|
+
if (value !== null && value !== undefined) {
|
|
17
|
+
return value
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 用自己的语言包
|
|
22
|
+
const array = path.split('.')
|
|
23
|
+
let current = lang
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < array.length; i++) {
|
|
26
|
+
const property = array[i]
|
|
27
|
+
const value = current[property]
|
|
28
|
+
|
|
29
|
+
if (i === array.length - 1) {
|
|
30
|
+
return value || path
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!value) return path
|
|
34
|
+
current = value
|
|
35
|
+
}
|
|
36
|
+
return path
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const use = function(l) {
|
|
40
|
+
lang = l || lang
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const i18n = function(fn) {
|
|
44
|
+
i18nHandler = fn
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default { use, t, i18n }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
elProComponents: {
|
|
3
|
+
placeholder: {
|
|
4
|
+
input: 'Please enter',
|
|
5
|
+
select: 'Please select',
|
|
6
|
+
selectTime: 'Select time',
|
|
7
|
+
selectDate: 'Select date'
|
|
8
|
+
},
|
|
9
|
+
proForm: {
|
|
10
|
+
reset: 'Reset',
|
|
11
|
+
submit: 'Submit'
|
|
12
|
+
},
|
|
13
|
+
dialogForm: {
|
|
14
|
+
cancel: 'Cancel',
|
|
15
|
+
confirm: 'Confirm'
|
|
16
|
+
},
|
|
17
|
+
proTable: {
|
|
18
|
+
expand: 'Expand',
|
|
19
|
+
collapse: 'Collapse',
|
|
20
|
+
search: 'Search',
|
|
21
|
+
reset: 'Reset',
|
|
22
|
+
},
|
|
23
|
+
tableToolBar: {
|
|
24
|
+
columnSetting: 'Settings',
|
|
25
|
+
reset: 'Reset',
|
|
26
|
+
columnDisplay: 'Column Display',
|
|
27
|
+
leftPin: 'Pin to left',
|
|
28
|
+
rightPin: 'Pin to right',
|
|
29
|
+
noPin: 'Unpinned',
|
|
30
|
+
leftFixedTitle: 'Fixed the left',
|
|
31
|
+
rightFixedTitle: 'Fixed the right',
|
|
32
|
+
noFixedTitle: 'Not Fixed',
|
|
33
|
+
},
|
|
34
|
+
editableProTable: {
|
|
35
|
+
add: 'add a row of data',
|
|
36
|
+
onlyAddOneLine: 'Only one line can be added',
|
|
37
|
+
save: 'Save',
|
|
38
|
+
delete: 'Delete',
|
|
39
|
+
cancel: 'Cancel',
|
|
40
|
+
deleteThisLine: 'Delete this line?',
|
|
41
|
+
confirmButtonText: 'Yes',
|
|
42
|
+
cancelButtonText: 'No',
|
|
43
|
+
onlyOneLineEditor: 'Only one line can be edited',
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
elProComponents: {
|
|
3
|
+
placeholder: {
|
|
4
|
+
input: '请输入',
|
|
5
|
+
select: '请选择',
|
|
6
|
+
selectTime: '选择时间',
|
|
7
|
+
selectDate: '选择日期'
|
|
8
|
+
},
|
|
9
|
+
proForm: {
|
|
10
|
+
reset: '重置',
|
|
11
|
+
submit: '提交'
|
|
12
|
+
},
|
|
13
|
+
dialogForm: {
|
|
14
|
+
cancel: '取消',
|
|
15
|
+
confirm: '确定'
|
|
16
|
+
},
|
|
17
|
+
proTable: {
|
|
18
|
+
expand: '展开',
|
|
19
|
+
collapse: '收起',
|
|
20
|
+
search: '查询',
|
|
21
|
+
reset: '重置',
|
|
22
|
+
},
|
|
23
|
+
tableToolBar: {
|
|
24
|
+
columnSetting: '列设置',
|
|
25
|
+
reset: '重置',
|
|
26
|
+
columnDisplay: '列展示',
|
|
27
|
+
leftPin: '固定在列首',
|
|
28
|
+
rightPin: '固定在列尾',
|
|
29
|
+
noPin: '不固定',
|
|
30
|
+
leftFixedTitle: '固定在左侧',
|
|
31
|
+
rightFixedTitle: '固定在右侧',
|
|
32
|
+
noFixedTitle: '不固定',
|
|
33
|
+
},
|
|
34
|
+
editableProTable: {
|
|
35
|
+
add: '添加一行数据',
|
|
36
|
+
onlyAddOneLine: '只能新增一行',
|
|
37
|
+
save: '保存',
|
|
38
|
+
delete: '删除',
|
|
39
|
+
cancel: '取消',
|
|
40
|
+
deleteThisLine: '删除此项?',
|
|
41
|
+
confirmButtonText: '确定',
|
|
42
|
+
cancelButtonText: '取消',
|
|
43
|
+
onlyOneLineEditor: '只能同时编辑一行',
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// 断点配置
|
|
2
|
+
const BREAKPOINTS = {
|
|
3
|
+
xs: 0, // < 768px
|
|
4
|
+
sm: 768, // ≥ 768px
|
|
5
|
+
md: 992, // ≥ 992px
|
|
6
|
+
lg: 1200, // ≥ 1200px
|
|
7
|
+
xl: 1920 // ≥ 1920px
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// Grid cols 份数
|
|
11
|
+
export const GRID_COLUMNS = 24
|
|
12
|
+
|
|
13
|
+
// 断点所占的份数
|
|
14
|
+
// 覆盖关系:默认 (span) < xs < sm < md < lg < xl
|
|
15
|
+
// 特殊情况:未指定默认(span)则显示 24 列
|
|
16
|
+
export const defaultColConfig = {
|
|
17
|
+
xs: 24, // <768px
|
|
18
|
+
sm: 24, // >=768px
|
|
19
|
+
md: 12, // >=992px
|
|
20
|
+
lg: 8, // ≥1200px
|
|
21
|
+
xl: 6, // ≥1920px
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// 断点优先级(从大到小)
|
|
25
|
+
export const BREAKPOINT_ORDER = ['xl', 'lg', 'md', 'sm', 'xs']
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 根据当前宽度获取对应的断点
|
|
29
|
+
* @param {number} width - 当前宽度
|
|
30
|
+
* @returns {string} - 断点名称
|
|
31
|
+
*/
|
|
32
|
+
const getCurrentBreakpoint = (width) => {
|
|
33
|
+
if (width >= BREAKPOINTS.xl) return 'xl'
|
|
34
|
+
if (width >= BREAKPOINTS.lg) return 'lg'
|
|
35
|
+
if (width >= BREAKPOINTS.md) return 'md'
|
|
36
|
+
if (width >= BREAKPOINTS.sm) return 'sm'
|
|
37
|
+
return 'xs'
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 动态计算当前应占的份数
|
|
42
|
+
* @param {Object} config - 配置对象 {span, xs, sm, md, lg, xl}
|
|
43
|
+
* @returns {number} - 应占的份数
|
|
44
|
+
*/
|
|
45
|
+
export const calculateCurrentSpan = (config) => {
|
|
46
|
+
const breakpoint = getCurrentBreakpoint(window.innerWidth)
|
|
47
|
+
|
|
48
|
+
// 按优先级获取配置值
|
|
49
|
+
const breakpoints = BREAKPOINT_ORDER
|
|
50
|
+
const currentIndex = breakpoints.indexOf(breakpoint)
|
|
51
|
+
|
|
52
|
+
// 按断点优先级查找
|
|
53
|
+
for (let i = currentIndex; i < breakpoints.length; i++) {
|
|
54
|
+
const bp = breakpoints[i]
|
|
55
|
+
if (config[bp]) {
|
|
56
|
+
return config[bp]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return config.span || GRID_COLUMNS
|
|
61
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const debounce = (func, delay = 150) => {
|
|
2
|
+
let timeout
|
|
3
|
+
const debounced = (...args) => {
|
|
4
|
+
if (timeout) {
|
|
5
|
+
clearTimeout(timeout)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
timeout = setTimeout(() => {
|
|
9
|
+
func.apply(this, args)
|
|
10
|
+
}, delay)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// 添加取消方法
|
|
14
|
+
debounced.cancel = function() {
|
|
15
|
+
if (timeout) {
|
|
16
|
+
clearTimeout(timeout);
|
|
17
|
+
timeout = null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return debounced
|
|
22
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { t } from 'element-ui-pro-components/src/locale'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @desc 获取表单元素默认的 placeholder
|
|
5
|
+
* @param {String} valueType 表单元素类型
|
|
6
|
+
*/
|
|
7
|
+
function getDefaultPlaceholder(valueType) {
|
|
8
|
+
switch (valueType) {
|
|
9
|
+
case 'input':
|
|
10
|
+
return t('elProComponents.placeholder.input')
|
|
11
|
+
case 'select':
|
|
12
|
+
case 'cascader':
|
|
13
|
+
return t('elProComponents.placeholder.select')
|
|
14
|
+
case 'time-picker':
|
|
15
|
+
return t('elProComponents.placeholder.selectTime')
|
|
16
|
+
case 'date-picker':
|
|
17
|
+
return t('elProComponents.placeholder.selectDate')
|
|
18
|
+
default:
|
|
19
|
+
return ''
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @desc 设置 placeholder
|
|
25
|
+
* @param {Object} fieldProps 表单元素属性
|
|
26
|
+
* @param {String} valueType 表单元素类型
|
|
27
|
+
*/
|
|
28
|
+
export function setPlaceholder(fieldProps, valueType) {
|
|
29
|
+
fieldProps.placeholder = fieldProps.placeholder ?? getDefaultPlaceholder(valueType)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @desc 设置 select options
|
|
34
|
+
* @param {Object} item 表单项
|
|
35
|
+
* @param {String} item.valueType 表单类型
|
|
36
|
+
* @param {Array} item.options 下拉列表
|
|
37
|
+
* @param {String} item.prop 字段属性值
|
|
38
|
+
* @param {Function} item.optionLoader 异步获取下拉数据
|
|
39
|
+
* @param {Object} cachedOptions 下拉数据
|
|
40
|
+
*/
|
|
41
|
+
export function setSelectOptions(item, cachedOptions) {
|
|
42
|
+
const { valueType, prop, options, valueEnum, optionLoader } = item
|
|
43
|
+
if (valueType !== 'select') {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 如果已有 options,保持不变
|
|
48
|
+
if (options?.length > 0) {
|
|
49
|
+
return
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// 有 valueEnum,自动转换
|
|
53
|
+
if (valueEnum) {
|
|
54
|
+
if (valueEnum instanceof Map) {
|
|
55
|
+
item.options = Array.from(valueEnum, ([key, value]) => ({ label: value, value: key }))
|
|
56
|
+
} else {
|
|
57
|
+
item.options = Object.entries(valueEnum)
|
|
58
|
+
.map(([key, value]) => ({ label: value, value: key }))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 设置 options:优先使用缓存
|
|
65
|
+
item.options = optionLoader && cachedOptions[prop]
|
|
66
|
+
? cachedOptions[prop]
|
|
67
|
+
: []
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @desc 设置 select options
|
|
72
|
+
* @param {Object} fieldProps 表单元素属性
|
|
73
|
+
* @param {Object} item 表单项
|
|
74
|
+
* @param {String} item.valueType 表单类型
|
|
75
|
+
* @param {String} item.prop 字段属性值
|
|
76
|
+
* @param {Function} item.optionLoader 异步获取下拉数据
|
|
77
|
+
* @param {Object} cachedOptions 下拉数据
|
|
78
|
+
*/
|
|
79
|
+
export function setCascaderOptions(fieldProps, item, cachedOptions) {
|
|
80
|
+
const { valueType, prop, optionLoader } = item
|
|
81
|
+
if (valueType !== 'cascader') {
|
|
82
|
+
return
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// 如果已有 options,保持不变
|
|
86
|
+
if (fieldProps.options?.length > 0) {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 设置 options:优先使用缓存
|
|
91
|
+
if (optionLoader && cachedOptions[prop]) {
|
|
92
|
+
fieldProps.options = cachedOptions[prop]
|
|
93
|
+
}
|
|
94
|
+
}
|