mi-assessment/uniapp/App.vue
zpc 4bf412af51 feat(invite): 邀请二维码改为COS存储,优化内存占用
- users表新增InviteQrcodeUrl字段,永久保存二维码URL
- InviteService改为:查用户字段→调微信接口→上传COS→存库
- 去掉Redis缓存base64图片数据的逻辑
- IUploadConfigService新增UploadFileAsync后端直传方法
- 前端进入邀请页自动预加载二维码URL
- 包含之前的小程序名称配置、二维码生成、邀请人绑定等功能
2026-03-25 01:34:06 +08:00

72 lines
1.8 KiB
Vue
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.

<script>
import { useUserStore } from './store/user.js'
import { useAppStore } from './store/app.js'
import { setupRouteGuard } from './utils/routeGuard.js'
export default {
onLaunch: function(options) {
console.log('App Launch', options)
// 初始化路由守卫(未登录跳转登录页)
setupRouteGuard()
// 初始化系统信息
const appStore = useAppStore()
appStore.initSystemInfo()
// 恢复用户状态
const userStore = useUserStore()
userStore.restoreFromStorage()
// 解析邀请人参数(二维码扫码 scene 或分享链接 query
this.parseInviterFromLaunch(options)
// 已登录时从服务器刷新用户信息
if (userStore.isLoggedIn) {
userStore.fetchUserInfo()
}
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
methods: {
/**
* 解析邀请人参数
* 来源1: 扫描小程序码 scene 参数,格式 inviter={userId}
* 来源2: 分享链接 query 参数 inviteUid={uid}
*/
parseInviterFromLaunch(options) {
if (!options) return
let inviterId = null
// 1. 扫码进入:解析 scene 参数inviter={userId}
if (options.scene) {
const scene = decodeURIComponent(options.scene)
console.log('扫码 scene:', scene)
const match = scene.match(/inviter=(\d+)/)
if (match) {
inviterId = match[1]
}
}
// 2. 分享链接进入:解析 inviterId 参数
if (!inviterId && options.inviterId) {
inviterId = options.inviterId
}
// 存储邀请人ID仅未登录用户需要绑定
if (inviterId) {
console.log('检测到邀请人ID:', inviterId)
uni.setStorageSync('inviterId', inviterId)
}
}
}
</script>
<style>
/*每个页面公共css */
</style>