search.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>搜索图书</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <link rel="stylesheet" href="../css/mui.min.css">
  10. <style>
  11. .title {
  12. margin: 20px 15px 10px;
  13. color: #6d6d72;
  14. font-size: 15px;
  15. }
  16. .mui-placeholder {
  17. text-align: left !important;
  18. padding-left: 5% !important;
  19. }
  20. .my-height {
  21. top: -20px;
  22. position: relative;
  23. right: -45px;
  24. height: 1px;
  25. color: brown;
  26. }
  27. @-webkit-keyframes btnRotate {
  28. 0% {
  29. -webkit-transform: rotateZ(0deg);
  30. }
  31. 100% {
  32. -webkit-transform: rotateZ(360deg);
  33. }
  34. }
  35. .donghua {
  36. -webkit-animation: btnRotate 1.5s linear infinite;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <header class="mui-bar mui-bar-nav">
  42. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  43. <button id="search-btn-id" style="color: #CF2D29;font-size: 15px;" type="button" class="mui-btn mui-btn-link mui-pull-right">
  44. 搜索
  45. </button>
  46. <div class="mui-input-row mui-search mui-pull-right" style="width: 70%;top: -43px;right: 40px;">
  47. <input id="search-book-id" type="search" class="mui-input-clear" placeholder="">
  48. </div>
  49. </header>
  50. <div class="mui-content">
  51. <ul class="mui-table-view mui-table-view-chevron" id="books-id">
  52. </ul>
  53. </div>
  54. </body>
  55. <script id="book-temp-id" type="text/html">
  56. <li class="mui-table-view-cell mui-media">
  57. <a data-id='{id}' data-name='{name}' data-html-dist='{html_dist}' data-html-name='{html_name}' data-img-path='{img_path}' data-category-id='{dic_category_id}' data-json='{json}' data-desc='{desc}' data-is-download='{isDownload}' download-start='false'>
  58. <img id="img-{id}" class="mui-media-object mui-pull-left">
  59. <div class="mui-media-body">
  60. {name}
  61. <p class='mui-ellipsis'>{desc}</p>
  62. </div>
  63. <div id='download-progress-{id}' class="mui-pull-right my-height" style="display: none;">0%</div>
  64. <div id='download-{id}' class="mui-icon mui-icon-pulldown mui-pull-right my-height" style="display: {display};"></div>
  65. </a>
  66. </li>
  67. </script>
  68. <!--
  69. 作者:HZC
  70. 时间:2015-08-26
  71. 描述:搜索图书
  72. -->
  73. <script type="text/javascript" src="../js/jquery.min.js" type="text/javascript" charset="UTF-8"></script>
  74. <script type="text/javascript" src="http://182.92.109.194:8080/rpc/helper.js" type="text/javascript" charset="UTF-8"></script>
  75. <script src="../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
  76. <script src="../js/routes.js" type="text/javascript" charset="utf-8"></script>
  77. <script src="../js/app.js" type="text/javascript" charset="utf-8"></script>
  78. <script src="../js/db/service.js" type="text/javascript" charset="utf-8"></script>
  79. <script src="../js/hzc.rpc.js" type="text/javascript" charset="utf-8"></script>
  80. <script type="text/javascript">
  81. mui.init();
  82. mui.plusReady(function() {
  83. var self = plus.webview.currentWebview();
  84. openKeyBoard();
  85. search();
  86. openBook();
  87. });
  88. /**
  89. * 开始搜索
  90. */
  91. function search() {
  92. $id('search-btn-id').addEventListener('tap', function() {
  93. var keyword = $id('search-book-id').value;
  94. // console.log('开始搜索关键字:' + keyword);
  95. searchBooks(keyword, function(data) {
  96. if (data.length > 0) {
  97. var htmlStr = '';
  98. for (var i = 0; i < data.length; i++) {
  99. var book = data[i];
  100. // console.log(JSON.stringify(book))
  101. var myBooks = getBookIdsFromStorage();
  102. if (myBooks && myBooks.toString().indexOf(book.id) > -1) {
  103. book.display = 'none';
  104. book.isDownload = '1';
  105. } else {
  106. book.isDownload = '0';
  107. }
  108. var tempHtml = $id('book-temp-id').innerHTML;
  109. htmlStr += render(tempHtml, book);
  110. $id('books-id').innerHTML = htmlStr
  111. book.imgPath = Routes.urls.book.bookUrl + book.img_path;
  112. //book.imgPath = "http://pics.sc.chinaz.com/Files/pic/icons128/5911/o1.png";
  113. setImg('img-' + book.id, book.imgPath);
  114. }
  115. } else {
  116. $id('books-id').innerHTML = '<li class="mui-table-view-cell mui-media"><div style="text-align: center;margin-right: -60px;">没有相关图书</div></li>';
  117. }
  118. });
  119. })
  120. }
  121. /**
  122. * 打开键盘
  123. */
  124. function openKeyBoard() {
  125. setTimeout(function() {
  126. var Context = plus.android.importClass("android.content.Context");
  127. var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
  128. var main = plus.android.runtimeMainActivity();
  129. var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
  130. imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
  131. }, 1000)
  132. document.getElementById("search-book-id").focus();
  133. }
  134. /**
  135. * 打开书
  136. */
  137. function openBook() {
  138. mui('#books-id').on('tap', 'a', function() {
  139. var bookSelf = this;
  140. //是否已经下载
  141. var isDownload = bookSelf.getAttribute('data-is-download');
  142. //书id
  143. var bookId = bookSelf.getAttribute('data-id');
  144. //html的名字
  145. var htmlName = bookSelf.getAttribute('data-html-name');
  146. var htmlDist = bookSelf.getAttribute('data-html-dist');
  147. //服务器中书的下载地址
  148. var loadUrl = Routes.urls.book.downloadBook + htmlDist + '/' + htmlName;
  149. // console.log(loadUrl)
  150. //没有下载,则提示下载,并开始下载,下载成功更新数据库中的下载状态
  151. if (isDownload == '0') {
  152. if (bookSelf.getAttribute('download-start') == 'true') {
  153. mui.toast('正在下载');
  154. return;
  155. }
  156. window.__downloading = true;
  157. mui.toast('开始下载');
  158. // setDownloadImage('img-' + bookId);
  159. // $id('img-' + bookId).classList.add('donghua');
  160. $id('download-' + bookId).style.display = 'none';
  161. $id('download-progress-'+bookId).style.display = 'block';
  162. bookSelf.setAttribute('download-start', 'true');
  163. //开始下载图书
  164. downloadSource(loadUrl, function() {
  165. var bookName = bookSelf.getAttribute('data-name');
  166. var dicCategoryId = bookSelf.getAttribute('data-category-id');
  167. var imgPath = bookSelf.getAttribute('data-img-path');
  168. var jsonList = bookSelf.getAttribute('data-json');
  169. var desc = bookSelf.getAttribute('data-desc');
  170. var newBook = {};
  171. newBook.id = bookId;
  172. //id,name,img_path,pdf_path,html_dist,html_name,dic_category_id,json,desc,status(0:无效,1:有效),is_download(0:没有下载,1:已经下载)
  173. newBook.name = bookName;
  174. newBook.imgPath = imgPath;
  175. newBook.desc = desc;
  176. newBook.status = 1;
  177. newBook.htmlName = htmlName;
  178. newBook.jsonList = jsonList;
  179. var jl = jsonList.split(',');
  180. var jll = jl.length;
  181. var progress = 1;
  182. for (var i = 0; i < jll; i++) {
  183. if (i == 0) continue;
  184. var suburl = jl[i];
  185. suburl = Routes.urls.book.getBooks + htmlDist + '/' + suburl;
  186. downloadSource(suburl, function() {
  187. progress += 1;
  188. var jindu = (progress / jll) * 100;
  189. $id('download-progress-'+bookId).innerHTML = parseInt(jindu)+'%';
  190. // console.log(jindu + '---------------------------------------------------')
  191. if (progress == jll) {
  192. saveBook(newBook, function() {
  193. window.__downloading = false;
  194. mui.toast(bookName + ',下载成功');
  195. // setImg('img-' + bookId, imgPath);
  196. // $id('img-' + bookId).classList.remove('donghua');
  197. bookSelf.setAttribute('data-is-download', '1');
  198. console.log('数据库更新成功');
  199. saveBookIds();
  200. $id('download-progress-'+bookId).style.display = 'none';
  201. });
  202. }
  203. }, function() {
  204. window.__downloading = false;
  205. mui.toast('下载失败');
  206. });
  207. }
  208. }, function() {
  209. mui.toast('下载失败');
  210. $id('download-' + bookId).style.display = 'block';
  211. bookSelf.setAttribute('download-start', 'false');
  212. });
  213. } else {
  214. var bookPath = DOWNLOADPATH + htmlName;
  215. var absoluteBookPath = convertToAbsoluteURL(bookPath);
  216. //已下载
  217. mui.openWindow({
  218. id: 'book-id',
  219. url: 'book.html',
  220. extras: {
  221. href: absoluteBookPath
  222. },
  223. show: {
  224. duration: 200
  225. }
  226. });
  227. }
  228. });
  229. }
  230. var oldBack = mui.back;
  231. mui.back = function() {
  232. // plus.webview.getWebviewById('tab-webview-subpage-first.html').reload();
  233. plus.webview.currentWebview().opener().evalJS("document.getElementById('books-id').innerHTML = '';window.start = 0;window.loadBooks(1);");
  234. oldBack();
  235. }
  236. </script>
  237. </html>