浏览代码

更换oss上传

lex 1 年之前
父节点
当前提交
b69f16a565

+ 2 - 1
package.json

@@ -21,13 +21,13 @@
     "@rongcloud/imlib-next": "^5.4.3",
     "@shopify/draggable": "^1.0.0-beta.8",
     "@vant/touch-emulator": "^1.4.0",
-    "JSONPath": "^0.11.2",
     "axios": "0.18.1",
     "browserslist": "^4.18.1",
     "caniuse-lite": "^1.0.30001286",
     "clean-deep": "^3.3.0",
     "clipboard": "^2.0.10",
     "copy-to-clipboard": "^3.3.1",
+    "cos-js-sdk-v5": "^1.4.20",
     "dayjs": "^1.8.35",
     "echarts": "^4.8.0",
     "element-ui": "^2.13.2",
@@ -36,6 +36,7 @@
     "i": "^0.3.6",
     "js-base64": "^3.6.0",
     "js-cookie": "2.2.0",
+    "JSONPath": "^0.11.2",
     "linq": "^3.2.2",
     "lodash": "^4.17.20",
     "mammoth": "^1.4.19",

+ 106 - 32
src/components/Editor/index.vue

@@ -10,18 +10,19 @@
       @change="onEditorChange($event)"
     ></quill-editor>
 
+    <!-- :on-success="handleSuccess" -->
     <el-upload
       ref="ivuUpload"
       class="ivu-upload"
       style="height: 1px"
       :show-file-list="false"
-      :on-success="handleSuccess"
       accept=".jpg, .jpeg, .png"
       :before-upload="beforeImgUpload"
       :max-size="2048"
       multiple
       :action="ossUploadUrl"
       :data="dataObj"
+      :http-request="handleChangeImg"
     >
       <p></p>
     </el-upload>
@@ -34,17 +35,17 @@
     >
       <el-form :model="dialogForm" ref="diologForm" :rules="dialogFormRules">
         <el-form-item label="封面图地址" label-width="90px">
-          <!--        v-loading="uploadImgLoading" -->
+          <!--        v-loading="uploadImgLoading" :on-success="handleImgSuccess" -->
           <el-upload
             class="avatar-uploader"
             style="line-height: 0; display: inline-block"
             :show-file-list="false"
             accept=".jpg, .jpeg, .png"
-            :on-success="handleImgSuccess"
             :on-error="handleUploadImgError"
             :before-upload="beforeImgUpload"
             :action="ossUploadUrl"
             :data="dataObj"
+            :http-request="handleImgChange"
           >
             <img
               width="300px"
@@ -79,12 +80,12 @@
           label-width="90px"
           prop="videoUrl"
         >
+          <!-- :on-success="handleUploadSuccess" -->
           <el-upload
             class="upload-demo"
             style="display: inline-block"
             v-loading="uploadLoading"
             :before-upload="beforeUpload"
-            :on-success="handleUploadSuccess"
             :on-error="handleUploadError"
             :show-file-list="false"
             accept=".mp4"
@@ -92,6 +93,7 @@
             :on-exceed="handleExceed"
             :action="ossUploadUrl"
             :data="dataObj"
+            :http-request="handleSuccessChange"
           >
             <video
               style="width: 120px; height: 120px"
@@ -123,6 +125,7 @@ import "quill/dist/quill.bubble.css";
 import Quill from "quill";
 import { quillEditor } from "vue-quill-editor";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 // 工具栏配置
 const toolbarOptions = [
   ["bold", "italic", "underline", "strike"], // 加粗 斜体 下划线 删除线
@@ -308,26 +311,59 @@ export default {
         }
       });
     },
-    handleSuccess(res) {
-      // 获取富文本组件实例
-      let quill = this.ActiveEditor;
-      // 光标所在位置
-      // 如果上传成功
-
-      // return;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        // 获取光标所在位置
-        let length = quill.getSelection().index || 0;
-        // 插入图片,res为服务器返回的图片链接地址
-        quill.insertEmbed(length, "image", url);
-        // 调整光标到最后
-        quill.setSelection(length + 1);
-      } else {
-        // 提示信息,需引入Message
-        this.$message.error("图片插入失败");
+    async handleChangeImg(info) {
+      console.log(info, "1212");
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        // 获取富文本组件实例
+        let quill = this.ActiveEditor;
+        // 光标所在位置
+        // 如果上传成功
+        if (url) {
+          // 获取光标所在位置
+          let length = quill.getSelection().index || 0;
+          // 插入图片,res为服务器返回的图片链接地址
+          quill.insertEmbed(length, "image", url);
+          // 调整光标到最后
+          quill.setSelection(length + 1);
+        } else {
+          // 提示信息,需引入Message
+          this.$message.error("图片插入失败");
+        }
+      } catch (e) {
+        //
+        console.log(e, "e.message");
       }
     },
+    // handleSuccess(res) {
+    //   // 获取富文本组件实例
+    //   let quill = this.ActiveEditor;
+    //   // 光标所在位置
+    //   // 如果上传成功
+
+    //   // return;
+    //   let url = this.ossUploadUrl + "/" + this.dataObj.key;
+    //   if (url) {
+    //     // 获取光标所在位置
+    //     let length = quill.getSelection().index || 0;
+    //     // 插入图片,res为服务器返回的图片链接地址
+    //     quill.insertEmbed(length, "image", url);
+    //     // 调整光标到最后
+    //     quill.setSelection(length + 1);
+    //   } else {
+    //     // 提示信息,需引入Message
+    //     this.$message.error("图片插入失败");
+    //   }
+    // },
     addQuillTitle() {
       const oToolBar = document.querySelector(".ql-toolbar"),
         aButton = oToolBar.querySelectorAll("button"),
@@ -351,11 +387,29 @@ export default {
       this.uploadImgLoading = false;
       this.$message.error("上传失败");
     },
-    handleImgSuccess(res, file) {
-      this.uploadImgLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      this.dialogForm.poster = url;
+    async handleImgChange(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        this.uploadImgLoading = false;
+        this.dialogForm.poster = url;
+      } catch {
+        //
+      }
     },
+    // handleImgSuccess(res, file) {
+    //   this.uploadImgLoading = false;
+    //   let url = this.ossUploadUrl + "/" + this.dataObj.key;
+    //   this.dialogForm.poster = url;
+    // },
     async beforeImgUpload(file) {
       const imageType = {
         "image/png": true,
@@ -388,7 +442,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -449,7 +504,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -470,12 +526,30 @@ export default {
       this.uploadLoading = false;
       this.$message.error("上传视频失败");
     },
-    handleUploadSuccess(file, fileList) {
-      this.uploadLoading = false;
+    // handleUploadSuccess(file, fileList) {
+    //   this.uploadLoading = false;
 
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
+    //   let url = this.ossUploadUrl + "/" + this.dataObj.key;
 
-      this.dialogForm.videoUrl = url;
+    //   this.dialogForm.videoUrl = url;
+    // },
+    async handleSuccessChange(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        this.uploadLoading = false;
+        this.dialogForm.videoUrl = url;
+      } catch {
+        //
+      }
     },
     handleExceed(files, fileList) {
       this.$message.error("您已上传过视频");

+ 50 - 27
src/components/ImageCropper/index.vue

@@ -42,6 +42,7 @@
 import CropperModal from "./CropperModal";
 import { policy } from "@/api/appTenant";
 import axios from "axios";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 export default {
   name: "ImageCropper",
   components: {
@@ -187,51 +188,34 @@ export default {
 
     async handleCropperSuccess(data) {
       // 开始上传数据
-      let { action, headers, filename } = this.info;
+
       let fileName = this.info.file.name.replaceAll(" ", "_");
-      const formData = new FormData();
       try {
         let key = new Date().getTime() + fileName;
         let obj = {
-          filename: fileName,
+          filename: key,
           bucketName: this.bucket_name,
           postData: {
-            filename: fileName,
+            filename: key,
             acl: "public-read",
             key: key,
             unknowValueField: []
           }
         };
-        const res = await policy(obj);
-        this.dataObj = {
+
+        const res = await getUploadSign(obj);
+        const objInfo = {
           policy: res.data.policy,
           signature: res.data.signature,
           key: key,
           KSSAccessKeyId: res.data.kssAccessKeyId,
           acl: "public-read",
-          name: fileName
+          name: key,
+          file: data
         };
-        for (let key in this.dataObj) {
-          formData.append(key, this.dataObj[key]);
-        }
-        formData.append(filename, data, fileName);
-        axios
-          .post(action, formData, {
-            ...headers
-          })
-          .then(res => {
-            let url = this.ossUploadUrl + "/" + this.dataObj.key;
-
+        await onOnlyFileUpload(this.ossUploadUrl, objInfo)
+          .then(url => {
             if (url) {
-              // filelist.value = [
-              //   {
-              //     name: url,
-              //     url: url,
-              //   },
-              // ];
-
-              // resValues.value = url;
-
               let data = {
                 data: {
                   url: url
@@ -249,8 +233,47 @@ export default {
             // console.log(e, '失败')
             this.handleCropperClose();
           });
+        // const res = await policy(obj);
+        // this.dataObj = {
+        //   policy: res.data.policy,
+        //   signature: res.data.signature,
+        //   key: key,
+        //   KSSAccessKeyId: res.data.kssAccessKeyId,
+        //   acl: "public-read",
+        //   name: fileName
+        // };
+        // for (let key in this.dataObj) {
+        //   formData.append(key, this.dataObj[key]);
+        // }
+        // formData.append(filename, data, fileName);
+        // axios
+        //   .post(action, formData, {
+        //     ...headers
+        //   })
+        //   .then(res => {
+        //     let url = this.ossUploadUrl + "/" + this.dataObj.key;
+
+        //     if (url) {
+        //       let data = {
+        //         data: {
+        //           url: url
+        //         }
+        //       };
+        //       this.loading = false;
+        //       this.$emit("crop-upload-success", data);
+        //       CropperModal.value.closeVisible();
+        //     } else {
+        //       this.handleCropperClose();
+        //       // ElMessage.error(res.msg || '上传失败')
+        //     }
+        //   })
+        //   .catch(e => {
+        //     // console.log(e, '失败')
+        //     this.handleCropperClose();
+        //   });
         //putObject
       } catch (err) {
+        console.log(err, "error");
         this.handleCropperClose();
         this.$message.error("上传失败");
       }

+ 20 - 7
src/components/Upload/index.vue

@@ -1,6 +1,6 @@
 <template>
   <div class="upload">
-    <!--       :headers="headers" -->
+    <!--       :headers="headers" :on-success="handleImgSuccess" -->
     <el-upload
       class="avatar-uploader"
       style="line-height: 0; display: inline-block"
@@ -9,7 +9,7 @@
       :show-file-list="false"
       v-loading="uploadImgLoading"
       :accept="accept"
-      :on-success="handleImgSuccess"
+      :http-request="handleImgSuccess"
       :on-error="handleUploadImgError"
       :before-upload="beforeImgUpload"
     >
@@ -23,6 +23,7 @@
 import load from "@/utils/loading";
 import { getToken } from "@/utils/auth";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 export default {
   data() {
     return {
@@ -158,7 +159,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -179,11 +181,22 @@ export default {
       this.uploadImgLoading = false;
       this.$message.error("上传失败");
     },
-    handleImgSuccess(res, file) {
+    async handleImgSuccess(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        this.imgUrl = url;
+        this.$emit("input", url);
+      } catch {}
       this.uploadImgLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      this.imgUrl = url;
-      this.$emit("input", url);
     }
   },
   watch: {

+ 64 - 27
src/components/singe-file-upload/index.vue

@@ -1,9 +1,9 @@
 <template>
-  <!-- :before-upload="beforeUpload"     :headers="headers"    action="/api-web/uploadFile"-->
+  <!-- :before-upload="beforeUpload"     :headers="headers"    action="/api-web/uploadFile" :on-success="success"-->
   <el-upload
     :action="ossUploadUrl"
     :data="dataObj"
-    :on-success="success"
+    :http-request="success"
     :on-remove="remove"
     :on-progress="progress"
     :on-error="error"
@@ -43,6 +43,7 @@ import copy from "copy-to-clipboard";
 import { getToken } from "@/utils/auth";
 import load from "@/utils/loading";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 export default {
   name: "singe-file-upload",
   props: {
@@ -122,32 +123,67 @@ export default {
     progress(file) {
       load.startLoading();
     },
-    success(res, file) {
+    async success(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.filelist = [
+            {
+              name: url,
+              url: url
+            }
+          ];
+          this.$emit("update:value", url);
+          this.$emit("input", url);
+          this.$emit("inputFile", file);
+          this.$emit("success");
+          // val.data.name
+
+          let res = {
+            data: {
+              name: this.dataObj.name
+            }
+          };
+          this.$emit("getName", res);
+        } else {
+          this.remove();
+          this.$message.error(res.msg || "上传失败");
+        }
+      } catch {}
       load.endLoading();
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        this.filelist = [
-          {
-            name: url,
-            url: url
-          }
-        ];
-        this.$emit("update:value", url);
-        this.$emit("input", url);
-        this.$emit("inputFile", file);
-        this.$emit("success");
-        // val.data.name
+      // let url = this.ossUploadUrl + "/" + this.dataObj.key;
+      // if (url) {
+      //   this.filelist = [
+      //     {
+      //       name: url,
+      //       url: url
+      //     }
+      //   ];
+      //   this.$emit("update:value", url);
+      //   this.$emit("input", url);
+      //   this.$emit("inputFile", file);
+      //   this.$emit("success");
+      //   // val.data.name
 
-        let res = {
-          data: {
-            name: this.dataObj.name
-          }
-        };
-        this.$emit("getName", res);
-      } else {
-        this.remove();
-        this.$message.error(res.msg || "上传失败");
-      }
+      //   let res = {
+      //     data: {
+      //       name: this.dataObj.name
+      //     }
+      //   };
+      //   this.$emit("getName", res);
+      // } else {
+      //   this.remove();
+      //   this.$message.error(res.msg || "上传失败");
+      // }
     },
     copyText(text) {
       if (text) {
@@ -183,7 +219,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,

+ 29 - 15
src/components/uploadImageList/index.vue

@@ -1,5 +1,5 @@
 <template>
-  <!-- :before-upload="beforeUpload"     :headers="headers"    action="/api-web/uploadFile"-->
+  <!-- :before-upload="beforeUpload"     :headers="headers"    action="/api-web/uploadFile" :on-success="successed"-->
   <div>
     <el-upload
       :action="ossUploadUrl"
@@ -9,7 +9,7 @@
       multiple
       accept=".png, .jpg, .jpeg, .gif"
       :before-upload="beforeUpload"
-      :on-success="successed"
+      :http-request="successed"
       :on-remove="handleRemove"
       :on-exceed="handError"
       :limit="max"
@@ -48,6 +48,7 @@ import copy from "copy-to-clipboard";
 import { getToken } from "@/utils/auth";
 import load from "@/utils/loading";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 export default {
   name: "uploadImageList",
   props: {
@@ -134,7 +135,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -150,19 +152,31 @@ export default {
       }
       return true;
     },
-    successed(response, file, fileList) {
+    async successed(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          console.log(url, "url");
+          this.uploaded.push({
+            url,
+            name: info.file.name.split(".").shift(),
+            clientShow: "YES"
+          });
+        } else {
+          this.$message.error("上传失败");
+        }
+      } catch {}
       this.uploading = false;
-      let url = this.ossUploadUrl + "/" + file.raw.key;
-      if (url) {
-        this.uploaded.push({
-          url,
-          name: file.name.split(".").shift(),
-          clientShow: "YES"
-        });
-      } else {
-        this.$message.error(res.data?.message || res.msg || "上传失败");
-      }
-      console.log(response, file, fileList);
+      // let url = this.ossUploadUrl + "/" + file.raw.key;
     },
     handleRemove(file, fileList) {
       console.log(file, fileList);

+ 219 - 0
src/helpers/oss-file-upload.js

@@ -0,0 +1,219 @@
+import request from "../utils/request2";
+import axios from "axios";
+// import umiRequest from "umi-request";
+import COS from "cos-js-sdk-v5";
+export const ossSwitch = "tencent"; //as 'ks3' | 'tencent'; // 上传文件服务商
+const tencentBucket = "daya-online-1303457149";
+
+/**
+ * 管乐团 gyt/
+ * 酷乐秀 klx/
+ * 课堂乐器 ktqy/
+ * 管乐迷 gym/
+ */
+
+// 定义一个cos 对象
+/**
+ * 获取上传文件签名
+ * @param params 上传对应参数
+ * { filename: fileName,
+     bucketName: props.bucketName,
+     postData: {
+      filename: fileName,
+      acl: 'public-read',
+      key: fileName,
+      unknowValueField: []
+    }}
+ * @param oss 服务商 ks3 tencent
+ * @returns ”{'signatur'':'',''kssAccessKeyI'':'',''policy': '' }“
+ */
+export const getUploadSign = async params => {
+  const { bucketName, filename, postData } = params;
+  const ossType = ossSwitch;
+  let bucket = bucketName;
+  let file = filename;
+  // const key = postData.key;
+  let tempPostData = {};
+  if (ossType === "tencent") {
+    bucket = tencentBucket;
+    file = "gym/" + filename;
+
+    tempPostData = {
+      key: "gym/" + postData.key
+    };
+  } else {
+    tempPostData = postData;
+  }
+  return request.post("/api-web/getUploadSign?pluginName=" + ossType, {
+    postData: tempPostData,
+    pluginName: ossType,
+    bucketName: bucket,
+    filename: file
+  });
+};
+
+/**
+ * 使用组件上传时,调用方法
+ * @param param0
+ */
+export const onFileUpload = ({
+  file,
+  action,
+  data,
+  onProgress,
+  onFinish,
+  onError
+}) => {
+  if (ossSwitch === "ks3") {
+    const fileParams = {
+      policy: data.policy,
+      signature: data.signature,
+      key: data.key,
+      acl: "public-read",
+      KSSAccessKeyId: data.KSSAccessKeyId,
+      name: data.name
+    };
+    const formData = new FormData();
+    for (const key in fileParams) {
+      formData.append(key, fileParams[key]);
+    }
+    formData.append("file", data.file);
+    axios
+      .post(action, formData, {
+        onUploadProgress: ({ progress }) => {
+          onProgress({ percent: Math.ceil((progress || 0) * 100) });
+        }
+      })
+      .then(() => {
+        file.url = action + data.key;
+        onFinish();
+      })
+      .catch(error => {
+        onError(error);
+      });
+  } else {
+    const cos = new COS({
+      Domain: "https://oss.dayaedu.com",
+      Protocol: "https",
+      // getAuthorization 必选参数
+      getAuthorization: async (options, callback) => {
+        callback({ Authorization: data.signature });
+      }
+    });
+    cos
+      .uploadFile({
+        Bucket: tencentBucket /* 填写自己的 bucket,必须字段 */,
+        Region: "ap-nanjing" /* 存储桶所在地域,必须字段 */,
+        Key: `gym/${data.name}`,
+        /* 存储在桶里的对象键(例如:1.jpg,a/b/test.txt,图片.jpg)支持中文,必须字段 */
+        Body: data.file.file, // 上传文件对象
+        SliceSize:
+          1024 *
+          1024 *
+          500 /* 触发分块上传的阈值,超过5MB使用分块上传,小于5MB使用简单上传。可自行设置,非必须 */,
+        onProgress: function(progressData) {
+          onProgress({ percent: Math.ceil((progressData.percent || 0) * 100) });
+        }
+      })
+      .then(res => {
+        // file.url = 'https://' + res.Location;
+        if (res.Location?.indexOf("http") >= 0) {
+          file.url = res.Location;
+        } else {
+          file.url = "https://" + res.Location;
+        }
+        onFinish();
+      })
+      .catch(() => {
+        onError();
+      });
+  }
+};
+
+export const onOnlyFileUpload = async (action, params) => {
+  if (ossSwitch === "ks3") {
+    const fileParams = {
+      policy: params.policy,
+      signature: params.signature,
+      key: params.key,
+      acl: "public-read",
+      KSSAccessKeyId: params.KSSAccessKeyId,
+      name: params.name
+    };
+    const formData = new FormData();
+    for (const key in fileParams) {
+      formData.append(key, fileParams[key]);
+    }
+    formData.append("file", params.file);
+    let file = "";
+    let errorObj = null;
+    await axios
+      .post(action, formData, {
+        // onUploadProgress: ({ progress }) => {
+        //   console.log(progress);
+        //   onProgress({ percent: Math.ceil((progress || 0) * 100) });
+        // }
+      })
+      .then(() => {
+        file = action + params.key;
+      })
+      .catch(error => {
+        // onError(error);
+        errorObj = error;
+        // throw new Error(error);
+      });
+    if (file) {
+      return file;
+    } else {
+      throw new Error(errorObj);
+    }
+  } else {
+    let file = "";
+    let errorObj = null;
+    // console.log(params, "params");
+    const cos = new COS({
+      Domain: "https://oss.dayaedu.com",
+      // getAuthorization 必选参数
+      getAuthorization: async (options, callback) => {
+        callback({ Authorization: params.signature });
+      }
+    });
+
+    await cos
+      .uploadFile({
+        Bucket: tencentBucket /* 填写自己的 bucket,必须字段 */,
+        Region: "ap-nanjing" /* 存储桶所在地域,必须字段 */,
+        Key: `gym/${params.name}`,
+        /* 存储在桶里的对象键(例如:1.jpg,a/b/test.txt,图片.jpg)支持中文,必须字段 */
+        Body: params.file, // 上传文件对象
+        SliceSize:
+          1024 *
+          1024 *
+          500 /* 触发分块上传的阈值,超过5MB使用分块上传,小于5MB使用简单上传。可自行设置,非必须 */
+        // onProgress: function (progressData) {
+        //   onProgress({ percent: Math.ceil((progressData.percent || 0) * 100) });
+        // }
+      })
+      .then(res => {
+        // file.url = 'https://' + res.Location;
+        // file = 'https://' + res.Location;
+        if (res.Location?.indexOf("http") >= 0) {
+          file = res.Location;
+        } else {
+          file = "https://" + res.Location;
+        }
+        // onFinish();
+      })
+      .catch(error => {
+        // console.log(error, 'error');
+        // onError();
+        // throw new Error(error);
+        errorObj = error;
+      });
+    if (file) {
+      return file;
+    } else {
+      throw new Error(errorObj);
+    }
+  }
+};

+ 21 - 5
src/layout/components/modal/userModal.vue

@@ -8,12 +8,13 @@
     >
       <el-form-item label="用户头像" prop="avatar">
         <div style="width: 150px !important">
+          <!-- :on-success="handleAvatarSuccess" -->
           <el-upload
             class="avatar-uploader"
             accept=".png, .jpg, .jpeg, .gif"
             :show-file-list="false"
-            :on-success="handleAvatarSuccess"
             :before-upload="beforeAvatarUpload"
+            :http-request="handleAvatarSuccess"
             :action="ossUploadUrl"
             :data="dataObj"
           >
@@ -77,6 +78,7 @@ import { simpleUpdate } from "@/api/systemManage";
 import { isvalidPhone } from "@/utils/validate";
 import { getToken } from "@/utils/auth";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 let validPhone = (rule, value, callback) => {
   if (!value) {
     callback(new Error("请输入电话号码"));
@@ -169,9 +171,22 @@ export default {
         };
       } catch (e) {}
     },
-    handleAvatarSuccess(res) {
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      this.form.avatar = url;
+    async handleAvatarSuccess(info) {
+      // let url = this.ossUploadUrl + "/" + this.dataObj.key;
+      // this.form.avatar = url;
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        this.form.avatar = url;
+      } catch {}
     },
     async beforeAvatarUpload(file) {
       const imageType = {
@@ -205,7 +220,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,

+ 1 - 1
src/views/adapayAccount/form.vue

@@ -567,7 +567,7 @@ export default {
         };
         this.files = file;
         this.form.multipartFile = file.raw;
-        console.log("🚀 ~ this.form.multipartFile:", this.form.multipartFile)
+        console.log("🚀 ~ this.form.multipartFile:", this.form.multipartFile);
         this.$refs["accountForm"].validateField("multipartFile");
       } catch (e) {
         console.log(e);

+ 1 - 1
src/views/branchPayManager/payShareList.vue

@@ -3,7 +3,7 @@
   <div class="m-container">
     <h2>
       <div class="squrt"></div>
-      合作单位分润列表
+      合作单位分润
     </h2>
     <div class="m-core">
       <save-form

+ 144 - 92
src/views/contentManager/model/livehelpModel.vue

@@ -9,7 +9,10 @@
         style="width: 100%"
       >
         <el-form-item label="标题" prop="title">
-          <el-input v-model.trim="form.title" placeholder="请输入标题"></el-input>
+          <el-input
+            v-model.trim="form.title"
+            placeholder="请输入标题"
+          ></el-input>
         </el-form-item>
         <el-form-item label="排序值">
           <el-input
@@ -54,11 +57,12 @@
             :options="editorOption"
             @change="onEditorChange($event)"
           ></quill-editor>
+          <!-- :on-success="handleSuccess" -->
 
           <el-upload
             class="ivu-upload"
             :show-upload-list="false"
-            :on-success="handleSuccess"
+            :http-request="handleSuccess"
             accept=".jpg, .jpeg, .png, .gif"
             :max-size="2048"
             multiple
@@ -94,8 +98,8 @@
             {
               required: uploadType == 2 ? true : false,
               message: '请上传封面图',
-              trigger: 'blur',
-            },
+              trigger: 'blur'
+            }
           ]"
           label-width="120px"
         >
@@ -107,11 +111,15 @@
             :show-file-list="false"
             v-loading="uploadImgLoading"
             accept=".jpg, .jpeg, .png, .gif"
-            :on-success="handleImgSuccess"
+            :http-request="handleImgSuccess"
             :on-error="handleUploadImgError"
             :before-upload="beforeImgUpload"
           >
-            <img v-if="dialogForm.poster" :src="dialogForm.poster" class="avatar" />
+            <img
+              v-if="dialogForm.poster"
+              :src="dialogForm.poster"
+              class="avatar"
+            />
             <i v-else class="el-icon-plus avatar-uploader-icon"></i>
           </el-upload>
         </el-form-item>
@@ -146,7 +154,7 @@
             :action="ossUploadUrl"
             :data="dataObj"
             :before-upload="beforeUpload"
-            :on-success="handleUploadSuccess"
+            :http-request="handleUploadSuccess"
             :on-error="handleUploadError"
             :show-file-list="false"
             accept=".mp4"
@@ -173,7 +181,9 @@
       </el-form>
       <div slot="footer" class="dialog-footer">
         <el-button @click="dialogFormVisible = false">取 消</el-button>
-        <el-button type="primary" @click="onVideoComfirm('diologForm')">确 定</el-button>
+        <el-button type="primary" @click="onVideoComfirm('diologForm')"
+          >确 定</el-button
+        >
       </div>
     </el-dialog>
 
@@ -189,7 +199,10 @@
           <p>{{ typeCheck(dataInfo.type) }}</p>
           <p>{{ dataInfo.updateTime }}</p>
         </div>
-        <div class="msgWrap quill-editor ql-editor" v-html="dataInfo.content"></div>
+        <div
+          class="msgWrap quill-editor ql-editor"
+          v-html="dataInfo.content"
+        ></div>
       </div>
     </el-dialog>
   </div>
@@ -197,6 +210,7 @@
 <script>
 import { policy } from "@/api/appTenant";
 import { newsQueryId, newsAdd, newsUpdate } from "@/api/contentManager";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 import { getToken } from "@/utils/auth";
 import { vaildStudentUrl } from "@/utils/validate";
 import "quill/dist/quill.core.css";
@@ -219,7 +233,7 @@ const toolbarOptions = [
   [{ font: [] }], // 字体种类
   [{ align: [] }], // 对齐方式
   ["clean"], // 清除文本格式
-  ["image", "video"], // 链接、图片、视频
+  ["image", "video"] // 链接、图片、视频
   // ["link", "image", "video"] // 链接、图片、视频
 ];
 // 标题
@@ -246,7 +260,7 @@ const titleConfig = {
   "ql-image": "图片",
   "ql-video": "视频",
   "ql-clean": "清除字体样式",
-  "ql-upload": "文件",
+  "ql-upload": "文件"
 };
 
 // 这里引入修改过的video模块并注册
@@ -257,7 +271,7 @@ export default {
   props: ["options", "typeList"],
   name: "contentOperation",
   components: {
-    quillEditor,
+    quillEditor
   },
   data() {
     let that = this;
@@ -279,7 +293,7 @@ export default {
         title: "",
         type: query.type,
         updateTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
-        content: null,
+        content: null
       },
       editorIndex: 0, // 光标位置
       editorOption: {
@@ -288,7 +302,7 @@ export default {
           toolbar: {
             container: toolbarOptions,
             handlers: {
-              image: function (value) {
+              image: function(value) {
                 if (value) {
                   // 调用iview图片上传
                   document.querySelector(".ivu-upload .el-upload").click();
@@ -296,7 +310,7 @@ export default {
                   this.quill.format("image", false);
                 }
               },
-              video: function (value) {
+              video: function(value) {
                 if (value) {
                   that.dialogFormVisible = true;
                   let editor = that.$refs.myQuillEditor.quill;
@@ -305,22 +319,22 @@ export default {
                 } else {
                   this.quill.format("image", false);
                 }
-              },
-            },
-          },
-        },
+              }
+            }
+          }
+        }
       },
       dialogForm: {
         poster: null,
         url: null,
-        videoUrl: null,
+        videoUrl: null
       },
       uploadLoading: false,
       uploadImgLoading: false,
       fileList: [],
       dialogFormRules: {
         url: [{ required: true, message: "请输入视频地址", trigger: "blur" }],
-        videoUrl: [{ required: true, message: "请上传视频", trigger: "blur" }],
+        videoUrl: [{ required: true, message: "请上传视频", trigger: "blur" }]
       },
       outUrlRadio: 0, // 是否使用外部连接,默认不使用
       form: {
@@ -330,7 +344,7 @@ export default {
         type: query.type,
         status: 0,
         content: null,
-        organIdList: [],
+        organIdList: []
       },
       rules: {
         title: [
@@ -339,10 +353,12 @@ export default {
             min: 2,
             max: 30,
             message: "长度在 2 到 30 个字符",
-            trigger: "blur",
-          },
+            trigger: "blur"
+          }
         ],
-        organIdList: [{ required: true, message: "请选择分部", trigger: "change" }],
+        organIdList: [
+          { required: true, message: "请选择分部", trigger: "change" }
+        ]
       },
       imageSize: null,
       dataObj: {
@@ -352,12 +368,12 @@ export default {
         KSSAccessKeyId: "",
         // dir: "",
         acl: "public-read",
-        name: "",
+        name: ""
         // bucket_name: props.bucket_name
       },
       // ossUploadUrl: "https://ks3-cn-beijing.ksyuncs.com/" + "news-info",
       ossUploadUrl: `https://gyt.ks3-cn-beijing.ksyuncs.com`,
-      bucket_name: "gyt",
+      bucket_name: "gyt"
     };
   },
   mounted() {
@@ -378,14 +394,14 @@ export default {
         5: "图片不能超过 2M;",
         6: "图片不能超过 2M;",
         7: "图片不能超过 2M;",
-        8: "1242px * 2208px; 图片不能超过 2M;",
+        8: "1242px * 2208px; 图片不能超过 2M;"
       };
       this.imageSize = tempTitle[this.form.type];
 
       this.$refs["form"].clearValidate();
     },
     onVideoComfirm(formName) {
-      this.$refs[formName].validate((valid) => {
+      this.$refs[formName].validate(valid => {
         if (valid) {
           let dialogForm = this.dialogForm;
           // 编辑器输入视频
@@ -394,7 +410,7 @@ export default {
           // 插入图片,res为服务器返回的图片链接地址
           const params = {
             poster: dialogForm.poster,
-            url: this.formRadio == 1 ? dialogForm.url : dialogForm.videoUrl,
+            url: this.formRadio == 1 ? dialogForm.url : dialogForm.videoUrl
           };
           quill.insertEmbed(this.editorIndex, "video", params);
           // 调整光标到最后
@@ -404,7 +420,7 @@ export default {
           this.dialogForm = {
             poster: null,
             url: null,
-            videoUrl: null,
+            videoUrl: null
           };
         } else {
           return false;
@@ -415,7 +431,7 @@ export default {
       this.dialogForm = {
         poster: null,
         url: null,
-        videoUrl: null,
+        videoUrl: null
       };
       this.$refs[diologForm].resetFields();
     },
@@ -423,21 +439,23 @@ export default {
       const oToolBar = document.querySelector(".ql-toolbar"),
         aButton = oToolBar.querySelectorAll("button"),
         aSelect = oToolBar.querySelectorAll("select");
-      aButton.forEach(function (item) {
+      aButton.forEach(function(item) {
         if (item.className === "ql-script") {
           item.value === "sub" ? (item.title = "下标") : (item.title = "上标");
         } else if (item.className === "ql-indent") {
-          item.value === "+1" ? (item.title = "向右缩进") : (item.title = "向左缩进");
+          item.value === "+1"
+            ? (item.title = "向右缩进")
+            : (item.title = "向左缩进");
         } else {
           item.title = titleConfig[item.classList[0]];
         }
       });
-      aSelect.forEach(function (item) {
+      aSelect.forEach(function(item) {
         item.parentNode.title = titleConfig[item.classList[0]];
       });
     },
     onSubmit(formName) {
-      this.$refs[formName].validate(async (valid) => {
+      this.$refs[formName].validate(async valid => {
         if (valid) {
           let { organIdList, linkUrl, content, ...rest } = this.form;
           if (this.outUrlRadio == 1) {
@@ -449,7 +467,7 @@ export default {
             ...rest,
             linkUrl,
             content,
-            organIdList: organIdList ? organIdList.join(",") : null,
+            organIdList: organIdList ? organIdList.join(",") : null
           };
           if (this.pageType == "create") {
             if (form.id) {
@@ -457,11 +475,11 @@ export default {
               delete form.id;
             }
             // return false
-            await newsAdd(form).then((res) => {
+            await newsAdd(form).then(res => {
               this.messageTips("添加", res);
             });
           } else if (this.pageType == "update") {
-            await newsUpdate(form).then((res) => {
+            await newsUpdate(form).then(res => {
               this.messageTips("修改", res);
             });
           }
@@ -470,7 +488,7 @@ export default {
             let isError = document.getElementsByClassName("is-error");
             isError[0].scrollIntoView({
               block: "center",
-              behavior: "smooth",
+              behavior: "smooth"
             });
           });
           return false;
@@ -486,24 +504,35 @@ export default {
         this.$message.error(res.msg);
       }
     },
-    handleSuccess(res) {
+    async handleSuccess(info) {
       // 获取富文本组件实例
-      this.uploadImgLoading = false;
-      let quill = this.editor;
-      // 如果上传成功
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        // 获取光标所在位置
-        let length = quill.getSelection().index;
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        let quill = this.editor;
+        // 如果上传成功
+        if (url) {
+          // 获取光标所在位置
+          let length = quill.getSelection().index;
 
-        // 插入图片,res为服务器返回的图片链接地址
-        quill.insertEmbed(length, "image", url);
-        // 调整光标到最后
-        quill.setSelection(length + 1);
-      } else {
-        // 提示信息,需引入Message
-        this.$message.error("图片插入失败");
-      }
+          // 插入图片,res为服务器返回的图片链接地址
+          quill.insertEmbed(length, "image", url);
+          // 调整光标到最后
+          quill.setSelection(length + 1);
+        } else {
+          // 提示信息,需引入Message
+          this.$message.error("图片插入失败");
+        }
+      } catch {}
+      this.uploadImgLoading = false;
     },
     onReSet(formName) {
       this.form = {
@@ -513,7 +542,7 @@ export default {
         type: this.type,
         status: 1,
         content: null,
-        organIdList: [],
+        organIdList: []
       };
       this.$refs[formName].resetFields();
     },
@@ -526,14 +555,14 @@ export default {
       setTimeout(() => {
         let imgNode = document.querySelectorAll(".msgWrap img");
         if (imgNode.length > 0) {
-          imgNode.forEach((item) => {
+          imgNode.forEach(item => {
             item.style.width = "100%";
           });
         }
 
         let videoNode = document.querySelectorAll(".msgWrap .ql-video");
         if (videoNode.length > 0) {
-          videoNode.forEach((item) => {
+          videoNode.forEach(item => {
             item.style.width = "100%";
             item.style.height = "195px";
           });
@@ -545,7 +574,7 @@ export default {
       if (this.pageType == "create") {
         return;
       } else {
-        await newsQueryId({ id: this.options.id }).then((res) => {
+        await newsQueryId({ id: this.options.id }).then(res => {
           if (res.code == 200) {
             let result = res.data;
             let organ = result.organIdList ? result.organIdList.split(",") : [];
@@ -562,11 +591,11 @@ export default {
               linkUrl: result.linkUrl,
               type: result.type,
               status: result.status,
-              organIdList: organ.map((item) => {
+              organIdList: organ.map(item => {
                 return +item;
               }),
               content: result.content,
-              subType: result.subType,
+              subType: result.subType
             };
             this.dataInfo.updateTime = result.updateTime;
           }
@@ -577,19 +606,30 @@ export default {
       this.uploadImgLoading = false;
       this.$message.error("上传失败");
     },
-    handleImgSuccess(res, file) {
+    async handleImgSuccess(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.dialogForm.poster = url;
+        } else {
+          this.$message.error("上传失败");
+        }
+      } catch {}
       this.uploadImgLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        this.dialogForm.poster = url;
-      } else {
-        this.$message.error("上传失败");
-      }
     },
     async beforeImgUpload(file) {
       const imageType = {
         "image/png": true,
-        "image/jpeg": true,
+        "image/jpeg": true
       };
       const isImage = imageType[file.type];
       const isLt2M = file.size / 1024 / 1024 < 2;
@@ -613,12 +653,12 @@ export default {
           postData: {
             filename: fileName,
             acl: "public-read",
-            key: key,
-            unknowValueField: [],
-          },
+            key: key
+          }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -626,7 +666,7 @@ export default {
           KSSAccessKeyId: res.data.kssAccessKeyId,
           // dir: "",
           acl: "public-read",
-          name: fileName,
+          name: fileName
           // bucket_name: props.bucket_name
         };
       } catch (e) {
@@ -641,7 +681,7 @@ export default {
         2: "热门资讯",
         4: "专项训练",
         7: "知识库",
-        19: "系统通知",
+        19: "系统通知"
       };
       return params[type] ? params[type] : "管乐迷";
     },
@@ -655,7 +695,7 @@ export default {
         6: 5,
         7: 6,
         8: 7,
-        19: 8,
+        19: 8
       };
       return tempTitle[type];
     },
@@ -683,11 +723,12 @@ export default {
             filename: fileName,
             acl: "public-read",
             key: key,
-            unknowValueField: [],
-          },
+            unknowValueField: []
+          }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -695,7 +736,7 @@ export default {
           KSSAccessKeyId: res.data.kssAccessKeyId,
           // dir: "",
           acl: "public-read",
-          name: fileName,
+          name: fileName
           // bucket_name: props.bucket_name
         };
       } catch (e) {
@@ -708,25 +749,36 @@ export default {
       this.uploadLoading = false;
       this.$message.error("上传视频失败");
     },
-    handleUploadSuccess(file, fileList) {
+    async handleUploadSuccess(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.$message.success("上传视频成功");
+          this.dialogForm.videoUrl = url;
+        } else {
+          this.$message.error("上传视频失败");
+        }
+      } catch {}
       this.uploadLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        this.$message.success("上传视频成功");
-        this.dialogForm.videoUrl = url;
-      } else {
-        this.$message.error("上传视频失败");
-      }
     },
     handleExceed(files, fileList) {
       this.$message.error("您已上传过视频");
-    },
+    }
   },
   computed: {
     editor() {
       return this.$refs.myQuillEditor.quill;
-    },
-  },
+    }
+  }
 };
 </script>
 <style lang="scss" scoped>

+ 73 - 36
src/views/contentManager/model/systemNotifyModel.vue

@@ -90,7 +90,7 @@
           <el-upload
             class="ivu-upload"
             :show-upload-list="false"
-            :on-success="handleSuccess"
+            :http-request="handleSuccess"
             accept=".jpg, .jpeg, .png, .gif"
             :max-size="2048"
             multiple
@@ -139,7 +139,7 @@
             :show-file-list="false"
             v-loading="uploadImgLoading"
             accept=".jpg, .jpeg, .png, .gif"
-            :on-success="handleImgSuccess"
+            :http-request="handleImgSuccess"
             :on-error="handleUploadImgError"
             :before-upload="beforeImgUpload"
           >
@@ -182,7 +182,7 @@
             :action="ossUploadUrl"
             :data="dataObj"
             :before-upload="beforeUpload"
-            :on-success="handleUploadSuccess"
+            :http-request="handleUploadSuccess"
             :on-error="handleUploadError"
             :show-file-list="false"
             accept=".mp4"
@@ -237,6 +237,7 @@
 </template>
 <script>
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 import { newsQueryId, newsAdd, newsUpdate } from "@/api/contentManager";
 import { getToken } from "@/utils/auth";
 import { vaildStudentUrl } from "@/utils/validate";
@@ -531,24 +532,36 @@ export default {
         this.$message.error(res.msg);
       }
     },
-    handleSuccess(res) {
+    async handleSuccess(info) {
       // 获取富文本组件实例
-      this.uploadImgLoading = false;
-      let quill = this.editor;
-      // 如果上传成功
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        // 获取光标所在位置
-        let length = quill.getSelection().index;
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        let quill = this.editor;
+        // 如果上传成功
 
-        // 插入图片,res为服务器返回的图片链接地址
-        quill.insertEmbed(length, "image", url);
-        // 调整光标到最后
-        quill.setSelection(length + 1);
-      } else {
-        // 提示信息,需引入Message
-        this.$message.error("图片插入失败");
-      }
+        if (url) {
+          // 获取光标所在位置
+          let length = quill.getSelection().index;
+
+          // 插入图片,res为服务器返回的图片链接地址
+          quill.insertEmbed(length, "image", url);
+          // 调整光标到最后
+          quill.setSelection(length + 1);
+        } else {
+          // 提示信息,需引入Message
+          this.$message.error("图片插入失败");
+        }
+      } catch {}
+      this.uploadImgLoading = false;
     },
     onReSet(formName) {
       this.form = {
@@ -621,14 +634,25 @@ export default {
       this.uploadImgLoading = false;
       this.$message.error("上传失败");
     },
-    handleImgSuccess(res, file) {
+    async handleImgSuccess(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.dialogForm.poster = url;
+        } else {
+          this.$message.error("上传失败");
+        }
+      } catch {}
       this.uploadImgLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        this.dialogForm.poster = url;
-      } else {
-        this.$message.error("上传失败");
-      }
     },
     async beforeImgUpload(file) {
       const imageType = {
@@ -662,7 +686,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -731,7 +756,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -752,15 +778,26 @@ export default {
       this.uploadLoading = false;
       this.$message.error("上传视频失败");
     },
-    handleUploadSuccess(file, fileList) {
+    async handleUploadSuccess(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.$message.success("上传视频成功");
+          this.dialogForm.videoUrl = url;
+        } else {
+          this.$message.error("上传视频失败");
+        }
+      } catch {}
       this.uploadLoading = false;
-      let url = this.ossUploadUrl + "/" + this.dataObj.key;
-      if (url) {
-        this.$message.success("上传视频成功");
-        this.dialogForm.videoUrl = url;
-      } else {
-        this.$message.error("上传视频失败");
-      }
     },
     handleExceed(files, fileList) {
       this.$message.error("您已上传过视频");

+ 26 - 14
src/views/resetTeaming/components/training-photos/upload/index.vue

@@ -27,7 +27,7 @@
         multiple
         accept=".png, .jpg, .jpeg, .gif"
         :before-upload="beforeUpload"
-        :on-success="successed"
+        :http-request="successed"
         :on-remove="handleRemove"
       >
         <el-button :loading="uploading" type="primary">上传图片</el-button>
@@ -68,6 +68,7 @@
 <script>
 import { photoAdd, photoAlbumQueryPage } from "../api";
 import { policy } from "@/api/appTenant";
+import { getUploadSign, onOnlyFileUpload } from "@/helpers/oss-file-upload";
 export default {
   props: {
     name: String,
@@ -131,7 +132,8 @@ export default {
           }
         };
 
-        const res = await policy(obj);
+        // const res = await policy(obj);
+        const res = await getUploadSign(obj);
         this.dataObj = {
           policy: res.data.policy,
           signature: res.data.signature,
@@ -147,19 +149,29 @@ export default {
       }
       return true;
     },
-    successed(response, file, fileList) {
+    async successed(info) {
+      try {
+        const obj = {
+          policy: info.data.policy,
+          signature: info.data.signature,
+          key: info.data.key,
+          KSSAccessKeyId: info.data.kssAccessKeyId,
+          acl: "public-read",
+          name: info.data.key,
+          file: info.file
+        };
+        const url = await onOnlyFileUpload(this.ossUploadUrl, obj);
+        if (url) {
+          this.uploaded.push({
+            url,
+            name: file.name.split(".").shift(),
+            clientShow: "YES"
+          });
+        } else {
+          this.$message.error("上传失败");
+        }
+      } catch {}
       this.uploading = false;
-      let url = this.ossUploadUrl + "/" + file.raw.key;
-      if (url) {
-        this.uploaded.push({
-          url,
-          name: file.name.split(".").shift(),
-          clientShow: "YES"
-        });
-      } else {
-        this.$message.error(res.data?.message || res.msg || "上传失败");
-      }
-      console.log(response, file, fileList);
     },
     handleRemove(file, fileList) {
       console.log(file, fileList);

+ 31 - 23
src/views/teachManager/modals/addRoot.vue

@@ -9,8 +9,8 @@
           {
             required: true,
             message: '请输入教材名称',
-            trigger: 'blur',
-          },
+            trigger: 'blur'
+          }
         ]"
       >
         <el-input
@@ -27,8 +27,8 @@
           {
             required: true,
             message: '请选择音源设置',
-            trigger: 'change',
-          },
+            trigger: 'change'
+          }
         ]"
       >
         <el-select
@@ -38,7 +38,10 @@
           v-model="form.soundResource"
           style="width: 100% !important"
         >
-          <el-option label="NotePerformer音源" value="NOTEPERFORMER"></el-option>
+          <el-option
+            label="NotePerformer音源"
+            value="NOTEPERFORMER"
+          ></el-option>
           <el-option label="标准音源" value="TANG"></el-option>
           <el-option label="官方音源" value="OFFICIAL"></el-option>
         </el-select>
@@ -50,8 +53,8 @@
           {
             required: level > 1 ? false : true,
             message: '请上传教材封面图',
-            trigger: 'blur',
-          },
+            trigger: 'blur'
+          }
         ]"
         label-width="120px"
       >
@@ -82,12 +85,16 @@
 <script>
 import Upload from "@/components/Upload/index";
 import ImageCropper from "@/components/ImageCropper";
-import { addsysMusicScore, getSysMusicScoreDetail, resetsysMusicScore } from "../api";
+import {
+  addsysMusicScore,
+  getSysMusicScoreDetail,
+  resetsysMusicScore
+} from "../api";
 export default {
   props: ["type", "activeRow"],
   components: {
     Upload,
-    ImageCropper,
+    ImageCropper
   },
   data() {
     return {
@@ -98,13 +105,13 @@ export default {
         name: null,
         coverImg: "",
         soundResource: null,
-        sysMusicScoreCategoriesList: [],
+        sysMusicScoreCategoriesList: []
         // delCategoriesIds: [],
       },
       index: 0,
       treeProps: {
         children: "sysMusicScoreCategoriesList",
-        label: "name",
+        label: "name"
       },
       level: 0, // 当前添加或修改第几层
       cropperOptions: {
@@ -115,8 +122,8 @@ export default {
         previewsCircle: false, //预览图是否是圆形
         full: true, // 是否输出原图比例的截图
         enlarge: 2,
-        title: "教材封面图", //模态框上显示的标题
-      },
+        title: "教材封面图" //模态框上显示的标题
+      }
     };
   },
   async mounted() {
@@ -135,13 +142,13 @@ export default {
         const res = await getSysMusicScoreDetail({ id: this.activeRow.id });
         if (this.type == "create") {
           // 添加一级分类或子级
-          this.form.organId = res.data.organId.split(",").map((item) => {
+          this.form.organId = res.data.organId.split(",").map(item => {
             return Number(item);
           });
         } else if (this.type == "update") {
           // 修改分类
           this.form.name = res.data.name;
-          this.form.organId = res.data.organId.split(",").map((item) => {
+          this.form.organId = res.data.organId.split(",").map(item => {
             return Number(item);
           });
           this.form.coverImg = res.data.coverImg;
@@ -154,10 +161,11 @@ export default {
     formatParentId(id, list, ids = []) {
       for (const item of list) {
         if (item.sysMusicScoreCategoriesList) {
-          const cIds = this.formatParentId(id, item.sysMusicScoreCategoriesList, [
-            ...ids,
-            item.id,
-          ]);
+          const cIds = this.formatParentId(
+            id,
+            item.sysMusicScoreCategoriesList,
+            [...ids, item.id]
+          );
           if (cIds.includes(id)) {
             return cIds;
           }
@@ -169,7 +177,7 @@ export default {
       return ids;
     },
     addSubmit() {
-      this.$refs.form.validate(async (flag) => {
+      this.$refs.form.validate(async flag => {
         if (flag) {
           let { organId, ...rest } = this.form;
           let parentId = 0;
@@ -181,7 +189,7 @@ export default {
           let obj = {
             ...rest,
             parentId,
-            organId: organId.join(","),
+            organId: organId.join(",")
           };
           try {
             if (this.type == "update") {
@@ -214,9 +222,9 @@ export default {
       // this.imgUrl = data.data.avatar
       this.form.coverImg = data.data.url;
       console.log(this.form.coverImg);
-    },
+    }
   },
-  computed: {},
+  computed: {}
 };
 </script>
 <style lang="scss" scoped>

+ 39 - 35
src/views/teachManager/modals/addTeach.vue

@@ -1,12 +1,7 @@
 <template>
   <div>
     <el-alert title="教材信息" :closable="false" class="alert" type="info" />
-    <el-form
-      :model="form"
-      label-width="120px"
-      class="form"
-      ref="form"
-    >
+    <el-form :model="form" label-width="120px" class="form" ref="form">
       <el-form-item
         label="教材名称"
         prop="name"
@@ -14,8 +9,8 @@
           {
             required: true,
             message: '请输入教材名称',
-            trigger: 'blur',
-          },
+            trigger: 'blur'
+          }
         ]"
       >
         <el-input v-model="form.name" style="width: 100%"></el-input>
@@ -27,13 +22,13 @@
           {
             required: true,
             message: '请选择适用分部',
-            trigger: 'change',
-          },
+            trigger: 'change'
+          }
         ]"
       >
         <select-all
           v-model.trim="form.organId"
-           style="width: 100%"
+          style="width: 100%"
           class="organSelect"
           filterable
           placeholder="请选择分部"
@@ -55,12 +50,21 @@
           {
             required: true,
             message: '请选择音源设置',
-            trigger: 'blur',
-          },
+            trigger: 'blur'
+          }
         ]"
       >
-        <el-select filterable placeholder="请选择音源设置" clearable v-model="form.soundResource" style="width: 100% !important">
-          <el-option label="NotePerformer音源" value="NOTEPERFORMER"></el-option>
+        <el-select
+          filterable
+          placeholder="请选择音源设置"
+          clearable
+          v-model="form.soundResource"
+          style="width: 100% !important"
+        >
+          <el-option
+            label="NotePerformer音源"
+            value="NOTEPERFORMER"
+          ></el-option>
           <el-option label="标准音源" value="TANG"></el-option>
           <el-option label="官方音源" value="OFFICIAL"></el-option>
         </el-select>
@@ -72,8 +76,8 @@
           {
             required: true,
             message: '请上传教材封面图',
-            trigger: 'blur',
-          },
+            trigger: 'blur'
+          }
         ]"
         label-width="120px"
       >
@@ -140,12 +144,12 @@ import Upload from "@/components/Upload/index";
 import {
   addsysMusicScore,
   getSysMusicScoreDetail,
-  resetsysMusicScore,
+  resetsysMusicScore
 } from "../api";
 export default {
   props: ["activeRow"],
   components: {
-    Upload,
+    Upload
   },
   data() {
     return {
@@ -155,13 +159,13 @@ export default {
         coverImg: "",
         soundResource: null,
         sysMusicScoreCategoriesList: [],
-        delCategoriesIds: [],
+        delCategoriesIds: []
       },
       index: 0,
       treeProps: {
         children: "sysMusicScoreCategoriesList",
-        label: "name",
-      },
+        label: "name"
+      }
     };
   },
   async mounted() {
@@ -170,7 +174,7 @@ export default {
       try {
         const res = await getSysMusicScoreDetail({ id: this.activeRow.id });
         this.form.name = res.data.name;
-        this.form.organId = res.data.organId.split(",").map((item) => {
+        this.form.organId = res.data.organId.split(",").map(item => {
           return Number(item);
         });
         this.form.coverImg = res.data.coverImg;
@@ -189,7 +193,7 @@ export default {
         for (let i = 0; i < arr.length; i++) {
           let obj = {
             ...arr[i],
-            index: arr[i].id,
+            index: arr[i].id
           };
 
           if (
@@ -213,7 +217,7 @@ export default {
         cancelButtonText: "取消",
         closeOnClickModal: false,
         inputPattern: /^.{1,30}$/,
-        inputErrorMessage: "请输入1到15个汉字或字符",
+        inputErrorMessage: "请输入1到15个汉字或字符"
       })
         .then(({ value }) => {
           this.index += 1;
@@ -221,7 +225,7 @@ export default {
           const newChild = {
             index: `xxx${this.index}`,
             name: value,
-            sysMusicScoreCategoriesList: [],
+            sysMusicScoreCategoriesList: []
           };
           if (!data.sysMusicScoreCategoriesList) {
             this.$set(data, "sysMusicScoreCategoriesList", []);
@@ -234,7 +238,7 @@ export default {
       const parent = node.parent;
       const children = parent.data.sysMusicScoreCategoriesList || parent.data;
 
-      const index = children.findIndex((d) => {
+      const index = children.findIndex(d => {
         this.form.delCategoriesIds.push(data.id);
         return d.id === data.id;
       });
@@ -248,7 +252,7 @@ export default {
         closeOnClickModal: false,
         inputValue: data.name,
         inputPattern: /^.{1,30}$/,
-        inputErrorMessage: "请输入1到15个汉字或字符",
+        inputErrorMessage: "请输入1到15个汉字或字符"
       })
         .then(({ value }) => {
           data.name = value;
@@ -262,26 +266,26 @@ export default {
         cancelButtonText: "取消",
         closeOnClickModal: false,
         inputPattern: /^.{1,30}$/,
-        inputErrorMessage: "请输入1到15个汉字或字符",
+        inputErrorMessage: "请输入1到15个汉字或字符"
       })
         .then(({ value }) => {
           this.index += 1;
           this.form.sysMusicScoreCategoriesList.push({
             index: `xxx${this.index}`,
-            name: value,
+            name: value
           });
         })
         .catch(() => {});
       // this.form.data.push({})
     },
     addSubmit() {
-      this.$refs.form.validate(async (flag) => {
+      this.$refs.form.validate(async flag => {
         if (flag) {
           let { organId, delCategoriesIds, ...rest } = this.form;
           let obj = {
             ...rest,
             organId: organId.join(","),
-            delCategoriesIds: delCategoriesIds.join(","),
+            delCategoriesIds: delCategoriesIds.join(",")
           };
           try {
             if (this.activeRow?.id) {
@@ -315,13 +319,13 @@ export default {
           flag = false;
         }
       }
-      if(draggingNode.childNodes.length > 0&&dropNode.level!=1){
+      if (draggingNode.childNodes.length > 0 && dropNode.level != 1) {
         flag = false;
       }
       return flag;
-    },
+    }
   },
-  computed: {},
+  computed: {}
 };
 </script>
 <style lang="scss" scoped>

+ 25 - 29
src/views/teachManager/teachClass.vue

@@ -17,8 +17,8 @@
           <el-input
             v-model.trim="searchForm.search"
             clearable
-              @keyup.enter.native="
-              (e) => {
+            @keyup.enter.native="
+              e => {
                 e.target.blur();
                 $refs.searchForm.save();
                 search();
@@ -93,11 +93,7 @@
             prop="musicScoreNum"
             label="曲目数量"
           ></el-table-column>
-          <el-table-column
-            align="center"
-            prop="musicScoreNum"
-            label="使用音源"
-          >
+          <el-table-column align="center" prop="musicScoreNum" label="使用音源">
             <template slot-scope="scope">
               {{ scope.row.soundResource | formatSoundReSource }}
             </template>
@@ -216,7 +212,7 @@ import addRoot from "./modals/addRoot";
 import {
   getSysMusicScoreList,
   enableSysMusicScore,
-  removeSysMusicScore,
+  removeSysMusicScore
 } from "./api";
 export default {
   components: { pagination, addRoot },
@@ -224,7 +220,7 @@ export default {
     return {
       searchForm: {
         search: null,
-        enable: null,
+        enable: null
       },
 
       tableList: [],
@@ -234,10 +230,10 @@ export default {
         limit: 10, // 限制显示条数
         page: 1, // 当前页
         total: 0, // 总条数
-        page_size: [10, 20, 40, 50], // 选择限制显示条数
+        page_size: [10, 20, 40, 50] // 选择限制显示条数
       },
       teachVisible: false,
-      activeRow: null,
+      activeRow: null
     };
   },
   //生命周期 - 创建完成(可以访问当前this实例)
@@ -245,34 +241,34 @@ export default {
   //生命周期 - 挂载完成(可以访问DOM元素)
   mounted() {
     // 获取分部
-     this.$store.dispatch("setBranchs");
+    this.$store.dispatch("setBranchs");
     this.getList();
   },
   filters: {
     formatSoundReSource(val) {
       let template = {
-        NOTEPERFORMER: 'NotePerformer音源',
-        TANG: '标准音源',
-        OFFICIAL: '官方音源'
-      }
-      return template[val]
+        NOTEPERFORMER: "NotePerformer音源",
+        TANG: "标准音源",
+        OFFICIAL: "官方音源"
+      };
+      return template[val];
     }
   },
   methods: {
     async getList() {
-      let {organId ,...rest} =  this.searchForm
+      let { organId, ...rest } = this.searchForm;
       try {
         const res = await getSysMusicScoreList({
           // organId:organId.join(','),
-         ...rest,
+          ...rest,
           parentId: 0,
           page: this.rules.page,
-          rows: this.rules.limit,
+          rows: this.rules.limit
         });
         this.rules.total = res.data.total;
         this.tableList = res.data.rows;
       } catch (e) {
-        console.log(e)
+        console.log(e);
       }
     },
     search() {
@@ -304,7 +300,7 @@ export default {
       this.$confirm(str, "提示", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
-        type: "warning",
+        type: "warning"
       })
         .then(async () => {
           try {
@@ -320,7 +316,7 @@ export default {
             console.log(e);
           }
         })
-        .catch((e) => {
+        .catch(e => {
           console.log(e);
         });
     },
@@ -328,7 +324,7 @@ export default {
       this.$confirm(`是否删除${row.name}`, "提示", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
-        type: "warning",
+        type: "warning"
       })
         .then(async () => {
           try {
@@ -339,20 +335,20 @@ export default {
             console.log(e);
           }
         })
-        .catch((e) => {
+        .catch(e => {
           console.log(e);
         });
     },
     lookMusic(row) {
       this.$router.push({
         name: "accompaniment",
-        params: { categoriesId: row.id },
+        params: { categoriesId: row.id }
       });
-    },
-  },
+    }
+  }
 };
 </script>
-<style lang='scss' scoped>
+<style lang="scss" scoped>
 .btnList {
   margin-bottom: 20px;
 }