custom.vue 9.4 KB

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