feat:部分 utils、store、hooks 里的 uni.showToast 替换成 wd-toast

This commit is contained in:
YunaiV
2025-12-15 23:06:07 +08:00
parent b9cbcd5b45
commit f9fc5a8abe
5 changed files with 63 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
import { ref } from 'vue'
import { useToast } from 'wot-design-uni'
import { getEnvBaseUrl } from '@/utils/index'
const VITE_UPLOAD_BASEURL = `${getEnvBaseUrl()}/upload`
@@ -29,13 +30,16 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
const loading = ref(false)
const error = ref<Error | null>(null)
const data = ref<any>(null)
const toast = useToast()
const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
if (size > maxSize) {
uni.showToast({
title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`,
icon: 'none',
})
// 注释 by 芋艿:使用 wd-toast 替代
// uni.showToast({
// title: `文件大小不能超过 ${maxSize / 1024 / 1024}MB`,
// icon: 'none',
// })
toast.show(`文件大小不能超过 ${maxSize / 1024 / 1024}MB`)
return
}
@@ -62,8 +66,7 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
const jsonData = JSON.parse(res)
// 检查是否包含data字段
parsedData = jsonData.data || jsonData
}
catch (e) {
} catch (e) {
// 如果解析失败,使用原始数据
console.log('Response is not JSON, using raw data:', res)
}
@@ -123,8 +126,7 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
// #ifndef MP-WEIXIN
uni.chooseImage(chooseFileOptions)
// #endif
}
else {
} else {
uni.chooseFile({
...chooseFileOptions,
type: 'all',
@@ -157,8 +159,7 @@ async function uploadFile({
try {
const data = uploadFileRes.data
onSuccess(data)
}
catch (err) {
} catch (err) {
onError(err)
}
},