index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <!-- 规则列表 -- 表格 -->
  2. <template>
  3. <div class="layout-pd">
  4. <el-row>
  5. <!--操作-->
  6. <el-col :xs="24">
  7. <el-card class="mt8" shadow="hover">
  8. <el-form :model="Data.Filter" @submit.stop.prevent>
  9. <el-form-item prop="name" style="width: 100%">
  10. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  11. <el-form-item label="规则名称">
  12. <el-input v-model="Data.Filter.ruleName" placeholder="请输入规则名称" clearable></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  16. <el-form-item label="状态">
  17. <el-select v-model="Data.Filter.isActive" placeholder="请选择状态">
  18. <el-option v-for="item in StatusOptions" :key="item.value" :label="item.label" :value="item.value" />
  19. </el-select>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  23. <el-form-item label="推送方式">
  24. <el-select placeholder="请选择推送方式">
  25. <el-option label="所有" :value="''"></el-option>
  26. <el-option label="电子邮箱" :value="''"></el-option>
  27. <el-option label="微信" :value="''"></el-option>
  28. </el-select>
  29. </el-form-item>
  30. </el-col>
  31. </el-form-item>
  32. </el-form>
  33. <hr>
  34. <!-- 按钮 -->
  35. <el-row justify="space-between" class="submit-button" style="margin-bottom: -9px;">
  36. <el-row>
  37. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  38. <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
  39. </el-row>
  40. <el-row>
  41. <el-button type="primary" icon="ele-Plus" @click="addAlarmRules('')"> 添加 </el-button>
  42. </el-row>
  43. </el-row>
  44. </el-card>
  45. </el-col>
  46. <!--表格-->
  47. <el-col :xs="24">
  48. <el-card style="height: 76vh;" class="my-fill mt8" shadow="hover">
  49. <el-table ref="multipleTableRef" v-loading="Data.loading" stripe :data="Data.tableModel" row-key="id"
  50. style="width: 100%">
  51. <el-table-column v-for="column in Data.dynamicColumns" :key="column.prop" :prop="column.prop"
  52. :label="column.label" />
  53. <el-table-column label="状态" width="80" align="center" show-overflow-tooltip>
  54. <template #default="{ row }">
  55. <StatusBox :status="row.isActive ? '启用' : '禁用'" />
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="操作" fixed="right" header-align="center" align="center" class="right-operation"
  59. width="100">
  60. <template #default="{ row }">
  61. <el-link class="my-el-link mr12 ml12" @click="addAlarmRules(row)" type="primary" icon="ele-EditPen"
  62. :underline="false" target="_blank">编辑</el-link>
  63. <el-link class="my-el-link mr12 ml12" @click="toDelete(row.id)" type="primary" icon="ele-Delete"
  64. :underline="false" target="_blank">删除</el-link>
  65. <el-link class="my-el-link mr12 ml12" @click="toOpen(row)" type="primary" icon="ele-SwitchButton"
  66. :underline="false" target="_blank">启用</el-link>
  67. </template>
  68. </el-table-column>
  69. </el-table>
  70. <div class="my-flex my-flex-end" style="margin-top: 20px">
  71. <el-pagination v-model:currentPage="Data.pageInput.currentPage" v-model:page-size="Data.pageInput.pageSize"
  72. :total="Data.total" :page-sizes="[5, 10, 15, 20, 50, 100]" small background @size-change="onSizeChange"
  73. @current-change="onCurrentChange" layout="total, sizes, prev, pager, next, jumper" />
  74. </div>
  75. </el-card>
  76. </el-col>
  77. </el-row>
  78. <EditDialog ref="editDialogRef" />
  79. </div>
  80. </template>
  81. <script setup lang="ts" name="partsManagement/oilGun">
  82. import { defineAsyncComponent, onBeforeMount, onMounted, reactive, ref, watch } from "vue";
  83. import { alarmRluesFilterModel_SearchFilter, alarmRluesFilterModel, PageInputAlarmRluesFilterModel } from "/@/api/admin/AlarmService/alarmRulesDto";
  84. import { alarmRulesApi } from "/@/api/admin/AlarmService/alarmRulesApi";
  85. import eventBus from "/@/utils/mitt";
  86. import StatusBox from '/@/components/StatusBox.vue';
  87. import { useDynamicPageSize } from "/@/composables/useDynamicPageSize";
  88. // 使用组合式函数获取分页状态
  89. const pageState = useDynamicPageSize(10, 15);
  90. /**页面对象 */
  91. const Data = reactive({
  92. time1: '',
  93. /** 选择框列表 */
  94. statusList: [] as any,
  95. supplierList: [] as any,
  96. /**加载显示 */
  97. loading: false,
  98. /**条件查询模块 */
  99. Filter: {
  100. /** 规则名称 */
  101. ruleName: "",
  102. Status:"",
  103. upload:"",
  104. isActive:undefined
  105. } as alarmRluesFilterModel_SearchFilter,
  106. /**表格信息 */
  107. tableModel: [] as alarmRluesFilterModel[],
  108. /**动态表头 */
  109. dynamicColumns: [
  110. { prop: 'ruleName', label: '规则名称' },
  111. { prop: 'userName', label: '用户' },
  112. { prop: 'pushMethod', label: '推送方式' },
  113. { prop: 'triggerMethod', label: '触发方式' },
  114. { prop: 'regular', label: '正则匹配' },
  115. { prop: 'taskPriority', label: '优先级' },
  116. { prop: 'isExclusive', label: '是否互斥' },
  117. // { prop: 'stationName', label: '推送方式' },
  118. { prop: 'pushTemplateMappingID', label: '模板' },
  119. { prop: 'remark', label: '备注' },
  120. ],
  121. /**分页总数 */
  122. total: 0,
  123. /**分页标识 */
  124. pageInput: {
  125. currentPage: 1,
  126. pageSize: 10,
  127. } as PageInputAlarmRluesFilterModel,
  128. })
  129. // 定义状态选项
  130. const StatusOptions = [
  131. { value: undefined, label: '所有' },
  132. { value: true, label: '启用' },
  133. { value: false, label: '禁用' }
  134. ];
  135. enum upload {
  136. email="电子邮箱",
  137. vx="微信"
  138. }
  139. /**引入组件*/
  140. const EditDialog = defineAsyncComponent(() => import('./components/add-alarmRules.vue'))
  141. const editDialogRef = ref()
  142. // // 条件查询
  143. const init = async () => {
  144. Data.loading = true
  145. const res: any = await new alarmRulesApi().getData({ ...Data.pageInput, filter: Data.Filter })
  146. console.log(res)
  147. Data.tableModel = res?.data.list ?? []
  148. Data.total = res?.data?.list.length ?? 0 // 接口中没有总的数据量
  149. Data.loading = false
  150. pushMethodChange()
  151. }
  152. const onQuery = () => {
  153. init()
  154. console.log("查询")
  155. }
  156. /**重置查询条件 */
  157. const resetQuery = () => {
  158. Data.Filter.ruleName = ''
  159. }
  160. /**重置 */
  161. const onReset = () => {
  162. resetQuery()
  163. init()
  164. }
  165. /**
  166. * 添加规则
  167. */
  168. const addAlarmRules = ((row: any) => {
  169. editDialogRef.value.openDialog(row)
  170. init()
  171. })
  172. /**
  173. * 页条变化
  174. * @param val
  175. */
  176. const onSizeChange = (val: number) => {
  177. Data.pageInput.pageSize = val
  178. init()
  179. }
  180. /**
  181. * 页数 变化
  182. * @param val
  183. */
  184. const onCurrentChange = (val: number) => {
  185. Data.pageInput.currentPage = val
  186. init()
  187. }
  188. /** 数据转换 */
  189. const pushMethodChange = (() => {
  190. // 推送方式
  191. Data.tableModel.forEach((item: any) => {
  192. const pushList = item['pushMethod'].split(',')
  193. for (var i = 0; i < pushList.length; i++) {
  194. if (pushList[i] == 'wx') {
  195. pushList[i] = "微信"
  196. } else if (pushList[i] == 'email') {
  197. pushList[i] = "电子邮箱"
  198. }
  199. }
  200. item['pushMethod'] = pushList.toString()
  201. // 是否互斥
  202. if (item['isExclusive'] == true) {
  203. item['isExclusive'] = "是"
  204. } else {
  205. item['isExclusive'] = "否"
  206. }
  207. })
  208. })
  209. // 操作
  210. const toDelete = (async (id?: number) => {
  211. await new alarmRulesApi().deliteData({ 'id': id }).then(() => {
  212. eventBus.emit('refreshView')
  213. })
  214. })
  215. const toOpen = (async (row: any) => {
  216. row.isActive = !row.isActive
  217. const data = { ...row } as any
  218. if (data.isExclusive == '是') {
  219. data.isExclusive = true
  220. console.log(1)
  221. } else {
  222. data.isExclusive = false
  223. }
  224. if (data.pushMethod == '') {
  225. return
  226. } else {
  227. if (data.pushMethod == '微信') {
  228. data.pushMethod = 'wx'
  229. } else if (data.pushMethod == '电子邮箱') {
  230. data.pushMethod = 'email'
  231. } else {
  232. data.pushMethod = 'wx,email'
  233. }
  234. }
  235. await new alarmRulesApi().addForm(data).then(() => {
  236. eventBus.emit('refreshView')
  237. })
  238. })
  239. // 挂载前
  240. onBeforeMount(() => {
  241. eventBus.off('refreshView')
  242. })
  243. // 挂载时
  244. onMounted(async () => {
  245. // 初始化分页大小
  246. Data.pageInput.pageSize = pageState.pageInput.pageSize;
  247. await init()
  248. eventBus.off('refreshView')
  249. eventBus.on('refreshView', async () => {
  250. await init()
  251. })
  252. })
  253. </script>
  254. <style scoped lang="scss">
  255. .el-input,
  256. .el-select {
  257. width: 240px;
  258. }
  259. /* 输入框标签固定四个字符宽度 */
  260. ::v-deep .el-form-item__label {
  261. // 字体大小14,4个字符,12px右间距
  262. width: 14*4px+12px;
  263. justify-content: start;
  264. }
  265. /* 数据表头 设置灰色样式 */
  266. ::v-deep .el-table th.el-table__cell {
  267. background-color: #F6F6F6;
  268. }
  269. </style>