f
This commit is contained in:
104
src/App.vue
104
src/App.vue
@@ -9,6 +9,7 @@ import { useAppStore } from "@/stores/appStore";
|
|||||||
import { useWeixinShare } from "@/composables/useWeixinShare";
|
import { useWeixinShare } from "@/composables/useWeixinShare";
|
||||||
import BindPhoneDialog from "@/components/BindPhoneDialog.vue";
|
import BindPhoneDialog from "@/components/BindPhoneDialog.vue";
|
||||||
import BindPhoneOnlyDialog from "@/components/BindPhoneOnlyDialog.vue";
|
import BindPhoneOnlyDialog from "@/components/BindPhoneOnlyDialog.vue";
|
||||||
|
import WechatOverlay from "@/components/WechatOverlay.vue";
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -265,66 +266,67 @@ const refreshTokenIfNeeded = async () => {
|
|||||||
* 这个逻辑已经在路由守卫中实现了
|
* 这个逻辑已经在路由守卫中实现了
|
||||||
* 这里保留这个函数的备份,以防需要其他地方调用
|
* 这里保留这个函数的备份,以防需要其他地方调用
|
||||||
*/
|
*/
|
||||||
const getWeixinAuthUrl = () => {
|
// const getWeixinAuthUrl = () => {
|
||||||
const isAuthenticated = localStorage.getItem("token");
|
// const isAuthenticated = localStorage.getItem("token");
|
||||||
|
|
||||||
// 检查 token 是否过期
|
// // 检查 token 是否过期
|
||||||
const accessExpire = localStorage.getItem("accessExpire");
|
// const accessExpire = localStorage.getItem("accessExpire");
|
||||||
const now = Date.now();
|
// const now = Date.now();
|
||||||
let isTokenExpired = false;
|
// let isTokenExpired = false;
|
||||||
if (accessExpire) {
|
// if (accessExpire) {
|
||||||
isTokenExpired = now > parseInt(accessExpire) * 1000;
|
// isTokenExpired = now > parseInt(accessExpire) * 1000;
|
||||||
}
|
// }
|
||||||
console.log("WeChat auth check:", {
|
// console.log("WeChat auth check:", {
|
||||||
isWeChat: isWeChat.value,
|
// isWeChat: isWeChat.value,
|
||||||
isAuthenticated,
|
// isAuthenticated,
|
||||||
isTokenExpired
|
// isTokenExpired
|
||||||
});
|
// });
|
||||||
if (isWeChat.value && !isAuthenticated && !isTokenExpired) {
|
// if (isWeChat.value && !isAuthenticated && !isTokenExpired) {
|
||||||
console.log("🔄 Initiating WeChat auth flow");
|
// console.log("🔄 Initiating WeChat auth flow");
|
||||||
// 如果正在授权中或已完成授权,则阻止重复授权
|
// // 如果正在授权中或已完成授权,则阻止重复授权
|
||||||
console.log("Auth store state:", {
|
// console.log("Auth store state:", {
|
||||||
isWeixinAuthing: authStore.isWeixinAuthing,
|
// isWeixinAuthing: authStore.isWeixinAuthing,
|
||||||
weixinAuthComplete: authStore.weixinAuthComplete
|
// weixinAuthComplete: authStore.weixinAuthComplete
|
||||||
});
|
// });
|
||||||
if (authStore.isWeixinAuthing || authStore.weixinAuthComplete) {
|
// if (authStore.isWeixinAuthing || authStore.weixinAuthComplete) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
// 保存目标路由
|
// // 保存目标路由
|
||||||
authStore.startWeixinAuth(route);
|
// authStore.startWeixinAuth(route);
|
||||||
console.log("🔖 Saved pendingRoute for WeChat auth:", route.fullPath);
|
// console.log("🔖 Saved pendingRoute for WeChat auth:", route.fullPath);
|
||||||
const appId = import.meta.env.VITE_WECHAT_APP_ID;
|
// const appId = import.meta.env.VITE_WECHAT_APP_ID;
|
||||||
const url = new URL(window.location.href);
|
// const url = new URL(window.location.href);
|
||||||
const params = new URLSearchParams(url.search);
|
// const params = new URLSearchParams(url.search);
|
||||||
params.delete("code");
|
// params.delete("code");
|
||||||
params.delete("state");
|
// params.delete("state");
|
||||||
|
|
||||||
// 使用配置的固定域名,如果没有配置则使用当前域名
|
// // 使用配置的固定域名,如果没有配置则使用当前域名
|
||||||
const redirectDomain = import.meta.env.VITE_WECHAT_REDIRECT_DOMAIN || url.origin;
|
// const redirectDomain = import.meta.env.VITE_WECHAT_REDIRECT_DOMAIN || url.origin;
|
||||||
const cleanUrl = `${redirectDomain}${url.pathname}${params.toString() ? "?" + params.toString() : ""
|
// const cleanUrl = `${redirectDomain}${url.pathname}${params.toString() ? "?" + params.toString() : ""
|
||||||
}`;
|
// }`;
|
||||||
const redirectUri = encodeURIComponent(cleanUrl);
|
// const redirectUri = encodeURIComponent(cleanUrl);
|
||||||
|
|
||||||
console.log("🔗 WeChat redirectUri config:", {
|
// console.log("🔗 WeChat redirectUri config:", {
|
||||||
configuredDomain: import.meta.env.VITE_WECHAT_REDIRECT_DOMAIN || "未配置(使用当前域名)",
|
// configuredDomain: import.meta.env.VITE_WECHAT_REDIRECT_DOMAIN || "未配置(使用当前域名)",
|
||||||
currentOrigin: url.origin,
|
// currentOrigin: url.origin,
|
||||||
finalRedirectDomain: redirectDomain,
|
// finalRedirectDomain: redirectDomain,
|
||||||
redirectUri: cleanUrl
|
// redirectUri: cleanUrl
|
||||||
});
|
// });
|
||||||
const weixinAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=snsapi_base#wechat_redirect`;
|
// const weixinAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_base&state=snsapi_base#wechat_redirect`;
|
||||||
|
|
||||||
console.log(
|
// console.log(
|
||||||
"🔄 Triggering WeChat auth from route guard, pendingRoute:",
|
// "🔄 Triggering WeChat auth from route guard, pendingRoute:",
|
||||||
route.fullPath
|
// route.fullPath
|
||||||
);
|
// );
|
||||||
window.location.href = weixinAuthUrl;
|
// window.location.href = weixinAuthUrl;
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
<BindPhoneDialog />
|
<BindPhoneDialog />
|
||||||
|
<WechatOverlay />
|
||||||
<BindPhoneOnlyDialog />
|
<BindPhoneOnlyDialog />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ const isIdCardValid = computed(() => /^\d{17}[\dX]$/i.test(formData.idCard));
|
|||||||
const isLoggedIn = computed(() => userStore.isLoggedIn);
|
const isLoggedIn = computed(() => userStore.isLoggedIn);
|
||||||
|
|
||||||
const buttonText = computed(() => {
|
const buttonText = computed(() => {
|
||||||
return isLoggedIn.value ? '立即查询' : '前往登录';
|
return '立即查询'; // 不需要登录,始终显示"立即查询"
|
||||||
});
|
});
|
||||||
|
|
||||||
// 获取产品背景图片
|
// 获取产品背景图片
|
||||||
@@ -322,33 +322,14 @@ function handleBindSuccess() {
|
|||||||
|
|
||||||
// 处理输入框点击事件
|
// 处理输入框点击事件
|
||||||
const handleInputClick = async () => {
|
const handleInputClick = async () => {
|
||||||
if (!isLoggedIn.value) {
|
// 不需要登录检查,允许未登录用户使用
|
||||||
if (!isWeChat.value && props.type !== 'promotion') {
|
// 如果已登录且在微信环境且未绑定手机号,提示绑定
|
||||||
try {
|
if (isLoggedIn.value && isWeChat.value && !userStore.mobile && props.type !== 'promotion') {
|
||||||
await showConfirmDialog({
|
dialogStore.openBindPhone();
|
||||||
title: '提示',
|
|
||||||
message: '您需要登录后才能进行查询,是否前往登录?',
|
|
||||||
confirmButtonText: '前往登录',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
});
|
|
||||||
router.push('/login');
|
|
||||||
} catch {
|
|
||||||
// 用户点击取消,什么都不做
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (isWeChat.value && !userStore.mobile && props.type !== 'promotion') {
|
|
||||||
dialogStore.openBindPhone();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
if (!isWeChat.value && !isLoggedIn.value && props.type !== 'promotion') {
|
|
||||||
router.push('/login');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 基本协议验证
|
// 基本协议验证
|
||||||
if (!formData.agreeToTerms) {
|
if (!formData.agreeToTerms) {
|
||||||
showToast({ message: `请阅读并同意用户协议和隐私政策` });
|
showToast({ message: `请阅读并同意用户协议和隐私政策` });
|
||||||
@@ -379,8 +360,9 @@ function handleSubmit() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否需要绑定手机号
|
// 不需要登录也能查询,直接提交请求
|
||||||
if (!userStore.mobile && props.type !== 'promotion') {
|
// 如果是已登录用户在微信环境且未绑定手机号,提示绑定(但不强制)
|
||||||
|
if (isLoggedIn.value && !userStore.mobile && props.type !== 'promotion' && isWeChat.value) {
|
||||||
pendingPayment.value = true;
|
pendingPayment.value = true;
|
||||||
dialogStore.openBindPhone();
|
dialogStore.openBindPhone();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
<van-radio v-model="selectedPaymentMethod" name="test" />
|
<van-radio v-model="selectedPaymentMethod" name="test" />
|
||||||
</template>
|
</template>
|
||||||
</van-cell>
|
</van-cell>
|
||||||
|
|
||||||
|
|
||||||
<van-cell v-if="isWeChat" title="微信支付" clickable @click="selectedPaymentMethod = 'wechat'">
|
<van-cell v-if="isWeChat" title="微信支付" clickable @click="selectedPaymentMethod = 'wechat'">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
|
|||||||
@@ -18,42 +18,28 @@ const feature = ref(route.params.feature);
|
|||||||
// 获取产品信息
|
// 获取产品信息
|
||||||
const featureData = ref({});
|
const featureData = ref({});
|
||||||
|
|
||||||
// 检查是否可以查询:已登录且已绑定手机号
|
// 检查是否可以查询:不需要登录,直接允许查询
|
||||||
const canQuery = computed(() => {
|
const canQuery = computed(() => {
|
||||||
return isLoggedIn.value && mobile.value && mobile.value.trim() !== '';
|
return true; // 允许未登录用户查询
|
||||||
});
|
});
|
||||||
|
|
||||||
// 检查登录状态和手机号绑定
|
// 初始化:检查支付回调并加载产品信息
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
// 检查支付回调
|
// 检查支付回调
|
||||||
isFinishPayment();
|
isFinishPayment();
|
||||||
|
|
||||||
// 检查是否已登录
|
// 如果有 token,尝试加载用户信息(但不强制)
|
||||||
const token = localStorage.getItem("token");
|
const token = localStorage.getItem("token");
|
||||||
if (!token) {
|
if (token) {
|
||||||
showToast({ message: "请先登录才能使用查询功能" });
|
try {
|
||||||
router.replace("/login");
|
await userStore.fetchUserInfo();
|
||||||
return;
|
} catch (error) {
|
||||||
|
console.warn("获取用户信息失败(可选):", error);
|
||||||
|
// 不影响查询功能,继续执行
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取用户信息(包括手机号)
|
// 直接加载产品信息,不需要登录
|
||||||
try {
|
|
||||||
await userStore.fetchUserInfo();
|
|
||||||
} catch (error) {
|
|
||||||
console.error("获取用户信息失败:", error);
|
|
||||||
showToast({ message: "获取用户信息失败,请重新登录" });
|
|
||||||
router.replace("/login");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否已绑定手机号
|
|
||||||
if (!mobile.value || mobile.value.trim() === '') {
|
|
||||||
showToast({ message: "请先绑定手机号才能使用查询功能" });
|
|
||||||
router.replace("/me");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 已登录且已绑定手机号,可以查询
|
|
||||||
await getProduct();
|
await getProduct();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -88,20 +74,6 @@ async function getProduct() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<!-- 未登录或未绑定手机号,提示 -->
|
<!-- 直接显示查询表单,不需要登录 -->
|
||||||
<div v-if="!canQuery" class="min-h-screen flex items-center justify-center p-6">
|
<InquireForm :type="'normal'" :feature="feature" :feature-data="featureData" />
|
||||||
<div class="text-center">
|
|
||||||
<div class="text-lg font-bold mb-4">无法使用查询功能</div>
|
|
||||||
<div class="text-gray-600 mb-6">
|
|
||||||
<span v-if="!isLoggedIn">请先登录</span>
|
|
||||||
<span v-else>请先绑定手机号</span>
|
|
||||||
</div>
|
|
||||||
<button @click="router.push(isLoggedIn ? '/me' : '/login')"
|
|
||||||
class="px-6 py-3 bg-primary text-white rounded-lg">
|
|
||||||
{{ isLoggedIn ? '去绑定手机号' : '去登录' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<!-- 已登录且已绑定手机号,可以使用查询功能 -->
|
|
||||||
<InquireForm v-else :type="'normal'" :feature="feature" :feature-data="featureData" />
|
|
||||||
</template>
|
</template>
|
||||||
Reference in New Issue
Block a user