login.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 v-if="mine_code == 'ningdongyunying'">E信管理</text>
  9. <text v-if="mine_code == 'zaoquan'">枣泉煤矿</text>
  10. </view>
  11. <view class="login_box">
  12. <view class="item">
  13. <view class="name">工号</view>
  14. <view class="input">
  15. <input type="text" value="" v-model="user.username" />
  16. </view>
  17. <view class="icon icon_avatar"></view>
  18. </view>
  19. <view class="item">
  20. <view class="name">密码</view>
  21. <view class="input">
  22. <input type="password" value="" v-model="user.password" />
  23. </view>
  24. <view class="icon icon_password"></view>
  25. </view>
  26. </view>
  27. <view class="tips" @click="go_forget_password()">
  28. <text>忘记密码?点击这里重置!</text>
  29. </view>
  30. <view class="login_btn" @click="loginBtn()">
  31. <text>登录</text>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. data() {
  38. return {
  39. mine_code:"",
  40. user: {
  41. username: '',
  42. password: ''
  43. }
  44. };
  45. },
  46. onLoad() {
  47. this.mine_code = uni.getStorageSync('mine_code')
  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. go_forget_password(){
  114. uni.navigateTo({
  115. url:"../forget-password/forget-password"
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss">
  122. page {}
  123. .content {
  124. width: 749rpx;
  125. height: 100vh;
  126. background-image: url(~@/static/login.png);
  127. background-size: cover;
  128. background-position: center center;
  129. background-repeat: no-repeat;
  130. .logo {
  131. width: 344rpx;
  132. height: 350rpx;
  133. margin: 0 auto;
  134. padding-top: 100rpx;
  135. image {
  136. width: 100%;
  137. height: 100%;
  138. }
  139. }
  140. .title {
  141. margin: 0 auto;
  142. margin-top: 32rpx;
  143. width: 288rpx;
  144. height: 47rpx;
  145. font-size: 36rpx;
  146. color: #FFFFFF;
  147. line-height: 47rpx;
  148. text-align: center;
  149. }
  150. .login_box {
  151. padding-top: 40px;
  152. .item {
  153. margin: 0 auto;
  154. margin-bottom: 20px;
  155. width: 500rpx;
  156. height: 45px;
  157. background: #FFFFFF;
  158. border-radius: 25px;
  159. padding-left: 20px;
  160. padding-right: 20px;
  161. box-sizing: border-box;
  162. display: flex;
  163. align-items: center;
  164. .name {
  165. width: 80rpx;
  166. font-size: 16px;
  167. color: #009FE8;
  168. line-height: 45px;
  169. }
  170. .input {
  171. width: 280rpx;
  172. input {
  173. height: 45px;
  174. color: #666;
  175. }
  176. }
  177. .icon {}
  178. .icon_avatar {
  179. margin-left: 10rpx;
  180. width: 25px;
  181. height: 25px;
  182. background-image: url(./icon/Avatar.png);
  183. background-size: cover;
  184. background-repeat: no-repeat;
  185. }
  186. .icon_password {
  187. margin-left: 18rpx;
  188. width: 25px;
  189. height: 28px;
  190. background-image: url(./icon/Password.png);
  191. background-size: cover;
  192. background-repeat: no-repeat;
  193. }
  194. }
  195. }
  196. .tips {
  197. margin: 0 auto;
  198. margin-top: 25px;
  199. text-align: center;
  200. font-size: 14px;
  201. color: #ECF0F1;
  202. line-height: 40px;
  203. text-align: center;
  204. }
  205. .login_btn {
  206. margin: 0 auto;
  207. margin-top: 40px;
  208. width: 200px;
  209. height: 50px;
  210. background: rgba(100, 220, 255, 0.8);
  211. border-radius: 25px;
  212. text-align: center;
  213. line-height: 50px;
  214. text {
  215. font-size: 18px;
  216. color: #FFFFFF;
  217. letter-spacing: 4px;
  218. }
  219. }
  220. }
  221. </style>