Blame view

ant-design-vue-jeecg/src/views/modules/oss/OSSFileList.vue 5.6 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <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="文件名称">
              <a-input placeholder="请输入文件名称" v-model="queryParam.fileName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="文件地址">
              <a-input placeholder="请输入文件地址" v-model="queryParam.url"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
19
20
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('button.search') }}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('button.reset') }}</a-button>
肖超群 authored
21
22
23
24
25
26
27
28
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
pengyongcheng authored
29
      <!--      <a-button type="primary" icon="download" @click="handleExportXls('文件列表')">{{ $t('button.export') }}</a-button>-->
肖超群 authored
30
      <a-upload
肖超群 authored
31
32
33
34
35
36
37
        name="file"
        :multiple="false"
        :action="uploadAction"
        :headers="tokenHeader"
        :showUploadList="false"
        :beforeUpload="beforeUpload"
        @change="handleChange">
肖超群 authored
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        <a-button>
          <a-icon type="upload"/>
          OSS文件上传
        </a-button>
      </a-upload>

      <a-upload
        name="file"
        :multiple="false"
        :action="minioUploadAction"
        :headers="tokenHeader"
        :showUploadList="false"
        :beforeUpload="beforeUpload"
        @change="handleChange">
        <a-button>
          <a-icon type="upload"/>
          MINIO文件上传
        </a-button>
      </a-upload>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
62
63
64
        <i class="anticon anticon-info-circle ant-alert-icon"></i> {{ $t('button.selected') }}
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a> {{ $t('button.item') }}
        <a style="margin-left: 24px" @click="onClearSelected">{{ $t('button.clearAll') }}</a>
肖超群 authored
65
66
67
      </div>

      <a-table
肖超群 authored
68
69
70
71
72
73
74
75
76
77
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
肖超群 authored
78
79
80
81

        <span slot="action" slot-scope="text, record">
          <a @click="handlePreview(record)">预览</a>
          <a-divider type="vertical"/>
82
          <a @click="ossDelete(record.id)">{{$t('button.delete')}}</a>
肖超群 authored
83
84
85
86
87
88
89
90
91
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->
  </a-card>
</template>

<script>
肖超群 authored
92
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
肖超群 authored
93
肖超群 authored
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
export default {
  name: "OSSFileList",
  mixins: [JeecgListMixin],
  data() {
    return {
      description: '文件列表',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
肖超群 authored
110
          }
肖超群 authored
111
112
113
114
115
116
117
118
119
120
121
122
        },
        {
          title: '文件名称',
          align: "center",
          dataIndex: 'fileName'
        },
        {
          title: '文件地址',
          align: "center",
          dataIndex: 'url'
        },
        {
123
          title: this.$t('system.options'),
肖超群 authored
124
125
126
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
肖超群 authored
127
        }
肖超群 authored
128
129
130
131
132
133
      ],
      url: {
        upload: "/sys/oss/file/upload",
        list: "/sys/oss/file/list",
        delete: "/sys/oss/file/delete",
        minioUpload: "/sys/upload/uploadMinio"
肖超群 authored
134
      }
肖超群 authored
135
136
137
138
139
    }
  },
  computed: {
    uploadAction() {
      return window._CONFIG['domianURL'] + this.url.upload;
肖超群 authored
140
    },
肖超群 authored
141
142
    minioUploadAction() {
      return window._CONFIG['domianURL'] + this.url.minioUpload;
肖超群 authored
143
    },
肖超群 authored
144
145
146
147
148
149
150
151
  },
  methods: {
    beforeUpload(file) {
      var fileType = file.type;
      if (fileType === 'image') {
        if (fileType.indexOf('image') < 0) {
          this.$message.warning('请上传图片');
          return false;
肖超群 authored
152
        }
肖超群 authored
153
154
155
156
157
158
159
160
161
162
163
164
165
166
      } else if (fileType === 'file') {
        if (fileType.indexOf('image') >= 0) {
          this.$message.warning('请上传文件');
          return false;
        }
      }
      return true
    },
    handleChange(info) {
      if (info.file.status === 'done') {
        if (info.file.response.success) {
          this.loadData()
          this.$message.success(`${info.file.name} 上传成功!`);
        } else {
肖超群 authored
167
168
          this.$message.error(`${info.file.response.message}`);
        }
肖超群 authored
169
170
171
172
173
174
175
176
177
178
179
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.response.message}`);
      }
    },
    ossDelete(id) {
      var that = this;
      that.$confirm({
        title: "确认删除",
        content: "是否删除选中文件?",
        onOk: function () {
          that.handleDelete(id)
肖超群 authored
180
        }
肖超群 authored
181
182
183
184
185
186
      });
    },
    handlePreview(record) {
      if (record && record.url) {
        let url = window._CONFIG['onlinePreviewDomainURL'] + '?url=' + encodeURIComponent(record.url)
        window.open(url, '_blank')
肖超群 authored
187
188
189
      }
    }
  }
肖超群 authored
190
}
肖超群 authored
191
192
193
</script>

<style scoped>
肖超群 authored
194
@import '~@assets/less/common.less';
肖超群 authored
195
</style>