修改bug

This commit is contained in:
微微一笑
2025-07-22 10:29:34 +08:00
parent 6a49341c6a
commit 2d0eda83e8
2 changed files with 137 additions and 91 deletions

View File

@ -136,42 +136,58 @@
<script setup name="User" lang="ts">
import api from '@/api/equipmentManagement/deviceType/index';
import { UserForm, deviceTypeQuery, deviceTypeVO } from '@/api/equipmentManagement/deviceType/types';
import { UserQuery, UserVO } from '@/api/system/user/types';
import { deviceTypeQuery } from '@/api/equipmentManagement/deviceType/types';
import { to } from 'await-to-js';
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';
interface deviceTypeVO {
id: string | number;
typeName: string;
isSupportBle: boolean;
locateMode: string;
communicationMode: string;
createTime: string;
createByName: string;
}
interface DeviceTypeForm extends deviceTypeVO {
// 可能有其他字段
}
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const deviceTypeList = ref<deviceTypeVO[]>();
import { to } from 'await-to-js';
const loading = ref(true);
const showSearch = ref(true);
const ids = ref<Array<number | string>>([]);
const ids = ref<deviceTypeVO[]>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const initPassword = ref<string>('');
const queryFormRef = ref<ElFormInstance>();
const userFormRef = ref<ElFormInstance>();
const formDialogRef = ref<ElDialogInstance>();
const queryFormRef = ref<InstanceType<typeof ElForm>>();
const userFormRef = ref<InstanceType<typeof ElForm>>();
const formDialogRef = ref<InstanceType<typeof ElDialog>>();
const loadingIng = ref(false)
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
const initFormData: UserForm = {
const initFormData: DeviceTypeForm = {
typeName: '',
isSupportBle: '',
isSupportBle: false,
locateMode: '',
communicationMode: '',
id: ''
id: '',
createTime: '',
createByName: '',
};
const initData: PageData<UserForm, deviceTypeQuery> = {
const initData = {
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
typeName: '',
},
rules: {
typeName: [
@ -185,8 +201,15 @@ const initData: PageData<UserForm, deviceTypeQuery> = {
],
}
};
const data = reactive<PageData<UserForm, UserQuery>>(initData);
const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data);
const data = reactive<{
form: DeviceTypeForm,
queryParams: deviceTypeQuery,
rules: any
}>(initData);
const { queryParams, form, rules } = toRefs(data);
/** 查询用户列表 */
const getList = async () => {
loading.value = true;
@ -196,7 +219,6 @@ const getList = async () => {
total.value = res.total;
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
@ -204,42 +226,34 @@ const handleQuery = () => {
};
/** 重置按钮操作 */
const resetQuery = () => {
queryParams.value.typeName = ''
queryFormRef.value?.resetFields();
queryParams.value.pageNum = 1;
getList();
};
/** 删除按钮操作 */
const handleDelete = async (row?: UserVO) => {
// 批量删除逻辑
let arrey = ids.value.map((item) => item.id);
if (!row) {
const [err] = await to(proxy?.$modal.confirm(`是否确认删除选中的 ${ids.value.length} 条数据?`) as any);
if (!err) {
await api.deleteDeviceType(arrey);
await getList();
proxy?.$modal.msgSuccess('删除成功');
}
return;
}
// 单行删除逻辑
const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + row.typeName + '"的数据项?') as any);
const handleDelete = async (row?: deviceTypeVO) => {
const deviceTypeIds = row ? [row.id] : ids.value.map(item => item.id);
const typeNames = row ? row.typeName : ids.value.map(item => item.typeName).join(',');
const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + typeNames + '"的数据项?', '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}) as any);
if (!err) {
await api.deleteDeviceType([row.id]);
await api.deleteDeviceType(deviceTypeIds);
await getList();
proxy?.$modal.msgSuccess('删除成功');
}
};
/** 选择条数 */
const handleSelectionChange = (selection: UserVO[]) => {
ids.value = selection.map((item) => item);
const handleSelectionChange = (selection: deviceTypeVO[]) => {
ids.value = selection;
single.value = selection.length != 1;
multiple.value = !selection.length;
};
/** 重置操作表单 */
const reset = () => {
form.value = { ...initFormData };
@ -256,21 +270,19 @@ const handleAdd = async () => {
reset();
dialog.visible = true;
dialog.title = '新增设备类型';
form.value.password = initPassword.value.toString();
};
/** 修改按钮操作 */
const handleUpdate = async (row?: UserForm) => {
const handleUpdate = async (row?: DeviceTypeForm) => {
reset();
dialog.visible = true;
dialog.title = '修改设备类型';
try {
if (row) {
// 从行内按钮调用,直接使用行数据
Object.assign(form.value, row);
} else {
const customerId = ids.value[0];
Object.assign(form.value, customerId);
const selectedId = ids.value[0];
Object.assign(form.value, selectedId);
}
} catch (error) {
dialog.visible = false;
@ -282,11 +294,14 @@ const submitForm = () => {
userFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
loadingIng.value = true;
form.value.id ? await api.updateDeviceType(form.value) : await api.addDeviceType(form.value);
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
loadingIng.value = false;
try {
form.value.id ? await api.updateDeviceType(form.value) : await api.addDeviceType(form.value);
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
} finally {
loadingIng.value = false;
}
}
});
};
@ -297,7 +312,6 @@ const submitForm = () => {
const closeDialog = () => {
dialog.visible = false;
resetForm();
loadingIng.value = false;
};
/**
@ -306,11 +320,11 @@ const closeDialog = () => {
const resetForm = () => {
userFormRef.value?.resetFields();
userFormRef.value?.clearValidate();
form.value.customerId = undefined;
form.value.id = '';
};
onMounted(() => {
getList(); // 初始化列表数据
});
</script>