123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625 |
- const app = getApp();
- const time = require('../../../utils/time.js');
- const ImageType = 'images';
- const TextType = 'text';
- Page({
-
- data: {
- codedata: true,
- frequency:true,
- hiddenName:true,
- toView:'Stop',
- scrollTopVal: 1,
- menu: false,
- Expression: false,
- Sendoutshow: false,
- menushow: true,
- _width: 500,
-
- news: '',
- KeyboardHeight: 366.66666666666674,
- ExpressionImg: '',
-
- inputValue: '',
- photo: '',
- Receive_news: '',
- UserToken: '',
- limit_page: 1,
- myheadurl: '',
- headUrl: '',
- to_id: '',
- form_id: '',
-
- connectemojiO: ['😊', '😅', '😲', '😭', '😂', '😄', '😩', '😞', '😵', '😒', '😍', '😤', '😜', '😝', '😋', '😘', '😚', '😷', '😳', '😃', '😆', '😁', '😢', '😨', '😠', '😣', '😌', '😖', '😔', '😰', '😱', '😪', '😏', '😓'],
- },
- onLoad: function (options) {
- var that = this;
- that.ArrMsg = [];
-
-
-
-
-
- const friend = options;
- that.setData({
- to_id: friend.to_id,
- UserToken: getApp().UserToken(),
- myheadurl: options.myheadurl,
- headUrl: options.headUrl,
- })
- this.SocketSend({
-
-
- type: 'get_history',
- page: this.data.limit_page,
- limit:10
-
- });
- getApp().Imsocket().onSocketMessageCallback = this.onSocketMessageCallback;
-
- },
-
- resetInputStatus: function () {
- var that = this;
- that.setData({
- menu: false,
- Expression: false,
- })
- },
-
- chatInputExtraClickEvent: function () {
- var that = this;
- that.setData({
- menu: !that.data.menu,
- Expression: false,
- })
- },
-
- ExpressionClickEvent: function () {
- var that = this;
- that.setData({
- Expression: !that.data.Expression,
- menu: false,
- })
- },
-
- enlarge: function (e) {
- var that = this;
-
- console.log(e.currentTarget.dataset.src,)
- wx.previewImage({
- current: e.currentTarget.dataset.src,
- urls: [e.currentTarget.dataset.src],
- })
- },
-
- Telephone: function (e) {
- var that = this;
-
- that.setData({
- news: e.detail.value,
- })
- that.Sendoutswitch(e.detail.value);
- },
-
- chooseImageTap: function () {
- var that = this;
- wx.chooseImage({
- count: 1,
- sizeType: ['original', 'compressed'],
- sourceType: ['album', 'camera'],
- success(res) {
- wx.uploadFile({
- url: getApp().globalData.url + 'imsocket/images/chatimg',
- filePath: res.tempFilePaths[0],
- name: 'photo',
- formData: {
- key: wx.getStorageSync('access_key'),
- token: wx.getStorageSync('access_token')
- },
- success: function (res) {
- var data = JSON.parse(res.data);
- console.log(data, '图片上传成功');
- if (data.code == 201) {
- let con = data.data;
-
- console.log(con, 1);
-
- that.SocketSend({ type: ImageType, content: con.img_name });
-
- } else if (data.code == 301) {
- wx.showModal({
- title: '提示',
- content: data.msg,
- showCancel: false,
- })
- }
- }, fail: function (d) {
- }
- })
- console.log(res.tempFilePaths[0]);
-
- that.setData({
- photo: res.tempFilePaths[0],
- menu: false,
- });
- }
- })
- },
-
- retransmission: function () {
- wx.showModal({
- content: '重发该消息?',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- },
-
- SocketSend: function (msg) {
- var that = this;
- msg.form_id = getApp().UserId();
- msg.to_id = that.data.to_id;
-
-
-
- getApp().Imsocket().sendSocketMessage({
- msg: JSON.stringify(msg),
- success: function (res) {
- var current_time = Date.now();
- var _time = time.TimeFormatting(current_time);
-
-
- switch (msg.type) {
- case "alone":
-
- console.log(' 发送文本');
- var obj = {
- content: that.data.news,
- type: 1,
- time: _time,
- isMy: true,
- send: true,
- };
- let _Receive_news = that.data.Receive_news;
- _Receive_news.push(obj);
- console.log(_Receive_news, 'aaa');
- that.setData({
- Receive_news: _Receive_news,
- });
-
- that.scrollbar(_Receive_news);
- break;
- case "images":
- console.log(' 发送图片');
- var obj = {
- content: that.data.photo,
- type: 2,
- time: _time,
- isMy: true,
- send: true,
- };
- let _Receive_img = that.data.Receive_news;
- _Receive_img.push(obj);
- console.log(_Receive_img, '发送图片');
- that.setData({
- Receive_news: _Receive_img,
- });
-
- that.scrollbar(_Receive_img);
- break;
- }
- console.log(res, '获取历史消息成功');
- }, fail: function (res) {
- console.log('获取历史消息失败')
- }
- })
- },
-
- onSocketMessageCallback: function (e) {
- var that = this;
- let data = JSON.parse(e);
-
- console.log(data,'接受消息成功');
- var arrData = data.data.data;
-
- switch (data.type) {
-
- case "get_history":
-
- var _code = data.code;
- if (_code == 201){
-
-
-
-
-
- console.log(arrData);
- for (var index in arrData) {
- if (arrData[index].form_id == getApp().UserToken()) {
- arrData[index].isMy = true;
- } else {
- arrData[index].isMy = false;
- }
- if (arrData[index].type == 2){
- arrData[index].content = data.data.url + arrData[index].content + data.data.stylename;
- }
- if (arrData[index].create_at){
- var _time = time.TimeFormatting(arrData[index].create_at);
- arrData[index].time = _time;
- }
-
- that.ArrMsg.push(arrData[index]);
- }
- for (var index in that.ArrMsg) {
- if(that.ArrMsg[index].hooks){
- that.ArrMsg[index].hooks = '';
- }
- }
-
- let Arrs1 = that.sortarr(that.ArrMsg);
- if(Arrs1[10]){
- Arrs1[10].hooks = 'Stop';
- }
-
- console.log(Arrs1, 111112222);
-
- if (that.data.limit_page == 1) {
- that.setData({
- Receive_news: Arrs1,
- scrollTopVal: that.ArrMsg.length * 999,
- toView: false,
- });
- }else{
- that.setData({
- Receive_news: Arrs1,
- toView: 'Stop'
- });
- }
-
- that.setData({
- toView: false,
- frequency: true,
- hiddenName: true,
- });
- }else{
- that.setData({
- hiddenName: true,
- codedata: false
- });
- }
- break;
- case "alone":
- var arrDatatext = data.data;
- console.log(arrDatatext, "aaasd");
- var current_time = Date.now();
- var _time = time.TimeFormatting(current_time);
-
- var obj = {
- content: arrDatatext.content,
- type: 1,
- time: _time,
- isMy: false,
- };
-
- let _Receive_news = that.data.Receive_news;
- if (typeof _Receive_news == 'object'){
- _Receive_news.push(obj);
- }
- that.setData({
- Receive_news: _Receive_news,
- });
-
- that.scrollbar(_Receive_news);
- break;
- case "images":
- var arrDataimg = data.data;
- console.log(arrDataimg, "接收图片");
- var current_time = Date.now();
- var _time = time.TimeFormatting(current_time);
-
- var obj = {
- content: arrDataimg.content,
- type: 2,
- time: _time,
- isMy: false,
-
- };
- let _Receive_img = that.data.Receive_news;
- _Receive_img.push(obj);
- that.setData({
- Receive_news: _Receive_img,
- });
-
- that.scrollbar(_Receive_img);
- break;
- }
- },
-
- scrollbar: function (data) {
- var that = this;
- if (data) {
- let lengNum = data.length;
-
- that.setData({
- scrollTopVal: lengNum * 999
- })
- console.log(lengNum * 999);
- }
- },
-
- Sendout: function (e) {
- var that = this;
-
- let msg = {
-
-
- type: 'alone',
- content: that.data.news
- };
-
- this.SocketSend(msg);
- that.setData({
- menu: false,
- Expression: false,
- inputValue: '',
- news: '',
- })
- that.Sendoutswitch(that.data.news)
-
- },
-
- sortarr: function (arr) {
- for (let i = 0; i < arr.length - 1; i++) {
- for (let j = 0; j < arr.length - 1 - i; j++) {
- if (arr[j].create_at > arr[j + 1].create_at) {
- var temp = arr[j];
- arr[j] = arr[j + 1];
- arr[j + 1] = temp;
- }
- }
- }
- return arr;
- },
-
- upper: function (e) {
- var that = this;
-
- if (that.data.codedata == true){
- that.setData({
- hiddenName: false,
- })
- }
-
- if (that.data.frequency == true){
-
- that.setData({
- limit_page: that.data.limit_page * 1 + 1,
- frequency:false
- })
- console.log(that.data.limit_page * 1 + 1)
- that.SocketSend({ type: 'get_history', page: that.data.limit_page,limit:10})
-
- }
-
- },
-
- Expression: function (e) {
- var that = this;
- var _news = that.data.news;
- var _text = _news + e.currentTarget.dataset.id;
- console.log(that.data.news)
- console.log(_text)
- that.setData({
- news: _text,
- inputValue: _text,
- })
- that.Sendoutswitch(that.data.news)
- },
-
- bindfocusclick: function (e) {
- var that = this;
- that.setData({
- Expression: false,
- menu: false,
- KeyboardHeight: e.detail.height,
- })
-
- },
-
- Sendoutswitch: function (data) {
- var that = this;
- if (data == '') {
- that.setData({
- menushow: true,
- Sendoutshow: false,
- _width: 500,
- })
- } else {
- that.setData({
- menushow: false,
- Sendoutshow: true,
- _width: 447,
- })
- }
- },
- onUnload: function (e) {
- let url = 'imsocket/imchatmessage/clearunreadmsg';
- let datas = {
- to_id: this.data.to_id, form_id: getApp().UserId()
- };
-
- getApp().postRequest(url, datas, function (res) {
- console.log(res, 11111);
- })
- console.log('销毁页面');
- },
-
-
-
-
-
-
-
-
-
-
- })
|