Commit c854d6f0 by jscat

nyx weapp: 功能更新

1. 添加榜单: 1)热度商家榜 2)活跃主播榜
parent 4ed5e230
...@@ -58,6 +58,38 @@ Page({ ...@@ -58,6 +58,38 @@ Page({
touchTime: 0, touchTime: 0,
touchId: "", touchId: "",
//榜单栏 jscat 2020/11/20
/*
榜单数据流: 1_server vs n_client
1) client: socket: 上传文字 @cincin #南沙, dict->string
2) client: weapp : dict->string, 调用server, 更新redis
3) server: jaapp : 解析并更新redis
4) server: socket: sendData to n_client
5) client: socket: receive , 更新 local rankData_raw, 更新list
6) client: weapp : 点击; rankData_raw -> list data
*/
selected : '@',
likeUrl: "../../icon/activity/like_selected.png", // like图标的url
//directly to redis
rankData_raw_like: {
'@叁年间' : 100,
'@cincin' : 40,
"#六尾的大baby": 100,
"#南沙": 39,
"#小妹最乖哦": 3123,
},
rankData: [
{
name: "@叁年间",
like:100
},
{
name:"@cincin",
like:40
}
],
}, },
/** /**
...@@ -112,13 +144,13 @@ Page({ ...@@ -112,13 +144,13 @@ Page({
var sid = _this.data.sid var sid = _this.data.sid
if (sid != undefined && nyxCode != undefined && sid != "" && nyxCode != "") { if (sid != undefined && nyxCode != undefined && sid != "" && nyxCode != "") {
console.log("===onLoad_initSocket") console.log("===onLoad_initSocket")
app.initSocket(sid, nyxCode, "驾临互动圈") app.initSocket(sid, nyxCode, "驾临大厅")
app.globalData.socketClose = false app.globalData.socketClose = false
} }
} }
wx.setNavigationBarTitle({ wx.setNavigationBarTitle({
title: "新鲜互动" title: "互动大厅"
}) })
/** /**
...@@ -142,6 +174,10 @@ Page({ ...@@ -142,6 +174,10 @@ Page({
emotionHost: app.globalData.emotionHost emotionHost: app.globalData.emotionHost
}) })
//构建榜单数据
var raw = _this.__data__.rankData_raw_like
_this.genRankData(raw, '@')
}, },
// 初始化socket, 监听socket // 初始化socket, 监听socket
...@@ -153,7 +189,7 @@ Page({ ...@@ -153,7 +189,7 @@ Page({
var sid = _this.data.sid var sid = _this.data.sid
if (sid != undefined && uid != undefined && sid != "" && uid != "") { if (sid != undefined && uid != undefined && sid != "" && uid != "") {
console.log("===onShow_initSocket") console.log("===onShow_initSocket")
app.initSocket(sid, uid, "驾临互动圈") app.initSocket(sid, uid, "驾临大厅")
app.globalData.socketClose = false app.globalData.socketClose = false
} }
} }
...@@ -198,7 +234,7 @@ Page({ ...@@ -198,7 +234,7 @@ Page({
clearTimeout(app.globalData.connectSocketTimeOut) clearTimeout(app.globalData.connectSocketTimeOut)
app.globalData.connectSocketTimeOut = setTimeout(() => { app.globalData.connectSocketTimeOut = setTimeout(() => {
console.log("===onClose_initSocket") console.log("===onClose_initSocket")
app.initSocket(_this.data.sid, app.globalData.nyxCode, "驾临互动圈") app.initSocket(_this.data.sid, app.globalData.nyxCode, "驾临大厅")
}, 3000); }, 3000);
} }
}) })
...@@ -253,34 +289,6 @@ Page({ ...@@ -253,34 +289,6 @@ Page({
}, },
onType: function (e) {
console.log(e)
switch (e.detail.idx) {
case '1':
wx.navigateTo({
url: '/pages/key/matchTest/matchTest'
})
break;
case '2':
wx.navigateTo({
url: '/pages/key/matchTest/matchTest'
})
break;
case '3':
wx.navigateTo({
url: '/pages/key/matchOne/matchOne'
})
break;
case '4':
wx.navigateTo({
url: '/pages/key/matchTwo/matchTwo'
})
break;
default:
break;
}
},
/* /*
*/ */
...@@ -376,6 +384,7 @@ Page({ ...@@ -376,6 +384,7 @@ Page({
//https://www.cnblogs.com/qlongbg/p/11603328.html //https://www.cnblogs.com/qlongbg/p/11603328.html
promise.then(function (value) { promise.then(function (value) {
console.log("===enter promise then_pass_" + value) console.log("===enter promise then_pass_" + value)
self.submitToLike(messageVal)
self.submitTo(messageVal) self.submitTo(messageVal)
//更新数据(模拟请求历史数据) //更新数据(模拟请求历史数据)
self.setData({ self.setData({
...@@ -440,6 +449,21 @@ Page({ ...@@ -440,6 +449,21 @@ Page({
} }
}, },
// 提交引用 Like
submitToLike: function (inputValue) {
let _this = this;
if (app.globalData.socketTask.readyState == 1) {
// 如果打开了socket就发送数据给服务器
var msg = JSON.stringify({
'cmd': 'onLike',
'uid': app.globalData.nyxCode,
'msg': inputValue
})
_this.sendSocketMessage(msg)
}
},
bindKeyInput: function (e) { bindKeyInput: function (e) {
this.setData({ this.setData({
inputValue: e.detail.value inputValue: e.detail.value
...@@ -470,7 +494,7 @@ Page({ ...@@ -470,7 +494,7 @@ Page({
processData(json) { processData(json) {
var _this = this; var _this = this;
/* /*
cmd==onOpen, text = "欢迎" + map.uid + "驾临互动圈" cmd==onOpen, text = "欢迎" + map.uid + "大厅"
cmd==onData, text = map.msg cmd==onData, text = map.msg
if(chatUserinfo.nickName == app.globalData.userInfo.nickName) 不添加 if(chatUserinfo.nickName == app.globalData.userInfo.nickName) 不添加
*/ */
...@@ -482,66 +506,41 @@ Page({ ...@@ -482,66 +506,41 @@ Page({
text = " " + _this.data.chatUserInfo.nickName + " " +json["msg"] text = " " + _this.data.chatUserInfo.nickName + " " +json["msg"]
nickName = "系统" nickName = "系统"
avater = "../../icon/mall.png" avater = "../../icon/mall.png"
_this.processOpen(text, nickName, avater)
} }
else if (json["cmd"] == "onData") { else if (json["cmd"] == "onData") {
text = json["msg"] text = json["msg"]
nickName = _this.data.chatUserInfo.nickName nickName = _this.data.chatUserInfo.nickName
avater = _this.data.chatUserInfo.avatarUrl avater = _this.data.chatUserInfo.avatarUrl
_this.processInfo(text, nickName, avater)
} }
else if (json["cmd"] == "onLike")
//表情处理
var reg = /\[.+?\]/g;
let newVal = text.replace(reg, function (a, b) {
return face(a) ? face(a) : a;
});
//回复
let objL = {
nickName: nickName,
type: 'L',
messageType: 'txt',
con: newVal,
avater: avater,
};
let messageArr = [];
//jscat 20200314 most important!
// 判断内容是否显示
// 1. 发送data,同时非自己
// 2. (自己登陆,不需要重复发送),
// 3. (竞答完成后,需要发送内容)
// 4. (别人登陆, 需要发送)
if (
(json["cmd"] == "onData" && _this.data.chatUserInfo.userid != app.globalData.nyxCode)
|| (json["cmd"] == "onOpen" && app.globalData.onOpenOp.key!=true)
|| (json["cmd"] == "onOpen" && _this.data.chatUserInfo.userid != app.globalData.nyxCode)
|| (json["cmd"] == "onScore")
)
{ {
messageArr.push(objL); text = json["msg"]
} //https://www.runoob.com/jsref/jsref-obj-regexp.html
if ((json["cmd"] == "onScore" && wx.getStorageSync("sendMsg") != "")) // js regex
//获取名字 name,
/*
1. 空格结尾或者没有空格
2. 不包括'@ '和'# '情况
3. #123 #123 这种情况要去掉
*/
var reg = /(@|#)\S.+?(\s+|$)/g;
let newList = text.match(reg);
if(newList != null)
{ {
wx.setStorageSync('sendMsg', ''); var str = uniqueList(newList).join("::")
nickName = _this.data.chatUserInfo.nickName
avater = _this.data.chatUserInfo.avatarUrl
_this.processLike(str, nickName, avater)
} }
if (json["cmd"] == "onOpen")
{
app.globalData.onOpenOp.key = true;
} }
let newMessageArr = _this.data.messageList.concat(messageArr);
//更新数据(模拟请求历史数据)
_this.setData({
messageInputVal: "",
messageList: newMessageArr,
isEmotion: false,
isMedia: false,
})
_this.scrollBottom();
}, },
touchStart:function(e){ touchStart:function(e){
    var _this=this;     var _this=this;
    _this.setData({     _this.setData({
...@@ -602,6 +601,177 @@ Page({ ...@@ -602,6 +601,177 @@ Page({
 }  }
}, },
switchCategory(e) {
var _this = this;
var curIndex = e.currentTarget.dataset.index ? e.currentTarget.dataset.index : 0
this.setData({
curIndex: curIndex,
})
},
selected: function (e) {
var _this = this;
var raw = _this.__data__.rankData_raw_like
//js的e.currentTarget.id 对应wxml的 id="tab0"
//js的e.currentTarget.dataSet.id 对应wxml的 data-id="tab0"
var index = e.currentTarget.id
let selected = index=='@' ? '@' : "#"
this.setData({
selected
})
_this.genRankData(raw, selected)
},
//处理Like
processLike:function(text, nickName, avater)
{
var _this = this;
var raw = _this.__data__.rankData_raw_like
var selected = _this.__data__.selected
//获取名字 name
//input: @叁年间::#南沙
//output: ['@叁年间', '#南沙']
let newVal = text.split("::")
for(let i=0; i<newVal.length; i++)
{
if(raw.hasOwnProperty(newVal[i]))
{
raw[newVal[i]] = raw[newVal[i]]+1
}
else
{
raw[newVal[i]] = 1
}
}
//更新数据(模拟请求历史数据)
_this.genRankData(raw, selected)
},
//处理open的代码
processOpen:function(text, nickName, avater)
{
var _this = this;
//表情处理
var reg = /\[.+?\]/g;
let newVal = text.replace(reg, function (a, b) {
return face(a) ? face(a) : a;
});
//回复
let objL = {
nickName: nickName,
type: 'L',
messageType: 'txt',
con: newVal,
avater: avater,
};
let messageArr = [];
//jscat 20200314 most important!
// 判断内容是否显示
// 1. 发送data,同时非自己
// 2. (自己登陆,不需要重复发送),
// 3. (竞答完成后,需要发送内容)
// 4. (别人登陆, 需要发送)
if (
(app.globalData.onOpenOp.key!=true)
|| (_this.data.chatUserInfo.userid != app.globalData.nyxCode)
)
{
messageArr.push(objL);
}
app.globalData.onOpenOp.key = true;
let newMessageArr = _this.data.messageList.concat(messageArr);
//更新数据(模拟请求历史数据)
_this.setData({
messageInputVal: "",
messageList: newMessageArr,
isEmotion: false,
isMedia: false,
})
_this.scrollBottom();
},
//处理info data
processInfo: function(text, nickName, avater)
{
var _this = this;
//表情处理
var reg = /\[.+?\]/g;
let newVal = text.replace(reg, function (a, b) {
return face(a) ? face(a) : a;
});
//回复
let objL = {
nickName: nickName,
type: 'L',
messageType: 'txt',
con: newVal,
avater: avater,
};
let messageArr = [];
//jscat 20200314 most important!
// 判断内容是否显示
// 1. 发送data,同时非自己
// 2. (自己登陆,不需要重复发送),
// 3. (竞答完成后,需要发送内容)
// 4. (别人登陆, 需要发送)
if (
(_this.data.chatUserInfo.userid != app.globalData.nyxCode)
)
{
messageArr.push(objL);
}
let newMessageArr = _this.data.messageList.concat(messageArr);
//更新数据(模拟请求历史数据)
_this.setData({
messageInputVal: "",
messageList: newMessageArr,
isEmotion: false,
isMedia: false,
})
_this.scrollBottom();
},
genRankData: function(raw, rankType)
{
var _this = this;
//raw: dict, {"@叁年间":100, "#123":34}
//rankType: string, "@"
var rankData = []
var res = Object.keys(raw).sort(function(a,b){ return raw[b]-raw[a]; });
for (var key in res)
{
if(res[key][0] == rankType)
{
var dict = {}
var key1 = res[key].replace(rankType,"")
dict["name"] = key1
dict["like"] = raw[res[key]]
rankData.push(dict)
}
}
_this.setData({rankData })
}
}) })
//通过Promise方式为wx.request添加同步操作 //通过Promise方式为wx.request添加同步操作
...@@ -744,3 +914,17 @@ function face(obj) { ...@@ -744,3 +914,17 @@ function face(obj) {
} }
return face[obj]; return face[obj];
} }
function uniqueList(arr) {
var res = [];
var json = {};
var r = /\s+/g;
for(var i = 0; i < arr.length; i++){
var str = arr[i].replace(r,'')
if(!json[str]){
res.push(str);
json[str] = 1;
}
}
return res;
}
\ No newline at end of file
<!--pages/key/key.wxml--> <!--pages/share/share.wxml-->
<view class="page"> <view class="page">
<!-- start key view --> <!-- start key view -->
<view class="weui-cells"> <view class="tab">
<scroll-view scroll-y="true" style="height:{{keyHeight}}px;position:fixed; top:0;"> <view class="tab-title">
<navigator class="weui-cell weui-cell_access" hover-class="weui-cell_active" url="/pages/key/matchTest/matchTest"> <view class="{{selected=='@'?'border-tottom':'default'}}" id="@" bindtap="selected">热度商家榜</view>
<view class="weui-cell__hd"> <view class="{{selected=='#'?'border-tottom':'default'}}" id="#" bindtap="selected">活跃主播榜</view>
<image src="/icon/daily.png" /> </view>
<view class="tab-content" style="height:{{keyHeight-100}}px;">
<view class="selected1" wx:for="{{rankData}}"
wx:key="{{item.id}}" data-id="{{item.id}}" data-index="{{index}}"
bindtap="switchCategory">
<view class="rank">
<view class="rank-left">{{item.name}}</view>
<view class="rank-right">
<view class="rank-row"><image src="{{likeUrl}}"></image> {{item.like}}</view>
</view>
</view>
</view> </view>
<view class="weui-cell__bd">随便看看</view>
<view class="weui-cell__ft weui-cell__ft_in-access"></view>
</navigator>
<navigator class="weui-cell weui-cell_access" hover-class="weui-cell_active" url="/pages/key/matchStudy/matchStudy">
<view class="weui-cell__hd">
<image src="/icon/study.png"/>
</view> </view>
<view class="weui-cell__bd">知识学习</view>
<view class="weui-cell__ft weui-cell__ft_in-access"></view>
</navigator>
</scroll-view>
</view> </view>
<!--end key view -->
<!--end key view -->
<!--公屏view--> <!--公屏view-->
<view style="height:{{chatHeight+40}}px;position:fixed; bottom:0;"> <view style="height:{{chatHeight+40}}px;position:fixed; bottom:0;">
......
...@@ -301,3 +301,42 @@ ...@@ -301,3 +301,42 @@
vertical-align: middle; vertical-align: middle;
} }
.tab-title{
height: 60rpx;
background: #fff;
border-top: 1px solid #fafafa;
padding: 16rpx;
line-height: 60rpx;
display:flex;
flex-direction: row;
}
.tab-title view{
flex:auto;
text-align:center;
}
.tab-content{
height: 60rpx;
background: #fff;
padding: 16rpx;
}
.border-tottom{
border-bottom:1rpx solid red;
}
.show{display:block;}
.hidden{display:none;}
/* rank-info */
.rank{width: 100%; display: flex; margin-top: 0rpx; align-items: center;}
/* .rank-left{width: 50%; text-align: center;}
.rank-right{width: 50%; display: flex; justify-content: center;} */
.rank-left{width: 50%; padding-left:100rpx; margin-bottom: 10rpx;}
.rank-right{width: 50%; display: flex; padding-left:100rpx;}
.rank-right image{
width: 40rpx;
height: 40rpx;
font-size: 0;
}
.rank-row{
display: flex;
flex-direction: row;
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论