docs: update readme

Signed-off-by: yovinchen <gzh298255@gmail.com>
This commit is contained in:
yovinchen 2023-06-10 23:56:33 +08:00
parent 6de594bebc
commit f68997e6ac
18 changed files with 682 additions and 282 deletions

View File

@ -65,5 +65,33 @@ export default {
method: 'put',
data: sysMenu
})
},
/**
* 查看某个角色的权限列表
*
* @param roleId
* @returns {AxiosPromise}
*/
toAssign(roleId) {
return request({
url: `${api_name}/toAssign/${roleId}`,
method: 'get'
})
},
/**
* 给某个角色授权
*
* @param assignMenuVo
* @returns {AxiosPromise}
*/
doAssign(assignMenuVo) {
return request({
url: `${api_name}/doAssign`,
method: 'post',
data: assignMenuVo
})
}
}

View File

@ -12,7 +12,7 @@ export function getInfo(token) {
return request({
url: '/admin/system/index/info',
method: 'get',
params: {token}
params: { token }
})
}

View File

@ -0,0 +1,3 @@
<template>
<router-view />
</template>

View File

@ -3,16 +3,16 @@
<logo v-if="showLogo" :collapse="isCollapse" />
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-menu
:default-active="activeMenu"
:collapse="isCollapse"
:active-text-color="variables.menuActiveText"
:background-color="variables.menuBg"
:collapse="isCollapse"
:collapse-transition="false"
:default-active="activeMenu"
:text-color="variables.menuText"
:unique-opened="false"
:active-text-color="variables.menuActiveText"
:collapse-transition="false"
mode="vertical"
>
<sidebar-item v-for="route in routes" :key="route.path" :item="route" :base-path="route.path" />
<sidebar-item v-for="route in routes" :key="route.path" :base-path="route.path" :item="route" />
</el-menu>
</el-scrollbar>
</div>
@ -31,7 +31,8 @@ export default {
'sidebar'
]),
routes() {
return this.$router.options.routes
// return this.$router.options.routes
return this.$router.options.routes.concat(global.antRouter)
},
activeMenu() {
const route = this.$route

View File

@ -1,19 +1,20 @@
import Vue from 'vue'
import 'normalize.css/normalize.css' // A modern alternative to CSS resets
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n
import '@/styles/index.scss' // global css
import App from './App'
import store from './store'
import router from './router'
import '@/icons' // icon
import '@/permission' // permission control
// 新增
import hasBtnPermission from '@/utils/btn-permission'
Vue.prototype.$hasBP = hasBtnPermission
/**
* If you don't want to use mock-server
@ -29,9 +30,9 @@ if (process.env.NODE_ENV === 'production') {
}
// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui按如下方式声明
// Vue.use(ElementUI)
Vue.use(ElementUI)
Vue.config.productionTip = false

View File

@ -1,25 +1,23 @@
import router from './router'
import store from './store'
import { getToken } from '@/utils/auth'
import { Message } from 'element-ui'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import { getToken } from '@/utils/auth' // get token from cookie
import getPageTitle from '@/utils/get-page-title'
import NProgress from 'nprogress' // 水平进度条提示: 在跳转路由时使用
import 'nprogress/nprogress.css' // 水平进度条样式
import getPageTitle from '@/utils/get-page-title' // 获取应用头部标题的函数
import Layout from '@/layout'
import ParentView from '@/components/ParentView'
const _import = require('./router/_import_' + process.env.NODE_ENV) // 获取组件的方法
NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/login'] // no redirect whitelist
router.beforeEach(async(to, from, next) => {
// start progress bar
NProgress.start()
// set page title
document.title = getPageTitle(to.meta.title)
// determine whether the user has logged in
const hasToken = getToken()
if (hasToken) {
if (to.path === '/login') {
// if is logged in, redirect to the home page
@ -32,11 +30,25 @@ router.beforeEach(async(to, from, next) => {
} else {
try {
// get user info
await store.dispatch('user/getInfo')
next()
await store.dispatch('user/getInfo')// 请求获取用户信息
if (store.getters.menus.length < 1) {
global.antRouter = []
next()
}
const menus = filterAsyncRouter(store.getters.menus)// 1.过滤路由
console.log(menus)
router.addRoutes(menus) // 2.动态添加路由
const lastRou = [{ path: '*', redirect: '/404', hidden: true }]
router.addRoutes(lastRou)
global.antRouter = menus // 3.将路由数据传递给全局变量,做侧边栏菜单渲染工作
next({
...to,
replace: true
})
// next()
} catch (error) {
// remove token and go to login page to re-login
console.log(error)
await store.dispatch('user/resetToken')
Message.error(error || 'Has Error')
next(`/login?redirect=${to.path}`)
@ -44,9 +56,7 @@ router.beforeEach(async(to, from, next) => {
}
}
}
} else {
/* has no token*/
} else { /* has no token*/
if (whiteList.indexOf(to.path) !== -1) {
// in the free login whitelist, go directly
next()
@ -58,7 +68,32 @@ router.beforeEach(async(to, from, next) => {
}
})
router.afterEach(() => {
// finish progress bar
router.afterEach(() => { // finish progress bar
NProgress.done()
})
}) // // 遍历后台传来的路由字符串,转换为组件对象
function filterAsyncRouter(asyncRouterMap) {
const accessedRouters = asyncRouterMap.filter(route => {
if (route.component) {
if (route.component === 'Layout') {
route.component = Layout
} else if (route.component === 'ParentView') {
route.component = ParentView
} else {
try {
route.component = _import(route.component)// 导入组件
} catch (error) {
debugger
console.log(error)
route.component = _import('dashboard/index')// 导入组件
}
}
}
if (route.children && route.children.length > 0) {
route.children = filterAsyncRouter(route.children)
} else {
delete route.children
}
return true
})
return accessedRouters
}

View File

@ -0,0 +1,2 @@
// 开发环境导入组件
module.exports = file => require('@/views/' + file + '.vue').default // vue-loader at least v13.0.0+

View File

@ -0,0 +1,2 @@
// 生产环境导入组件
module.exports = file => () => import('@/views/' + file + '.vue')

View File

@ -35,13 +35,6 @@ export const constantRoutes = [
component: () => import('@/views/login/index'),
hidden: true
},
{
path: '/404',
component: () => import('@/views/404'),
hidden: true
},
{
path: '/',
component: Layout,
@ -52,152 +45,7 @@ export const constantRoutes = [
component: () => import('@/views/dashboard/index'),
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'
}
},
{
name: 'sysMenu',
path: 'sysMenu',
component: () => import('@/views/system/sysMenu/list'),
meta: {
title: '菜单管理',
icon: 'el-icon-s-unfold'
}
}
]
},
{
path: '/example',
component: Layout,
redirect: '/example/table',
name: 'Example',
meta: { title: 'Example', icon: 'el-icon-s-help' },
children: [
{
path: 'table',
name: 'Table',
component: () => import('@/views/table/index'),
meta: { title: 'Table', icon: 'table' }
},
{
path: 'tree',
name: 'Tree',
component: () => import('@/views/tree/index'),
meta: { title: 'Tree', icon: 'tree' }
}
]
},
{
path: '/form',
component: Layout,
children: [
{
path: 'index',
name: 'Form',
component: () => import('@/views/form/index'),
meta: { title: 'Form', icon: 'form' }
}
]
},
{
path: '/nested',
component: Layout,
redirect: '/nested/menu1',
name: 'Nested',
meta: {
title: 'Nested',
icon: 'nested'
},
children: [
{
path: 'menu1',
component: () => import('@/views/nested/menu1/index'), // Parent router-view
name: 'Menu1',
meta: { title: 'Menu1' },
children: [
{
path: 'menu1-1',
component: () => import('@/views/nested/menu1/menu1-1'),
name: 'Menu1-1',
meta: { title: 'Menu1-1' }
},
{
path: 'menu1-2',
component: () => import('@/views/nested/menu1/menu1-2'),
name: 'Menu1-2',
meta: { title: 'Menu1-2' },
children: [
{
path: 'menu1-2-1',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
name: 'Menu1-2-1',
meta: { title: 'Menu1-2-1' }
},
{
path: 'menu1-2-2',
component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
name: 'Menu1-2-2',
meta: { title: 'Menu1-2-2' }
}
]
},
{
path: 'menu1-3',
component: () => import('@/views/nested/menu1/menu1-3'),
name: 'Menu1-3',
meta: { title: 'Menu1-3' }
}
]
},
{
path: 'menu2',
component: () => import('@/views/nested/menu2/index'),
name: 'Menu2',
meta: { title: 'menu2' }
}
]
},
{
path: 'external-link',
component: Layout,
children: [
{
path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
meta: { title: 'External Link', icon: 'link' }
}
]
},
// 404 page must be placed at the end !!!
{ path: '*', redirect: '/404', hidden: true }
}
]
const createRouter = () => new Router({

View File

@ -3,6 +3,9 @@ const getters = {
device: state => state.app.device,
token: state => state.user.token,
avatar: state => state.user.avatar,
name: state => state.user.name
name: state => state.user.name,
// 新增
buttons: state => state.user.buttons,
menus: state => state.user.menus
}
export default getters

View File

@ -1,12 +1,15 @@
import { login, logout, getInfo } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { getInfo, login, logout } from '@/api/user'
import { getToken, removeToken, setToken } from '@/utils/auth'
import { resetRouter } from '@/router'
const getDefaultState = () => {
return {
token: getToken(),
name: '',
avatar: ''
avatar: '',
buttons: [], // 新增
menus: '' // 新增
}
}
@ -24,6 +27,14 @@ const mutations = {
},
SET_AVATAR: (state, avatar) => {
state.avatar = avatar
},
// 新增
SET_BUTTONS: (state, buttons) => {
state.buttons = buttons
},
// 新增
SET_MENUS: (state, menus) => {
state.menus = menus
}
}
@ -46,7 +57,7 @@ const actions = {
// get user info
getInfo({ commit, state }) {
return new Promise((resolve, reject) => {
getInfo(state.token).then(response => {
getInfo().then(response => {
const { data } = response
if (!data) {
@ -57,6 +68,9 @@ const actions = {
commit('SET_NAME', name)
commit('SET_AVATAR', avatar)
commit('SET_BUTTONS', data.buttons)
commit('SET_MENUS', data.routers)
resolve(data)
}).catch(error => {
reject(error)

View File

@ -0,0 +1,12 @@
import store from '@/store'
/**
* 判断当前用户是否有此按钮权限
* 按钮权限字符串 permission
*/
export default function hasBtnPermission(permission) {
// 得到当前用户的所有按钮权限
const myBtns = store.getters.buttons
// 如果指定的功能权限在myBtns中, 返回true ==> 这个按钮就会显示, 否则隐藏
return myBtns.indexOf(permission) !== -1
}

View File

@ -19,7 +19,7 @@ service.interceptors.request.use(
// let each request carry token
// ['X-Token'] is a custom headers key
// please modify it according to the actual situation
config.headers['X-Token'] = getToken()
config.headers['token'] = getToken()
}
return config
},

View File

@ -1,6 +1,13 @@
<template>
<div class="login-container">
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
<el-form
ref="loginForm"
:model="loginForm"
:rules="loginRules"
auto-complete="on"
class="login-form"
label-position="left"
>
<div class="title-container">
<h3 class="title">Login Form</h3>
@ -13,11 +20,11 @@
<el-input
ref="username"
v-model="loginForm.username"
placeholder="Username"
name="username"
type="text"
tabindex="1"
auto-complete="on"
name="username"
placeholder="Username"
tabindex="1"
type="text"
/>
</el-form-item>
@ -30,10 +37,10 @@
ref="password"
v-model="loginForm.password"
:type="passwordType"
placeholder="Password"
name="password"
tabindex="2"
auto-complete="on"
name="password"
placeholder="Password"
tabindex="2"
@keyup.enter.native="handleLogin"
/>
<span class="show-pwd" @click="showPwd">
@ -41,7 +48,13 @@
</span>
</el-form-item>
<el-button :loading="loading" type="primary" style="width:100%;margin-bottom:30px;" @click.native.prevent="handleLogin">Login</el-button>
<el-button
:loading="loading"
style="width:100%;margin-bottom:30px;"
type="primary"
@click.native.prevent="handleLogin"
>Login
</el-button>
<div class="tips">
<span style="margin-right:20px;">username: admin</span>
@ -53,13 +66,12 @@
</template>
<script>
import { validUsername } from '@/utils/validate'
export default {
name: 'Login',
data() {
const validateUsername = (rule, value, callback) => {
if (!validUsername(value)) {
if (value.length < 4) {
callback(new Error('Please enter the correct user name'))
} else {
callback()
@ -129,8 +141,8 @@ export default {
/* 修复input 背景不协调 和光标变色 */
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
$bg:#283443;
$light_gray:#fff;
$bg: #283443;
$light_gray: #fff;
$cursor: #fff;
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
@ -173,9 +185,9 @@ $cursor: #fff;
</style>
<style lang="scss" scoped>
$bg:#2d3a4b;
$dark_gray:#889aa4;
$light_gray:#eee;
$bg: #2d3a4b;
$dark_gray: #889aa4;
$light_gray: #eee;
.login-container {
min-height: 100%;

View File

@ -0,0 +1,332 @@
<template>
<div class="app-container">
<!-- 工具条 -->
<div class="tools-div">
<el-button icon="el-icon-plus" size="mini" type="success" @click="add()"> </el-button>
</div>
<el-table
:data="sysMenuList"
:default-expand-all="false"
:tree-props="{children: 'children'}"
border
row-key="id"
style="width: 100%;margin-bottom: 20px;margin-top: 10px;"
>
<el-table-column label="菜单名称" prop="name" width="160" />
<el-table-column label="图标">
<template slot-scope="scope">
<i :class="scope.row.icon" />
</template>
</el-table-column>
<el-table-column label="权限标识" prop="perms" width="160" />
<el-table-column label="路由地址" prop="path" width="120" />
<el-table-column label="组件路径" prop="component" width="160" />
<el-table-column label="排序" prop="sortValue" width="60" />
<el-table-column label="状态" width="80">
<template slot-scope="scope">
<el-switch
v-model="scope.row.status === 1"
disabled="true"
/>
</template>
</el-table-column>
<el-table-column label="创建时间" prop="createTime" width="160" />
<el-table-column align="center" fixed="right" label="操作" width="180">
<template slot-scope="scope">
<el-button
v-if="scope.row.type !== 2"
icon="el-icon-plus"
size="mini"
title="添加下级节点"
type="success"
@click="add(scope.row)"
/>
<el-button icon="el-icon-edit" size="mini" title="修改" type="primary" @click="edit(scope.row)" />
<el-button
:disabled="scope.row.children.length > 0"
icon="el-icon-delete"
size="mini"
title="删除"
type="danger"
@click="removeDataById(scope.row.id)"
/>
</template>
</el-table-column>
</el-table>
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="40%">
<el-form ref="dataForm" :model="sysMenu" label-width="150px" size="small" style="padding-right: 40px;">
<el-form-item v-if="sysMenu.id === ''" label="上级部门">
<el-input v-model="sysMenu.parentName" disabled="true" />
</el-form-item>
<el-form-item label="菜单类型" prop="type">
<el-radio-group v-model="sysMenu.type" :disabled="typeDisabled">
<el-radio :disabled="type0Disabled" :label="0">目录</el-radio>
<el-radio :disabled="type1Disabled" :label="1">菜单</el-radio>
<el-radio :disabled="type2Disabled" :label="2">按钮</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="菜单名称" prop="name">
<el-input v-model="sysMenu.name" />
</el-form-item>
<el-form-item v-if="sysMenu.type !== 2" label="图标" prop="icon">
<el-select v-model="sysMenu.icon" clearable>
<el-option v-for="item in iconList" :key="item.class" :label="item.class" :value="item.class">
<span style="float: left;">
<i :class="item.class" /> <!-- 如果动态显示图标这里添加判断 -->
</span>
<span style="padding-left: 6px;">{{ item.class }}</span>
</el-option>
</el-select>
</el-form-item>
<el-form-item label="排序">
<el-input-number v-model="sysMenu.sortValue" :min="0" controls-position="right" />
</el-form-item>
<el-form-item prop="path">
<span slot="label">
<el-tooltip content="访问的路由地址,如:`sysUser`" placement="top">
<i class="el-icon-question" />
</el-tooltip>
路由地址
</span>
<el-input v-model="sysMenu.path" placeholder="请输入路由地址" />
</el-form-item>
<el-form-item v-if="sysMenu.type !== 0" prop="component">
<span slot="label">
<el-tooltip content="访问的组件路径,如:`system/user/index`,默认在`views`目录下" placement="top">
<i class="el-icon-question" />
</el-tooltip>
组件路径
</span>
<el-input v-model="sysMenu.component" placeholder="请输入组件路径" />
</el-form-item>
<el-form-item v-if="sysMenu.type === 2">
<el-input v-model="sysMenu.perms" maxlength="100" placeholder="请输入权限标识" />
<span slot="label">
<el-tooltip
content="控制器中定义的权限字符,如:@PreAuthorize(hasAuthority('bnt.sysRole.list'))"
placement="top"
>
<i class="el-icon-question" />
</el-tooltip>
权限字符
</span>
</el-form-item>
<el-form-item label="状态" prop="type">
<el-radio-group v-model="sysMenu.status">
<el-radio :label="1">正常</el-radio>
<el-radio :label="0">停用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button icon="el-icon-refresh-right" size="small" @click="dialogVisible = false"> </el-button>
<el-button icon="el-icon-check" size="small" type="primary" @click="saveOrUpdate()"> </el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import api from '@/api/system/sysMenu'
const defaultForm = {
id: '',
parentId: '',
name: '',
type: 0,
path: '',
component: '',
perms: '',
icon: '',
sortValue: 1,
status: 1
}
export default {
//
data() {
return {
sysMenuList: [],
expandKeys: [], //
typeDisabled: false,
type0Disabled: false,
type1Disabled: false,
type2Disabled: false,
dialogTitle: '',
dialogVisible: false,
sysMenu: defaultForm,
saveBtnDisabled: false,
iconList: [
{
class: 'el-icon-s-tools'
},
{
class: 'el-icon-s-custom'
},
{
class: 'el-icon-setting'
},
{
class: 'el-icon-user-solid'
},
{
class: 'el-icon-s-help'
},
{
class: 'el-icon-phone'
},
{
class: 'el-icon-s-unfold'
},
{
class: 'el-icon-s-operation'
},
{
class: 'el-icon-more-outline'
},
{
class: 'el-icon-s-check'
},
{
class: 'el-icon-tickets'
},
{
class: 'el-icon-s-goods'
},
{
class: 'el-icon-document-remove'
},
{
class: 'el-icon-warning'
},
{
class: 'el-icon-warning-outline'
},
{
class: 'el-icon-question'
},
{
class: 'el-icon-info'
}
]
}
},
//
created() {
this.fetchData()
},
methods: {
// api
fetchData() {
console.log('加载列表')
api.findNodes().then(response => {
this.sysMenuList = response.data
console.log(this.sysMenuList)
})
},
// id
removeDataById(id) {
// debugger
this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => { // promise
// ajax
return api.removeById(id)
}).then((response) => {
this.fetchData()
this.$message({
type: 'success',
message: '删除成功!'
})
}).catch(() => {
this.$message.info('取消删除')
})
},
// -------------
add(row) {
debugger
this.typeDisabled = false
this.dialogTitle = '添加下级节点'
this.dialogVisible = true
this.sysMenu = Object.assign({}, defaultForm)
this.sysMenu.id = ''
if (row) {
this.sysMenu.parentId = row.id
this.sysMenu.parentName = row.name
// this.sysMenu.component = 'ParentView'
if (row.type === 0) {
this.sysMenu.type = 1
this.typeDisabled = false
this.type0Disabled = false
this.type1Disabled = false
this.type2Disabled = true
} else if (row.type === 1) {
this.sysMenu.type = 2
this.typeDisabled = true
}
} else {
this.dialogTitle = '添加目录节点'
this.sysMenu.type = 0
this.sysMenu.component = 'Layout'
this.sysMenu.parentId = 0
this.typeDisabled = true
}
},
edit(row) {
debugger
this.dialogTitle = '修改节点'
this.dialogVisible = true
this.sysMenu = Object.assign({}, row)
this.typeDisabled = true
},
saveOrUpdate() {
if (this.sysMenu.type === 0 && this.sysMenu.parentId !== 0) {
this.sysMenu.component = 'ParentView'
}
this.$refs.dataForm.validate(valid => {
if (valid) {
this.saveBtnDisabled = true //
if (!this.sysMenu.id) {
this.saveData()
} else {
this.updateData()
}
}
})
},
//
saveData() {
api.save(this.sysMenu).then(response => {
this.$message.success(response.message || '操作成功')
this.dialogVisible = false
this.fetchData(this.page)
})
},
// id
updateData() {
api.updateById(this.sysMenu).then(response => {
this.$message.success(response.message || '操作成功')
this.dialogVisible = false
this.fetchData()
})
}
}
}
</script>

View File

@ -0,0 +1,94 @@
<template>
<div class="app-container">
<div style="padding: 20px 20px 0 20px;">
授权角色{{ $route.query.roleName }}
</div>
<el-tree
ref="tree"
:data="sysMenuList"
:props="defaultProps"
default-expand-all
node-key="id"
show-checkbox
style="margin: 20px 0"
/>
<div style="padding: 20px 20px;">
<el-button :loading="loading" icon="el-icon-check" size="mini" type="primary" @click="save">保存</el-button>
<el-button icon="el-icon-refresh-right" size="mini" @click="$router.push('/system/sysRole')">返回</el-button>
</div>
</div>
</template>
<script>
import api from '@/api/system/sysMenu'
export default {
name: 'RoleAuth',
data() {
return {
loading: false, // ,
sysMenuList: [], //
defaultProps: {
children: 'children',
label: 'name'
}
}
},
created() {
this.fetchData()
},
methods: {
/*
初始化
*/
fetchData() {
const roleId = this.$route.query.id
api.toAssign(roleId).then(result => {
const sysMenuList = result.data
this.sysMenuList = sysMenuList
const checkedIds = this.getCheckedIds(sysMenuList)
console.log('getPermissions() checkedIds', checkedIds)
this.$refs.tree.setCheckedKeys(checkedIds)
})
},
/*
得到所有选中的id列表
*/
getCheckedIds(auths, initArr = []) {
return auths.reduce((pre, item) => {
if (item.select && item.children.length === 0) {
pre.push(item.id)
} else if (item.children) {
this.getCheckedIds(item.children, initArr)
}
return pre
}, initArr)
},
/*
保存权限列表
*/
save() {
//
// const checkedNodes = this.$refs.tree.getCheckedNodes()
//
const allCheckedNodes = this.$refs.tree.getCheckedNodes(false, true)
const idList = allCheckedNodes.map(node => node.id)
console.log(idList)
const assginMenuVo = {
roleId: this.$route.query.id,
menuIdList: idList
}
this.loading = true
api.doAssign(assginMenuVo).then(result => {
this.loading = false
this.$message.success(result.$message || '分配权限成功')
this.$router.push('/system/sysRole')
})
}
}
}
</script>

View File

@ -1,6 +1,5 @@
<template>
<div class="app-container">
<!--查询表单-->
<div class="search-div">
<el-form label-width="70px" size="small">
@ -16,14 +15,20 @@
</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
<!-- 工具条 -->
<!-- <div class="tools-div" style="padding-left: 15px">-->
<el-button icon="el-icon-plus" size="mini" type="success" @click="add"> </el-button>
<!-- <div class="tools-div">-->
<el-button
:disabled="$hasBP('bnt.sysRole.add') === false"
icon="el-icon-plus"
size="mini"
type="success"
@click="add"
>
</el-button>
<el-button class="btn-add" size="mini" @click="batchRemove()">批量删除</el-button>
<!-- </div>-->
</el-row>
</el-form>
</div>
<!-- 表格 -->
<el-table
v-loading="listLoading"
@ -59,10 +64,17 @@
type="danger"
@click="removeDataById(scope.row.id)"
/>
<el-button
icon="el-icon-baseball"
size="mini"
title="分配权限"
type="warning"
@click="showAssignAuth(scope.row)"
/>
</template>
</el-table-column>
</el-table>
<!-- 分页组件 -->
<el-pagination
:current-page="page"
@ -92,38 +104,42 @@
</template>
<script>
// js
import api from '@/api/system/sysRole'
export default {
//
// vue
//
data() {
return {
list: [], //
list: [], //
page: 1, //
limit: 10, //
total: 0, //
page: 1, //
limit: 10, //
searchObj: {}, //
multipleSelection: [], //
dialogVisible: false, //
sysRole: {}, //
saveBtnDisabled: false
searchObj: {}, //
selections: [], //
sysRole: {}, //
dialogVisible: false//
}
},
//
created() {
created() { //
this.fetchData()
},
//
methods: {
//
methods: { //
//
showAssignAuth(row) {
this.$router.push('/system/assignAuth?id=' + row.id + '&roleName=' + row.roleName)
},
//
handleSelectionChange(selection) {
console.log(selection)
this.multipleSelection = selection
this.selections = selection
console.log(this.selections)
},
//
batchRemove() {
if (this.multipleSelection.length === 0) {
//
if (this.selections.length === 0) {
this.$message.warning('请选择要删除的记录!')
return
}
@ -132,20 +148,19 @@ export default {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
// ajax
// selectionidid
// [1,2,3]
var idList = []
this.multipleSelection.forEach(item => {
idList.push(item.id)
// this.selections
this.selections.forEach(item => {
var id = item.id
idList.push(id)
})
// api
return api.batchRemove(idList)
}).then((response) => {
this.fetchData()
}).then(response => {
this.$message.success(response.message)
this.fetchData()
})
},
// id
edit(id) {
//
@ -153,74 +168,69 @@ export default {
// id
this.fetchDataById(id)
},
// id
fetchDataById(id) {
api.getById(id).then(response => {
this.sysRole = response.data
})
api.getById(id)
.then(response => {
this.sysRole = response.data
})
},
//
//
add() {
this.dialogVisible = true
},
//
saveOrUpdate() {
this.saveBtnDisabled = true //
// id
if (!this.sysRole.id) { //
this.saveData()
this.save()
} else { //
this.updateData()
this.update()
}
},
//
saveData() {
api.save(this.sysRole).then(response => {
//
this.$message.success(response.message || '操作成功')
//
this.dialogVisible = false
//
this.fetchData(this.page)
})
save() { //
api.saveRole(this.sysRole)
.then(response => {
//
this.$message.success(response.message || '操作成功')
//
this.dialogVisible = false
//
this.fetchData()
})
},
//
updateData() {
api.updateById(this.sysRole).then(response => {
//
this.$message.success(response.message || '操作成功')
//
this.dialogVisible = false
//
this.fetchData(this.page)
})
update() { //
api.updateById(this.sysRole)
.then(response => {
//
this.$message.success(response.message || '操作成功')
//
this.dialogVisible = false
//
this.fetchData()
})
},
//
fetchData(current = 1) {
this.page = current
// api
api.getPageList(this.page, this.limit, this.searchObj).then(response => {
this.list = response.data.records
this.total = response.data.total
})
api.getPageList(this.page, this.limit, this.searchObj)
.then(response => {
this.list = response.data.records
this.total = response.data.total
})
},
// id
//
removeDataById(id) {
// debugger
this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => { // promise
// ajax
}).then(() => {
//
return api.removeById(id)
}).then((response) => {
}).then(response => {
//
this.fetchData(this.page)
this.fetchData()
//
this.$message.success(response.message || '删除成功')
})

View File

@ -66,7 +66,10 @@
</el-table-column>
<el-table-column label="状态" width="80">
<template slot-scope="scope">
<el-switch v-model="scope.row.status === 1" @change="switchStatus(scope.row)" />
<el-switch
v-model="scope.row.status === 1"
@change="switchStatus(scope.row)"
/>
</template>
</el-table-column>
<el-table-column label="创建时间" prop="createTime" width="160" />