login.vue 6.0 KB

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