Skip to content

Commit

Permalink
fix alipay mp api & optimize offline log upload behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
qkang07 committed Nov 28, 2024
1 parent f4f6574 commit 4b05167
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
20 changes: 11 additions & 9 deletions packages/page-spy-mp-base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,17 @@ class PageSpy {
{
text: 'PageSpy 房间号:' + this.address.slice(0, 4),
action() {
mp.setClipboardData({
data: that.getDebugLink(),
success() {
mp.showToast({
title: '复制成功',
icon: 'success',
});
},
});
if (mp.setClipboardData) {
mp.setClipboardData({
data: that.getDebugLink(),
success() {
mp.showToast({
title: '复制成功',
icon: 'success',
});
},
});
}
},
},
];
Expand Down
5 changes: 5 additions & 0 deletions packages/page-spy-plugin-mp-data-harbor/src/harbor/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ export type CacheMessageItem = Pick<
> & {
timestamp: number;
};

export interface WholeActionParams {
clearCache?: boolean;
remark?: string;
}
61 changes: 43 additions & 18 deletions packages/page-spy-plugin-mp-data-harbor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { removeEndSlash } from '@huolala-tech/page-spy-base/dist/utils';
import { MemoryHarbor } from './harbor/memoryHarbor';
import { startUpload } from './utils/upload';
import { buildSearchParams, getDeviceId, makeData, makeFile } from './utils';
import { DataType } from './harbor/base';
import { DataType, WholeActionParams } from './harbor/base';
import {
getMPSDK,
type Client,
Expand Down Expand Up @@ -114,17 +114,50 @@ export default class MPDataHarborPlugin implements PageSpyPlugin {
{
text: '上传离线日志',
action: async () => {
const result = await this.upload();
const mp = getMPSDK();
mp.showLoading({ title: '正在上传离线日志...' });
try {
const result = await this.upload();
mp.hideLoading();
if (result) {
if (mp.setClipboardData) {
mp.showModal({
title: '上传成功',
confirmText: '复制链接',
showCancel: false,
success(res) {
if (res.confirm) {
mp.setClipboardData({
data: result,
});
}
},
});
} else {
mp.showModal({
title: '上传成功',
content: result,
showCancel: false,
});
}
} else {
mp.showToast({
title: '上传失败',
});
}
} catch (e) {
mp.hideLoading();
mp.showToast({
title: '上传失败',
});
}
},
},
];
}

async upload(clearCache = true) {
async upload(params?: WholeActionParams) {
const mp = getMPSDK();
mp.showLoading({
title: '正在上传离线日志...',
});
const { filename } = this.$harborConfig;
const { project = '', title = '' } = this.$pageSpyConfig || {};
const tags = {
Expand All @@ -133,8 +166,8 @@ export default class MPDataHarborPlugin implements PageSpyPlugin {
deviceId: getDeviceId(),
// userAgent: navigator.userAgent,
userAgent: this.client?.getName(),
remark: params?.remark || '',
};

const data = [...this.harbor.container];
data.push(this.makeMetaInfo());

Expand All @@ -146,26 +179,18 @@ export default class MPDataHarborPlugin implements PageSpyPlugin {
url,
});

if (clearCache) {
if (params?.clearCache !== false) {
this.harbor.clear();
this.$socketStore?.dispatchEvent('harbor-clear', null);
}
mp.hideLoading();
mp.showToast({
title: '离线日志上传成功',
icon: 'success',
});
} catch (e: any) {
psLog.error(e);
mp.hideLoading();
mp.showToast({
icon: 'error',
title: '离线日志上传失败',
});
return '';
}
// remove the local file
const fs = mp.getFileSystemManager();
fs.unlinkSync(path);
return url;
}

onReset() {
Expand Down

0 comments on commit 4b05167

Please sign in to comment.