fix(mp): handle mini-program launch params and pre-create share code for user page

App.vue: add handleLaunchParams() to read token/shareCode from onLaunch/onShow query in MP-WEIXIN context. user.vue: pre-create share record on page load, use dynamic path with shareCode in onShareAppMessage.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
yuzhiran
2026-06-22 14:23:27 +08:00
parent d74fc74f28
commit 1a45822a58
2 changed files with 51 additions and 3 deletions
+23 -2
View File
@@ -1,15 +1,24 @@
<script setup lang="ts">
import { onLaunch } from '@dcloudio/uni-app'
import { onLaunch, onShow } from '@dcloudio/uni-app'
onLaunch(() => {
onLaunch((options) => {
// #ifdef MP-WEIXIN
initPrivacy()
handleLaunchParams(options?.query)
// #endif
// #ifdef H5
handleH5UrlParams()
// #endif
})
// #ifdef MP-WEIXIN
onShow((options) => {
if (options?.query) {
handleLaunchParams(options.query)
}
})
// #endif
// #ifdef H5
function handleH5UrlParams() {
const params = new URLSearchParams(window.location.search)
@@ -28,6 +37,18 @@ function handleH5UrlParams() {
// #endif
// #ifdef MP-WEIXIN
function handleLaunchParams(query?: Record<string, string>) {
if (!query) return
const token = query.token
if (token) {
uni.setStorageSync('token', token)
}
const shareCode = query.share || query.shareCode
if (shareCode) {
uni.setStorageSync('shareCode', shareCode)
}
}
function initPrivacy() {
if (wx.onNeedPrivacyAuthorization) {
wx.onNeedPrivacyAuthorization((resolve) => {