4 changed files with 276 additions and 174 deletions
@ -1,55 +1,78 @@ |
|||||||
<template> |
<template> |
||||||
<BasicModal |
<BasicModal v-bind="$attrs" |
||||||
v-bind="$attrs" |
width="720px" |
||||||
showFooter |
@register="registerModal" |
||||||
:title="getTitle" |
@ok="handleSubmit" |
||||||
width="500px" |
|
||||||
@register="registerModal" |
|
||||||
@ok="handleSubmit" |
|
||||||
> |
> |
||||||
<BasicForm @register="registerForm"/> |
<BasicForm @register="registerForm"/> |
||||||
</BasicModal> |
</BasicModal> |
||||||
</template> |
</template> |
||||||
<script lang="ts" setup> |
<script lang="ts" setup> |
||||||
import {ref, computed, unref} from 'vue'; |
/** |
||||||
import {BasicForm, useForm} from '/@/components/Form/index'; |
* 提供模板规范代码参考,请尽量保证编写代码风格跟模板规范代码一致 |
||||||
import {formSchema} from './dictdata.data'; |
* 采用vben-动态表格表单封装组件编写,采用 setup 写法 |
||||||
//import {set} from '/@/api/platform/system/controller/dictdata'; |
* Copyright © 2020-2022 <a href="http://www.entfrm.com/">entfrm</a> All rights reserved. |
||||||
import {BasicModal, useModalInner} from '/@/components/Modal'; |
* author entfrm开发团队-王翔 |
||||||
|
*/ |
||||||
|
import { ref, unref } from 'vue'; |
||||||
|
import { BasicForm, useForm } from '/@/components/Form/index'; |
||||||
|
import { formSchema } from './dictdata.data'; |
||||||
|
import { getDictData, addDictData, editDictData } from '/@/api/platform/system/controller/dictdata'; |
||||||
|
import { BasicModal, ModalProps, useModalInner } from '/@/components/Modal'; |
||||||
|
|
||||||
const emit = defineEmits(['success', 'register']); |
/** 通用变量统一声明区域 */ |
||||||
const isUpdate = ref(true); |
const tag = ref<Nullable<string>>(''); |
||||||
const [registerForm, {resetFields, setFieldsValue, validate}] = useForm({ |
/** https://v3.cn.vuejs.org/api/options-data.html#emits */ |
||||||
labelWidth: 100, |
const emit = defineEmits(['success', 'register']); |
||||||
schemas: formSchema, |
const [registerForm, { resetFields, setFieldsValue, validate, clearValidate }] = useForm({ |
||||||
showActionButtonGroup: false, |
labelWidth: 100, |
||||||
}); |
schemas: formSchema, |
||||||
|
showActionButtonGroup: false, |
||||||
|
baseColProps: { span: 24 } |
||||||
|
}); |
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: WindowInnerData = { _tag: '' }) => { |
||||||
|
// 处理清除脏数据 |
||||||
|
await resetFields(); |
||||||
|
await clearValidate(); |
||||||
|
// 处理设置数据 |
||||||
|
tag.value = data._tag; |
||||||
|
const dictDataId = data.record?.id; |
||||||
|
const props: Partial<ModalProps> = { confirmLoading: false }; |
||||||
|
// 采用tag标签区分操作 |
||||||
|
switch (unref(tag)) { |
||||||
|
case 'add': |
||||||
|
props.title = '新增字典数据'; |
||||||
|
break; |
||||||
|
case 'edit': |
||||||
|
props.title = '编辑字典数据'; |
||||||
|
await setFieldsValue(await getDictData(dictDataId)); |
||||||
|
break; |
||||||
|
} |
||||||
|
// 尾部:设置处理后的最终配置数据 |
||||||
|
setModalProps(props); |
||||||
|
}); |
||||||
|
|
||||||
const [registerModal, {setModalProps, closeModal}] = useModalInner(async (data) => { |
/** 处理弹出框提交 */ |
||||||
await resetFields(); |
async function handleSubmit() { |
||||||
setModalProps({confirmLoading: false}); |
try { |
||||||
isUpdate.value = !!data?.isUpdate; |
// 提取验证数据 |
||||||
|
const formData = await validate(); |
||||||
if (unref(isUpdate)) { |
// 处理提交之前逻辑 |
||||||
await setFieldsValue({ |
setModalProps({ confirmLoading: true }); |
||||||
...data.record, |
// 采用tag标签区分操作 |
||||||
}); |
switch (unref(tag)) { |
||||||
} |
case 'add': |
||||||
}); |
await addDictData(formData); |
||||||
|
break; |
||||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增字典项' : '编辑字典项')); |
case 'edit': |
||||||
|
await editDictData(formData); |
||||||
async function handleSubmit() { |
break; |
||||||
try { |
} |
||||||
const values = await validate(); |
// 处理提交完成之后逻辑 |
||||||
setModalProps({confirmLoading: true}); |
closeModal(); |
||||||
//await set(values); |
emit('success'); |
||||||
closeModal(); |
} finally { |
||||||
emit('success'); |
setModalProps({ confirmLoading: false }); |
||||||
} finally { |
} |
||||||
setModalProps({confirmLoading: false}); |
|
||||||
} |
} |
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
</script> |
</script> |
||||||
|
@ -1,82 +1,107 @@ |
|||||||
import {BasicColumn} from '/@/components/Table'; |
/** |
||||||
import {FormSchema} from '/@/components/Table'; |
* @program: kicc-ui |
||||||
|
* @description: 字典数据模块动态渲染配置 |
||||||
|
* @author: entfrm开发团队-王翔 |
||||||
|
* @create: 2022/5/8 |
||||||
|
*/ |
||||||
|
|
||||||
export const columns: BasicColumn[] = [ |
import { BasicColumn } from '/@/components/Table'; |
||||||
{ |
import { FormSchema } from '/@/components/Table'; |
||||||
title: '字典ID', |
|
||||||
dataIndex: 'id', |
|
||||||
width: 100, |
|
||||||
}, |
|
||||||
{ |
|
||||||
title: '字典类型', |
|
||||||
dataIndex: 'dictType', |
|
||||||
width: 100, |
|
||||||
}, |
|
||||||
{ |
|
||||||
title: '字典标签', |
|
||||||
dataIndex: 'label', |
|
||||||
width: 130, |
|
||||||
}, |
|
||||||
{ |
|
||||||
title: '字典键值', |
|
||||||
dataIndex: 'value', |
|
||||||
width: 90, |
|
||||||
}, |
|
||||||
{ |
|
||||||
title: '字典排序', |
|
||||||
dataIndex: 'sort', |
|
||||||
width: 90, |
|
||||||
} |
|
||||||
|
|
||||||
|
/** 表格列配置 */ |
||||||
|
export const columns: BasicColumn[] = [ |
||||||
|
{ |
||||||
|
title: '字典数据类型', |
||||||
|
dataIndex: 'dictType' |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '字典数据标签', |
||||||
|
dataIndex: 'label' |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '字典数据键值', |
||||||
|
dataIndex: 'value' |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '字典数据排序', |
||||||
|
dataIndex: 'sort' |
||||||
|
} |
||||||
]; |
]; |
||||||
|
|
||||||
|
/** 搜索表单配置 */ |
||||||
export const searchFormSchema: FormSchema[] = [ |
export const searchFormSchema: FormSchema[] = [ |
||||||
{ |
{ |
||||||
field: 'dataType', |
field: 'dataType', |
||||||
label: '字典参数类型', |
label: '字典类型', |
||||||
component: 'Input', |
component: 'Input', |
||||||
componentProps: { |
componentProps: { |
||||||
placeholder: '请输入字典参数类型', |
placeholder: '请输入字典类型' |
||||||
}, |
}, |
||||||
colProps: {span: 16}, |
colProps: { span: 12 } |
||||||
} |
}, |
||||||
|
{ |
||||||
|
field: 'dataType', |
||||||
|
label: '字典数据标签', |
||||||
|
component: 'Input', |
||||||
|
componentProps: { |
||||||
|
placeholder: '请输入字典数据标签' |
||||||
|
}, |
||||||
|
colProps: { span: 12 } |
||||||
|
} |
||||||
]; |
]; |
||||||
|
|
||||||
|
/** 表单配置 */ |
||||||
export const formSchema: FormSchema[] = [ |
export const formSchema: FormSchema[] = [ |
||||||
{ |
{ |
||||||
field: 'id', |
field: 'id', |
||||||
label: 'ID', |
label: 'ID', |
||||||
component: 'Input', |
component: 'Input', |
||||||
show: false, |
show: false |
||||||
}, |
}, |
||||||
{ |
{ |
||||||
field: 'dictType', |
field: 'dictType', |
||||||
label: '字典类型', |
label: '字典类型', |
||||||
component: 'Input', |
component: 'Input', |
||||||
required: true, |
required: true, |
||||||
componentProps: {disabled: true} |
componentProps: { disabled: true }, |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'label', |
||||||
|
label: '字典标签', |
||||||
|
component: 'Input', |
||||||
|
required: true, |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'value', |
||||||
|
label: '字典键值', |
||||||
|
component: 'Input', |
||||||
|
required: true, |
||||||
|
colProps:{ span: 12 } |
||||||
|
}, |
||||||
|
{ |
||||||
|
field: 'sort', |
||||||
|
label: '排序', |
||||||
|
component: 'InputNumber', |
||||||
|
componentProps: { |
||||||
|
style: { width:'100%' }, |
||||||
|
min: 0 |
||||||
}, |
}, |
||||||
{ |
required: true, |
||||||
field: 'label', |
colProps: { |
||||||
label: '字典标签', |
span: 12 |
||||||
component: 'Input', |
} |
||||||
required: true |
}, |
||||||
}, |
{ |
||||||
{ |
field: 'remark', |
||||||
field: 'value', |
label: '备注', |
||||||
label: '字典键值', |
component: 'InputTextArea', |
||||||
component: 'Input', |
componentProps: { |
||||||
required: true |
rows: 6 |
||||||
}, |
|
||||||
{ |
|
||||||
field: 'sort', |
|
||||||
label: '排序', |
|
||||||
component: 'InputNumber', |
|
||||||
}, |
}, |
||||||
{ |
colProps: { |
||||||
field: 'remark', |
span: 24 |
||||||
label: '备注', |
|
||||||
component: 'InputTextArea', |
|
||||||
} |
} |
||||||
|
} |
||||||
]; |
]; |
Loading…
Reference in new issue