feat: 页面分享设置
This commit is contained in:
@@ -151,17 +151,26 @@ this.initPageInfo({ title: string, desc?: string, functionId: string })
|
||||
|
||||
导出并保存图片(用于打印)。
|
||||
|
||||
### getShareOptions()
|
||||
### getShareOptions() / getAppShareAppMessage() / getAppShareTimeline()
|
||||
|
||||
获取分享配置。
|
||||
全站统一使用 `config/config.ts` 中的 `defaultShareConfig`(标题、分享图);**分享 path 为当前页面**(含 `?id=` 等参数)。`createPage` 页面已内置 `onShareAppMessage` / `onShareTimeline`。
|
||||
|
||||
### onShareAppMessage()
|
||||
收藏、我的、设置页在 `*.json` 中关闭分享,并在 `onLoad` 调用 `disablePageShareMenu()`。
|
||||
|
||||
微信小程序分享处理函数。
|
||||
普通 `Page({})` 可展开:
|
||||
|
||||
### onShareTimeline()
|
||||
```typescript
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
|
||||
微信朋友圈分享处理函数。
|
||||
Page({
|
||||
// ...
|
||||
...appSharePageMethods,
|
||||
});
|
||||
```
|
||||
|
||||
### onShareAppMessage() / onShareTimeline()
|
||||
|
||||
由 `pageMixin` 提供,分享内容固定为首页入口,埋点仍上报当前页 `pageTitle`(canvas 页)或不带标签(Tab 页)。
|
||||
|
||||
## 专注力模块使用示例
|
||||
|
||||
@@ -203,7 +212,7 @@ function focusPageInfoLookup(functionId: string) {
|
||||
const focusConfig: PageCommonMethodsConfig = {
|
||||
shareConfig: {
|
||||
title: '涂鸦丫-专注力训练',
|
||||
imageUrl: 'https://cdn.joeyone.cn/doodle/share-img/focus-share.png',
|
||||
imageUrl: 'https://cdn.joeyone.cn/doodle/share-img/share-v3-800.png',
|
||||
},
|
||||
pageInfoLookup: focusPageInfoLookup,
|
||||
};
|
||||
|
||||
+107
-22
@@ -73,17 +73,111 @@ export interface InitCanvasOptions {
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享配置选项
|
||||
* 分享配置选项(文案/图统一,path 为当前页)
|
||||
*/
|
||||
export interface ShareOptions {
|
||||
/**
|
||||
* 页面路径(相对于 mathPages 目录,例如:'missingNumber/missingNumber')
|
||||
*/
|
||||
path: string;
|
||||
title: string;
|
||||
imageUrl: string;
|
||||
}
|
||||
|
||||
type SharePathData = {
|
||||
functionId?: string;
|
||||
worksheetId?: string;
|
||||
currentMode?: string;
|
||||
};
|
||||
|
||||
type SharePathPage = {
|
||||
route?: string;
|
||||
data?: SharePathData;
|
||||
};
|
||||
|
||||
/** 禁止右上角转发/分享到朋友圈的页面 route(不含开头 /) */
|
||||
export const SHARE_DISABLED_ROUTES = new Set([
|
||||
'pages/favorites/favorites',
|
||||
'pages/profile/profile',
|
||||
'supportPages/settings/settings',
|
||||
]);
|
||||
|
||||
/** 关闭当前页分享菜单(收藏、我的、设置等) */
|
||||
export function disablePageShareMenu() {
|
||||
wx.hideShareMenu({
|
||||
menus: ['shareAppMessage', 'shareTimeline'],
|
||||
});
|
||||
}
|
||||
|
||||
/** 根据页面 route 与 data 生成分享 path */
|
||||
export function buildPageSharePath(page?: SharePathPage): string {
|
||||
const route = page?.route || '';
|
||||
if (!route) {
|
||||
return defaultShareConfig.path;
|
||||
}
|
||||
|
||||
const normalized = route.startsWith('/') ? route : `/${route}`;
|
||||
const data = page?.data || {};
|
||||
const functionId = (data.functionId || data.worksheetId) as
|
||||
| string
|
||||
| undefined;
|
||||
const currentMode = data.currentMode as string | undefined;
|
||||
|
||||
if (!functionId) {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const modeQuery =
|
||||
currentMode && currentMode !== functionId
|
||||
? `&mode=${currentMode}`
|
||||
: '';
|
||||
return `${normalized}?id=${functionId}${modeQuery}`;
|
||||
}
|
||||
|
||||
/** 朋友圈分享 query(对应当前页 path 的查询串) */
|
||||
export function buildPageShareTimelineQuery(page?: SharePathPage): string {
|
||||
const path = buildPageSharePath(page);
|
||||
const qIndex = path.indexOf('?');
|
||||
return qIndex >= 0 ? path.slice(qIndex + 1) : '';
|
||||
}
|
||||
|
||||
/** 全站统一分享文案与图;path 默认当前页 */
|
||||
export function getAppShareAppMessage(
|
||||
trackerLabel?: string,
|
||||
page?: SharePathPage,
|
||||
) {
|
||||
if (trackerLabel) {
|
||||
tracker.reportShare(trackerLabel);
|
||||
}
|
||||
return {
|
||||
title: defaultShareConfig.title,
|
||||
path: buildPageSharePath(page),
|
||||
imageUrl: defaultShareConfig.imageUrl,
|
||||
};
|
||||
}
|
||||
|
||||
/** 全站统一朋友圈分享;query 对应当前页 */
|
||||
export function getAppShareTimeline(
|
||||
trackerLabel?: string,
|
||||
page?: SharePathPage,
|
||||
) {
|
||||
if (trackerLabel) {
|
||||
tracker.reportShare(trackerLabel);
|
||||
}
|
||||
return {
|
||||
title: defaultShareConfig.title,
|
||||
query: buildPageShareTimelineQuery(page),
|
||||
imageUrl: defaultShareConfig.imageUrl,
|
||||
};
|
||||
}
|
||||
|
||||
/** 供 Page({}) 直接展开:统一转发 / 分享到朋友圈(path 为当前页) */
|
||||
export const appSharePageMethods = {
|
||||
onShareAppMessage(this: SharePathPage) {
|
||||
return getAppShareAppMessage(undefined, this);
|
||||
},
|
||||
onShareTimeline(this: SharePathPage) {
|
||||
return getAppShareTimeline(undefined, this);
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* 页面信息接口
|
||||
*/
|
||||
@@ -104,8 +198,10 @@ export interface PageCommonMethodsConfig {
|
||||
/**
|
||||
* 分享配置
|
||||
*/
|
||||
/** 可选;默认使用 config 中的 defaultShareConfig(统一首页 path / 文案 / 分享图) */
|
||||
shareConfig?: {
|
||||
title: string;
|
||||
path: string;
|
||||
imageUrl: string;
|
||||
};
|
||||
/**
|
||||
@@ -256,36 +352,25 @@ export function getPageCommonMethods(config: PageCommonMethodsConfig = {}) {
|
||||
},
|
||||
|
||||
getShareOptions(this: PageCanvasInstance): ShareOptions {
|
||||
const route = this.route || '';
|
||||
const { functionId, currentMode } = this.data;
|
||||
const currentModeQuery = currentMode ? `&mode=${currentMode}` : '';
|
||||
const path = `${route}?id=${functionId}${currentModeQuery}`;
|
||||
|
||||
console.log('getShareOptions path', path);
|
||||
return {
|
||||
...shareConfig,
|
||||
path,
|
||||
title: shareConfig.title,
|
||||
path: buildPageSharePath(this),
|
||||
imageUrl: shareConfig.imageUrl,
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享小程序
|
||||
* 分享小程序(统一文案与分享图,path 为当前页)
|
||||
*/
|
||||
onShareAppMessage(this: PageCanvasInstance) {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare(this.data.pageTitle);
|
||||
|
||||
return this.getShareOptions();
|
||||
return getAppShareAppMessage(this.data.pageTitle, this);
|
||||
},
|
||||
|
||||
/**
|
||||
* 分享到朋友圈
|
||||
* 分享到朋友圈(统一文案与分享图,query 为当前页参数)
|
||||
*/
|
||||
onShareTimeline(this: PageCanvasInstance) {
|
||||
console.log('onShareTimeline');
|
||||
// 上报分享埋点
|
||||
tracker.reportShare(this.data.pageTitle);
|
||||
return this.getShareOptions();
|
||||
return getAppShareTimeline(this.data.pageTitle, this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
} from '../shared/getWordsSvgJson';
|
||||
import { WORDS, getCategoryTabIndex } from '../../core/data/words';
|
||||
import { CharacterItem } from '../../types/characterType';
|
||||
import tracker from '../../utils/tracker';
|
||||
import { createPage } from '../../base/pageMixin';
|
||||
import { defaultShareConfig } from '../../config/config';
|
||||
import {
|
||||
@@ -498,22 +497,6 @@ createPage(
|
||||
|
||||
onShare() {},
|
||||
|
||||
onShareAppMessage() {
|
||||
tracker.reportShare('练字贴');
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
path: `/chinesePages/handwritingSheet/handwritingSheet?id=${this.data.currentMode}`,
|
||||
};
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
tracker.reportShare('练字贴');
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
query: `id=${this.data.currentMode}`,
|
||||
};
|
||||
},
|
||||
|
||||
getPublishMeta(): DebugPublishMeta {
|
||||
const meta = getPublishMetaByMode(this.data.currentMode);
|
||||
if (!meta) {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
import { SHAPES, ShapeCard } from '../../constants/shapes';
|
||||
import { WATER_COLORS, PAPER_SIZE } from '../../constants/colors';
|
||||
import ShapeDrawService from '../../service/shapeDrawService';
|
||||
import { downloadPrint, tryUnlockWithRewardedAd } from '../../utils/downloadPrint';
|
||||
import {
|
||||
downloadPrint,
|
||||
tryUnlockWithRewardedAd,
|
||||
} from '../../utils/downloadPrint';
|
||||
import {
|
||||
shouldShowShareGuide,
|
||||
shouldUnlockWithAd,
|
||||
@@ -316,29 +320,6 @@ Page({
|
||||
this.setData({ showShareDialog: false });
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('图形涂色');
|
||||
|
||||
return {
|
||||
title: '涂鸦丫-涂色|识字|图形|打印',
|
||||
path: '/pages/shape/index',
|
||||
imageUrl:
|
||||
'https://cdn.joeyone.cn/doodle/share-img/index-share-v2.png',
|
||||
};
|
||||
},
|
||||
onShareTimeline() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('图形涂色');
|
||||
|
||||
return {
|
||||
title: '涂鸦丫-涂色|识字|图形|打印',
|
||||
query: '/pages/shape/index',
|
||||
imageUrl:
|
||||
'https://cdn.joeyone.cn/doodle/share-img/index-share-v2.png',
|
||||
};
|
||||
},
|
||||
|
||||
/** 分享成功回调(由组件触发) */
|
||||
async onShareSuccess() {
|
||||
this.setData({ showShareDialog: false });
|
||||
@@ -355,4 +336,6 @@ Page({
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
},
|
||||
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
import { AGE_BANDS, AgeBandKey } from '../../core/data/difficulty';
|
||||
import { parseMiniProgramUrl } from '../../utils/index';
|
||||
import {
|
||||
@@ -161,4 +162,6 @@ Page({
|
||||
(e.currentTarget.dataset.title as string | undefined);
|
||||
navigateByPath(path, title);
|
||||
},
|
||||
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
import { CATEGORY_LIST_WITH_ALL } from '../../core/data/categories';
|
||||
import { takePendingCategoryTabId } from '../../utils/index';
|
||||
import { CATEGORY_DATA, type CategoryItem } from './category.data';
|
||||
@@ -320,17 +321,5 @@ Page({
|
||||
wx.navigateTo({ url: path });
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '涂鸦丫 - 全部练习分类',
|
||||
path: '/pages/category/category',
|
||||
};
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
return {
|
||||
title: '涂鸦丫 - 全部练习分类',
|
||||
query: '',
|
||||
};
|
||||
},
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"enableShareAppMessage": false,
|
||||
"enableShareTimelineMessage": false,
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "我的收藏",
|
||||
"navigationBarTextStyle": "black",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { disablePageShareMenu } from '../../base/pageMixin';
|
||||
import { NAV_INNER_PX } from '../../utils/navMetrics';
|
||||
import { getFavoriteList, removeFavorite } from '../../utils/favorites';
|
||||
import {
|
||||
@@ -167,6 +168,7 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
disablePageShareMenu();
|
||||
const win = wx.getWindowInfo();
|
||||
this.setData({
|
||||
favScrollHeight: win.windowHeight - NAV_BLOCK_HEIGHT,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
import { NAV_INNER_PX } from '../../utils/navMetrics';
|
||||
import {
|
||||
parseMiniProgramUrl,
|
||||
@@ -285,19 +286,5 @@ Page({
|
||||
navigateByPath(path, title);
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
return {
|
||||
title: '涂鸦丫 - 快来生成宝宝的专属学习卡',
|
||||
path: '/pages/home/home',
|
||||
imageUrl:
|
||||
'https://cdn.joeyone.cn/doodle/share-img/index-share-v2.png',
|
||||
};
|
||||
},
|
||||
|
||||
onShareTimeline() {
|
||||
return {
|
||||
title: '涂鸦丫 - 快来生成宝宝的专属学习卡',
|
||||
query: '',
|
||||
};
|
||||
},
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"enableShareAppMessage": false,
|
||||
"enableShareTimelineMessage": false,
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "我的",
|
||||
"navigationBarTextStyle": "black",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { disablePageShareMenu } from '../../base/pageMixin';
|
||||
import { getDownloadLogCount } from '../../utils/downloadLogs';
|
||||
import { getFavoriteCount } from '../../utils/favorites';
|
||||
import {
|
||||
@@ -23,6 +24,7 @@ Page({
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
disablePageShareMenu();
|
||||
this.syncUserInfoFromApp();
|
||||
const isDevEnv =
|
||||
wx.getAccountInfoSync().miniProgram.envVersion === 'develop';
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { FOCUS_FUNCTION_TYPES } from '../../constants/focusFunctions';
|
||||
import tracker from '../../utils/tracker';
|
||||
import { defaultShareConfig } from '../../config/config';
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -42,22 +41,5 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('专注力游戏');
|
||||
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
path: `/pages/focusIndex/focusIndex`,
|
||||
};
|
||||
},
|
||||
onShareTimeline() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('专注力游戏');
|
||||
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
query: `/pages/focusIndex/focusIndex`,
|
||||
};
|
||||
},
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MATH_FUNCTION_TYPES } from '../../constants/mathFunctions';
|
||||
import tracker from '../../utils/tracker';
|
||||
import { defaultShareConfig } from '../../config/config';
|
||||
import { appSharePageMethods } from '../../base/pageMixin';
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -38,22 +37,5 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onShareAppMessage() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('数感启蒙');
|
||||
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
path: `/pages/mathIndex/mathIndex`,
|
||||
};
|
||||
},
|
||||
onShareTimeline() {
|
||||
// 上报分享埋点
|
||||
tracker.reportShare('数感启蒙');
|
||||
|
||||
return {
|
||||
...defaultShareConfig,
|
||||
query: `/pages/mathIndex/mathIndex`,
|
||||
};
|
||||
},
|
||||
...appSharePageMethods,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"enableShareAppMessage": false,
|
||||
"enableShareTimelineMessage": false,
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "设置",
|
||||
"navigationBarTextStyle": "black",
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { disablePageShareMenu } from '../../base/pageMixin';
|
||||
import { clearUser } from '../../utils/auth';
|
||||
|
||||
Page({
|
||||
onLoad() {
|
||||
disablePageShareMenu();
|
||||
},
|
||||
|
||||
onClearProfile() {
|
||||
wx.showModal({
|
||||
title: '确认删除',
|
||||
|
||||
Reference in New Issue
Block a user