mobile.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
  6. <meta name="format-detection" content="telephone=no">
  7. <title>镜像站@WAP 版演示</title>
  8. <link rel="stylesheet" href="../../../../res.layui.com/layui/dist/css/layui.css" tppabs="https://res.layui.com/layui/dist/css/layui.css?v=3.9.8">
  9. </head>
  10. <body>
  11. <script src="../../../../res.layui.com/layui/dist/layui.js" tppabs="https://res.layui.com/layui/dist/layui.js?v=3.9.81"></script>
  12. <script>
  13. layui.config({
  14. base: '../dist/layim-assets/lib/'
  15. ,layimAssetsPath: '../dist/layim-assets/' //layim 资源文件所在目录
  16. ,version: true
  17. }).extend({
  18. 'layer-mobile': 'layer-mobile'
  19. ,'zepto': 'zepto'
  20. ,'upload-mobile': 'upload-mobile'
  21. ,'layim-mobile': 'layim-mobile'
  22. }).use('layim-mobile', function(){
  23. var layim = layui['layim-mobile'] //WebIM
  24. ,layer = layui['layer-mobile']; //弹层
  25. //提示层
  26. layer.msg = function(content){
  27. return layer.open({
  28. content: content
  29. ,skin: 'msg'
  30. ,time: 2 //2秒后自动关闭
  31. });
  32. };
  33. //演示自动回复
  34. var autoReplay = [
  35. '您好,我现在有事不在,一会再和您联系。',
  36. '你没发错吧?face[微笑] ',
  37. '这是一段演示消息 face[哈哈] ',
  38. '演示消息 face[心] face[心] face[心] ',
  39. 'face[威武] face[威武] face[威武] face[威武] ',
  40. '<(@ ̄︶ ̄@)>',
  41. '你要和我说话?你真的要和我说话?你确定自己想说吗?你一定非说不可吗?那你说吧,这是自动回复。',
  42. 'face[黑线] 你慢慢说,别急……',
  43. '(*^__^*) face[嘻嘻]'
  44. ];
  45. layim.config({
  46. //上传图片接口
  47. uploadImage: {
  48. url: '/upload/image' //(返回的数据格式见下文)
  49. ,type: '' //默认post
  50. }
  51. //上传文件接口
  52. ,uploadFile: {
  53. url: '/upload/file' //(返回的数据格式见下文)
  54. ,type: '' //默认post
  55. }
  56. //,brief: true
  57. ,init: {
  58. //我的信息
  59. mine: {
  60. "username": "测试" //我的昵称
  61. ,"id": 123 //我的ID
  62. ,"avatar": "../../../../other/crop.0.0.300.300.180/006Iv8Wjly8ff7ghbigcij308c08ct8i.jpg"/*tpa=http://tvax1.sinaimg.cn/crop.0.0.300.300.180/006Iv8Wjly8ff7ghbigcij308c08ct8i.jpg*/ //我的头像
  63. ,"sign": "测试内容"
  64. }
  65. //我的好友列表
  66. ,"friend": [{
  67. "groupname": "测试分组一"
  68. ,"id": 0
  69. ,"list": [{
  70. "username": "测试1"
  71. ,"id": "100001"
  72. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  73. ,"sign": "测试内容1"
  74. ,"status": "online"
  75. },{
  76. "username": "测试2"
  77. ,"id": "100001222"
  78. ,"sign": "测试内容2"
  79. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  80. },{
  81. "username": "测试3"
  82. ,"id": "10034001"
  83. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  84. ,"sign": ""
  85. },{
  86. "username": "测试4"
  87. ,"id": "168168"
  88. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  89. ,"sign": "测试内容4"
  90. },{
  91. "username": "测试5"
  92. ,"id": "666666"
  93. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  94. ,"sign": "测试内容5"
  95. }]
  96. },{
  97. "groupname": "测试分组二"
  98. ,"id": 1
  99. ,"list": [{
  100. "username": "测试6"
  101. ,"id": "121286"
  102. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  103. ,"sign": "测试内容6"
  104. },{
  105. "username": "测试7"
  106. ,"id": "108101"
  107. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  108. ,"sign": "微电商达人"
  109. },{
  110. "username": "测试8"
  111. ,"id": "12123454"
  112. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  113. ,"sign": "测试内容8"
  114. },{
  115. "username": "测试9"
  116. ,"id": "102101"
  117. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  118. ,"sign": ""
  119. },{
  120. "username": "测试10"
  121. ,"id": "3435343"
  122. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  123. ,"sign": ""
  124. }]
  125. },{
  126. "groupname": "测试分组三"
  127. ,"id": 2
  128. ,"list": [{
  129. "username": "测试11"
  130. ,"id": "76543"
  131. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  132. ,"sign": "测试内容11"
  133. },{
  134. "username": "测试12"
  135. ,"id": "4803920"
  136. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  137. ,"sign": "测试内容12"
  138. }]
  139. }]
  140. ,"group": [{
  141. "groupname": "测试群组一"
  142. ,"id": "101"
  143. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  144. },{
  145. "groupname": "测试群组二"
  146. ,"id": "102"
  147. ,"avatar": "../../../../res.layui.com/images/fly/avatar/default.png"/*tpa=https://res.layui.com/images/fly/avatar/default.png*/
  148. }]
  149. }
  150. //扩展聊天面板工具栏
  151. ,tool: [{
  152. alias: 'code'
  153. ,title: '代码'
  154. ,iconUnicode: '&#xe64e;'
  155. }]
  156. //扩展更多列表
  157. ,moreList: [{
  158. alias: 'find'
  159. ,title: '发现'
  160. ,iconUnicode: '&#xe628;' //图标字体的unicode,可不填
  161. ,iconClass: '' //图标字体的class类名
  162. },{
  163. alias: 'share'
  164. ,title: '分享与邀请'
  165. ,iconUnicode: '&#xe641;' //图标字体的unicode,可不填
  166. ,iconClass: '' //图标字体的class类名
  167. }]
  168. //,tabIndex: 1 //用户设定初始打开的Tab项下标
  169. //,isNewFriend: false //是否开启“新的朋友”
  170. ,isgroup: true //是否开启“群聊”
  171. //,chatTitleColor: '#c00' //顶部Bar颜色
  172. //,title: 'LayIM' //应用名,默认:我的IM
  173. });
  174. //创建一个会话
  175. /*
  176. layim.chat({
  177. id: 111111
  178. ,name: '许闲心'
  179. ,type: 'kefu' //friend、group等字符,如果是group,则创建的是群聊
  180. ,avatar: 'http://tp1.sinaimg.cn/1571889140/180/40030060651/1'
  181. });
  182. */
  183. //监听点击“新的朋友”
  184. layim.on('newFriend', function(){
  185. layim.panel({
  186. title: '新的朋友' //标题
  187. ,tpl: '<div style="padding: 10px;">自定义模版,{{d.data.test}}</div>' //模版
  188. ,data: { //数据
  189. test: '么么哒'
  190. }
  191. });
  192. });
  193. //查看聊天信息
  194. layim.on('detail', function(data){
  195. //console.log(data); //获取当前会话对象
  196. layim.panel({
  197. title: data.name + ' 聊天信息' //标题
  198. ,tpl: '<div style="padding: 10px;">自定义模版</div>' //模版
  199. ,data: { //数据
  200. test: '么么哒'
  201. }
  202. });
  203. });
  204. //监听点击更多列表
  205. layim.on('moreList', function(obj){
  206. switch(obj.alias){
  207. case 'find':
  208. layer.msg('自定义发现动作');
  209. //模拟标记“发现新动态”为已读
  210. layim.showNew('More', false);
  211. layim.showNew('find', false);
  212. break;
  213. case 'share':
  214. layim.panel({
  215. title: '邀请好友' //标题
  216. ,tpl: '<div style="padding: 10px;">自定义模版,{{d.data.test}}</div>' //模版
  217. ,data: { //数据
  218. test: '么么哒'
  219. }
  220. });
  221. break;
  222. }
  223. });
  224. //监听返回
  225. layim.on('back', function(){
  226. //如果你只是弹出一个会话界面(不显示主面板),那么可通过监听返回,跳转到上一页面,如:history.back();
  227. });
  228. //监听自定义工具栏点击,以添加代码为例
  229. layim.on('tool(code)', function(insert, send){
  230. insert('[pre class=layui-code]123[/pre]'); //将内容插入到编辑器
  231. send();
  232. });
  233. //监听发送消息
  234. layim.on('sendMessage', function(data){
  235. var To = data.to;
  236. //console.log(data);
  237. //演示自动回复
  238. setTimeout(function(){
  239. var obj = {};
  240. if(To.type === 'group'){
  241. obj = {
  242. username: '模拟群员'+(Math.random()*100|0)
  243. ,avatar: layui.cache.layimAssetsPath + 'images/face/'+ (Math.random()*72|0) + '.gif'
  244. ,id: To.id
  245. ,type: 'group'
  246. ,content: autoReplay[Math.random()*9|0]
  247. }
  248. } else {
  249. obj = {
  250. username: To.name
  251. ,avatar: To.avatar
  252. ,id: To.id
  253. ,type: To.type
  254. ,content: autoReplay[Math.random()*9|0]
  255. }
  256. }
  257. layim.getMessage(obj);
  258. }, 3000);
  259. });
  260. //模拟收到一条好友消息
  261. setTimeout(function(){
  262. layim.getMessage({
  263. username: "测试1"
  264. ,avatar: ""
  265. ,id: "100001"
  266. ,type: "friend"
  267. ,cid: Math.random()*100000|0 //模拟消息id,会赋值在li的data-cid上,以便完成一些消息的操作(如撤回),可不填
  268. ,content: "嗨,欢迎体验LayIM。演示标记:"+ new Date().getTime()
  269. });
  270. }, 3000);
  271. //监听查看更多记录
  272. layim.on('chatlog', function(data, ul){
  273. console.log(data);
  274. layim.panel({
  275. title: '与 '+ data.name +' 的聊天记录' //标题
  276. ,tpl: '<div style="padding: 10px;">这里是模版,{{d.data.test}}</div>' //模版
  277. ,data: { //数据
  278. test: 'Hello'
  279. }
  280. });
  281. });
  282. //模拟"更多"有新动态
  283. layim.showNew('More', true);
  284. layim.showNew('find', true);
  285. });
  286. </script>
  287. </body>
  288. </html>