·修改部分页面数据冗余

This commit is contained in:
lemon橪
2021-05-14 17:31:40 +08:00
parent 23804939eb
commit 7f4212755d
42 changed files with 1415 additions and 2987 deletions

View File

@@ -23,31 +23,30 @@
<script>
import { sendMobile, smsLogin } from "@/api/login";
import { getUserInfo } from "@/api/members";
import storage from "@/utils/storage.js";
import myVerification from "@/components/verification/verification.vue";
import uuid from "@/utils/uuid.modified.js";
import storage from "@/utils/storage.js"; //缓存
import { whetherNavigate } from "@/utils/Foundation"; //登录跳转
import myVerification from "@/components/verification/verification.vue"; //验证码模块
import uuid from "@/utils/uuid.modified.js"; // uuid
export default {
components: {
myVerification,
},
props: ["status"],
props: ["status"], //是否勾选 《用户隐私》和《隐私政策》
data() {
return {
uuid,
flage: false, //是否验证码验证
codeFlag: true,
// 验证码登录form
codeFlag: true, //验证开关
codeForm: {
mobile: "",
code: "",
mobile: "", //手机号
code: "", //验证码
},
tips: "",
clientType: "",
tips: "", //提示
clientType: "", // 客户端类型
seconds: 60,
// 验证码登录校验
codeRules: {
// 手机号验证
mobile: [
{
validator: (rule, value, callback) => {
@@ -57,6 +56,7 @@ export default {
trigger: ["blur"],
},
],
// 验证码验证
code: [
{
min: 4,
@@ -72,6 +72,9 @@ export default {
// 必须要在onReady生命周期因为onLoad生命周期组件可能尚未创建完毕
mounted() {
this.$refs.validateCodeForm.setRules(this.codeRules);
/**
* 条件编译判断当前客户端类型
*/
//#ifdef H5
this.clientType = "H5";
//#endif
@@ -115,6 +118,10 @@ export default {
// 登录
submit() {
if (!this.status) {
/**
* 用户必须了解
* 用户协议以及隐私政策
*/
uni.showToast({
title: "请您阅读并同意用户协议以及隐私政策",
duration: 2000,
@@ -125,18 +132,30 @@ export default {
let _this = this;
this.$refs.validateCodeForm.validate((valid) => {
if (valid) {
/**
* 清空当前账号信息
*/
storage.setHasLogin(false);
storage.setAccessToken("");
storage.setRefreshToken("");
storage.setUuid(this.uuid.v1());
storage.setUserInfo({});
/**
* 执行登录
*/
smsLogin(this.codeForm, _this.clientType).then((res) => {
if (res.data.success) {
storage.setAccessToken(res.data.result.accessToken);
storage.setRefreshToken(res.data.result.refreshToken);
/**
* 登录成功后获取个人信息
*/
getUserInfo().then((user) => {
if (user.data.success) {
/**
* 个人信息存储到缓存userInfo中
*/
storage.setUserInfo(user.data.result);
storage.setHasLogin(true);
// 登录成功
@@ -145,34 +164,12 @@ export default {
icon: "none",
});
if (getCurrentPages().length > 1) {
if (
(getCurrentPages().length - 2).route ==
"pages/passport/login"
) {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
} else {
if (
!(getCurrentPages().length - 2).route ||
(getCurrentPages().length - 2).route == "undefined"
) {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
} else {
uni.navigateBack({
delta: getCurrentPages().length - 2,
});
}
}
} else {
uni.switchTab({
url: "/pages/tabbar/home/index",
});
}
/**
* 计算出当前router路径
* 1.如果跳转的链接为登录页面或跳转的链接为空页面。则会重新跳转到首页
* 2.都不满足返回跳转页面
*/
whetherNavigate();
} else {
uni.switchTab({
url: "/pages/tabbar/home/index",
@@ -184,15 +181,16 @@ export default {
}
});
},
// 跳转到一键登录
clickLogin() {
this.$emit("open", "click");
},
/**点击验证码*/
codeChange(text) {
console.log(text);
this.tips = text;
},
/** 结束验证码后执行 */
end() {},
/**获取验证码 */
getCode() {
@@ -219,6 +217,8 @@ export default {
return false;
}
},
// 点击获取验证码
start() {
this.$u.toast("验证码已发送");
this.flage = false;

View File

@@ -2,9 +2,9 @@
<div class="form">
<u-form ref="validateCodeForm">
<div class="login-list">
<!-- 循环出当前可使用的第三方登录模式 -->
<div class="login-item" v-for="(item,index) in loginList" :key="index">
<u-icon :color="item.color" size="80" :name="item.icon" @click="toLogin(item)"></u-icon>
<u-icon :color="item.color" size="80" :name="item.icon" @click="navigateLogin(item)"></u-icon>
<div>{{item.title}}</div>
</div>
</div>
@@ -15,7 +15,7 @@
<script>
import { webConnect, openIdLogin } from "@/api/connect.js";
import { whetherNavigate } from "@/utils/Foundation"; //登录跳转
import { getUserInfo } from "@/api/members";
import storage from "@/utils/storage.js";
@@ -48,7 +48,7 @@ export default {
props: ["status"],
mounted() {
//#ifdef APP-PLUS
//如果是app 加载支持的登录方式
/**如果是app 加载支持的登录方式*/
let _this = this;
uni.getProvider({
service: "oauth",
@@ -94,7 +94,11 @@ export default {
});
},
fail: (error) => {
console.log("获取登录通道失败", error);
uni.showToast({
title: "获取登录通道失败" + error,
duration: 2000,
icon: "none",
});
},
});
//#endif
@@ -111,21 +115,28 @@ export default {
},
methods: {
/** 根据参数显示登录模块 */
methodFilter(code) {
let way = [];
this.loginList.forEach((item) => {
code.length != 0
? code.forEach((val) => {
if (item.code == val) {
way.push(item);
}
})
: console.error("error");
if (code.length != 0) {
code.forEach((val) => {
if (item.code == val) {
way.push(item);
}
});
} else {
uni.showToast({
title: '配置有误请联系管理员',
duration: 2000,
icon:"none"
});
}
});
this.loginList = way;
},
toLogin(connectLogin) {
/**跳转到登录页面 */
navigateLogin(connectLogin) {
if (!this.status) {
uni.showToast({
title: "请您阅读并同意用户协议以及隐私政策",
@@ -148,6 +159,8 @@ export default {
this.nonH5OpenId(connectLogin);
// #endif
},
// 跳转到一键登录
clickCodeLogin() {
this.$emit("open", "code");
},
@@ -169,7 +182,6 @@ export default {
// #endif
},
fail(e) {
console.log(e);
uni.showToast({
title: "第三方登录暂不可用!",
icon: "none",
@@ -184,15 +196,15 @@ export default {
//写入用户信息
uni.setStorageSync("nickname", infoRes.userInfo.nickName);
uni.setStorageSync("avatar", infoRes.userInfo.avatarUrl);
// #ifdef MP-WEIXIN
// #ifdef MP-WEIXIN
//微信小程序获取openid 需要特殊处理 如需获取openid请参考uni-id: https://uniapp.dcloud.net.cn/uniCloud/uni-id
_this.weixinMPOpenID(res).then((res) => {
//这里需要先行获得openid再使用openid登录小程序登录需要两步所以这里特殊编译
_this.goOpenidLogin("WECHAT_MP");
});
// #endif
});
// #endif
// #ifndef MP-WEIXIN
_this.goOpenidLogin("APP");
//#endif
@@ -230,23 +242,17 @@ export default {
title: "第三方登录成功!",
icon: "none",
});
// 执行登录
getUserInfo().then((user) => {
storage.setUserInfo(user.data.result);
storage.setHasLogin(true);
});
getCurrentPages().length > 1
? uni.navigateBack({
delta: getCurrentPages().length - 2,
})
: uni.switchTab({
url: "/pages/tabbar/home/index",
});
whetherNavigate()
}
});
},
//微信小程序获取openid
async weixinMPOpenID(res) {
let openId = "";
await miniProgramLogin(res.code).then((res) => {
uni.setStorageSync("openid", res.data);
});