diff --git a/app/src/api/employee.js b/app/src/api/employee.js index d73321c..b9a3c59 100644 --- a/app/src/api/employee.js +++ b/app/src/api/employee.js @@ -21,10 +21,14 @@ const getAllEmployee = (params) => { params }) } +const loginEmployee = (params) => { + return http.post('/employee/login', params) +} export { getEmployee, createEmployee, getAllEmployee, updateEmployee, - deleteEmployee + deleteEmployee, + loginEmployee } diff --git a/app/src/stores/modules/user.js b/app/src/stores/modules/user.js index 3c8efa3..39dc49f 100644 --- a/app/src/stores/modules/user.js +++ b/app/src/stores/modules/user.js @@ -14,204 +14,26 @@ const useUserStore = defineStore( () => { // 模拟后台返回的token const token = ref('') + const _id = ref('') + const name = ref('') + const userType = ref('') const setToken = (newToken) => { token.value = newToken } + const setId = (newId) => { + _id.value = newId + } + const setName = (newName) => { + name.value = newName + } + const setUserType = (newUserType) => { + userType.value = newUserType + } // 模拟后台返回的侧边栏数据 const asideData = ref([]) - // const asideData = ref([ - // { - // index: '/home', - // icon: 'icon iconfont icon-shujutongji', - // name: '数据统计' - // }, - // // - // { - // index: '/user-manage', - // icon: 'icon iconfont icon-yonghuguanli', - // name: '用户管理' - // }, - // { - // index: '/employee-manage', - // icon: 'icon iconfont icon-shenfenzhongxin-xinxiguanlizhigongxinxiguanli', - // name: '职工管理' - // }, - // { - // index: '/reward-manage', - // icon: 'icon iconfont icon-gerenjixiao', - // name: '绩效管理' - // }, - // // 二级 - // { - // index: '/feedback', - // icon: 'icon iconfont icon-fankui', - // name: '员工反馈与投诉管理', - // children: [ - // { - // index: '/feedback/manage', - // name: '投诉管理' - // }, - // { - // index: '/feedback/view', - // name: '员工反馈' - // } - // ] - // }, - // { - // index: '/request', - // icon: 'icon iconfont icon-qingjiashenqing', - // name: '请假管理', - // children: [ - // { - // index: '/request/manage', - // name: '请假信息管理' - // }, - // { - // index: '/request/view', - // name: '个人请假信息' - // } - // ] - // }, - // { - // index: '/person', - // icon: 'icon iconfont icon-gerenxinxiguanli', - // name: '个人信息管理', - // children: [ - // { - // index: '/person/password', - // name: '修改密码' - // }, - // { - // index: '/person/avatar', - // name: '修改个人信息' - // } - // ] - // } - // ]) // 模拟后台返回的路由数据 const routerData = ref([]) - // const routerData = ref([ - // { - // path: 'home', - // name: 'home', - // meta: { - // // 路由组件的路径 - // url: '../views/HomeView.vue' - // } - // }, - // { - // path: 'table/main-table1', - // name: 'main-table', - // meta: { - // name: '表格1', - // url: '../views/table/MainTableView.vue' - // } - // }, - // { - // path: 'excel', - // name: 'excel', - - // meta: { - // name: 'excel', - // url: '../views/ExcelView.vue' - // } - // }, - - // { - // path: 'tx-yun', - // name: 'tx-yun', - - // meta: { - // name: 'tx-yun', - // url: '../views/TxView.vue' - // } - // }, - - // { - // path: 'preview-picture', - // name: 'preview-picture', - - // meta: { - // name: 'preview-picture', - // url: '../views/PreviewPictureView.vue' - // } - // }, - // // - // { - // path: 'user-manage', - // name: 'user-manage', - // meta: { - // // 路由组件的路径 - // url: '../views/UserManageView.vue' - // } - // }, - // { - // path: 'employee-manage', - // name: 'employee-manage', - // meta: { - // // 路由组件的路径 - // url: '../views/EmployeeManageView.vue' - // } - // }, - // { - // path: 'reward-manage', - // name: 'reward-manage', - // meta: { - // // 路由组件的路径 - // url: '../views/RewardManageView.vue' - // } - // }, - // // 二级 - // { - // path: 'feedback/manage', - // name: 'feedback-manage', - // meta: { - // // 路由组件的路径 - // url: '../views/feedback/FeedbackManageView.vue' - // } - // }, - // { - // path: 'feedback/view', - // name: 'feedback-view', - // meta: { - // // 路由组件的路径 - // url: '../views/feedback/FeedbackView.vue' - // } - // }, - // { - // path: 'request/manage', - // name: 'request-manage', - // meta: { - // // 路由组件的路径 - // url: '../views/request/RequestManageView.vue' - // } - // }, - // { - // path: 'request/view', - // name: 'request-view', - // meta: { - // // 路由组件的路径 - // url: '../views/request/RequestView.vue' - // } - // }, - // { - // path: 'person/password', - // name: 'person-password', - // meta: { - // // 路由组件的路径 - // url: '../views/PersonInfo/ChangePasswordView.vue' - // } - // }, - // { - // path: 'person/avatar', - // name: 'person-avatar', - // meta: { - // // 路由组件的路径 - // url: '../views/PersonInfo/ChangeAvatarView.vue' - // } - // } - // ]) // 动态添加路由 const addUserRoute = (router, modules) => { routerData.value.forEach((item) => { @@ -236,7 +58,13 @@ const useUserStore = defineStore( routerData, setToken, token, - asideData + asideData, + _id, + setId, + userType, + name, + setName, + setUserType } }, { diff --git a/app/src/views/LoginView.vue b/app/src/views/LoginView.vue index ef5fa2e..9df43ce 100644 --- a/app/src/views/LoginView.vue +++ b/app/src/views/LoginView.vue @@ -2,7 +2,7 @@ * @Author: BINGWU * @Date: 2024-04-10 16:15:37 * @LastEditors: BINGWU HuJiaCheng2003@163.com - * @LastEditTime: 2024-05-19 17:07:18 + * @LastEditTime: 2024-05-23 11:34:56 * @FilePath: \employee-information-management-system\app\src\views\LoginView.vue * @Describe: * @Mark: ૮(˶ᵔ ᵕ ᵔ˶)ა @@ -18,7 +18,16 @@ - 登陆 +
+ + 登陆 +
@@ -28,6 +37,7 @@ import { ref } from 'vue' import { useRouter } from 'vue-router' import { getUserStore } from '@/stores' import { loginUser, getUser } from '@/api/user' +import { loginEmployee, getEmployee } from '@/api/employee' const modules = import.meta.glob('../views/**/**.vue') const router = useRouter() const userStore = getUserStore() @@ -35,29 +45,63 @@ const formData = ref({ username: '', password: '' }) -const login = () => { - loginUser({ - ...formData.value +const mode = ref(true) + +const handleLogin = (callback, params) => { + callback(params) + return new Promise((reslove, reject) => { + callback(params) + .then((res) => { + reslove(res.data) + }) + .catch((error) => { + reject(error) + }) }) - .then(async (res) => { - const { token, _id } = res.data +} + +const login = async () => { + const callback = mode.value ? loginUser : loginEmployee + const params = { + password: formData.value.password + } + if (mode.value) { + params.username = formData.value.username + } else { + params.employeeName = formData.value.username + } + handleLogin(callback, params) + .then(async ({ token, _id, msg }) => { + let data = null ElMessage({ - message: res.data.msg, + message: msg, type: 'success', plain: true }) userStore.setToken(token) - const data = await getUser(_id) - const { asideData, routerData } = data.data + userStore.setId(_id) + if (mode.value) { + data = await getUser(_id) + } else { + data = await getEmployee(_id) + } + const { asideData, routerData, userType } = data.data userStore.addUserRoute(router, modules) userStore.asideData = asideData userStore.routerData = routerData + userStore.setUserType(userType) - router.push('/home') + if (mode.value) { + userStore.setName(data.data.username) + router.push('/home') + } else { + userStore.setName(data.data.employeeName) + router.push('/feedback/view') + } }) - .catch((message) => { + .catch((error) => { ElMessage({ - message, + message: error, type: 'error', plain: true }) @@ -72,6 +116,10 @@ const login = () => { .content { margin-top: 100px; text-align: center; + .bottom { + display: flex; + justify-content: space-between; + } } } diff --git a/app/src/views/feedback/FeedbackView.vue b/app/src/views/feedback/FeedbackView.vue index f1353ab..efa9456 100644 --- a/app/src/views/feedback/FeedbackView.vue +++ b/app/src/views/feedback/FeedbackView.vue @@ -1,7 +1,62 @@ - + - + diff --git a/serve/serve/views/__pycache__/employee.cpython-311.pyc b/serve/serve/views/__pycache__/employee.cpython-311.pyc index 2660912..b6b98b3 100644 Binary files a/serve/serve/views/__pycache__/employee.cpython-311.pyc and b/serve/serve/views/__pycache__/employee.cpython-311.pyc differ diff --git a/serve/serve/views/employee.py b/serve/serve/views/employee.py index 0337a67..7def6d0 100644 --- a/serve/serve/views/employee.py +++ b/serve/serve/views/employee.py @@ -3,7 +3,8 @@ from django.urls import path from serve.utils.connectdb import connectdb from bson.objectid import ObjectId from serve.middleware.handleErrorMethod import handleErrorMethod -from serve.utils.pyjwt import decode_jwt_token +from serve.utils.decodeBody import decodeBody +from serve.utils.pyjwt import decode_jwt_token, get_jwt_token from serve.commonViews.commonViews import delete, getAll, create, update collection = connectdb('employee_model') @@ -44,10 +45,32 @@ def getEmployee(request): return JsonResponse(result[1]) +def loginEmployee(request): + result = handleErrorMethod(request.method, 'POST') + if result[0]: + data = decodeBody(request) + query = { + "$and": [ + {"employeeName": data['employeeName']}, + {"password": data['password']} + ] + } + employee = collection.find_one(query) + if employee: + token = get_jwt_token(data['employeeName'], data['password']) + return JsonResponse({"code": 2000, "msg": "登陆成功", "token": token, "_id": str(employee['_id'])}) + else: + return JsonResponse({"code": 1000, "msg": "数据不存在"}) + + else: + return JsonResponse(result[1]) + + employee_url = [ path('employee/create', createEmployee), path('employee/delete', deleteEmployee), path('employee/update', updateEmployee), path('employee/get', getEmployee), path('employee/get-all', getAllEmployee), + path('employee/login', loginEmployee), ]