dragIndex.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Hello MUI</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. <link rel="stylesheet" href="css/iconfont.css">
  11. <script src="js/mui.min.js"></script>
  12. <script src="js/routes.js"></script>
  13. <script src="js/app.js"></script>
  14. <script src="js/service.js"></script>
  15. <script src="js/update.js"></script>
  16. <style>
  17. html,
  18. body {
  19. background-color: #efeff4;
  20. }
  21. .mui-off-canvas-left {
  22. /*color: #fff;*/
  23. }
  24. .title {
  25. margin: 35px 15px 10px;
  26. margin-bottom: 20px;
  27. font-size: 24px;
  28. font-weight: 700;
  29. color: green;
  30. }
  31. .title+.content {
  32. margin: 10px 15px 35px;
  33. color: #bbb;
  34. text-indent: 1em;
  35. font-size: 14px;
  36. line-height: 24px;
  37. }
  38. #list {
  39. /*避免导航边框和列表背景边框重叠,看起来像两条边框似得;*/
  40. padding-top: 130px;
  41. margin-top: -1px;
  42. }
  43. #topPopover {
  44. position: fixed;
  45. top: 16px;
  46. right: 6px;
  47. width: 150px !important;
  48. z-index: 2;
  49. top: 60px !important;
  50. height: 140px;
  51. }
  52. #topPopover .mui-popover-arrow {
  53. left: auto;
  54. right: 6px;
  55. }
  56. .mui-popover {
  57. height: 100px;
  58. }
  59. .kaishi {
  60. width: 100px;
  61. height: 30px;
  62. border-radius: 4px;
  63. margin-left: auto;
  64. margin-right: auto;
  65. padding-top: 6px;
  66. background-color: #EA5555;
  67. color: white;
  68. font-size: 14px;
  69. }
  70. .biaoti {
  71. word-wrap: break-word;
  72. word-break: normal;
  73. white-space: normal;
  74. height: 90px;
  75. padding-top: 20px;
  76. padding-left: 15px;
  77. padding-right: 15px;
  78. font-size: 18px;
  79. }
  80. .zhang {
  81. height: 140px;
  82. width: 90%;
  83. margin: 0 auto;
  84. border: 1px solid lightgray;
  85. background-color: #F8F8F8;
  86. border-radius: 6px;
  87. }
  88. .zhang:active {
  89. background-color: #95DECA;
  90. border: 1px solid #95DECA;
  91. }
  92. .mui-media-li-self {
  93. margin-top: 30px;
  94. }
  95. .jindulan {
  96. height: 100%;
  97. background-color: #428bca;
  98. border-bottom-left-radius: 4px;
  99. border-top-left-radius: 4px;
  100. }
  101. .jindu {
  102. text-align: center;
  103. font-size: 12px;
  104. margin: 0 auto;
  105. width: 78%;
  106. height: 25px;
  107. border-radius: 4px;
  108. background-color: #E2E6E5;
  109. }
  110. .my-course-img-1 {
  111. /*margin-top: 50px !important;*/
  112. padding-bottom: 80px !important;
  113. background-size: 100% 150px;
  114. background-repeat: no-repeat;
  115. }
  116. .my-course-active {
  117. width: 3px;
  118. height: 100%;
  119. background-color: red;
  120. position: absolute;
  121. margin-top: -32px;
  122. margin-left: -10px;
  123. }
  124. .my-mui-navigate-right {
  125. background-color: red !important;
  126. }
  127. .my-mui-table-view {
  128. background-color: #EBEBEB !important;
  129. }
  130. </style>
  131. </head>
  132. <body style="margin: 0;padding: 0;">
  133. <div id="offCanvasWrapper" class="mui-off-canvas-wrap mui-draggable">
  134. <!--侧滑菜单部分-->
  135. <aside id="offCanvasSide" class="mui-off-canvas-left">
  136. <!--<div id="offCanvasSideScroll" class="mui-scroll-wrapper"><div class="mui-scroll">-->
  137. <div class="title">课程</div>
  138. <ul id="course-target-id" class="mui-table-view mui-table-view-chevron mui-table-view-inverted">
  139. </ul>
  140. <div id="btn-denglu-id" style="bottom: 30px;position: fixed;font-size: 20px;font-weight: 800;width: 100%;">
  141. <hr />
  142. <br />
  143. <a style="padding:10px;margin-left:10%;border-radius: 3px;">
  144. <span class="mui-icon mui-icon-person"></span>
  145. <span id="span-login-id">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;录&nbsp;&nbsp;</span>
  146. </a>
  147. </div>
  148. <!--</div></div>-->
  149. </aside>
  150. <!--主界面部分-->
  151. <div class="mui-inner-wrap" style="position: fixed !important;top: -2px !important;">
  152. <header class="mui-bar mui-bar-nav">
  153. <a href="#offCanvasSide" class="mui-icon mui-action-menu mui-icon-bars mui-pull-left"></a>
  154. <a id="info" class="mui-icon mui-pull-right"><i class="icon iconfont">&#xe730;</i></a>
  155. <h1 id="title" class="mui-title">交际英语</h1>
  156. </header>
  157. <div id="offCanvasContentScroll" class="mui-content mui-scroll-wrapper">
  158. <div class="mui-scroll" id="my-scroll">
  159. <ul id="list" class="mui-table-view mui-grid-view my-course-img-1 my-mui-table-view" style="height: 100% !important;">
  160. </ul>
  161. </div>
  162. </div>
  163. <!-- off-canvas backdrop -->
  164. <div class="mui-off-canvas-backdrop"></div>
  165. </div>
  166. </div>
  167. <!--右上角弹出菜单-->
  168. <div id="topPopover" class="mui-popover">
  169. <div class="mui-scroll-wrapper">
  170. <div class="mui-scroll">
  171. <ul class="mui-table-view">
  172. <li class="mui-table-view-cell">
  173. <a id="cuotiben" data-course-id="" data-href="app/review-chapter.html" data-type='2' style="color: red;">
  174. <i class="mui-icon icon iconfont icon-zhangben" style="margin-right: 10px;"></i>错题本
  175. </a>
  176. </li>
  177. <li class="mui-table-view-cell">
  178. <a id="shoucangben" data-course-id="" data-href="app/review-chapter.html" data-type='1' style="color: dodgerblue;">
  179. <i class="mui-icon icon iconfont icon-shu" style="margin-right: 10px;"></i>收藏本
  180. </a>
  181. </li>
  182. <li class="mui-table-view-cell">
  183. <a id="bijiben" data-course-id="" data-href="app/review-chapter.html" data-type='3' style="color: green;">
  184. <i class="mui-icon icon iconfont icon-shu" style="margin-right: 10px;"></i>笔记本
  185. </a>
  186. </li>
  187. </ul>
  188. </div>
  189. </div>
  190. </div>
  191. <script type="text/html" id="template-course-id">
  192. <li class="mui-table-view-cell">
  193. <a class="mui-navigate-right" data-id="{code}" data-href="dragIndex.html">{name}</a>
  194. </li>
  195. </script>
  196. <script type="text/html" id="template-chapter-id">
  197. <li class="mui-table-view-cell mui-media mui-col-xs-12 mui-media-li-self">
  198. <a href="app/section.html" data-title="{name}" data-chapter-id='{code}'>
  199. <div class="zhang">
  200. <div class=" biaoti">
  201. {name}
  202. </div>
  203. <div class="jindu" style="text-align: center;">
  204. <div class="jindulan" style="width: {progress}%;">
  205. </div>
  206. <div style="margin-top:-22px;font-size: 12px;color: #4D4D4D;">已完成{progress}%</div>
  207. </div>
  208. </div>
  209. </a>
  210. </li>
  211. </script>
  212. <script type="text/javascript">
  213. function setBackgrounImage() {
  214. //课程上部插图
  215. if (window.self.courseTitle == "交际英语") {
  216. window.myimage = 'url(images/englishchatu-1.png)';
  217. } else if (window.self.courseTitle == "阅读理解") {
  218. window.myimage = 'url(images/englishchatu-2.png)';
  219. } else if (window.self.courseTitle == "词汇与结构") {
  220. window.myimage = 'url(images/englishchatu-3.png)';
  221. } else if (window.self.courseTitle == "完形填空") {
  222. window.myimage = 'url(images/englishchatu-4.png)';
  223. } else if (window.self.courseTitle == "英译汉复习资料") {
  224. window.myimage = 'url(images/englishchatu-5.png)';
  225. } else {
  226. window.myimage = 'url(images/englishchatu-6.png)';
  227. }
  228. }
  229. /*--------------------------------------------------------------------------------------------------*/
  230. /**
  231. * 初始化章
  232. */
  233. function initChapterDom() {
  234. queryCategory(window.self.courseId, function(rows) {
  235. var scriptCourse = document.getElementById('template-chapter-id');
  236. var template = scriptCourse.innerHTML;
  237. var htmlStr = '';
  238. for (var i = 0; i < rows.length; i++) {
  239. var row = rows[i];
  240. htmlStr += render(template, row);
  241. }
  242. var ct = document.getElementById('list');
  243. ct.innerHTML = htmlStr;
  244. mui('#offCanvasContentScroll').scroll().scrollTo(0, 0);
  245. document.getElementById("list").style.backgroundImage = window.myimage;
  246. });
  247. }
  248. /**
  249. * 初始化菜单
  250. * @param {Object} rows
  251. */
  252. function initMenuDom(rows) {
  253. var scriptCourse = document.getElementById('template-course-id');
  254. var template = scriptCourse.innerHTML;
  255. var htmlStr = '';
  256. for (var i = 0; i < rows.length; i++) {
  257. var row = rows[i];
  258. htmlStr += render(template, row);
  259. }
  260. var ct = document.getElementById('course-target-id');
  261. ct.innerHTML = htmlStr;
  262. }
  263. /**
  264. * 菜单点击
  265. */
  266. function courseClickEvent() {
  267. mui('#course-target-id').on('tap', 'a', function() {
  268. window.offCanvasWrapper.offCanvas('close');
  269. var courseId = this.getAttribute('data-id');
  270. window.self.courseTitle = ('' + this.innerHTML).trim();
  271. updateTitle();
  272. setBackgrounImage();
  273. window.self.courseId = courseId;
  274. initCourseId();
  275. initChapterDom();
  276. });
  277. }
  278. /**
  279. * 点击章时间
  280. */
  281. function chapterTapEvent() {
  282. mui('#list').on('tap', 'a', function() {
  283. var chapterTitle = this.getAttribute('data-title');
  284. var chapterId = this.getAttribute('data-chapter-id');
  285. mui.openWindow({
  286. id: 'section-win-' + chapterId,
  287. url: this.href,
  288. waiting: {
  289. autoShow: true
  290. },
  291. extras: {
  292. chapterTitle: chapterTitle,
  293. chapterId: chapterId
  294. }
  295. })
  296. });
  297. }
  298. //右上角菜单点击事件(收藏本、错题本)
  299. function rightBarTapEvent() {
  300. mui('#topPopover').on('tap', 'a', function() {
  301. var courseId = this.getAttribute('data-course-id');
  302. var href = this.getAttribute('data-href');
  303. var type = this.getAttribute('data-type');
  304. var title = this.innerHTML;
  305. if (type == 3) { // TODO 这个在实现后,记得删除,这是笔记本的处理逻辑
  306. alert('近期上线,敬请期待');
  307. return;
  308. }
  309. mui.openWindow({
  310. id: 'bar-' + courseId,
  311. url: href,
  312. waiting: {
  313. autoShow: true
  314. },
  315. extras: {
  316. barTitle: title,
  317. courseId: courseId,
  318. type: type
  319. }
  320. })
  321. mui("#topPopover").popover("toggle");
  322. });
  323. }
  324. /**
  325. * 更新标题
  326. */
  327. function updateTitle() {
  328. var courseTitle = window.self.courseTitle;
  329. if (courseTitle) {
  330. var titleDom = document.getElementById('title');
  331. titleDom.innerHTML = courseTitle;
  332. } else {
  333. window.self.courseTitle = '交际英语';
  334. }
  335. setBackgrounImage();
  336. }
  337. /**
  338. * 点击应用,打开收藏本、错题本
  339. */
  340. function infoTapEvent() {
  341. document.getElementById('info').addEventListener('tap', function() {
  342. mui("#topPopover").popover("toggle");
  343. });
  344. }
  345. function initCourseId() {
  346. var cuotiben = document.getElementById('cuotiben');
  347. var shoucangben = document.getElementById('shoucangben');
  348. var bijiben = document.getElementById('bijiben');
  349. cuotiben.setAttribute("data-course-id", window.self.courseId);
  350. shoucangben.setAttribute('data-course-id', window.self.courseId);
  351. bijiben.setAttribute('data-course-id', window.self.courseId);
  352. }
  353. /**
  354. * 不管登录与否,打开app即检查服务器端的category(大纲)是否有更新
  355. */
  356. function ajaxAppVersion() {
  357. var localCategoryVersion = window.localStorage.getItem('category_version');
  358. if (!localCategoryVersion) {
  359. window.localStorage.setItem('category_version', 1);
  360. localCategoryVersion = window.localStorage.getItem('category_version');
  361. }
  362. mui.ajax(Routes.urls.syncdata.getAppVersion, {
  363. data: {},
  364. dataType: 'json', //服务器返回json格式数据
  365. type: 'post', //HTTP请求类型
  366. timeout: 10000, //超时时间设置为10秒;
  367. success: function(data) {
  368. if (data && data.version) {
  369. updateLocalAppVersion(data.version);
  370. }
  371. }
  372. });
  373. }
  374. /**
  375. * 启动自动登录
  376. */
  377. function autoLogin() {
  378. var phone = window.localStorage.getItem("phone");
  379. var password = window.localStorage.getItem("password");
  380. if (phone == null || password == null) {
  381. //TODO 最后需要打开这个
  382. window.localStorage.setItem('isAlreadyLogin', false);
  383. return;
  384. }
  385. /**
  386. * 登录请求
  387. */
  388. mui.ajax(Routes.urls.user.login, {
  389. data: {
  390. username: phone,
  391. password: password
  392. },
  393. dataType: 'json', //服务器返回json格式数据
  394. type: 'post', //HTTP请求类型
  395. timeout: 10000, //超时时间设置为10秒;
  396. success: function(data) {
  397. // TODO 这个地方需要在生产环境下去掉
  398. // data.success = true;
  399. if (data && data.success) {
  400. //记录用户登录信息
  401. window.localStorage.setItem('isAlreadyLogin', true);
  402. window.localStorage.setItem("phone", phone);
  403. window.localStorage.setItem("password", password);
  404. updateUserInfoToLocal();
  405. } else {
  406. window.localStorage.setItem('isAlreadyLogin', false);
  407. mui.toast(data.message);
  408. }
  409. },
  410. error: function() {}
  411. });
  412. }
  413. function updateDengluMenu() {
  414. var loginSpan = document.getElementById("span-login-id");
  415. var phone = window.localStorage.getItem("phone");
  416. if (phone && phone.length == 11) {
  417. loginSpan.innerText = '个人中心';
  418. }
  419. }
  420. /**
  421. * 初始化登录
  422. */
  423. function initDenglu() {
  424. alreadyLogin(function() {
  425. var loginSpan = document.getElementById("span-login-id");
  426. loginSpan.innerText = '个人中心';
  427. }, function() {
  428. var loginSpan = document.getElementById("span-login-id")
  429. loginSpan.innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;登&nbsp;&nbsp;录&nbsp;&nbsp;';
  430. });
  431. }
  432. /**
  433. * 注册登录事件
  434. */
  435. function dengluEvent() {
  436. document.getElementById("btn-denglu-id").addEventListener('tap', function() {
  437. var loginSpan = this;
  438. var phone = window.localStorage.getItem("phone");
  439. if (phone && phone.length == 11) {
  440. mui.openWindow({
  441. id: 'personal-win',
  442. url: 'app/personal.html',
  443. waiting: {
  444. autoShow: false
  445. }
  446. })
  447. } else {
  448. mui.openWindow({
  449. id: 'login-win',
  450. url: 'app/login.html',
  451. waiting: {
  452. autoShow: false
  453. },
  454. extras: {
  455. sectionId: window.sectionId,
  456. gotoUrl: '../dragIndex.html',
  457. serviceObj: window.serviceObj
  458. }
  459. });
  460. }
  461. });
  462. }
  463. /**
  464. * 个推消息记录
  465. */
  466. function getuiEvent() {
  467. try {
  468. /**
  469. * 个推的透传,使用key--value对,会重写msg中的title和content
  470. * title:正确,content:错误,则title是正确的信息,content则为json格式的数据
  471. * title:错误,content:正确,则title为“个推”,content是正确的信息
  472. */
  473. plus.push.addEventListener("receive", function(msg) {
  474. try {
  475. //用户推送输入错误,则不再保存消息
  476. var contents = msg.content;
  477. var contentJson = JSON.parse(contents);
  478. } catch (e) {
  479. //用户推送正确的信息,保存信息到消息中心
  480. saveMessage(msg);
  481. if (msg) {
  482. mui.openWindow({
  483. id: "msg-center-win",
  484. url: "app/msg-center.html",
  485. waiting: {
  486. autoShow: true
  487. }
  488. });
  489. }
  490. }
  491. });
  492. } catch (e) {}
  493. }
  494. mui.init();
  495. mui.plusReady(function() {
  496. ajaxAppVersion();
  497. window.self = plus.webview.currentWebview();
  498. if (!window.self.courseId) {
  499. window.self.courseId = '0001';
  500. }
  501. //查询所有课程,加载课程菜单
  502. queryAllCourse(function(rows) {
  503. initChapterDom();
  504. initMenuDom(rows);
  505. courseClickEvent();
  506. chapterTapEvent();
  507. updateTitle();
  508. });
  509. initCourseId();
  510. rightBarTapEvent();
  511. dengluEvent();
  512. initDenglu();
  513. autoLogin();
  514. getuiEvent();
  515. infoTapEvent();
  516. setTimeout(function() {
  517. initUpdate();
  518. }, 2000);
  519. window.offCanvasWrapper = mui('#offCanvasWrapper');
  520. });
  521. //首页返回键处理
  522. //处理逻辑:1秒内,连续两次按返回键,则退出应用;
  523. var first = null;
  524. mui.back = function() {
  525. //首次按键,提示‘再按一次退出应用’
  526. if (!first) {
  527. first = new Date().getTime();
  528. mui.toast('再按一次退出应用');
  529. setTimeout(function() {
  530. first = null;
  531. }, 1000);
  532. } else {
  533. if (new Date().getTime() - first < 1000) {
  534. plus.runtime.quit();
  535. }
  536. }
  537. }
  538. function call() {
  539. //切换到拨打电话界面,但是不会直接拨打
  540. //plus.device.dial("153",false);
  541. //此方法可直接拨打电话
  542. // 导入Activity、Intent类
  543. var Intent = plus.android.importClass("android.content.Intent");
  544. var Uri = plus.android.importClass("android.net.Uri");
  545. // 获取主Activity对象的实例
  546. var main = plus.android.runtimeMainActivity();
  547. // 创建Intent
  548. var uri = Uri.parse("tel:4001109999"); // 这里可修改电话号码
  549. var call = new Intent("android.intent.action.CALL", uri);
  550. // 调用startActivity方法拨打电话
  551. main.startActivity(call);
  552. }
  553. </script>
  554. </body>
  555. </html>