index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="check-body">
  3. <div class="site-content">
  4. <div class="site-row">
  5. <div class="site-progress" :style="`width: ${currentProgress}%`"></div>
  6. <div class="site-label">
  7. <div class="site-node" v-for="(item,index) in checkList" :key="item.ccId">
  8. <div :class="['site',index<=cIndex && cIndex!=null?'normal':'un-info ']"/>
  9. <div :class="['site-name',{'active-site-name':index<=cIndex && cIndex!=null}]">{{ item.className }}</div>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. <div class="site-content mt10">
  15. <div class="check-status">
  16. <el-button type="primary" :loading="cLoading" @click="onNowCheck"
  17. style="padding:16px 22px;">
  18. 立即巡检
  19. </el-button>
  20. <span class="check-progress" v-if="cLoading">
  21. <span class="t-span">巡检进度:</span>
  22. <el-progress type="circle" :percentage="currentProgress" width="50" stroke-width="4" :color="colors">
  23. <template #default="{ percentage }">
  24. <span class="percentage-value">{{ percentage }}%</span>
  25. </template>
  26. </el-progress>
  27. </span>
  28. <span class="check-progress" v-else>
  29. <span class="t-span" style="font-size: 14px;font-weight: 400;text-align: center;width: 100%;"
  30. v-show="nowCheck.checkResult">
  31. {{ nowCheck.checkResult }}
  32. </span>
  33. </span>
  34. <span>
  35. <span v-show="checkTime" class="check-time">
  36. <span v-if="checkFlag" style="margin-right: 10px">
  37. <el-button size="small" @click="handleDialog('setting')" icon="Setting">巡检记录配置</el-button>
  38. <el-button size="small" @click="handleDialog('report')" icon="Document">
  39. 巡查报告查看
  40. </el-button>
  41. </span>
  42. <span class="t-span">巡检时间:</span>
  43. <span class="check-time">{{ checkTime }}</span>
  44. </span>
  45. </span>
  46. </div>
  47. <el-table :data="listData" style="width: 100%" border class="mt20" :span-method="spanMethod">
  48. <el-table-column prop="className" label="分类" width="180" align="center"/>
  49. <el-table-column prop="checkName" label="巡检项"/>
  50. <el-table-column label="巡检结果" width="160" align="center">
  51. <template #default="{row}">
  52. <span v-if="checkTime">
  53. <span v-if="row.resultL">
  54. {{ row.resultL }}
  55. </span>
  56. <el-icon size="25" color="#388e3c" class="rotate" v-else><Loading/></el-icon>
  57. </span>
  58. <span v-else>-</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column prop="remark" label="备注" align="center" width="160">
  62. <template #default="{row}">
  63. <span v-if="checkTime">
  64. <span v-if="row.resultR" :style="`color:${row.resultR === '正常'||row.resultR === '是'?'#1ab43f':'#e43'}`">
  65. {{ row.resultR }}
  66. </span>
  67. <el-icon size="25" color="#388e3c" class="rotate" v-else><Loading/></el-icon>
  68. </span>
  69. <span v-else>-</span>
  70. </template>
  71. </el-table-column>
  72. </el-table>
  73. </div>
  74. <el-dialog v-model="isComponent.visible" width="1000" :title="isComponent.title" style="margin-top:2vh!important">
  75. <component :is="isComponent.component" :crId="nowCheck.crId" :spanMethod="spanMethod"/>
  76. </el-dialog>
  77. </div>
  78. </template>
  79. <script setup lang="ts">
  80. import {chkcCheck, chkcResult, listChkc} from "@/api/check/chkc"
  81. import {onMounted} from "vue";
  82. import {Loading} from "@element-plus/icons-vue";
  83. import nCheckList from "./widget/nCheckList.vue"
  84. import nReportList from "./widget/nReportList.vue"
  85. const checkList = ref([])
  86. const listData = ref([])
  87. const currentProgress = ref(0)
  88. const cIndex = ref(null)
  89. const cLoading = ref(false)
  90. const checkTime = ref(null)
  91. const nowCheck = ref({})
  92. const checkFlag = ref(false)
  93. const isComponent = ref({
  94. visible: false,
  95. title: "",
  96. component: nReportList
  97. })
  98. const colors = [
  99. {color: '#bbdefb', percentage: 20},
  100. {color: '#90caf9', percentage: 40},
  101. {color: '#64b5f6', percentage: 60},
  102. {color: '#2196f3', percentage: 80},
  103. {color: '#1e88e5', percentage: 100},
  104. ]
  105. const initData = async () => {
  106. await chkcResult(0)
  107. getListChkc().then()
  108. }
  109. onMounted(() => {
  110. if (localStorage.getItem("listData")) {
  111. return restoreCache()
  112. }
  113. initData()
  114. })
  115. const handleDialog = (action) => {
  116. if (action === 'report') {
  117. isComponent.value = {
  118. visible: true,
  119. title: "巡检报告查看",
  120. component: nReportList
  121. }
  122. } else {
  123. isComponent.value = {
  124. visible: true,
  125. title: "巡检记录配置",
  126. component: nCheckList
  127. }
  128. }
  129. }
  130. const restoreCache = async () => {
  131. const {data} = await chkcResult(0)
  132. console.error(data)
  133. // listData.value = JSON.parse(localStorage.getItem("listData"))
  134. nowCheck.value = data
  135. listData.value = data.detailList
  136. checkTime.value = data.checkTime;
  137. // checkResult.value = data.checkResult
  138. checkList.value = uniqueByKey(listData.value, 'className')
  139. checkFlag.value = true
  140. // cIndex.value = listData.value.length - 1
  141. // checkTime.value = nowCheck.value.checkTime
  142. currentProgress.value = 100
  143. }
  144. const spanMethod = ({row, column, rowIndex}) => {
  145. if (column.property === "className") {
  146. const currentClass = listData.value[rowIndex].className;
  147. const prevClass = listData.value[rowIndex - 1]?.className;
  148. if (currentClass !== prevClass) {
  149. let rowspan = 1;
  150. for (let i = rowIndex + 1; i < listData.value.length; i++) {
  151. if (listData.value[i].className === currentClass) {
  152. rowspan++;
  153. } else {
  154. break;
  155. }
  156. }
  157. return {rowspan, colspan: 1};
  158. } else {
  159. return {rowspan: 0, colspan: 0};
  160. }
  161. }
  162. }
  163. const uniqueByKey = (array, key) => {
  164. const map = new Map();
  165. array.forEach(item => map.set(item[key], item));
  166. return Array.from(map.values());
  167. }
  168. const getListChkc = async () => {
  169. const {rows} = await listChkc({pageSize: 100})
  170. listData.value = rows
  171. checkList.value = uniqueByKey(rows, 'className')
  172. }
  173. const padZero = (number) => {
  174. return (number < 10 ? "0" : "") + number;
  175. }
  176. const getRandomInt = (min, max) => {
  177. return Math.floor(Math.random() * (max - min + 1)) + min;
  178. }
  179. const onNowCheck = async () => {
  180. const {data} = await chkcCheck()
  181. nowCheck.value = data
  182. checkTime.value = data.checkTime;
  183. handleCheck(0)
  184. }
  185. const handleCheck = (i) => {
  186. if (!cLoading.value) {
  187. getListChkc();
  188. cLoading.value = true;
  189. cIndex.value = null;
  190. currentProgress.value = 0;
  191. checkFlag.value = false;
  192. if (localStorage.getItem("listData")) {
  193. localStorage.removeItem("listData")
  194. localStorage.removeItem("nowCheck")
  195. }
  196. }
  197. const randomStep = getRandomInt(1, 4);
  198. const index = Math.min(i + randomStep, listData.value.length - 1);
  199. if (i < listData.value.length) {
  200. setTimeout(() => {
  201. currentProgress.value = Number(((index + 1) / listData.value.length * 100).toFixed(1));
  202. for (let j = i; j <= index; j++) {
  203. const item = listData.value[j];
  204. const detail = nowCheck.value.detailList.find(cItem => cItem.ccId === item.ccId);
  205. if (detail) {
  206. const {resultL, resultR, remark} = detail;
  207. listData.value[j] = {...item, resultL, resultR, remark};
  208. }
  209. }
  210. handleCheck(index + 1);
  211. }, getRandomInt(1000, 4000));
  212. } else {
  213. cLoading.value = false;
  214. currentProgress.value = 100;
  215. checkFlag.value = true
  216. localStorage.setItem("nowCheck", JSON.stringify(nowCheck.value))
  217. localStorage.setItem("listData", JSON.stringify(listData.value))
  218. }
  219. }
  220. </script>
  221. <style scoped lang="scss">
  222. @import "./css/style.scss";
  223. </style>