feat: 3.5版本规划

This commit is contained in:
R524809
2026-09-24 17:14:38 +08:00
parent f82ac4d89d
commit 08d9a2792a
19 changed files with 769 additions and 45 deletions
+109 -9
View File
@@ -85,6 +85,7 @@ type SharePathData = {
functionId?: string;
worksheetId?: string;
currentMode?: string;
pageTitle?: string;
};
type SharePathPage = {
@@ -143,9 +144,13 @@ export function getAppShareAppMessage(
trackerLabel?: string,
page?: SharePathPage,
) {
if (trackerLabel) {
tracker.reportShare(trackerLabel);
}
tracker.reportShare(page?.route || trackerLabel || '', {
...(trackerLabel && { worksheet_title: trackerLabel }),
...(page?.data?.functionId || page?.data?.worksheetId
? { worksheet_id: page.data.functionId || page.data.worksheetId }
: {}),
...(page?.data?.currentMode ? { mode: page.data.currentMode } : {}),
});
return {
title: defaultShareConfig.title,
path: buildPageSharePath(page),
@@ -158,9 +163,13 @@ export function getAppShareTimeline(
trackerLabel?: string,
page?: SharePathPage,
) {
if (trackerLabel) {
tracker.reportShare(trackerLabel);
}
tracker.reportShare(page?.route || trackerLabel || '', {
...(trackerLabel && { worksheet_title: trackerLabel }),
...(page?.data?.functionId || page?.data?.worksheetId
? { worksheet_id: page.data.functionId || page.data.worksheetId }
: {}),
...(page?.data?.currentMode ? { mode: page.data.currentMode } : {}),
});
return {
title: defaultShareConfig.title,
query: buildPageShareTimelineQuery(page),
@@ -171,10 +180,10 @@ export function getAppShareTimeline(
/** 供 Page({}) 直接展开:统一转发 / 分享到朋友圈(path 为当前页) */
export const appSharePageMethods = {
onShareAppMessage(this: SharePathPage) {
return getAppShareAppMessage(undefined, this);
return getAppShareAppMessage(this.data?.pageTitle, this);
},
onShareTimeline(this: SharePathPage) {
return getAppShareTimeline(undefined, this);
return getAppShareTimeline(this.data?.pageTitle, this);
},
};
@@ -331,6 +340,7 @@ export function getPageCommonMethods(config: PageCommonMethodsConfig = {}) {
errorToast: '请先生成内容',
trackerName: this.data.pageTitle,
trackerMode: this.data.currentMode,
trackerPage: this.route,
worksheetId,
};
@@ -394,6 +404,7 @@ export function getPageCommonMethods(config: PageCommonMethodsConfig = {}) {
errorToast: '请先生成内容',
trackerName: this.data.pageTitle,
trackerMode: this.data.currentMode,
trackerPage: this.route,
worksheetId,
});
}
@@ -591,6 +602,11 @@ export function getPageCommonMethods(config: PageCommonMethodsConfig = {}) {
});
wx.setNavigationBarTitle({ title });
tracker.reportPreviewView(this.route || '', {
worksheet_id: functionId,
worksheet_title: title,
...(this.data.currentMode ? { mode: this.data.currentMode } : {}),
});
},
};
}
@@ -607,6 +623,90 @@ export function applyPageMixin(
config: PageCommonMethodsConfig = {},
) {
const commonMethods = getPageCommonMethods(config);
const trackedOptions = { ...pageOptions };
const generationStartKey = '__generationTrackingStartedAt';
const beginGenerationTracking = function (this: PageCanvasInstance) {
if ((this as any)[generationStartKey]) return;
const worksheetId =
typeof this.getWorksheetStatsId === 'function'
? this.getWorksheetStatsId()
: this.data.functionId;
(this as any)[generationStartKey] = Date.now();
tracker.reportGenerateStart(this.route || '', {
worksheet_id: worksheetId || '',
...(this.data.currentMode ? { mode: this.data.currentMode } : {}),
});
};
const originalOnRandom = pageOptions.onRandom;
if (typeof originalOnRandom === 'function') {
trackedOptions.onRandom = function (
this: PageCanvasInstance,
...args: any[]
) {
beginGenerationTracking.call(this);
return originalOnRandom.apply(this, args);
};
}
const originalOnPreviewRefresh = pageOptions.onPreviewRefresh;
if (typeof originalOnPreviewRefresh === 'function') {
trackedOptions.onPreviewRefresh = function (
this: PageCanvasInstance,
...args: any[]
) {
beginGenerationTracking.call(this);
return originalOnPreviewRefresh.apply(this, args);
};
}
const originalDrawCanvas = pageOptions.drawCanvas;
if (typeof originalDrawCanvas === 'function') {
trackedOptions.drawCanvas = async function (
this: PageCanvasInstance,
...args: any[]
) {
try {
const result = await originalDrawCanvas.apply(this, args);
const startedAt = (this as any)[generationStartKey] as
| number
| undefined;
if (startedAt) {
delete (this as any)[generationStartKey];
const worksheetId =
typeof this.getWorksheetStatsId === 'function'
? this.getWorksheetStatsId()
: this.data.functionId;
tracker.reportGenerateResult(
this.route || '',
this.data.hasContent !== false,
{
worksheet_id: worksheetId || '',
duration_ms: Date.now() - startedAt,
...(this.data.currentMode
? { mode: this.data.currentMode }
: {}),
},
);
}
return result;
} catch (error) {
const startedAt = (this as any)[generationStartKey] as
| number
| undefined;
if (startedAt) {
delete (this as any)[generationStartKey];
tracker.reportGenerateResult(this.route || '', false, {
worksheet_id: this.data.functionId || '',
duration_ms: Date.now() - startedAt,
fail_reason: 'draw_exception',
});
}
throw error;
}
};
}
// 提取 pageOptions 中的 data(如果有)
const pageData = pageOptions.data || {};
@@ -615,7 +715,7 @@ export function applyPageMixin(
// 注意:pageOptions 放在后面,这样页面可以覆盖公共方法
const mergedOptions: any = {
...commonMethods,
...pageOptions,
...trackedOptions,
// 处理 data 的合并(需要特殊处理,避免覆盖)
data: {
...pageData,