提交 a7308226 编写于 作者: laizhilong's avatar laizhilong

修改视图保存逻辑:在父页面保存之前进行保存

上级 6101fb6e
<template> <template>
<div class="view-container dempickupview sys-permissionmpickup-view"> <div class="view-container dempickupview sys-permissionmpickup-view">
<card class='view-card view-no-caption view-no-toolbar' :dis-hover="true" :padding="0" :bordered="false"> <card class='view-card view-no-caption view-no-toolbar' :dis-hover="true" :padding="0" :bordered="false">
<div class="content-container pickup-view"> <div class="content-container pickup-view">
<div class="translate-contant"> <div class="translate-contant">
<!--应用菜单--> <!--应用菜单-->
<div class="center" :style="{width : '33%',border:'1px solid #dcdee2', margin: '0 10px 0 0'}"> <div class="center" :style="{width : '33%',border:'1px solid #dcdee2', margin: '0 10px 0 0'}">
<context-menu-container class='design-tree-container'> <context-menu-container class='design-tree-container'>
<div> <div>
<!--<div class="text">应用菜单</div>--> <!--<div class="text">应用菜单</div>-->
<div style="margin: 20px 20px 0 20px;"> <div style="margin: 20px 20px 0 20px;">
<el-input size="small" placeholder="搜索应用菜单..." v-model="CDtreefilterText" @input="filterChangeCDtree"> <el-input size="small" placeholder="搜索应用菜单..." v-model="CDtreefilterText" @input="filterChangeCDtree">
<i slot="prefix" class="el-input__icon el-icon-search"></i> <i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input> </el-input>
</div>
<div class="roll">
<el-tree
:filter-node-method="fiterNode"
class="tre"
:data="this.CDdata"
ref="CDtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:default-expanded-keys="this.CDdataexpandedKeys"
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
<!--数据能力-->
<div class="center" :style="{width : '33%',border:'1px solid #dcdee2', margin: '0 10px 0 0' }">
<context-menu-container class='design-tree-container'>
<div>
<!--<div class="text">数据能力</div>-->
<div style="margin: 20px 20px 0 20px;">
<el-input size="small" placeholder="搜索数据能力..." v-model="QXtreefilterText" @input="filterChangeQXtree">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</div>
<div class="roll">
<el-tree
:filter-node-method="fiterNode"
class="tre"
:data="this.QXdata"
ref="QXtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:default-expanded-keys="this.QXdataexpandedKeys"
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
<!--自定义资源-->
<div class="center" :style="{width : '33%',border:'1px solid #dcdee2' }">
<context-menu-container class='design-tree-container'>
<div>
<!--<div class="text">自定义资源</div>-->
<div style="margin: 20px 20px 0 20px;">
<el-input size="small" placeholder="搜索自定义资源..." v-model="ZYtreefilterText" @input="filterChangeZYtree">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</div>
<div class="roll">
<el-tree
:filter-node-method="fiterNode"
class="tre"
:data="this.ZYdata"
ref="ZYtree"
show-checkbox
node-key="id"
:default-expand-all="false"
highlight-current
:default-expanded-keys="this.ZYdataexpandedKeys"
:props="this.defaultProps"
@check-change="handleCheckChange"
>
</el-tree>
</div>
</div>
</context-menu-container>
</div>
</div> </div>
<div class="roll">
</div> <el-tree :filter-node-method="fiterNode" class="tre" :data="this.CDdata" ref="CDtree" show-checkbox node-key="id" :default-expand-all="false" highlight-current :default-expanded-keys="this.CDdataexpandedKeys" :props="this.defaultProps" @check-change="handleCheckChange">
</card> </el-tree>
</div> </div>
</div>
</context-menu-container>
</div>
<!--数据能力-->
<div class="center" :style="{width : '33%',border:'1px solid #dcdee2', margin: '0 10px 0 0' }">
<context-menu-container class='design-tree-container'>
<div>
<!--<div class="text">数据能力</div>-->
<div style="margin: 20px 20px 0 20px;">
<el-input size="small" placeholder="搜索数据能力..." v-model="QXtreefilterText" @input="filterChangeQXtree">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</div>
<div class="roll">
<el-tree :filter-node-method="fiterNode" class="tre" :data="this.QXdata" ref="QXtree" show-checkbox node-key="id" :default-expand-all="false" highlight-current :default-expanded-keys="this.QXdataexpandedKeys" :props="this.defaultProps" @check-change="handleCheckChange">
</el-tree>
</div>
</div>
</context-menu-container>
</div>
<!--自定义资源-->
<div class="center" :style="{width : '33%',border:'1px solid #dcdee2' }">
<context-menu-container class='design-tree-container'>
<div>
<!--<div class="text">自定义资源</div>-->
<div style="margin: 20px 20px 0 20px;">
<el-input size="small" placeholder="搜索自定义资源..." v-model="ZYtreefilterText" @input="filterChangeZYtree">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</div>
<div class="roll">
<el-tree :filter-node-method="fiterNode" class="tre" :data="this.ZYdata" ref="ZYtree" show-checkbox node-key="id" :default-expand-all="false" highlight-current :default-expanded-keys="this.ZYdataexpandedKeys" :props="this.defaultProps" @check-change="handleCheckChange">
</el-tree>
</div>
</div>
</context-menu-container>
</div>
</div>
</div>
</card>
</div>
</template> </template>
<script lang='tsx'> <script lang='tsx'>
import {Component, Prop, Vue, Watch} from 'vue-property-decorator'; import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import view_pickupviewpanel import view_pickupviewpanel from "@widgets/sys-permission/mpickup-viewpickupviewpanel-pickupviewpanel/mpickup-viewpickupviewpanel-pickupviewpanel.vue";
from '@widgets/sys-permission/mpickup-viewpickupviewpanel-pickupviewpanel/mpickup-viewpickupviewpanel-pickupviewpanel.vue'; import ContextMenuContainer from "@components/context-menu-container/context-menu-container.vue";
import ContextMenuContainer from "@components/context-menu-container/context-menu-container.vue"; import { Subject } from "rxjs";
import {Subject} from "rxjs";
@Component({
@Component({ components: {
components: { ContextMenuContainer,
ContextMenuContainer, view_pickupviewpanel,
view_pickupviewpanel, },
}, beforeRouteEnter: (to: any, from: any, next: any) => {
beforeRouteEnter: (to: any, from: any, next: any) => { next((vm: any) => {
next((vm: any) => { vm.$store.commit("addCurPageViewtag", {
vm.$store.commit('addCurPageViewtag', {fullPath: to.fullPath, viewtag: vm.viewtag}); fullPath: to.fullPath,
}); viewtag: vm.viewtag,
}, });
}) });
export default class SYS_ROLE_PERMISSIONCustomView extends Vue { },
})
// 应用菜单树搜索文本 export default class SYS_ROLE_PERMISSIONCustomView extends Vue {
public CDtreefilterText:any = ''; // 应用菜单树搜索文本
// 数据能力树搜索文本 public CDtreefilterText: any = "";
public QXtreefilterText:any = ''; // 数据能力树搜索文本
// 自定义资源树搜索文本 public QXtreefilterText: any = "";
public ZYtreefilterText:any = ''; // 自定义资源树搜索文本
public ZYtreefilterText: any = "";
/**
* 过滤节点 /**
*/ * 过滤节点
public fiterNode(value:any,data:any){ */
if (!value) return true; public fiterNode(value: any, data: any) {
return data.label.indexOf(value) !==-1; if (!value) return true;
} return data.label.indexOf(value) !== -1;
/** }
* 应用菜单树搜索触发 /**
*/ * 应用菜单树搜索触发
public filterChangeCDtree(){ */
const CDtree:any = this.$refs.CDtree; public filterChangeCDtree() {
CDtree.filter(this.CDtreefilterText); const CDtree: any = this.$refs.CDtree;
} CDtree.filter(this.CDtreefilterText);
/** }
* 数据能力树搜索触发 /**
*/ * 数据能力树搜索触发
public filterChangeQXtree(){ */
const QXtree:any = this.$refs.QXtree; public filterChangeQXtree() {
QXtree.filter(this.QXtreefilterText); const QXtree: any = this.$refs.QXtree;
} QXtree.filter(this.QXtreefilterText);
/** }
* 自定义资源树搜索触发 /**
*/ * 自定义资源树搜索触发
public filterChangeZYtree(){ */
const ZYtree:any = this.$refs.ZYtree; public filterChangeZYtree() {
ZYtree.filter(this.ZYtreefilterText); const ZYtree: any = this.$refs.ZYtree;
} ZYtree.filter(this.ZYtreefilterText);
}
/*应用菜单数据*/
protected CDdata: any = []; /*应用菜单数据*/
/*数据能力数据*/ protected CDdata: any = [];
protected QXdata: any = []; /*数据能力数据*/
/*自定义资源数据*/ protected QXdata: any = [];
protected ZYdata: any = []; /*自定义资源数据*/
/*默认选中节点*/ protected ZYdata: any = [];
protected defaultCheckedNodes: any = []; /*默认选中节点*/
/*应用菜单数据默认展开节点*/ protected defaultCheckedNodes: any = [];
protected CDdataexpandedKeys: any = []; /*应用菜单数据默认展开节点*/
/*数据能力数据默认展开节点*/ protected CDdataexpandedKeys: any = [];
protected QXdataexpandedKeys: any = []; /*数据能力数据默认展开节点*/
/*自定义资源数据默认展开节点*/ protected QXdataexpandedKeys: any = [];
protected ZYdataexpandedKeys: any = []; /*自定义资源数据默认展开节点*/
protected ZYdataexpandedKeys: any = [];
/**
* 树显示说明:子树为节点对象的children,节点标签为节点对象的label /**
*/ * 树显示说明:子树为节点对象的children,节点标签为节点对象的label
protected defaultProps: any = { */
children: 'children', protected defaultProps: any = {
label: 'label' children: "children",
} label: "label",
/** };
* 选中数据 /**
*/ * 选中数据
protected selectData: any = {}; */
/** protected selectData: any = {};
* 初始选中的数据 /**
*/ * 初始选中的数据
protected ininselectData: any = {}; */
protected ininselectData: any = {};
/**
* 视图选中数据 /**
*/ * 视图选中数据
public viewSelections: any[] = []; */
public viewSelections: any[] = [];
/**
* 父数据 /**
*/ * 父数据
protected parentData: any = {}; */
/** protected parentData: any = {};
* 父数据主键 /**
*/ * 父数据主键
protected srfparentkey: any; */
protected srfparentkey: any;
/**
* 视图标识 /**
* * 视图标识
* @type {string} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {string}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public viewtag: string = 'e791be173ed0f4bbe9cce942b6edde63'; */
public viewtag: string = "e791be173ed0f4bbe9cce942b6edde63";
/**
* 是否嵌入关系界面 /**
* * 是否嵌入关系界面
* @type {boolean} *
* @memberof SYS_USER_ROLEGridViewBase * @type {boolean}
*/ * @memberof SYS_USER_ROLEGridViewBase
@Prop({default:false}) public isformDruipart?: boolean; */
@Prop({ default: false }) public isformDruipart?: boolean;
/**
* 界面关系通讯对象 /**
* * 界面关系通讯对象
* @type {Subject<ViewState>} *
* @memberof SYS_USER_ROLEGridViewBase * @type {Subject<ViewState>}
*/ * @memberof SYS_USER_ROLEGridViewBase
@Prop() public formDruipart?: Subject<ViewState>; */
@Prop() public formDruipart?: Subject<ViewState>;
/**
* 应用上下文 /**
* * 应用上下文
* @type {*} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {*}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public context:any = {}; */
public context: any = {};
/**
* 视图参数 /**
* * 视图参数
* @type {*} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {*}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public viewparams:any = {}; */
public viewparams: any = {};
/**
* 传入视图上下文 /**
* * 传入视图上下文
* @type {string} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {string}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
@Prop() public viewdata!: string; */
@Prop() public viewdata!: string;
@Watch('viewdata')
public watchViewData(){ @Watch("viewdata")
if(!this.viewdata||Object.is(this.viewdata,'')){ public watchViewData() {
return; if (!this.viewdata || Object.is(this.viewdata, "")) {
} return;
this.parseViewParam(); }
const _this: any = this; this.parseViewParam();
// 获取父数据 const _this: any = this;
if (_this && _this.viewdata) { // 获取父数据
_this.parentData = JSON.parse(_this.viewdata); if (_this && _this.viewdata) {
} _this.parentData = JSON.parse(_this.viewdata);
if (_this.parentData && _this.parentData.sysrole) { }
// console.log("当前角色id:" + _this.parentData.sysrole); if (_this.parentData && _this.parentData.sysrole) {
_this.srfparentkey = _this.parentData.sysrole; // console.log("当前角色id:" + _this.parentData.sysrole);
} _this.srfparentkey = _this.parentData.sysrole;
this.initTree(); }
} this.initTree();
}
/**
* 视图默认使用 /**
* * 视图默认使用
* @type {boolean} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {boolean}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
@Prop({ default: true }) public viewDefaultUsage!: boolean; */
@Prop({ default: true }) public viewDefaultUsage!: boolean;
/**
* 自定义视图导航上下文集合 /**
* * 自定义视图导航上下文集合
* @type {*} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {*}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public customViewNavContexts:any ={}; */
/** public customViewNavContexts: any = {};
* 自定义视图导航参数集合 /**
* * 自定义视图导航参数集合
* @type {*} *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @type {*}
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public customViewParams:any ={}; */
public customViewParams: any = {};
/**
* 解析视图参数 /**
* * 解析视图参数
* @public *
* @memberof SYS_ROLE_PERMISSIONCustomViewBase * @public
*/ * @memberof SYS_ROLE_PERMISSIONCustomViewBase
public parseViewParam(): void { */
for(let key in this.context){ public parseViewParam(): void {
delete this.context[key]; for (let key in this.context) {
} delete this.context[key];
if (!this.viewDefaultUsage && this.viewdata && !Object.is(this.viewdata, '')) { }
Object.assign(this.context, JSON.parse(this.viewdata)); if (
if(this.context && this.context.srfparentdename){ !this.viewDefaultUsage &&
Object.assign(this.viewparams,{srfparentdename:this.context.srfparentdename}); this.viewdata &&
} !Object.is(this.viewdata, "")
if(this.context && this.context.srfparentkey){ ) {
Object.assign(this.viewparams,{srfparentkey:this.context.srfparentkey}); Object.assign(this.context, JSON.parse(this.viewdata));
} if (this.context && this.context.srfparentdename) {
this.handleCustomViewData(); Object.assign(this.viewparams, {
return; srfparentdename: this.context.srfparentdename,
} });
const path = (this.$route.matched[this.$route.matched.length - 1]).path; }
const keys: Array<any> = []; if (this.context && this.context.srfparentkey) {
const curReg = this.$pathToRegExp.pathToRegexp(path, keys); Object.assign(this.viewparams, {
const matchArray = curReg.exec(this.$route.path); srfparentkey: this.context.srfparentkey,
let tempValue: Object = {}; });
keys.forEach((item: any, index: number) => { }
Object.defineProperty(tempValue, item.name, { this.handleCustomViewData();
enumerable: true, return;
value: matchArray[index + 1] }
}); const path = this.$route.matched[this.$route.matched.length - 1].path;
}); const keys: Array<any> = [];
this.$viewTool.formatRouteParams(tempValue,this.$route,this.context,this.viewparams); const curReg = this.$pathToRegExp.pathToRegexp(path, keys);
if(this.$store.getters.getAppData() && this.$store.getters.getAppData().context){ const matchArray = curReg.exec(this.$route.path);
Object.assign(this.context,this.$store.getters.getAppData().context); let tempValue: Object = {};
} keys.forEach((item: any, index: number) => {
//初始化视图唯一标识 Object.defineProperty(tempValue, item.name, {
Object.assign(this.context,{srfsessionid:this.$util.createUUID()}); enumerable: true,
this.handleCustomViewData(); value: matchArray[index + 1],
} });
});
/** this.$viewTool.formatRouteParams(
* 处理自定义视图数据 tempValue,
* this.$route,
* @memberof SYS_ROLE_PERMISSIONCustomViewBase this.context,
*/ this.viewparams
public handleCustomViewData(){ );
if(Object.keys(this.customViewNavContexts).length > 0){ if (
Object.keys(this.customViewNavContexts).forEach((item:any) =>{ this.$store.getters.getAppData() &&
let tempContext:any = {}; this.$store.getters.getAppData().context
let curNavContext:any = this.customViewNavContexts[item]; ) {
this.handleCustomDataLogic(curNavContext,tempContext,item); Object.assign(this.context, this.$store.getters.getAppData().context);
Object.assign(this.context,tempContext); }
}) //初始化视图唯一标识
} Object.assign(this.context, { srfsessionid: this.$util.createUUID() });
if(Object.keys(this.customViewParams).length > 0){ this.handleCustomViewData();
Object.keys(this.customViewParams).forEach((item:any) =>{ }
let tempParam:any = {};
let curNavParam:any = this.customViewParams[item]; /**
this.handleCustomDataLogic(curNavParam,tempParam,item); * 处理自定义视图数据
Object.assign(this.viewparams,tempParam); *
}) * @memberof SYS_ROLE_PERMISSIONCustomViewBase
} */
} public handleCustomViewData() {
if (Object.keys(this.customViewNavContexts).length > 0) {
/** Object.keys(this.customViewNavContexts).forEach((item: any) => {
* 处理自定义视图数据逻辑 let tempContext: any = {};
* let curNavContext: any = this.customViewNavContexts[item];
* @memberof SYS_ROLE_PERMISSIONCustomViewBase this.handleCustomDataLogic(curNavContext, tempContext, item);
*/ Object.assign(this.context, tempContext);
public handleCustomDataLogic(curNavData:any,tempData:any,item:string){ });
// 直接值直接赋值 }
if(curNavData.isRawValue){ if (Object.keys(this.customViewParams).length > 0) {
if(Object.is(curNavData.value,"null") || Object.is(curNavData.value,"")){ Object.keys(this.customViewParams).forEach((item: any) => {
Object.defineProperty(tempData, item.toLowerCase(), { let tempParam: any = {};
value: null, let curNavParam: any = this.customViewParams[item];
writable : true, this.handleCustomDataLogic(curNavParam, tempParam, item);
enumerable : true, Object.assign(this.viewparams, tempParam);
configurable : true });
}); }
}else{ }
Object.defineProperty(tempData, item.toLowerCase(), {
value: curNavData.value, /**
writable : true, * 处理自定义视图数据逻辑
enumerable : true, *
configurable : true * @memberof SYS_ROLE_PERMISSIONCustomViewBase
}); */
} public handleCustomDataLogic(curNavData: any, tempData: any, item: string) {
}else{ // 直接值直接赋值
// 先从导航上下文取数,没有再从导航参数(URL)取数,如果导航上下文和导航参数都没有则为null if (curNavData.isRawValue) {
if(this.context[(curNavData.value).toLowerCase()]){ if (
Object.defineProperty(tempData, item.toLowerCase(), { Object.is(curNavData.value, "null") ||
value: this.context[(curNavData.value).toLowerCase()], Object.is(curNavData.value, "")
writable : true, ) {
enumerable : true, Object.defineProperty(tempData, item.toLowerCase(), {
configurable : true value: null,
}); writable: true,
}else{ enumerable: true,
if(this.viewparams[(curNavData.value).toLowerCase()]){ configurable: true,
Object.defineProperty(tempData, item.toLowerCase(), { });
value: this.viewparams[(curNavData.value).toLowerCase()], } else {
writable : true, Object.defineProperty(tempData, item.toLowerCase(), {
enumerable : true, value: curNavData.value,
configurable : true writable: true,
}); enumerable: true,
}else{ configurable: true,
Object.defineProperty(tempData, item.toLowerCase(), { });
value: null, }
writable : true, } else {
enumerable : true, // 先从导航上下文取数,没有再从导航参数(URL)取数,如果导航上下文和导航参数都没有则为null
configurable : true if (this.context[curNavData.value.toLowerCase()]) {
}); Object.defineProperty(tempData, item.toLowerCase(), {
} value: this.context[curNavData.value.toLowerCase()],
} writable: true,
} enumerable: true,
} configurable: true,
});
/** } else {
* vue 创建 if (this.viewparams[curNavData.value.toLowerCase()]) {
*/ Object.defineProperty(tempData, item.toLowerCase(), {
public created() { value: this.viewparams[curNavData.value.toLowerCase()],
this.afterCreated(); writable: true,
} enumerable: true,
configurable: true,
/** });
* 执行created后的逻辑 } else {
* Object.defineProperty(tempData, item.toLowerCase(), {
* @memberof SYS_USER_ROLEGridViewBase value: null,
*/ writable: true,
public afterCreated(){ enumerable: true,
const secondtag = this.$util.createUUID(); configurable: true,
this.$store.commit('viewaction/createdView', { viewtag: this.viewtag, secondtag: secondtag }); });
this.viewtag = secondtag;
// this.parseViewParam();
const _this: any = this;
// 获取父数据
// if (_this && _this.viewdata) {
// _this.parentData = JSON.parse(_this.viewdata);
// }
// if (_this.parentData && _this.parentData.sysrole) {
// // console.log("当前角色id:" + _this.parentData.sysrole);
// _this.srfparentkey = _this.parentData.sysrole;
// }
// 监听父页面
if(this.formDruipart){
this.formDruipart.subscribe((res:any) =>{
if(Object.is(res.action,'load')){
// 如果是新建角色保存,需要从res中获取父数据主键
if (res.data) {
let parentData = res.data;
this.srfparentkey = parentData.srfparentkey;
}
// 父数据保存时调用当前视图的事件
if(this.selectData.length>0){
// 选中了数据
this.onClickOk();
}else{
// 没选中数据
this.onClear();
}
}
});
}
}
/**
* vue 挂载
*/
public mounted() {
// this.initTree();
} }
}
/** }
* 初始化树 }
*/
private initTree() { /**
const _this = this; * vue 创建
// get全部菜单和数据能力和自定义资源的请求路径 */
const url = `sysroles/`+_this.srfparentkey+`/sysrolepermissions/tree`; public created() {
this.$http.get(url).then((response: any) => { this.afterCreated();
if (!response || response.status !== 200) { }
this.$Notice.error({title: '错误', desc: response.message});
return; /**
} else { * 执行created后的逻辑
// 给树赋值,数据结构在后台已经按照eltree格式化 *
_this.CDdata = response.data.APPMENU; * @memberof SYS_USER_ROLEGridViewBase
_this.QXdata = response.data.OPPRIV; */
_this.ZYdata = response.data.UNIRES; public afterCreated() {
_this.defaultCheckedNodes = response.data.SELECTED; const secondtag = this.$util.createUUID();
this.$store.commit("viewaction/createdView", {
// 设置默认第一级展开 viewtag: this.viewtag,
for (let i = 0; i < _this.CDdata.length; i++) { secondtag: secondtag,
_this.CDdataexpandedKeys.push(_this.CDdata[i].id); });
} this.viewtag = secondtag;
for (let i = 0; i < _this.QXdata.length; i++) { // this.parseViewParam();
_this.QXdataexpandedKeys.push(_this.QXdata[i].id);
} const _this: any = this;
for (let i = 0; i < _this.ZYdata.length; i++) { // 获取父数据
_this.ZYdataexpandedKeys.push(_this.ZYdata[i].id); // if (_this && _this.viewdata) {
} // _this.parentData = JSON.parse(_this.viewdata);
// }
// 设置默认选中节点,即当前角色所有权限 // if (_this.parentData && _this.parentData.sysrole) {
this.$nextTick(()=>{ // // console.log("当前角色id:" + _this.parentData.sysrole);
const CDtree: any = this.$refs.CDtree; // _this.srfparentkey = _this.parentData.sysrole;
const QXtree: any = this.$refs.QXtree; // }
const ZYtree: any = this.$refs.ZYtree;
// 监听父页面
CDtree.setCheckedNodes(_this.defaultCheckedNodes); if (this.formDruipart) {
QXtree.setCheckedNodes(_this.defaultCheckedNodes); this.formDruipart.subscribe((res: any) => {
ZYtree.setCheckedNodes(_this.defaultCheckedNodes); // 如果是新建角色保存,需要从res中获取父数据主键
if (!this.srfparentkey && res.data) {
// 保存初始选中的节点数据,便于后续保存时比较 let parentData = res.data;
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes()).concat(ZYtree.getCheckedNodes()); this.srfparentkey = parentData.srfparentkey;
this.ininselectData = arr;
});
}
}).catch((e) => {
console.log(e);
});
} }
// 父页面的保存前,先进行树数据的更新处理
/** if (Object.is(res.action, "save")) {
* 销毁之前 if (this.selectData.length > 0) {
* // 选中了数据
* @memberof SYS_ROLE_PERMISSIONCustomViewBase this.onClickOk();
*/ } else {
public beforeDestroy() { // 没选中数据
// 清空选中数据 this.onClear();
this.selectData = {}; }
// 清空视图选中数据
this.viewSelections = [];
this.$store.commit('viewaction/removeView', this.viewtag);
} }
});
}
/** }
* 处理选中节点
*/ /**
protected handleCheckChange() { * vue 挂载
// console.log("SYS_PERMISSIONMPickupView执行了handleCheckChange") */
// 获取当前三棵树 public mounted() {
// this.initTree();
}
/**
* 初始化树
*/
private initTree() {
const _this = this;
// get全部菜单和数据能力和自定义资源的请求路径
const url = `sysroles/` + _this.srfparentkey + `/sysrolepermissions/tree`;
this.$http
.get(url)
.then((response: any) => {
if (!response || response.status !== 200) {
this.$Notice.error({ title: "错误", desc: response.message });
return;
} else {
// 给树赋值,数据结构在后台已经按照eltree格式化
_this.CDdata = response.data.APPMENU;
_this.QXdata = response.data.OPPRIV;
_this.ZYdata = response.data.UNIRES;
_this.defaultCheckedNodes = response.data.SELECTED;
// 设置默认第一级展开
for (let i = 0; i < _this.CDdata.length; i++) {
_this.CDdataexpandedKeys.push(_this.CDdata[i].id);
}
for (let i = 0; i < _this.QXdata.length; i++) {
_this.QXdataexpandedKeys.push(_this.QXdata[i].id);
}
for (let i = 0; i < _this.ZYdata.length; i++) {
_this.ZYdataexpandedKeys.push(_this.ZYdata[i].id);
}
// 设置默认选中节点,即当前角色所有权限
this.$nextTick(() => {
const CDtree: any = this.$refs.CDtree; const CDtree: any = this.$refs.CDtree;
const QXtree: any = this.$refs.QXtree; const QXtree: any = this.$refs.QXtree;
const ZYtree: any = this.$refs.ZYtree; const ZYtree: any = this.$refs.ZYtree;
// 获取选中状态的节点
const arr = CDtree.getCheckedNodes().concat(QXtree.getCheckedNodes()).concat(ZYtree.getCheckedNodes());
this.selectData = arr;
// console.log("选中的node:" + JSON.stringify(this.selectData));
}
/** CDtree.setCheckedNodes(_this.defaultCheckedNodes);
* 容器模型 QXtree.setCheckedNodes(_this.defaultCheckedNodes);
*/ ZYtree.setCheckedNodes(_this.defaultCheckedNodes);
public containerModel: any = {
view_okbtn: {name: 'okbtn', type: 'button', text: '确定', disabled: true},
};
/**
* 确定
*/
public onClickOk(): void {
// 处理选中的数据
if (this.selectData && this.selectData.length > 0) {
// 判断选中的数据和初始数据
if (JSON.stringify(this.selectData) == JSON.stringify(this.ininselectData)) {
return;
}
this.selectData.forEach((item: any) => {
let _itemTemp: any = JSON.parse(JSON.stringify(item));
let _item: any = {};
if (_itemTemp.type) {
_item.permissionid = _itemTemp.id;
_item.permissiontype = _itemTemp.type;
_item.permissionname = _itemTemp.fullName;
Object.assign(_item, {_select: false})
this.viewSelections.push(_item);
}
});
// 保存选中的权限信息
let url = '/sysroles/'+this.srfparentkey+'/sysrolepermissions/refreshbatch';
this.$http.post(url,this.viewSelections).then((response: any) => {
if (!(!response || response.status !== 200)) {
} else {
this.$Notice.error({title: '错误', desc: response.message});
return;
}
}).catch((e) => {
});
}
// 清空视图选中数据,避免重复添加
this.viewSelections = [];
}
/**
* 清除
*/
private onClear(){
// 未选中数据,即没有赋予任何权限,需要清除当前角色的所有权限
if (this.selectData.length==0) {
// 保存选中的权限信息
let url = '/sysroles/'+this.srfparentkey+'/sysrolepermissions/refreshbatch';
this.$http.post(url,[]).then((response: any) => {
if (!(!response || response.status !== 200)) {
} else {
this.$Notice.error({title: '错误', desc: response.message});
return;
}
}).catch((e) => {
});
}
// 保存初始选中的节点数据,便于后续保存时比较
const arr = CDtree.getCheckedNodes()
.concat(QXtree.getCheckedNodes())
.concat(ZYtree.getCheckedNodes());
this.ininselectData = arr;
});
}
})
.catch((e) => {
console.log(e);
});
}
/**
* 销毁之前
*
* @memberof SYS_ROLE_PERMISSIONCustomViewBase
*/
public beforeDestroy() {
// 清空选中数据
this.selectData = {};
// 清空视图选中数据
this.viewSelections = [];
this.$store.commit("viewaction/removeView", this.viewtag);
}
/**
* 处理选中节点
*/
protected handleCheckChange() {
// console.log("SYS_PERMISSIONMPickupView执行了handleCheckChange")
// 获取当前三棵树
const CDtree: any = this.$refs.CDtree;
const QXtree: any = this.$refs.QXtree;
const ZYtree: any = this.$refs.ZYtree;
// 获取选中状态的节点
const arr = CDtree.getCheckedNodes()
.concat(QXtree.getCheckedNodes())
.concat(ZYtree.getCheckedNodes());
this.selectData = arr;
// console.log("选中的node:" + JSON.stringify(this.selectData));
}
/**
* 容器模型
*/
public containerModel: any = {
view_okbtn: { name: "okbtn", type: "button", text: "确定", disabled: true },
};
/**
* 确定
*/
public onClickOk(): void {
// 处理选中的数据
if (this.selectData && this.selectData.length > 0) {
// 判断选中的数据和初始数据
if (
JSON.stringify(this.selectData) == JSON.stringify(this.ininselectData)
) {
return;
}
this.selectData.forEach((item: any) => {
let _itemTemp: any = JSON.parse(JSON.stringify(item));
let _item: any = {};
if (_itemTemp.type) {
_item.permissionid = _itemTemp.id;
_item.permissiontype = _itemTemp.type;
_item.permissionname = _itemTemp.fullName;
Object.assign(_item, { _select: false });
this.viewSelections.push(_item);
} }
});
// 保存选中的权限信息
let url =
"/sysroles/" + this.srfparentkey + "/sysrolepermissions/refreshbatch";
this.$http
.post(url, this.viewSelections)
.then((response: any) => {
if (!response || response.status !== 200) {
return this.$Notice.error({
title: "错误",
desc: response.message,
});
} else {
// 抛出事件,通知父页面进行表单保存
return this.$emit("drdatasaved", {});
}
})
.catch((e) => {
return this.$Notice.error({ title: "错误", desc: e });
});
}
// 清空视图选中数据,避免重复添加
this.viewSelections = [];
}
/**
* 清除
*/
private onClear() {
// 未选中数据,即没有赋予任何权限,需要清除当前角色的所有权限
if (this.selectData.length == 0) {
// 保存选中的权限信息
let url =
"/sysroles/" + this.srfparentkey + "/sysrolepermissions/refreshbatch";
this.$http
.post(url, [])
.then((response: any) => {
if (!response || response.status !== 200) {
return this.$Notice.error({
title: "错误",
desc: response.message,
});
} else {
// 抛出事件,通知父页面进行表单保存
return this.$emit("drdatasaved", {});
}
})
.catch((e) => {
return this.$Notice.error({ title: "错误", desc: e });
});
} }
}
}
</script> </script>
<style lang='less'> <style lang='less'>
@import './sys-role-permission-custom-view'; @import "./sys-role-permission-custom-view";
</style> </style>
\ No newline at end of file
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
:localParam ='{}' :localParam ='{}'
parameterName='sysrole' parameterName='sysrole'
parentName="SysRole" parentName="SysRole"
refviewtype='DECUSTOMVIEW' refviewtype='DEMEDITVIEW9'
refreshitems='' refreshitems=''
:ignorefieldvaluechange="ignorefieldvaluechange" :ignorefieldvaluechange="ignorefieldvaluechange"
viewname='sys-role-permission-custom-view' viewname='sys-role-permission-custom-view'
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册