Explorar o código

ETA_1.1.8暂存

hbchen hai 1 ano
pai
achega
c6e915dd24

+ 4 - 0
build/webpack.base.conf.js

@@ -17,6 +17,10 @@ module.exports = {
     // app: './src/main.js',
     app: ['babel-polyfill', './src/main.js']
   },
+  // 防止有依赖关联到fs而报错,浏览器不让用 fs
+  node: {
+    fs: "empty"
+  },
   output: {
     path:process.env.NODE_ENV === 'production'? config.build.assetsRoot:config.test.assetsRoot,
     filename: '[name].js',

+ 1 - 0
package.json

@@ -38,6 +38,7 @@
     "js-md5": "^0.7.3",
     "less-loader": "^4.1.0",
     "lodash": "^4.17.21",
+    "minio": "^7.0.18",
     "pptxgenjs": "^3.10.0",
     "qrcode": "^1.4.4",
     "sortablejs": "^1.15.0",

+ 182 - 0
src/utils/common.js

@@ -2,6 +2,11 @@
 // import  getNetworkType from './getNetworkType';
 // import  getSystemInfo from './getSystemInfo';
 
+import {Message} from "element-ui"
+import{getOSSSign} from "@/api/api.js"
+const Minio = require('minio')
+const stream = require('stream')
+
 // 根据字节流下载文件
 /**
  * @param {Blob} data 流数据
@@ -45,4 +50,181 @@ export function getUrlParams(str=window.location.href,key) {
 	str.split('?')[1].split('&').map(i => obj[(i.split('=')[0])] = i.split('=')[1]);
 
   return obj[key]
+}
+
+/**
+ * 
+ * @param {*} objectStorageClient 1-走oss 2-走minio
+ * @param {*} file 上传文件
+ * @param {*} temName 文件路径/文件名字
+ * @param {*} options 文件路径/文件名字
+ * @param {*} options.OSS 上传至阿里云的配置
+ * @param {*} options.MINIO 上传至MINIO的配置
+ */
+
+// 上传文件 直接走对象存取服务器
+export function uploadFileDirect(objectStorageClient,file,temName,options={}){
+  const objectStorageType= (objectStorageClient || JSON.parse(localStorage.getItem('dynamicOutLinks')).ObjectStorageClient)+""
+  console.log(objectStorageType,'objectStorageType');
+  return 
+  if(!objectStorageType){
+    Message.error("ObjectStorageClient参数丢失")
+    return new Promise((resolve,reject) => reject("ObjectStorageClient参数丢失"))
+  }
+  if(!file){
+    Message.error("file参数错误")
+    return new Promise((resolve,reject) => reject("file参数错误"))
+  }
+  if(!temName){
+    Message.error("temName参数错误")
+    return new Promise((resolve,reject) => reject("temName参数错误"))
+  }
+  console.log(objectStorageClient,file,temName,options,'objectStorageClient,file,temName,options');
+  switch (objectStorageClient) {
+    case "1":
+      let ossOptions = {}
+      if(options.OSS){
+        ossOptions=options.OSS
+      }
+
+      return handleUploadToOSS(file,temName,ossOptions)
+      // break;
+    case "2":
+      let minioOptions = {}
+      if(options.MINIO){
+        minioOptions=options.MINIO
+      }
+      return handleUploadToMinIO(file,temName,minioOptions)
+      // break;
+    default:
+      break;
+  }
+}
+
+const handleUploadToOSS= (file,fileName,options={})=>{
+  return new Promise(async (resolve,reject)=>{
+    // 获取oss临时签名
+    const res=await getOSSSign()
+    if(res.Ret!==200) reject("获取oss临时签名错误")
+    try {
+
+      let oss_params = {
+        // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
+        region: res.Data.RegionId,
+        // 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
+        accessKeyId: res.Data.AccessKeyId,
+        accessKeySecret: res.Data.AccessKeySecret,
+        // 从STS服务获取的安全令牌(SecurityToken)。
+        stsToken: res.Data.SecurityToken,
+        // 填写Bucket名称,例如examplebucket。
+        bucket: res.Data.Bucketname,
+        endpoint: res.Data.Endpoint,
+        cname:true,
+        timeout:6000000
+      }
+  
+      let imgHost = res.Data.Imghost;
+  
+      const ALOSSINS=new OSS(oss_params);
+
+      const resp=await ALOSSINS.multipartUpload(fileName,file,{...options})
+      console.log('上传结果',resp);
+      if(resp.res.status===200){
+        let url=imgHost+resp.name
+        resolve(url)
+        console.log('oss文件地址',url);
+      }else{
+        throw new Error('上传到阿里云失败:res.status'+resp.res.status)
+      }
+    } catch (error) {
+      console.error(error);
+      if (error.name !== "cancel") {
+        Message.warning('上传失败,请刷新重试')
+      }
+      reject(error)
+    }
+  })
+}
+
+// minio sdk 文档 https://min.io/docs/minio/linux/developers/javascript/API.html
+const handleUploadToMinIO=(file,fileName,options={})=>{
+  return new Promise(async (resolve,reject)=>{
+    // console.log(Minio);
+    const minioClient = new Minio.Client({
+      endPoint: '8.136.199.33',
+      port: 9000,
+      useSSL: false,
+      accessKey: 'eta',
+      secretKey: 'eta202309',
+    })
+
+    try {
+      var metaData = {...{
+        'Content-Type': file.type||'application/octet-stream',
+        "Content-Length": file.size,
+        // example: 5678,
+      },...options}
+    
+      minioClient.bucketExists("etastatic", function (err, exists) {
+          if (err) {
+              throw "minio 查看桶是否存在失败"+err
+              // return console.log(err);
+          }
+          if (!exists) {
+            // 不存在桶,创建桶
+            minioClient.makeBucket('etastatic', function (err) {
+              if (err) {
+                throw "minio 创建桶失败"+err
+              }
+            
+              let reader = new FileReader();
+              // console.log(reader);
+              reader.readAsArrayBuffer(file);
+              reader.onloadend = function (e) {
+                const dataurl = e.target.result;
+                let bufferStream = new stream.PassThrough();
+                // 转化成数据流  minio接受数据流格式
+                bufferStream.end(Buffer.from(dataurl))
+                // console.log(bufferStream);
+                minioClient.putObject('etastatic', fileName, bufferStream, metaData, function (err, etag) {
+                  if (err){
+                    throw "上传到minio失败:"+err
+                  }
+            
+                })
+              }
+            })
+          }
+          if (exists) {
+            // console.log("exists");
+            let reader = new FileReader();
+            console.log(reader);
+            reader.readAsArrayBuffer(file);
+            reader.onloadend = function (e) {
+              const dataurl = e.target.result;
+              let bufferStream = new stream.PassThrough();
+    
+              bufferStream.end(Buffer.from(dataurl))
+              console.log(bufferStream);
+              // Using fPutObject API upload your file to the bucket europetrip.
+              minioClient.putObject('etastatic', fileName, bufferStream, metaData, function (err, etag) {
+                if (err){
+                  throw "上传到minio失败:"+err
+                }
+                console.log(minioClient);
+                // let fileUrl = http://8.136.199.33:9000/etastatic/testOne.jpeg
+                resolve("http://8.136.199.33:9000/etastatic/testOne.jpeg")
+              })
+            }
+          }
+      })
+    } catch (error) {
+      console.error(error);
+      if (error.name !== "cancel") {
+        //不是取消上传的则给错误提示
+        this.$message.warning("上传失败,请刷新重试");
+      }
+      reject(error)
+    }
+  })
 }

+ 39 - 2
src/views/ppt_manage/newVersion/pptEnPublish.vue

@@ -60,6 +60,8 @@ import {pptEnInterface} from '@/api/modules/pptEnApi.js';
 import Highcharts from "highcharts/highstock";
 import HighchartszhCN  from '@/utils/highcahrts-zh_CN'
 import HightchartsExport from 'highcharts/modules/exporting';
+import {uploadFileDirect} from "@/utils/common.js"
+
 HightchartsExport(Highcharts)
 HighchartszhCN(Highcharts)
 export default {
@@ -430,10 +432,45 @@ export default {
         text:"发布中..."
       })
       //console.log('pptx',pptx)
+      // pptx2.write('blob').then((data)=>{
+      //   // 上传到阿里云oss
+      //   // this.handleUploadToOSS(data)
+      // })
+      // 生成文件名
+      let t=new Date()
+      let month=moment(t).format('YYYYMM')
+      let day=moment(t).format('YYYYMMDD')
+      /* const temName=`ppt/${month}/${day}/${this.coverInfo.page.Title}.pptx` */
+      const temName=`ppt/${month}/${day}/${createRandomCode(32)}.pptx`
+
+      const options = {
+        OSS:{
+          // 获取分片上传进度、断点和返回值。
+          progress: (p, cpt, res) => {
+            console.log(p);
+              // this.percentage=parseInt(p*100)
+          },
+          // 设置并发上传的分片数量。
+          parallel: 10,
+          // 设置分片大小。默认值为1 MB,最小值为100 KB。
+          partSize: 1024 * 1024 * 10, // 10MB
+        }
+      };
+
       pptx2.write('blob').then((data)=>{
-        // 上传到阿里云oss
-        this.handleUploadToOSS(data)
+        let clientType = this.$setting.dynamicOutLinks.ObjectStorageClient ||
+                        this.$store.state.dynamicOutLinks.ObjectStorageClient ||
+                        JSON.parse(localStorage.getItem('dynamicOutLinks')).ObjectStorageClient
+        // 上传到 对象存储器
+        uploadFileDirect(clientType,data,temName,options).then(res=>{
+          console.log('文件地址',url);
+          this.publishLoading&&this.publishLoading.close()
+          // this.publishPPT(url)
+        }).catch(err=>{
+          console.error(err);
+        })
       })
+
     },
     //计算各版式下,对应position在ppt中的位置
     getPosition(modelId, position) {

+ 36 - 1
src/views/ppt_manage/newVersion/pptPublish.vue

@@ -120,6 +120,8 @@ import{pptInterface,dataBaseInterface,getOSSSign} from "@/api/api.js"
 import Highcharts from "highcharts/highstock";
 import HighchartszhCN  from '@/utils/highcahrts-zh_CN'
 import HightchartsExport from 'highcharts/modules/exporting';
+import {uploadFileDirect} from "@/utils/common.js"
+
 HightchartsExport(Highcharts)
 HighchartszhCN(Highcharts)
 export default {
@@ -508,6 +510,28 @@ export default {
         fullscreen:true,
         text:"发布中..."
       })
+
+      // 生成文件名
+      let t=new Date()
+      let month=moment(t).format('YYYYMM')
+      let day=moment(t).format('YYYYMMDD')
+      /* const temName=`ppt/${month}/${day}/${this.coverInfo.page.Title}.pptx` */
+      const temName=`ppt/${month}/${day}/${createRandomCode(32)}.pptx`
+
+      const options = {
+        OSS:{
+          // 获取分片上传进度、断点和返回值。
+          progress: (p, cpt, res) => {
+            console.log(p);
+              // this.percentage=parseInt(p*100)
+          },
+          // 设置并发上传的分片数量。
+          parallel: 10,
+          // 设置分片大小。默认值为1 MB,最小值为100 KB。
+          partSize: 1024 * 1024 * 10, // 10MB
+        }
+      };
+
       //console.log('pptx',pptx)
       pptx2.write('blob').then((data)=>{
         // let form = new FormData()
@@ -519,7 +543,18 @@ export default {
         //   }
         // })
         // 上传到阿里云oss
-        this.handleUploadToOSS(data)
+        // this.handleUploadToOSS(data)
+        let clientType = this.$setting.dynamicOutLinks.ObjectStorageClient ||
+                        this.$store.state.dynamicOutLinks.ObjectStorageClient ||
+                        JSON.parse(localStorage.getItem('dynamicOutLinks')).ObjectStorageClient
+        // 上传到 对象存储器
+        uploadFileDirect(clientType,data,temName,options).then(res=>{
+          console.log('文件地址',url);
+          this.publishLoading&&this.publishLoading.close()
+          // this.publishPPT(url)
+        }).catch(err=>{
+          console.error(err);
+        })
       })
     },
     //计算各版式下,对应position在ppt中的位置

+ 43 - 25
src/views/report_manage/editChapterReport.vue

@@ -319,7 +319,8 @@ import reportMixin from './mixins/reportMixin';
 import moment from "moment";
 import importMyChart from "./components/importMyChart.vue";
 import importSemantics from './components/importSemantics.vue';
-let ALOSSINS = null; //阿里云上传实例
+import {uploadFileDirect} from "@/utils/common.js"
+
 export default {
   beforeRouteEnter(to, from, next) {
     // 设置面包屑
@@ -428,35 +429,52 @@ export default {
   },
   methods: {
     handelBeforeUploadAudio(e) {
-      console.log(e);
-      if (
-        e.name.indexOf(".mp3") == -1 &&
-        e.name.indexOf(".wav") == -1 &&
-        e.name.indexOf(".wma") == -1 &&
-        e.name.indexOf(".m4a") == -1
-      ) {
-        this.$message.warning("上传失败,上传音频格式不正确");
-        return false;
-      }
+      // console.log(e);
+      // if (
+      //   e.name.indexOf(".mp3") == -1 &&
+      //   e.name.indexOf(".wav") == -1 &&
+      //   e.name.indexOf(".wma") == -1 &&
+      //   e.name.indexOf(".m4a") == -1
+      // ) {
+      //   this.$message.warning("上传失败,上传音频格式不正确");
+      //   return false;
+      // }
     },
     async handleUpload(e) {
-      console.log(e.file.size);
-      const duration = await this.handleGetDuration(e.file);
-      if (duration > 60 * 15) {
-        this.$message.warning("音频时长不得超过15分钟");
-        return;
-      }
-      this.aeForm.audioDuration = duration;
-      this.aeForm.audioSize = e.file.size / 1024 / 1024; //单位MB
-      const res = await getOSSSign();
-      if (res.Ret === 200) {
-        
-        this.handleUploadToOSS(e.file, res.Data);
-      }
+      // const duration = await this.handleGetDuration(e.file);
+      // if (duration > 60 * 15) {
+      //   this.$message.warning("音频时长不得超过15分钟");
+      //   return;
+      // }
+      // this.aeForm.audioDuration = duration;
+      // this.aeForm.audioSize = e.file.size / 1024 / 1024; //单位MB
+      this.startUploadAudio = true;
+
+      // const t = new Date().getTime().toString();
+      // const temName = `static/yb/audio/${process.env.NODE_ENV}/${MD5(t)}.${
+      //   e.file.type.split("/")[1]
+      // }`;
+      const temName = `testOne.${
+        e.file.type.split("/")[1]
+      }`;
+
+      let clientType = this.$setting.dynamicOutLinks.ObjectStorageClient ||
+                        this.$store.state.dynamicOutLinks.ObjectStorageClient ||
+                        JSON.parse(localStorage.getItem('dynamicOutLinks')).ObjectStorageClient
+      uploadFileDirect(clientType,e.file,temName).then(res=>{
+        console.log(res);
+        this.aeForm.audioUrl = res;
+      })
+      .finally(()=>{
+        this.startUploadAudio = false;
+      })
+      // const res = await getOSSSign();
+      // if (res.Ret === 200) {
+        // this.handleUploadToOSS(e.file, res.Data);
+      // }
     },
     //上传到阿里云
     async handleUploadToOSS(file, ossRes) {
-      this.startUploadAudio = true;
 
        let oss_params = {
         // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。