login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <view class="page">
  3. <view class="logTitle">
  4. <view class="welcome flex-row justify-center">
  5. <text>欢迎登录娇骄儿拓客端</text>
  6. </view>
  7. <view class="flex-row justify-center">
  8. <image src="../../static/logo.png" class="log"></image>
  9. </view>
  10. </view>
  11. <view class="form">
  12. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  13. <view class="formItem">
  14. <u-form-item label="账号" prop="username" borderBottom ref="item1">
  15. <u--input v-model="form.username" placeholder="请输入账号" border="none"></u--input>
  16. </u-form-item>
  17. </view>
  18. <view class="formItem">
  19. <u-form-item label="密码" prop="password" borderBottom ref="item1">
  20. <u--input v-model="form.password" placeholder="请输入密码" border="none" type="password"></u--input>
  21. </u-form-item>
  22. </view>
  23. <view class="forgetPassword flex-row justify-between ">
  24. <view>
  25. <checkbox-group @change="checkboxChange">
  26. <checkbox :checked="savePassword" color="#FFCC33" :style="{'transform':'scale(0.8)'}"/>
  27. <text>记住账号密码</text>
  28. </checkbox-group>
  29. </view>
  30. <view>
  31. <text @click="forgetPassword">忘记密码?</text>
  32. </view>
  33. </view>
  34. <view class="loginButton" @click="login">
  35. <text>登录</text>
  36. </view>
  37. <!-- <view class="loginButton" @click="getWxCosde">-->
  38. <!-- <text>获取微信code</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. requestStatus:false,
  53. savePassword:true,
  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. onLoad(e){
  85. console.log('重定向获取到的参数',e)
  86. console.log('重定向的url',location.href)
  87. let code = this.getUrlCode('code')
  88. if (code){
  89. uni.showToast({
  90. icon: 'success',
  91. duration: 5000,
  92. title: '获取到的code:'+code
  93. });
  94. }
  95. },
  96. methods: {
  97. getUrlCode(name) {
  98. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||[, ''])[1].replace(/\+/g, '%20')) || null
  99. },
  100. getWxCosde(){
  101. const callBack = this.$callbackUrl; //回调地址 就是完整地址登录页
  102. let wx_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx54f2b294ce5acbe7&redirect_uri='+encodeURIComponent(callBack)+'&response_type=code&scope=snsapi_base#wechat_redirect'
  103. window.location.href = wx_url;
  104. },
  105. goRegister(){
  106. uni.redirectTo({
  107. url:'/pages/register/register'
  108. })
  109. },
  110. forgetPassword(){
  111. uni.navigateTo({
  112. url:'/pages/forgetPassword/forgetPassword'
  113. })
  114. },
  115. checkboxChange(e){
  116. this.savePassword = !this.savePassword
  117. console.log(this.savePassword)
  118. },
  119. login() {
  120. if (this.requestStatus){
  121. return
  122. }
  123. this.requestStatus=true
  124. this.$refs.uForm.validate().then(res => {
  125. if (this.savePassword){
  126. uni.setStorageSync('savePassword', this.savePassword)
  127. uni.setStorageSync('username', this.form.username)
  128. uni.setStorageSync('password', this.form.password)
  129. }else {
  130. uni.setStorageSync('savePassword', this.savePassword)
  131. uni.removeStorageSync('username');
  132. uni.removeStorageSync('password');
  133. }
  134. uni.showLoading({
  135. title: '登录中...'
  136. });
  137. this.$api.login.expandLogin(this.form).then(res => {
  138. uni.hideLoading();
  139. this.requestStatus=false
  140. uni.setStorageSync('accessToken', res.data.data.access_token)
  141. this.$api.user.getUserInfo().then(res=>{
  142. this.userInfo = res.data.data
  143. uni.setStorageSync('spreadUserInfo', this.userInfo)
  144. uni.showToast({
  145. icon: 'success',
  146. duration: 1000,
  147. title: '登陆成功'
  148. });
  149. setTimeout(()=>{
  150. uni.switchTab({
  151. url: "/pages/index/index"
  152. })
  153. },1000)
  154. })
  155. }).catch(err=>{
  156. this.requestStatus=false
  157. })
  158. }).catch(err=>{
  159. this.requestStatus=false
  160. })
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. @import './index.rpx.css';
  167. </style>