index.vue 10 KB

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