This commit is contained in:
fengerli
2025-07-22 10:49:53 +08:00
2 changed files with 137 additions and 91 deletions

View File

@ -121,22 +121,48 @@
<script setup name="User" lang="ts"> <script setup name="User" lang="ts">
import api from '@/api/customerManagement'; import api from '@/api/customerManagement';
import { UserForm, UserQuery, UserVO } from '@/api/customerManagement/types';
import { to } from 'await-to-js'; 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 UserVO {
customerId: string | number;
nickName: string;
userName: string;
status: string;
createTime: string;
userId: number;
}
interface UserForm extends UserVO {
password?: string;
enabled?: boolean;
}
interface UserQuery {
pageNum: number;
pageSize: number;
blurry: string;
status: string;
enabled: string;
}
const { proxy } = getCurrentInstance() as ComponentInternalInstance; const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const customerList = ref<UserVO[]>(); const customerList = ref<UserVO[]>();
const loading = ref(true); const loading = ref(true);
const showSearch = ref(true); const showSearch = ref(true);
const ids = ref<Array<number | string>>([]); const ids = ref<UserVO[]>([]);
const single = ref(true); const single = ref(true);
const multiple = ref(true); const multiple = ref(true);
const total = ref(0); const total = ref(0);
const dateRange = ref<[DateModelType, DateModelType]>(['', '']); const dateRange = ref<[DateModelType, DateModelType]>(['', '']);
const initPassword = ref<string>(''); const initPassword = ref<string>('');
const queryFormRef = ref<ElFormInstance>(); const queryFormRef = ref<InstanceType<typeof ElForm>>();
const userFormRef = ref<ElFormInstance>(); const userFormRef = ref<InstanceType<typeof ElForm>>();
const formDialogRef = ref<ElDialogInstance>(); const formDialogRef = ref<InstanceType<typeof ElDialog>>();
const loadingIng = ref(false) const loadingIng = ref(false)
const dialog = reactive<DialogOption>({ const dialog = reactive<DialogOption>({
visible: false, visible: false,
title: '' title: ''
@ -144,19 +170,27 @@ const dialog = reactive<DialogOption>({
const initFormData: UserForm = { const initFormData: UserForm = {
userName: '', userName: '',
nickName: undefined, nickName: '',
password: '', password: '',
enabled: true, enabled: true,
customerId: '' customerId: '',
status: '',
createTime: '',
userId: 0,
}; };
const initData: PageData<UserForm, UserQuery> = { const initData: {
form: UserForm,
queryParams: UserQuery,
rules: any
} = {
form: { ...initFormData }, form: { ...initFormData },
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 10, pageSize: 10,
blurry: '', blurry: '',
enabled: '', enabled: '',
status: ''
}, },
rules: { rules: {
nickName: [ nickName: [
@ -184,9 +218,9 @@ const initData: PageData<UserForm, UserQuery> = {
], ],
} }
}; };
const data = reactive<PageData<UserForm, UserQuery>>(initData); const data = reactive(initData);
const { queryParams, form, rules } = toRefs<PageData<UserForm, UserQuery>>(data); const { queryParams, form, rules } = toRefs(data);
/** 查询用户列表 */ /** 查询用户列表 */
const getList = async () => { const getList = async () => {
@ -206,6 +240,7 @@ const handleQuery = () => {
/** 重置按钮操作 */ /** 重置按钮操作 */
const resetQuery = () => { const resetQuery = () => {
dateRange.value = ['', '']; dateRange.value = ['', ''];
queryFormRef.value?.resetFields();
queryParams.value.pageNum = 1; queryParams.value.pageNum = 1;
queryParams.value.status='' queryParams.value.status=''
handleQuery(); handleQuery();
@ -214,21 +249,15 @@ const resetQuery = () => {
/** 删除按钮操作 */ /** 删除按钮操作 */
const handleDelete = async (row?: UserVO) => { const handleDelete = async (row?: UserVO) => {
// 批量删除逻辑 const customerIds = row ? [row.customerId] : ids.value.map(item => item.customerId);
let arrey = ids.value.map((item) => item.customerId); const nickNames = row ? row.nickName : ids.value.map(item => item.nickName).join(',');
if (!row) { const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + nickNames + '"的数据项?', '系统提示', {
const [err] = await to(proxy?.$modal.confirm(`是否确认删除选中的 ${ids.value.length} 条数据?`) as any); confirmButtonText: '确定',
if (!err) { cancelButtonText: '取消',
await api.deleteCustomer(arrey); type: 'warning'
await getList(); }) as any);
proxy?.$modal.msgSuccess('删除成功');
}
return;
}
// 单行删除逻辑
const [err] = await to(proxy?.$modal.confirm('是否确认删除"' + row.nickName + '"的数据项?') as any);
if (!err) { if (!err) {
await api.deleteCustomer([row.customerId]); await api.deleteCustomer(customerIds);
await getList(); await getList();
proxy?.$modal.msgSuccess('删除成功'); proxy?.$modal.msgSuccess('删除成功');
} }
@ -236,11 +265,14 @@ const handleDelete = async (row?: UserVO) => {
/** 用户状态修改 */ /** 用户状态修改 */
const handleStatusChange = async (row: any) => { const handleStatusChange = async (row: any) => {
// 计算新状态(取反)
const originalStatus = row.status; const originalStatus = row.status;
const actionText = row.status == 0 ? '启用' : '停用'; const actionText = row.status == 0 ? '启用' : '停用';
try { try {
await proxy?.$modal.confirm(`确认要${actionText}"${row.nickName}"客户吗?`); await proxy?.$modal.confirm(`确认要${actionText}"${row.nickName}"客户吗?`, '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
});
await api.updateCustomer({ await api.updateCustomer({
customerId: row.customerId, customerId: row.customerId,
enabled: originalStatus == 0 ? true : false enabled: originalStatus == 0 ? true : false
@ -248,18 +280,18 @@ const handleStatusChange = async (row: any) => {
proxy?.$modal.msgSuccess(actionText + '成功'); proxy?.$modal.msgSuccess(actionText + '成功');
await getList(); await getList();
} catch (err) { } catch (err) {
if (err == 'cancel') { // 这里假设confirm方法在用户取消时reject with 'cancel' if (err == 'cancel') {
console.log(err, 'errr'); console.log(err, 'errr');
proxy?.$modal.msgWarning('操作已取消'); proxy?.$modal.msgWarning('操作已取消');
await getList(); await getList();
} }
} }
}; };
/** 选择条数 */ /** 选择条数 */
const handleSelectionChange = (selection: UserVO[]) => { const handleSelectionChange = (selection: UserVO[]) => {
ids.value = selection.map((item) => item); ids.value = selection;
single.value = selection.length != 1; single.value = selection.length != 1;
multiple.value = !selection.length; multiple.value = !selection.length;
}; };
@ -291,11 +323,10 @@ const handleUpdate = async (row?: UserForm) => {
dialog.title = '修改客户'; dialog.title = '修改客户';
try { try {
if (row) { if (row) {
// 从行内按钮调用,直接使用行数据
Object.assign(form.value, row); Object.assign(form.value, row);
} else { } else {
const customerId = ids.value[0]; const selectedId = ids.value[0];
Object.assign(form.value, customerId); Object.assign(form.value, selectedId);
} }
} catch (error) { } catch (error) {
dialog.visible = false; dialog.visible = false;
@ -304,15 +335,17 @@ const handleUpdate = async (row?: UserForm) => {
/** 提交按钮 */ /** 提交按钮 */
const submitForm = () => { const submitForm = () => {
userFormRef.value?.validate(async (valid: boolean) => { userFormRef.value?.validate(async (valid: boolean) => {
if (valid) { if (valid) {
loadingIng.value = true loadingIng.value = true;
form.value.customerId ? await api.updateCustomer(form.value) : await api.addCustomer(form.value); try {
proxy?.$modal.msgSuccess('操作成功'); form.value.customerId ? await api.updateCustomer(form.value) : await api.addCustomer(form.value);
dialog.visible = false; proxy?.$modal.msgSuccess('操作成功');
await getList(); dialog.visible = false;
loadingIng.value = false await getList();
} finally {
loadingIng.value = false;
}
} }
}); });
}; };
@ -331,11 +364,10 @@ const closeDialog = () => {
const resetForm = () => { const resetForm = () => {
userFormRef.value?.resetFields(); userFormRef.value?.resetFields();
userFormRef.value?.clearValidate(); userFormRef.value?.clearValidate();
form.value.customerId = undefined; form.value.customerId = '';
}; };
onMounted(() => { onMounted(() => {
getList(); // 初始化列表数据 getList(); // 初始化列表数据
}); });
</script> </script>

View File

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