feat:部分 utils、store、hooks 里的 uni.showToast 替换成 wd-toast
This commit is contained in:
@@ -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)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user