Explorar o código

feat: 对接消息

linwenxin hai 1 ano
pai
achega
8b693d9262

+ 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 {

+ 2 - 2
src/common/utils/navPag.js

@@ -64,9 +64,9 @@ export const navToPage = (function() {
 export function webViewHref(url) {
   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||''}`
+      `&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||''}`
+      `?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">
-
+                <!-- item.userPic -->
               </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">
-
+                <!-- item.goods_img -->
               </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=' + 888888
         })
       }
     },

+ 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) {