瀏覽代碼

完成消息列表下拉刷新与加载更多

LinWuTai 1 周之前
父節點
當前提交
f643e3047c
共有 3 個文件被更改,包括 35 次插入3 次删除
  1. 1 1
      pages.json
  2. 28 2
      pages/chat/chat.vue
  3. 6 0
      pages/chatDetail/chatDetail.vue

+ 1 - 1
pages.json

@@ -26,7 +26,7 @@
 			"path": "pages/chat/chat",
 			"path": "pages/chat/chat",
 			"style": {
 			"style": {
 				"navigationBarTitleText": "消息",
 				"navigationBarTitleText": "消息",
-				"enablePullDownRefresh": false,
+				"enablePullDownRefresh": true,
 				"app-plus": {
 				"app-plus": {
 					"autoBackButton": false,
 					"autoBackButton": false,
 					"titleNView": true
 					"titleNView": true

+ 28 - 2
pages/chat/chat.vue

@@ -9,6 +9,14 @@
 				placeholder="请输入搜索内容"
 				placeholder="请输入搜索内容"
 			></u-search>
 			></u-search>
 		</view>
 		</view>
+		<u-empty
+			mode="data"
+			v-if="list.length === 0"
+			iconSize="120"
+			textSize="58"
+			text="暂无数据"
+		>
+		</u-empty>
 		<view class="list-box">
 		<view class="list-box">
 			<view class="list-item-box" v-for="item in list" :key="item.id" @click="onChatClick(item)">
 			<view class="list-item-box" v-for="item in list" :key="item.id" @click="onChatClick(item)">
 				<view class="main-box">
 				<view class="main-box">
@@ -34,12 +42,13 @@
 				<view class="line-box"></view>
 				<view class="line-box"></view>
 			</view>
 			</view>
 		</view>
 		</view>
+		<uni-load-more v-show="visualLoadMore" :status="loadMoreStatus"></uni-load-more>
 	</view>
 	</view>
 </template>
 </template>
 
 
 <script setup>
 <script setup>
 	import { ref } from 'vue'
 	import { ref } from 'vue'
-	import { onLoad, onReachBottom } from '@dcloudio/uni-app'
+	import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app'
 	import { query, count } from '@/api/chat.js'
 	import { query, count } from '@/api/chat.js'
 	
 	
 	const uToast = ref()
 	const uToast = ref()
@@ -108,7 +117,24 @@
 			url: `/pages/chatDetail/chatDetail?id=${chat.id}&title=${chat.title}`
 			url: `/pages/chatDetail/chatDetail?id=${chat.id}&title=${chat.title}`
 		})
 		})
 	}
 	}
-	
+	onPullDownRefresh((e) => {
+		searchForm.value.pageNumber = 1
+		loadMoreStatus.value = 'more'
+		query(searchForm.value).then(res => {
+			if (res && res.message === 'success') {
+				list.value = res.data
+				if (res.count === 0) {
+					visualLoadMore.value = false
+				}
+				uni.showToast({
+					title: '刷新成功',
+					icon: 'success',
+					duration: 2000
+				})
+				uni.stopPullDownRefresh()
+			}
+		})
+	})
 	
 	
 	onReachBottom(async () => {
 	onReachBottom(async () => {
 		if (loadMoreStatus.value === 'noMore') {
 		if (loadMoreStatus.value === 'noMore') {

+ 6 - 0
pages/chatDetail/chatDetail.vue

@@ -19,6 +19,7 @@
 <script setup>
 <script setup>
 	import { ref } from 'vue'
 	import { ref } from 'vue'
 	import { onLoad } from '@dcloudio/uni-app'
 	import { onLoad } from '@dcloudio/uni-app'
+	import { detail } from '@/api/chat.js'
 	
 	
 	const chatId = ref()
 	const chatId = ref()
 	const chatTitle = ref('')
 	const chatTitle = ref('')
@@ -33,6 +34,11 @@
 	
 	
 	onLoad((load) => {
 	onLoad((load) => {
 		chatId.value = load.id
 		chatId.value = load.id
+		detail(chatId.value).then(res => {
+			if (res && res.message === 'success') {
+				chat.value = res.data
+			}
+		})
 		chatTitle.value = load.title
 		chatTitle.value = load.title
 		uni.setNavigationBarTitle({
 		uni.setNavigationBarTitle({
 			title: chatTitle.value
 			title: chatTitle.value