|
@@ -0,0 +1,1079 @@
|
|
|
|
+/**
|
|
|
|
+* 附件上传组件
|
|
|
|
+* @params
|
|
|
|
+***
|
|
|
|
+* autoUp 是否开启自动上传
|
|
|
|
+* downAll 是否可以批量下载
|
|
|
|
+* accept=".jpg,.jpeg,.png,.gif,.bmp,.pdf" 指定可上传的文件类型
|
|
|
|
+* show-file-list 是否采用elementUi默认展示方式?
|
|
|
|
+* defaultFileList 初始化list数据 展示时使用 不可编辑
|
|
|
|
+* draftFileList 初始化list数据 草稿状态使用 仍然可以进行编辑
|
|
|
|
+* down-and-preview show-file-list为true情况下是否可以预览和下载
|
|
|
|
+* show-table 和 show-file-list 只能一个为true 或者都为false 自定义 success 回调的展示
|
|
|
|
+* show-table 采用表格展示方式 false
|
|
|
|
+* columns 采用表格展示,需要配置表头
|
|
|
|
+**/
|
|
|
|
+<template>
|
|
|
|
+ <div class="myupload">
|
|
|
|
+ <el-upload
|
|
|
|
+ v-if="ie10Control"
|
|
|
|
+ class="upload-demo"
|
|
|
|
+ ref="upload"
|
|
|
|
+ action="#"
|
|
|
|
+ :disabled="disabled"
|
|
|
|
+ :accept="acceptType"
|
|
|
|
+ :before-upload="beforeUploadFile"
|
|
|
|
+ :on-change="handleChange"
|
|
|
|
+ :http-request="toUpload"
|
|
|
|
+ :on-progress="toUploadProgress"
|
|
|
|
+ :on-success="toUploadSuccess"
|
|
|
|
+ :on-error="toUploadError"
|
|
|
|
+ :on-preview="handlePreview"
|
|
|
|
+ :before-remove="beforeRemove"
|
|
|
|
+ :on-remove="handleRemove"
|
|
|
|
+ :on-exceed="handleExceed"
|
|
|
|
+ :file-list="fileList"
|
|
|
|
+ :auto-upload="autoUp"
|
|
|
|
+ :show-file-list="showFileList"
|
|
|
|
+ :limit="fileNum"
|
|
|
|
+ :multiple="multipleCtrl"
|
|
|
|
+ >
|
|
|
|
+ <span
|
|
|
|
+ style="
|
|
|
|
+ color: red;
|
|
|
|
+ margin-left: calc(100% - 485px);
|
|
|
|
+ float: left;
|
|
|
|
+ display: inline-block;
|
|
|
|
+ height: 30px;
|
|
|
|
+ line-height: 30px;
|
|
|
|
+ "
|
|
|
|
+ v-if="fjShowMsg"
|
|
|
|
+ >
|
|
|
|
+ 请不要上传、处理、存储、传输涉密信息!</span
|
|
|
|
+ >
|
|
|
|
+ <el-button
|
|
|
|
+ :disabled="disabled"
|
|
|
|
+ v-if="defaultFileList.length == 0"
|
|
|
|
+ slot="trigger"
|
|
|
|
+ size="small"
|
|
|
|
+ type="primary"
|
|
|
|
+ icon="el-icon-circle-plus"
|
|
|
|
+ >选取文件
|
|
|
|
+ </el-button>
|
|
|
|
+ <el-button
|
|
|
|
+ v-if="!autoUp"
|
|
|
|
+ style="margin-left: 10px"
|
|
|
|
+ size="small"
|
|
|
|
+ type="success"
|
|
|
|
+ @click="submitUpload"
|
|
|
|
+ icon="el-icon-upload"
|
|
|
|
+ >
|
|
|
|
+ 上传文件
|
|
|
|
+ </el-button>
|
|
|
|
+ <el-button
|
|
|
|
+ v-if="downAll"
|
|
|
|
+ style="margin-left: 10px"
|
|
|
|
+ size="small"
|
|
|
|
+ type="success"
|
|
|
|
+ @click.stop="downloadAll"
|
|
|
|
+ icon="el-icon-download"
|
|
|
|
+ >
|
|
|
|
+ 批量下载
|
|
|
|
+ </el-button>
|
|
|
|
+ <span style="color: red; margin-left: 5px" v-if="isShowUploadMsg"
|
|
|
|
+ >请不要上传、处理、存储、传输涉密信息!</span
|
|
|
|
+ >
|
|
|
|
+ <div slot="tip" class="mytip">
|
|
|
|
+ <slot name="mytip"></slot>
|
|
|
|
+ <el-progress
|
|
|
|
+ v-if="isMultipartUpload && showProgress"
|
|
|
|
+ :key="refresh"
|
|
|
|
+ status="success"
|
|
|
|
+ :percentage="multipartPercentage"
|
|
|
|
+ :text-inside="true"
|
|
|
|
+ :stroke-width="13"
|
|
|
|
+ >
|
|
|
|
+ </el-progress>
|
|
|
|
+ </div>
|
|
|
|
+ </el-upload>
|
|
|
|
+ <table-list
|
|
|
|
+ ref="table"
|
|
|
|
+ v-if="defaultFileList.length > 0"
|
|
|
|
+ index
|
|
|
|
+ :getDataWay="getDataWay"
|
|
|
|
+ :columns="columns"
|
|
|
|
+ >
|
|
|
|
+ <el-table-column label="操作" slot="opts" width="200">
|
|
|
|
+ <template slot-scope="scope">
|
|
|
|
+ <el-link
|
|
|
|
+ :underline="false"
|
|
|
|
+ @click="showPreview(scope.row)"
|
|
|
|
+ class="a-link optItem"
|
|
|
|
+ >
|
|
|
|
+ 预览
|
|
|
|
+ </el-link>
|
|
|
|
+ <el-link
|
|
|
|
+ :underline="false"
|
|
|
|
+ @click="showDownload(scope.row)"
|
|
|
|
+ class="a-link optItem"
|
|
|
|
+ >
|
|
|
|
+ 下载
|
|
|
|
+ </el-link>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ </table-list>
|
|
|
|
+ <div v-if="downAndPreview">
|
|
|
|
+ <el-dialog
|
|
|
|
+ title="提示"
|
|
|
|
+ :visible.sync="dialogVisible"
|
|
|
|
+ width="500px"
|
|
|
|
+ :close="dialogClose"
|
|
|
|
+ :close-on-click-modal="false"
|
|
|
|
+ :close-on-press-escape="false"
|
|
|
|
+ :modal-append-to-body="true"
|
|
|
|
+ :append-to-body="true"
|
|
|
|
+ v-dialogDrag="true"
|
|
|
|
+ >
|
|
|
|
+ <span
|
|
|
|
+ ><i class="el-icon-warning el-dialog__body-myi"></i
|
|
|
|
+ >对该文件进行预览或者下载?</span
|
|
|
|
+ >
|
|
|
|
+ <span slot="footer" class="dialog-footer">
|
|
|
|
+ <el-button size="small" type="primary" @click="preViewFile"
|
|
|
|
+ >文件预览</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button size="small" type="primary" @click="downloadFile"
|
|
|
|
+ >文件下载</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button size="small" @click="dialogVisible = false"
|
|
|
|
+ >取 消</el-button
|
|
|
|
+ >
|
|
|
|
+ </span>
|
|
|
|
+ </el-dialog>
|
|
|
|
+ </div>
|
|
|
|
+ <!-- <preview ref="preview"></preview> -->
|
|
|
|
+ </div>
|
|
|
|
+</template>
|
|
|
|
+<script>
|
|
|
|
+let ifrm;
|
|
|
|
+
|
|
|
|
+function ssoVerify(domain) {
|
|
|
|
+ try {
|
|
|
|
+ ifrm = document.createElement('<iframe name="ssoIframe"></iframe>');
|
|
|
|
+ } catch (e) {
|
|
|
|
+ ifrm = document.createElement("iframe");
|
|
|
|
+ ifrm.name = "ssoIframe";
|
|
|
|
+ }
|
|
|
|
+ ifrm.src =
|
|
|
|
+ domain +
|
|
|
|
+ "/ssoCheck.action?toUrl=" +
|
|
|
|
+ encodeURIComponent(store.state.fileServiceUrl);
|
|
|
|
+ ifrm.style = "display:none";
|
|
|
|
+ document.body.appendChild(ifrm);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function noop() {}
|
|
|
|
+
|
|
|
|
+function defaultUpload(file) {
|
|
|
|
+ const is30M = file.size / 1024 / 1024 < 30;
|
|
|
|
+ if (!is30M) {
|
|
|
|
+ this.$message.error("上传文件大小不能超过 30MB!");
|
|
|
|
+ }
|
|
|
|
+ return is30M;
|
|
|
|
+}
|
|
|
|
+// import "@/lib/spark-md5.min.js";
|
|
|
|
+import TableList from "@/components/grid/TableList";
|
|
|
|
+// import preview from "@/components/upload/preview";
|
|
|
|
+export default {
|
|
|
|
+ name: "upload",
|
|
|
|
+ props: {
|
|
|
|
+ //是否显示非mi提示
|
|
|
|
+ isShowUploadMsg: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ //附件页签 显示提示 在选取文件左侧
|
|
|
|
+ fjShowMsg: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ //上传文件新加参数,默认1,只有部门共享文件上传2
|
|
|
|
+ uploadFileType: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: "1",
|
|
|
|
+ },
|
|
|
|
+ isMultipartUpload: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ disabled: {
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ getDataWay: {
|
|
|
|
+ //初始化list数据
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ dataType: "data",
|
|
|
|
+ data: [{ name: "测试.pdf", size: "1024" }],
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ columns: {
|
|
|
|
+ //初始化list数据
|
|
|
|
+ type: Array,
|
|
|
|
+ default: () => [
|
|
|
|
+ {
|
|
|
|
+ label: "文件名称",
|
|
|
|
+ prop: "name",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: "文件大小",
|
|
|
|
+ prop: "size",
|
|
|
|
+ columnWidth: "100",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ label: "操作",
|
|
|
|
+ prop: "opts",
|
|
|
|
+ columnWidth: "200",
|
|
|
|
+ template: true,
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ },
|
|
|
|
+ acceptType: {
|
|
|
|
+ //接受的上传类型
|
|
|
|
+ type: String,
|
|
|
|
+ default: "",
|
|
|
|
+ },
|
|
|
|
+ autoUp: {
|
|
|
|
+ //自动上传
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ downAll: {
|
|
|
|
+ //下载全部
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: false,
|
|
|
|
+ },
|
|
|
|
+ showFileList: {
|
|
|
|
+ //是否使用elementUi自带的展示方式
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: true,
|
|
|
|
+ },
|
|
|
|
+ showTable: {
|
|
|
|
+ //是否使用elementUi自带的展示方式
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: true,
|
|
|
|
+ },
|
|
|
|
+ downAndPreview: {
|
|
|
|
+ //elementUi展示是否可以预览
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: true,
|
|
|
|
+ },
|
|
|
|
+ fileNum: {
|
|
|
|
+ type: Number,
|
|
|
|
+ default: 10000,
|
|
|
|
+ },
|
|
|
|
+ listType: {
|
|
|
|
+ type: String,
|
|
|
|
+ default: "text",
|
|
|
|
+ },
|
|
|
|
+ defaultFileList: {
|
|
|
|
+ //初始化list数据
|
|
|
|
+ type: Array,
|
|
|
|
+ default: () => [],
|
|
|
|
+ },
|
|
|
|
+ draftFileList: {
|
|
|
|
+ //草稿初始化list数据
|
|
|
|
+ type: Array,
|
|
|
|
+ default: () => [],
|
|
|
|
+ },
|
|
|
|
+ md5CheckParams: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ //md5校验需要的参数
|
|
|
|
+ userId: "222222",
|
|
|
|
+ moduleName: "CheckForFrontEnd",
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ upLoadParams: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ //上传需要的其他参数
|
|
|
|
+ userId: "222222",
|
|
|
|
+ moduleName: "CheckForFrontEnd",
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ downLoadOneParams: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ //下载需要的参数
|
|
|
|
+ isPreview: 1,
|
|
|
|
+ forceDocx: 1,
|
|
|
|
+ webOffice: 1,
|
|
|
|
+ wordWaterMark: 1,
|
|
|
|
+ isWpsSecure: 1,
|
|
|
|
+ caToken: 1,
|
|
|
|
+ waterMark: 1,
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ downLoadAllParams: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ //下载需要的参数
|
|
|
|
+ zipName: "zipDownload.zip",
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ getPdfPathParams: {
|
|
|
|
+ type: Object,
|
|
|
|
+ default: () => ({
|
|
|
|
+ isPreview: 1,
|
|
|
|
+ forceRefresh: 1,
|
|
|
|
+ xdocPdf: 1,
|
|
|
|
+ }),
|
|
|
|
+ },
|
|
|
|
+ onUpSuccess: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpError: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpProgress: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpChange: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpRemove: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpDownloadOne: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ onUpDownloadMany: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ //用于传输上传和删除数据的props
|
|
|
|
+ transferUploadRes: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ transferDelete: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: noop,
|
|
|
|
+ },
|
|
|
|
+ /*beforeUpload: {
|
|
|
|
+ type: Function,
|
|
|
|
+ default: defaultUpload
|
|
|
|
+ },*/
|
|
|
|
+ multipleCtrl: {
|
|
|
|
+ //控制是否多选
|
|
|
|
+ type: Boolean,
|
|
|
|
+ default: true,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ components: { TableList },
|
|
|
|
+ data() {
|
|
|
|
+ return {
|
|
|
|
+ refresh: 0, //再次上传视频时更新组件
|
|
|
|
+ showProgress: false, //显示进度条
|
|
|
|
+ multipartPercentage: 0,
|
|
|
|
+ dialogVisible: false,
|
|
|
|
+ fileList: [],
|
|
|
|
+ currentFileData: {},
|
|
|
|
+ ie10Control: true,
|
|
|
|
+ fileIndex: 0,
|
|
|
|
+ };
|
|
|
|
+ },
|
|
|
|
+ computed: {
|
|
|
|
+ // 控制是否多选
|
|
|
|
+ // 发文、签报、收文 单选
|
|
|
|
+ /* multipleCtrl() {
|
|
|
|
+
|
|
|
|
+ // 发文拟稿状态 => 单选
|
|
|
|
+ if ( this.$route &&
|
|
|
|
+ this.$route.name &&
|
|
|
|
+ this.$route.name == 'SendProcessForm') {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 发文流转状态 => 单选
|
|
|
|
+ else if ( this.$route &&
|
|
|
|
+ this.$route.query &&
|
|
|
|
+ this.$route.query.formData &&
|
|
|
|
+ this.$route.query.formData.bizType &&
|
|
|
|
+ this.$route.query.formData.bizType == "FW_TYLX" ) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 签报拟稿状态 => 单选
|
|
|
|
+ else if ( this.$route &&
|
|
|
|
+ this.$route.name &&
|
|
|
|
+ this.$route.name == 'ReportProcessForm') {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 签报流转状态 => 单选
|
|
|
|
+ else if ( this.$route &&
|
|
|
|
+ this.$route.query &&
|
|
|
|
+ this.$route.query.formData &&
|
|
|
|
+ this.$route.query.formData.bizType &&
|
|
|
|
+ this.$route.query.formData.bizType == "QB_TYLX" ) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 收文拟稿状态 => 单选
|
|
|
|
+ if ( this.$route &&
|
|
|
|
+ this.$route.name &&
|
|
|
|
+ this.$route.name == 'AcceptProcessForm') {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 收文流转状态 => 单选
|
|
|
|
+ else if ( this.$route &&
|
|
|
|
+ this.$route.query &&
|
|
|
|
+ this.$route.query.formData &&
|
|
|
|
+ this.$route.query.formData.bizType &&
|
|
|
|
+ this.$route.query.formData.bizType == "SW_TYLX" ) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ // 其他情况 => 多选
|
|
|
|
+ else{
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }, */
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ created() {
|
|
|
|
+ if (this.defaultFileList && this.defaultFileList.length > 0) {
|
|
|
|
+ this.getDataWay.data = this.defaultFileList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (this.draftFileList && this.draftFileList.length > 0) {
|
|
|
|
+ this.fileList = this.draftFileList;
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ watch: {
|
|
|
|
+ draftFileList: {
|
|
|
|
+ handler: function () {
|
|
|
|
+ this.fileList = this.draftFileList;
|
|
|
|
+ },
|
|
|
|
+ immediate: true,
|
|
|
|
+ },
|
|
|
|
+ defaultFileList: {
|
|
|
|
+ handler: function () {
|
|
|
|
+ this.getDataWay.data = this.defaultFileList;
|
|
|
|
+ },
|
|
|
|
+ immediate: true,
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ methods: {
|
|
|
|
+ beforeUploadFile(file) {
|
|
|
|
+ let testmsg = file.name.substring(file.name.lastIndexOf(".") + 1);
|
|
|
|
+ let acceptType = this.acceptType;
|
|
|
|
+ if (acceptType && acceptType.indexOf(testmsg) == -1) {
|
|
|
|
+ this.$message({
|
|
|
|
+ message: "上传文件只能是" + acceptType + "格式!",
|
|
|
|
+ type: "warning",
|
|
|
|
+ });
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //上传前判断
|
|
|
|
+ // 如果是视频文件或者文件大小超过200M,走分片上传逻辑
|
|
|
|
+ this.isMultipartUpload =
|
|
|
|
+ ["mp4", "MP4"].indexOf(testmsg) !== -1 ||
|
|
|
|
+ file.size > 2.1 * Math.pow(10, 8);
|
|
|
|
+
|
|
|
|
+ // let name = file.name;
|
|
|
|
+ // for (let i = 0; i < this.fileList.length; i++) {
|
|
|
|
+ // let listName = this.fileList[i].name;
|
|
|
|
+ // if (listName == name) {
|
|
|
|
+ // this.$message({
|
|
|
|
+ // type: 'warning',
|
|
|
|
+ // message: '您已经上传过' + name + ',请勿重复上传!'
|
|
|
|
+ // })
|
|
|
|
+ // return false;
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ return true;
|
|
|
|
+ },
|
|
|
|
+ showPreview(row) {
|
|
|
|
+ this.currentFileData = row;
|
|
|
|
+ this.preViewFile();
|
|
|
|
+ },
|
|
|
|
+ showDownload(row) {
|
|
|
|
+ this.currentFileData = row;
|
|
|
|
+ this.downloadFile();
|
|
|
|
+ },
|
|
|
|
+ submitUpload() {
|
|
|
|
+ this.$refs.upload.submit();
|
|
|
|
+ },
|
|
|
|
+ toUpload(params) {
|
|
|
|
+ let that = this;
|
|
|
|
+ params.file.index = ++that.fileIndex;
|
|
|
|
+ that.$$md5ByFile(params).then((res) => {
|
|
|
|
+ let defaultParam = {
|
|
|
|
+ file: params.file,
|
|
|
|
+ md5: res.md5,
|
|
|
|
+ };
|
|
|
|
+ that.$$md5CheckByFile(
|
|
|
|
+ Object.assign(defaultParam, that.md5CheckParams)
|
|
|
|
+ )
|
|
|
|
+ .then(async (checkRes) => {
|
|
|
|
+ if (checkRes && checkRes.message === "正常上传") {
|
|
|
|
+ if (that.isMultipartUpload) {
|
|
|
|
+ this.multipartPercentage = 0;
|
|
|
|
+ this.refresh++;
|
|
|
|
+ that.showProgress = true;
|
|
|
|
+ let fileResult = await that.sliceChunkFile(
|
|
|
|
+ params
|
|
|
|
+ );
|
|
|
|
+ let checkResult = await that.checkChunkFile(
|
|
|
|
+ fileResult.filechunks[0].md5,
|
|
|
|
+ fileResult.filechunks[0].fileSize
|
|
|
|
+ );
|
|
|
|
+ fileResult.wholeFile = params.file;
|
|
|
|
+ await that.uploadChunkFile(
|
|
|
|
+ res.md5,
|
|
|
|
+ fileResult,
|
|
|
|
+ checkResult.info.index + 1
|
|
|
|
+ );
|
|
|
|
+ this.finishChunkFile(
|
|
|
|
+ res.md5,
|
|
|
|
+ fileResult.chunks,
|
|
|
|
+ params
|
|
|
|
+ );
|
|
|
|
+ } else {
|
|
|
|
+ that.toUploadDfs(params, defaultParam);
|
|
|
|
+ }
|
|
|
|
+ } else if (checkRes && checkRes.message === "0") {
|
|
|
|
+ this.transferUploadRes({
|
|
|
|
+ file: defaultParam.file,
|
|
|
|
+ md5: defaultParam.md5,
|
|
|
|
+ url: checkRes.url,
|
|
|
|
+ });
|
|
|
|
+ that.$$updateAnyoneDownload(checkRes.url)
|
|
|
|
+ .then(function (res) {
|
|
|
|
+ params.onSuccess(checkRes);
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "更新预览状态失败!",
|
|
|
|
+ });
|
|
|
|
+ params.onError(error);
|
|
|
|
+ });
|
|
|
|
+ } else if (checkRes && checkRes == "ssoNotLogin") {
|
|
|
|
+ //that.toNotLogin(params, defaultParam);
|
|
|
|
+ } else {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "上传失败",
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ //that.toNotLogin(params, defaultParam);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ toUploadDfs(params, defaultParam) {
|
|
|
|
+ let that = this;
|
|
|
|
+ that.$$uploadFile(
|
|
|
|
+ Object.assign(defaultParam, {
|
|
|
|
+ progress: params.onProgress,
|
|
|
|
+ uploadFileType: this.uploadFileType,
|
|
|
|
+ })
|
|
|
|
+ )
|
|
|
|
+ .then(function (response) {
|
|
|
|
+ that.transferUploadRes({
|
|
|
|
+ file: response.fileSrcName,
|
|
|
|
+ md5: response.md5,
|
|
|
|
+ url: response.url,
|
|
|
|
+ });
|
|
|
|
+ let resObj = {
|
|
|
|
+ fileExt: response.fileExt,
|
|
|
|
+ secretKey: response.secretKey,
|
|
|
|
+ fileSize: response.fileSize,
|
|
|
|
+ name: response.fileSrcName,
|
|
|
|
+ url: response.url,
|
|
|
|
+ md5: response.md5,
|
|
|
|
+ };
|
|
|
|
+ that.$$updateAnyoneDownload(response.url)
|
|
|
|
+ .then(function (res) {
|
|
|
|
+ params.onSuccess(Object.assign(resObj, response));
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "更新预览状态失败!",
|
|
|
|
+ });
|
|
|
|
+ params.onError(error);
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "上传失败",
|
|
|
|
+ });
|
|
|
|
+ params.onError(error);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ toNotLogin(params, defaultParam) {
|
|
|
|
+ let that = this;
|
|
|
|
+ ssoVerify(store.state.ssoServiceUrl);
|
|
|
|
+ if (ifrm.attachEvent) {
|
|
|
|
+ //ie
|
|
|
|
+ ifrm.attachEvent("onload", function () {
|
|
|
|
+ that.toUploadDfs(params, defaultParam);
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ // chrome
|
|
|
|
+ ifrm.onload = function () {
|
|
|
|
+ that.toUploadDfs(params, defaultParam);
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ sortFileList(fileList) {
|
|
|
|
+ if (
|
|
|
|
+ fileList.length > 0 &&
|
|
|
|
+ fileList[0].raw &&
|
|
|
|
+ fileList[0].raw.index
|
|
|
|
+ ) {
|
|
|
|
+ fileList.sort((a, b) => {
|
|
|
|
+ return a.raw.index - b.raw.index;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ toUploadSuccess(response, file, fileList) {
|
|
|
|
+ if (this.$IEVersion() <= 10) {
|
|
|
|
+ this.ie10Control = false;
|
|
|
|
+ this.$nextTick(() => {
|
|
|
|
+ this.ie10Control = true;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.onUpSuccess(response, file, fileList);
|
|
|
|
+ this.fileList = fileList;
|
|
|
|
+ },
|
|
|
|
+ toUploadError(err, file, fileList) {
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.onUpError(err, file, fileList);
|
|
|
|
+ },
|
|
|
|
+ toUploadProgress(event, file, fileList) {
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.onUpProgress(event, file, fileList);
|
|
|
|
+ },
|
|
|
|
+ handleExceed() {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "warning",
|
|
|
|
+ message: "文件个数不能超过" + this.fileNum + "个",
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ handleChange(file, fileList) {
|
|
|
|
+ if (file.response) {
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.onUpChange(file, fileList);
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ async beforeRemove(file, fileList) {
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.onUpRemove(file, fileList);
|
|
|
|
+ this.transferDelete(file.name);
|
|
|
|
+ },
|
|
|
|
+ handleRemove(file, fileList) {
|
|
|
|
+ this.sortFileList(fileList);
|
|
|
|
+ this.fileList = fileList;
|
|
|
|
+ this.onUpChange(file, fileList);
|
|
|
|
+ },
|
|
|
|
+ handleRemoveSelf(filePath) {
|
|
|
|
+ for (let i = 0; i < this.fileList.length; i++) {
|
|
|
|
+ if (this.fileList[i].response.url === filePath) {
|
|
|
|
+ this.fileList.splice(i, 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ handlePreview(file) {
|
|
|
|
+ if (file.hasOwnProperty("status") && file.status === "success") {
|
|
|
|
+ this.currentFileData = Object.assign(file.response, file);
|
|
|
|
+ this.dialogVisible = true;
|
|
|
|
+ } else {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "warning",
|
|
|
|
+ message: "请先上传,再对文件进行预览或下载",
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ /* preViewFile() {
|
|
|
|
+ //文件预览
|
|
|
|
+ if (this.currentFileData.url) {
|
|
|
|
+ var suffixArr = this.currentFileData.name.split(".");
|
|
|
|
+ var suffix = suffixArr[suffixArr.length - 1];
|
|
|
|
+ this.$refs.preview.preViewFile({
|
|
|
|
+ name: this.currentFileData.name,
|
|
|
|
+ suffix: "." + suffix,
|
|
|
|
+ url: this.currentFileData.url,
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "warning",
|
|
|
|
+ message: "预览失败,请检查文件路径!",
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }, */
|
|
|
|
+
|
|
|
|
+ /*单文件下载*/
|
|
|
|
+ downloadFile() {
|
|
|
|
+ let that = this;
|
|
|
|
+ this.$$download(this.currentFileData)
|
|
|
|
+ .then(() => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "success",
|
|
|
|
+ message: "下载成功!",
|
|
|
|
+ });
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "info",
|
|
|
|
+ message: "下载失败!",
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ this.dialogVisible = false;
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ dialogClose() {
|
|
|
|
+ this.currentFileData = {};
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ //批量下载
|
|
|
|
+ downloadAll() {
|
|
|
|
+ let that = this;
|
|
|
|
+ let md5Path = [];
|
|
|
|
+ let list = [];
|
|
|
|
+ if (this.defaultFileList && this.defaultFileList.length > 0) {
|
|
|
|
+ list = this.defaultFileList;
|
|
|
|
+ } else {
|
|
|
|
+ list = this.fileList;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ list.forEach((item, index) => {
|
|
|
|
+ if (!!item.response.url) {
|
|
|
|
+ md5Path.push({
|
|
|
|
+ md5Path: item.response.url,
|
|
|
|
+ fileName: item.name,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ if (Array.isArray(this.downLoadAllParams.downloadFiles)) {
|
|
|
|
+ this.downLoadAllParams.downloadFiles.forEach((item) => {
|
|
|
|
+ for (var i = 0; i < md5Path.length; i++) {
|
|
|
|
+ if (
|
|
|
|
+ item.md5Path == md5Path[i].md5Path &&
|
|
|
|
+ item.fileName == md5Path[i].fileName
|
|
|
|
+ ) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (!!item.md5Path) {
|
|
|
|
+ md5Path.push({
|
|
|
|
+ md5Path: item.md5Path,
|
|
|
|
+ fileName: item.fileName,
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // let Params = Object.assign({//拼接参数
|
|
|
|
+ // downloadFiles: md5Path,
|
|
|
|
+ // }, this.downLoadAllParams);
|
|
|
|
+ let Params = {
|
|
|
|
+ downloadFiles: md5Path,
|
|
|
|
+ zipName: this.downLoadAllParams.zipName,
|
|
|
|
+ };
|
|
|
|
+ // let arr=[];
|
|
|
|
+ // Params.md5Paths.forEach((item)=>{
|
|
|
|
+ // if(!!item){
|
|
|
|
+ // arr.push(item)
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+ // Params.md5Paths = arr;
|
|
|
|
+ // Params.md5Path=[...arr];
|
|
|
|
+ if (!md5Path.length) {
|
|
|
|
+ this.$message.warning("请先上传文件!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.$$downloadPackage(Params)
|
|
|
|
+ .then(() => {
|
|
|
|
+ // that.$message({
|
|
|
|
+ // type: 'success',
|
|
|
|
+ // message: '下载成功!'
|
|
|
|
+ // })
|
|
|
|
+ })
|
|
|
|
+ .catch((err) => {
|
|
|
|
+ that.$message({
|
|
|
|
+ type: "info",
|
|
|
|
+ message: "下载失败!",
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ * 分片-切片
|
|
|
|
+ */
|
|
|
|
+ sliceChunkFile(param) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let blobSlice =
|
|
|
|
+ File.prototype.slice ||
|
|
|
|
+ File.prototype.mozSlice ||
|
|
|
|
+ File.prototype.webkitSlice;
|
|
|
|
+ let chunkSize = 1024 * 1024 * 2;
|
|
|
|
+ let filechunks = new Array(
|
|
|
|
+ Math.ceil(param.file.size / chunkSize)
|
|
|
|
+ );
|
|
|
|
+ let currrentChunk = 0;
|
|
|
|
+ let reader = new FileReader();
|
|
|
|
+ let start, end;
|
|
|
|
+ reader.onload = function (e) {
|
|
|
|
+ var chunkfile = e.target.result;
|
|
|
|
+ filechunks[currrentChunk] = {
|
|
|
|
+ chunk: currrentChunk,
|
|
|
|
+ fileSize: chunkfile.byteLength,
|
|
|
|
+ chunkSize: chunkSize,
|
|
|
|
+ chunkStart: start,
|
|
|
|
+ chunkEnd: end,
|
|
|
|
+ };
|
|
|
|
+ console.log(
|
|
|
|
+ `分片计算情况: 分片数:${filechunks.length} -- 当前片:${currrentChunk}`
|
|
|
|
+ ); // --片大小:${chunkfile.byteLength}
|
|
|
|
+ //spark.append(file);
|
|
|
|
+ currrentChunk++;
|
|
|
|
+ if (currrentChunk < filechunks.length) {
|
|
|
|
+ loadNext();
|
|
|
|
+ } else {
|
|
|
|
+ console.log("完成分片解析");
|
|
|
|
+ resolve({
|
|
|
|
+ filechunks: filechunks,
|
|
|
|
+ chunks: filechunks.length,
|
|
|
|
+ fileName: param.file.name,
|
|
|
|
+ //wholeFile: param.file //完整的文件的传递
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ reader.onerror = function () {
|
|
|
|
+ reject({ msg: "file too large" });
|
|
|
|
+ };
|
|
|
|
+ let loadNext = function () {
|
|
|
|
+ start = currrentChunk * chunkSize;
|
|
|
|
+ end =
|
|
|
|
+ start + chunkSize >= param.file.size
|
|
|
|
+ ? param.file.size
|
|
|
|
+ : start + chunkSize;
|
|
|
|
+ reader.readAsArrayBuffer(
|
|
|
|
+ blobSlice.call(param.file, start, end)
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+ loadNext();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /*
|
|
|
|
+ * 分片-查片
|
|
|
|
+ */
|
|
|
|
+ checkChunkFile(md5, fileSize) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ this.$asyncAjaxCommon(this.$api.upload.md5Check4Chunk, {
|
|
|
|
+ md5: md5,
|
|
|
|
+ fileSize: fileSize,
|
|
|
|
+ })
|
|
|
|
+ .then((res) => {
|
|
|
|
+ resolve(res);
|
|
|
|
+ })
|
|
|
|
+ .catch((res) => {
|
|
|
|
+ reject(res);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /*
|
|
|
|
+ * 分片-上传
|
|
|
|
+ */
|
|
|
|
+ uploadSingleFile(md5, fileInfo, chunk, chunks, fileName) {
|
|
|
|
+ let _this = this;
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let chunkfile = null; //片文件(实际文件)
|
|
|
|
+ //用于获取文件指定片的参数
|
|
|
|
+ let blobSlice =
|
|
|
|
+ File.prototype.slice ||
|
|
|
|
+ File.prototype.mozSlice ||
|
|
|
|
+ File.prototype.webkitSlice;
|
|
|
|
+ let reader = new FileReader();
|
|
|
|
+ reader.onload = function (e) {
|
|
|
|
+ chunkfile = e.target.result;
|
|
|
|
+ console.log(`进入了上传(第${chunk}/${chunks}片文件)`);
|
|
|
|
+ var formData = new FormData();
|
|
|
|
+ formData.append("md5", md5);
|
|
|
|
+ let blobFile = new Blob([chunkfile]);
|
|
|
|
+ formData.append("file", blobFile);
|
|
|
|
+ formData.append("chunk", chunk);
|
|
|
|
+ formData.append("chunks", chunks);
|
|
|
|
+ formData.append("fileName", fileName);
|
|
|
|
+ formData.append("uploadFileType", _this.uploadFileType);
|
|
|
|
+ _this
|
|
|
|
+ .$axios({
|
|
|
|
+ method: "post",
|
|
|
|
+ url: _this.$api.upload.upload4Chunk,
|
|
|
|
+ data: formData,
|
|
|
|
+ withCredentials: true,
|
|
|
|
+ headers: {
|
|
|
|
+ "Content-type": "multipart/form-data",
|
|
|
|
+ },
|
|
|
|
+ onUploadProgress: (progressEvent) => {
|
|
|
|
+ var precent =
|
|
|
|
+ ((progressEvent.loaded /
|
|
|
|
+ progressEvent.total) *
|
|
|
|
+ 100) |
|
|
|
|
+ 0;
|
|
|
|
+ _this.multipartPercentage =
|
|
|
|
+ (((chunk * 100 + precent) /
|
|
|
|
+ (chunks * 100)) *
|
|
|
|
+ 100) >>
|
|
|
|
+ 0;
|
|
|
|
+ },
|
|
|
|
+ })
|
|
|
|
+ .then(function (res) {
|
|
|
|
+ resolve(res);
|
|
|
|
+ })
|
|
|
|
+ .catch(function (error) {
|
|
|
|
+ reject(error);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ reader.onerror = function () {
|
|
|
|
+ alert("上传出错请联系管理员!");
|
|
|
|
+ };
|
|
|
|
+ reader.readAsArrayBuffer(
|
|
|
|
+ blobSlice.call(
|
|
|
|
+ fileInfo.wholeFile,
|
|
|
|
+ fileInfo.chunkStart,
|
|
|
|
+ fileInfo.chunkEnd
|
|
|
|
+ )
|
|
|
|
+ );
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ uploadChunkFile(allMd5, obj, indexDefualt) {
|
|
|
|
+ let index = indexDefualt;
|
|
|
|
+ let chunksNum = obj.chunks; //分片总数
|
|
|
|
+ let fileName = obj.fileName; //上传的文件名
|
|
|
|
+ let errorNum = 0;
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ let loop = async (resolve, reject) => {
|
|
|
|
+ let chunkFileInfo; //分片的详细信息{chunk:当前片的位数}
|
|
|
|
+ if (index >= chunksNum) {
|
|
|
|
+ index = null;
|
|
|
|
+ chunksNum = null;
|
|
|
|
+ resolve(true);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ chunkFileInfo = obj.filechunks[index];
|
|
|
|
+ chunkFileInfo.wholeFile = obj.wholeFile;
|
|
|
|
+ //获取单独的一片准备上传
|
|
|
|
+ var chunkReuslt = await this.uploadSingleFile(
|
|
|
|
+ allMd5,
|
|
|
|
+ chunkFileInfo,
|
|
|
|
+ chunkFileInfo.chunk,
|
|
|
|
+ chunksNum,
|
|
|
|
+ fileName
|
|
|
|
+ );
|
|
|
|
+ if (chunkReuslt.code == "200") {
|
|
|
|
+ index++;
|
|
|
|
+ loop(resolve, reject);
|
|
|
|
+ } else {
|
|
|
|
+ errorNum++;
|
|
|
|
+ if (errorNum > 10) {
|
|
|
|
+ reject(new Error("分片文件上传失败"));
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ // 再传一遍
|
|
|
|
+ loop(resolve, reject);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ loop(resolve, reject);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ /*
|
|
|
|
+ * 分片-合并
|
|
|
|
+ */
|
|
|
|
+ finishChunkFile(md5, chunks, params) {
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
+ this.$asyncAjaxCommon(this.$api.upload.finishUpload, {
|
|
|
|
+ md5: md5,
|
|
|
|
+ businessSysCode: "OA_GT_001",
|
|
|
|
+ chunks: chunks,
|
|
|
|
+ })
|
|
|
|
+ .then((res) => {
|
|
|
|
+ this.transferUploadRes({
|
|
|
|
+ file: res.fileName,
|
|
|
|
+ md5: res.md5Path,
|
|
|
|
+ url: res.md5Path,
|
|
|
|
+ });
|
|
|
|
+ let resObj = {
|
|
|
|
+ fileExt: res.fileExt,
|
|
|
|
+ secretKey: res.secretKey,
|
|
|
|
+ fileSize: res.fileSize,
|
|
|
|
+ name: res.fileName,
|
|
|
|
+ url: res.md5Path,
|
|
|
|
+ md5: res.md5Path,
|
|
|
|
+ };
|
|
|
|
+ this.$$updateAnyoneDownload(res.url)
|
|
|
|
+ .then(function (res2) {
|
|
|
|
+ params.onSuccess(Object.assign(resObj, res));
|
|
|
|
+ })
|
|
|
|
+ .catch((error) => {
|
|
|
|
+ this.$message({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: "更新预览状态失败!",
|
|
|
|
+ });
|
|
|
|
+ params.onError(error);
|
|
|
|
+ });
|
|
|
|
+ resolve(res);
|
|
|
|
+ })
|
|
|
|
+ .catch((res) => {
|
|
|
|
+ this.$ajaxError({
|
|
|
|
+ mag: "分片合并失败",
|
|
|
|
+ });
|
|
|
|
+ reject(res);
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+};
|
|
|
|
+</script>
|
|
|
|
+
|
|
|
|
+<style lang="less" scoped>
|
|
|
|
+.myupload .el-dialog__body {
|
|
|
|
+ padding: 10px 20px;
|
|
|
|
+ font-size: 16px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.myupload .el-dialog__body-myi {
|
|
|
|
+ color: #eed46f;
|
|
|
|
+ margin-right: 20px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.mytip {
|
|
|
|
+ font-size: 12px;
|
|
|
|
+ color: #909399;
|
|
|
|
+ margin: 3px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+.optItem {
|
|
|
|
+ margin-left: 15px;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/deep/ .el-upload-list {
|
|
|
|
+ width: fit-content;
|
|
|
|
+}
|
|
|
|
+</style>
|