alarm.vue
6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<template>
<view class="alarm-page" :class="pageDisableScroll">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<!-- 告警头部 -->
<header-search @openOrg="openOrg" @openSearchDialog="openSearchDialog" :total="alarmTotal"
:totalText="$t(totalText)">
<!-- 不能写在封装组件里传placeholder,mp-wenxin端编译要报错 -->
<u--input prefixIcon="search" :placeholder="$t('alarm.pleaseEnterDevice')" shape="circle" @change="inputChanged">
</u--input>
</header-search>
<!-- 告警分页 -->
<mescroll-body ref="mescrollRef" :up="upOption" @init="mescrollInit" :down="downOption" @down="downCallback"
@up="upCallback">
<alarm-item :list="list" @openAlertDetail="openAlertDetail"></alarm-item>
<mescroll-empty v-if="!list.length" />
</mescroll-body>
<view style="height: 20rpx"></view>
<!-- 告警筛选-->
<alarm-popup ref="alarmPopupRef" :show="show" @close="close" @queryCondition="getQueryCondition"></alarm-popup>
<f-tabbar></f-tabbar>
</view>
</template>
<script>
import {mapActions } from 'vuex'
import fTabbar from '@/components/module/f-tabbar/f-tabbar';
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
import api from '@/api/index.js'
import alarmItem from './components/alarm-item.vue'
import alarmPopup from './components/alarm-popup.vue'
import {
usePageScrollTo,
useNavigateTo
} from '@/plugins/utils.js'
export default {
mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
components: {
fTabbar,
alarmItem,
alarmPopup
},
data() {
return {
totalText: 'alarm.alarmNum',
page: {
num: 0,
size: 10
},
downOption: {
auto: false //是否在初始化后,自动执行downCallback; 默认true
},
upOption: {
auto: false // 不自动加载
},
show: false,
list: [],
alarmTotal: 0,
queryCondition: {
searchAlarmText: '',
},
conditions: {},
ordId: '',
paramsStaus:null
};
},
onShow() {
this.$nextTick(()=>{
uni.setNavigationBarTitle({
title:this.$t('menu.alarm')
})
})
if (getApp().getBindNot()) {
return
}
if (this.ordId) {
this.loadData(1, {
organizationId: this.ordId
});
this.conditions = {
organizationId: this.ordId
}
return
}
this.loadData(1, {
status:this.paramsStaus
});
},
onHide() {
this.ordId = ''
this.paramsStaus = ''
},
onLoad(e) {
if (getApp().getBindNot()) {
return
}
if (!e.type) {
this.loadData(1);
} else {
let params = JSON.parse(e.type);
this.parmasStatus = null
if (Array.isArray(params)) {
this.paramsStaus = params.join(',');
} else {
this.paramsStaus = params;
}
this.conditions = {
status:this.paramsStaus
}
}
// 隐藏原生的tabbar
uni.hideTabBar();
},
computed: {
pageDisableScroll() {
return this.show ? 'pop-no-scroll' : ''
}
},
methods: {
...mapActions(['updateBadgeTotal']),
inputChanged(e) {
if (getApp().getBindNot()) {
return
}
this.resetQuery();
this.topBack();
this.queryCondition.searchAlarmText = e;
this.page.num = 1;
this.conditions = {
deviceName: e
}
this.loadData(1, {
deviceName: e
});
},
getQueryCondition(value) {
this.loadData(1, value);
this.conditions = value
this.close()
},
resetQuery() {
this.queryCondition.searchAlarmText = '';
this.page.num = 1;
this.$nextTick(() => {
this.$refs.alarmPopupRef.resetQuery()
})
this.conditions = {}
},
topBack() {
usePageScrollTo(0, 10)
},
//下拉刷新
downCallback() {
if (getApp().getBindNot()) {
setTimeout(()=>{
this.mescroll.endByPage(0,0)
},200)
return
}
this.list.length = 0;
this.page.num = 1;
this.resetQuery();
this.loadData(this.page.num);
},
//上拉加载
upCallback() {
if (getApp().getBindNot()) {
setTimeout(()=>{
this.mescroll.endByPage(0,0)
},200)
return
}
const condition = Object.values(this.conditions)
if (condition.length === 0) {
this.page.num += 1;
this.loadData(this.page.num);
} else if (condition.filter(Boolean).length > 0) {
this.page.num += 1;
this.loadData(this.page.num, this.conditions);
} else {
this.page.num += 1;
this.loadData(this.page.num);
}
},
async loadData(page, param) {
let that = this;
let params = {
page,
pageSize: 10,
...param
};
const res = await api.alarmApi.getAlarmApi({
params,
custom: {
load: false
}
})
if(res){
const resAlarm = await uni.$u.http.get('/yt/homepage/app?login=true');
if (resAlarm) {
//异步实时更新告警徽标数
await this.updateBadgeTotal(resAlarm.totalAlarm?.activedAlarm);
}
uni.stopPullDownRefresh();
that.mescroll.endByPage(res.items.length, res.total); //必传参数(当前页的数据个数, 总页数)
that.alarmTotal = res.total;
if (page == 1) {
that.list = res.items;
} else {
that.list = that.list.concat(res.items);
}
}
},
close() {
this.show = false;
},
openSearchDialog() {
if (getApp().getBindNot()) {
uni.$u.toast(this.$t('common.pleaseBindAccount'))
return
}
this.show = true;
this.$nextTick(() => {
this.resetQuery();
})
},
openOrg() {
if (getApp().getBindNot()) {
uni.$u.toast(this.$t('common.pleaseBindAccount'))
return
}
useNavigateTo('/pages/organization/organization')
},
//跳转告警详情
openAlertDetail(e) {
useNavigateTo('/alarm-subpackage/alarm-detail/alarm-detail?data=', e)
},
}
};
</script>
<style lang="scss" scoped>
@import './static/alarm.scss';
/deep/ .u-button--primary {
background-color: #377dff !important;
border-color: #377dff !important;
}
/deep/ .u-button--info {
background-color: #e3e3e5 !important;
border-color: #e3e3e5 !important;
}
/deep/ .u-cell__right-icon-wrap {
margin-top: -55rpx !important;
}
/deep/ .uni-calendar--fixed {
bottom: 172rpx !important;
}
.pop-no-scroll {
overflow: hidden;
position: fixed;
height: 100%;
width: 100%;
}
</style>