|
|
@@ -75,7 +75,7 @@
|
|
|
<script setup lang="ts">
|
|
|
import { computed, reactive, ref } from 'vue';
|
|
|
import { propGetThemeVar, useTheme, type TextStyle, type ViewStyle } from '../theme/ThemeDefine';
|
|
|
-import { Debounce, LogUtils } from '@imengyu/imengyu-utils';
|
|
|
+import { Debounce, LogUtils, StringUtils } from '@imengyu/imengyu-utils';
|
|
|
import { actionSheet } from '../dialog/CommonRoot';
|
|
|
import type { ToastInstance } from '../feedback/Toast.vue';
|
|
|
import type { UploaderAction, UploaderItem } from './Uploader';
|
|
|
@@ -330,6 +330,7 @@ function getUploadItemDisplayKind(item: UploaderItem): UploadDisplayKind {
|
|
|
|
|
|
function makeUploadTitleItem(label: string): UploaderItem {
|
|
|
return {
|
|
|
+ name: label,
|
|
|
filePath: label,
|
|
|
isTitle: true,
|
|
|
state: 'success',
|
|
|
@@ -381,6 +382,7 @@ function onUploadPress() {
|
|
|
function handleFiles(res: {
|
|
|
path: string;
|
|
|
size: number;
|
|
|
+ name: string;
|
|
|
}[]) {
|
|
|
resolve(res.map((item) => {
|
|
|
let isImage = typeof (item as any).type === 'string' ? (item as any).type.startsWith('image/') : false;
|
|
|
@@ -388,6 +390,7 @@ function onUploadPress() {
|
|
|
isImage = isImagePath(item.path);
|
|
|
}
|
|
|
return {
|
|
|
+ name: item.name,
|
|
|
filePath: item.path,
|
|
|
previewPath: item.path,
|
|
|
size: item.size,
|
|
|
@@ -420,11 +423,11 @@ function onUploadPress() {
|
|
|
chooseLocal();
|
|
|
} else if (index === 1) {
|
|
|
uni.chooseMessageFile({
|
|
|
- type: props.chooseType || 'all',
|
|
|
+ type: props.chooseType === 'file' ? 'all' :(props.chooseType || 'all'),
|
|
|
count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
success: (res) => {
|
|
|
LogUtils.printLog(TAG, 'info', 'chooseMessageFile', res);
|
|
|
- handleFiles(res.tempFiles as { path: string; size: number; }[])
|
|
|
+ handleFiles(res.tempFiles as { path: string; name: string; size: number; }[])
|
|
|
},
|
|
|
fail: (e) => {
|
|
|
LogUtils.printLog(TAG, 'error', 'chooseMessageFile', e);
|
|
|
@@ -447,18 +450,29 @@ function onUploadPress() {
|
|
|
uni.chooseVideo().then((res) => handleFiles([
|
|
|
{
|
|
|
path: res.tempFilePath,
|
|
|
+ name: res.name || StringUtils.path.getFileName(res.tempFilePath) || '',
|
|
|
size: res.size,
|
|
|
}
|
|
|
])).catch(reject);
|
|
|
break;
|
|
|
+ //#ifdef H5
|
|
|
case 'file':
|
|
|
- uni.chooseFile().then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
+ uni.chooseFile().then((res) => handleFiles((res.tempFiles as any []).map((item) => ({
|
|
|
+ path: item.path,
|
|
|
+ name: item.name || StringUtils.path.getFileName(item.path) || '',
|
|
|
+ size: item.size,
|
|
|
+ })))).catch(reject);
|
|
|
break;
|
|
|
+ //#endif
|
|
|
default:
|
|
|
case 'image':
|
|
|
uni.chooseImage({
|
|
|
count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
- }).then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
+ }).then((res) => handleFiles((res.tempFiles as any[]).map((item) => ({
|
|
|
+ path: item.path,
|
|
|
+ name: item.name || StringUtils.path.getFileName(item.path) || '',
|
|
|
+ size: item.size,
|
|
|
+ })))).catch(reject);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -562,6 +576,16 @@ function deleteListItem(item: UploaderItem) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+function formatError(error: unknown) {
|
|
|
+ if (error instanceof Error)
|
|
|
+ return error.message;
|
|
|
+ if (typeof error === 'string')
|
|
|
+ return error;
|
|
|
+ if (typeof error === 'object')
|
|
|
+ return JSON.stringify(error);
|
|
|
+ return '' + error;
|
|
|
+}
|
|
|
+
|
|
|
//开始上传条目
|
|
|
function startUploadItem(item: UploaderItem) {
|
|
|
if (item.state === 'uploading')
|
|
|
@@ -584,7 +608,7 @@ function startUploadItem(item: UploaderItem) {
|
|
|
item,
|
|
|
onError(error) {
|
|
|
item.state = 'fail';
|
|
|
- item.message = ('' + error) || '上传失败';
|
|
|
+ item.message = formatError(error) || '上传失败';
|
|
|
updateListItem(item);
|
|
|
reject(error);
|
|
|
LogUtils.printLog(TAG, 'error', `上传文件 ${item.filePath} 失败,错误信息:${error}`);
|