|
@@ -1,4 +1,5 @@
|
|
|
import { ref } from 'vue'
|
|
import { ref } from 'vue'
|
|
|
|
|
+import { useToast } from 'wot-design-uni'
|
|
|
import { getEnvBaseUrl } from '@/utils/index'
|
|
import { getEnvBaseUrl } from '@/utils/index'
|
|
|
|
|
|
|
|
const VITE_UPLOAD_BASEURL = `${getEnvBaseUrl()}/upload`
|
|
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 loading = ref(false)
|
|
|
const error = ref<Error | null>(null)
|
|
const error = ref<Error | null>(null)
|
|
|
const data = ref<any>(null)
|
|
const data = ref<any>(null)
|
|
|
|
|
+ const toast = useToast()
|
|
|
|
|
|
|
|
const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
|
|
const handleFileChoose = ({ tempFilePath, size }: { tempFilePath: string, size: number }) => {
|
|
|
if (size > maxSize) {
|
|
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
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -62,8 +66,7 @@ export default function useUpload<T extends TfileType>(options: TOptions<T> = {}
|
|
|
const jsonData = JSON.parse(res)
|
|
const jsonData = JSON.parse(res)
|
|
|
// 检查是否包含data字段
|
|
// 检查是否包含data字段
|
|
|
parsedData = jsonData.data || jsonData
|
|
parsedData = jsonData.data || jsonData
|
|
|
- }
|
|
|
|
|
- catch (e) {
|
|
|
|
|
|
|
+ } catch (e) {
|
|
|
// 如果解析失败,使用原始数据
|
|
// 如果解析失败,使用原始数据
|
|
|
console.log('Response is not JSON, using raw data:', res)
|
|
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
|
|
// #ifndef MP-WEIXIN
|
|
|
uni.chooseImage(chooseFileOptions)
|
|
uni.chooseImage(chooseFileOptions)
|
|
|
// #endif
|
|
// #endif
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
|
|
+ } else {
|
|
|
uni.chooseFile({
|
|
uni.chooseFile({
|
|
|
...chooseFileOptions,
|
|
...chooseFileOptions,
|
|
|
type: 'all',
|
|
type: 'all',
|
|
@@ -157,8 +159,7 @@ async function uploadFile({
|
|
|
try {
|
|
try {
|
|
|
const data = uploadFileRes.data
|
|
const data = uploadFileRes.data
|
|
|
onSuccess(data)
|
|
onSuccess(data)
|
|
|
- }
|
|
|
|
|
- catch (err) {
|
|
|
|
|
|
|
+ } catch (err) {
|
|
|
onError(err)
|
|
onError(err)
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|