login.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. if (uni.getStorageSync('savePassword')){
  83. this.savePassword = uni.getStorageSync('savePassword')
  84. }
  85. },
  86. onLoad(e){
  87. console.log('重定向获取到的参数',e)
  88. console.log('重定向的url',location.href)
  89. let code = this.getUrlCode('code')
  90. if (code){
  91. uni.showToast({
  92. icon: 'success',
  93. duration: 5000,
  94. title: '获取到的code:'+code
  95. });
  96. }
  97. },
  98. methods: {
  99. getUrlCode(name) {
  100. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||[, ''])[1].replace(/\+/g, '%20')) || null
  101. },
  102. getWxCosde(){
  103. const callBack = this.$callbackUrl; //回调地址 就是完整地址登录页
  104. 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'
  105. window.location.href = wx_url;
  106. },
  107. goRegister(){
  108. uni.redirectTo({
  109. url:'/pages/register/register'
  110. })
  111. },
  112. forgetPassword(){
  113. uni.navigateTo({
  114. url:'/pages/forgetPassword/forgetPassword'
  115. })
  116. },
  117. checkboxChange(e){
  118. this.savePassword = !this.savePassword
  119. console.log(this.savePassword)
  120. },
  121. login() {
  122. console.log('savePassword', this.savePassword)
  123. if (this.requestStatus){
  124. return
  125. }
  126. this.requestStatus=true
  127. this.$refs.uForm.validate().then(res => {
  128. console.log('savePassword', this.savePassword)
  129. if (this.savePassword){
  130. uni.setStorageSync('savePassword', this.savePassword)
  131. uni.setStorageSync('username', this.form.username)
  132. uni.setStorageSync('password', this.form.password)
  133. }else {
  134. uni.setStorageSync('savePassword', this.savePassword)
  135. uni.removeStorageSync('username');
  136. uni.removeStorageSync('password');
  137. }
  138. uni.showLoading({
  139. title: '登录中...'
  140. });
  141. this.$api.login.expandLogin(this.form).then(res => {
  142. uni.hideLoading();
  143. this.requestStatus=false
  144. uni.setStorageSync('accessToken', res.data.data.access_token)
  145. this.$api.user.getUserInfo().then(res=>{
  146. if (res.data.data.img){
  147. res.data.data.img = res.data.data.img.replace(/^http:/, "https:")
  148. }
  149. this.userInfo = res.data.data
  150. uni.setStorageSync('spreadUserInfo', this.userInfo)
  151. uni.showToast({
  152. icon: 'success',
  153. duration: 1000,
  154. title: '登陆成功'
  155. });
  156. setTimeout(()=>{
  157. uni.switchTab({
  158. url: "/pages/index/index"
  159. })
  160. },1000)
  161. })
  162. }).catch(err=>{
  163. this.requestStatus=false
  164. })
  165. }).catch(err=>{
  166. this.requestStatus=false
  167. })
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="scss" scoped>
  173. @import './index.rpx.css';
  174. </style>