Files
template-10579/src/app.ts
赵忠林 eee4644d06 ```
feat(registration): 优化经销商注册流程并增加地址定位功能

- 修改导航栏标题从“邀请注册”为“注册成为会员”
- 修复重复提交问题并移除不必要的submitting状态
- 增加昵称和头像的必填验证提示
- 添加用户角色缺失时的默认角色写入机制
- 集成地图选点功能,支持经纬度获取和地址解析
- 实现微信地址导入功能,自动填充基本信息
- 增加定位权限检查和错误处理机制
- 添加.gitignore规则忽略备份文件夹src__bak
- 移除已废弃的银行卡和客户管理页面代码
- 优化表单验证规则和错误提示信息
- 实现经销商注册成功后自动跳转到“我的”页面
- 添加用户信息缓存刷新机制确保角色信息同步
```
2026-03-01 12:35:41 +08:00

102 lines
2.9 KiB
TypeScript
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.

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 { useConfig } from "@/hooks/useConfig"; // 引入新的自定义Hook
function App(props: { children: any; }) {
const { refetch: handleTheme } = useConfig(); // 使用新的Hook
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(() => {
// 设置主题 (现在由useConfig Hook处理)
handleTheme()
// Taro.getSetting获取用户的当前设置。返回值中只会出现小程序已经向用户请求过的权限。
Taro.getSetting({
success: (res) => {
if (res.authSetting['scope.userInfo']) {
reload();
}
}
});
}, []);
// 对应 onShow
useDidShow(() => {
// 处理小程序启动参数中的邀请信息
const options = Taro.getLaunchOptionsSync()
handleLaunchOptions(options)
})
// 处理启动参数
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(() => {
console.log(`检测到邀请信息 ID:${inviteParams.inviter}`)
}, 1000)
} else {
console.log('❌ 未检测到邀请参数')
}
console.log('=== 小程序启动参数处理结束 ===')
} catch (error) {
console.error('处理启动参数失败:', error)
}
}
// 对应 onHide
useDidHide(() => {
})
return props.children
}
export default App