提交 d16a65f2 编写于 作者: zcdtk's avatar zcdtk

视图参数处理方法优化

上级 36740bcb
......@@ -279,32 +279,33 @@ export class ViewTool {
}
/**
* 解析视图数据
* 视图参数处理
*
* @returns {{ context: {}, viewparams: {} }}
* @param {*} view
* @param {boolean} isPSDEView
* @returns {{ context: {}, param: {} }} 返回处理后直接可用的上下文和参数对象
* @memberof ViewTool
*/
public parseViewData(view: any, isPSDEView: boolean): { context: {}, viewparams: {} } {
let data = { context: {}, viewparams: {} };
public formatNavigateViewParam(view: any, isPSDEView: boolean): { context: {}, param: {} } {
let _context: any = {}, _param: any = {};
// 合并全局上下文
const { context, param } = view.$store.getters.getAppData();
if (context && Object.keys(context).length > 0) {
data.context = { ...context };
_context = { ...context };
}
// 合并全局参数
if (param && Object.keys(param).length > 0) {
data.viewparams = { ...param };
_param = { ...param };
}
let _context: any = {}, _viewparams: any = {};
if (!view.viewDefaultUsage) {
// 视图模态或者嵌入打开
if (view._context && !Object.is(view._context, '')) {
_context = { ...JSON.parse(view._context) };
_context = { ..._context, ...JSON.parse(view._context) };
}
if (view._viewparams && !Object.is(view._viewparams, '')) {
_viewparams = { ...JSON.parse(view._viewparams) };
_param = { ..._param, ...JSON.parse(view._viewparams) };
}
} else {
// 视图路由打开
......@@ -320,82 +321,16 @@ export class ViewTool {
});
if (view.$route && view.$route.fullPath && view.$route.fullPath.indexOf("?") > -1) {
const viewParamStr = view.$route.fullPath.slice(view.$route.fullPath.indexOf("?") + 1);
_viewparams = { ...qs.parse(viewParamStr, { delimiter: '&' }) };
_param = { ..._param, ...qs.parse(viewParamStr, { delimiter: '&' }) };
}
}
// 合并视图上下文
data.context = { ...data.context, ..._context };
// 合并视图参数
data.viewparams = { ...data.viewparams, ..._viewparams };
this.parseViewNavData(data, view.navContext, view.navParam);
let data = this.formatNavigateParam(view.navContext, view.navParam, _context, _param, {});
if (isPSDEView) {
data.context = { ...data.context, ...{ srfsessionid: Util.createUUID() } };
Object.assign(data.context, { srfsessionid: Util.createUUID() });
}
return data;
}
/**
* 动态视图导航数据
*
* @private
* @param {({ context: any | {}, viewparams: any | {} })} data
* @param {*} [navContext={}]
* @param {*} [navParam={}]
* @memberof ViewTool
*/
private parseViewNavData(data: { context: any | {}, viewparams: any | {} }, navContext: any = {}, navParam: any = {}): void {
Object.keys(navContext).forEach((name: any) => {
if (!name) {
return;
}
let value: any = navContext[name];
// 配置值置空,去掉属性
if (data.context.hasOwnProperty(name) && (this.isNull(value) || this.isUndefined(value))) {
delete data.context[name];
return;
}
if (value.startsWith('%') && value.endsWith('%')) {
const key: string = value.slice(1, -1);
let has_value: boolean = false;
if (data.context.hasOwnProperty(key)) {
has_value = true;
value = data.context[key];
delete data.context[name];
}
if (!has_value) {
return;
}
}
Object.assign(data.context, { [name]: value });
});
Object.keys(navParam).forEach((name: any) => {
if (!name) {
return;
}
let value: any = navParam[name];
// 配置值置空,去掉属性
if (data.viewparams.hasOwnProperty(name) && (this.isNull(value) || this.isUndefined(value))) {
delete data.viewparams[name];
return;
}
if (value.startsWith('%') && value.endsWith('%')) {
const key: string = value.slice(1, -1);
let has_value: boolean = false;
if (data.viewparams.hasOwnProperty(key)) {
has_value = true;
value = data.viewparams[key];
delete data.viewparams[name];
}
if (!has_value) {
return;
}
}
Object.assign(data.viewparams, { [name]: value });
});
}
}
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册