114 lines
3.0 KiB
Plaintext
114 lines
3.0 KiB
Plaintext
<template>
|
|
<a-modal v-model:visible="props.visible" :title="props.dictItemId ? '编辑字典项' : '新增字典项'" width="500px" @cancel="dialogClose">
|
|
<a-form
|
|
class="ls-form"
|
|
ref="formRef"
|
|
:model="formData"
|
|
:label-col="{ style: { width: '100px' }}">
|
|
<a-form-item
|
|
label="字典项名"
|
|
name="name"
|
|
:rules="{ required: true, message: '请输入字典项名称', trigger: 'blur' }"
|
|
>
|
|
<a-input
|
|
class="ls-input"
|
|
v-model:value="formData.name"
|
|
placeholder="请输入字典项名称"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item
|
|
label="字典项值"
|
|
name="value"
|
|
>
|
|
<a-input
|
|
class="ls-input"
|
|
v-model:value="formData.value"
|
|
placeholder="请输入字典项值"
|
|
allow-clear
|
|
/>
|
|
</a-form-item>
|
|
<a-form-item label="排序" name="sort">
|
|
<a-input-number v-model:value="formData.sort"/>
|
|
</a-form-item>
|
|
<a-form-item label="备注" name="note">
|
|
<a-input v-model:value="formData.note" type="textarea" placeholder="请输入备注" allow-clear />
|
|
</a-form-item>
|
|
</a-form>
|
|
<template #footer>
|
|
<span class="dialog-footer">
|
|
<a-button @click="dialogClose">取消</a-button>
|
|
<a-button :loading="subLoading" type="primary" @click="submit">
|
|
确定
|
|
</a-button>
|
|
</span>
|
|
</template>
|
|
</a-modal>
|
|
</template>
|
|
<script lang="ts" setup>
|
|
import type { FormInstance } from 'ant-design-vue';
|
|
import {getDictItemDetail,dictItemAdd,dictItemUpdate} from "@/api/data/dictionary";
|
|
import {onMounted, ref,reactive, shallowRef} from "vue";
|
|
import { message } from 'ant-design-vue'
|
|
import {useLockFn} from "@/utils/useLockFn";
|
|
|
|
const emit = defineEmits(["success", "update:visible"]);
|
|
const formRef = shallowRef<FormInstance>();
|
|
const formData = reactive({
|
|
id: "",
|
|
name: "",
|
|
value: "",
|
|
sort: 0,
|
|
note:''
|
|
});
|
|
const props = defineProps({
|
|
visible: {
|
|
type: Boolean,
|
|
required: true,
|
|
default: false
|
|
},
|
|
dictId: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0
|
|
},
|
|
dictItemId: {
|
|
type: Number,
|
|
required: true,
|
|
default: 0
|
|
}
|
|
});
|
|
|
|
const handleSubmit = async () => {
|
|
await formRef.value?.validate();
|
|
props.dictItemId ? await dictItemUpdate({...formData,dictId:props.dictId}) : await dictItemAdd({...formData,dictId:props.dictId});
|
|
message.success("操作成功");
|
|
emit("update:visible", false);
|
|
emit("success");
|
|
};
|
|
|
|
const dialogClose = () => {
|
|
emit("update:visible", false);
|
|
};
|
|
|
|
const { isLock:subLoading,lockFn: submit } = useLockFn(handleSubmit);
|
|
|
|
|
|
const setFormData = async () => {
|
|
const data = await getDictItemDetail(props.dictItemId);
|
|
for (const key in formData) {
|
|
if (data[key] != null && data[key] != undefined) {
|
|
//@ts-ignore
|
|
formData[key] = data[key];
|
|
}
|
|
}
|
|
};
|
|
|
|
onMounted(() => {
|
|
if (props.dictItemId) {
|
|
setFormData();
|
|
}
|
|
});
|
|
|
|
</script>
|