fastbee/yack-app/pagesA/home/device/log/alertLog.vue
2026-02-10 08:41:06 +08:00

323 lines
8.2 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<view class="device-alert-log">
<u-sticky offset-top="45" zIndex="98" bgColor="#eef3f7">
<view class="nav-bar">
<view class="left-wrap">
<view v-if="!isSearch">
<u-icon name="search" size="23" @click="isSearch = true"></u-icon>
</view>
<view v-else style="width: 100%;">
<!-- #ifndef APP-NVUE -->
<u-input :customStyle="{ padding: '6rpx 18rpx'}" v-model="queryParams.alertName"
:placeholder="$tt('alert.inputAlertName')" shape="circle" @clear="handleClearSearch" clearable>
<!-- #endif -->
<!-- #ifdef APP-NVUE -->
<u--input :customStyle="{ padding: '6rpx 18rpx'}" v-model="queryParams.alertName"
:placeholder="$tt('alert.inputAlertName')" shape="circle" @clear="handleClearSearch" clearable>
<!-- #endif -->
<template slot="prefix">
<u-icon name="search" size="22" @click="isSearch = false"></u-icon>
</template>
<template slot="suffix">
<u-button :text="$tt('scene.search')" type="primary" shape="circle" size="mini"
@click="handleSearch"></u-button>
</template>
<!-- #ifndef APP-NVUE -->
</u-input>
<!-- #endif -->
<!-- #ifdef APP-NVUE -->
</u--input>
<!-- #endif -->
</view>
</view>
</view>
</u-sticky>
<view class="log-content">
<view class="item-wrap" v-for="(item, index) in dataList" :key="index" @click="handleDispose(item)">
<view class="title">
<view class="name">{{item.deviceName}}</view>
<view class="status"
:class="{'success': item.alertLevel === 1, 'warning': item.alertLevel === 2, 'error': item.alertLevel === 3}">
{{ getaLertLevelDisplay(item) }}
</view>
</view>
<view class="describe">
<view class="item">{{$tt('alert.alertName')}}:{{item.alertName}}</view>
<view class="item">
{{$tt('alert.processState')}}:<text
:class="{'success': item.status === 1 || item.status === 3, 'warning' : item.status === 2}">
{{ getaStatusDisplay(item) }}</text>
</view>
<view class="item">{{$tt('alert.data')}}:<rich-text :nodes="getaDataDetailDisplay(item)"></rich-text></view>
<view class="item">{{$tt('alert.alertTime')}}:{{item.createTime}}</view>
</view>
<view class="tools" v-if="item.status === 2">
<view class="btn"><u-button type="primary" size="mini" :text="$tt('alert.process')"></u-button>
</view>
</view>
</view>
<u-empty mode="data" :show="total === 0" marginTop="60" :text="$tt('scene.emptyData')"></u-empty>
</view>
<u-loadmore :status="loadmoreStatus" v-if="total > queryParams.pageSize" :loading-text="$tt('timing.effortLoading')"
:loadmoreText="$tt('timing.loadMore')" :nomoreText="$tt('timing.nothing')" marginTop="20" @loadmore="loadMoreLogs" />
</view>
</template>
<script>
import { listAlertLog } from '@/apis/modules/device.js';
import { getAlertTemplateId } from '@/apis/modules/alertLog.js';
export default {
name: "deviceAlertLog",
props: {
device: {
type: Object,
default: null,
required: true
}
},
watch: {
// 兼容小程序
device: function (newVal, oldVal) {
this.deviceInfo = newVal;
if (newVal.deviceId && newVal.deviceId !== oldVal.deviceId) {
this.queryParams.serialNumber = newVal.serialNumber;
this.getAlertLogList();
}
},
},
data () {
return {
isSearch: true, // 是否开启搜索框
queryParams: {
alertName: null,
serialNumber: null,
pageNum: 1,
pageSize: 10,
},
dataList: [],
total: 0, // 总条数
loadmoreStatus: 'loadmore', // 加载更多
tmpIds: null, // 模版id
};
},
mounted () {
const { deviceId, serialNumber } = this.device;
if (deviceId) {
this.queryParams.serialNumber = serialNumber;
this.getAlertLogList();
}
this.getTmplIds(); // 获取模版id
},
methods: {
getAlertLogList () {
listAlertLog(this.queryParams).then((res) => {
if (res.code === 200) {
if (this.queryParams.pageNum == 1) {
this.dataList = res.rows;
} else {
this.dataList = this.dataList.concat(res.rows);
}
this.total = res.total;
setTimeout(() => {
if ((this.queryParams.pageNum - 1) * this.queryParams.pageSize >= this.total) {
this.loadmoreStatus = 'nomore';
} else {
this.loadmoreStatus = 'loadmore';
}
}, 1000);
}
uni.stopPullDownRefresh();
});
},
handleSearch () {
this.dataList = [];
this.queryParams.pageNum = 1;
this.getAlertLogList();
},
handleClearSearch () {
this.handleSearch();
},
// 处理
handleDispose (item) {
// 订阅通知
// #ifdef MP-WEIXIN
uni.requestSubscribeMessage({
tmplIds: [this.tmpIds],
success (res) {
console.log(res);
},
fail (err) {
console.error(err); //失败
}
});
// #endif
uni.navigateTo({
url: `/pages/tabBar/alert/edit?alertLogId=${item.alertLogId}&source=1`
});
},
// 获取模板id
getTmplIds () {
getAlertTemplateId().then(res => {
if (res.code == 200) {
if (res.msg != '') {
this.tmpIds = res.msg;
} else {
console.log('模板id为空!');
}
} else {
console.log(res.msg);
}
});
},
// 获取告警级别显示
getaLertLevelDisplay (item) {
const { alertLevel } = item;
if (alertLevel === 1) {
return this.$tt('alert.notice');
} else if (alertLevel === 2) {
return this.$tt('alert.minor');
} else if (alertLevel === 3) {
return this.$tt('alert.warning');
}
},
// 获取告警状态显示
getaStatusDisplay (item) {
const { status } = item;
if (status === 1) {
return this.$tt('alert.noNeed');
} else if (status === 2) {
return this.$tt('alert.Unprocessed');
} else if (status === 3) {
return this.$tt('alert.processed');
}
},
// 获取告警数据内容
getaDataDetailDisplay (item) {
const { detail } = item;
if (detail) {
const detailObj = JSON.parse(detail);
return `<div>id:<span style="color:#F56C6C">${detailObj.id}</span>,value:<span style="color:#F56C6C">${detailObj.value}</span></div>`
}
},
// 上拉加载
loadMoreLogs () {
this.loadmoreStatus = 'loading';
this.queryParams.pageNum = ++this.queryParams.pageNum;
// 模拟网络请求
setTimeout(() => {
if ((this.queryParams.pageNum - 1) * this.queryParams.pageSize >= this.total) {
this.loadmoreStatus = 'nomore';
} else {
this.loadmoreStatus = 'loading';
this.getAlertLogList();
}
}, 1000);
},
// 下拉刷新
onPullDownRefresh () {
this.dataList = [];
this.queryParams.pageNum = 1;
// 模拟网络请求
setTimeout(x => {
this.getList();
uni.stopPullDownRefresh();
}, 1000);
},
}
}
</script>
<style lang="scss">
page {
background: #eef3f7;
}
.device-alert-log {
.nav-bar {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
padding: 20rpx;
height: 74rpx;
.left-wrap {
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
}
}
.log-content {
width: 100%;
.item-wrap {
box-shadow: 0 2rpx 0px 0 rgba(0, 0, 0, 0.1);
border-radius: 10rpx;
margin: 20rpx;
padding: 10rpx 20rpx;
background-color: #ffffff;
&:first-child {
margin-top: 0;
}
.title {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #eaecef;
padding: 20rpx 0;
.name {
flex: 1;
font-size: 32rpx;
margin-right: 20rpx;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.status {
font-size: 24rpx;
}
}
.describe {
font-size: 28rpx;
.item {
display: flex;
margin: 16rpx 0;
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
.tools {
display: flex;
flex-direction: row;
justify-content: flex-end;
margin-bottom: 10rpx;
}
}
}
.success {
color: #5ac725;
}
.warning {
color: #f9ae3d;
}
.error {
color: #f56c6c;
}
}
</style>