Aucune description

chats.html 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
  6. <title></title>
  7. <link href="../css/mui.min.css" rel="stylesheet" />
  8. <link rel="stylesheet" type="text/css" href="../css/app.css" />
  9. <link href="../css/iconfont.css" rel="stylesheet" />
  10. <link href="../css/mui.imageviewer.css" rel="stylesheet" />
  11. <style>
  12. html,
  13. body {
  14. height: 100%;
  15. margin: 0px;
  16. padding: 0px;
  17. overflow: hidden;
  18. -webkit-touch-callout: none;
  19. -webkit-user-select: none;
  20. }
  21. footer {
  22. position: fixed;
  23. width: 100%;
  24. height: 50px;
  25. min-height: 50px;
  26. border-top: solid 1px #bbb;
  27. left: 0px;
  28. bottom: 0px;
  29. overflow: hidden;
  30. padding: 0px 50px;
  31. background-color: #fafafa;
  32. }
  33. .footer-left {
  34. position: absolute;
  35. width: 50px;
  36. height: 50px;
  37. left: 0px;
  38. bottom: 0px;
  39. text-align: center;
  40. vertical-align: middle;
  41. line-height: 100%;
  42. padding: 12px 4px;
  43. }
  44. .footer-right {
  45. position: absolute;
  46. width: 50px;
  47. height: 50px;
  48. right: 0px;
  49. bottom: 0px;
  50. text-align: center;
  51. vertical-align: middle;
  52. line-height: 100%;
  53. padding: 12px 5px;
  54. display: inline-block;
  55. }
  56. .footer-center {
  57. height: 100%;
  58. padding: 5px 0px;
  59. }
  60. .footer-center [class*=input] {
  61. width: 100%;
  62. height: 100%;
  63. border-radius: 5px;
  64. }
  65. .footer-center .input-text {
  66. background: #fff;
  67. border: solid 1px #ddd;
  68. padding: 10px !important;
  69. font-size: 16px !important;
  70. line-height: 18px !important;
  71. font-family: verdana !important;
  72. overflow: hidden;
  73. }
  74. .footer-center .input-sound {
  75. background-color: #eee;
  76. }
  77. .mui-content {
  78. height: 100%;
  79. padding: 44px 0px 50px 0px;
  80. overflow: auto;
  81. background-color: #eaeaea;
  82. }
  83. #msg-list {
  84. height: 100%;
  85. overflow: auto;
  86. -webkit-overflow-scrolling: touch;
  87. }
  88. .msg-item {
  89. padding: 8px;
  90. clear: both;
  91. }
  92. .msg-item .mui-item-clear {
  93. clear: both;
  94. }
  95. .msg-item .msg-user {
  96. width: 38px;
  97. height: 38px;
  98. border: solid 1px #d3d3d3;
  99. display: inline-block;
  100. background: #fff;
  101. border-radius: 3px;
  102. vertical-align: top;
  103. text-align: center;
  104. float: left;
  105. padding: 3px;
  106. color: #ddd;
  107. }
  108. .msg-item .msg-user-img{
  109. width: 38px;
  110. height: 38px;
  111. display: inline-block;
  112. border-radius: 3px;
  113. vertical-align: top;
  114. text-align: center;
  115. float: left;
  116. color: #ddd;
  117. }
  118. .msg-item .msg-content {
  119. display: inline-block;
  120. border-radius: 5px;
  121. border: solid 1px #d3d3d3;
  122. background-color: #FFFFFF;
  123. color: #333;
  124. padding: 8px;
  125. vertical-align: top;
  126. font-size: 15px;
  127. position: relative;
  128. margin: 0px 8px;
  129. max-width: 75%;
  130. min-width: 35px;
  131. float: left;
  132. }
  133. .msg-item .msg-content .msg-content-inner {
  134. overflow-x: hidden;
  135. }
  136. .msg-item .msg-content .msg-content-arrow {
  137. position: absolute;
  138. border: solid 1px #d3d3d3;
  139. border-right: none;
  140. border-top: none;
  141. background-color: #FFFFFF;
  142. width: 10px;
  143. height: 10px;
  144. left: -5px;
  145. top: 12px;
  146. -webkit-transform: rotateZ(45deg);
  147. transform: rotateZ(45deg);
  148. }
  149. .msg-item-self .msg-user,
  150. .msg-item-self .msg-content {
  151. float: right;
  152. }
  153. .msg-item-self .msg-content .msg-content-arrow {
  154. left: auto;
  155. right: -5px;
  156. -webkit-transform: rotateZ(225deg);
  157. transform: rotateZ(225deg);
  158. }
  159. .msg-item-self .msg-content,
  160. .msg-item-self .msg-content .msg-content-arrow {
  161. background-color: #4CD964;
  162. color: #fff;
  163. border-color: #2AC845;
  164. }
  165. footer .mui-icon {
  166. color: #999999;
  167. }
  168. footer .mui-icon:active {
  169. color: #FF9900 !important;
  170. }/*#007AFF*/
  171. footer .mui-icon-paperplane:before {
  172. content: "发送";
  173. }
  174. footer .mui-icon-paperplane {
  175. /*-webkit-transform: rotateZ(45deg);
  176. transform: rotateZ(45deg);*/
  177. font-size: 16px;
  178. word-break: keep-all;
  179. line-height: 100%;
  180. padding-top: 6px;
  181. color: rgba(0, 135, 250, 1);
  182. }
  183. #msg-sound {
  184. -webkit-user-select: none !important;
  185. user-select: none !important;
  186. }
  187. .rprogress {
  188. position: absolute;
  189. left: 50%;
  190. top: 50%;
  191. width: 140px;
  192. height: 140px;
  193. margin-left: -70px;
  194. margin-top: -70px;
  195. background-image: url(../images/arecord.png);
  196. background-repeat: no-repeat;
  197. background-position: center center;
  198. background-size: 30px 30px;
  199. background-color: rgba(0, 0, 0, 0.7);
  200. border-radius: 5px;
  201. display: none;
  202. -webkit-transition: .15s;
  203. }
  204. .rschedule {
  205. background-color: rgba(0, 0, 0, 0);
  206. border: 5px solid rgba(0, 183, 229, 0.9);
  207. opacity: .9;
  208. border-left: 5px solid rgba(0, 0, 0, 0);
  209. border-right: 5px solid rgba(0, 0, 0, 0);
  210. border-radius: 50px;
  211. box-shadow: 0 0 15px #2187e7;
  212. width: 46px;
  213. height: 46px;
  214. position: absolute;
  215. left: 50%;
  216. top: 50%;
  217. margin-left: -23px;
  218. margin-top: -23px;
  219. -webkit-animation: spin 1s infinite linear;
  220. animation: spin 1s infinite linear;
  221. }
  222. .r-sigh{
  223. display: none;
  224. border-radius: 50px;
  225. box-shadow: 0 0 15px #2187e7;
  226. width: 46px;
  227. height: 46px;
  228. position: absolute;
  229. left: 50%;
  230. top: 50%;
  231. margin-left: -23px;
  232. margin-top: -23px;
  233. text-align: center;
  234. line-height: 46px;
  235. font-size: 40px;
  236. font-weight: bold;
  237. color: #2187e7;
  238. }
  239. .rprogress-sigh{
  240. background-image: none !important;
  241. }
  242. .rprogress-sigh .rschedule{
  243. display: none !important;
  244. }
  245. .rprogress-sigh .r-sigh{
  246. display: block !important;
  247. }
  248. .rsalert {
  249. font-size: 12px;
  250. color: #bbb;
  251. text-align: center;
  252. position: absolute;
  253. border-radius: 5px;
  254. width: 130px;
  255. margin: 5px 5px;
  256. padding: 5px;
  257. left: 0px;
  258. bottom: 0px;
  259. }
  260. @-webkit-keyframes spin {
  261. 0% {
  262. -webkit-transform: rotate(0deg);
  263. }
  264. 100% {
  265. -webkit-transform: rotate(360deg);
  266. }
  267. }
  268. @keyframes spin {
  269. 0% {
  270. transform: rotate(0deg);
  271. }
  272. 100% {
  273. transform: rotate(360deg);
  274. }
  275. }
  276. #h {
  277. background: #fff;
  278. border: solid 1px #ddd;
  279. padding: 10px !important;
  280. font-size: 16px !important;
  281. font-family: verdana !important;
  282. line-height: 18px !important;
  283. overflow: visible;
  284. position: absolute;
  285. left: -1000px;
  286. right: 0px;
  287. word-break: break-all;
  288. word-wrap: break-word;
  289. }
  290. .cancel {
  291. background-color: darkred;
  292. }
  293. .displayNone {
  294. display: none;
  295. }
  296. #consultCon {
  297. margin: -11px 15px -11px;
  298. }
  299. #lookConBtn {
  300. text-align: center;
  301. }
  302. /*#middlePopover {
  303. height: 200px;
  304. width:80%;
  305. margin: auto;
  306. }*/
  307. .mui-popover #arrow {
  308. background: none;
  309. }
  310. .assessAtarStyle {
  311. padding-bottom: 10px;
  312. left: 0;
  313. z-index: 999;
  314. }
  315. #assessText {
  316. }
  317. .showCon {
  318. padding: 10px 20px;
  319. }
  320. /*待评价开始*/
  321. .frmbtn1 {
  322. border:1px solid red;
  323. border-radius:6px;
  324. color:red;
  325. }
  326. .frmbtn1.mui-btn:enabled:active{
  327. background: red;
  328. color: #fff;
  329. }
  330. /*待评价结束*/
  331. </style>
  332. </head>
  333. <body contextmenu="return false;">
  334. <header class="mui-bar mui-bar-nav toptitbox">
  335. <span class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left topback" id="backBtn">
  336. <a href="consultlist.html"></a>
  337. </span>
  338. <h1 class="mui-title toptit" id="chatName"></h1>
  339. <span class="mui-icon mui-icon-contact mui-pull-right personhead"></span>
  340. </header>
  341. <pre id='h'></pre>
  342. <script id='msg-template' type="text/template">
  343. <% for(var i in record){ var item=record[i]; %>
  344. <div class="msg-item <%= (item.sender=='self'?' msg-item-self':'') %>" msg-type='<%=(item.type)%>' msg-content='<%=(item.content)%>'>
  345. <!--对话内容渲染-->
  346. <% if(item.sender=='self' ) { %>
  347. <!--<i class="msg-user mui-icon mui-icon-person"></i>-->
  348. <img class="msg-user msg-user-img" src="../images/dialogue.png" alt="" />
  349. <% } else { %>
  350. <img class="msg-user msg-user-img" src="../images/logo.png" alt="" />
  351. <% } %>
  352. <div class="msg-content">
  353. <div class="msg-content-inner">
  354. <% if(item.type=='text' ) { %>
  355. <%=( item.content|| '&nbsp;&nbsp;') %>
  356. <% } else if(item.type=='image' ) { %>
  357. <img class="msg-content-image" src="<%=(item.content)%>" style="max-width: 100px;" />
  358. <% } else if(item.type=='sound' ) { %>
  359. <span class="mui-icon mui-icon-mic" style="font-size: 18px;font-weight: bold;"></span>
  360. <span class="play-state">点击播放</span>
  361. <% } %>
  362. </div>
  363. <div class="msg-content-arrow"></div>
  364. </div>
  365. <div class="mui-item-clear"></div>
  366. </div>
  367. <% } %>
  368. </script>
  369. <div class="mui-content">
  370. <div class="displayNone" id="status"></div>
  371. <!--评价内容-->
  372. <!--<div id="middlePopover" class="mui-popover">
  373. <div class="mui-popover-arrow" id="arrow"></div>
  374. <div class="mui-scroll-wrapper">
  375. <div class="mui-scroll">
  376. <ul class="mui-table-view showCon" >
  377. <div class="assessAtarStyle">
  378. <div class="levelbox" id="showStar">
  379. <span class="mui-icon iconfont icon-favor"></span>
  380. <span class="mui-icon iconfont icon-favor"></span>
  381. <span class="mui-icon iconfont icon-favor"></span>
  382. <span class="mui-icon iconfont icon-favor"></span>
  383. <span class="mui-icon iconfont icon-favor"></span>
  384. </div>
  385. </div>
  386. <div id="assessText"></div>
  387. </ul>
  388. </div>
  389. </div>
  390. </div>--><!--评价内容-->
  391. <div class="operatebox">
  392. <div class="themespan mui-pull-left">
  393. <span class="" id="consultTitle">
  394. 上面的例子用了很多属性来设置边框。
  395. </span>
  396. </div>
  397. <!--我的需求,进行中-->
  398. <div class="operatebtnbox mui-pull-right displayNone" id="confirm">
  399. <button class="mui-btn mui-btn-block mui-btn-outlined frmbtn operatebtn" id="confirmBtn" >点击确认完成咨询</button>
  400. </div>
  401. <!--我的需求,未评价-->
  402. <div class="operatebtnbox mui-pull-right displayNone" id="assessBtn">
  403. <button class="mui-btn mui-btn-block mui-btn-outlined frmbtn1 operatebtn" style="width:80px;">去评价</button>
  404. </div>
  405. <!--我的需求,已评价-->
  406. <div class="operatebtnbox mui-pull-right operated displayNone" id="assessed">
  407. <a href="#middlePopover">
  408. <div class="evabox" id="assessed_center">
  409. <span>已评价</span>
  410. <div class="levelbox" id="my_starContainer">
  411. <span class="mui-icon iconfont icon-favor"></span> <!--无色星星icon-favor 黄色星icon-favorfill-->
  412. <span class="mui-icon iconfont icon-favor"></span>
  413. <span class="mui-icon iconfont icon-favor"></span>
  414. <span class="mui-icon iconfont icon-favor"></span>
  415. <span class="mui-icon iconfont icon-favor"></span>
  416. </div>
  417. </div>
  418. </a>
  419. </div>
  420. <!--收到咨询,对方未评价-->
  421. <div class="operatebtnbox mui-pull-right displayNone" style="width:30%;" id="that_weiassess">
  422. <div class="evabox"><span>对方还未评价</span></div>
  423. </div>
  424. <!--收到咨询,进行中-->
  425. <div class="operatebtnbox mui-pull-right displayNone" id="waying" style="width:30%;">
  426. <div class="evabox"><span>进行中</span></div>
  427. </div>
  428. <!--收到咨询,对方已评价-->
  429. <div class="operatebtnbox mui-pull-right operated displayNone" id="that_assessed" style="cursor: pointer;">
  430. <a href="#middlePopover">
  431. <div class="evabox" >
  432. <span>对方已评价</span>
  433. <div class="levelbox" id="consult_starContainer">
  434. <span class="mui-icon iconfont icon-favor"></span> <!--无色星星icon-favor 黄色星icon-favorfill-->
  435. <span class="mui-icon iconfont icon-favor"></span>
  436. <span class="mui-icon iconfont icon-favor"></span>
  437. <span class="mui-icon iconfont icon-favor"></span>
  438. <span class="mui-icon iconfont icon-favor"></span>
  439. </div>
  440. </div>
  441. </a>
  442. </div>
  443. </div>
  444. <div class="consult_content">
  445. <ul class="mui-table-view" >
  446. <li class="mui-table-view-cell mui-collapse" id="mui-active" style="background-color:#fff;">
  447. <div class="mui-collapse-content" id="consultCon">
  448. 可以在折叠面板中放置任何内容;折叠面板默认收缩,若希望某个面板默认展开,
  449. 只需要在包含.mui-collapse类的li节点上,增加.mui-active类即可;mui官网中的方法说明,
  450. 使用的就是折叠面板控件。
  451. </div>
  452. <a class="mui-navigate-right" href="#" id="lookConBtn">查看咨询内容</a>
  453. </li>
  454. </ul>
  455. </div>
  456. <div id='msg-list'>
  457. </div>
  458. </div>
  459. <footer class="" id="chatFooter">
  460. <div class="footer-left">
  461. <i id='msg-image' class="mui-icon mui-icon-camera" style="font-size: 28px;"></i>
  462. </div>
  463. <div class="footer-center">
  464. <textarea id='msg-text' type="text" class='input-text'></textarea>
  465. <button id='msg-sound' type="button" class='input-sound' style="display: none;">按住说话</button>
  466. </div>
  467. <label for="" class="footer-right">
  468. <i id='msg-type' class="mui-icon mui-icon-mic"></i>
  469. </label>
  470. </footer>
  471. <div id='sound-alert' class="rprogress">
  472. <div class="rschedule"></div>
  473. <div class="r-sigh">!</div>
  474. <div id="audio_tips" class="rsalert">手指上滑,取消发送</div>
  475. </div>
  476. <script src="../js/public/mui.min.js"></script>
  477. <script src="../js/public/base.js"></script>
  478. <script src="../js/public/mui.imageViewer.js"></script>
  479. <script src="../js/public/arttmpl.js"></script>
  480. <script type="text/javascript" src="../js/chats.js"></script>
  481. <script type="text/javascript" charset="utf-8">
  482. /*mui.init({
  483. swipeBack: true //启用右滑关闭功能
  484. });*/
  485. /*mui('.mui-scroll-wrapper').scroll();
  486. mui('body').on('shown', '.mui-popover', function(e) {
  487. //console.log('shown', e.detail.id);//detail为当前popover元素
  488. console.log('shown');
  489. });
  490. mui('body').on('hidden', '.mui-popover', function(e) {
  491. //console.log('hidden', e.detail.id);//detail为当前popover元素
  492. });*/
  493. /*(function($, doc) {
  494. var MIN_SOUND_TIME = 800;
  495. $.init({
  496. gestureConfig: {
  497. tap: true, //默认为true
  498. doubletap: true, //默认为false
  499. longtap: true, //默认为false
  500. swipe: true, //默认为true
  501. drag: true, //默认为true
  502. hold: true, //默认为false,不监听
  503. release: true //默认为false,不监听
  504. }
  505. });
  506. template.config('escape', false);
  507. //$.plusReady=function(fn){fn();};
  508. $.plusReady(function() {
  509. plus.webview.currentWebview().setStyle({
  510. softinputMode: "adjustResize"
  511. });
  512. var showKeyboard = function() {
  513. if ($.os.ios) {
  514. var webView = plus.webview.currentWebview().nativeInstanceObject();
  515. webView.plusCallMethod({
  516. "setKeyboardDisplayRequiresUserAction": false
  517. });
  518. } else {
  519. var Context = plus.android.importClass("android.content.Context");
  520. var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
  521. var main = plus.android.runtimeMainActivity();
  522. var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
  523. imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
  524. //var view = ((ViewGroup)main.findViewById(android.R.id.content)).getChildAt(0);
  525. imm.showSoftInput(main.getWindow().getDecorView(), InputMethodManager.SHOW_IMPLICIT);
  526. //alert("ll");
  527. }
  528. };
  529. var record = [{
  530. sender: 'zs',
  531. type: 'text',
  532. content: 'Hi,我是 科袖 小管家!'
  533. }];
  534. var ui = {
  535. body: doc.querySelector('body'),
  536. footer: doc.querySelector('footer'),
  537. footerRight: doc.querySelector('.footer-right'),
  538. footerLeft: doc.querySelector('.footer-left'),
  539. btnMsgType: doc.querySelector('#msg-type'),
  540. boxMsgText: doc.querySelector('#msg-text'),
  541. boxMsgSound: doc.querySelector('#msg-sound'),
  542. btnMsgImage: doc.querySelector('#msg-image'),
  543. areaMsgList: doc.querySelector('#msg-list'),
  544. boxSoundAlert: doc.querySelector('#sound-alert'),
  545. h: doc.querySelector('#h'),
  546. content: doc.querySelector('.mui-content')
  547. };
  548. ui.h.style.width = ui.boxMsgText.offsetWidth+'px';
  549. //alert(ui.boxMsgText.offsetWidth );
  550. var footerPadding = ui.footer.offsetHeight - ui.boxMsgText.offsetHeight;
  551. var msgItemTap = function(msgItem, event) {
  552. var msgType = msgItem.getAttribute('msg-type');
  553. var msgContent = msgItem.getAttribute('msg-content')
  554. if (msgType == 'sound') {
  555. player = plus.audio.createPlayer(msgContent);
  556. var playState = msgItem.querySelector('.play-state');
  557. playState.innerText = '正在播放...';
  558. player.play(function() {
  559. playState.innerText = '点击播放';
  560. }, function(e) {
  561. playState.innerText = '点击播放';
  562. });
  563. }
  564. };
  565. var imageViewer = new $.ImageViewer('.msg-content-image', {
  566. dbl: false
  567. });
  568. var bindMsgList = function() {
  569. //绑定数据:
  570. // tp.bind({
  571. // template: 'msg-template',
  572. // element: 'msg-list',
  573. // model: record
  574. // });
  575. ui.areaMsgList.innerHTML = template('msg-template', {
  576. "record": record
  577. });
  578. var msgItems = ui.areaMsgList.querySelectorAll('.msg-item');
  579. [].forEach.call(msgItems, function(item, index) {
  580. item.addEventListener('tap', function(event) {
  581. msgItemTap(item, event);
  582. }, false);
  583. });
  584. imageViewer.findAllImage();
  585. ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
  586. };
  587. bindMsgList();
  588. window.addEventListener('resize', function() {
  589. ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
  590. }, false);
  591. var send = function(msg) {
  592. record.push(msg);
  593. bindMsgList();
  594. toRobot(msg.content);
  595. };
  596. var toRobot = function(info) {
  597. var apiUrl = 'http://www.tuling123.com/openapi/api';
  598. // var apiUrl = baseUrl+'/ajax/tidings/qacon';
  599. $.getJSON(apiUrl, {
  600. "key": 'acfbca724ea1b5db96d2eef88ce677dc',
  601. "info": info,
  602. "userid": plus.device.uuid
  603. }, function(data) {
  604. //alert(JSON.stringify(data));
  605. record.push({
  606. sender: 'zs',
  607. type: 'text',
  608. content: data.text
  609. });
  610. bindMsgList();
  611. });
  612. };
  613. function msgTextFocus() {
  614. ui.boxMsgText.focus();
  615. setTimeout(function() {
  616. ui.boxMsgText.focus();
  617. }, 150);
  618. }
  619. //解决长按“发送”按钮,导致键盘关闭的问题;
  620. ui.footerRight.addEventListener('touchstart', function(event) {
  621. if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
  622. msgTextFocus();
  623. event.preventDefault();
  624. }
  625. });
  626. //解决长按“发送”按钮,导致键盘关闭的问题;
  627. ui.footerRight.addEventListener('touchmove', function(event) {
  628. if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
  629. msgTextFocus();
  630. event.preventDefault();
  631. }
  632. });
  633. // ui.footerRight.addEventListener('touchcancel', function(event) {
  634. // if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
  635. // msgTextFocus();
  636. // event.preventDefault();
  637. // }
  638. // });
  639. // ui.footerRight.addEventListener('touchend', function(event) {
  640. // if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
  641. // msgTextFocus();
  642. // event.preventDefault();
  643. // }
  644. // });
  645. ui.footerRight.addEventListener('release', function(event) {
  646. if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
  647. //showKeyboard();
  648. ui.boxMsgText.focus();
  649. setTimeout(function() {
  650. ui.boxMsgText.focus();
  651. }, 150);
  652. // event.detail.gesture.preventDefault();
  653. send({
  654. sender: 'self',
  655. type: 'text',
  656. content: ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '<br/>')
  657. });
  658. ui.boxMsgText.value = '';
  659. $.trigger(ui.boxMsgText, 'input', null);
  660. } else if (ui.btnMsgType.classList.contains('mui-icon-mic')) {
  661. ui.btnMsgType.classList.add('mui-icon-compose');
  662. ui.btnMsgType.classList.remove('mui-icon-mic');
  663. ui.boxMsgText.style.display = 'none';
  664. ui.boxMsgSound.style.display = 'block';
  665. ui.boxMsgText.blur();
  666. document.body.focus();
  667. } else if (ui.btnMsgType.classList.contains('mui-icon-compose')) {
  668. ui.btnMsgType.classList.add('mui-icon-mic');
  669. ui.btnMsgType.classList.remove('mui-icon-compose');
  670. ui.boxMsgSound.style.display = 'none';
  671. ui.boxMsgText.style.display = 'block';
  672. //--
  673. //showKeyboard();
  674. ui.boxMsgText.focus();
  675. setTimeout(function() {
  676. ui.boxMsgText.focus();
  677. }, 150);
  678. }
  679. }, false);
  680. ui.footerLeft.addEventListener('tap', function(event) {
  681. var btnArray = [{
  682. title: "拍照"
  683. }, {
  684. title: "从相册选择"
  685. }];
  686. plus.nativeUI.actionSheet({
  687. title: "选择照片",
  688. cancel: "取消",
  689. buttons: btnArray
  690. }, function(e) {
  691. var index = e.index;
  692. switch (index) {
  693. case 0:
  694. break;
  695. case 1:
  696. var cmr = plus.camera.getCamera();
  697. cmr.captureImage(function(path) {
  698. send({
  699. sender: 'self',
  700. type: 'image',
  701. content: "file://" + plus.io.convertLocalFileSystemURL(path)
  702. });
  703. }, function(err) {});
  704. break;
  705. case 2:
  706. plus.gallery.pick(function(path) {
  707. send({
  708. sender: 'self',
  709. type: 'image',
  710. content: path
  711. });
  712. }, function(err) {}, null);
  713. break;
  714. }
  715. });
  716. }, false);
  717. var setSoundAlertVisable=function(show){
  718. if(show){
  719. ui.boxSoundAlert.style.display = 'block';
  720. ui.boxSoundAlert.style.opacity = 1;
  721. }else{
  722. ui.boxSoundAlert.style.opacity = 0;
  723. //fadeOut完成再真正隐藏
  724. setTimeout(function(){
  725. ui.boxSoundAlert.style.display = 'none';
  726. },200);
  727. }
  728. };
  729. var recordCancel = false;
  730. var recorder = null;
  731. var audio_tips = document.getElementById("audio_tips");
  732. var startTimestamp = null;
  733. var stopTimestamp = null;
  734. var stopTimer = null;
  735. ui.boxMsgSound.addEventListener('hold', function(event) {
  736. recordCancel = false;
  737. if(stopTimer)clearTimeout(stopTimer);
  738. audio_tips.innerHTML = "手指上划,取消发送";
  739. ui.boxSoundAlert.classList.remove('rprogress-sigh');
  740. setSoundAlertVisable(true);
  741. recorder = plus.audio.getRecorder();
  742. if (recorder == null) {
  743. plus.nativeUI.toast("不能获取录音对象");
  744. return;
  745. }
  746. startTimestamp = (new Date()).getTime();
  747. recorder.record({
  748. filename: "_doc/audio/"
  749. }, function(path) {
  750. if (recordCancel) return;
  751. send({
  752. sender: 'self',
  753. type: 'sound',
  754. content: path
  755. });
  756. }, function(e) {
  757. plus.nativeUI.toast("录音时出现异常: " + e.message);
  758. });
  759. }, false);
  760. ui.body.addEventListener('drag', function(event) {
  761. //console.log('drag');
  762. if (Math.abs(event.detail.deltaY) > 50) {
  763. if (!recordCancel) {
  764. recordCancel = true;
  765. if (!audio_tips.classList.contains("cancel")) {
  766. audio_tips.classList.add("cancel");
  767. }
  768. audio_tips.innerHTML = "松开手指,取消发送";
  769. }
  770. } else {
  771. if (recordCancel) {
  772. recordCancel = false;
  773. if (audio_tips.classList.contains("cancel")) {
  774. audio_tips.classList.remove("cancel");
  775. }
  776. audio_tips.innerHTML = "手指上划,取消发送";
  777. }
  778. }
  779. }, false);
  780. ui.boxMsgSound.addEventListener('release', function(event) {
  781. //console.log('release');
  782. if (audio_tips.classList.contains("cancel")) {
  783. audio_tips.classList.remove("cancel");
  784. audio_tips.innerHTML = "手指上划,取消发送";
  785. }
  786. //
  787. stopTimestamp = (new Date()).getTime();
  788. if (stopTimestamp - startTimestamp < MIN_SOUND_TIME) {
  789. audio_tips.innerHTML = "录音时间太短";
  790. ui.boxSoundAlert.classList.add('rprogress-sigh');
  791. recordCancel = true;
  792. stopTimer=setTimeout(function(){
  793. setSoundAlertVisable(false);
  794. },800);
  795. }else{
  796. setSoundAlertVisable(false);
  797. }
  798. recorder.stop();
  799. }, false);
  800. ui.boxMsgSound.addEventListener("touchstart", function(e) {
  801. //console.log("start....");
  802. e.preventDefault();
  803. });
  804. ui.boxMsgText.addEventListener('input', function(event) {
  805. ui.btnMsgType.classList[ui.boxMsgText.value == '' ? 'remove' : 'add']('mui-icon-paperplane');
  806. ui.btnMsgType.setAttribute("for", ui.boxMsgText.value == '' ? '' : 'msg-text');
  807. ui.h.innerText = ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '\n-') || '-';
  808. ui.footer.style.height = (ui.h.offsetHeight + footerPadding) + 'px';
  809. ui.content.style.paddingBottom = ui.footer.style.height;
  810. });
  811. ui.boxMsgText.addEventListener('tap', function(event) {
  812. ui.boxMsgText.focus();
  813. setTimeout(function() {
  814. ui.boxMsgText.focus();
  815. }, 0);
  816. }, false);
  817. });
  818. }(mui, document));*/
  819. </script>
  820. </body>
  821. </html>