Explorar el Código

Merge branch 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile

* 'master' of ssh://gogs.zfire.top:2222/zfire-front/recycle-mobile:
  feat: 完成消息对接
  修改跳转传参
  feat: 对接消息
Moss hace 1 año
padre
commit
7900e452da

+ 15 - 13
src/common/http/index.js

@@ -16,10 +16,10 @@ const program = {
 };
 const whiteCodes = [200, 201, 4444]
 
-export const $http = (url, method, data, json) => {
+export const $http = (url, method, data, json, loadingBool = true) => {
   //设置请求前拦截器
   http.interceptor.request = (config) => {
-    if (url !== '/homepage/study') {
+    if (loadingBool && url !== '/homepage/study') {
       uni.showLoading({
         title: '加载中...'
       })
@@ -35,7 +35,9 @@ export const $http = (url, method, data, json) => {
   //设置请求结束后拦截器
   http.interceptor.response = async (response) => {
     //判断返回状态 执行相应操作
-    uni.hideLoading()
+    if (loadingBool) {
+      uni.hideLoading()
+    }
     const res = response.data;
     if (whiteCodes.indexOf(res.code) < 0) {
       if (res.code === 1001) {
@@ -100,24 +102,24 @@ async function doRequest(response, url) {
   }
 }
 
-function postJson(url, data) {
-  return $http(url, 'POST', data)
+function postJson(url, data, loadingBool) {
+  return $http(url, 'POST', data, false, loadingBool)
 }
 
-function get(url, data) {
-  return $http(url, 'GET', data)
+function get(url, data, loadingBool) {
+  return $http(url, 'GET', data, false, loadingBool)
 }
 
-function post(url, data) {
-  return $http(url, 'POST', data, true)
+function post(url, data, loadingBool) {
+  return $http(url, 'POST', data, true, loadingBool)
 }
 
-function put(url, data) {
-  return $http(url, 'PUT', data, true)
+function put(url, data, loadingBool) {
+  return $http(url, 'PUT', data, true, loadingBool)
 }
 
-function del(url, data) {
-  return $http(url, 'DELETE', data, true)
+function del(url, data, loadingBool) {
+  return $http(url, 'DELETE', data, true, loadingBool)
 }
 
 export default {

+ 6 - 3
src/common/utils/navPag.js

@@ -61,12 +61,15 @@ export const navToPage = (function() {
   }
 })()
 
-export function webViewHref(url) {
+export function webViewHref(url, pam = {}) {
+  var pamstr = Object.entries(pam).map(item => {
+    return item.join("=")
+  }).join("&");
   if (!!~url.indexOf("?")) {
     return process.env.VUE_APP_HREF + url +
-      `&x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
+      `${pamstr?"&"+pamstr:""}&x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
   } else {
     return process.env.VUE_APP_HREF + url +
-      `?x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
+      `?${pamstr?pamstr+"&":""}x-token=${store.state.user.token||''}&openId=${store.state.user.openId||''}&userId=${store.state.user.userId}&username=${store.state.user.name||''}&useravatar=${store.state.user.avatar||''}`
   }
 }

+ 2 - 1
src/pages/login/indexs.vue

@@ -111,6 +111,7 @@
               this.$store.commit("user/set_openId", res.data.openId)
               this.$store.commit("user/set_name", res.data.name)
               this.$store.commit("user/set_avatar", res.data.avatar)
+              this.$store.commit("user/set_userId", res.data.baseUserId)
               this.$navToPage({
                 url: "/pages/index/index"
               }, "switchTab")
@@ -217,4 +218,4 @@
     background: linear-gradient(135deg, #7fdaff 0%, #6da7ff 100%);
     border-radius: 50rpx;
   }
-</style>
+</style>

+ 31 - 8
src/pages/message/index.vue

@@ -10,24 +10,24 @@
     <view class="message_view">
       <scroll-view class="message_view_scroll" :scroll-y="true" :scroll-top="scrollTop" :enhanced="true"
         :bounces="false" :show-scrollbar="false" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
-        <view class="message_user_aview" v-for="(item,index) in 15" :key="index" @click="goMsgView">
+        <view class="message_user_aview" v-for="(item,index) in list" :key="index" @click="goMsgView(item)">
           <view class="message_user_a">
             <view class="message_user_info">
               <!-- 头像 -->
               <view class="user_head">
-
+                <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.userPic"></image>
               </view>
               <view class="user_info">
                 <!-- 姓名 -->
-                <view class="user_name">{{item}}张锋</view>
+                <view class="user_name">{{item.userName}}</view>
                 <!-- 聊天信息最后一条 -->
-                <view class="user_goods">商品很nice</view>
+                <view class="user_goods">{{item.message}}</view>
                 <!-- 聊天信息最后一条的时间 -->
-                <view class="user_time">2023-10-21 12:20:21</view>
+                <view class="user_time">{{item.createTime}}</view>
               </view>
               <!-- 商品图片 -->
               <view class="goods_img">
-
+                <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.goods_img"></image>
               </view>
             </view>
           </view>
@@ -42,11 +42,34 @@
 </template>
 
 <script>
+  import api from '@/common/http/'
   export default {
     // #ifdef H5
     data() {
       return {
         scrollTop: 0,
+        list: []
+      }
+    },
+    onShow() {
+      var getList = () => {
+        if (this.timeId) {
+          clearTimeout(this.timeId)
+        }
+        api.postJson('/user/talk/list2', {
+          userId: this.$store.state.user.userId,
+          pageNum: 1,
+          pageSize: -1
+        }, false).then(res => {
+          this.list = res.data.records
+          this.timeId = setTimeout(getList, 3000)
+        })
+      }
+      getList()
+    },
+    onHide() {
+      if (this.timeId) {
+        clearTimeout(this.timeId)
       }
     },
     methods: {
@@ -59,9 +82,9 @@
       scroll(e) {
         this.scrollTop = e.detail.scrollTop
       },
-      goMsgView() {
+      goMsgView(item) {
         this.$navToPage({
-          url: '/pages/message/msgView'
+          url: '/pages/message/msgView?goodsId=' + item.goodsId || '' + "&groupId=" + item.groupId || ''
         })
       }
     },

+ 146 - 22
src/pages/message/msgView.vue

@@ -9,13 +9,15 @@
     <!-- 商品信息 -->
     <view class="goods_info">
       <!-- 商品图片 -->
-      <view class="goods_img"></view>
+      <view class="goods_img">
+        <image style="width: 100%; height: 100%;" mode="aspectFill" :src="goodsDetail.goodsPicUrl"></image>
+      </view>
       <!-- 商品描述 -->
       <view class="goods_text">
-        <view class="goods_name">商品的名称展示</view>
+        <view class="goods_name">{{goodsDetail.title}}</view>
         <view class="goods_pon">
           <view>
-            <view class="goods_jiag">¥{{180.00}}</view>
+            <view class="goods_jiag">{{goodsDetail.amount?"¥"+goodsDetail.amount:"面议"}}</view>
             <view class="goods_fuwu">卖家包运费</view>
           </view>
           <view class="go_goods_btn">立即购买</view>
@@ -26,31 +28,33 @@
     <view class="message_view">
       <scroll-view class="message_view_scroll" :scroll-y="true" :scroll-top="scrollTop" :enhanced="true"
         :bounces="false" :show-scrollbar="false" @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll">
-        <view style="box-sizing: border-box;padding: 10rpx 0;">
-          <view v-for="(item,index) in 50" :key="index">
+        <view style="box-sizing: border-box;padding: 10rpx 0;" ref="scrollviewDiv" class="scrollviewDiv">
+          <view v-for="(item,index) in list" :key="index">
             <!-- 右消息 -->
-            <view class="msg_view">
+            <view class="msg_view" v-if="userId===item.userId">
               <!-- 占位 -->
               <view class="msg_user_img_kong">
               </view>
               <view class="msg_view_info msg_view_info_right">
                 <view class="msg_view_conent">
-                  12465479198kuhsadbckaehbl12465479198kuhsadbckaehbl12465479198kuhsadbckaehbl12465479198kuhsadbckaehbl
+                  {{item.message}}
                 </view>
-                <view class="msg_view_time">2023-10-11 12:12:12</view>
+                <view class="msg_view_time">{{item.createTime}}</view>
               </view>
               <!-- 头像 -->
               <view class="msg_user_img">
+                <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.userPic"></image>
               </view>
             </view>
             <!-- 左消息 -->
-            <view class="msg_view">
+            <view class="msg_view" v-else>
               <!-- 头像 -->
               <view class="msg_user_img">
+                <image style="width: 100%; height: 100%;" mode="aspectFill" :src="item.userPic"></image>
               </view>
               <view class="msg_view_info msg_view_info_left">
-                <view class="msg_view_conent">12465479198kuhsadbckaehbl</view>
-                <view class="msg_view_time">2023-10-11 12:12:12</view>
+                <view class="msg_view_conent">{{item.message}}</view>
+                <view class="msg_view_time">{{item.createTime}}</view>
               </view>
               <!-- 占位 -->
               <view class="msg_user_img_kong">
@@ -65,10 +69,15 @@
       <view class="text_input_view">
         <view class="text_input_lay">
           <view class="text_input_tengh">
-            <input class="uni-input_chat" focus placeholder="请输入" />
+            <input class="uni-input_chat" focus placeholder="请输入" v-model="message" />
           </view>
-          <view class="text_input_mount" @click="gengduo = !gengduo">
+          <!-- 更多功能 -->
+          <!-- <view class="text_input_mount" @click="gengduo = !gengduo">
             +
+          </view> -->
+          <!-- 发送消息 -->
+          <view class="text_input_mount" @click="send">
+            <image style="width: 60%; height: 60%;" mode="aspectFill" src="/static/tabBar/icon_issue01.png"></image>
           </view>
         </view>
       </view>
@@ -94,34 +103,149 @@
   </view>
   <!-- #endif -->
   <!-- #ifndef H5 -->
-  <web-view :src="webViewHref('/pages/message/msgView')"></web-view>
+  <web-view :src="webViewHref('/pages/message/msgView',pam)"></web-view>
   <!-- #endif -->
 </template>
 
 <script>
+  import api from '@/common/http/'
   export default {
-    // #ifdef H5
     data() {
       return {
         scrollTop: 0,
-        gengduo: false
+        gengduo: false,
+        pam: {},
+        list: [],
+        message: "",
+        userId: this.$store.state.user.userId,
+        goodsDetail: {}
+      }
+    },
+    onLoad(pam) {
+      this.pam = pam
+    },
+    onShow() {
+      // #ifdef H5
+      this.getGoods()
+      this.getNewList()
+      // #endif
+    },
+    onHide() {
+      // #ifdef H5
+      if (this.timeId) {
+        clearTimeout(this.timeId)
       }
+      // #endif
     },
     methods: {
+      // #ifdef H5
+      getGoods() {
+        if (!this.pam.goodsId) {
+          return
+        }
+        api.postJson('/goods/detail', {
+          id: this.pam.goodsId,
+        }).then(res => {
+          this.goodsDetail = res.data
+          console.log(res)
+        })
+      },
+      getNewList() {
+        if (this.timeId) {
+          clearTimeout(this.timeId)
+        }
+        this.getMsgList(0, () => {
+          this.timeId = setTimeout(this.getNewList, 3000)
+          uni.createSelectorQuery().select('.message_view_scroll').boundingClientRect(data => {
+            uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
+              if ((this.scrollTop + data.height + 10) >= data2.height) {
+                this.scrollTop = data2.height
+              }
+            }).exec()
+          }).exec()
+        })
+      },
+      getMsgList(flag, cb) {
+        api.postJson('/user/talk/list', {
+          userId: this.$store.state.user.userId,
+          flag: flag,
+          ...(() => {
+            if (this.pam.goodsId) {
+              return {
+                goodsId: this.pam.goodsId,
+              }
+            }
+            return {}
+          })(),
+          ...(() => {
+            if (this.pam.groupId) {
+              return {
+                groupId: this.pam.groupId,
+              }
+            }
+            return {}
+          })(),
+          ...(() => {
+            if (this.list.length) {
+              return {
+                id: this.list[flag ? 0 : this.list.length - 1].id
+              }
+            }
+            return {}
+          })(),
+        }, false).then(res => {
+          if (flag) {
+            this.list.unshift(...res.data)
+          } else {
+            this.list.push(...res.data)
+          }
+          cb && cb()
+        })
+      },
       upper() {
-        console.log("顶")
+        // console.log("顶")
+        uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data => {
+          var oldHeight = data.height
+          this.getMsgList(1, () => {
+            this.$nextTick(() => {
+              uni.createSelectorQuery().select('.scrollviewDiv').boundingClientRect(data2 => {
+                this.scrollTop = data2.height - oldHeight
+              }).exec()
+            })
+          })
+        }).exec()
       },
       lower() {
-        console.log("底")
+        // console.log("底")
       },
       scroll(e) {
         this.scrollTop = e.detail.scrollTop
       },
-    },
-    // #endif
-    // #ifndef H5
+      send() {
+        if (this.pam.goodsId && this.$store.state.user.userId) {
+          api.postJson('/user/talk/send', {
+            message: this.message,
+            userId: this.$store.state.user.userId,
+            goodsId: this.pam.goodsId,
+            ...(() => {
+              if (this.pam.groupId) {
+                return {
+                  groupId: this.pam.groupId,
+                }
+              }
+              return {}
+            })(),
+          }, false).then(res => {
+            this.message = ""
+            this.getNewList()
+          })
+        }
+      },
+      // #endif
+      // #ifndef H5
 
-    // #endif
+      // #endif
+    },
   }
 </script>
 

+ 1 - 0
src/store/getters.js

@@ -3,6 +3,7 @@ const getters = {
   openId: state => state.user.openId,
   name: state => state.user.name,
   avatar: state => state.user.avatar,
+  userId: state => state.user.userId,
 }
 
 

+ 1 - 0
src/store/modules/user/actions.js

@@ -33,6 +33,7 @@ export default {
       commit("set_openId", "")
       commit("set_name", "")
       commit("set_avatar", "")
+      commit("set_userId", "")
       resolve()
     })
   },

+ 6 - 1
src/store/modules/user/index.js

@@ -35,6 +35,10 @@ var useravatar = getQueryVariable("useravatar")
 if (useravatar) {
   uni.setStorageSync('recycle_mobile_avatar', useravatar)
 }
+var userId = getQueryVariable("userId")
+if (userId) {
+  uni.setStorageSync('recycle_mobile_userId', userId)
+}
 // #endif
 
 const state = {
@@ -42,10 +46,11 @@ const state = {
   token: uni.getStorageSync('recycle_mobile_token') || '',
   name: uni.getStorageSync('recycle_mobile_name') || '',
   avatar: uni.getStorageSync('recycle_mobile_avatar') || '',
+  userId: uni.getStorageSync('recycle_mobile_userId') || '',
 }
 export default {
   namespaced: true,
   state,
   mutations,
   actions
-}
+}

+ 9 - 0
src/store/modules/user/mutations.js

@@ -9,6 +9,15 @@ export default {
     }
   },
 
+  set_userId: (state, userId) => {
+    state.userId = userId
+    if (userId) {
+      uni.setStorageSync('recycle_mobile_userId', userId)
+    } else {
+      uni.removeStorageSync("recycle_mobile_userId")
+    }
+  },
+
   set_openId: (state, openId) => {
     state.openId = openId
     if (openId) {