Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
89414f17
提交
89414f17
authored
10月 16, 2021
作者:
zuihou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(Form): 新增 ApiRadioGroup 组件
上级
34781d42
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
182 行增加
和
4 行删除
+182
-4
select-demo.ts
mock/demo/select-demo.ts
+4
-4
index.ts
src/components/Form/index.ts
+1
-0
componentMap.ts
src/components/Form/src/componentMap.ts
+2
-0
ApiRadioGroup.vue
src/components/Form/src/components/ApiRadioGroup.vue
+130
-0
index.ts
src/components/Form/src/types/index.ts
+1
-0
index.vue
src/views/demo/form/index.vue
+44
-0
没有找到文件。
mock/demo/select-demo.ts
浏览文件 @
89414f17
import
{
MockMethod
}
from
'vite-plugin-mock'
;
import
{
MockMethod
}
from
'vite-plugin-mock'
;
import
{
resultSuccess
}
from
'../_util'
;
import
{
resultSuccess
}
from
'../_util'
;
const
demoList
=
(
keyword
)
=>
{
const
demoList
=
(
keyword
,
count
=
20
)
=>
{
const
result
=
{
const
result
=
{
list
:
[]
as
any
[],
list
:
[]
as
any
[],
};
};
for
(
let
index
=
0
;
index
<
20
;
index
++
)
{
for
(
let
index
=
0
;
index
<
count
;
index
++
)
{
result
.
list
.
push
({
result
.
list
.
push
({
name
:
`
${
keyword
??
''
}
选项
$
{
index
}
`,
name
:
`
${
keyword
??
''
}
选项
$
{
index
}
`,
id: `
$
{
index
}
`,
id: `
$
{
index
}
`,
...
@@ -20,9 +20,9 @@ export default [
...
@@ -20,9 +20,9 @@ export default [
timeout: 1000,
timeout: 1000,
method: 'get',
method: 'get',
response: ({ query }) => {
response: ({ query }) => {
const { keyword } = query;
const { keyword
, count
} = query;
console.log(keyword);
console.log(keyword);
return resultSuccess(demoList(keyword));
return resultSuccess(demoList(keyword
, count
));
},
},
},
},
] as MockMethod[];
] as MockMethod[];
src/components/Form/index.ts
浏览文件 @
89414f17
...
@@ -9,5 +9,6 @@ export { useForm } from './src/hooks/useForm';
...
@@ -9,5 +9,6 @@ export { useForm } from './src/hooks/useForm';
export
{
default
as
ApiSelect
}
from
'./src/components/ApiSelect.vue'
;
export
{
default
as
ApiSelect
}
from
'./src/components/ApiSelect.vue'
;
export
{
default
as
RadioButtonGroup
}
from
'./src/components/RadioButtonGroup.vue'
;
export
{
default
as
RadioButtonGroup
}
from
'./src/components/RadioButtonGroup.vue'
;
export
{
default
as
ApiTreeSelect
}
from
'./src/components/ApiTreeSelect.vue'
;
export
{
default
as
ApiTreeSelect
}
from
'./src/components/ApiTreeSelect.vue'
;
export
{
default
as
ApiRadioGroup
}
from
'./src/components/ApiRadioGroup.vue'
;
export
{
BasicForm
};
export
{
BasicForm
};
src/components/Form/src/componentMap.ts
浏览文件 @
89414f17
...
@@ -21,6 +21,7 @@ import {
...
@@ -21,6 +21,7 @@ import {
Divider
,
Divider
,
}
from
'ant-design-vue'
;
}
from
'ant-design-vue'
;
import
ApiRadioGroup
from
'./components/ApiRadioGroup.vue'
;
import
RadioButtonGroup
from
'./components/RadioButtonGroup.vue'
;
import
RadioButtonGroup
from
'./components/RadioButtonGroup.vue'
;
import
ApiSelect
from
'./components/ApiSelect.vue'
;
import
ApiSelect
from
'./components/ApiSelect.vue'
;
import
ApiTreeSelect
from
'./components/ApiTreeSelect.vue'
;
import
ApiTreeSelect
from
'./components/ApiTreeSelect.vue'
;
...
@@ -43,6 +44,7 @@ componentMap.set('Select', Select);
...
@@ -43,6 +44,7 @@ componentMap.set('Select', Select);
componentMap
.
set
(
'ApiSelect'
,
ApiSelect
);
componentMap
.
set
(
'ApiSelect'
,
ApiSelect
);
componentMap
.
set
(
'TreeSelect'
,
TreeSelect
);
componentMap
.
set
(
'TreeSelect'
,
TreeSelect
);
componentMap
.
set
(
'ApiTreeSelect'
,
ApiTreeSelect
);
componentMap
.
set
(
'ApiTreeSelect'
,
ApiTreeSelect
);
componentMap
.
set
(
'ApiRadioGroup'
,
ApiRadioGroup
);
componentMap
.
set
(
'Switch'
,
Switch
);
componentMap
.
set
(
'Switch'
,
Switch
);
componentMap
.
set
(
'RadioButtonGroup'
,
RadioButtonGroup
);
componentMap
.
set
(
'RadioButtonGroup'
,
RadioButtonGroup
);
componentMap
.
set
(
'RadioGroup'
,
Radio
.
Group
);
componentMap
.
set
(
'RadioGroup'
,
Radio
.
Group
);
...
...
src/components/Form/src/components/ApiRadioGroup.vue
0 → 100644
浏览文件 @
89414f17
<!--
* @Description:It is troublesome to implement radio button group in the form. So it is extracted independently as a separate component
-->
<
template
>
<RadioGroup
v-bind=
"attrs"
v-model:value=
"state"
button-style=
"solid"
@
change=
"handleChange"
>
<template
v-for=
"item in getOptions"
:key=
"`$
{item.value}`">
<RadioButton
v-if=
"props.isBtn"
:value=
"item.value"
:disabled=
"item.disabled"
>
{{
item
.
label
}}
</RadioButton>
<Radio
v-else
:value=
"item.value"
:disabled=
"item.disabled"
>
{{
item
.
label
}}
</Radio>
</
template
>
</RadioGroup>
</template>
<
script
lang=
"ts"
>
import
{
defineComponent
,
PropType
,
ref
,
watchEffect
,
computed
,
unref
,
watch
}
from
'vue'
;
import
{
Radio
}
from
'ant-design-vue'
;
import
{
isFunction
}
from
'/@/utils/is'
;
import
{
useRuleFormItem
}
from
'/@/hooks/component/useFormItem'
;
import
{
useAttrs
}
from
'/@/hooks/core/useAttrs'
;
import
{
propTypes
}
from
'/@/utils/propTypes'
;
import
{
get
,
omit
}
from
'lodash-es'
;
import
{
useI18n
}
from
'/@/hooks/web/useI18n'
;
type
OptionsItem
=
{
label
:
string
;
value
:
string
|
number
|
boolean
;
disabled
?:
boolean
};
export
default
defineComponent
({
name
:
'ApiRadioGroup'
,
components
:
{
RadioGroup
:
Radio
.
Group
,
RadioButton
:
Radio
.
Button
,
Radio
,
},
props
:
{
api
:
{
type
:
Function
as
PropType
<
(
arg
?:
Recordable
|
string
)
=>
Promise
<
OptionsItem
[]
>>
,
default
:
null
,
},
params
:
{
type
:
[
Object
,
String
]
as
PropType
<
Recordable
|
string
>
,
default
:
()
=>
({}),
},
value
:
{
type
:
[
String
,
Number
,
Boolean
]
as
PropType
<
string
|
number
|
boolean
>
,
},
isBtn
:
{
type
:
[
Boolean
]
as
PropType
<
boolean
>
,
default
:
false
,
},
numberToString
:
propTypes
.
bool
,
resultField
:
propTypes
.
string
.
def
(
''
),
labelField
:
propTypes
.
string
.
def
(
'label'
),
valueField
:
propTypes
.
string
.
def
(
'value'
),
immediate
:
propTypes
.
bool
.
def
(
true
),
},
emits
:
[
'options-change'
,
'change'
],
setup
(
props
,
{
emit
})
{
const
options
=
ref
<
OptionsItem
[]
>
([]);
const
loading
=
ref
(
false
);
const
isFirstLoad
=
ref
(
true
);
const
emitData
=
ref
<
any
[]
>
([]);
const
attrs
=
useAttrs
();
const
{
t
}
=
useI18n
();
// Embedded in the form, just use the hook binding to perform form verification
const
[
state
]
=
useRuleFormItem
(
props
);
// Processing options value
const
getOptions
=
computed
(()
=>
{
const
{
labelField
,
valueField
,
numberToString
}
=
props
;
return
unref
(
options
).
reduce
((
prev
,
next
:
Recordable
)
=>
{
if
(
next
)
{
const
value
=
next
[
valueField
];
prev
.
push
({
label
:
next
[
labelField
],
value
:
numberToString
?
`
${
value
}
`
:
value
,
...
omit
(
next
,
[
labelField
,
valueField
]),
});
}
return
prev
;
},
[]
as
OptionsItem
[]);
});
watchEffect
(()
=>
{
props
.
immediate
&&
fetch
();
});
watch
(
()
=>
props
.
params
,
()
=>
{
!
unref
(
isFirstLoad
)
&&
fetch
();
},
{
deep
:
true
},
);
async
function
fetch
()
{
const
api
=
props
.
api
;
if
(
!
api
||
!
isFunction
(
api
))
return
;
options
.
value
=
[];
try
{
loading
.
value
=
true
;
const
res
=
await
api
(
props
.
params
);
if
(
Array
.
isArray
(
res
))
{
options
.
value
=
res
;
emitChange
();
return
;
}
if
(
props
.
resultField
)
{
options
.
value
=
get
(
res
,
props
.
resultField
)
||
[];
}
emitChange
();
}
catch
(
error
)
{
console
.
warn
(
error
);
}
finally
{
loading
.
value
=
false
;
}
}
function
emitChange
()
{
emit
(
'options-change'
,
unref
(
getOptions
));
}
function
handleChange
(
_
,
...
args
)
{
emitData
.
value
=
args
;
}
return
{
state
,
getOptions
,
attrs
,
loading
,
t
,
handleChange
,
props
};
},
});
</
script
>
src/components/Form/src/types/index.ts
浏览文件 @
89414f17
...
@@ -92,6 +92,7 @@ export type ComponentType =
...
@@ -92,6 +92,7 @@ export type ComponentType =
|
'ApiSelect'
|
'ApiSelect'
|
'TreeSelect'
|
'TreeSelect'
|
'ApiTreeSelect'
|
'ApiTreeSelect'
|
'ApiRadioGroup'
|
'RadioButtonGroup'
|
'RadioButtonGroup'
|
'RadioGroup'
|
'RadioGroup'
|
'Checkbox'
|
'Checkbox'
...
...
src/views/demo/form/index.vue
浏览文件 @
89414f17
...
@@ -411,6 +411,50 @@
...
@@ -411,6 +411,50 @@
},
},
},
},
{
{
field
:
'field34'
,
component
:
'ApiRadioGroup'
,
label
:
'远程Radio'
,
helpMessage
:
[
'ApiRadioGroup组件'
,
'使用接口提供的数据生成选项'
],
required
:
true
,
componentProps
:
{
api
:
optionsListApi
,
params
:
{
count
:
2
,
},
resultField
:
'list'
,
// use name as label
labelField
:
'name'
,
// use id as value
valueField
:
'id'
,
},
defaultValue
:
'1'
,
colProps
:
{
span
:
8
,
},
},
{
field
:
'field35'
,
component
:
'ApiRadioGroup'
,
label
:
'远程Radio'
,
helpMessage
:
[
'ApiRadioGroup组件'
,
'使用接口提供的数据生成选项'
],
required
:
true
,
componentProps
:
{
api
:
optionsListApi
,
params
:
{
count
:
2
,
},
resultField
:
'list'
,
// use name as label
labelField
:
'name'
,
// use id as value
valueField
:
'id'
,
isBtn
:
true
,
},
colProps
:
{
span
:
8
,
},
},
{
field
:
'divider-linked'
,
field
:
'divider-linked'
,
component
:
'Divider'
,
component
:
'Divider'
,
label
:
'字段联动'
,
label
:
'字段联动'
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论