Kaynağa Gözat

尝试传输列表

“yueshang” 2 yıl önce
ebeveyn
işleme
a181462b7c

+ 8 - 0
src/api/chat/msg.js

@@ -128,4 +128,12 @@ export function fileDownload(data){
       url:`/biz/info/download/${data}`,
       method:"get"
   })
+}
+//测试
+export function uploadFileMany(data) {
+  return request({
+      url: `/biz/info/uploadFiles`,
+      method: "post",
+      data,
+  })
 }

+ 1 - 1
src/components/FileTreeChoice/index.vue

@@ -11,7 +11,7 @@
           ref="treeRef"
           :data="treeData.data"
           :show-checkbox="false"
-          :height="280"
+          :height="320"
           :props="defaultProps"
           @node-click="handleNodeClick"
         >

+ 1 - 1
src/layout/indexCommon.vue

@@ -252,7 +252,7 @@ const menuList = reactive({
     },
     {
       label: "传输列表",
-      path: "/ws",
+      path: "/transFile",
       imgs: chuanshu,
       beimgs: bechuanshu,
     },

+ 9 - 0
src/router/index.js

@@ -137,6 +137,15 @@ export const constantRoutes = [{
 				}
 			},
 			{
+				path: "/transFile",
+				component: () => import("@/views/transFile/index.vue"),
+				name: "transFile",
+				meta: {
+					title: "聊天",
+					icon: "department"
+				}
+			},
+			{
 				path: "/highsearch",
 				component: () => import("@/views/highSearch/HighSearch.vue"),
 				name: "highsearch",

+ 9 - 0
src/store/modules/process.js

@@ -0,0 +1,9 @@
+
+const uploadStore = defineStore('uploadsss', {
+    state: () => ({
+        multiFileList: [],
+        processNumber: 3,
+        promise: []
+    })
+})
+export default uploadStore

+ 15 - 1
src/store/modules/user.js

@@ -3,6 +3,7 @@ import {
 	logout,
 	getInfo
 } from '@/api/login'
+import {spaceInfo} from "@/api/chat/msg";
 import {
 	getToken,
 	setToken,
@@ -19,7 +20,8 @@ const useUserStore = defineStore(
 			uname: '',
 			avatar: '',
 			roles: [],
-			permissions: []
+			permissions: [],
+			spaceIdCommon:''
 		}),
 		actions: {
 			// 登录
@@ -56,6 +58,7 @@ const useUserStore = defineStore(
 						this.avatar = avatar;
 						const websoctStore = useWebsoctStore()
 						websoctStore.connect()
+						this.getSpaceInfo()
 						resolve(res)
 					}).catch(error => {
 						reject(error)
@@ -75,6 +78,17 @@ const useUserStore = defineStore(
 						reject(error)
 					})
 				})
+			},
+			//获取空间id
+			getSpaceInfo(){
+				return new Promise((resolve, reject) => {
+					spaceInfo(3).then((topSpaceid) => {
+						this.spaceIdCommon= topSpaceid.data.spaceId.toString();
+						resolve()
+					}).catch(error => {
+						reject(error)
+					})
+				})
 			}
 		}
 	})

+ 165 - 0
src/utils/progress.js

@@ -0,0 +1,165 @@
+import uploadStore from '@/store/modules/process'
+import { ElMessage } from 'element-plus'
+import { uploadFileMany } from "@/api/chat/msg";
+import useUserStore from "@/store/modules/user";
+const useUserStoreId = useUserStore();
+export function addUploadFile(raw) {
+  const upload = uploadStore()
+  const uploadProgress = {
+    progress: 0,
+    file_id: '',
+    file_name: raw.name,
+    percent: [],
+    speed: '0 MB',
+    file_size: raw.size,
+    upload_size: 0,
+    upload_time: new Date()
+  }
+  // status上传状态 0 队列,1 上传中,2 上传成功 , 3 取消上传
+  // failTryCount 失败上传次数, 没上传一次,自动减去已,当为0的时候,停止上传
+  upload.multiFileList.push({file: raw, progress: uploadProgress, status: 0, failTryCount: 3})
+  multiUpload()
+}
+
+export function multiUpload() {
+  const upload = uploadStore()
+  const readFileList = []
+  upload.multiFileList.forEach(res => {
+    if (res.status === 0) {
+      readFileList.push(res)
+    }
+  })
+  if (readFileList.length > 0) {
+    multiRun(upload, readFileList.slice(0, upload.processNumber), uploadAsync)
+  }
+}
+
+function multiRun(upload, keyList, func) {
+  const processNumber = upload.processNumber
+  const promise = upload.promise
+  for (let i = 0; i < processNumber - promise.length; i++) {
+    promise.push(Promise.resolve())
+  }
+  let reduceNumber = promise.length - processNumber
+  if (reduceNumber > 0) {
+    upload.promise = promise.slice(0, reduceNumber)
+  }
+  for (let j = 0; j < keyList.length; j += processNumber) {
+    for (let i = 0; i < processNumber; i++) {
+      if (i + j < keyList.length) {
+        promise[(j + i) % processNumber] = promise[(j + i) % processNumber].then(() => func(keyList[i + j]))
+        // .catch(({fileInfo,err}) => {
+        //   if (fileInfo?.status === 3) {
+        //     console.log(fileInfo.file.name, '取消上传')
+        //   } else {
+        //     fileInfo.status = 0
+        //     fileInfo.failTryCount -= 1
+        //     if (fileInfo.failTryCount < 1) {
+        //       ElMessage.error(`${fileInfo.file.name} 超过最大重试次数,停止上传`)
+        //     } else {
+        //       ElMessage.error(`${fileInfo.file.name} 上传失败,正在重试`)
+        //       console.log(fileInfo.file.name, err)
+        //       multiUpload()
+        //     }
+        //   }
+        // })
+      }
+    }
+  }
+}
+
+function uploadAsync(fileInfo) {
+  const progress = fileInfo.progress
+  const file = fileInfo.file
+  return new Promise((resolve, reject) => {
+    progress.file_name = file.name
+    progress.file_size = file.size
+    if (fileInfo.status === 0) {
+      fileInfo.status = 1
+    } else {
+      return resolve()
+    }
+    progress.progress = 10
+    // getUploadSid().then(async res => {
+    //   progress.speed = '文件读取中'
+    //   let hash = await PreHash(file, progress)
+    //   let fileHashInfo = {
+    //     sid: res.data.sid,
+    //     file_name: progress.file_name,
+    //     file_size: progress.file_size,
+    //     pre_hash: hash
+    //   }
+    //   progress.progress = 20
+    //   checkPreHash(fileHashInfo).then(async pRes => {
+    //     if (pRes.data.check_status === true) {
+    //       progress.progress = 30
+    //       const md5Code = pRes.data.md5_token
+    //       progress.speed = '文件校验中'
+    //       let hash = await ContentHash(file, md5Code, progress)
+    //       fileHashInfo.proof_code = hash.proofCode
+    //       fileHashInfo.content_hash = hash.conHash
+    //       checkContentHash(fileHashInfo).then(async cRes => {
+    //         if (cRes.data.check_status === true) {
+    //           progress.progress = 100
+    //           progress.upload_size = progress.file_size
+    //           progress.speed = '秒传成功'
+    //           fileInfo.status = 2
+    //           fileInfo.upload_time = new Date()
+    //           multiUpload()
+    //           resolve()
+    //         } else {
+    //           return await ChunkedUpload(fileInfo, fileHashInfo, cRes.data.upload_extra, cRes.data.part_info_list, () => {
+    //             fileInfo.status = 2
+    //             fileInfo.upload_time = new Date()
+    //             multiUpload()
+    //             resolve()
+    //           }, (err) => {
+    //             reject({fileInfo, err})
+    //           })
+    //         }
+    //       }).catch((err) => {
+    //         reject({fileInfo, err})
+    //       })
+    //     } else {
+    //       return await ChunkedUpload(fileInfo, fileHashInfo, pRes.data.upload_extra, pRes.data.part_info_list, () => {
+    //         fileInfo.status = 2
+    //         fileInfo.upload_time = new Date()
+    //         multiUpload()
+    //         resolve()
+    //       }, (err) => {
+    //         reject({fileInfo, err})
+    //       })
+    //     }
+    //   }).catch((err) => {
+    //     reject({fileInfo, err})
+    //   })
+    // }).catch((err) => {
+    //   reject({fileInfo, err})
+    // })
+
+    // Update this part of the code based on your project's API for uploading files
+    console.log('file=========', file,)
+    uploadFileMany({spaceId:useUserStoreId.spaceIdCommon,dirId:17,files:''}).then((res) => {
+      progress.progress = 100
+      progress.upload_size = progress.file_size
+      progress.speed = '上传成功'
+      fileInfo.status = 2
+      fileInfo.upload_time = new Date()
+      console.log('res===', res)
+      multiUpload()
+
+      resolve()
+    }).catch((err) => {
+      fileInfo.status = 0
+      fileInfo.failTryCount -= 1
+      if (fileInfo.failTryCount < 1) {
+        ElMessage.error(`${fileInfo.file.name} 超过最大重试次数,停止上传`)
+      } else {
+        ElMessage.error(`${fileInfo.file.name} 上传失败,正在重试`)
+        console.log(fileInfo.file.name, err)
+        multiUpload()
+      }
+      reject({fileInfo, err})
+    })
+  })
+}

+ 1 - 0
src/views/liveChat/index.vue

@@ -491,6 +491,7 @@ onMounted(() => {
               clearable
               size="small"
               placeholder="请输入聊天内容"
+              maxlength="450"
               @keydown.enter="msgSendClick"
             />
             <!-- 发送按钮 -->

+ 40 - 0
src/views/transFile/index.vue

@@ -0,0 +1,40 @@
+<script>
+export default {
+  name: "ttansFile",
+};
+</script>
+<script setup>
+import { ref, reactive } from "vue";
+import { addUploadFile } from "@/utils/progress";
+const beforeUpload=(raw)=>{
+    addUploadFile(raw)
+  return false
+}
+</script>
+
+<template>
+  <div>
+    <!-- before-upload限制上传的格式和大小  action请求url  drag拖拽上传 multiple多文件-->
+    <el-upload
+      :before-upload="beforeUpload"
+      action="#"
+      class="upload"
+      drag
+      multiple
+    >
+      <el-icon class="el-icon--upload">
+        <upload-filled />
+      </el-icon>
+      <div class="el-upload__text">拖拽或 <em>点击上传</em></div>
+      <!-- 提示说明文字 -->
+      <template #tip>
+        <div class="el-upload__tip">
+          请上传文件,仅支持上传文件,不支持文件夹
+        </div>
+      </template>
+    </el-upload>
+  </div>
+</template>
+
+<style scoped>
+</style>