layim.html 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=00000000000000" rel="nofollow">
  301. <img src="/public/upload/2021_8/168_1628847893037_87773.png" tppabs="http://cdn.layui.com/upload/2021_8/168_1628847893037_87773.png">
  302. 公网安备 00000000000000号
  303. </a>
  304. <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">ICP备00000000号</a>
  305. </p>
  306. <div class="site-union">
  307. <p class="site-union-desc">
  308. <span>
  309. </span>
  310. </p>
  311. </div>
  312. </div>
  313. <script>
  314. window.global = {
  315. pageType: 'demo'
  316. ,preview: function(){
  317. var preview = document.getElementById('LAY_preview');
  318. return preview ? preview.innerHTML : '';
  319. }()
  320. };
  321. </script>
  322. <div class="site-tree-mobile layui-hide">
  323. <i class="layui-icon layui-icon-spread-left"></i>
  324. </div>
  325. <div class="site-mobile-shade"></div>
  326. <script src="/public/layui/dist/layui.js" tppabs="http://res.layui.com/layui/dist/layui.js?t=1632428048260" charset="utf-8"></script>
  327. <script>
  328. layui.config({
  329. base: '/public/static/lay/modules/layui/'
  330. ,version: '1632428048260'
  331. }).use('global');
  332. </script>
  333. </div>
  334. <div id="LAY_democodejs">
  335. <script>
  336. layui.config({
  337. base: ''
  338. ,layimPath: '../layim/pro/dist/' //配置 layim.js 所在目录
  339. ,layimAssetsPath: '../layim/pro/dist/layim-assets/' //layim 资源文件所在目录
  340. }).extend({
  341. layim: layui.cache.layimPath + 'layim' //配置 layim 组件所在的路径
  342. }).use('layim', function(layim){ //加载组件
  343. var layim = layui.layim;
  344. //演示自动回复
  345. var autoReplay = [
  346. '您好,我现在有事不在,一会再和您联系。',
  347. '你没发错吧?face[微笑] ',
  348. '这是一段演示消息 face[哈哈] ',
  349. '演示消息 face[心] face[心] face[心] ',
  350. 'face[威武] face[威武] face[威武] face[威武] ',
  351. '<(@ ̄︶ ̄@)>',
  352. '你要和我说话?你真的要和我说话?你确定自己想说吗?你一定非说不可吗?那你说吧,这是自动回复。',
  353. 'face[黑线] 你慢慢说,别急……',
  354. '(*^__^*) face[嘻嘻]'
  355. ];
  356. //基础配置
  357. layim.config({
  358. //初始化接口
  359. init: {
  360. url: '../../www.layui.com/layim/pro/demo/json/getList.json.js'
  361. ,data: {}
  362. }
  363. //查看群员接口
  364. ,members: {
  365. url: '../../www.layui.com/layim/pro/demo/json/getMembers.json.js'
  366. ,data: {}
  367. }
  368. ,uploadImage: {
  369. url: '' //(返回的数据格式见下文)
  370. ,type: '' //默认post
  371. }
  372. ,uploadFile: {
  373. url: '' //(返回的数据格式见下文)
  374. ,type: '' //默认post
  375. }
  376. ,isAudio: true //开启聊天工具栏音频
  377. ,isVideo: true //开启聊天工具栏视频
  378. //扩展工具栏
  379. ,tool: [{
  380. alias: 'code'
  381. ,title: '代码'
  382. ,icon: '&#xe64e;'
  383. }]
  384. //,brief: true //是否简约模式(若开启则不显示主面板)
  385. //,title: 'WebIM' //自定义主面板最小化时的标题
  386. //,right: '100px' //主面板相对浏览器右侧距离
  387. //,minRight: '90px' //聊天面板最小化时相对浏览器右侧距离
  388. ,initSkin: '3.jpg'/*tpa=https://www.layui.com/demo/3.jpg*/ //1-5 设置初始背景
  389. //,skin: ['aaa.jpg'/*tpa=https://www.layui.com/demo/aaa.jpg*/] //新增皮肤
  390. //,isfriend: false //是否开启好友
  391. //,isgroup: false //是否开启群组
  392. //,min: true //是否始终最小化主面板,默认false
  393. //,notice: true //是否开启桌面消息提醒,默认false
  394. //,voice: false //声音提醒,默认开启,声音文件为:default.mp3
  395. ,msgbox: layui.cache.layimAssetsPath + 'html/msgbox.html' //消息盒子页面地址,若不开启,剔除该项即可
  396. ,find: layui.cache.layimAssetsPath + 'html/find.html' //发现页面地址,若不开启,剔除该项即可
  397. ,chatLog: layui.cache.layimAssetsPath + 'html/chatlog.html' //聊天记录页面地址,若不开启,剔除该项即可
  398. });
  399. //监听在线状态的切换事件
  400. layim.on('online', function(status){
  401. layer.msg(status);
  402. });
  403. //监听签名修改
  404. layim.on('sign', function(value){
  405. layer.msg(value);
  406. });
  407. //监听自定义工具栏点击,以添加代码为例
  408. layim.on('tool(code)', function(insert){
  409. layer.prompt({
  410. title: '插入代码 - 工具栏扩展示例'
  411. ,formType: 2
  412. ,shade: 0
  413. }, function(text, index){
  414. layer.close(index);
  415. insert('[pre class=layui-code]' + text + '[/pre]'); //将内容插入到编辑器
  416. });
  417. });
  418. //监听layim建立就绪
  419. layim.on('ready', function(res){
  420. //console.log(res.mine);
  421. layim.msgbox(5); //模拟消息盒子有新消息,实际使用时,一般是动态获得
  422. });
  423. //监听发送消息
  424. layim.on('sendMessage', function(data){
  425. var To = data.to;
  426. //console.log(data);
  427. if(To.type === 'friend'){
  428. layim.setChatStatus('<span style="color:#FF5722;">对方正在输入。。。</span>');
  429. }
  430. //演示自动回复
  431. setTimeout(function(){
  432. var obj = {};
  433. if(To.type === 'group'){
  434. obj = {
  435. username: '模拟群员'+(Math.random()*100|0)
  436. ,avatar: layui.cache.layimAssetsPath + 'images/face/'+ (Math.random()*72|0) + '.gif'
  437. ,id: To.id
  438. ,type: To.type
  439. ,content: autoReplay[Math.random()*9|0]
  440. }
  441. } else {
  442. obj = {
  443. username: To.name
  444. ,avatar: To.avatar
  445. ,id: To.id
  446. ,type: To.type
  447. ,content: autoReplay[Math.random()*9|0]
  448. }
  449. layim.setChatStatus('<span style="color:#FF5722;">在线</span>');
  450. }
  451. layim.getMessage(obj);
  452. }, 1000);
  453. });
  454. //监听查看群员
  455. layim.on('members', function(data){
  456. //console.log(data);
  457. });
  458. //监听聊天窗口的切换
  459. layim.on('chatChange', function(res){
  460. var type = res.data.type;
  461. console.log(res.data.id)
  462. if(type === 'friend'){
  463. //模拟标注好友状态
  464. //layim.setChatStatus('<span style="color:#FF5722;">在线</span>');
  465. } else if(type === 'group'){
  466. //模拟系统消息
  467. layim.getMessage({
  468. system: true
  469. ,id: res.data.id
  470. ,type: "group"
  471. ,content: '模拟群员'+(Math.random()*100|0) + '加入群聊'
  472. });
  473. }
  474. });
  475. //面板外的操作
  476. var $ = layui.jquery, active = {
  477. chat: function(){
  478. //自定义会话
  479. layim.chat({
  480. name: '小测试'
  481. ,type: 'friend'
  482. ,avatar: '../../other/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg'/*tpa=https://tva3.sinaimg.cn/crop.0.0.180.180.180/7f5f6861jw1e8qgp5bmzyj2050050aa8.jpg*/
  483. ,id: 1008612
  484. });
  485. layer.msg('也就是说,此人可以不在好友面板里');
  486. }
  487. ,message: function(){
  488. //制造好友消息
  489. layim.getMessage({
  490. username: "测试1"
  491. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  492. ,id: "100001"
  493. ,type: "friend"
  494. ,content: "嗨,你好!这是一条测试内容。演示标记:"+ new Date().getTime()
  495. ,timestamp: new Date().getTime()
  496. });
  497. }
  498. ,messageAudio: function(){
  499. //接受音频消息
  500. layim.getMessage({
  501. username: "测试1"
  502. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  503. ,id: "100001"
  504. ,type: "friend"
  505. ,content: "audio[http://gddx.sc.chinaz.com/Files/DownLoad/sound1/201510/6473.mp3]"
  506. ,timestamp: new Date().getTime()
  507. });
  508. }
  509. ,messageVideo: function(){
  510. //接受视频消息
  511. layim.getMessage({
  512. username: "测试1"
  513. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  514. ,id: "100001"
  515. ,type: "friend"
  516. ,content: "video[http://www.w3school.com.cn//i/movie.ogg]"
  517. ,timestamp: new Date().getTime()
  518. });
  519. }
  520. ,messageTemp: function(){
  521. //接受临时会话消息
  522. layim.getMessage({
  523. username: "测试X"
  524. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  525. ,id: "198909151014"
  526. ,type: "friend"
  527. ,content: "临时:"+ new Date().getTime()
  528. });
  529. }
  530. ,add: function(){
  531. //实际使用时数据由动态获得
  532. layim.add({
  533. type: 'friend'
  534. ,username: '测试Y'
  535. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  536. ,submit: function(group, remark, index){
  537. layer.msg('好友申请已发送,请等待对方确认', {
  538. icon: 1
  539. ,shade: 0.5
  540. }, function(){
  541. layer.close(index);
  542. });
  543. //通知对方
  544. /*
  545. $.post('/im-applyFriend/', {
  546. uid: info.uid
  547. ,from_group: group
  548. ,remark: remark
  549. }, function(res){
  550. if(res.status != 0){
  551. return layer.msg(res.msg);
  552. }
  553. layer.msg('好友申请已发送,请等待对方确认', {
  554. icon: 1
  555. ,shade: 0.5
  556. }, function(){
  557. layer.close(index);
  558. });
  559. });
  560. */
  561. }
  562. });
  563. }
  564. ,addqun: function(){
  565. layim.add({
  566. type: 'group'
  567. ,username: '测试群组1'
  568. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  569. ,submit: function(group, remark, index){
  570. layer.msg('申请已发送,请等待管理员确认', {
  571. icon: 1
  572. ,shade: 0.5
  573. }, function(){
  574. layer.close(index);
  575. });
  576. //通知对方
  577. /*
  578. $.post('/im-applyGroup/', {
  579. uid: info.uid
  580. ,from_group: group
  581. ,remark: remark
  582. }, function(res){
  583. });
  584. */
  585. }
  586. });
  587. }
  588. ,addFriend: function(){
  589. var user = {
  590. type: 'friend'
  591. ,id: 1234560
  592. ,username: '测试A' //好友昵称,若申请加群,参数为:groupname
  593. ,avatar: '/public/images/fly/avatar/default.png'/*tpa=https://res.layui.com/images/fly/avatar/default.png*/ //头像
  594. ,sign: '测试内容'
  595. }
  596. layim.setFriendGroup({
  597. type: user.type
  598. ,username: user.username
  599. ,avatar: user.avatar
  600. ,group: layim.cache().friend //获取好友列表数据
  601. ,submit: function(group, index){
  602. //一般在此执行Ajax和WS,以通知对方已经同意申请
  603. //……
  604. //同意后,将好友追加到主面板
  605. layim.addList({
  606. type: user.type
  607. ,username: user.username
  608. ,avatar: user.avatar
  609. ,groupid: group //所在的分组id
  610. ,id: user.id //好友ID
  611. ,sign: user.sign //好友签名
  612. });
  613. layer.close(index);
  614. }
  615. });
  616. }
  617. ,addGroup: function(){
  618. layer.msg('已成功把[测试群组33]添加到群组里', {
  619. icon: 1
  620. });
  621. //增加一个群组
  622. layim.addList({
  623. type: 'group'
  624. ,avatar: "/public/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  625. ,groupname: '测试群组33'
  626. ,id: "12333333"
  627. ,members: 0
  628. });
  629. }
  630. ,removeFriend: function(){
  631. layer.msg('已成功删除[测试2]', {
  632. icon: 1
  633. });
  634. //删除一个好友
  635. layim.removeList({
  636. id: 100001222
  637. ,type: 'friend'
  638. });
  639. }
  640. ,removeGroup: function(){
  641. layer.msg('已成功删除[测试群组33]', {
  642. icon: 1
  643. });
  644. //删除一个群组
  645. layim.removeList({
  646. id: 12333333
  647. ,type: 'group'
  648. });
  649. }
  650. //置灰离线好友
  651. ,setGray: function(){
  652. layim.setFriendStatus(168168, 'offline');
  653. layer.msg('已成功将好友[测试4]置灰', {
  654. icon: 1
  655. });
  656. }
  657. //取消好友置灰
  658. ,unGray: function(){
  659. layim.setFriendStatus(168168, 'online');
  660. layer.msg('成功取消好友[测试4]置灰状态', {
  661. icon: 1
  662. });
  663. }
  664. //移动端版本
  665. ,mobile: function(){
  666. var device = layui.device();
  667. var mobileHome = '../../www.layui.com/layim/pro/demo/mobile.html';
  668. if(device.android || device.ios){
  669. return location.href = mobileHome;
  670. }
  671. var index = layer.open({
  672. type: 2
  673. ,title: '移动版演示 (或手机扫右侧二维码预览)'
  674. ,content: mobileHome
  675. ,area: ['375px', '667px']
  676. ,shadeClose: true
  677. ,scrollbar: false
  678. ,shade: 0.8
  679. ,end: function(){
  680. layer.close(index + 2);
  681. }
  682. });
  683. }
  684. };
  685. $('.site-demo-layim').on('click', function(){
  686. var type = $(this).data('type');
  687. active[type] ? active[type].call(this) : '';
  688. });
  689. });
  690. </script>
  691. </div>
  692. </body>
  693. </html>