消息日志

feasure-livedata
lld 2026-04-01 23:43:31 +08:00
parent af05f4f5e4
commit a06466d834
1 changed files with 75 additions and 41 deletions

View File

@ -10,27 +10,28 @@
:refresher-triggered="refreshing"
:scroll-into-view="scrollId"
:scroll-with-animation="false"
@refresherrefresh="onRefresh"
@refresherrefresh="getList"
@scrolltolower="onLoadMore"
>
<view
v-for="(item, index) in messageList"
:key="index"
:id="`item${item.id}`"
@click="gotoDevice(item)"
class="message-item"
>
<!-- 时间标签如果是第一条或者与上一条时间不同才显示 -->
<view class="time-label" v-if="index === 0 || !isSameMinute(item.createTime, messageList[index - 1].createTime)">
{{ formatTime(item.createTime) }}
<view class="time-label">
{{ item.createTime }}
</view>
<view class="champion-card">
<view class="sender-info">
<view class="sender-info" @click="gotoDevice(item)">
<image class="avatar" :src="avatar" mode="aspectFill"></image>
<text class="sender-text">{{ item.content }}</text>
</view>
</view>
</view>
<uni-load-more iconType="auto" :status="status" :content-text="contentText" />
</scroll-view>
<view class="empty__item tn-margin-top empty__view" v-else>
<tn-empty icon="https://resource.tuniaokj.com/images/empty/alien/2.png"
@ -42,8 +43,7 @@
<script>
import Uuid from "@/tuniao-ui/libs/function/uuid";
import {getMessages, listMessage} from "@/api/warn/message";
import {formatDate} from "@/uni_modules/uni-dateformat/components/uni-dateformat/date-format";
import {listMessage} from "@/api/warn/message";
export default {
data() {
@ -52,12 +52,22 @@ export default {
avatar: 'https://img.xiaoces.com/photos/logo200.png',
messageList: [],
isHaveOldData: true,
scrollId: null
scrollId: null,
msgList:[],
pageNum: 0,
status: 'more',
contentText: {
contentdown: '查看更多',
contentrefresh: '加载中.....',
contentnomore: '没有更多数据了'
},
sortNewId: null,
sortOldId: null,
}
},
onShow() {
onLoad() {
//
this.getSortDate();
// this.getSortDate();
this.getList()
},
methods: {
@ -106,11 +116,10 @@ export default {
const D = String(target.getDate()).padStart(2, '0');
return `${Y}-${M}-${D} ${time}`;
},
getSortDate() {
return this.messageList.sort((a, b) => new Date(a.time) - new Date(b.time));
getSortDate(messageList) {
return messageList.sort((a, b) => new Date(a.createTime) - new Date(b.createTime));
},
//
onRefresh() {
getList() {
this.refreshing = true;
if (!this.isHaveOldData) {
setTimeout(() => {
@ -120,42 +129,67 @@ export default {
}, 800);
return;
}
//
setTimeout(() => {
// 10
const newData = Array.from({ length: 10 }, (_, i) => ({
id: Uuid(16),
time: '2026-03-27 12:00:00',
type: 'champion',
avatar: 'https://picsum.photos/id/999/60/60',
sender: '新用户' + i,
date: '03月27'
}));
//
this.messageList = [...newData, ...this.messageList];
var query = {
msgType: "status",
pageSize: 10,
sortOldId: this.sortOldId
}
listMessage(query).then(response => {
if (response.code === 200) {
if (response.rows.length > 0) {
var newData = this.getSortDate(response.rows);
this.sortOldId = response.rows[0].id
this.messageList = [...newData, ...this.msgList];
this.msgList = [...newData, ...this.msgList]
console.info("时间最早的数据id",this.sortOldId)
return;
}
this.isHaveOldData = false;
}
}).finally(()=>{
// scrollId
this.$nextTick(() => {
//
this.scrollId = "item"+this.messageList[10].id;
this.scrollId = "item"+this.messageList[9].id;
});
//
this.refreshing = false;
}, 800);
},
getList() {
var query = {
msgType: "status",
pageNum: 1,
pageSize: 5
}
listMessage(query).then(response => {
if (response.code === 200 && response.rows.length > 0) {
this.messageList = response.rows
}
})
},
onLoadMore() {
if (!this.sortNewId) {
this.sortNewId = this.msgList[this.msgList.length - 1].id;
}
this.status = 'loading'
var query = {
msgType: "status",
sortNewId: this.sortNewId
}
listMessage(query).then(response => {
if (response.code === 200) {
if (response.rows.length > 0) {
var newData = this.getSortDate(response.rows);
this.messageList = [...this.msgList, ...newData]
this.msgList = [...this.msgList, ...newData]
this.sortNewId = response.rows[response.rows.length-1].id
return;
}
this.$modal.msg("已是最新数据了!");
//
this.status = 'nomore'
}
}).finally(()=>{
// scrollId
this.$nextTick(() => {
//
this.scrollId = "item"+this.messageList[this.messageList.length-1].id;
});
//
this.status = 'more'
})
},
gotoDevice(item) {
this.$tab.navigateTo(item.linkUrl)