diff --git a/build/build.js b/build/build.js deleted file mode 100644 index e69de29..0000000 diff --git a/build/env.config.js b/build/env.config.js deleted file mode 100644 index 031de36..0000000 --- a/build/env.config.js +++ /dev/null @@ -1,45 +0,0 @@ -/* - * @Author: ch - * @Date: 2022-05-05 14:40:00 - * @LastEditors: ch - * @LastEditTime: 2022-05-05 18:07:18 - * @Description: 根据git分支生成对应环境的环境变量 - * 开发时如果环境变量换了,可以不用重启服务,直接运行node env.config.js即可 - */ -const fs = require('fs'); -const path = require('path'); -const getRepoInfo = require('git-repo-info'); - -const envConfig = { - dev : { - base_url: 'dev' - }, - test : { - base_url: 'xxx' - }, - reslese : { - base_url: 'xxx' - }, - prod : { - base_url: 'xxx' - } -} -const branch = getRepoInfo().branch; // 调用获取git信息 -let curEnvConfig = {}; -switch (branch){ - case 'msb_test': - curEnvConfig = envConfig.test; - break; - case 'msb_beta': - curEnvConfig = envConfig.release; - break; - case 'msb_prod': - curEnvConfig = envConfig.prod; - break; - default: - curEnvConfig = envConfig.dev; - break; - -} -fs.writeFileSync(`${path.resolve(__dirname, '../common/config')}/env.js`, - `const ENV = ${JSON.stringify(curEnvConfig)}; export default ENV;`); diff --git a/common/dicts/im.js b/common/dicts/im.js new file mode 100644 index 0000000..23505d3 --- /dev/null +++ b/common/dicts/im.js @@ -0,0 +1,35 @@ +/* + * @Author: ch + * @Date: 2022-05-10 20:50:54 + * @LastEditors: ch + * @LastEditTime: 2022-05-13 14:28:29 + * @Description: file content + */ + +const MSG_TYPE = { + // 文本消息 + TXT: 1, + // 语音消息 + VOICE: 2, + // 图片消息 + IMG: 3, + // 视频消息 + VIDEO: 4, + // 自定义类型 + CUSTOM : 6, + // 提示消息 + TIP : 7 +} +const TYPE = { + // 给某个会话发送消息 + SEND_MSG: 20, + // 创建会话 + CRETAE_SEEION: 21, + // 会话心跳 + SESSION_HEART : 22 + +} +export { + // 消息类型 + MSG_TYPE +} \ No newline at end of file diff --git a/common/plugins/emoji.js b/common/plugins/emoji.js new file mode 100644 index 0000000..aa206cf --- /dev/null +++ b/common/plugins/emoji.js @@ -0,0 +1,357 @@ +export const emojiData = [ + //笑脸 + { + type: 'smiley', + name: '笑脸', + list: [ + '😀', + '😁', + '😂', + '🤣', + '😃', + '😄', + '😅', + '😆', + '😉', + '😊', + '😋', + '😎', + '😍', + '😘', + '😗', + '😙', + '😚', + '🙂', + '🤗', + '🤩', + '🤔', + '🤨', + '😐', + '😑', + '😶', + '🙄', + '😏', + '😣', + '😥', + '😮', + '🤐', + '😯', + '😪', + '😫', + '😴', + '😌', + '😛', + '😜', + '😝', + '🤤', + '😒', + '😓', + '😔', + '😕', + '🙃', + '🤑', + '😲', + '🙁', + '😖', + '😞', + '😟', + '😤', + '😢', + '😭', + '😦', + '😧', + '😨', + '😩', + '🤯', + '😬', + '😰', + '😱', + '😳', + '🤪', + '😵', + '😡', + '😠', + '🤬', + '😷', + '🤒', + '🤕', + '🤢', + '🤮', + '🤧', + '😇', + '🤠', + '🤡', + '🤥', + '🤫', + '🤭', + '🧐', + '🤓', + '😈', + '👿', + '👹', + '👺', + '💀', + '👻', + '👽', + '🤖', + '💩', + ], + }, + //手势 + { + type: 'gesture', + name: '手势', + list: [ + '🤲', + '👐', + '🙌', + '👏', + '🤝', + '👍', + '👎', + '👊', + '🤛', + '🤜', + '🤞', + '🤟', + '🤘', + '👌', + '👈', + '👉', + '👆', + '👇', + '🤚', + '🖐', + '🖖', + '👋', + '🤙', + '💪', + // "🖕", + '🙏', + ], + }, + //人物 + { + type: 'people', + name: '人物', + list: [ + '👦', + '👧', + '👨', + '👩', + '👴', + '👵', + '👶', + '👱', + '👮', + '👲', + '👳', + '👷', + '👸', + '💂', + '🎅', + '👰', + '👼', + '💆', + '💇', + '🙍', + '🙎', + '🙅', + '🙆', + '💁', + '🙋', + '🙇', + '🙌', + '🙏', + '👤', + '👥', + '🚶', + '🏃', + '👯', + '💃', + '👫', + '👬', + '👭', + '💏', + '💑', + '👪', + ], + }, + //动物 + { + type: 'animal', + name: '动物', + list: [ + '🙈', + '🙉', + '🙊', + '🐵', + '🐒', + '🐶', + '🐕', + '🐩', + '🐺', + '🐱', + '😺', + '😸', + '😹', + '😻', + '😼', + '😽', + '🙀', + '😿', + '😾', + '🐈', + '🐯', + '🐅', + '🐆', + '🐴', + '🐎', + '🐮', + '🐂', + '🐃', + '🐄', + '🐷', + '🐖', + '🐗', + '🐽', + '🐏', + '🐑', + '🐐', + '🐪', + '🐫', + '🐘', + '🐭', + '🐁', + '🐀', + '🐹', + '🐰', + '🐇', + '🐻', + '🐨', + '🐼', + '🐾', + '🐔', + '🐓', + '🐣', + '🐤', + '🐥', + '🐦', + '🐧', + '🐸', + '🐊', + '🐢', + '🐍', + '🐲', + '🐉', + '🐳', + '🐋', + '🐬', + '🐟', + '🐠', + '🐡', + '🐙', + '🐚', + '🐌', + '🐛', + '🐜', + '🐝', + '🐞', + '🦋', + '🐁', + '🐂', + '🐅', + '🐇', + '🐉', + '🐍', + '🐎', + '🐐', + '🐒', + '🐓', + '🐕', + '🐖', + ], + }, + //其他 + { + type: 'other', + name: '其他', + list: [ + '🌹', + '🍀', + '🍎', + '💰', + '📱', + '🌙', + '🍁', + '🍂', + '🍃', + '🌷', + '💎', + '🔪', + '🔫', + '🏀', + '👄', + '👍', + '🔥', + '💘', + '💓', + '💔', + '💕', + '💖', + '💗', + '💙', + '💚', + '💛', + '💜', + '💝', + '💞', + '💟', + ], + }, +]; +//emoji表情编码 +export function utf16toEntities(str) { + const patt = /[\ud800-\udbff][\udc00-\udfff]/g; // 检测utf16字符正则 + str = str.replace(patt, (char) => { + let H; + let L; + let code; + let s; + + if (char.length === 2) { + H = char.charCodeAt(0); // 取出高位 + L = char.charCodeAt(1); // 取出低位 + code = (H - 0xd800) * 0x400 + 0x10000 + L - 0xdc00; // 转换算法 + s = `&#${code};`; + } else { + s = char; + } + + return s; + }); + + return str; +} +// 表情解码 +export function entitiestoUtf16(strObj) { + const patt = /&#\d+;/g; + const arr = strObj.match(patt) || []; + + let H; + let L; + let code; + + for (let i = 0; i < arr.length; i += 1) { + code = arr[i]; + code = code.replace('&#', '').replace(';', ''); + // 高位 + H = Math.floor((code - 0x10000) / 0x400) + 0xd800; + // 低位 + L = ((code - 0x10000) % 0x400) + 0xdc00; + code = `&#${code};`; + const s = String.fromCharCode(H, L); + strObj = strObj.replace(code, s); + } + return strObj; +} diff --git a/common/utils/websocket.js b/common/utils/websocket.js index 3b77690..6ca0a64 100644 --- a/common/utils/websocket.js +++ b/common/utils/websocket.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-04-25 14:39:19 * @LastEditors: ch - * @LastEditTime: 2022-05-10 19:17:16 + * @LastEditTime: 2022-05-14 18:06:30 * @Description: file content */ import store from "../store"; @@ -12,8 +12,10 @@ const sessionList = (ctx) => { sessionListFlag = true; // 来新消息先查会话列表是否一存在,存在则加消息数。不存在则向会话列表加一个会话框 ctx.sessionVOS.forEach(item => { - item.lastMessage.createTimeStamp = formatDate(item.lastMessage.createTimeStamp, 'mm-dd hh:ii') - item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {}); + if (item.lastMessage) { + item.lastMessage.createTimeStamp = formatDate(item.lastMessage.createTimeStamp, 'mm-dd hh:ii') + item.lastMessage.payload = JSON.parse(item.lastMessage.payload || {}); + } let historyData = store.state.sessionData; let hisIndex = historyData.findIndex(i => i.id === item.id); if(hisIndex >= 0){ @@ -32,14 +34,15 @@ const historyMsg = (ctx) => { if(!ctx.length){ return false; } - ctx.reverse(); + // ctx.reverse(); let newData = store.state.sessionData; const hisIdx = newData.findIndex(i => i.id === ctx[0].sessionId); ctx.forEach(item => { - item.createTimeStamp = formatDate(item.createTimeStamp, 'mm-dd hh:ii') + item.createTimeStamp = formatDate(item.createTimeStamp, 'mm-dd hh:ii'); item.payload = JSON.parse(item.payload) }) - newData[hisIdx].messageList = ctx.concat(newData[hisIdx].messageList); + // newData[hisIdx].messageList = ctx.concat(newData[hisIdx].messageList); + newData[hisIdx].messageList = newData[hisIdx].messageList.concat(ctx); store.commit('SET_SESSION_DATA', newData); } /** @@ -52,7 +55,7 @@ const sessionMsg = (ctx)=>{ return } ctx.payload = JSON.parse(ctx.payload || {}); - ctx.createTimeStamp = formatDate(ctx.createTimeStamp, 'mm-dd hh:ii') + ctx.createTimeStamp = formatDate(ctx.createTimeStamp || new Date(), 'mm-dd hh:ii') let historyData = store.state.sessionData; const hisIndex = historyData.findIndex(i => i.id === ctx.sessionId); // 不在当前会话框则全局消息加1 @@ -62,7 +65,8 @@ const sessionMsg = (ctx)=>{ if(hisIndex >= 0){ // 存在会话往现有会话增加一条消息 const curHisData = historyData[hisIndex]; - curHisData.messageList = [ ctx, ...(curHisData.messageList || [])] + // curHisData.messageList = [ ctx, ...(curHisData.messageList || [])] + curHisData.messageList.push(ctx); //= [ ctx, ...(curHisData.messageList || [])] // 不在当前会话框则会话框消息加1 if(ctx.sessionId !== store.state.sessionMsgId){ curHisData.unreadCount++; @@ -81,43 +85,69 @@ const sessionMsg = (ctx)=>{ }]); } +} +// 用户自己创建了一个会话 +const createSessionMain = (ctx) => { + let historyData = store.state.sessionData; + const curHis = historyData.find(i => i.id === ctx.id); + store.commit('SET_SESSION_MSG_ID', ctx.id); + if (curHis) { + return false; + } + + store.commit('SET_SESSION_DATA',[...historyData, { + ...ctx, + unreadCount : 0, + messageList : [] + }]); + } export let MsbWebSkt = null; - +const token = 'eyJhbGciOiJSUzI1NiJ9.eyJleHAiOjQwNzA4ODAwMDAsImlkIjo5LCJ0aW1lIjoxNjUyNTAwMDUyNTgwfQ.VAMmJTU1FAcw-vD39E_7EHoDaEdKD3A53L-kdcF6Hj_ygs1urs7xfTNsE2Z_Tb5wXRkS_j-qm0pGnRgfD2EQebc8Pcd28-Rp2W8o-CmCw2_uZUZbfUGeFRZ_ihsFCCpsepU7uEkA9L--cI_u3jw9xdNqzkiXYAVeAXsJ2j570bk' export const MsbWebSktInit = () => { return new Promise((resolve, reject) => { MsbWebSkt = uni.connectSocket({ // url : `wss://you-gateway.mashibing.com/ws?client=${store.state.token}`, // url是websocket连接ip - url : `wss://k8s-horse-gateway.mashibing.cn/ws?client=${store.state.token}`, // url是websocket连接ip + // url : `wss://k8s-horse-gateway.mashibing.cn/ws?client=${store.state.token}`, // url是websocket连接ip + url : `ws://192.168.10.93:8090/ws?client=${token}&type=1`, // url是websocket连接ip fail: e => { reject(e) } }); MsbWebSkt.onOpen(() => { - MsbWebSkt.onMessage((res)=>{ + MsbWebSkt.onMessage((res) => { const data = JSON.parse(res.data || {}); - if(data.code === 200){ + if (data.code === 200) { const ctx = data.content; - switch(data.traceType){ + switch (data.traceType) { // 会话列表 - case 1 : + case 1: sessionList(ctx); - break; + break; // 历史消息 - case 2 : - historyMsg(ctx) - - break; + case 2: + case 23: + historyMsg(ctx); + break; + // 创建会话 + case 21: + createSessionMain(ctx); + break; // 会话消息 - case 7 : + case 25: + case 20: + case 7: sessionMsg(ctx) - break; - default : - break; + break; + default: + break; } } }) resolve(); + }); + MsbWebSkt.onClose(() => { + console.log('断开。。。。。'); }) }) diff --git a/main.js b/main.js index 5fc5bfd..3ef12e2 100644 --- a/main.js +++ b/main.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2021-07-26 23:22:16 * @LastEditors: ch - * @LastEditTime: 2022-05-10 19:13:01 + * @LastEditTime: 2022-05-11 15:56:00 * @Description: file content */ import Vue from 'vue'; @@ -29,7 +29,6 @@ if(store.state.token){ }); setInterval(()=>{ - console.log('-----'); MsbWebSkt.send({ data : JSON.stringify({ traceId : createUUID(), @@ -38,7 +37,7 @@ if(store.state.token){ }) }) - }, 5000); + }, 5000000); }) } diff --git a/pages.json b/pages.json index 8a42451..3f9efcb 100644 --- a/pages.json +++ b/pages.json @@ -228,7 +228,7 @@ } }, { - "path": "pages/account/message/chat", + "path": "pages/account/message/chat/index", "aliasPath" : "/messageChat", "style": { "navigationBarTitleText": "马士兵严选" diff --git a/pages/account/index.vue b/pages/account/index.vue index 88aed27..37c7307 100644 --- a/pages/account/index.vue +++ b/pages/account/index.vue @@ -3,7 +3,7 @@ components: { UiCell },: ch * @Date: 2019-08-22 19:41:20 * @LastEditors: ch - * @LastEditTime: 2022-04-29 22:58:50 + * @LastEditTime: 2022-05-13 17:52:27 * @Description: file content -->