Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b4d85b78
authored
May 01, 2024
by
puhui999
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form-create: 封装通用选择器 hook
parent
c1c21d82
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
114 additions
and
63 deletions
+114
-63
src/components/DictSelect/index.ts
+0
-3
src/components/DictSelect/src/DictSelect.vue
+0
-46
src/components/FormCreate/src/components/useCurrencySelect.tsx
+93
-10
src/components/FormCreate/src/config/selectRule.ts
+11
-0
src/components/FormCreate/src/config/useDictSelectRule.ts
+1
-1
src/components/FormCreate/src/type/index.ts
+3
-2
src/components/FormCreate/src/useFormCreateDesigner.ts
+2
-0
src/plugins/formCreate/index.ts
+4
-1
No files found.
src/components/DictSelect/index.ts
deleted
100644 → 0
View file @
c1c21d82
import
DictSelect
from
'./src/DictSelect.vue'
export
{
DictSelect
}
src/components/DictSelect/src/DictSelect.vue
deleted
100644 → 0
View file @
c1c21d82
<!-- 数据字典 Select 选择器 -->
<
template
>
<el-select
class=
"w-1/1"
v-bind=
"attrs"
>
<template
v-if=
"valueType === 'int'"
>
<el-option
v-for=
"(dict, index) in getIntDictOptions(dictType)"
:key=
"index"
:label=
"dict.label"
:value=
"dict.value"
/>
</
template
>
<
template
v-if=
"valueType === 'str'"
>
<el-option
v-for=
"(dict, index) in getStrDictOptions(dictType)"
:key=
"index"
:label=
"dict.label"
:value=
"dict.value"
/>
</
template
>
<
template
v-if=
"valueType === 'bool'"
>
<el-option
v-for=
"(dict, index) in getBoolDictOptions(dictType)"
:key=
"index"
:label=
"dict.label"
:value=
"dict.value"
/>
</
template
>
</el-select>
</template>
<
script
lang=
"ts"
setup
>
import
{
getBoolDictOptions
,
getIntDictOptions
,
getStrDictOptions
}
from
'@/utils/dict'
// 接受父组件参数
interface
Props
{
dictType
:
string
// 字典类型
valueType
:
string
// 字典值类型
}
withDefaults
(
defineProps
<
Props
>
(),
{
dictType
:
''
,
valueType
:
'str'
})
const
attrs
=
useAttrs
()
defineOptions
({
name
:
'DictSelect'
})
</
script
>
src/components/FormCreate/src/components/useCurrencySelect.tsx
View file @
b4d85b78
import
request
from
'@/config/axios'
import
request
from
'@/config/axios'
import
{
isEmpty
}
from
'@/utils/is'
import
{
isEmpty
}
from
'@/utils/is'
import
{
CurrencySelectProps
}
from
'@/components/FormCreate/src/type'
import
{
CurrencySelectProps
}
from
'@/components/FormCreate/src/type'
import
{
getBoolDictOptions
,
getIntDictOptions
,
getStrDictOptions
}
from
'@/utils/dict'
export
const
useCurrencySelect
=
(
option
:
CurrencySelectProps
)
=>
{
export
const
useCurrencySelect
=
(
option
:
CurrencySelectProps
)
=>
{
return
defineComponent
({
return
defineComponent
({
name
:
option
.
name
,
name
:
option
.
name
,
props
:
{
props
:
{
//
字典类型
//
选项标签
labelField
:
{
labelField
:
{
type
:
String
,
type
:
String
,
default
:
()
=>
option
.
labelField
??
''
default
:
()
=>
option
.
labelField
??
'
label
'
},
},
//
字典值类型
//
选项的值
valueField
:
{
valueField
:
{
type
:
String
,
type
:
String
,
default
:
()
=>
option
.
valueField
??
''
default
:
()
=>
option
.
valueField
??
'
value
'
},
},
// api 接口
// api 接口
restful
:
{
restful
:
{
type
:
String
,
type
:
String
,
default
:
()
=>
option
.
restful
??
''
default
:
()
=>
option
.
restful
??
''
},
// 字典类型
dictType
:
{
type
:
String
,
default
:
''
},
// 字典值类型 'str' | 'int' | 'bool'
dictValueType
:
{
type
:
String
,
default
:
'str'
},
// 选择器类型,下拉框 select、多选框 checkbox、单选框 radio
selectType
:
{
type
:
String
,
default
:
'select'
}
}
},
},
setup
(
props
)
{
setup
(
props
)
{
...
@@ -27,6 +43,12 @@ export const useCurrencySelect = (option: CurrencySelectProps) => {
...
@@ -27,6 +43,12 @@ export const useCurrencySelect = (option: CurrencySelectProps) => {
const
options
=
ref
<
any
[]
>
([])
// 下拉数据
const
options
=
ref
<
any
[]
>
([])
// 下拉数据
const
getOptions
=
async
()
=>
{
const
getOptions
=
async
()
=>
{
options
.
value
=
[]
options
.
value
=
[]
// 字典选择器
if
(
option
.
isDict
)
{
options
.
value
=
getDictOptions
()
return
}
// 接口选择器
if
(
isEmpty
(
props
.
restful
))
{
if
(
isEmpty
(
props
.
restful
))
{
return
return
}
}
...
@@ -41,17 +63,78 @@ export const useCurrencySelect = (option: CurrencySelectProps) => {
...
@@ -41,17 +63,78 @@ export const useCurrencySelect = (option: CurrencySelectProps) => {
}
}
console
.
log
(
`接口[
${
props
.
restful
}
] 返回结果不是一个数组`
)
console
.
log
(
`接口[
${
props
.
restful
}
] 返回结果不是一个数组`
)
}
}
// 获得字典配置
const
getDictOptions
=
()
=>
{
switch
(
props
.
dictValueType
)
{
case
'str'
:
return
getStrDictOptions
(
props
.
dictType
)
case
'int'
:
return
getIntDictOptions
(
props
.
dictType
)
case
'bool'
:
return
getBoolDictOptions
(
props
.
dictType
)
default
:
return
[]
}
}
onMounted
(
async
()
=>
{
onMounted
(
async
()
=>
{
await
getOptions
()
await
getOptions
()
})
})
const
buildSelect
=
()
=>
{
return
(
<>
<
el
-
select
class=
"w-1/1"
{
...
attrs
}
>
{
options
.
value
.
map
((
item
,
index
)
=>
(
<
el
-
option
key=
{
index
}
label=
{
item
.
label
}
value=
{
item
.
value
}
/>
))
}
</
el
-
select
>
</>
)
}
const
buildCheckbox
=
()
=>
{
if
(
isEmpty
(
options
.
value
))
{
options
.
value
=
[
{
label
:
'选项1'
,
value
:
'选项1'
},
{
label
:
'选项2'
,
value
:
'选项2'
}
]
}
return
(
<>
<
el
-
checkbox
-
group
class=
"w-1/1"
{
...
attrs
}
>
{
options
.
value
.
map
((
item
,
index
)
=>
(
<
el
-
checkbox
key=
{
index
}
label=
{
item
.
label
}
value=
{
item
.
value
}
/>
))
}
</
el
-
checkbox
-
group
>
</>
)
}
const
buildRadio
=
()
=>
{
if
(
isEmpty
(
options
.
value
))
{
options
.
value
=
[
{
label
:
'选项1'
,
value
:
'选项1'
},
{
label
:
'选项2'
,
value
:
'选项2'
}
]
}
return
(
<>
<
el
-
radio
-
group
class=
"w-1/1"
{
...
attrs
}
>
{
options
.
value
.
map
((
item
,
index
)
=>
(
<
el
-
radio
key=
{
index
}
value=
{
item
.
value
}
>
{
item
.
label
}
</
el
-
radio
>
))
}
</
el
-
radio
-
group
>
</>
)
}
return
()
=>
(
return
()
=>
(
<>
<>
<
el
-
select
className=
"w-1/1"
{
...
attrs
}
>
{
props
.
selectType
===
'select'
{
options
.
value
.
map
((
item
,
index
)
=>
(
?
buildSelect
()
<
el
-
option
key=
{
index
}
label=
{
item
.
label
}
value=
{
item
.
value
}
/>
:
props
.
selectType
===
'radio'
))
}
?
buildRadio
()
</
el
-
select
>
:
props
.
selectType
===
'checkbox'
?
buildCheckbox
()
:
buildSelect
()
}
</>
</>
)
)
}
}
...
...
src/components/FormCreate/src/config/selectRule.ts
View file @
b4d85b78
const
selectRule
=
[
const
selectRule
=
[
{
type
:
'select'
,
field
:
'selectType'
,
title
:
'选择器类型'
,
value
:
'select'
,
options
:
[
{
label
:
'下拉框'
,
value
:
'select'
},
{
label
:
'单选框'
,
value
:
'radio'
},
{
label
:
'多选框'
,
value
:
'checkbox'
}
]
},
{
type
:
'switch'
,
field
:
'multiple'
,
title
:
'是否多选'
},
{
type
:
'switch'
,
field
:
'multiple'
,
title
:
'是否多选'
},
{
{
type
:
'switch'
,
type
:
'switch'
,
...
...
src/components/FormCreate/src/config/useDictSelectRule.ts
View file @
b4d85b78
...
@@ -46,7 +46,7 @@ export const useDictSelectRule = () => {
...
@@ -46,7 +46,7 @@ export const useDictSelectRule = () => {
},
},
{
{
type
:
'select'
,
type
:
'select'
,
field
:
'
v
alueType'
,
field
:
'
dictV
alueType'
,
title
:
'字典值类型'
,
title
:
'字典值类型'
,
value
:
'str'
,
value
:
'str'
,
options
:
[
options
:
[
...
...
src/components/FormCreate/src/type/index.ts
View file @
b4d85b78
...
@@ -35,9 +35,10 @@ export interface DragRule {
...
@@ -35,9 +35,10 @@ export interface DragRule {
// 通用下拉组件 Props 类型
// 通用下拉组件 Props 类型
export
interface
CurrencySelectProps
{
export
interface
CurrencySelectProps
{
name
:
string
// 组件名称
name
:
string
// 组件名称
labelField
?:
string
//
字典类型
labelField
?:
string
//
选项标签
valueField
?:
string
//
字典值类型
valueField
?:
string
//
选项的值
restful
?:
string
// api 接口
restful
?:
string
// api 接口
isDict
?:
boolean
// 是否字典选择器
}
}
// 选择组件规则配置类型
// 选择组件规则配置类型
...
...
src/components/FormCreate/src/useFormCreateDesigner.ts
View file @
b4d85b78
...
@@ -67,6 +67,8 @@ export const useFormCreateDesigner = async (designer: Ref) => {
...
@@ -67,6 +67,8 @@ export const useFormCreateDesigner = async (designer: Ref) => {
designer
.
value
?.
removeMenuItem
(
'fc-editor'
)
designer
.
value
?.
removeMenuItem
(
'fc-editor'
)
// 移除自带的下拉选择器组件,使用 currencySelectRule 替代
// 移除自带的下拉选择器组件,使用 currencySelectRule 替代
designer
.
value
?.
removeMenuItem
(
'select'
)
designer
.
value
?.
removeMenuItem
(
'select'
)
designer
.
value
?.
removeMenuItem
(
'radio'
)
designer
.
value
?.
removeMenuItem
(
'checkbox'
)
const
components
=
[
const
components
=
[
editorRule
,
editorRule
,
uploadFileRule
,
uploadFileRule
,
...
...
src/plugins/formCreate/index.ts
View file @
b4d85b78
...
@@ -19,7 +19,6 @@ import formCreate from '@form-create/element-ui'
...
@@ -19,7 +19,6 @@ import formCreate from '@form-create/element-ui'
import
install
from
'@form-create/element-ui/auto-import'
import
install
from
'@form-create/element-ui/auto-import'
//======================= 自定义组件 =======================
//======================= 自定义组件 =======================
import
{
UploadFile
,
UploadImg
,
UploadImgs
}
from
'@/components/UploadFile'
import
{
UploadFile
,
UploadImg
,
UploadImgs
}
from
'@/components/UploadFile'
import
{
DictSelect
}
from
'@/components/DictSelect'
import
{
useCurrencySelect
}
from
'@/components/FormCreate'
import
{
useCurrencySelect
}
from
'@/components/FormCreate'
import
{
Editor
}
from
'@/components/Editor'
import
{
Editor
}
from
'@/components/Editor'
...
@@ -38,6 +37,10 @@ const DeptSelect = useCurrencySelect({
...
@@ -38,6 +37,10 @@ const DeptSelect = useCurrencySelect({
const
RestfulSelect
=
useCurrencySelect
({
const
RestfulSelect
=
useCurrencySelect
({
name
:
'RestfulSelect'
name
:
'RestfulSelect'
})
})
const
DictSelect
=
useCurrencySelect
({
name
:
'DictSelect'
,
isDict
:
true
})
const
components
=
[
const
components
=
[
ElAside
,
ElAside
,
ElPopconfirm
,
ElPopconfirm
,
...
...
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