index.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. }
  44. .LoginHeader>p {
  45. display: inline-block;
  46. color: #333333;
  47. font-size: 32px;
  48. position: relative;
  49. }
  50. .LoginHeader>p:after {
  51. content: "";
  52. display: block;
  53. width: 25px;
  54. height: 8px;
  55. background: linear-gradient(to right, #A080FF, #5D6BFF);
  56. position: absolute;
  57. right: -15px;
  58. bottom: 5px;
  59. z-index: -1;
  60. }
  61. .FormInput {
  62. width: 100%;
  63. border: none;
  64. border-bottom: 1px solid #EEEEEE;
  65. padding: 15px 0;
  66. margin-bottom: 15px;
  67. outline: none;
  68. }
  69. .LoginSubmit {
  70. width: calc(100% - 40px);
  71. height: 48px;
  72. margin: 0 auto;
  73. border-radius: 48px;
  74. text-align: center;
  75. line-height: 48px;
  76. color: #FFFFFF;
  77. font-size: 20px;
  78. background: linear-gradient(to right, #A080FF, #5D6BFF);
  79. }
  80. /* [v-cloak]{
  81. display: none !important;
  82. } */
  83. </style>
  84. </head>
  85. <!-- <body v-cloak>
  86. <div id="app" v-cloak> -->
  87. <body>
  88. <div id="app">
  89. <div class="LoginContainer">
  90. <div class="LoginHeader">
  91. <!-- {{ width }} -->
  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="toLogin">确认登录</p>
  99. </div>
  100. </div>
  101. <script type="text/babel">
  102. var app = new Vue({
  103. el: '#app',
  104. data() {
  105. return {
  106. width: 10,
  107. phone:'',
  108. password: '',
  109. uuid: '',
  110. // 账号密码15236877164 12345678
  111. // 860681052009616,860681052009624
  112. }
  113. },
  114. mounted() {
  115. this.width = document.documentElement.clientHeight
  116. this.isLogin()
  117. let that = this
  118. if (window.plus) {
  119. // 在这里调用5+ API
  120. this.getDeviceInfo()
  121. } else { // 兼容老版本的plusready事件
  122. document.addEventListener('plusready',function () {
  123. that.getDeviceInfo()
  124. },false)
  125. }
  126. },
  127. methods: {
  128. isLogin() {
  129. let token = window.localStorage.getItem("token")
  130. let name = window.localStorage.getItem("name")
  131. let uuid = window.localStorage.getItem("uuid")
  132. if(token && name && uuid) {
  133. this.checkLoginTokenSuccess()
  134. }
  135. },
  136. checkLoginTokenSuccess() {
  137. let loading = window.ELEMENT.Loading.service()
  138. let _this = this
  139. axios.get('http://fangwei.cliu.cc/api/get_good', {
  140. headers: {
  141. Authorization: `Bearer ` + localStorage.getItem("token")
  142. }
  143. }).then(res => {
  144. loading.close()
  145. if(res.code === 200) {
  146. window.location.href = "./pages/product.html"
  147. } else {
  148. window.localStorage.removeItem("token")
  149. }
  150. }).catch(() => {
  151. loading.close()
  152. window.localStorage.removeItem("token")
  153. })
  154. },
  155. getDeviceInfo(){
  156. let that = this
  157. plus.device.getInfo({
  158. success:function(e){
  159. that.uuid = e.uuid
  160. },
  161. fail:function(e){
  162. that.uuid = JSON.stringify(e.uuid)
  163. }
  164. });
  165. },
  166. toLogin() {
  167. if(!this.phone) {
  168. window.ELEMENT.Message.error('请输入手机号')
  169. return false
  170. }
  171. if(!this.password) {
  172. window.ELEMENT.Message.error('请输入密码')
  173. return false
  174. }
  175. let loading = window.ELEMENT.Loading.service()
  176. let _this = this
  177. axios.get('http://fangwei.cliu.cc/api/NewLogin', {
  178. params: {
  179. mobile: _this.phone,
  180. password: _this.password,
  181. uuid: _this.uuid
  182. }
  183. }).then(res => {
  184. loading.close()
  185. if (res.code === 200) {
  186. window.localStorage.setItem('token', res.data.token)
  187. window.localStorage.setItem('name', res.data.name)
  188. window.localStorage.setItem('uuid', _this.uuid)
  189. console.log(res.data)
  190. window.location.href = "./pages/product.html"
  191. } else {
  192. window.ELEMENT.Message.error(res.msg || '登陆失败')
  193. }
  194. }).catch(() => {
  195. loading.close()
  196. window.ELEMENT.Message.error('登陆失败')
  197. })
  198. }
  199. }
  200. })
  201. </script>
  202. </body>
  203. </html>