diff --git a/app/api-collect-code/goods/index.js b/app/api-collect-code/goods/index.js index 30e1fb0..60a5206 100644 --- a/app/api-collect-code/goods/index.js +++ b/app/api-collect-code/goods/index.js @@ -29,3 +29,35 @@ export async function userArtworks(data) { data }) } +export async function fddInfo(data) { + + return await request( { + url:'/api/v1/contract/fdd-info', + method: 'POST', + data + }) +} +export async function sessionUserNoCreate(data) { + + return await request( { + url:'/api/v1/auction/sessionUserNo/create', + method: 'POST', + data + }) +} +export async function offlineQrcode(data) { + + return await request( { + url:'/api/v1/offlineQrcode/info', + method: 'POST', + data + }) +} +export async function createOrder(data) { + + return await request( { + url:'/api/v1/offlineQrcode/createOrder', + method: 'POST', + data + }) +} \ No newline at end of file diff --git a/app/api-collect-code/http.js b/app/api-collect-code/http.js index 4b5be00..e59b001 100644 --- a/app/api-collect-code/http.js +++ b/app/api-collect-code/http.js @@ -6,25 +6,26 @@ 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: '网关超时' -} - +// HTTP 状态码映射 - 使用i18n国际化 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 i18n = useNuxtApp().$i18n + + // 国际化的HTTP状态码映射 + const HTTP_STATUS_MAP = { + 400: i18n.t('http.error.badRequest'), + 401: i18n.t('http.error.unauthorized'), + 403: i18n.t('http.error.forbidden'), + 404: i18n.t('http.error.notFound'), + 500: i18n.t('http.error.serverError'), + 502: i18n.t('http.error.badGateway'), + 503: i18n.t('http.error.serviceUnavailable'), + 504: i18n.t('http.error.gatewayTimeout') + } const defaultOptions = { baseURL, @@ -42,7 +43,8 @@ export function setupHttp() { // 添加 token options.headers = { ...options.headers, - Authorization: token.value + Authorization: token.value, + 'accept-language': i18n.locale.value } // GET 请求添加时间戳防止缓存 @@ -60,12 +62,12 @@ export function setupHttp() { // 处理业务错误 if (data.status === 1) { - message.error(data.msg || '操作失败') + message.error(data.msg || i18n.t('http.error.operationFailed')) } // 处理登录失效 if (data.status === 401) { - message.error('登录已过期,请重新登录') + message.error(i18n.t('http.error.loginExpired')) token.value = '' // 清除 token router.replace('/collectCode/login') } @@ -77,14 +79,14 @@ export function setupHttp() { async onResponseError({ response, request }) { // 网络错误 if (!response) { - message.error('网络连接失败,请检查网络设置') - return Promise.reject(new Error('网络错误')) + message.error(i18n.t('http.error.networkError')) + return Promise.reject(new Error(i18n.t('http.error.networkError'))) } const status = response.status const data = response._data // 处理 HTTP 状态错误 - const errorMessage = data.msg || HTTP_STATUS_MAP[status] || '请求失败' + const errorMessage = data.msg || HTTP_STATUS_MAP[status] || i18n.t('http.error.requestFailed') if (Array.isArray(data.msg)) { data.msg.forEach(item => { @@ -112,7 +114,7 @@ export function injectHttpStatusErrorHandler(handler) { export function getHttp() { if (!http) { - throw new Error('HTTP client not initialized. Call setupHttp first.') + throw new Error(useNuxtApp().$i18n.t('http.error.httpNotInitialized')) } return http } diff --git a/app/api/goods/index.js b/app/api/goods/index.js index 264ba5e..a2a5606 100644 --- a/app/api/goods/index.js +++ b/app/api/goods/index.js @@ -53,4 +53,52 @@ export async function logSendlog(data) { method: 'POST', data }) +} +export async function signOnline(data) { + + return await request( { + url:'/api/v1/contract/sign-online', + method: 'POST', + data + }) +} +export async function signOffline(data) { + + return await request( { + url:'/api/v1/contract/sign-offline', + method: 'POST', + data + }) +} +export async function fddCheck(data) { + + return await request( { + url:'/api/v1/m/user/fdd/check', + method: 'POST', + data + }) +} +export async function createBuyOrder(data) { + + return await request( { + url:'/api/v1/m/auction/createBuyOrder', + method: 'POST', + data + }) +} +export async function orderQuery(data) { + + return await request( { + url:'/api/v1/payment/order/query', + method: 'POST', + data + }) +} +export async function contractView(data) { + + return await request( { + url:'/api/v1/contract/contract-view', + method: 'POST', + data + }) } \ No newline at end of file diff --git a/app/api/http.js b/app/api/http.js index 1749f32..40abb74 100644 --- a/app/api/http.js +++ b/app/api/http.js @@ -6,26 +6,27 @@ import {authStore} from "@/stores/auth/index.js" let httpStatusErrorHandler let http -// HTTP 状态码映射 -const HTTP_STATUS_MAP = { - 400: '请求参数错误', - 401: '未授权或登录过期', - 403: '访问被禁止', - 404: '请求的资源不存在', - 500: '服务器内部错误', - 502: '网关错误', - 503: '服务暂时不可用', - 504: '网关超时' -} - +// HTTP 状态码映射 - 使用i18n国际化 export function setupHttp() { if (http) return http - const config = useRuntimeConfig() const baseURL = config.public.NUXT_PUBLIC_API_BASE const { token } = authStore() const router = useRouter() - + const i18n = useNuxtApp().$i18n + + // 国际化的HTTP状态码映射 + const HTTP_STATUS_MAP = { + 400: i18n.t('http.error.badRequest'), + 401: i18n.t('http.error.unauthorized'), + 403: i18n.t('http.error.forbidden'), + 404: i18n.t('http.error.notFound'), + 500: i18n.t('http.error.serverError'), + 502: i18n.t('http.error.badGateway'), + 503: i18n.t('http.error.serviceUnavailable'), + 504: i18n.t('http.error.gatewayTimeout') + } + const defaultOptions = { baseURL, headers: { 'Content-Type': 'application/json' }, @@ -33,7 +34,6 @@ export function setupHttp() { retry: 3, retryDelay: 1000, } - http = ofetch.create({ ...defaultOptions, @@ -42,8 +42,10 @@ export function setupHttp() { // 添加 token options.headers = { ...options.headers, - Authorization: token.value - } + Authorization: token.value, + 'accept-language':i18n.locale.value + + } // GET 请求添加时间戳防止缓存 if (request.toLowerCase().includes('get')) { @@ -60,12 +62,12 @@ export function setupHttp() { // 处理业务错误 if (data.status === 1) { - message.error(data.msg || '操作失败') + message.error(data.msg || i18n.t('http.error.operationFailed')) } // 处理登录失效 if (data.status === 401) { - message.error('登录已过期,请重新登录') + message.error(i18n.t('http.error.loginExpired')) token.value = '' // 清除 token router.replace('/login') } @@ -77,14 +79,14 @@ export function setupHttp() { async onResponseError({ response, request }) { // 网络错误 if (!response) { - message.error('网络连接失败,请检查网络设置') - return Promise.reject(new Error('网络错误')) + message.error(i18n.t('http.error.networkError')) + return Promise.reject(new Error(i18n.t('http.error.networkError'))) } const status = response.status const data = response._data // 处理 HTTP 状态错误 - const errorMessage = data.msg || HTTP_STATUS_MAP[status] || '请求失败' + const errorMessage = data.msg || HTTP_STATUS_MAP[status] || i18n.t('http.error.requestFailed') if (Array.isArray(data.msg)) { data.msg.forEach(item => { @@ -112,7 +114,7 @@ export function injectHttpStatusErrorHandler(handler) { export function getHttp() { if (!http) { - throw new Error('HTTP client not initialized. Call setupHttp first.') + throw new Error(useNuxtApp().$i18n.t('http.error.httpNotInitialized')) } return http } diff --git a/app/app.vue b/app/app.vue index a373a9a..3784383 100644 --- a/app/app.vue +++ b/app/app.vue @@ -1,6 +1,7 @@ \ No newline at end of file diff --git a/app/components/AppHeader.vue b/app/components/AppHeader.vue index d8dca6a..3164524 100644 --- a/app/components/AppHeader.vue +++ b/app/components/AppHeader.vue @@ -1,11 +1,13 @@