微信支付
This commit is contained in:
@@ -137,7 +137,7 @@ const routes = [
|
||||
component: () => import('@/views/Payment.vue'),
|
||||
meta: {
|
||||
title: '支付激活',
|
||||
requiresAuth: true
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -248,37 +248,37 @@ const routes = [
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/buydetail',
|
||||
name: 'BuyDetail',
|
||||
component: () => import('../views/BuyDetails.vue'),
|
||||
meta: { title: '确认订单' }
|
||||
},
|
||||
{
|
||||
path: '/pay/:orderId',
|
||||
name: 'Pay',
|
||||
component: () => import('@/views/Pay.vue'),
|
||||
meta: { title: '确认支付' },
|
||||
props: route => ({ orderId: route.query.orderId })
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
name: 'Cart',
|
||||
component: () => import('@/views/Cart.vue'),
|
||||
meta: { title: '购物车' }
|
||||
},
|
||||
{
|
||||
path: '/address',
|
||||
name: 'Address',
|
||||
component: () => import('@/views/Address.vue'),
|
||||
meta: { title: '地址管理', requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/payloading',
|
||||
name: 'PayLoading',
|
||||
component: () => import('@/views/PayLoading.vue'),
|
||||
meta: { title: '支付确认' },
|
||||
props: route => ({ orderId: route.query.orderId })
|
||||
},
|
||||
path: '/buydetail',
|
||||
name: 'BuyDetail',
|
||||
component: () => import('../views/BuyDetails.vue'),
|
||||
meta: { title: '确认订单' }
|
||||
},
|
||||
{
|
||||
path: '/pay/:orderId',
|
||||
name: 'Pay',
|
||||
component: () => import('@/views/Pay.vue'),
|
||||
meta: { title: '确认支付' },
|
||||
props: route => ({ orderId: route.query.orderId })
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
name: 'Cart',
|
||||
component: () => import('@/views/Cart.vue'),
|
||||
meta: { title: '购物车' }
|
||||
},
|
||||
{
|
||||
path: '/address',
|
||||
name: 'Address',
|
||||
component: () => import('@/views/Address.vue'),
|
||||
meta: { title: '地址管理', requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/payloading',
|
||||
name: 'PayLoading',
|
||||
component: () => import('@/views/PayLoading.vue'),
|
||||
meta: { title: '支付确认' },
|
||||
props: route => ({ orderId: route.query.orderId })
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'NotFound',
|
||||
@@ -314,8 +314,8 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
// 检查维护模式
|
||||
try {
|
||||
const {data} = await api.get('/system/maintenance-status', { showLoading: false })
|
||||
console.log(data,'data');
|
||||
const { data } = await api.get('/system/maintenance-status', { showLoading: false })
|
||||
console.log(data, 'data');
|
||||
|
||||
if (data.success) {
|
||||
if (data.data.maintenance_mode) {
|
||||
@@ -347,7 +347,7 @@ router.beforeEach(async (to, from, next) => {
|
||||
|
||||
if (!agentInfo || !agentToken) {
|
||||
next({
|
||||
path: '/agent/login',
|
||||
path: '/mylogin',
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
return
|
||||
@@ -368,7 +368,11 @@ router.beforeEach(async (to, from, next) => {
|
||||
}
|
||||
|
||||
// 检查支付状态(管理员除外)
|
||||
console.log(userStore.user);
|
||||
|
||||
if (userStore.user && userStore.user.role !== 'admin' && userStore.user.payment_status === 'unpaid') {
|
||||
console.log('进来了');
|
||||
|
||||
// 如果当前不在支付页面,静默重定向到支付页面(不显示额外通知)
|
||||
if (to.name !== 'Payment') {
|
||||
next({
|
||||
@@ -376,6 +380,8 @@ router.beforeEach(async (to, from, next) => {
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
return
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,13 +48,24 @@ export const useUserStore = defineStore('user', () => {
|
||||
ElMessage.success(response.data.message || '登录成功')
|
||||
return { success: true, data: response.data }
|
||||
} 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,
|
||||
needPayment: true,
|
||||
userId: response.data.userId,
|
||||
message: response.data.message
|
||||
}
|
||||
console.log('即将返回needPayment数据:', returnData);
|
||||
return returnData
|
||||
} else {
|
||||
const message = response.data.message || '登录失败'
|
||||
ElMessage.error(message)
|
||||
|
||||
@@ -72,10 +72,10 @@ api.interceptors.response.use(
|
||||
// 判断当前是否在代理相关页面
|
||||
const currentPath = router.currentRoute.value.path
|
||||
if (currentPath.startsWith('/agent')) {
|
||||
router.push('/agent/login')
|
||||
router.push('/agent/mylogin')
|
||||
ElMessage.error('代理登录已过期,请重新登录')
|
||||
} else {
|
||||
router.push({ name: 'Login' })
|
||||
router.push({ name: 'MyLogin' })
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
}
|
||||
break
|
||||
@@ -86,7 +86,7 @@ api.interceptors.response.use(
|
||||
// 清除token并跳转到登录页
|
||||
localStorage.removeItem('token')
|
||||
delete api.defaults.headers.common['Authorization']
|
||||
router.push({ name: 'Login' })
|
||||
router.push({ name: 'MyLogin' })
|
||||
ElMessage.error(data.message || '账户已被拉黑,请联系管理员')
|
||||
} else if (data.code === 'PAYMENT_REQUIRED') {
|
||||
// 需要支付,跳转到支付页面
|
||||
|
||||
@@ -173,22 +173,40 @@ const handleLogin = async () => {
|
||||
captchaText: captchaInfo.captchaText
|
||||
}
|
||||
|
||||
const result = await userStore.login(loginData)
|
||||
console.log('开始调用登录接口');
|
||||
try {
|
||||
const result = await userStore.login(loginData)
|
||||
console.log('登录接口调用完成');
|
||||
console.log(result,'result');
|
||||
|
||||
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'
|
||||
}
|
||||
})
|
||||
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) {
|
||||
console.error('登录失败:', error)
|
||||
|
||||
@@ -181,7 +181,7 @@ const handleLogin = async () => {
|
||||
const valid = await loginFormRef.value.validate()
|
||||
if (!valid) return
|
||||
|
||||
// // 验证验证码
|
||||
// 验证验证码
|
||||
// const captchaValid = await captchaRef.value.verifyCaptcha(loginForm.captcha)
|
||||
// if (!captchaValid) {
|
||||
// loginForm.captcha = ''
|
||||
@@ -199,12 +199,40 @@ const handleLogin = async () => {
|
||||
captchaText: captchaInfo.captchaText
|
||||
}
|
||||
|
||||
const result = await userStore.login(loginData)
|
||||
console.log('开始调用登录接口');
|
||||
try {
|
||||
const result = await userStore.login(loginData)
|
||||
console.log('登录接口调用完成');
|
||||
console.log(result,'result');
|
||||
|
||||
if (result.success) {
|
||||
// 登录成功,跳转到目标页面或转账管理
|
||||
const redirectPath = route.query.redirect || '/mainpage'
|
||||
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) {
|
||||
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 = () => {
|
||||
ElMessageBox.alert(
|
||||
|
||||
@@ -7,14 +7,6 @@
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<span class="label">支付金额:</span>
|
||||
<span class="value price">¥{{ paymentAmount }}</span>
|
||||
@@ -78,8 +70,7 @@ const paymentLoading = ref(false)
|
||||
const paymentStatus = ref('')
|
||||
const paymentAmount = ref(99) // 注册费用
|
||||
const userInfo = reactive({
|
||||
username: '',
|
||||
phone: ''
|
||||
userId: '',
|
||||
})
|
||||
|
||||
// 获取用户信息
|
||||
@@ -91,31 +82,6 @@ const getUserInfo = async () => {
|
||||
userInfo.phone = userStore.user.phone
|
||||
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) {
|
||||
console.error('获取用户信息失败:', error)
|
||||
ElMessage.error('获取用户信息失败')
|
||||
|
||||
Reference in New Issue
Block a user