index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. <template>
  2. <div class="page padding bg page-full">
  3. <el-form :model="tableData.param" ref="queryRef" inline>
  4. <el-form-item class="mb-0">
  5. <el-button type="primary" @click="onOpenAdd" v-auth="'add'">
  6. <el-icon>
  7. <ele-FolderAdd />
  8. </el-icon>
  9. 新增告警
  10. </el-button>
  11. <el-button type="primary" @click="onOpenLevel" v-auth="'level'">
  12. <el-icon>
  13. <ele-Setting />
  14. </el-icon>
  15. 级别设置
  16. </el-button>
  17. </el-form-item>
  18. </el-form>
  19. <el-divider class="my-5" />
  20. <el-row class="page-full-part">
  21. <el-col :span="6" v-for="(item, index) in tableData.data" :key="index">
  22. <div class="card">
  23. <div class="ant-card">
  24. <div class="ant-card-body">
  25. <div class="pro-table-card-item">
  26. <div class="card-item-avatar" v-col="'image'">
  27. <img width="88" height="88" src="/src/assets/img/alarm.svg" />
  28. </div>
  29. <div class="card-item-body">
  30. <div class="card-item-header">
  31. <div v-col="'name'">
  32. <div class="ellipsis card-item-header-name" style="width: 100%; height: 45px">{{ item.name }}</div>
  33. </div>
  34. </div>
  35. <div class="card-item-content" v-col="'alarm'">
  36. <div>
  37. <label>触发:</label>
  38. <div>
  39. <div>级别:</div>
  40. </div>
  41. </div>
  42. <div>
  43. <label>{{ item.triggerTypeName }}</label>
  44. <div>
  45. <div>{{ item.alarmLevel.name }}</div>
  46. </div>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="card-state success" v-if="item.status == 1" v-col="'liststatus'">
  52. <div class="card-state-content">
  53. <span class="ant-badge ant-badge-status ant-badge-not-a-wrapper">
  54. <span class="ant-badge-status-dot ant-badge-status-success"></span>
  55. <span class="ant-badge-status-text">已启用</span>
  56. </span>
  57. </div>
  58. </div>
  59. <div class="card-state error" v-if="item.status == 0" v-col="'liststatus'">
  60. <div class="card-state-content">
  61. <span class="ant-badge ant-badge-status ant-badge-not-a-wrapper"><span class="ant-badge-status-dot ant-badge-status-error"></span><span class="ant-badge-status-text">未启用</span></span>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div class="card-tools">
  67. <el-button type="primary" text bg @click="onOpenEdit(item)" v-auth="'edit'">
  68. <el-icon>
  69. <ele-Edit />
  70. </el-icon>
  71. 修改
  72. </el-button>
  73. <el-button type="warning" text bg @click="onActionStatus(item)" v-if="item.status == 0" v-auth="'status'">
  74. <el-icon>
  75. <ele-Check />
  76. </el-icon>
  77. 启用
  78. </el-button>
  79. <el-button type="info" text bg @click="onActionStatus(item)" v-if="item.status == 1" v-auth="'status'">
  80. <el-icon>
  81. <ele-Close />
  82. </el-icon>
  83. 禁用
  84. </el-button>
  85. <el-button type="info" text bg @click="onRowDel(item)" v-auth="'del'">
  86. <el-icon>
  87. <ele-Delete />
  88. </el-icon>
  89. 删除
  90. </el-button>
  91. </div>
  92. </div>
  93. </el-col>
  94. </el-row>
  95. <pagination v-show="tableData.total > 0" :total="tableData.total" v-model:page="tableData.param.pageNum" v-model:limit="tableData.param.pageSize" @pagination="dataList" />
  96. <EditDic ref="editDicRef" @dataList="dataList" />
  97. <LevelDic ref="levelDicRef" @dataList="dataList" />
  98. </div>
  99. </template>
  100. <script lang="ts">
  101. import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue';
  102. import { ElMessageBox, ElMessage, FormInstance } from 'element-plus';
  103. import EditDic from './component/edit.vue';
  104. import LevelDic from './component/level.vue';
  105. import alarm from '/@/api/alarm';
  106. // 定义接口来定义对象的类型
  107. interface TableDataRow {
  108. id: number;
  109. name: string;
  110. key: string;
  111. createBy: string;
  112. }
  113. interface TableDataState {
  114. ids: number[];
  115. tableData: {
  116. data: Array<TableDataRow>;
  117. total: number;
  118. loading: boolean;
  119. param: {
  120. pageNum: number;
  121. pageSize: number;
  122. name: string;
  123. level: number;
  124. triggerType: number;
  125. };
  126. };
  127. }
  128. export default defineComponent({
  129. name: 'setlist',
  130. components: { EditDic, LevelDic },
  131. setup() {
  132. const addDicRef = ref();
  133. const levelDicRef = ref();
  134. const editDicRef = ref();
  135. const detailRef = ref();
  136. const queryRef = ref();
  137. const state = reactive<TableDataState>({
  138. tableData: {
  139. data: [],
  140. total: 0,
  141. loading: false,
  142. param: {
  143. pageNum: 1,
  144. pageSize: 20,
  145. name: '',
  146. level: '',
  147. triggerType: '',
  148. },
  149. },
  150. });
  151. // 初始化表格数据
  152. const initTableData = () => {
  153. dataList();
  154. };
  155. const dataList = () => {
  156. state.tableData.loading = true;
  157. alarm.common
  158. .getList(state.tableData.param)
  159. .then((res: any) => {
  160. state.tableData.data = res.list;
  161. state.tableData.total = res.Total;
  162. })
  163. .finally(() => (state.tableData.loading = false));
  164. };
  165. // 打开新增菜单弹窗
  166. const onOpenAdd = () => {
  167. editDicRef.value.openDialog();
  168. };
  169. const onOpenLevel = () => {
  170. levelDicRef.value.openDialog();
  171. };
  172. // 打开修改模型弹窗
  173. const onOpenEdit = (row: TableDataRow) => {
  174. editDicRef.value.openDialog({ ...row });
  175. };
  176. //打开数据记录
  177. const onOpenRecord = (row: TableDataRow) => {
  178. detailRef.value.openDialog(row);
  179. };
  180. const onRowDel = (row?: TableDataRow) => {
  181. let msg = '你确定要删除所选数据?';
  182. let ids: number[] = [];
  183. if (row) {
  184. msg = `此操作将永久删除告警:“${row.name}”,是否继续?`;
  185. ids = row.id;
  186. } else {
  187. ids = state.ids;
  188. }
  189. if (ids.length === 0) {
  190. ElMessage.error('请选择要删除的数据。');
  191. return;
  192. }
  193. ElMessageBox.confirm(msg, '提示', {
  194. confirmButtonText: '确认',
  195. cancelButtonText: '取消',
  196. type: 'warning',
  197. })
  198. .then(() => {
  199. alarm.common.delete(ids).then(() => {
  200. ElMessage.success('删除成功');
  201. dataList();
  202. });
  203. })
  204. };
  205. // 页面加载时
  206. onMounted(() => {
  207. initTableData();
  208. });
  209. /** 重置按钮操作 */
  210. const resetQuery = (formEl: FormInstance | undefined) => {
  211. if (!formEl) return;
  212. formEl.resetFields();
  213. dataList();
  214. };
  215. const onActionStatus = (item: TableDataRow[]) => {
  216. if (item.status == 0) {
  217. alarm.common.deploy({ id: item.id }).then(() => {
  218. dataList();
  219. });
  220. } else {
  221. alarm.common.undeploy({ id: item.id }).then(() => {
  222. dataList();
  223. });
  224. }
  225. }
  226. return {
  227. onActionStatus,
  228. addDicRef,
  229. editDicRef,
  230. detailRef,
  231. queryRef,
  232. levelDicRef,
  233. onOpenRecord,
  234. onOpenLevel,
  235. onOpenAdd,
  236. onOpenEdit,
  237. onRowDel,
  238. dataList,
  239. resetQuery,
  240. ...toRefs(state),
  241. };
  242. },
  243. });
  244. </script>
  245. <style scoped lang="scss">
  246. .el-button.is-text:not(.is-disabled).is-has-bg {
  247. background-color: var(--next-border-color-light);
  248. }
  249. .card {
  250. margin: 0 10px 20px;
  251. }
  252. .ant-card {
  253. box-sizing: border-box;
  254. font-size: 14px;
  255. font-variant: tabular-nums;
  256. border: 1px solid var(--next-border-color-light);
  257. line-height: 1.5;
  258. list-style: none;
  259. font-feature-settings: 'tnum';
  260. position: relative;
  261. border-radius: 2px;
  262. transition: all 0.3s;
  263. overflow: hidden;
  264. }
  265. .ant-card-body {
  266. padding: 12px;
  267. zoom: 1;
  268. overflow: hidden;
  269. }
  270. .pro-table-card-item {
  271. display: flex;
  272. justify-content: stretch;
  273. .card-item-avatar {
  274. display: flex;
  275. align-items: center;
  276. }
  277. }
  278. .pro-table-card-item .card-item-avatar {
  279. margin-right: 16px;
  280. }
  281. .pro-table-card-item .card-item-body {
  282. display: flex;
  283. flex-direction: column;
  284. flex-grow: 1;
  285. width: 0;
  286. }
  287. .pro-table-card-item .card-item-body .card-item-header {
  288. display: flex;
  289. margin-bottom: 12px;
  290. margin-top: 10px;
  291. }
  292. .pro-table-card-item .card-item-body .card-item-content {
  293. display: flex;
  294. flex-wrap: wrap;
  295. font-weight: bolder;
  296. line-height: 25px;
  297. }
  298. .ellipsis {
  299. display: -webkit-box;
  300. overflow: hidden;
  301. text-align: left;
  302. text-overflow: ellipsis;
  303. word-break: break-all;
  304. }
  305. .card-item-body .card-item-header .card-item-header-name {
  306. font-weight: 700;
  307. font-size: 16px;
  308. }
  309. .card-state {
  310. position: absolute;
  311. top: 0px;
  312. right: -12px;
  313. display: flex;
  314. justify-content: center;
  315. width: 100px;
  316. padding: 2px 0;
  317. background-color: rgba(89, 149, 245, 0.15);
  318. transform: skewX(45deg);
  319. }
  320. .card-state.success {
  321. background-color: #f6ffed;
  322. color: #000;
  323. }
  324. .iot-card .card-warp .card-content .card-state.error {
  325. background-color: rgba(229, 0, 18, .1);
  326. }
  327. .card-state .card-state-content {
  328. transform: skewX(-45deg);
  329. }
  330. .ant-badge-status-success {
  331. background-color: #52c41a;
  332. }
  333. .ant-badge-status-error {
  334. background-color: #ff4d4f;
  335. }
  336. .ant-badge-status-dot {
  337. position: relative;
  338. top: -1px;
  339. display: inline-block;
  340. width: 6px;
  341. height: 6px;
  342. vertical-align: middle;
  343. border-radius: 50%;
  344. }
  345. .card-tools {
  346. display: flex;
  347. margin-top: 8px;
  348. justify-content: space-between;
  349. overflow: hidden;
  350. gap: 8px;
  351. .el-button {
  352. flex: 1;
  353. margin-left: 0;
  354. }
  355. }
  356. /* /* .card-tools .card-button:not(:last-child) {
  357. margin-right: 8px;
  358. } */
  359. .card-tools .card-button {
  360. display: flex;
  361. flex-grow: 1;
  362. }
  363. .card-tools .card-button>span,
  364. .card-tools .card-button button {
  365. width: 100%;
  366. border-radius: 0;
  367. }
  368. .ant-btn-link {
  369. color: #1d39c4;
  370. border-color: transparent;
  371. background: transparent;
  372. box-shadow: none;
  373. }
  374. .ant-badge-status-text {
  375. margin-left: 8px;
  376. font-size: 14px;
  377. }
  378. .ant-btn {
  379. line-height: 1.5715;
  380. position: relative;
  381. display: inline-block;
  382. font-weight: 400;
  383. white-space: nowrap;
  384. text-align: center;
  385. background-image: none;
  386. box-shadow: 0 2px 0 rgb(0 0 0 / 2%);
  387. cursor: pointer;
  388. transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  389. -webkit-user-select: none;
  390. -moz-user-select: none;
  391. -ms-user-select: none;
  392. user-select: none;
  393. touch-action: manipulation;
  394. height: 32px;
  395. padding: 4px 15px;
  396. font-size: 14px;
  397. border-radius: 2px;
  398. color: rgba(0, 0, 0, 0.85);
  399. border: 1px solid #d9d9d9;
  400. background: #fff;
  401. }
  402. .ant-btn>.anticon {
  403. line-height: 1;
  404. }
  405. .ant-btn>span {
  406. display: inline-block;
  407. }
  408. .cardflex {
  409. display: flex;
  410. justify-content: space-between;
  411. }
  412. .statusname {
  413. font-size: 30px;
  414. margin-top: 10px;
  415. margin-bottom: 15px;
  416. }
  417. .comtest {
  418. margin-top: 20px;
  419. height: 30px;
  420. line-height: 30px;
  421. }
  422. </style>