var app = getApp()
Page({
data: {
globalData:{
StatusBar:'',
Custom:'',
CustomBar:'',
},
newsList:[],
openid:'换日线',
animation:false,
voice:false,
sendout:false,
camera:false,
news:'',
pression:[],
emojis:false,
curra:0,
feature:[
{ src: '/images/album.png', name: '相册' }
],
alcur:false,
vision:'',
time:'',
duration:'',
playing:false,
cuindex:'',
},
fanhui:function(e){
wx.navigateBack({
delta: 1
})
},
cuinbut:function(e){
let that = this
setTimeout(function () {
wx.createSelectorQuery().select('#chat-height').boundingClientRect(function (rect) {
that.setData({
chatheight: parseFloat(rect.height) + parseFloat(that.data.curra),
curr: 'jump' + JSON.stringify(that.data.newsList.length - 1)
})
}).exec()
}, 100)
},
onShow:function(e){
this.setData({
curr: 'jump' + JSON.stringify(this.data.newsList.length-1)
})
},
onLoad: function (options) {
let that = this
wx.getSystemInfo({
success: e => {
that.data.globalData.StatusBar = e.statusBarHeight;
let capsule = wx.getMenuButtonBoundingClientRect();
if (capsule) {
that.data.globalData.Custom = capsule;
that.data.globalData.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
} else {
that.data.globalData.CustomBar = e.statusBarHeight + 50;
}
}
})
that.setData({
openid:options.openid,
globalData: that.data.globalData,
newsList: wx.getStorageSync('newsList'),
pression: app.emoji.pression,
vision: wx.getRecorderManager(),
})
},
getkey:function(e){
this.setData({
curra: e.detail.height,
})
this.cuinbut();
},
getblur:function(e){
this.setData({
curra: 0,
})
this.cuinbut();
},
onReady: function (e) {
this.cuinbut();
},
moninput:function(e){
let that = this
that.cuinbut();
this.setData({
sendout: e.detail.value?true:false,
news: e.detail.value,
})
},
scrollstart:function(e){
this.setData({
emojis: false,
camera: false,
})
this.cuinbut();
},
speak:function(e){
this.setData({
voice: !this.data.voice,
emojis:false,
camera:false,
})
this.cuinbut();
},
emoji:function(e){
this.setData({
emojis: !this.data.emojis,
voice:false,
camera:false,
})
this.cuinbut();
},
camerax:function(e){
this.setData({
camera: !this.data.camera,
voice: false,
emojis: false,
})
this.cuinbut();
},
upload:function(e){
const that = this
wx.chooseImage({
count: 1,
success: function (res) {
const src = res.tempFilePaths[0]
wx.getImageInfo({
src,
success: function (res) {
const { width, height } = res
const newChatList = [...that.data.newsList,{
news_type: 'image',
news_centent: { src, width, height },
openid: that.data.openid,
}]
that.setData({
animation: true,
newsList: newChatList,
})
wx.setStorageSync('newsList', newChatList);
that.cuinbut();
}
})
}
})
},
picture:function(e){
let src = e.currentTarget.dataset.src
wx.previewImage({
current: src,
urls: [src]
})
},
message:function(e){
let that = this
const newChatList = [...that.data.newsList, {
news_type: 'text',
news_centent: that.data.news,
openid: that.data.openid,
}]
that.setData({
animation: true,
newsList: newChatList,
sendout:false,
news: '',
})
wx.setStorageSync('newsList', newChatList);
that.cuinbut();
},
expression:function(e){
let item = e.currentTarget.dataset.item
this.setData({
sendout: true,
news: this.data.news+=item,
})
},
featch:function(e){
let that = this
let index = e.currentTarget.dataset.index
if(index == 0){
that.upload();
}
},
touchdown: function (e) {
let that = this
wx.stopVoice();
that.setData({
alcur: true,
playing: false,
cuindex: ''
})
that.data.duration = 0
that.data.time = setInterval(function () {
that.setData({
duration: that.data.duration+1
})
},1000)
wx.startRecord({
success: function (res) {
const newChatList = [...that.data.newsList, {
news_type: 'voice',
news_centent: { voice: res.tempFilePath, dimen: that.data.duration},
openid: that.data.openid,
}]
that.setData({
newsList: newChatList,
})
wx.setStorageSync('newsList', newChatList);
that.cuinbut();
},
fail:function(e){
that.touchup();
}
})
},
touchup: function (e) {
let that = this
wx.stopRecord()
clearInterval(that.data.time)
that.setData({
alcur:false
})
},
play: function (e) {
let that = this
let voice = e.currentTarget.dataset.voice
var index = e.currentTarget.dataset.index
if (!that.data.playing){
that.setData({
playing:true,
cuindex:index
})
wx.playVoice({
filePath: voice,
success: function () {
that.setData({
playing: false,
cuindex:''
})
},
})
}
},
suspend:function(e){
wx.stopVoice();
this.setData({
playing: false,
cuindex: ''
})
},
})