优化登录逻辑

main
岩仔88 4 weeks ago
parent 058a8ac04b
commit 5fef307e88

@ -1,88 +1,85 @@
<script setup> <script setup>
import DraggableButton from "@/pages/components/goHome.vue"; import DraggableButton from "@/pages/components/goHome.vue";
/** /**
* name * name
* usersa0ChunLuyu * usersa0ChunLuyu
* date2024年8月12日 19:47:35 * date2024年8月12日 19:47:35
*/ */
import { import { ref } from 'vue'
ref import { $response } from '@/api'
} from 'vue' import { onShow } from '@dcloudio/uni-app'
import {
$response
} from '@/api'
import {
onShow
} from '@dcloudio/uni-app'
const $props = defineProps({
openid: {
type: String,
default: ''
},
path:{
type:String,
default:''
},
orderid:{
type:String,
default:''
}
});
const tip_str = ref('授权登录中,请稍候...')
const checkOpenid = () => {
let openid = ''
let path=''
let param=''
if (!!$props.openid) {
openid = decodeURIComponent($props.openid)
}
if (!!$props.path) {
path = decodeURIComponent($props.path)
const index = path.indexOf('#'); // 1. props Vue
if (index !== -1) { const props = defineProps({
path= path.substring(0, index); // # # openid: {
} type: String,
default: ''
},
path: {
type: String,
default: ''
},
orderid: {
type: String,
default: ''
}
});
param=param+"?path="+path const tip_str = ref('授权登录中,请稍候...')
}
if (!!$props.orderid) {
path = decodeURIComponent($props.orderid)
const index = path.indexOf('#');
if (index !== -1) {
path= path.substring(0, index); // # #
}
param=param+"&orderid="+path
}
if (!!openid) {
const index = openid.indexOf('#');
if (index !== -1) {
openid= openid.substring(0, index); // # #
}
uni.setStorageSync('OPENID', openid)
uni.redirectTo({
url: "/pages/main/index/index"+param
})
} else {
tip_str.value = '未获取到授权信息,请从小程序进入'
}
}
onShow(() => { // 2. #
checkOpenid() 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);
// 4. undefined
let redirectParams = '';
// path
if (path) {
redirectParams += `?path=${path}`;
}
// orderid path
if (orderid) {
redirectParams += `${redirectParams ? '&' : '?'}orderid=${orderid}`;
}
if (openid) {
uni.setStorageSync('OPENID', openid);
//
uni.redirectTo({
url: `/pages/main/index/index${redirectParams}`
});
} else {
tip_str.value = '未获取到授权信息,请从小程序进入';
}
};
onShow(() => {
checkOpenid();
});
</script> </script>
<template> <template>
<view class="tip_wrapper"> <view class="tip_wrapper">
{{ tip_str }} {{ tip_str }}
</view> </view>
</template> </template>
<style scoped> <style scoped>
.tip_wrapper { .tip_wrapper {
height: 100vh; height: 100vh;
width: 100%; width: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
</style> </style>

@ -404,7 +404,6 @@
} }
onMounted(() => { onMounted(() => {
deepInfo(); deepInfo();
}); });
</script> </script>

Loading…
Cancel
Save