PlanList.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <template>
  2. <div class="sub-container">
  3. <!-- <plan-table class_name="class-test" /> -->
  4. <div class="search-bar">
  5. <div class="left">
  6. <div class="search-date item">
  7. <!-- 建立日期 -->
  8. <div class="title">建立日期:</div>
  9. <el-date-picker
  10. v-model="dateValue"
  11. type="daterange"
  12. start-placeholder="开始日期"
  13. end-placeholder="结束日期"
  14. :default-time="['00:00:00', '23:59:59']"
  15. value-format="yyyy-MM-dd HH:mm:ss"
  16. @focus="hiddenToolTip"
  17. />
  18. </div>
  19. <div class="search-protocol item">
  20. <!-- 协议 -->
  21. <div class="title">协议:</div>
  22. <el-select v-model="protocolValue" filterable placeholder="请选择">
  23. <el-option
  24. v-for="item in protocolOptions"
  25. :key="item.id"
  26. :label="item.name"
  27. :value="item.id"
  28. />
  29. </el-select>
  30. </div>
  31. <div class="search-device-type item">
  32. <!-- 设备类型 暂时取消-->
  33. <div class="title">方案名称:</div>
  34. <el-input
  35. v-model="searchName"
  36. placeholder="请输入方案名称"
  37. clearable
  38. maxlength="32"
  39. />
  40. </div>
  41. </div>
  42. <div class="right">
  43. <div class="reset item">
  44. <el-button
  45. icon="el-icon-refresh-left"
  46. class="light-button"
  47. @click="searchReset()"
  48. >重置</el-button>
  49. </div>
  50. <div class="search-submit item">
  51. <el-button
  52. type="primary"
  53. icon="el-icon-search"
  54. class="dark-button"
  55. @click="planSearch()"
  56. >查询</el-button>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="content">
  61. <div class="content-title">
  62. <div class="left">
  63. <div class="clear item">
  64. <el-button
  65. :ref="`btn_case_batch_delete`"
  66. data-controlcode="btn_case_batch_delete"
  67. :class="{'dark-button':showDel}"
  68. icon="el-icon-delete"
  69. :disabled="!showDel"
  70. @click="multDelete()"
  71. >批量删除</el-button>
  72. </div>
  73. </div>
  74. <div class="right">
  75. <div class="creat-plan">
  76. <el-button
  77. ref="btn_case_new"
  78. data-controlcode="btn_case_new"
  79. icon="el-icon-plus"
  80. class="light-button"
  81. @click="routerGoto('/plan/save')"
  82. >新建方案</el-button>
  83. </div>
  84. <div ref="btn_exp_case" data-controlcode="btn_exp_case" class="export-plan">
  85. <a download="方案列表.xls" target="_blank" :href="`${APP_BASE_API}/test/suite/suite.xls`">
  86. <el-button
  87. icon="el-icon-upload"
  88. class="light-button"
  89. >列表导出</el-button>
  90. </a>
  91. </div>
  92. </div>
  93. </div>
  94. <div class="table-container">
  95. <el-table :data="tableData" :height="tableHeight" stripe @selection-change="handleSelectionChange">
  96. <!-- 隐藏 列 这里不用显示,但是在编辑的时候需要获取此数据 -->
  97. <el-table-column v-if="false" prop="planId" label="序号" />
  98. <!-- 隐藏 列 -->
  99. <el-table-column
  100. type="selection"
  101. />
  102. <el-table-column prop="planName" label="方案名称" />
  103. <el-table-column prop="deviceType" label="检测协议" />
  104. <el-table-column prop="checkModel" label="测点模型">
  105. <template slot-scope="scope">
  106. <el-link type="primary" @click="toSee(scope.row)">查看</el-link>
  107. </template>
  108. </el-table-column>
  109. <el-table-column prop="creatDate" label="创建日期" />
  110. <el-table-column fixed="right" label="操作" width="160">
  111. <template slot-scope="scope">
  112. <!--
  113. 按状态显示
  114. 未运行
  115. 编辑
  116. 删除
  117. 已运行
  118. 详情
  119. 导出
  120. -->
  121. <!-- planId > 0 时显示 -->
  122. <span
  123. v-if="scope.row.planId > 0"
  124. :ref="`btn_case_edit_${scope.$index}`"
  125. data-controlcode="btn_case_edit"
  126. class="table-act"
  127. type="text"
  128. icon="el-icon-edit"
  129. size="small"
  130. style="cursor: pointer;"
  131. @click="editClick(scope.row)"
  132. ><i class="el-icon-edit" /> 编辑</span>
  133. <span
  134. v-if="scope.row.planId > 0"
  135. :ref="`btn_case_delete_${scope.$index}`"
  136. data-controlcode="btn_case_delete"
  137. class="table-act"
  138. type="text"
  139. icon="el-icon-delete"
  140. size="small"
  141. style="cursor: pointer;"
  142. @click="delClick(scope.row, scope.$index)"
  143. ><i class="el-icon-delete" /> 删除</span>
  144. <!-- planId = 0 时显示 -->
  145. <div v-if="scope.row.planId == 0">加载中...</div>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. </div>
  150. <!-- 分页 -->
  151. <div class="page-bar">
  152. <pagination
  153. background
  154. layout="pager"
  155. :limit="pageLimit"
  156. :total="paginationTotalElements"
  157. :current-page.sync="paginationNumber"
  158. :page="paginationNumber"
  159. @pagination="planSearch"
  160. />
  161. </div>
  162. <!-- 查看模型点弹出框 -->
  163. <el-dialog title="模型点表" :visible.sync="showCheckModel">
  164. <el-table :data="checkModelData" :height="modaltableHeight" stripe>
  165. <el-table-column property="id" label="序号" />
  166. <el-table-column property="name" label="测点名称" />
  167. <el-table-column property="groupingName" label="设备名称" />
  168. <el-table-column property="range" label="测点类型" />
  169. <el-table-column property="offset" label="点号" />
  170. </el-table>
  171. <!-- 分页 -->
  172. <div class="page-bar">
  173. <pagination
  174. background
  175. layout="pager"
  176. :limit="dialogPageLimit"
  177. :total="dialogPaginationTotalElements"
  178. :current-page.sync="dialogPaginationNumber"
  179. :page="dialogPaginationNumber"
  180. @pagination="getdialogPoint"
  181. />
  182. </div></el-dialog>
  183. <!-- 底部按钮 -->
  184. <!-- <div class="bottom-button">
  185. <div class="cancel-plan">
  186. <el-button class="light-button">取消</el-button>
  187. </div>
  188. <div class="save-plan">
  189. <el-button class="dark-button">保存</el-button>
  190. </div>
  191. </div> -->
  192. </div>
  193. </div>
  194. </template>
  195. <script>
  196. import { dictOptions } from '@/api/dict'
  197. import { searchPlanData, planCheckPoint } from '@/api/plan'
  198. import { delRecord, getOptions, httpGet } from '@/api/common-action'
  199. import Pagination from '@/components/Pagination'
  200. export default {
  201. name: 'PlanList',
  202. components: { Pagination },
  203. data() {
  204. return {
  205. // 提示框默认数据
  206. dateToolTip: {
  207. dateToolTipShow: false,
  208. dateToolTipContent: '加载中'
  209. },
  210. // 表格默认数据
  211. tableData: [
  212. {
  213. planId: 0,
  214. planName: '加载中...',
  215. deviceType: '加载中...',
  216. checkModel: '加载中...',
  217. protocol: '加载中...',
  218. creatDate: '加载中...'
  219. }
  220. ],
  221. APP_BASE_API: window.STATIC_CONFIG.proxyUrl,
  222. // 固定表头的表格高度
  223. tableHeight: 0,
  224. // 每页显示多少条
  225. pageLimit: 20,
  226. dialogPageLimit: 20,
  227. // 当前第几页
  228. paginationNumber: 1,
  229. dialogPaginationNumber: 1,
  230. // 一共多少条
  231. paginationTotalElements: 0,
  232. dialogPaginationTotalElements: 0,
  233. // 一共多少页
  234. // paginationTotalPages: 1,
  235. // 建立日期
  236. dateValue: [],
  237. // 协议
  238. protocolOptions: [],
  239. // 协议默认值
  240. protocolValue: '',
  241. deviceTypeValue: '',
  242. searchName: '',
  243. /*
  244. // 设备类型暂时取消
  245. deviceOptions: [
  246. {
  247. value: 'device-id-1',
  248. label: '设备型号1'
  249. },
  250. {
  251. value: 'device-id-2',
  252. label: '设备型号2'
  253. },
  254. {
  255. value: 'device-id-3',
  256. label: '设备型号3'
  257. },
  258. {
  259. value: 'device-id-4',
  260. label: '设备型号4'
  261. }
  262. ], */
  263. // 控制模型点弹出框显示
  264. showCheckModel: false,
  265. // 模型点表数据
  266. checkModelData: [],
  267. // 控制批量删除按钮状态
  268. showDel: false,
  269. // 多选框选中数据
  270. multipleSelection: [],
  271. // 功能码选项
  272. checkPointFuctionOptions: [],
  273. // 值类型列表
  274. valueTypeOptions: [],
  275. // 模态框固定表头的表格高度
  276. modaltableHeight: 0,
  277. // 当前查看测点模型的id
  278. showModelId: ''
  279. }
  280. },
  281. watch: {
  282. multipleSelection(nv, ov) {
  283. if (nv.length === 0) {
  284. this.showDel = false
  285. }
  286. }
  287. },
  288. created() {
  289. // 动态设置表格高度
  290. const marginBottom = 300
  291. this.tableHeight = window.innerHeight - marginBottom
  292. const modalmarginBottom = 400
  293. this.modaltableHeight = window.innerHeight - modalmarginBottom
  294. },
  295. mounted() {
  296. this.$nextTick(() => {
  297. // 网页加载完成后执行
  298. this.initFunctions()
  299. // 对表格中的操作列做了权限控制(根据权限可能会移除其中的按钮)后,会导致操作列的行高错位(原因是有固定列),需要再调用一次查询方法重绘一下表格才能恢复正常,原理不明,但确实能解决问题
  300. this.planSearch()
  301. })
  302. },
  303. methods: {
  304. // 初始化
  305. async initFunctions() {
  306. // 获取功能码选项 131
  307. let res = await getOptions('/dict/131/options')
  308. this.checkPointFuctionOptions = res
  309. // 获取值类型列表
  310. res = await dictOptions('132')
  311. this.valueTypeOptions = res
  312. // console.log('获取值类型列表 this.valueTypeOptions=', this.valueTypeOptions)
  313. // console.log('获取功能码 this.checkPointFuctionOptions=', this.checkPointFuctionOptions)
  314. // 初始化协议选项
  315. // 初始化检测状态选项
  316. this.protocolOptions = [
  317. {
  318. id: null,
  319. name: '全部'
  320. }
  321. ]
  322. // 设置默认选中值
  323. this.protocolValue = this.protocolOptions[0].id
  324. this.protocolOptions.push(
  325. ...JSON.parse(localStorage.getItem('dictDeviceProductType'))
  326. )
  327. // console.log('获取字典选项 this.protocolOptions=', this.protocolOptions)
  328. // this.initProtocolOptions()
  329. this.planSearch()
  330. },
  331. // 查询
  332. planSearch(pageObj) {
  333. // 翻页时pageObj对象才会有值,属性分别为page和limit
  334. if (pageObj == null) {
  335. pageObj = {
  336. page: 0,
  337. limit: this.pageLimit
  338. }
  339. this.paginationNumber = 1
  340. } else {
  341. this.pageLimit = pageObj.limit
  342. }
  343. const searchParams = {
  344. // 通信协议 productType
  345. productType: this.protocolValue,
  346. // 建立日期 this.dateValue: start end
  347. start: this.dateValue ? this.dateValue[0] : null,
  348. end: this.dateValue ? this.dateValue[1] : null,
  349. name: this.searchName,
  350. // 未知 enable #TODO: 这里这个 enable 还不知道什么意思 先使用默认值 1
  351. enable: 1
  352. }
  353. // console.log('getDictOptions dictData=', dictData)
  354. searchPlanData(pageObj, searchParams).then((response) => {
  355. this.paginationTotalElements = response.totalElements * 1 // *1 强制转换为数字型
  356. this.paginationNumber = response.number * 1 + 1
  357. this.getTableData(response)
  358. this.$nextTick(() => {
  359. this.common.ApplyElementPurviewByRef(this.$refs)
  360. })
  361. })
  362. },
  363. // 重置查询
  364. searchReset() {
  365. // 建立日期
  366. this.dateValue = []
  367. this.protocolValue = ''
  368. this.deviceTypeValue = ''
  369. this.searchName = ''
  370. // 重置后,重载一次表格数据
  371. this.planSearch()
  372. },
  373. // 改变页码
  374. changePage(pageObj) {
  375. // console.log('pageObj= ', pageObj)
  376. this.getPlan(pageObj)
  377. },
  378. // 隐藏提示条
  379. hiddenToolTip() {
  380. // console.log('hiddenToolTip start')
  381. this.dateToolTip.dateToolTipShow = false
  382. },
  383. // 列表导出
  384. exportPlan() {
  385. // console.log('列表导出')
  386. this.$message({
  387. message: '列表导出 正在准备后端数据',
  388. type: 'warning',
  389. offset: window.screen.height / 3
  390. })
  391. },
  392. // 跳转到新建一样的界面,只不过会有默认数据
  393. editClick(row) {
  394. // console.log('editClick=', row)
  395. this.$router.push({
  396. path: `/plan/save`,
  397. query: { planId: row.planId, isChange: true }
  398. })
  399. },
  400. // 多选按钮状态改变 handleSelectionChange
  401. handleSelectionChange(val) {
  402. // console.log('val= ', val)
  403. // 选中行存入临时变量中
  404. this.multipleSelection = val
  405. // console.log('handleSelectionChange val', val)
  406. // 批量删除按钮激活
  407. this.showDel = true
  408. },
  409. // 批量删除
  410. async multDelete() {
  411. for (let i = 0; i < this.tableData.length; i++) {
  412. const item = this.tableData[i]
  413. // 判断当前行数据是否被选中
  414. if (this.multipleSelection.includes(item)) {
  415. // 如果选中,则从 开始删除
  416. // console.log('this.multipleSelection item=', item)
  417. // 如果 id > 0 则表示 是已经保存在后端的数据了,需要向后端发送删除请求
  418. const delUrl = `/test/suite/${item.planId}`
  419. await delRecord(delUrl).then((response) => {
  420. // console.log('delRecord rs=', response)
  421. // 后端成功执行后,前端再删除选中行
  422. this.tableData.splice(i, 1)
  423. i-- // 因为 `splice` 方法会修改数组长度,所以需要将 `i` 减去 1,避免漏删下一个元素
  424. }).catch((err) => {
  425. console.log('delRecord err rs=', err)
  426. })
  427. }
  428. }
  429. },
  430. delClick(row, index) {
  431. // console.log('delClick row=', row)
  432. this.$confirm(
  433. '此操作将永久删除该记录, 是否继续?',
  434. `删除:${row.planName}`,
  435. {
  436. confirmButtonText: '确定',
  437. cancelButtonText: '取消',
  438. type: 'warning'
  439. }
  440. )
  441. .then(() => {
  442. if (row.planId > 0) {
  443. // /test/suite/:suite
  444. delRecord(`/test/suite/${row.planId}`)
  445. .then((response) => {
  446. // console.log('delRecord rs=', response)
  447. // 后端成功执行后,前端再删除选中行
  448. this.tableData.splice(index, 1)
  449. // console.log('delClick index=', index)
  450. // console.log('delClick this.tableData=', this.tableData)
  451. this.$message({
  452. message: `${row.planName} 删除成功`,
  453. type: 'success',
  454. offset: window.screen.height / 3
  455. })
  456. this.planSearch()
  457. })
  458. .catch((err) => {
  459. console.log('delRecord err rs=', err)
  460. })
  461. } else {
  462. // 如果是新增的临时行,直接删除选中行
  463. this.tableData.splice(index, 1)
  464. }
  465. })
  466. .catch(() => {
  467. this.$message({
  468. type: 'info',
  469. message: '已取消删除',
  470. offset: window.screen.height / 3
  471. })
  472. })
  473. },
  474. routerGoto(goto_url) {
  475. this.$router.push({ path: goto_url })
  476. },
  477. // 获取测点表格数据
  478. async getdialogPoint(pageObj) {
  479. // 翻页时pageObj对象才会有值,属性分别为page和limit
  480. if (pageObj == null) {
  481. pageObj = {
  482. page: 0,
  483. limit: this.dialogPageLimit
  484. }
  485. this.dialogPaginationNumber = 0
  486. } else {
  487. this.dialogPageLimit = pageObj.limit
  488. }
  489. const getUrl = `/product/model/${this.showModelId}/paging?page=${pageObj.page}&size=${pageObj.limit}`
  490. httpGet(getUrl).then((response) => {
  491. this.checkModelData = response.content.map(item => {
  492. this.checkPointFuctionOptions.forEach(par => {
  493. if (item.range === par.id) {
  494. item.range = par.name
  495. }
  496. })
  497. this.valueTypeOptions.forEach(par => {
  498. if (item.dataType === par.id) {
  499. item.dataType = par.name
  500. }
  501. })
  502. return item
  503. })
  504. this.dialogPaginationTotalElements = parseInt(response.totalElements)
  505. this.dialogPaginationNumber = response.number * 1 + 1
  506. })
  507. },
  508. // 查看模型点表
  509. async toSee(row) {
  510. // console.log('tosee=', row)
  511. this.showCheckModel = true
  512. this.showModelId = row.checkModel
  513. const res = await planCheckPoint(row.checkModel)
  514. // console.log('tosee res=', res)
  515. this.checkModelData = res.content.map(item => {
  516. this.checkPointFuctionOptions.forEach(par => {
  517. if (item.range === par.id) {
  518. item.range = par.name
  519. }
  520. })
  521. this.valueTypeOptions.forEach(par => {
  522. if (item.dataType === par.id) {
  523. item.dataType = par.name
  524. }
  525. })
  526. return item
  527. })
  528. this.dialogPaginationTotalElements = parseInt(res.totalElements)
  529. },
  530. // 获取表格数据-公用
  531. getTableData(tmpTableData) {
  532. const productTypeArr = JSON.parse(
  533. localStorage.getItem('dictDeviceProductType')
  534. )
  535. // console.log('productType=', productTypeArr)
  536. this.tableData = []
  537. tmpTableData.content.forEach((rs_v) => {
  538. const newTable = {
  539. planId: rs_v.id,
  540. planName: rs_v.name,
  541. deviceType: rs_v.productType,
  542. checkModel: rs_v.product,
  543. protocol: rs_v.protocol,
  544. creatDate: rs_v.createdDate
  545. }
  546. productTypeArr.forEach((item) => {
  547. if (item.id === newTable.deviceType) {
  548. newTable.deviceType = item.name
  549. }
  550. })
  551. this.tableData.push(newTable)
  552. })
  553. }
  554. }
  555. }
  556. </script>
  557. <!-- // tool-tip 样式不能写在 scoped 中-->
  558. <style lang="scss">
  559. $tool-tip-bg: #db1414;
  560. // tool-tip 样式必须写在最外面,dom结构它就在最外面
  561. // 如果 vue 中的 placement = "left" 那么 border-top-color 应该是 border-left-color
  562. .warnning-tool-tip.el-tooltip__popper[x-placement^="top"] .popper__arrow {
  563. border-top-color: $tool-tip-bg;
  564. }
  565. .warnning-tool-tip.el-tooltip__popper[x-placement^="top"] .popper__arrow:after {
  566. border-top-color: $tool-tip-bg;
  567. }
  568. .warnning-tool-tip {
  569. background: $tool-tip-bg !important;
  570. }
  571. </style>
  572. <style lang="scss" scoped>
  573. .sub-container {
  574. // border: 1px #CCC solid;
  575. padding: 5px 10px;
  576. background-color: #fff;
  577. position: relative;
  578. font-size: 18px;
  579. color: rgb(112, 112, 112);
  580. height: 100%;
  581. overflow: hidden;
  582. // 搜索栏
  583. .search-bar {
  584. display: flex;
  585. border: 1px #ccc solid;
  586. padding: 20px 0 14px 20px;
  587. justify-content: left;
  588. font-size: 16px;
  589. .left {
  590. width: 80%;
  591. display: flex;
  592. .item {
  593. padding-right: 20px;
  594. display: flex;
  595. align-items: center;
  596. }
  597. .search-date {
  598. .title {
  599. padding-right: 5px;
  600. }
  601. }
  602. .search-device-type {
  603. .title {
  604. width: 120px;
  605. padding-right: 5px;
  606. }
  607. }
  608. }
  609. .right {
  610. width: 20%;
  611. display: flex;
  612. justify-content: right;
  613. .item {
  614. padding-right: 20px;
  615. }
  616. }
  617. }
  618. // 表格内容
  619. .content {
  620. border: 1px #ccc solid;
  621. margin-top: 20px;
  622. height: 100%;
  623. padding: 10px;
  624. .content-title {
  625. display: flex;
  626. justify-content: right;
  627. padding: 10px;
  628. .left,
  629. .right {
  630. width: 50%;
  631. .creat-plan {
  632. padding-right: 20px;
  633. }
  634. }
  635. .right{
  636. display: flex;
  637. justify-content: right;
  638. }
  639. }
  640. .table-container {
  641. height: 100%;
  642. .table-act {
  643. padding-right: 20px;
  644. }
  645. }
  646. }
  647. // 底部按钮
  648. .bottom-button {
  649. display: flex;
  650. justify-content: center;
  651. padding-bottom: 20px;
  652. .cancel-plan {
  653. padding-right: 20px;
  654. }
  655. }
  656. // 按钮公用样式
  657. .dark-button {
  658. background-color: #00706b;
  659. border: 1px #00706b solid;
  660. color: #fff;
  661. }
  662. .light-button {
  663. color: #00706b;
  664. border: 1px #00706b solid;
  665. }
  666. }
  667. </style>