快乐的梦鱼 1 miesiąc temu
rodzic
commit
5e40318b82

+ 6 - 4
src/components/dialog/ActionSheetRoot.vue

@@ -2,6 +2,8 @@
   <ActionSheet 
     v-bind="options"
     :show="show"
+    @close="options?.onClose"
+    @select="options?.onSelect"
   />
 </template>
 
@@ -14,7 +16,7 @@ export interface ActionSheetOptions extends Omit<ActionSheetProps, 'show'> {
   onClose?: () => void;
 }
 export interface ActionSheetRoot {
-  show(options: ActionSheetOptions): Promise<void>;
+  show(options: ActionSheetOptions): Promise<number|undefined>;
 }
 
 const show = ref(false);
@@ -28,16 +30,16 @@ defineExpose<ActionSheetRoot>({
     const onSelect = _options.onSelect;
     const onClose = _options.onClose;
 
-    return new Promise<void>((resolve) => {
+    return new Promise<number|undefined>((resolve) => {
       _options.onClose = () => {
         show.value = false;
         onClose?.();
-        resolve();
+        resolve(undefined);
       };
       _options.onSelect = (i: number, n: string) => {
         show.value = false;
         onSelect?.(i, n);
-        resolve();
+        resolve(i);
       };
       options.value = _options;
       show.value = true;

+ 67 - 19
src/components/form/Uploader.vue

@@ -74,6 +74,7 @@ import FlexCol from '../layout/FlexCol.vue';
 import type { UploaderAction, UploaderItem } from './Uploader';
 import { LogUtils } from '@imengyu/imengyu-utils';
 import Text from '../basic/Text.vue';
+import { actionSheet } from '../dialog/CommonRoot';
 
 const themeContext = useTheme();
 const TAG = 'Uploader';
@@ -168,7 +169,13 @@ export interface UploaderProps {
    * * video:视频
    * @default 'image'
    */
-  chooseType?: 'image'|'video'|'file';
+  chooseType?: 'image'|'video'|'file'|'';
+  /**
+   * 是否是从消息中选择文件
+   * @default true
+   */
+  formMessage?: boolean;
+
   /**
    * 上传处理。不提供则无法上传
    * @required true
@@ -274,6 +281,7 @@ const props = withDefaults(defineProps<UploaderProps>(), {
   showUpload: true,
   uploadWhenAdded: true,
   autoUpdateUploadList: true,
+  formMessage: true,
   uploadQueueMode: 'all',
   listType: 'grid',
   chooseType: 'image',
@@ -318,25 +326,65 @@ function onUploadPress() {
           } 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;
+        }
       }
     });
 

+ 1 - 0
src/components/form/UploaderField.vue

@@ -36,6 +36,7 @@ const props = withDefaults(defineProps<UploaderFieldProps>(), {
   showDelete: true,
   showUpload: true,
   uploadWhenAdded: true,
+  formMessage: true,
   autoUpdateUploadList: true,
 });
 

+ 2 - 0
src/pages/dig/forms/data/common.ts

@@ -153,6 +153,7 @@ export function villageCommonContent (ref: Ref<IDynamicFormRef>, options: {
             additionalProps: {
               upload: useAliOssUploadCo('xiangyuan/archives'),
               maxFileSize: 1024 * 1024 * 20,
+              chooseType: '',
               single: true,
             } as UploaderFieldProps,
             rules: [],
@@ -169,6 +170,7 @@ export function villageCommonContent (ref: Ref<IDynamicFormRef>, options: {
               upload: useAliOssUploadCo('xiangyuan/annex'),
               maxFileSize: 1024 * 1024 * 20,
               maxUploadCount: 20,
+              chooseType: '',
             } as UploaderFieldProps,
             rules: [],
             formProps: {

+ 1 - 1
src/pages/dig/forms/data/cultural.ts

@@ -170,7 +170,7 @@ export const villageInfoCulture : GroupForm = {
           defaultValue: '',
           additionalProps: {
             upload: useAliOssUploadCo('xiangyuan/cultural/video'),
-            chooseType: 'video',
+            chooseType: '',
             maxFileSize: 1024 * 1024 * 20,
             single: true,
           } as UploaderFieldProps,