scdTree.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <div>
  3. <div class="btnBox">
  4. <div @click="checkNow">
  5. <img :src="addPng" alt="" />
  6. <span>新的比对</span>
  7. </div>
  8. <div @click="reloadCheck">
  9. <img :src="againPng" alt="" />
  10. <span>重新比对</span>
  11. </div>
  12. <div @click="excelPort">
  13. <img :src="dervicePng" alt="" />
  14. <span>导出所有结果</span>
  15. </div>
  16. </div>
  17. <div class="tableBox">
  18. <el-table
  19. ref="multipleTableRef"
  20. :data="tableList"
  21. style="width: 100%; height: calc(100vh - 320px)"
  22. stripe
  23. @selection-change="handleSelectionChange"
  24. @select-all="chooseAll"
  25. :header-cell-style="{
  26. background: '#F7F8FB !important',
  27. color: '#7484AB',
  28. borderBottom: '1px solid #A3ADE0 !important',
  29. fontWeight: '400',
  30. }"
  31. >
  32. <el-table-column type="selection" width="55" />
  33. <el-table-column
  34. label="对比scd"
  35. width="190"
  36. :show-overflow-tooltip="true"
  37. >
  38. <template #default="scope">{{ scope.row.name }}</template>
  39. </el-table-column>
  40. <el-table-column
  41. property="CREATED_TIME"
  42. label="时间"
  43. width="auto"
  44. :show-overflow-tooltip="true"
  45. />
  46. <el-table-column fixed="right" label="操作" width="120">
  47. <template #default="scope">
  48. <el-button
  49. link
  50. type="primary"
  51. size="small"
  52. @click="searchScdCheck(scope.row)"
  53. ><el-icon> <View /> </el-icon>查看</el-button
  54. >
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. </div>
  59. <!-- <div>新的对比
  60. <LookScd
  61. v-if="lookScdModal"
  62. :lookScdModal="lookScdModal"
  63. :aktType="aktType"
  64. @lookScdBack="lookScdBack"
  65. >
  66. </LookScd>
  67. </div> -->
  68. <!-- 新的对比弹窗 -->
  69. <el-dialog
  70. @close="cancelClick"
  71. v-model="lookScdModal"
  72. width="30vw"
  73. style="height: 400px"
  74. append-to-body
  75. draggable
  76. >
  77. <template #header>
  78. <div class="my-header">
  79. <div class="title">请选择对比的SCD文件</div>
  80. </div>
  81. </template>
  82. <div class="uploda-file" v-loading="loadingAdd">
  83. <span class="file-title">选择文件</span>
  84. <el-input
  85. v-model="chooseFile"
  86. class="w-50 m-2"
  87. placeholder="点击右侧按钮上传文件"
  88. clearable
  89. @clear="clearFile"
  90. >
  91. <template #suffix>
  92. <img
  93. v-if="chooseFile"
  94. :src="uploadSPng"
  95. alt=""
  96. style="width: 20px; height: 20px"
  97. />
  98. <img
  99. v-if="loadingAddError"
  100. :src="uploadEPng"
  101. alt=""
  102. style="width: 20px; height: 20px"
  103. />
  104. </template>
  105. </el-input>
  106. <el-upload
  107. v-model:file-list="fileList"
  108. :limit="1"
  109. class="upload-demo"
  110. :http-request="uploadFile"
  111. :on-exceed="exceed"
  112. :show-file-list="false"
  113. >
  114. <template #trigger>
  115. <div class="upload-title">
  116. <img :src="uploadPng" alt="" />
  117. <span>上传文件</span>
  118. </div>
  119. </template>
  120. </el-upload>
  121. </div>
  122. <div class="sure-file">
  123. <div v-if="!isAnalysis && AnalysisProcess" class="analysis success">
  124. 文件解析完成
  125. </div>
  126. <div v-else-if="isAnalysis && AnalysisProcess" class="analysis fail">
  127. 文件解析失败
  128. </div>
  129. <div v-if="chooseFile && !AnalysisProcess" class="analysis">
  130. 文件正在解析中,请等待...
  131. </div>
  132. <!-- <div
  133. class="sures"
  134. :class="{ 'sures-success': !isAnalysis && AnalysisProcess }"
  135. >
  136. 确认上传
  137. </div> -->
  138. <div
  139. class="sures"
  140. :class="{ 'sures-success': !isAnalysis && AnalysisProcess }"
  141. >
  142. 开始对比
  143. </div>
  144. </div>
  145. </el-dialog>
  146. </div>
  147. </template>
  148. <script setup>
  149. import {
  150. ref,
  151. onMounted,
  152. toRefs,
  153. watch,
  154. nextTick,
  155. defineEmits,
  156. onUnmounted,
  157. } from "vue";
  158. import scdCheck from "@/api/scdCheck/scdCheck";
  159. import { uploadfile, tmpParse } from "@/api/scdCheck/scdCheck2";
  160. import scd from "@/api/scd";
  161. import systemRow from "@/api/systemRow";
  162. import { ElMessage, ElLoading } from "element-plus";
  163. import LookScd from "../modalCom/LookScd.vue";
  164. import dervicePng from "@/assets/image/scdcheck/derive.png";
  165. import againPng from "@/assets/image/scdcheck/again.png";
  166. import addPng from "@/assets/image/scdcheck/add.png";
  167. import uploadPng from "@/assets/image/scdcheck/upload.png";
  168. import uploadSPng from "@/assets/image/scdcheck/upload_success.png";
  169. import uploadEPng from "@/assets/image/scdcheck/upload_error.png";
  170. import { useRoute } from "vue-router";
  171. import createds from "@/utils/scdMqtt.js";
  172. const route = useRoute();
  173. const emit = defineEmits(["scdTreeBack"]);
  174. let tableList = ref([]);
  175. let multipleTableRef = ref();
  176. let alreadyTriggered = ref(false);
  177. let scdid = ref([]);
  178. const loading = ref(false);
  179. let lookScdArr = ref([]);
  180. let lookScdModal = ref(false);
  181. const fileList = ref([]); //上传的文件
  182. const loadingAdd = ref(false); //文件上传的加载状态
  183. const loadingAddError = ref(false); //文件上传的加载状态
  184. const chooseFile = ref("");
  185. const handleSelectionChange = (e) => {
  186. //复选
  187. };
  188. const chooseAll = (e) => {
  189. //全选
  190. };
  191. const checkNow = (e) => {
  192. //scd比对
  193. lookScdModal.value = true;
  194. };
  195. const excelPort = () => {
  196. //导出excel
  197. systemRow
  198. .portExcel({
  199. code: "scd-comp-result",
  200. })
  201. .then((res) => {
  202. console.log(res, "port");
  203. if (res.data) {
  204. return;
  205. } else {
  206. ElMessage({
  207. message: res.msg,
  208. type: "info",
  209. });
  210. }
  211. });
  212. };
  213. const reloadCheck = () => {
  214. //重新比对
  215. checkNow();
  216. };
  217. const exceed = (files) => {
  218. if (fileList.value.length > 0) {
  219. ElMessage({
  220. type: "warning",
  221. message: "请清除选择文件后重新选择!",
  222. });
  223. }
  224. };
  225. const uploadFile = async (e) => {
  226. fileList.value = [];
  227. chooseFile.value = "";
  228. loadingAddError.value = false;
  229. console.log("e", e);
  230. loadingAdd.value = true;
  231. const fileRes = await uploadfile({
  232. file: e.file,
  233. station_id: route.query.stationId,
  234. is_checkin: 0,
  235. data_type: "a_scd",
  236. });
  237. if (fileRes.code == 0) {
  238. fileList.value.push(fileRes.data);
  239. chooseFile.value = fileRes.data.filename;
  240. loadingAdd.value = false;
  241. ElMessage({
  242. type: "success",
  243. message: "上传成功!",
  244. });
  245. const resParse = await tmpParse({
  246. station_id: route.query.stationId,
  247. scd_name: fileRes.data.filename,
  248. scd_path: fileRes.data.path,
  249. });
  250. startMqtt(`/jujutong/scd_check_tools/parse/#`);
  251. } else {
  252. loadingAdd.value = false;
  253. loadingAddError.value = true;
  254. ElMessage({
  255. type: "error",
  256. message: "上传失败!",
  257. });
  258. }
  259. };
  260. const searchScdCheck = (row) => {
  261. //查看scd对比
  262. const loading = ElLoading.service({
  263. lock: true,
  264. text: "正在查询数据",
  265. background: "rgba(0, 0, 0, 0.7)",
  266. });
  267. scdCheck.scdResult({ comp_id: row.id }).then((res) => {
  268. console.log(res, "对比详细");
  269. if (res.code == 0) {
  270. loading.close();
  271. }
  272. });
  273. // scdCheck.scdAll({ comp_id: row.id }).then(res => {
  274. // console.log(res, '阿拉蕾');
  275. // })
  276. };
  277. const lookScdBack = (data, row) => {
  278. //选择scd文件模态框返回数据
  279. lookScdModal.value = data;
  280. lookScdArr.value = row;
  281. emit("scdTreeBack", lookScdArr.value);
  282. };
  283. const aktType = () => {
  284. //初始化数据
  285. scdCheck
  286. .flashStationDui({ station_id: route.query.stationId })
  287. .then((res) => {
  288. //获取差异纪录列表
  289. tableList.value = res.data;
  290. });
  291. };
  292. // mqtt=======
  293. const PublicMqtt = ref(null);
  294. const mesg = ref(null); //订阅成功的消息
  295. const isAnalysis = ref(false); //解析是否成功
  296. const AnalysisProcess = ref(false); //解析是否完成
  297. const startMqtt = (val) => {
  298. //val = 订阅地址
  299. //设置订阅地址
  300. PublicMqtt.value = new createds(val);
  301. console.log("firPublicMqtt.valuest", PublicMqtt.value);
  302. //初始化mqtt
  303. PublicMqtt.value.init();
  304. //链接mqtt
  305. PublicMqtt.value.link();
  306. getMessage();
  307. };
  308. //获取订阅数据
  309. const getMessage = () => {
  310. PublicMqtt.value.client.on("message", (topic, message) => {
  311. // topic包含error就表示解析错误,message此时就是错误信息
  312. AnalysisProcess.value = true;
  313. mesg.value = JSON.parse(message.toString());
  314. if (topic.includes("error")) {
  315. isAnalysis.value = true;
  316. ElMessage({
  317. type: "error",
  318. message: mesg.value,
  319. });
  320. } else {
  321. isAnalysis.value = false;
  322. }
  323. console.log(mesg.value, "返回的数据", topic);
  324. });
  325. };
  326. //取消MQTT订阅
  327. const unsubscribe = () => {
  328. //如果页面并没有初始化MQTT,无需取消订阅
  329. if (PublicMqtt.value) {
  330. PublicMqtt.unsubscribes();
  331. }
  332. };
  333. onUnmounted(() => {
  334. //页面销毁结束订阅
  335. if (PublicMqtt.value) {
  336. PublicMqtt.value.unsubscribes();
  337. PublicMqtt.value.over();
  338. }
  339. });
  340. // mqtt=======
  341. // 取消弹窗
  342. const cancelClick = () => {
  343. loadingAddError.value = false;
  344. loadingAdd.value = false;
  345. };
  346. //点击输入框中的清除按钮
  347. const clearFile = () => {
  348. fileList.value = [];
  349. };
  350. watch(
  351. () => chooseFile.value,
  352. (newValue) => {
  353. if (!newValue) {
  354. fileList.value = [];
  355. }
  356. }
  357. );
  358. onMounted(() => {
  359. aktType();
  360. });
  361. </script>
  362. <style scoped lang="scss">
  363. .btnBox > div,
  364. .upload-title {
  365. height: 50px;
  366. display: flex;
  367. align-items: center;
  368. justify-content: center;
  369. margin-right: 8px;
  370. cursor: pointer;
  371. background: url("~@/assets/image/scdcheck/bgscd.png") no-repeat center;
  372. border-radius: 2px;
  373. font-size: 14px;
  374. color: #255ce7;
  375. img {
  376. width: 20px;
  377. height: 20px;
  378. margin: 0 4px 0 0;
  379. }
  380. }
  381. .upload-title {
  382. width: 102px;
  383. background-size: 103px 50px;
  384. margin-top: 4px;
  385. }
  386. .btnBox {
  387. display: flex;
  388. margin-bottom: 12px;
  389. & > div:first-child,
  390. & > div:nth-child(2) {
  391. width: 102px;
  392. background-size: 102px 45px;
  393. }
  394. & > div:last-child {
  395. width: 128px;
  396. background-size: 128px 45px;
  397. }
  398. }
  399. .my-header {
  400. border-bottom: 1px solid #a3ade0;
  401. font-size: 16px;
  402. color: #1a2447;
  403. .title {
  404. padding-bottom: 15px;
  405. }
  406. }
  407. .uploda-file {
  408. display: flex;
  409. align-items: center;
  410. }
  411. .upload-demo {
  412. display: flex;
  413. }
  414. .sure-file {
  415. display: flex;
  416. flex-direction: column;
  417. justify-content: center;
  418. align-items: center;
  419. }
  420. .sures {
  421. background: #dfe8ff;
  422. margin-left: 60px;
  423. color: #fff;
  424. width: 124px;
  425. height: 32px;
  426. margin-top: 60px;
  427. line-height: 32px;
  428. text-align: center;
  429. cursor: pointer;
  430. }
  431. .sures-success {
  432. background: #255ce7;
  433. }
  434. .sureUpload {
  435. }
  436. .file-title {
  437. width: 90px;
  438. color: #1a2447;
  439. font-size: 14px;
  440. margin-right: 8px;
  441. }
  442. :deep(.el-input__wrapper) {
  443. height: 38px;
  444. border: 1px solid #a3ade0;
  445. }
  446. .analysis {
  447. margin-left: 67px;
  448. margin-top: 10px;
  449. color: #255ce7;
  450. }
  451. .analysis.success {
  452. color: #3be078;
  453. }
  454. .analysis.fail {
  455. color: #e50505;
  456. }
  457. </style>