LAYIM自定義工具欄與自定義發(fā)送消息

1.在layim.config中定義 tool

layim.config({ //初始化接口 init: { url: app+'/imGroupAndUserController/init' ,type: 'get' //默認(rèn)get,一般可不填 ,data: {} } //簡約模式(不顯示主面板) //,brief: true //查看群員接口 ,members: { url: app+'/imGroupAndUserController/getGroupUser' ,type: 'get' //默認(rèn)get,一般可不填 ,data: {} } ,uploadImage: { url: app+'/imChatMessageController/uploadImage' //(返回的數(shù)據(jù)格式見下文) ,type: '' //默認(rèn)post } ,uploadFile: { url: app+'/imChatMessageController/uploadFile' //(返回的數(shù)據(jù)格式見下文) ,type: '' //默認(rèn)post } ,right:"20px" //,skin: ['aaa.jpg'] //新增皮膚 //,isfriend: false //是否開啟好友 //,isgroup: false //是否開啟群組 ,min: true //是否始終最小化主面板(默認(rèn)false) ,initSkin: '1.jpg' //1-5 設(shè)置初始背景 ,title:"即時(shí)通信工具" ,chatLog: app + '/imChatMessageController/chatLog' //聊天記錄地址 ,find: app + '/imGroupController/addGroup'// ,msgbox: app + '/plugins/layui/css/modules/layim/html/msgbox.html' //消息盒子頁面地址,若不開啟,剔除該項(xiàng)即可 ,copyright: true //是否授權(quán) // ,right:'200px' // ,minRight:'200px' //可同時(shí)配置多個(gè)工具欄 ,tool: [{ alias: 'archivesPush' //工具別名 ,title: '推送檔案' //工具名稱 ,icon: '' //工具圖標(biāo),參考圖標(biāo)文檔 }] });


2. 定義監(jiān)聽事件



注意insert() 為在面板添加聊天內(nèi)容 send()表示發(fā)送

insert()傳入?yún)?shù)是可以定義的在layim.js中


2.//監(jiān)聽自定義工具欄點(diǎn)擊,以添加代碼為例layim.on('tool(archivesPush)', function(insert, send, obj){ //事件中的tool為固定字符,而code則為過濾器,對應(yīng)的是工具別名(alias) var content = app + "daportal/daportalBorrowCart/imlist"; var btns = ['推送','關(guān)閉']; var iframeWin ; top.layer.open({ type: 2, title: "推送", area: ["900px", "600px"], shade: 0.5, maxmin: false, content: content, btn: btns, btn1: function (index, layero) { iframeWin = top.window[layero.find('iframe')[0]["name"]]; // console.log(iframeWin) var bb = iframeWin.daportalBorrowCartJs.archivesPush(); for(var i =0;i<bb.length;i++){ var data =bb[i].split('#'); var onclick="openInfo(\'"+data[0]+"\',\'"+data[1]+"\',\'"+data[2] +"\');" var text = "a("+onclick+")["+data[3]+"]"; insert(text); //將內(nèi)容插入到編輯器,主要由insert完成 send(); //自動(dòng)發(fā)送 } //格式text = "a(aad)[下載文件3]";// // insert(text); //將內(nèi)容插入到編輯器,主要由insert完成// send(); //自動(dòng)發(fā)送 // console.log(bb) top.layer.close(index); }, //zIndex : layer.zIndex, btn2: function (index,layero) { top.layer.close(index); }, });

3.發(fā)現(xiàn)問題。

加載聊天歷史的時(shí)候一直去訪問相對路徑。記得在源碼的這個(gè)位置加個(gè)。 (uploadIM為自定義的工具)


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容