<template>
|
<div class='offical-authority'>
|
<p class="title"> 后台模块管理 </p>
|
|
<el-card>
|
<el-row>
|
<el-button class="create-button"
|
type="primary" @click='createModule'>新增</el-button>
|
<el-button class="delete-button"
|
type="primary" @click='deleteModule' v-if='isDelete'>删除</el-button>
|
</el-row>
|
<el-table
|
ref="moduleTable"
|
:data="rightsList"
|
border
|
max-height="600px"
|
@selection-change="handleSelectionChange"
|
v-bind="$attrs"
|
:row-style="showRow">
|
<el-table-column
|
show-overflow-tooltip
|
type="selection"
|
align="center"
|
width="55"/>
|
<el-table-column label="图标" prop="IconPath" width="100">
|
<template slot-scope="scope">
|
<div :class='scope.row.IconPath' style='margin-left:5px; width: 20px;height: 25px;'></div>
|
</template>
|
</el-table-column>
|
<el-table-column label="标题" prop="ModuleName" width="400">
|
<template slot-scope="scope">
|
<span class='level'>
|
<div v-if="scope.row.Children&&scope.row.Children.length>0" @click="openToggle(scope.row)"
|
:class="[scope.row.open?'el-table__expand-icon el-table__expand-icon--expanded':'el-table__expand-icon']">
|
<i class='el-icon-arrow-right'></i>
|
</div>
|
</span>
|
{{scope.row.ModuleName}}
|
<span>
|
<el-tooltip :content="scope.row.Description" placement="bottom" effect="light" v-show='scope.row.Description'>
|
<i class='el-icon-warning-outline'></i>
|
</el-tooltip>
|
</span>
|
</template>
|
</el-table-column>
|
<el-table-column label="地址" prop="LinkUrl" width="400"></el-table-column>
|
<el-table-column label="显示" prop="IsShow">
|
<template slot-scope="scope">
|
<img :class="scope.row.IsShow?'el-icon-success':'el-icon-error'" />
|
</template>
|
</el-table-column>
|
<el-table-column label="排序" prop="SortNumber"></el-table-column>
|
<el-table-column
|
prop="operation"
|
label="操作">
|
<template slot-scope="scope">
|
<el-button type="text" size="small" @click='addModule(scope.row)'>添加子级</el-button>
|
<el-button type="text" size="small" @click='editModule(scope.row)'>编辑模块</el-button>
|
<el-button type="text" size="small" @click='deleteSingleModule(scope.row.Id)'>删除模块</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</el-card>
|
<!-- 导航新增编辑弹出框 -->
|
<el-dialog
|
:visible.sync="moduleDialog"
|
:title='addTitle'
|
:before-close="cancelDialog"
|
width="40%">
|
<el-form
|
ref="createForm"
|
:model="createForm"
|
:rules="createRules"
|
label-width="80px"
|
class="login-form"
|
auto-complete="on"
|
label-position="left">
|
<el-form-item label="上级导航" prop='fatherIntro'>
|
<el-cascader
|
ref="refSubCat"
|
placeholder="请选择上级导航"
|
:options="isCreate? selectOpts: rightsList"
|
:show-all-levels="false"
|
:props="{
|
children: 'Children',
|
label: 'ModuleName',
|
value: 'Id'
|
}"
|
v-model="createForm.fatherIntro"
|
style="width: 100%;"
|
@change='getFatherOpt'
|
change-on-select/>
|
</el-form-item>
|
<el-form-item label="导航标题" prop='introName'>
|
<el-input
|
v-model="createForm.introName"
|
placeholder="请输入导航标题"/>
|
</el-form-item>
|
<el-form-item label="是否显示">
|
<el-switch v-model="createForm.isShow"></el-switch>
|
</el-form-item>
|
<el-form-item label="排序数字">
|
<el-input
|
class='numInp'
|
type='number'
|
v-model="createForm.sortNum"
|
placeholder="请输入排序数字"/>
|
</el-form-item>
|
<el-form-item label="自定义图标">
|
<el-select v-model="createForm.img" placeholder="请选择图标">
|
<el-option
|
v-for="(item, index) in iconOption"
|
class='iconList'
|
:class='item.name'
|
:key="index"
|
:label="item.name"
|
:value="item.name"/>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="链接地址">
|
<el-input
|
v-model="createForm.address"
|
placeholder="请输入链接地址"/>
|
</el-form-item>
|
<el-form-item label="备注说明">
|
<el-input
|
type='textarea'
|
v-model="createForm.info"
|
placeholder="请输入备注说明"/>
|
</el-form-item>
|
<el-form-item>
|
<el-button @click="cancelDialog">取 消</el-button>
|
<el-button
|
type="primary"
|
@click="submitDialog('createForm')">确 定</el-button>
|
</el-form-item>
|
</el-form>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import Vue from 'vue'
|
import Lockr from 'lockr'
|
import { GetSysModuleList, DeleteSysModule, AddSysModule, UpdateSysModule, GetCurrentUserModules } from '@/api/moduleManage/moduleManage'
|
import { mapGetters } from 'vuex'
|
export default {
|
name: 'ModuleManage',
|
data () {
|
return {
|
rightsList: [],
|
selectOpts: [],
|
defaultProps: {
|
children: 'children',
|
label: 'title'
|
},
|
moduleDialog: false,
|
createForm: {
|
fatherIntro: '',
|
introName: '',
|
isShow: true,
|
sortNum: 1,
|
img: '',
|
address: '',
|
info: ''
|
},
|
createRules: {
|
fatherIntro: [
|
{ required: true, trigger: 'blur', message: '请选择上级导航' }
|
],
|
introName: [{ required: true, trigger: 'blur', message: '请输入导航标题' }]
|
},
|
iconOption: [{id: '1', name: 'icon-financial'}, {id: '2', name: 'icon-company'}, {id: '3', name: 'icon-customer'}, {id: '4', name: 'icon-order'}, {id: '5', name: 'icon-product'}, {id: '6', name: 'icon-system'}, {id: '7', name: 'icon-total'}, {id: '8', name: 'icon-workbench'}, {id: '7', name: 'icon-business'}, {id: '8', name: 'icon-personnel'}],
|
authName: '',
|
isCreate: false,
|
isSon: false,
|
addTitle: '',
|
isDelete: false,
|
deleteIds: [],
|
parentId: ''
|
}
|
},
|
computed: {
|
...mapGetters(['moduleBlock'])
|
},
|
created () {
|
this.getRightsList()
|
},
|
methods: {
|
// 树节点开关操作
|
openToggle (item) {
|
console.log(item)
|
// 这里只是展开和关闭样式的变换方法
|
Vue.set(item, 'open', !item.open)
|
// 展开的时候,显示子节点,关闭的时候隐藏子节点
|
// 遍历所有的子节点,加入到menuTable中
|
for (let j = 0; j < this.rightsList.length; j++) {
|
// 找到父节点的id,然后依次把子节点放到数组里面父节点后面
|
if (this.rightsList[j].Id !== item.Id) {
|
continue
|
}
|
if (item.open) { // open => close
|
console.log(item.Children)
|
let rightsList = this.rightsList
|
item.Children.forEach(function (child, index) {
|
rightsList.splice(j + index + 1, 0, child) // 添加子节点
|
})
|
} else {
|
this.rightsList.splice(j + 1, item.Children.length) // 删除子节点
|
}
|
break
|
}
|
},
|
showRow (row) {
|
const show = row.row.parent
|
? row.row.parent._expanded && row.row.parent._show
|
: true
|
row.row._show = show
|
return show
|
? 'animation:treeTableShow 1s;-webkit-animation:treeTableShow 1s;'
|
: 'display:none;'
|
},
|
handleSelectionChange (val) {
|
console.log(val)
|
if (val.length > 0) {
|
let deleteId = []
|
val.forEach(item => {
|
deleteId.push(item.Id)
|
})
|
this.isDelete = true
|
this.deleteIds = deleteId
|
} else {
|
this.isDelete = false
|
}
|
},
|
createModule () {
|
this.isCreate = true
|
this.isSon = false
|
this.moduleDialog = true
|
this.addTitle = '新增模块'
|
},
|
deleteModule () {
|
DeleteSysModule({'Id': this.deleteIds}).then(res => {
|
console.log(res)
|
if (res.data.ErrorCode === 200) {
|
this.$message.success(res.data.Message)
|
this.getRightsList()
|
this.getCurrentUser()
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
},
|
addModule (row) {
|
console.log(row)
|
this.isCreate = true
|
this.isSon = true
|
this.addTitle = '添加子级'
|
this.moduleDialog = true
|
this.createForm = {
|
fatherIntro: row.Id,
|
introName: '',
|
isShow: row.IsShow,
|
sortNum: Number(row.SortNumber) + 1,
|
img: '',
|
address: '',
|
info: ''
|
}
|
this.parentId = row.Id
|
},
|
deleteSingleModule (id) {
|
this.$confirm('确定删除?', '提示', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
})
|
.then(() => {
|
DeleteSysModule([{'Id': id}]).then(res => {
|
console.log(res)
|
if (res.data.ErrorCode === 200) {
|
this.$message.success(res.data.Message)
|
this.getRightsList()
|
this.getCurrentUser()
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
})
|
.catch(() => {
|
this.$message({
|
type: 'info',
|
message: '已取消删除'
|
})
|
})
|
},
|
editModule (row) {
|
this.isCreate = false
|
this.isSon = false
|
this.addTitle = '编辑模块'
|
this.moduleDialog = true
|
this.createForm = {
|
fatherIntro: row.Id,
|
introName: row.ModuleName,
|
isShow: row.IsShow,
|
sortNum: row.SortNumber,
|
img: row.IconPath,
|
address: row.LinkUrl,
|
info: row.Description
|
}
|
this.parentId = row.ParentModuleId
|
},
|
submitDialog (formName) {
|
this.$refs[formName].validate(valid => {
|
if (!valid) return
|
const isIntro = Array.isArray(this.createForm.fatherIntro)
|
let params = {
|
'ModuleName': this.createForm.introName,
|
'ParentModuleId': isIntro ? (this.createForm.fatherIntro.length > 1 ? this.createForm.fatherIntro[this.createForm.fatherIntro.length - 1] : (this.createForm.fatherIntro[0] === 100001 ? '' : this.createForm.fatherIntro[0])) : this.createForm.fatherIntro,
|
'ParentModuleName': this.createForm.fatherIntro[0] === '' ? '' : this.$refs['refSubCat'].getCheckedNodes()[0].label,
|
'LinkUrl': this.createForm.address,
|
'IconPath': this.createForm.img,
|
'IsShow': this.createForm.isShow,
|
'SortNumber': Number(this.createForm.sortNum),
|
'Description': this.createForm.info
|
}
|
if (this.isCreate) {
|
if (this.isSon) {
|
params.ParentModuleId = this.parentId
|
}
|
AddSysModule(params).then(res => {
|
console.log(res)
|
if (res.data.ErrorCode === 200) {
|
this.$message.success(res.data.Message)
|
this.getRightsList()
|
this.getCurrentUser()
|
this.moduleDialog = false
|
this.$refs.createForm.resetFields()
|
this.createForm = {
|
fatherIntro: '',
|
introName: '',
|
isShow: true,
|
sortNum: 1,
|
img: '',
|
address: '',
|
info: ''
|
}
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
} else {
|
params.Id = isIntro ? (this.createForm.fatherIntro.length > 1 ? this.createForm.fatherIntro[this.createForm.fatherIntro.length - 1] : this.createForm.fatherIntro[0]) : this.createForm.fatherIntro
|
|
params.ParentModuleId = this.parentId
|
|
UpdateSysModule(params).then(res => {
|
console.log(res)
|
if (res.data.ErrorCode === 200) {
|
this.$message.success(res.data.Message)
|
this.getRightsList()
|
this.getCurrentUser()
|
this.moduleDialog = false
|
this.$refs.createForm.resetFields()
|
this.createForm = {
|
fatherIntro: '',
|
introName: '',
|
isShow: true,
|
sortNum: 1,
|
img: '',
|
address: '',
|
info: ''
|
}
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
}
|
})
|
},
|
cancelDialog () {
|
this.$refs.createForm.resetFields()
|
this.createForm = {
|
fatherIntro: '',
|
introName: '',
|
isShow: true,
|
sortNum: 1,
|
img: '',
|
address: '',
|
info: ''
|
}
|
this.moduleDialog = false
|
},
|
getFatherOpt () {
|
console.log(this.createForm.fatherIntro[0])
|
const flag = Array.isArray(this.createForm.fatherIntro)
|
if (flag) {
|
this.parentId = this.createForm.fatherIntro.length > 1 ? this.createForm.fatherIntro[0] : ''
|
}
|
},
|
getRightsList () {
|
GetSysModuleList().then(res => {
|
if (res.data.ErrorCode === 200 && res.data.Result) {
|
this.rightsList = res.data.Result
|
this.selectOpts = JSON.parse(JSON.stringify(this.rightsList))
|
this.selectOpts.unshift({ ModuleName: '无上级导航', Id: 100001 })
|
// this.$store.commit('SET_MODULE', res.data.Result)
|
// Lockr.set('authList', res.data.Result)
|
// console.log(this.moduleBlock)
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
},
|
getCurrentUser () {
|
GetCurrentUserModules().then(res => {
|
if (res.data.ErrorCode === 200 && res.data.Result) {
|
this.$store.commit('SET_MODULE', res.data.Result)
|
Lockr.set('authList', res.data.Result)
|
console.log(this.moduleBlock)
|
} else {
|
this.$message.error(res.data.Message)
|
}
|
})
|
}
|
}
|
}
|
</script>
|
|
<style lang='scss' scoped>
|
|
.offical-authority{}
|
|
.title {
|
font-size: 18px;
|
height: 40px;
|
line-height: 40px;
|
margin: 10px 0;
|
color: #333;
|
padding: 0 20px;
|
}
|
.nav-dialog-div {
|
margin-bottom: 12px;
|
}
|
.checkedBox{
|
display:flex;
|
flex-direction:row;
|
}
|
.allChecked{
|
margin-right:20px;
|
}
|
.dialogLabel{
|
font-size: 16px;
|
float:right;
|
margin-right: 20px;
|
}
|
.create-button{
|
margin-bottom: 20px;
|
float: right;
|
}
|
.delete-button{
|
margin-bottom: 20px;
|
float: right;
|
margin-right: 20px;
|
}
|
.level {
|
display: inline-block;
|
width: 20px;
|
}
|
|
.level1 {
|
margin-left: 5px;
|
}
|
|
.level2 {
|
margin-left: 20px;
|
}
|
|
.level3 {
|
margin-left: 35px;
|
}
|
.numInp{
|
width:40%;
|
}
|
</style>
|