login.vue 5.9 KB

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