index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. size="mini"
  22. @click="handleAdd"
  23. v-hasPermi="['manage:analyzeResult:add']"
  24. >选择解析文件</el-button>
  25. </el-col>
  26. <el-col :span="1.5">
  27. <el-button
  28. type="warning"
  29. plain
  30. icon="el-icon-download"
  31. size="mini"
  32. @click="handleExport"
  33. v-hasPermi="['manage:analyzeResult:export']"
  34. >导出</el-button>
  35. </el-col>
  36. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  37. </el-row>
  38. <el-table v-loading="loading" :data="analyzeResultList" @selection-change="handleSelectionChange">
  39. <el-table-column type="selection" width="55" align="center" />
  40. <el-table-column label="源数据文件名称" align="center" prop="sourceName" />
  41. <el-table-column label="解析后文件名称" align="center" prop="name" />
  42. <el-table-column label="备注" align="center" prop="remark"/>
  43. <el-table-column label="解析后结果列表" align="center" />
  44. </el-table>
  45. <pagination
  46. v-show="total>0"
  47. :total="total"
  48. :page.sync="queryParams.pageNum"
  49. :limit.sync="queryParams.pageSize"
  50. @pagination="getList"
  51. />
  52. <!-- 添加或修改数据解析结果对话框 -->
  53. <el-dialog :title="title" :visible.sync="open" :close-on-click-modal="false" width="500px" append-to-body>
  54. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  55. <el-form-item label="文件名" prop="name">
  56. <el-select v-model="form.name" placeholder="请选择要解析的数据" style="width:100%">
  57. <el-option
  58. v-for="item in sourceDataList"
  59. :key="item.name"
  60. :label="item.name"
  61. :value="item.name">
  62. </el-option>
  63. </el-select>
  64. </el-form-item>
  65. <el-form-item label="备注" prop="remark">
  66. <el-input v-model="form.remark" placeholder="请输入备注" />
  67. </el-form-item>
  68. </el-form>
  69. <div slot="footer" class="dialog-footer">
  70. <el-button type="primary" @click="submitForm" :loading="butLoading">{{butText}}</el-button>
  71. <el-button @click="cancel">取 消</el-button>
  72. </div>
  73. </el-dialog>
  74. </div>
  75. </template>
  76. <script>
  77. import { listAnalyzeResult, getAnalyzeResult, delAnalyzeResult, addAnalyzeResult, updateAnalyzeResult } from "@/api/manage/analyzeResult";
  78. import {
  79. listDataDown
  80. } from "@/api/manage/dataDown";
  81. export default {
  82. name: "AnalyzeResult",
  83. data() {
  84. return {
  85. // 按钮加载
  86. butLoading: false,
  87. // 按钮显示文本
  88. butText: "开始解析",
  89. // 源数据文件列表
  90. sourceDataList: [],
  91. // 遮罩层
  92. loading: true,
  93. // 选中数组
  94. ids: [],
  95. // 非单个禁用
  96. single: true,
  97. // 非多个禁用
  98. multiple: true,
  99. // 显示搜索条件
  100. showSearch: true,
  101. // 总条数
  102. total: 0,
  103. // 数据解析结果表格数据
  104. analyzeResultList: [],
  105. // 弹出层标题
  106. title: "",
  107. // 是否显示弹出层
  108. open: false,
  109. // 查询参数
  110. queryParams: {
  111. pageNum: 1,
  112. pageSize: 10,
  113. },
  114. // 表单参数
  115. form: {},
  116. // 表单校验
  117. rules: {
  118. isDelete: [
  119. { required: true, message: "数据是否删除不能为空", trigger: "blur" }
  120. ],
  121. }
  122. };
  123. },
  124. created() {
  125. this.getList();
  126. this.getSourceDataList();
  127. },
  128. methods: {
  129. getSourceDataList() {
  130. // listDataDown(this.queryParams).then(response => {
  131. // this.sourceDataList = response.rows;
  132. // });
  133. this.sourceDataList = JSON.parse(localStorage.getItem("data-down")) || [];
  134. },
  135. /** 查询数据解析结果列表 */
  136. getList() {
  137. this.loading = true;
  138. // listAnalyzeResult(this.queryParams).then(response => {
  139. // this.analyzeResultList = response.rows;
  140. // this.total = response.total;
  141. // this.loading = false;
  142. // });
  143. this.analyzeResultList = JSON.parse(localStorage.getItem("data-analyze")) || [];
  144. this.total = this.dataDownList?.length || 0;
  145. this.loading = false;
  146. },
  147. // 取消按钮
  148. cancel() {
  149. this.open = false;
  150. this.reset();
  151. },
  152. // 表单重置
  153. reset() {
  154. this.form = {
  155. name: null,
  156. remark: null
  157. };
  158. this.resetForm("form");
  159. },
  160. /** 搜索按钮操作 */
  161. handleQuery() {
  162. this.queryParams.pageNum = 1;
  163. this.getList();
  164. },
  165. /** 重置按钮操作 */
  166. resetQuery() {
  167. this.resetForm("queryForm");
  168. this.handleQuery();
  169. },
  170. // 多选框选中数据
  171. handleSelectionChange(selection) {
  172. this.ids = selection.map(item => item.id)
  173. this.single = selection.length!==1
  174. this.multiple = !selection.length
  175. },
  176. /** 新增按钮操作 */
  177. handleAdd() {
  178. this.reset();
  179. this.open = true;
  180. this.title = "添加数据解析结果";
  181. },
  182. /** 修改按钮操作 */
  183. handleUpdate(row) {
  184. this.reset();
  185. const id = row.id || this.ids
  186. getAnalyzeResult(id).then(response => {
  187. this.form = response.data;
  188. this.open = true;
  189. this.title = "修改数据解析结果";
  190. });
  191. },
  192. /** 提交按钮 */
  193. submitForm() {
  194. this.butLoading = true;
  195. this.butText = "解析中...";
  196. setTimeout(() => {
  197. // 服务获取文件
  198. let dataObj = {
  199. name: `解析后固定格式_${new Date().getTime()}.xlsx`,
  200. sourceName: this.form.name,
  201. remark: this.form.remark,
  202. };
  203. let data = JSON.parse(localStorage.getItem("data-analyze")) || [];
  204. data.push(dataObj);
  205. localStorage.setItem("data-analyze", JSON.stringify(data));
  206. this.getList();
  207. // 保存指定路径
  208. this.butLoading = false;
  209. this.butText = "开始解析";
  210. this.$modal.msgSuccess("解析成功");
  211. this.open = false;
  212. }, 1000);
  213. // this.$refs["form"].validate(valid => {
  214. // if (valid) {
  215. // if (this.form.id != null) {
  216. // updateAnalyzeResult(this.form).then(response => {
  217. // this.$modal.msgSuccess("修改成功");
  218. // this.open = false;
  219. // this.getList();
  220. // });
  221. // } else {
  222. // addAnalyzeResult(this.form).then(response => {
  223. // this.$modal.msgSuccess("新增成功");
  224. // this.open = false;
  225. // this.getList();
  226. // });
  227. // }
  228. // }
  229. // });
  230. },
  231. /** 删除按钮操作 */
  232. handleDelete(row) {
  233. const ids = row.id || this.ids;
  234. this.$modal.confirm('是否确认删除数据解析结果编号为"' + ids + '"的数据项?').then(function() {
  235. return delAnalyzeResult(ids);
  236. }).then(() => {
  237. this.getList();
  238. this.$modal.msgSuccess("删除成功");
  239. }).catch(() => {});
  240. },
  241. /** 导出按钮操作 */
  242. handleExport() {
  243. this.download('manage/analyzeResult/export', {
  244. ...this.queryParams
  245. }, `analyzeResult_${new Date().getTime()}.xlsx`)
  246. }
  247. }
  248. };
  249. </script>