From 88cfc5514fb54fdeef2d4339b2f5d2d2313588a9 Mon Sep 17 00:00:00 2001 From: "gan.jin" Date: Sun, 28 Jan 2024 20:39:36 +0800 Subject: [PATCH] fix(frontend): share with local image (#3) --- README.md | 2 +- README.zh.md | 4 ++-- frontend/weapp/src/helpers/wx/adapter.ts | 15 ++++++++++++++- .../weapp/src/modules/utils/app.service.ts | 5 +++++ .../weapp/src/pages/moment/detail/script.ts | 12 ++---------- frontend/weapp/src/pages/moment/edit/script.ts | 17 ++--------------- frontend/weapp/src/pages/moment/list/script.ts | 12 ++---------- .../weapp/src/pages/puzzle/detail/script.ts | 18 +++--------------- .../weapp/src/pages/puzzle/ranking/script.ts | 11 +---------- frontend/weapp/src/pages/user/detail/script.ts | 9 --------- 10 files changed, 32 insertions(+), 73 deletions(-) diff --git a/README.md b/README.md index 8ddcb166..d52a025f 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The source code of the 'Guess Who I Am' Wechat miniprogram #### Linux or MacOS ```shell -git@github.com:jinganix/guess.git +git clone git@github.com:jinganix/guess.git cd guess/service/guess ./gradlew service:guess:bootRun --args='--core.weapp.app-id=? --core.weapp.app-secret=? --core.url.db-mysql=? --spring.datasource.username=? --spring.datasource.password=?' ``` diff --git a/README.zh.md b/README.zh.md index 1b2d72e2..48490248 100644 --- a/README.zh.md +++ b/README.zh.md @@ -12,7 +12,7 @@ #### Linux和MacOS ```shell -git@github.com:jinganix/guess.git +git clone git@github.com:jinganix/guess.git cd guess/service/guess ./gradlew service:guess:bootRun --args='--core.weapp.app-id=? --core.weapp.app-secret=? --core.url.db-mysql=? --spring.datasource.username=? --spring.datasource.password=?' ``` @@ -25,7 +25,7 @@ cd guess/service/guess - core.weapp.app-id: 微信小程序的`app-id` - core.weapp.app-secret: 微信小程序的`app-secret` -- core.url.db-mysql: mysql数据库连接地址,如`jdbc:mysql://127.0.0.1:3306/guess` +- core.url.db-mysql: mysql数据库连接地址,如`jdbc:mysql://127.0.0.1:3306/guess` - spring.datasource.username: 数据库用户名 - spring.datasource.password: 数据库密码 diff --git a/frontend/weapp/src/helpers/wx/adapter.ts b/frontend/weapp/src/helpers/wx/adapter.ts index 0e4a03f6..de2559ec 100644 --- a/frontend/weapp/src/helpers/wx/adapter.ts +++ b/frontend/weapp/src/helpers/wx/adapter.ts @@ -27,6 +27,8 @@ import { CompOtherOption, CustomOption, FullProperty, + ICustomShareContent, + ICustomTimelineContent, MethodOption, PageData, PageDataOption, @@ -39,6 +41,7 @@ import { } from "@helpers/wx/wx.types"; import { includes } from "lodash"; import { cast } from "@helpers/utils/utils"; +import { appService } from "@modules/container"; type Method = (this: Script, ...args: unknown[]) => void; type Methods = Record & Script; @@ -84,7 +87,17 @@ export function componentMethods( } export function pageMethods(obj: { prototype: T }): MethodOption { - return delegatedMethods(obj, PAGE_LIFETIMES); + return { + ...delegatedMethods(obj, PAGE_LIFETIMES), + + onShareAppMessage(this: ScriptedPage): ICustomShareContent | void { + return appService.share(this.route ?? ""); + }, + + onShareTimeline(this: ScriptedPage): ICustomTimelineContent | void { + return appService.shareTimeline(this.route ?? ""); + }, + }; } interface ScriptOption { diff --git a/frontend/weapp/src/modules/utils/app.service.ts b/frontend/weapp/src/modules/utils/app.service.ts index 4ecd0f79..f653b819 100644 --- a/frontend/weapp/src/modules/utils/app.service.ts +++ b/frontend/weapp/src/modules/utils/app.service.ts @@ -31,6 +31,11 @@ export class AppService { } share(route: string): ICustomShareContent | void { + console.log({ + imageUrl: `${relativePrefix(route)}assets/images/puzzle.png`, + path: `${Pages.PUZZLE_DETAIL}`, + title: "看图猜成语", + }); return { imageUrl: `${relativePrefix(route)}assets/images/puzzle.png`, path: `${Pages.PUZZLE_DETAIL}`, diff --git a/frontend/weapp/src/pages/moment/detail/script.ts b/frontend/weapp/src/pages/moment/detail/script.ts index e793e6ee..dcf11347 100644 --- a/frontend/weapp/src/pages/moment/detail/script.ts +++ b/frontend/weapp/src/pages/moment/detail/script.ts @@ -18,7 +18,7 @@ import { httpService } from "@helpers/service/http.service"; import { MomentRetrieveRequest, MomentRetrieveResponse } from "@proto/MomentProto"; -import { appService, cacheService, components, configStore } from "@modules/container"; +import { cacheService, components, configStore } from "@modules/container"; import { ComponentScript, makePublicObservable } from "@helpers/wx/component.script"; import { Connector, DataPiker, SourceType } from "@helpers/wx/connect"; import { ScriptedPage } from "@helpers/wx/adapter"; @@ -28,7 +28,7 @@ import { tryInitializeModules } from "@helpers/module/module.initializer"; import { Replay } from "@helpers/promise/replay"; import { Dispose } from "@helpers/types/types"; import { CommentListScript } from "@comps/comment-list/script"; -import { ICustomShareContent, ICustomTimelineContent, TappedEvent } from "@helpers/wx/wx.types"; +import { TappedEvent } from "@helpers/wx/wx.types"; import { CommentEditorScript } from "@comps/comment-editor/script"; import { classId } from "@helpers/utils/utils"; @@ -81,14 +81,6 @@ export class MomentDetailScript extends ComponentScript { this.moment = null; } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route); - } - async fetchData(force: boolean): Promise { if (!(await tryInitializeModules())) { return; diff --git a/frontend/weapp/src/pages/moment/edit/script.ts b/frontend/weapp/src/pages/moment/edit/script.ts index 3baf1de8..29fdb706 100644 --- a/frontend/weapp/src/pages/moment/edit/script.ts +++ b/frontend/weapp/src/pages/moment/edit/script.ts @@ -24,16 +24,11 @@ import { MomentCreateResponse, } from "@proto/MomentProto"; import { every, some } from "lodash"; -import { appService, components, userExtraStore } from "@modules/container"; +import { components, userExtraStore } from "@modules/container"; import { ComponentScript, makePublicObservable } from "@helpers/wx/component.script"; import { Connector, DataPiker, SourceType } from "@helpers/wx/connect"; import { ScriptedPage } from "@helpers/wx/adapter"; -import { - CustomEvent, - ICustomShareContent, - ICustomTimelineContent, - Input, -} from "@helpers/wx/wx.types"; +import { CustomEvent, Input } from "@helpers/wx/wx.types"; import { classId, trimContent } from "@helpers/utils/utils"; import { MomentListScript } from "../list/script"; @@ -96,14 +91,6 @@ export class MomentEditScript extends ComponentScript { this.options = new EditOptions(); } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route); - } - onCollapse(): void { this.activeNames = this.activeNames.length ? [] : ["1"]; } diff --git a/frontend/weapp/src/pages/moment/list/script.ts b/frontend/weapp/src/pages/moment/list/script.ts index 110d8651..2dc3c38c 100644 --- a/frontend/weapp/src/pages/moment/list/script.ts +++ b/frontend/weapp/src/pages/moment/list/script.ts @@ -22,7 +22,7 @@ import { ComponentScript, makePublicObservable } from "@helpers/wx/component.scr import { Connector, DataPiker, SourceType } from "@helpers/wx/connect"; import { ConfigStore } from "@modules/config/config.store"; import { ScriptedPage } from "@helpers/wx/adapter"; -import { appService, configStore } from "@modules/container"; +import { configStore } from "@modules/container"; import { IMomentFacadePb, MomentCategory, @@ -35,7 +35,7 @@ import { find } from "lodash"; import { CacheKey } from "@modules/cache/cache.service"; import { classId, formatUrl } from "@helpers/utils/utils"; import { Pages } from "@helpers/const"; -import { ICustomShareContent, ICustomTimelineContent, TappedEvent } from "@helpers/wx/wx.types"; +import { TappedEvent } from "@helpers/wx/wx.types"; const CATEGORIES = { [MomentCategory.ALL]: "动态", @@ -71,14 +71,6 @@ export class MomentListScript extends ComponentScript { return { configStore, store: this }; } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route); - } - didMount({ category }: { category?: string }): void { super.didMount(); this.category = category ? Number(category) : MomentCategory.ALL; diff --git a/frontend/weapp/src/pages/puzzle/detail/script.ts b/frontend/weapp/src/pages/puzzle/detail/script.ts index f3d34322..cea8fc00 100644 --- a/frontend/weapp/src/pages/puzzle/detail/script.ts +++ b/frontend/weapp/src/pages/puzzle/detail/script.ts @@ -27,13 +27,8 @@ import { import { Replay } from "@helpers/promise/replay"; import { tryInitializeModules } from "@helpers/module/module.initializer"; import { classId, trimContent } from "@helpers/utils/utils"; -import { appService, components, configStore } from "@modules/container"; -import { - ICustomShareContent, - ICustomTimelineContent, - InterstitialAd, - TappedEvent, -} from "@helpers/wx/wx.types"; +import { components, configStore } from "@modules/container"; +import { InterstitialAd, TappedEvent } from "@helpers/wx/wx.types"; import { ComponentScript, makePublicObservable } from "@helpers/wx/component.script"; import { Pages } from "@helpers/const"; import { PopoverTimelineScript } from "@comps/popover-timeline/script"; @@ -47,6 +42,7 @@ const CONNECTOR = new Connector({ configStore: DataPiker.align(["adCustomPuzzleReply", "preview"]), store: DataPiker.align(DataPiker.ALL), }); + interface Source extends SourceType {} export class PuzzleDetailScript extends ComponentScript { @@ -92,14 +88,6 @@ export class PuzzleDetailScript extends ComponentScript { this.limit = 0; } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route ?? ""); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route ?? ""); - } - showAd(): void { if (!wx.createInterstitialAd) { return; diff --git a/frontend/weapp/src/pages/puzzle/ranking/script.ts b/frontend/weapp/src/pages/puzzle/ranking/script.ts index cd25c55a..2faf4b4c 100644 --- a/frontend/weapp/src/pages/puzzle/ranking/script.ts +++ b/frontend/weapp/src/pages/puzzle/ranking/script.ts @@ -25,9 +25,8 @@ import { ComponentScript, makePublicObservable } from "@helpers/wx/component.scr import { Connector, DataPiker, SourceType } from "@helpers/wx/connect"; import { ConfigStore } from "@modules/config/config.store"; import { ScriptedPage } from "@helpers/wx/adapter"; -import { appService, configStore } from "@modules/container"; +import { configStore } from "@modules/container"; import { classId } from "@helpers/utils/utils"; -import { ICustomShareContent, ICustomTimelineContent } from "@helpers/wx/wx.types"; const CONNECTOR = new Connector({ configStore: DataPiker.align(["adCustomPuzzleRanking", "preview"]), @@ -66,14 +65,6 @@ export class PuzzleRankingScript extends ComponentScript { this.rankings = []; } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route ?? ""); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route ?? ""); - } - async fetchData(force = false): Promise { this.loading = true; if (!(await tryInitializeModules())) { diff --git a/frontend/weapp/src/pages/user/detail/script.ts b/frontend/weapp/src/pages/user/detail/script.ts index 5094e127..941391bc 100644 --- a/frontend/weapp/src/pages/user/detail/script.ts +++ b/frontend/weapp/src/pages/user/detail/script.ts @@ -22,7 +22,6 @@ import { ComponentScript, makePublicObservable } from "@helpers/wx/component.scr import { Connector, DataPiker, SourceType } from "@helpers/wx/connect"; import { ScriptedPage } from "@helpers/wx/adapter"; import { ConfigStore } from "@modules/config/config.store"; -import { ICustomShareContent, ICustomTimelineContent } from "@helpers/wx/wx.types"; import { UserExtraStore } from "@modules/user/user.extra.store"; import { UserStore } from "@modules/user/user.store"; import { UserEditScript } from "@comps/user-edit/script"; @@ -59,14 +58,6 @@ export class UserDetailScript extends ComponentScript { void userExtraStore.fetchData(); } - onShareAppMessage(): ICustomShareContent | void { - return appService.share((this._comp as ScriptedPage).route); - } - - onShareTimeline(): ICustomTimelineContent | void { - return appService.shareTimeline((this._comp as ScriptedPage).route); - } - tapAvatar(): void { components.getInPage(UserEditScript, this.pageId).checkOpen(); }