Browse Source

修改未登录时不调用方法

plg 8 months ago
parent
commit
b2f5ce4444
2 changed files with 84 additions and 26 deletions
  1. 78 26
      src/views/Community.vue
  2. 6 0
      src/views/TestRecord.vue

+ 78 - 26
src/views/Community.vue

@@ -45,7 +45,7 @@ onMounted(() => {
     userNo.value = userInfo.userInfo.userNo;
     userSex.value = userInfo.userInfo.gender;
     //进到界面开始轮询
-    queryMsg()
+    // queryMsg()
 })
 //界面销毁函数
 
@@ -82,19 +82,28 @@ const queryMsg = async () => {
 
 //获取数据报
 const getData = async () => {
+    console.log('架子了')
     //判断总条数是否大于当前页面的数据
-    console.log(totol.value == list.value.length)
+    // console.log(totol.value == list.value.length)
     //先判断
-    if (totol.value == list.value.length) {
-        //显示noMore
-        if (totol.value == 0) {
-            noMore.value = true;
-        } else {
-            noMore.value = false;
-        }
-
+    // debugger;
+    if (totol.value < list.value.length) {
+        noMore.value = true;
         return
     }
+    if (totol.value != 0) {
+        if (totol.value == list.value.length) {
+            //显示noMore
+            if (totol.value == 0) {
+                noMore.value = false;
+            } else {
+                noMore.value = true;
+            }
+
+            return
+        }
+    }
+
 
     //先是加载中的话就不加载了
     if (isLoading.value) {
@@ -102,9 +111,10 @@ const getData = async () => {
     }
     isLoading.value = true;
     //参数构造
-    pageNum.value++
+
     //到这里就可以显示加载中
     let res = await queryMsg()
+    pageNum.value++
     isLoading.value = false;
 
 }
@@ -126,7 +136,9 @@ const queryMsg1 = async () => {
         parentUserNo: parentUserNo.value
     }
     let res: any = await queryMsgApi1(params)
-    console.log(res)
+
+    //修改文本
+
     if (res.code == 200) {
         // 将值赋值给列表
         if (res.data.content.length > 0) {
@@ -146,13 +158,18 @@ const queryMsg1 = async () => {
 const getData1 = async () => {
     //判断总条数是否大于当前页面的数据
     console.log(totol1.value == list1.value.length)
+    if (totol1.value < list1.value.length) {
+        noMore1.value = true;
+        return
+    }
     //先判断
     if (totol1.value == list1.value.length) {
         //显示noMore
         if (totol1.value == 0) {
-            noMore1.value = true;
-        } else {
             noMore1.value = false;
+        } else {
+
+            noMore1.value = true;
         }
 
         return
@@ -164,9 +181,10 @@ const getData1 = async () => {
     }
     isLoading1.value = true;
     //参数构造
-    pageNum1.value++
+
     //到这里就可以显示加载中
     let res = await queryMsg1()
+    pageNum1.value++
     isLoading1.value = false;
 
 }
@@ -184,6 +202,15 @@ const openPubMsg = () => {
 
 //点击进行发布信息
 const pubMsg = async () => {
+    des_input.value.value = ''
+    //判断用户是否登陆了
+    if (!userInfo.token) {
+        ElMessage({
+            message: '尚未登录',
+            type: 'warning'
+        })
+        return
+    }
     if (des_input.value == '') {
         ElMessage({
             message: '留言不能为空',
@@ -202,6 +229,7 @@ const pubMsg = async () => {
     }
     let res: any = await pubMsgApi(params)
     if (res.code == 200) {
+        list.value.push(res.data)
         des_input.value.value = ''
         isLock.value = false
         pub_visible.value = false
@@ -232,12 +260,27 @@ const subFun = (item: any) => {
     comDes.value = item.commentContent;
     parentUserNo.value = item.userNo
     sub_visible.value = true
+    subMM.value = ''
+    //打开的时候
+    // 需要将数据值空
+    resetFun()
+
     queryMsg1()
 }
 
 
 //点击进行发布信息-----子信息
 const subPubMsg = async () => {
+    //判断是否登陆了
+    if (!userInfo.token) {
+        ElMessage({
+            message: '尚未登录',
+            type: 'warning'
+        })
+        return
+    }
+
+
     if (subMM.value == '') {
         ElMessage({
             message: '留言不能为空',
@@ -261,12 +304,19 @@ const subPubMsg = async () => {
     }
     let res: any = await subPubMsgApi(params)
     if (res.code == 200) {
-        subMM.value = ''
+
         isLock.value = false
         // sub_visible.value = false
         //调用个查询
-        resetFun()
-        queryMsg1()
+        //加一条在上边
+        console.log(list1.value)
+        list1.value.push(res.data)
+        subMM.value = ''
+
+        //禁用滚动
+        //在这里应该需要滚动到最底部
+        // resetFun()
+        // queryMsg1()
     } else {
         ElMessage({
             message: res.msg,
@@ -327,7 +377,8 @@ onUnmounted(() => {
                         </div>
                     </div>
                     <!-- //留言内容 -->
-                    <div class="com_out" style="overflow: auto" v-infinite-scroll="getData">
+                    <div class="com_out" style="overflow: auto" :infinite-scroll-distance="20"
+                        v-infinite-scroll="getData">
                         <div v-for="item in list">
                             <div class="com_title">
                                 <img src="../assets/kepu/man.png" />
@@ -348,9 +399,10 @@ onUnmounted(() => {
                                 <span>{{ item.count }}</span>
                             </div>
                         </div>
-                        <div style="text-align: center;margin-top:20px" v-show="isLoading">努力加载中...</div>
-                        <div style="text-align: center;;margin-top:20px" v-show="noMore">没有更多了</div>
+                        <div style="text-align: center" v-if="isLoading">努力加载中...</div>
+                        <div style="text-align: center;" v-if="noMore">没有更多了</div>
                     </div>
+
                 </div>
 
             </div>
@@ -410,7 +462,8 @@ onUnmounted(() => {
                     {{ comDes }}
                 </div>
                 <el-divider border-style="dotted" style="margin-top:40px;" />
-                <div class="sub_infinite-list-wrapper" style="overflow: auto" v-infinite-scroll="getData1">
+                <div class="sub_infinite-list-wrapper" style="overflow: auto" :infinite-scroll-distance="20"
+                    v-infinite-scroll="getData1">
                     <div v-for="item in list1" style="margin-top:40px">
 
                         <div class="msg_dig">
@@ -430,8 +483,8 @@ onUnmounted(() => {
                             {{ item.commentContent }}
                         </div>
                     </div>
-                    <div style="text-align: center;margin-top:20px" v-show="isLoading1">努力加载中...</div>
-                    <div style="text-align: center;;margin-top:20px" v-show="noMore1">没有更多了</div>
+                    <div style="text-align: center;margin-top:20px" v-if="isLoading1">努力加载中...</div>
+                    <div style="text-align: center;;margin-top:20px" v-if="noMore1">没有更多了</div>
                 </div>
 
                 <el-divider border-style="dotted" style="margin-top:40px;" />
@@ -639,8 +692,7 @@ label {
             }
 
             .com_out {
-                min-height: 500px;
-                max-height: 500px;
+                height: 500px;
 
                 .com_title {
                     margin-top: 40px;

+ 6 - 0
src/views/TestRecord.vue

@@ -57,6 +57,12 @@ const getData = async () => {
 }
 
 const initData = async () => {
+
+    //判断用户登录没有
+    if (!userInfo.token) {
+        return
+    }
+
     let params = {
         pageNum: pageNum.value,
         pageSize: pageSize.value,