login.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0, user-scalable=no">
  7. <title>FrozenUI Demo</title>
  8. <link rel="stylesheet" href="../css/mui.min.css">
  9. <link rel="stylesheet" type="text/css" href="../css/reset.css" />
  10. <link rel="stylesheet" type="text/css" href="../css/iconfont.css" />
  11. <style type="text/css">
  12. html {
  13. height: 100%;
  14. }
  15. body {
  16. height: 100%;
  17. background: #fff;
  18. }
  19. .page {
  20. height: 100%;
  21. overflow: hidden;
  22. }
  23. .logo {
  24. text-align: center;
  25. margin: 6rem 0 4.5rem;
  26. }
  27. .logo >img{
  28. width: 50%;
  29. }
  30. .logo h1{
  31. color: #2DADF6;
  32. font-size: 24px;
  33. }
  34. .logoCover {
  35. width: 80%;
  36. margin: 0 auto;
  37. }
  38. .logoItem {
  39. border-bottom: 1px solid #bbb;
  40. position: relative;
  41. height: 40px;
  42. margin-bottom: 15px;
  43. }
  44. .logoItem .inputicon {
  45. font-size: 22px;
  46. color: #22ace1;
  47. vertical-align: middle;
  48. position: absolute;
  49. left: 0;
  50. bottom: 8px;
  51. }
  52. #recordPwdIcon{
  53. color: #22ace1;
  54. }
  55. .logoItem input {
  56. background: transparent;
  57. border: none;
  58. padding: 0 0 4px 35px;
  59. position: absolute;
  60. left: 0;
  61. bottom: 0;
  62. margin: 0;
  63. }
  64. .logoItem .unlock {
  65. font-size: 29px;
  66. }
  67. input::-webkit-input-placeholder {
  68. color: #969696;
  69. }
  70. input::-moz-placeholder {
  71. /* Mozilla Firefox 19+ */
  72. color: #969696;
  73. }
  74. input:-moz-placeholder {
  75. /* Mozilla Firefox 4 to 18 */
  76. color: #969696;
  77. }
  78. input:-ms-input-placeholder {
  79. /* Internet Explorer 10-11 */
  80. color: #969696;
  81. }
  82. #forgetPwd,
  83. #registerBtn,
  84. .recordPwdLabel,
  85. .logoItem input {
  86. color: #bbb;
  87. }
  88. #loginBtn {
  89. width: 100%;
  90. /*line-height: 30px;*/
  91. font-size: 18px;
  92. letter-spacing: 6px;
  93. border-radius: 6px;
  94. margin: 20px 0 13px;
  95. color: #bbb;
  96. }
  97. #loginBtn:enabled:active{
  98. color: #fff;
  99. border: 1px solid #39c7fc;
  100. background-color: #39c7fc !important;
  101. }
  102. #loginBtn.btn-primary{
  103. background-color: #05a0db;
  104. border: 1px solid #12a5dc;
  105. color: #fff;
  106. }
  107. /*记住密码*/
  108. .checkbox {
  109. display: none;
  110. }
  111. #addUser {
  112. position: fixed;
  113. left: 0;
  114. right: 0;
  115. bottom: 10px;
  116. text-align: center;
  117. }
  118. /**/
  119. .lookpsd{
  120. position: absolute;
  121. right: 6px;
  122. bottom: 8px;
  123. font-size: 27px;
  124. color: #c1c1c1;
  125. }
  126. #lookpsdBox,#openeye{
  127. display: none;
  128. }
  129. </style>
  130. </head>
  131. <body>
  132. <div class="page">
  133. <div class="logo">
  134. <img src="../images/commonLogoTxt.png" alt="云飞智能科技" />
  135. <!--<h1>智慧农业物联网</h1>-->
  136. </div>
  137. <div class="logoCover">
  138. <div class="logoInner">
  139. <form action="" method="post">
  140. <ul>
  141. <li class="logoItem">
  142. <i class="iconfont inputicon">&#xe636;</i>
  143. <input type="text" id="username" placeholder="请输入用户名" />
  144. </li>
  145. <li class="logoItem">
  146. <i class="iconfont inputicon">&#xe689;</i>
  147. <input type="password" id="password" placeholder="请输入密码" />
  148. <span id="lookpsdBox">
  149. <i class="iconfont lookpsd" id="openeye" onclick="openpsd()">&#xe62d;</i> <!--看-->
  150. <i class="iconfont lookpsd" id="closeeye" onclick="closepsd()">&#xe61d;</i> <!--闭-->
  151. </span>
  152. </li>
  153. </ul>
  154. <input type="button" id="loginBtn" value="登录" />
  155. </form>
  156. </div>
  157. <div class="otherBtns">
  158. <div class="mui-row">
  159. <div class="mui-col-xs-6">
  160. <!--<i class="iconfont" id="recordPwdIcon">&#xe614;</i>-->
  161. <label class="recordPwdLabel" for="recordPwd">
  162. <i class="iconfont" id="recordPwdIcon">&#xe614;</i>
  163. <input type="checkbox" class="checkbox" id="recordPwd" />
  164. <span>自动登录</span>
  165. </label>
  166. </div>
  167. <div class="mui-col-xs-6" style="text-align: right;">
  168. <a href="" id="forgetPwd">忘记密码?</a>
  169. </div>
  170. </div>
  171. </div>
  172. <div id="addUser">
  173. <!--<a href="javascript:;" id="registerBtn">创建新账户+</a>-->
  174. </div>
  175. </div>
  176. </div>
  177. </body>
  178. <script src="../js/mui.min.js"></script>
  179. <script>
  180. mui.init();
  181. mui.plusReady(function() {
  182. var all = plus.webview.all();
  183. var current = plus.webview.currentWebview().id;
  184. var index = plus.runtime.appid;
  185. console.log(all)
  186. for (var i = 0, len = all.length; i < len; i++) {
  187. if (all[i].id !== current && all[i].id != index) {
  188. all[i].hide();
  189. all[i].close();
  190. }
  191. }
  192. autoLogin()
  193. var windowInnerHeight = window.innerHeight;
  194. //解决fixed问题
  195. window.onresize = function() {
  196. if(window.innerHeight < windowInnerHeight) {
  197. document.getElementById("addUser").style.position = 'static';
  198. } else {
  199. document.getElementById("addUser").style.position = 'fixed';
  200. }
  201. }
  202. var username = document.getElementById('username'),
  203. password = document.getElementById('password');
  204. //登录颜色
  205. password.addEventListener('keyup', function() {
  206. var passwordVal = this.value;
  207. var usernameVal = username.value;
  208. //查看密码
  209. if(passwordVal.length >= 1) {
  210. document.getElementById('lookpsdBox').style.display = 'block';
  211. }else{
  212. document.getElementById('lookpsdBox').style.display = 'none';
  213. }
  214. //是否能登录
  215. if(passwordVal.length >= 6 && usernameVal != '') {
  216. document.getElementById("loginBtn").classList.add("btn-primary");
  217. } else {
  218. document.getElementById("loginBtn").classList.remove("btn-primary");
  219. }
  220. //键盘确定登录
  221. if(event.keyCode ==13){
  222. login(usernameVal, passwordVal);
  223. }
  224. })
  225. //监听查看密码
  226. // password.addEventListener('input', function() {
  227. // alert(1);;
  228. // })
  229. //记住密码
  230. mui(".otherBtns").on('tap', ".recordPwdLabel", function() {
  231. remFun()
  232. })
  233. function remFun() {
  234. if(!document.getElementById("recordPwd").checked) {
  235. document.getElementById('recordPwdIcon').innerHTML = '&#xe656;';
  236. plus.storage.setItem('remState', 'true'); //设置本地存储
  237. } else {
  238. document.getElementById('recordPwdIcon').innerHTML = '&#xe614;';
  239. plus.storage.setItem('remState', 'false'); //设置本地存储
  240. }
  241. }
  242. function autoLogin() {
  243. var username = plus.storage.getItem('username');
  244. var password = plus.storage.getItem('password');
  245. var remState = plus.storage.getItem('remState');
  246. console.log(plus.storage.getItem('username'))
  247. console.log(plus.storage.getItem('password'))
  248. console.log(plus.storage.getItem('remState'))
  249. if(remState == 'true' || remState == true) {
  250. login(username, password);
  251. }
  252. }
  253. //登录
  254. document.getElementById("loginBtn").addEventListener('tap', function() {
  255. if(this.className == 'btn-primary') {
  256. login(username.value, password.value)
  257. } else {
  258. mui.toast('请将信息填写完整');
  259. }
  260. })
  261. function login(name, pwd) {
  262. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  263. mui.toast("网络异常,请检查网络设置!");
  264. } else {
  265. mui.ajax('http://192.168.1.11:8000/app_login', {
  266. data: {
  267. 'username': name,
  268. 'password': pwd
  269. },
  270. dataType: 'json', //服务器返回json格式数据
  271. type: 'post', //HTTP请求类型
  272. timeout: 10000, //超时时间设置为10秒;
  273. success: function(data) {
  274. plus.storage.setItem('username', name); //设置本地存储
  275. plus.storage.setItem('password', pwd); //设置本地存储
  276. if(data.code == 0) {
  277. if(data.role == 'user'){
  278. plus.storage.setItem('isuser', 'user'); //普通用户
  279. }else if(data.role == 'agency'){
  280. plus.storage.setItem('isuser', 'agency'); //代理商
  281. }else{
  282. plus.storage.setItem('isuser', 'admin'); //管理员
  283. }
  284. mui.openWindow({
  285. url: 'main.html',
  286. id: 'main',
  287. extras: {
  288. name: 'mui' //扩展参数
  289. },
  290. })
  291. } else if(data.code == 1) {
  292. mui.toast('用户不存在');
  293. } else if(data.code == 2) {
  294. mui.toast('用户不可用');
  295. } else if(data.code == 3) {
  296. mui.toast('密码错误');
  297. }
  298. },
  299. error: function(xhr, type, errorThrown) {
  300. // console.log(type)
  301. console.log(errorThrown)
  302. mui.toast('登录请求失败');
  303. }
  304. });
  305. }
  306. }
  307. })
  308. //查看密码
  309. function openpsd(){
  310. document.getElementById('openeye').style.display = 'none';
  311. document.getElementById('closeeye').style.display = 'block';
  312. document.getElementById('password').setAttribute('type','password');
  313. }
  314. //隐藏密码
  315. function closepsd(){
  316. document.getElementById('openeye').style.display = 'block';
  317. document.getElementById('closeeye').style.display = 'none';
  318. document.getElementById('password').setAttribute('type','text');
  319. }
  320. //注册
  321. mui('#addUser').on('tap','#registerBtn',function(){
  322. mui.openWindow({
  323. url:'register.html',
  324. id:'register'
  325. })
  326. })
  327. //退出应用
  328. mui.oldback = mui.back;
  329. var clickNum = 0;
  330. mui.back = function(event) {
  331. clickNum++;
  332. if(clickNum > 1) {
  333. plus.runtime.quit();
  334. } else {
  335. mui.toast("再按一次退出应用");
  336. }
  337. setTimeout(function() {
  338. clickNum = 0
  339. }, 1000);
  340. return false;
  341. }
  342. //测试网络
  343. // document.addEventListener("netchange", networkinfo, false);
  344. function networkinfo() {
  345. if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
  346. mui.toast("网络异常,请检查网络设置!");
  347. }
  348. }
  349. </script>
  350. </html>