index.vue 10.0 KB

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