| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- <style>
- .table-body {
- padding: 20px 20px;
- background-color: #fff;
- }
- .table-body .top-input{
- margin-top: 34px;
- }
- .input-item {
- width: 200px;
- margin-right: 20px;
- }
- .input-item .el-input__inner {
- border-right: 0;
- }
- .input-item .el-input__inner:hover {
- border: 1px solid #dcdfe6;
- border-right: 0;
- outline: 0;
- }
- .input-item .el-input__inner:focus {
- border: 1px solid #dcdfe6;
- border-right: 0;
- outline: 0;
- }
- .input-item .el-input-group__append {
- background-color: #fff;
- border-left: 0;
- width: 10%;
- padding: 0;
- }
- .input-item .el-input-group__append .el-button {
- padding: 0;
- }
- .input-item .el-input-group__append .el-button {
- margin: 0;
- }
- /* #app .table-body .el-table .el-button {
- border-radius: 16px;
- } */
- .create {
- height: 36px;
- line-height: 36px;
- float: right;
- color: #BCBCBC;
- margin-left: 20px;
- }
- .name {
- cursor: pointer;
- color: #49A9FF;
- }
- .el-input-group__append {
- /* background-color: #fff; */
- }
- /* 卡片 */
- .plugin-list {
- margin: 0 0 0 -20px;
- /* padding-right: 100px; */
- display: flex;
- flex-wrap:wrap;
- }
- .plugin-list .plugin-item{
- width: 20%;
- min-width: 400px;
- }
- .plugin-item {
- border: 1px solid #ebebeb;
- background: #FFFFFF;
- box-shadow: 3px 5px 15px rgba(80, 80, 80, 0.16);
- opacity: 1;
- border-radius: 5px;
- padding: 20px;
- margin: 0 0 20px 20px;
- transition: 250ms;
- position: relative;
- /* min-width: 300px; */
- }
- .plugin-item .item-status{
- position: absolute;
- top: 0;
- right: 0;
- width: 94px;
- height: 30px;
- background: #E8EAEC;
- opacity: 1;
- border-radius: 0px 5px 0px 5px;
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- line-height: 30px;
- color: #9398A4;
- text-align: center;
- }
- .item-status-permanent{
- width: 94px;
- }
- .item-status-effective{
- width: 164px;
- }
- .plugin-item .item-info{
- display: flex;
- align-items: center;
- }
- /* .plugin-item .item-info .item-right{
- min-width: 500px;
- } */
- .plugin-item .item-btns{
- display: flex;
- align-items: center;
- justify-content:flex-end;
- margin-top: 12px;
- }
- .plugin-item .mall-logo{
- width: 70px;
- height: 70px;
- margin-right: 12px;
- }
- .plugin-item .mall-logo img{
- width: 100%;
- height: 100%;
- display: block;
- border-radius: 50%;
- }
- .plugin-item .display-name {
- font-size: 18pt;
- margin-top: 10px;
- margin-bottom: 4px;
- font-family: Microsoft YaHei;
- font-weight: bold;
- line-height: 30px;
- color: #3F495D;
- opacity: 1;
- width: 200px;
- white-space:nowrap;
- overflow:hidden;
- text-overflow:ellipsis;
- }
- .plugin-item .name {
- color: #909399;
- }
- .plugin-item:hover {
- cursor: pointer;
- border-color: #bfddff;
- }
- /* .plugin-item:hover .display-name {
- color: #409EFF;
- } */
- .plugin-item .plugin-option-btn {
- height: 25px;
- width: 25px;
- font-size: 12px;
- padding: 0;
- }
- .plugin-item .detail-option.detail-option {
- color: #909399;
- background: #F2F6FC;
- }
- .plugin-item .detail-option:hover {
- color: #fff;
- background: #909399;
- }
- </style>
- <div id="app" v-cloak>
- <el-card shadow="never" style="border:0;min-width: 1200px;" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
- <div slot="header">
- <div>
- <span>角色管理</span>
- <div style="float: right; margin: -5px 0">
- <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
- </div>
- </div>
- </div>
- <div class="table-body">
- <template>
- <div>
- <el-table
- :data="tableData"
- style="width: 100%;margin-bottom: 20px;"
- row-key="id"
- stripe
- lazy
- :load="loadData"
- :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
- <el-table-column
- prop="title"
- label="名称"
- sortable
- width="180">
- <template slot-scope="scope">
- <span style="margin-left: 10px" >{{ scope.row.title }}</span>
- <!-- <i class="el-icon-circle-plus" @click="handleAdds(scope.$index, scope.row)"></i>-->
- </template>
- </el-table-column>
- <el-table-column
- prop="sort"
- label="排序">
- <template slot-scope="scope">
- <span style="margin-left: 10px">{{ scope.row.sort }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作">
- <template slot-scope="scope">
- <el-button type="text" size="mini" circle style="margin-left: 10px;margin-top: 10px"
- @click="handleEdit(scope.$index, scope.row)">
- <el-tooltip class="item" effect="dark" content="编辑" placement="top">
- <img src="resources/img/mall/edit.png" alt="">
- </el-tooltip>
- </el-button>
- <el-button style="margin-left: 10px;margin-top: 10px" type="text"
- class="set-el-button"
- size="mini" circle @click="handleDelete(scope.$index, scope.row)">
- <el-tooltip class="item" effect="dark" content="删除" placement="top">
- <img src="resources/img/mall/del.png" alt="">
- </el-tooltip>
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </template>
- </div>
- <el-dialog :title="title" :visible.sync="dialogFormVisible_add" >
- <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
- <el-form-item label="上级角色" :label-width="formLabelWidth">
- <el-select v-model="parent_title" placeholder="请选择" @change="handleChange">
- <el-option
- v-for="item,k in parent_list"
- :key="k"
- :label="item"
- :value="k">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
- <el-input v-model="form.title" autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item label="状态" :label-width="formLabelWidth">
- <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
- </el-form-item>
- <el-form-item label="排序" :label-width="formLabelWidth">
- <el-input v-model="form.sort" autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item label="权限" :label-width="formLabelWidth">
- <el-tree
- :data="tree_data"
- show-checkbox
- node-key="id"
- ref="tree"
- :default-checked-keys="checkedKey"
- :props="defaultProps">
- </el-tree>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogFormVisible_edit = false">取 消</el-button>
- <el-button type="primary" @click="postAdd('form')">确 定</el-button>
- </div>
- </el-dialog>
- <el-dialog :title="title" :visible.sync="dialogFormVisible_edit">
- <el-form :model="form" :rules="rules" ref="form" @close="handleClose('form')">
- <el-form-item label="上级角色" :label-width="formLabelWidth">
- <el-select v-model="parent_title" placeholder="请选择" @change="handleChange">
- <el-option
- v-for="item,k in parent_list"
- :key="k"
- :label="item"
- :value="k">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="名称" :label-width="formLabelWidth" prop="title">
- <el-input v-model="form.title" autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item label="状态" :label-width="formLabelWidth">
- <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>
- </el-form-item>
- <el-form-item label="排序" :label-width="formLabelWidth">
- <el-input v-model="form.sort" autocomplete="off"></el-input>
- </el-form-item>
- <el-form-item label="权限" :label-width="formLabelWidth">
- <el-tabs v-model="activeName" @tab-click="handleClick">
- <el-tab-pane label="平台" name="1">
- <el-tree
- :data="tree_data1"
- show-checkbox
- node-key="id"
- ref="tree1"
- @check-change="checkchange1"
- :check-strictly="true"
- :default-checked-keys="checkedKey"
- :props="defaultProps">
- </el-tree>
- </el-tab-pane>
- <el-tab-pane label="商城" name="2">
- <el-tree
- :data="tree_data2"
- show-checkbox
- node-key="id"
- ref="tree2"
- @check-change="checkchange2"
- :check-strictly="true"
- :default-checked-keys="checkedKey"
- :props="defaultProps">
- </el-tree>
- </el-tab-pane>
- <el-tab-pane label="应用" name="3">
- <el-tree
- :data="tree_data3"
- show-checkbox
- node-key="id"
- ref="tree3"
- @check-change="checkchange3"
- :check-strictly="true"
- :default-checked-keys="checkedKey"
- :props="defaultProps">
- </el-tree>
- </el-tab-pane>
- </el-tabs>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogFormVisible_edit = false">取 消</el-button>
- <el-button type="primary" @click="postAdd('form')">确 定</el-button>
- </div>
- </el-dialog>
- </el-card>
- </div>
- <script>
- new Vue({
- el: '#app',
- data() {
- return {
- activeName:"1",
- tree_data1:[],
- tree_data2:[],
- tree_data3:[],
- tableData: [],
- dialogFormVisible_edit:false,
- dialogFormVisible_add:false,
- parent_list: [],
- items: [],
- parent_title:'',
- form: {
- id:'',
- title:'',
- pid:0,
- sort:999,
- status:1,
- },
- rules:{
- title: [
- { required: true, message: '请输入名称', trigger: 'blur' },
- { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
- ],
- },
- formLabelWidth: '120px',
- defaultProps: {
- children: 'children',
- label: 'label'
- },
- tree_data:[],
- checkedKey:[],
- title:'新增'
- }
- },
- created() {
- this.loadList({});
- },
- methods: {
- checkchange1(data, checked, indeterminate){
- this.checkchange(data,checked,indeterminate,'tree1')
- },
- checkchange2(data, checked, indeterminate){
- this.checkchange(data,checked,indeterminate,'tree2')
- },
- checkchange3(data, checked, indeterminate){
- this.checkchange(data,checked,indeterminate,'tree3')
- },
- checkchange(data, checked, indeterminate,type){
- console.log(type)
- let checkid = []
- console.log(data,'data555555555')
- if(checked == true){
- checkid.push(data.id)
- if(data.children && data.children.length > 0){
- data.children.forEach((it,i)=>{
- checkid.push(it.id)
- if(it.children && it.children.length > 0){
- it.children.forEach((item,index)=>{
- checkid.push(item.id)
- if(item.children && item.children.length > 0){
- item.children.forEach((item1,index1)=>{
- checkid.push(item1.id)
- })
- }
- })
- }
- })
- }
- this.checkedKey = checkid
- }else{
- let treenodes=[]
- if(type == 'tree2'){
- treenodes=this.$refs.tree2.getCheckedKeys()
- }else if(type == 'tree3'){
- treenodes=this.$refs.tree3.getCheckedKeys()
- }else{
- treenodes=this.$refs.tree1.getCheckedKeys()
- }
- treenodes.forEach((v,i)=>{
- if(data.children && data.children.length >0){
- data.children.forEach((v1,i1)=>{
- if(v== v1.id){
- if(type == 'tree2'){
- this.$refs.tree2.setChecked(v,false);
- }else if(type == 'tree3'){
- this.$refs.tree3.setChecked(v,false);
- }else{
- this.$refs.tree1.setChecked(v,false);
- }
- }
- })
- if(data.children.children && data.children.children.length >0){
- data.children.children.forEach((v2,i2)=>{
- if(v== v2.id){
- if(type == 'tree2'){
- this.$refs.tree2.setChecked(v,false);
- }else if(type == 'tree3'){
- this.$refs.tree3.setChecked(v,false);
- }else{
- this.$refs.tree1.setChecked(v,false);
- }
- }
- })
- if(data.children.children.children && data.children.children.children.length >0){
- data.children.children.children.forEach((v3,i3)=>{
- if(v== v3.id){
- if(type == 'tree2'){
- this.$refs.tree2.setChecked(v,false);
- }else if(type == 'tree3'){
- this.$refs.tree3.setChecked(v,false);
- }else{
- this.$refs.tree1.setChecked(v,false);
- }
- }
- })
- }
- }
- }
- })
- }
- },
- loadList(params) {
- params['r'] = 'admin/role/index';
- this.$request({
- params: params,
- }).then(e => {
- if(e.data.code==0){
- if(e.data.data.list){
- let list = e.data.data.list;
- for(var i in list) {
- if(list[i]['child'].length!=0){
- list[i].hasChildren = true;
- }
- }
- this.tableData = list;
- }
- }
- }).catch(e => {
- });
- },
- handleChange(value){
- this.form.pid = value;
- },
- handleAdd()
- {
- this.title='新增';
- this.dialogFormVisible_edit = true;
- this.$request({
- params: {
- r:'admin/role/edit',
- id:''
- },
- }).then(e => {
- if(e.data.code==0){
- this.parent_title = e.data.data.parent_title;
- this.parent_list = e.data.data.list;
- this.tree_data1 = e.data.data.item_list1;
- this.tree_data2 = e.data.data.item_list2;
- this.tree_data3 = e.data.data.item_list3;
- this.checkedKey = e.data.data.checked_key;
- }
- }).catch(e => {
- });
- },
- handleAdds(index, row)
- {
- this.title='新增';
- this.dialogFormVisible_edit = true;
- this.$request({
- params: {
- r:'admin/role/edit',
- id:row.id
- },
- }).then(e => {
- if(e.data.code==0){
- this.form.pid = row.id;
- this.parent_list = e.data.data.list;
- this.tree_data = e.data.data.item_list;
- this.parent_title =e.data.data.role.title;
- }
- }).catch(e => {
- });
- },
- handleEdit(index, row)
- {
- this.title='编辑';
- this.form.id = row.id
- this.dialogFormVisible_edit = true;
- this.$request({
- params: {
- r:'admin/role/edit',
- id:row.id
- },
- }).then(e => {
- if(e.data.code==0){
- this.form.title = e.data.data.role.title;
- this.form.sort = e.data.data.role.sort;
- this.form.status = e.data.data.role.status;
- this.form.pid = e.data.data.role.pid;
- this.parent_title = e.data.data.parent_title;
- this.parent_list = e.data.data.list;
- this.tree_data1 = e.data.data.item_list1;
- this.tree_data2 = e.data.data.item_list2;
- this.tree_data3 = e.data.data.item_list3;
- this.checkedKey = e.data.data.checked_key;
- }
- }).catch(e => {
- });
- },
- postEdit(formName){
- this.$refs[formName].validate((valid) => {
- if(valid){
- let item_ids = this.$refs.tree.getCheckedKeys();
- let parent_item_ids = this.$refs.tree.getHalfCheckedKeys();
- if(parent_item_ids.length!=0){
- parent_item_ids.forEach(function (item) {
- item_ids.push(item);
- });
- }
- this.form.item_ids = item_ids;
- this.$request({
- method:"post",
- params: {
- r:'admin/role/edit',
- },
- data:this.form
- }).then(e => {
- if(e.data.code==0){
- if(this.form.id){
- this.dialogFormVisible_edit = false;
- }else{
- this.dialogFormVisible_add = false;
- }
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- this.dialogFormVisible_edit = false;
- location.reload();
- }else{
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- }
- });
- },
- postAdd(formName){
- this.$refs[formName].validate((valid) => {
- if(valid){
- let item_ids1 = this.$refs.tree1.getCheckedKeys();
- let item_ids2 = this.$refs.tree2.getCheckedKeys();
- let item_ids3 = this.$refs.tree3.getCheckedKeys();
- // let parent_item_ids = this.$refs.tree.getHalfCheckedKeys();
- // if(parent_item_ids.length!=0){
- // parent_item_ids.forEach(function (item) {
- // item_ids.push(item);
- // });
- // }
- let item_ids = [];
- item_ids1.forEach(function (item_id){
- item_ids.push(item_id);
- });
- item_ids2.forEach(function (item_id){
- item_ids.push(item_id);
- });
- item_ids3.forEach(function (item_id){
- item_ids.push(item_id);
- });
- this.form.item_ids = item_ids;
- this.$request({
- method:"post",
- params: {
- r:'admin/role/edit',
- },
- data:this.form
- }).then(e => {
- if(e.data.code==0){
- this.dialogFormVisible_add = false;
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- this.dialogFormVisible_edit = false;
- location.reload();
- }else{
- this.$message.error(e.data.msg);
- }
- }).catch(e => {
- });
- }
- });
- },
- handleDelete(index, row) {
- this.$confirm('删除该条数据后不可以恢复, 是否继续?', '警告', {type: 'warning'}).then(() => {
- this.form.id = row.id
- this.$request({
- params: {
- r: 'admin/role/del',
- id: row.id,
- },
- }).then(e => {
- if (e.data.code == 0) {
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- location.reload();
- }else{
- this.$message({
- message: e.data.msg,
- type: 'error'
- });
- }
- }).catch(e => {
- });
- });
- },
- loadData(tree, treeNode, resolve){
- this.$request({
- params: {
- r:'admin/role/index',
- pid:tree.id,
- },
- }).then(e => {
- if(e.data.code==0){
- let list = e.data.data.list;
- for(var i in list) {
- console.log(list[i]['child'].length);
- if(list[i]['child'].length!=0){
- list[i].hasChildren = true;
- }
- }
- resolve(list);
- }
- }).catch(e => {
- });
- },
- handleClose(formName){
- this.$refs[formName].resetFields();
- },
- handleClick(tab, event) {
- console.log(tab, event);
- }
- },
- });
- </script>
|