custom.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <el-row type="flex" justify="space-between">
  3. <div class="handle-box" style="margin-bottom: 10px">
  4. <el-button class="buttons" size="mini" round @click="handleInsert">
  5. 新增记录
  6. </el-button>
  7. <el-button class="buttons" size="mini" round @click="export2Excel">
  8. 批量导出</el-button
  9. >
  10. <el-button class="buttons" size="mini" round @click="outExe">
  11. 模板下载</el-button
  12. >
  13. <el-upload
  14. style="display: inline; margin-left: 10px"
  15. action="/sharding/alertrule2/import"
  16. :headers="token"
  17. :show-file-list="false"
  18. :on-success="handleSuccess"
  19. :on-progress="handleProgress"
  20. :on-error="handleError"
  21. >
  22. <el-button class="buttons" size="mini" round @click="exportShow = true">
  23. 批量导入</el-button
  24. >
  25. </el-upload>
  26. </div>
  27. <div style="display: flex; flex-direction: row; margin-bottom: 10px">
  28. <el-select
  29. v-model="query.category"
  30. size="mini"
  31. style="width: 150px"
  32. popper-class="select"
  33. @change="handleCategoryChange"
  34. >
  35. <el-option
  36. key="windturbine"
  37. label="风机"
  38. value="windturbine"
  39. ></el-option>
  40. <el-option key="inverter" label="逆变器" value="inverter"></el-option>
  41. <!-- <el-option
  42. key="booststation"
  43. label="升压站"
  44. value="booststation"
  45. ></el-option> -->
  46. </el-select>
  47. <el-select
  48. v-model="query.station"
  49. clearable
  50. filterable
  51. size="mini"
  52. style="width: 150px"
  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.name"
  62. ></el-option>
  63. </el-select>
  64. <el-select
  65. v-model="query.modelId"
  66. clearable
  67. filterable
  68. size="mini"
  69. style="width: 150px"
  70. placeholder="全部机型"
  71. popper-class="select"
  72. >
  73. <el-option
  74. v-for="item in state.modelList"
  75. :key="item"
  76. :value="item"
  77. :label="item"
  78. ></el-option>
  79. </el-select>
  80. <el-select
  81. v-model="query.rank"
  82. clearable
  83. filterable
  84. size="mini"
  85. style="width: 150px"
  86. placeholder="全部级别"
  87. popper-class="select"
  88. >
  89. <el-option
  90. v-for="item in state.rankList"
  91. :key="item.id"
  92. :value="item.id"
  93. :label="item.name"
  94. ></el-option>
  95. </el-select>
  96. <el-input
  97. placeholder="请输入名称"
  98. v-model="query.name"
  99. style="width: 150px; margin-right: 10px"
  100. size="mini"
  101. clearable
  102. ></el-input>
  103. <el-button
  104. icon="el-icon-search"
  105. class="buttons"
  106. round
  107. size="mini"
  108. @click="getData"
  109. >搜索</el-button
  110. >
  111. </div>
  112. </el-row>
  113. <div class="custom-table">
  114. <el-table
  115. :data="state.tableData"
  116. stripe
  117. height="calc(100% - 45px)"
  118. style="width: 100%"
  119. >
  120. <el-table-column label="编码" align="center" prop="id" width="50" />
  121. <el-table-column
  122. label="场站"
  123. align="center"
  124. prop="stationName"
  125. min-width="50"
  126. />
  127. <el-table-column
  128. label="机型"
  129. align="center"
  130. prop="modelId"
  131. min-width="50"
  132. />
  133. <el-table-column label="名称" align="left" prop="name" min-width="50" />
  134. <el-table-column label="表达式" align="left" prop="expression" />
  135. <el-table-column label="级别" align="center" prop="rank" min-width="20">
  136. <template #default="scope">{{ rankConvert(scope.row.rank) }}</template>
  137. </el-table-column>
  138. <el-table-column
  139. label="类型"
  140. align="center"
  141. prop="category"
  142. min-width="20"
  143. >
  144. <template #default="scope">{{
  145. categoryConvert(scope.row.category)
  146. }}</template>
  147. </el-table-column>
  148. <el-table-column label="描述" align="left" prop="description" />
  149. <el-table-column
  150. label="是否启用"
  151. align="center"
  152. prop="enabled"
  153. width="80"
  154. >
  155. <template #default="scope">
  156. {{ scope.row.enabled ? "启用" : "未启用" }}
  157. </template>
  158. </el-table-column>
  159. <el-table-column
  160. label="所属部件"
  161. align="center"
  162. prop="relatedPartsName"
  163. min-width="30"
  164. />
  165. <el-table-column label="操作" align="center" width="80">
  166. <template #default="scope">
  167. <el-button
  168. style="color: #05bb4c"
  169. type="text"
  170. icon="el-icon-lx-edit"
  171. :disabled="scope.row.range == 1"
  172. @click="handleEditClick(scope.row)"
  173. >编辑</el-button
  174. >
  175. <!-- <el-button type="primary" plain round size="mini" icon="el-icon-search" @click="handleViewClick(scope.$index, scope.row)">查看</el-button> -->
  176. </template>
  177. </el-table-column>
  178. </el-table>
  179. <div class="pagination">
  180. <el-pagination
  181. layout="total, sizes, prev, pager, next"
  182. :page-sizes="[19, 50, 100, 200, 500]"
  183. @size-change="
  184. (value) => {
  185. query.pageSize = value;
  186. query.pageNum = 1;
  187. getData();
  188. }
  189. "
  190. :current-page="query.pageNum"
  191. :page-size="query.pageSize"
  192. :total="total"
  193. @current-change="handlePageChange"
  194. ></el-pagination>
  195. </div>
  196. </div>
  197. <customcomponents
  198. @close="dialogclose"
  199. :isVisible="state.visible"
  200. :form="state.form"
  201. />
  202. </template>
  203. <script setup>
  204. import { custombj_fetchTableData, getWtModel } from "@/api/zhbj/index.js";
  205. import { outExportExcel } from "@/tools/excel/exportExcel.js"; //引入文件
  206. import { ref, onMounted, provide, computed, reactive, watch } from "vue";
  207. import { useStore } from "vuex";
  208. import { ElMessageBox, ElMessage } from "element-plus";
  209. import customcomponents from "./custom_components.vue";
  210. const token = { token: sessionStorage.getItem("token") };
  211. const store = useStore();
  212. const stationList = computed(() =>
  213. query.category == "windturbine"
  214. ? store.state.stationListAll.filter((item) => item.windType == -1)
  215. : store.state.stationListAll.filter((item) => item.windType == -2)
  216. );
  217. const isStation = computed(() => store.getters.isStation);
  218. const state = reactive({
  219. tableData: [],
  220. modelList: [],
  221. rankList: [
  222. {
  223. id: 1,
  224. name: "低级",
  225. },
  226. {
  227. id: 2,
  228. name: "低中",
  229. },
  230. {
  231. id: 3,
  232. name: "中级",
  233. },
  234. {
  235. id: 4,
  236. name: "中高级",
  237. },
  238. {
  239. id: 5,
  240. name: "高级",
  241. },
  242. ],
  243. visible: false,
  244. form: {},
  245. });
  246. const query = reactive({
  247. pageNum: 1,
  248. pageSize: 19,
  249. name: "",
  250. station: "",
  251. rank: "",
  252. modelId: "",
  253. category: "windturbine",
  254. });
  255. let total = ref(0);
  256. onMounted(() => {
  257. getData();
  258. getequipmentmodel_list();
  259. });
  260. const dialogclose = () => {
  261. state.visible = false;
  262. getData();
  263. };
  264. const getData = async () => {
  265. const { data } = await custombj_fetchTableData(query);
  266. state.tableData = data.records;
  267. total.value = data.total;
  268. };
  269. const handleEditClick = (row) => {
  270. let obj = Object.assign({}, row);
  271. state.form = obj;
  272. state.visible = true;
  273. };
  274. const handleInsert = () => {
  275. state.visible = true;
  276. };
  277. //changeStation
  278. const changeStation = async () => {
  279. query.modelId = "";
  280. await getequipmentmodel_list();
  281. };
  282. // 机型
  283. const getequipmentmodel_list = async () => {
  284. const { data } = await getWtModel(query.station);
  285. state.modelList = data;
  286. };
  287. // 分页导航
  288. const handlePageChange = (val) => {
  289. query.pagenum = val;
  290. getData();
  291. };
  292. const tableHeader = [
  293. "id",
  294. "规则名称",
  295. "报警类别(1:风气;2:升压站)",
  296. "报警级别(1:低级;2:低中级;3:中级;4:中高级;5:高级)",
  297. "是否启用(0:停用;1:启用)",
  298. "风场",
  299. "风机类型",
  300. "所属部件",
  301. "表达式",
  302. "规则描述",
  303. ];
  304. const tableKey = [
  305. "id",
  306. "name",
  307. "category",
  308. "rank",
  309. "enabled",
  310. "station",
  311. "modelId",
  312. "relatedParts",
  313. "expressionShow",
  314. "descriptionShow",
  315. ];
  316. // 批量导出
  317. const export2Excel = async () => {
  318. let { name, station, rank, modelId, category } = query;
  319. const res = await custombj_fetchTableData({
  320. pageNum: 1,
  321. pageSize: 999999,
  322. name,
  323. station,
  324. rank,
  325. modelId,
  326. category,
  327. });
  328. ElMessage.success(`导出成功!`);
  329. outExportExcel(tableHeader, tableKey, res.records, "自定义预警配置导出excel");
  330. };
  331. // 模板下载
  332. const outExe = () => {
  333. const data = [];
  334. ElMessage.success(`导出成功!`);
  335. outExportExcel(tableHeader, tableKey, data, "自定义报警模板");
  336. };
  337. // 批量导入
  338. const handleSuccess = (response, file, fileList) => {
  339. ElMessage.success("导入成功!");
  340. getData();
  341. };
  342. const handleProgress = (response, file, fileList) => {};
  343. const handleError = (response, file, fileList) => {
  344. ElMessage.success("导入失败!");
  345. };
  346. const rankConvert = (val) => {
  347. if (val === 1) {
  348. return "低级";
  349. } else if (val === 2) {
  350. return "低中级";
  351. } else if (val === 3) {
  352. return "中级";
  353. } else if (val === 4) {
  354. return "中高级";
  355. } else if (val === 5) {
  356. return "高级";
  357. }
  358. };
  359. // 类型
  360. const categoryConvert = (val) => {
  361. if (val === "windturbine") {
  362. return "风机";
  363. } else if (val === "inverter") {
  364. return "逆变器";
  365. } else if (val === "booststation") {
  366. return "升压站";
  367. }
  368. };
  369. </script>
  370. <style scoped lang="less">
  371. .custom-table {
  372. height: calc(100% - 40px);
  373. }
  374. .buttons {
  375. background-color: rgba(5, 187, 76, 0.2);
  376. border: 1px solid #3b6c53;
  377. color: #b3b3b3;
  378. font-size: 14px;
  379. &:hover {
  380. background-color: rgba(5, 187, 76, 0.5);
  381. color: #ffffff;
  382. }
  383. }
  384. .el-select ::v-deep {
  385. margin-right: 10px;
  386. }
  387. .el-button + .el-button {
  388. margin-left: 10px;
  389. }
  390. .pagination {
  391. padding-top: 10px;
  392. }
  393. </style>