index.vue 12 KB

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