Prechádzať zdrojové kódy

fix:socket nickname过滤特殊字符

jinx 3 rokov pred
rodič
commit
7976027734
2 zmenil súbory, kde vykonal 59 pridanie a 26 odobranie
  1. 57 23
      pages/webview/index.js
  2. 2 3
      socket.js

+ 57 - 23
pages/webview/index.js

@@ -16,8 +16,8 @@ Page({
     loadUrl: false,
     goodsCount: 0,
     canIUse: wx.canIUse('button.open-type.getUserInfo'),
-    rnd:'',
-    temp:'',
+    rnd: '',
+    temp: '',
     live_base_url: 'rtmp://120.24.85.77:1935/hls',
     peopleCount: 5,
     surplus: 5
@@ -31,7 +31,7 @@ Page({
   onLoad: async function (options) {
     getApp().checkNetStatu();
 
-    
+
     // setTimeout(() => this.login(), 3000)
     this.setData({
       join: false,
@@ -56,7 +56,7 @@ Page({
       page: 1,
       size: 1000
     })
-    
+
     // console.log(options)
     // options.id = '1046098'
 
@@ -81,17 +81,37 @@ Page({
   async init() {
     let options = this.options
 
-    let {url: base, obj: m } = await new Promise(r => this.getBrandDetail(options.id, (url, obj)  => r({url, obj})))
+    let {
+      url: base,
+      obj: m
+    } = await new Promise(r => this.getBrandDetail(options.id, (url, obj) => r({
+      url,
+      obj
+    })))
 
     this.getBrand(options.id, m)
     this.mcode = m
-    let socketOptions = await this.socketStart({sceneId: this.mcode, roomId: options.roomId})
+    let socketOptions = await this.socketStart({
+      sceneId: this.mcode,
+      roomId: options.roomId
+    })
     let url = this.getUrl(base, socketOptions, this.data.join) + this.urlPj
 
     this.base = base
 
-    this.setData({urlTemp: url.split('').join(' ')})
-    this.setData({ url, loadUrl: true, socketOptions, reload: true, hideWebView: false })
+    this.setData({
+      urlTemp: url.split('').join(' ')
+    })
+    socketOptions.nickname = socketOptions.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
+    console.error(socketOptions)
+
+    this.setData({
+      url,
+      loadUrl: true,
+      socketOptions,
+      reload: true,
+      hideWebView: false
+    })
     this.recorderManager = wx.getRecorderManager()
 
     this.brandId = options.id
@@ -100,20 +120,28 @@ Page({
   },
 
   hideInvitation() {
-    this.setData({ showInvitation: false })
+    this.setData({
+      showInvitation: false
+    })
     this.exit()
   },
 
   hideGuide() {
-    this.setData({ showGuide: false })
+    this.setData({
+      showGuide: false
+    })
   },
 
   hideEnd() {
-    this.setData({ showEnd: false })
+    this.setData({
+      showEnd: false
+    })
   },
 
   hideAlert() {
-    this.setData({ showAlert: false })
+    this.setData({
+      showAlert: false
+    })
   },
 
   // exit() {
@@ -121,23 +149,27 @@ Page({
   //   this.socketStop && this.socketStop()
   //   wx.navigateBack()
   // },
-  
+
   hidePacked() {
-    this.setData({ showPacked: false })
+    this.setData({
+      showPacked: false
+    })
   },
-  
+
   hideIsEnd() {
-    this.setData({ showIsEnd: false })
+    this.setData({
+      showIsEnd: false
+    })
   },
 
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady: function () {
-    
+
   },
 
-  
+
 
 
   /**
@@ -146,11 +178,11 @@ Page({
   onShow: async function () {
     getApp().updateCardCount()
 
-    
-    
+
+
     // this.options.join = true
     // this.getCartList()
-    
+
     let userInfo = wx.getStorageSync('userInfo');
     let token = wx.getStorageSync('token');
 
@@ -180,7 +212,9 @@ Page({
           webviewUrl: null
         })
         setTimeout(() => {
-          this.setData({ hideWebView: false })
+          this.setData({
+            hideWebView: false
+          })
           this.init()
         }, 500)
       } else {
@@ -205,7 +239,7 @@ Page({
     getApp().onPullDownRefresh()
   },
 
-  
+
   /**
    * 页面上拉触底事件的处理函数
    */

+ 2 - 3
socket.js

@@ -66,7 +66,7 @@ export default {
       sponsor = false
     }
 
-    let base = remote.viewHost + '/shop-container/fashilong.html?time='+new Date().getTime()+'&env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
+    let base = remote.viewHost + '/shop-container/fashilong.html?time=' + new Date().getTime() + '&env=' + remote.env + '&sponsor=' + sponsor + '&many=' + this.data.many
     // let base = remote.viewHost + '/shop.html'
 
     this.data.reload = false
@@ -237,7 +237,7 @@ export default {
     //   userInfoa: userInfo.nickname.split('').join(' ')
     // })
 
-
+    userInfo.nickname = userInfo.nickname.replace(/[^\u4E00-\u9FA5A-Za-z0-9]/g, '')
 
     this.role !== 'leader'
     let roomType
@@ -468,7 +468,6 @@ export default {
       }
     }
 
-
     const socketOptions = this.data.socketOptions
     getApp().globalData.roomId = socketOptions.roomId
     const user = data.roomsPerson.find(user => user.userId == socketOptions.userId)