You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.2 KiB
Vue

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<script setup>
import DraggableButton from "@/pages/components/goHome.vue";
/**
* name
* usersa0ChunLuyu
* date2024年8月12日 19:47:35
*/
import { ref } from 'vue'
import { $response } from '@/api'
import { onShow } from '@dcloudio/uni-app'
// 1. 解构 props命名更清晰符合 Vue 最佳实践
const props = defineProps({
openid: {
type: String,
default: ''
},
path: {
type: String,
default: ''
},
orderid: {
type: String,
default: ''
},
status: {
type: String,
default: ''
}
});
const tip_str = ref('授权登录中,请稍候...')
// 2. 封装通用函数:截取 # 之前的字符串,避免重复代码
const getPureValue = (value) => {
if (!value) return '';
const decodedValue = decodeURIComponent(value);
const hashIndex = decodedValue.indexOf('#');
return hashIndex !== -1 ? decodedValue.substring(0, hashIndex) : decodedValue;
};
const checkOpenid = () => {
// 3. 处理各参数,使用通用函数统一处理 # 截取
const openid = getPureValue(props.openid);
const path = getPureValue(props.path);
const orderid = getPureValue(props.orderid);
const status = getPureValue(props.status);
// 4. 初始化参数拼接字符串,避免 undefined 开头
let redirectParams = '';
// 拼接 path 参数
if (path) {
redirectParams += `?path=${path}`;
}
// 拼接 orderid 参数(修复:不再覆盖 path 变量)
if (orderid) {
redirectParams += `${redirectParams ? '&' : '?'}orderid=${orderid}`;
}
if (status) {
redirectParams += `${redirectParams ? '&' : '?'}status=${encodeURIComponent(status)}`;
}
if (openid) {
uni.setStorageSync('OPENID', openid);
// 跳转页面,拼接参数
uni.redirectTo({
url: `/pages/main/index/index${redirectParams}`
});
} else {
tip_str.value = '未获取到授权信息,请从小程序进入';
}
};
onShow(() => {
checkOpenid();
});
</script>
<template>
<view class="tip_wrapper">
{{ tip_str }}
</view>
</template>
<style scoped>
.tip_wrapper {
height: 100vh;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
</style>