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

update:更新

上级 8aaf05fe
...@@ -2,9 +2,10 @@ import { SyncSeriesHook } from "qx-util"; ...@@ -2,9 +2,10 @@ import { SyncSeriesHook } from "qx-util";
import { Environment } from "@/environments/environment"; import { Environment } from "@/environments/environment";
import router from "@/router"; import router from "@/router";
import { OpenViewService } from "@/utils"; import { OpenViewService } from "@/utils";
import { AppBase, IParam, ViewDetail, IApp, IOpenViewService, deepCopy, getSessionStorage, Http, AppUtil } from "@core"; import { AppBase, IParam, ViewDetail, IApp, IOpenViewService, deepCopy, Http, IAppAuthService } from "@core";
import { AppFuncConfig, AppViewConfig, AppEntityConfig } from './config'; import { AppFuncConfig, AppViewConfig, AppEntityConfig } from './config';
import { DataServiceRegister, UIServiceRegister } from "./register"; import { DataServiceRegister, UIServiceRegister } from "./register";
import { AppAuthService } from "./service/app-auth-service";
export class App extends AppBase implements IApp { export class App extends AppBase implements IApp {
...@@ -50,31 +51,14 @@ export class App extends AppBase implements IApp { ...@@ -50,31 +51,14 @@ export class App extends AppBase implements IApp {
} }
/** /**
* 初始化应用权限 * 初始化应用
* *
* @param {IParam} params 应用预置参数 * @param {IParam} params 应用预置参数
* @return {*} {Promise<any>} * @return {*} {Promise<any>}
* @memberof App * @memberof App
*/ */
public async initAppAuth(params: IParam): Promise<any> { public async initApp(params: IParam): Promise<any> {
let result = true; return await this.getAppAuthService().initAppAuth(params, App.hooks);
if (Environment && Environment.SaaSMode) {
if (getSessionStorage('activeOrgData')) {
result = await AppUtil.getAppData(App.hooks, params);
} else {
result = await AppUtil.getOrgsByDcsystem(App.hooks);
if (result) {
result = await AppUtil.getAppData(App.hooks, params);
}
}
} else {
result = await AppUtil.getAppData(App.hooks, params);
}
if (!result) {
// 登录
}
// TODO
return true;
} }
/** /**
...@@ -87,6 +71,16 @@ export class App extends AppBase implements IApp { ...@@ -87,6 +71,16 @@ export class App extends AppBase implements IApp {
return AppFuncConfig; return AppFuncConfig;
} }
/**
* 获取应用权限服务
*
* @return {*} {IAppAuthService}
* @memberof App
*/
public getAppAuthService(): IAppAuthService {
return AppAuthService.getInstance();
}
/** /**
* 获取打开视图服务 * 获取打开视图服务
* *
...@@ -158,14 +152,4 @@ export class App extends AppBase implements IApp { ...@@ -158,14 +152,4 @@ export class App extends AppBase implements IApp {
} }
} }
/**
* @description 登录
*
* @return {*} {Promise<IParam>}
* @memberof App
*/
handleLogin(): Promise<IParam> {
throw new Error("Method not implemented.");
}
} }
\ No newline at end of file
import { AppAuthServiceBase, IAppAuthService, IParam } from "@core";
/**
* 应用权限服务
*
* @export
* @class AppAuthService
*/
export class AppAuthService extends AppAuthServiceBase implements IAppAuthService {
/**
* 唯一实例
*
* @private
* @static
* @memberof AppAuthService
*/
private static readonly instance = new AppAuthService();
/**
* 获取唯一实例
*
* @static
* @return {*} {AppAuthService}
* @memberof AppAuthService
*/
public static getInstance(): AppAuthService {
return AppAuthService.instance;
}
}
\ No newline at end of file
import { IParam, ViewDetail } from "../common"; import { IParam, ViewDetail } from "../common";
import { IAppFuncService, IOpenViewService } from "../service"; import { IAppAuthService, IAppFuncService, IOpenViewService } from "../service";
/** /**
...@@ -11,21 +11,13 @@ import { IAppFuncService, IOpenViewService } from "../service"; ...@@ -11,21 +11,13 @@ import { IAppFuncService, IOpenViewService } from "../service";
export interface IApp { export interface IApp {
/** /**
* 初始化应用权限 * 初始化应用
* *
* @param {IParam} params 应用预置参数 * @param {IParam} params 应用预置参数
* @return {*} {Promise<any>} * @return {*} {Promise<any>}
* @memberof IApp * @memberof IApp
*/ */
initAppAuth(params: IParam): Promise<any>; initApp(params: IParam): Promise<any>;
/**
* 获取应用所有功能
*
* @return {*} {IParam[]}
* @memberof IApp
*/
getAllFuncs(): IParam[];
/** /**
* 获取应用功能服务 * 获取应用功能服务
...@@ -43,6 +35,14 @@ export interface IApp { ...@@ -43,6 +35,14 @@ export interface IApp {
*/ */
getOpenViewService(): IOpenViewService; getOpenViewService(): IOpenViewService;
/**
* 获取应用权限服务
*
* @return {*} {IAppAuthService}
* @memberof IApp
*/
getAppAuthService(): IAppAuthService;
/** /**
* 获取UI服务 * 获取UI服务
* *
...@@ -63,6 +63,14 @@ export interface IApp { ...@@ -63,6 +63,14 @@ export interface IApp {
*/ */
getDataService(entityKey: string, context?: IParam): Promise<any>; getDataService(entityKey: string, context?: IParam): Promise<any>;
/**
* 获取应用所有功能
*
* @return {*} {IParam[]}
* @memberof IApp
*/
getAllFuncs(): IParam[];
/** /**
* 获取指定视图信息 * 获取指定视图信息
* *
...@@ -82,7 +90,6 @@ export interface IApp { ...@@ -82,7 +90,6 @@ export interface IApp {
*/ */
getEntityInfo(codeName: string): any; getEntityInfo(codeName: string): any;
/** /**
* 获取应用数据 * 获取应用数据
* *
...@@ -106,12 +113,4 @@ export interface IApp { ...@@ -106,12 +113,4 @@ export interface IApp {
*/ */
gotoLoginPage(): void; gotoLoginPage(): void;
/**
* @description 登录
*
* @return {*} {Promise<IParam>}
* @memberof IApp
*/
handleLogin(): Promise<IParam>;
} }
\ No newline at end of file
import { IParam } from "../common";
/**
* @description 应用权限服务
* @export
* @interface IAppAuthService
*/
export interface IAppAuthService {
/**
* 初始化应用权限
*
* @param {IParam} params 应用预置参数
* @return {*} {Promise<any>}
* @memberof IAppAuthService
*/
initAppAuth(params: IParam, hooks: IParam): Promise<any>;
/**
* 获取应用数据
*
* @return {*} {IParam}
* @memberof IAppAuthService
*/
getAppData(): IParam;
/**
* 设置应用数据
*
* @param {IParam} opt
* @memberof IAppAuthService
*/
setAppData(opt: IParam): void;
/**
* 登录
*
* @param {IParam} params 应用预置参数
* @return {*} {Promise<any>}
* @memberof IAppAuthService
*/
login(opts: IParam): Promise<IParam>;
}
\ No newline at end of file
...@@ -3,3 +3,4 @@ export * from './i-app-action-service'; ...@@ -3,3 +3,4 @@ export * from './i-app-action-service';
export * from './i-open-view-service'; export * from './i-open-view-service';
export * from './i-data-service-register'; export * from './i-data-service-register';
export * from './i-ui-service-register'; export * from './i-ui-service-register';
export * from './i-app-auth-service';
\ No newline at end of file
export * from './app-func-service';
export * from './app-action-service';
\ No newline at end of file
export * from './app-logic';
export * from './app-ui-action'; export * from './app-ui-action';
\ No newline at end of file
import { AppFuncService, IApp, IAppFuncService, IOpenViewService, ViewDetail } from "@core"; import { AppFuncService, IApp, IAppFuncService, IOpenViewService, ViewDetail } from "@core";
import { IParam } from "@core/interface"; import { IAppAuthService, IParam } from "@core/interface";
/** /**
* 应用基类 * 应用基类
...@@ -19,22 +19,12 @@ export abstract class AppBase implements IApp { ...@@ -19,22 +19,12 @@ export abstract class AppBase implements IApp {
private appFuncService: AppFuncService = AppFuncService.getInstance(); private appFuncService: AppFuncService = AppFuncService.getInstance();
/** /**
* 应用数据 * 初始化应用
* *
* @private * @param {IParam} opt
* @type {IParam}
* @memberof AppBase
*/
private appData: IParam = {};
/**
* 初始化应用权限
*
* @param {IParam} params 应用预置参数
* @return {*} {Promise<any>}
* @memberof AppBase * @memberof AppBase
*/ */
public async initAppAuth(params: IParam): Promise<any> { public initApp(params: IParam): Promise<any> {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
...@@ -45,7 +35,7 @@ export abstract class AppBase implements IApp { ...@@ -45,7 +35,7 @@ export abstract class AppBase implements IApp {
* @memberof AppBase * @memberof AppBase
*/ */
public setAppData(opt: IParam): void { public setAppData(opt: IParam): void {
this.appData = opt; this.getAppAuthService().setAppData(opt);
} }
/** /**
...@@ -55,7 +45,17 @@ export abstract class AppBase implements IApp { ...@@ -55,7 +45,17 @@ export abstract class AppBase implements IApp {
* @memberof AppBase * @memberof AppBase
*/ */
public getAppData(): IParam { public getAppData(): IParam {
return this.appData; return this.getAppAuthService().getAppData();
}
/**
* 获取应用权限服务
*
* @return {IAppFuncService}
* @memberof AppBase
*/
public getAppAuthService(): IAppAuthService {
throw new Error("Method not implemented.");
} }
/** /**
...@@ -132,21 +132,12 @@ export abstract class AppBase implements IApp { ...@@ -132,21 +132,12 @@ export abstract class AppBase implements IApp {
} }
/** /**
* @description 跳转登录页 * @description 跳转登录页
* *
* @memberof AppBase * @memberof AppBase
*/ */
gotoLoginPage(): void { public gotoLoginPage(): void {
throw new Error("Method not implemented."); throw new Error("Method not implemented.");
} }
/**
* @description 登录
*
* @return {*} {Promise<IParam>}
* @memberof AppBase
*/
handleLogin(): Promise<IParam> {
throw new Error("Method not implemented.");
}
} }
\ No newline at end of file
...@@ -92,7 +92,7 @@ export class ViewBase { ...@@ -92,7 +92,7 @@ export class ViewBase {
* 关闭视图 * 关闭视图
* *
*/ */
public closeView(){ public closeView() {
window.history.go(-1); window.history.go(-1);
} }
...@@ -109,8 +109,8 @@ export class ViewBase { ...@@ -109,8 +109,8 @@ export class ViewBase {
const { appViewNavContexts, appViewNavParams } = this.state; const { appViewNavContexts, appViewNavParams } = this.state;
if (Object.is(props.openType, 'ROUTE')) { if (Object.is(props.openType, 'ROUTE')) {
// 应用上下文 // 应用上下文
const appContext = App.getAppData(); const appData = App.getAppData();
Object.assign(context.value, appContext); Object.assign(context.value, appData.context ? appData.context : {});
// 视图应用上下文 // 视图应用上下文
const pageContext = {}; const pageContext = {};
const routeParams = useRoute().params; const routeParams = useRoute().params;
......
import { hasFunction } from "@core"; import { hasFunction } from "@core";
import { IParam, IContext, IAppActionService } from "@core/interface"; import { IParam, IContext, IAppActionService } from "@core/interface";
import { AppSysAction } from "../app-ui-action/app-sys-action"; import { AppSysAction } from "../../logic/app-ui-action/app-sys-action";
export class AppActionService implements IAppActionService { export class AppActionService implements IAppActionService {
......
export { AppActionService } from './app-action-service';
\ No newline at end of file
import qs from "qs"; import qs from "qs";
import { getCookie } from "qx-util"; import { clearCookie, getCookie, setCookie } from "qx-util";
import { deepCopy, getSessionStorage, Http, removeSessionStorage, setSessionStorage } from "@core";
import { IParam, IAppAuthService } from "@core/interface";
import { Environment } from "@/environments/environment"; import { Environment } from "@/environments/environment";
import { getSessionStorage, Http, IParam, setSessionStorage } from "@core";
/** export abstract class AppAuthServiceBase implements IAppAuthService {
* 应用相关处理逻辑工具类
/**
* 应用数据
* *
* @export * @private
* @class AppUtil * @type {IParam}
* @memberof AppAuthServiceBase
*/ */
export class AppUtil { private appData: IParam = {};
/** /**
* 获取应用数据 * 获取应用数据
* *
* @static * @return {*} {IParam}
* @memberof AppAuthServiceBase
*/
public getAppData(): IParam {
return this.appData;
}
/**
* 设置应用数据
*
* @param {IParam} opt
* @memberof AppAuthServiceBase
*/
public setAppData(opt: IParam = {}): void {
this.appData = opt;
}
/**
* 初始化应用权限
*
* @param {IParam} params 应用预置参数
* @return {*} {Promise<any>}
* @memberof AppAuthServiceBase
*/
public async initAppAuth(params: IParam, hooks: IParam): Promise<any> {
let result = true;
if (Environment && Environment.SaaSMode) {
if (getSessionStorage('activeOrgData')) {
result = await this.getAppInitData(hooks, params);
} else {
result = await this.getOrgsByDcsystem(hooks);
if (result) {
result = await this.getAppInitData(hooks, params);
}
}
} else {
result = await this.getAppInitData(hooks, params);
}
return result;
}
/**
* 获取应用初始数据
*
* @param {IParam} hooks 应用钩子 * @param {IParam} hooks 应用钩子
* @param {IParam} [params={}] 应用参数 * @param {IParam} [params={}] 应用参数
* @return {*} {Promise<boolean>} * @return {*} {Promise<boolean>}
* @memberof AppUtil * @memberof AppAuthServiceBase
*/ */
public static async getAppData(hooks: IParam, params: IParam = {}): Promise<boolean> { public async getAppInitData(hooks: IParam, params: IParam = {}): Promise<boolean> {
try { try {
const url = '/appdata'; const url = '/appdata';
hooks.appBefore.callSync({ url: url, param: params }); hooks.appBefore.callSync({ url: url, param: params });
...@@ -32,22 +79,24 @@ export class AppUtil { ...@@ -32,22 +79,24 @@ export class AppUtil {
return false; return false;
} }
// token认证把用户信息放入应用级数据 // token认证把用户信息放入应用级数据
let localAppData: any = {};
if (getCookie('ibzuaa-user')) { if (getCookie('ibzuaa-user')) {
let user: any = JSON.parse(getCookie('ibzuaa-user') as string); let user: any = JSON.parse(getCookie('ibzuaa-user') as string);
let localAppData: any = {};
if (user.sessionParams) { if (user.sessionParams) {
localAppData = { context: user.sessionParams }; localAppData = { context: user.sessionParams };
Object.assign(localAppData, data); Object.assign(localAppData, data);
} else {
Object.assign(localAppData, data);
} }
data = JSON.parse(JSON.stringify(localAppData)); } else {
Object.assign(localAppData, data);
} }
App.setAppData(data); this.setAppData(deepCopy(localAppData));
return true; return true;
} else { } else {
return false; return false;
} }
} catch (error) { } catch (error) {
// App.gotoLoginPage();
return false; return false;
} }
} }
...@@ -58,9 +107,9 @@ export class AppUtil { ...@@ -58,9 +107,9 @@ export class AppUtil {
* @static * @static
* @param {IParam} hooks 应用钩子 * @param {IParam} hooks 应用钩子
* @return {*} {Promise<boolean>} * @return {*} {Promise<boolean>}
* @memberof AppUtil * @memberof AppAuthServiceBase
*/ */
public static async getOrgsByDcsystem(hooks: IParam): Promise<boolean> { public async getOrgsByDcsystem(hooks: IParam): Promise<boolean> {
try { try {
let tempViewParam = this.hanldeViewParam(window.location.href); let tempViewParam = this.hanldeViewParam(window.location.href);
if (!tempViewParam.srfdcsystem) { if (!tempViewParam.srfdcsystem) {
...@@ -95,20 +144,85 @@ export class AppUtil { ...@@ -95,20 +144,85 @@ export class AppUtil {
return false; return false;
} }
} catch (error) { } catch (error) {
// App.gotoLoginPage();
return false; return false;
} }
} }
/**
* @description 登录
*
* @memberof AppAuthServiceBase
*/
public async login(opts: IParam): Promise<IParam> {
try {
this.clearAppData();
const result: IParam = await Http.getInstance().post('/v7/login', opts, true);
const { status, data } = result;
if (status == 200) {
if (data && data.token) {
setCookie('ibzuaa-token', data.token, 7, true);
}
if (data && data.user) {
setCookie('ibzuaa-user', JSON.stringify(data.user), 7, true);
}
setCookie('loginname', opts.loginname, 7, true);
return result;
} else {
return result;
}
} catch (error: any) {
return error;
}
}
/**
* 登出
*
* @return {*} {Promise<IParam>}
* @memberof AppAuthServiceBase
*/
public async logout(): Promise<IParam> {
try {
const result: IParam = await Http.getInstance().get('/v7/logout');
const { status, data } = result;
if (status === 200) {
this.clearAppData();
return data;
} else {
return data;
}
} catch (error: any) {
return error;
}
}
/**
* 清除应用级数据
*
* @memberof AppAuthServiceBase
*/
public clearAppData() {
// 清除登录信息
clearCookie('ibzuaa-token', true);
clearCookie('ibzuaa-user', true);
clearCookie('loginname', true);
// 清除应用级数据
this.setAppData();
// 清除租户相关信息
removeSessionStorage('dcsystem');
removeSessionStorage('orgsData');
removeSessionStorage('activeOrgData');
}
/** /**
* 处理路径数据 * 处理路径数据
* *
* @static
* @param {string} urlStr 路径 * @param {string} urlStr 路径
* @return {*} {*} * @return {*} {*}
* @memberof AppUtil * @memberof AppAuthServiceBase
*/ */
public static hanldeViewParam(urlStr: string): any { public hanldeViewParam(urlStr: string): any {
let tempViewParam: any = {}; let tempViewParam: any = {};
const tempViewparam: any = urlStr.slice(urlStr.indexOf('?') + 1); const tempViewparam: any = urlStr.slice(urlStr.indexOf('?') + 1);
const viewparamArray: Array<string> = decodeURIComponent(tempViewparam).split(';'); const viewparamArray: Array<string> = decodeURIComponent(tempViewparam).split(';');
......
export { AppAuthServiceBase } from './app-auth-service';
\ No newline at end of file
export { AppFuncService } from './app-func-service';
\ No newline at end of file
import { IParam } from "@core";
/**
* 界面服务基类
*
* @export
* @class UIServiceBase
*/
export class UIServiceBase {
/**
* 应用上下文
*
* @protected
* @type {IParam}
* @memberof UIServiceBase
*/
protected context: IParam;
/**
*
* @param {*} [opts={}]
* @memberof UIServiceBase
*/
constructor(context: IParam = {}) {
this.context = context;
}
/**
* 界面行为模型对象
*
* @type {*}
* @memberof UIServiceBase
*/
public uiActionModes: any = {};
/**
*
* 获取界面行为模型对象
*
* @param {string} actionName
* @memberof UIServiceBase
*/
public getUIActionModel(actionName: string) {
if (!actionName) {
return;
}
return this.uiActionModes[actionName] ? this.uiActionModes[actionName] : null;
}
}
export { UIServiceBase } from './entity-ui-service-base';
\ No newline at end of file
export * from './control-service' export * from './app-action-service';
export * from './entity-service' export * from './app-auth-service';
export * from './ui-service' export * from './app-func-service';
\ No newline at end of file export * from './control-service';
export * from './entity-service';
export * from './entity-ui-service';
\ No newline at end of file
...@@ -2,5 +2,4 @@ export { RouteUtil } from './route-util'; ...@@ -2,5 +2,4 @@ export { RouteUtil } from './route-util';
export { UIUtil } from './ui-util'; export { UIUtil } from './ui-util';
export { UIActionUtil } from './uiaction-util'; export { UIActionUtil } from './uiaction-util';
export { ViewUtil } from './view-util'; export { ViewUtil } from './view-util';
export { AppUtil } from './app-util';
export { DataTypes } from './data-types'; export { DataTypes } from './data-types';
\ No newline at end of file
...@@ -59,6 +59,7 @@ const routes = [ ...@@ -59,6 +59,7 @@ const routes = [
}, },
{ {
path: '/404', path: '/404',
name: '404',
component: () => import('@components/common/404.vue') component: () => import('@components/common/404.vue')
}, },
{ {
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册