index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view class="login">
  3. <view class="form">
  4. <view class="input-wrapper">
  5. <view class="label">账号</view>
  6. <view class="input-box flex aic"><u-input v-model="username" fontSize="32rpx"
  7. border="none" type="text" placeholder="请输入账号" clearable></u-input></view>
  8. </view>
  9. <view class="input-wrapper">
  10. <view class="label">密码</view>
  11. <view class="input-box flex aic jcsb">
  12. <u-input :type="passwordType" v-model="password" fontSize="32rpx" border="none" placeholder="请输入密码"></u-input>
  13. <view v-if="password" class="eye-icon" @click="togglePassword">
  14. <pv-icon :name="icon" color="#bfbfbf" :customStyle="{ fontSize: '46rpx'}"></pv-icon>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="btn">
  19. <u-button @click="toLogin()">登录</u-button>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import { login } from '@/apis/login.js'
  26. export default {
  27. data(){
  28. return{
  29. username:'',
  30. password:'',
  31. passwordType:'password',
  32. icon:'icon-eye-off'
  33. }
  34. },
  35. methods:{
  36. togglePassword() {
  37. this.passwordType = this.passwordType === 'password' ? 'text' : 'password';
  38. this.icon = this.passwordType === 'password' ? 'icon-eye-off' : 'icon-eye-fill';
  39. },
  40. // 登录
  41. async toLogin () {
  42. uni.showLoading()
  43. let params = {
  44. username: this.username,
  45. password: this.password
  46. }
  47. const res = await login(params)
  48. const { token } = res
  49. uni.setStorageSync('Authorization',token)
  50. uni.setStorageSync('username',this.username)
  51. uni.hideLoading()
  52. uni.showToast({
  53. title: '登录成功',
  54. icon:'none'
  55. });
  56. uni.reLaunch({
  57. url:'/pages/index/index'
  58. })
  59. }
  60. },
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .login{
  65. .form{
  66. height: 100%;
  67. background: #fff;
  68. padding: 40rpx 32rpx;
  69. border-radius: 24rpx;
  70. .input-wrapper {
  71. background:#fff;
  72. padding-bottom: 22rpx;
  73. font-size: 36rpx;
  74. margin-bottom: 50rpx;
  75. .label{
  76. font-weight: 500;
  77. font-size: 32rpx;
  78. color: #171717;
  79. margin-bottom: 20rpx;
  80. }
  81. .input-box{
  82. color: #171717;
  83. height: 84rpx;
  84. background: #F3F7FF;
  85. border-radius: 42rpx;
  86. padding: 0 32rpx;
  87. font-size: 28rpx
  88. }
  89. .icon-pad {
  90. padding: 10rpx;
  91. }
  92. }
  93. .btn{
  94. margin-top: 127rpx;
  95. button{
  96. color: #fff;
  97. background: linear-gradient( 172deg, #216CFF 30%, #C7F0FF 100%);
  98. border-radius: 48rpx;
  99. }
  100. }
  101. }
  102. }
  103. </style>