login.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. requestStatus:false,
  54. savePassword:false,
  55. form: {
  56. username: '',
  57. password: ''
  58. },
  59. rules: {
  60. 'username': {
  61. type: 'string',
  62. required: true,
  63. min: 11,
  64. max: 11,
  65. pattern:this.$phonePattern,
  66. message: '请输入正确的电话号码',
  67. trigger: ['blur', 'change']
  68. },
  69. 'password': {
  70. type: 'string',
  71. required: true,
  72. min: 6,
  73. max: 18,
  74. message: '请输入6-18位密码',
  75. trigger: ['blur', 'change']
  76. }
  77. }
  78. }
  79. },
  80. onShow(){
  81. this.form.username = uni.getStorageSync('username')
  82. this.form.password = uni.getStorageSync('password')
  83. this.savePassword = uni.getStorageSync('savePassword')
  84. },
  85. methods: {
  86. goRegister(){
  87. uni.redirectTo({
  88. url:'/pages/register/register'
  89. })
  90. },
  91. forgetPassword(){
  92. uni.navigateTo({
  93. url:'/pages/forgetPassword/forgetPassword'
  94. })
  95. },
  96. checkboxChange(e){
  97. this.savePassword = !this.savePassword
  98. console.log(this.savePassword)
  99. },
  100. login() {
  101. if (this.requestStatus){
  102. return
  103. }
  104. this.requestStatus=true
  105. this.$refs.uForm.validate().then(res => {
  106. if (this.savePassword){
  107. uni.setStorageSync('savePassword', this.savePassword)
  108. uni.setStorageSync('username', this.form.username)
  109. uni.setStorageSync('password', this.form.password)
  110. }else {
  111. uni.setStorageSync('savePassword', this.savePassword)
  112. uni.removeStorageSync('username');
  113. uni.removeStorageSync('password');
  114. }
  115. uni.showLoading({
  116. title: '登录中...'
  117. });
  118. this.$api.login.expandLogin(this.form).then(res => {
  119. uni.hideLoading();
  120. this.requestStatus=false
  121. uni.setStorageSync('accessToken', res.data.data.access_token)
  122. this.$api.user.getUserInfo().then(res=>{
  123. this.userInfo = res.data.data
  124. uni.setStorageSync('spreadUserInfo', this.userInfo)
  125. uni.showToast({
  126. icon: 'success',
  127. duration: 1000,
  128. title: '登陆成功'
  129. });
  130. setTimeout(()=>{
  131. uni.switchTab({
  132. url: "/pages/index/index"
  133. })
  134. },1000)
  135. })
  136. }).catch(err=>{
  137. this.requestStatus=false
  138. })
  139. }).catch(err=>{
  140. this.requestStatus=false
  141. })
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="scss" scoped>
  147. @import './index.rpx.css';
  148. </style>