- 移除邀请人ID表单项并注释相关代码 - 注释掉邀请信息检测成功提示弹窗功能 - 在开发、生产、测试环境中添加本地API调试配置选项 - 添加分销商角色权限检查,非分销商无法查看客户列表 - 使用useRef避免重复显示无权限提示 - 在客户列表页面添加权限验证和加载状态处理 - 移除用户卡片中的余额、积分、优惠券、礼品卡等显示组件 - 简化用户角色名称获取逻辑,优先使用用户角色数组第一个角色名称 - 优化用户信息加载和权限验证流程
116 lines
3.3 KiB
TypeScript
116 lines
3.3 KiB
TypeScript
import {useEffect} from 'react'
|
||
import Taro, {useDidShow, useDidHide} from '@tarojs/taro'
|
||
|
||
// 全局样式
|
||
import './app.scss'
|
||
import {loginByOpenId} from "@/api/layout";
|
||
import {TenantId} from "@/config/app";
|
||
import {saveStorageByLoginUser} from "@/utils/server";
|
||
import {parseInviteParams, saveInviteParams, trackInviteSource, handleInviteRelation} from "@/utils/invite";
|
||
import {configWebsiteField} from "@/api/cms/cmsWebsiteField";
|
||
|
||
function App(props: { children: any; }) {
|
||
const reload = () => {
|
||
Taro.login({
|
||
success: (res) => {
|
||
loginByOpenId({
|
||
code: res.code,
|
||
tenantId: TenantId
|
||
}).then(async data => {
|
||
if (data) {
|
||
saveStorageByLoginUser(data.access_token, data.user)
|
||
|
||
// 处理邀请关系
|
||
if (data.user?.userId) {
|
||
try {
|
||
const inviteSuccess = await handleInviteRelation(data.user.userId)
|
||
if (inviteSuccess) {
|
||
console.log('自动登录时邀请关系建立成功')
|
||
}
|
||
} catch (error) {
|
||
console.error('自动登录时处理邀请关系失败:', error)
|
||
}
|
||
}
|
||
}
|
||
})
|
||
}
|
||
})
|
||
};
|
||
// 可以使用所有的 React Hooks
|
||
useEffect(() => {
|
||
// Taro.getSetting:获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
|
||
Taro.getSetting({
|
||
success: (res) => {
|
||
if (res.authSetting['scope.userInfo']) {
|
||
reload();
|
||
}
|
||
}
|
||
});
|
||
}, []);
|
||
|
||
// 对应 onShow
|
||
useDidShow(() => {
|
||
// 处理小程序启动参数中的邀请信息
|
||
const options = Taro.getLaunchOptionsSync()
|
||
handleLaunchOptions(options)
|
||
handleTheme()
|
||
})
|
||
|
||
// 处理启动参数
|
||
const handleLaunchOptions = (options: any) => {
|
||
try {
|
||
console.log('=== 小程序启动参数处理开始 ===')
|
||
console.log('完整启动参数:', JSON.stringify(options, null, 2))
|
||
|
||
// 解析邀请参数
|
||
const inviteParams = parseInviteParams(options)
|
||
if (inviteParams) {
|
||
console.log('✅ 成功检测到邀请参数:', inviteParams)
|
||
|
||
// 保存邀请参数到本地存储
|
||
saveInviteParams(inviteParams)
|
||
|
||
// 统计邀请来源
|
||
trackInviteSource(inviteParams.source || 'unknown', parseInt(inviteParams.inviter || '0'))
|
||
|
||
// 显示邀请提示
|
||
// setTimeout(() => {
|
||
// Taro.showToast({
|
||
// title: `检测到邀请信息 ID:${inviteParams.inviter}`,
|
||
// icon: 'success',
|
||
// duration: 3000
|
||
// })
|
||
// }, 1000)
|
||
|
||
} else {
|
||
console.log('❌ 未检测到邀请参数')
|
||
}
|
||
|
||
console.log('=== 小程序启动参数处理结束 ===')
|
||
} catch (error) {
|
||
console.error('处理启动参数失败:', error)
|
||
}
|
||
}
|
||
|
||
const handleTheme = () => {
|
||
configWebsiteField().then(data => {
|
||
// 设置主题
|
||
if(data.theme && !Taro.getStorageSync('user_theme')){
|
||
Taro.setStorageSync('user_theme', data.theme)
|
||
}
|
||
// 自定义接口
|
||
if(data.apiUrl && process.env.NODE_ENV !== 'development'){
|
||
Taro.setStorageSync('ApiUrl', data.apiUrl)
|
||
}
|
||
})
|
||
}
|
||
|
||
// 对应 onHide
|
||
useDidHide(() => {
|
||
})
|
||
|
||
return props.children
|
||
}
|
||
|
||
export default App
|