Commit c939274d by suwenbiao

聊天

parent 7af70dc1
......@@ -3,128 +3,41 @@
<!-- 特效礼物 -->
<special :url="specialUrl"></special>
<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">
<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="cavasation my-2" v-for="(item,index) in msgList" :key="index">
<view class="person">
<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 class="content">
<span class="text">{{item.content}}</span>
<span class="text">{{item.text}}</span>
</view>
</view>
</scroll-view>
</view>
</scroll-view>
</view>
</template>
<script>
import special from "@/components/footer/gift/special-effects/special.vue"
var Live
export default {
name: "chat",
components: {
special
},
props: ["specialUrl"],
props: {
specialUrl:String,
msgList:Array,
// scrollTop: String,
},
data() {
return {
scrollFalg: false,
scrollTop: 0,
msgList: []
}
},
created() {
this.getusertoken()
},
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>
......@@ -133,12 +46,14 @@
.ml-1 {
margin-left: 10rpx;
}
.font-14{
.font-14 {
font-size: 14rpx;
}
.my-2 {
margin: 20rpx 0;
padding-top: 10rpx;
}
.box {
......@@ -149,9 +64,9 @@
.chat {
box-sizing: border-box;
height: calc(100vh - 500rpx);
padding: 40rpx;
padding-bottom: 100rpx;
letter-spacing: 2rpx;
margin-left: 30rpx;
.person {
display: flex;
align-items: center;
......
......@@ -6,11 +6,13 @@
<view class="input">
<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"
confirmType="发送" confirm="send"></u--input>
confirmType="send" confirm="send">
</u--input>
</view>
<u-button style="margin: 0 0 0 20rpx;width: 20%;height: 70%;" text="发送" type="success" v-show="!inputFalg" @click="send">
</u-button>
<!-- <u-button style="margin: 0 0 0 20rpx;width: 20%;height: 70%;" text="发送" type="success" v-show="!inputFalg" touchend.prevent="send">
</u-button> -->
<button class="btn_send" text="发送" v-show="!inputFalg" @touchend.prevent="send">
发送</button>
<view class="icon" v-show="inputFalg">
<image v-for="(item,index) in imageList" :key="index+''" :src="item.url" style="width:68rpx" mode="widthFix"
@click="iconbtn(item.title)"></image>
......@@ -34,6 +36,9 @@
import reward from "./reward/reward.vue";
import shoplist from "./shopList/shoplist.vue"
import msg from "@/components/chat/chat.vue"
export default {
name: "foot",
components: {
......@@ -44,6 +49,9 @@
reward,
shoplist
},
created() {
},
data() {
return {
inputFalg: true,
......@@ -97,7 +105,7 @@
type: 1,
sendText: this.value
}
msg.methods.send(obj)
this.$emit("sendmsg",obj)
this.value = ""
},
// 输入框聚焦事件
......@@ -162,7 +170,16 @@
// width: 294rpx;
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 {
flex: 1;
text-align: right;
......
......@@ -49,6 +49,7 @@
console.log(res);
if (res.data.code == 200) {
this.nickname = res.data.data
uni.setStorageSync('room_account',this.acount_input)
if (localStorage.getItem('wxnick') == 1) {
this.$api.getusertoken('', this.acount_input, true).then(res => {
uni.setStorageSync('room_token', res.data.data)
......
......@@ -142,15 +142,15 @@
this.is_show = false
if (res.data.data) {
uni.showToast({
title:"登录成功"
title: "登录成功"
})
setTimeout(()=>{
location.reload();
},1800);
setTimeout(() => {
location.reload();
}, 1800);
uni.setStorageSync("user_name", res.data.data.account);
uni.setStorageSync("user_headimg", res.data.data.avatar);
uni.setStorageSync("user_token", res.data.data.token);
}
})
}
......@@ -168,7 +168,8 @@
//获取观看方式
get_watchtype() {
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
console.log(res.data.data);
if (this.watch_info.types == 1) {
......@@ -182,20 +183,25 @@
//验证观看方式
check_watchtype() {
this.$api.roomwatchytypeverify().then(res => {
console.log(res);
if (res.data.code === 200) {
if (this.watch_info.types == 4) {
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.$api.roomwatchytype().then(res => {
var wxis = "0"
String()
if(res.data.data.wxNick===1){
wxis="1"
}
uni.setStorageSync("wxnick",wxis)
})
uni.setStorageSync("wxnick", this.watch_info.wxNick + '')
} else {
if (localStorage.getItem('wxnick') == 1) {
this.$api.getusertoken('', uni.getStorageSync("room_account"), true).then(
res => {
uni.setStorageSync('room_token', res.data.data)
})
} else {
this.$api.getusertoken(uni.getStorageSync("user_name1"), uni.getStorageSync(
"room_account"), true).then(res => {
uni.setStorageSync('room_token', res.data.data)
})
}
}
} else {
uni.removeStorageSync("room_token")
......
import App from './App'
import uView from '@/uni_modules/uview-ui'
import api from "./api/index.js"
Vue.use(uView)
// 如此配置即可
uni.$u.config.unit = 'rpx'
Vue.prototype.$api = api
......
......@@ -7,10 +7,10 @@
</view>
<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'">
<foot @specialShow="specialShow"></foot>
<foot @specialShow="specialShow" @sendmsg="sendmsg"></foot>
</view>
</view>
</template>
......@@ -23,7 +23,9 @@
import sinatv from "@/components/tabs/sinaTv/sinaTv.vue"
import lives from "@/components/live/live.vue"
import courseware from "@/components/tabs/courseware/courseware.vue"
import face from "@/until/face.js"
var Live
export default {
components: {
foot,
......@@ -40,15 +42,21 @@
value: '',
currentTabComponent: 'chat',
special: "",
msgList: [],
scrollTop:0
}
},
created() {
this.getusertoken()
},
onshow() {
},
methods: {
//触发消息
sendmsg(val) {
this.send(val)
},
skip(value) {
this.currentTabComponent = value
},
......@@ -59,6 +67,87 @@
_this.special = ''
}, 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>
......@@ -97,7 +186,8 @@
box-shadow: 0 -2rpx 30rpx #dadada;
;
}
#playerback{
#playerback {
width: 100%;
height: 420rpx;
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