|
@@ -74,6 +74,7 @@ import FlexCol from '../layout/FlexCol.vue';
|
|
|
import type { UploaderAction, UploaderItem } from './Uploader';
|
|
import type { UploaderAction, UploaderItem } from './Uploader';
|
|
|
import { LogUtils } from '@imengyu/imengyu-utils';
|
|
import { LogUtils } from '@imengyu/imengyu-utils';
|
|
|
import Text from '../basic/Text.vue';
|
|
import Text from '../basic/Text.vue';
|
|
|
|
|
+import { actionSheet } from '../dialog/CommonRoot';
|
|
|
|
|
|
|
|
const themeContext = useTheme();
|
|
const themeContext = useTheme();
|
|
|
const TAG = 'Uploader';
|
|
const TAG = 'Uploader';
|
|
@@ -168,7 +169,13 @@ export interface UploaderProps {
|
|
|
* * video:视频
|
|
* * video:视频
|
|
|
* @default 'image'
|
|
* @default 'image'
|
|
|
*/
|
|
*/
|
|
|
- chooseType?: 'image'|'video'|'file';
|
|
|
|
|
|
|
+ chooseType?: 'image'|'video'|'file'|'';
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 是否是从消息中选择文件
|
|
|
|
|
+ * @default true
|
|
|
|
|
+ */
|
|
|
|
|
+ formMessage?: boolean;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 上传处理。不提供则无法上传
|
|
* 上传处理。不提供则无法上传
|
|
|
* @required true
|
|
* @required true
|
|
@@ -274,6 +281,7 @@ const props = withDefaults(defineProps<UploaderProps>(), {
|
|
|
showUpload: true,
|
|
showUpload: true,
|
|
|
uploadWhenAdded: true,
|
|
uploadWhenAdded: true,
|
|
|
autoUpdateUploadList: true,
|
|
autoUpdateUploadList: true,
|
|
|
|
|
+ formMessage: true,
|
|
|
uploadQueueMode: 'all',
|
|
uploadQueueMode: 'all',
|
|
|
listType: 'grid',
|
|
listType: 'grid',
|
|
|
chooseType: 'image',
|
|
chooseType: 'image',
|
|
@@ -318,25 +326,65 @@ function onUploadPress() {
|
|
|
} as UploaderItem
|
|
} as UploaderItem
|
|
|
}))
|
|
}))
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- switch (props.chooseType) {
|
|
|
|
|
- case 'video':
|
|
|
|
|
- uni.chooseVideo().then((res) => handleFiles([
|
|
|
|
|
|
|
+ //#ifdef MP
|
|
|
|
|
+ if (props.formMessage) {
|
|
|
|
|
+ actionSheet({
|
|
|
|
|
+ title: '选择上传方式',
|
|
|
|
|
+ actions: [
|
|
|
{
|
|
{
|
|
|
- path: res.tempFilePath,
|
|
|
|
|
- size: res.size,
|
|
|
|
|
- }
|
|
|
|
|
- ])).catch(reject);
|
|
|
|
|
- break;
|
|
|
|
|
- case 'file':
|
|
|
|
|
- uni.chooseFile().then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
|
|
- break;
|
|
|
|
|
- default:
|
|
|
|
|
- case 'image':
|
|
|
|
|
- uni.chooseImage({
|
|
|
|
|
- count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
|
|
- }).then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ name: '从相册选择',
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ name: '从微信聊天中选择',
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ onSelect(index, name) {
|
|
|
|
|
+ },
|
|
|
|
|
+ }).then((index) => {
|
|
|
|
|
+ if (index === 0) {
|
|
|
|
|
+ chooseLocal();
|
|
|
|
|
+ } else if (index === 1) {
|
|
|
|
|
+ uni.chooseMessageFile({
|
|
|
|
|
+ type: props.chooseType || 'all',
|
|
|
|
|
+ count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
|
|
+ success: (res) => {
|
|
|
|
|
+ handleFiles(res.tempFiles as { path: string; size: number; }[])
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (e) => {
|
|
|
|
|
+ reject(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ chooseLocal();
|
|
|
|
|
+ }
|
|
|
|
|
+ //#endif
|
|
|
|
|
+ //#ifndef MP
|
|
|
|
|
+ chooseLocal();
|
|
|
|
|
+ ///#endif
|
|
|
|
|
+
|
|
|
|
|
+ function chooseLocal() {
|
|
|
|
|
+ switch (props.chooseType) {
|
|
|
|
|
+ case 'video':
|
|
|
|
|
+ uni.chooseVideo().then((res) => handleFiles([
|
|
|
|
|
+ {
|
|
|
|
|
+ path: res.tempFilePath,
|
|
|
|
|
+ size: res.size,
|
|
|
|
|
+ }
|
|
|
|
|
+ ])).catch(reject);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 'file':
|
|
|
|
|
+ uni.chooseFile().then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ case 'image':
|
|
|
|
|
+ uni.chooseImage({
|
|
|
|
|
+ count: props.maxUploadCount - currentUpladList.value.length,
|
|
|
|
|
+ }).then((res) => handleFiles(res.tempFiles as { path: string; size: number; }[])).catch(reject);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|