frontend/.env.development

This commit is contained in:
sjl
2024-11-01 15:29:16 +08:00
25 changed files with 752 additions and 853 deletions

View File

@@ -18,5 +18,7 @@ VITE_PWA=false
VITE_API_URL=/api VITE_API_URL=/api
# 开发环境跨域代理,支持配置多个 # 开发环境跨域代理,支持配置多个
VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]//awen
#VITE_PROXY=[["/api","http://192.168.1.138:8080/"]]//zwen VITE_PROXY=[["/api","http://192.168.1.122:18092/"]]
# VITE_PROXY=[["/api","http://192.168.1.125:18092/"]]
# VITE_PROXY=[["/api","http://192.168.1.138:8080/"]]

View File

@@ -0,0 +1,29 @@
import http from '@/api'
import {type Dict} from '@/api/system/dictionary/interface'
import type {ResultData} from "@/api/interface";
//获取字典数据
export const getDictDataListByTypeId = (params: Dict.ReqDictDataParams) => {
return http.post(`/dictData/listByTypeId`, params)
}
//添加字典数据
export const addDictData = (params: Dict.ResDictData) => {
return http.post(`/dictData/add`, params)
}
//编辑字典数据
export const updateDictData = (params: Dict.ResDictData) => {
return http.post(`/dictData/update`, params)
}
//删除字典数据
export const deleteDictData = (params: string[]) => {
return http.post(`/dictData/delete`, params)
}
export const getDicDataById = (params: string) => {
return http.post('/dictData/getDicDataById', params)
}

View File

@@ -1,139 +0,0 @@
import { type Dict } from "@/api/system/dictionary/interface";
export const dictTypeList: Dict.ResDictType[] = [
{
id: "1",
name: "用户性别",
code: "EXAMPLE_CODE1",
sort: 100,
openLevel: 1,
openDescribe: 1,
remark: "示例描述示例描述示例描述12231",
state: 1,
createBy: "admin",
createTime: "2023-10-01 12:00:00",
updateBy: "admin",
updateTime: "2023-10-12 14:40:00",
},
{
id: "231",
name: "菜单状态",
code: "EXAMPLE_CODE2",
sort: 100,
openLevel: 1,
openDescribe: 1,
remark: "示例描述示例描述示例描述11133",
state: 0,
createBy: "admin",
createTime: "2023-10-01 12:00:00",
updateBy: "admin",
updateTime: "2023-10-10 12:00:00",
},
{
id: "33",
name: "系统开关",
code: "EXAMPLE_CODE3",
sort: 100,
openLevel: 1,
openDescribe: 1,
remark: "示例描述示例描述示例描述11144",
state: 1,
createBy: "admin",
createTime: "2023-10-01 12:00:00",
updateBy: "admin",
updateTime: "2023-10-10 12:00:00",
},
];
export const dictDataList: Dict.ResDictData[] = [
{
id: "210",
typeId: "101",
name: "字典项1",
code: "EXAMPLE_00111",
sort:100,
level: 1,
algoDescribe: null,
value: "字典值1",
state: 1,
createBy: "admin",
createTime: "2023-10-01 12:00:00",
updateBy: "admin",
updateTime: "2023-10-01 14:43:03",
},
{
id: "2210",
typeId: "101",
name: "字典项2",
code: "EXAMPLE_00121",
sort:100,
level: 2,
algoDescribe: null,
value: "字典值2",
state: 1,
createBy: "admin",
createTime: "2023-10-03 12:00:00",
updateBy: "admin",
updateTime: "2023-10-05 14:43:03",
},
{
id: "212",
typeId: "101",
name: "字典项3",
code: "EXAMPLE_00141",
sort:100,
level: 3,
algoDescribe: null,
value: "字典值3",
state: 0,
createBy: "admin",
createTime: "2023-10-01 11:00:00",
updateBy: "admin",
updateTime: "2023-10-05 16:43:03",
},
{
id: "210",
typeId: "101",
name: "字典项4",
code: "EXAMPLE_00311",
sort:100,
level: null,
algoDescribe: null,
value: "字典值4",
state: 0,
createBy: "admin",
createTime: "2023-10-03 12:40:00",
updateBy: "admin",
updateTime: "2023-10-04 14:43:03",
},
{
id: "217",
typeId: "101",
name: "字典项5",
code: "EXAMPLE_00341",
sort:100,
level: undefined,
algoDescribe: null,
value: "字典值5",
state: 1,
createBy: "admin",
createTime: "2023-10-06 12:45:03",
updateBy: "admin",
updateTime: "2023-10-07 19:37:03",
},
{
id: "237",
typeId: "101",
name: "字典项6",
code: "EXAMPLE_00318",
sort:100,
level: 0,
algoDescribe: null,
value: "字典值6",
state: 1,
createBy: "admin",
createTime: "2023-10-16 10:45:03",
updateBy: "admin",
updateTime: "2023-10-17 19:37:03",
},
];

View File

@@ -1,70 +0,0 @@
import http from "@/api";
import { ADMIN as rePrefix } from "@/api/config/serviceName";
import { type Dict } from "@/api/system/dictionary/interface";
//获取字典类型
export const getDictTypeList = (params: Dict.ReqDictTypeParams) => {
return http.post(`${rePrefix}/dict/list`, params);
};
//添加字典类型
export const addDictType = (params: Dict.ReqDictTypeParams) => {
return http.post(`${rePrefix}/dict/add`,params);
};
//删除字典类型
export const deleteDictType = (params: { id: string[] }) => {
return http.post(`${rePrefix}/dict/delete`, { data: params });
};
//编辑字典类型
export const updateDictType = (params: Dict.ReqDictTypeParams) => {
return http.post(`${rePrefix}/dict/update`, params);
};
//导出字典类型
export const exportDictType = (params: Dict.ResDictType) => {
return http.download(`${rePrefix}/dict/export`, params);
};
//批量添加字典类型
export const batchAddDictType = (params: FormData) => {
return http.post(`${rePrefix}/dict/import`, params);
};
//获取字典数据
export const getDictDataList = (params: Dict.ReqDictDataParams) => {
return http.post(`${rePrefix}/dict-data/list`, params);
};
//添加字典数据
export const addDictData = (params: Dict.ReqDictDataParams) => {
return http.post(`${rePrefix}/dict-data/add`, params);
};
//删除字典数据
export const deleteDictData = (params: { id: string[] }) => {
return http.post(`${rePrefix}/dict-data/delete`, { data: params });
};
//编辑字典数据
export const updateDictData = (params: Dict.ReqDictDataParams) => {
return http.post(`${rePrefix}/dict-data/update`, params);
};
//导出字典数据
export const exportDictData = (params: Dict.ResDictData) => {
return http.download(`${rePrefix}/dict-data/export`, params);
};
//批量添加字典数据
export const batchAddDictData = (params: FormData) => {
return http.post(`${rePrefix}/dict-data/import`, params);
};

View File

@@ -65,6 +65,7 @@ export namespace Dict {
level?: number | null; // 事件等级0-普通1-中等2-严重 (默认为0) level?: number | null; // 事件等级0-普通1-中等2-严重 (默认为0)
algoDescribe?: number | null; // 与高级算法内部Id描述对应 algoDescribe?: number | null; // 与高级算法内部Id描述对应
value?: string | null; // 字典针对电压等级 value?: string | null; // 字典针对电压等级
dictValue?:string|null;
state: number; // 状态0-删除 1-正常 state: number; // 状态0-删除 1-正常
createBy?: string | null; // 创建用户 createBy?: string | null; // 创建用户
createTime?: string | null; // 创建时间 createTime?: string | null; // 创建时间

View File

@@ -18,29 +18,21 @@ export namespace Login {
// 用户管理模块 // 用户管理模块
export namespace User { export namespace User {
// 用户列表 // 用户接口
export interface ResUserList { export interface UserBO {
id: string; //用户ID作为唯一标识 id?: string; //用户ID作为唯一标识
username: string; //用户名 name: string; //用户名(别名)
loginName: string;//登录名
password: string; //密码 password: string; //密码
realname: string; //真实姓名 phone?: string; //手机号
status: number; //用户状态 email?: string; //邮箱
rolename: string; //角色名称 loginTime?: string;//最后一次登录时间
loginErrorTimes: number;//登录错误次数
lockTime?: string; //用户密码错误锁定时间
} }
// 用户+分页
export interface ReqUserParams extends ReqPage,UserBO {
export interface ReqUserParams extends ReqPage {
id: string; //用户ID作为唯一标识
username: string; //用户名
password: string; //密码
realname: string; //真实姓名
status: number; //用户状态
rolename: string; //角色名称
} }
export interface ResStatus {
userLabel: string;
userValue: number;
}
} }

View File

@@ -8,7 +8,7 @@ import http from '@/api'
*/ */
// 获取用户列表 // 获取用户列表
export const getUserList = (params: User.ReqUserParams) => { export const getUserList = (params: User.ReqUserParams) => {
return http.post<ResPage<User.ResUserList>>(`${rePrefix}/user/list`, params) return http.post<ResPage<User.UserBO>>(`/user/list`, params)
} }
// 获取树形用户列表 // 获取树形用户列表
@@ -17,8 +17,8 @@ export const getUserList = (params: User.ReqUserParams) => {
// } // }
// 新增用户 // 新增用户
export const addUser = (params: { id: string }) => { export const addUser = (params: User.UserBO) => {
return http.post(`${rePrefix}/user/add`, params) return http.post(`/user/add`, params)
} }
// 批量添加用户 // 批量添加用户
@@ -27,24 +27,24 @@ export const BatchAddUser = (params: FormData) => {
} }
// 编辑用户 // 编辑用户
export const editUser = (params: { id: string }) => { export const editUser = (params: User.UserBO) => {
return http.post(`${rePrefix}/user/edit`, params) return http.post(`/user/edit`, params)
} }
// 删除用户 // 删除用户
export const deleteUser = (params: { id: string[] }) => { export const deleteUser = (params: { id: string[] }) => {
return http.post(`${rePrefix}/user/delete`, params) return http.post(`/user/delete`, params)
} }
// 切换用户状态 // 切换用户状态
export const changeUserStatus = (params: { id: string; status: number }) => { // export const changeUserStatus = (params: { id: string; status: number }) => {
return http.post(`${rePrefix}/user/change`, params) // return http.post(`${rePrefix}/user/change`, params)
} // }
// 重置用户密码 // 重置用户密码
export const resetUserPassWord = (params: { id: string }) => { // export const resetUserPassWord = (params: { id: string }) => {
return http.post(`${rePrefix}/user/rest_password`, params) // return http.post(`${rePrefix}/user/rest_password`, params)
} // }
// 导出用户数据 // 导出用户数据
export const exportUserInfo = (params: User.ReqUserParams) => { export const exportUserInfo = (params: User.ReqUserParams) => {
@@ -52,6 +52,6 @@ export const exportUserInfo = (params: User.ReqUserParams) => {
} }
// 获取用户状态字典 // 获取用户状态字典
export const getUserStatus = () => { // export const getUserStatus = () => {
return http.get<User.ResStatus[]>(`${rePrefix}/user/status`) // return http.get<User.ResStatus[]>(`${rePrefix}/user/status`)
} // }

View File

@@ -15,118 +15,118 @@ const data = [
'status': 1, 'status': 1,
'rolename': '管理员', 'rolename': '管理员',
}, },
{ // {
'id': '652286556713195552', // 'id': '652286556713195552',
'username': 'operator_A', // 'username': 'operator_A',
'password': '12345678', // 'password': '12345678',
'realname': '潘霞', // 'realname': '潘霞',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '373930342176416776', // 'id': '373930342176416776',
'username': 'operator_B', // 'username': 'operator_B',
'password': '12345678', // 'password': '12345678',
'realname': '郝秀英', // 'realname': '郝秀英',
'status': 0, // 'status': 0,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '429621442453555775', // 'id': '429621442453555775',
'username': 'operator_C', // 'username': 'operator_C',
'password': '12345678', // 'password': '12345678',
'realname': '吕洋', // 'realname': '吕洋',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '387231964476618937', // 'id': '387231964476618937',
'username': 'operator_D', // 'username': 'operator_D',
'password': '12345678', // 'password': '12345678',
'realname': '江磊', // 'realname': '江磊',
'status': 0, // 'status': 0,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '604013348875476647', // 'id': '604013348875476647',
'username': 'operator_E', // 'username': 'operator_E',
'password': '12345678', // 'password': '12345678',
'realname': '姚静', // 'realname': '姚静',
'status': 0, // 'status': 0,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '028222596330483467', // 'id': '028222596330483467',
'username': 'operator_F', // 'username': 'operator_F',
'password': '12345678', // 'password': '12345678',
'realname': '龙艳', // 'realname': '龙艳',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '739427478368274267', // 'id': '739427478368274267',
'username': 'operator_G', // 'username': 'operator_G',
'password': '12345678', // 'password': '12345678',
'realname': '武涛', // 'realname': '武涛',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127243', // 'id': '448686878612127243',
'username': 'operator_H', // 'username': 'operator_H',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳', // 'realname': '孙芳',
'status': 0, // 'status': 0,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127244', // 'id': '448686878612127244',
'username': 'operator_I', // 'username': 'operator_I',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳1', // 'realname': '孙芳1',
'status': 0, // 'status': 0,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127245', // 'id': '448686878612127245',
'username': 'operator_J', // 'username': 'operator_J',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳2', // 'realname': '孙芳2',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127245', // 'id': '448686878612127245',
'username': 'operator_J', // 'username': 'operator_J',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳2', // 'realname': '孙芳2',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127245', // 'id': '448686878612127245',
'username': 'operator_J', // 'username': 'operator_J',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳2', // 'realname': '孙芳2',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127245', // 'id': '448686878612127245',
'username': 'operator_J', // 'username': 'operator_J',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳2', // 'realname': '孙芳2',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
}, // },
{ // {
'id': '448686878612127245', // 'id': '448686878612127245',
'username': 'operator_J', // 'username': 'operator_J',
'password': '12345678', // 'password': '12345678',
'realname': '孙芳2', // 'realname': '孙芳2',
'status': 1, // 'status': 1,
'rolename': '操作员', // 'rolename': '操作员',
} // }
] ]

View File

@@ -23,8 +23,14 @@ interface Pageable {
total: number; total: number;
} }
interface ResPageable {
current: number;
size: number;
total: number;
}
interface PaginationProps { interface PaginationProps {
pageable: Pageable; pageable: ResPageable;
handleSizeChange: (size: number) => void; handleSizeChange: (size: number) => void;
handleCurrentChange: (currentPage: number) => void; handleCurrentChange: (currentPage: number) => void;
} }

View File

@@ -94,7 +94,7 @@
<slot name='pagination'> <slot name='pagination'>
<Pagination <Pagination
v-if='pagination' v-if='pagination'
:pageable='pageable' :pageable='resPageable'
:handle-size-change='handleSizeChange' :handle-size-change='handleSizeChange'
:handle-current-change='handleCurrentChange' :handle-current-change='handleCurrentChange'
/> />
@@ -173,6 +173,7 @@ const { selectionChange, selectedList, selectedListIds, isSelected } = useSelect
const { const {
tableData, tableData,
pageable, pageable,
resPageable,
searchParam, searchParam,
searchInitParam, searchInitParam,
getTableList, getTableList,
@@ -190,7 +191,7 @@ const clearSelection = () => tableRef.value!.clearSelection()
onMounted(() => { onMounted(() => {
dragSort() dragSort()
props.requestAuto && getTableList() props.requestAuto && getTableList()
props.data && (pageable.value.total = props.data.length) props.data && (resPageable.value.total = props.data.length)
}) })
// 处理表格数据 // 处理表格数据
@@ -198,8 +199,8 @@ const processTableData = computed(() => {
if (!props.data) return tableData.value if (!props.data) return tableData.value
if (!props.pagination) return props.data if (!props.pagination) return props.data
return props.data.slice( return props.data.slice(
(pageable.value.pageNum - 1) * pageable.value.pageSize, (resPageable.value.current - 1) * resPageable.value.size,
pageable.value.pageSize * pageable.value.pageNum, resPageable.value.size * resPageable.value.current,
) )
}) })

View File

@@ -4,9 +4,17 @@ export namespace Table {
pageSize: number; pageSize: number;
total: number; total: number;
} }
export interface ResPageable {
current: number;
size: number;
total: number;
}
export interface StateProps { export interface StateProps {
tableData: any[]; tableData: any[];
pageable: Pageable; pageable: Pageable;
resPageable: ResPageable;
searchParam: { searchParam: {
[key: string]: any; [key: string]: any;
}; };

View File

@@ -20,6 +20,15 @@ export const useTable = (
tableData: [], tableData: [],
// 分页数据 // 分页数据
pageable: { pageable: {
// 当前页数
pageNum: 1,
// 每页显示条数
pageSize: 10,
// 总条数
total: 0,
},
// 响应分页
resPageable: {
// 当前页数 // 当前页数
current: 1, current: 1,
// 每页显示条数 // 每页显示条数
@@ -71,9 +80,9 @@ export const useTable = (
state.tableData = isPageable ? data.records : data; state.tableData = isPageable ? data.records : data;
// 解构后台返回的分页数据 (如果有分页更新分页信息) // 解构后台返回的分页数据 (如果有分页更新分页信息)
if (isPageable) { if (isPageable) {
state.pageable.total = data.total; state.resPageable.total = data.total;
state.pageable.current = data.current; state.resPageable.current = data.current;
state.pageable.size = data.size; state.resPageable.size = data.size;
} }
} catch (error) { } catch (error) {
requestError && requestError(error); requestError && requestError(error);

View File

@@ -3,17 +3,16 @@ import { ref } from 'vue'
export const useViewSize = () => { export const useViewSize = () => {
const popupBaseView = ref(null) const popupBaseView = ref(null)
const viewWidth = ref("0") const viewWidth = ref(0)
const viewHeight = ref("0") const viewHeight = ref(0)
const unit = 'px'
/** /**
* 更新宽和高的数据 * 更新宽和高的数据
*/ */
const updateDimensions = () => { const updateDimensions = () => {
if (popupBaseView.value) { if (popupBaseView.value) {
viewWidth.value = popupBaseView.value.offsetWidth + unit viewWidth.value = popupBaseView.value.offsetWidth
viewHeight.value = popupBaseView.value.offsetHeight + unit viewHeight.value = popupBaseView.value.offsetHeight
} }
} }

View File

@@ -100,26 +100,26 @@
if(openType === "add") if(openType === "add")
{ {
addRole(data).then(res => { addRole(data).then(res => {
if(res.code === "200") // if(res.code === "200")
{ // {
ElMessage.success(res.message) ElMessage.success(res.message)
getTableList() getTableList()
} // }
else // else
ElMessage.error(res.message) // ElMessage.error(res.message)
}) })
} }
if(openType === "edit") if(openType === "edit")
{ {
editRole(data).then(res => { editRole(data).then(res => {
if(res.code === "200") // if(res.code === "200")
{ // {
ElMessage.success(res.message) ElMessage.success(res.message)
getTableList() getTableList()
} // }
else // else
ElMessage.error(res.message) // ElMessage.error(res.message)
}) })
} }

View File

@@ -88,10 +88,10 @@ const proTable = ref<ProTableInstance>()
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行 // 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
const dataCallback = (data: any) => { const dataCallback = (data: any) => {
return { return {
list: data.list, records: data.list,
total: data.total, total: data.total,
pageNum: data.pageNum, current: data.pageNum,
pageSize: data.pageSize, size: data.pageSize,
} }
} }

View File

@@ -0,0 +1,142 @@
<template>
<!-- 基础信息弹出框 -->
<el-dialog :model-value="dialogVisible" :title="title" v-bind="dialogSmall" @close="handleCancel" width="500" draggable>
<div>
<el-form :model="data"
ref='formRuleRef'
:rules='rules'
>
<el-form-item label="用户名" prop='name' :label-width="100">
<el-input v-model="data.name" placeholder="请输入用户名" autocomplete="off" />
</el-form-item>
<el-form-item label="登录名" prop='loginName' :label-width="100">
<el-input v-model="data.loginName" placeholder="请输入登录名" autocomplete="off" />
</el-form-item>
<el-form-item label="密码" prop='password' :label-width="100">
<el-input type="password" v-model="data.password" placeholder="请输入密码" autocomplete="off" />
</el-form-item>
<el-form-item label="手机号码" prop='phone' :label-width="100">
<el-input v-model="data.phone" placeholder="请输入手机号码" autocomplete="off" />
</el-form-item>
<el-form-item label="邮箱地址" prop='email' :label-width="100">
<el-input v-model="data.email" placeholder="请输入邮箱地址" autocomplete="off" />
</el-form-item>
<el-form-item label="最后一次登录时间" prop='loginTime' :label-width="100">
<el-input v-model="data.loginTime" placeholder="请输入最后一次登录时间" autocomplete="off" />
</el-form-item>
<el-form-item label="登录错误次数" prop='loginErrorTimes' :label-width="100">
<el-input v-model="data.loginErrorTimes" placeholder="请输入登录错误次数" autocomplete="off" />
</el-form-item>
<el-form-item label="用户密码错误锁定时间" prop='lockTime' :label-width="100">
<el-input v-model="data.lockTime" placeholder="请输入用户密码错误锁定时间" autocomplete="off" />
</el-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleOK">
保存
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { ref,computed } from 'vue'
import {dialogSmall} from '@/utils/elementBind'
import { FormInstance,FormItemRule } from 'element-plus'
import {
addUser,
editUser,
} from '@/api/user/user'
const {dialogVisible,title,data,openType,getTableList} = defineProps<{
dialogVisible:boolean;
title:string;
openType:string;
getTableList:Function;
data:{
id?: string; //用户ID作为唯一标识
name: string; //用户名(别名)
loginName: string;//登录名
password: string; //密码
phone?: string; //手机号
email?: string; //邮箱
loginTime?: string;//最后一次登录时间
loginErrorTimes: number;//登录错误次数
lockTime?: string; //用户密码错误锁定时间
}
}>();
//定义规则
const formRuleRef = ref<FormInstance>()
//定义校验规则
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
name: [{ required: true, message: '名称必填!', trigger: 'blur' }],
loginName: [{ required: true, message: '登录名必填!', trigger: 'blur' }],
password: [{ required: true, message: '密码必填!', trigger: 'blur' }],
loginErrorTimes: [{ required: true, message: '登录错误次数必填!', trigger: 'blur' }],
})
// const value = computed({
// get: () => data.status === 1,
// set: (value: boolean) => data.status = value ? 1 : 0
// })
const emit = defineEmits<{
(e:'update:visible',value:boolean):void;
}>();
const handleCancel = () => {
emit('update:visible',false)
}
const handleOK = () => {
ElMessage.info('用户数据提交')
try {
formRuleRef.value?.validate((valid: boolean) => {
if (valid) {
// 将表单数据转为json,发送到后端
// let confirmFormData = JSON.parse(JSON.stringify(form.value))
// console.log(confirmFormData)
if(openType === "add")
{
addUser(data).then(res => {
if(res.code === "200")
{
ElMessage.success(res.message)
getTableList()
}
else
ElMessage.error(res.message)
})
}
if(openType === "edit")
{
editUser(data).then(res => {
if(res.code === "200")
{
ElMessage.success(res.message)
getTableList()
}
else
ElMessage.error(res.message)
})
}
emit('update:visible',false)
} else {
ElMessage.error('表单验证失败!')
}
})
} catch (error) {
console.error('验证过程中发生错误', error)
}
}
</script>

View File

@@ -1,70 +0,0 @@
<template>
<!-- 基础信息弹出框 -->
<el-dialog :model-value="dialogVisible" :title="title" v-bind="dialogSmall" @close="handleCancel" width="500" draggable>
<div>
<el-form :model="data">
<el-form-item label="用户名" :label-width="100">
<el-input v-model="data.username" placeholder="请输入用户名" autocomplete="off" />
</el-form-item>
<el-form-item label="真实姓名" :label-width="100">
<el-input v-model="data.realname" placeholder="请输入真实姓名" autocomplete="off" />
</el-form-item>
<el-form-item label="密码" :label-width="100">
<el-input type="password" v-model="data.password" placeholder="请输入密码" autocomplete="off" />
</el-form-item>
<el-form-item label="用户角色" :label-width="100">
<el-input v-model="data.rolename" placeholder="请输入用户角色" autocomplete="off" />
</el-form-item>
<el-form-item label="用户状态" :label-width="100">
<el-switch
v-model=value
inline-prompt
style="--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
active-text="启用"
inactive-text="禁用"
/>
</el-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="handleCancel">取消</el-button>
<el-button type="primary" @click="handleCancel">
保存
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts" setup>
import { ref,computed } from 'vue'
import {dialogSmall} from '@/utils/elementBind'
const {dialogVisible,title,data} = defineProps<{
dialogVisible:boolean;
title:string;
data:{
username:string;
password:string;
realname:string;
status:number;
rolename:string;
}
}>();
const value = computed({
get: () => data.status === 1,
set: (value: boolean) => data.status = value ? 1 : 0
})
const emit = defineEmits<{
(e:'update:visible',value:boolean):void;
}>();
const handleCancel = () => {
emit('update:visible',false)
}
</script>

View File

@@ -3,12 +3,14 @@
<ProTable <ProTable
ref='proTable' ref='proTable'
:columns='columns' :columns='columns'
:data='userData' :request-api="getTableList"
:data-callback="dataCallback"
> >
<!-- :data='userData' -->
<!-- 表格 header 按钮 --> <!-- 表格 header 按钮 -->
<template #tableHeader='scope'> <template #tableHeader='scope'>
<el-button type='primary' :icon='CirclePlus' @click="openDrawer('新增用户')">新增</el-button> <el-button type='primary' :icon='CirclePlus' @click="openDrawer('新增用户')">新增</el-button>
<el-button type='primary' :icon='Download' plain @click='downloadFile'>导出数据</el-button> <el-button type='primary' :icon='Download' plain >导出数据</el-button>
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected' <el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
@click='batchDelete(scope.selectedListIds)'> @click='batchDelete(scope.selectedListIds)'>
批量删除 批量删除
@@ -23,11 +25,13 @@
</ProTable> </ProTable>
</div> </div>
<userUnit <userPopup
:dialogVisible = userUnitVisible :dialogVisible = userPopupVisible
:title = userUnitTitle :title = userPopupTitle
:data = userUnitData :data = userPopupData
@update:visible="userUnitVisible = $event" :openType=openType
:getTableList="proTable?.getTableList || (() => {})"
@update:visible="userPopupVisible = $event"
/> />
</template> </template>
@@ -37,7 +41,7 @@
import { useDownload } from '@/hooks/useDownload' import { useDownload } from '@/hooks/useDownload'
import { useAuthButtons } from '@/hooks/useAuthButtons' import { useAuthButtons } from '@/hooks/useAuthButtons'
import ProTable from '@/components/ProTable/index.vue' import ProTable from '@/components/ProTable/index.vue'
import userUnit from './components/userUnit.vue' import userPopup from './components/userPopup.vue'
import ImportExcel from '@/components/ImportExcel/index.vue' import ImportExcel from '@/components/ImportExcel/index.vue'
import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface' import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
@@ -50,28 +54,25 @@
BatchAddUser, BatchAddUser,
editUser, editUser,
deleteUser, deleteUser,
changeUserStatus,
exportUserInfo,
getUserStatus,
} from '@/api/user/user' } from '@/api/user/user'
const {userUnitVisible,userUnitTitle,userUnitData} = useCount(); const {userPopupVisible,userPopupTitle,userPopupData} = useCount();
function useCount() { function useCount() {
const userUnitVisible = ref(false) const userPopupVisible = ref(false)
const userUnitTitle = ref() const userPopupTitle = ref()
const userUnitData = ref<User.ResUserList>({} as User.ResUserList) const userPopupData = ref<User.UserBO>({} as User.UserBO)
return {userUnitVisible,userUnitTitle,userUnitData}; return {userPopupVisible,userPopupTitle,userPopupData};
} }
const dictStore = useDictStore() const dictStore = useDictStore()
let openType = ''
const userData = userDataList // const userData = userDataList
// ProTable 实例 // ProTable 实例
const proTable = ref<ProTableInstance>() const proTable = ref<ProTableInstance>()
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据) // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
const initParam = reactive({ type: 1 }) // const initParam = reactive({ type: 1 })
// dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段 // dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行 // 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
@@ -79,6 +80,8 @@
return { return {
list: data.list, list: data.list,
total: data.total, total: data.total,
pageNum: data.pageNum,
pageSize: data.pageSize,
} }
} }
@@ -96,102 +99,116 @@
const { BUTTONS } = useAuthButtons() const { BUTTONS } = useAuthButtons()
// 表格配置项 // 表格配置项
const columns = reactive<ColumnProps<User.ResUserList>[]>([ const columns = reactive<ColumnProps<User.UserBO>[]>([
{ type: 'selection', fixed: 'left', width: 70 }, { type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' }, { type: 'index', fixed: 'left', width: 70, label: '序号' },
{ {
prop: 'username', prop: 'name',
label: '用户名', label: '用户名',
search: { el: 'input' }, search: { el: 'input' },
minWidth: 150, minWidth: 150,
}, },
{ {
prop: 'realname', prop: 'loginName',
label: '真实姓名', label: '登录名',
search: { el: 'input' },
minWidth: 180, minWidth: 180,
}, },
{ {
prop: 'rolename', prop: 'password',
label: '角色类型', label: '密码',
minWidth: 180, minWidth: 180,
}, },
{ {
prop: 'status', prop: 'phone',
label: '手机号',
label: '状态', minWidth: 180,
enum: dictStore.getDictData('status'),
search: { el: 'tree-select', props: { filterable: true } },
minWidth: 100,
fieldNames: { label: 'label', value: 'code' },
render: scope => {
return (
<el-tag type={scope.row.status ? 'success' : 'danger'}>{scope.row.status ? '启用' : '禁用'}</el-tag>
)
}, },
{
prop: 'email',
label: '邮箱',
minWidth: 180,
},
{
prop: 'loginTime',
label: '最后一次登录时间',
minWidth: 180,
},
{
prop: 'loginErrorTimes',
label: '登录错误次数',
minWidth: 180,
},
{
prop: 'lockTime',
label: '用户密码错误锁定时间',
minWidth: 180,
}, },
{ prop: 'operation', label: '操作', fixed: 'right', width: 330 }, { prop: 'operation', label: '操作', fixed: 'right', width: 330 },
]) ])
// 删除角色信息 // 删除用户信息
const deleteAccount = async (params: User.ResUserList) => { const deleteAccount = async (params: User.UserBO) => {
await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.rolename}角色`) await useHandleData(deleteUser, { id: [params.id] }, `删除【${params.name}用户`)
proTable.value?.getTableList() proTable.value?.getTableList()
} }
// 批量删除角色信息 // 批量删除角色信息
const batchDelete = async (id: string[]) => { const batchDelete = async (id: string[]) => {
await useHandleData(deleteUser, { id }, '删除所选角色信息') await useHandleData(deleteUser, { id }, '删除所选用户信息')
proTable.value?.clearSelection() proTable.value?.clearSelection()
proTable.value?.getTableList() proTable.value?.getTableList()
} }
// 切换角色状态
const changeStatus = async (row: User.ResUserList) => {
await useHandleData(changeUserStatus, {
id: row.id,
status: row.status == 1 ? 0 : 1,
}, `切换【${row.rolename}】角色状态`)
proTable.value?.getTableList()
}
// 导出角色列表 // 导出角色列表
const downloadFile = async () => { // const downloadFile = async () => {
ElMessageBox.confirm('确认导出角色数据?', '温馨提示', { type: 'warning' }).then(() => // ElMessageBox.confirm('确认导出角色数据?', '温馨提示', { type: 'warning' }).then(() =>
useDownload(exportUserInfo, '角色列表', proTable.value?.searchParam), // useDownload(exportUserInfo, '角色列表', proTable.value?.searchParam),
) // )
} // }
// 批量添加角色 // 批量添加角色
const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null) const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
const batchAdd = () => { const batchAdd = () => {
const params = { // const params = {
title: '角色', // title: '角色',
tempApi: exportUserInfo, // tempApi: exportUserInfo,
importApi: BatchAddUser, // importApi: BatchAddUser,
getTableList: proTable.value?.getTableList, // getTableList: proTable.value?.getTableList,
} // }
dialogRef.value?.acceptParams(params) // dialogRef.value?.acceptParams(params)
} }
// 打开 drawer(新增、查看、编辑) // 打开 drawer(新增、查看、编辑)
const openDrawer = (title: string, row: Partial<User.ResUserList> = {}) => { const openDrawer = (title: string, row: Partial<User.UserBO> = {}) => {
if(title === "查看用户" ||title === "新增用户" || title === '编辑用户' ) if(title === "查看用户" ||title === "新增用户" || title === '编辑用户' )
{ {
userUnitVisible.value = true if (title === '查看用户')
userUnitTitle.value = title openType = 'view'
else if (title === '新增用户')
openType = 'add'
else if (title === '编辑用户')
openType = 'edit'
userPopupVisible.value = true
userPopupTitle.value = title
if (row) { if (row) {
// 确保 row 的所有属性都符合 User.ResUserList 的要求 // 确保 row 的所有属性都符合 User.ResUserList 的要求
const safeRow: User.ResUserList = { const safeRow: User.UserBO = {
id: row.id || '', id: row.id || '',
username: row.username || '', name: row.name || '',
loginName: row.loginName || '',
password: row.password || '', password: row.password || '',
realname: row.realname || '', phone: row.phone || '',
status: row.status || 0, email: row.email || '',
rolename: row.rolename || '', loginTime: row.loginTime || '',
loginErrorTimes: row.loginErrorTimes || 0,
lockTime: row.lockTime || '',
}; };
userUnitData.value = safeRow; userPopupData.value = safeRow;
} }
} }

View File

@@ -3,11 +3,11 @@
<el-dialog class='table-box' <el-dialog class='table-box'
v-model='dialogVisible' v-model='dialogVisible'
top='114px' top='114px'
:style="{height:height,maxHeight:height,overflow:'hidden'}" :style="{height:height+'px',maxHeight:height+'px',overflow:'hidden'}"
:title='title' :title='title'
:width='width' :width='width'
:modal='false'> :modal='false'>
<div class='table-box'> <div class='table-box' :style="{height:(height-64)+'px',maxHeight:(height-64)+'px',overflow:'hidden'}">
<ProTable <ProTable
ref='proTable' ref='proTable'
:columns='columns' :columns='columns'
@@ -140,12 +140,12 @@ defineExpose({ open })
const props = defineProps({ const props = defineProps({
width: { width: {
type: String, type: Number,
default: '800px', default: 800,
}, },
height: { height: {
type: String, type: Number,
default: '744px', default: 744,
}, },
}) })

View File

@@ -21,7 +21,7 @@
<el-button type='primary' link :icon='View' >查看</el-button> <el-button type='primary' link :icon='View' >查看</el-button>
<el-button type='primary' link :icon='EditPen' >编辑</el-button> <el-button type='primary' link :icon='EditPen' >编辑</el-button>
<el-button type='primary' link :icon='Delete' >删除</el-button> <el-button type='primary' link :icon='Delete' >删除</el-button>
<el-button type='primary' link :icon='Upload' >升级为模板</el-button> <el-button type='primary' :model-value="false" link :icon='Upload' >升级为模板</el-button>
</template> </template>
</ProTable> </ProTable>

View File

@@ -1,282 +0,0 @@
<template>
<el-dialog class='table-box' v-model='dialogVisible1' top='114px'
:style="{ height: height, maxHeight: height, overflow: 'hidden' }" :title='title1' :width='width' :modal='false'>
<div class="table-box">
<ProTable :columns="columns" :data="data">
<template #tableHeader="scope">
<el-button type="primary" :icon="CirclePlus" @click="openDrawer('新增')">新增</el-button>
<el-button type="primary" :icon="Upload" plain @click="batchAdd">批量添加</el-button>
<el-button type="primary" :icon="Download" plain @click="downloadFile">导出</el-button>
<el-button type="danger" :icon="Delete" plain :disabled="!scope.isSelected"
@click="batchDelete(scope.selectedListIds)">
批量删除
</el-button>
</template>
<template #operation="scope">
<el-button type="primary" link :icon="EditPen" @click="openDrawer('编辑', scope.row)">编辑</el-button>
<el-button type="primary" link :icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
</template>
</ProTable>
</div>
</el-dialog>
<el-dialog v-model="dialogVisible2" :title="dialogType2 === '新增' ? '新增字典数据' : '编辑字典数据'" v-bind="dialogSmall">
<div>
<el-form :model="dialogForm" ref="dialogFormRef" :rules="rules">
<el-form-item label="字典类型编码" :label-width="100">
<el-input :value="route.params.code" disabled />
</el-form-item>
<el-form-item label="名称" :label-width="100" prop="name">
<el-input v-model="dialogForm.name" placeholder="请输入" autocomplete="off" />
</el-form-item>
<el-form-item label="编码" :label-width="100" prop="code">
<el-input v-model="dialogForm.code" placeholder="请输入" autocomplete="off" />
</el-form-item>
<el-form-item label="值" :label-width="100" prop="value">
<el-input v-model="dialogForm.value" placeholder="请输入" autocomplete="off" />
</el-form-item>
<el-form-item label="显示排序" :label-width="100">
<el-input-number v-model="dialogForm.sort" />
</el-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()">
保存
</el-button>
</div>
</template>
</el-dialog>
</template>
<script setup lang="tsx" name="dictData">
import { useRoute } from 'vue-router'
import { CirclePlus, Delete, EditPen, Download, Upload } from '@element-plus/icons-vue'
import { Dict } from '@/api/system/dictionary/interface'
import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface'
import ImportExcel from '@/components/ImportExcel/index.vue'
import { dialogSmall } from '@/utils/elementBind'
import { useDictStore } from '@/stores/modules/dict'
import { useHandleData } from '@/hooks/useHandleData'
import { useDownload } from '@/hooks/useDownload'
import { dictDataList } from '@/api/system/dictionary/dictExample'
import { FormItemRule } from 'element-plus'
import {
getDictDataList,
updateDictData,
addDictData,
batchAddDictData,
exportDictData,
deleteDictData
} from '@/api/system/dictionary'
const route = useRoute()
const dictStore = useDictStore()
const data = dictDataList
const proTable = ref<ProTableInstance>()
const dictTypeId = ref('')
const dialogVisible1 = ref(false)
const title1 = ref('')
const dialogFormRef = ref()
const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
{ type: 'selection', fixed: 'left', width: 70 },
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
{
prop: 'name',
label: '名称',
width: 180,
search: {
el: 'input'
}
},
{
prop: 'code',
label: '编码',
width: 180,
search: {
el: 'input'
}
},
{
prop: 'value',
label: '值',
width: 180
},
{
prop: 'level',
label: '事件等级',
width: 120,
render: scope => {
return (
<>
{scope.row.level === 0 || scope.row.level === null || scope.row.level === undefined ?
(<span></span>) :
(<el-tag type={scope.row.level === 1 ? 'info' : scope.row.level === 2 ? 'warning' : 'danger'}>
{scope.row.level === 1 ? '普通' : scope.row.level === 2 ? '警告' : '危险'}
</el-tag>)
}
</>
)
}
},
{
prop: 'state',
label: '状态',
minWidth: 100,
enum: dictStore.getDictData('status'),
search: {
el: 'tree-select',
props: { filterable: true }
},
fieldNames: { label: 'label', value: 'code' },
render: scope => {
return (
<>
{
<el-tag type={scope.row.state ? 'success' : 'danger'} > {scope.row.state ? '正常' : '禁用'} </el-tag>
}
</>
)
},
},
{
prop: 'createTime',
label: '创建时间',
width: 180,
search: {
el: 'date-picker',
props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' }
}
},
{
prop: 'operation',
label: '操作',
fixed: 'right',
width: 330
},
])
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
name: [{ required: true, message: '类型名称必填!', trigger: 'blur' }],
code: [{ required: true, message: '类型编码必填!', trigger: 'blur' }],
value: [{ required: true, message: '类型值必填!', trigger: 'blur' }],
})
const { dialogVisible2, dialogType2, dialogForm } = useCount();
function useCount() {
const dialogVisible2 = ref(false)
const dialogType2 = ref('新增')
const dialogForm = ref({
id: "",
name: "",
code: "",
value: "",
sort: 100,
})
return { dialogVisible2, dialogType2, dialogForm };
}
const props = defineProps({
width: {
type: String,
default: '800px',
},
height: {
type: String,
default: '744px',
},
})
const open = (textTitle: string, id: string) => {
dialogVisible1.value = true
title1.value = textTitle
dictTypeId.value = id
// getDictDataList({ dictTypeId: id }).then(res => {
// data.value = res.data
// }
}
defineExpose({ open })
// 打开 drawer(新增、查看、编辑)
const openDrawer = (title: string, row: Partial<Dict.ResDictType> = {}) => {
dialogVisible2.value = true
dialogType2.value = title
if (title === '编辑') {
row && (dialogForm.value = row as { id: string; name: string; code: string; value: string; sort: number; state: number; });
}
}
// 批量添加字典数据
const dialogRef = ref<InstanceType<typeof ImportExcel> | null>(null)
const batchAdd = () => {
const params = {
title: '字典数据',
tempApi: exportDictData,
importApi: batchAddDictData,
getTableList: proTable.value?.getTableList,
}
dialogRef.value?.acceptParams(params)
}
// 导出字典数据
const downloadFile = async () => {
ElMessageBox.confirm('确认导出字典数据?', '温馨提示', { type: 'warning' }).then(() =>
useDownload(exportDictData, '字典数据列表', proTable.value?.searchParam),
)
}
// 批量删除字典数据
const batchDelete = async (id: string[]) => {
await useHandleData(deleteDictData, { id }, '删除所选字典数据')
proTable.value?.clearSelection()
proTable.value?.getTableList()
}
// 删除字典数据
const handleDelete = async (params: Dict.ResDictType) => {
await useHandleData(deleteDictData, { id: [params.id] }, `删除【${params.name}】字典数据`)
proTable.value?.getTableList()
}
const close = () => {
dialogVisible2.value = false
//清空dialogForm中的值
dialogForm.value = {
id: "",
name: "",
code: "",
value: "",
sort: 100
}
dialogFormRef.value?.resetFields()
}
const save = () => {
try {
dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
let params = JSON.stringify(dialogForm.value)
console.log(params)
if (dialogType2.value === '新增') {
await useHandleData(addDictData, dialogForm.value, '新增字典数据')
} else {
await useHandleData(updateDictData, dialogForm.value, '编辑字典数据')
}
close()
proTable.value?.getTableList()
} else {
ElMessage.error('表单验证失败!')
}
})
} catch (err) {
console.error('验证过程中出现错误', err)
}
}
</script>

View File

@@ -0,0 +1,128 @@
<template>
<el-dialog v-model="dialogVisible" :title="dialogTitle"
v-bind="dialogSmall">
<div>
<el-form :model="formContent" ref="dialogFormRef" :rules="rules">
<el-form-item label="字典类型" :label-width="100">
<el-input :value="dictTypeName" disabled/>
</el-form-item>
<el-form-item label="名称" :label-width="100" prop="name">
<el-input v-model="formContent.name" placeholder="请输入" autocomplete="off"/>
</el-form-item>
<el-form-item label="编码" :label-width="100" prop="code">
<el-input v-model="formContent.code" placeholder="请输入" autocomplete="off"/>
</el-form-item>
<el-form-item label="值" :label-width="100" prop="dictValue">
<el-input v-model="formContent.dictValue" placeholder="请输入" autocomplete="off"/>
</el-form-item>
<el-form-item label="显示排序" :label-width="100">
<el-input-number v-model="formContent.sort"/>
</el-form-item>
</el-form>
</div>
<template #footer>
<div class="dialog-footer">
<el-button @click="close()">取消</el-button>
<el-button type="primary" @click="save()">
保存
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="tsx" setup>
import {dialogSmall} from "@/utils/elementBind";
import {addDictData, updateDictData} from "@/api/system/dictionary/dictData";
import {Dict} from "@/api/system/dictionary/interface";
import {FormItemRule} from "element-plus";
import type {Ref} from "vue";
const rules: Ref<Record<string, Array<FormItemRule>>> = ref({
name: [{required: true, message: '类型名称必填!', trigger: 'blur'}],
code: [{required: true, message: '类型编码必填!', trigger: 'blur'}],
dictValue: [{required: true, message: '类型值必填!', trigger: 'blur'}],
})
const dialogFormRef = ref()
const {dialogVisible, titleType, formContent, dictTypeName} = useMetaInfo();
function useMetaInfo() {
const dialogVisible = ref(false)
const titleType = ref('add')
const dictTypeName = ref('')
const formContent = ref<Dict.ResDictData>({
id: "",
typeId: "",
name: "",
code: "",
value: "",
dictValue: "",
sort: 100,
state: 1,
})
return {dialogVisible, titleType, formContent, dictTypeName};
}
let dialogTitle = computed(() => {
return titleType.value === 'add' ? '新增字典类型' : '编辑字典类型'
})
const resetFormContent = () => {
formContent.value = {
id: "",
typeId: "",
name: "",
code: "",
value: "",
sort: 100,
state: 1,
}
}
const close = () => {
dialogVisible.value = false
resetFormContent()
dialogFormRef.value?.resetFields()
}
const open = (sign: string, typeId: string, name: string, data: Dict.ResDictData) => {
resetFormContent()
titleType.value = sign
formContent.value.typeId = typeId
dictTypeName.value = name
dialogVisible.value = true
if (data.id) {
formContent.value = {...data}
formContent.value.dictValue = data.value
}
}
const save = () => {
try {
dialogFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
formContent.value.value = formContent.value.dictValue
console.log(formContent.value)
if (formContent.value.id) {
await updateDictData(formContent.value)
} else {
await addDictData(formContent.value)
}
ElMessage.success({message: `${dialogTitle.value}成功!`})
close()
await props.refreshTable!()
}
})
} catch (err) {
console.error('验证过程中出现错误', err)
}
}
// 对外映射
defineExpose({open})
const props = defineProps<{
refreshTable: (() => Promise<void>) | undefined;
}>()
</script>

View File

@@ -0,0 +1,139 @@
<template>
<el-dialog class='table-box' v-model='dialogVisible' top='114px'
:style="{ height: height+'px', maxHeight: height+'px', overflow: 'hidden' }" title='字典数据'
:width='width'
:modal='false'>
<div class='table-box' :style="{height:(height-64)+'px',maxHeight:(height-64)+'px',overflow:'hidden'}">
<ProTable ref='proTable' :columns="columns" :request-api='getDictDataListByTypeId' :initParam="initParam">
<template #tableHeader="scope">
<el-button type="primary" :icon="CirclePlus" @click="openDialog('add')">新增</el-button>
<el-button type="danger" :icon="Delete" plain :disabled="!scope.isSelected"
@click="batchDelete(scope.selectedListIds)">
批量删除
</el-button>
</template>
<template #operation="scope">
<el-button type="primary" link :icon="EditPen" @click="openDialog('edit', scope.row)">编辑</el-button>
<el-button type="primary" link :icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
</template>
</ProTable>
</div>
</el-dialog>
<DataPopup :refresh-table='proTable?.getTableList' ref='dataPopup'/>
</template>
<script setup lang="tsx" name="dictData">
import {CirclePlus, Delete, EditPen} from '@element-plus/icons-vue'
import {Dict} from '@/api/system/dictionary/interface'
import {ProTableInstance, ColumnProps} from '@/components/ProTable/interface'
import {useHandleData} from '@/hooks/useHandleData'
import DataPopup from '@/views/system/dictionary/dictData/components/dataPopup.vue'
import {
getDictDataListByTypeId,
deleteDictData,
} from "@/api/system/dictionary/dictData";
const proTable = ref<ProTableInstance>()
const dialogVisible = ref(false)
//字典数据所属的字典类型Id
const dictTypeId = ref('')
const dictTypeName = ref('')
const initParam = reactive({typeId: ''})
const dataPopup = ref()
const props = defineProps({
width: {
type: String,
default: '800px',
},
height: {
type: String,
default: '744px',
},
})
const columns = reactive<ColumnProps<Dict.ResDictData>[]>([
{type: 'selection', fixed: 'left', width: 70},
{type: 'index', fixed: 'left', width: 70, label: '序号'},
{
prop: 'name',
label: '名称',
width: 180,
search: {
el: 'input'
}
},
{
prop: 'code',
label: '编码',
width: 180,
search: {
el: 'input'
}
},
{
prop: 'value',
label: '值',
width: 180
},
{
prop: 'level',
label: '事件等级',
width: 180,
render: scope => {
return (
<>
{scope.row.level === 0 || scope.row.level === null || scope.row.level === undefined ?
(<span></span>) :
(<el-tag type={scope.row.level === 1 ? 'info' : scope.row.level === 2 ? 'warning' : 'danger'}>
{scope.row.level === 1 ? '普通' : scope.row.level === 2 ? '警告' : '危险'}
</el-tag>)
}
</>
)
}
},
{
prop: 'createTime',
label: '创建时间',
width: 180
},
{
prop: 'operation',
label: '操作',
fixed: 'right',
minWidth: 300
},
])
const open = (row: Dict.ResDictType) => {
dialogVisible.value = true
dictTypeId.value = row.id
dictTypeName.value = row.name
initParam.typeId = row.id
}
defineExpose({open})
// 打开 dialog(新增、查看、编辑)
const openDialog = (titleType: string, row: Partial<Dict.ResDictData> = {}) => {
dataPopup.value?.open(titleType, dictTypeId.value, dictTypeName.value, row)
}
// 批量删除字典数据
const batchDelete = async (id: string[]) => {
await useHandleData(deleteDictData, id, '删除所选字典数据')
proTable.value?.clearSelection()
proTable.value?.getTableList()
}
// 删除字典数据
const handleDelete = async (params: Dict.ResDictData) => {
await useHandleData(deleteDictData, [params.id], `删除【${params.name}】字典数据`)
proTable.value?.getTableList()
}
</script>

View File

@@ -8,6 +8,18 @@
<el-form-item label='类型编码' :label-width='100' prop='code'> <el-form-item label='类型编码' :label-width='100' prop='code'>
<el-input v-model='formContent.code' placeholder='请输入' autocomplete='off' /> <el-input v-model='formContent.code' placeholder='请输入' autocomplete='off' />
</el-form-item> </el-form-item>
<el-form-item label="开启等级" :label-width="100">
<el-radio-group v-model="formContent.openLevel" size="medium">
<el-radio-button label="开启" :value="1"></el-radio-button>
<el-radio-button label="关闭" :value="0"></el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="开启描述" :label-width="100">
<el-radio-group v-model="formContent.openDescribe" size="medium">
<el-radio-button label="开启" :value="1"></el-radio-button>
<el-radio-button label="关闭" :value="0"></el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label='显示排序' :label-width='100'> <el-form-item label='显示排序' :label-width='100'>
<el-input-number v-model='formContent.sort' /> <el-input-number v-model='formContent.sort' />
</el-form-item> </el-form-item>
@@ -103,8 +115,6 @@ const save = () => {
close() close()
// 刷新表格 // 刷新表格
await props.refreshTable!() await props.refreshTable!()
} else {
ElMessage.error('表单验证失败!')
} }
}) })
} catch (err) { } catch (err) {

View File

@@ -21,34 +21,34 @@
</template> </template>
</ProTable> </ProTable>
</div> </div>
<Data :width='viewWidth' :height='viewHeight' ref='openView' /> <DictData :width='viewWidth' :height='viewHeight' ref='openView'/>
<type-popup :refresh-table='proTable?.getTableList' ref='typePopup' /> <type-popup :refresh-table='proTable?.getTableList' ref='typePopup'/>
</template> </template>
<script setup lang='tsx' name='dict'> <script setup lang='tsx' name='dict'>
import { CirclePlus, Delete, EditPen, Download, View } from '@element-plus/icons-vue' import {CirclePlus, Delete, EditPen, Download, View} from '@element-plus/icons-vue'
import { Dict } from '@/api/system/dictionary/interface' import {Dict} from '@/api/system/dictionary/interface'
import { ProTableInstance, ColumnProps } from '@/components/ProTable/interface' import {ProTableInstance, ColumnProps} from '@/components/ProTable/interface'
import TypePopup from '@/views/system/dictionary/dictType/components/typePopup.vue' import TypePopup from '@/views/system/dictionary/dictType/components/typePopup.vue'
import Data from '@/views/system/dictionary/data.vue' import DictData from '@/views/system/dictionary/dictData/index.vue'
import { useDictStore } from '@/stores/modules/dict' import {useDictStore} from '@/stores/modules/dict'
import { useHandleData } from '@/hooks/useHandleData' import {useHandleData} from '@/hooks/useHandleData'
import { useViewSize } from '@/hooks/useViewSize' import {useViewSize} from '@/hooks/useViewSize'
import { import {
getDictTypeList, getDictTypeList,
deleteDictType, deleteDictType,
} from '@/api/system/dictionary/dictType' } from '@/api/system/dictionary/dictType'
const dictStore = useDictStore() const dictStore = useDictStore()
const { popupBaseView, viewWidth, viewHeight } = useViewSize() const {popupBaseView, viewWidth, viewHeight} = useViewSize()
const proTable = ref<ProTableInstance>() const proTable = ref<ProTableInstance>()
const typePopup = ref() const typePopup = ref()
const openView = ref() const openView = ref()
const columns = reactive<ColumnProps<Dict.ResDictType>[]>([ const columns = reactive<ColumnProps<Dict.ResDictType>[]>([
{ type: 'selection', fixed: 'left', width: 70 }, {type: 'selection', fixed: 'left', width: 70},
{ type: 'index', fixed: 'left', width: 70, label: '序号' }, {type: 'index', fixed: 'left', width: 70, label: '序号'},
{ {
prop: 'name', prop: 'name',
label: '类型名称', label: '类型名称',
@@ -68,35 +68,12 @@ const columns = reactive<ColumnProps<Dict.ResDictType>[]>([
{ {
prop: 'remark', prop: 'remark',
label: '描述', label: '描述',
width: 340, minWidth: 300,
},
{
prop: 'state',
label: '状态',
enum: dictStore.getDictData('status'),
search: {
el: 'tree-select',
props: { filterable: true },
},
fieldNames: { label: 'label', value: 'code' },
render: scope => {
return (
<>
{
<el-tag type={scope.row.state ? 'success' : 'danger'}> {scope.row.state ? '正常' : '禁用'} </el-tag>
}
</>
)
},
}, },
{ {
prop: 'createTime', prop: 'createTime',
label: '创建时间', label: '创建时间',
width: 180, width: 180,
search: {
el: 'date-picker',
props: { type: 'daterange', valueFormat: 'YYYY-MM-DD' },
},
}, },
{ {
prop: 'operation', prop: 'operation',
@@ -134,7 +111,7 @@ const handleDelete = async (params: Dict.ResDictType) => {
//查看字典类型包含的字典数据 //查看字典类型包含的字典数据
const toDictData = (row: Dict.ResDictType) => { const toDictData = (row: Dict.ResDictType) => {
openView.value.open('字典数据', row.id) openView.value.open(row)
} }