|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import Message from "@/views/front/develop/Communication/Message";
- import type { PageBase } from './PageBase'
- import type { ITradeHelper } from './ITradeHelper'
- import type { TradeBusHelper } from './TradeBusHelper'
- import type { TradeInfoHelper } from './TradeInfoHelper'
-
- import type { TradeResourcesHelper } from './TradeResourcesHelper'
- import TradeAPIsHelper from "./TradeAPIsHelper";
- import { reactive } from "vue";
-
- /**
- * 入口基类,包括Message和PageBase
- */
- export class EntryBase implements ITradeHelper {
- TradeResources: TradeAPIsHelper;
- //#region 数据属性
- private _messageData: Message | null = null
- private _pageData: PageBase | null = null
-
- public get MessageData(): Message | null {
- return this._messageData
- }
- private set MessageData(value: Message | null) {
- this._messageData = value
- }
-
- public get PageData(): PageBase | null {
- return this._pageData
- }
- private set PageData(value: PageBase | null) {
- this._pageData = value
- }
- #endregion
-
- /**
- * 加载数据
- * @param page
- * @param message
- * @returns
- */
- public LoadData(page: PageBase, message: Message): boolean {
- let flag = true
-
- // 检测参数变化
- if (page !== null && page === this.PageData) {
- if (message === this.MessageData ||
- (message.fileData === this.MessageData?.fileData &&
- this.getDiffFields(message, this.MessageData).length === 0)) {
- flag = false // 参数与历史登记一致,未作修改
- }
- }
-
- this.PageData = page
- this.MessageData = message
- return this.OnLoadData(flag)
- }
-
- private getDiffFields(newMsg: Message, oldMsg: Message): string[] {
- const newFields = Object.keys(newMsg)
- const oldFields = Object.keys(oldMsg)
- return newFields.filter(key => newMsg[key] !== oldMsg[key])
- }
-
- /**
- * 加载数据时触发
- * @param changed 标识数据是否发生改变
- * @returns
- */
- protected OnLoadData(changed: boolean): boolean {
- return true
- }
-
- public get TradeBus(): TradeBusHelper {
- if (!this.PageData) throw new Error('PageData is null')
- return this.PageData.TradeBus
- }
-
- public get TradeInfo(): TradeInfoHelper {
- if (!this.PageData) throw new Error('PageData is null')
- return this.PageData.TradeInfo
- }
-
- public get TradeAPIs(): TradeAPIsHelper {
- if (!this.PageData) throw new Error('PageData is null')
- return this.PageData.TradeAPIs
- }
-
- // public get TradeResources(): TradeResourcesHelper {
- // if (!this.PageData) throw new Error('PageData is null')
- // return this.PageData.TradeResources
- // } hulei-/暂时注释
-
- }
-
- // Vue组件封装
- export const useEntryBase = () => {
- return {
- EntryBase,
- createEntry: () => reactive(new EntryBase())
- }
- }
|