提交 e74dc6ef 编写于 作者: tony001's avatar tony001

add:新增上下文、视图参数处理

上级 e754676d
......@@ -10,10 +10,10 @@
:context="state.context"
:viewParams="state.viewParams"
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
{{#if item.psEditor.psAppDataEntity}}
{{!-- deMajorField="getDeMajorField({{item.psEditor.psAppDataEntity.codeName}})" --}}
......
......@@ -13,10 +13,10 @@
valueSeparator="{{item.psEditor.codeList.valueSeparator}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
:context="state.context"
:viewParams="state.viewParams"
......
......@@ -11,10 +11,10 @@
disabled="{{item.psEditor.disabled}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
:context="state.context"
:viewParams="state.viewParams"
......
......@@ -11,10 +11,10 @@
disabled="{{item.psEditor.disabled}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
:context="state.context"
:viewParams="state.viewParams"
......
......@@ -16,10 +16,10 @@
:multiple="{{item.psEditor.editorParams.multiple}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
{{#eq item.psEditor.editorType "MDROPDOWNLIST"}}
:multiple="true"
......
......@@ -13,10 +13,10 @@
:readonly="{{item.psEditor.isReadOnly}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
:context="state.context"
:viewParams="state.viewParams"
......
......@@ -17,10 +17,10 @@
:precision="{{item.psEditor.precision}}"
{{/if}}
{{#if item.psEditor.psNavigateContexts}}
localContext="{{item.psEditor.psNavigateContexts}}"
localContext="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateContexts}}"
{{/if}}
{{#if item.psEditor.psNavigateParams}}
localParam="{{item.psEditor.psNavigateParams}}"
localParam="{{> @macro/front-end/common/navparam.hbs appNavParams=item.psEditor.psNavigateParams}}"
{{/if}}
{{#if (or (eq ctrlType 'form') (eq ctrlType 'panel'))}}
:value="state.data.{{item.psEditor.name}}"
......
{ {{#appNavParams}}'{{lowerCase getKey}}':{{#if (eq isRawValue true)}}'{{lowerCase getValue}}'{{else}}'%{{lowerCase getValue}}%'{{/if}}{{#unless @last}},{{/unless}}{{/appNavParams}} }
\ No newline at end of file
......@@ -14,6 +14,8 @@
showCaptionBar: '{{page.viewStyle}}',
xDataControlName:'{{page.xDataControlName}}',
openDataViewName:'ExampleEditorEditView',
appViewNavContexts:{{> @macro/front-end/common/navparam.hbs appNavParams=page.psAppViewNavContexts}},
appViewNavParams:{{> @macro/front-end/common/navparam.hbs appNavParams=page.getPSAppViewNavParams}},
viewToolbarModel: [
{{#page.viewToolBarItems}}
{{#items}}
......
import { Ref } from 'vue';
import { useRoute } from 'vue-router';
import { ViewPropsBase, ViewStateBase, UIBase, IParam } from '@core';
import { ViewPropsBase, ViewStateBase, UIBase, IParam, UIUtil } from '@core';
/**
* @description 视图基类
......@@ -8,7 +8,7 @@ import { ViewPropsBase, ViewStateBase, UIBase, IParam } from '@core';
* @class ViewBase
*/
export class ViewBase {
/**
* @description 视图状态
* @type {ViewStateBase}
......@@ -44,27 +44,48 @@ export class ViewBase {
* @param viewParams 视图参数
*/
public handleViewContextParams(props: ViewPropsBase, context: Ref<IParam | undefined>, viewParams: Ref<IParam | undefined>) {
if (!context.value) context.value = {};
if (!viewParams.value) viewParams.value = {};
if (Object.is(props.openType, 'ROUTE')) {
const appContext = {};
Object.assign(context.value, appContext);
const pageContext = useRoute().params;
Object.assign(context.value, pageContext);
const pageCustomContext = {};
Object.assign(context.value, pageCustomContext);
console.log(context);
const pageViewParams = useRoute().query;
Object.assign(viewParams.value, pageViewParams);
const pageCustomViewParams = {};
Object.assign(viewParams.value, pageCustomViewParams);
console.log(viewParams);
} else {
const customContext = {};
Object.assign(context.value, customContext);
const pageCustomViewParams = {};
Object.assign(viewParams.value, pageCustomViewParams);
if (!context.value) context.value = {};
if (!viewParams.value) viewParams.value = {};
if (Object.is(props.openType, 'ROUTE')) {
// 应用上下文
const appContext = App.getAppData();
Object.assign(context.value, appContext);
// 视图应用上下文
const pageContext = {};
const routeParams = useRoute().params;
if (routeParams && (Object.keys(routeParams).length > 0)) {
Object.keys(routeParams).forEach((key: string) => {
if (routeParams[key]) {
Object.assign(pageContext, { [key]: decodeURIComponent(routeParams[key] as string) });
}
})
}
Object.assign(context.value, pageContext);
// 视图参数
const pageViewParams = {};
const routeQuerys = useRoute().query;
if (routeQuerys && (Object.keys(routeQuerys).length > 0)) {
Object.keys(routeQuerys).forEach((key: string) => {
if (routeQuerys[key]) {
Object.assign(pageViewParams, { [key]: routeQuerys[key] });
}
})
}
Object.assign(viewParams.value, pageViewParams);
// 视图自定义应用上下文
const pageCustomContext = UIUtil.computedNavData(null, context.value, viewParams.value, this.viewState.appViewNavContexts);
Object.assign(context.value, pageCustomContext);
// 视图自定义视图参数
const pageCustomViewParams = UIUtil.computedNavData(null, context.value, viewParams.value, this.viewState.appViewNavParams);
Object.assign(viewParams.value, pageCustomViewParams);
} else {
// 视图自定义应用上下文
const customContext = UIUtil.computedNavData(null, context.value, viewParams.value, this.viewState.appViewNavContexts);
Object.assign(context.value, customContext);
// 视图自定义视图参数
const pageCustomViewParams = UIUtil.computedNavData(null, context.value, viewParams.value, this.viewState.appViewNavParams);
Object.assign(viewParams.value, pageCustomViewParams);
}
}
/**
......@@ -79,7 +100,7 @@ export class ViewBase {
// 导航视图参数处理
this.handleViewContextParams(props, context, viewParams);
watch(context, (newVal: any, oldVal: any) => {
this.handleViewContextParams(props, newVal,viewParams);
this.handleViewContextParams(props, newVal, viewParams);
});
// 把Ref赋值到State上进行解包
this.viewState.context = context;
......@@ -92,7 +113,7 @@ export class ViewBase {
* @param {ViewPropsBase} props 传入参数
* @memberof ViewBase
*/
public useCounterService(props: ViewPropsBase){}
public useCounterService(props: ViewPropsBase) { }
/**
* @description 安装视图所有功能模块的方法
......
......@@ -7,7 +7,7 @@ import { IActionParam, IParam } from '@core';
* @interface ViewStateBase
*/
export interface ViewStateBase {
/**
* @description 视图名称
* @type {string}
......@@ -50,6 +50,22 @@ export interface ViewStateBase {
*/
viewToolbarModel: IParam[];
/**
* 自定义视图导航上下文
*
* @type {IParam}
* @memberof ViewStateBase
*/
appViewNavContexts: IParam;
/**
* 自定义视图参数
*
* @type {IParam}
* @memberof ViewStateBase
*/
appViewNavParams: IParam;
// 声明任意属性
[propName: string]: any;
}
......@@ -77,7 +77,6 @@ export class Interceptors {
if (!Object.is(Environment.BaseUrl, "") && !config.url.startsWith('https://') && !config.url.startsWith('http://') && !config.url.startsWith('./assets')) {
config.url = Environment.BaseUrl + config.url;
}
console.log(config);
return config;
}, (error: any) => {
return Promise.reject(error);
......
......@@ -60,15 +60,15 @@ export class UIUtil {
/**
* @description 计算导航数据
* 先从当前数据目标计算,然后再从当前上下文计算,最后从当前视图参数计算,没有则为null
* 先从当前激活数据计算,然后再从当前上下文计算,最后从当前视图参数计算,没有则为null
* @export
* @param {*} data 当前数据目标
* @param {*} parentContext 当前上下文
* @param {*} parentParam 当前视图参数
* @param {*} activedata 当前激活数据
* @param {*} context 当前上下文
* @param {*} viewParam 当前视图参数
* @param {*} params 导航参数
* @return {*}
*/
public static computedNavData(data: any, parentContext: any, parentParam: any, params: any): any {
public static computedNavData(activedata: any, context: any, viewParam: any, params: any): any {
const _data: any = {};
if (params && Object.keys(params).length > 0) {
Object.keys(params).forEach((name: string) => {
......@@ -78,12 +78,12 @@ export class UIUtil {
let value: string | null = params[name];
if (value && value.toString().startsWith('%') && value.toString().endsWith('%')) {
const key = value.substring(1, value.length - 1).toLowerCase();
if (data && data.hasOwnProperty(key)) {
value = data[key];
} else if (parentContext && parentContext[key]) {
value = parentContext[key];
} else if (parentParam && parentParam[key]) {
value = parentParam[key];
if (activedata && activedata.hasOwnProperty(key)) {
value = activedata[key];
} else if (context && context[key]) {
value = context[key];
} else if (viewParam && viewParam[key]) {
value = viewParam[key];
} else {
value = null;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册