login.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="content">
  3. <view class="status_bar"></view>
  4. <view class="logo">
  5. <image src="~@/static/logo.png" mode="aspectFit"></image>
  6. </view>
  7. <view class="title">
  8. <text>E信管理</text>
  9. </view>
  10. <view class="login_box">
  11. <view class="item">
  12. <view class="name">工号</view>
  13. <view class="input">
  14. <input type="text" value="" v-model="user.username" />
  15. </view>
  16. <view class="icon icon_avatar"></view>
  17. </view>
  18. <view class="item">
  19. <view class="name">密码</view>
  20. <view class="input">
  21. <input type="password" value="" v-model="user.password" />
  22. </view>
  23. <view class="icon icon_password"></view>
  24. </view>
  25. </view>
  26. <view class="tips">
  27. <text>忘记密码?请联系信息科管理员重置</text>
  28. </view>
  29. <!-- <view class="tips">
  30. <text>忘记密码?请联系信息科重置密码</text>
  31. </view> -->
  32. <view class="login_btn" @click="loginBtn()">
  33. <text>登录</text>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. user: {
  42. username: '',
  43. password: ''
  44. }
  45. };
  46. },
  47. onLoad() {
  48. },
  49. methods: {
  50. loginBtn() {
  51. const user = this.user
  52. uni.setStorageSync('login_password', this.user.password)
  53. // 判断是否为空
  54. if (user.username == '' || user.password == '') {
  55. uni.showToast({
  56. icon: "none",
  57. title: "请填写用户信息"
  58. })
  59. return false
  60. }
  61. this.$api.login({
  62. username: user.username,
  63. password: user.password
  64. }).then((res) => {
  65. if (res.data.code === 0) {
  66. // console.log(res.data.data.token_type +''+res.data.data.access_token)
  67. console.log(res.data.data.user.mobile)
  68. uni.setStorageSync('Authorization', res.data.data.access_token)
  69. uni.setStorageSync('token_type', res.data.data.token_type)
  70. // 存储用户基本信息
  71. uni.setStorageSync('user', res.data.data.user);
  72. // 存储电话号码
  73. uni.setStorageSync('mobile', res.data.data.user.mobile);
  74. setTimeout(function() {
  75. uni.showToast({
  76. icon: "none",
  77. title: "登录成功"
  78. })
  79. uni.switchTab({
  80. url:"../../tabbar/index/index",
  81. success: () => {
  82. //#ifdef H5
  83. window.location.reload();
  84. //#endif
  85. }
  86. })
  87. }, 500)
  88. // #ifdef APP-PLUS
  89. plus.runtime.restart();
  90. // #endif
  91. } else if (res.data.code === 1001) {
  92. uni.showToast({
  93. icon: "none",
  94. title: "用户不存在"
  95. })
  96. } else if (res.data.code === 1002) {
  97. uni.showToast({
  98. icon: "none",
  99. title: "密码错误"
  100. })
  101. } else {
  102. return false
  103. }
  104. }).catch((err) => {
  105. console.log('request fail', err);
  106. uni.showToast({
  107. icon: "none",
  108. title: err
  109. })
  110. })
  111. },
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. page {}
  117. .content {
  118. width: 749rpx;
  119. height: 100vh;
  120. background-image: url(~@/static/login.png);
  121. background-size: cover;
  122. background-position: center center;
  123. background-repeat: no-repeat;
  124. .logo {
  125. width: 344rpx;
  126. height: 350rpx;
  127. margin: 0 auto;
  128. padding-top: 100rpx;
  129. image {
  130. width: 100%;
  131. height: 100%;
  132. }
  133. }
  134. .title {
  135. margin: 0 auto;
  136. margin-top: 32rpx;
  137. width: 288rpx;
  138. height: 47rpx;
  139. font-size: 36rpx;
  140. font-family: MicrosoftYaHei;
  141. color: #FFFFFF;
  142. line-height: 47rpx;
  143. text-align: center;
  144. }
  145. .login_box {
  146. padding-top: 40px;
  147. .item {
  148. margin: 0 auto;
  149. margin-bottom: 20px;
  150. width: 500rpx;
  151. height: 45px;
  152. background: #FFFFFF;
  153. border-radius: 25px;
  154. padding-left: 20px;
  155. padding-right: 20px;
  156. box-sizing: border-box;
  157. display: flex;
  158. align-items: center;
  159. .name {
  160. width: 80rpx;
  161. font-size: 16px;
  162. color: #009FE8;
  163. line-height: 45px;
  164. }
  165. .input {
  166. width: 280rpx;
  167. input {
  168. height: 45px;
  169. color: #666;
  170. }
  171. }
  172. .icon {}
  173. .icon_avatar {
  174. margin-left: 10rpx;
  175. width: 25px;
  176. height: 25px;
  177. background-image: url(./icon/Avatar.png);
  178. background-size: cover;
  179. background-repeat: no-repeat;
  180. }
  181. .icon_password {
  182. margin-left: 18rpx;
  183. width: 25px;
  184. height: 28px;
  185. background-image: url(./icon/Password.png);
  186. background-size: cover;
  187. background-repeat: no-repeat;
  188. }
  189. }
  190. }
  191. .tips {
  192. margin: 0 auto;
  193. margin-top: 25px;
  194. text-align: center;
  195. font-size: 14px;
  196. color: #ECF0F1;
  197. line-height: 40px;
  198. text-align: center;
  199. }
  200. .login_btn {
  201. margin: 0 auto;
  202. margin-top: 40px;
  203. width: 200px;
  204. height: 50px;
  205. background: rgba(100, 220, 255, 0.8);
  206. border-radius: 25px;
  207. text-align: center;
  208. line-height: 50px;
  209. text {
  210. font-size: 18px;
  211. color: #FFFFFF;
  212. letter-spacing: 4px;
  213. }
  214. }
  215. }
  216. </style>