login.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. <!-- <view class="loginButton" @click="getWxCosde">-->
  41. <!-- <text>获取微信code</text>-->
  42. <!-- </view>-->
  43. </u--form>
  44. </view>
  45. <view class="flex-row justify-center register">
  46. <text>无账号?</text>
  47. <text @click="goRegister" :style="{color:'#FFE05C'}">切换注册</text>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. requestStatus:false,
  56. savePassword:true,
  57. form: {
  58. username: '',
  59. password: ''
  60. },
  61. rules: {
  62. 'username': {
  63. type: 'string',
  64. required: true,
  65. min: 11,
  66. max: 11,
  67. pattern:this.$phonePattern,
  68. message: '请输入正确的电话号码',
  69. trigger: ['blur', 'change']
  70. },
  71. 'password': {
  72. type: 'string',
  73. required: true,
  74. min: 6,
  75. max: 18,
  76. message: '请输入6-18位密码',
  77. trigger: ['blur', 'change']
  78. }
  79. }
  80. }
  81. },
  82. onShow(){
  83. this.form.username = uni.getStorageSync('username')
  84. this.form.password = uni.getStorageSync('password')
  85. this.savePassword = uni.getStorageSync('savePassword')
  86. },
  87. onLoad(e){
  88. console.log('重定向获取到的参数',e)
  89. console.log('重定向的url',location.href)
  90. let code = this.getUrlCode('code')
  91. if (code){
  92. uni.showToast({
  93. icon: 'success',
  94. duration: 5000,
  95. title: '获取到的code:'+code
  96. });
  97. }
  98. },
  99. methods: {
  100. getUrlCode(name) {
  101. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||[, ''])[1].replace(/\+/g, '%20')) || null
  102. },
  103. getWxCosde(){
  104. const callBack = this.$callbackUrl; //回调地址 就是完整地址登录页
  105. 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'
  106. window.location.href = wx_url;
  107. },
  108. goRegister(){
  109. uni.redirectTo({
  110. url:'/pages/register/register'
  111. })
  112. },
  113. forgetPassword(){
  114. uni.navigateTo({
  115. url:'/pages/forgetPassword/forgetPassword'
  116. })
  117. },
  118. checkboxChange(e){
  119. this.savePassword = !this.savePassword
  120. console.log(this.savePassword)
  121. },
  122. login() {
  123. if (this.requestStatus){
  124. return
  125. }
  126. this.requestStatus=true
  127. this.$refs.uForm.validate().then(res => {
  128. if (this.savePassword){
  129. uni.setStorageSync('savePassword', this.savePassword)
  130. uni.setStorageSync('username', this.form.username)
  131. uni.setStorageSync('password', this.form.password)
  132. }else {
  133. uni.setStorageSync('savePassword', this.savePassword)
  134. uni.removeStorageSync('username');
  135. uni.removeStorageSync('password');
  136. }
  137. uni.showLoading({
  138. title: '登录中...'
  139. });
  140. this.$api.login.expandLogin(this.form).then(res => {
  141. uni.hideLoading();
  142. this.requestStatus=false
  143. uni.setStorageSync('accessToken', res.data.data.access_token)
  144. this.$api.user.getUserInfo().then(res=>{
  145. this.userInfo = res.data.data
  146. uni.setStorageSync('spreadUserInfo', this.userInfo)
  147. uni.showToast({
  148. icon: 'success',
  149. duration: 1000,
  150. title: '登陆成功'
  151. });
  152. setTimeout(()=>{
  153. uni.switchTab({
  154. url: "/pages/index/index"
  155. })
  156. },1000)
  157. })
  158. }).catch(err=>{
  159. this.requestStatus=false
  160. })
  161. }).catch(err=>{
  162. this.requestStatus=false
  163. })
  164. }
  165. }
  166. }
  167. </script>
  168. <style lang="scss" scoped>
  169. @import './index.rpx.css';
  170. </style>