list.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <a-card size="small" :bordered="false" class="dowloadFIle-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="创建时间">
  10. <a-range-picker
  11. id="dowloadFIle-beginDate"
  12. :disabled-date="disabledDate"
  13. v-model="time"
  14. format="YYYY-MM-DD"
  15. @change="dateChange" />
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="文件名称">
  20. <a-input id="dowloadFIle-fileName" v-model.trim="queryParam.fileName" allowClear placeholder="请输入文件名称"/>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24">
  24. <a-form-item label="状态">
  25. <v-select code="EXPORT_TASK_STATE" id="dowloadFIle-taskState" v-model="queryParam.taskState" allowClear placeholder="请选择状态"></v-select>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  29. <a-button type="primary" @click="searchForm" :disabled="disabled" id="dowloadFIle-refresh">查询</a-button>
  30. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="dowloadFIle-reset">重置</a-button>
  31. </a-col>
  32. </a-row>
  33. </a-form>
  34. </div>
  35. <!-- 总计 -->
  36. <a-alert type="info" style="margin-bottom:10px">
  37. <div slot="message">注意:所有文件只保留7天,超过7天后,不能下载</div>
  38. </a-alert>
  39. <!-- 列表 -->
  40. <s-table
  41. class="sTable fixPagination"
  42. ref="table"
  43. :style="{ height: tableHeight+84.5+'px' }"
  44. size="small"
  45. :rowKey="(record) => record.id"
  46. :columns="columns"
  47. :data="loadData"
  48. :scroll="{ y: tableHeight }"
  49. :defaultLoadData="true"
  50. bordered>
  51. <!-- 操作 -->
  52. <template slot="action" slot-scope="text, record">
  53. <a :id="'file-'+record.id" :href="record.fileUrl" style="padding: 5px 0 0 23px;display: block;" v-if="record.taskState=='SUCCESS'">下载文件</a>
  54. <span v-else>--</span>
  55. </template>
  56. </s-table>
  57. </a-spin>
  58. </a-card>
  59. </template>
  60. <script>
  61. import moment from 'moment'
  62. import { commonMixin } from '@/utils/mixin'
  63. import getDate from '@/libs/getDate.js'
  64. import { STable, VSelect } from '@/components'
  65. import { taskList, dowloadFile } from '@/api/dowloadFile'
  66. export default {
  67. name: 'DowloadFile',
  68. mixins: [commonMixin],
  69. components: { STable, VSelect },
  70. data () {
  71. const startDate = getDate.getRecentday().starttime
  72. const endDate = getDate.getRecentday().endtime
  73. return {
  74. spinning: false,
  75. tableHeight: 0,
  76. // 默认时间
  77. time: [
  78. startDate,
  79. endDate
  80. ],
  81. queryParam: { // 查询条件
  82. beginDate: startDate, // 开始时间
  83. endDate: endDate, // 结束时间
  84. fileName: '', // 文件名称
  85. taskState: undefined // 状态
  86. },
  87. disabled: false, // 查询、重置按钮是否可操作
  88. columns: [
  89. { title: '序号', dataIndex: 'no', width: '10%', align: 'center' },
  90. { title: '创建时间', dataIndex: 'createDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  91. { title: '文件名称', dataIndex: 'fileName', align: 'center', width: '40%', customRender: function (text) { return text || '--' }, ellipsis: true },
  92. { title: '状态', dataIndex: 'taskStateDictValue', align: 'center', width: '20%', customRender: function (text) { return text || '--' } },
  93. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  94. ],
  95. // 加载数据方法 必须为 Promise 对象
  96. loadData: parameter => {
  97. this.disabled = true
  98. this.spinning = true
  99. return taskList(Object.assign(parameter, this.queryParam)).then(res => {
  100. let data
  101. if (res.status == 200) {
  102. data = res.data
  103. const no = (data.pageNo - 1) * data.pageSize
  104. for (var i = 0; i < data.list.length; i++) {
  105. data.list[i].no = no + i + 1
  106. const furl = data.list[i].fileUrl
  107. data.list[i].fileUrl = furl ? furl.replace('http:', location.protocol) : ''
  108. }
  109. this.total = data.count || 0
  110. this.disabled = false
  111. }
  112. this.spinning = false
  113. return data
  114. })
  115. },
  116. total: 0, // 合计
  117. openModal: false, // 编辑 弹框
  118. openDetailModal: false, // 详情 弹框
  119. itemId: '' // 当前产品id
  120. }
  121. },
  122. methods: {
  123. // 禁用时间
  124. disabledDate (current) {
  125. return current && (current < moment(getDate.getRecentday().starttime) || current > moment().endOf('day'))
  126. },
  127. // 下载文件
  128. dowloadExcel (url) {
  129. dowloadFile(url, '')
  130. },
  131. // 时间 change
  132. dateChange (date, dateString) {
  133. this.queryParam.beginDate = dateString[0] ? moment(dateString[0]).format('YYYY-MM-DD 00:00:00') : ''
  134. this.queryParam.endDate = dateString[1] ? moment(dateString[1]).format('YYYY-MM-DD 23:59:59') : ''
  135. },
  136. // 查询
  137. searchForm () {
  138. this.$refs.table.refresh(true)
  139. },
  140. // 重置
  141. resetSearchForm () {
  142. this.time = [getDate.getRecentday().starttime, getDate.getRecentday().endtime]
  143. this.queryParam.beginDate = getDate.getRecentday().starttime
  144. this.queryParam.endDate = getDate.getRecentday().endtime
  145. this.queryParam.fileName = ''
  146. this.queryParam.type = undefined
  147. this.queryParam.taskState = undefined
  148. this.$refs.table.refresh(true)
  149. },
  150. // 页面初始化
  151. pageInit () {
  152. const _this = this
  153. this.$nextTick(() => { // 页面渲染完成后的回调
  154. _this.setTableH()
  155. })
  156. },
  157. // 表格高度计算
  158. setTableH () {
  159. const tableSearchH = this.$refs.tableSearch.offsetHeight
  160. this.tableHeight = window.innerHeight - tableSearchH - 235
  161. }
  162. },
  163. watch: {
  164. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  165. this.setTableH()
  166. }
  167. },
  168. mounted () {
  169. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  170. this.pageInit()
  171. this.resetSearchForm()
  172. }
  173. },
  174. activated () {
  175. // 如果是新页签打开,则重置当前页面
  176. if (this.$store.state.app.isNewTab) {
  177. this.pageInit()
  178. this.resetSearchForm()
  179. }
  180. // 仅刷新列表,不重置页面
  181. if (this.$store.state.app.updateList) {
  182. this.pageInit()
  183. this.$refs.table.refresh()
  184. }
  185. }
  186. }
  187. </script>