字段调整

This commit is contained in:
GYYM
2024-11-01 13:49:32 +08:00
parent c875ab72fa
commit d9d7a801c8
10 changed files with 279 additions and 198 deletions

View File

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

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 {
id: string; //用户ID作为唯一标识
username: string; //用户名
password: string; //密码
realname: string; //真实姓名
status: number; //用户状态
rolename: string; //角色名称
}
export interface ResStatus {
userLabel: string;
userValue: number;
} }
// 用户+分页
export interface ReqUserParams extends ReqPage,UserBO {
}
} }

View File

@@ -7,20 +7,20 @@ import http from '@/api'
*/ */
// 用户登录 // 用户登录
export const loginApi = (params: Login.ReqLoginForm) => { export const loginApi = (params: Login.ReqLoginForm) => {
return http.post<Login.ResLogin>(`${rePrefix}/login`, params, { loading: false }) // return http.post<Login.ResLogin>(`${rePrefix}/login`, params, { loading: false })
// return http.post<Login.ResLogin>(`/Register1`, params, { loading: false }) return http.post<Login.ResLogin>(`/Register1`, params, { loading: false })
} }
// 获取菜单列表 // 获取菜单列表
export const getAuthMenuListApi = () => { export const getAuthMenuListApi = () => {
return http.get<Menu.MenuOptions[]>(`${rePrefix}/menu/list`, {}, { loading: false }) // return http.get<Menu.MenuOptions[]>(`${rePrefix}/menu/list`, {}, { loading: false })
// return http.post<Menu.MenuOptions[]>(`/Register2`, {}, { loading: false }) return http.post<Menu.MenuOptions[]>(`/Register2`, {}, { loading: false })
} }
// 获取按钮权限 // 获取按钮权限
export const getAuthButtonListApi = () => { export const getAuthButtonListApi = () => {
return http.get<Login.ResAuthButtons>(`${rePrefix}/auth/buttons`, {}, { loading: false }) // return http.get<Login.ResAuthButtons>(`${rePrefix}/auth/buttons`, {}, { loading: false })
// return http.post<Login.ResAuthButtons>(`/Register3`, {}, { loading: false }) return http.post<Login.ResAuthButtons>(`/Register3`, {}, { loading: false })
} }
// 用户退出登录 // 用户退出登录

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

@@ -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, recoards: 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, prop: 'email',
fieldNames: { label: 'label', value: 'code' }, label: '邮箱',
render: scope => { minWidth: 180,
return ( },
<el-tag type={scope.row.status ? 'success' : 'danger'}>{scope.row.status ? '启用' : '禁用'}</el-tag> {
) 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

@@ -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>