login.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <view class="page">
  3. <view class="logTitle">
  4. <view class="welcome">
  5. <text>HI,您好!</text>
  6. </view>
  7. <view class="welcome">
  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-end register">
  43. <text @click="goRegister">去注册-></text>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. savePassword:false,
  52. form: {
  53. username: '',
  54. password: ''
  55. },
  56. rules: {
  57. 'username': {
  58. type: 'string',
  59. required: true,
  60. min: 11,
  61. max: 11,
  62. pattern:this.$phonePattern,
  63. message: '请输入正确的电话号码',
  64. trigger: ['blur', 'change']
  65. },
  66. 'password': {
  67. type: 'string',
  68. required: true,
  69. min: 6,
  70. max: 18,
  71. message: '请输入6-18位密码',
  72. trigger: ['blur', 'change']
  73. }
  74. }
  75. }
  76. },
  77. onShow(){
  78. this.form.username = uni.getStorageSync('username')
  79. this.form.password = uni.getStorageSync('password')
  80. this.savePassword = uni.getStorageSync('savePassword')
  81. },
  82. methods: {
  83. goRegister(){
  84. uni.navigateTo({
  85. url:'/pages/register/register'
  86. })
  87. },
  88. forgetPassword(){
  89. uni.navigateTo({
  90. url:'/pages/forgetPassword/forgetPassword'
  91. })
  92. },
  93. checkboxChange(e){
  94. this.savePassword = !this.savePassword
  95. console.log(this.savePassword)
  96. },
  97. login() {
  98. this.$refs.uForm.validate().then(res => {
  99. if (this.savePassword){
  100. uni.setStorageSync('savePassword', this.savePassword)
  101. uni.setStorageSync('username', this.form.username)
  102. uni.setStorageSync('password', this.form.password)
  103. }else {
  104. uni.setStorageSync('savePassword', this.savePassword)
  105. uni.removeStorageSync('username');
  106. uni.removeStorageSync('password');
  107. }
  108. this.$api.login.techLogin(this.form).then(res => {
  109. uni.setStorageSync('accessToken', res.data.data.access_token)
  110. uni.removeStorageSync('storeId');
  111. uni.removeStorageSync('storeName');
  112. uni.switchTab({
  113. url: "/pages/index/index"
  114. })
  115. })
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. @import './index.rpx.css';
  123. </style>