Ei kuvausta

chats.html 25KB

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