index.vue 7.1 KB

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