lex 1 年之前
父节点
当前提交
96531913f7

+ 16 - 8
src/helpers/oss-file-upload.ts

@@ -2,9 +2,9 @@ import request from '@/utils/request';
 import axios from 'axios';
 const ossSwitch = 'ks3' as 'ks3' | 'tencent'; // 上传文件服务商
 /**
- * 班级管理 - 班级列表
+ * 获取上传文件签名
  */
-export const classGroupList = (params: any) => {
+export const getSign = (params: any) => {
   return request.post('/edu-app/open/getUploadSign', {
     data: params
   });
@@ -13,12 +13,20 @@ export const classGroupList = (params: any) => {
 /**
  * 获取上传文件签名
  * @param params 上传对应参数
+ * { filename: fileName,
+          bucketName: props.bucketName,
+          postData: {
+            filename: fileName,
+            acl: 'public-read',
+            key: fileName,
+            unknowValueField: []
+          }}
  * @param oss 服务商 ks3 tencent
  */
-export const getUploadSign = (params: any, oss?: string) => {
-  throw new Error('获取失败');
-  // try {
-  // } catch (e: any) {
-  //   throw new Error(e.message || '获取失败');
-  // }
+export const getUploadSign = async (params: any, oss?: string) => {
+  try {
+    const { data } = await getSign({ params });
+  } catch (e: any) {
+    throw new Error(e.message || '获取失败');
+  }
 };

+ 3 - 0
src/views/natural-resources/components/my-resources/save-modal/index.tsx

@@ -13,6 +13,7 @@ import { NaturalTypeEnum, PageEnum } from '/src/enums/pageEnum';
 import { policy } from '/src/components/upload-file/api';
 import { formatUrlType } from '../upload-modal';
 import axios from 'axios';
+import { getUploadSign } from '/src/helpers/oss-file-upload';
 
 export default defineComponent({
   name: 'save-modal',
@@ -93,6 +94,7 @@ export default defineComponent({
         : 'other';
 
       console.log(type, 'type');
+
       if (type === 'other') {
         message.error(`文件格式不支持`);
         return false;
@@ -128,6 +130,7 @@ export default defineComponent({
       // }
 
       try {
+        await getUploadSign({ name: 'upload' });
         btnLoading.value = true;
         const name = file.file.name;
         const suffix = name.slice(name.lastIndexOf('.'));