index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. <template>
  2. <div class="custom-config">
  3. <div class="form-wrapper">
  4. <div class="btns" style="margin-bottom: 10px">
  5. <el-button class="buttons" size="mini" round @click="handleInsert">
  6. 新增记录
  7. </el-button>
  8. <el-button class="buttons" size="mini" round @click="export2Excel">
  9. 批量导出</el-button
  10. >
  11. <el-button class="buttons" size="mini" round @click="outExe">
  12. 模板下载</el-button
  13. >
  14. <el-upload
  15. style="display: inline; margin-left: 10px"
  16. :action="url + 'alertrule/import'"
  17. :show-file-list="false"
  18. :on-success="handleSuccess"
  19. :on-progress="handleProgress"
  20. :on-error="handleError"
  21. >
  22. <el-button
  23. class="buttons"
  24. size="mini"
  25. round
  26. @click="exportShow = true"
  27. >
  28. 批量导入</el-button
  29. >
  30. </el-upload>
  31. </div>
  32. <div class="search-wrapper">
  33. <el-select
  34. v-model="query.category"
  35. size="mini"
  36. class="search-item"
  37. popper-class="select"
  38. @change="categorychanged"
  39. >
  40. <el-option key="1" label="风机报警" value="windturbine"></el-option>
  41. <!-- <el-option
  42. key="2"
  43. label="升压站报警"
  44. value="booststation"
  45. ></el-option> -->
  46. <el-option key="3" label="光伏报警" value="inverter"></el-option>
  47. </el-select>
  48. <el-select
  49. v-model="query.wpId"
  50. clearable
  51. size="mini"
  52. class="search-item"
  53. :placeholder="'全部场站'"
  54. popper-class="select"
  55. @change="changeStation"
  56. >
  57. <el-option
  58. v-for="item in stationList"
  59. :key="item.id"
  60. :value="item.id"
  61. :label="item.aname"
  62. ></el-option>
  63. </el-select>
  64. <el-select
  65. v-model="query.relatedparts"
  66. clearable
  67. size="mini"
  68. class="search-item"
  69. placeholder="所属部件"
  70. >
  71. <el-option
  72. v-for="item in fetchList"
  73. :key="item.id"
  74. :label="item.name"
  75. :value="item.nemCode"
  76. >
  77. </el-option>
  78. </el-select>
  79. <el-select
  80. v-model="query.enabled"
  81. clearable
  82. size="mini"
  83. class="search-item"
  84. placeholder="是否可用"
  85. >
  86. <el-option
  87. v-for="item in state.isEnabled"
  88. :key="item.id"
  89. :label="item.name"
  90. :value="item.id"
  91. >
  92. </el-option>
  93. </el-select>
  94. <el-select
  95. v-model="query.modelId"
  96. clearable
  97. size="mini"
  98. class="search-item"
  99. placeholder="全部机型"
  100. popper-class="select"
  101. >
  102. <el-option
  103. v-for="item in modelList"
  104. :key="item.id"
  105. :value="item.id"
  106. :label="item.aname"
  107. ></el-option>
  108. </el-select>
  109. <!-- <el-select
  110. v-model="query.rank"
  111. clearable
  112. size="mini"
  113. class="search-item"
  114. placeholder="全部级别"
  115. popper-class="select"
  116. >
  117. <el-option
  118. v-for="item in state.rankList"
  119. :key="item.id"
  120. :value="item.id"
  121. :label="item.name"
  122. ></el-option>
  123. </el-select> -->
  124. <el-input
  125. placeholder="请输入名称"
  126. v-model="query.name"
  127. size="mini"
  128. class="search-item"
  129. clearable
  130. ></el-input>
  131. <el-button class="buttons" round size="mini" @click="getData"
  132. >搜索</el-button
  133. >
  134. </div>
  135. </div>
  136. <div class="table-wrapper">
  137. <div class="leftContent">
  138. <span>{{ pageTitle }}</span>
  139. </div>
  140. <el-table
  141. :data="state.tableData"
  142. stripe
  143. height="calc(100% - 42px - 45px)"
  144. >
  145. <el-table-column
  146. v-for="item in state.tableHeader"
  147. :key="item.code"
  148. :label="item.title"
  149. align="center"
  150. :prop="item.code"
  151. :minWidth="item.width ? item.width : 60"
  152. show-overflow-tooltip
  153. >
  154. <template #default="scope">
  155. <span v-if="item.code == 'rank'">
  156. {{ rankConvert(scope.row.rank) }}
  157. </span>
  158. <span v-else-if="item.code == 'category'">
  159. {{ categoryConvert(scope.row.category) }}
  160. </span>
  161. <span v-else-if="item.code == 'enable'">
  162. {{ enabledConvert(scope.row.enable) }}
  163. </span>
  164. <span v-else>
  165. {{ scope.row[item.code] }}
  166. </span>
  167. </template>
  168. </el-table-column>
  169. <el-table-column label="操作" align="center" width="100">
  170. <template #default="scope">
  171. <el-button
  172. type="text"
  173. style="color: #05bb4c"
  174. size="mini"
  175. @click="handleEditClick(scope.row)"
  176. >编辑</el-button
  177. >
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. <div class="pagination">
  182. <el-pagination
  183. layout="total, sizes, prev, pager, next"
  184. :current-page="query.pageNum"
  185. :page-size="query.pageSize"
  186. :page-sizes="[22, 50, 100, 200, 500]"
  187. :total="total"
  188. @size-change="
  189. (value) => {
  190. query.pageSize = value;
  191. query.pageNum = 1;
  192. getData();
  193. }
  194. "
  195. @current-change="handlePageChange"
  196. ></el-pagination>
  197. </div>
  198. </div>
  199. <customcomponents
  200. @close="dialogclose"
  201. :isVisible="state.visible"
  202. :dialogOptions="state.form"
  203. :rankList="state.rankList"
  204. :modelListAll="state.modelListAll"
  205. :fetchListAll="state.fetchListAll"
  206. />
  207. </div>
  208. </template>
  209. <script setup>
  210. import {
  211. custombj_fetchTableData,
  212. getStationinfo,
  213. fetchRelatePartAndAlarmType,
  214. fetchModel,
  215. fetchBooststation,
  216. custombj_importTemplate,
  217. getWpList,
  218. } from "@/api/zhbj/index.js";
  219. import { outExportExcel } from "@/tools/excel/exportExcel.js"; //引入文件
  220. import {
  221. ref,
  222. onMounted,
  223. provide,
  224. computed,
  225. reactive,
  226. watch,
  227. nextTick,
  228. } from "vue";
  229. import { useStore } from "vuex";
  230. import { useRouter } from "vue-router";
  231. import { ElMessageBox, ElMessage } from "element-plus";
  232. import customcomponents from "@/views/IntegratedAlarm/alarmConfig/components/custom_components.vue";
  233. const pageTitle = "预警配置";
  234. const store = useStore();
  235. const token = { token: store.state.user.authToken };
  236. const url = process.env.VUE_APP_ALARM;
  237. const router = useRouter();
  238. const query = reactive({
  239. pageNum: 1,
  240. pageSize: 22,
  241. name: "",
  242. wpId: "",
  243. rank: "",
  244. modelId: "",
  245. category: "windturbine",
  246. enabled: "",
  247. relatedparts: "",
  248. });
  249. const state = reactive({
  250. tableData: [],
  251. fetchListAll: [], //部件及预警类型
  252. modelListAll: {}, //型号所有列表
  253. isEnabled: [
  254. {
  255. id: false,
  256. name: "否",
  257. },
  258. {
  259. id: true,
  260. name: "是",
  261. },
  262. ],
  263. rankList: [
  264. {
  265. id: 1,
  266. name: "低",
  267. },
  268. {
  269. id: 2,
  270. name: "中低",
  271. },
  272. {
  273. id: 3,
  274. name: "中",
  275. },
  276. {
  277. id: 4,
  278. name: "中高",
  279. },
  280. {
  281. id: 5,
  282. name: "高",
  283. },
  284. ],
  285. visible: false,
  286. form: {},
  287. tableHeader: [
  288. { title: "编码", code: "id" },
  289. { title: "场站", code: "stationName", width: "100" },
  290. { title: "机型", code: "modelId" },
  291. { title: "规则名称", code: "name", width: "150" },
  292. { title: "表达式", code: "expression", width: "150" },
  293. { title: "描述", code: "description", width: "150" },
  294. { title: "所属部件", code: "relatedPartsName" },
  295. // { title: "级别", code: "rank" },
  296. { title: "类型", code: "category" },
  297. { title: "是否启用", code: "enable" },
  298. ],
  299. tableHeader1: [
  300. { title: "编码", code: "id" },
  301. { title: "升压站", code: "stationName" },
  302. { title: "规则名称", code: "name" },
  303. { title: "表达式", code: "expression" },
  304. { title: "描述", code: "description" },
  305. // { title: "级别", code: "rank" },
  306. { title: "类型", code: "category" },
  307. { title: "是否启用", code: "enable" },
  308. ],
  309. });
  310. //型号列表
  311. const modelList = computed(() => {
  312. if (query.wpId == "") {
  313. return [];
  314. } else {
  315. return state.modelListAll[query.wpId];
  316. }
  317. });
  318. //部件列表
  319. const fetchList = computed(() => {
  320. if (query.wpId == "") {
  321. return [];
  322. } else {
  323. if (query.wpId.includes("FDC")) {
  324. return state.fetchListAll?.fjbj;
  325. } else {
  326. return state.fetchListAll?.gfbj;
  327. }
  328. }
  329. });
  330. // 场站列表/升压站列表
  331. const stationList = ref([]);
  332. let total = ref(0);
  333. onMounted(() => {
  334. getWpArray();
  335. getfetchRelatePart();
  336. getequipmentmodel_list();
  337. getData();
  338. });
  339. const dialogclose = () => {
  340. state.visible = false;
  341. state.form = {};
  342. getData();
  343. };
  344. const getWpArray = async () => {
  345. const { data } = await getWpList(query.category);
  346. stationList.value = data;
  347. };
  348. const getData = async () => {
  349. const { data } = await custombj_fetchTableData(query);
  350. state.tableData = data.records;
  351. total.value = data.total;
  352. };
  353. //所属部件
  354. const getfetchRelatePart = async () => {
  355. const { data } = await fetchRelatePartAndAlarmType();
  356. state.fetchListAll = data;
  357. // if (router && router.currentRoute.value.query.name) {
  358. // let queryName = router.currentRoute.value.query.name;
  359. // query.relatedparts = queryName;
  360. // }
  361. // getData();
  362. };
  363. // 机型
  364. const getequipmentmodel_list = async () => {
  365. const { data } = await fetchModel();
  366. state.modelListAll = data;
  367. };
  368. const handleEditClick = (row) => {
  369. let obj = Object.assign({}, row);
  370. state.form = obj;
  371. state.visible = true;
  372. };
  373. const handleInsert = () => {
  374. state.form = {
  375. category: "windturbine",
  376. enable: true,
  377. stationId: "",
  378. expression: "",
  379. };
  380. state.visible = true;
  381. };
  382. //changeStation
  383. const changeStation = async () => {
  384. query.modelId = "";
  385. query.relatedparts = "";
  386. };
  387. //categorychanged
  388. const categorychanged = async () => {
  389. getWpArray();
  390. this.clean();
  391. getData();
  392. };
  393. // 分页导航
  394. const handlePageChange = (val) => {
  395. query.pageNum = val;
  396. getData();
  397. };
  398. // 批量导出
  399. const export2Excel = async () => {
  400. let tableHeader = [];
  401. let tableKey = [];
  402. const { data } = await custombj_fetchTableData({
  403. pageNum: 1,
  404. pageSize: total.value,
  405. ...query,
  406. });
  407. ElMessage.success(`导出成功!`);
  408. if (query.category == "windturbine") {
  409. tableHeader = state.tableHeader.map((item) => item.title);
  410. tableKey = state.tableHeader.map((item) => item.code);
  411. } else if (query.category == "booststation") {
  412. tableHeader = state.tableHeader1.map((item) => item.title);
  413. tableKey = state.tableHeader1.map((item) => item.code);
  414. }
  415. outExportExcel(
  416. tableHeader,
  417. tableKey,
  418. data.records,
  419. "自定义预警配置导出excel"
  420. );
  421. };
  422. // 模板下载
  423. const outExe = () => {
  424. custombj_importTemplate().then((response) => {
  425. const link = document.createElement("a");
  426. const blob = new Blob([response], {
  427. type: "application/vnd.ms-excel",
  428. });
  429. link.style.display = "none";
  430. link.href = URL.createObjectURL(blob);
  431. link.download = "自定义报警模板.xlsx";
  432. document.body.appendChild(link);
  433. link.click();
  434. document.body.removeChild(link);
  435. });
  436. };
  437. // 批量导入
  438. const handleSuccess = (response) => {
  439. if (response.code == "200") {
  440. ElMessage.success("导入成功!");
  441. getData();
  442. } else {
  443. ElMessage.error(response.msg);
  444. }
  445. };
  446. // 批量导入中
  447. const handleProgress = (response) => {};
  448. // 批量导入失败
  449. const handleError = (response) => {
  450. ElMessage.success("导入失败!");
  451. };
  452. // 清空字段
  453. const clean = () => {
  454. query.modelId = "";
  455. query.relatedparts = "";
  456. query.wpId = "";
  457. query.enabled = "";
  458. query.rank = "";
  459. query.name = "";
  460. query.pageNum = 1;
  461. state.tableData = [];
  462. total.value = 0;
  463. };
  464. const rankConvert = (val) => {
  465. if (val == 1) {
  466. return "低";
  467. } else if (val == 2) {
  468. return "中低";
  469. } else if (val == 3) {
  470. return "中";
  471. } else if (val == 4) {
  472. return "中高";
  473. } else if (val == 5) {
  474. return "高";
  475. }
  476. };
  477. // 类型
  478. const categoryConvert = (val) => {
  479. if (val === "windturbine") {
  480. return "风机";
  481. } else if (val === "inverter") {
  482. return "光伏";
  483. }
  484. };
  485. // 状态
  486. const enabledConvert = (val) => {
  487. if (val === false) {
  488. return "停用";
  489. } else if (val === true) {
  490. return "启用";
  491. }
  492. };
  493. </script>
  494. <style scoped lang="less">
  495. .custom-config {
  496. height: 100%;
  497. width: 100%;
  498. padding: 0 20px;
  499. padding-bottom: 10px;
  500. .form-wrapper {
  501. display: flex;
  502. padding-top: 10px;
  503. justify-content: space-between;
  504. .search-wrapper::v-deep {
  505. display: flex;
  506. align-items: center;
  507. font-size: 14px;
  508. font-family: Microsoft YaHei;
  509. font-weight: 400;
  510. color: #b3b3b3;
  511. margin-bottom: 10px;
  512. .search-item {
  513. margin-right: 10px;
  514. max-width: 190px;
  515. }
  516. }
  517. .btns {
  518. display: flex;
  519. justify-content: flex-end;
  520. margin-right: 10px;
  521. // position: absolute;
  522. // right: 0;
  523. // top: 53px;
  524. .el-button + .el-button {
  525. margin-left: 10px;
  526. }
  527. }
  528. .buttons {
  529. background-color: rgba(5, 187, 76, 0.2);
  530. border: 1px solid #3b6c53;
  531. color: #b3b3b3;
  532. font-size: 14px;
  533. &:hover {
  534. background-color: rgba(5, 187, 76, 0.5);
  535. color: #ffffff;
  536. }
  537. }
  538. }
  539. }
  540. .table-wrapper {
  541. height: calc(100% - 43px);
  542. width: 100%;
  543. .leftContent {
  544. width: 242px;
  545. height: 41px;
  546. display: flex;
  547. align-items: center;
  548. background: url("~@/assets/imgs/title_left_bg1.png") no-repeat;
  549. span {
  550. font-size: 16px;
  551. font-family: Microsoft YaHei;
  552. font-weight: 400;
  553. color: #05bb4c;
  554. margin-left: 25px;
  555. }
  556. }
  557. .el-table::v-deep {
  558. .el-table__body-wrapper {
  559. height: calc(100% - 45px) !important;
  560. }
  561. }
  562. .pagination-wrapper ::v-deep {
  563. text-align: right;
  564. margin-top: 10px;
  565. }
  566. }
  567. </style>