From 2e08e6efcb44c2525b094377f01131a01ecb73c7 Mon Sep 17 00:00:00 2001 From: xingyy <64720302+Concur-max@users.noreply.github.com> Date: Wed, 5 Feb 2025 17:00:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(collect-code):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=94=B6=E6=AC=BE=E4=BA=8C=E7=BB=B4=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加新的 API接口和相关组件 - 实现用户认证和艺术品列表展示- 新增个人资料填写页面- 优化首页和登录页面样式 --- app/api-collect-code/auth/index.js | 25 ++ app/api-collect-code/goods/index.js | 32 +++ app/api-collect-code/http.js | 128 +++++++++++ app/app.vue | 4 + app/components/x-image/index.vue | 2 - app/components/x-van-date/index.vue | 109 +++++++++ app/components/x-van-select/index.vue | 88 +++++++ app/pages/collectCode/login/index.vue | 5 - app/pages/collectCode/mine/index.vue | 215 ++++++++++++++++-- .../signature/personal-Info/index.vue | 52 +++++ .../home/components/DetailPopup/index.vue | 6 +- app/pages/home/components/ItemList/index.vue | 2 +- .../components/SideButton/tangPopup.vue | 66 +++--- app/pages/liveRoom/index.client.vue | 6 +- app/pages/login/index.vue | 2 +- app/static/images/delete3@.png | Bin 0 -> 2566 bytes app/static/images/icon-design-42@3x.png | Bin 0 -> 686 bytes app/stores-collect-code/auth/index.js | 13 ++ app/stores-collect-code/goods/index.js | 114 ++++++++++ app/stores-collect-code/live/index.js | 43 ++++ env/.env.test | 1 + package.json | 1 + pnpm-lock.yaml | 22 +- uno.config.js | 3 + 24 files changed, 864 insertions(+), 75 deletions(-) create mode 100644 app/api-collect-code/auth/index.js create mode 100644 app/api-collect-code/goods/index.js create mode 100644 app/api-collect-code/http.js create mode 100644 app/components/x-van-date/index.vue create mode 100644 app/components/x-van-select/index.vue create mode 100644 app/pages/collectCode/signature/personal-Info/index.vue create mode 100644 app/static/images/delete3@.png create mode 100644 app/static/images/icon-design-42@3x.png create mode 100644 app/stores-collect-code/auth/index.js create mode 100644 app/stores-collect-code/goods/index.js create mode 100644 app/stores-collect-code/live/index.js diff --git a/app/api-collect-code/auth/index.js b/app/api-collect-code/auth/index.js new file mode 100644 index 0000000..66c5ee3 --- /dev/null +++ b/app/api-collect-code/auth/index.js @@ -0,0 +1,25 @@ +import { request } from '@/api/http.js' + +export async function senCode(data) { + + return await request({ + url:'/api/v1/m/user/send', + method: 'POST', + data + }) +} +export async function userLogin(data) { + + return await request( { + url:'/api/v1/m/user/login', + method: 'POST', + data + }) +} +export async function userUpdate(data) { + return await request( { + url:'/api/v1/m/user/update', + method: 'POST', + data + }) +} \ No newline at end of file diff --git a/app/api-collect-code/goods/index.js b/app/api-collect-code/goods/index.js new file mode 100644 index 0000000..99c537d --- /dev/null +++ b/app/api-collect-code/goods/index.js @@ -0,0 +1,32 @@ +import { request } from '@/api/http.js' + +export async function artworkList(data) { + return await request( { + url:'/api/v1/m/auction/default/artwork/list', + method: 'POST', + data + }) +} +export async function defaultDetail(data) { + return await request ({ + url:'/api/v1/m/auction/default/detail', + method: 'POST', + data + }) +} +export async function artworkDetail(data) { + + return await request( { + url:'/api/v1/m/artwork/detail', + method: 'POST', + data, + }) +} +export async function userArtworks(data) { + + return await request( { + url:'/api/v1/m/user/artworks', + method: 'POST', + data + }) +} diff --git a/app/api-collect-code/http.js b/app/api-collect-code/http.js new file mode 100644 index 0000000..4b5be00 --- /dev/null +++ b/app/api-collect-code/http.js @@ -0,0 +1,128 @@ +import {useRuntimeConfig} from '#app' +import {ofetch} from 'ofetch' +import {message} from '@/components/x-message/useMessage.js' +import {codeAuthStore} from "@/stores-collect-code/auth/index.js" + +let httpStatusErrorHandler +let http + +// HTTP 状态码映射 +const HTTP_STATUS_MAP = { + 400: '请求参数错误', + 401: '未授权或登录过期', + 403: '访问被禁止', + 404: '请求的资源不存在', + 500: '服务器内部错误', + 502: '网关错误', + 503: '服务暂时不可用', + 504: '网关超时' +} + +export function setupHttp() { + if (http) return http + const {token}= codeAuthStore() + const config = useRuntimeConfig() + const baseURL = config.public.NUXT_PUBLIC_API_COLLECT_CODE + + const router = useRouter() + + const defaultOptions = { + baseURL, + headers: { 'Content-Type': 'application/json' }, + timeout: 15000, // 15秒超时 + retry: 3, + retryDelay: 1000, + } + + http = ofetch.create({ + ...defaultOptions, + + // 请求拦截 + async onRequest({ options, request }) { + // 添加 token + options.headers = { + ...options.headers, + Authorization: token.value + } + + // GET 请求添加时间戳防止缓存 + if (request.toLowerCase().includes('get')) { + options.params = { + ...options.params, + _t: Date.now() + } + } + }, + + // 响应拦截 + async onResponse({ response }) { + const data = response._data + + // 处理业务错误 + if (data.status === 1) { + message.error(data.msg || '操作失败') + } + + // 处理登录失效 + if (data.status === 401) { + message.error('登录已过期,请重新登录') + token.value = '' // 清除 token + router.replace('/collectCode/login') + } + + return response + }, + + // 响应错误处理 + async onResponseError({ response, request }) { + // 网络错误 + if (!response) { + message.error('网络连接失败,请检查网络设置') + return Promise.reject(new Error('网络错误')) + } + const status = response.status + const data = response._data + + // 处理 HTTP 状态错误 + const errorMessage = data.msg || HTTP_STATUS_MAP[status] || '请求失败' + + if (Array.isArray(data.msg)) { + data.msg.forEach(item => { + httpStatusErrorHandler?.(item, status) + }) + } else { + httpStatusErrorHandler?.(errorMessage, status) + } + + message.error(errorMessage) + return Promise.reject(data) + }, + }) + + return http +} + +export function createAbortController() { + return new AbortController() +} + +export function injectHttpStatusErrorHandler(handler) { + httpStatusErrorHandler = handler +} + +export function getHttp() { + if (!http) { + throw new Error('HTTP client not initialized. Call setupHttp first.') + } + return http +} + +// 导出请求工具函数 +export async function request({url,...options}) { + const http = getHttp() + try { + return await http(url, {...options,body:options.data}) + } catch (error) { + throw error + } +} \ No newline at end of file diff --git a/app/app.vue b/app/app.vue index 240e930..a373a9a 100644 --- a/app/app.vue +++ b/app/app.vue @@ -51,6 +51,9 @@ provide('slideDirection', slideDirection) \ No newline at end of file diff --git a/app/components/x-image/index.vue b/app/components/x-image/index.vue index 88d87e9..0ea2349 100644 --- a/app/components/x-image/index.vue +++ b/app/components/x-image/index.vue @@ -36,7 +36,6 @@ const showImage = () => { diff --git a/app/pages/collectCode/signature/personal-Info/index.vue b/app/pages/collectCode/signature/personal-Info/index.vue new file mode 100644 index 0000000..38d6152 --- /dev/null +++ b/app/pages/collectCode/signature/personal-Info/index.vue @@ -0,0 +1,52 @@ + + + + + \ No newline at end of file diff --git a/app/pages/home/components/DetailPopup/index.vue b/app/pages/home/components/DetailPopup/index.vue index e315e58..91b4cec 100644 --- a/app/pages/home/components/DetailPopup/index.vue +++ b/app/pages/home/components/DetailPopup/index.vue @@ -9,6 +9,10 @@ const props = defineProps({ show: { type: Boolean, default: false + }, + detailInfo: { + type: Object, + default: null } }) @@ -19,6 +23,6 @@ const handleClose = () => { \ No newline at end of file diff --git a/app/pages/home/components/ItemList/index.vue b/app/pages/home/components/ItemList/index.vue index 99ac880..f35dd41 100644 --- a/app/pages/home/components/ItemList/index.vue +++ b/app/pages/home/components/ItemList/index.vue @@ -104,7 +104,7 @@ const openShow = async (item) => { - + diff --git a/app/pages/liveRoom/components/SideButton/tangPopup.vue b/app/pages/liveRoom/components/SideButton/tangPopup.vue index a4828f4..ac49fac 100644 --- a/app/pages/liveRoom/components/SideButton/tangPopup.vue +++ b/app/pages/liveRoom/components/SideButton/tangPopup.vue @@ -13,48 +13,52 @@ const props = defineProps({ } }) const emit = defineEmits(['update:show']) - +const showDetailInfo=ref(null) const close = () => emit('update:show', false); -const openShow=()=>{ +const openShow=(item)=>{ + showDetailInfo.value=item showDetail.value=true + } +