login.vue 5.2 KB

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