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.

272 lines
8.5 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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: "profingFile",
  7. components: {UploadFileList},
  8. props:{
  9. testNo:{
  10. type:String,
  11. },
  12. height:{
  13. type:Number,
  14. default:300
  15. },
  16. },
  17. data(){
  18. return{
  19. uploadDialog:false,
  20. fileRemark:'',
  21. token:'',
  22. fileList:[],
  23. dataList:[],
  24. columnList:[
  25. {
  26. userId: this.$store.state.user.name,
  27. functionId: 104001,
  28. serialNumber: '104001Table4FileName',
  29. tableId: '104001Table4',
  30. tableName: '文件信息表',
  31. columnProp: 'fileName',
  32. headerAlign: 'center',
  33. align: 'center',
  34. columnLabel: '文件名称',
  35. columnHidden: false,
  36. columnImage: false,
  37. columnSortable: false,
  38. sortLv: 0,
  39. status: true,
  40. fixed: '',
  41. },
  42. {
  43. userId: this.$store.state.user.name,
  44. functionId: 104001,
  45. serialNumber: '104001Table4FileRemark',
  46. tableId: '104001Table4',
  47. tableName: '文件信息表',
  48. columnProp: 'fileRemark',
  49. headerAlign: 'center',
  50. align: 'center',
  51. columnLabel: '备注',
  52. columnHidden: false,
  53. columnImage: false,
  54. columnSortable: false,
  55. sortLv: 0,
  56. status: true,
  57. fixed: '',
  58. },
  59. {
  60. userId: this.$store.state.user.name,
  61. functionId: 104001,
  62. serialNumber: '104001Table4CreateDate',
  63. tableId: '104001Table4',
  64. tableName: '文件信息表',
  65. columnProp: 'createDate',
  66. headerAlign: 'center',
  67. align: 'center',
  68. columnLabel: '上传时间',
  69. columnHidden: false,
  70. columnImage: false,
  71. columnSortable: false,
  72. sortLv: 0,
  73. status: true,
  74. fixed: '',
  75. },
  76. {
  77. userId: this.$store.state.user.name,
  78. functionId: 104001,
  79. serialNumber: '104001Table4CreatedBy',
  80. tableId: '104001Table4',
  81. tableName: '文件信息表',
  82. columnProp: 'createBy',
  83. headerAlign: 'center',
  84. align: 'center',
  85. columnLabel: '上传人',
  86. columnHidden: false,
  87. columnImage: false,
  88. columnSortable: false,
  89. sortLv: 0,
  90. status: true,
  91. fixed: '',
  92. }
  93. ],
  94. }
  95. },
  96. methods:{
  97. getFileContentList(){
  98. let params = {
  99. orderRef1:this.$store.state.user.site,
  100. orderRef2:this.testNo
  101. }
  102. getFileContentList(params).then(({data})=>{
  103. if (data && data.code === 0){
  104. this.dataList=data.rows
  105. }else {
  106. this.$message.warning(data.msg)
  107. }
  108. }).catch((error)=>{
  109. this.$message.error(error)
  110. })
  111. },
  112. downloadFile (row) {
  113. downLoadQuotationFile(row).then(({data}) => {
  114. // 不限制文件下载类型
  115. const blob = new Blob([data], {type:'application/octet-stream;charset=utf-8'})
  116. // 下载文件名称
  117. const fileName = row.fileName
  118. // a标签下载
  119. const linkNode = document.createElement('a')
  120. linkNode.download = fileName // a标签的download属性规定下载文件的名称
  121. linkNode.style.display = 'none'
  122. linkNode.href = URL.createObjectURL(blob) // 生成一个Blob URL
  123. document.body.appendChild(linkNode)
  124. linkNode.click() // 模拟在按钮上的一次鼠标单击
  125. URL.revokeObjectURL(linkNode.href) // 释放URL 对象
  126. document.body.removeChild(linkNode)
  127. })
  128. },
  129. removeFile(row){
  130. this.$confirm('确定要删除此文件?', '提示', {
  131. confirmButtonText: '确定',
  132. cancelButtonText: '取消',
  133. type: 'warning'
  134. }).then(() => {
  135. deleteQuotationFile(row).then(({data}) => {
  136. if (data && data.code === 0) {
  137. this.getFileContentList()
  138. } else {
  139. this.$alert(data.msg, '错误', {
  140. confirmButtonText: '确定'
  141. })
  142. }
  143. })
  144. }).catch(() => {
  145. })
  146. },
  147. previewFile(row){
  148. // 预览文件
  149. let image = ['jpg', 'jpeg', 'png', 'gif', 'bmp'];
  150. let type = '';
  151. if (image.includes(row.fileType.toLowerCase())){
  152. type = 'image/' + row.fileType;
  153. }
  154. let video = ['mp4', 'avi', 'mov', 'wmv', 'flv'];
  155. if (video.includes(row.fileType.toLowerCase())){
  156. type = 'video/' + row.fileType;
  157. }
  158. let txt = ['txt'];
  159. if (txt.includes(row.fileType.toLowerCase())){
  160. type = 'text/plain';
  161. }
  162. let office = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx'];
  163. if (office.includes(row.fileType.toLowerCase())){
  164. // if (row.fileType.toLowerCase() === 'doc' || row.fileType.toLowerCase() === 'docx'){
  165. // type = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
  166. // } else if (row.fileType.toLowerCase() === 'ppt' || row.fileType.toLowerCase() === 'pptx'){
  167. // type = 'application/vnd.openxmlformats-officedocument.presentationml.presentation';
  168. // } else {
  169. // type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
  170. // }
  171. this.$message.warning(`该文件格式暂不支持预览`)
  172. return
  173. }
  174. let pdf = ['pdf'];
  175. if (pdf.includes(row.fileType.toLowerCase())){
  176. type = 'application/pdf';
  177. }
  178. if (type === ''){
  179. this.$message.warning(`该文件格式暂不支持预览`)
  180. return;
  181. }
  182. downLoadQuotationFile(row).then(({data}) => {
  183. const blob = new Blob([data], { type: type });
  184. // 创建URL来生成预览
  185. const fileURL = URL.createObjectURL(blob);
  186. // 在新标签页中打开文件预览
  187. const newTab = window.open(fileURL, '_blank');
  188. });
  189. },
  190. downloadBtn(){
  191. if (this.selectionFile.length < 1){
  192. this.$message.warning('请选择需要下载的文件')
  193. return
  194. }
  195. for (let i = 0; i < this.selectionFile.length; i++) {
  196. this.downloadFile(this.selectionFile[i])
  197. }
  198. },
  199. handleSelectionChange(val){
  200. this.selectionFile = val
  201. }
  202. },
  203. watch:{
  204. uploadDialog(newValue,oldValue){
  205. if (newValue === false){
  206. this.getFileContentList();
  207. }
  208. },
  209. testNo(newValue,oldValue){
  210. if (newValue){
  211. this.getFileContentList();
  212. }
  213. },
  214. }
  215. }
  216. </script>
  217. <template>
  218. <div>
  219. <div style="margin: 5px 0px">
  220. <el-button type="primary" @click="uploadDialog = true">上传文件</el-button>
  221. <el-button type="primary" @click="downloadBtn" >下载</el-button>
  222. </div>
  223. <el-table
  224. :height="height"
  225. :data="dataList"
  226. border
  227. @selection-change="handleSelectionChange"
  228. style="width: 100%">
  229. <el-table-column type="selection" label="序号" align="center"/>
  230. <el-table-column
  231. v-for="(item,index) in columnList" :key="index"
  232. :sortable="item.columnSortable"
  233. :prop="item.columnProp"
  234. :header-align="item.headerAlign"
  235. :show-overflow-tooltip="item.showOverflowTooltip"
  236. :align="item.align"
  237. :fixed="item.fixed===''?false:item.fixed"
  238. :min-width="item.columnWidth"
  239. :label="item.columnLabel">
  240. <template slot-scope="scope">
  241. <span v-if="!item.columnHidden">{{scope.row[item.columnProp]}}</span>
  242. <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
  243. </template>
  244. </el-table-column>
  245. <el-table-column
  246. fixed="right"
  247. header-align="center"
  248. align="center"
  249. width="120"
  250. label="操作">
  251. <template slot-scope="{row,$index}">
  252. <!-- <el-link style="cursor:pointer;" @click="downloadFile(row)">下载</el-link>-->
  253. <el-link style="cursor:pointer;" @click="removeFile(row)">删除</el-link>
  254. <el-link style="cursor:pointer;" @click="previewFile(row)">预览</el-link>
  255. </template>
  256. </el-table-column>
  257. </el-table>
  258. <upload-file-list folder="testFile" :label="'测试单号:'" :file-list.sync="fileList" :no="testNo" :upload-dialog.sync="uploadDialog" path="/upload/test"></upload-file-list>
  259. </div>
  260. </template>
  261. <style scoped>
  262. </style>