明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_front
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
jt_front
Commits
ea70d53d
Commit
ea70d53d
authored
Apr 10, 2026
by
zhanghan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
ec2bef8a
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
11 deletions
+76
-11
CommonSelector.vue
src/components/CommonSelector.vue
+25
-8
index.vue
src/components/FormDynamicTable/index.vue
+34
-2
SuperForm.vue
src/components/common/SuperForm.vue
+17
-1
No files found.
src/components/CommonSelector.vue
View file @
ea70d53d
...
@@ -12,7 +12,7 @@
...
@@ -12,7 +12,7 @@
>
>
<el-option
<el-option
v-for=
"(item, index) in currentOptions"
v-for=
"(item, index) in currentOptions"
:key=
"`$
{dictName}-${index}`"
:key=
"`$
{dictName
|| 'custom'
}-${index}`"
:label="item[labelKey]"
:label="item[labelKey]"
:value="item[valueKey]"
:value="item[valueKey]"
>
</el-option>
>
</el-option>
...
@@ -28,7 +28,7 @@
...
@@ -28,7 +28,7 @@
>
>
<el-radio
<el-radio
v-for=
"(item, index) in currentOptions"
v-for=
"(item, index) in currentOptions"
:key=
"`$
{dictName}-${index}`"
:key=
"`$
{dictName
|| 'custom'
}-${index}`"
:value="item[valueKey]"
:value="item[valueKey]"
>
>
{{
item
[
labelKey
]
}}
{{
item
[
labelKey
]
}}
...
@@ -47,17 +47,22 @@ import {
...
@@ -47,17 +47,22 @@ import {
onUnmounted
,
onUnmounted
,
}
from
"vue"
;
}
from
"vue"
;
// 极简Props:仅传 v-model + dictName
(必传
),其余可选
// 极简Props:仅传 v-model + dictName
/options(二选一
),其余可选
const
props
=
defineProps
({
const
props
=
defineProps
({
// 双向绑定值(必传)
// 双向绑定值(必传)
modelValue
:
{
modelValue
:
{
type
:
[
String
,
Number
,
Object
],
type
:
[
String
,
Number
,
Object
],
default
:
undefined
,
default
:
undefined
,
},
},
// 必传:指定从resourceData中取哪个字典(如dqlx/ zdfx-type/ fileHierarchy)
// 可选:直接传入选项数据(优先级高于 dictName)
options
:
{
type
:
Array
,
default
:
()
=>
[],
},
// 可选:指定从resourceData中取哪个字典(如dqlx/ zdfx-type/ fileHierarchy)
dictName
:
{
dictName
:
{
type
:
String
,
type
:
String
,
required
:
tru
e
,
required
:
fals
e
,
},
},
// 可选:自定义选项标签字段(默认name)
// 可选:自定义选项标签字段(默认name)
labelKey
:
{
labelKey
:
{
...
@@ -103,8 +108,20 @@ const emit = defineEmits(["update:modelValue", "change"]);
...
@@ -103,8 +108,20 @@ const emit = defineEmits(["update:modelValue", "change"]);
const
innerValue
=
ref
(
props
.
modelValue
);
// 内部绑定值
const
innerValue
=
ref
(
props
.
modelValue
);
// 内部绑定值
const
currentOptions
=
ref
([]);
// 最终渲染的字典数据
const
currentOptions
=
ref
([]);
// 最终渲染的字典数据
// 核心方法:
从sessionStorage读取resourceData并匹配字典
// 核心方法:
获取选项数据(优先使用传入的 options,否则从 sessionStorage 读取)
const
getDictFromStorage
=
()
=>
{
const
getDictFromStorage
=
()
=>
{
// 如果传入了 options,优先使用
if
(
props
.
options
&&
props
.
options
.
length
>
0
)
{
currentOptions
.
value
=
props
.
options
;
return
;
}
// 否则从 sessionStorage 读取(需要提供 dictName)
if
(
!
props
.
dictName
)
{
currentOptions
.
value
=
[];
return
;
}
try
{
try
{
// 读取并解析sessionStorage中的resourceData
// 读取并解析sessionStorage中的resourceData
const
resourceStr
=
sessionStorage
.
getItem
(
"resourceData"
)
||
"{}"
;
const
resourceStr
=
sessionStorage
.
getItem
(
"resourceData"
)
||
"{}"
;
...
@@ -143,9 +160,9 @@ watch(
...
@@ -143,9 +160,9 @@ watch(
{
immediate
:
true
},
{
immediate
:
true
},
);
);
// 监听2:dictName/labelKey/valueKey
变化,重新读取字典(适配动态切换字典
的场景)
// 监听2:dictName/labelKey/valueKey
/options变化,重新读取字典(适配动态切换字典或选项
的场景)
watch
(
watch
(
()
=>
[
props
.
dictName
,
props
.
labelKey
,
props
.
valueKey
],
()
=>
[
props
.
dictName
,
props
.
labelKey
,
props
.
valueKey
,
props
.
options
],
()
=>
{
()
=>
{
getDictFromStorage
();
getDictFromStorage
();
},
},
...
...
src/components/FormDynamicTable/index.vue
View file @
ea70d53d
...
@@ -174,6 +174,21 @@
...
@@ -174,6 +174,21 @@
:isInline=
"col.isInline ?? true"
:isInline=
"col.isInline ?? true"
/>
/>
</
template
>
</
template
>
<!-- CommonSelector 通用选择器类型 -->
<
template
v-else-if=
"col.type === 'common-selector'"
>
<CommonSelector
v-model=
"scope.row[col.prop]"
:dictName=
"col.dictName"
:options=
"col.options"
:labelKey=
"col.labelKey"
:valueKey=
"col.valueKey"
:radio=
"col.radio"
:disabled=
"disabled || col.disabled"
:placeholder=
"col.placeholder"
:clearable=
"col.clearable !== false"
/>
</
template
>
</template>
</template>
</el-table-column>
</el-table-column>
</el-table-column>
</el-table-column>
...
@@ -309,6 +324,21 @@
...
@@ -309,6 +324,21 @@
:isInline=
"col.isInline ?? true"
:isInline=
"col.isInline ?? true"
/>
/>
</
template
>
</
template
>
<!-- CommonSelector 通用选择器类型 -->
<
template
v-else-if=
"col.type === 'common-selector'"
>
<CommonSelector
v-model=
"scope.row[col.prop]"
:dictName=
"col.dictName"
:options=
"col.options"
:labelKey=
"col.labelKey"
:valueKey=
"col.valueKey"
:radio=
"col.radio"
:disabled=
"disabled || col.disabled"
:placeholder=
"col.placeholder"
:clearable=
"col.clearable !== false"
/>
</
template
>
</template>
</template>
</el-table-column>
</el-table-column>
...
@@ -372,6 +402,8 @@ import {
...
@@ -372,6 +402,8 @@ import {
import
{
ElMessageBox
,
ElMessage
}
from
"element-plus"
;
import
{
ElMessageBox
,
ElMessage
}
from
"element-plus"
;
// 引入文件上传组件(适配你的项目路径)
// 引入文件上传组件(适配你的项目路径)
import
FileUploader
from
"@/components/FileUploader/index.vue"
;
import
FileUploader
from
"@/components/FileUploader/index.vue"
;
// 引入通用选择器组件
import
CommonSelector
from
"@/components/CommonSelector.vue"
;
// 获取全局实例(用于接口请求/全局配置)
// 获取全局实例(用于接口请求/全局配置)
const
{
proxy
}
=
getCurrentInstance
();
const
{
proxy
}
=
getCurrentInstance
();
...
@@ -517,9 +549,9 @@ const handleAdd = () => {
...
@@ -517,9 +549,9 @@ const handleAdd = () => {
if
(
col
.
type
===
"upload"
&&
newRow
[
col
.
prop
]
===
undefined
)
{
if
(
col
.
type
===
"upload"
&&
newRow
[
col
.
prop
]
===
undefined
)
{
newRow
[
col
.
prop
]
=
[];
newRow
[
col
.
prop
]
=
[];
}
}
// Select/Input 初始化为空字符串
// Select/Input
/Number/CommonSelector
初始化为空字符串
if
(
if
(
[
"input"
,
"select"
,
"number"
].
includes
(
col
.
type
)
&&
[
"input"
,
"select"
,
"number"
,
"common-selector"
].
includes
(
col
.
type
)
&&
newRow
[
col
.
prop
]
===
undefined
newRow
[
col
.
prop
]
===
undefined
)
{
)
{
newRow
[
col
.
prop
]
=
""
;
newRow
[
col
.
prop
]
=
""
;
...
...
src/components/common/SuperForm.vue
View file @
ea70d53d
...
@@ -396,12 +396,27 @@
...
@@ -396,12 +396,27 @@
/>
/>
</
template
>
</
template
>
<!-- 通用选择器 -->
<
template
v-else-if=
"item.type === 'selector'"
>
<CommonSelector
v-model=
"formData[item.field]"
:dict-name=
"item.dictName"
:radio=
"item.radio"
:placeholder=
"item.placeholder"
:clearable=
"item.clearable !== false"
:disabled=
"item.disabled"
:label-key=
"item.labelKey"
:value-key=
"item.valueKey"
@
change=
"handleFieldChange(item, $event)"
/>
</
template
>
<!-- 自定义组件 -->
<!-- 自定义组件 -->
<
template
v-else-if=
"item.type === 'component' && item.component"
>
<
template
v-else-if=
"item.type === 'component' && item.component"
>
<component
<component
:is=
"item.component"
:is=
"item.component"
v-model=
"formData[item.field]"
v-model=
"formData[item.field]"
v-bind=
"
getItemProps(item)
"
v-bind=
"
{ ...getItemProps(item), ...item.componentProps }
"
@change="handleFieldChange(item, $event)"
@change="handleFieldChange(item, $event)"
@blur="handleFieldBlur(item, $event)"
@blur="handleFieldBlur(item, $event)"
@focus="handleFieldFocus(item, $event)"
@focus="handleFieldFocus(item, $event)"
...
@@ -483,6 +498,7 @@
...
@@ -483,6 +498,7 @@
<
script
setup
>
<
script
setup
>
import
{
ref
,
reactive
,
computed
,
watch
,
onMounted
,
getCurrentInstance
}
from
'vue'
import
{
ref
,
reactive
,
computed
,
watch
,
onMounted
,
getCurrentInstance
}
from
'vue'
import
{
UploadFilled
}
from
'@element-plus/icons-vue'
import
{
UploadFilled
}
from
'@element-plus/icons-vue'
import
CommonSelector
from
'@/components/CommonSelector.vue'
const
props
=
defineProps
({
const
props
=
defineProps
({
// 表单配置
// 表单配置
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment