detail.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <el-dialog
  3. title="历史版本"
  4. :visible.sync="dialogVisible"
  5. width="50%"
  6. :before-close="handleClose"
  7. >
  8. <template>
  9. <el-table
  10. :data="tableData"
  11. style="width: 100%"
  12. stripe
  13. :header-cell-style="{ background: '#F7F7F7' }"
  14. >
  15. <el-table-column
  16. prop="name"
  17. align="center"
  18. show-overflow-tooltip
  19. label="文件名称"
  20. width="180"
  21. >
  22. </el-table-column>
  23. <el-table-column
  24. prop="docUrl"
  25. align="center"
  26. show-overflow-tooltip
  27. label="链接地址"
  28. width="180"
  29. >
  30. </el-table-column>
  31. <el-table-column
  32. prop="createUser"
  33. align="center"
  34. show-overflow-tooltip
  35. label="创建人"
  36. >
  37. </el-table-column>
  38. <el-table-column
  39. prop="createTime"
  40. align="center"
  41. show-overflow-tooltip
  42. label="创建时间"
  43. >
  44. </el-table-column>
  45. <el-table-column label="操作" align="center">
  46. <template slot-scope="scope">
  47. <el-button type="text" @click="download(scope.row)">下载</el-button>
  48. </template>
  49. </el-table-column>
  50. </el-table>
  51. </template>
  52. <span slot="footer" class="dialog-footer">
  53. <el-button size="small" @click="dialogVisible = false">取 消</el-button>
  54. </span>
  55. </el-dialog>
  56. </template>
  57. <script>
  58. import * as api from '@/api/api'
  59. export default {
  60. data() {
  61. return {
  62. dialogVisible: false,
  63. tableData: []
  64. }
  65. },
  66. methods: {
  67. handleClose() {
  68. this.dialogVisible = false
  69. },
  70. openClose(val) {
  71. this.dialogVisible = true
  72. this.listDataInit(val)
  73. },
  74. /**
  75. * @method 历史版本信息
  76. * **/
  77. listDataInit(val) {
  78. let code = {
  79. id: val.id
  80. }
  81. api.GET('/doc/getDocHistoryList', code).then(data => {
  82. if (data.code == 0) {
  83. this.tableData = data.data
  84. }
  85. })
  86. },
  87. /**
  88. * @method 下载
  89. * **/
  90. download(val) {
  91. fetch(val.docUrl, {
  92. method: 'get',
  93. responseType: 'arraybuffer'
  94. })
  95. .then(function (res) {
  96. if (res.status !== 200) {
  97. return res.json()
  98. }
  99. return res.arrayBuffer()
  100. })
  101. .then(blobRes => {
  102. // 生成 Blob 对象,设置 type 等信息
  103. const e = new Blob([blobRes], {
  104. type: 'application/octet-stream',
  105. 'Content-Disposition': 'attachment'
  106. })
  107. // 将 Blob 对象转为 url
  108. let formName = val.name + '.pdf'
  109. const link = window.URL.createObjectURL(e)
  110. this.handleFileDownload(link, formName)
  111. })
  112. .catch(err => {
  113. console.error(err)
  114. })
  115. },
  116. handleFileDownload(url, filename) {
  117. // 创建 a 标签
  118. let a = document.createElement('a')
  119. a.href = url
  120. a.download = filename
  121. a.click()
  122. }
  123. }
  124. }
  125. </script>