main.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. <!--标准mui.css-->
  10. <link rel="stylesheet" href="css/mui.min.css">
  11. <!--App自定义的css-->
  12. <link rel="stylesheet" type="text/css" href="../css/app.css" />
  13. <style>
  14. .title {
  15. margin: 20px 15px 10px;
  16. color: #6d6d72;
  17. font-size: 15px;
  18. }
  19. .oa-contact-cell.mui-table .mui-table-cell {
  20. padding: 11px 0;
  21. vertical-align: middle;
  22. }
  23. .oa-contact-cell {
  24. position: relative;
  25. margin: -11px 0;
  26. }
  27. .oa-contact-avatar {
  28. width: 75px;
  29. }
  30. .oa-contact-avatar img {
  31. border-radius: 50%;
  32. }
  33. .oa-contact-content {
  34. width: 100%;
  35. }
  36. .oa-contact-name {
  37. margin-right: 20px;
  38. }
  39. .oa-contact-name,
  40. oa-contact-position {
  41. float: left;
  42. }
  43. body {
  44. background-color: #efeff4;
  45. }
  46. h5 {
  47. padding-top: 8px;
  48. padding-bottom: 8px;
  49. text-indent: 12px;
  50. }
  51. .mui-table-view.mui-grid-view .mui-table-view-cell .mui-media-body {
  52. font-size: 15px;
  53. margin-top: 8px;
  54. color: #333;
  55. }
  56. .my-mui-media-body {
  57. height: 30px !important;
  58. font-size: 18px !important;
  59. line-height: 30px !important;
  60. }
  61. .mui-media-object {
  62. width: 80% !important;
  63. }
  64. .mui-table-view-cell {
  65. padding-right:10px !important;
  66. }
  67. </style>
  68. </head>
  69. <body>
  70. <header class="mui-bar mui-bar-nav">
  71. <a id="search-id" class="mui-icon mui-icon-search mui-pull-right" style="display: none;"></a>
  72. <h1 class="mui-title">石油书吧</h1>
  73. </header>
  74. <nav class="mui-bar mui-bar-tab" id='menu-nav-id'>
  75. <a class="mui-tab-item mui-active" href="#tabbar">
  76. <span class="mui-icon mui-icon-contact" style="font-weight: bolder"></span>
  77. <span class="mui-tab-label" style="font-weight: bolder">书&nbsp;&nbsp;&nbsp;&nbsp;吧</span>
  78. </a>
  79. <a data-search='true' class="mui-tab-item" href="#tabbar-with-chat">
  80. <span class="mui-icon mui-icon-email" style="font-weight: bolder"></span>
  81. <span class="mui-tab-label" style="font-weight: bolder">书&nbsp;&nbsp;&nbsp;&nbsp;架</span>
  82. </a>
  83. <a class="mui-tab-item" href="#tabbar-with-map">
  84. <span class="mui-icon mui-icon-gear" style="font-weight: bolder"></span>
  85. <span class="mui-tab-label" style="font-weight: bolder">设&nbsp;&nbsp;&nbsp;&nbsp;置</span>
  86. </a>
  87. </nav>
  88. <div class="mui-content">
  89. <!--
  90. 描述:书吧
  91. -->
  92. <div id="tabbar" class="mui-control-content mui-active">
  93. <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
  94. <div class="mui-scroll" style="margin-top: 15px;">
  95. <ul id="books-id" class="mui-table-view mui-table-view-chevron">
  96. <li id="loading-id" class="mui-table-view-cell mui-media">
  97. <div style="text-align: center;margin-right: -60px;">加载中...</div>
  98. </li>
  99. </ul>
  100. </div>
  101. </div>
  102. </div>
  103. <!--
  104. 描述:书架
  105. -->
  106. <div id="tabbar-with-chat" class="mui-control-content">
  107. <ul id="book-list-id" class="mui-table-view mui-grid-view mui-grid-9">
  108. </ul>
  109. </div>
  110. <!--
  111. 描述:设置
  112. -->
  113. <div id="tabbar-with-map" class="mui-control-content">
  114. <div class="mui-scroll-wrapper">
  115. <div class="mui-scroll">
  116. <ul class="mui-table-view" style="margin-top: 20px;">
  117. <li class="mui-table-view-cell">
  118. <a id="tel" class="mui-navigate-right">
  119. 客服电话
  120. </a>
  121. </li>
  122. <li class="mui-table-view-cell" >
  123. <a id="feedback-btn" data-href="app/feedback.html" class="mui-navigate-right">
  124. 问题反馈
  125. </a>
  126. </li>
  127. </ul>
  128. <ul class="mui-table-view" style="margin-top: 20px;">
  129. <li class="mui-table-view-cell">
  130. <a id="update" class="mui-navigate-right">检查更新</a>
  131. </li>
  132. </ul>
  133. <ul class="mui-table-view" style="margin-top: 25px;">
  134. <li class="mui-table-view-cell">
  135. <a id="logout" data-href="logout" style="text-align: center;color: #FF3B30;">
  136. 退出登录
  137. </a>
  138. </li>
  139. </ul>
  140. </div>
  141. </div>
  142. </div>
  143. </div>
  144. </body>
  145. <script id="book-temp-id" type="text/html">
  146. <div class="mui-slider-right mui-disabled">
  147. <div class="mui-btn mui-btn-red" data-id='{id}'>删除</div>
  148. </div>
  149. <div class="mui-slider-handle">
  150. <a data-id='{id}' data-is-dowanload='{isDownload}' download-start='false' data-html-name='{htmlName}'>
  151. <img id="img-{id}" class="mui-media-object mui-pull-left">
  152. <div class="mui-media-body">
  153. {name}
  154. <p class='mui-ellipsis'>{desc}</p>
  155. </div>
  156. </a>
  157. </div>
  158. </script>
  159. <script type="text/html" id="category-temp-id">
  160. <!--<li class="mui-table-view-cell mui-media mui-col-xs-6">-->
  161. <a href="javascript:void(0)" data-title='{name}' data-id='{id}'>
  162. <img class="mui-media-object" id="img-category-{id}" style="width:130px !important;height: 80px !important;">
  163. <div class="mui-media-body my-mui-media-body">{name}</div>
  164. </a>
  165. <!--</li>-->
  166. </script>
  167. <!--
  168. 作者:52529860@qq.com
  169. 时间:2015-09-14
  170. 描述:主页
  171. -->
  172. <script type="text/javascript" src="js/jquery.min.js" type="text/javascript" charset="UTF-8"></script>
  173. <script type="text/javascript" src="http://182.92.109.194:8080/rpc/helper.js" type="text/javascript" charset="UTF-8"></script>
  174. <script src="js/mui.min.js" type="text/javascript" charset="utf-8"></script>
  175. <script src="js/routes.js" type="text/javascript" charset="utf-8"></script>
  176. <script src="js/update.js" type="text/javascript" charset="utf-8"></script>
  177. <script src="js/app.js" type="text/javascript" charset="utf-8"></script>
  178. <script src="js/db/service.js" type="text/javascript" charset="utf-8"></script>
  179. <script src="js/hzc.rpc.js" type="text/javascript" charset="utf-8"></script>
  180. <script>
  181. mui.init({
  182. swipeBack: false,
  183. pullRefresh: {
  184. container: '#pullrefresh',
  185. up: {
  186. contentrefresh: '正在加载...',
  187. callback: pullupRefresh
  188. }
  189. }
  190. });
  191. mui.plusReady(function() {
  192. // plus.screen.lockOrientation("portrait");
  193. loadBooks(1);
  194. initCategory();
  195. openBook();
  196. saveBookIds();
  197. openList();
  198. callPhone();
  199. checkUpdate();
  200. feedback();
  201. navTab();
  202. doSearch();
  203. deleteBook();
  204. logout();
  205. });
  206. /**
  207. * 删除图书
  208. */
  209. function deleteBook() {
  210. mui('#books-id').on('tap', '.mui-btn', function() {
  211. var elem = this;
  212. var btnArray = ['确认', '取消'];
  213. mui.confirm('确认删除该条记录?', '', btnArray, function(e) {
  214. if (e.index == 0) {
  215. var bookId = elem.getAttribute('data-id');
  216. deleteBooks(bookId, function() {
  217. saveBookIds(function() {})
  218. var li = elem.parentElement.parentElement;
  219. var p = li.parentElement;
  220. p.removeChild(li);
  221. console.log(p.children.length);
  222. if (p.children.length == 0) {
  223. var li = document.createElement('li');
  224. li.className = 'mui-table-view-cell mui-media';
  225. li.innerHTML = '<div style="text-align: center;">没有相关图书</div>';
  226. //p.appendChild('<li id="loading-id" class="mui-table-view-cell mui-media"><div style="text-align: center;margin-right: -60px;">加载中...</div></li>');
  227. p.appendChild(li);
  228. }
  229. });
  230. }
  231. });
  232. });
  233. }
  234. /**
  235. * 初始化图书分类
  236. */
  237. function initCategory() {
  238. listCategoryRpc(function(data) {
  239. // console.log(JSON.stringify(data));
  240. var htmlStr = '';
  241. // <li class="mui-table-view-cell mui-media"><div style="text-align: center;margin-right: -60px;">数据加载中...</div></li>
  242. if (data.length < 1) {
  243. htmlStr = '<div style="text-align: center;">没有相关数据</div>';
  244. $id('book-list-id').innerHTML = htmlStr;
  245. return;
  246. }
  247. $id('book-list-id').innerHTML = '';
  248. var tempHtml = $id('category-temp-id').innerHTML;
  249. for (var i = 0; i < data.length; i++) {
  250. var category = data[i];
  251. // console.log(JSON.stringify(category))
  252. var li = document.createElement('li');
  253. li.className = 'mui-table-view-cell mui-media mui-col-xs-6';
  254. li.innerHTML = render(tempHtml, category);
  255. $id('book-list-id').appendChild(li);
  256. category.imgPath = Routes.urls.book.bookUrl + category.img_path;
  257. setImg('img-category-' + category.id, category.imgPath);
  258. }
  259. });
  260. }
  261. window.count = 0;
  262. //分页查询我的book
  263. window.start = 0;
  264. /**
  265. * 上拉加载具体业务实现
  266. */
  267. function pullupRefresh() {
  268. setTimeout(function() {
  269. mui('#pullrefresh').pullRefresh().endPullupToRefresh((++window.count > 50)); //参数为true代表没有更多数据了。
  270. loadBooks(2);
  271. }, 1000);
  272. }
  273. /**
  274. * 加载图书
  275. * @param {Object} source:来源:1,初始化,2,上拉刷新
  276. */
  277. function loadBooks(source) {
  278. getMyBooks(window.start, function(data) {
  279. toastNetworkInfo('当前网络不可用');
  280. if (data.length < 1) {
  281. mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
  282. if (source == 1) {
  283. $id('books-id').innerHTML = '<li class="mui-table-view-cell mui-media"><div style="text-align: center;">没有相关图书</div></li>';
  284. } else {
  285. mui.toast('没有更多数据了');
  286. }
  287. return;
  288. }
  289. window.start += 5;
  290. var tempHtml = $id('book-temp-id').innerHTML;
  291. try {
  292. $id('loading-id').style.display = 'none';
  293. $id('loading-id').parentElement.removeChild($id('loading-id'))
  294. } catch (e) {}
  295. if (toastNetworkInfo('当前网络不可用')) {
  296. listDelPdfId(function(delData) {
  297. var delDataStr = delData.toString();
  298. // console.log(delDataStr)
  299. for (var i = 0; i < data.length; i++) {
  300. var book = data[i];
  301. if (delDataStr && !delDataStr.indexOf(book.id) > 0) {
  302. updateBookStatus(book.id, '0', function() {});
  303. continue;
  304. }
  305. var li = document.createElement('li');
  306. li.className = 'mui-table-view-cell mui-media';
  307. li.innerHTML = render(tempHtml, book);
  308. $id('books-id').appendChild(li);
  309. book.imgPath = Routes.urls.book.bookUrl + book.imgPath;
  310. setImg('img-' + book.id, book.imgPath);
  311. }
  312. });
  313. } else {
  314. for (var i = 0; i < data.length; i++) {
  315. var book = data[i];
  316. var li = document.createElement('li');
  317. li.className = 'mui-table-view-cell mui-media';
  318. li.innerHTML = render(tempHtml, book);
  319. $id('books-id').appendChild(li);
  320. book.imgPath = Routes.urls.book.bookUrl + book.imgPath;
  321. setImg('img-' + book.id, book.imgPath);
  322. }
  323. }
  324. });
  325. }
  326. /**
  327. * 打开书
  328. */
  329. function openBook() {
  330. mui('#books-id').on('tap', 'a', function() {
  331. var self = this;
  332. var htmlName = self.getAttribute('data-html-name');
  333. var bookPath = DOWNLOADPATH + htmlName;
  334. var absoluteBookPath = convertToAbsoluteURL(bookPath);
  335. mui.openWindow({
  336. id: 'book-id',
  337. url: 'app/book.html',
  338. extras: {
  339. href: absoluteBookPath
  340. },
  341. show: {
  342. duration: 200
  343. }
  344. })
  345. });
  346. }
  347. /**
  348. * 打开图书列表
  349. */
  350. function openList() {
  351. mui('#book-list-id').on('tap', 'a', function() {
  352. var title = this.getAttribute('data-title');
  353. var categoryId = this.getAttribute('data-id');
  354. if (toastNetworkInfo('当前网络不可用')) {
  355. var oldWin = plus.webview.getWebviewById('book-list-id-' + categoryId);
  356. if (oldWin) {
  357. oldWin.show();
  358. // plus.webview.getWebviewById('tab-webview-main-id').reload();
  359. return;
  360. }
  361. mui.openWindow({
  362. id: 'book-list-id-' + categoryId,
  363. url: 'app/book-list.html',
  364. extras: {
  365. title: title,
  366. categoryId: categoryId
  367. },
  368. show: {
  369. duration: 350
  370. }
  371. });
  372. // plus.webview.getWebviewById('tab-webview-main-id').reload();
  373. }
  374. });
  375. }
  376. //客服电话
  377. function callPhone() {
  378. document.getElementById("tel").addEventListener('tap', function() {
  379. plus.device.dial("114");
  380. });
  381. }
  382. function feedback() {
  383. document.getElementById("feedback-btn").addEventListener('tap', function() {
  384. mui.openWindow({
  385. id: 'feedback-id',
  386. url: this.getAttribute('data-href'),
  387. show: {
  388. duration: 200
  389. }
  390. })
  391. })
  392. }
  393. //检查更新
  394. function checkUpdate() {
  395. document.getElementById("update").addEventListener('tap', function() {
  396. update("inner");
  397. });
  398. }
  399. /**
  400. * 退出
  401. */
  402. function logout() {
  403. document.getElementById("logout").addEventListener('tap', function() {
  404. var btnArray = ['是', '否'];
  405. mui.confirm('确定要退出登录吗?', '', btnArray, function(e) {
  406. if (e.index == 0) {
  407. plus.downloader.clear();
  408. setLoginStatus('false');
  409. mui.openWindow({
  410. id: 'login-id',
  411. url: 'login.html',
  412. show: {
  413. duration: 200
  414. }
  415. });
  416. setTimeout(function() {
  417. plus.webview.getWebviewById('tab-webview-main-id').close();
  418. }, 2000);
  419. }
  420. });
  421. });
  422. }
  423. /**
  424. * 显示收藏
  425. */
  426. function navTab() {
  427. mui('#menu-nav-id').on('tap', 'a', function() {
  428. var data = this.getAttribute('data-search');
  429. if (data == 'true') {
  430. $id('search-id').style.display = 'block';
  431. } else {
  432. $id('search-id').style.display = 'none';
  433. }
  434. })
  435. }
  436. /**
  437. * 点击搜索
  438. */
  439. function doSearch() {
  440. document.getElementById("search-id").addEventListener('tap', function() {
  441. if (toastNetworkInfo('当前网络不可用')) {
  442. mui.openWindow({
  443. id: 'search-id',
  444. url: 'app/search.html',
  445. show: {
  446. duration: 200
  447. }
  448. });
  449. }
  450. });
  451. }
  452. //退出
  453. var backButtonPress = 0;
  454. mui.back = function(event) {
  455. backButtonPress++;
  456. if (backButtonPress > 1) {
  457. plus.downloader.clear();
  458. plus.runtime.quit();
  459. } else {
  460. plus.nativeUI.toast('再按一次退出应用');
  461. }
  462. setTimeout(function() {
  463. backButtonPress = 0;
  464. }, 1000);
  465. return false;
  466. };
  467. </script>
  468. </html>