sceneUploadList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. <template>
  2. <div>
  3. <search-layout :needBox="true">
  4. <template slot="searchItem1">
  5. <span class="label">任务名称</span>
  6. <el-input
  7. v-model="searchParams.name"
  8. size="small"
  9. clearable
  10. placeholder="请输入"
  11. maxlength="60"
  12. @keyup.enter.native="doSearch(false)"
  13. >
  14. </el-input>
  15. </template>
  16. <template slot="searchItem2">
  17. <span class="label">上传时间</span>
  18. <!-- <el-date-picker
  19. v-model="uploadDate"
  20. type="daterange"
  21. format="yyyy-MM-dd"
  22. value-format="yyyy-MM-dd"
  23. range-separator="至"
  24. start-placeholder="开始日期"
  25. end-placeholder="结束日期"
  26. >
  27. </el-date-picker> -->
  28. <el-date-picker
  29. v-model="searchParams.timeBegin"
  30. type="date"
  31. format="yyyy-MM-dd"
  32. value-format="yyyy-MM-dd"
  33. placeholder="开始日期"
  34. class="dateRangeInput"
  35. >
  36. </el-date-picker>
  37. <span class="dateSeparator">至</span>
  38. <el-date-picker
  39. v-model="searchParams.timeEnd"
  40. type="date"
  41. format="yyyy-MM-dd"
  42. value-format="yyyy-MM-dd"
  43. placeholder="结束日期"
  44. class="dateRangeInput"
  45. >
  46. </el-date-picker>
  47. </template>
  48. <template slot="searchBtn1">
  49. <el-button type="primary" @click="doSearch(false)">查询</el-button>
  50. </template>
  51. <template slot="searchBtn2">
  52. <el-button type="primary" @click="doReset">重置</el-button>
  53. </template>
  54. </search-layout>
  55. <div class="btnsPanel">
  56. <el-button
  57. type="primary"
  58. icon="el-icon-circle-plus-outline"
  59. @click="addOne"
  60. >新增</el-button
  61. >
  62. </div>
  63. <tableList
  64. ref="table"
  65. style="margin: 0 30px"
  66. :columns="columns"
  67. :getDataWay="getDataWay"
  68. :pagination="pagination"
  69. index
  70. >
  71. <el-table-column label="操作" slot="cgInfos" align="center">
  72. <template v-slot="scope">
  73. <!-- <span
  74. v-if="scope.row.errorMessage"
  75. @click="viewRow(scope.row.errorMessage)"
  76. class="errRecord tdBtn"
  77. >错误记录</span
  78. > -->
  79. <i
  80. v-if="scope.row.errorMessage"
  81. @click="viewRow(scope.row.errorMessage)"
  82. class="el-icon-document elIcon tdBtn"
  83. title="错误记录"
  84. ></i>
  85. <i
  86. @click="delRow(scope.row.id)"
  87. class="el-icon-delete elIcon tdBtn"
  88. title="删除"
  89. ></i>
  90. </template>
  91. </el-table-column>
  92. </tableList>
  93. <el-dialog
  94. title="场景上传"
  95. :visible.sync="dialogVisible"
  96. width="690px"
  97. :close-on-click-modal="false"
  98. :close-on-press-escape="false"
  99. :before-close="uploadCancel"
  100. >
  101. <el-form
  102. ref="form"
  103. :model="form"
  104. :rules="rules"
  105. label-width="108px"
  106. >
  107. <el-form-item label="任务名称:" prop="name">
  108. <el-input
  109. placeholder="请输入"
  110. maxlength="60"
  111. v-autoTrim="{ obj: form, key: 'name' }"
  112. v-model="form.name"
  113. >
  114. </el-input>
  115. </el-form-item>
  116. <el-form-item label="场景分类:" prop="sceneType">
  117. <el-select
  118. v-model="form.sceneType"
  119. @change="sceneTypeChange"
  120. >
  121. <el-option
  122. v-for="item in sceneTypeList"
  123. :label="item.caption"
  124. :value="item.code"
  125. :key="item.code"
  126. ></el-option>
  127. </el-select>
  128. </el-form-item>
  129. <!-- 三个真实场景时展示 -->
  130. <el-form-item
  131. v-if="form.sceneType != '4'"
  132. label="场景路径:"
  133. prop="dataDirectory"
  134. >
  135. <el-input
  136. placeholder="请输入"
  137. maxlength="300"
  138. v-autoTrim="{ obj: form, key: 'dataDirectory' }"
  139. v-model="form.dataDirectory"
  140. >
  141. </el-input>
  142. </el-form-item>
  143. <!-- 泛化时展示 -->
  144. <el-form-item
  145. v-if="form.sceneType === '4'"
  146. label="文件上传:"
  147. prop="fileName"
  148. >
  149. <el-input
  150. placeholder="请输入"
  151. maxlength="600"
  152. v-autoTrim="{ obj: form, key: 'fileName' }"
  153. v-model="form.fileName"
  154. disabled
  155. >
  156. </el-input>
  157. <upload
  158. ref="upload"
  159. class="upload"
  160. @handleChange="handleChange"
  161. ></upload>
  162. </el-form-item>
  163. </el-form>
  164. <span slot="footer">
  165. <el-button type="primary" @click="uploadConfirm"
  166. >确 定</el-button
  167. >
  168. <el-button @click="uploadCancel">取 消</el-button>
  169. </span>
  170. </el-dialog>
  171. <el-dialog
  172. title="错误记录"
  173. :visible.sync="errRocordVisible"
  174. width="690px"
  175. :close-on-click-modal="false"
  176. :close-on-press-escape="false"
  177. :before-close="errClose"
  178. >
  179. <div>{{ errorMessage }}</div>
  180. <span slot="footer">
  181. <el-button type="primary" @click="errClose">关 闭</el-button>
  182. </span>
  183. </el-dialog>
  184. </div>
  185. </template>
  186. <script>
  187. import searchLayout from "@/components/grid/searchLayout";
  188. import tableList from "@/components/grid/TableList";
  189. import upload from "./components/upload";
  190. export default {
  191. name: "sceneUploadList", // 场景上传
  192. components: { searchLayout, tableList, upload },
  193. data() {
  194. let formatSeconds = function formatSeconds(value) {
  195. var theTime = parseInt(value); // 秒
  196. var theTime1 = 0; // 分
  197. var theTime2 = 0; // 小时
  198. if (theTime > 60) {
  199. theTime1 = parseInt(theTime / 60);
  200. theTime = parseInt(theTime % 60);
  201. if (theTime1 > 60) {
  202. theTime2 = parseInt(theTime1 / 60);
  203. theTime1 = parseInt(theTime1 % 60);
  204. }
  205. }
  206. var result = "" + parseInt(theTime) + "秒";
  207. if (theTime1 > 0) {
  208. result = "" + parseInt(theTime1) + "分" + result;
  209. }
  210. if (theTime2 > 0) {
  211. result = "" + parseInt(theTime2) + "小时" + result;
  212. }
  213. return result;
  214. };
  215. return {
  216. searchParams: {
  217. //搜索参数
  218. name: "", // 任务名称
  219. timeBegin: "", // 上传时间起
  220. timeEnd: "", // 上传时间止
  221. },
  222. uploadDate: "",
  223. columns: [
  224. {
  225. label: "任务名称",
  226. prop: "name",
  227. },
  228. {
  229. label: "场景分类",
  230. prop: "sceneType",
  231. },
  232. {
  233. label: "上传时间",
  234. prop: "createTime",
  235. },
  236. {
  237. label: "上传状态",
  238. prop: "status",
  239. },
  240. {
  241. label: "总用时长",
  242. prop: "totalTime",
  243. formatter: (row) => {
  244. if (row.totalTime)
  245. if (row.totalTime && !isNaN(row.totalTime)) {
  246. return formatSeconds(row.totalTime);
  247. }
  248. },
  249. },
  250. {
  251. label: "操作",
  252. prop: "cgInfos",
  253. template: true,
  254. },
  255. ],
  256. pagination: {
  257. //分页使用
  258. currentPage: 1,
  259. pageSize: 10,
  260. position: "right",
  261. pageSizes: [10, 30, 50, 100, 200],
  262. layout: "sizes, total, prev, pager, next, jumper",
  263. },
  264. getDataWay: {
  265. //加载表格数据
  266. dataType: "url",
  267. type: "post",
  268. // firstRequest: false,
  269. data: this.$api.systemManagement.getSceneImporPagetList,
  270. param: {},
  271. },
  272. form: {
  273. name: "", // 任务名称
  274. sceneType: "", // 场景分类
  275. dataDirectory: "", // 场景路径
  276. fileName: "", // 文件名称
  277. },
  278. rules: {
  279. name: [{ required: true, message: "请输入", trigger: "blur" }],
  280. sceneType: [
  281. { required: true, message: "请选择", trigger: "change" },
  282. ],
  283. dataDirectory: [
  284. { required: true, message: "请输入", trigger: "blur" },
  285. ],
  286. fileName: [
  287. { required: true, message: "请上传", trigger: "change" },
  288. ],
  289. },
  290. sceneTypeList: [],
  291. dialogVisible: false,
  292. file: null,
  293. errRocordVisible: false,
  294. errorMessage: "",
  295. timer: null,
  296. };
  297. },
  298. methods: {
  299. doSearch(isTimer = false) {
  300. // if (this.uploadDate) {
  301. // this.searchParams.timeBegin = `${this.uploadDate[0]}`;
  302. // this.searchParams.timeEnd = `${this.uploadDate[1]}`;
  303. // } else {
  304. // this.searchParams.timeBegin = "";
  305. // this.searchParams.timeEnd = "";
  306. // }
  307. let timeBegin = "";
  308. if (this.searchParams.timeBegin) {
  309. timeBegin = `${this.searchParams.timeBegin} 00:00:00`;
  310. }
  311. let timeEnd = "";
  312. if (this.searchParams.timeEnd) {
  313. timeEnd = `${this.searchParams.timeEnd} 23:59:59`;
  314. }
  315. if (timeBegin && timeEnd && timeBegin > timeEnd) {
  316. this.$message.error("结束时间不能早于开始时间");
  317. return;
  318. }
  319. let pageMap = {
  320. name: this.searchParams.name,
  321. timeBegin,
  322. timeEnd,
  323. resetPageNum: !isTimer ? false : (this.pagination.currentPage || 1),
  324. };
  325. if(!isTimer) this.pagination.currentPage = 1;
  326. this.refreshList(pageMap);
  327. if (this.timer) clearInterval(this.timer);
  328. this.timer = setInterval(() => {
  329. if (this.$refs["table"]) this.doSearch(true);
  330. }, 1000 * 60);
  331. },
  332. //刷新table
  333. refreshList(param) {
  334. param
  335. ? this.$refs["table"].loadData(param)
  336. : this.$refs["table"].loadData();
  337. },
  338. doReset() {
  339. this.searchParams = {
  340. name: "",
  341. timeBegin: "",
  342. timeEnd: "",
  343. };
  344. // this.uploadDate = "";
  345. this.doSearch(false);
  346. },
  347. addOne() {
  348. this.form = {
  349. name: "",
  350. sceneType: "",
  351. dataDirectory: "",
  352. fileName: "",
  353. };
  354. this.file = null;
  355. this.dialogVisible = true;
  356. this.$nextTick(() => {
  357. this.$refs.form.clearValidate();
  358. });
  359. },
  360. viewRow(errorMessage) {
  361. this.errorMessage = errorMessage;
  362. this.errRocordVisible = true;
  363. },
  364. delRow(id) {
  365. this.$confirm("确认是否删除?", "提示", {
  366. confirmButtonText: "确定",
  367. cancelButtonText: "取消",
  368. type: "warning",
  369. }).then(() => {
  370. this.$axios({
  371. method: "post",
  372. url: this.$api.systemManagement.deleteTask,
  373. data: {
  374. id,
  375. },
  376. }).then((res) => {
  377. if (res.code == 200) {
  378. this.$message.success("删除成功");
  379. } else {
  380. this.$message.error(res.message || "删除失败");
  381. }
  382. this.doSearch();
  383. });
  384. });
  385. },
  386. errClose() {
  387. this.errRocordVisible = false;
  388. this.errorMessage = "";
  389. },
  390. uploadConfirm() {
  391. this.$refs.form.validate(async (valid) => {
  392. if (valid) {
  393. if (this.form.sceneType === "4") {
  394. let formData = new FormData();
  395. await formData.append("taskName", this.form.name);
  396. await formData.append("name", this.file.name);
  397. await formData.append("file", this.file.raw);
  398. await this.$axios({
  399. method: "post",
  400. url: this.$api.systemManagement
  401. .saveSceneGeneralTemplateAll,
  402. data: formData,
  403. withCredentials: true,
  404. headers: {
  405. "Content-type": "multipart/form-data",
  406. },
  407. }).then((res) => {
  408. if (res.code == 200) {
  409. this.$message.success("保存成功");
  410. this.uploadCancel();
  411. this.doSearch();
  412. } else {
  413. this.$message.error(res.message || "保存失败");
  414. }
  415. });
  416. } else {
  417. this.$axios({
  418. method: "post",
  419. url: this.$api.systemManagement.saveTask,
  420. data: { ...this.form },
  421. }).then((res) => {
  422. if (res.code == 200) {
  423. this.$message.success("保存成功");
  424. this.uploadCancel();
  425. this.doSearch();
  426. } else {
  427. this.$message.error(res.message || "保存失败");
  428. }
  429. });
  430. }
  431. }
  432. });
  433. },
  434. uploadCancel() {
  435. this.dialogVisible = false;
  436. },
  437. attachmentChange(obj) {
  438. this.attachmentList = obj;
  439. },
  440. handleChange(file) {
  441. this.file = file;
  442. this.form.fileName = file.name;
  443. },
  444. sceneTypeChange(v) {
  445. if (v === "4") {
  446. this.$refs.form.clearValidate("dataDirectory");
  447. } else {
  448. this.file = null;
  449. this.form.fileName = "";
  450. this.$refs.form.clearValidate("fileName");
  451. }
  452. },
  453. },
  454. async mounted() {
  455. if (this.timer) clearInterval(this.timer);
  456. this.timer = setInterval(() => {
  457. if (this.$refs["table"]) this.doSearch(true);
  458. }, 1000 * 60);
  459. await this.$dicsListsInit({
  460. sceneTypeList: "sceneType",
  461. });
  462. },
  463. beforeDestroy() {
  464. clearInterval(this.timer);
  465. },
  466. };
  467. </script>
  468. <style lang='less' scoped>
  469. .btnsPanel {
  470. margin: 45px 40px 15px;
  471. text-align: right;
  472. }
  473. .errRecord {
  474. color: @themeColor;
  475. cursor: pointer;
  476. }
  477. .tdBtn {
  478. margin-right: 10px;
  479. &:last-child {
  480. margin-right: 0;
  481. }
  482. }
  483. .upload {
  484. margin-top: 15px;
  485. }
  486. </style>