| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <template>
- <view class="page">
- <view class="logTitle">
- <view class="welcome flex-row justify-center">
- <text>欢迎登录娇骄儿拓客端</text>
- </view>
- <view class="flex-row justify-center">
- <image src="../../static/logo.png" class="log"></image>
- </view>
- </view>
- <view class="form">
- <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
- <view class="formItem">
- <u-form-item label="账号" prop="username" borderBottom ref="item1">
- <u--input v-model="form.username" placeholder="请输入账号" border="none"></u--input>
- </u-form-item>
- </view>
- <view class="formItem">
- <u-form-item label="密码" prop="password" borderBottom ref="item1">
- <u--input v-model="form.password" placeholder="请输入密码" border="none" type="password"></u--input>
- </u-form-item>
- </view>
- <view class="forgetPassword flex-row justify-between ">
- <view>
- <checkbox-group @change="checkboxChange">
- <checkbox :checked="savePassword" color="#FFCC33" :style="{'transform':'scale(0.8)'}"/>
- <text>记住账号密码</text>
- </checkbox-group>
- </view>
- <view>
- <text @click="forgetPassword">忘记密码?</text>
- </view>
- </view>
- <view class="loginButton" @click="login">
- <text>登录</text>
- </view>
- <!-- <view class="loginButton" @click="getWxCosde">-->
- <!-- <text>获取微信code</text>-->
- <!-- </view>-->
- </u--form>
- </view>
- <!-- <view class="flex-row justify-center register">-->
- <!-- <text>无账号?</text>-->
- <!-- <text @click="goRegister" :style="{color:'#FFE05C'}">切换注册</text>-->
- <!-- </view>-->
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- requestStatus:false,
- savePassword:true,
- form: {
- username: '',
- password: ''
- },
- rules: {
- 'username': {
- type: 'string',
- required: true,
- min: 11,
- max: 11,
- pattern:this.$phonePattern,
- message: '请输入正确的电话号码',
- trigger: ['blur', 'change']
- },
- 'password': {
- type: 'string',
- required: true,
- min: 6,
- max: 18,
- message: '请输入6-18位密码',
- trigger: ['blur', 'change']
- }
- }
- }
- },
- onShow(){
- this.form.username = uni.getStorageSync('username')
- this.form.password = uni.getStorageSync('password')
- if (uni.getStorageSync('savePassword')){
- this.savePassword = uni.getStorageSync('savePassword')
- }
- },
- onLoad(e){
- console.log('重定向获取到的参数',e)
- console.log('重定向的url',location.href)
- let code = this.getUrlCode('code')
- if (code){
- uni.showToast({
- icon: 'success',
- duration: 5000,
- title: '获取到的code:'+code
- });
- }
- },
- methods: {
- getUrlCode(name) {
- return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) ||[, ''])[1].replace(/\+/g, '%20')) || null
- },
- getWxCosde(){
- const callBack = this.$callbackUrl; //回调地址 就是完整地址登录页
- 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'
- window.location.href = wx_url;
- },
- goRegister(){
- uni.redirectTo({
- url:'/pages/register/register'
- })
- },
- forgetPassword(){
- uni.navigateTo({
- url:'/pages/forgetPassword/forgetPassword'
- })
- },
- checkboxChange(e){
- this.savePassword = !this.savePassword
- console.log(this.savePassword)
- },
- login() {
- console.log('savePassword', this.savePassword)
- if (this.requestStatus){
- return
- }
- this.requestStatus=true
- this.$refs.uForm.validate().then(res => {
- console.log('savePassword', this.savePassword)
- if (this.savePassword){
- uni.setStorageSync('savePassword', this.savePassword)
- uni.setStorageSync('username', this.form.username)
- uni.setStorageSync('password', this.form.password)
- }else {
- uni.setStorageSync('savePassword', this.savePassword)
- uni.removeStorageSync('username');
- uni.removeStorageSync('password');
- }
- uni.showLoading({
- title: '登录中...'
- });
- this.$api.login.expandLogin(this.form).then(res => {
- uni.hideLoading();
- this.requestStatus=false
- uni.setStorageSync('accessToken', res.data.data.access_token)
- this.$api.user.getUserInfo().then(res=>{
- if (res.data.data.img){
- res.data.data.img = res.data.data.img.replace(/^http:/, "https:")
- }
- this.userInfo = res.data.data
- uni.setStorageSync('spreadUserInfo', this.userInfo)
- uni.showToast({
- icon: 'success',
- duration: 1000,
- title: '登陆成功'
- });
- setTimeout(()=>{
- uni.switchTab({
- url: "/pages/index/index"
- })
- },1000)
- })
- }).catch(err=>{
- this.requestStatus=false
- })
- }).catch(err=>{
- this.requestStatus=false
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import './index.rpx.css';
- </style>
|