Commit b874c2a0 authored by miaojiale's avatar miaojiale

修改上传代码

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