From f51508616268829888df261a0ee36176863bfefb Mon Sep 17 00:00:00 2001 From: dzl <786316265@qq.com> Date: Mon, 20 Oct 2025 17:21:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E5=AE=A1?= =?UTF-8?q?=E6=A0=B8=EF=BC=8C=E9=99=90=E5=88=B6=E6=98=BE=E7=A4=BA=E5=86=85?= =?UTF-8?q?=E5=AE=B9=EF=BC=8C=E7=BB=86=E8=8A=82=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Captcha.vue | 2 +- src/layout/Layout.vue | 20 +++++++++++--------- src/router/index.js | 13 ++++++++++++- src/stores/user.js | 7 ++++++- src/utils/api.js | 7 ++++--- src/views/Orders.vue | 3 +++ src/views/ProductForm.vue | 11 +++++++++-- src/views/Products.vue | 9 ++++++--- src/views/Profile.vue | 7 ++++--- src/views/WithdrawalApproval.vue | 3 ++- 10 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/components/Captcha.vue b/src/components/Captcha.vue index 1911153..af9ad77 100644 --- a/src/components/Captcha.vue +++ b/src/components/Captcha.vue @@ -81,7 +81,7 @@ const loading = ref(false) const getCaptcha = async () => { try { loading.value = true - const response = await api.auth.captcha('/captcha/generate') + const response = await api.auth.captcha() if (response.data.success) { captchaImage.value = response.data.data.image diff --git a/src/layout/Layout.vue b/src/layout/Layout.vue index cd90f74..e7f2eca 100644 --- a/src/layout/Layout.vue +++ b/src/layout/Layout.vue @@ -20,16 +20,16 @@ - + - + - + @@ -199,6 +199,7 @@ import { const route = useRoute() const router = useRouter() const userStore = useUserStore() +import api from '@/utils/api' // 组件挂载时不再自动验证token,避免登录后立即触发401错误 // token验证交给具体的API调用时处理 @@ -228,8 +229,8 @@ const passwordRules = { { required: true, message: '请输入新密码', trigger: 'blur' }, { min: 6, message: '密码长度不能少于6位', trigger: 'blur' }, { - pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{6,}$/, - message: '密码必须包含大小写字母和数字', + pattern: /^(?=.*[a-zA-Z])(?=.*\d)/, + message: '密码必须包含字母和数字', trigger: 'blur' } ], @@ -320,12 +321,13 @@ const handleChangePassword = async () => { try { await passwordFormRef.value.validate() - const result = await userStore.changePassword({ - currentPassword: passwordForm.value.currentPassword, + const result = await api.users.changePassword({ + id: userStore.user.id, + oldPassword: passwordForm.value.currentPassword, newPassword: passwordForm.value.newPassword }) - - if (result.success) { + if (result.data.success) { + ElMessage.success('密码修改成功') passwordDialogVisible.value = false resetPasswordForm() diff --git a/src/router/index.js b/src/router/index.js index ae8d32e..9213053 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -160,11 +160,22 @@ router.beforeEach(async (to, from, next) => { } // 检查管理员权限 - if (to.meta.requiresAdmin && !userStore.isAdmin) { + if (!userStore.isSupplier || userStore.isDelete) { ElMessage.error('您没有权限访问此页面') next('/dashboard') return } + + // 检查审核状态 + if (userStore.audit_status === 'pending') { + ElMessage.warning('您的账号审核中,请稍后登录') + next('/dashboard') + return + } else if (userStore.audit_status === 'rejected') { + ElMessage.error('您的账号已被拒绝,请联系管理员') + next('/dashboard') + return + } } // 如果已登录用户访问登录页,重定向到仪表盘 diff --git a/src/stores/user.js b/src/stores/user.js index a660119..5b5482a 100644 --- a/src/stores/user.js +++ b/src/stores/user.js @@ -12,7 +12,12 @@ export const useUserStore = defineStore('user', { getters: { isAuthenticated: (state) => !!state.token && !!state.user, - isAdmin: (state) => state.user?.role === 'admin' + isAdmin: (state) => state.user?.role === 'admin', + isSupplier: (state) => state.user?.role === "supplier", + isDelete: (state) => state.user?.is_delete === 1, + audit_status: (state) => state.user?.audit_status || "pending", + + // isSupplier: (state) => state.user?.user_type === "supplier", }, actions: { diff --git a/src/utils/api.js b/src/utils/api.js index a4fd879..cab33d1 100644 --- a/src/utils/api.js +++ b/src/utils/api.js @@ -160,7 +160,7 @@ export const createRequest = (baseURL) => { } // 生成不同的实例 export const apiRequest = createRequest(import.meta.env.VITE_API_BASE_URL || '/api') -export const midRequest = createRequest(import.meta.env.VITE_UPLOAD_BASE_URL || '/mid') +export const midRequest = createRequest(import.meta.env.VITE_UPLOAD_BASE_URL || 'http://192.168.0.12:3005/mid') // API接口定义 @@ -170,7 +170,7 @@ const api = { login: (data) => midRequest.post('/auth/login', data), register: (data) => apiRequest.post('/auth/register', data), getCurrentUser: () => apiRequest.get('/auth/me'), - changePassword: (data) => apiRequest.put('/auth/change-password', data), + // changePassword: (data) => apiRequest.put('/auth/change-password', data), captcha: () => midRequest.get('/captcha/generate'), }, @@ -184,7 +184,8 @@ const api = { getUserStats: () => apiRequest.get('/users/stats'), getUserGrowthTrend: (params) => apiRequest.get('/users/growth-trend', {params}), getDailyRevenue: (params) => apiRequest.get('/users/daily-revenue', {params}), - getAgentOptions: (params) => apiRequest.get('/admin/agents', {params}) + getAgentOptions: (params) => apiRequest.get('/admin/agents', {params}), + changePassword: (data) => apiRequest.put('/users/password', data), }, diff --git a/src/views/Orders.vue b/src/views/Orders.vue index acbbb6e..f5917d3 100644 --- a/src/views/Orders.vue +++ b/src/views/Orders.vue @@ -265,6 +265,7 @@ import { ElMessage, ElMessageBox } from 'element-plus'; import { ArrowDown } from '@element-plus/icons-vue'; import api from '@/utils/api'; import { getImageUrl } from '@/utils/config'; +import { useUserStore } from '@/stores/user'; import dayjs from 'dayjs'; const loading = ref(false); @@ -272,6 +273,7 @@ const orders = ref([]); const dialogVisible = ref(false); const deliveryDialogVisible = ref(false); const selectedOrder = ref(null); +const user = useUserStore().user; const filters = reactive({ orderNumber: '', @@ -301,6 +303,7 @@ const loadOrders = async () => { orderNumber: filters.orderNumber, username: filters.username, status: filters.status, + shop_name: user.id, }; if (filters.dateRange && filters.dateRange.length === 2) { diff --git a/src/views/ProductForm.vue b/src/views/ProductForm.vue index 1d19009..f06c7c0 100644 --- a/src/views/ProductForm.vue +++ b/src/views/ProductForm.vue @@ -58,6 +58,7 @@ size="large" clearable @change="handlePrimaryCategoryChange" + filterable > { return categories.value.filter(cat => cat.level === 1) @@ -755,7 +762,7 @@ const form = reactive({ images: [], videos: [], shop_name: '', - shop_avatar: '', + shop_avatar: getImageUrl(user.avatar), payment_methods: ['points'], description: '', details: '', @@ -1171,7 +1178,7 @@ const submitForm = async () => { image_url: form.image.replace('https://minio.zrbjr.com', ''), // 前端 image -> 后端 image_url images: JSON.stringify(form.images.map(img => img.replace('https://minio.zrbjr.com', ''))), videos: JSON.stringify(form.videos), - shop_name: form.shop_name, + shop_name: user.id, shop_avatar: form.shop_avatar, payment_methods: JSON.stringify(form.payment_methods), description: form.description, diff --git a/src/views/Products.vue b/src/views/Products.vue index 2e48f23..021b598 100644 --- a/src/views/Products.vue +++ b/src/views/Products.vue @@ -19,7 +19,7 @@ /> - + {{ row.rongdou_price || 0 }} 融豆 - + @@ -147,11 +147,13 @@ import { ElMessage, ElMessageBox } from 'element-plus' import { Plus, ArrowDown, Setting, Grid } from '@element-plus/icons-vue' import api from '@/utils/api' import { getImageUrl } from '@/utils/config' +import {useUserStore} from '@/stores/user' const router = useRouter() const loading = ref(false) const products = ref([]) const categories = ref([]) +const user = useUserStore().user const filters = reactive({ search: '', @@ -170,6 +172,7 @@ const loadProducts = async () => { loading.value = true try { const params = { + shop_name: user.id, page: pagination.value.page, limit: pagination.value.limit, ...filters diff --git a/src/views/Profile.vue b/src/views/Profile.vue index f5b8531..6cfefcd 100644 --- a/src/views/Profile.vue +++ b/src/views/Profile.vue @@ -394,8 +394,8 @@ const passwordRules = { { required: true, message: '请输入新密码', trigger: 'blur' }, { min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur' }, { - pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]/, - message: '密码必须包含大小写字母和数字', + pattern: /^(?=.*[a-zA-Z])(?=.*\d)/, + message: '密码必须包含字母和数字', trigger: 'blur' } ], @@ -488,7 +488,8 @@ const changePassword = async () => { changingPassword.value = true await api.users.changePassword({ - currentPassword: passwordForm.currentPassword, + id: userStore.user.id, + oldPassword: passwordForm.currentPassword, newPassword: passwordForm.newPassword }) diff --git a/src/views/WithdrawalApproval.vue b/src/views/WithdrawalApproval.vue index ee34813..db3b08a 100644 --- a/src/views/WithdrawalApproval.vue +++ b/src/views/WithdrawalApproval.vue @@ -178,7 +178,8 @@ const loadWithdrawList = async () => { try { const { data } = await api.withdraw.getWithdrawList({ page: pagination.page, - limit: pagination.limit + limit: pagination.limit, + user_id: userStore.user.id }) withdrawList.value = data.data.withdrawals || [] pagination.total = data.data.pagination.total || 0