index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. let params = {
  43. username: this.username,
  44. password: this.password
  45. }
  46. const res = await login(params)
  47. const { token } = res
  48. uni.setStorageSync('Authorization',token)
  49. uni.setStorageSync('username',this.username)
  50. uni.showToast({
  51. title: '登录成功',
  52. icon:'none'
  53. });
  54. uni.reLaunch({
  55. url:'/pages/index/index'
  56. })
  57. }
  58. },
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .login{
  63. .form{
  64. height: 100%;
  65. background: #fff;
  66. padding: 40rpx 32rpx;
  67. border-radius: 24rpx;
  68. .input-wrapper {
  69. background:#fff;
  70. padding-bottom: 22rpx;
  71. font-size: 36rpx;
  72. margin-bottom: 50rpx;
  73. .label{
  74. font-weight: 500;
  75. font-size: 32rpx;
  76. color: #171717;
  77. margin-bottom: 20rpx;
  78. }
  79. .input-box{
  80. color: #171717;
  81. height: 84rpx;
  82. background: #F3F7FF;
  83. border-radius: 42rpx;
  84. padding: 0 32rpx;
  85. font-size: 28rpx
  86. }
  87. .icon-pad {
  88. padding: 10rpx;
  89. }
  90. }
  91. .btn{
  92. margin-top: 127rpx;
  93. button{
  94. color: #fff;
  95. background: linear-gradient( 172deg, #216CFF 30%, #C7F0FF 100%);
  96. border-radius: 48rpx;
  97. }
  98. }
  99. }
  100. }
  101. </style>