login.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="content">
  3. <view class="logo">
  4. <image src="../../static/logo.png" mode="aspectFit"></image>
  5. </view>
  6. <view class="title">
  7. <text>宁夏煤业枣泉煤矿</text>
  8. </view>
  9. <view class="login_box">
  10. <view class="item">
  11. <view class="name">工号</view>
  12. <view class="input">
  13. <input type="text" value="" v-model="user.username"/>
  14. </view>
  15. <view class="icon icon_avatar"></view>
  16. </view>
  17. <view class="item">
  18. <view class="name">密码</view>
  19. <view class="input">
  20. <input type="password" value="" v-model="user.password"/>
  21. </view>
  22. <view class="icon icon_password"></view>
  23. </view>
  24. </view>
  25. <view class="tips">
  26. <text>忘记密码?请联系信息科管理员重置</text>
  27. </view>
  28. <view class="login_btn" @click="loginBtn()">
  29. <text>登录</text>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. user:{
  38. username:'123456',
  39. password:'Zhks123456+'
  40. }
  41. };
  42. },
  43. onLoad() {
  44. },
  45. methods: {
  46. loginBtn(){
  47. const user = this.user
  48. // 判断是否为空
  49. if(user.username == '' || user.password == ''){
  50. uni.showToast({
  51. icon:"none",
  52. title:"请填写用户信息"
  53. })
  54. return false
  55. }
  56. // 登录逻辑,
  57. // 1.在登录页,根据填写的账号密码,然后正常请求。获取返回值。在你这个项目里面,access_token是登录token
  58. // 2.将token保存在localstorge里面,让他在其他界面可以用的到。
  59. // 3.在需要登录的地方,将token带上,就实现了登录。你这个项目里面,header里面的Authorization是登录验证参数,然后赋予localstorge里面的值。其他的就按正常请求即可。
  60. // 注意点:有时候token需要拼接一下。例如你这个项目。将type和access_token拼接
  61. uni.request({
  62. method: "POST",
  63. url: "http://colliery.nxjiewei.com/api/oauth/token", //登录接口
  64. data: {
  65. username: user.username,
  66. password: user.password
  67. },
  68. header: {
  69. 'Content-Type': 'application/x-www-form-urlencoded' //自定义请求头信息
  70. },
  71. success: (res) => {
  72. console.log(res)
  73. if( res.data.code === 0 ){
  74. uni.showToast({
  75. icon:"none",
  76. title:"登录成功"
  77. })
  78. uni.setStorageSync('Authorization', res.data.data.access_token)
  79. uni.setStorageSync('token_type', res.data.data.token_type)
  80. uni.setStorage({
  81. key: 'user',
  82. data: res.data.data.user,
  83. success: function () {
  84. console.log(res.data.data.user);
  85. }
  86. });
  87. setTimeout(function(){
  88. uni.switchTab({
  89. url: '../tabbar/my/my'
  90. });
  91. },1500);
  92. }else if( res.data.code === 1001 ){
  93. uni.showToast({
  94. icon:"none",
  95. title:"用户不存在"
  96. })
  97. }else if( res.data.code === 1002 ){
  98. uni.showToast({
  99. icon:"none",
  100. title:"密码错误"
  101. })
  102. }else{
  103. return false
  104. }
  105. },
  106. fail: (res) => {
  107. uni.showToast({
  108. icon:"none",
  109. title:res
  110. })
  111. }
  112. });
  113. }
  114. }
  115. }
  116. </script>
  117. <style lang="scss">
  118. .content {
  119. width: 100%;
  120. height: 100vh;
  121. background-image: url(../../static/Bitmap.png);
  122. background-size: cover;
  123. background-repeat: no-repeat;
  124. .logo {
  125. width: 344rpx;
  126. height: 350rpx;
  127. margin: 0 auto;
  128. padding-top: 229rpx;
  129. image {
  130. width: 100%;
  131. height: 100%;
  132. }
  133. }
  134. .title {
  135. margin: 0 auto;
  136. margin-top: 32rpx;
  137. width: 288rpx;
  138. height: 47rpx;
  139. font-size: 36rpx;
  140. font-family: MicrosoftYaHei;
  141. color: #FFFFFF;
  142. line-height: 47rpx;
  143. text-align: center;
  144. }
  145. .login_box {
  146. margin-top: 65rpx;
  147. .item {
  148. margin: 0 auto;
  149. margin-bottom: 34rpx;
  150. width: 500rpx;
  151. height: 86rpx;
  152. background: #FFFFFF;
  153. border-radius: 96rpx;
  154. padding-left: 40rpx;
  155. // padding-top: 19rpx;
  156. padding-right: 40rpx;
  157. box-sizing: border-box;
  158. display: flex;
  159. .name {
  160. width: 80rpx;
  161. font-size: 33rpx;
  162. font-family: MicrosoftYaHei;
  163. color: #009FE8;
  164. line-height: 86rpx;
  165. }
  166. .input {
  167. width: 280rpx;
  168. height: 86rpx;
  169. input {
  170. height: 86rpx;
  171. line-height: 86rpx;
  172. color: #666;
  173. }
  174. }
  175. .icon {
  176. margin-top: 19rpx;
  177. }
  178. .icon_avatar {
  179. margin-left: 10rpx;
  180. width: 50rpx;
  181. height: 49rpx;
  182. background-image: url(icon/Avatar.png);
  183. background-size: cover;
  184. background-repeat: no-repeat;
  185. }
  186. .icon_password {
  187. margin-left: 18rpx;
  188. width: 42rpx;
  189. height: 48rpx;
  190. background-image: url(icon/Password.png);
  191. background-size: cover;
  192. background-repeat: no-repeat;
  193. }
  194. }
  195. }
  196. .tips {
  197. margin: 0 auto;
  198. margin-top: 46rpx;
  199. width: 531rpx;
  200. height: 44rpx;
  201. font-size: 28rpx;
  202. font-family: MicrosoftYaHei;
  203. color: #ECF0F1;
  204. line-height: 44rpx;
  205. text-align: center;
  206. }
  207. .login_btn {
  208. margin: 0 auto;
  209. margin-top: 45rpx;
  210. width: 384rpx;
  211. height: 100rpx;
  212. background: rgba(100, 220, 255, 0.8);
  213. border-radius: 50rpx;
  214. text-align: center;
  215. line-height: 100rpx;
  216. text {
  217. font-size: 40rpx;
  218. font-family: MicrosoftYaHei;
  219. color: #FFFFFF;
  220. letter-spacing: 1rpx;
  221. }
  222. }
  223. }
  224. </style>