增加类型字典code

This commit is contained in:
微微一笑
2025-08-14 18:51:32 +08:00
parent 0d8f101582
commit d96b28a0b9

View File

@ -40,6 +40,11 @@
<el-table v-loading="loading" border :data="deviceTypeList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" border :data="deviceTypeList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="50" align="center" /> <el-table-column type="selection" width="50" align="center" />
<el-table-column label="型号名称" align="center" prop="typeName" /> <el-table-column label="型号名称" align="center" prop="typeName" />
<el-table-column label="类型code" align="center" prop="modelDictionary">
<template #default="scope">
{{ modelDictionaryOptions.find(item => item.dictValue == scope.row.modelDictionary)?.dictLabel }}
</template>
</el-table-column>
<el-table-column label="是否支持蓝牙" align="center" prop="isSupportBle"> <el-table-column label="是否支持蓝牙" align="center" prop="isSupportBle">
<template #default="scope"> <template #default="scope">
{{ scope.row.isSupportBle ? '是' : '否' }} {{ scope.row.isSupportBle ? '是' : '否' }}
@ -90,6 +95,16 @@
</el-form-item> </el-form-item>
</el-col> </el-col>
</el-row> </el-row>
<el-row>
<el-col :span="24">
<el-form-item label="类型code" prop="modelDictionary">
<el-select v-model="form.modelDictionary" placeholder="请选择">
<el-option v-for="item in modelDictionaryOptions" :key="item.dictValue" :label="item.dictLabel"
:value="item.dictValue" />
</el-select>
</el-form-item>
</el-col>
</el-row>
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<el-form-item label="是否支持蓝牙" prop="isSupportBle"> <el-form-item label="是否支持蓝牙" prop="isSupportBle">
@ -137,24 +152,22 @@
<script setup name="User" lang="ts"> <script setup name="User" lang="ts">
import api from '@/api/equipmentManagement/deviceType/index'; import api from '@/api/equipmentManagement/deviceType/index';
import { deviceTypeQuery } from '@/api/equipmentManagement/deviceType/types'; import { deviceTypeQuery } from '@/api/equipmentManagement/deviceType/types';
import { getDicts } from '@/api/system/dict/data';
import { to } from 'await-to-js'; import { to } from 'await-to-js';
import { ComponentInternalInstance, getCurrentInstance, onMounted, reactive, ref, toRefs } from 'vue'; import { ComponentInternalInstance, getCurrentInstance, onMounted, reactive, ref, toRefs } from 'vue';
import { ElDialog, ElForm, ElFormItem, ElInput, ElRow, ElCol, ElButton, ElCard, ElSelect, ElOption, ElDatePicker, ElTable, ElTableColumn, ElTooltip, ElSwitch } from 'element-plus'; import { ElDialog, ElForm, ElFormItem, ElInput, ElRow, ElCol, ElButton, ElCard, ElSelect, ElOption, ElDatePicker, ElTable, ElTableColumn, ElTooltip, ElSwitch } from 'element-plus';
interface deviceTypeVO { interface deviceTypeVO {
id: string | number; id: string | number;
typeName: string; typeName: string;
isSupportBle: boolean; isSupportBle: boolean;
locateMode: string; locateMode: string;
modelDictionary: string;
communicationMode: string; communicationMode: string;
createTime: string; createTime: string;
createByName: string; createByName: string;
} }
interface DeviceTypeForm extends deviceTypeVO { interface DeviceTypeForm extends deviceTypeVO {
// 可能有其他字段
} }
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const deviceTypeList = ref<deviceTypeVO[]>(); const deviceTypeList = ref<deviceTypeVO[]>();
const loading = ref(true); const loading = ref(true);
@ -167,15 +180,16 @@ const queryFormRef = ref<InstanceType<typeof ElForm>>();
const userFormRef = ref<InstanceType<typeof ElForm>>(); const userFormRef = ref<InstanceType<typeof ElForm>>();
const formDialogRef = ref<InstanceType<typeof ElDialog>>(); const formDialogRef = ref<InstanceType<typeof ElDialog>>();
const loadingIng = ref(false) const loadingIng = ref(false)
const modelDictionaryOptions = ref<any[]>([]);
const dialog = reactive<DialogOption>({ const dialog = reactive<DialogOption>({
visible: false, visible: false,
title: '' title: ''
}); });
const initFormData: DeviceTypeForm = { const initFormData: DeviceTypeForm = {
typeName: '', typeName: '',
isSupportBle: false, isSupportBle: false,
locateMode: '', locateMode: '',
modelDictionary: '',
communicationMode: '', communicationMode: '',
id: '', id: '',
createTime: '', createTime: '',
@ -193,6 +207,9 @@ const initData = {
typeName: [ typeName: [
{ required: true, message: '请输入设备类型名称', trigger: 'blur' }, { required: true, message: '请输入设备类型名称', trigger: 'blur' },
], ],
modelDictionary: [
{ required: true, message: '请选择类型code', trigger: 'blur' },
],
locateMode: [ locateMode: [
{ required: true, message: '请选择定位方式', trigger: 'blur' }, { required: true, message: '请选择定位方式', trigger: 'blur' },
], ],
@ -218,7 +235,10 @@ const getList = async () => {
deviceTypeList.value = res.rows; deviceTypeList.value = res.rows;
total.value = res.total; total.value = res.total;
}; };
const getDict = async () => {
const res = await getDicts('model_dictionary');
modelDictionaryOptions.value = res.data;
}
/** 搜索按钮操作 */ /** 搜索按钮操作 */
const handleQuery = () => { const handleQuery = () => {
queryParams.value.pageNum = 1; queryParams.value.pageNum = 1;
@ -278,11 +298,10 @@ const handleUpdate = async (row?: DeviceTypeForm) => {
dialog.visible = true; dialog.visible = true;
dialog.title = '修改设备类型'; dialog.title = '修改设备类型';
try { try {
if (row) { const deviceData = row || ids.value[0];
Object.assign(form.value, row); Object.assign(form.value, deviceData);
} else { if (form.value.modelDictionary) {
const selectedId = ids.value[0]; form.value.modelDictionary = String(form.value.modelDictionary);
Object.assign(form.value, selectedId);
} }
} catch (error) { } catch (error) {
dialog.visible = false; dialog.visible = false;
@ -295,7 +314,11 @@ const submitForm = () => {
if (valid) { if (valid) {
loadingIng.value = true; loadingIng.value = true;
try { try {
form.value.id ? await api.updateDeviceType(form.value) : await api.addDeviceType(form.value); const payload = {
...form.value,
modelDictionary: Number(form.value.modelDictionary)
};
form.value.id ? await api.updateDeviceType(payload) : await api.addDeviceType(payload);
proxy?.$modal.msgSuccess('操作成功'); proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false; dialog.visible = false;
await getList(); await getList();
@ -325,6 +348,7 @@ const resetForm = () => {
onMounted(() => { onMounted(() => {
getList(); // 初始化列表数据 getList(); // 初始化列表数据
getDict();
}); });
</script> </script>