Skip to content

Commit

Permalink
fix(frontend): share with local image (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinganix authored Jan 28, 2024
1 parent 66e8749 commit 88cfc55
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=?'
```
Expand Down
4 changes: 2 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=?'
```
Expand All @@ -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: 数据库密码

Expand Down
15 changes: 14 additions & 1 deletion frontend/weapp/src/helpers/wx/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
CompOtherOption,
CustomOption,
FullProperty,
ICustomShareContent,
ICustomTimelineContent,
MethodOption,
PageData,
PageDataOption,
Expand All @@ -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<string, Method> & Script;
Expand Down Expand Up @@ -84,7 +87,17 @@ export function componentMethods<T extends ComponentScript>(
}

export function pageMethods<T extends ComponentScript>(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<T extends ComponentScript> {
Expand Down
5 changes: 5 additions & 0 deletions frontend/weapp/src/modules/utils/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
12 changes: 2 additions & 10 deletions frontend/weapp/src/pages/moment/detail/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -81,14 +81,6 @@ export class MomentDetailScript extends ComponentScript<Source> {
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<void> {
if (!(await tryInitializeModules())) {
return;
Expand Down
17 changes: 2 additions & 15 deletions frontend/weapp/src/pages/moment/edit/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -96,14 +91,6 @@ export class MomentEditScript extends ComponentScript<Source> {
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"];
}
Expand Down
12 changes: 2 additions & 10 deletions frontend/weapp/src/pages/moment/list/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]: "动态",
Expand Down Expand Up @@ -71,14 +71,6 @@ export class MomentListScript extends ComponentScript<Source> {
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;
Expand Down
18 changes: 3 additions & 15 deletions frontend/weapp/src/pages/puzzle/detail/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -47,6 +42,7 @@ const CONNECTOR = new Connector({
configStore: DataPiker.align<ConfigStore>(["adCustomPuzzleReply", "preview"]),
store: DataPiker.align<PuzzleDetailScript>(DataPiker.ALL),
});

interface Source extends SourceType<typeof CONNECTOR> {}

export class PuzzleDetailScript extends ComponentScript<Source> {
Expand Down Expand Up @@ -92,14 +88,6 @@ export class PuzzleDetailScript extends ComponentScript<Source> {
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;
Expand Down
11 changes: 1 addition & 10 deletions frontend/weapp/src/pages/puzzle/ranking/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigStore>(["adCustomPuzzleRanking", "preview"]),
Expand Down Expand Up @@ -66,14 +65,6 @@ export class PuzzleRankingScript extends ComponentScript<Source> {
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<void> {
this.loading = true;
if (!(await tryInitializeModules())) {
Expand Down
9 changes: 0 additions & 9 deletions frontend/weapp/src/pages/user/detail/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -59,14 +58,6 @@ export class UserDetailScript extends ComponentScript<Source> {
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();
}
Expand Down

0 comments on commit 88cfc55

Please sign in to comment.