layim.html 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>镜像站@WebIM 网页聊天界面组件 - 在线演示 - Layui</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  10. <meta name="apple-mobile-web-app-capable" content="yes">
  11. <meta name="format-detection" content="telephone=no">
  12. <script>
  13. ;!function(){self!==parent&&(location.href="https://www.baidu.com/")}();
  14. </script>
  15. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="http://res.layui.com/layui/dist/css/layui.css?t=1632428048355" media="all">
  16. <link rel="stylesheet" href="/public/static/css/global.css" tppabs="http://res.layui.com/static/css/global.css?t=1632428048355-19" media="all">
  17. </head>
  18. <body>
  19. <div class="layui-layout layui-layout-admin">
  20. <div class="layui-header header header-demo" autumn>
  21. <div class="layui-fluid">
  22. <a class="logo" href="../index.html" tppabs="http://www.layui.com/">
  23. <img src="/public/static/images/layui/logo.png" tppabs="http://res.layui.com/static/images/layui/logo.png" alt="layui">
  24. </a>
  25. <div class="layui-form layui-hide-xs component" lay-filter="LAY-site-header-component"></div>
  26. <div class="layui-hide-xs site-notice"></div>
  27. <ul class="layui-nav" id="LAY_NAV_TOP">
  28. <li class="layui-nav-item ">
  29. <a href="../doc/index.html" tppabs="http://www.layui.com/doc/">文档</a>
  30. </li>
  31. <li class="layui-nav-item layui-this">
  32. <a href="index.html" tppabs="http://www.layui.com/demo/">示例</a>
  33. </li>
  34. <li class="layui-nav-item">
  35. <a href="javascript:;">
  36. <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>-->
  37. 周边
  38. </a>
  39. <dl class="layui-nav-child layui-nav-child-c">
  40. <dd class="layui-hide-sm layui-show-xs" lay-unselect>
  41. <a href="https://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">问题反馈</a>
  42. <hr>
  43. </dd>
  44. <dd lay-unselect><a href="../alone.html" tppabs="http://www.layui.com/alone.html" target="_blank" lay-unselect>独立组件</a></dd>
  45. <dd lay-unselect><a href="../../fly.layui.com/extend/index.html" target="_blank">扩展组件</a></dd>
  46. </dl>
  47. </li>
  48. <li class="layui-nav-item layui-hide-xs">
  49. <a href="http://gitee.com/sentsin/layui/issues" target="_blank" rel="nofollow">反馈</a>
  50. </li>
  51. </ul>
  52. </div>
  53. </div>
  54. <!-- 让IE8/9支持媒体查询,从而兼容栅格 -->
  55. <!--[if lt IE 9]>
  56. <script src="../../other/html5shiv/r29/html5.min.js" tppabs="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  57. <script src="../../other/respond.js/1.4.2/respond.min.js" tppabs="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
  58. <![endif]-->
  59. <div class="layui-side layui-bg-black">
  60. <div class="layui-side-scroll">
  61. <ul class="layui-nav layui-nav-tree site-demo-nav">
  62. <li class="layui-nav-item layui-nav-itemed">
  63. <a class="javascript:;" href="javascript:;">演示</a>
  64. <dl class="layui-nav-child">
  65. <dd>
  66. <a href="index.html" tppabs="https://www.layui.com/demo/">调试预览</a>
  67. </dd>
  68. </dl>
  69. </li>
  70. <li class="layui-nav-item layui-nav-itemed">
  71. <a class="javascript:;" href="javascript:;">布局</a>
  72. <dl class="layui-nav-child">
  73. <dd class="">
  74. <a href="grid.html" tppabs="https://www.layui.com/demo/grid.html">栅格</a>
  75. </dd>
  76. <dd class="">
  77. <a href="admin.html" tppabs="https://www.layui.com/demo/admin.html">框架</a>
  78. </dd>
  79. </dl>
  80. </li>
  81. <li class="layui-nav-item layui-nav-itemed">
  82. <a class="javascript:;" href="javascript:;">基本元素</a>
  83. <dl class="layui-nav-child">
  84. <dd class="">
  85. <a href="button.html" tppabs="https://www.layui.com/demo/button.html">按钮</a>
  86. </dd>
  87. <dd class="">
  88. <a href="form.html" tppabs="https://www.layui.com/demo/form.html">表单</a>
  89. </dd>
  90. <dd class="">
  91. <a href="nav.html" tppabs="https://www.layui.com/demo/nav.html">导航 / 面包屑</a>
  92. </dd>
  93. <dd class="">
  94. <a href="menu.html" tppabs="https://www.layui.com/demo/menu.html">基础菜单</a>
  95. </dd>
  96. <dd class="">
  97. <a href="tab.html" tppabs="https://www.layui.com/demo/tab.html">选项卡</a>
  98. </dd>
  99. <dd class="">
  100. <a href="progress.html" tppabs="https://www.layui.com/demo/progress.html">进度条</a>
  101. </dd>
  102. <dd class="">
  103. <a href="panel.html" tppabs="https://www.layui.com/demo/panel.html">面板</a>
  104. </dd>
  105. <dd class="">
  106. <a href="badge.html" tppabs="https://www.layui.com/demo/badge.html">徽章</a>
  107. </dd>
  108. <dd class="">
  109. <a href="timeline.html" tppabs="https://www.layui.com/demo/timeline.html">时间线</a>
  110. </dd>
  111. <dd class="">
  112. <a href="table-element.html" tppabs="https://www.layui.com/demo/table-element.html">静态表格</a>
  113. </dd>
  114. <dd class="">
  115. <a href="anim.html" tppabs="https://www.layui.com/demo/anim.html">动画</a>
  116. </dd>
  117. <dd class="">
  118. <a href="auxiliar.html" tppabs="https://www.layui.com/demo/auxiliar.html">辅助元素</a>
  119. </dd>
  120. </dl>
  121. </li>
  122. <li class="layui-nav-item layui-nav-itemed">
  123. <a class="javascript:;" href="javascript:;">组件示例</a>
  124. <dl class="layui-nav-child">
  125. <dd class="">
  126. <a href="layer.html" tppabs="https://www.layui.com/demo/layer.html">
  127. 弹出层
  128. </a>
  129. </dd>
  130. <dd class="">
  131. <a href="laydate.html" tppabs="https://www.layui.com/demo/laydate.html">
  132. 日期与时间选择
  133. </a>
  134. </dd>
  135. <dd class="">
  136. <a href="table.html" tppabs="https://www.layui.com/demo/table.html">
  137. 数据表格
  138. </a>
  139. </dd>
  140. <dd class="">
  141. <a href="laypage.html" tppabs="https://www.layui.com/demo/laypage.html">
  142. 分页
  143. </a>
  144. </dd>
  145. <dd class="">
  146. <a href="dropdown.html" tppabs="https://www.layui.com/demo/dropdown.html">
  147. 下拉菜单
  148. </a>
  149. </dd>
  150. <dd class="">
  151. <a href="upload.html" tppabs="https://www.layui.com/demo/upload.html">
  152. 文件上传
  153. </a>
  154. </dd>
  155. <dd class="">
  156. <a href="transfer.html" tppabs="https://www.layui.com/demo/transfer.html">
  157. 穿梭框
  158. </a>
  159. </dd>
  160. <dd class="">
  161. <a href="tree.html" tppabs="https://www.layui.com/demo/tree.html">
  162. 树形组件
  163. </a>
  164. </dd>
  165. <dd class="">
  166. <a href="colorpicker.html" tppabs="https://www.layui.com/demo/colorpicker.html">
  167. 颜色选择器
  168. </a>
  169. </dd>
  170. <dd class="">
  171. <a href="slider.html" tppabs="https://www.layui.com/demo/slider.html">
  172. 滑块
  173. </a>
  174. </dd>
  175. <dd class="">
  176. <a href="rate.html" tppabs="https://www.layui.com/demo/rate.html">
  177. 评分
  178. </a>
  179. </dd>
  180. <dd class="">
  181. <a href="carousel.html" tppabs="https://www.layui.com/demo/carousel.html">
  182. 轮播
  183. </a>
  184. </dd>
  185. <dd class="">
  186. <a href="laytpl.html" tppabs="https://www.layui.com/demo/laytpl.html">
  187. 模板引擎
  188. </a>
  189. </dd>
  190. <dd class="">
  191. <a href="layedit.html" tppabs="http://www.layui.com/demo/layedit.html">
  192. 富文本编辑器
  193. </a>
  194. </dd>
  195. <dd class="">
  196. <a href="flow.html" tppabs="https://www.layui.com/demo/flow.html">
  197. 流加载
  198. </a>
  199. </dd>
  200. <dd class="">
  201. <a href="util.html" tppabs="https://www.layui.com/demo/util.html">
  202. 工具模块
  203. </a>
  204. </dd>
  205. <dd class="">
  206. <a href="code.html" tppabs="https://www.layui.com/demo/code.html">
  207. 文本行修饰
  208. </a>
  209. </dd>
  210. </dl>
  211. </li>
  212. <li class="layui-nav-item" style="height: 30px; text-align: center"></li>
  213. </ul>
  214. </div>
  215. </div>
  216. <div class="layui-tab layui-tab-brief" lay-filter="demoTitle">
  217. <ul class="layui-tab-title site-demo-title">
  218. <li class="layui-this">预览</li>
  219. <li>查看代码</li>
  220. <li>帮助</li>
  221. </ul>
  222. <div class="layui-body layui-tab-content site-demo site-demo-body">
  223. <div class="layui-tab-item layui-show">
  224. <div class="layui-main">
  225. <div id="LAY_preview">
  226. <blockquote class="layui-elem-quote">
  227. LayIM 是基于 layui 的一款用于开发网页端聊天系统的纯静态 UI 界面解决方案,其包含的只是一套前端源代码素材和相关的模拟示例,没有后端程序及数据库存储等服务。
  228. </blockquote>
  229. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  230. <legend>面板外的操作示例</legend>
  231. </fieldset>
  232. <div class="site-demo-button">
  233. <button class="layui-btn site-demo-layim" data-type="chat">自定义会话</button>
  234. <button class="layui-btn site-demo-layim" data-type="message">接受好友的消息</button>
  235. <button class="layui-btn site-demo-layim" data-type="messageAudio">接受音频消息</button>
  236. <button class="layui-btn site-demo-layim" data-type="messageVideo">接受视频消息</button>
  237. <button class="layui-btn site-demo-layim" data-type="messageTemp">接受临时会话消息</button>
  238. <br>
  239. <button class="layui-btn site-demo-layim" data-type="add">申请好友</button>
  240. <button class="layui-btn site-demo-layim" data-type="addqun">申请加群</button>
  241. <button class="layui-btn site-demo-layim" data-type="addFriend">同意好友</button>
  242. <button class="layui-btn site-demo-layim" data-type="addGroup">增加群组到主面板</button>
  243. <button class="layui-btn site-demo-layim" data-type="removeFriend">删除主面板好友</button>
  244. <button class="layui-btn site-demo-layim" data-type="removeGroup">删除主面板群组</button>
  245. <br>
  246. <button class="layui-btn site-demo-layim" data-type="setGray">置灰离线好友</button>
  247. <button class="layui-btn site-demo-layim" data-type="unGray">取消好友置灰</button>
  248. <button class="layui-btn site-demo-layim" style="background-color: #3FDD86" data-type="mobile">WAP 版演示</button>
  249. </div>
  250. </div>
  251. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  252. <legend>其它</legend>
  253. </fieldset>
  254. <a href="../../www.layui.com/layim/index.html" target="_blank" class="layui-btn layui-btn-warm">获取 LayIM</a>
  255. <blockquote class="layui-elem-quote" style="margin-top: 30px;">
  256. 更多我们未能呈现的示例,还有待您在阅读文档、以及不断使用的过程,去深入挖掘。
  257. </blockquote>
  258. <div style="margin: 15px 0 100px; padding-bottom: 100px;">
  259. <!-- 通用-970*90 -->
  260. <ins class="adsbygoogle"
  261. style="display:inline-block;width:970px;height:90px"
  262. data-ad-client="ca-pub-6111334333458862"
  263. data-ad-slot="6835627838"></ins>
  264. </div>
  265. </div>
  266. </div>
  267. <div class="layui-tab-item">
  268. <textarea class="layui-border-box site-demo-text site-demo-code" id="LAY_democode" spellcheck="false" readonly>
  269. <!DOCTYPE html>
  270. <html>
  271. <head>
  272. <meta charset="utf-8">
  273. <title>Layui</title>
  274. <meta name="renderer" content="webkit">
  275. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  276. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  277. <link rel="stylesheet" href="/public/layui/dist/css/layui.css" tppabs="https://res.layui.com/layui/dist/css/layui.css" media="all">
  278. <!-- 注意:如果你直接复制所有代码到本地,上述css路径需要改成你本地的 -->
  279. </head>
  280. </textarea>
  281. </div>
  282. <div class="layui-tab-item">
  283. <div class="layui-main">
  284. <p>我们更希望您能授权获得 LayIM。扣码防不住,君子不用防。</p>
  285. <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
  286. <legend>相关</legend>
  287. </fieldset>
  288. <a class="layui-btn layui-btn-normal" href="../../fly.layui.com/docs/7.html" target="_blank">LayIM 文档</a>
  289. </div>
  290. </div>
  291. </div>
  292. </div>
  293. <div class="layui-footer footer footer-demo">
  294. <p>
  295. Copyright &copy; 2021 <a href="../index.html" tppabs="http://www.layui.com/">「本站仅为 layui 文档保留的镜像站点,与官方无关」</a> MIT Licensed</p>
  296. <p>
  297. <a href="../about/disclaimer.html" tppabs="http://www.layui.com/about/disclaimer.html" target="_blank">免责声明</a>
  298. <a href="../about/relatedlinks.html" tppabs="http://www.layui.com/about/relatedlinks.html" target="_blank">友链</a>
  299. <a href="javascript:;" site-event="weixinmp">公众号</a>
  300. </p>
  301. <div class="site-union">
  302. <p class="site-union-desc">
  303. <span>
  304. </span>
  305. </p>
  306. </div>
  307. </div>
  308. <script>
  309. window.global = {
  310. pageType: 'demo'
  311. ,preview: function(){
  312. var preview = document.getElementById('LAY_preview');
  313. return preview ? preview.innerHTML : '';
  314. }()
  315. };
  316. </script>
  317. <div class="site-tree-mobile layui-hide">
  318. <i class="layui-icon layui-icon-spread-left"></i>
  319. </div>
  320. <div class="site-mobile-shade"></div>
  321. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048260" charset="utf-8"></script>
  322. <script>
  323. layui.config({
  324. base: '/public/static/lay/modules/layui/'
  325. ,version: '1632428048260'
  326. }).use('global');
  327. </script>
  328. </div>
  329. <div id="LAY_democodejs">
  330. <script>
  331. layui.config({
  332. base: ''
  333. ,layimPath: '../layim/pro/dist/' //配置 layim.js 所在目录
  334. ,layimAssetsPath: '../layim/pro/dist/layim-assets/' //layim 资源文件所在目录
  335. }).extend({
  336. layim: layui.cache.layimPath + 'layim' //配置 layim 组件所在的路径
  337. }).use('layim', function(layim){ //加载组件
  338. var layim = layui.layim;
  339. //演示自动回复
  340. var autoReplay = [
  341. '您好,我现在有事不在,一会再和您联系。',
  342. '你没发错吧?face[微笑] ',
  343. '这是一段演示消息 face[哈哈] ',
  344. '演示消息 face[心] face[心] face[心] ',
  345. 'face[威武] face[威武] face[威武] face[威武] ',
  346. '<(@ ̄︶ ̄@)>',
  347. '你要和我说话?你真的要和我说话?你确定自己想说吗?你一定非说不可吗?那你说吧,这是自动回复。',
  348. 'face[黑线] 你慢慢说,别急……',
  349. '(*^__^*) face[嘻嘻]'
  350. ];
  351. //基础配置
  352. layim.config({
  353. //初始化接口
  354. init: {
  355. url: '../../www.layui.com/layim/pro/demo/json/getList.json.js'
  356. ,data: {}
  357. }
  358. //查看群员接口
  359. ,members: {
  360. url: '../../www.layui.com/layim/pro/demo/json/getMembers.json.js'
  361. ,data: {}
  362. }
  363. ,uploadImage: {
  364. url: '' //(返回的数据格式见下文)
  365. ,type: '' //默认post
  366. }
  367. ,uploadFile: {
  368. url: '' //(返回的数据格式见下文)
  369. ,type: '' //默认post
  370. }
  371. ,isAudio: true //开启聊天工具栏音频
  372. ,isVideo: true //开启聊天工具栏视频
  373. //扩展工具栏
  374. ,tool: [{
  375. alias: 'code'
  376. ,title: '代码'
  377. ,icon: '&#xe64e;'
  378. }]
  379. //,brief: true //是否简约模式(若开启则不显示主面板)
  380. //,title: 'WebIM' //自定义主面板最小化时的标题
  381. //,right: '100px' //主面板相对浏览器右侧距离
  382. //,minRight: '90px' //聊天面板最小化时相对浏览器右侧距离
  383. ,initSkin: '3.jpg'/*tpa=https://www.layui.com/demo/3.jpg*/ //1-5 设置初始背景
  384. //,skin: ['aaa.jpg'/*tpa=https://www.layui.com/demo/aaa.jpg*/] //新增皮肤
  385. //,isfriend: false //是否开启好友
  386. //,isgroup: false //是否开启群组
  387. //,min: true //是否始终最小化主面板,默认false
  388. //,notice: true //是否开启桌面消息提醒,默认false
  389. //,voice: false //声音提醒,默认开启,声音文件为:default.mp3
  390. ,msgbox: layui.cache.layimAssetsPath + 'html/msgbox.html' //消息盒子页面地址,若不开启,剔除该项即可
  391. ,find: layui.cache.layimAssetsPath + 'html/find.html' //发现页面地址,若不开启,剔除该项即可
  392. ,chatLog: layui.cache.layimAssetsPath + 'html/chatlog.html' //聊天记录页面地址,若不开启,剔除该项即可
  393. });
  394. //监听在线状态的切换事件
  395. layim.on('online', function(status){
  396. layer.msg(status);
  397. });
  398. //监听签名修改
  399. layim.on('sign', function(value){
  400. layer.msg(value);
  401. });
  402. //监听自定义工具栏点击,以添加代码为例
  403. layim.on('tool(code)', function(insert){
  404. layer.prompt({
  405. title: '插入代码 - 工具栏扩展示例'
  406. ,formType: 2
  407. ,shade: 0
  408. }, function(text, index){
  409. layer.close(index);
  410. insert('[pre class=layui-code]' + text + '[/pre]'); //将内容插入到编辑器
  411. });
  412. });
  413. //监听layim建立就绪
  414. layim.on('ready', function(res){
  415. //console.log(res.mine);
  416. layim.msgbox(5); //模拟消息盒子有新消息,实际使用时,一般是动态获得
  417. });
  418. //监听发送消息
  419. layim.on('sendMessage', function(data){
  420. var To = data.to;
  421. //console.log(data);
  422. if(To.type === 'friend'){
  423. layim.setChatStatus('<span style="color:#FF5722;">对方正在输入。。。</span>');
  424. }
  425. //演示自动回复
  426. setTimeout(function(){
  427. var obj = {};
  428. if(To.type === 'group'){
  429. obj = {
  430. username: '模拟群员'+(Math.random()*100|0)
  431. ,avatar: layui.cache.layimAssetsPath + 'images/face/'+ (Math.random()*72|0) + '.gif'
  432. ,id: To.id
  433. ,type: To.type
  434. ,content: autoReplay[Math.random()*9|0]
  435. }
  436. } else {
  437. obj = {
  438. username: To.name
  439. ,avatar: To.avatar
  440. ,id: To.id
  441. ,type: To.type
  442. ,content: autoReplay[Math.random()*9|0]
  443. }
  444. layim.setChatStatus('<span style="color:#FF5722;">在线</span>');
  445. }
  446. layim.getMessage(obj);
  447. }, 1000);
  448. });
  449. //监听查看群员
  450. layim.on('members', function(data){
  451. //console.log(data);
  452. });
  453. //监听聊天窗口的切换
  454. layim.on('chatChange', function(res){
  455. var type = res.data.type;
  456. console.log(res.data.id)
  457. if(type === 'friend'){
  458. //模拟标注好友状态
  459. //layim.setChatStatus('<span style="color:#FF5722;">在线</span>');
  460. } else if(type === 'group'){
  461. //模拟系统消息
  462. layim.getMessage({
  463. system: true
  464. ,id: res.data.id
  465. ,type: "group"
  466. ,content: '模拟群员'+(Math.random()*100|0) + '加入群聊'
  467. });
  468. }
  469. });
  470. //面板外的操作
  471. var $ = layui.jquery, active = {
  472. chat: function(){
  473. //自定义会话
  474. layim.chat({
  475. name: '小测试'
  476. ,type: 'friend'
  477. ,avatar: '../../other/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg'/*tpa=https://tva3.sinaimg.cn/crop.0.0.180.180.180/7f5f6861jw1e8qgp5bmzyj2050050aa8.jpg*/
  478. ,id: 1008612
  479. });
  480. layer.msg('也就是说,此人可以不在好友面板里');
  481. }
  482. ,message: function(){
  483. //制造好友消息
  484. layim.getMessage({
  485. username: "测试1"
  486. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  487. ,id: "100001"
  488. ,type: "friend"
  489. ,content: "嗨,你好!这是一条测试内容。演示标记:"+ new Date().getTime()
  490. ,timestamp: new Date().getTime()
  491. });
  492. }
  493. ,messageAudio: function(){
  494. //接受音频消息
  495. layim.getMessage({
  496. username: "测试1"
  497. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  498. ,id: "100001"
  499. ,type: "friend"
  500. ,content: "audio[http://gddx.sc.chinaz.com/Files/DownLoad/sound1/201510/6473.mp3]"
  501. ,timestamp: new Date().getTime()
  502. });
  503. }
  504. ,messageVideo: function(){
  505. //接受视频消息
  506. layim.getMessage({
  507. username: "测试1"
  508. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  509. ,id: "100001"
  510. ,type: "friend"
  511. ,content: "video[http://www.w3school.com.cn//i/movie.ogg]"
  512. ,timestamp: new Date().getTime()
  513. });
  514. }
  515. ,messageTemp: function(){
  516. //接受临时会话消息
  517. layim.getMessage({
  518. username: "测试X"
  519. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  520. ,id: "198909151014"
  521. ,type: "friend"
  522. ,content: "临时:"+ new Date().getTime()
  523. });
  524. }
  525. ,add: function(){
  526. //实际使用时数据由动态获得
  527. layim.add({
  528. type: 'friend'
  529. ,username: '测试Y'
  530. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  531. ,submit: function(group, remark, index){
  532. layer.msg('好友申请已发送,请等待对方确认', {
  533. icon: 1
  534. ,shade: 0.5
  535. }, function(){
  536. layer.close(index);
  537. });
  538. //通知对方
  539. /*
  540. $.post('/im-applyFriend/', {
  541. uid: info.uid
  542. ,from_group: group
  543. ,remark: remark
  544. }, function(res){
  545. if(res.status != 0){
  546. return layer.msg(res.msg);
  547. }
  548. layer.msg('好友申请已发送,请等待对方确认', {
  549. icon: 1
  550. ,shade: 0.5
  551. }, function(){
  552. layer.close(index);
  553. });
  554. });
  555. */
  556. }
  557. });
  558. }
  559. ,addqun: function(){
  560. layim.add({
  561. type: 'group'
  562. ,username: '测试群组1'
  563. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  564. ,submit: function(group, remark, index){
  565. layer.msg('申请已发送,请等待管理员确认', {
  566. icon: 1
  567. ,shade: 0.5
  568. }, function(){
  569. layer.close(index);
  570. });
  571. //通知对方
  572. /*
  573. $.post('/im-applyGroup/', {
  574. uid: info.uid
  575. ,from_group: group
  576. ,remark: remark
  577. }, function(res){
  578. });
  579. */
  580. }
  581. });
  582. }
  583. ,addFriend: function(){
  584. var user = {
  585. type: 'friend'
  586. ,id: 1234560
  587. ,username: '测试A' //好友昵称,若申请加群,参数为:groupname
  588. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/ //头像
  589. ,sign: '测试内容'
  590. }
  591. layim.setFriendGroup({
  592. type: user.type
  593. ,username: user.username
  594. ,avatar: user.avatar
  595. ,group: layim.cache().friend //获取好友列表数据
  596. ,submit: function(group, index){
  597. //一般在此执行Ajax和WS,以通知对方已经同意申请
  598. //……
  599. //同意后,将好友追加到主面板
  600. layim.addList({
  601. type: user.type
  602. ,username: user.username
  603. ,avatar: user.avatar
  604. ,groupid: group //所在的分组id
  605. ,id: user.id //好友ID
  606. ,sign: user.sign //好友签名
  607. });
  608. layer.close(index);
  609. }
  610. });
  611. }
  612. ,addGroup: function(){
  613. layer.msg('已成功把[测试群组33]添加到群组里', {
  614. icon: 1
  615. });
  616. //增加一个群组
  617. layim.addList({
  618. type: 'group'
  619. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  620. ,groupname: '测试群组33'
  621. ,id: "12333333"
  622. ,members: 0
  623. });
  624. }
  625. ,removeFriend: function(){
  626. layer.msg('已成功删除[测试2]', {
  627. icon: 1
  628. });
  629. //删除一个好友
  630. layim.removeList({
  631. id: 100001222
  632. ,type: 'friend'
  633. });
  634. }
  635. ,removeGroup: function(){
  636. layer.msg('已成功删除[测试群组33]', {
  637. icon: 1
  638. });
  639. //删除一个群组
  640. layim.removeList({
  641. id: 12333333
  642. ,type: 'group'
  643. });
  644. }
  645. //置灰离线好友
  646. ,setGray: function(){
  647. layim.setFriendStatus(168168, 'offline');
  648. layer.msg('已成功将好友[测试4]置灰', {
  649. icon: 1
  650. });
  651. }
  652. //取消好友置灰
  653. ,unGray: function(){
  654. layim.setFriendStatus(168168, 'online');
  655. layer.msg('成功取消好友[测试4]置灰状态', {
  656. icon: 1
  657. });
  658. }
  659. //移动端版本
  660. ,mobile: function(){
  661. var device = layui.device();
  662. var mobileHome = '../../www.layui.com/layim/pro/demo/mobile.html';
  663. if(device.android || device.ios){
  664. return location.href = mobileHome;
  665. }
  666. var index = layer.open({
  667. type: 2
  668. ,title: '移动版演示 (或手机扫右侧二维码预览)'
  669. ,content: mobileHome
  670. ,area: ['375px', '667px']
  671. ,shadeClose: true
  672. ,scrollbar: false
  673. ,shade: 0.8
  674. ,end: function(){
  675. layer.close(index + 2);
  676. }
  677. });
  678. }
  679. };
  680. $('.site-demo-layim').on('click', function(){
  681. var type = $(this).data('type');
  682. active[type] ? active[type].call(this) : '';
  683. });
  684. });
  685. </script>
  686. </div>
  687. </body>
  688. </html>