index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
  6. <link rel="stylesheet" href="./css/element.css">
  7. <script src="./js/babel.min.js"></script>
  8. <script src="./js/vue.js"></script>
  9. <script src="./js/axios.min.js"></script>
  10. <script src="./js/element.js"></script>
  11. <title>大卫博士-防伪查询</title>
  12. <script type="text/javascript">
  13. document.addEventListener('plusready', function() {
  14. //console.log("所有plus api都应该在此事件发生后调用,否则会出现plus is undefined。")
  15. });
  16. </script>
  17. <style>
  18. * {
  19. margin: 0;
  20. padding: 0;
  21. }
  22. html,
  23. body,
  24. #app {
  25. width: 100%;
  26. height: 100%;
  27. display: flex;
  28. justify-content: flex-start;
  29. flex-direction: column;
  30. }
  31. .LoginContainer {
  32. flex: 1;
  33. overflow: hidden;
  34. padding: 80px 25px;
  35. box-sizing: border-box;
  36. /* display: flex;
  37. justify-content: space-between;
  38. flex-direction: column; */
  39. }
  40. .LoginHeader {
  41. color: #333333;
  42. width: 100%;
  43. margin-bottom: 30px;
  44. }
  45. .LoginHeader>p {
  46. display: inline-block;
  47. color: #333333;
  48. font-size: 32px;
  49. /* position: relative; */
  50. }
  51. /* .LoginHeader>p:after {
  52. content: "";
  53. display: block;
  54. width: 25px;
  55. height: 8px;
  56. background: linear-gradient(to right, #A080FF, #5D6BFF);
  57. position: absolute;
  58. right: -15px;
  59. bottom: 5px;
  60. z-index: -1;
  61. } */
  62. .FormInput {
  63. width: 100%;
  64. border: none;
  65. border-bottom: 1px solid #EEEEEE;
  66. padding: 15px 0;
  67. margin-bottom: 15px;
  68. outline: none;
  69. }
  70. .LoginSubmit {
  71. width: calc(100% - 40px);
  72. height: 48px;
  73. margin: 20px auto 0;
  74. border-radius: 48px;
  75. text-align: center;
  76. line-height: 48px;
  77. color: #FFFFFF;
  78. font-size: 20px;
  79. background: linear-gradient(to right, #A080FF, #5D6BFF);
  80. }
  81. /* [v-cloak]{
  82. display: none !important;
  83. } */
  84. </style>
  85. </head>
  86. <!-- <body v-cloak>
  87. <div id="app" v-cloak> -->
  88. <body>
  89. <div id="app">
  90. <div class="LoginContainer">
  91. <div class="LoginHeader">
  92. <p>登录</p>
  93. </div>
  94. <div class="LoginForm">
  95. <input v-model="phone" type="text" placeholder="请输入手机号" class="FormInput">
  96. <input v-model="password" type="password" placeholder="请输入密码" class="FormInput">
  97. </div>
  98. <p class="LoginSubmit" @click="noMultipleClicks(toLogin)">确认登录</p>
  99. </div>
  100. </div>
  101. <script type="text/babel">
  102. var app = new Vue({
  103. el: '#app',
  104. data() {
  105. return {
  106. noClick: true,
  107. phone:'',
  108. password:'',
  109. }
  110. },
  111. mounted() {
  112. this.isLogin()
  113. },
  114. methods: {
  115. // 防连点
  116. noMultipleClicks(methods) {
  117. let that = this;
  118. if (that.noClick) {
  119. that.noClick= false;
  120. methods();
  121. setTimeout(function () {
  122. that.noClick= true;
  123. }, 1500)
  124. }
  125. },
  126. isLogin() {
  127. let token = window.localStorage.getItem("token")
  128. if(token) {
  129. this.checkLoginTokenSuccess()
  130. }
  131. },
  132. checkLoginTokenSuccess() {
  133. let loading = window.ELEMENT.Loading.service()
  134. let _this = this
  135. axios.get('http://fangw.jiuweiyun.cn/api/get_good', {
  136. headers: {
  137. Authorization: `Bearer ` + localStorage.getItem("token")
  138. }
  139. }).then(res => {
  140. loading.close()
  141. if(res.code === 200) {
  142. window.location.href = "./pages/product.html"
  143. } else {
  144. window.localStorage.removeItem("token")
  145. }
  146. }).catch(() => {
  147. loading.close()
  148. window.localStorage.removeItem("token")
  149. })
  150. },
  151. toLogin() {
  152. if(!this.phone) {
  153. window.ELEMENT.Message.error('请输入手机号')
  154. return false
  155. }
  156. if(!this.password) {
  157. window.ELEMENT.Message.error('请输入密码')
  158. return false
  159. }
  160. let loading = window.ELEMENT.Loading.service()
  161. let _this = this
  162. axios.post('http://fangw.jiuweiyun.cn/api/login/ChangeAppLogin', {
  163. phone: _this.phone,
  164. password: _this.password
  165. }).then(res => {
  166. if (res.code === 200) {
  167. window.localStorage.setItem('token', res.data.token)
  168. window.ELEMENT.Message.success('登录成功')
  169. window.location.href = "./pages/product.html"
  170. loading.close()
  171. } else {
  172. window.ELEMENT.Message.error(res.msg || '登录失败')
  173. loading.close()
  174. }
  175. }).catch(() => {
  176. loading.close()
  177. window.ELEMENT.Message.error('登录失败')
  178. })
  179. }
  180. }
  181. })
  182. </script>
  183. </body>
  184. </html>