diff --git a/es/components/config/style/platform/index.d.ts b/es/components/config/style/platform/index.d.ts index bd3579c54..0017a6f93 100644 --- a/es/components/config/style/platform/index.d.ts +++ b/es/components/config/style/platform/index.d.ts @@ -1,7 +1,7 @@ import { Style } from '../../../../types/Style'; declare const _default: (props: import("oak-frontend-base").ReactComponentProps) => import("react").ReactElement>; diff --git a/es/components/config/upsert/index.d.ts b/es/components/config/upsert/index.d.ts index 6a8e95a3d..26655e31f 100644 --- a/es/components/config/upsert/index.d.ts +++ b/es/components/config/upsert/index.d.ts @@ -1,7 +1,7 @@ import { Config } from '../../../types/Config'; declare const _default: (props: import("oak-frontend-base").ReactComponentProps) => import("react").ReactElement>; diff --git a/es/components/extraFile/commit/index.d.ts b/es/components/extraFile/commit/index.d.ts index 64581d76a..eb1082122 100644 --- a/es/components/extraFile/commit/index.d.ts +++ b/es/components/extraFile/commit/index.d.ts @@ -14,17 +14,17 @@ declare const _default: ) => unknown) | undefined; - type?: "button" | "submit" | "reset" | undefined; + type?: "button" | "reset" | "submit" | undefined; shape?: "default" | "rounded" | "rectangular" | undefined; children?: import("react").ReactNode; - } & Pick & import("react").ButtonHTMLAttributes, "id" | "onMouseDown" | "onMouseUp" | "onTouchEnd" | "onTouchStart"> & { + } & Pick & import("react").ButtonHTMLAttributes, "id" | "onMouseUp" | "onMouseDown" | "onTouchStart" | "onTouchEnd"> & { className?: string | undefined; style?: (import("react").CSSProperties & Partial>) | undefined; tabIndex?: number | undefined; diff --git a/es/components/message/index.js b/es/components/message/index.js index 216097147..ffdb2613d 100644 --- a/es/components/message/index.js +++ b/es/components/message/index.js @@ -20,9 +20,5 @@ export default OakComponent({ data, }; }, - lifetimes: { - attached() { - this.subscribed.push(this.features.message.subscribe(() => this.reRender())); - } - } + features: ['message'], }); diff --git a/es/components/message/list/index.js b/es/components/message/list/index.js index ec0f36ed3..d5524ac63 100644 --- a/es/components/message/list/index.js +++ b/es/components/message/list/index.js @@ -50,11 +50,7 @@ export default OakComponent({ messages, }; }, - lifetimes: { - attached() { - this.subscribed.push(this.features.token.subscribe(() => this.reRender())); - }, - }, + features: ['message'], methods: { goDetailById(id) { this.navigateTo({ diff --git a/es/components/my/avatar/index.js b/es/components/my/avatar/index.js index b7d424ffd..5d057ac8a 100644 --- a/es/components/my/avatar/index.js +++ b/es/components/my/avatar/index.js @@ -19,9 +19,4 @@ export default OakComponent({ avatarUrl: '', }; }, - lifetimes: { - attached() { - this.subscribed.push(this.features.token.subscribe(() => this.reRender())); - }, - }, }); diff --git a/es/components/my/info/index.js b/es/components/my/info/index.js index 2ab857c8d..53f6f7fb0 100644 --- a/es/components/my/info/index.js +++ b/es/components/my/info/index.js @@ -27,12 +27,7 @@ export default OakComponent({ properties: { showLogout: false, }, - lifetimes: { - attached() { - this.subscribed.push(this.features.token.subscribe(() => this.reRender())); - this.subscribed.push(this.features.cache.subscribe(() => this.reRender())); - }, - }, + features: ['cache'], methods: { logout() { this.features.token.logout(); diff --git a/es/features/token.js b/es/features/token.js index 1f444dc2e..f3712c396 100644 --- a/es/features/token.js +++ b/es/features/token.js @@ -27,6 +27,7 @@ export class Token extends Feature { else { this.tokenValue = undefined; } + this.publish(); } constructor(cache, storage, environment) { super(); @@ -201,7 +202,7 @@ export class Token extends Feature { code, env: env, }); - this.publish(); + // this.publish(); } async wakeupParasite(id) { const env = await this.environment.getEnv(); diff --git a/es/oak-app-domain/SmsTemplate/Schema.d.ts b/es/oak-app-domain/SmsTemplate/Schema.d.ts index 28c38b3c6..4238265a7 100644 --- a/es/oak-app-domain/SmsTemplate/Schema.d.ts +++ b/es/oak-app-domain/SmsTemplate/Schema.d.ts @@ -1,5 +1,5 @@ import { ForeignKey } from "oak-domain/lib/types/DataType"; -import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey, SubQueryPredicateMetadata } from "oak-domain/lib/types/Demand"; +import { Q_DateValue, Q_NumberValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey, SubQueryPredicateMetadata } from "oak-domain/lib/types/Demand"; import { OneOf } from "oak-domain/lib/types/Polyfill"; import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, AggregationResult } from "oak-domain/lib/types/Entity"; import { GenericAction } from "oak-domain/lib/actions/action"; @@ -27,8 +27,8 @@ export type Schema = EntityShape & { messageTypeSmsTemplate$template?: Array; messageTypeSmsTemplate$template$$aggr?: AggregationResult; } & { - [A in ExpressionKey]?: any; - }; + [A in ExpressionKey]?: any; +}; type AttrFilter = { id: Q_StringValue; $$createAt$$: Q_DateValue; @@ -156,4 +156,4 @@ export type EntityDef = { CreateSingle: CreateSingleOperation; CreateMulti: CreateMultipleOperation; }; -export { }; +export {}; diff --git a/es/page.mp.js b/es/page.mp.js index 9f7fadd0a..c535fa9f8 100644 --- a/es/page.mp.js +++ b/es/page.mp.js @@ -60,10 +60,19 @@ export async function subscribeMpMessage(messageTypes, haveToAccept, tip) { return true; } export function createComponent(option, features) { - const { wechatMp, methods, lifetimes, ...rest } = option; + const { wechatMp, data, methods, lifetimes, userInsensitive, ...rest } = option; const { relatedMessageTypes } = wechatMp || {}; - const { ready, attached, ...restLifeTimes } = lifetimes || {}; + const { ready, attached, show, hide, ...restLifeTimes } = lifetimes || {}; return createBaseComponent({ + data: typeof data === 'function' ? function () { + return { + __userId: undefined, + ...(data.call(this)), + }; + } : { + __userId: undefined, + ...data, + }, methods: { async subscribeMpMessage(messageTypes, haveToAccept, tip) { return await subscribeMpMessage.call(this, messageTypes, haveToAccept, tip); @@ -72,7 +81,9 @@ export function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + if (!userInsensitive) { + this.addFeatureSub('token', () => this.refresh()); + } attached && attached.call(this); }, ready() { @@ -123,6 +134,22 @@ export function createComponent(option, features) { } ready && ready.call(this); }, + show() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + if (userId !== this.state.__userId) { + this.refresh(); + } + } + }, + hide() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + this.setState({ + __userId: userId, + }); + } + }, ...restLifeTimes, }, wechatMp, diff --git a/es/page.native.js b/es/page.native.js index bc81e16d4..1ad861c3a 100644 --- a/es/page.native.js +++ b/es/page.native.js @@ -11,7 +11,7 @@ export function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/es/page.web.js b/es/page.web.js index e282900a5..a2969929a 100644 --- a/es/page.web.js +++ b/es/page.web.js @@ -11,7 +11,7 @@ export function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/es/triggers/index.d.ts b/es/triggers/index.d.ts index 487031783..0770eae70 100644 --- a/es/triggers/index.d.ts +++ b/es/triggers/index.d.ts @@ -1,2 +1,2 @@ -declare const _default: (import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger>)[]; +declare const _default: (import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger>)[]; export default _default; diff --git a/es/triggers/toDo.d.ts b/es/triggers/toDo.d.ts index 95d028df6..3c8646ad8 100644 --- a/es/triggers/toDo.d.ts +++ b/es/triggers/toDo.d.ts @@ -12,7 +12,7 @@ export declare function createToDo; +}, userIds?: string[]): Promise<0 | 1>; /** * 完成todo例程,当在entity对象上进行action操作时(操作条件是filter),将对应的todo完成 * 必须在entity的action的后trigger中调用 diff --git a/es/types/Page.d.ts b/es/types/Page.d.ts index 5a7deaa05..7f540de0a 100644 --- a/es/types/Page.d.ts +++ b/es/types/Page.d.ts @@ -13,6 +13,7 @@ import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext'; export type OakComponentOption, FrontCxt extends FrontendRuntimeContext>, AD extends Record>, FD extends Record, FormedData extends Record, TData extends Record, TProperty extends DataOption, TMethod extends Record> = BaseOakComponentOption, FD & GFD>, FormedData, TData, TProperty, TMethod, { subscribeMpMessage: (messageTypes: string[], haveToAccept?: boolean, tip?: string) => Promise; }> & Partial<{ + userInsensitive?: true; wechatMp: { relatedMessageTypes?: string[]; }; diff --git a/lib/endpoints/wechat.js b/lib/endpoints/wechat.js index 591854c2d..e0383a276 100644 --- a/lib/endpoints/wechat.js +++ b/lib/endpoints/wechat.js @@ -9,7 +9,7 @@ const x2js_1 = tslib_1.__importDefault(require("x2js")); const oak_external_sdk_1 = require("oak-external-sdk"); const uuid_1 = require("oak-domain/lib/utils/uuid"); const domain_1 = require("../utils/domain"); -const url_2 = require("oak-domain/lib/utils/domain"); +const domain_2 = require("oak-domain/lib/utils/domain"); const session_1 = require("../aspects/session"); const application_1 = require("../aspects/application"); const X2Js = new x2js_1.default(); @@ -231,7 +231,7 @@ async function setUserSubscribed(openId, eventKey, context) { (0, assert_1.assert)(appMp, '公众号推送小程序码时找不到关联的小程序'); const { config } = appMp; const { appId } = config; - const url = (0, url_2.composeUrl)('pages/wechatQrCode/scan/index', { + const url = (0, domain_2.composeUrl)('pages/wechatQrCode/scan/index', { scene: sceneStr, time: `${Date.now()}`, }); diff --git a/lib/features/token.js b/lib/features/token.js index 7740ed3ea..d6100afc0 100644 --- a/lib/features/token.js +++ b/lib/features/token.js @@ -30,6 +30,7 @@ class Token extends oak_frontend_base_1.Feature { else { this.tokenValue = undefined; } + this.publish(); } constructor(cache, storage, environment) { super(); @@ -204,7 +205,7 @@ class Token extends oak_frontend_base_1.Feature { code, env: env, }); - this.publish(); + // this.publish(); } async wakeupParasite(id) { const env = await this.environment.getEnv(); diff --git a/lib/oak-app-domain/SmsTemplate/Schema.d.ts b/lib/oak-app-domain/SmsTemplate/Schema.d.ts index 28c38b3c6..4238265a7 100644 --- a/lib/oak-app-domain/SmsTemplate/Schema.d.ts +++ b/lib/oak-app-domain/SmsTemplate/Schema.d.ts @@ -1,5 +1,5 @@ import { ForeignKey } from "oak-domain/lib/types/DataType"; -import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey, SubQueryPredicateMetadata } from "oak-domain/lib/types/Demand"; +import { Q_DateValue, Q_NumberValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey, SubQueryPredicateMetadata } from "oak-domain/lib/types/Demand"; import { OneOf } from "oak-domain/lib/types/Polyfill"; import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, AggregationResult } from "oak-domain/lib/types/Entity"; import { GenericAction } from "oak-domain/lib/actions/action"; @@ -27,8 +27,8 @@ export type Schema = EntityShape & { messageTypeSmsTemplate$template?: Array; messageTypeSmsTemplate$template$$aggr?: AggregationResult; } & { - [A in ExpressionKey]?: any; - }; + [A in ExpressionKey]?: any; +}; type AttrFilter = { id: Q_StringValue; $$createAt$$: Q_DateValue; @@ -156,4 +156,4 @@ export type EntityDef = { CreateSingle: CreateSingleOperation; CreateMulti: CreateMultipleOperation; }; -export { }; +export {}; diff --git a/lib/page.mp.js b/lib/page.mp.js index 4f2bf6e13..1daf3424e 100644 --- a/lib/page.mp.js +++ b/lib/page.mp.js @@ -64,10 +64,19 @@ async function subscribeMpMessage(messageTypes, haveToAccept, tip) { } exports.subscribeMpMessage = subscribeMpMessage; function createComponent(option, features) { - const { wechatMp, methods, lifetimes, ...rest } = option; + const { wechatMp, data, methods, lifetimes, userInsensitive, ...rest } = option; const { relatedMessageTypes } = wechatMp || {}; - const { ready, attached, ...restLifeTimes } = lifetimes || {}; + const { ready, attached, show, hide, ...restLifeTimes } = lifetimes || {}; return (0, page_mp_1.createComponent)({ + data: typeof data === 'function' ? function () { + return { + __userId: undefined, + ...(data.call(this)), + }; + } : { + __userId: undefined, + ...data, + }, methods: { async subscribeMpMessage(messageTypes, haveToAccept, tip) { return await subscribeMpMessage.call(this, messageTypes, haveToAccept, tip); @@ -76,7 +85,9 @@ function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + if (!userInsensitive) { + this.addFeatureSub('token', () => this.refresh()); + } attached && attached.call(this); }, ready() { @@ -127,6 +138,22 @@ function createComponent(option, features) { } ready && ready.call(this); }, + show() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + if (userId !== this.state.__userId) { + this.refresh(); + } + } + }, + hide() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + this.setState({ + __userId: userId, + }); + } + }, ...restLifeTimes, }, wechatMp, diff --git a/lib/page.native.js b/lib/page.native.js index ebeca1575..e67545785 100644 --- a/lib/page.native.js +++ b/lib/page.native.js @@ -14,7 +14,7 @@ function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/lib/page.web.js b/lib/page.web.js index c9ffcedf3..c77e913c7 100644 --- a/lib/page.web.js +++ b/lib/page.web.js @@ -14,7 +14,7 @@ function createComponent(option, features) { }, lifetimes: { attached() { - this.subscribed.push(this.features.token.subscribe(() => this.refresh())); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/lib/triggers/index.d.ts b/lib/triggers/index.d.ts index 0eeafa483..0770eae70 100644 --- a/lib/triggers/index.d.ts +++ b/lib/triggers/index.d.ts @@ -1,2 +1,2 @@ -declare const _default: (import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger>)[]; +declare const _default: (import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger> | import("oak-domain").Trigger>)[]; export default _default; diff --git a/lib/triggers/notification.js b/lib/triggers/notification.js index a0d2a9adc..a7970e581 100644 --- a/lib/triggers/notification.js +++ b/lib/triggers/notification.js @@ -2,11 +2,11 @@ Object.defineProperty(exports, "__esModule", { value: true }); const assert_1 = require("oak-domain/lib/utils/assert"); const oak_external_sdk_1 = require("oak-external-sdk"); -const url_1 = require("oak-domain/lib/utils/domain"); +const domain_1 = require("oak-domain/lib/utils/domain"); const uuid_1 = require("oak-domain/lib/utils/uuid"); const sms_1 = require("../utils/sms"); const message_1 = require("./message"); -const domain_1 = require("../utils/domain"); +const domain_2 = require("../utils/domain"); async function sendNotification(notification, context) { const { data, templateId, channel, messageSystemId, data1, id } = notification; const [messageSystem] = await context.select('messageSystem', { @@ -50,7 +50,7 @@ async function sendNotification(notification, context) { const url = pathname.startsWith('/') ? `pages${pathname}/index` : `pages/${pathname}/index`; - page = (0, url_1.composeUrl)(url, Object.assign({}, router.props, router.state)); + page = (0, domain_1.composeUrl)(url, Object.assign({}, router.props, router.state)); } // 根据当前环境决定消息推哪个版本 const StateDict = { @@ -119,11 +119,11 @@ async function sendNotification(notification, context) { const url = pathname.startsWith('/') ? `pages${pathname}/index` : `pages/${pathname}/index`; - page = (0, url_1.composeUrl)(url, Object.assign({}, router.props, router.state)); + page = (0, domain_1.composeUrl)(url, Object.assign({}, router.props, router.state)); } else { - const url = (0, domain_1.composeDomainUrl)(domain, pathname); - page = (0, url_1.composeUrl)(url, Object.assign({}, router.props, router.state)); + const url = (0, domain_2.composeDomainUrl)(domain, pathname); + page = (0, domain_1.composeUrl)(url, Object.assign({}, router.props, router.state)); } } try { diff --git a/lib/triggers/toDo.d.ts b/lib/triggers/toDo.d.ts index 95d028df6..3c8646ad8 100644 --- a/lib/triggers/toDo.d.ts +++ b/lib/triggers/toDo.d.ts @@ -12,7 +12,7 @@ export declare function createToDo; +}, userIds?: string[]): Promise<0 | 1>; /** * 完成todo例程,当在entity对象上进行action操作时(操作条件是filter),将对应的todo完成 * 必须在entity的action的后trigger中调用 diff --git a/lib/types/Page.d.ts b/lib/types/Page.d.ts index 5a7deaa05..7f540de0a 100644 --- a/lib/types/Page.d.ts +++ b/lib/types/Page.d.ts @@ -13,6 +13,7 @@ import { FrontendRuntimeContext } from '../context/FrontendRuntimeContext'; export type OakComponentOption, FrontCxt extends FrontendRuntimeContext>, AD extends Record>, FD extends Record, FormedData extends Record, TData extends Record, TProperty extends DataOption, TMethod extends Record> = BaseOakComponentOption, FD & GFD>, FormedData, TData, TProperty, TMethod, { subscribeMpMessage: (messageTypes: string[], haveToAccept?: boolean, tip?: string) => Promise; }> & Partial<{ + userInsensitive?: true; wechatMp: { relatedMessageTypes?: string[]; }; diff --git a/src/components/message/index.ts b/src/components/message/index.ts index 1c4443174..f4fde6596 100644 --- a/src/components/message/index.ts +++ b/src/components/message/index.ts @@ -24,13 +24,5 @@ export default OakComponent({ data, }; }, - lifetimes: { - attached() { - this.subscribed!.push( - this.features.message.subscribe( - () => this.reRender() - ) - ); - } - } + features: ['message'], }); diff --git a/src/components/message/list/index.ts b/src/components/message/list/index.ts index 69b53316a..e11dc8553 100644 --- a/src/components/message/list/index.ts +++ b/src/components/message/list/index.ts @@ -51,13 +51,7 @@ export default OakComponent({ messages, }; }, - lifetimes: { - attached() { - this.subscribed.push( - this.features.token.subscribe(() => this.reRender()) - ); - }, - }, + features: ['message'], methods: { goDetailById(id: string) { this.navigateTo({ diff --git a/src/components/my/avatar/index.ts b/src/components/my/avatar/index.ts index d52a96010..e9c3a4716 100644 --- a/src/components/my/avatar/index.ts +++ b/src/components/my/avatar/index.ts @@ -23,11 +23,4 @@ export default OakComponent({ avatarUrl: '', }; }, - lifetimes: { - attached() { - this.subscribed.push( - this.features.token.subscribe(() => this.reRender()) - ); - }, - }, }); diff --git a/src/components/my/info/index.ts b/src/components/my/info/index.ts index 2c432643b..48ba4a011 100644 --- a/src/components/my/info/index.ts +++ b/src/components/my/info/index.ts @@ -38,16 +38,7 @@ export default OakComponent({ properties: { showLogout: false, }, - lifetimes: { - attached() { - this.subscribed.push( - this.features.token.subscribe(() => this.reRender()) - ); - this.subscribed.push( - this.features.cache.subscribe(() => this.reRender()) - ); - }, - }, + features: ['cache'], methods: { logout() { this.features.token.logout(); diff --git a/src/features/token.ts b/src/features/token.ts index 112a92f91..69726f3c5 100644 --- a/src/features/token.ts +++ b/src/features/token.ts @@ -48,6 +48,7 @@ export class Token< else { this.tokenValue = undefined; } + this.publish(); } constructor(cache: Cache, storage: LocalStorage, environment: Environment) { @@ -255,7 +256,7 @@ export class Token< code, env: env as WechatMpEnv, }); - this.publish(); + // this.publish(); } async wakeupParasite(id: string) { diff --git a/src/page.mp.ts b/src/page.mp.ts index 853c48fdd..e9c840731 100644 --- a/src/page.mp.ts +++ b/src/page.mp.ts @@ -124,13 +124,28 @@ export function createComponent< >, features: BasicFeatures> & FD, ) { - const { wechatMp, methods, lifetimes, ...rest } = option; + const { wechatMp, data, methods, lifetimes, userInsensitive, ...rest } = option; const { relatedMessageTypes } = wechatMp || {}; - const { ready, attached, ...restLifeTimes } = lifetimes || {}; + const { ready, attached, show, hide, ...restLifeTimes } = lifetimes || {}; - return createBaseComponent Promise; }>({ + data: typeof data === 'function' ? function() { + return { + __userId: undefined, + ...(data.call(this)), + } as TData & { + __userId: string | undefined; + } + } : { + __userId: undefined, + ...data, + } as TData & { + __userId: string | undefined; + }, methods: { async subscribeMpMessage(messageTypes: string[], haveToAccept?: boolean, tip?: string) { return await subscribeMpMessage.call(this as any, messageTypes, haveToAccept, tip); @@ -139,11 +154,9 @@ export function createComponent< }, lifetimes: { attached() { - this.subscribed.push( - this.features.token.subscribe( - () => this.refresh() - ) - ); + if (!userInsensitive) { + this.addFeatureSub('token', () => this.refresh()); + } attached && attached.call(this); }, ready() { @@ -197,6 +210,22 @@ export function createComponent< } ready && ready.call(this); }, + show() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + if (userId !== this.state.__userId) { + this.refresh(); + } + } + }, + hide() { + if (!userInsensitive) { + const userId = this.features.token.getUserId(true); + this.setState({ + __userId: userId as string | undefined, + } as any); + } + }, ...restLifeTimes, }, wechatMp, diff --git a/src/page.native.ts b/src/page.native.ts index 8e093dc39..4bd8bfa9a 100644 --- a/src/page.native.ts +++ b/src/page.native.ts @@ -52,11 +52,7 @@ export function createComponent< }, lifetimes: { attached() { - this.subscribed.push( - this.features.token.subscribe( - () => this.refresh() - ) - ); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/src/page.web.ts b/src/page.web.ts index 3a2d89f82..c40fb3a37 100644 --- a/src/page.web.ts +++ b/src/page.web.ts @@ -52,11 +52,7 @@ export function createComponent< }, lifetimes: { attached() { - this.subscribed.push( - this.features.token.subscribe( - () => this.refresh() - ) - ); + this.addFeatureSub('token', () => this.refresh()); attached && attached.call(this); }, ...restLifeTimes, diff --git a/src/types/Page.ts b/src/types/Page.ts index 30e96bf48..de4452f97 100644 --- a/src/types/Page.ts +++ b/src/types/Page.ts @@ -31,6 +31,7 @@ export type OakComponentOption< > = BaseOakComponentOption, FD & GFD>, FormedData, TData, TProperty, TMethod, { subscribeMpMessage: (messageTypes: string[], haveToAccept?: boolean, tip?: string) => Promise; }> & Partial<{ + userInsensitive?: true; wechatMp: { relatedMessageTypes?: string[]; }