|
|
@@ -0,0 +1,157 @@
|
|
|
+<template>
|
|
|
+ <el-upload
|
|
|
+ ref="uploadMy"
|
|
|
+ class="upload-demo"
|
|
|
+ action="#"
|
|
|
+ :accept='accept'
|
|
|
+ :on-preview="handlePreview"
|
|
|
+ :on-progress="handleProgress"
|
|
|
+ :on-remove="handleRemove"
|
|
|
+ :before-remove="beforeRemove"
|
|
|
+ :on-change="handleChange"
|
|
|
+ multiple
|
|
|
+ :auto-upload="false"
|
|
|
+ :file-list="listFile">
|
|
|
+ <el-button icon="el-icon-upload2" type="primary" size="mini" >上传文件</el-button>
|
|
|
+ </el-upload>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ name: "index",
|
|
|
+ props:["bindData","folderid",'title','accept'],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ listFile: [],
|
|
|
+ params: {
|
|
|
+ "classname": "system.attachment.huawei.OBS",
|
|
|
+ "method": "getFileName",
|
|
|
+ "content": {
|
|
|
+ "filename": '',
|
|
|
+ "filetype": '',
|
|
|
+ "parentid": ""//归属文件夹ID
|
|
|
+ }
|
|
|
+ },
|
|
|
+ count:0,
|
|
|
+ file: {},
|
|
|
+ filelist: [],
|
|
|
+ oldCount:0
|
|
|
+ };
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ async handleRemove(file, fileList) {
|
|
|
+ this.$emit('uploadGet')
|
|
|
+ const res = await this.$api.requested({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "deleteFileLink",
|
|
|
+ "content": {
|
|
|
+ "linksids":[file.linksid]
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.oldCount = this.oldCount - 1
|
|
|
+ this.$emit('onSuccess',res)
|
|
|
+ },
|
|
|
+ handleProgress(file,fileList){
|
|
|
+
|
|
|
+ },
|
|
|
+ handlePreview(file) {
|
|
|
+ /*this.fileList = fileList*/
|
|
|
+ },
|
|
|
+ beforeRemove(file, fileList) {
|
|
|
+ return this.$confirm(`确定移除 ${ file.name }?`);
|
|
|
+ },
|
|
|
+ handleChange (file, filelist) {
|
|
|
+ this.$emit('uploadGet')
|
|
|
+ this.filelist = []
|
|
|
+ this.filelist = filelist
|
|
|
+ var index = file.raw.name.lastIndexOf(".");
|
|
|
+ var ext = file.name.substr(index + 1);
|
|
|
+ this.params.content.filename = file.raw.name
|
|
|
+ this.params.content.filetype = ext
|
|
|
+ this.getUploadUrl(file, ext)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取华为云上传地址
|
|
|
+ async getUploadUrl (file, ext) {
|
|
|
+ this.params.content.parentid = this.folderid
|
|
|
+ const res = await this.$api.requested(this.params)
|
|
|
+ let url = res.data.uploadurl
|
|
|
+ let obsfilename = res.data.serialfilename
|
|
|
+
|
|
|
+ this.upoladFileToServer(url, file, ext, obsfilename)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传到华为云
|
|
|
+ async upoladFileToServer (url, file, ext, obsfilename) {
|
|
|
+ console.log(file)
|
|
|
+ let THIS = this
|
|
|
+ let config = {
|
|
|
+ headers: ext === 'pdf' ? { 'Content-Type': 'application/pdf' } : ext === 'svg'?{ 'Content-Type': 'image/svg+xml' } : { 'Content-Type': 'application/octet-stream' },
|
|
|
+ onUploadProgress: function (progressEvent) {
|
|
|
+ let percent = progressEvent.loaded / progressEvent.total * 100
|
|
|
+ THIS.filelist.forEach(e => {
|
|
|
+ if (e.uid === file.uid) {
|
|
|
+ THIS.$set(e, 'type', ext.toUpperCase());
|
|
|
+ THIS.$set(e, 'progress', percent);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ }
|
|
|
+ const res = await this.$upload.hw_upload(url, file.raw, config)
|
|
|
+ this.createFileRecord(obsfilename)
|
|
|
+ },
|
|
|
+
|
|
|
+ // 上传成功以后生成附件记录
|
|
|
+ async createFileRecord (obsfilename,attinfos) {
|
|
|
+ let obj = {
|
|
|
+ "serialfilename": obsfilename
|
|
|
+ }
|
|
|
+ obj = Object.assign({},obj,this.bindData)
|
|
|
+ let param = {
|
|
|
+ "classname": "system.attachment.huawei.OBS",
|
|
|
+ "method": "uploadSuccess",
|
|
|
+ "content":obj
|
|
|
+ }
|
|
|
+ const res = await this.$api.requested(param)
|
|
|
+ console.log("上传文件",res)
|
|
|
+ this.count++
|
|
|
+ console.log(this.count,'count')
|
|
|
+ console.log(this.filelist.length,'length')
|
|
|
+ if (this.count == this.filelist.length - this.oldCount) {
|
|
|
+ this.oldCount = this.oldCount + this.count
|
|
|
+ this.count = 0
|
|
|
+ console.log(this.count,'count')
|
|
|
+ console.log('触发');
|
|
|
+ this.$refs.uploadMy.clearFiles()
|
|
|
+ this.filelist = []
|
|
|
+ this.$emit('onSuccess',res)
|
|
|
+ }
|
|
|
+ // if (res.code === 1) {
|
|
|
+ // this.$emit('onSuccess',res)
|
|
|
+ // }
|
|
|
+ },
|
|
|
+ async uploadSuccess(){
|
|
|
+ const res = await this.$api.requested({
|
|
|
+ "classname": "system.attachment.Attachment",
|
|
|
+ "method": "queryFileLink",
|
|
|
+ "content": {
|
|
|
+ "ownertable": 'sa_quotedprice',
|
|
|
+ "ownerid": this.ownerid,
|
|
|
+ "usetype":""
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+/deep/ .el-upload {
|
|
|
+ display: inline-block;
|
|
|
+ text-align: left;
|
|
|
+ cursor: pointer;
|
|
|
+ outline: 0;
|
|
|
+}
|
|
|
+</style>
|