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