From 0aeea9dd20dd7283efb46cfb94861caa4befe5ae Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Thu, 23 Oct 2025 21:10:54 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8F=90=E7=8E=B0=E7=94=B3=E8=AF=B7?= =?UTF-8?q?=E5=8A=9F=E8=83=BD):=20=E5=AF=B9=E6=8E=A5=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/upload.js | 14 +++ src/utils/applyStore.js | 39 +++++++++ src/utils/http.js | 53 ++++++------ src/views/Activities/Lottery/Lottery.vue | 14 +-- src/views/Wallet/CashOut/CashOut.vue | 41 +++++---- src/views/Wallet/CashOut/KYC.vue | 103 ++++++++++++++++++----- 6 files changed, 198 insertions(+), 66 deletions(-) create mode 100644 src/api/upload.js create mode 100644 src/utils/applyStore.js diff --git a/src/api/upload.js b/src/api/upload.js new file mode 100644 index 0000000..66cdb36 --- /dev/null +++ b/src/api/upload.js @@ -0,0 +1,14 @@ +import { get, post } from '../utils/http.js' + +// 上传图片 +export const uploadImg = async (file) => { + try { + const formData = new FormData() + formData.append('file', file) // 这里的'file'需要与后端接口期望的参数名一致 + const response = await post('/external/oss/upload', formData) + return response + } catch (error) { + console.error('Failed to upload img:', error) + throw error + } +} diff --git a/src/utils/applyStore.js b/src/utils/applyStore.js new file mode 100644 index 0000000..bfcb1dd --- /dev/null +++ b/src/utils/applyStore.js @@ -0,0 +1,39 @@ +let applyInfo = null + +/** + * 设置申请资料缓存 + * @param {Object} applyInfo - 申请资料 + */ +export function setApplyInfo(data) { + applyInfo = data + + // 可选:存储到localStorage以便持久化 + if (data) { + localStorage.setItem('applyInfo', JSON.stringify(data)) + } else { + localStorage.removeItem('applyInfo') + } +} + +/** + * 获取申请资料 + * @returns {Object|null} + */ +export function getApplyInfo() { + if (applyInfo) { + return applyInfo + } + + // 从localStorage恢复 + const stored = localStorage.getItem('applyInfo') + if (stored) { + try { + applyInfo = JSON.parse(stored) + return applyInfo + } catch (error) { + console.error('解析申请资料缓存失败:', error) + } + } + + return null +} diff --git a/src/utils/http.js b/src/utils/http.js index 632b2e7..9cd0785 100644 --- a/src/utils/http.js +++ b/src/utils/http.js @@ -1,5 +1,5 @@ // HTTP请求配置 -import {getApiBaseUrl, getCurrentEnv, getUserAuth, isDebugMode} from './env.js' +import { getApiBaseUrl, getCurrentEnv, getUserAuth, isDebugMode } from './env.js' /** * 自定义API错误类 @@ -8,14 +8,14 @@ class ApiError extends Error { constructor(message, options = {}) { super(message) this.name = 'ApiError' - this.status = options.status || null // HTTP状态码 - this.errorCode = options.errorCode || null // 业务错误码 (如: 6010) + this.status = options.status || null // HTTP状态码 + this.errorCode = options.errorCode || null // 业务错误码 (如: 6010) this.errorCodeName = options.errorCodeName || null // 错误码名称 (如: "TEAM_NOT_FOUND") - this.errorMsg = options.errorMsg || null // 业务错误消息 - this.time = options.time || null // API响应时间戳 - this.extValues = options.extValues || null // 扩展值 - this.response = options.response || null // 原始响应数据 - this.type = options.type || 'unknown' // 错误类型: 'http' | 'business' | 'network' + this.errorMsg = options.errorMsg || null // 业务错误消息 + this.time = options.time || null // API响应时间戳 + this.extValues = options.extValues || null // 扩展值 + this.response = options.response || null // 原始响应数据 + this.type = options.type || 'unknown' // 错误类型: 'http' | 'business' | 'network' } } @@ -32,7 +32,7 @@ if (DEBUG_MODE) { const token = getUserAuth() // 默认公共请求头配置 let COMMON_HEADERS = { - 'authorization': `Bearer ${token}`, + authorization: `Bearer ${token}`, 'req-app-intel': 'version=1.0.0;build=1;model=SM-G9550;sysVersion=9;channel=Google', 'req-client': 'Android', 'req-imei': '8fa54d728ab449e04f9292329ed44bda', @@ -49,7 +49,7 @@ let COMMON_HEADERS = { export function updateCommonHeaders(headers) { COMMON_HEADERS = { ...COMMON_HEADERS, - ...headers + ...headers, } console.debug('🔄 Updated common headers:', COMMON_HEADERS) } @@ -110,37 +110,40 @@ export { COMMON_HEADERS, ApiError } * @returns {Promise} - 返回Promise对象 */ export async function request(url, options = {}) { - const { - method = 'GET', - data = null, - headers = {}, - ...otherOptions - } = options - + const { method = 'GET', data = null, headers = {}, ...otherOptions } = options const fullUrl = url.startsWith('http') ? url : `${API_BASE_URL}${url}` const config = { method, headers: { - 'Content-Type': 'application/json', ...COMMON_HEADERS, - ...headers + ...headers, }, - ...otherOptions + ...otherOptions, } // 如果是POST、PUT等方法且有数据,添加body if (data && ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase())) { - config.body = JSON.stringify(data) + if (data instanceof FormData) { + // FormData类型:由浏览器自动设置Content-Type + config.body = data + // 删除手动设置的Content-Type(重要!) + if (config.headers['Content-Type']) { + delete config.headers['Content-Type'] + } + } else { + // 非FormData:按JSON处理 + config.body = JSON.stringify(data) + config.headers['Content-Type'] = 'application/json' + } } try { - const response = await fetch(fullUrl, config) if (!response.ok) { // 尝试解析响应体获取更多错误信息 - let errorData = await response.json() + let errorData = await response.json() throw new ApiError(`HTTP Error: ${response.status} ${response.statusText}`, { type: 'http', @@ -149,7 +152,7 @@ export async function request(url, options = {}) { errorCode: errorData.errorCode, errorCodeName: errorData.errorCodeName, errorMsg: errorData.errorMsg, - time: errorData.time + time: errorData.time, }) } @@ -180,7 +183,7 @@ export async function request(url, options = {}) { throw new ApiError(error.message || 'Network or unknown error', { type: 'network', originalError: error, - code: 'NETWORK_ERROR' + code: 'NETWORK_ERROR', }) } diff --git a/src/views/Activities/Lottery/Lottery.vue b/src/views/Activities/Lottery/Lottery.vue index f40a128..eb90239 100644 --- a/src/views/Activities/Lottery/Lottery.vue +++ b/src/views/Activities/Lottery/Lottery.vue @@ -1399,15 +1399,19 @@ const getWinners = async () => { } } -//获取中奖记录 +//获取领取任务奖励 const receiveTaskReward = async (code) => { let data = { taskCode: code, } - const resReceive = await receiveTickets(data) - if (resReceive.status && resReceive.body) { - getTaskList() //获取任务列表 - getTickets() //获取拥有的抽奖券 + try { + const resReceive = await receiveTickets(data) + if (resReceive.status && resReceive.body) { + getTaskList() //获取任务列表 + getTickets() //获取拥有的抽奖券 + } + } catch (error) { + showError(error.errorMsg) } } diff --git a/src/views/Wallet/CashOut/CashOut.vue b/src/views/Wallet/CashOut/CashOut.vue index c9d6734..1861644 100644 --- a/src/views/Wallet/CashOut/CashOut.vue +++ b/src/views/Wallet/CashOut/CashOut.vue @@ -70,7 +70,9 @@
- Passport/ID card:(3/3) + Passport/ID card:({{ bankCardInfo.cardImages.length }}/3)
-
-
-
+
Contact number:
- 123-456-789-1234 + {{ bankCardInfo.contactNumber }}
Other description:
- asdfasdfasdfasdf asfasfsaasdasdfasdfasdfa sfasfasfasfasfsdasdfasdfasf asdfafdsa asdf - asdasddsasdsadads + {{ bankCardInfo.description }}
@@ -192,7 +190,9 @@ import GeneralHeader from '@/components/GeneralHeader.vue' import maskLayer from '@/components/MaskLayer.vue' import { withdrawableAmount, //获取可提现金额 + withdrawApply, //提交提现申请 } from '@/api/lottery' +import { setApplyInfo, getApplyInfo } from '@/utils/applyStore.js' import { ref, onMounted, computed } from 'vue' import { useRouter } from 'vue-router' const router = useRouter() @@ -200,9 +200,7 @@ const router = useRouter() const maskLayerShow = ref(false) const currentAmount = ref(0) //可提现金额 -const bankCardInfo = ref({ - // id: '', -}) +const bankCardInfo = ref({}) const hasBankCard = computed(() => { return Object.keys(bankCardInfo.value).length > 0 }) @@ -220,6 +218,15 @@ const gotoKYC = () => { // 提现按钮 const CashOut = () => { if (hasBankCard.value) { + try { + const resApply = withdrawApply(getApplyInfo()) + if (resApply.status) { + setApplyInfo() + router.go(-1) + } + } catch (error) { + showError(error.errorMsg) + } } else { maskLayerShow.value = true } @@ -242,6 +249,8 @@ const getDrawableAmount = async () => { onMounted(() => { getDrawableAmount() //获取可提现金额 + bankCardInfo.value = + { ...getApplyInfo(), cardImages: JSON.parse(getApplyInfo().cardImages) } || {} }) diff --git a/src/views/Wallet/CashOut/KYC.vue b/src/views/Wallet/CashOut/KYC.vue index 52de529..67d1c5a 100644 --- a/src/views/Wallet/CashOut/KYC.vue +++ b/src/views/Wallet/CashOut/KYC.vue @@ -61,19 +61,27 @@
Passport/lD card:
- +
+ + +
+ -
+
@@ -89,6 +97,7 @@ aspect-ratio: 1/1; object-fit: cover; " + @click="handleCancel(index)" />
@@ -119,11 +128,10 @@