feat:部分 utils、store、hooks 里的 uni.showToast 替换成 wd-toast
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
|
||||
import { isH5, isMpWeixin } from '@uni-helper/uni-env'
|
||||
import { useToast } from 'wot-design-uni'
|
||||
|
||||
const toast = useToast()
|
||||
|
||||
/** 保存图片到相册 */
|
||||
export async function saveImageToAlbum(url: string, fileName?: string): Promise<void> {
|
||||
@@ -20,12 +23,16 @@ export async function saveImageToAlbum(url: string, fileName?: string): Promise<
|
||||
if (downloadResult.statusCode === 200) {
|
||||
saveToAlbum(downloadResult.tempFilePath, resolve, reject)
|
||||
} else {
|
||||
uni.showToast({ icon: 'none', title: '下载失败' })
|
||||
// 注释 by 芋艿:使用 wd-toast 替代
|
||||
// uni.showToast({ icon: 'none', title: '下载失败' })
|
||||
toast.show('下载失败')
|
||||
reject(new Error('Download failed'))
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.showToast({ icon: 'none', title: '下载失败' })
|
||||
// 注释 by 芋艿:使用 wd-toast 替代
|
||||
// uni.showToast({ icon: 'none', title: '下载失败' })
|
||||
toast.show('下载失败')
|
||||
reject(err)
|
||||
},
|
||||
})
|
||||
@@ -45,10 +52,11 @@ function saveToAlbum(
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath,
|
||||
success: () => {
|
||||
uni.showToast({
|
||||
icon: 'success',
|
||||
title: '已保存到相册',
|
||||
})
|
||||
// uni.showToast({
|
||||
// icon: 'success',
|
||||
// title: '已保存到相册',
|
||||
// })
|
||||
toast.success('已保存到相册')
|
||||
resolve()
|
||||
},
|
||||
fail: (err) => {
|
||||
@@ -64,23 +72,22 @@ function saveToAlbum(
|
||||
if (settingRes.authSetting['scope.writePhotosAlbum']) {
|
||||
// 重新尝试保存
|
||||
saveToAlbum(filePath, resolve, reject)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
reject(new Error('User denied'))
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
reject(new Error('User cancelled'))
|
||||
}
|
||||
},
|
||||
})
|
||||
} else {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: '保存失败',
|
||||
})
|
||||
// uni.showToast({
|
||||
// icon: 'none',
|
||||
// title: '保存失败',
|
||||
// })
|
||||
toast.show('保存失败')
|
||||
reject(err)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* 通过环境变量 VITE_UPLOAD_TYPE 配置
|
||||
*/
|
||||
|
||||
import { useToast } from 'wot-design-uni'
|
||||
import * as FileApi from '@/api/infra/file'
|
||||
|
||||
/** 上传类型 */
|
||||
@@ -163,6 +164,7 @@ export function useUpload<T = string>(url: string, formData: Record<string, any>
|
||||
const data = ref<T>()
|
||||
/** 上传进度(0-100) */
|
||||
const progress = ref(0)
|
||||
const toast = useToast()
|
||||
|
||||
/** 解构上传选项,设置默认值 */
|
||||
const {
|
||||
@@ -192,10 +194,12 @@ export function useUpload<T = string>(url: string, formData: Record<string, any>
|
||||
const checkFileSize = (size: number) => {
|
||||
const sizeInMB = size / 1024 / 1024
|
||||
if (sizeInMB > maxSize) {
|
||||
uni.showToast({
|
||||
title: `文件大小不能超过${maxSize}MB`,
|
||||
icon: 'none',
|
||||
})
|
||||
// 注释 by 芋艿:使用 wd-toast 替代
|
||||
// uni.showToast({
|
||||
// title: `文件大小不能超过${maxSize}MB`,
|
||||
// icon: 'none',
|
||||
// })
|
||||
toast.show(`文件大小不能超过${maxSize}MB`)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user