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