初始版本提交
This commit is contained in:
110
src/components/DicSelect/components/DicDetailDrawer.vue
Normal file
110
src/components/DicSelect/components/DicDetailDrawer.vue
Normal file
@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<BasicDrawer
|
||||
v-bind="$attrs"
|
||||
@register="registerDrawer"
|
||||
showFooter
|
||||
:title="t('新增数据字典')"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<BasicForm @register="registerForm" />
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref } from 'vue';
|
||||
import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
||||
|
||||
import { addDicDetail } from '/@/api/system/dic';
|
||||
|
||||
import { useMessage } from '/@/hooks/web/useMessage';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
const { t } = useI18n();
|
||||
|
||||
const emit = defineEmits(['success', 'register']);
|
||||
|
||||
const formSchema: FormSchema[] = [
|
||||
{
|
||||
field: 'name',
|
||||
label: t('字典名称'),
|
||||
required: true,
|
||||
title: t('基本信息'),
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: t('请输入字典名称'),
|
||||
},
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
{
|
||||
field: 'code',
|
||||
label: t('字典编码'),
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: t('请输入字典编码'),
|
||||
},
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
{
|
||||
field: 'value',
|
||||
label: t('字典值'),
|
||||
required: true,
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: t('请输入字典值'),
|
||||
},
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
{
|
||||
field: 'sortCode',
|
||||
label: t('排序'),
|
||||
component: 'InputNumber',
|
||||
componentProps: {
|
||||
style: { width: '100%' },
|
||||
placeholder: t('请输入排序号'),
|
||||
},
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
{
|
||||
label: t('备注'),
|
||||
field: 'remark',
|
||||
component: 'InputTextArea',
|
||||
componentProps: {
|
||||
placeholder: t('请输入备注'),
|
||||
},
|
||||
colProps: { span: 24 },
|
||||
},
|
||||
];
|
||||
|
||||
const { notification } = useMessage();
|
||||
const itemId = ref('');
|
||||
|
||||
const [registerForm, { resetFields, validate }] = useForm({
|
||||
labelWidth: 90,
|
||||
schemas: formSchema,
|
||||
showActionButtonGroup: false,
|
||||
});
|
||||
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||
resetFields();
|
||||
setDrawerProps({ confirmLoading: false });
|
||||
|
||||
itemId.value = data.itemId;
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
const values = await validate();
|
||||
values.itemId = itemId.value;
|
||||
await addDicDetail(values);
|
||||
notification.success({
|
||||
message: t('提示'),
|
||||
description: t('新增成功'),
|
||||
}); //提示消息
|
||||
closeDrawer();
|
||||
emit('success', values);
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false });
|
||||
}
|
||||
}
|
||||
</script>
|
||||
4
src/components/DicSelect/index.ts
Normal file
4
src/components/DicSelect/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { withInstall } from '/@/utils/index';
|
||||
import dicSelect from './src/DicSelect.vue';
|
||||
|
||||
export const DicSelect = withInstall(dicSelect);
|
||||
108
src/components/DicSelect/src/DicSelect.vue
Normal file
108
src/components/DicSelect/src/DicSelect.vue
Normal file
@ -0,0 +1,108 @@
|
||||
<template>
|
||||
<div>
|
||||
<Select
|
||||
v-bind="$attrs"
|
||||
v-model:value="value"
|
||||
style="width: 100%"
|
||||
:options="data.map((item) => ({ value: item.id, label: item.name }))"
|
||||
:placeholder="placeholder"
|
||||
:mode="mode"
|
||||
>
|
||||
<template #dropdownRender="{ menuNode: menu }" v-if="isShowAdd">
|
||||
<component :is="menu" />
|
||||
<Divider style="margin: 4px 0" />
|
||||
<div
|
||||
style="padding: 4px 8px; cursor: pointer"
|
||||
@mousedown="(e) => e.preventDefault()"
|
||||
@click="add"
|
||||
>
|
||||
<plus-outlined />
|
||||
{{ t('新增') }}
|
||||
</div>
|
||||
</template>
|
||||
</Select>
|
||||
<DicDetailDrawer @register="registerDetailDrawer" @success="handleDetailSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { Select, Divider } from 'ant-design-vue';
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { onMounted, ref, unref, watch } from 'vue';
|
||||
import { getDicDetailList } from '/@/api/system/dic';
|
||||
import { DicDetailListParams } from '/@/api/system/dic/model';
|
||||
import DicDetailDrawer from '../components/DicDetailDrawer.vue';
|
||||
import { useDrawer } from '../../Drawer/src/useDrawer';
|
||||
import { useI18n } from '/@/hooks/web/useI18n';
|
||||
const { t } = useI18n();
|
||||
const emit = defineEmits(['change']);
|
||||
|
||||
const props = defineProps({
|
||||
value: [String, Array],
|
||||
itemId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
placeholder: String,
|
||||
isShowAdd: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
},
|
||||
isDefaultValue: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const value = ref();
|
||||
|
||||
const data = ref<Recordable[]>([]);
|
||||
|
||||
onMounted(() => {
|
||||
fetch();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => value,
|
||||
(val) => {
|
||||
emit(
|
||||
'change',
|
||||
unref(value),
|
||||
unref(data).find((x) => x.id === val),
|
||||
);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(val) => {
|
||||
value.value = val;
|
||||
emit(
|
||||
'change',
|
||||
unref(value),
|
||||
unref(data).find((x) => x.id === val),
|
||||
);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
async function fetch() {
|
||||
const params = { itemId: props.itemId } as DicDetailListParams;
|
||||
data.value = ((await getDicDetailList(params)) as unknown as Recordable[]) || [];
|
||||
|
||||
value.value = props.value || (props.isDefaultValue ? data.value[0].id : undefined);
|
||||
}
|
||||
|
||||
const [registerDetailDrawer, { openDrawer }] = useDrawer();
|
||||
|
||||
const add = () => {
|
||||
openDrawer(true, { itemId: props.itemId });
|
||||
};
|
||||
|
||||
const handleDetailSuccess = () => {
|
||||
fetch();
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user