login.html 9.6 KB

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