zhangherong
2025-03-05 e2105dc94d2f03070398114ea47fba8f9105dee8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
<template>
  <a-card
    :bordered="false"
    title=""
  >
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form
        layout="inline"
        @keyup.enter.native="searchQuery"
      >
        <a-row :gutter="24">
          <a-col
            :md="6"
            :sm="8"
          >
            <a-form-item label="名称">
              <j-input
                placeholder="请输入名称检索"
                v-model="queryParam.name"
              ></j-input>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>
 
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button
        type="primary"
        @click="searchQuery"
        icon="search"
      >查询</a-button>
      <a-button
        @click="searchReset"
        icon="reload"
      >重置</a-button>
      <a-button
        @click="handleAdd"
        type="primary"
        icon="upload"
      >标准模板上传</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item
            key="1"
            @click="batchDel"
          >
            <a-icon type="delete" />删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>
 
    <!-- table区域-begin -->
    <div>
      <div
        class="ant-alert ant-alert-info"
        style="margin-bottom: 16px"
      >
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a
          style="margin-left: 24px"
          @click="onClearSelected"
        >清空</a>
      </div>
 
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange,
          getCheckboxProps: getCheckboxProps,
        }"
        @change="handleTableChange"
      >
        <!--字符串超长截取省略号显示-->
        <span
          slot="description"
          slot-scope="text"
        >
          <j-ellipsis
            :value="text"
            :length="20"
          />
        </span>
 
        <span
          slot="size"
          slot-scope="text"
          class="error"
        >
          {{ sizeConvert(text) }}
        </span>
 
        <span
          slot="format"
          slot-scope="text"
          class="success"
        >
          <a-icon
            v-if="text == 'pdf'"
            type="file-pdf"
          />
          <a-icon
            v-else-if="text == 'xls' || text == 'xlsx'"
            type="file-excel"
          />
          <a-icon
            v-else-if="text == 'doc' || text == 'docx'"
            type="file-word"
          />
          <a-icon
            v-else-if="
              text == 'jpg' ||
              text == 'bmp' ||
              text == 'gif' ||
              text == 'png' ||
              text == 'jpeg' ||
              text == 'tiff' ||
              text == 'psd' ||
              text == 'raw' ||
              text == 'tif' ||
              text == 'pcx' ||
              text == 'tga' ||
              text == 'exif' ||
              text == 'fpx' ||
              text == 'svg' ||
              text == 'cdr' ||
              text == 'pcd' ||
              text == 'dxf' ||
              text == 'ufo' ||
              text == 'eps'
            "
            type="file-image"
          />
          <a-icon
            v-else-if="text == 'ppt'"
            type="file-ppt"
          />
          <a-icon
            v-else-if="text == 'text'"
            type="file-text"
          />
          <a-icon
            v-else-if="text == 'zip' || text == 'rar'"
            type="file-zip"
          />
          <a-icon
            v-else
            type="file-unknown"
          />
          {{ text }}
        </span>
 
        <span
          slot="action"
          slot-scope="text, record"
        >
          <Tooltip
            placement="top"
            title="预览图片"
          >
            <img
              v-if="
                record.path && (record.format.toLowerCase()=='jpg'||record.format.toLowerCase()=='bmp'||record.format.toLowerCase()=='png'||record.format.toLowerCase()=='jpeg'||record.format.toLowerCase()=='gif')
              "
              width="30"
              height="14"
              border="1"
              draggable="false"
              :preview="record.id"
              :preview-text="record.name"
              :src="record.src"
            />
          </Tooltip>
          <!-- :src="'http://127.0.0.1:8090/mes/sys/common/static//2022-03/30/051ce6948b96dc2eed0d66a838eb443e468b1990919a8fafd9f145869f587c38'" -->
 
          <a
            v-if="record.path && record.format.toLowerCase() == 'pdf'"
            href="javascript:;"
            @click="view(record)"
          >
            预览
          </a>
 
          <a-divider
            v-if="
              record.path &&
              (record.format.toLowerCase() == 'jpg' ||
                record.format.toLowerCase() == 'bmp' ||
                record.format.toLowerCase() == 'png' ||
                record.format.toLowerCase() == 'jpeg' ||
                record.format.toLowerCase() == 'gif' ||
                record.format.toLowerCase() == 'pdf')
            "
            type="vertical"
          />
 
          <a
            href="javascript:;"
            @click="handleDownload(record)"
          >下载</a>
 
          <a-divider type="vertical" />
          <a-popconfirm
            title="确定删除吗?"
            @confirm="() => handleDelete(record.id)"
          >
            <a :disabled="record.uploadRelaCount != 0">删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <pdf-view ref="pdfview"></pdf-view>
    <!-- 表单区域 -->
    <upload-model
      ref="modalForm"
      @ok="modalFormOk"
    ></upload-model>
  </a-card>
</template>
 
<script>
import UploadModel from './modules/uploadModel/UploadModel'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
import { getAction, requestPut, downFile, getFileAccessHttpUrl } from '@/api/manage'
import JInput from '@/components/jeecg/JInput'
import JEllipsis from '@/components/jeecg/JEllipsis'
import Tooltip from 'ant-design-vue/es/tooltip'
 
import { preview } from 'vue-photo-preview'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import Vue from 'vue'
import PdfView from '../common/PdfView' //PDF预览
 
export default {
  name: 'UploadList',
  mixins: [JeecgListMixin],
  components: {
    UploadModel,
    JDictSelectTag,
    JInput,
    JEllipsis,
    JSearchSelectTag,
    Tooltip,
    PdfView,
    preview,
  },
  data() {
    return {
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name',
          sorter: true,
        },
        {
          title: '格式',
          align: 'center',
          dataIndex: 'format',
          scopedSlots: { customRender: 'format' },
          sorter: true,
        },
        {
          title: '大小',
          align: 'center',
          dataIndex: 'size',
          scopedSlots: { customRender: 'size' },
          sorter: true,
        },
        {
          title: '描述',
          align: 'center',
          dataIndex: 'description',
          scopedSlots: { customRender: 'description' },
          sorter: true,
        },
        {
          title: '上传人',
          align: 'center',
          dataIndex: 'createBy',
          sorter: true,
        },
        {
          title: '上传时间',
          align: 'center',
          dataIndex: 'createTime',
          sorter: true,
        },
 
        {
          width: 150,
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/sys/upload/listByType',
        uploadRelaListByUploadId: '/sys/uploadRela/listByUploadId',
        delete: '/sys/upload/delete',
        deleteBatch: '/sys/upload/deleteBatch',
        urlDownload: '/sys/common/static',
        download: '/sys/upload/downloadFile',
        // download: '/sys/upload/downloadFileByType', 
        realityUrl: 'sys/upload/realityUrl',
      },
      path: '',
    }
  },
  methods: {
    getCheckboxProps(record) {
      return {
        props: {
          disabled: record.uploadRelaCount != 0,
        },
      }
    },
    view(record) {
      // let realPath;
      // //获取当前文件真实路径
      // getAction(this.url.realityUrl, { id: record.id }).then((res) => {
      //   if (res.success) {
      //     let path = res.message;
      //     console.log("获取后台路径path---------------->" + path);
      //     realPath = this.url.urlDownload + '/' + path;
      //   }
      // }).then(() => {
      //   this.$refs.pdfview.showPdf(realPath);
      // })
      // this.$refs.pdfview.showPdf('http://127.0.0.1:8090/mes/sys/common/static//2022-03/30/8bc6d02e2421bf94ff73afedc422cf42b9f8c868c8dbb0689f598e87902ed2fd')
      this.$refs.pdfview.showPdf(record.src);
    },
    loadData(arg) {
      if (arg === 1) {
        this.ipagination.current = 1
      }
 
      var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          for (let i = 0; i < res.result.records.length; i++) {
            let r = res.result.records[i]
            r.src = this.getSrc(res.result.records[i])
          }
          this.dataSource = res.result.records
          console.log('dataSource', this.dataSource);
          this.ipagination.total = res.result.total
        }
        this.loading = false
      })
    },
    //拼装src
    getSrc(record) {
      if (!record.path) {
        return ''
      }
      //本地:local\Minio:minio\阿里云:alioss
      if (record.uploadType == 'local') {
        //根据发布状态修改https 或 http
        // return getFileAccessHttpUrl(record.path + record.encodeName, this.url.urlDownload, window._CONFIG['hyperTextTransfer'])
        return window._CONFIG['domianURL'] + this.url.urlDownload + "/" + record.path + record.encodeName;
        // return window._CONFIG['domianURL'] + this.url.urlDownload + "/" + record.path + record.encodeName;
      } else if (record.uploadType == 'alioss') {
        const OSS = require('ali-oss')
        const client = new OSS({
          // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
          region: window._CONFIG['region'],
          // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
          accessKeyId: window._CONFIG['accessKeyId'],
          accessKeySecret: window._CONFIG['accessKeySecret'],
          bucket: window._CONFIG['bucket'],
        })
        // object-key表示从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
        return client.signatureUrl(record.path)
      }
    },
    handleDownload(record) {
      downFile(this.url.download, { id: record.id }).then((res) => {
        if (!res) {
          this.$message.warning('文件下载失败')
          return
        } else {
          let fileName = record.name
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([res]), fileName)
          } else {
            let url = window.URL.createObjectURL(new Blob([res]))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName)
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link) //下载完成移除元素
            window.URL.revokeObjectURL(url) //释放掉blob对象
          }
        }
      })
    },
    sizeConvert(limit) {
      var size = ''
      if (limit < 0.1 * 1024) {
        size = parseFloat(limit).toFixed(2) + 'B' //小于0.1KB,则转化成B
      } else if (limit < 0.1 * 1024 * 1024) {
        size = (parseFloat(limit) / 1024).toFixed(2) + 'KB' //小于0.1MB,则转化成KB
      } else if (limit < 0.1 * 1024 * 1024 * 1024) {
        size = (parseFloat(limit) / (1024 * 1024)).toFixed(2) + 'MB' //小于0.1GB,则转化成MB
      } else {
        size = (parseFloat(limit) / (1024 * 1024 * 1024)).toFixed(2) + 'GB' //其他转化成GB
      }
      var sizeStr = size + '' //转成字符串
      var index = sizeStr.indexOf('.') //获取小数点处的索引
      var dou = sizeStr.substr(index + 1, 2) //获取小数点后两位的值
      if (dou == '00') {
        //判断后两位是否为00,如果是则删除00
        return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2)
      }
      return size
    },
    handleAdd: function () {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '文件上传'
      this.$refs.modalForm.disableSubmit = false
    },
  },
  computed: {
    importExcelUrl: function () {
      console.log('请求地址为::', `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`)
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  mounted() {
    this.$previewRefresh()
    this.$preview.on('close', () => {
      this.isShow = false
    })
  },
}
</script>
<style>
@import '~@assets/less/common.less';
.frozenRowClass {
  color: #c9c9c9;
}
.success {
  color: green;
}
.error {
  color: red;
}
.fontweight {
  font-weight: bold;
}
</style>