Commit b874c2a0 authored by miaojiale's avatar miaojiale

修改上传代码

parent e2ced02a
NODE_ENV = 'production'
VUE_APP_URL = 'https://zcas.wzswsj.gov.cn:8079/screening-api/'
VUE_APP_URL = '/screening-api/'
VUE_APP_URL = 'https://inno.sh-sict.com/gastric-api/'
VUE_APP_IMG = 'https://inno.sh-sict.com/wjy-mobile/'
\ No newline at end of file
......@@ -27,6 +27,9 @@ export const API = {
);
},
fileUpload: (data) => {
return post(`${ewellDefectData}/app/report/video/upload`, data);
return post(`${ewellDefectData}/app/report/video/chunk`, data);
},
fileMerge: (data) => {
return post(`${ewellDefectData}/app/report/video/merge`, data);
}
};
......@@ -15,7 +15,7 @@ let CommonAlert = function (msg) {
// axios.defaults.timeout = 5000;
if (process.env.NODE_ENV == "development") {
axios.defaults.baseURL = "https://inno.sh-sict.com/gastric-api/";
// axios.defaults.baseURL = "https://inno.sh-sict.com/gastric-api/";
} else {
axios.defaults.baseURL = process.env.VUE_APP_URL;
}
......
......@@ -93,7 +93,7 @@ export default {
this.finished = false;
this.$API.getPeopleList(data).then(res => {
this.loading = false
this.totalCount = res.object.totalCount
this.totalCount = res.object?.totalCount
this.peopleList = [...this.peopleList, ...res.object.list]
if (this.peopleList.length >= this.totalCount) {
this.finished = true
......@@ -105,10 +105,6 @@ export default {
this.getList()
},
},
created () {
this.peopleList = []
this.getList()
},
activated () {
const scrollTops = this.$route.meta.scrollTop;
const $content = document.querySelector('.list_content');
......@@ -126,6 +122,9 @@ export default {
next()
},
mounted () {
// console.log('???');
this.peopleList = []
this.getList()
},
watch: {},
filters: {
......
......@@ -173,20 +173,29 @@ export default {
afterRead (file) {
this.uploadLoading = true
// console.log(file);
let dataId = this.$route.query.id
let randomNum = dataId + '' + Math.round(Math.random() * 10000)
uploadByPieces({
randoms: '', // 随机数,这里作为给后端处理分片的标识 根据项目看情况 是否要加
randoms: randomNum, // 随机数,这里作为给后端处理分片的标识 根据项目看情况 是否要加
file: file.file, // 视频实体
pieceSize: 10, // 分片大小
dataId: this.$route.query.id,
dataId: dataId,
success: data => {
console.log('分片上传视频成功', data)
this.uploadLoading = false
// 合并
this.$API.fileMerge({
dataId: dataId,
videoName: data.videoName,
id: randomNum
})
this.pageNum = 1
this.videoList = []
this.getVideoList()
},
error: e => {
console.log('分片上传视频失败', e)
this.uploadLoading = false
}
})
},
......
import md5 from "js-md5"; //引入MD5加密
import md5, { arrayBuffer } from "js-md5"; //引入MD5加密
import { API } from "@/axios/api"; // 这里指前端调用接口的api方法
export const uploadByPieces = ({
randoms,
......@@ -19,15 +19,15 @@ export const uploadByPieces = ({
// 获取md5
const readFileMD5 = () => {
// 读取视频文件的md5
console.log("获取文件的MD5值");
// console.log("获取文件的MD5值");
let fileRederInstance = new FileReader();
console.log("file", file);
fileRederInstance.readAsBinaryString(file);
fileRederInstance.addEventListener("load", (e) => {
let fileBolb = e.target.result;
fileMD5 = md5(fileBolb);
console.log("fileMD5", fileMD5);
console.log("文件未被上传,将分片上传");
// console.log("fileMD5", fileMD5);
// console.log("文件未被上传,将分片上传");
readChunkMD5();
});
};
......@@ -40,12 +40,13 @@ export const uploadByPieces = ({
// 针对每个文件进行chunk处理
const readChunkMD5 = () => {
// 针对单个文件进行chunk上传
let arr = [];
for (var i = 0; i < chunkCount; i++) {
const { chunk } = getChunkInfo(file, i, chunkSize);
console.log("总片数" + chunkCount);
console.log("分片后的数据---测试:" + i);
console.log(chunk);
uploadChunk({ chunk, currentChunk: i, chunkCount });
uploadChunk({ chunk, currentChunk: i, chunkCount, arr });
}
};
const uploadChunk = (chunkInfo) => {
......@@ -69,23 +70,30 @@ export const uploadByPieces = ({
// fetchForm.append('md5', fileMD5)
API.fileUpload(fetchForm, config)
.then((res) => {
console.log("分片上传返回信息:" + res);
// console.log("分片上传返回信息:" + JSON.stringify(res));
// console.log(chunkInfo);
chunkInfo.arr.push(chunkInfo.currentChunk);
// console.log(chunkInfo.arr);
if (res.code == 1) {
// 结合不同项目 将成功的信息返回出去,这里可变的是指 res.data[0]
success();
if (chunkInfo.arr.length == chunkInfo.chunkCount) {
success({
videoName: file.name
});
}
// 下面如果在项目中没有用到可以不用打开注释
// if (chunkInfo.currentChunk < chunkInfo.chunkCount - 1) {
// console.log("分片上传成功")
// } else {
// // 当总数大于等于分片个数的时候
// if ((chunkInfo.currentChunk + 1) == chunkInfo.chunkCount) {
// console.log("文件开始------合并成功")
// success(res.data[0])
// }
// }
console.log(chunkInfo);
if (chunkInfo.currentChunk < chunkInfo.chunkCount - 1) {
console.log("分片上传成功");
} else {
// 当总数大于等于分片个数的时候
if (chunkInfo.currentChunk + 1 == chunkInfo.chunkCount) {
console.log("文件开始------合并成功");
}
}
} else {
console.log(res.message);
error();
}
})
.catch((e) => {
......
......@@ -2,7 +2,7 @@ const path = require("path");
module.exports = {
publicPath: "",
outputDir: "cssc-mobile",
outputDir: "dist",
assetsDir: "static",
configureWebpack: (config) => {
require("@vux/loader").merge(config, {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment