Commit 171a1a43 authored by wangxl's avatar wangxl

444

parent 9fc6e92c
......@@ -4,10 +4,10 @@
<div>
<document-view :fileUrl="file.downloadUrl" :fileName="file.fileName" :imageArray="[file.downloadUrl]"></document-view>
</div>
<a-icon type="delete" class="hover-pointer d-icon" @click="deletefile(file)" style="margin: 0px 2px;" />
<a-icon type="delete" class="hover-pointer d-icon" @click="deletefile(file)" style="margin: 0px 4px;" />
</div>
<div v-else>
<a-form-model-item :prop="name +'.'+ index + '.downloadUrl'" :rules="{required: true, message: '请上传附件',trigger: 'blur',}">
<a-form-model-item :prop="name +'.'+ index + '.downloadUrl'" :rules="{required: file.isRequired, message: '请上传附件',trigger: 'blur',}">
<input type="file" :ref="name +'fileElem' + index" class="visually-hidden" @change="handleFiles(file, index)" />
<a-button @click="fileSelect(index)"><a-icon type="upload" />选择文件</a-button>
</a-form-model-item>
......@@ -26,12 +26,6 @@ export default {
};
},
props: {
value: {
type: Object,
default: () => {
return null
}
},
file: {
type: Object,
default: () => {
......@@ -50,23 +44,29 @@ export default {
return 0
},
},
format: {
type: Array,
default () {
return []
}
},
},
created () {
},
methods: {
deletefile (item) {
this.$api.base.deletefile({ id: item.downloadId }).then(({ data = {} }) => {
deletefile (obj) {
this.$api.base.deletefile({ id: obj.downloadId }).then(({ data = {} }) => {
if (data) {
item.fileName = ''
item.downloadUrl = ''
item.downloadId = ''
obj.fileName = null
obj.downloadUrl = null
obj.downloadId = null
}
}).catch(() => {
this.$message.error('删除失败')
})
},
handleFiles (item, index) {
handleFiles (obj, index) {
let fileElem = this.$refs[this.name + 'fileElem' + index]
let files = fileElem.files
if (files.length <= 0) {
......@@ -77,9 +77,9 @@ export default {
return
this.$api.base.asyncUpload(this.uploadHandle(files[0], files[0].name)).then(({ data = {} }) => {
if (data) {
item.fileName = files[0].name
item.downloadUrl = data.downloadUrl
item.downloadId = data.id
obj.fileName = files[0].name
obj.downloadUrl = data.downloadUrl
obj.downloadId = data.id
} else
this.$message.error('上传失败')
}).catch(() => {
......@@ -93,13 +93,15 @@ export default {
this.$message.error('文件大小不能超过15M!');
return false
}
// var fileNames = file.name.split('.')
// var fileType = fileNames[fileNames.length - 1].toLocaleLowerCase()
// var extList = ['doc', 'docx', 'pdf']
// if (!extList.find((item) => item == fileType)) {
// this.$message.error('文件格式错误!')
// return false
// }
if (!!this.format && this.format.length > 0) {
var fileNames = file.name.split('.')
var fileType = fileNames[fileNames.length - 1].toLocaleLowerCase()
var extList = this.format
if (!extList.find((e) => e == fileType)) {
this.$message.error('文件格式错误!')
return false
}
}
return true
},
uploadHandle (file, fileName) {
......@@ -114,14 +116,10 @@ export default {
fileElem.click()
}
},
},
watch: {
value: {
handler (value) {
downloadfile () {
},
}
}
},
};
</script>
<style scoped lang="less">
......
......@@ -110,9 +110,9 @@ export default {
this.$message.error('文件大小不能超过15M!');
return false
}
if (!!this.format && this.format.length > 0) {
var fileNames = file.name.split('.')
var fileType = fileNames[fileNames.length - 1].toLocaleLowerCase()
if (!!this.format && this.format.length > 0) {
var extList = this.format
if (!extList.find((item) => item == fileType)) {
this.$message.error('文件格式错误!')
......
......@@ -21,7 +21,7 @@
<a-divider style="height: 1px; background-color: #e8e8e8;" />
<div class="submit-btn">
<a-button type="primary" @click="exportData" icon="download">Excel</a-button>
<!-- <a-button type="primary" @click="scoreClick" icon="download">评分</a-button> -->
<a-button type="primary" @click="scoreClick" icon="download">评分</a-button>
</div>
<a-table :dataSource="tableData" :columns="columns" :scroll="{ x: 'max-content' }" rowKey="id" :pagination="false" :loading="loading">
<template slot="projName" slot-scope="record">
......
......@@ -60,23 +60,13 @@
</a-form-model-item>
</a-col>
<a-col :span="2">
<div class="special-middle" style="text-align: center;"><div>{{ item.isRequired == true ? "是" : "否" }}</div></div>
<div class="special-middle" style="text-align: center;">
<div>{{ item.isRequired == true ? "是" : "否" }}</div>
</div>
</a-col>
<a-col :span="10">
<div class="special-middle">
<div v-if="item.downloadUrl" class="file-box">
<div>
<a-icon type="file" style="margin-right: 8px" />
<span class="hover-pointer" @click="downloadfile(item)">{{item.fileName}}</span>
</div>
<a-icon type="delete" class="hover-pointer d-icon" @click="deletefile(item, index)" />
</div>
<div v-else>
<a-form-model-item :prop="'fileList.' + index + '.downloadUrl'" :rules="{required: item.isRequired, message: '请上传附件',trigger: 'blur',}">
<input type="file" :ref="'fileElem' + index" class="visually-hidden" @change="handleFiles(item, index)" />
<a-button @click="fileSelect(item, index)"><a-icon type="upload" />选择文件</a-button>
</a-form-model-item>
</div>
<file-load :file.sync="fileList[index]" :index="index" :name="'fileList'" />
</div>
</a-col>
<a-col :span="4">
......@@ -104,7 +94,7 @@
</template>
<script>
const File = { fileName: "", downloadUrl: "", fileExplain: "", downloadId: "", isRequired: false, required: false };
const File = { fileName: null, downloadUrl: null, fileExplain: null, downloadId: null, isRequired: false, required: false };
export default {
name: "fileEdit",
......@@ -116,68 +106,13 @@ export default {
},
},
},
created() {},
data() {
created () { },
data () {
return {
mustAttachment: [ 0, 1 ],
mustAttachment: [0, 1],
};
},
methods: {
downloadfile() {
},
deletefile (item, index) {
this.$api.base.deletefile({ id: item.downloadId }).then(({ data = {} }) => {
if (data) {
item.fileName = ''
item.downloadUrl = ''
item.downloadId = ''
}
}).catch(() => {
this.$message.error('删除失败')
})
},
uploadHandle (file, fileName) {
let formData = new FormData()
formData.append('file', file)
formData.append('fileName', fileName)
return formData
},
handleFiles(item, index) {
let fileElem = this.$refs['fileElem' + index][0]
let files = fileElem.files
if (files.length <= 0) {
this.$message.error('未选中文件,请尝试重新选择')
return
}
if (!this.fileCheck(files[0]))
return
this.$api.base.asyncUpload(this.uploadHandle(files[0], files[0].name)).then(({ data = {} }) => {
if (data) {
item.fileName = files[0].name
item.downloadUrl = '/' + files[0].name
item.downloadId = data.id
} else
this.$message.error('上传失败')
}).catch(() => {
this.$message.error('上传失败')
})
},
fileSelect (item, index) {
let fileElem = this.$refs['fileElem' + index][0]
if (fileElem) {
fileElem.click()
}
},
fileCheck (file) {
//判断是否小于1M
let isLtSize = file.size < 1024 * 1024 * 15;
if (!isLtSize) {
this.$message.error('文件大小不能超过15M!');
return false
}
return true
},
// 添加附件
addfileList () {
this.fileList.push(Object.assign({ ...File }, { fileExplain: '' }))
......
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