feat: 添加公共配置获取与订阅消息模板加载

This commit is contained in:
邹方成 2026-01-06 02:24:42 +08:00
parent b9246bc728
commit 7edb2e7844
3 changed files with 32 additions and 5 deletions

13
App.vue
View File

@ -1,4 +1,5 @@
<script>
import { getPublicConfig } from '@/api/appUser'
export default {
onLaunch: function(options) {
console.log('App Launch', options)
@ -7,6 +8,16 @@ export default {
console.log('App Launch captured invite_code:', options.query.invite_code)
try { uni.setStorageSync('inviter_code', options.query.invite_code) } catch (e) { console.error('Save invite code failed', e) }
}
// (ID)
getPublicConfig().then(res => {
if (res && res.subscribe_templates) {
console.log('Loaded public config:', res)
try { uni.setStorageSync('subscribe_templates', res.subscribe_templates) } catch (_) {}
}
}).catch(err => {
console.warn('Failed to load public config:', err)
})
},
onShow: function() {
console.log('App Show')

View File

@ -276,6 +276,11 @@ export function getUserInfo() {
return authRequest({ url: '/api/app/users/info', method: 'GET' })
}
// 获取公开配置
export function getPublicConfig() {
return request({ url: '/api/app/config/public', method: 'GET' })
}
export const getUserTasks = getTasks
export function getInviteRecords(page = 1, page_size = 20) {
const user_id = uni.getStorageSync('user_id')

View File

@ -3,8 +3,18 @@
* 用于在抽奖前请求用户授权接收开奖通知
*/
// 抽奖结果通知模板 ID
const LOTTERY_RESULT_TEMPLATE_ID = 'O2eqJQD3pn-vQ6g2z9DWzINVwOmPoz8yW-172J_YcpI'
// 抽奖结果通知模板 ID (默认兜底)
const DEFAULT_LOTTERY_RESULT_TEMPLATE_ID = 'O2eqJQD3pn-vQ6g2z9DWzINVwOmPoz8yW-172J_YcpI'
function getLotteryTemplateId() {
try {
const templates = uni.getStorageSync('subscribe_templates')
if (templates && templates.lottery_result) {
return templates.lottery_result
}
} catch (e) { console.error(e) }
return DEFAULT_LOTTERY_RESULT_TEMPLATE_ID
}
/**
* 请求用户订阅抽奖结果通知
@ -13,15 +23,16 @@ const LOTTERY_RESULT_TEMPLATE_ID = 'O2eqJQD3pn-vQ6g2z9DWzINVwOmPoz8yW-172J_YcpI'
export function requestLotterySubscription() {
return new Promise((resolve) => {
// #ifdef MP-WEIXIN
const tmplId = getLotteryTemplateId()
wx.requestSubscribeMessage({
tmplIds: [LOTTERY_RESULT_TEMPLATE_ID],
tmplIds: [tmplId],
success(res) {
console.log('订阅消息授权结果:', res)
resolve({
success: true,
result: res,
// 检查用户是否接受了订阅
accepted: res[LOTTERY_RESULT_TEMPLATE_ID] === 'accept'
accepted: res[tmplId] === 'accept'
})
},
fail(err) {