index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <a-spin :spinning="cardLoading">
  3. <a-card :bordered="false">
  4. <div class="table-page-search-wrapper" v-if="hasPerm('sysFileInfo:page')">
  5. <a-form layout="inline">
  6. <a-row :gutter="48">
  7. <a-col :md="8" :sm="24">
  8. <a-form-item label="存储位置">
  9. <a-select v-model="queryParam.fileLocation" placeholder="请选择存储位置" >
  10. <a-select-option v-for='(item,index) in fileLocationDictTypeDropDown' :key="index" :value="item.code" >{{item.value}}</a-select-option>
  11. </a-select>
  12. </a-form-item>
  13. </a-col>
  14. <a-col :md="8" :sm="24">
  15. <a-form-item label="文件仓库">
  16. <a-input v-model="queryParam.fileBucket" placeholder="请输入文件仓库"/>
  17. </a-form-item>
  18. </a-col>
  19. <template v-if="advanced">
  20. <a-col :md="8" :sm="24">
  21. <a-form-item label="文件名称">
  22. <a-input v-model="queryParam.fileOriginName" placeholder="请输入文件名称(上传时候的文件名)"/>
  23. </a-form-item>
  24. </a-col>
  25. </template>
  26. <a-col :md="!advanced && 8 || 24" :sm="24">
  27. <span class="table-page-search-submitButtons" :style="advanced && { float: 'right', overflow: 'hidden' } || {} ">
  28. <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
  29. <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
  30. <a @click="toggleAdvanced" style="margin-left: 8px">
  31. {{ advanced ? '收起' : '展开' }}
  32. <a-icon :type="advanced ? 'up' : 'down'"/>
  33. </a>
  34. </span>
  35. </a-col>
  36. </a-row>
  37. </a-form>
  38. </div>
  39. <div class="table-operator" v-if="hasPerm('sysFileInfo:upload')">
  40. <a-upload
  41. v-if="hasPerm('sysFileInfo:upload')"
  42. name="file"
  43. :multiple="true"
  44. :customRequest="customRequest"
  45. :showUploadList="false"
  46. >
  47. <a-button> <a-icon type="upload" />上传文件</a-button>
  48. </a-upload>
  49. </div>
  50. <s-table
  51. ref="table"
  52. size="default"
  53. :columns="columns"
  54. :data="loadData"
  55. :alert="true"
  56. :rowKey="(record) => record.id"
  57. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
  58. >
  59. <span slot="fileOriginName" slot-scope="text">
  60. <ellipsis :length="10" tooltip>{{text}}</ellipsis>
  61. </span>
  62. <span slot="fileObjectName" slot-scope="text">
  63. <ellipsis :length="10" tooltip>{{text}}</ellipsis>
  64. </span>
  65. <span slot="fileLocation" slot-scope="text">
  66. {{ fileLocationFilter(text) }}
  67. </span>
  68. <span slot="fileSuffix" slot-scope="text">
  69. <a-tag color="blue">{{ text }}</a-tag>
  70. </span>
  71. <span slot="action" slot-scope="text, record">
  72. <a v-if="hasPerm('sysFileInfo:download')" @click="sysFileInfoDownload(record)">下载</a>
  73. <a-divider type="vertical" v-if="hasPerm('sysFileInfo:download') & hasPerm('sysFileInfo:detail')"/>
  74. <a v-if="hasPerm('sysFileInfo:detail')" @click="$refs.detailForm.detail(record)">详情</a>
  75. <a-divider type="vertical" v-if="hasPerm('sysFileInfo:detail') & hasPerm('sysFileInfo:delete')"/>
  76. <a-popconfirm v-if="hasPerm('sysFileInfo:delete')" placement="topRight" title="确认删除?" @confirm="() => sysFileInfoDelete(record)">
  77. <a>删除</a>
  78. </a-popconfirm>
  79. <a-divider type="vertical" v-if="(hasPerm('sysFileInfo:preview') & record.fileSuffix === 'png' || record.fileSuffix === 'PNG' || record.fileSuffix === 'jpeg' || record.fileSuffix === 'JPEG'
  80. || record.fileSuffix === 'jpg' || record.fileSuffix === 'JPG' || record.fileSuffix === 'gif' || record.fileSuffix === 'GIF' ||
  81. record.fileSuffix === 'tif' || record.fileSuffix === 'TIF' || record.fileSuffix === 'bmp' || record.fileSuffix === 'BMP') & hasPerm('sysFileInfo:delete')"/>
  82. <a v-if="(hasPerm('sysFileInfo:preview') & record.fileSuffix === 'png' || record.fileSuffix === 'PNG' || record.fileSuffix === 'jpeg' || record.fileSuffix === 'JPEG'
  83. || record.fileSuffix === 'jpg' || record.fileSuffix === 'JPG' || record.fileSuffix === 'gif' || record.fileSuffix === 'GIF' ||
  84. record.fileSuffix === 'tif' || record.fileSuffix === 'TIF' || record.fileSuffix === 'bmp' || record.fileSuffix === 'BMP')" @click="$refs.previewForm.preview(record)">预览</a>
  85. </span>
  86. </s-table>
  87. <detail-form ref="detailForm" @ok="handleOk" v-if="hasPerm('sysFileInfo:detail')"/>
  88. <preview-form ref="previewForm" v-if="hasPerm('sysFileInfo:preview')"/>
  89. </a-card>
  90. </a-spin>
  91. </template>
  92. <script>
  93. import { STable,Ellipsis } from '@/components'
  94. import { sysDictTypeDropDown } from '@/api/modular/system/dictManage'
  95. import { sysFileInfoPage ,sysFileInfoDelete ,sysFileInfoUpload ,sysFileInfoDownload} from '@/api/modular/system/fileManage'
  96. import detailForm from './detailForm'
  97. import previewForm from './previewForm'
  98. export default {
  99. components: {
  100. STable,
  101. Ellipsis,
  102. detailForm,
  103. previewForm
  104. },
  105. data () {
  106. return {
  107. // 高级搜索 展开/关闭
  108. advanced: false,
  109. // 查询参数
  110. queryParam: {},
  111. // 表头
  112. columns: [
  113. {
  114. title: '存储位置',
  115. dataIndex: 'fileLocation',
  116. scopedSlots: {customRender: 'fileLocation'}
  117. },
  118. {
  119. title: '文件仓库',
  120. dataIndex: 'fileBucket'
  121. },
  122. {
  123. title: '文件名称',
  124. dataIndex: 'fileOriginName',
  125. scopedSlots: { customRender: 'fileOriginName' },
  126. },
  127. {
  128. title: '文件后缀',
  129. dataIndex: 'fileSuffix',
  130. scopedSlots: { customRender: 'fileSuffix' },
  131. },
  132. {
  133. title: '文件大小',
  134. dataIndex: 'fileSizeInfo'
  135. },
  136. {
  137. title: '唯一标识id',
  138. dataIndex: 'fileObjectName',
  139. scopedSlots: { customRender: 'fileObjectName' },
  140. },
  141. ],
  142. // 加载数据方法 必须为 Promise 对象
  143. loadData: parameter => {
  144. return sysFileInfoPage(Object.assign(parameter, this.queryParam)).then((res) => {
  145. return res.data
  146. })
  147. },
  148. cardLoading:false,
  149. fileLocationDictTypeDropDown:[],
  150. selectedRowKeys: [],
  151. selectedRows: [],
  152. }
  153. },
  154. created(){
  155. this.sysDictTypeDropDown()
  156. if(this.hasPerm('sysPos:edit') || this.hasPerm('sysPos:delete')){
  157. this.columns.push({
  158. title: '操作',
  159. width: '200px',
  160. dataIndex: 'action',
  161. scopedSlots: { customRender: 'action' }
  162. })
  163. }
  164. },
  165. methods: {
  166. fileLocationFilter (fileLocation) {
  167. const fileLocation_value = this.fileLocationDictTypeDropDown.filter(item => item.code == fileLocation)
  168. if(fileLocation_value.length>0){
  169. return fileLocation_value[0].value
  170. }
  171. },
  172. /**
  173. * 获取字典数据
  174. */
  175. sysDictTypeDropDown(){
  176. sysDictTypeDropDown({code:'file_storage_location'}).then((res)=>{
  177. this.fileLocationDictTypeDropDown=res.data
  178. })
  179. },
  180. /**
  181. * 下载文件(所有文件)
  182. */
  183. sysFileInfoDownload(record){
  184. this.cardLoading = true
  185. sysFileInfoDownload({id:record.id}).then((res)=>{
  186. this.cardLoading = false
  187. this.downloadfile(res)
  188. }).catch((err)=>{
  189. this.cardLoading = false
  190. this.$message.error('下载错误:获取文件流错误')
  191. })
  192. },
  193. downloadfile(res) {
  194. var blob = new Blob([res.data], {type: 'application/octet-stream;charset=UTF-8'});
  195. var contentDisposition = res.headers['content-disposition'];
  196. var patt = new RegExp("filename=([^;]+\\.[^\\.;]+);*");
  197. var result = patt.exec(contentDisposition);
  198. var filename = result[1];
  199. var downloadElement = document.createElement('a');
  200. var href = window.URL.createObjectURL(blob); //创建下载的链接
  201. var reg = /^["](.*)["]$/g;
  202. downloadElement.style.display = 'none';
  203. downloadElement.href = href;
  204. downloadElement.download = decodeURI(filename.replace(reg,"$1")); //下载后文件名
  205. document.body.appendChild(downloadElement);
  206. downloadElement.click(); //点击下载
  207. document.body.removeChild(downloadElement); //下载完成移除元素
  208. window.URL.revokeObjectURL(href);
  209. },
  210. sysFileInfoDelete(record){
  211. sysFileInfoDelete(record).then((res)=>{
  212. if(res.success) {
  213. this.$message.success('删除成功')
  214. this.$refs.table.refresh()
  215. }else{
  216. this.$message.error('删除失败:'+res.message)
  217. }
  218. }).catch((err)=>{
  219. this.$message.error('删除错误:'+err.message)
  220. })
  221. },
  222. toggleAdvanced () {
  223. this.advanced = !this.advanced
  224. },
  225. /**
  226. * 上传文件
  227. */
  228. customRequest(data){
  229. const formData = new FormData()
  230. formData.append('file', data.file)
  231. sysFileInfoUpload(formData).then((res) => {
  232. if (res.success) {
  233. this.$message.success('上传成功');
  234. this.$refs.table.refresh()
  235. } else {
  236. this.$message.error('上传失败:' + res.message);
  237. }
  238. })
  239. },
  240. handleOk () {
  241. this.$refs.table.refresh()
  242. },
  243. onSelectChange (selectedRowKeys, selectedRows) {
  244. this.selectedRowKeys = selectedRowKeys
  245. this.selectedRows = selectedRows
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="less">
  251. .table-operator {
  252. margin-bottom: 18px;
  253. }
  254. button {
  255. margin-right: 8px;
  256. }
  257. </style>