From 535a5dd1b5cd53816bed2ad6b22dc4e1e6f40d7f Mon Sep 17 00:00:00 2001 From: Yovinchen Date: Fri, 19 Nov 2021 15:21:54 +0800 Subject: [PATCH] docs: update readme Signed-off-by: yovinchen --- README-zh.md | 9 + README.md | 9 + src/api/system/sysRole.js | 116 ++++++++++ src/api/system/sysUser.js | 49 ++++ src/api/user.js | 8 +- src/router/index.js | 33 ++- src/utils/request.js | 2 +- src/views/system/sysRole/list.vue | 230 +++++++++++++++++++ src/views/system/sysUser/list.vue | 370 ++++++++++++++++++++++++++++++ vue.config.js | 55 +++-- 10 files changed, 850 insertions(+), 31 deletions(-) create mode 100644 src/api/system/sysRole.js create mode 100644 src/api/system/sysUser.js create mode 100644 src/views/system/sysRole/list.vue create mode 100644 src/views/system/sysUser/list.vue diff --git a/README-zh.md b/README-zh.md index 5b6f7bd..1beec9b 100644 --- a/README-zh.md +++ b/README-zh.md @@ -8,6 +8,15 @@ 目前版本为 `v4.0+` 基于 `vue-cli` 进行构建,若你想使用旧版本,可以切换分支到[tag/3.11.0](https://github.com/PanJiaChen/vue-admin-template/tree/tag/3.11.0),它不依赖 `vue-cli`。 +

+ SPONSORED BY +

+

+ + + +

+ ## Extra 如果你想要根据用户角色来动态生成侧边栏和 router,你可以使用该分支[permission-control](https://github.com/PanJiaChen/vue-admin-template/tree/permission-control) diff --git a/README.md b/README.md index a2f3c71..fa54b78 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,15 @@ English | [简体中文](./README-zh.md) **The current version is `v4.0+` build on `vue-cli`. If you want to use the old version , you can switch branch to [tag/3.11.0](https://github.com/PanJiaChen/vue-admin-template/tree/tag/3.11.0), it does not rely on `vue-cli`** +

+ SPONSORED BY +

+

+ + + +

+ ## Build Setup ```bash diff --git a/src/api/system/sysRole.js b/src/api/system/sysRole.js new file mode 100644 index 0000000..194068c --- /dev/null +++ b/src/api/system/sysRole.js @@ -0,0 +1,116 @@ +/* +角色管理相关的API请求函数 +*/ +import request from '@/utils/request' + +const api_name = '/admin/system/sysRole' + +export default { + + /** + * 获取角色分页列表(带搜索) + * @param {*} page + * @param {*} limit + * @param {*} searchObj + * @returns + */ + getPageList(page, limit, searchObj) { + return request({ + url: `${api_name}/${page}/${limit}`, + method: 'get', + // 如果是普通对象参数写法,params:对象参数名 + // 如果是使用json格式传递,data:对象参数名 + params: searchObj + }) + }, + + /** + * 角色删除 + * @param {*} id + * @returns + */ + removeById(id) { + return request({ + url: `${api_name}/remove/${id}`, + method: 'delete' + }) + }, + + /** + * 角色添加 + * @param {*} role + * @returns + */ + save(role) { + return request({ + url: `${api_name}/save`, + method: 'post', + data: role + }) + }, + + /** + * 回显要修改的id信息 + * + * @param id + * @returns {*} + */ + getById(id) { + return request({ + url: `${api_name}/get/${id}`, + method: 'get' + }) + }, + + /** 修改 + * + * @param role + * @returns {*} + */ + updateById(role) { + return request({ + url: `${api_name}/update`, + method: 'put', + data: role + }) + }, + + /** + * 批量删除 + * + * @param idList + * @returns {*} + */ + batchRemove(idList) { + return request({ + url: `${api_name}/batchRemove`, + method: `delete`, + data: idList + }) + }, + /** + * 根据用户获取角色数据 + * + * @param adminId + * @returns {*} + */ + getRoles(adminId) { + return request({ + url: `${api_name}/toAssign/${adminId}`, + method: 'get' + }) + }, + /** + * 为用户分配角色 + * + * @param assginRoleVo + * @returns {*} + */ + assignRoles(assginRoleVo) { + return request({ + url: `${api_name}/doAssign`, + method: 'post', + data: assginRoleVo + }) + } +} diff --git a/src/api/system/sysUser.js b/src/api/system/sysUser.js new file mode 100644 index 0000000..6f8e9cf --- /dev/null +++ b/src/api/system/sysUser.js @@ -0,0 +1,49 @@ +import request from '@/utils/request' + +const api_name = '/admin/system/sysUser' + +export default { + + getPageList(page, limit, searchObj) { + return request({ + url: `${api_name}/${page}/${limit}`, + method: 'get', + params: searchObj // url查询字符串或表单键值对 + }) + }, + getById(id) { + return request({ + url: `${api_name}/get/${id}`, + method: 'get' + }) + }, + + save(role) { + return request({ + url: `${api_name}/save`, + method: 'post', + data: role + }) + }, + + updateById(role) { + return request({ + url: `${api_name}/update`, + method: 'put', + data: role + }) + }, + removeById(id) { + return request({ + url: `${api_name}/remove/${id}`, + method: 'delete' + }) + }, + + updateStatus(id, status) { + return request({ + url: `${api_name}/updateStatus/${id}/${status}`, + method: 'get' + }) + } +} diff --git a/src/api/user.js b/src/api/user.js index 8ff4389..cc79a94 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -2,7 +2,7 @@ import request from '@/utils/request' export function login(data) { return request({ - url: '/vue-admin-template/user/login', + url: '/admin/system/index/login', method: 'post', data }) @@ -10,15 +10,15 @@ export function login(data) { export function getInfo(token) { return request({ - url: '/vue-admin-template/user/info', + url: '/admin/system/index/info', method: 'get', - params: { token } + params: {token} }) } export function logout() { return request({ - url: '/vue-admin-template/user/logout', + url: '/admin/system/index/logout', method: 'post' }) } diff --git a/src/router/index.js b/src/router/index.js index 13459e9..773df0f 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,11 +1,10 @@ import Vue from 'vue' import Router from 'vue-router' - -Vue.use(Router) - /* Layout */ import Layout from '@/layout' +Vue.use(Router) + /** * Note: sub-menu only appear when route children.length >= 1 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html @@ -54,6 +53,34 @@ export const constantRoutes = [ meta: { title: 'Dashboard', icon: 'dashboard' } }] }, + { + path: '/system', + component: Layout, + meta: { + title: '系统管理', + icon: 'el-icon-s-tools' + }, + alwaysShow: true, + children: [ + { + name: 'sysUser', + path: 'sysUser', + component: () => import('@/views/system/sysUser/list'), + meta: { + title: '用户管理', + icon: 'el-icon-s-custom' + } + }, + { + path: 'sysRole', + component: () => import('@/views/system/sysRole/list'), + meta: { + title: '角色管理', + icon: 'el-icon-s-help' + } + } + ] + }, { path: '/example', diff --git a/src/utils/request.js b/src/utils/request.js index 2fb95ac..0976d23 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -46,7 +46,7 @@ service.interceptors.response.use( const res = response.data // if the custom code is not 20000, it is judged as an error. - if (res.code !== 20000) { + if (res.code !== 200) { Message({ message: res.message || 'Error', type: 'error', diff --git a/src/views/system/sysRole/list.vue b/src/views/system/sysRole/list.vue new file mode 100644 index 0000000..fb841de --- /dev/null +++ b/src/views/system/sysRole/list.vue @@ -0,0 +1,230 @@ + + + diff --git a/src/views/system/sysUser/list.vue b/src/views/system/sysUser/list.vue new file mode 100644 index 0000000..45da248 --- /dev/null +++ b/src/views/system/sysUser/list.vue @@ -0,0 +1,370 @@ + + + diff --git a/vue.config.js b/vue.config.js index 4856ed0..e36b2c9 100644 --- a/vue.config.js +++ b/vue.config.js @@ -36,7 +36,16 @@ module.exports = { warnings: false, errors: true }, - before: require('./mock/mock-server.js') + // before: require('./mock/mock-server.js') + proxy: { + '/dev-api': { // 匹配所有以 '/dev-api'开头的请求路径 + target: 'http://localhost:8800', + changeOrigin: true, // 支持跨域 + pathRewrite: { // 重写路径: 去掉路径中开头的'/dev-api' + '^/dev-api': '' + } + } + } }, configureWebpack: { // provide the app's title in webpack's name field, so that @@ -87,34 +96,34 @@ module.exports = { .plugin('ScriptExtHtmlWebpackPlugin') .after('html') .use('script-ext-html-webpack-plugin', [{ - // `runtime` must same as runtimeChunk name. default is `runtime` + // `runtime` must same as runtimeChunk name. default is `runtime` inline: /runtime\..*\.js$/ }]) .end() config .optimization.splitChunks({ - chunks: 'all', - cacheGroups: { - libs: { - name: 'chunk-libs', - test: /[\\/]node_modules[\\/]/, - priority: 10, - chunks: 'initial' // only package third parties that are initially dependent - }, - elementUI: { - name: 'chunk-elementUI', // split elementUI into a single package - priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app - test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm - }, - commons: { - name: 'chunk-commons', - test: resolve('src/components'), // can customize your rules - minChunks: 3, // minimum common number - priority: 5, - reuseExistingChunk: true - } + chunks: 'all', + cacheGroups: { + libs: { + name: 'chunk-libs', + test: /[\\/]node_modules[\\/]/, + priority: 10, + chunks: 'initial' // only package third parties that are initially dependent + }, + elementUI: { + name: 'chunk-elementUI', // split elementUI into a single package + priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app + test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm + }, + commons: { + name: 'chunk-commons', + test: resolve('src/components'), // can customize your rules + minChunks: 3, // minimum common number + priority: 5, + reuseExistingChunk: true } - }) + } + }) // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk config.optimization.runtimeChunk('single') }