微信支付
This commit is contained in:
@@ -137,7 +137,7 @@ const routes = [
|
|||||||
component: () => import('@/views/Payment.vue'),
|
component: () => import('@/views/Payment.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: '支付激活',
|
title: '支付激活',
|
||||||
requiresAuth: true
|
requiresAuth: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -248,37 +248,37 @@ const routes = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/buydetail',
|
path: '/buydetail',
|
||||||
name: 'BuyDetail',
|
name: 'BuyDetail',
|
||||||
component: () => import('../views/BuyDetails.vue'),
|
component: () => import('../views/BuyDetails.vue'),
|
||||||
meta: { title: '确认订单' }
|
meta: { title: '确认订单' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/pay/:orderId',
|
path: '/pay/:orderId',
|
||||||
name: 'Pay',
|
name: 'Pay',
|
||||||
component: () => import('@/views/Pay.vue'),
|
component: () => import('@/views/Pay.vue'),
|
||||||
meta: { title: '确认支付' },
|
meta: { title: '确认支付' },
|
||||||
props: route => ({ orderId: route.query.orderId })
|
props: route => ({ orderId: route.query.orderId })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/cart',
|
path: '/cart',
|
||||||
name: 'Cart',
|
name: 'Cart',
|
||||||
component: () => import('@/views/Cart.vue'),
|
component: () => import('@/views/Cart.vue'),
|
||||||
meta: { title: '购物车' }
|
meta: { title: '购物车' }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/address',
|
path: '/address',
|
||||||
name: 'Address',
|
name: 'Address',
|
||||||
component: () => import('@/views/Address.vue'),
|
component: () => import('@/views/Address.vue'),
|
||||||
meta: { title: '地址管理', requiresAuth: true }
|
meta: { title: '地址管理', requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/payloading',
|
path: '/payloading',
|
||||||
name: 'PayLoading',
|
name: 'PayLoading',
|
||||||
component: () => import('@/views/PayLoading.vue'),
|
component: () => import('@/views/PayLoading.vue'),
|
||||||
meta: { title: '支付确认' },
|
meta: { title: '支付确认' },
|
||||||
props: route => ({ orderId: route.query.orderId })
|
props: route => ({ orderId: route.query.orderId })
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)*',
|
||||||
name: 'NotFound',
|
name: 'NotFound',
|
||||||
@@ -304,19 +304,19 @@ const router = createRouter({
|
|||||||
// 路由守卫
|
// 路由守卫
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
NProgress.start()
|
NProgress.start()
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
// 设置页面标题
|
// 设置页面标题
|
||||||
if (to.meta.title) {
|
if (to.meta.title) {
|
||||||
document.title = `${to.meta.title} - 炬融圈`
|
document.title = `${to.meta.title} - 炬融圈`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查维护模式
|
// 检查维护模式
|
||||||
try {
|
try {
|
||||||
const {data} = await api.get('/system/maintenance-status', { showLoading: false })
|
const { data } = await api.get('/system/maintenance-status', { showLoading: false })
|
||||||
console.log(data,'data');
|
console.log(data, 'data');
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
if (data.data.maintenance_mode) {
|
if (data.data.maintenance_mode) {
|
||||||
// 维护模式开启,且不在维护页面,跳转到维护页面
|
// 维护模式开启,且不在维护页面,跳转到维护页面
|
||||||
@@ -336,7 +336,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
// 如果检查维护状态失败,继续正常流程
|
// 如果检查维护状态失败,继续正常流程
|
||||||
console.warn('检查维护状态失败:', error)
|
console.warn('检查维护状态失败:', error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查是否需要认证
|
// 检查是否需要认证
|
||||||
if (to.meta.requiresAuth) {
|
if (to.meta.requiresAuth) {
|
||||||
// 检查是否是代理页面
|
// 检查是否是代理页面
|
||||||
@@ -344,10 +344,10 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
// 代理页面认证逻辑
|
// 代理页面认证逻辑
|
||||||
const agentInfo = localStorage.getItem('agentInfo')
|
const agentInfo = localStorage.getItem('agentInfo')
|
||||||
const agentToken = localStorage.getItem('token')
|
const agentToken = localStorage.getItem('token')
|
||||||
|
|
||||||
if (!agentInfo || !agentToken) {
|
if (!agentInfo || !agentToken) {
|
||||||
next({
|
next({
|
||||||
path: '/agent/login',
|
path: '/mylogin',
|
||||||
query: { redirect: to.fullPath }
|
query: { redirect: to.fullPath }
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@@ -357,7 +357,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
if (!userStore.isAuthenticated) {
|
if (!userStore.isAuthenticated) {
|
||||||
// 尝试从本地存储恢复登录状态
|
// 尝试从本地存储恢复登录状态
|
||||||
await userStore.checkAuth()
|
await userStore.checkAuth()
|
||||||
|
|
||||||
if (!userStore.isAuthenticated) {
|
if (!userStore.isAuthenticated) {
|
||||||
next({
|
next({
|
||||||
name: 'MyLogin',
|
name: 'MyLogin',
|
||||||
@@ -366,9 +366,13 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查支付状态(管理员除外)
|
// 检查支付状态(管理员除外)
|
||||||
|
console.log(userStore.user);
|
||||||
|
|
||||||
if (userStore.user && userStore.user.role !== 'admin' && userStore.user.payment_status === 'unpaid') {
|
if (userStore.user && userStore.user.role !== 'admin' && userStore.user.payment_status === 'unpaid') {
|
||||||
|
console.log('进来了');
|
||||||
|
|
||||||
// 如果当前不在支付页面,静默重定向到支付页面(不显示额外通知)
|
// 如果当前不在支付页面,静默重定向到支付页面(不显示额外通知)
|
||||||
if (to.name !== 'Payment') {
|
if (to.name !== 'Payment') {
|
||||||
next({
|
next({
|
||||||
@@ -376,17 +380,19 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
query: { redirect: to.fullPath }
|
query: { redirect: to.fullPath }
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果已登录用户访问登录/注册页面,重定向到转账管理(改成了主页)
|
// 如果已登录用户访问登录/注册页面,重定向到转账管理(改成了主页)
|
||||||
if (to.meta.hideForAuth && userStore.isAuthenticated) {
|
if (to.meta.hideForAuth && userStore.isAuthenticated) {
|
||||||
next({ name: 'MainPage' })
|
next({ name: 'MainPage' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -48,13 +48,24 @@ export const useUserStore = defineStore('user', () => {
|
|||||||
ElMessage.success(response.data.message || '登录成功')
|
ElMessage.success(response.data.message || '登录成功')
|
||||||
return { success: true, data: response.data }
|
return { success: true, data: response.data }
|
||||||
} else if (response.data.needPayment) {
|
} else if (response.data.needPayment) {
|
||||||
|
console.log(response.data.needPayment,'response.data.needPayment');
|
||||||
|
console.log({
|
||||||
|
success: false,
|
||||||
|
needPayment: true,
|
||||||
|
userId: response.data.userId,
|
||||||
|
message: response.data.message
|
||||||
|
});
|
||||||
|
setToken(response.data.token)
|
||||||
|
setUser(response.data.user)
|
||||||
// 用户需要支付激活,不显示错误消息,由前端页面处理
|
// 用户需要支付激活,不显示错误消息,由前端页面处理
|
||||||
return {
|
const returnData = {
|
||||||
success: false,
|
success: false,
|
||||||
needPayment: true,
|
needPayment: true,
|
||||||
userId: response.data.userId,
|
userId: response.data.userId,
|
||||||
message: response.data.message
|
message: response.data.message
|
||||||
}
|
}
|
||||||
|
console.log('即将返回needPayment数据:', returnData);
|
||||||
|
return returnData
|
||||||
} else {
|
} else {
|
||||||
const message = response.data.message || '登录失败'
|
const message = response.data.message || '登录失败'
|
||||||
ElMessage.error(message)
|
ElMessage.error(message)
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ api.interceptors.response.use(
|
|||||||
// 判断当前是否在代理相关页面
|
// 判断当前是否在代理相关页面
|
||||||
const currentPath = router.currentRoute.value.path
|
const currentPath = router.currentRoute.value.path
|
||||||
if (currentPath.startsWith('/agent')) {
|
if (currentPath.startsWith('/agent')) {
|
||||||
router.push('/agent/login')
|
router.push('/agent/mylogin')
|
||||||
ElMessage.error('代理登录已过期,请重新登录')
|
ElMessage.error('代理登录已过期,请重新登录')
|
||||||
} else {
|
} else {
|
||||||
router.push({ name: 'Login' })
|
router.push({ name: 'MyLogin' })
|
||||||
ElMessage.error('登录已过期,请重新登录')
|
ElMessage.error('登录已过期,请重新登录')
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@@ -86,7 +86,7 @@ api.interceptors.response.use(
|
|||||||
// 清除token并跳转到登录页
|
// 清除token并跳转到登录页
|
||||||
localStorage.removeItem('token')
|
localStorage.removeItem('token')
|
||||||
delete api.defaults.headers.common['Authorization']
|
delete api.defaults.headers.common['Authorization']
|
||||||
router.push({ name: 'Login' })
|
router.push({ name: 'MyLogin' })
|
||||||
ElMessage.error(data.message || '账户已被拉黑,请联系管理员')
|
ElMessage.error(data.message || '账户已被拉黑,请联系管理员')
|
||||||
} else if (data.code === 'PAYMENT_REQUIRED') {
|
} else if (data.code === 'PAYMENT_REQUIRED') {
|
||||||
// 需要支付,跳转到支付页面
|
// 需要支付,跳转到支付页面
|
||||||
|
|||||||
@@ -173,22 +173,40 @@ const handleLogin = async () => {
|
|||||||
captchaText: captchaInfo.captchaText
|
captchaText: captchaInfo.captchaText
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await userStore.login(loginData)
|
console.log('开始调用登录接口');
|
||||||
|
try {
|
||||||
if (result.success) {
|
const result = await userStore.login(loginData)
|
||||||
// 登录成功,跳转到目标页面或转账管理
|
console.log('登录接口调用完成');
|
||||||
const redirectPath = route.query.redirect || '/transfers'
|
console.log(result,'result');
|
||||||
router.push(redirectPath)
|
|
||||||
} else if (result.needPayment) {
|
if (result.success) {
|
||||||
// 用户需要支付激活,直接跳转到支付页面
|
// 登录成功,跳转到目标页面或转账管理
|
||||||
ElMessage.info('账户尚未激活,正在跳转到支付页面...')
|
const redirectPath = route.query.redirect || '/transfers'
|
||||||
router.push({
|
router.push(redirectPath)
|
||||||
path: '/payment',
|
} else if (result.needPayment) {
|
||||||
query: {
|
// 用户需要支付激活,直接跳转到支付页面
|
||||||
userId: result.userId,
|
ElMessage.info('账户尚未激活,正在跳转到支付页面...')
|
||||||
from: 'login'
|
router.push({
|
||||||
}
|
path: '/payment',
|
||||||
})
|
query: {
|
||||||
|
userId: result.userId,
|
||||||
|
from: 'login'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (loginError) {
|
||||||
|
console.error('登录调用异常:', loginError)
|
||||||
|
// 如果是支付相关的错误,也要处理
|
||||||
|
if (loginError.needPayment) {
|
||||||
|
ElMessage.info('账户尚未激活,正在跳转到支付页面...')
|
||||||
|
router.push({
|
||||||
|
path: '/payment',
|
||||||
|
query: {
|
||||||
|
userId: loginError.userId,
|
||||||
|
from: 'login'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('登录失败:', error)
|
console.error('登录失败:', error)
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ const handleLogin = async () => {
|
|||||||
const valid = await loginFormRef.value.validate()
|
const valid = await loginFormRef.value.validate()
|
||||||
if (!valid) return
|
if (!valid) return
|
||||||
|
|
||||||
// // 验证验证码
|
// 验证验证码
|
||||||
// const captchaValid = await captchaRef.value.verifyCaptcha(loginForm.captcha)
|
// const captchaValid = await captchaRef.value.verifyCaptcha(loginForm.captcha)
|
||||||
// if (!captchaValid) {
|
// if (!captchaValid) {
|
||||||
// loginForm.captcha = ''
|
// loginForm.captcha = ''
|
||||||
@@ -199,12 +199,40 @@ const handleLogin = async () => {
|
|||||||
captchaText: captchaInfo.captchaText
|
captchaText: captchaInfo.captchaText
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await userStore.login(loginData)
|
console.log('开始调用登录接口');
|
||||||
|
try {
|
||||||
if (result.success) {
|
const result = await userStore.login(loginData)
|
||||||
// 登录成功,跳转到目标页面或转账管理
|
console.log('登录接口调用完成');
|
||||||
const redirectPath = route.query.redirect || '/mainpage'
|
console.log(result,'result');
|
||||||
router.push(redirectPath)
|
|
||||||
|
if (result.success) {
|
||||||
|
// 登录成功,跳转到目标页面或转账管理
|
||||||
|
const redirectPath = route.query.redirect || '/transfers'
|
||||||
|
router.push(redirectPath)
|
||||||
|
} else if (result.needPayment) {
|
||||||
|
// 用户需要支付激活,直接跳转到支付页面
|
||||||
|
ElMessage.info('账户尚未激活,正在跳转到支付页面...')
|
||||||
|
router.push({
|
||||||
|
path: '/payment',
|
||||||
|
query: {
|
||||||
|
userId: result.userId,
|
||||||
|
from: 'login'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (loginError) {
|
||||||
|
console.error('登录调用异常:', loginError)
|
||||||
|
// 如果是支付相关的错误,也要处理
|
||||||
|
if (loginError.needPayment) {
|
||||||
|
ElMessage.info('账户尚未激活,正在跳转到支付页面...')
|
||||||
|
router.push({
|
||||||
|
path: '/payment',
|
||||||
|
query: {
|
||||||
|
userId: loginError.userId,
|
||||||
|
from: 'login'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('登录失败:', error)
|
console.error('登录失败:', error)
|
||||||
@@ -216,21 +244,6 @@ const handleLogin = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 快速登录(演示用)
|
|
||||||
const quickLogin = async (type) => {
|
|
||||||
if (type === 'admin') {
|
|
||||||
loginForm.username = 'admin'
|
|
||||||
loginForm.password = 'admin123'
|
|
||||||
} else {
|
|
||||||
loginForm.username = 'user'
|
|
||||||
loginForm.password = 'user123'
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清空验证码,让用户手动输入
|
|
||||||
loginForm.captcha = ''
|
|
||||||
ElMessage.info('请输入验证码后登录')
|
|
||||||
}
|
|
||||||
|
|
||||||
// 忘记密码
|
// 忘记密码
|
||||||
const showForgotPassword = () => {
|
const showForgotPassword = () => {
|
||||||
ElMessageBox.alert(
|
ElMessageBox.alert(
|
||||||
|
|||||||
@@ -7,14 +7,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="payment-info">
|
<div class="payment-info">
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">用户名:</span>
|
|
||||||
<span class="value">{{ userInfo.username }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="info-item">
|
|
||||||
<span class="label">手机号:</span>
|
|
||||||
<span class="value">{{ userInfo.phone }}</span>
|
|
||||||
</div>
|
|
||||||
<div class="info-item">
|
<div class="info-item">
|
||||||
<span class="label">支付金额:</span>
|
<span class="label">支付金额:</span>
|
||||||
<span class="value price">¥{{ paymentAmount }}</span>
|
<span class="value price">¥{{ paymentAmount }}</span>
|
||||||
@@ -78,8 +70,7 @@ const paymentLoading = ref(false)
|
|||||||
const paymentStatus = ref('')
|
const paymentStatus = ref('')
|
||||||
const paymentAmount = ref(99) // 注册费用
|
const paymentAmount = ref(99) // 注册费用
|
||||||
const userInfo = reactive({
|
const userInfo = reactive({
|
||||||
username: '',
|
userId: '',
|
||||||
phone: ''
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
@@ -91,31 +82,6 @@ const getUserInfo = async () => {
|
|||||||
userInfo.phone = userStore.user.phone
|
userInfo.phone = userStore.user.phone
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果store中没有用户信息,尝试从URL参数获取
|
|
||||||
const token = route.query.token
|
|
||||||
const userId = route.query.userId
|
|
||||||
|
|
||||||
if (token && userId) {
|
|
||||||
// 设置临时token以获取用户信息
|
|
||||||
const response = await api.get(`/users/${userId}`, {
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${token}`
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.data.success) {
|
|
||||||
userInfo.username = response.data.user.username
|
|
||||||
userInfo.phone = response.data.user.phone
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果没有URL参数,尝试获取当前用户信息
|
|
||||||
const response = await api.get('/auth/me')
|
|
||||||
if (response.data.success) {
|
|
||||||
userInfo.username = response.data.user.username
|
|
||||||
userInfo.phone = response.data.user.phone
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取用户信息失败:', error)
|
console.error('获取用户信息失败:', error)
|
||||||
ElMessage.error('获取用户信息失败')
|
ElMessage.error('获取用户信息失败')
|
||||||
|
|||||||
Reference in New Issue
Block a user