提交 63e0ab96 编写于 作者: WodahsOrez's avatar WodahsOrez

update: open-view-service

上级 9e083037
......@@ -38,6 +38,7 @@ public class AppModel extends BaseModel{
if(getApplication().getAllPSAppDataEntities()!=null)
{
getApplication().getAllPSAppDataEntities().forEach(appDataEntity ->{
if(appDataEntity.getMinorPSAppDERSs() != null){
appDataEntity.getMinorPSAppDERSs().forEach(appDERS ->{
JSONObject tempObj = new JSONObject();
......@@ -59,6 +60,41 @@ public class AppModel extends BaseModel{
}
});
}
// 初始化应用实体关系数据Set
if(getApplication().getAllPSAppDataEntities()!=null){
getApplication().getAllPSAppDataEntities().forEach(appDataEntity ->{
JSONObject tempObj = new JSONObject();
tempObj.put("appDataEntity",appDataEntity);
if(appDataEntity.getMinorPSAppDERSs() != null){
List deResLinks = new ArrayList<JSONObject>();
appDataEntity.getMinorPSAppDERSs().forEach(appDERS ->{
JSONObject deResLink = new JSONObject();
String majorCodeName = appDERS.getMajorPSAppDataEntity().getCodeName();
String minorCodeName = appDERS.getMinorPSAppDataEntity().getCodeName();
String path = String.format("%1$s/:%2$s?/%3$s/:%4$s?",Inflector.getInstance().pluralize(majorCodeName),majorCodeName,Inflector.getInstance().pluralize(minorCodeName),minorCodeName).toLowerCase();
deResLink.put("majorCodeName",majorCodeName.toLowerCase());
deResLink.put("path",path);
// 路由关系参数数组
List deResParameters = new ArrayList();
JSONObject majorResObj = new JSONObject();
majorResObj.put("pathName", Inflector.getInstance().pluralize(majorCodeName).toLowerCase());
majorResObj.put("parameterName", majorCodeName.toLowerCase());
deResParameters.add(majorResObj);
JSONObject minorResObj = new JSONObject();
minorResObj.put("pathName", Inflector.getInstance().pluralize(minorCodeName).toLowerCase());
minorResObj.put("parameterName", minorCodeName.toLowerCase());
deResParameters.add(minorResObj);
deResLink.put("deResParameters", deResParameters);
deResLinks.add(deResLink);
});
tempObj.put("deResLinks", deResLinks);
}else{
tempObj.put("path",String.format("%1$s/:%2$s?",Inflector.getInstance().pluralize(appDataEntity.getCodeName()),appDataEntity.getCodeName()).toLowerCase());
}
appDeResSet.add(tempObj);
});
}
}
......@@ -109,6 +145,11 @@ public class AppModel extends BaseModel{
*/
private Map<String, JSONObject> appEntityResourceMap =new LinkedHashMap<>();
/**
* 应用实体关系对象Set
*/
private Set<JSONObject> appDeResSet =new HashSet<>();
/**
* 获取应用实体资源数据
* @return
......
export * from './control-service'
export * from './entity'
\ No newline at end of file
export * from './entity'
export * from './singleton'
\ No newline at end of file
/**
* 单例基类
*
* @export
* @class Singleton
*/
export class Singleton{
/**
* 唯一实例
*
* @private
* @static
* @memberof Singleton
*/
private static readonly instance = new Singleton();
/**
* 获取唯一实例
*
* @static
* @return {*} {Singleton}
* @memberof Singleton
*/
public static getInstance(): Singleton {
return Singleton.instance;
}
}
\ No newline at end of file
export * from './util';
export * from './view-util';
export * from './view-tool';
export { Http } from './net/http';
\ No newline at end of file
import { useRoute } from 'vue-router';
import { notEmpty } from '@ibiz-core';
import qs from 'qs';
/**
* 路由相关处理逻辑工具类
*
* @export
* @class RouteTool
*/
export class RouteTool {
/**
* 处理路由路径
*
* @static
* @param {Route} route 路由
* @param {*} [viewParam={}]
* @param {any[]} deResParameters 关系实体参数对象
* @param {any[]} parameters 当前应用视图参数对象
* @param {any[]} args 多项数据
* @param {*} data 行为参数
* @returns {string}
* @memberof RouteTool
*/
/**
* 处理路由路径
* @static
* @param view 视图信息
* @param context 上下文
* @param viewParams 视图参数
* @return {*}
*/
public static buildUpRoutePath(view: any, context: any, viewParams: any): string {
const route = useRoute()
const { deResLinks, parameters } = view;
const deResParameters = deResLinks[0];
const indexRoutePath = this.getIndexRoutePath(route);
const deResRoutePath = this.getDeResRoutePath(context, deResParameters);
const deRoutePath = this.getActiveRoutePath(parameters, context, viewParams);
return `${indexRoutePath}${deResRoutePath}${deRoutePath}`;
}
/**
* 获取首页根路由路径
*
* @static
* @param {Route} route 路由对象
* @returns {string}
* @memberof RouteTool
*/
public static getIndexRoutePath(route: any): string {
const { parameters: _parameters }: { parameters: any[] } = route.meta;
const { pathName: _pathName, parameterName: _parameterName }: { pathName: string, parameterName: string } = _parameters[0];
const param = route.params[_parameterName];
if (notEmpty(param)) {
return `/${_parameterName}/${param}`;
}
return `/${_parameterName}`;
}
/**
* 获取关系实体路径
*
* @static
* @param {*} [viewParam={}] 视图上下文
* @param {any[]} deResParameters 关系实体参数对象数组
* @returns {string}
* @memberof RouteTool
*/
public static getDeResRoutePath(context: any = {}, deResParameters: any[]): string {
let routePath: string = '';
if (deResParameters && deResParameters.length > 0) {
deResParameters.forEach(({ pathName, parameterName }: { pathName: string, parameterName: string }) => {
let value: any = null;
if (context[parameterName] && !Object.is(context[parameterName], '') && !Object.is(context[parameterName], 'null')) {
value = context[parameterName];
}
routePath = `${routePath}/${pathName}` + (notEmpty(value) ? `/${value}` : '');
});
}
return routePath;
}
/**
* 当前激活路由路径
*
* @static
* @param parameters 当前视图参数对象
* @param context 视图上下文
* @param [viewParams={}] 视图参数
* @return {*}
*/
public static getActiveRoutePath(parameters: any[], context: any, viewParams: any = {}): string {
let routePath: string = '';
if (parameters && parameters.length > 0) {
// 不存在应用实体
if (parameters.length === 1) {
const [{ parameterName }] = parameters;
routePath = `/views/${parameterName}`;
if (Object.keys(viewParams).length > 0) {
routePath = `${routePath}?${qs.stringify(viewParams, { delimiter: ';' })}`;
}
} else if (parameters.length === 2) {
let [arg] = args;
arg = arg ? arg : {};
const [{ pathName: _pathName, parameterName: _parameterName }, { pathName: _pathName2, parameterName: _parameterName2 }] = parameters;
const _value: any = context[_parameterName] || null;
routePath = `/${_pathName}${notEmpty(_value) ? `/${_value}` : ''}/views/${_parameterName2}`;
if (Object.keys(viewParams).length > 0) {
routePath = `${routePath}?${qs.stringify(viewParams, { delimiter: ';' })}`;
}
}
}
return routePath;
}
/**
* 格式化路由参数
*
* @static
* @param {*} params
* @returns {*}
* @memberof RouteTool
*/
public static formatRouteParams(params: any, route: any, context: any, viewparams: any): void {
Object.keys(params).forEach((key: string, index: number) => {
const param: string | null | undefined = params[key];
if (!param || Object.is(param, '') || Object.is(param, 'null')) {
return;
}
if (param.indexOf('=') > 0) {
const _param = qs.parse(param, { delimiter: ';' });
Object.assign(context, _param);
} else {
Object.assign(context, { [key]: param });
}
});
if (route && route.fullPath && route.fullPath.indexOf("?") > -1) {
const _viewparams: any = route.fullPath.slice(route.fullPath.indexOf("?") + 1);
const _viewparamArray: Array<string> = decodeURIComponent(_viewparams).split(";")
if (_viewparamArray.length > 0) {
_viewparamArray.forEach((item: any) => {
Object.assign(viewparams, qs.parse(item));
})
}
}
}
/**
* 首页路由结构参数
*
* @private
* @static
* @type {any[]}
* @memberof RouteTool
*/
private static indexParameters: any[] = [];
/**
* 设置首页路由结构参数
*
* @static
* @param {any[]} parameters
* @memberof RouteTool
*/
public static setIndexParameters(parameters: any[]): void {
this.indexParameters = [...parameters]
}
/**
* 获取首页路由结构参数
*
* @static
* @returns {any[]}
* @memberof RouteTool
*/
public static getIndexParameters(): any[] {
return this.indexParameters;
}
/**
* 首页视图参数
*
* @static
* @type {*}
* @memberof RouteTool
*/
public static indexViewParam: any = {};
/**
* 设置首页视图参数
*
* @static
* @param {*} [viewParam={}]
* @memberof RouteTool
*/
public static setIndexViewParam(viewParam: any = {}): void {
Object.assign(this.indexViewParam, viewParam);
}
/**
* 获取首页视图参数
*
* @static
* @returns {*}
* @memberof RouteTool
*/
public static getIndexViewParam(): any {
return this.indexViewParam;
}
/**
* 计算界面行为项权限状态
*
* @static
* @param {*} [data] 传入数据
* @param {*} [ActionModel] 界面行为模型
* @param {*} [UIService] 界面行为服务
* @memberof RouteTool
*/
public static calcActionItemAuthState(data: any, ActionModel: any, UIService: any) {
let result: any[] = [];
if (!UIService)
return;
for (const key in ActionModel) {
if (!ActionModel.hasOwnProperty(key)) {
return result;
}
const _item = ActionModel[key];
let dataActionResult: any;
if (_item && _item['dataAccessAction']) {
if (Object.is(_item['actionTarget'], "NONE") || Object.is(_item['actionTarget'], "")) {
dataActionResult = UIService.getAllOPPrivs(undefined, _item['dataAccessAction']);
} else {
if (data && Object.keys(data).length > 0) {
dataActionResult = UIService.getAllOPPrivs(data, _item['dataAccessAction']);
}
}
} else {
dataActionResult = 1;
}
// 无权限:0;有权限:1
if (dataActionResult === 0) {
// 禁用:1;隐藏:2;隐藏且默认隐藏:6
if (_item.getNoPrivDisplayMode === 1) {
_item.disabled = true;
}
if ((_item.getNoPrivDisplayMode === 2) || (_item.getNoPrivDisplayMode === 6)) {
_item.visabled = false;
} else {
_item.visabled = true;
}
}
if (dataActionResult === 1) {
_item.visabled = true;
_item.disabled = false;
}
// 返回权限验证的结果
_item.dataActionResult = dataActionResult;
result.push(dataActionResult);
}
return result;
}
/**
* 计算界面行为项权限状态(树节点版本)
*
* @static
* @param {*} [data] 传入数据
* @param {*} [ActionModel] 界面行为模型
* @param {*} [UIService] 界面行为服务
* @memberof RouteTool
*/
public static calcTreeActionItemAuthState(data: any, ActionModel: any, UIService: any) {
let result: any[] = [];
if (!UIService)
return;
for (const key in ActionModel) {
if (!ActionModel.hasOwnProperty(key)) {
return result;
}
const _item = ActionModel[key];
let dataActionResult: any;
if (Object.is(_item['actiontarget'], "NONE") || Object.is(_item['actiontarget'], "")) {
dataActionResult = UIService.getAllOPPrivs(undefined, _item['dataaccaction']);
} else {
if (_item && _item['dataaccaction'] && UIService.isEnableDEMainState) {
if (data && Object.keys(data).length > 0) {
dataActionResult = UIService.getAllOPPrivs(data, _item['dataaccaction']);
}
}
}
// 无权限:0;有权限:1
if (dataActionResult === 0) {
// 禁用:1;隐藏:2;隐藏且默认隐藏:6
if (_item.noprivdisplaymode === 1) {
_item.disabled = true;
}
if ((_item.noprivdisplaymode === 2) || (_item.noprivdisplaymode === 6)) {
_item.visabled = false;
} else {
_item.visabled = true;
}
}
if (dataActionResult === 1) {
_item.visabled = true;
_item.disabled = false;
}
// 返回权限验证的结果
_item.dataActionResult = dataActionResult;
result.push(dataActionResult);
}
return result;
}
/**
* 计算重定向上下文
*
* @static
* @param {*} [tempContext] 上下文
* @param {*} [data] 传入数据
* @param {*} [redirectAppEntity] 应用实体对象
* @memberof RouteTool
*/
public static async calcRedirectContext(tempContext: any, data: any, redirectAppEntity: any) {
if (redirectAppEntity && redirectAppEntity.getMinorPSAppDERSs() && ((redirectAppEntity.getMinorPSAppDERSs() as []).length > 0)) {
for (const item of redirectAppEntity.getMinorPSAppDERSs()) {
const parentPSAppDEFieldCodeName: string = item.M.getParentPSAppDEField?.codeName;
if (parentPSAppDEFieldCodeName) {
const curData: any = data;
if (curData && curData[parentPSAppDEFieldCodeName.toLowerCase()]) {
const majorAppEntity: any = item.getMajorPSAppDataEntity();
await majorAppEntity.fill();
if (!tempContext[majorAppEntity.codeName.toLowerCase()]) {
Object.assign(tempContext, { [majorAppEntity.codeName.toLowerCase()]: curData[parentPSAppDEFieldCodeName.toLowerCase()] });
}
}
}
}
}
}
}
\ No newline at end of file
......@@ -20,6 +20,16 @@ export function isExist(arg: any): boolean{
return arg !== undefined && arg !== null && arg === arg;
}
/**
* @description 除undefined,null,NaN,空字符串以外都为true
* @export
* @param {*} arg
* @return {*} {boolean}
*/
export function notEmpty(arg: any): boolean{
return isExist(arg) && arg != '';
}
/**
* @description 是否拥有某个方法
* @param {*} arg 校验对象
......
import { deepCopy, IParam, Singleton, RouteTool } from "@ibiz-core";
import { useRouter } from "vue-router";
const allViews= require('./views.json')
interface View extends IParam{
codeName: string,
openMode ?: string,
}
interface Params extends IParam{
context: any,
viewParams: any,
}
/**
* 视图打开服务
* @export
* @class OpenViewService
*/
export class OpenViewService extends Singleton{
/**
* 打开视图
*
* @param view 视图信息
* @param params 相关参数
*/
public openView(view: View, params: Params){
// 获取详细视图信息
let _view: any = allViews[view.codeName];
if(!_view){
console.error(`应用中不存在${view.codeName}视图`);
return
}
// 拷贝防污染,view的openMode覆盖配置的
_view = deepCopy(_view);
if(view.openMode){
_view.openMode = view.openMode;
}
// 重定向视图走重定向逻辑,其他根据openMode打开
if(_view.redirectView){
this.openRedirectView(_view, params);
}else{
this.openByOpenMode(_view, params)
}
}
/**
* 根据打开方式打开视图
*
* @param view 视图信息
* @param params 相关参数
*/
public openByOpenMode(view: any, params: Params){
const { openMode } = view;
const { viewParams, context } = params
// 路由打开视图
if(openMode == 'INDEXVIEWTAB' || openMode == 'POPUPAPP'){
// TODO 视图关系参数处理
const router = useRouter();
const routePath = RouteTool.buildUpRoutePath(view, context,viewParams);
if(openMode == 'INDEXVIEWTAB'){
router.push(routePath);
}else{
window.open('./#' + routePath, '_blank');
}
}else if(openMode == 'POPUPMODAL'){
}else if(openMode.indexOf('DRAWER') !== -1){
// TODO PMS上面抽屉DRAWER_TOP
}else if(openMode == 'POPOVER'){
// TODO 打开气泡卡片
}else{
console.error(`未支持${openMode}打开方式`);
}
}
/**
* 重定向视图处理
*
* @param view 视图信息
* @param params 相关参数
*/
public openRedirectView(view: any, params: Params){
// TODO 重定向视图处理
}
}
\ No newline at end of file
{{!-- {
{{#each app.appEntityResources as |appEntityResource|}}
{{#if appEntityResource.appDataEntity.allPSAppViews}}
{{#each appEntityResource.appDataEntity.allPSAppViews as |appView|}}
"{{appView.codeName}}":{
"name": "{{appView.name}}",
"codeName": "{{appView.codeName}}",
"openMode": "{{#if appView.openMode}}{{appView.openMode}}{{else}}INDEXVIEWTAB{{/if}}",
"redirectView": {{appView.redirectView}},
"path": "{{appEntityResource.path}}/views/{{lowerCase appView.codeName}}",
{{#if appView.capPSLanguageRes}}
"captionTag": "{{appView.capPSLanguageRes.lanResTag}}",
{{/if}}
"caption": "{{appView.caption}}",
{{#if appView.psSysImage}}
"imgPath": "{{appView.psSysImage.imagePath}}",
"iconCls": "{{appView.psSysImage.cssClass}}",
{{/if}}
"viewType": "{{appView.viewType}}",
"fileDir": "@page/{{#if psAppDataEntity}}{{spinalCase psAppDataEntity.codeName}}{{else}}default{{/if}}/{{spinalCase appView.codeName}}"
}{{#unless (and @last ../@last)}},{{/unless}}
{{/each}}
{{/if}}
{{/each}}
} --}}
{
{{#each app.appDeResSet as |appDeRes|}}
{{#if appDeRes.deResLinks}}
{{#each appDeRes.appDataEntity.allPSAppViews as |appView|}}
"{{appView.codeName}}":{
"name": "{{appView.name}}",
"codeName": "{{appView.codeName}}",
"openMode": "{{#if appView.openMode}}{{appView.openMode}}{{else}}INDEXVIEWTAB{{/if}}",
"redirectView": {{appView.redirectView}},
"deResLinks": [
{{#each appDeRes.deResLinks as |deResLink| }}
[
{{#each deResLink.deResParameters as |deResParameter| }}
{ "pathName": "{{deResParameter.pathName}}", "parameterName": "{{deResParameter.parameterName}}" }{{#unless @last}},{{/unless}}
{{/each}}
]{{#unless @last}},{{/unless}}
{{/each}}
],
"parameters": [
{{#if appDeRes.appDataEntity}}
{ "pathName": "{{pluralize appDeRes.appDataEntity.codeName}}", "parameterName": "{{appDeRes.appDataEntity.codeName}}" },
{{/if}}
{ "pathName": "views", "parameterName": "{{lowerCase appView.codeName}}" }
],
{{#if appView.capPSLanguageRes}}
"captionTag": "{{appView.capPSLanguageRes.lanResTag}}",
{{/if}}
"caption": "{{appView.caption}}",
{{#if appView.psSysImage}}
"imgPath": "{{appView.psSysImage.imagePath}}",
"iconCls": "{{appView.psSysImage.cssClass}}",
{{/if}}
"viewType": "{{appView.viewType}}",
"fileDir": "@page/{{#if psAppDataEntity}}{{spinalCase psAppDataEntity.codeName}}{{else}}default{{/if}}/{{spinalCase appView.codeName}}"
}{{#unless (and @last ../@last)}},{{/unless}}
{{/each}}
{{/if}}
{{/each}}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册