main_old.html 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  6. <meta name="apple-mobile-web-app-capable" content="yes">
  7. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  8. <title></title>
  9. <link href="css/mui.min.css" rel="stylesheet" />
  10. <link href="css/main.css" rel="stylesheet" />
  11. <link href="css/index.css" rel="stylesheet" />
  12. <script>
  13. ! function() {
  14. var e;
  15. e = function(e) {
  16. return function(e, t) {
  17. function i() {
  18. var t = r.getBoundingClientRect().width;
  19. t / m > 540 && (t = 540 * m);
  20. var i = t / 16;
  21. r.style.fontSize = i + "px", d.rem = e.rem = i
  22. }
  23. var a, n = e.document,
  24. r = n.documentElement,
  25. o = n.querySelector('meta[name="viewport"]'),
  26. l = n.querySelector('meta[name="flexible"]'),
  27. m = 0,
  28. s = 0,
  29. d = t.flexible || (t.flexible = {});
  30. if (o) {
  31. console.warn("将根据已有的meta标签来设置缩放比例");
  32. var c = o.getAttribute("content").match(/initial\-scale=([\d\.]+)/);
  33. c && (s = parseFloat(c[1]), m = parseInt(1 / s))
  34. } else if (l) {
  35. var p = l.getAttribute("content");
  36. if (p) {
  37. var u = p.match(/initial\-dpr=([\d\.]+)/),
  38. f = p.match(/maximum\-dpr=([\d\.]+)/);
  39. u && (m = parseFloat(u[1]), s = parseFloat((1 / m).toFixed(2))), f && (m = parseFloat(f[1]), s = parseFloat((1 / m).toFixed(2)))
  40. }
  41. }
  42. if (!m && !s) {
  43. var v = (e.navigator.appVersion.match(/android/gi), e.navigator.appVersion.match(/iphone/gi)),
  44. h = e.devicePixelRatio;
  45. m = v ? h >= 3 && (!m || m >= 3) ? 3 : h >= 2 && (!m || m >= 2) ? 2 : 1 : 1, s = 1 / m
  46. }
  47. if (r.setAttribute("data-dpr", m), !o)
  48. if (o = n.createElement("meta"), o.setAttribute("name", "viewport"), o.setAttribute("content", "initial-scale=" + s + ", maximum-scale=" + s + ", minimum-scale=" + s + ", user-scalable=no"), r.firstElementChild) r.firstElementChild.appendChild(o);
  49. else {
  50. var x = n.createElement("div");
  51. x.appendChild(o), n.write(x.innerHTML)
  52. }
  53. e.addEventListener("resize", function() {
  54. clearTimeout(a), a = setTimeout(i, 300)
  55. }, !1), e.addEventListener("pageshow", function(e) {
  56. e.persisted && (clearTimeout(a), a = setTimeout(i, 300))
  57. }, !1), "complete" === n.readyState ? n.body.style.fontSize = 12 * m + "px" : n.addEventListener("DOMContentLoaded", function(e) {
  58. n.body.style.fontSize = 12 * m + "px"
  59. }, !1), i(), d.dpr = e.dpr = m, d.refreshRem = i, d.rem2px = function(e) {
  60. var t = parseFloat(e) * this.rem;
  61. return "string" == typeof e && e.match(/rem$/) && (t += "px"), t
  62. }, d.px2rem = function(e) {
  63. var t = parseFloat(e) / this.rem;
  64. return "string" == typeof e && e.match(/px$/) && (t += "rem"), t
  65. }
  66. }(window, window.lib || (window.lib = {})), e
  67. }()
  68. }();
  69. </script>
  70. <style>
  71. html,
  72. body {
  73. background-color: #efeff4;
  74. }
  75. p {
  76. text-indent: 22px;
  77. }
  78. span.mui-icon {
  79. font-size: 14px;
  80. color: #007aff;
  81. margin-left: -15px;
  82. padding-right: 10px;
  83. }
  84. .mui-off-canvas-left {
  85. color: #fff;
  86. }
  87. .title {
  88. margin: 35px 15px 10px;
  89. }
  90. .title+.content {
  91. margin: 10px 15px 35px;
  92. color: #bbb;
  93. text-indent: 1em;
  94. font-size: 14px;
  95. line-height: 24px;
  96. }
  97. input {
  98. color: #000;
  99. }
  100. </style>
  101. </head>
  102. <body>
  103. <div id="offCanvasWrapper" class="mui-off-canvas-wrap mui-draggable">
  104. <!--侧滑菜单部分-->
  105. <aside id="offCanvasSide" class="mui-off-canvas-left">
  106. <div id="offCanvasSideScroll" class="mui-scroll-wrapper">
  107. <div class="mui-scroll">
  108. <div class="title" id="title_user">你好,XXX</div>
  109. <div class="title">设备选择</div>
  110. <ul class="mui-table-view mui-table-view-chevron mui-table-view-inverted" id="park">
  111. <li class="mui-table-view-cell">
  112. <a class="mui-navigate-right">
  113. Item 1
  114. </a>
  115. </li>
  116. <li class="mui-table-view-cell">
  117. <a class="mui-navigate-right">
  118. Item 2
  119. </a>
  120. </li>
  121. </ul>
  122. <div style="margin-top: 70%;">
  123. <div class="title" style="text-align: center;">新农宝盒 V2.0</div>
  124. <div style="text-align: center;">[退出账号]</div>
  125. </div>
  126. </div>
  127. </div>
  128. </aside>
  129. <div class="mui-inner-wrap">
  130. <header class="mui-bar mui-bar-nav">
  131. <a href="#offCanvasSide" class="mui-icon mui-action-menu mui-icon-bars mui-pull-left maze_menu" style="display:none;"></a>
  132. <a id="info" href="#" class="ico-msg has-msg"></a>
  133. <h1 class="mui-title">新农宝盒V2</h1>
  134. </header>
  135. <div id="offCanvasContentScroll" class="mui-content mui-scroll-wrapper">
  136. <div class="mui-content">
  137. <div class="index" id="device">
  138. </div>
  139. </div>
  140. </div>
  141. <!-- off-canvas backdrop -->
  142. <div class="mui-off-canvas-backdrop"></div>
  143. </div>
  144. </div>
  145. <script src="js/mui.min.js"></script>
  146. <script src="js/main.js"></script>
  147. <script type="text/javascript" charset="utf-8">
  148. (function($, self) {
  149. $.init
  150. ({
  151. beforeback: function(){
  152. //获得登录界面的webview
  153. var login = plus.webview.getWebviewById('login');
  154. //触发登录界面的自定义事件(refresh),从而进行数据刷新
  155. mui.fire(login,'refresh');
  156. //返回true,继续页面关闭逻辑
  157. return true;
  158. }
  159. });
  160. $.plusReady(function() {
  161. var state = app.getState();
  162. if(state.token)
  163. {
  164. self.getElementById('title_user').innerText = '你好,' + state.account;
  165. }
  166. //获取设备
  167. $.ajax('http://company.xinnongbaohe.com/info.farm_list?json=1', {
  168. dataType: 'text', //服务器返回json格式数据
  169. timeout: 10000, //超时时间设置为10秒;
  170. type: 'get', //HTTP请求类型
  171. success: function(r) {
  172. var t = JSON.parse(r);
  173. var html = '';
  174. var data = [];
  175. //t.reverse();
  176. for (var a in t) {
  177. data.push('<li class="mui-table-view-cell"><a class="mui-navigate-right park-list" vid="' + t[a].id + '" id="park_' + t[a].id + '">' + t[a].name + '</a></li>')
  178. }
  179. for (var a in data) {
  180. html += data[a];
  181. }
  182. document.getElementById("park").innerHTML = html;
  183. mui('.park-list').each(function() {
  184. document.getElementById(this.id).addEventListener('tap', function(e) {
  185. $.ajax('http://www.xinnongbaohe.com/index?farm=' + this.getAttribute('vid'), {
  186. dataType: 'text', //服务器返回json格式数据
  187. timeout: 10000, //超时时间设置为10秒;
  188. type: 'get', //HTTP请求类型
  189. success: function(r) {
  190. mui('#offCanvasWrapper').offCanvas('close');
  191. getDevice();
  192. }
  193. });
  194. });
  195. })
  196. }
  197. });
  198. function getDevice() {
  199. // 获取设备
  200. $.ajax('http://company.xinnongbaohe.com/info.park?json=1', {
  201. dataType: 'text', //服务器返回json格式数据
  202. timeout: 10000, //超时时间设置为10秒;
  203. type: 'get', //HTTP请求类型
  204. success: function(r) {
  205. //alert(t);
  206. var t = JSON.parse(r);
  207. //console.info(t);
  208. //var html = '<div class="item"><div class="device-list"><a href="#/tab/news" class="device-item index-news">消息通知</a><a href="#/tab/question" class="device-item index-questions">常见问题</a></div></div>';
  209. var html = '';
  210. html += '<div class="device-list">';
  211. var data = [];
  212. //t.reverse();
  213. for (var a in t) {
  214. //alert(t[a].name);
  215. if (t[a].type == 4) {
  216. data.push('<a page="business" name="' + t[a].name + '" tid="' + t[a].id + '" fid="' + t[a].farm_id + '" id="page_' + t[a].id + '" class="device-item index-two">' + t[a].name + '</a>');
  217. } else if (t[a].type == 3) {
  218. data.push('<a page="greenhouse" name="' + t[a].name + '" tid="' + t[a].id + '" fid="' + t[a].farm_id + '" id="page_' + t[a].id + '" class="device-item index-three">' + t[a].name + '</a>');
  219. }
  220. }
  221. //alert(data);
  222. //data.reverse();
  223. for (var a in data) {
  224. html += data[a];
  225. }
  226. html += '</div>';
  227. //window.localStorage['device'] = html;
  228. //alert(html);
  229. document.getElementById("device").innerHTML = html;
  230. var detailPage = null;
  231. mui('.device-item').each(function() {
  232. document.getElementById(this.id).addEventListener('tap', function(e) {
  233. var tid = this.getAttribute('tid');
  234. var fid = this.getAttribute('fid');
  235. var name = this.getAttribute('name');
  236. var page = this.getAttribute('page');
  237. //打开详情页面
  238. $.openWindow({
  239. id: page,
  240. url: page + '.html',
  241. extras: {
  242. tid: tid,
  243. fid: fid,
  244. name: name
  245. }
  246. });
  247. });
  248. })
  249. },
  250. error: function(xhr, type, errorThrown) {
  251. //异常处理;
  252. alert(type);
  253. console.log(type);
  254. }
  255. });
  256. }
  257. getDevice();
  258. });
  259. }(mui, document));
  260. </script>
  261. </body>
  262. </html>