|
@@ -1,23 +1,326 @@
|
|
|
-// pages/chatRoom/dialogbox.js
|
|
|
+const app = getApp();
|
|
|
+import {
|
|
|
+ ApiModel
|
|
|
+} from "../../utils/api";
|
|
|
+const _Http = new ApiModel();
|
|
|
Page({
|
|
|
|
|
|
/**
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- iosX: false
|
|
|
+ iosX: false,
|
|
|
+ sendText: "", //输入框内容
|
|
|
+ headerTitle: "对话框",
|
|
|
+ socketMsgQueue: [],
|
|
|
+ lineCount: 1, //输入框行数
|
|
|
+ toView: 'item0',
|
|
|
+ keyboardHeight: 0, //键盘高度
|
|
|
+ functionToChoose: "", //功能选项
|
|
|
+ memePopup: false, //表情弹出
|
|
|
+ pageNumber: 1,
|
|
|
+ pageTotal: 1,
|
|
|
+ triggered: false, //下拉状态
|
|
|
+ unreadCount: 0, //对方发送未读信息
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
+ app.initSocket(); //链接websocket 用于测试
|
|
|
+ const that = this;
|
|
|
+ this.setData({
|
|
|
+ timdialogid: options.id,
|
|
|
+ userid: wx.getStorageSync('userData').userid
|
|
|
+ });
|
|
|
+ //详情
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.im.imdialog.imdialog",
|
|
|
+ "method": "query_imdialogMain",
|
|
|
+ "content": {
|
|
|
+ "timdialogid": options.id
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log("详情", res)
|
|
|
+ let title = res.data[0].fimdialogname.split('-');
|
|
|
+ this.setData({
|
|
|
+ headerTitle: title[0]
|
|
|
+ })
|
|
|
+ })
|
|
|
+ //群历史信息
|
|
|
+ this.query_imdialogMessage();
|
|
|
let iosX = (getApp().globalData.safeAreaBottom == 0) ? false : true;
|
|
|
this.setData({
|
|
|
iosX
|
|
|
})
|
|
|
+ //获取表情包
|
|
|
+ this.getMeme()
|
|
|
},
|
|
|
+ //历史信息查询
|
|
|
+ query_imdialogMessage() {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.im.imdialog.imdialog",
|
|
|
+ "method": "query_imdialogMessage",
|
|
|
+ "content": {
|
|
|
+ "pageNumber": this.data.pageNumber,
|
|
|
+ "pageSize": 20,
|
|
|
+ "timdialogid": this.data.timdialogid
|
|
|
+ }
|
|
|
+ }, false).then(res => {
|
|
|
+ if (res.msg != '成功') return wx.showToast({
|
|
|
+ title: res.data,
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ console.log(res)
|
|
|
+ if (res.pageNumber != 1) {
|
|
|
+ let list = res.data;
|
|
|
+ list = list.concat(this.data.socketMsgQueue);
|
|
|
+ this.setData({
|
|
|
+ socketMsgQueue: list,
|
|
|
+ toView: `item${res.data.length - 1}`,
|
|
|
+ triggered: false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.setData({
|
|
|
+ socketMsgQueue: res.data,
|
|
|
+ toView: `item${res.data.length - 1}`,
|
|
|
+ pageTotal: res.pageTotal
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
+ })
|
|
|
+ },
|
|
|
+ scrolltoupper() {
|
|
|
+ if (this.data.pageNumber < this.data.pageTotal) {
|
|
|
+ this.setData({
|
|
|
+ pageNumber: this.data.pageNumber + 1,
|
|
|
+ triggered: true
|
|
|
+ })
|
|
|
+ this.query_imdialogMessage();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //键盘弹出高度
|
|
|
+ keyboardheightchange(e) {
|
|
|
+ let {
|
|
|
+ height
|
|
|
+ } = e.detail;
|
|
|
+ if (this.data.iosX && height > 150) height = height - 17;
|
|
|
+ this.setData({
|
|
|
+ keyboardHeight: height
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 输入框数据绑定 */
|
|
|
+ sendInput(e) {
|
|
|
+ this.setData({
|
|
|
+ sendText: e.detail.value
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 发送信息 */
|
|
|
+ sendMsg(type, data) {
|
|
|
+ const content = this.data.sendText.trim(),
|
|
|
+ that = this;
|
|
|
+ if (type === 'file') {
|
|
|
+ console.log("发送", data)
|
|
|
+ app.globalData.SocketTask.send({
|
|
|
+ data: JSON.stringify({
|
|
|
+ "classname": "message.message",
|
|
|
+ "method": "sendFileMessage",
|
|
|
+ "content": {
|
|
|
+ "timdialogid": this.data.timdialogid,
|
|
|
+ "tattachmentid": data[0].tattachmentid
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ success(res) {}
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ if (content == '') return;
|
|
|
+ app.globalData.SocketTask.send({
|
|
|
+ data: JSON.stringify({
|
|
|
+ "classname": "message.message",
|
|
|
+ "method": "sendTextMessage",
|
|
|
+ "content": {
|
|
|
+ "timdialogid": that.data.timdialogid,
|
|
|
+ "fmessage": content
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ success(res) {
|
|
|
+ that.setData({
|
|
|
+ sendText: ''
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ sendMeme(e) {
|
|
|
+ const {
|
|
|
+ item
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ let data = [];
|
|
|
+ data.push(item);
|
|
|
+ this.sendMsg('file', data)
|
|
|
+ },
|
|
|
+ //功能选择
|
|
|
+ selectionFunction(e) {
|
|
|
+ const {
|
|
|
+ name
|
|
|
+ } = e.target.dataset,
|
|
|
+ that = this;
|
|
|
+ if (name == undefined || name == "") return;
|
|
|
+ console.log(name)
|
|
|
+ if (name == '表情') {
|
|
|
+ let keyboardHeight = (this.data.iosX == true) ? 220 : 200;
|
|
|
+ this.setData({
|
|
|
+ keyboardHeight,
|
|
|
+ memePopup: true
|
|
|
+ })
|
|
|
+ that.toBotton()
|
|
|
+ let time1 = setInterval(() => {
|
|
|
+ this.setData({
|
|
|
+ keyboardHeight
|
|
|
+ })
|
|
|
+ if (this.data.keyboardHeight == keyboardHeight && this.data.memePopup) clearInterval(time1);
|
|
|
+ }, 100);
|
|
|
+ } else if (name == '图片') {
|
|
|
+ this.endMemePopup()
|
|
|
+ wx.chooseMedia({
|
|
|
+ count: 1,
|
|
|
+ mediaType: ['image'],
|
|
|
+ sourceType: ['album', 'camera'],
|
|
|
+ maxDuration: 30,
|
|
|
+ camera: 'back',
|
|
|
+ success(res) {
|
|
|
+ let data = {
|
|
|
+ file: res.tempFiles[0].tempFilePath
|
|
|
+ };
|
|
|
+ that.afterRead(data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ textareaFocus() {
|
|
|
+ this.setData({
|
|
|
+ memePopup: false, //表情弹出
|
|
|
+ })
|
|
|
+ this.toBotton()
|
|
|
+ },
|
|
|
+ //关闭表情
|
|
|
+ endMemePopup(e) {
|
|
|
+ this.setData({
|
|
|
+ keyboardHeight: 0, //键盘高度
|
|
|
+ memePopup: false, //表情弹出
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 文本域行数变化 */
|
|
|
+ linechange(e) {
|
|
|
+ const {
|
|
|
+ lineCount
|
|
|
+ } = e.detail;
|
|
|
+ this.setData({
|
|
|
+ lineCount
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //获取表情包
|
|
|
+ getMeme() {
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "queryDoc",
|
|
|
+ "content": {
|
|
|
+ "getdatafromdbanyway": true,
|
|
|
+ "ownertable": "system",
|
|
|
+ "ownerid": 0
|
|
|
+ }
|
|
|
+ }, false).then(res => {
|
|
|
+ if (res.msg != '成功') return setTimeout(() => {
|
|
|
+ this.getMeme();
|
|
|
+ }, 3000);
|
|
|
+ this.setData({
|
|
|
+ memeList: res.data
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ afterRead({
|
|
|
+ file
|
|
|
+ }) {
|
|
|
+ var that = this
|
|
|
+ var index = file.lastIndexOf(".");
|
|
|
+ var ext = file.substr(index + 1);
|
|
|
+ var timestamp = Date.parse(new Date());
|
|
|
+ wx.getFileSystemManager().readFile({
|
|
|
+ filePath: file,
|
|
|
+ // encoding:'utf-8',
|
|
|
+ success: result => {
|
|
|
+ //返回临时文件路径
|
|
|
+ const fileData = result.data
|
|
|
+ wx.request({
|
|
|
+ url: 'https://www.buwanjia.com/bwj/rest/webclientrest/', //仅为示例,并非真实的接口地址
|
|
|
+ data: {
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "getFileName",
|
|
|
+ "content": {
|
|
|
+ "filename": 'wx' + timestamp,
|
|
|
+ "filetype": ext,
|
|
|
+ "ownertable": "timdialog",
|
|
|
+ "ownerid": that.data.timdialogid,
|
|
|
+ "ftype": "default",
|
|
|
+ "HttpMethod": 'put'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ method: 'post',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json' // 默认值
|
|
|
+ },
|
|
|
+ success(res) {
|
|
|
+ console.log(res)
|
|
|
+ that.uploadFile(res, fileData)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ fail: console.error
|
|
|
+ })
|
|
|
+ },
|
|
|
+ uploadFile(res, data) {
|
|
|
+ var that = this
|
|
|
+ wx.request({
|
|
|
+ url: res.data.data.obsuploadurl,
|
|
|
+ method: "PUT",
|
|
|
+ data: data,
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/octet-stream' // 默认值
|
|
|
+ },
|
|
|
+ success() {
|
|
|
+ wx.request({
|
|
|
+ url: 'https://www.buwanjia.com/bwj/rest/webclientrest/', //仅为示例,并非真实的接口地址
|
|
|
+ data: {
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.system.docManage",
|
|
|
+ "method": "uploadSuccess",
|
|
|
+ "content": {
|
|
|
+ "obsfilename": res.data.data.obsfilename
|
|
|
+ }
|
|
|
+ },
|
|
|
+ method: 'post',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/json' // 默认值
|
|
|
+ },
|
|
|
+ success(res) {
|
|
|
+ let file = res.data.data;
|
|
|
+ console.log(res)
|
|
|
+ that.sendMsg('file', file)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ toBotton() {
|
|
|
+ this.setData({
|
|
|
+ toView: 'bottom'
|
|
|
+ })
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
*/
|
|
@@ -29,7 +332,26 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow: function () {
|
|
|
-
|
|
|
+ var that = this
|
|
|
+ app.globalData.callback = function (res) {
|
|
|
+ //res 接收websocket onMessage事件返回的数据
|
|
|
+ let objs = JSON.parse(res.data),
|
|
|
+ unreadCount = that.data.unreadCount; /* triggered */
|
|
|
+ that.data.socketMsgQueue.push(objs)
|
|
|
+ console.log("发送消息", objs)
|
|
|
+ that.setData({
|
|
|
+ socketMsgQueue: that.data.socketMsgQueue
|
|
|
+ })
|
|
|
+ that.toBotton()
|
|
|
+ /* if (wx.getStorageSync('userData').userid == objs.message.sendfrom.userid) {
|
|
|
+ } else {
|
|
|
+ that.setData({
|
|
|
+ socketMsgQueue: that.data.socketMsgQueue
|
|
|
+ })
|
|
|
+ } */
|
|
|
+ /* ,
|
|
|
+ toView: `item${that.data.socketMsgQueue.length - 1}` */
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -43,7 +365,17 @@ Page({
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
-
|
|
|
+ //重置未读信息
|
|
|
+ _Http.basic({
|
|
|
+ "accesstoken": wx.getStorageSync('userData').token,
|
|
|
+ "classname": "system.im.imdialog.imdialog",
|
|
|
+ "method": "restUnReadMsgCount",
|
|
|
+ "content": {
|
|
|
+ "timdialogid": this.data.timdialogid
|
|
|
+ }
|
|
|
+ }).then(res => {
|
|
|
+ console.log(res)
|
|
|
+ })
|
|
|
},
|
|
|
|
|
|
/**
|