login.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <view class="page">
  3. <uni-nav-bar :fixed="true" background-color="#FFE05C" :border="false" :statusBar="true" title="登录" />
  4. <view class="logTitle">
  5. <!-- <view class="welcome">-->
  6. <!-- <text>HI,您好!</text>-->
  7. <!-- </view>-->
  8. <view class="welcome flex-row justify-center">
  9. <text>欢迎登录娇骄儿拓客端</text>
  10. </view>
  11. <view class="flex-row justify-center">
  12. <image src="../../static/logo.png" class="log"></image>
  13. </view>
  14. </view>
  15. <view class="form">
  16. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  17. <view class="formItem">
  18. <u-form-item label="账号" prop="username" borderBottom ref="item1">
  19. <u--input v-model="form.username" placeholder="请输入账号" border="none"></u--input>
  20. </u-form-item>
  21. </view>
  22. <view class="formItem">
  23. <u-form-item label="密码" prop="password" borderBottom ref="item1">
  24. <u--input v-model="form.password" placeholder="请输入密码" border="none" type="password"></u--input>
  25. </u-form-item>
  26. </view>
  27. <view class="forgetPassword flex-row justify-between ">
  28. <view>
  29. <checkbox-group @change="checkboxChange">
  30. <checkbox :checked="savePassword" color="#FFCC33" :style="{'transform':'scale(0.8)'}"/>
  31. <text>记住账号密码</text>
  32. </checkbox-group>
  33. </view>
  34. <view>
  35. <text @click="forgetPassword">忘记密码?</text>
  36. </view>
  37. </view>
  38. <view class="loginButton" @click="login">
  39. <text>登录</text>
  40. </view>
  41. </u--form>
  42. </view>
  43. <view class="flex-row justify-center register">
  44. <text>无账号?</text>
  45. <text @click="goRegister" :style="{color:'#FFE05C'}">切换注册</text>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. savePassword:false,
  54. form: {
  55. username: '',
  56. password: ''
  57. },
  58. rules: {
  59. 'username': {
  60. type: 'string',
  61. required: true,
  62. min: 11,
  63. max: 11,
  64. pattern:this.$phonePattern,
  65. message: '请输入正确的电话号码',
  66. trigger: ['blur', 'change']
  67. },
  68. 'password': {
  69. type: 'string',
  70. required: true,
  71. min: 6,
  72. max: 18,
  73. message: '请输入6-18位密码',
  74. trigger: ['blur', 'change']
  75. }
  76. }
  77. }
  78. },
  79. onShow(){
  80. this.form.username = uni.getStorageSync('username')
  81. this.form.password = uni.getStorageSync('password')
  82. this.savePassword = uni.getStorageSync('savePassword')
  83. },
  84. methods: {
  85. goRegister(){
  86. uni.redirectTo({
  87. url:'/pages/register/register'
  88. })
  89. },
  90. forgetPassword(){
  91. uni.navigateTo({
  92. url:'/pages/forgetPassword/forgetPassword'
  93. })
  94. },
  95. checkboxChange(e){
  96. this.savePassword = !this.savePassword
  97. console.log(this.savePassword)
  98. },
  99. login() {
  100. this.$refs.uForm.validate().then(res => {
  101. if (this.savePassword){
  102. uni.setStorageSync('savePassword', this.savePassword)
  103. uni.setStorageSync('username', this.form.username)
  104. uni.setStorageSync('password', this.form.password)
  105. }else {
  106. uni.setStorageSync('savePassword', this.savePassword)
  107. uni.removeStorageSync('username');
  108. uni.removeStorageSync('password');
  109. }
  110. this.$api.login.expandLogin(this.form).then(res => {
  111. uni.setStorageSync('accessToken', res.data.data.access_token)
  112. this.$api.user.getUserInfo().then(res=>{
  113. this.userInfo = res.data.data
  114. uni.setStorageSync('spreadUserInfo', this.userInfo)
  115. uni.showToast({
  116. icon: 'success',
  117. duration: 1000,
  118. title: '登陆成功'
  119. });
  120. setTimeout(()=>{
  121. uni.switchTab({
  122. url: "/pages/index/index"
  123. })
  124. },1000)
  125. })
  126. })
  127. })
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. @import './index.rpx.css';
  134. </style>