From e149c57502ec2a2114a116ab9521a59d3bc49170 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Mon, 19 Feb 2024 21:50:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD:?= =?UTF-8?q?=20=F0=9F=9A=80=20=E5=91=98=E5=B7=A5=E5=A2=9E=E5=88=A0=E6=94=B9?= =?UTF-8?q?=E6=9F=A5=E5=AE=8C=E6=88=90-=E5=8A=A8=E7=94=BB=E6=9C=AA?= =?UTF-8?q?=E5=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + components.d.ts | 1 + src/App.vue | 20 +++ src/api/employee.ts | 24 ++++ src/assets/css/index.scss | 1 + src/assets/css/mixin/circle.scss | 30 +++++ src/assets/css/mixin/index.scss | 1 + src/commpent/button/black-btn.vue | 15 +++ src/commpent/button/cancel-save-add.vue | 50 +++++++ src/commpent/button/primary-btn.vue | 15 +++ src/commpent/page-header.vue | 41 ++++++ src/commpent/pagination.vue | 26 ++++ src/commpent/table/table-footer.vue | 13 ++ src/commpent/table/table-header.vue | 19 +++ src/commpent/table/table-plus.vue | 2 +- src/router/index.ts | 8 ++ src/store/employee.ts | 59 ++++++++- src/views/employee/add-employee.vue | 167 ++++++++++++++++++++++++ src/views/employee/index.vue | 145 +++++++++++++++----- vue.config.js | 2 +- 20 files changed, 599 insertions(+), 41 deletions(-) create mode 100644 src/assets/css/mixin/circle.scss create mode 100644 src/assets/css/mixin/index.scss create mode 100644 src/commpent/button/black-btn.vue create mode 100644 src/commpent/button/cancel-save-add.vue create mode 100644 src/commpent/button/primary-btn.vue create mode 100644 src/commpent/page-header.vue create mode 100644 src/commpent/pagination.vue create mode 100644 src/commpent/table/table-footer.vue create mode 100644 src/commpent/table/table-header.vue create mode 100644 src/views/employee/add-employee.vue diff --git a/.eslintrc.js b/.eslintrc.js index 712f877..97db69b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,5 +12,6 @@ module.exports = { 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'vue/multi-word-component-names': 'off', '@typescript-eslint/no-explicit-any': 'off', + 'vue/no-mutating-props': 'off', }, }; diff --git a/components.d.ts b/components.d.ts index f2bf317..769796c 100644 --- a/components.d.ts +++ b/components.d.ts @@ -22,6 +22,7 @@ declare module 'vue' { ElMain: typeof import('element-plus/es')['ElMain']; ElMenu: typeof import('element-plus/es')['ElMenu']; ElMenuItem: typeof import('element-plus/es')['ElMenuItem']; + ElPagination: typeof import('element-plus/es')['ElPagination']; ElRadio: typeof import('element-plus/es')['ElRadio']; ElRadioButton: typeof import('element-plus/es')['ElRadioButton']; ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup']; diff --git a/src/App.vue b/src/App.vue index e6a5d3b..f5772bb 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,4 +2,24 @@ + diff --git a/src/api/employee.ts b/src/api/employee.ts index 2f3daa3..4593353 100644 --- a/src/api/employee.ts +++ b/src/api/employee.ts @@ -8,6 +8,30 @@ export const reqLogin = (data: any) => { return Request({ url: '/admin/employee/login', method: 'POST', data }); }; +/** + * 启用、禁用员工账号 + * @param data + */ +export const reqStatus = (data: any) => { + return Request({ url: `/admin/employee/status/${data.status}`, method: 'POST', params: { id: data.id } }); +}; + +/** + * 新增员工 + * @param data + */ +export const reqAddEmployee = (data: any) => { + return Request({ url: `/admin/employee`, method: 'POST', data }); +}; + +/** + * 编辑员工信息 + * @param data + */ +export const reqEditEmployee = (data: any) => { + return Request({ url: `/admin/employee`, method: 'PUT', data }); +}; + /** * 员工分页查询 * @param params diff --git a/src/assets/css/index.scss b/src/assets/css/index.scss index 88581c1..82e5f80 100644 --- a/src/assets/css/index.scss +++ b/src/assets/css/index.scss @@ -1,4 +1,5 @@ @charset "UTF-8"; + :root { --el-color-white: #ffffff; --el-color-black: #000000; diff --git a/src/assets/css/mixin/circle.scss b/src/assets/css/mixin/circle.scss new file mode 100644 index 0000000..80b5077 --- /dev/null +++ b/src/assets/css/mixin/circle.scss @@ -0,0 +1,30 @@ +@charset "UTF-8"; + +@mixin circle() { + content: ''; + position: absolute; + top: 50%; + left: -10px; + transform: translateY(-50%); + width: 5px; + height: 5px; + border-radius: 50%; +} + +.circle-success { + position: relative; + + &::before { + @include circle; + background-color: var(--el-color-success); + } +} + +.circle-danger { + position: relative; + + &::before { + @include circle; + background-color: var(--el-color-danger); + } +} diff --git a/src/assets/css/mixin/index.scss b/src/assets/css/mixin/index.scss new file mode 100644 index 0000000..a118da0 --- /dev/null +++ b/src/assets/css/mixin/index.scss @@ -0,0 +1 @@ +@use 'circle'; diff --git a/src/commpent/button/black-btn.vue b/src/commpent/button/black-btn.vue new file mode 100644 index 0000000..ca0eec5 --- /dev/null +++ b/src/commpent/button/black-btn.vue @@ -0,0 +1,15 @@ + + {{ title }} + + + + diff --git a/src/commpent/button/cancel-save-add.vue b/src/commpent/button/cancel-save-add.vue new file mode 100644 index 0000000..98774c6 --- /dev/null +++ b/src/commpent/button/cancel-save-add.vue @@ -0,0 +1,50 @@ + + + 取消 + 保存 + + 保存并继续添加 + + + + + diff --git a/src/commpent/button/primary-btn.vue b/src/commpent/button/primary-btn.vue new file mode 100644 index 0000000..3a27a29 --- /dev/null +++ b/src/commpent/button/primary-btn.vue @@ -0,0 +1,15 @@ + + {{ title }} + + + + diff --git a/src/commpent/page-header.vue b/src/commpent/page-header.vue new file mode 100644 index 0000000..678665d --- /dev/null +++ b/src/commpent/page-header.vue @@ -0,0 +1,41 @@ + + + + + + + + 返回 + + {{ title }} + + + + + + diff --git a/src/commpent/pagination.vue b/src/commpent/pagination.vue new file mode 100644 index 0000000..256ab8e --- /dev/null +++ b/src/commpent/pagination.vue @@ -0,0 +1,26 @@ + + + + diff --git a/src/commpent/table/table-footer.vue b/src/commpent/table/table-footer.vue new file mode 100644 index 0000000..3f206d0 --- /dev/null +++ b/src/commpent/table/table-footer.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/src/commpent/table/table-header.vue b/src/commpent/table/table-header.vue new file mode 100644 index 0000000..346ea21 --- /dev/null +++ b/src/commpent/table/table-header.vue @@ -0,0 +1,19 @@ + + + + + + + + + + + + + diff --git a/src/commpent/table/table-plus.vue b/src/commpent/table/table-plus.vue index fb8058f..c0d77c6 100644 --- a/src/commpent/table/table-plus.vue +++ b/src/commpent/table/table-plus.vue @@ -1,5 +1,5 @@ - + diff --git a/src/router/index.ts b/src/router/index.ts index 00fe454..e9da2bb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -40,6 +40,14 @@ const routes: Array = [ path: 'employee', name: 'employee', component: () => import(/* webpackChunkName: "employee" */ '@/views/employee/index.vue'), + children: [ + { + path: 'add', + name: 'employeeAdd', + component: () => import(/* webpackChunkName: "employeeAdd" */ '@/views/employee/add-employee.vue'), + meta: { title: '添加员工' }, + }, + ], }, ], }, diff --git a/src/store/employee.ts b/src/store/employee.ts index 41e746e..e4b9073 100644 --- a/src/store/employee.ts +++ b/src/store/employee.ts @@ -1,12 +1,14 @@ import { defineStore } from 'pinia'; -import { reqGetEmployeeById, reqGetEmployeePage, reqLogin } from '@/api/employee'; +import { reqAddEmployee, reqEditEmployee, reqGetEmployeeById, reqGetEmployeePage, reqLogin, reqStatus } from '@/api/employee'; import Cookies from 'js-cookie'; import router from '@/router'; import { ElMessage } from 'element-plus'; export const employeeStore = defineStore('employeeStore', { state: () => ({ - employeeList: [], + employeeList: { records: [], total: 0 }, + employeeDetail: {}, + requestData: { name: '', page: 1, pageSize: 10 }, }), getters: {}, actions: { @@ -29,6 +31,31 @@ export const employeeStore = defineStore('employeeStore', { ElMessage.error(e.message); } }, + /** + * 新增员工 + * @param data + */ + async addEmployee(data: any) { + try { + const response: any = await reqAddEmployee(data); + if (response.code !== 1) { + return Promise.reject(new Error(response.msg)); + } + } catch (e: any) { + ElMessage.error(e.message); + } + }, + /** + * 启用、禁用员工账号 + * @param data + */ + async changeStatus(data: any) { + try { + await reqStatus(data); + } catch (e: any) { + ElMessage.error(e.message); + } + }, /** * 员工分页查询 * @param data @@ -36,7 +63,7 @@ export const employeeStore = defineStore('employeeStore', { async getEmployeePage(data: any) { try { const response: any = await reqGetEmployeePage(data); - this.employeeList = response.data.records; + this.employeeList = response.data; } catch (e: any) { ElMessage.error(e.message); } @@ -47,8 +74,30 @@ export const employeeStore = defineStore('employeeStore', { * @param id */ async getEmployeeListById(id: number) { - const response = await reqGetEmployeeById(id); - this.employeeList = response.data; + try { + const response: any = await reqGetEmployeeById(id); + + if (response.code !== 1) { + return Promise.reject(new Error(response.msg)); + } + + this.employeeDetail = response.data; + } catch (e: any) { + ElMessage.error(e.message); + } + }, + async editEmployee(data: any) { + try { + const response: any = await reqEditEmployee(data); + + if (response.code !== 1) { + return Promise.reject(new Error(response.msg)); + } + + this.employeeDetail = response.data; + } catch (e: any) { + ElMessage.error(e.message); + } }, }, }); diff --git a/src/views/employee/add-employee.vue b/src/views/employee/add-employee.vue new file mode 100644 index 0000000..9024378 --- /dev/null +++ b/src/views/employee/add-employee.vue @@ -0,0 +1,167 @@ + + + + + + + + + + + + + + + + + + + 男 + 女 + + + + + + + + + + + + + + + diff --git a/src/views/employee/index.vue b/src/views/employee/index.vue index 2039e34..5fe3414 100644 --- a/src/views/employee/index.vue +++ b/src/views/employee/index.vue @@ -1,55 +1,132 @@ - - - 启用 - 禁用 - - + + + + + + 员工姓名: + + + + + + + + + + + 启用 + 禁用 + + + + 修改 + 启用 + 禁用 + + + 修改 + 禁用 + + + + + + + + diff --git a/vue.config.js b/vue.config.js index 2548ec6..ce9ac27 100644 --- a/vue.config.js +++ b/vue.config.js @@ -29,7 +29,7 @@ module.exports = defineConfig({ css: { loaderOptions: { scss: { - additionalData: `@use "~@/assets/css/index.scss" as *;`, + additionalData: `@use "~@/assets/css/index.scss" as *; @use "~@/assets/css/mixin/index.scss";`, }, }, },