sceneUploadList.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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"
  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">查询</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"
  77. >错误记录</span
  78. >
  79. </template>
  80. </el-table-column>
  81. </tableList>
  82. <el-dialog
  83. title="场景上传"
  84. :visible.sync="dialogVisible"
  85. width="690px"
  86. :close-on-click-modal="false"
  87. :close-on-press-escape="false"
  88. :before-close="uploadCancel"
  89. >
  90. <el-form
  91. ref="form"
  92. :model="form"
  93. :rules="rules"
  94. label-width="108px"
  95. >
  96. <el-form-item label="任务名称:" prop="name">
  97. <el-input
  98. placeholder="请输入"
  99. maxlength="60"
  100. v-autoTrim="{ obj: form, key: 'name' }"
  101. v-model="form.name"
  102. >
  103. </el-input>
  104. </el-form-item>
  105. <el-form-item label="场景分类:" prop="sceneType">
  106. <el-select
  107. v-model="form.sceneType"
  108. @change="sceneTypeChange"
  109. >
  110. <el-option
  111. v-for="item in sceneTypeList"
  112. :label="item.caption"
  113. :value="item.code"
  114. :key="item.code"
  115. ></el-option>
  116. </el-select>
  117. </el-form-item>
  118. <!-- 三个真实场景时展示 -->
  119. <el-form-item
  120. v-if="form.sceneType != '4'"
  121. label="场景路径:"
  122. prop="dataDirectory"
  123. >
  124. <el-input
  125. placeholder="请输入"
  126. maxlength="300"
  127. v-autoTrim="{ obj: form, key: 'dataDirectory' }"
  128. v-model="form.dataDirectory"
  129. >
  130. </el-input>
  131. </el-form-item>
  132. <!-- 泛化时展示 -->
  133. <el-form-item
  134. v-if="form.sceneType === '4'"
  135. label="文件上传:"
  136. prop="fileName"
  137. >
  138. <el-input
  139. placeholder="请输入"
  140. maxlength="600"
  141. v-autoTrim="{ obj: form, key: 'fileName' }"
  142. v-model="form.fileName"
  143. disabled
  144. >
  145. </el-input>
  146. <upload
  147. ref="upload"
  148. class="upload"
  149. @handleChange="handleChange"
  150. ></upload>
  151. </el-form-item>
  152. </el-form>
  153. <span slot="footer">
  154. <el-button type="primary" @click="uploadConfirm"
  155. >确 定</el-button
  156. >
  157. <el-button @click="uploadCancel">取 消</el-button>
  158. </span>
  159. </el-dialog>
  160. <el-dialog
  161. title="错误记录"
  162. :visible.sync="errRocordVisible"
  163. width="690px"
  164. :close-on-click-modal="false"
  165. :close-on-press-escape="false"
  166. :before-close="errClose"
  167. >
  168. <div>{{ errorMessage }}</div>
  169. <span slot="footer">
  170. <el-button type="primary" @click="errClose">关 闭</el-button>
  171. </span>
  172. </el-dialog>
  173. </div>
  174. </template>
  175. <script>
  176. import searchLayout from "@/components/grid/searchLayout";
  177. import tableList from "@/components/grid/TableList";
  178. import upload from "./components/upload";
  179. export default {
  180. name: "sceneUploadList", // 场景上传
  181. components: { searchLayout, tableList, upload },
  182. data() {
  183. let formatSeconds = function formatSeconds(value) {
  184. var theTime = parseInt(value); // 秒
  185. var theTime1 = 0; // 分
  186. var theTime2 = 0; // 小时
  187. if (theTime > 60) {
  188. theTime1 = parseInt(theTime / 60);
  189. theTime = parseInt(theTime % 60);
  190. if (theTime1 > 60) {
  191. theTime2 = parseInt(theTime1 / 60);
  192. theTime1 = parseInt(theTime1 % 60);
  193. }
  194. }
  195. var result = "" + parseInt(theTime) + "秒";
  196. if (theTime1 > 0) {
  197. result = "" + parseInt(theTime1) + "分" + result;
  198. }
  199. if (theTime2 > 0) {
  200. result = "" + parseInt(theTime2) + "小时" + result;
  201. }
  202. return result;
  203. };
  204. return {
  205. searchParams: {
  206. //搜索参数
  207. name: "", // 任务名称
  208. timeBegin: "", // 上传时间起
  209. timeEnd: "", // 上传时间止
  210. },
  211. uploadDate: "",
  212. columns: [
  213. {
  214. label: "任务名称",
  215. prop: "name",
  216. },
  217. {
  218. label: "场景分类",
  219. prop: "sceneType",
  220. },
  221. {
  222. label: "上传时间",
  223. prop: "createTime",
  224. },
  225. {
  226. label: "上传状态",
  227. prop: "status",
  228. },
  229. {
  230. label: "总用时长",
  231. prop: "totalTime",
  232. formatter: (row) => {
  233. if (row.totalTime)
  234. if (row.totalTime && !isNaN(row.totalTime)) {
  235. return formatSeconds(row.totalTime);
  236. }
  237. },
  238. },
  239. {
  240. label: "操作",
  241. prop: "cgInfos",
  242. template: true,
  243. },
  244. ],
  245. pagination: {
  246. //分页使用
  247. currentPage: 1,
  248. pageSize: 10,
  249. position: "right",
  250. pageSizes: [10, 30, 50, 100, 200],
  251. layout: "sizes, total, prev, pager, next, jumper",
  252. },
  253. getDataWay: {
  254. //加载表格数据
  255. dataType: "url",
  256. type: "post",
  257. // firstRequest: false,
  258. data: this.$api.systemManagement.getSceneImporPagetList,
  259. param: {},
  260. },
  261. form: {
  262. name: "", // 任务名称
  263. sceneType: "", // 场景分类
  264. dataDirectory: "", // 场景路径
  265. fileName: "", // 文件名称
  266. },
  267. rules: {
  268. name: [{ required: true, message: "请输入", trigger: "blur" }],
  269. sceneType: [
  270. { required: true, message: "请选择", trigger: "change" },
  271. ],
  272. dataDirectory: [
  273. { required: true, message: "请输入", trigger: "blur" },
  274. ],
  275. fileName: [
  276. { required: true, message: "请上传", trigger: "change" },
  277. ],
  278. },
  279. sceneTypeList: [],
  280. dialogVisible: false,
  281. file: null,
  282. errRocordVisible: false,
  283. errorMessage: "",
  284. timer: null,
  285. };
  286. },
  287. methods: {
  288. doSearch() {
  289. // if (this.uploadDate) {
  290. // this.searchParams.timeBegin = `${this.uploadDate[0]}`;
  291. // this.searchParams.timeEnd = `${this.uploadDate[1]}`;
  292. // } else {
  293. // this.searchParams.timeBegin = "";
  294. // this.searchParams.timeEnd = "";
  295. // }
  296. let timeBegin = "";
  297. if (this.searchParams.timeBegin) {
  298. timeBegin = `${this.searchParams.timeBegin} 00:00:00`;
  299. }
  300. let timeEnd = "";
  301. if (this.searchParams.timeEnd) {
  302. timeEnd = `${this.searchParams.timeEnd} 23:59:59`;
  303. }
  304. if (timeBegin && timeEnd && timeBegin > timeEnd) {
  305. this.$message.error("结束时间不能早于开始时间");
  306. return;
  307. }
  308. let pageMap = {
  309. name: this.searchParams.name,
  310. timeBegin,
  311. timeEnd,
  312. };
  313. this.refreshList(pageMap);
  314. if (this.timer) clearInterval(this.timer);
  315. this.timer = setInterval(() => {
  316. if (this.$refs["table"]) this.doSearch();
  317. }, 1000 * 60);
  318. },
  319. //刷新table
  320. refreshList(param) {
  321. param
  322. ? this.$refs["table"].loadData(param)
  323. : this.$refs["table"].loadData();
  324. },
  325. doReset() {
  326. this.searchParams = {
  327. name: "",
  328. timeBegin: "",
  329. timeEnd: "",
  330. };
  331. // this.uploadDate = "";
  332. this.doSearch();
  333. },
  334. addOne() {
  335. this.form = {
  336. name: "",
  337. sceneType: "",
  338. dataDirectory: "",
  339. fileName: "",
  340. };
  341. this.file = null;
  342. this.dialogVisible = true;
  343. this.$nextTick(() => {
  344. this.$refs.form.clearValidate();
  345. });
  346. },
  347. viewRow(errorMessage) {
  348. this.errorMessage = errorMessage;
  349. this.errRocordVisible = true;
  350. },
  351. errClose() {
  352. this.errRocordVisible = false;
  353. this.errorMessage = "";
  354. },
  355. uploadConfirm() {
  356. this.$refs.form.validate(async (valid) => {
  357. if (valid) {
  358. if (this.form.sceneType === "4") {
  359. let formData = new FormData();
  360. await formData.append("taskName", this.form.name);
  361. await formData.append("name", this.file.name);
  362. await formData.append("file", this.file.raw);
  363. await this.$axios({
  364. method: "post",
  365. url: this.$api.systemManagement
  366. .saveSceneGeneralTemplateAll,
  367. data: formData,
  368. withCredentials: true,
  369. headers: {
  370. "Content-type": "multipart/form-data",
  371. },
  372. }).then((res) => {
  373. if (res.code == 200) {
  374. this.$message.success("保存成功");
  375. this.uploadCancel();
  376. this.doSearch();
  377. } else {
  378. this.$message.error(res.message || "保存失败");
  379. }
  380. });
  381. } else {
  382. this.$axios({
  383. method: "post",
  384. url: this.$api.systemManagement.saveTask,
  385. data: { ...this.form },
  386. }).then((res) => {
  387. if (res.code == 200) {
  388. this.$message.success("保存成功");
  389. this.uploadCancel();
  390. this.doSearch();
  391. } else {
  392. this.$message.error(res.message || "保存失败");
  393. }
  394. });
  395. }
  396. }
  397. });
  398. },
  399. uploadCancel() {
  400. this.dialogVisible = false;
  401. },
  402. attachmentChange(obj) {
  403. this.attachmentList = obj;
  404. },
  405. handleChange(file) {
  406. this.file = file;
  407. this.form.fileName = file.name;
  408. },
  409. sceneTypeChange(v) {
  410. if (v === "4") {
  411. this.$refs.form.clearValidate("dataDirectory");
  412. } else {
  413. this.file = null;
  414. this.form.fileName = "";
  415. this.$refs.form.clearValidate("fileName");
  416. }
  417. },
  418. },
  419. async mounted() {
  420. if (this.timer) clearInterval(this.timer);
  421. this.timer = setInterval(() => {
  422. if (this.$refs["table"]) this.doSearch();
  423. }, 1000 * 60);
  424. await this.$dicsListsInit({
  425. sceneTypeList: "sceneType",
  426. });
  427. },
  428. beforeDestroy() {
  429. clearInterval(this.timer);
  430. },
  431. };
  432. </script>
  433. <style lang='less' scoped>
  434. .btnsPanel {
  435. margin: 45px 40px 15px;
  436. text-align: right;
  437. }
  438. .errRecord {
  439. color: @themeColor;
  440. cursor: pointer;
  441. }
  442. .upload {
  443. margin-top: 15px;
  444. }
  445. </style>