index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <div class="layout-pd">
  3. <el-row>
  4. <!--操作-->
  5. <el-col :xs="24" >
  6. <el-card class="mt8" shadow="hover" >
  7. <el-form :model="state.filter" :inline="true" @submit.stop.prevent style="margin-bottom:-20px;">
  8. <el-form-item prop="name" style="width: 100%">
  9. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  10. <el-form-item label="推送用户">
  11. <el-input v-model="state.filter.pushUser" placeholder="请输入推送用户" clearable></el-input>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  15. <el-form-item label="是否推送">
  16. <el-select v-model="state.filter.ispushed" placeholder="请选择推送状态">
  17. <el-option label="所有" :value="undefined"></el-option>
  18. <el-option v-for="(value, key) in FuelDispenserEnum" :key="key" :label="value" :value="key" />
  19. </el-select>
  20. <!-- <el-input v-model="state.filter.isPushed" placeholder="单行输入" clearable></el-input> -->
  21. </el-form-item>
  22. </el-col>
  23. <el-col :xs="24" :sm="12" :md="8" :lg="8" :xl="6" class="mb20">
  24. <el-form-item label="推送时间">
  25. <el-date-picker
  26. v-model="state.filter.pushTime"
  27. type="datetimerange"
  28. value-format="YYYY-MM-DD HH:mm:ss"
  29. range-separator="To"
  30. start-placeholder="开始日期"
  31. end-placeholder="结束日期"
  32. />
  33. </el-form-item>
  34. </el-col>
  35. </el-form-item>
  36. </el-form>
  37. <hr>
  38. <el-row justify="space-between" class="submit-button" style="margin-bottom:-6px;">
  39. <el-row>
  40. <el-button type="primary" icon="ele-Search" @click="onQuery"> 查询 </el-button>
  41. <el-button type="primary" icon="ele-RefreshRight" @click="onReset"> 重置 </el-button>
  42. <el-button v-auth="'api:admin:file:upload-file'" type="primary" icon="ele-Upload"> 立即推送
  43. </el-button>
  44. </el-row>
  45. </el-row>
  46. </el-card>
  47. </el-col>
  48. <!--表格-->
  49. <el-col :xs="24" >
  50. <el-card style="height: 70vh" class="my-fill mt8" shadow="hover">
  51. <el-table v-loading="state.loading" stripe :data="state.tableModel" row-key="id" style="width: 100%">
  52. <el-table-column type="selection" width="55" fixed="left"></el-table-column>
  53. <el-table-column v-for="column in state.dynamicColumns" :key="column.prop" :prop="column.prop" :label="column.label" >
  54. </el-table-column>
  55. <!-- <el-table-column label="操作" fixed="right" header-align="center" align="center" class="right-operation" width="140">
  56. <template #default="{ row }" >
  57. <el-link v-if="row.isPushed === '未推送'"
  58. class="my-el-link mr12 ml12"
  59. type="primary"
  60. icon="ele-Upload"
  61. @click="onDateUpdate(row)"
  62. :underline="false"
  63. target="_blank"
  64. >立即推送</el-link>
  65. </template>
  66. </el-table-column> -->
  67. </el-table>
  68. <div class="my-flex my-flex-end" style="margin-top: 20px">
  69. <el-pagination v-model:currentPage="state.pageInput.currentPage"
  70. v-model:page-size="state.pageInput.pageSize" :total="state.total" :page-sizes="[10, 15, 20, 50, 100]"
  71. small background @size-change="onSizeChange" @current-change="onCurrentChange"
  72. layout="total, sizes, prev, pager, next, jumper" />
  73. </div>
  74. </el-card>
  75. </el-col>
  76. </el-row>
  77. </div>
  78. </template>
  79. <script setup lang="ts">
  80. import {onBeforeMount, onMounted, reactive, ref, watch} from "vue";
  81. import eventBus from "/@/utils/mitt";
  82. import {Api} from "/@/api/admin/AlarmService/alarmQueryApi";
  83. import { PushDto } from "/@/api/admin/AlarmService/alarmQueryDto";
  84. import { PageInputAlarmFilterModel } from "/@/api/admin/reportManagement/alarm/alarmDto";
  85. import { useDynamicPageSize } from "/@/composables/useDynamicPageSize";
  86. import { ElMessage } from "element-plus";
  87. import { all } from "axios";
  88. // 使用组合式函数获取分页状态
  89. // const pageState = useDynamicPageSize(10, 15);
  90. /**数据对象*/
  91. const state = reactive({
  92. /**加载显示 */
  93. loading: false,
  94. /**条件查询模块 */
  95. filter: {
  96. /**推送用户 */
  97. pushUser: "",
  98. /**是否推送 */
  99. pushed: "",
  100. /**推送时间 */
  101. pushTime: "",
  102. ispushed:undefined
  103. },
  104. /**表格信息 */
  105. tableModel: [] as PushDto[],
  106. /**动态表头 */
  107. dynamicColumns: [
  108. { prop: 'ruleName', label: '规则名称' },
  109. // { prop: 'pushUserid', label: '推送用户id' },
  110. { prop: 'pushUser', label: '推送用户' },
  111. { prop: 'content', label: '推送内容' },
  112. { prop: 'pushed', label: '是否推送' },
  113. { prop: 'pushTime', label: '推送时间' },
  114. // { prop: 'alarmhistoryID', label: '报警ID' },
  115. // { prop: 'taskPriority', label: '优先级' },
  116. ],
  117. /**分页标识 */
  118. pageInput: {
  119. currentPage: 1,
  120. pageSize: 15,
  121. } as PageInputAlarmFilterModel,
  122. /**分页总数 */
  123. total: 0,
  124. })
  125. /**设备状态*/
  126. enum FuelDispenserEnum {
  127. true = "已推送",
  128. false = "未推送",
  129. }
  130. onMounted(async () => {
  131. await onQuery()
  132. init()
  133. eventBus.off('refreshView')
  134. eventBus.on('refreshView', async () => {
  135. await init()
  136. })
  137. console.log()
  138. })
  139. onBeforeMount(() => {
  140. eventBus.off('refreshView')
  141. })
  142. /**
  143. * 页条变化
  144. * @param val
  145. */
  146. const onSizeChange = (val: number) => {
  147. state.pageInput.pageSize = val
  148. init()
  149. }
  150. /**
  151. * 页数 变化
  152. * @param val
  153. */
  154. const onCurrentChange = (val: number) => {
  155. state.pageInput.currentPage = val
  156. init()
  157. }
  158. /**
  159. * 监听变换
  160. */
  161. watch(() => {})
  162. /**条件查询 */
  163. const onQuery = () => {
  164. init()
  165. }
  166. /**初始化 */
  167. const init = async () => {
  168. state.loading = true;
  169. try {
  170. // 处理时间范围
  171. let sdate = '';
  172. let edate = '';
  173. if (state.filter.pushTime && Array.isArray(state.filter.pushTime) && state.filter.pushTime.length === 2) {
  174. sdate = state.filter.pushTime[0]; // 开始时间
  175. edate = state.filter.pushTime[1]; // 结束时间
  176. }
  177. const params = {
  178. ...state.pageInput,
  179. filter: {
  180. ...state.filter,
  181. sdate,
  182. edate,
  183. pushTime: undefined, // 避免传到后端去
  184. },
  185. };
  186. const res = await new Api().getList(params);
  187. state.tableModel = res?.data?.list ?? [];
  188. state.total = res?.data?.total ?? 0;
  189. } catch (error) {
  190. console.error('获取数据失败:', error);
  191. ElMessage.error('获取数据失败,请重试');
  192. } finally {
  193. state.loading = false;
  194. }
  195. };
  196. /**重置 */
  197. const onReset=()=>{
  198. // 重置查询条件
  199. state.filter = {
  200. pushUser: "",
  201. pushed: "",
  202. pushTime: "",
  203. ispushed:undefined
  204. };
  205. // 重新加载数据
  206. init();
  207. }
  208. /**编辑 */
  209. const onDateUpdate=(row: any)=>{
  210. console.log("编辑行数据:", row);
  211. }
  212. </script>
  213. <style scoped lang="scss">
  214. .el-input,
  215. .el-select {
  216. width: 240px;
  217. }
  218. /* 输入框标签固定四个字符宽度 */
  219. ::v-deep .el-form-item__label {
  220. // 字体大小14,4个字符,12px右间距
  221. width: 14*4px+12px;
  222. justify-content: start;
  223. }
  224. /* 数据表头 设置灰色样式 */
  225. ::v-deep .el-table th.el-table__cell {
  226. background-color: #F6F6F6;
  227. }
  228. </style>