提交 | 用户 | 时间
|
759b1c
|
1 |
<template> |
H |
2 |
<div class="app-container"> |
|
3 |
<!-- 搜索工作栏 --> |
|
4 |
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> |
|
5 |
<el-form-item label="文件路径" prop="path"> |
|
6 |
<el-input v-model="queryParams.path" placeholder="请输入文件路径" clearable @keyup.enter.native="handleQuery"/> |
|
7 |
</el-form-item> |
|
8 |
<el-form-item label="创建时间" prop="createTime"> |
|
9 |
<el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" |
|
10 |
type="daterange" |
|
11 |
range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" |
|
12 |
:default-time="['00:00:00', '23:59:59']"/> |
|
13 |
</el-form-item> |
|
14 |
<el-form-item> |
|
15 |
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button> |
|
16 |
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button> |
|
17 |
</el-form-item> |
|
18 |
</el-form> |
|
19 |
|
|
20 |
<!-- 操作工具栏 --> |
|
21 |
<el-row :gutter="10" class="mb8"> |
|
22 |
<el-col :span="1.5"> |
|
23 |
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">上传文件</el-button> |
|
24 |
</el-col> |
|
25 |
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
|
26 |
</el-row> |
|
27 |
|
|
28 |
<!-- 列表 --> |
|
29 |
<el-table v-loading="loading" :data="list"> |
|
30 |
<el-table-column label="文件名" :show-overflow-tooltip="true" align="center" min-width="200px" prop="name"/> |
|
31 |
<el-table-column label="文件路径" :show-overflow-tooltip="true" align="center" min-width="250px" prop="path"/> |
|
32 |
<el-table-column label="文件 URL" :show-overflow-tooltip="true" align="center" min-width="300px" prop="url"/> |
|
33 |
<el-table-column label="文件大小" align="center" prop="size" min-width="120px" :formatter="sizeFormat"/> |
|
34 |
<el-table-column label="文件类型" :show-overflow-tooltip="true" align="center" prop="type" width="180px"/> |
|
35 |
<el-table-column label="文件内容" align="center" prop="content" min-width="150px"> |
|
36 |
<template v-slot="scope"> |
|
37 |
<image-preview v-if="scope.row.type&&scope.row.type.indexOf('image/') === 0" :src="scope.row.url" |
|
38 |
:width="'100px'"></image-preview> |
|
39 |
<video v-else-if="scope.row.type&&scope.row.type.indexOf('video/') === 0" :width="'100px'"> |
|
40 |
<source :src="scope.row.url"/> |
|
41 |
</video> |
|
42 |
<i v-else>无法预览,点击 |
|
43 |
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" target="_blank" |
|
44 |
:href="getFileUrl + scope.row.configId + '/get/' + scope.row.path">下载 |
|
45 |
</el-link> |
|
46 |
</i> |
|
47 |
</template> |
|
48 |
</el-table-column> |
|
49 |
<el-table-column label="上传时间" align="center" prop="createTime" min-width="170px"> |
|
50 |
<template v-slot="scope"> |
|
51 |
<span>{{ parseTime(scope.row.createTime) }}</span> |
|
52 |
</template> |
|
53 |
</el-table-column> |
|
54 |
<el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="100px"> |
|
55 |
<template v-slot="scope"> |
|
56 |
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" |
|
57 |
v-hasPermi="['infra:file:delete']">删除 |
|
58 |
</el-button> |
|
59 |
</template> |
|
60 |
</el-table-column> |
|
61 |
</el-table> |
|
62 |
<!-- 分页组件 --> |
|
63 |
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" |
|
64 |
@pagination="getList"/> |
|
65 |
|
|
66 |
<!-- 对话框(添加 / 修改) --> |
|
67 |
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body> |
|
68 |
<el-upload ref="upload" :limit="1" accept=".jpg, .png, .gif" :auto-upload="false" drag |
|
69 |
:headers="upload.headers" :action="upload.url" :data="upload.data" :disabled="upload.isUploading" |
|
70 |
:on-change="handleFileChange" |
|
71 |
:on-progress="handleFileUploadProgress" |
|
72 |
:on-success="handleFileSuccess"> |
|
73 |
<i class="el-icon-upload"></i> |
|
74 |
<div class="el-upload__text"> |
|
75 |
将文件拖到此处,或 <em>点击上传</em> |
|
76 |
</div> |
|
77 |
<div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入 jpg、png、gif 格式文件!</div> |
|
78 |
</el-upload> |
|
79 |
<div slot="footer" class="dialog-footer"> |
|
80 |
<el-button type="primary" @click="submitFileForm">确 定</el-button> |
|
81 |
<el-button @click="upload.open = false">取 消</el-button> |
|
82 |
</div> |
|
83 |
</el-dialog> |
|
84 |
|
|
85 |
</div> |
|
86 |
</template> |
|
87 |
|
|
88 |
<script> |
|
89 |
import {deleteFile, getFilePage} from "@/api/infra/file"; |
|
90 |
import {getAccessToken} from "@/utils/auth"; |
|
91 |
import ImagePreview from "@/components/ImagePreview"; |
|
92 |
|
|
93 |
export default { |
|
94 |
name: "InfraFile", |
|
95 |
components: { |
|
96 |
ImagePreview |
|
97 |
}, |
|
98 |
data() { |
|
99 |
return { |
|
100 |
getFileUrl: process.env.VUE_APP_BASE_API + '/admin-api/infra/file/', |
|
101 |
// 遮罩层 |
|
102 |
loading: true, |
|
103 |
// 显示搜索条件 |
|
104 |
showSearch: true, |
|
105 |
// 总条数 |
|
106 |
total: 0, |
|
107 |
// 文件列表 |
|
108 |
list: [], |
|
109 |
// 弹出层标题 |
|
110 |
title: "", |
|
111 |
// 查询参数 |
|
112 |
queryParams: { |
|
113 |
pageNo: 1, |
|
114 |
pageSize: 10, |
|
115 |
path: null, |
|
116 |
type: null, |
|
117 |
createTime: [] |
|
118 |
}, |
|
119 |
// 用户导入参数 |
|
120 |
upload: { |
|
121 |
open: false, // 是否显示弹出层 |
|
122 |
title: "", // 弹出层标题 |
|
123 |
isUploading: false, // 是否禁用上传 |
|
124 |
url: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", // 请求地址 |
|
125 |
headers: {Authorization: "Bearer " + getAccessToken()}, // 设置上传的请求头部 |
|
126 |
data: {} // 上传的额外数据,用于文件名 |
|
127 |
}, |
|
128 |
}; |
|
129 |
}, |
|
130 |
created() { |
|
131 |
this.getList(); |
|
132 |
}, |
|
133 |
methods: { |
|
134 |
/** 查询列表 */ |
|
135 |
getList() { |
|
136 |
this.loading = true; |
|
137 |
// 执行查询 |
|
138 |
getFilePage(this.queryParams).then(response => { |
|
139 |
this.list = response.data.list; |
|
140 |
this.total = response.data.total; |
|
141 |
this.loading = false; |
|
142 |
}); |
|
143 |
}, |
|
144 |
/** 取消按钮 */ |
|
145 |
cancel() { |
|
146 |
this.open = false; |
|
147 |
this.reset(); |
|
148 |
}, |
|
149 |
/** 表单重置 */ |
|
150 |
reset() { |
|
151 |
this.form = { |
|
152 |
content: undefined, |
|
153 |
}; |
|
154 |
this.resetForm("form"); |
|
155 |
}, |
|
156 |
/** 搜索按钮操作 */ |
|
157 |
handleQuery() { |
|
158 |
this.queryParams.pageNo = 1; |
|
159 |
this.getList(); |
|
160 |
}, |
|
161 |
/** 重置按钮操作 */ |
|
162 |
resetQuery() { |
|
163 |
this.resetForm("queryForm"); |
|
164 |
this.handleQuery(); |
|
165 |
}, |
|
166 |
/** 新增按钮操作 */ |
|
167 |
handleAdd() { |
|
168 |
this.upload.open = true; |
|
169 |
this.upload.title = "上传文件"; |
|
170 |
}, |
|
171 |
/** 处理上传的文件发生变化 */ |
|
172 |
handleFileChange(file, fileList) { |
|
173 |
|
|
174 |
}, |
|
175 |
/** 处理文件上传中 */ |
|
176 |
handleFileUploadProgress(event, file, fileList) { |
|
177 |
this.upload.isUploading = true; // 禁止修改 |
|
178 |
}, |
|
179 |
/** 发起文件上传 */ |
|
180 |
submitFileForm() { |
|
181 |
this.$refs.upload.submit(); |
|
182 |
}, |
|
183 |
/** 文件上传成功处理 */ |
|
184 |
handleFileSuccess(response, file, fileList) { |
|
185 |
// 清理 |
|
186 |
this.upload.open = false; |
|
187 |
this.upload.isUploading = false; |
|
188 |
this.$refs.upload.clearFiles(); |
|
189 |
// 提示成功,并刷新 |
|
190 |
this.$modal.msgSuccess("上传成功"); |
|
191 |
this.getList(); |
|
192 |
}, |
|
193 |
/** 删除按钮操作 */ |
|
194 |
handleDelete(row) { |
|
195 |
const id = row.id; |
|
196 |
this.$modal.confirm('是否确认删除文件编号为"' + id + '"的数据项?').then(function () { |
|
197 |
return deleteFile(id); |
|
198 |
}).then(() => { |
|
199 |
this.getList(); |
|
200 |
this.$modal.msgSuccess("删除成功"); |
|
201 |
}).catch(() => { |
|
202 |
}); |
|
203 |
}, |
|
204 |
// 用户昵称展示 |
|
205 |
sizeFormat(row, column) { |
|
206 |
const unitArr = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; |
|
207 |
const srcSize = parseFloat(row.size); |
|
208 |
const index = Math.floor(Math.log(srcSize) / Math.log(1024)); |
|
209 |
let size = srcSize / Math.pow(1024, index); |
|
210 |
size = size.toFixed(2);//保留的小数位数 |
|
211 |
return size + ' ' + unitArr[index]; |
|
212 |
}, |
|
213 |
} |
|
214 |
}; |
|
215 |
</script> |