Commit c939274d by suwenbiao

聊天

parent 7af70dc1
...@@ -3,128 +3,41 @@ ...@@ -3,128 +3,41 @@
<!-- 特效礼物 --> <!-- 特效礼物 -->
<special :url="specialUrl"></special> <special :url="specialUrl"></special>
<scroll-view lower-threshold="20" scroll-y="true" class="chat" show-scrollbar="false" :scroll-top="scrollTop"> <scroll-view lower-threshold="20" scroll-y="true" class="chat" show-scrollbar="false" :scroll-top="scrollTop">
<view class="cavasation my-1" v-for="(item,index) in msgList" :key="index"> <view class="cavasation my-2" v-for="(item,index) in msgList" :key="index">
<scroll-view lower-threshold="20" scroll-y="true" class="chat" show-scrollbar="true">
<view class="cavasation my-2" v-for="(item,index) in datalist" :key="index">
<view class="person"> <view class="person">
<u-avatar :src="item.avatar" size="60"></u-avatar> <u-avatar :src="item.avatar" size="60"></u-avatar>
<span class="ml-1">{{item.name}}</span> <span class="ml-1">{{item.sendName}}</span>
</view> </view>
<view class="content"> <view class="content">
<span class="text">{{item.content}}</span> <span class="text">{{item.text}}</span>
</view> </view>
</view> </view>
</scroll-view>
</view>
</scroll-view> </scroll-view>
</view> </view>
</template> </template>
<script> <script>
import special from "@/components/footer/gift/special-effects/special.vue" import special from "@/components/footer/gift/special-effects/special.vue"
var Live
export default { export default {
name: "chat", name: "chat",
components: { components: {
special special
}, },
props: ["specialUrl"], props: {
specialUrl:String,
msgList:Array,
// scrollTop: String,
},
data() { data() {
return { return {
scrollFalg: false, scrollFalg: false,
scrollTop: 0, scrollTop: 0,
msgList: []
} }
}, },
created() { created() {
this.getusertoken()
}, },
methods: { methods: {
gsnickname(val) {
var msgname = val
msgname = msgname.replace(/\d{8,}/g, "*")
msgname = msgname.length > 8 ? msgname.substring(0, 8) + "..." : msgname
return msgname
},
//获取房间token
getusertoken() {
this.$nextTick(() => {
if (uni.getStorageSync("login_ok") == 'success') {
this.$api.getusertoken().then(res => {
var that = this
var roomdid = res.data.data
if (uni.getStorageSync('room_token')) {
roomdid = uni.getStorageSync('room_token')
}
Live = new Finezb.Live(roomdid)
Live.login(function() {
console.log('登录成功', JSON.stringify(Live.getLoginUser()))
uni.setStorageSync("user_account", Live.getLoginUser().account)
})
})
}
})
},
//发送消息
send(val) {
if (!val.sendText) {
return;
}
let data = {
text: val.sendText,
type: val.type,
nickName: uni.getStorageSync("user_name"),
};
if (uni.getStorageSync("watch_type") == 4 && uni.getStorageSync("wxnick") == 0) {
data.nickName = uni.getStorageSync("user_name1")
}
data.extra = {
headUrl: getStorageSync("user_headimg"),
role: 4,
isDirty: 0
};
// var sendlist = this.chatsetinfo.sensitiveWord
// if (this.chatsetinfo.sensitive && sendlist.length > 0) {
// for (var index in sendlist) {
// if (sendlist[index] != "" && sendlist[index].trim() != "" && this.sendText.includes(sendlist[
// index])) {
// data.extra.isDirty = 1
// break;
// }
// }
// }
data.extra = JSON.stringify(data.extra);
let msg = {
type: val.type,
sendTime: new Date().getTime(),
extra: {
headUrl: getStorageSync("user_headimg"),
role: 4
},
sendName: uni.getStorageSync("user_name"),
text: face.replaceEm(this.sendText)
}
if (uni.getStorageSync("watch_type") == 4 && uni.getStorageSync("wxnick") == 0) {
msg.sendName = uni.getStorageSync("user_name1")
}
msg.sendName = msg.sendName.replace(/\d{8,}/g, "*")
msg.sendName = msg.sendName.length > 8 ? msg.sendName.substring(0, 8) + "..." : msg.sendName
this.msgList.push(msg)
this.sendText = '';
// let id = 'msg' + msg.sendTime;
// this.msgBoxToBottom(id);
this.showexpression = false
this.showgift = false
console.log(data);
Live.sendMsg(data, function(ack) {
console.log(ack);
if (ack.code === 200) {
this.scrollTop = 500
}
})
},
} }
} }
</script> </script>
...@@ -133,12 +46,14 @@ ...@@ -133,12 +46,14 @@
.ml-1 { .ml-1 {
margin-left: 10rpx; margin-left: 10rpx;
} }
.font-14{
.font-14 {
font-size: 14rpx; font-size: 14rpx;
} }
.my-2 { .my-2 {
margin: 20rpx 0; margin: 20rpx 0;
padding-top: 10rpx;
} }
.box { .box {
...@@ -149,9 +64,9 @@ ...@@ -149,9 +64,9 @@
.chat { .chat {
box-sizing: border-box; box-sizing: border-box;
height: calc(100vh - 500rpx); height: calc(100vh - 500rpx);
padding: 40rpx; padding-bottom: 100rpx;
letter-spacing: 2rpx; letter-spacing: 2rpx;
margin-left: 30rpx;
.person { .person {
display: flex; display: flex;
align-items: center; align-items: center;
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
<view class="input"> <view class="input">
<u--input style="background-color: #d9d9d9;height: 64rpx;padding-left:20rpx;" type="text" border="none" <u--input style="background-color: #d9d9d9;height: 64rpx;padding-left:20rpx;" type="text" border="none"
shape="circle" placeholder="说点什么吧..." v-model="value" @focus="inputFocus" @blur="inputblur" shape="circle" placeholder="说点什么吧..." v-model="value" @focus="inputFocus" @blur="inputblur"
confirmType="发送" confirm="send"></u--input> confirmType="send" confirm="send">
</u--input> </u--input>
</view> </view>
<u-button style="margin: 0 0 0 20rpx;width: 20%;height: 70%;" text="发送" type="success" v-show="!inputFalg" @click="send"> <!-- <u-button style="margin: 0 0 0 20rpx;width: 20%;height: 70%;" text="发送" type="success" v-show="!inputFalg" touchend.prevent="send">
</u-button> </u-button> -->
<button class="btn_send" text="发送" v-show="!inputFalg" @touchend.prevent="send">
发送</button>
<view class="icon" v-show="inputFalg"> <view class="icon" v-show="inputFalg">
<image v-for="(item,index) in imageList" :key="index+''" :src="item.url" style="width:68rpx" mode="widthFix" <image v-for="(item,index) in imageList" :key="index+''" :src="item.url" style="width:68rpx" mode="widthFix"
@click="iconbtn(item.title)"></image> @click="iconbtn(item.title)"></image>
...@@ -34,6 +36,9 @@ ...@@ -34,6 +36,9 @@
import reward from "./reward/reward.vue"; import reward from "./reward/reward.vue";
import shoplist from "./shopList/shoplist.vue" import shoplist from "./shopList/shoplist.vue"
import msg from "@/components/chat/chat.vue" import msg from "@/components/chat/chat.vue"
export default { export default {
name: "foot", name: "foot",
components: { components: {
...@@ -44,6 +49,9 @@ ...@@ -44,6 +49,9 @@
reward, reward,
shoplist shoplist
}, },
created() {
},
data() { data() {
return { return {
inputFalg: true, inputFalg: true,
...@@ -97,7 +105,7 @@ ...@@ -97,7 +105,7 @@
type: 1, type: 1,
sendText: this.value sendText: this.value
} }
msg.methods.send(obj) this.$emit("sendmsg",obj)
this.value = "" this.value = ""
}, },
// 输入框聚焦事件 // 输入框聚焦事件
...@@ -162,7 +170,16 @@ ...@@ -162,7 +170,16 @@
// width: 294rpx; // width: 294rpx;
flex: 1; flex: 1;
} }
.btn_send{
margin: 0 0 0 20rpx;
width: 20%;
height: 70%;
background-color: #19be6b;
font-size: 24rpx;
text-align: center;
color: #fff;
outline: none;
}
.icon { .icon {
flex: 1; flex: 1;
text-align: right; text-align: right;
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
console.log(res); console.log(res);
if (res.data.code == 200) { if (res.data.code == 200) {
this.nickname = res.data.data this.nickname = res.data.data
uni.setStorageSync('room_account',this.acount_input)
if (localStorage.getItem('wxnick') == 1) { if (localStorage.getItem('wxnick') == 1) {
this.$api.getusertoken('', this.acount_input, true).then(res => { this.$api.getusertoken('', this.acount_input, true).then(res => {
uni.setStorageSync('room_token', res.data.data) uni.setStorageSync('room_token', res.data.data)
......
...@@ -142,15 +142,15 @@ ...@@ -142,15 +142,15 @@
this.is_show = false this.is_show = false
if (res.data.data) { if (res.data.data) {
uni.showToast({ uni.showToast({
title:"登录成功" title: "登录成功"
}) })
setTimeout(()=>{ setTimeout(() => {
location.reload(); location.reload();
},1800); }, 1800);
uni.setStorageSync("user_name", res.data.data.account); uni.setStorageSync("user_name", res.data.data.account);
uni.setStorageSync("user_headimg", res.data.data.avatar); uni.setStorageSync("user_headimg", res.data.data.avatar);
uni.setStorageSync("user_token", res.data.data.token); uni.setStorageSync("user_token", res.data.data.token);
} }
}) })
} }
...@@ -168,7 +168,8 @@ ...@@ -168,7 +168,8 @@
//获取观看方式 //获取观看方式
get_watchtype() { get_watchtype() {
this.$api.roomwatchytype().then(res => { this.$api.roomwatchytype().then(res => {
uni.setStorageSync("watch_type",res.data.data.types + "") console.log(res);
uni.setStorageSync("watch_type", res.data.data.types + "")
this.watch_info = res.data.data this.watch_info = res.data.data
console.log(res.data.data); console.log(res.data.data);
if (this.watch_info.types == 1) { if (this.watch_info.types == 1) {
...@@ -182,20 +183,25 @@ ...@@ -182,20 +183,25 @@
//验证观看方式 //验证观看方式
check_watchtype() { check_watchtype() {
this.$api.roomwatchytypeverify().then(res => { this.$api.roomwatchytypeverify().then(res => {
console.log(res);
if (res.data.code === 200) { if (res.data.code === 200) {
if (this.watch_info.types == 4) { if (this.watch_info.types == 4) {
console.log(this.watch_info) console.log(this.watch_info)
if (!uni.getStorageSync("wxnick") || uni.getStorageSync("wxnick") != this.watch_info.wxNick) { if (!uni.getStorageSync("wxnick") || uni.getStorageSync("wxnick") != this.watch_info
.wxNick) {
this.is_show = true this.is_show = true
this.$api.roomwatchytype().then(res => { uni.setStorageSync("wxnick", this.watch_info.wxNick + '')
var wxis = "0" } else {
String() if (localStorage.getItem('wxnick') == 1) {
if(res.data.data.wxNick===1){ this.$api.getusertoken('', uni.getStorageSync("room_account"), true).then(
wxis="1" res => {
} uni.setStorageSync('room_token', res.data.data)
uni.setStorageSync("wxnick",wxis) })
}) } else {
this.$api.getusertoken(uni.getStorageSync("user_name1"), uni.getStorageSync(
"room_account"), true).then(res => {
uni.setStorageSync('room_token', res.data.data)
})
}
} }
} else { } else {
uni.removeStorageSync("room_token") uni.removeStorageSync("room_token")
......
import App from './App' import App from './App'
import uView from '@/uni_modules/uview-ui' import uView from '@/uni_modules/uview-ui'
import api from "./api/index.js" import api from "./api/index.js"
Vue.use(uView) Vue.use(uView)
// 如此配置即可 // 如此配置即可
uni.$u.config.unit = 'rpx' uni.$u.config.unit = 'rpx'
Vue.prototype.$api = api Vue.prototype.$api = api
......
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
</view> </view>
<tabs @skipComponent="skip"></tabs> <tabs @skipComponent="skip"></tabs>
<!-- 聊天 --> <!-- 聊天 -->
<component :is="currentTabComponent" :specialUrl="special"></component> <component :is="currentTabComponent" :specialUrl="special" :msgList="msgList"></component>
<!-- 底部 --> <!-- 底部 -->
<view class="footer" v-show="currentTabComponent == 'chat'"> <view class="footer" v-show="currentTabComponent == 'chat'">
<foot @specialShow="specialShow"></foot> <foot @specialShow="specialShow" @sendmsg="sendmsg"></foot>
</view> </view>
</view> </view>
</template> </template>
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
import sinatv from "@/components/tabs/sinaTv/sinaTv.vue" import sinatv from "@/components/tabs/sinaTv/sinaTv.vue"
import lives from "@/components/live/live.vue" import lives from "@/components/live/live.vue"
import courseware from "@/components/tabs/courseware/courseware.vue" import courseware from "@/components/tabs/courseware/courseware.vue"
import face from "@/until/face.js"
var Live
export default { export default {
components: { components: {
foot, foot,
...@@ -40,15 +42,21 @@ ...@@ -40,15 +42,21 @@
value: '', value: '',
currentTabComponent: 'chat', currentTabComponent: 'chat',
special: "", special: "",
msgList: [],
scrollTop:0
} }
}, },
created() { created() {
this.getusertoken()
}, },
onshow() { onshow() {
}, },
methods: { methods: {
//触发消息
sendmsg(val) {
this.send(val)
},
skip(value) { skip(value) {
this.currentTabComponent = value this.currentTabComponent = value
}, },
...@@ -59,6 +67,87 @@ ...@@ -59,6 +67,87 @@
_this.special = '' _this.special = ''
}, 1000) }, 1000)
}, },
gsnickname(val) {
var msgname = val
msgname = msgname.replace(/\d{8,}/g, "*")
msgname = msgname.length > 8 ? msgname.substring(0, 8) + "..." : msgname
return msgname
},
//获取房间token
getusertoken() {
this.$nextTick(() => {
if (uni.getStorageSync("login_ok") == 'success') {
this.$api.getusertoken().then(res => {
var that = this
var roomdid = res.data.data
if (uni.getStorageSync('room_token')) {
roomdid = uni.getStorageSync('room_token')
}
Live = new Finezb.Live(roomdid)
Live.login(function() {
console.log('登录成功', JSON.stringify(Live.getLoginUser()))
uni.setStorageSync("user_account", Live.getLoginUser().account)
})
})
}
})
},
//发送消息
send(val) {
if (!val.sendText) {
return;
}
let data = {
text: val.sendText,
type: val.type,
nickName: uni.getStorageSync("user_name"),
};
if (uni.getStorageSync("watch_type") == 4 && uni.getStorageSync("wxnick") == 0) {
data.nickName = uni.getStorageSync("user_name1")
}
data.extra = {
headUrl: uni.getStorageSync("user_headimg"),
role: 4,
isDirty: 0
};
// var sendlist = this.chatsetinfo.sensitiveWord
// if (this.chatsetinfo.sensitive && sendlist.length > 0) {
// for (var index in sendlist) {
// if (sendlist[index] != "" && sendlist[index].trim() != "" && this.sendText.includes(sendlist[
// index])) {
// data.extra.isDirty = 1
// break;
// }
// }
// }
data.extra = JSON.stringify(data.extra);
let msg = {
type: val.type,
sendTime: new Date().getTime(),
extra: {
headUrl: uni.getStorageSync("user_headimg"),
role: 4
},
sendName: uni.getStorageSync("user_name"),
text: face.replaceEm(val.sendText)
}
if (uni.getStorageSync("watch_type") == 4 && uni.getStorageSync("wxnick") == 0) {
msg.sendName = uni.getStorageSync("user_name1")
}
msg.sendName = msg.sendName.replace(/\d{8,}/g, "*")
msg.sendName = msg.sendName.length > 8 ? msg.sendName.substring(0, 8) + "..." : msg.sendName
this.msgList.push(msg)
this.scrollTop = 9999999999
// console.log(that.datalist)
// let id = 'msg' + msg.sendTime;
// this.msgBoxToBottom(id);
Live.sendMsg(data, function(ack) {
console.log(ack);
if (ack.code === 200) {
this.scrollTop = 500
}
})
},
} }
} }
</script> </script>
...@@ -97,7 +186,8 @@ ...@@ -97,7 +186,8 @@
box-shadow: 0 -2rpx 30rpx #dadada; box-shadow: 0 -2rpx 30rpx #dadada;
; ;
} }
#playerback{
#playerback {
width: 100%; width: 100%;
height: 420rpx; height: 420rpx;
z-index: 0; z-index: 0;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment