login.vue 3.4 KB

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