login.vue 5.6 KB

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