plm前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
5.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <script>
  2. import UploadFileList from "../../common/uploadFileList.vue";
  3. import {downloadFileList, getFileContentList, removeFile} from "../../../../api/test/testInformation";
  4. import {deleteQuotationFile, downLoadQuotationFile} from "../../../../api/quotation/quotationInformation";
  5. export default {
  6. name: "testFile",
  7. components: {UploadFileList},
  8. props:{
  9. dataList:{
  10. type: Array,
  11. default: ()=>[],
  12. },
  13. testNo:{
  14. type:String,
  15. },
  16. columnList:{
  17. type: Array,
  18. default: ()=>[],
  19. },
  20. height:{
  21. type:Number,
  22. default:300
  23. },
  24. },
  25. model:{
  26. prop:"dataList",
  27. event:"change"
  28. },
  29. data(){
  30. return{
  31. uploadDialog:false,
  32. fileRemark:'',
  33. token:'',
  34. fileList:[],
  35. }
  36. },
  37. methods:{
  38. getFileContentList(){
  39. let params = {
  40. orderRef1:this.$store.state.user.site,
  41. orderRef2:this.testNo
  42. }
  43. getFileContentList(params).then(({data})=>{
  44. if (data && data.code === 0){
  45. this.$emit("change",data.rows)
  46. }else {
  47. this.$message.warning(data.msg)
  48. }
  49. }).catch((error)=>{
  50. this.$message.error(error)
  51. })
  52. },
  53. downloadFile (row) {
  54. downLoadQuotationFile(row).then(({data}) => {
  55. // 不限制文件下载类型
  56. const blob = new Blob([data], {type:'application/octet-stream;charset=utf-8'})
  57. // 下载文件名称
  58. const fileName = row.fileName
  59. // a标签下载
  60. const linkNode = document.createElement('a')
  61. linkNode.download = fileName // a标签的download属性规定下载文件的名称
  62. linkNode.style.display = 'none'
  63. linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
  64. document.body.appendChild(linkNode)
  65. linkNode.click() // 模拟在按钮上的一次鼠标单击
  66. URL.revokeObjectURL(linkNode.href) // 释放URL 对象
  67. document.body.removeChild(linkNode)
  68. })
  69. },
  70. removeFile(row){
  71. this.$confirm('确定要删除此文件?', '提示', {
  72. confirmButtonText: '确定',
  73. cancelButtonText: '取消',
  74. type: 'warning'
  75. }).then(() => {
  76. deleteQuotationFile(row).then(({data}) => {
  77. if (data && data.code === 0) {
  78. this.getFileContentList()
  79. } else {
  80. this.$alert(data.msg, '错误', {
  81. confirmButtonText: '确定'
  82. })
  83. }
  84. })
  85. }).catch(() => {
  86. })
  87. },
  88. previewFile(row){
  89. // 预览文件
  90. let type = '';
  91. let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];
  92. if (image.includes(row.fileType.toLowerCase())){
  93. type = 'image/' + row.fileType;
  94. }
  95. let video = ['mp4', 'avi', 'mov', 'wmv', 'flv'];
  96. if (video.includes(row.fileType.toLowerCase())){
  97. type = 'video/' + row.fileType;
  98. }
  99. let txt = ['txt'];
  100. if (txt.includes(row.fileType.toLowerCase())){
  101. type = 'text/plain';
  102. }
  103. let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'];
  104. if (office.includes(row.fileType.toLowerCase())){
  105. this.$message.warning(`该文件格式暂不支持预览`)
  106. return
  107. }
  108. let pdf = ['pdf'];
  109. if (pdf.includes(row.fileType.toLowerCase())){
  110. type = 'application/pdf';
  111. }
  112. if (type === ''){
  113. this.$message.warning(`该文件格式暂不支持预览`)
  114. return;
  115. }
  116. downLoadQuotationFile(row).then(({data}) => {
  117. const blob = new Blob([data], { type: type });
  118. // 创建URL来生成预览
  119. const fileURL = URL.createObjectURL(blob);
  120. // 在新标签页中打开文件预览
  121. const newTab = window.open(fileURL, '_blank');
  122. });
  123. },
  124. downloadBtn(){
  125. if (this.selectionFile.length < 1){
  126. this.$message.warning('请选择需要下载的文件')
  127. return
  128. }
  129. for (let i = 0; i < this.selectionFile.length; i++) {
  130. this.downloadFile(this.selectionFile[i])
  131. }
  132. },
  133. handleSelectionChange(val){
  134. this.selectionFile = val
  135. }
  136. },
  137. watch:{
  138. uploadDialog(newValue,oldValue){
  139. if (newValue === false){
  140. this.getFileContentList();
  141. }
  142. },
  143. }
  144. }
  145. </script>
  146. <template>
  147. <div>
  148. <div style="margin: 5px 0px">
  149. <el-button type="primary" @click="uploadDialog = true">上传文件</el-button>
  150. <el-button type="primary" @click="downloadBtn" >下载</el-button>
  151. </div>
  152. <el-table
  153. :height="height"
  154. :data="dataList"
  155. border
  156. @selection-change="handleSelectionChange"
  157. style="width: 100%">
  158. <el-table-column type="selection" label="序号" align="center"/>
  159. <el-table-column
  160. v-for="(item,index) in columnList" :key="index"
  161. :sortable="item.columnSortable"
  162. :prop="item.columnProp"
  163. :header-align="item.headerAlign"
  164. :show-overflow-tooltip="item.showOverflowTooltip"
  165. :align="item.align"
  166. :fixed="item.fixed===''?false:item.fixed"
  167. :min-width="item.columnWidth"
  168. :label="item.columnLabel">
  169. <template slot-scope="scope">
  170. <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
  171. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
  172. </template>
  173. </el-table-column>
  174. <el-table-column
  175. fixed="right"
  176. header-align="center"
  177. align="center"
  178. width="120"
  179. label="操作">
  180. <template slot-scope="{row,$index}">
  181. <!-- <el-link style="cursor:pointer;" @click="downloadFile(row)">下载</el-link>-->
  182. <el-link style="cursor:pointer;" @click="removeFile(row)">删除</el-link>
  183. <el-link style="cursor:pointer;" @click="previewFile(row)">预览</el-link>
  184. </template>
  185. </el-table-column>
  186. </el-table>
  187. <upload-file-list folder="testFile" :label="'测试单号:'" :file-list.sync="fileList" :no="testNo" :upload-dialog.sync="uploadDialog" path="/upload/test"></upload-file-list>
  188. </div>
  189. </template>
  190. <style scoped>
  191. </style>