Files
MBTI_wang/miniprogram/pages/promo/poster.js
Ghost c946584a7d feat: 双端小程序分享路径与测试入口上下文统一
1、修复了结果页、测试页与 test-select 的跳转上下文丢失问题。

2、调整 api/Test 与小程序 app/share 逻辑,补全第三方/企业场景参数透传。

3、优化 DISC/MBTI/PDP/SBTI 结果页样式与按钮交互,一致化微信与抖音端。

Made-with: Cursor
2026-04-14 16:40:20 +08:00

86 lines
2.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const app = getApp()
const { getApiBase } = require('../../utils/request')
const { getEffectiveEnterpriseId } = require('../../utils/enterpriseContext.js')
Page({
data: {
loading: true,
loadingText: '正在生成海报...',
posterUrl: ''
},
onLoad() {
app.ensureLogin()
.then((ok) => {
if (!ok) {
this.setData({ loading: false, loadingText: '请先登录后生成海报' })
wx.showToast({ title: '请先登录', icon: 'none' })
return
}
this.loadPoster()
})
.catch(() => {
this.setData({ loading: false, loadingText: '登录失败,请重试' })
})
},
/** 从后端接口下载完整合成海报 */
loadPoster() {
const app = getApp()
const gd = app.globalData || {}
const storedUser = wx.getStorageSync('userInfo') || {}
const userInfo = gd.userInfo || storedUser
const apiBase = getApiBase()
const token = wx.getStorageSync('token') || gd.token || ''
const scope = gd.appScope || 'personal'
// 企业 ID按优先级取 scene > globalData.userInfo > storage.userInfo
const eid = scope === 'enterprise' ? getEffectiveEnterpriseId() : null
let url = apiBase.replace(/\/$/, '') + '/api/distribution/poster'
if (eid) url += `?eid=${eid}&scope=enterprise`
else if (scope === 'enterprise') url += '?scope=enterprise' // 企业模式但 eid 未知,后端从 DB 取
else url += '?scope=personal'
wx.downloadFile({
url,
header: token ? { Authorization: 'Bearer ' + token } : {},
success: (res) => {
if (res.statusCode === 200 && res.tempFilePath) {
this.setData({ posterUrl: res.tempFilePath, loading: false })
} else {
this.setData({ loadingText: '海报生成失败', loading: false })
wx.showToast({ title: '生成失败', icon: 'none' })
}
},
fail: () => {
this.setData({ loadingText: '请求失败,请重试', loading: false })
wx.showToast({ title: '请求失败', icon: 'none' })
}
})
},
/** 保存到相册 */
savePoster() {
if (this.data.loading || !this.data.posterUrl) return
wx.showLoading({ title: '正在保存...' })
wx.saveImageToPhotosAlbum({
filePath: this.data.posterUrl,
success: () => {
wx.hideLoading()
wx.showToast({ title: '已保存到相册', icon: 'success' })
},
fail: (err) => {
wx.hideLoading()
if (err.errMsg && err.errMsg.indexOf('auth deny') >= 0) {
wx.showModal({
title: '提示',
content: '需要您授权保存图片到相册',
success: (r) => { if (r.confirm) wx.openSetting() }
})
} else {
wx.showToast({ title: '保存失败', icon: 'none' })
}
}
})
}
})