form-create:移除自带的下拉选择器组件,使用 currencySelectRule 替代
This commit is contained in:
parent
0076236280
commit
769b63d9ca
@ -1,3 +1,4 @@
|
|||||||
import { useFormCreateDesigner } from './src/useFormCreateDesigner'
|
import { useFormCreateDesigner } from './src/useFormCreateDesigner'
|
||||||
|
import CurrencySelect from './src/CurrencySelect/index.vue'
|
||||||
|
|
||||||
export { useFormCreateDesigner }
|
export { useFormCreateDesigner, CurrencySelect }
|
||||||
|
53
src/components/FormCreate/src/CurrencySelect/index.vue
Normal file
53
src/components/FormCreate/src/CurrencySelect/index.vue
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<template>
|
||||||
|
<el-select class="w-1/1" v-bind="attrs">
|
||||||
|
<el-option
|
||||||
|
v-for="(item, index) in options"
|
||||||
|
:key="index"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.value"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import request from '@/config/axios'
|
||||||
|
import { isEmpty } from '@/utils/is'
|
||||||
|
|
||||||
|
defineOptions({ name: 'CurrencySelect' })
|
||||||
|
|
||||||
|
// 接受父组件参数
|
||||||
|
interface Props {
|
||||||
|
labelField?: string // 字典类型
|
||||||
|
valueField?: string // 字典值类型
|
||||||
|
restful?: string // api 接口
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
labelField: 'nickname',
|
||||||
|
valueField: 'id',
|
||||||
|
restful: '/system/user/simple-list'
|
||||||
|
})
|
||||||
|
|
||||||
|
const attrs = useAttrs()
|
||||||
|
const options = ref<any[]>([]) // 下拉数据
|
||||||
|
const getOptions = async () => {
|
||||||
|
options.value = []
|
||||||
|
if (isEmpty(props.restful)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO 只支持 GET 查询,复杂下拉构建条件请使用业务表单
|
||||||
|
const data = await request.get({ url: props.restful })
|
||||||
|
if (Array.isArray(data)) {
|
||||||
|
options.value = data.map((item: any) => ({
|
||||||
|
label: item[props.labelField],
|
||||||
|
value: item[props.valueField]
|
||||||
|
}))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(`接口[${props.restful}] 返回结果不是一个数组`)
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
getOptions()
|
||||||
|
})
|
||||||
|
</script>
|
@ -2,7 +2,7 @@ import { useUploadFileRule } from './useUploadFileRule'
|
|||||||
import { useUploadImgRule } from './useUploadImgRule'
|
import { useUploadImgRule } from './useUploadImgRule'
|
||||||
import { useUploadImgsRule } from './useUploadImgsRule'
|
import { useUploadImgsRule } from './useUploadImgsRule'
|
||||||
import { useDictSelectRule } from './useDictSelectRule'
|
import { useDictSelectRule } from './useDictSelectRule'
|
||||||
import { useUserSelectRule } from './useUserSelectRule'
|
import { useCurrencySelectRule } from './useCurrencySelectRule'
|
||||||
import { useEditorRule } from './useEditorRule'
|
import { useEditorRule } from './useEditorRule'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@ -10,6 +10,6 @@ export {
|
|||||||
useUploadImgRule,
|
useUploadImgRule,
|
||||||
useUploadImgsRule,
|
useUploadImgsRule,
|
||||||
useDictSelectRule,
|
useDictSelectRule,
|
||||||
useUserSelectRule,
|
useCurrencySelectRule,
|
||||||
useEditorRule
|
useEditorRule
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
import { generateUUID } from '@/utils'
|
||||||
|
import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils'
|
||||||
|
import selectRule from '@/components/FormCreate/src/config/selectRule'
|
||||||
|
|
||||||
|
export const useCurrencySelectRule = () => {
|
||||||
|
const label = '通用选择器'
|
||||||
|
const name = 'CurrencySelect'
|
||||||
|
return {
|
||||||
|
icon: 'icon-select',
|
||||||
|
label,
|
||||||
|
name,
|
||||||
|
rule() {
|
||||||
|
return {
|
||||||
|
type: name,
|
||||||
|
field: generateUUID(),
|
||||||
|
title: label,
|
||||||
|
info: '下面以获得系统用户下拉数据为例,您可以自行按需更改',
|
||||||
|
$required: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
props(_, { t }) {
|
||||||
|
return localeProps(t, name + '.props', [
|
||||||
|
makeRequiredRule(),
|
||||||
|
{
|
||||||
|
type: 'input',
|
||||||
|
field: 'restful',
|
||||||
|
title: 'restful api 接口',
|
||||||
|
value: '/system/user/simple-list'
|
||||||
|
},
|
||||||
|
{ type: 'input', field: 'labelField', title: 'label 属性', value: 'nickname' },
|
||||||
|
{ type: 'input', field: 'valueField', title: 'value 属性', value: 'id' },
|
||||||
|
...selectRule
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +0,0 @@
|
|||||||
import { generateUUID } from '@/utils'
|
|
||||||
import { localeProps, makeRequiredRule } from '@/components/FormCreate/src/utils'
|
|
||||||
import selectRule from '@/components/FormCreate/src/config/selectRule'
|
|
||||||
|
|
||||||
export const useUserSelectRule = () => {
|
|
||||||
const label = '用户选择器'
|
|
||||||
const name = 'UserSelect'
|
|
||||||
return {
|
|
||||||
icon: 'icon-select',
|
|
||||||
label,
|
|
||||||
name,
|
|
||||||
rule() {
|
|
||||||
return {
|
|
||||||
type: name,
|
|
||||||
field: generateUUID(),
|
|
||||||
title: label,
|
|
||||||
info: '',
|
|
||||||
$required: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props(_, { t }) {
|
|
||||||
return localeProps(t, name + '.props', [makeRequiredRule(), ...selectRule])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
|
useCurrencySelectRule,
|
||||||
useDictSelectRule,
|
useDictSelectRule,
|
||||||
useEditorRule,
|
useEditorRule,
|
||||||
useUploadFileRule,
|
useUploadFileRule,
|
||||||
useUploadImgRule,
|
useUploadImgRule,
|
||||||
useUploadImgsRule,
|
useUploadImgsRule
|
||||||
useUserSelectRule
|
|
||||||
} from './config'
|
} from './config'
|
||||||
import { Ref } from 'vue'
|
import { Ref } from 'vue'
|
||||||
|
|
||||||
@ -24,20 +24,22 @@ export const useFormCreateDesigner = (designer: Ref) => {
|
|||||||
const uploadImgRule = useUploadImgRule()
|
const uploadImgRule = useUploadImgRule()
|
||||||
const uploadImgsRule = useUploadImgsRule()
|
const uploadImgsRule = useUploadImgsRule()
|
||||||
const dictSelectRule = useDictSelectRule()
|
const dictSelectRule = useDictSelectRule()
|
||||||
const userSelectRule = useUserSelectRule()
|
const currencySelectRule = useCurrencySelectRule()
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 移除自带的上传组件规则,使用 uploadFileRule、uploadImgRule、uploadImgsRule 替代
|
// 移除自带的上传组件规则,使用 uploadFileRule、uploadImgRule、uploadImgsRule 替代
|
||||||
designer.value?.removeMenuItem('upload')
|
designer.value?.removeMenuItem('upload')
|
||||||
// 移除自带的富文本组件规则,使用 editorRule 替代
|
// 移除自带的富文本组件规则,使用 editorRule 替代
|
||||||
designer.value?.removeMenuItem('fc-editor')
|
designer.value?.removeMenuItem('fc-editor')
|
||||||
|
// 移除自带的下拉选择器组件,使用 currencySelectRule 替代
|
||||||
|
designer.value?.removeMenuItem('select')
|
||||||
const components = [
|
const components = [
|
||||||
editorRule,
|
editorRule,
|
||||||
uploadFileRule,
|
uploadFileRule,
|
||||||
uploadImgRule,
|
uploadImgRule,
|
||||||
uploadImgsRule,
|
uploadImgsRule,
|
||||||
dictSelectRule,
|
dictSelectRule,
|
||||||
userSelectRule
|
currencySelectRule
|
||||||
]
|
]
|
||||||
components.forEach((component) => {
|
components.forEach((component) => {
|
||||||
// 插入组件规则
|
// 插入组件规则
|
||||||
|
@ -20,7 +20,7 @@ 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 { DictSelect } from '@/components/DictSelect'
|
||||||
import UserSelect from '@/views/system/user/components/UserSelect.vue'
|
import { CurrencySelect } from '@/components/FormCreate'
|
||||||
import { Editor } from '@/components/Editor'
|
import { Editor } from '@/components/Editor'
|
||||||
|
|
||||||
const components = [
|
const components = [
|
||||||
@ -40,7 +40,7 @@ const components = [
|
|||||||
UploadImgs,
|
UploadImgs,
|
||||||
UploadFile,
|
UploadFile,
|
||||||
DictSelect,
|
DictSelect,
|
||||||
UserSelect,
|
CurrencySelect,
|
||||||
Editor
|
Editor
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
<!-- TODO puhui999: 先单独一个后面封装成通用选择组件 -->
|
|
||||||
<template>
|
|
||||||
<el-select class="w-1/1" v-bind="attrs">
|
|
||||||
<el-option
|
|
||||||
v-for="(dict, index) in userOptions"
|
|
||||||
:key="index"
|
|
||||||
:label="dict.nickname"
|
|
||||||
:value="dict.id"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts" setup>
|
|
||||||
import * as UserApi from '@/api/system/user'
|
|
||||||
|
|
||||||
defineOptions({ name: 'UserSelect' })
|
|
||||||
|
|
||||||
const attrs = useAttrs()
|
|
||||||
const userOptions = ref<UserApi.UserVO[]>([]) // 用户下拉数据
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
const data = await UserApi.getSimpleUserList()
|
|
||||||
if (!data || data.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
userOptions.value = data
|
|
||||||
})
|
|
||||||
</script>
|
|
Loading…
Reference in New Issue
Block a user