feat(credit): 新增我的订单查询页面并优化文件上传功能
- 新增 credit/my-order/index 页面用于订单进度查询 - 在 app.config.ts 中注册新的订单查询页面路由 - 修改文件上传逻辑,统一使用 uploadFile 方法替代手动选择图片流程 - 重构 uploadFileByPath 函数,增强错误处理和响应解析逻辑 - 修复STS token过期判断条件,确保及时刷新临时凭证 - 实现订单列表的搜索、筛选、排序和分页加载功能 - 添加日期范围选择器和回款状态过滤功能 - 优化图片上传用户体验,与用户认证页面保持一致
This commit is contained in:
@@ -4,7 +4,7 @@ import dayjs from 'dayjs';
|
||||
import crypto from 'crypto-js';
|
||||
import {Base64} from 'js-base64';
|
||||
import {FileRecord} from "@/api/system/file/model";
|
||||
import {TenantId} from "@/config/app";
|
||||
import { TenantId } from "@/config/app";
|
||||
|
||||
export async function uploadOssByPath(filePath: string) {
|
||||
return new Promise(async (resolve) => {
|
||||
@@ -19,7 +19,7 @@ export async function uploadOssByPath(filePath: string) {
|
||||
};
|
||||
let sts = Taro.getStorageSync('sts');
|
||||
let stsExpired = Taro.getStorageSync('stsExpiredAt');
|
||||
if (!sts || (stsExpired && dayjs().isBefore(dayjs(stsExpired)))) {
|
||||
if (!sts || (stsExpired && dayjs().isAfter(dayjs(stsExpired)))) {
|
||||
// @ts-ignore
|
||||
const {data: {data: {credentials}}} = await request.get(`https://gle-server.websoft.top/api/oss/getSTSToken`)
|
||||
Taro.setStorageSync('sts', credentials)
|
||||
@@ -57,20 +57,58 @@ const computeSignature = (accessKeySecret: string, canonicalString: string): str
|
||||
* 上传阿里云OSS
|
||||
*/
|
||||
export async function uploadFileByPath(filePath: string) {
|
||||
const parseResponseToRecord = (res: any): FileRecord => {
|
||||
const statusCode = Number(res?.statusCode)
|
||||
if (Number.isFinite(statusCode) && statusCode !== 200) {
|
||||
throw new Error(`上传失败(HTTP ${statusCode})`)
|
||||
}
|
||||
|
||||
const raw = res?.data
|
||||
if (raw === null || raw === undefined || raw === '') {
|
||||
throw new Error('上传失败:响应为空')
|
||||
}
|
||||
|
||||
let data: any
|
||||
if (typeof raw === 'string') {
|
||||
const cleaned = raw.replace(/^\uFEFF/, '').trim()
|
||||
try {
|
||||
data = JSON.parse(cleaned)
|
||||
} catch (_e) {
|
||||
throw new Error('上传失败:响应格式错误')
|
||||
}
|
||||
} else {
|
||||
data = raw
|
||||
}
|
||||
|
||||
if (data?.code === 0) return data.data as FileRecord
|
||||
|
||||
const codeHint = data?.code !== undefined && data?.code !== null ? `(code=${String(data.code)})` : ''
|
||||
let msg = String(data?.message || data?.msg || data?.error || data?.errMsg || `上传失败${codeHint}`)
|
||||
try {
|
||||
msg = decodeURIComponent(escape(msg))
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
throw new Error(msg || '上传失败')
|
||||
}
|
||||
|
||||
const tenantIdInStorage = Taro.getStorageSync('TenantId')
|
||||
const tenantId =
|
||||
tenantIdInStorage && String(tenantIdInStorage) === String(TenantId)
|
||||
? tenantIdInStorage
|
||||
: TenantId
|
||||
|
||||
const header: Record<string, string> = {
|
||||
'content-type': 'application/json',
|
||||
TenantId: String(tenantId)
|
||||
}
|
||||
|
||||
return new Promise((resolve: (result: FileRecord) => void, reject) => {
|
||||
if (!filePath) {
|
||||
reject(new Error('缺少 filePath'))
|
||||
return
|
||||
}
|
||||
|
||||
const tenantId = Taro.getStorageSync('TenantId') || TenantId
|
||||
|
||||
const header: Record<string, string> = {
|
||||
'content-type': 'application/json',
|
||||
TenantId: String(tenantId)
|
||||
}
|
||||
|
||||
// 统一走同一个上传接口:既支持图片,也支持文档等文件(由后端决定白名单/大小限制)
|
||||
Taro.uploadFile({
|
||||
url: 'https://server.websoft.top/api/oss/upload',
|
||||
filePath,
|
||||
@@ -78,30 +116,14 @@ export async function uploadFileByPath(filePath: string) {
|
||||
header,
|
||||
success: (res) => {
|
||||
try {
|
||||
if ((res as any)?.statusCode && (res as any).statusCode !== 200) {
|
||||
reject(new Error(`上传失败(HTTP ${(res as any).statusCode})`))
|
||||
return
|
||||
}
|
||||
const raw = (res as any)?.data
|
||||
const data = typeof raw === 'string' ? JSON.parse(raw) : raw
|
||||
if (data.code === 0) {
|
||||
resolve(data.data)
|
||||
} else {
|
||||
let msg = String(data.message || '上传失败')
|
||||
try {
|
||||
msg = decodeURIComponent(escape(msg))
|
||||
} catch (_e) {
|
||||
// ignore
|
||||
}
|
||||
reject(new Error(msg || '上传失败'))
|
||||
}
|
||||
} catch (_error) {
|
||||
reject(new Error('解析响应数据失败'))
|
||||
resolve(parseResponseToRecord(res))
|
||||
} catch (e) {
|
||||
reject(e)
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('上传请求失败', err);
|
||||
reject(new Error('上传请求失败'))
|
||||
const msg = String((err as any)?.errMsg || (err as any)?.message || '上传请求失败')
|
||||
reject(new Error(msg))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user