sceneUploadList.vue 15 KB

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