login.vue 5.5 KB

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