帖子
帖子
用户
博客
课程
显示全部楼层
1682
帖子
10
勋章
Y币

UIChatBox 模块(聊天输入框)demo示例

  [复制链接]
发表于 2017-8-1 14:18:06
UIChatBox 模块是一个聊天输入框模块,开发者可自定义该输入框的功能。

完整源码下载链接:https://**.**/apicloudcom/UIChatBox-Example



index.html
  1. <!doctype html>
  2. <html>

  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"
  6.     />
  7.     <style type="text/css">
  8.         body {  padding-bottom: 50px; }
  9.         button {padding: 10px 20px; margin: 8px; }
  10.         button::after { content: '-' attr( data-name) '( )';}
  11.     </style>
  12. </head>

  13. <body>
  14.     <header>
  15.         <h1>UIChatBox</h1>
  16.         <mark>使用前请详细阅读 文档 使用规则</mark>
  17.     </header>
  18.     <button tapmode onclick="fnOpen( this )" data-name="open"></button>

  19.     <button tapmode onclick="fnClose( this )" data-name="close"></button>

  20.     <button tapmode onclick="fnShow( this )" data-name="show"></button>

  21.     <button tapmode onclick="fnHide( this )" data-name="hide"></button>

  22.     <button tapmode onclick="fnPopupKeyboard( this )" data-name="popupKeyboard"></button>

  23.     <button tapmode onclick="fnCloseKeyboard( this )" data-name="closeKeyboard"></button>

  24.     <button tapmode onclick="fnPopupBoard( this )" data-name="popupBoard"></button>

  25.     <button tapmode onclick="fnCloseBoard( this )" data-name="closeBoard"></button>

  26.     <button tapmode onclick="fnValue( this )" data-name="value">设置</button>

  27.     <button tapmode onclick="fnValue( this )" data-name="value">获取</button>

  28.     <button tapmode onclick="fnInsertValue( this )" data-name="insertValue"></button>

  29.     <button tapmode onclick="fnAddEventListener( this )" data-name="addEventListener">监听 recordBtn 按钮</button>

  30.     <button tapmode onclick="fnAddEventListener( this )" data-name="addEventListener">监听 inputBar</button>

  31.     <button tapmode onclick="fnSetPlaceholder( this )" data-name="setPlaceholder"></button>

  32.     <button tapmode onclick="fnReloadExtraBoard( this )" data-name="reloadExtraBoard"></button>
  33. </body>
  34. </html>
  35. <script type="text/javascript">
  36.     var UIChatBox;
  37.    
  38.     function apiready(){
  39.         UIChatBox = api.require('UIChatBox');
  40.         api.setStatusBarStyle({
  41.             color: '#2390ce'
  42.         });
  43.     };
  44.    
  45.     function fnClose( el ){
  46.         UIChatBox.close();
  47.     }
  48.    
  49.     function fnShow( el ){
  50.         UIChatBox.show();
  51.     }
  52.    
  53.     function fnHide( el ){
  54.         UIChatBox.hide();
  55.     }   
  56.    
  57.     function fnPopupBoard( el){
  58.         UIChatBox.popupBoard({
  59.             target:'extras'
  60.         });
  61.     }
  62.    
  63.     function fnPopupKeyboard( el){
  64.         UIChatBox.popupKeyboard();
  65.     }
  66.    
  67.     function fnCloseKeyboard( el){
  68.         UIChatBox.closeKeyboard();
  69.     }
  70.    
  71.     function fnCloseBoard( el){
  72.         UIChatBox.closeBoard();
  73.     }
  74.    
  75.     function fnValue( el){
  76.         if( el.innerHTML === '设置' ){
  77.             UIChatBox.value({
  78.                 msg: '使用 value 设置新值'
  79.             });
  80.         }else{
  81.             UIChatBox.value(function(ret, err){
  82.                 if( ret ){
  83.                     alert( JSON.stringify( ret ) );
  84.                 }else{
  85.                     alert( JSON.stringify( err ) );
  86.                 }
  87.             });
  88.         }
  89.     }
  90.    
  91.     function fnInsertValue( el){
  92.         UIChatBox.insertValue({
  93.             msg: '使用 insertValue 插入的新值'
  94.         });
  95.     }
  96.    
  97.    
  98.     function fnAddEventListener( el){
  99.         if( el.innerHTML === '监听 recordBtn 按钮' ){
  100.             UIChatBox.addEventListener({
  101.                 target: 'recordBtn',
  102.                 name: 'press'
  103.             }, function( ret, err ){
  104.                 if( ret ){
  105.                     alert( JSON.stringify( ret ) );
  106.                 }else{
  107.                     alert( JSON.stringify( err ) );
  108.                 }
  109.             });
  110.         }else{
  111.            UIChatBox.addEventListener({
  112.                 target: 'inputBar',
  113.                 name: 'move'
  114.             }, function( ret, err ){
  115.                 if( ret ){
  116.                     alert( JSON.stringify( ret ) );
  117.                 }else{
  118.                     alert( JSON.stringify( err ) );
  119.                 }
  120.             });
  121.         }
  122.     }
  123.    
  124.     function fnSetPlaceholder( el){
  125.         UIChatBox.setPlaceholder({
  126.             placeholder: '修改了占位提示内容'
  127.         });
  128.     }
  129.    
  130.     function fnReloadExtraBoard( el){
  131.         UIChatBox.reloadExtraBoard({
  132.             extras: {
  133.                 btns: [{
  134.                     title: '发送地址',
  135.                     normalImg: 'widget://image/loc1.png',
  136.                     activeImg: 'widget://image/loc2.png'
  137.                 },{
  138.                     title: '发送地址',
  139.                     normalImg: 'widget://image/loc1.png',
  140.                     activeImg: 'widget://image/loc2.png'
  141.                 },{
  142.                     title: '发送地址',
  143.                     normalImg: 'widget://image/loc1.png',
  144.                     activeImg: 'widget://image/loc2.png'
  145.                 },{
  146.                     title: '发送地址',
  147.                     normalImg: 'widget://image/loc1.png',
  148.                     activeImg: 'widget://image/loc2.png'
  149.                 },{
  150.                     title: '发送地址',
  151.                     normalImg: 'widget://image/loc1.png',
  152.                     activeImg: 'widget://image/loc2.png'
  153.                 },{
  154.                     title: '发送地址',
  155.                     normalImg: 'widget://image/loc1.png',
  156.                     activeImg: 'widget://image/loc2.png'
  157.                 },{
  158.                     title: '发送地址',
  159.                     normalImg: 'widget://image/loc1.png',
  160.                     activeImg: 'widget://image/loc2.png'
  161.                 },{
  162.                     title: '发送地址',
  163.                     normalImg: 'widget://image/loc1.png',
  164.                     activeImg: 'widget://image/loc2.png'
  165.                 },{
  166.                     title: '发送地址',
  167.                     normalImg: 'widget://image/loc1.png',
  168.                     activeImg: 'widget://image/loc2.png'
  169.                 },]
  170.             }
  171.         });
  172.     }
  173.    
  174.     function fnOpen( el ){
  175.         UIChatBox.open({
  176.             placeholder: '输入发送内容',
  177.             autoFocus: true,
  178.             emotionPath: 'widget://image/emotion',
  179.             styles: {
  180.                 extrasBtn: {
  181.                     normalImg: 'widget://image/add1.png'
  182.                 },
  183.                 speechBtn: {
  184.                     normalImg: 'widget://image/cam1.png'
  185.                 },
  186.                 indicator: {
  187.                     target: 'extrasPanel',
  188.                     color: '#c4c4c4',
  189.                     activeColor: '#9e9e9e'
  190.                 },
  191.                 sendBtn: {
  192.                     titleColor: '#4cc518',
  193.                     bg: '#999999' ,
  194.                     activeBg: '#46a91e',
  195.                     titleSize: 14
  196.                 }
  197.             },
  198.             extras: {
  199.                 titleSize: 10,
  200.                 titleColor: '#a3a3a3',
  201.                 btns: [{
  202.                     title: '图片',
  203.                     normalImg: 'widget://image/album1.png',
  204.                     activeImg: 'widget://image/album2.png'
  205.                 },{
  206.                     title: '发送地址',
  207.                     normalImg: 'widget://image/loc1.png',
  208.                     activeImg: 'widget://image/loc2.png'
  209.                 },{
  210.                     title: '图片',
  211.                     normalImg: 'widget://image/album1.png',
  212.                     activeImg: 'widget://image/album2.png'
  213.                 },{
  214.                     title: '发送地址',
  215.                     normalImg: 'widget://image/loc1.png',
  216.                     activeImg: 'widget://image/loc2.png'
  217.                 },{
  218.                     title: '图片',
  219.                     normalImg: 'widget://image/album1.png',
  220.                     activeImg: 'widget://image/album2.png'
  221.                 },{
  222.                     title: '发送地址',
  223.                     normalImg: 'widget://image/loc1.png',
  224.                     activeImg: 'widget://image/loc2.png'
  225.                 },{
  226.                     title: '图片',
  227.                     normalImg: 'widget://image/album1.png',
  228.                     activeImg: 'widget://image/album2.png'
  229.                 },{
  230.                     title: '发送地址',
  231.                     normalImg: 'widget://image/loc1.png',
  232.                     activeImg: 'widget://image/loc2.png'
  233.                 },{
  234.                     title: '图片',
  235.                     normalImg: 'widget://image/album1.png',
  236.                     activeImg: 'widget://image/album2.png'
  237.                 },{
  238.                     title: '发送地址',
  239.                     normalImg: 'widget://image/loc1.png',
  240.                     activeImg: 'widget://image/loc2.png'
  241.                 },{
  242.                     title: '图片',
  243.                     normalImg: 'widget://image/album1.png',
  244.                     activeImg: 'widget://image/album2.png'
  245.                 },{
  246.                     title: '发送地址',
  247.                     normalImg: 'widget://image/loc1.png',
  248.                     activeImg: 'widget://image/loc2.png'
  249.                 }]
  250.             }
  251.         }, function( ret, err ){
  252.             if( ret ){
  253.                 alert( JSON.stringify( ret ) );
  254.             }else{
  255.                 alert( JSON.stringify( err ) );
  256.             }
  257.         });
  258.     }
  259. </script>
复制代码



5
帖子
0
勋章
417
Y币
回帖拿金币,支持支持

回帖拿金币,支持支持
42
帖子
1
勋章
1万+
Y币
比较详细
9
帖子
0
勋章
653
Y币
支持一下
44
帖子
0
勋章
118
Y币
支持一下,拿云币
99
帖子
1
勋章
314
Y币
支持一下,拿云币
75
帖子
0
勋章
822
Y币
支持一下,拿云币
136
帖子
1
勋章
853
Y币
捡个云币
258
帖子
4
勋章
1024
Y币

回帖拿金币,支持支持
12345678910... 12下一页
您需要登录后才可以回帖 登录

本版积分规则