提交 da5b4d9f 编写于 作者: RedPig97's avatar RedPig97

add: 新增导航数据服务

上级 a3d91f4d
import { Environment } from "@/environments/environment";
import { OpenViewService } from "@/utils";
import { AppBase, IParam, ViewDetail, IApp, IOpenViewService, deepCopy, getSessionStorage, Http, AppUtil } from "@core";
import { AppBase, IParam, ViewDetail, IApp, IOpenViewService, deepCopy, getSessionStorage, Http, AppUtil, NavDataService, INavDataService } from "@core";
import { SyncSeriesHook } from "qx-util";
import { AppFuncConfig, AppViewConfig, AppEntityConfig } from './config';
import { DataServiceRegister, UIServiceRegister } from "./register";
......@@ -139,7 +139,16 @@ export class App extends AppBase implements IApp {
* @return {*}
*/
public getEntityInfo(codeName: string): any {
return AppEntityConfig[codeName] ? deepCopy(AppEntityConfig[codeName]) : undefined;;
return AppEntityConfig[codeName] ? deepCopy(AppEntityConfig[codeName]) : undefined;
}
/**
* @description 获取导航数据服务
* @return {*} {*}
* @memberof App
*/
public getNavDataService(): INavDataService {
return NavDataService.getInstance();
}
}
\ No newline at end of file
import { IParam, ViewDetail } from "../common";
import { IAppFuncService, IDataServiceRegister, IOpenViewService, IUIServiceRegister } from "../service";
import { IAppFuncService, IDataServiceRegister, INavDataService, IOpenViewService, IUIServiceRegister } from "../service";
/**
......@@ -99,4 +99,11 @@ export interface IApp {
*/
setAppData(opt: IParam): void;
/**
* @description 获取导航数据服务
* @return {*} {INavDataService}
* @memberof IApp
*/
getNavDataService(): INavDataService;
}
\ No newline at end of file
import { INavDataParam, IParam, ViewDetail } from "@core";
import { Subject } from 'rxjs';
/**
* @description 打开视图服务接口
* @export
* @interface INavDataService
*/
export interface INavDataService {
addNavData(curNavData: INavDataParam): void;
getNavData(): Array<INavDataParam>;
getPreNavData(tag: string): INavDataParam | null;
skipNavData(tag: string): void;
removeNavData(tag: string): void;
removeNavDataFirst(): void;
removeNavDataLast(): void;
removeAllNavData(): void;
}
\ No newline at end of file
......@@ -2,4 +2,5 @@ export * from './i-app-func-service';
export * from './i-app-action-service';
export * from './i-open-view-service';
export * from './i-data-service-register';
export * from './i-ui-service-register';
\ No newline at end of file
export * from './i-ui-service-register';
export * from './i-nav-data-service';
\ No newline at end of file
import { AppFuncService, IApp, IAppFuncService, IOpenViewService, ViewDetail } from "@core";
import { IDataServiceRegister, IParam, IUIServiceRegister } from "@core/interface";
import { IDataServiceRegister, INavDataService, IParam, IUIServiceRegister } from "@core/interface";
/**
* 应用基类
......@@ -120,4 +120,13 @@ export abstract class AppBase implements IApp {
public getViewInfo(codeName: string): ViewDetail | undefined {
return undefined;
}
/**
* @description 获取导航数据服务
* @return {*} {INavDataService}
* @memberof AppBase
*/
public getNavDataService(): INavDataService {
throw new Error("Method not implemented.");
}
}
\ No newline at end of file
......@@ -194,7 +194,19 @@ export class ViewBase {
*
* @memberof ViewBase
*/
public useViewInit() { }
public useViewInit() {
const route = useRoute();
App.getNavDataService().addNavData({title: this.state.viewCaption, viewType: this.state.viewType, path: unref(route.fullPath), openType: this.props.openType, tag: this.state.viewCodeName, key: '', data: {}});
}
/**
* @description 视图销毁
* @memberof ViewBase
*/
public useViewDestroyed() {
// 视图销毁从导航栈里面删除数据
App.getNavDataService().removeNavData(this.state.viewCodeName);
}
/**
* @description 安装视图所有功能模块的方法
......
export * from './navdata-service';
export * from './navdata-param';
\ No newline at end of file
import { IParam } from '@core';
export interface INavDataParam {
/**
* @description 视图标题
* @type {*}
* @memberof INavDataParam
*/
title: string;
/**
* @description 视图数据
* @type {*}
* @memberof INavDataParam
*/
data: IParam;
/**
* @description 视图路径
* @type {string}
* @memberof INavDataParam
*/
path: string;
/**
* @description 视图打开模式("ROUTE" | "MODAL" | "EMBED")
* @type {("ROUTE" | "MODAL" | "EMBED")}
* @memberof INavDataParam
*/
openType: "ROUTE" | "MODAL" | "EMBED";
/**
* @description 视图类型
* @type {string}
* @memberof INavDataParam
*/
viewType: string;
/**
* @description 视图标识
* @type {string}
* @memberof INavDataParam
*/
tag: string;
/**
* @description 数据标识
* @type {*}
* @memberof INavDataParam
*/
key: string;
}
import { IActionParam, INavDataService } from '@core';
import { Subject } from 'rxjs';
import { INavDataParam } from './navdata-param';
/**
* 导航数据服务
*
* @export
* @class CodeListService
*/
export class NavDataService implements INavDataService {
/**
* 单例变量声明
*
* @private
* @static
* @type {NavDataService}
* @memberof NavDataService
*/
private static navDataService: NavDataService;
/**
* 服务状态
*
* @memberof NavDataService
*/
public serviceState: Subject<IActionParam> = new Subject();
/**
* 导航数据栈
*
* @memberof NavDataService
*/
public navDataStack: Array<INavDataParam> = [];
/**
* 初始化实例
*
* @memberof NavDataService
*/
constructor(opts: any = {}) { }
/**
* 获取 NavDataService 单例对象
*
* @static
* @returns {NavDataService}
* @memberof NavDataService
*/
public static getInstance(): NavDataService {
if (!NavDataService.navDataService) {
NavDataService.navDataService = new NavDataService();
}
return this.navDataService;
}
/**
* 添加基础导航数据到栈中
*
* @memberof NavDataService
*/
public addNavData(curNavData: INavDataParam) {
this.navDataStack.push(curNavData);
}
/**
* 设置指定数据到基础导航数据栈中
*
* @memberof NavDataService
*/
public setNavDataByTag(tag: string, isSingleMode: boolean, data: any) {
if (this.navDataStack.length > 0) {
let tempIndex: number = this.navDataStack.findIndex((element: INavDataParam) => {
return Object.is(element.tag, tag);
})
if(this.navDataStack[tempIndex]){
this.navDataStack[tempIndex].data = data;
if (isSingleMode && data.srfkey && data.srfmajortext) {
this.navDataStack[tempIndex].key = data.srfkey;
this.navDataStack[tempIndex].title = data.srfmajortext;
}
return this.navDataStack[tempIndex];
}else{
return null;
}
} else {
return null;
}
}
/**
* 获取基础导航数据
*
* @memberof NavDataService
*/
public getNavData() {
return this.navDataStack;
}
/**
* 从导航数据栈中获取指定数据的前一条数据
*
* @memberof NavDataService
*/
public getPreNavData(tag: string) {
if (this.navDataStack.length > 0) {
let tempIndex: number = this.navDataStack.findIndex((element: INavDataParam) => {
return Object.is(element.tag, tag);
})
return this.navDataStack[tempIndex - 1];
} else {
return null;
}
}
/**
* 跳转到导航数据栈中指定数据
*
* @memberof NavDataService
*/
public skipNavData(tag: string) {
if ((this.navDataStack.length > 0) && tag) {
let tempIndex: number = this.navDataStack.findIndex((element: INavDataParam) => {
return Object.is(element.tag, tag);
})
if (tempIndex !== -1) {
this.navDataStack = this.navDataStack.slice(0, tempIndex + 1);
}
}
}
/**
* 从导航数据栈中指定数据
*
* @memberof NavDataService
*/
public removeNavData(tag: string) {
if ((this.navDataStack.length > 0) && tag) {
let tempIndex: number = this.navDataStack.findIndex((element: INavDataParam) => {
return Object.is(element.tag, tag);
})
if (tempIndex !== -1) {
this.navDataStack = this.navDataStack.slice(0, tempIndex);
}
}
}
/**
* 从导航数据栈中删除仅剩第一条数据
*
* @memberof NavDataService
*/
public removeNavDataFirst() {
if (this.navDataStack.length > 0) {
this.navDataStack = this.navDataStack.slice(0, 1);
}
}
/**
* 从导航数据栈中删除最后一条数据
*
* @memberof NavDataService
*/
public removeNavDataLast() {
if (this.navDataStack.length > 0) {
this.navDataStack.pop();
}
}
/**
* 从导航数据栈中删除所有数据
*
* @memberof NavDataService
*/
public removeAllNavData() {
this.navDataStack = [];
}
}
\ No newline at end of file
export * from './control-service'
export * from './entity-service'
export * from './ui-service'
\ No newline at end of file
export * from './ui-service'
export * from './common-service'
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册