qq.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. <template>
  2. <div class="app-container">
  3. <el-tabs type="card" v-model="appKey" @tab-click="qwUserChange">
  4. <el-tab-pane
  5. v-for="item in qwUserList"
  6. :key="item.id"
  7. :label="item.qwUserId"
  8. :name="item.appKey"/>
  9. </el-tabs>
  10. <div class="imui-center qq-lemon-imui" v-show="showQW">
  11. <lemon-imui class="lemon-slot"
  12. :width="windowWidth"
  13. :height="windowHeight"
  14. :user="UserData"
  15. ref="IMUI"
  16. :contact-contextmenu="contactContextmenu"
  17. :theme="theme"
  18. :hide-menu="hideMenu"
  19. :hide-menu-avatar="hideMenuAvatar"
  20. :hide-message-name="hideMessageName"
  21. :hide-message-time="hideMessageTime"
  22. :messageTimeFormat="messageTimeFormat"
  23. @change-menu="handleChangeMenu"
  24. @pull-messages="handlePullMessages"
  25. @change-contact="handleChangeContact"
  26. @change-conversation="handleChangeConversation"
  27. @message-click="handleMessageClick"
  28. @menu-avatar-click="handleMenuAvatarClick"
  29. @pick-image="handleImageClick"
  30. @send="handleSend">
  31. <template #cover>
  32. <div class="cover">
  33. <!-- <i class="lemon-icon-message"></i>
  34. <p>
  35. <b>自定义封面 Lemon</b>IMUI
  36. </p> -->
  37. </div>
  38. </template>
  39. <template #message-title="contact">
  40. <div>
  41. <div style="display:flex;justify-content:space-between">
  42. <span>{{contact.displayName}}</span>
  43. <span style="font-size:12px;">
  44. <el-button size="mini" @click="showDetail">详情</el-button>
  45. <!-- <el-button size="mini" @click="openDrawer('right')">侧边栏</el-button>-->
  46. <!-- <span style="cursor:pointer;" @click="openDrawer('right')">-->
  47. <!-- 右侧 |-->
  48. <!-- </span>-->
  49. <!-- <span style="cursor:pointer;" @click="openDrawer('rightInside')">-->
  50. <!-- 右侧内部 |-->
  51. <!-- </span>-->
  52. <!-- <span style="cursor:pointer;" @click="openDrawer('center')">-->
  53. <!-- 居中-->
  54. <!-- </span>-->
  55. </span>
  56. </div>
  57. <div v-if="contact.isGroup" class="slot-group-menu">
  58. <span>聊天</span>
  59. <span>公告</span>
  60. <span>相册</span>
  61. <span>文件</span>
  62. <span>活动</span>
  63. <span>设置(左键弹出菜单)</span>
  64. </div>
  65. </div>
  66. </template>
  67. <template #sidebar-contact-fixedtop="contact">
  68. <div class="slot-contact-fixedtop">
  69. <el-input size="mini" class="slot-search" placeholder="搜索通讯录" />
  70. </div>
  71. </template>
  72. <template #sidebar-message-fixedtop="message">
  73. <div class="slot-message-fixedtop">
  74. <el-input size="mini" v-model="contactName" class="slot-search" placeholder="搜索" />
  75. </div>
  76. </template>
  77. <template #message-side="contact">
  78. <div v-if="contact.isGroup" class="slot-group">
  79. <div class="slot-group-title">群通知</div>
  80. <div class="slot-group-notice">
  81. 进群请改备注,格式,工作地点-姓名,请大家配合谢谢
  82. </div>
  83. <div class="slot-group-title">群成员</div>
  84. <div class="slot-group-panel">
  85. <input class="slot-search" placeholder="搜索群成员" />
  86. <div class="slot-group-member">
  87. <div class="avatar"><img src="https://p.qqan.com/up/2020-2/2020022821001845128.jpg"></div>
  88. <div class="name">像梦一样自由</div>
  89. </div>
  90. <div class="slot-group-member">
  91. <div class="avatar"><img src="https://p.qqan.com/up/2018-4/15244505348390471.jpg"></div>
  92. <div class="name">野火</div>
  93. </div>
  94. <div class="slot-group-member">
  95. <div class="avatar"><img src="https://p.qqan.com/up/2021-1/20211411391666.jpg"></div>
  96. <div class="name">霸王花</div>
  97. </div>
  98. <div class="slot-group-member">
  99. <div class="avatar"><img src="https://p.qqan.com/up/2021-1/2021113104111220.jpg"></div>
  100. <div class="name">森系Style</div>
  101. </div>
  102. </div>
  103. </div>
  104. </template>
  105. </lemon-imui>
  106. </div>
  107. <el-dialog :visible.sync="dialogVisible" append-to-body width="35%">
  108. <img style="width:100%;height:auto" :src="dialogImageUrl" alt="" />
  109. </el-dialog>
  110. <el-dialog :visible.sync="dialogVideoVisible"
  111. :close-on-click-modal="false"
  112. :destroy-on-close="true"
  113. :width="aplayer.pWidth"
  114. :height="aplayer.height"
  115. @close="dialogVideoVisible=false"
  116. ref="player">
  117. <videoPlayer :width="aplayer.width" :height="aplayer.height" :videoWidth="aplayer.videoWidth" :videoHeight="aplayer.videoHeight" :vid="aplayer.vid" :autoplay="true"
  118. :source="dialogVideoUrl" :cover="dialogVideoCover" ref="player"></videoPlayer>
  119. </el-dialog>
  120. <!-- 用户详情 -->
  121. <el-drawer
  122. :with-header="false"
  123. size="75%"
  124. :title="detail.title" :visible.sync="detail.open">
  125. <userDetail ref="userDetail" />
  126. </el-drawer>
  127. </div>
  128. </template>
  129. <script>
  130. import store from "@/store";
  131. import LemonMessageVoice from "@/components/LemonUI/components/message/voice.vue";
  132. import { getContactsByUser,getConversations,getMessageList,getConversation,sendMsg,getQwUserList} from '@/api/qw/im';
  133. import Conversations from "@/components/LemonUI/database/conversations";
  134. import EmojiData from "@/components/LemonUI/database/emoji";
  135. import '@/components/LemonUI/index.css';
  136. import VideoPlayer from '@/components/VideoPlayer/VueAliplayer.vue'
  137. import UserDetail from "@/views/qw/qwChat/userDetail/index.vue";
  138. let pages = {};
  139. export default {
  140. name: "qqChat",
  141. components: {
  142. VideoPlayer,
  143. UserDetail
  144. },
  145. data() {
  146. return {
  147. contactName:'',
  148. appKey:null,
  149. qwUserId:null,
  150. qwUserList:[],
  151. theme: "default",
  152. IMUI:null,
  153. contactContextmenu: [
  154. {
  155. text: "删除该聊天",
  156. click: (e, instance, hide) => {
  157. const { IMUI, contact } = instance;
  158. IMUI.updateContact({
  159. id: contact.id,
  160. lastContent: null,
  161. });
  162. if (IMUI.currentContactId == contact.id) IMUI.changeContact(null);
  163. hide();
  164. },
  165. },
  166. {
  167. text: "设置备注和标签",
  168. },
  169. {
  170. text: "投诉",
  171. },
  172. {
  173. icon: "lemon-icon-message",
  174. text: "加入黑名单",
  175. render: (h, instance, hide) => {
  176. return (
  177. <div style="display:flex;justify-content:space-between;align-items:center;width:130px">
  178. <span>加入黑名单</span>
  179. <span>
  180. <input type="checkbox" id="switch" />
  181. <label id="switch-label" for="switch">
  182. Toggle
  183. </label>
  184. </span>
  185. </div>
  186. );
  187. },
  188. },
  189. {
  190. click(e, instance, hide) {
  191. const { IMUI, contact } = instance;
  192. IMUI.removeContact(contact.id);
  193. if (IMUI.currentContactId == contact.id) IMUI.changeContact(null);
  194. hide();
  195. },
  196. color: "red",
  197. text: "删除好友",
  198. },
  199. ],
  200. hideMenuAvatar: false,
  201. hideMenu: false,
  202. hideMessageName: false,
  203. hideMessageTime: true,
  204. qwUser:{},
  205. showQW:false,
  206. UserData: {
  207. // id: "1000",
  208. // displayName: "June",
  209. // avatar: "https://p.qqan.com/up/2018-4/15244505348390471.jpg",
  210. },
  211. contactData:null,
  212. conversationData:Conversations,
  213. dialogImageUrl: '',
  214. dialogVisible: false,
  215. dialogVideoVisible:false,
  216. dialogVideoUrl:'',
  217. dialogVideoCover:'',
  218. imageArr:[],
  219. pickUploadImgData:null,
  220. aplayer: {
  221. vid: "bf9b7e4a36d84aea8cee769765fbc28b",
  222. pWidth:"1040px",
  223. width:"1000px",
  224. height:"900px",
  225. videoWidth:"1000px",
  226. videoHeight:"900px"
  227. },
  228. player: null,
  229. roomMembers:[],
  230. roomAdmins:[],
  231. roomInfo:null,
  232. windowWidth: document.documentElement.clientWidth*0.6, //实时屏幕宽度
  233. windowHeight: document.documentElement.clientHeight*0.7, //实时屏幕高度
  234. queryParams: {
  235. pageNum: 1,
  236. pageSize: 10,
  237. conversationId: null,
  238. userId:null
  239. },
  240. sessionId: null,
  241. detail: {
  242. title: '',
  243. open: false
  244. }
  245. };
  246. },
  247. created(){
  248. //获取企微列表
  249. getQwUserList().then(response => {
  250. this.qwUserList = response.data;
  251. if (this.qwUserList.length>0){
  252. this.qwUser = this.qwUserList[0];
  253. this.appKey = this.qwUser.appKey;
  254. this.setQwUserInfo();
  255. this.getConversation();
  256. }else {
  257. this.qwUser={};
  258. }
  259. });
  260. },
  261. mounted() {
  262. this.$watch('appKey', (newValue, oldValue) => {
  263. if (newValue) {
  264. if (!this.qwIm.hasLogin) {
  265. this.initSocket(this.appKey);
  266. console.log("appkey====",this.appKey);
  267. }
  268. }
  269. });
  270. // this.UserData.id=this.qwUser.userId;
  271. // this.UserData.displayName=this.qwUser.qwUserName;
  272. // this.UserData.avatar="https://cos.his.cdwjyyh.com/fs/20241231/22a765a96da247d1b83ea94fef438a41.png";
  273. this.showQW=true;
  274. const contactData1 = {
  275. id: "contact-1",
  276. displayName: "工作协作群",
  277. avatar: "http://upload.qqbodys.com/img/weixin/20170804/ji5qxg1am5ztm.jpg",
  278. index: "[1]群组",
  279. unread: 0,
  280. lastSendTime: 1566047865417,
  281. lastContent: "2",
  282. };
  283. const contactData2 = {
  284. id: "contact-2",
  285. displayName: "自定义内容",
  286. avatar: "http://upload.qqbodys.com/img/weixin/20170807/jibfvfd00npin.jpg",
  287. //index: "Z",
  288. click(next) {
  289. next();
  290. },
  291. renderContainer: () => {
  292. return <h1 style="text-indent:20px">自定义页面</h1>;
  293. },
  294. lastSendTime: 1345209465000,
  295. lastContent: "12312",
  296. unread: 2,
  297. };
  298. const contactData3 = {
  299. id: "contact-3",
  300. displayName: "铁牛",
  301. avatar: "http://upload.qqbodys.com/img/weixin/20170803/jiq4nzrkrnd0e.jpg",
  302. index: "T",
  303. unread: 32,
  304. lastSendTime: 3,
  305. lastContent: "你好123",
  306. };
  307. const IMUI = this.$refs.IMUI;
  308. var conversationData = Conversations.filter(item => item.conversationId<=1);
  309. conversationData.sort((a1, a2) => {
  310. return a2.lastSendTime - a1.lastSendTime;
  311. });
  312. // this.getContacts(); //获取联系人信息
  313. // this.getConversation(); //获取会话信息
  314. IMUI.initMenus([
  315. {
  316. name: "messages",
  317. },
  318. {
  319. name: "contacts",
  320. },
  321. // {
  322. // name: "custom1",
  323. // title: "自定义按钮1",
  324. // unread: 0,
  325. // render: menu => {
  326. // return <i class="lemon-icon-attah" />;
  327. // },
  328. // renderContainer: () => {
  329. // return (
  330. // <div class="article">
  331. // <ul>
  332. // </ul>
  333. // <lemon-contact props={{ }} style="margin:20px"/>
  334. // <lemon-contact props={{ }} style="margin:20px" />
  335. // </div>
  336. // );
  337. // },
  338. // isBottom: true,
  339. // },
  340. // {
  341. // name: "custom2",
  342. // title: "自定义按钮2",
  343. // unread: 0,
  344. // click: () => {
  345. // alert("拦截导航点击事件");
  346. // },
  347. // render: menu => {
  348. // return <i class="lemon-icon-group" />;
  349. // },
  350. // isBottom: true,
  351. // },
  352. ]);
  353. IMUI.initEmoji(EmojiData);
  354. },
  355. methods: {
  356. initSocket(appKey) {
  357. let that=this;
  358. if(!!this.qwIm.socket){
  359. this.qwIm.initSocket(appKey,true);
  360. // 监听socket连接
  361. this.qwIm.socket.onopen = function() {
  362. console.log("socket 连接成功...");
  363. };
  364. this.qwIm.socket.onerror = function() {
  365. console.log("连接错误")
  366. };
  367. // 监听socket消息
  368. const IMUI = this.$refs.IMUI;
  369. this.qwIm.socket.onmessage = function(res) {
  370. var data=JSON.parse(res.data);
  371. console.log("收到服务端内容", JSON.stringify(data));
  372. if(data.cmd=="heartbeat"){ //收到心跳数据不处理
  373. console.log("heartbeat");
  374. }
  375. //接收消息
  376. if(data.cmd=="receiveMsg"){
  377. var msgData=JSON.parse(data.data);
  378. console.log("收到消息:>>>>>",msgData)
  379. if(!IMUI.hasConversation(msgData.toContactId)){ //收到新消息时是最新的会话,添加该会话
  380. let queryParams={conversationId:msgData.toContactId,userId:that.qwUser.userId};
  381. getConversation(queryParams).then(response => {
  382. if(response.code==200){
  383. var conversation=response.data;
  384. IMUI.appendConversation(conversation);
  385. that.appendMessageAction(msgData);
  386. }
  387. });
  388. }else{
  389. that.appendMessageAction(msgData);
  390. let conversation=IMUI.findConversation(msgData.toContactId);
  391. IMUI.topPopConversations(conversation);
  392. let queryParams={conversationId:msgData.toContactId,userId:that.qwUser.id};
  393. // getConversation(queryParams).then(response => {
  394. // if(response.code==200){
  395. // var conversation=response.data;
  396. // var unread=conversation.unread;
  397. // if(!unread){
  398. // conversation.unread=1;
  399. // }else{
  400. // conversation.unread+=1;
  401. // }
  402. // IMUI.topPopConversations(conversation);
  403. //
  404. // }
  405. // });
  406. }
  407. }
  408. };
  409. //监听socket重连
  410. this.qwIm.socket.onreconnect = function(res) {
  411. console.log("socket 断线重连...")
  412. };
  413. }
  414. },
  415. // 切换企微账号
  416. qwUserChange(tab, event){
  417. this.appKey = tab.name;
  418. let index= this.qwUserList.findIndex(item => item.appKey === tab.name);
  419. this.qwUser=this.qwUserList[index];
  420. this.getConversation(); //获取会话信息
  421. this.setQwUserInfo();
  422. this.initSocket(this.qwUser.appKey);
  423. },
  424. setQwUserInfo(){
  425. this.UserData.id=this.qwUser.id;
  426. this.UserData.displayName=this.qwUser.qwUserName;
  427. this.UserData.avatar="https://cos.his.cdwjyyh.com/fs/20241231/22a765a96da247d1b83ea94fef438a41.png";
  428. },
  429. getContacts(){
  430. getContactsByUser(this.qwUser.id).then(response => {
  431. this.contactData = response.data;
  432. this.$refs.IMUI.initContacts(this.contactData);
  433. //console.log("qxj request contactData:"+JSON.stringify(this.contactData));
  434. });
  435. },
  436. getConversation(){
  437. let that=this;
  438. const IMUI = this.$refs.IMUI;
  439. getConversations(this.qwUser.id).then(response => {
  440. this.conversationData = response.data;
  441. IMUI.initConversations(response.data);
  442. var fstConversation=this.conversationData[0];
  443. // console.log("qxj fstConversation:"+JSON.stringify(fstConversation));
  444. if(fstConversation) {
  445. IMUI.changeContact(fstConversation.conversationId);
  446. // setTimeout(() => {
  447. // IMUI.changeContact(1688856679458971);
  448. // }, 500);
  449. }
  450. //console.log("qxj request conversation:"+JSON.stringify(response.data));
  451. });
  452. },
  453. messageTimeFormat(time) {
  454. return this.friendlyDate(time);
  455. },
  456. changeTheme() {
  457. this.theme = this.theme == "default" ? "blue" : "default";
  458. },
  459. scrollToTop() {
  460. document.body.scrollIntoView();
  461. },
  462. openDrawer(position) {
  463. const IMUI = this.$refs.IMUI;
  464. const params = {
  465. position,
  466. render: contact => {
  467. return (
  468. <div style="padding:15px">
  469. <h5>{contact.displayName}</h5>
  470. <span style="cursor:pointer;" on-click={IMUI.closeDrawer}>关闭侧边栏</span>
  471. </div>
  472. );
  473. },
  474. };
  475. // if (position == "center") {
  476. // params.width = "50%";
  477. // params.height = "50%";
  478. // } else if (position == "rightInside") {
  479. // params.height = "90%";
  480. // params.offsetY = "10%";
  481. // }
  482. IMUI.openDrawer(params);
  483. },
  484. handlePullMessages(contact, next,instance) {
  485. const { IMUI } = this.$refs;
  486. let isEnd = false;
  487. getMessageList(this.queryParams).then(response => {
  488. if(response.code==200){
  489. isEnd=response.data.isLastPage;
  490. next(response.data.list, isEnd);
  491. if(!isEnd){
  492. pages[contact.conversationId]++;
  493. this.queryParams.pageNum=pages[contact.conversationId];
  494. this.queryParams.userId = this.qwUser.id
  495. }
  496. }
  497. });
  498. // setTimeout(() => {
  499. // let isEnd = true;
  500. // next(MessagesData[contact.conversationId], isEnd);
  501. // }, 2000);
  502. },
  503. handleChangeConversation(conversation, instance) {
  504. //console.log("qxj ChangeConversation:"+JSON.stringify(conversation));
  505. this.sessionId = conversation.conversationId
  506. if (!pages[conversation.conversationId]){
  507. pages[conversation.conversationId] =1;
  508. }
  509. this.queryParams.pageNum=pages[conversation.conversationId];
  510. this.queryParams.conversationId=conversation.conversationId;
  511. this.queryParams.userId = this.qwUser.id
  512. if(conversation.unread>0){
  513. conversation.unread=0;
  514. instance.updateContact(conversation);
  515. }
  516. // instance.closeDrawer();
  517. },
  518. handleChangeContact(contact, instance) {
  519. console.log("ChangeContact:", contact, instance)
  520. },
  521. //收到消息后添加消息显示
  522. appendMessageAction(msgData){
  523. if(msgData.type=="text" || msgData.type=="image" || msgData.type=="voice"){ //文本 text image video voice
  524. const message = {
  525. id: msgData.id,
  526. status: msgData.status,
  527. type: msgData.type,
  528. sendTime: msgData.sendTime,
  529. content: msgData.content,
  530. params1: "1",
  531. params2: "2",
  532. toContactId: msgData.toContactId,
  533. fromUser: msgData.fromUser,
  534. };
  535. this.appendRemoteMessage(message);
  536. }
  537. else if(msgData.type=="file"){
  538. const message = {
  539. id: msgData.id,
  540. status: msgData.status,
  541. type: msgData.type,
  542. sendTime: msgData.sendTime,
  543. content: msgData.content,
  544. toContactId: msgData.toContactId,
  545. fromUser: msgData.fromUser,
  546. fileName:msgData.fileName,
  547. fileSize:msgData.fileSize
  548. };
  549. this.appendRemoteMessage(message);
  550. }
  551. else{
  552. const message = {
  553. id: msgData.id,
  554. status: msgData.status,
  555. type: msgData.type,
  556. sendTime: msgData.sendTime,
  557. content: msgData.content,
  558. toContactId: msgData.toContactId,
  559. fromUser: msgData.fromUser,
  560. };
  561. this.appendRemoteMessage(message);
  562. }
  563. },
  564. //发送消息
  565. handleSend(message, next, file) {
  566. const IMUI = this.$refs.IMUI;
  567. var params={};
  568. if(message.type=="text"){ //text image voice video
  569. params={"sessionId":message.toContactId,"appKey":this.qwUser.appKey,"content":message.content};
  570. sendMsg(params).then(response => {
  571. if(response.code==200){
  572. var conversation=IMUI.findConversation(message.toContactId);
  573. conversation.lastSendTime=message.sendTime;
  574. conversation.lastContent=message.content;
  575. IMUI.topPopConversations(conversation);
  576. next();
  577. }
  578. });
  579. }
  580. // if(message.type=="image"){
  581. // params={"conversationId":message.toContactId,"deviceId":this.qwUser.deviceId,"userId":this.qwUser.userId,"materialId":this.pickUploadImgData.id};
  582. // sendImageMsg(params).then(response => {
  583. // if(response.code==200){
  584. // var conversation=IMUI.findConversation(message.toContactId);
  585. // conversation.lastSendTime=message.sendTime;
  586. // conversation.lastContent="[图片]";
  587. // IMUI.topPopConversations(conversation);
  588. // next();
  589. // }
  590. // });
  591. // }
  592. // setTimeout(() => {
  593. // next();
  594. // }, 1000);
  595. },
  596. handleMenuAvatarClick() {
  597. console.log("Event:menu-avatar-click");
  598. },
  599. //聊天工具栏点击图片
  600. handleImageClick() {
  601. // this.$refs.material.openMaterial(this.qwUser.deviceId);
  602. console.log("Event:handleImageClick");
  603. },
  604. //选择图片框确定按钮回调
  605. handlePickImageDone(data){
  606. console.log("handlePickImageDone:"+JSON.stringify(data));
  607. this.pickUploadImgData=data;
  608. const IMUI = this.$refs.IMUI;
  609. IMUI._handleRemoteImage(data.url);
  610. },
  611. tooglePlayVideo(data){
  612. this.dialogVideoVisible=true;
  613. this.dialogVideoUrl=data.content;
  614. this.dialogVideoCover=data.url;
  615. const player = this.$refs.player.instance
  616. player && player.play()
  617. },
  618. handleMessageClick(e, key, message, instance) {
  619. // console.log("点击了消息", e, key, message);
  620. //console.log("qxj message:"+JSON.stringify(message));
  621. if(message.type=="image"){
  622. var url=!!message.url?message.url:message.content;
  623. this.handlePicturePreview(url);
  624. }
  625. else if(message.type=="video"){
  626. this.tooglePlayVideo(message);
  627. }
  628. else if(message.type=="file"){
  629. }
  630. if (key == "status") {
  631. instance.updateMessage({
  632. id: message.id,
  633. status: "going",
  634. content: "正在重新发送消息...",
  635. });
  636. setTimeout(() => {
  637. instance.updateMessage({
  638. id: message.id,
  639. status: "succeed",
  640. content: "发送成功",
  641. });
  642. }, 2000);
  643. }
  644. },
  645. changeMenuAvatarVisible() {
  646. this.hideMenuAvatar = !this.hideMenuAvatar;
  647. },
  648. changeMenuVisible() {
  649. this.hideMenu = !this.hideMenu;
  650. },
  651. changeMessageNameVisible() {
  652. this.hideMessageName = !this.hideMessageName;
  653. },
  654. changeMessageTimeVisible() {
  655. this.hideMessageTime = !this.hideMessageTime;
  656. },
  657. removeMessage() {
  658. const { IMUI } = this.$refs;
  659. const messages = IMUI.getCurrentMessages();
  660. const id = messages[messages.length - 1].id;
  661. if (messages.length > 0) {
  662. IMUI.removeMessage(id);
  663. }
  664. },
  665. updateMessage() {
  666. const { IMUI } = this.$refs;
  667. const messages = IMUI.getCurrentMessages();
  668. const message = messages[messages.length - 1];
  669. if (messages.length > 0) {
  670. const update = {
  671. id: message.id,
  672. status: "succeed",
  673. type: "file",
  674. fileName: "被修改成文件了.txt",
  675. fileSize: "4200000",
  676. };
  677. if (message.type == "event") {
  678. update.fromUser = this.user;
  679. }
  680. IMUI.updateMessage(update);
  681. IMUI.messageViewToBottom();
  682. }
  683. },
  684. appendCustomMessage() {
  685. const { IMUI } = this.$refs;
  686. const message = {
  687. id: generateRandId(),
  688. status: "succeed",
  689. type: "voice",
  690. sendTime: getTime(),
  691. content: "语音消息",
  692. params1: "1",
  693. params2: "2",
  694. toContactId: "contact-1",
  695. fromUser: this.user,
  696. };
  697. IMUI.appendMessage(message, true);
  698. },
  699. appendMessage() {
  700. const { IMUI } = this.$refs;
  701. const contact = IMUI.currentContact;
  702. const message = generateMessage("contact-3");
  703. message.fromUser = {
  704. ...message.fromUser,
  705. ...this.user,
  706. };
  707. IMUI.appendMessage(message, true);
  708. console.log("🚀 ~ file: App.vue ~ line 1508 ~ appendMessage ~ message", message)
  709. },
  710. appendEventMessage() {
  711. const { IMUI } = this.$refs;
  712. const message = {
  713. id: generateRandId(),
  714. type: "event",
  715. content: (
  716. <span>
  717. 邀请你加入群聊{" "}
  718. <span
  719. style="color:#333;cursor:pointer"
  720. on-click={() => alert("OK")}
  721. >
  722. 接受
  723. </span>
  724. </span>
  725. ),
  726. toContactId: "contact-3",
  727. sendTime: getTime(),
  728. };
  729. IMUI.appendMessage(message, true);
  730. },
  731. appendRemoteMessage(message) { //从服务端返回的消息
  732. const { IMUI } = this.$refs;
  733. IMUI.appendMessage(message, true);
  734. },
  735. updateContact() {
  736. this.$refs.IMUI.updateContact({
  737. id: "contact-3",
  738. unread: 10,
  739. displayName: generateRandWord(),
  740. lastSendTime: getTime(),
  741. lastContent: "修改昵称为随机字母",
  742. });
  743. },
  744. handleChangeMenu() {
  745. console.log("Event:change-menu");
  746. },
  747. openCustomContainer() {
  748. },
  749. handlePicturePreview(url) {
  750. this.dialogImageUrl = url;
  751. this.dialogVisible = true;
  752. },
  753. // 详情
  754. showDetail() {
  755. console.log("Event:show-userDetail", this.sessionId)
  756. this.detail.open = true
  757. setTimeout(() => {
  758. this.$refs.userDetail.getDetail(this.sessionId);
  759. }, 1);
  760. }
  761. },
  762. };
  763. </script>
  764. <style lang="scss" scoped>
  765. .imui-center{
  766. margin-top:30px;
  767. align-items: center;
  768. justify-content: center;
  769. height: 80vh;
  770. }
  771. .lemon-wrapper{
  772. border:1px solid #ddd;
  773. //height: !important;
  774. }
  775. .lemon-drawer{
  776. border:1px solid #ddd;
  777. border-left:0;
  778. }
  779. .more {
  780. font-size: 12px;
  781. line-height: 24px;
  782. height: 24px;
  783. position: absolute;
  784. top: 14px;
  785. right: 14px;
  786. cursor: pointer;
  787. -webkit-user-select: none;
  788. -moz-user-select: none;
  789. -ms-user-select: none;
  790. user-select: none;
  791. color: #f1f1f1;
  792. display: inline-block;
  793. border-radius: 4px;
  794. background: #111;
  795. padding: 0 8px;
  796. }
  797. /deep/.el-dialog__headerbtn{
  798. top:10px;
  799. }
  800. /deep/.el-dialog:not(.is-fullscreen) {
  801. margin-top: 0 !important;
  802. }
  803. </style>
  804. <style lang="stylus">
  805. .lemon-container__title{
  806. padding-bottom:10px;
  807. }
  808. .slot-group{
  809. width:200px;
  810. }
  811. .slot-group-title{
  812. padding:0 0 10px 0;
  813. }
  814. .slot-group-notice{
  815. padding: 10px 10px;
  816. }
  817. .slot-search{
  818. width:calc(100% - 20px) ;
  819. margin:5px 10px;
  820. padding:3px 0px;
  821. }
  822. .slot-group-member{
  823. display: flex;
  824. padding: 5px 0;
  825. flex:1;
  826. font-size: 14px;
  827. align-items: center;
  828. }
  829. .avatar{
  830. width: 30px;
  831. height: 30px;
  832. line-height: 30px;
  833. margin-right:5px;
  834. }
  835. .img{
  836. vertical-align: middle;
  837. border-style: none;
  838. width: 100%;
  839. height: 100%;
  840. line-height: 30px;
  841. border-radius: 50%;
  842. }
  843. </style>