gemercheung 3 年之前
父節點
當前提交
ad05d12c6e

+ 29 - 8
miniprogram/api/roomList.ts

@@ -1,17 +1,38 @@
 
 
-import { WX_LOGIN } from '../utils/apiList'
+import { GET_HOME_ROOM_LIST } from '../utils/apiList'
 import { request, Response } from '../utils/http'
 
-interface LoginResType {
-  token: string
+
+interface parmams {
+  pageNum?: number,
+  pageSize?: number
+}
+
+export interface ListItem {
+  createTime: string
+  lastLookTime: string
+  roomCoverUrl: string
+  roomHostCode: string
+  roomHostName: string
+  roomId: string
+  roomInfo: string
+  roomShareCode: number
+  roomShareUrl: string
+  roomStatus: number
+  roomTitle: string
+  roomUserName: string
+  roomViewCount: number
+  tbStatus: number
+  updateTime: string
 }
-type RoomDetailRes = Response & {
-  data: LoginResType
+type RoomListRes = Response & {
+  data: ListItem[]
 }
-export const login = async (code: string): Promise<LoginResType> => {
-  const res = await request.get<RoomDetailRes>(WX_LOGIN, {
-    code
+export const getHomeRoomList = async (params: parmams): Promise<ListItem[]> => {
+  const res = await request.get<RoomListRes>(GET_HOME_ROOM_LIST, {
+    pageNum: params.pageNum || 1,
+    pageSize: params.pageSize || 1000
   })
   return res.data
 

+ 1 - 1
miniprogram/api/user.ts

@@ -30,7 +30,7 @@ export const getUserInfo = async (): Promise<UserResType> => {
   const res = await request.get<UserRes>(WX_GET_USER)
   const app = getApp<IAppOption>();
   app.globalData.userInfo = Object.assign({}, app.globalData.userInfo, res.data)
-  wx.setStorageSync('wxUserId', res.data.wxUserId)
+  wx.setStorageSync('wxUserId', res.data?.wxUserId || '')
   return res.data
 
 }

+ 14 - 2
miniprogram/app.ts

@@ -63,7 +63,7 @@ App<IAppOption>({
       enumerable: true,
       set: function (value) {
         this['_' + key] = value;
-        console.log('是否会被执行2')
+        console.log('是否会被执行2', key)
         method(value);
       },
       get: function () {
@@ -82,8 +82,20 @@ App<IAppOption>({
       }
     })
   },
+  resetUserInfo() {
+    this.globalData.userInfo = {
+      nickName: "",
+      gender: 0,
+      phoneNumber: "",
+      avatarUrl: '',
+      city: '',
+      country: '',
+      language: 'zh_CN',
+      province: ''
+    }
+  },
   onLaunch() {
- 
+
 
   },
 })

+ 5 - 32
miniprogram/pages/index/index.ts

@@ -2,31 +2,10 @@
 // 获取应用实例
 
 const app = getApp<IAppOption>()
-import { request, Response } from '../../utils/http'
+// import { request, Response } from '../../utils/http'
+import { getHomeRoomList, ListItem } from '../../api/roomList'
 
-interface ListItem {
-  createTime: string
-  lastLookTime: string
-  roomCoverUrl: string
-  roomHostCode: string
-  roomHostName: string
-  roomId: string
-  roomInfo: string
-  roomShareCode: number
-  roomShareUrl: string
-  roomStatus: number
-  roomTitle: string
-  roomUserName: string
-  roomViewCount: number
-  tbStatus: number
-  updateTime: string
-}
 
-type ListRes = Response & {
-  data: {
-    list: ListItem[]
-  }
-}
 
 Page({
   data: {
@@ -48,16 +27,10 @@ Page({
 
   async onShow() {
     this.getTabBar().init();
-    const res = await request.post<ListRes>('/takelook/roomList', {
-      pageNum: 1,
-      pageSize: 1000
+    const res = await getHomeRoomList({});
+    this.setData({
+      dataList: res
     })
-    // console.log(res.data.list)
-    if (res.code === 0) {
-      this.setData({
-        dataList: res.data.list
-      })
-    }
 
   },
   handleToRoom(event: WechatMiniprogram.TouchEvent) {

+ 7 - 3
miniprogram/pages/my/my.ts

@@ -27,20 +27,23 @@ Page({
     app.watch('isLogin', this.updateLoginStatus)
   },
 
-  updateUserInfo(data: GlobalUserInfo) {
+  updateUserInfo(data?: any) {
+    const app = getApp<IAppOption>();
+    const updateUserInfo = app.globalData.userInfo
+    const updateData = Object.assign({},updateUserInfo,data)
     this.setData({
-      userInfo: data
+      userInfo: updateData
     })
   },
 
   async updateLoginStatus(data: boolean) {
+    console.log('my页面-isLogin', data)
     this.setData({
       isLogin: data
     })
     if (data) {
       await getUserInfo();
     }
-
   },
   /**
    * 生命周期函数--监听页面显示
@@ -50,6 +53,7 @@ Page({
     const app = getApp<IAppOption>();
     const isLogin = wx.getStorageSync('isLogin')
     app.setLogin(isLogin)
+    this.updateUserInfo();
   },
   login() {
     const app = getApp<IAppOption>();

+ 1 - 1
miniprogram/pages/my/my.wxml

@@ -3,7 +3,7 @@
   <view class="personal-panel">
     <image class="topHeaderBg" src="../../static/images/top.png" mode="aspectFit" />
     <view class="info-box">
-      <t-avatar image="{{ userInfo.avatarUrl || avatar}}" class="avatar" size="large" />
+      <t-avatar image="{{ isLogin ? userInfo.avatarUrl :avatar}}" class="avatar" size="large" />
       <view class="personal-info" wx:if="{{isLogin}}" bindtap="handleToPersonalEdit">
         <text class="title">{{userInfo.nickName}}</text>
         <text class="desc">点击查看个人信息></text>

+ 3 - 15
miniprogram/pages/personal/personal.ts

@@ -92,17 +92,8 @@ Page({
     wx.showToast({
       title: '登出成功!'
     });
-    app.globalData.isLogin = false
-    app.globalData.userInfo = {
-      nickName: "",
-      gender: 0,
-      phoneNumber: "",
-      avatarUrl: '',
-      city: '',
-      country: '',
-      language: 'zh_CN',
-      province: ''
-    }
+    app.setLogin(false)
+    app.resetUserInfo();
   },
   async checkSession(): Promise<boolean> {
     let isExist = false
@@ -189,10 +180,7 @@ Page({
     })
     await getUserInfo();
   },
-  // async changeNickName(e: WechatMiniprogram.TouchEvent) {
-  //   const { value } = e.detail
-  //   console.log('value-2', value)
-  // },
+
   async updateNickName(e: WechatMiniprogram.TouchEvent) {
     const { value } = e.detail
     console.log('value-1', value)

+ 2 - 1
miniprogram/utils/apiList.ts

@@ -1,4 +1,5 @@
-export const GET_ROOM_LIST = '/takelook/roomList'
+export const GET_MY_ROOM_LIST = '/takelook/roomList'
+export const GET_HOME_ROOM_LIST = '/takelook/wxApi/roomList'
 export const GET_ROOM = '/takelook/roomInfo'
 export const GET_SIG = '/takelook/tencentYun/getSign'
 export const LEAVE_ROOM = '/takelook/inOrOutRoom'

+ 1 - 1
project.private.config.json

@@ -2,7 +2,7 @@
   "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "projectname": "livestream-miniapp",
   "setting": {
-    "compileHotReLoad": true,
+    "compileHotReLoad": false,
     "bigPackageSizeSupport": true
   }
 }

+ 2 - 1
typings/index.d.ts

@@ -29,5 +29,6 @@ interface IAppOption {
   setVoiceProps?: (param: VoiceProps) => void
   setLogin: (status: boolean) => Promise<boolean>
   watch: (key: string, method: Function) => void
-  unwatch (key: string, method: Function) => void
+  unwatch: (key: string, method: Function) => void
+  resetUserInfo: () => void
 }