优化登录逻辑

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

@ -5,16 +5,12 @@ import DraggableButton from "@/pages/components/goHome.vue";
* 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 // 1. props Vue
} from '@/api' const props = defineProps({
import {
onShow
} from '@dcloudio/uni-app'
const $props = defineProps({
openid: { openid: {
type: String, type: String,
default: '' default: ''
@ -28,55 +24,56 @@ import DraggableButton from "@/pages/components/goHome.vue";
default: '' default: ''
} }
}); });
const tip_str = ref('授权登录中,请稍候...') 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('#'); // 2. #
if (index !== -1) { const getPureValue = (value) => {
path= path.substring(0, index); // # # if (!value) return '';
} const decodedValue = decodeURIComponent(value);
const hashIndex = decodedValue.indexOf('#');
return hashIndex !== -1 ? decodedValue.substring(0, hashIndex) : decodedValue;
};
param=param+"?path="+path const checkOpenid = () => {
} // 3. 使 #
if (!!$props.orderid) { const openid = getPureValue(props.openid);
path = decodeURIComponent($props.orderid) const path = getPureValue(props.path);
const index = path.indexOf('#'); const orderid = getPureValue(props.orderid);
if (index !== -1) {
path= path.substring(0, index); // # # // 4. undefined
} let redirectParams = '';
param=param+"&orderid="+path // path
if (path) {
redirectParams += `?path=${path}`;
} }
if (!!openid) { // orderid path
const index = openid.indexOf('#'); if (orderid) {
if (index !== -1) { redirectParams += `${redirectParams ? '&' : '?'}orderid=${orderid}`;
openid= openid.substring(0, index); // # #
} }
uni.setStorageSync('OPENID', openid)
if (openid) {
uni.setStorageSync('OPENID', openid);
//
uni.redirectTo({ uni.redirectTo({
url: "/pages/main/index/index"+param url: `/pages/main/index/index${redirectParams}`
}) });
} else { } else {
tip_str.value = '未获取到授权信息,请从小程序进入' tip_str.value = '未获取到授权信息,请从小程序进入';
}
} }
};
onShow(() => { onShow(() => {
checkOpenid() 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;

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

Loading…
Cancel
Save