Files
MBTI_wang/miniprogram/pages/index/index.js
Ghost d07235b64c feat: 小程序 AI 底栏与聊天页、出站推送调试与 tabbar 迁移
- 自定义 tabBar:AI 入口图标与样式,相关页面与审核门控调整

- API:MpTabbar、出站推送 Hook、后台设置与迁移 SQL(含 FAB 居中排序)

- 管理端:推送 Hook 面板、出站推送调试工具与生产环境注释说明

Made-with: Cursor
2026-04-20 15:29:10 +08:00

221 lines
8.9 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.

// pages/index/index.js
const app = getApp()
const { request } = require('../../utils/request.js')
Page({
data: {
statusBarHeight: 0,
navbarHeight: 88,
showEnterpriseEntry: false,
siteTitle: '神仙团队性格测试',
startButtonText: '30秒测出你的性格',
aiAnalysisText: '分析',
reviewMode: true,
permFace: true
},
onLoad(options) {
// 获取状态栏高度和屏幕信息
const systemInfo = wx.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight || 0
const screenWidth = systemInfo.screenWidth || 375
// 将状态栏高度从px转换为rpx
const statusBarHeightRpx = (statusBarHeight * 750) / screenWidth
const navbarHeightRpx = statusBarHeightRpx + 88// 状态栏 + 导航栏内容
const userInfo = getApp().globalData.userInfo || wx.getStorageSync('userInfo') || {}
const gd = getApp().globalData
const rm0 = !!(gd.reviewMode || gd.maintenanceMode)
const ep = gd.enterprisePermissions
const pf = !ep || ep.face !== false
this.setData({
statusBarHeight: statusBarHeightRpx,
navbarHeight: navbarHeightRpx,
showEnterpriseEntry: userInfo.hasEnterprise === true,
siteTitle: rm0 ? (gd.siteTitle || '神仙团队性格测试').replace(/AI/gi, '') : (gd.siteTitle || '神仙团队性格测试'),
startButtonText: rm0 ? '开始性格测试' : ((gd.textConfig && gd.textConfig.startButtonText) || '30秒测出你的性格'),
aiAnalysisText: rm0 ? '分析' : ((gd.textConfig && gd.textConfig.aiAnalysisText) || '分析'),
reviewMode: rm0,
permFace: pf
})
// 预加载站点名称与文案配置
app.getRuntimeConfig().then((cfg) => {
if (cfg) {
const rm = !!(cfg.reviewMode || cfg.maintenanceMode)
getApp().globalData.reviewMode = rm
if (cfg.maintenanceMode !== undefined) {
getApp().globalData.maintenanceMode = !!cfg.maintenanceMode
}
try {
require('../../utils/miniprogramAuditGate.js').applyAuditUiOverride(getApp())
} catch (e) {}
const rmEff = !!(getApp().globalData.reviewMode || getApp().globalData.maintenanceMode)
if (cfg.siteTitle) {
getApp().globalData.siteTitle = cfg.siteTitle
this.setData({ siteTitle: rmEff ? cfg.siteTitle.replace(/AI/gi, '') : cfg.siteTitle })
}
if (cfg.textConfig) {
getApp().globalData.textConfig = cfg.textConfig
this.setData({
startButtonText: rmEff ? '开始性格测试' : (cfg.textConfig.startButtonText || '30秒测出你的性格'),
aiAnalysisText: rmEff ? '分析' : (cfg.textConfig.aiAnalysisText || '分析')
})
}
const ep2 = getApp().globalData.enterprisePermissions
this.setData({ reviewMode: rmEff, permFace: !ep2 || ep2.face !== false })
try {
const tb = typeof this.getTabBar === 'function' ? this.getTabBar() : null
if (tb && typeof tb.updateSelected === 'function') tb.updateSelected()
} catch (e) {}
}
}).catch(() => {})
// ── 解析入参(兼容扫码 scene / 分享链接 options──
const rawScene = (options && options.scene) ? decodeURIComponent(options.scene) : ''
const sceneParams = {}
if (rawScene) {
rawScene.split('&').forEach(pair => {
const [k, v] = pair.split('=')
if (k) sceneParams[k] = v || ''
})
}
try {
require('../../utils/thirdPartyContext.js').ingestThirdPartyOnPageLoad(options || {}, app)
} catch (e) {}
const uid = parseInt(sceneParams.uid || (options && options.uid) || 0, 10)
const eid = parseInt(sceneParams.eid || (options && options.eid) || 0, 10)
console.log('[index/onLoad] 解码参数 =>', {
rawScene,
sceneParams,
options,
uid,
eid
})
// 携带 eid跳转企业版首页
if (eid > 0) {
getApp().globalData.enterpriseIdFromScene = eid
wx.navigateTo({ url: '/pages/enterprise/index?uid=' + uid + '&eid=' + eid })
return
}
// 个人版分销绑定
if (uid > 0) {
app.globalData._pendingInviterId = uid
app.globalData._pendingInviterScope = 'personal'
}
},
onShow() {
const gd0 = getApp().globalData || {}
if (typeof this.getTabBar === 'function' && this.getTabBar()) {
const tb = this.getTabBar()
if (typeof tb.updateSelected === 'function') tb.updateSelected()
}
// 个人版首页:固定 scope=personal并清除企业来源上下文
try {
getApp().globalData.appScope = 'personal'
getApp().globalData.enterpriseIdFromScene = null
} catch (e) {}
const g = getApp().globalData
const rm = !!(g.reviewMode || g.maintenanceMode)
const ep3 = g.enterprisePermissions
this.setData({
siteTitle: rm ? (g.siteTitle || '神仙团队性格测试').replace(/AI/gi, '') : (g.siteTitle || '神仙团队性格测试'),
startButtonText: (rm || (ep3 && ep3.face === false)) ? '开始性格测试' : ((g.textConfig && g.textConfig.startButtonText) || '30秒测出你的性格'),
aiAnalysisText: rm ? '分析' : ((g.textConfig && g.textConfig.aiAnalysisText) || '分析'),
reviewMode: rm,
permFace: !ep3 || ep3.face !== false
})
const userInfo = getApp().globalData.userInfo || wx.getStorageSync('userInfo') || {}
this.setData({ showEnterpriseEntry: userInfo.hasEnterprise === true })
// 有 token 时拉取最新用户信息(含 hasEnterprise绑定企业后无需重新登录即可展示企业版入口
const token = getApp().globalData.token || wx.getStorageSync('token')
if (token) {
request({
url: '/api/auth/me',
method: 'GET',
success: (res) => {
if (res.statusCode === 200 && res.data && res.data.code === 200 && res.data.data) {
const user = res.data.data
getApp().globalData.userInfo = user
wx.setStorageSync('userInfo', user)
this.setData({ showEnterpriseEntry: user.hasEnterprise === true })
}
}
})
}
},
// 主按钮:面相/拍摄链路直进「拍摄」Tab与底栏拍摄一致审核模式或企业关闭面相时进测试列表
startCamera() {
try { getApp().globalData.appScope = 'personal' } catch (e) {}
const g = getApp().globalData
const rm = !!(g.reviewMode || g.maintenanceMode)
const ep = g.enterprisePermissions
const faceOff = ep && ep.face === false
if (rm || faceOff) {
try { require('../../utils/analytics').track('tap_home_test_select', {}) } catch (e) {}
wx.navigateTo({ url: '/pages/test-select/index' })
return
}
try { require('../../utils/analytics').track('tap_home_camera_tab', {}) } catch (e) {}
wx.switchTab({ url: '/pages/index/camera' })
},
// 上传照片(个人版入口:强制本次链路为个人定价)
uploadPhoto() {
try { getApp().globalData.appScope = 'personal' } catch (e) {}
try { require('../../utils/analytics').track('tap_upload_photo_home', {}) } catch (e) {}
wx.navigateTo({
url: '/pages/index/upload'
})
},
// 切换到企业版(仅已绑定企业的用户可进入,优先用登录返回的 hasEnterprise避免多请求
switchToEnterprise() {
try { require('../../utils/analytics').track('tap_enterprise_entry', {}) } catch (e) {}
const app = getApp()
const userInfo = app.globalData.userInfo || wx.getStorageSync('userInfo') || {}
if (userInfo.hasEnterprise === true) {
wx.navigateTo({ url: '/pages/enterprise/index' })
return
}
if (userInfo.hasEnterprise === false) {
wx.showToast({ title: '您尚未绑定任何企业,无法使用企业版', icon: 'none', duration: 2500 })
return
}
// 缓存里没有 hasEnterprise 时:临时用 enterprise scope 获取配置判定
try { app.globalData.appScope = 'enterprise' } catch (e) {}
app.ensureLogin().then(() => app.getRuntimeConfig()).then((cfg) => {
if ((cfg && cfg.pricingType) === 'enterprise') {
wx.navigateTo({ url: '/pages/enterprise/index' })
} else {
wx.showToast({ title: '您尚未绑定任何企业,无法使用企业版', icon: 'none', duration: 2500 })
}
}).catch(() => {
wx.showToast({ title: '无法获取配置,请稍后重试', icon: 'none' })
})
},
onShareAppMessage() {
const { getSharePathByScope } = require('../../utils/share')
const rm = this.data.reviewMode
return {
title: rm ? '性格测试 - 快来测测你的MBTI性格类型' : '性格测试 - 看看你的面相透露了什么性格密码',
path: getSharePathByScope('/pages/index/index')
}
},
onShareTimeline() {
const { buildShareQuery } = require('../../utils/share')
const rm = this.data.reviewMode
return {
title: rm ? '性格测试 - 快来测测你的MBTI性格类型' : '性格测试 - 看看你的面相透露了什么性格密码',
query: buildShareQuery()
}
}
})