Commit 657c985b authored by 朱招明's avatar 朱招明

update

parent 1b71189f
...@@ -25,6 +25,15 @@ export function menuEdit(id, parameter) { ...@@ -25,6 +25,15 @@ export function menuEdit(id, parameter) {
}) })
} }
export function saveChange(parameter) {
return request({
url: '/menu/save_change',
method: 'put',
data: parameter
})
}
export function menuDetail(id) { export function menuDetail(id) {
return request({ return request({
url: '/menu/' + id + '/detail', url: '/menu/' + id + '/detail',
......
...@@ -8,6 +8,8 @@ const getters = { ...@@ -8,6 +8,8 @@ const getters = {
token: state => state.user.token, token: state => state.user.token,
avatar: state => state.user.avatar, avatar: state => state.user.avatar,
name: state => state.user.name, name: state => state.user.name,
menus: state => state.user.menus,
is_admin: state => state.user.is_admin,
announcements: state => state.user.announcements, announcements: state => state.user.announcements,
addRouters: state => state.permission.addRouters, addRouters: state => state.permission.addRouters,
multiTab: state => state.app.multiTab, multiTab: state => state.app.multiTab,
......
...@@ -8,8 +8,9 @@ const getDefaultState = () => { ...@@ -8,8 +8,9 @@ const getDefaultState = () => {
name: '', name: '',
avatar: '', avatar: '',
user_info: null, user_info: null,
announcements: null announcements: null,
menus: null,
is_admin: false
} }
} }
...@@ -33,6 +34,12 @@ const mutations = { ...@@ -33,6 +34,12 @@ const mutations = {
}, },
SET_ANNOUNCEMENTS: (state, announcements) => { SET_ANNOUNCEMENTS: (state, announcements) => {
state.announcements = announcements state.announcements = announcements
},
SET_MENUS: (state, menus) => {
state.menus = menus
},
SET_IS_ADMIN: (state, is_admin) => {
state.is_admin = is_admin
} }
} }
...@@ -82,12 +89,14 @@ const actions = { ...@@ -82,12 +89,14 @@ const actions = {
return reject('获取配置失败,请重新登录') return reject('获取配置失败,请重新登录')
} }
const { user_info, announcements } = data const { user_info, announcements, menus, is_admin } = data
commit('SET_USER_INFO', user_info) commit('SET_USER_INFO', user_info)
commit('SET_NAME', user_info.name) commit('SET_NAME', user_info.name)
commit('SET_AVATAR', user_info.avatar_full_url) commit('SET_AVATAR', user_info.avatar_full_url)
commit('SET_MENUS', menus)
commit('SET_ANNOUNCEMENTS', announcements) commit('SET_ANNOUNCEMENTS', announcements)
commit('SET_IS_ADMIN', is_admin)
resolve(data) resolve(data)
}).catch(error => { }).catch(error => {
......
...@@ -2,6 +2,7 @@ import axios from 'axios' ...@@ -2,6 +2,7 @@ import axios from 'axios'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import store from '@/store' import store from '@/store'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import router from '@/router'
// create an axios instance // create an axios instance
const service = axios.create({ const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
...@@ -62,11 +63,13 @@ service.interceptors.response.use( ...@@ -62,11 +63,13 @@ service.interceptors.response.use(
Message.error('无权操作') Message.error('无权操作')
break break
case 401: case 401:
Message.error('请先登录')
if (token) { if (token) {
Message.error('登录已过期') Message.error('登录已过期')
store.dispatch('user/resetToken') store.dispatch('user/resetToken')
} else {
Message.error('请先登录')
} }
router.push('/login')
break break
default: default:
Message({ Message({
......
import { Message } from 'element-ui'
import store from '../store'
export function listToTree(list, tree, parentId) { export function listToTree(list, tree, parentId) {
list.forEach(item => { list.forEach(item => {
// 判断是否为父级菜单 // 判断是否为父级菜单
...@@ -33,3 +36,23 @@ export function deepClone(source) { ...@@ -33,3 +36,23 @@ export function deepClone(source) {
}) })
return targetObj return targetObj
} }
export function getRoleAction(menus, action, router) {
const parentMatchedRoute = router.matched[router.matched.length - 2]
const parent_name = parentMatchedRoute.name
const role_action = []
action.forEach((action) => {
if (menus.find(item => item.key === parent_name + '.' + action)) {
role_action.push(action)
}
})
return role_action
}
export function checkRoleAction(action, role_action) {
if (!store.getters.is_admin && !role_action.includes(action)) {
Message.error('无权操作')
return false
}
return true
}
...@@ -55,6 +55,8 @@ ...@@ -55,6 +55,8 @@
<script> <script>
// import { validUsername } from '@/utils/validate' // import { validUsername } from '@/utils/validate'
import { Message } from 'element-ui'
export default { export default {
name: 'Login', name: 'Login',
data() { data() {
...@@ -102,7 +104,7 @@ export default { ...@@ -102,7 +104,7 @@ export default {
if (valid) { if (valid) {
this.loading = true this.loading = true
this.$store.dispatch('user/login', this.loginForm).then((res) => { this.$store.dispatch('user/login', this.loginForm).then((res) => {
console.log(res) Message.success('登录成功')
this.$router.push({ path: this.redirect || '/' }) this.$router.push({ path: this.redirect || '/' })
this.loading = false this.loading = false
}).catch((error) => { }).catch((error) => {
......
...@@ -54,9 +54,10 @@ ...@@ -54,9 +54,10 @@
<script> <script>
import { announcementAdd, announcementDel, announcementEdit, announcementList, announcementChange } from '@/api/system/announcement' import { announcementAdd, announcementDel, announcementEdit, announcementList, announcementChange } from '@/api/system/announcement'
import { deepClone } from '@/utils/util' import { checkRoleAction, deepClone, getRoleAction } from '@/utils/util'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
export default { export default {
components: { Pagination }, components: { Pagination },
...@@ -87,7 +88,13 @@ export default { ...@@ -87,7 +88,13 @@ export default {
} }
}, },
computed: { computed: {
...mapGetters([
'menus'
]),
role_action() {
const action = ['add', 'edit', 'del', 'change']
return getRoleAction(this.menus, action, this.$route)
}
}, },
created() { created() {
this.getAnnouncements() this.getAnnouncements()
...@@ -105,16 +112,22 @@ export default { ...@@ -105,16 +112,22 @@ export default {
}, },
handleAdd() { handleAdd() {
if (!checkRoleAction('add', this.role_action)) return
this.form = Object.assign({}) this.form = Object.assign({})
this.dialogType = 'new' this.dialogType = 'new'
this.dialogVisible = true this.dialogVisible = true
}, },
handleEdit(scope) { handleEdit(scope) {
if (!checkRoleAction('edit', this.role_action)) return
this.dialogType = 'edit' this.dialogType = 'edit'
this.dialogVisible = true this.dialogVisible = true
this.form = deepClone(scope.row) this.form = deepClone(scope.row)
}, },
handleDelete({ $index, row }) { handleDelete({ $index, row }) {
if (!checkRoleAction('del', this.role_action)) return
this.$confirm('确定要删除嘛?', '删除', { this.$confirm('确定要删除嘛?', '删除', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
...@@ -155,6 +168,8 @@ export default { ...@@ -155,6 +168,8 @@ export default {
this.dialogVisible = false this.dialogVisible = false
}, },
handleChange(scope, type) { handleChange(scope, type) {
if (!checkRoleAction('change', this.role_action)) return
const { $index, row } = scope const { $index, row } = scope
this.listLoading = true this.listLoading = true
announcementChange(row.id, { type: type }) announcementChange(row.id, { type: type })
......
...@@ -52,9 +52,10 @@ ...@@ -52,9 +52,10 @@
<script> <script>
import { departmentAdd, departmentDel, departmentEdit, departmentList } from '@/api/system/company/department' import { departmentAdd, departmentDel, departmentEdit, departmentList } from '@/api/system/company/department'
import { deepClone } from '@/utils/util' import { checkRoleAction, deepClone, getRoleAction } from '@/utils/util'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
export default { export default {
components: { Pagination }, components: { Pagination },
...@@ -84,7 +85,13 @@ export default { ...@@ -84,7 +85,13 @@ export default {
} }
}, },
computed: { computed: {
...mapGetters([
'menus'
]),
role_action() {
const action = ['add', 'edit', 'del']
return getRoleAction(this.menus, action, this.$route)
}
}, },
created() { created() {
this.getDepartments() this.getDepartments()
...@@ -102,16 +109,22 @@ export default { ...@@ -102,16 +109,22 @@ export default {
}, },
handleAdd() { handleAdd() {
if (!checkRoleAction('add', this.role_action)) return
this.form = Object.assign({}) this.form = Object.assign({})
this.dialogType = 'new' this.dialogType = 'new'
this.dialogVisible = true this.dialogVisible = true
}, },
handleEdit(scope) { handleEdit(scope) {
if (!checkRoleAction('edit', this.role_action)) return
this.dialogType = 'edit' this.dialogType = 'edit'
this.dialogVisible = true this.dialogVisible = true
this.form = deepClone(scope.row) this.form = deepClone(scope.row)
}, },
handleDelete({ $index, row }) { handleDelete({ $index, row }) {
if (!checkRoleAction('del', this.role_action)) return
this.$confirm('确定要删除嘛?', '删除', { this.$confirm('确定要删除嘛?', '删除', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
<el-input v-model="form.username" placeholder="登录账号" /> <el-input v-model="form.username" placeholder="登录账号" />
</el-form-item> </el-form-item>
<el-form-item label="登录密码" prop="password"> <el-form-item label="登录密码" prop="password">
<el-input v-model="form.password" placeholder="不填默认123456" /> <el-input v-model="form.password" placeholder="为空不修改" />
</el-form-item> </el-form-item>
<el-form-item label="头像" prop="avatar"> <el-form-item label="头像" prop="avatar">
<el-upload <el-upload
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<i v-else class="el-icon-plus avatar-uploader-icon" /> <i v-else class="el-icon-plus avatar-uploader-icon" />
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="角色" prop="role_id"> <el-form-item v-if="!form.is_admin" label="角色" prop="role_id">
<el-select v-model="form.role_id" placeholder="请选择"> <el-select v-model="form.role_id" placeholder="请选择">
<el-option <el-option
v-for="item in roleData" v-for="item in roleData"
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</el-form-item> </el-form-item>
</el-tab-pane> </el-tab-pane>
<el-tab-pane label="员工信息" name="staff"> <el-tab-pane v-if="!form.is_admin" label="员工信息" name="staff">
<el-form-item label="姓名" prop="name"> <el-form-item label="姓名" prop="name">
<el-input v-model="form.name" placeholder="姓名" /> <el-input v-model="form.name" placeholder="姓名" />
</el-form-item> </el-form-item>
......
...@@ -99,6 +99,8 @@ import { userAdd, userDel, userEdit, userList, uploadFile } from '@/api/system/c ...@@ -99,6 +99,8 @@ import { userAdd, userDel, userEdit, userList, uploadFile } from '@/api/system/c
import { Message } from 'element-ui' import { Message } from 'element-ui'
import { roleList } from '@/api/system/power/role' import { roleList } from '@/api/system/power/role'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
import { checkRoleAction, getRoleAction } from '@/utils/util'
export default { export default {
components: { Pagination }, components: { Pagination },
...@@ -135,8 +137,12 @@ export default { ...@@ -135,8 +137,12 @@ export default {
} }
}, },
computed: { computed: {
domain() { ...mapGetters([
return this.$store.state.app.domain 'menus'
]),
role_action() {
const action = ['add', 'edit', 'del']
return getRoleAction(this.menus, action, this.$route)
} }
}, },
created() { created() {
...@@ -159,36 +165,22 @@ export default { ...@@ -159,36 +165,22 @@ export default {
}, },
handleAddRole() { handleAddRole() {
// this.user = Object.assign({}) if (!checkRoleAction('add', this.role_action)) return
// this.dialogType = 'new'
// this.dialogVisible = true
const parentMatchedRoute = this.$route.matched[this.$route.matched.length - 2] const parentMatchedRoute = this.$route.matched[this.$route.matched.length - 2]
const parent_name = parentMatchedRoute.name const parent_name = parentMatchedRoute.name
this.$router.push({ name: parent_name + '.add' }) this.$router.push({ path: parentMatchedRoute.path + '/' + parent_name + '.add' })
}, },
handleEdit(scope) { handleEdit(scope) {
if (!checkRoleAction('edit', this.role_action)) return
const parentMatchedRoute = this.$route.matched[this.$route.matched.length - 2] const parentMatchedRoute = this.$route.matched[this.$route.matched.length - 2]
const parent_name = parentMatchedRoute.name const parent_name = parentMatchedRoute.name
this.$router.push({ name: parent_name + '.edit', params: { id: scope.row.id }}) this.$router.push({ name: parent_name + '.edit', params: { id: scope.row.id }})
// this.dialogType = 'edit'
// this.dialogVisible = true
// const row = deepClone(scope.row)
// // this.user = row
// // this.user.role_id = row.roles.data.id
// this.user = {
// id: row.id,
// username: row.username,
// password: '',
// name: row.name,
// avatar: row.avatar,
// avatar_full_url: row.avatar_full_url,
// role_id: row.role.data.id,
// is_admin: row.is_admin,
// created_at: row.created_at
// }
}, },
handleDelete({ $index, row }) { handleDelete({ $index, row }) {
if (!checkRoleAction('del', this.role_action)) return
this.$confirm('确定要删除嘛?', '删除', { this.$confirm('确定要删除嘛?', '删除', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
......
<template> <template>
<div class="app-container"> <div class="app-container">
<div class="block"> <div class="block">
<el-button type="primary" @click="handleSaveChange">保存</el-button>
<el-tree <el-tree
v-loading="loading"
:data="treeData" :data="treeData"
node-key="id" node-key="id"
:props="{label:'title'}" :props="{label:'title'}"
default-expand-all default-expand-all
draggable
@node-drop="handleDrop"
> >
<span slot-scope="{ node, data }" class="custom-tree-node"> <span slot-scope="{ node, data }" class="custom-tree-node">
<span> <span>
...@@ -30,6 +35,7 @@ ...@@ -30,6 +35,7 @@
</el-button> </el-button>
<el-button <el-button
v-if="data.id !== 0" v-if="data.id !== 0"
:loading="loading"
type="text" type="text"
size="mini" size="mini"
@click="() => remove(node, data)" @click="() => remove(node, data)"
...@@ -81,8 +87,10 @@ ...@@ -81,8 +87,10 @@
</template> </template>
<script> <script>
import { menuList, menuAdd, menuDel, menuEdit } from '@/api/system/power/menu' import { menuList, menuAdd, menuDel, menuEdit, saveChange } from '@/api/system/power/menu'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import { mapGetters } from 'vuex'
import { checkRoleAction, getRoleAction } from '@/utils/util'
export default { export default {
name: 'List', name: 'List',
...@@ -106,10 +114,18 @@ export default { ...@@ -106,10 +114,18 @@ export default {
api: '', api: '',
icon: '', icon: '',
is_menu: 1 is_menu: 1
} },
dropData: {}
} }
}, },
computed: { computed: {
...mapGetters([
'menus'
]),
role_action() {
const action = ['add', 'edit', 'del', 'save_change']
return getRoleAction(this.menus, action, this.$route)
}
}, },
created() { created() {
this.init() this.init()
...@@ -172,6 +188,8 @@ export default { ...@@ -172,6 +188,8 @@ export default {
}) })
}, },
add(node, data) { add(node, data) {
if (!checkRoleAction('add', this.role_action)) return
this.form = Object.assign({ is_menu: 1 }) this.form = Object.assign({ is_menu: 1 })
this.form_parent_menu_id = data.id this.form_parent_menu_id = data.id
this.form.parent_id = data.id this.form.parent_id = data.id
...@@ -179,6 +197,8 @@ export default { ...@@ -179,6 +197,8 @@ export default {
this.dialogFormVisible = true this.dialogFormVisible = true
}, },
edit(node, data) { edit(node, data) {
if (!checkRoleAction('add', this.role_action)) return
this.resetForm() this.resetForm()
this.form_menu_id = data.id this.form_menu_id = data.id
this.dialogStatus = 'edit' this.dialogStatus = 'edit'
...@@ -186,6 +206,8 @@ export default { ...@@ -186,6 +206,8 @@ export default {
this.form = data this.form = data
}, },
remove(node, data) { remove(node, data) {
if (!checkRoleAction('del', this.role_action)) return
this.$confirm('确定要删除嘛?', '删除', { this.$confirm('确定要删除嘛?', '删除', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
...@@ -193,6 +215,7 @@ export default { ...@@ -193,6 +215,7 @@ export default {
}) })
.then(_ => { .then(_ => {
const menu_id = data.id const menu_id = data.id
this.loading = true
menuDel(menu_id).then(res => { menuDel(menu_id).then(res => {
Message.success('已删除') Message.success('已删除')
const parent = node.parent const parent = node.parent
...@@ -200,19 +223,50 @@ export default { ...@@ -200,19 +223,50 @@ export default {
const index = children.findIndex(d => d.id === data.id) const index = children.findIndex(d => d.id === data.id)
children.splice(index, 1) children.splice(index, 1)
}) })
}).catch(_ => {}) }).finally(() => { this.loading = false })
}, },
async onSubmit() { async onSubmit() {
this.loading = true this.loading = true
if (this.dialogStatus === 'create') { if (this.dialogStatus === 'create') {
await menuAdd(this.form) await menuAdd(this.form).finally(() => { this.loading = false })
Message.success('已添加') Message.success('已添加')
} else { } else {
await menuEdit(this.form.id, this.form) await menuEdit(this.form.id, this.form).finally(() => { this.loading = false })
Message.success('已修改') Message.success('已修改')
} }
this.loading = false
this.init() this.init()
},
handleDrop(draggingNode, dropNode, dropType, ev) {
switch (dropType) {
case 'before':
case 'after':
dropNode.parent.childNodes.forEach((item, index) => {
this.dropData[item.data.id] = {
id: item.data.id,
order: index,
parent_id: dropNode.data.parent_id
}
})
break
case 'inner':
dropNode.childNodes.forEach((item, index) => {
this.dropData[item.data.id] = {
id: item.data.id,
order: index,
parent_id: dropNode.data.id
}
})
break
}
},
handleSaveChange() {
if (!checkRoleAction('save_change', this.role_action)) return
this.loading = true
saveChange({ change_data: this.dropData })
.then(() => {
Message.success('成功')
}).finally(() => { this.loading = false })
} }
} }
} }
......
...@@ -65,10 +65,11 @@ ...@@ -65,10 +65,11 @@
<script> <script>
import { roleAdd, roleDel, roleEdit, roleList } from '@/api/system/power/role' import { roleAdd, roleDel, roleEdit, roleList } from '@/api/system/power/role'
import { deepClone } from '@/utils/util' import { checkRoleAction, deepClone, getRoleAction } from '@/utils/util'
import { menuList } from '@/api/system/power/menu' import { menuList } from '@/api/system/power/menu'
import { Message } from 'element-ui' import { Message } from 'element-ui'
import Pagination from '@/components/Pagination' import Pagination from '@/components/Pagination'
import { mapGetters } from 'vuex'
export default { export default {
components: { Pagination }, components: { Pagination },
...@@ -102,6 +103,13 @@ export default { ...@@ -102,6 +103,13 @@ export default {
computed: { computed: {
menuTree() { menuTree() {
return this.menuTreeData return this.menuTreeData
},
...mapGetters([
'menus'
]),
role_action() {
const action = ['add', 'edit', 'del']
return getRoleAction(this.menus, action, this.$route)
} }
}, },
created() { created() {
...@@ -150,6 +158,8 @@ export default { ...@@ -150,6 +158,8 @@ export default {
}, },
handleAddRole() { handleAddRole() {
if (!checkRoleAction('add', this.role_action)) return
this.role = Object.assign({}) this.role = Object.assign({})
if (this.$refs.tree) { if (this.$refs.tree) {
this.$refs.tree.setCheckedNodes([]) this.$refs.tree.setCheckedNodes([])
...@@ -158,6 +168,8 @@ export default { ...@@ -158,6 +168,8 @@ export default {
this.dialogVisible = true this.dialogVisible = true
}, },
handleEdit(scope) { handleEdit(scope) {
if (!checkRoleAction('edit', this.role_action)) return
this.dialogType = 'edit' this.dialogType = 'edit'
this.dialogVisible = true this.dialogVisible = true
this.checkStrictly = true this.checkStrictly = true
...@@ -172,6 +184,8 @@ export default { ...@@ -172,6 +184,8 @@ export default {
}) })
}, },
handleDelete({ $index, row }) { handleDelete({ $index, row }) {
if (!checkRoleAction('del', this.role_action)) return
this.$confirm('确定要删除嘛?', '删除', { this.$confirm('确定要删除嘛?', '删除', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment