new_shop_app/pages/users/login/login_copy.vue

1732 lines
44 KiB
Vue
Raw Normal View History

2024-02-24 16:08:09 +08:00
<template>
2024-04-27 11:47:31 +08:00
<view :style="viewColor">
<view class="register absolute" v-if="!auth_token">
<view class="login" style="background-size: 100% 100%;background-repeat: no-repeat;">
<view class="shading">
<view class="pictrue acea-row row-center-wrapper" style="background-color: transparent !important;">
<image src="@/static/images/logo1.png" />
</view>
</view>
<view class="" style="margin-top: 70rpx;" v-if='formItem==2'>
<view style="text-align: center;font-size: 36rpx;color: #20B128;font-weight: 700;">
重置密码
</view>
<view style="text-align: center;color: #BCBCBC;font-size: 24rpx;margin-top: 10rpx;">
请输入手机号码和验证码找回密码重置
</view>
</view>
<view class="whiteBg" v-if="formItem == 0">
<view class="logon" style="display: flex;align-items: center;justify-content: center;"
@click="wxLogin">
<u-icon name="weixin-fill" color="#fff" size="30"></u-icon> 微信一键登录
</view>
<view class="protocol acea-row row-between-wrapper">
<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
<checkbox class="checkbox" :checked="isAgree ? true : false" />
<text class="protocol_text">我已同意<text @click="userAgree"
class="font_pro">用户协议</text><text @click="userPrivacyAgree"
class="font_pro">隐私政策</text></text>
</checkbox-group>
</view>
</view>
<view class="whiteBg" v-else-if="formItem === 1">
<view class="title acea-row row-center-wrapper">
<view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList"
2024-02-24 16:08:09 +08:00
@click="navTap(index)" :key="index">
{{ item }}
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="list" :hidden="current !== 1">
2024-02-24 16:08:09 +08:00
<form @submit.prevent="submit">
2024-04-27 11:47:31 +08:00
<view class="item">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/phone_1.png"></image>
2024-03-21 14:36:34 +08:00
<input type="number" placeholder="输入账号" placeholder-class="placeholder"
2024-02-24 16:08:09 +08:00
v-model="account" required />
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item">
<view class="acea-row row-middle">
2024-04-30 18:56:28 +08:00
<image @click="type1=!type1" src="/static/images/eye.png"></image>
<input :type="type1?'password':'input'" placeholder="填写登录密码"
placeholder-class="placeholder" v-model="password" required />
2024-04-27 11:47:31 +08:00
<button class="code" @click="formItem=2">
忘记密码
</button>
</view>
</view>
2024-02-24 16:08:09 +08:00
</form>
2024-04-27 11:47:31 +08:00
</view>
<view class="list" :hidden="current !== 0">
<view class="item">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/phone_1.png"></image>
2024-03-21 14:36:34 +08:00
<input type="number" placeholder="输入手机号码" placeholder-class="placeholder"
2024-02-24 16:08:09 +08:00
v-model="account" />
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/code_2.png"></image>
2024-04-27 11:47:31 +08:00
<input type="number" placeholder="填写验证码" placeholder-class="placeholder"
class="codeIput" v-model="captcha" maxlength="4" />
2024-02-24 16:08:09 +08:00
<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''"
@click="handleVerify">
{{ text }}
</button>
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item" v-if="isShowCode">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/code_2.png"></image>
2024-04-27 11:47:31 +08:00
<input type="number" placeholder="填写验证码" placeholder-class="placeholder"
class="codeIput" v-model="codeVal" maxlength="4" />
<view class="code" @click="getcaptcha">
2024-02-24 16:08:09 +08:00
<image class="code-img" style="width: 100%;height: 100%;" :src="codeUrl" />
2024-04-27 11:47:31 +08:00
</view>
</view>
</view>
</view>
2024-04-30 09:33:23 +08:00
<view class="logon" @click="loginMobile" :hidden="current !== 0">登录</view>
2024-04-27 11:47:31 +08:00
<view class="logon" @click="submit" :hidden="current === 0">账号登录</view>
<view class="protocol acea-row row-between-wrapper">
2024-02-24 16:08:09 +08:00
<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
<checkbox class="checkbox" :checked="isAgree ? true : false" />
<text class="protocol_text">我已同意<text @click="userAgree"
class="font_pro">用户协议</text><text @click="userPrivacyAgree"
class="font_pro">隐私政策</text></text>
</checkbox-group>
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="whiteBg" style="margin-top: 0;" v-else-if='formItem==2'>
<view class="list">
<view class="item">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/phone_1.png"></image>
2024-03-21 14:36:34 +08:00
<input type="number" placeholder="输入手机号码" placeholder-class="placeholder"
2024-02-24 16:08:09 +08:00
v-model="account" />
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/code_2.png"></image>
2024-04-27 11:47:31 +08:00
<input type="number" placeholder="填写验证码" maxLength='4' placeholder-class="placeholder"
class="codeIput" v-model="captcha" />
2024-02-24 16:08:09 +08:00
<button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''"
@click="handleVerify">
{{ text }}
</button>
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item">
<view class="acea-row row-middle">
2024-04-30 18:56:28 +08:00
<image @click="type2=!type2" src="/static/images/eye.png"></image>
<input :type="type2?'password':'input'" placeholder="请输入新密码"
placeholder-class="placeholder" v-model="password" />
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item">
<view class="acea-row row-middle">
2024-04-30 18:56:28 +08:00
<image @click="type3=!type3" src="/static/images/eye.png"></image>
<input :type="type3?'password':'input'" placeholder="请再次输入密码"
placeholder-class="placeholder" v-model="confirm_pwd" />
2024-04-27 11:47:31 +08:00
</view>
</view>
<view class="item" v-if="isShowCode">
<view class="acea-row row-middle">
2024-02-24 16:08:09 +08:00
<image src="/static/images/code_2.png"></image>
2024-04-27 11:47:31 +08:00
<input type="number" placeholder="填写验证码" maxlength="4" placeholder-class="placeholder"
class="codeIput" v-model="codeVal" />
<view class="code" @click="getcaptcha">
2024-02-24 16:08:09 +08:00
<image class="code-img" style="width: 100%;height: 100%;" :src="codeUrl" />
2024-04-27 11:47:31 +08:00
</view>
</view>
</view>
</view>
<view class="logon" @click="registerReset">完成并登录</view>
<view class="tip">
<text @click="formItem=1">立即登录</text>
</view>
<view class="protocol acea-row row-between-wrapper">
2024-02-24 16:08:09 +08:00
<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
<checkbox class="checkbox" :checked="isAgree ? true : false" />
<text class="protocol_text">我已同意<text @click="userAgree"
class="font_pro">用户协议</text><text @click="userPrivacyAgree"
class="font_pro">隐私政策</text></text>
</checkbox-group>
2024-04-27 11:47:31 +08:00
</view>
</view>
</view>
<view class="bottom"></view>
2024-02-24 16:08:09 +08:00
<view class="settlementAgreement" v-if="showAgreement">
<view class="setAgCount">
<i class="icon iconfont icon-cha" @click="showAgreement = false"></i>
2024-04-27 11:47:31 +08:00
<view class="title">用户协议与隐私政策</view>
2024-02-24 16:08:09 +08:00
<view class="content">
<jyf-parser :html="agreement" ref="article" :tag-style="tagStyle"></jyf-parser>
</view>
</view>
</view>
2024-04-27 11:47:31 +08:00
<!-- #ifdef APP-PLUS -->
2024-04-27 14:43:05 +08:00
<view class="footer-btns" v-if='formItem!=2'>
2024-04-27 11:47:31 +08:00
<view class="login-type-btn" :class="{actLoginType:formItem==0}" style="margin-right: 70rpx;">
<text v-if='formItem == 1' @click="formItem = 0">微信快捷登录</text>
<text v-else @click="appOneClcik">本机一键登录</text>
</view>
<view class="login-type-btn" :class="{actLoginType:formItem==1}">
<text v-if='formItem == 0' @click="formItem = 1">更多登录方式</text>
<text v-else @click="appOneClcik">本机一键登录</text>
</view>
</view>
<!-- #endif -->
</view>
2024-02-24 16:08:09 +08:00
<form report-submit='true' v-if="auth_token">
<view class="ChangePassword">
2024-04-27 11:47:31 +08:00
<view class="title">
<view>首次登录</view>
<view style="font-size: 36rpx;">需要绑定手机号码</view>
</view>
2024-02-24 16:08:09 +08:00
<view class="list">
<view class="item">
<input type='number' placeholder='填写手机号码' placeholder-class='placeholder'
v-model="account"></input>
</view>
2024-04-27 11:47:31 +08:00
2024-02-24 16:08:09 +08:00
<view class="item acea-row row-between-wrapper">
2024-04-27 11:47:31 +08:00
<input type='number' placeholder='填写验证码' maxlength="4" placeholder-class='placeholder'
class="codeIput" v-model="captcha"></input>
2024-02-24 16:08:09 +08:00
<button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled'
@click="handleVerify">
{{ text }}
</button>
</view>
<view class="item">
2024-04-27 11:47:31 +08:00
<input type='password' placeholder='填写登录密码' placeholder-class='placeholder'
2024-02-24 16:08:09 +08:00
v-model="password"></input>
</view>
<view class="protocol acea-row row-between-wrapper">
<checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
<checkbox class="checkbox" :checked="isAgree ? true : false" />
<text class="protocol_text">我已同意<text @click="userAgree"
class="font_pro">用户协议</text><text @click="userPrivacyAgree"
class="font_pro">隐私政策</text></text>
</checkbox-group>
</view>
</view>
2024-03-15 17:01:27 +08:00
<button form-type="submit" @click="weixinMerge" class="confirmBnt">确认绑定</button>
2024-02-24 16:08:09 +08:00
<button form-type="submit" @click="auth_token = ''" class="confirmBnt back">返回</button>
</view>
</form>
<Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }"
ref="verify"></Verify>
2024-04-27 11:47:31 +08:00
<!-- tips弹窗 -->
<u-overlay :show="showTips">
<view class="tips">
<view class="" style="font-size: 32rpx;">
2024-04-30 09:33:23 +08:00
温馨提示
2024-04-27 11:47:31 +08:00
</view>
<block v-if="tispTile=='密码错误'">
<view class="">
{{tipsErr}}
</view>
<view class="" style="display: flex;">
<view style="width: 236rpx;height: 84rpx;margin-right:38rpx;">
<u-button plain text="找回密码" @tap="showTips=false,formItem=2"></u-button>
</view>
<view style="width: 236rpx;height: 84rpx;">
<u-button color="#46BF6F" text="重新输入" @tap="showTips=false"></u-button>
</view>
</view>
</block>
<block v-else-if="tispTile=='验证码错误'">
<view class="">
验证码错误请重新收入
</view>
<view class="" style="display: flex;">
<u-button color="#46BF6F" text="确定" @tap="showTips=false"></u-button>
</view>
</block>
<block v-else-if="tispTile=='密码不一致'">
<view class="">
两次输入的密码不一致请重新输入
</view>
<view class="" style="display: flex;">
<u-button color="#46BF6F" text="确定" @tap="showTips=false"></u-button>
</view>
</block>
<block v-else>
2024-04-30 09:33:23 +08:00
<view class="">
{{tispTile}}
</view>
2024-04-27 11:47:31 +08:00
<view class="" style="display: flex;width: 236rpx;">
<u-button color="#46BF6F" text="确定" @tap="showTips=false"></u-button>
</view>
</block>
</view>
</u-overlay>
<!-- tips结束 -->
</view>
2024-02-24 16:08:09 +08:00
</template>
<script>
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
import dayjs from "@/plugin/dayjs/dayjs.min.js";
import sendVerifyCode from "@/mixins/SendVerifyCode";
import {
loginH5,
loginMobile,
registerVerify,
register,
getCodeApi,
getUserInfo,
getCaptcha,
getAgreementApi,
appleLogin,
2024-04-27 11:47:31 +08:00
loginMpPhone,
registerForget,
phonelogin
2024-02-24 16:08:09 +08:00
} from "@/api/user";
// #ifdef APP-PLUS
import {
wechatAppAuth,
appleAppAuth
} from '@/api/api.js'
// #endif
import attrs, {
required,
alpha_num,
chs_phone
} from "@/utils/validate";
import {
validatorDefaultCatch
} from "@/utils/dialog";
import {
getLogo,
getconfig,
getVersion,
bindMp,
bindJG
} from "@/api/public";
// import cookie from "@/utils/store/cookie";
import {
VUE_APP_API_URL,
configMap
} from "@/utils";
import parser from "@/components/jyf-parser/jyf-parser";
import {
2024-03-15 17:01:27 +08:00
commonAuth,
2024-04-27 11:47:31 +08:00
userMerge
2024-02-24 16:08:09 +08:00
} from '../../../api/public';
import {
mapGetters
} from "vuex";
import Verify from '@/components/verify/verify.vue';
2024-04-27 11:47:31 +08:00
import {
Toast
} from "../../../libs/uniApi";
2024-02-24 16:08:09 +08:00
const BACK_URL = "login_back_url";
// #ifdef APP-PLUS
2024-04-27 11:47:31 +08:00
import oneClickStyle from "./oneClickStyle.js"
2024-02-24 16:08:09 +08:00
var jpushModule = uni.requireNativePlugin("JG-JPush");
// #endif
export default {
name: "Login",
mixins: [sendVerifyCode],
components: {
"jyf-parser": parser,
Verify
},
data: function() {
return {
2024-04-30 18:56:28 +08:00
type1: true,
type2: true,
type3: true,
2024-04-27 11:47:31 +08:00
tipsErr: "",
tispTile: '密码错误',
showTips: false,
navList: ["快速登录", "账号登录"],
2024-02-24 16:08:09 +08:00
current: 0,
account: "",
password: "",
2024-04-27 11:47:31 +08:00
confirm_pwd: "",
2024-02-24 16:08:09 +08:00
captcha: "",
2024-03-15 17:01:27 +08:00
// #ifdef APP-PLUS
formItem: 0,
// #endif
2024-04-27 11:47:31 +08:00
// #ifndef APP-PLUS
formItem: 1,
// #endif
2024-02-24 16:08:09 +08:00
type: "login",
keyCode: "",
codeUrl: "",
codeVal: "",
isShowCode: false,
showAgreement: false,
tagStyle: {
img: 'width:100%;display:block;'
},
isAgree: false,
agreement: '',
appLoginStatus: false, // 微信登录强制绑定手机号码状态
appUserInfo: null, // 微信登录保存的用户信息
appleLoginStatus: false, // 苹果登录强制绑定手机号码状态
appleUserInfo: null,
appleShow: false, // 苹果登录版本必须要求ios13以上的
keyLock: true,
auth_token: '',
codeVal: '',
copyright: {}
};
},
computed: configMap(['login_logo'], mapGetters(['viewColor'])),
watch: {
formItem: function(nval, oVal) {
if (nval == 1) {
this.type = 'login'
2024-04-27 11:47:31 +08:00
} else if (nval == 2) {
this.type = 'change_pwd'
2024-02-24 16:08:09 +08:00
} else {
this.type = 'register'
}
2024-03-15 17:01:27 +08:00
},
2024-02-24 16:08:09 +08:00
},
onLoad() {
let self = this
uni.getSystemInfo({
success: function(res) {
if (res.platform.toLowerCase() == 'ios' && self.getSystem(res.system) >= 13) {
self.appleShow = true
}
}
});
this.getVersion();
},
mounted: function() {
2024-04-27 11:47:31 +08:00
2024-02-24 16:08:09 +08:00
},
onReady() {
let that = this
// #ifdef MP
wx.login({
success(res) {
if (res.code) {
that.codeVal = res.code
} else {
// console.log('登录失败!' + res.errMsg)
}
}
})
// #endif
},
methods: {
2024-04-27 11:47:31 +08:00
showTipsFn(text, err) {
this.showTips = true
this.tispTile = text
this.tipsErr = err || ''
},
navgo(url) {
uni.navigateTo({
url
})
},
2024-02-24 16:08:09 +08:00
// #ifdef MP
getPhoneNumber(e) {
let that = this;
loginMpPhone({
iv: e.detail.iv,
encryptedData: e.detail.encryptedData,
code: that.codeVal,
auth_token: uni.getStorageSync('auth_token'),
}).then(({
data
}) => {
2024-04-27 11:47:31 +08:00
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
2024-02-24 16:08:09 +08:00
that.$Cache.clear(BACK_URL);
2024-03-15 17:01:27 +08:00
that.$Cache.clear('login_back_url_weixin');
2024-02-24 16:08:09 +08:00
that.$store.commit("LOGIN", {
'token': data.token,
'time': data.exp
});
that.$store.commit("SETUID", data.user.uid);
that.$store.commit('UPDATE_USERINFO', data.user);
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index', '/pages/plant_grass/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
})
.catch(res => {
that.$util.Tips({
title: res
});
});
},
// #endif
goCopyUrl() {
// #ifdef H5
// location.href = 'http://' + this.copyright.url
// #endif
},
userAgree() {
uni.navigateTo({
url: '/pages/users/user_about/index?from=sys_user_agree'
})
},
userPrivacyAgree() {
uni.navigateTo({
url: '/pages/users/user_about/index?from=sys_userr_privacy'
})
},
getSystem(system) {
if (system.indexOf('iOS') === -1) {
return system
} else {
let str = system.split(' ')[1]
if (str.indexOf('.')) {
return Number(str.split('.')[0])
} else {
return Number(str)
}
}
},
// 苹果登录
appleLogin() {
let self = this
this.account = ''
this.captcha = ''
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'apple',
timeout: 10000,
success(loginRes) {
uni.getUserInfo({
provider: 'apple',
success: function(infoRes) {
self.appleUserInfo = infoRes.userInfo
self.appleLoginApi()
},
fail() {
uni.showToast({
title: '获取用户信息失败',
icon: 'none',
duration: 2000
})
},
complete() {
uni.hideLoading()
}
});
},
fail(error) {
uni.showToast({
title: '获取用户信息失败',
icon: 'none',
duration: 2000
})
// console.log(error)
}
})
},
appleLoginApi() {
let that = this
commonAuth({
auth: {
type: 'apple',
auth: {
userInfo: that.appleUserInfo,
openId: that.appleUserInfo.openId,
nickname: (that.appleUserInfo.fullName.familyName || '') + (that.appleUserInfo.fullName
.giveName || ''),
}
}
}).then(res => {
const data = res.data;
if (res.data.status == 200) {
2024-04-27 11:47:31 +08:00
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
2024-02-24 16:08:09 +08:00
that.$Cache.clear(BACK_URL);
2024-03-15 17:01:27 +08:00
that.$Cache.clear('login_back_url_weixin');
2024-02-24 16:08:09 +08:00
that.$store.commit("LOGIN", {
'token': data.result.token,
'time': data.result.exp
});
that.$store.commit("SETUID", data.result.user.uid);
that.$store.commit('UPDATE_USERINFO', data.result.user);
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index', '/pages/plant_grass/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
} else {
uni.hideLoading();
that.auth_token = res.data.result.key;
}
}).catch(res => {
uni.hideLoading();
uni.showToast({
title: res.message || res,
icon: 'none',
duration: 2000
});
});
},
// App微信登录
wxLogin() {
if (!this.isAgree) return this.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
let self = this
this.account = ''
this.captcha = ''
uni.showLoading({
title: '登录中'
})
uni.login({
provider: 'weixin',
2024-03-15 17:01:27 +08:00
onlyAuthorize: true,
2024-02-24 16:08:09 +08:00
success: function(loginRes) {
2024-04-27 11:47:31 +08:00
console.log(loginRes);
uni.hideLoading()
2024-03-15 17:01:27 +08:00
self.appUserInfo = loginRes;
self.weixinLoginApi()
2024-02-24 16:08:09 +08:00
},
fail(error) {
2024-04-27 11:47:31 +08:00
console.log(error);
2024-02-24 16:08:09 +08:00
uni.showToast({
title: '登录失败',
icon: 'none',
duration: 2000
})
}
});
},
getPath(url) {
if (url.indexOf("?") != -1) {
url = url.split("?")[0];
// console.log(url);
}
return url
},
wxLoginApi() {
const that = this
commonAuth({
auth: {
type: 'app_wechat',
2024-04-27 11:47:31 +08:00
auth: {
code: that.appUserInfo.authResult.access_token,
openid: that.appUserInfo.authResult.openid,
phone: this.account,
}
}
}).then(res => {
const data = res.data;
if (res.data.status == 200) {
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
that.$Cache.clear(BACK_URL);
that.$Cache.clear('login_back_url_weixin');
that.$store.commit("LOGIN", {
'token': data.result.token,
'time': data.result.exp
});
that.$store.commit("SETUID", data.result.user.uid);
that.$store.commit('UPDATE_USERINFO', data.result.user);
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index', '/pages/plant_grass/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
} else {
that.isAgree = false;
that.auth_token = res.data.result.key;
that.bindStatus = true;
}
uni.hideLoading();
}).catch(res => {
console.log(res);
uni.hideLoading();
uni.showToast({
title: res.message || res,
icon: 'none',
duration: 2000
});
});
},
weixinLoginApi() {
const that = this
commonAuth({
auth: {
type: 'app_wechat',
auth: {
code: that.appUserInfo.code
}
2024-02-24 16:08:09 +08:00
}
}).then(res => {
2024-04-27 11:47:31 +08:00
console.log('--', res);
2024-02-24 16:08:09 +08:00
const data = res.data;
if (res.data.status == 200) {
2024-04-27 11:47:31 +08:00
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
2024-02-24 16:08:09 +08:00
that.$Cache.clear(BACK_URL);
2024-03-15 17:01:27 +08:00
that.$Cache.clear('login_back_url_weixin');
2024-02-24 16:08:09 +08:00
that.$store.commit("LOGIN", {
'token': data.result.token,
'time': data.result.exp
});
that.$store.commit("SETUID", data.result.user.uid);
that.$store.commit('UPDATE_USERINFO', data.result.user);
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index', '/pages/plant_grass/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
} else {
2024-04-27 11:47:31 +08:00
that.isAgree = false;
2024-02-24 16:08:09 +08:00
that.auth_token = res.data.result.key;
that.bindStatus = true;
}
uni.hideLoading();
}).catch(res => {
2024-04-27 11:47:31 +08:00
console.log('错误--', res);
2024-02-24 16:08:09 +08:00
uni.hideLoading();
uni.showToast({
title: res.message || res,
icon: 'none',
duration: 2000
});
});
},
getAgreement() {
let that = this
getAgreementApi('sys_user_agree').then(res => {
that.agreement = res.data.sys_user_agree
})
},
getCode(data) {
let that = this
getCodeApi()
.then(res => {
that.keyCode = res.data.key;
that.code(data);
})
.catch(res => {
that.$util.Tips({
title: res
});
});
},
2024-04-27 11:47:31 +08:00
// 快速登录
2024-02-24 16:08:09 +08:00
async loginMobile() {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (!that.captcha) return that.$util.Tips({
title: '请输入验证码'
});
if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
title: '请输入正确的验证码'
});
if (!that.isAgree) return that.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
loginMobile({
auth_token: uni.getStorageSync('auth_token'),
phone: that.account,
sms_code: that.captcha,
spread: that.$Cache.get("spread"),
// #ifdef APP-PLUS
user_type: 'app',
// #endif
// #ifdef H5
user_type: 'h5',
// #endif
})
.then(({
data
}) => {
this.checkOpenId(data.user)
2024-04-27 11:47:31 +08:00
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
2024-02-24 16:08:09 +08:00
that.$store.commit("LOGIN", {
'token': data.token,
'time': data.exp
});
that.$store.commit("SETUID", data.user.uid);
that.$store.commit('UPDATE_USERINFO', data.user);
2024-04-27 11:47:31 +08:00
if (data.is_new_user && !that.$Cache.get('login_back_url_weixin')) {
return uni.navigateTo({
url: '/pages/helpPeople/helpPeople'
})
}
that.$Cache.clear(BACK_URL);
that.$Cache.clear('login_back_url_weixin');
2024-02-24 16:08:09 +08:00
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
})
.catch(res => {
2024-04-27 11:47:31 +08:00
that.showTipsFn(res)
2024-02-24 16:08:09 +08:00
});
},
async register() {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (!that.captcha) return that.$util.Tips({
title: '请输入验证码'
});
if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
title: '请输入正确的验证码'
});
if (!that.password) return that.$util.Tips({
title: '请输入密码'
});
if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
title: '请输入6-16位字母加数字组合'
});
if (!that.isAgree) return that.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
register({
auth_token: this.auth_token || uni.getStorageSync('auth_token'),
phone: that.account,
sms_code: that.captcha,
pwd: that.password,
spread: that.$Cache.get("spread"),
// #ifdef APP-PLUS
user_type: 'app',
// #endif
// #ifdef H5
user_type: 'h5',
// #endif
})
.then(res => {
that.$store.commit("LOGIN", {
'token': res.data.token,
'time': res.data.exp
});
that.$store.commit("SETUID", res.data.user.uid);
that.$store.commit('UPDATE_USERINFO', res.data.user);
2024-04-27 11:47:31 +08:00
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
that.$Cache.clear(BACK_URL);
that.$Cache.clear('login_back_url_weixin');
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
uni[method]({
url: backUrl,
success: () => {
this.auth_token = ''
}
});
})
.catch(res => {
console.log(res, 'res')
that.showTipsFn('密码错误', res)
});
},
async weixinMerge() {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (!that.captcha) return that.$util.Tips({
title: '请输入验证码'
});
if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
title: '请输入正确的验证码'
});
if (!that.password) return that.$util.Tips({
title: '请输入密码'
});
if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
title: '请输入6-16位字母加数字组合'
});
if (!that.isAgree) return that.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
console.log('绑定前', {
auth_token: this.auth_token || uni.getStorageSync('auth_token'),
phone: that.account,
sms_code: that.captcha,
pwd: that.password,
spread: that.$Cache.get("spread"),
// #ifdef APP-PLUS
user_type: 'app',
// #endif
// #ifdef H5
user_type: 'h5',
// #endif
});
userMerge({
auth_token: this.auth_token || uni.getStorageSync('auth_token'),
phone: that.account,
sms_code: that.captcha,
pwd: that.password,
spread: that.$Cache.get("spread"),
// #ifdef APP-PLUS
user_type: 'app',
// #endif
// #ifdef H5
user_type: 'h5',
// #endif
})
.then(res => {
console.log(res);
that.$store.commit("LOGIN", {
'token': res.data.token,
'time': res.data.exp
});
that.$store.commit("SETUID", res.data.user.uid);
that.$store.commit('UPDATE_USERINFO', res.data.user);
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
2024-03-15 17:01:27 +08:00
that.$Cache.clear(BACK_URL);
that.$Cache.clear('login_back_url_weixin');
2024-04-27 11:47:31 +08:00
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
uni[method]({
url: backUrl,
success: () => {
this.auth_token = ''
}
});
2024-02-24 16:08:09 +08:00
})
.catch(res => {
2024-04-27 11:47:31 +08:00
console.log('error', err);
2024-02-24 16:08:09 +08:00
that.$util.Tips({
title: res
});
});
},
async code(data) {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
// if (that.formItem == 2) that.type = "register";
await registerVerify({
phone: that.account,
2024-04-27 11:47:31 +08:00
type: that.type,
2024-02-24 16:08:09 +08:00
key: that.keyCode,
// code: that.codeVal,
toke: data.token,
captchaType: 'blockPuzzle',
captchaVerification: data.captchaVerification
})
.then(res => {
that.$util.Tips({
title: res.message
});
that.sendCode();
})
.catch(res => {
that.$util.Tips({
title: res
});
});
},
2024-04-27 11:47:31 +08:00
async registerReset() {
var that = this;
if (!that.account) return that.$util.Tips({
title: '请填写手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (that.password == '123456') return that.$util.Tips({
title: '您输入的密码过于简单'
});
if (that.password != that.confirm_pwd) return that.$util.Tips({
title: '两次密码不一致'
});
if (!that.captcha) return that.$util.Tips({
title: '请填写验证码'
});
registerForget({
phone: that.account,
sms_code: that.captcha,
pwd: that.password,
confirm_pwd: that.confirm_pwd
})
.then(res => {
that.submitSuccess(res.data)
})
.catch(res => {
that.$util.Tips({
title: res
})
});
},
2024-02-24 16:08:09 +08:00
getcaptcha() {
let that = this
getCaptcha().then(data => {
// that.codeUrl = `${VUE_APP_API_URL}/sms_captcha?key=${that.keyCode}`;
that.codeUrl = data.data.captcha;
that.keyCode = data.data.key
})
that.isShowCode = true;
},
navTap: function(index) {
this.current = index;
},
getPath(url) {
if (url.indexOf("?") != -1) {
url = url.split("?")[0];
}
return url
},
2024-04-27 11:47:31 +08:00
// 账号登录
2024-02-24 16:08:09 +08:00
async submit() {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入账号'
});
if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的账号'
});
if (!that.password) return that.$util.Tips({
title: '请输入密码'
});
if (!that.isAgree) return that.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
loginH5({
auth_token: uni.getStorageSync('auth_token'),
account: that.account,
password: that.password,
spread: that.$Cache.get("spread")
})
.then(({
data
}) => {
2024-04-27 11:47:31 +08:00
this.submitSuccess(data)
2024-02-24 16:08:09 +08:00
})
.catch(e => {
2024-04-27 11:47:31 +08:00
that.showTipsFn("密码错误", e)
2024-02-24 16:08:09 +08:00
});
},
2024-04-27 11:47:31 +08:00
// 账号密码验证通过后的逻辑
submitSuccess(data) {
console.log(data, 'hanshu')
let that = this
this.checkOpenId(data.user)
const backUrl = that.$Cache.get('login_back_url_weixin') || that.$Cache.get(BACK_URL) ||
"/pages/index/index";
that.$store.commit("LOGIN", {
'token': data.token,
'time': data.exp
});
that.$store.commit("SETUID", data.user.uid);
that.$store.commit('UPDATE_USERINFO', data.user);
if (data.is_new_user && !that.$Cache.get('login_back_url_weixin')) {
return uni.navigateTo({
url: '/pages/helpPeople/helpPeople'
})
}
that.$Cache.clear(BACK_URL);
that.$Cache.clear('login_back_url_weixin');
let method
let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart',
'/pages/goods_cate/goods_cate',
'/pages/user/index'
]
if (indexPat.includes(this.getPath(backUrl))) {
method = 'switchTab'
} else {
method = 'navigateTo'
}
if (this.getPath(backUrl) === '/pages/users/login/index') {
uni.switchTab({
url: '/pages/index/index'
});
return
}
uni[method]({
url: backUrl
});
},
2024-02-24 16:08:09 +08:00
getVersion() {
getVersion().then(data => {
this.copyright = data.data;
});
},
success(data) {
this.$refs.verify.hide();
this.code(data);
},
handleVerify() {
let that = this;
if (!that.account) return that.$util.Tips({
title: '请输入手机号码'
});
if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
title: '请输入正确的手机号码'
});
if (!that.isAgree) return that.$util.Tips({
title: '请勾选用户协议与隐私政策'
});
that.$refs.verify.show();
},
checkOpenId(user) {
if (user.wechat_user_id === 0) {
let that = this
2024-04-27 11:47:31 +08:00
try {
wx.getUserInfo({
success: function(res) {
const encryptedData = res.encryptedData
const iv = res.iv
wx.login({
success(res) {
if (res.code) {
bindMp({
code: res.code,
iv: iv,
encryptedData: encryptedData,
phone: that.account
}).then(res => {
// console.log(res);
})
} else {
// console.log('登录失败!' + res.errMsg)
}
}
})
},
fail(e) {
// console.log('登录失败!' + res.errMsg)
}
})
} catch (e) {
console.log(e);
2024-02-24 16:08:09 +08:00
}
}
// #ifdef APP-PLUS
jpushModule.initJPushService()
jpushModule.getRegistrationID(result => {
if (result.registerID) {
bindJG({
phone: this.account,
jg_register_id: result.registerID
2024-04-27 11:47:31 +08:00
}).then(res => {
console.log("绑定成功", res);
}).catch(err => {
console.log("绑定失败", err);
})
2024-02-24 16:08:09 +08:00
}
})
// #endif
2024-04-27 11:47:31 +08:00
},
// app手机号一键登录
appOneClcik() {
let that = this
uni.preLogin({
provider: 'univerify',
success() {
console.log("当前环境支持一键登录")
uni.login({
provider: 'univerify',
univerifyStyle: oneClickStyle,
success(res) {
console.log(res, 'res')
phonelogin({
access_token: res.authResult.access_token,
openid: res.authResult.openid,
auth_token: that.auth_token,
user_type: 'app'
}).then(res => {
uni.closeAuthView()
that.submitSuccess(res.data)
}).catch(err => {
uni.closeAuthView()
that.$util.Tips({
title: '登录失败,请稍后再试'
});
})
// uniCloud.callFunction({
// name: 'oneClickLoginFn',
// data: {
// 'access_token': res.authResult
// .access_token,
// 'openid': res.authResult.openid
// }
// }).then(res => {
// console.log(res, '登录成功后的res')
// }).catch(err => {
// console.log(err, 'ererre')
// })
},
fail(res) { // 登录失败
console.log(res.errCode)
console.log(res.errMsg)
}
})
},
fail(res) {
that.$util.Tips({
title: '当前环境不支持一键登录'
});
}
})
2024-02-24 16:08:09 +08:00
}
2024-04-27 11:47:31 +08:00
2024-02-24 16:08:09 +08:00
}
};
</script>
<style lang="scss" scoped>
page {
background-color: #fff !important;
}
/deep/uni-checkbox .uni-checkbox-input {
border-radius: 100%;
}
2024-04-27 11:47:31 +08:00
.ChangePassword {
.title {
width: 580rpx;
margin: 180rpx auto 0 auto;
font-size: 46rpx;
color: #7f7f7f;
}
}
2024-02-24 16:08:09 +08:00
.ChangePassword .phone {
font-size: 32rpx;
font-weight: bold;
text-align: center;
margin-top: 55rpx;
}
.ChangePassword .list {
width: 580rpx;
margin: 53rpx auto 0 auto;
}
.ChangePassword .list .item {
width: 100%;
height: 110rpx;
border-bottom: 2rpx solid #f0f0f0;
}
.ChangePassword .list .item input {
width: 100%;
height: 100%;
font-size: 32rpx;
}
.ChangePassword .list .item .placeholder {
color: #b9b9bc;
}
.ChangePassword .list .item input.codeIput {
width: 240rpx;
}
/deep/.uni-input-wrapper,
/deep/.uni-input-input {
// width: 240rpx;
}
.ChangePassword .list .item .code {
font-size: 32rpx;
background-color: #fff;
color: var(--view-theme);
}
.ChangePassword .list .item .code.on {
color: #b9b9bc;
}
.ChangePassword .confirmBnt {
font-size: 32rpx;
width: 580rpx;
height: 90rpx;
border-radius: 45rpx;
color: #fff;
margin: 92rpx auto 0 auto;
text-align: center;
line-height: 90rpx;
background-color: var(--view-theme);
}
.ChangePassword .confirmBnt.back {
background-color: #FFFFFF;
border: 1px solid var(--view-theme);
color: var(--view-theme);
margin-top: 30rpx;
}
.getPhoneBtn {
font-size: 32rpx;
width: 580rpx;
height: 90rpx;
border-radius: 45rpx;
border: 1rpx solid #3CB625;
color: #3CB625;
margin: 40rpx auto 0 auto;
text-align: center;
line-height: 90rpx;
.iconfont {
font-size: 32rpx;
margin-right: 12rpx;
}
}
.code image {
width: 100%;
height: 100%;
}
.acea-row.row-middle {
input {
margin-left: 20rpx;
}
}
.settlementAgreement {
width: 100%;
height: 100%;
position: fixed;
top: 0;
left: 0;
background: rgba(0, 0, 0, .5);
z-index: 10;
}
.protocol_text {
color: #999;
font-size: 24rpx;
}
.settlementAgreement .setAgCount {
background: #fff;
width: 656rpx;
height: 458px;
position: absolute;
top: 50%;
left: 50%;
border-radius: 12rpx;
-webkit-border-radius: 12rpx;
padding: 52rpx;
-webkit-transform: translate(-50%, -50%);
-moz-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
overflow: hidden;
.content {
height: 900rpx;
overflow-y: scroll;
/deep/ p {
font-size: 13px;
line-height: 22px;
}
/deep/ img {
max-width: 100%;
}
}
}
.settlementAgreement .setAgCount .icon {
font-size: 42rpx;
color: #b4b1b4;
position: absolute;
top: 15rpx;
right: 15rpx;
}
.settlementAgreement .setAgCount .title {
color: #333;
font-size: 32rpx;
text-align: center;
font-weight: bold;
}
.settlementAgreement .setAgCount .content {
margin-top: 32rpx;
color: #333;
font-size: 26rpx;
line-height: 22px;
text-align: justify;
text-justify: distribute-all-lines;
height: 756rpx;
overflow-y: scroll;
}
.protocol {
display: flex;
justify-content: center;
text-align: center;
margin-top: 30rpx;
}
.protocol_text {
.font_pro {
2024-03-15 17:01:27 +08:00
color: var(--view-theme);
2024-02-24 16:08:09 +08:00
}
}
.appLogin {
.hds {
display: flex;
justify-content: center;
align-items: center;
font-size: 24rpx;
color: #B4B4B4;
.line {
width: 68rpx;
height: 1rpx;
background: #CCCCCC;
}
p {
margin: 0 20rpx;
}
}
.btn-wrapper {
display: flex;
align-items: center;
justify-content: center;
margin-top: 30rpx;
.btn {
display: flex;
align-items: center;
justify-content: center;
width: 68rpx;
height: 68rpx;
border-radius: 50%;
+.btn {
margin-left: 30rpx;
}
}
.apple-btn {
display: flex;
align-items: center;
justify-content: center;
width: 246rpx;
height: 66rpx;
margin-left: 10rpx;
background: #EAEAEA;
border-radius: 34rpx;
font-size: 24rpx;
.icon-s-pingguo {
color: #333;
margin-right: 10rpx;
font-size: 34rpx;
}
}
.iconfont {
font-size: 40rpx;
color: #fff;
}
.wx {
// margin-right: 30rpx;
background-color: #61C64F;
&.btn-apple {
margin-right: 0;
background-color: #333;
}
}
.mima {
background-color: #28B3E9;
}
.yanzheng {
background-color: #F89C23;
}
}
}
.code img {
width: 100%;
height: 100%;
}
.acea-row.row-middle {
input {
margin-left: 20rpx;
display: block;
}
}
.login-wrapper {
padding: 30rpx;
.shading {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
/* #ifdef APP-VUE */
margin-top: 50rpx;
/* #endif */
/* #ifndef APP-VUE */
margin-top: 200rpx;
/* #endif */
image {
width: 180rpx;
height: 180rpx;
}
}
.whiteBg {
margin-top: 100rpx;
2024-04-27 11:47:31 +08:00
transition: 300ms;
2024-02-24 16:08:09 +08:00
.list {
border-radius: 16rpx;
overflow: hidden;
.item {
border-bottom: 1px solid #F0F0F0;
background: #fff;
.row-middle {
position: relative;
padding: 16rpx 45rpx;
input {
flex: 1;
font-size: 28rpx;
height: 80rpx;
}
.code {
color: #E93323;
font-size: 26rpx;
transform: translateY(-50%);
}
}
}
}
.logon {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 86rpx;
margin-top: 80rpx;
background-color: $theme-color;
border-radius: 120rpx;
color: #FFFFFF;
font-size: 30rpx;
}
.tips {
margin: 30rpx;
text-align: center;
color: #999;
}
}
}
.copyright {
position: absolute;
bottom: 30rpx;
left: 0;
width: 100%;
text-align: center;
font-size: 20rpx;
line-height: 28rpx;
color: #ccc;
.cell {
// margin-left: 6rpx;
font-size: 20rpx;
}
}
2024-04-27 11:47:31 +08:00
.footer-btns {
position: absolute;
bottom: 160rpx;
left: 50%;
transform: translate(-50%);
display: flex;
justify-content: space-between;
width: 750rpx !important;
padding: 0 112rpx;
.login-type-btn {
padding: 12rpx 30rpx;
border-radius: 32rpx;
background-color: #F6F6F6
}
.actLoginType {
color: #20B128;
background-color: #E8F7E9;
}
}
.tips {
width: 590rpx;
height: 354rpx;
background-color: white;
border-radius: 16rpx;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
box-sizing: border-box;
padding: 50rpx 40rpx;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
2024-02-24 16:08:09 +08:00
</style>