mirror of
https://gitee.com/beijing_hongye_huicheng/lilishop-uniapp.git
synced 2025-12-17 07:55:53 +08:00
commit message
This commit is contained in:
48
pages/passport/article.vue
Normal file
48
pages/passport/article.vue
Normal file
@@ -0,0 +1,48 @@
|
||||
<template>
|
||||
<!-- 此文件路径禁止移动 -->
|
||||
<view>
|
||||
<view class="container ">
|
||||
<view class="u-skeleton" v-if="!articleData">
|
||||
<u-empty text="文章暂无内容" mode="list"></u-empty>
|
||||
</view>
|
||||
<!-- <h3>{{routers.title}}</h3> -->
|
||||
<u-parse v-else :html="articleData"></u-parse>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getArticleDetail } from "@/api/article.js";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: true,
|
||||
routers: "",
|
||||
articleData: "",
|
||||
};
|
||||
},
|
||||
onLoad(val) {
|
||||
this.routers = val;
|
||||
console.log(val);
|
||||
getArticleDetail(val.id).then((res) => {
|
||||
if (res.data.result) {
|
||||
this.articleData = res.data.result.content;
|
||||
}
|
||||
uni.setNavigationBarTitle({
|
||||
title: val.title,
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
page {
|
||||
background: #fff;
|
||||
}
|
||||
.container {
|
||||
padding: 32rpx;
|
||||
> p {
|
||||
margin: 20rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
239
pages/passport/codeLogin.vue
Normal file
239
pages/passport/codeLogin.vue
Normal file
@@ -0,0 +1,239 @@
|
||||
<template>
|
||||
<div class="form">
|
||||
<u-form :model="codeForm" ref="validateCodeForm">
|
||||
<u-form-item class="cell" label-width="120" label="手机号" prop="mobile">
|
||||
<u-input maxlength="11" v-model="codeForm.mobile" placeholder="请输入您的手机号" />
|
||||
</u-form-item>
|
||||
|
||||
<u-form-item class="cell code" label-width="120" prop="code" label="验证码">
|
||||
<div style="display:flex; with:100%;">
|
||||
<u-input v-model="codeForm.code" placeholder="请输入验证码" />
|
||||
<u-verification-code keep-running unique-key="page-login" :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-verification-code>
|
||||
<view @tap="getCode" class="text-tips">{{ tips }}</view>
|
||||
</div>
|
||||
</u-form-item>
|
||||
|
||||
<view class="submit" @click="submit">登录</view>
|
||||
<view class="text-tips cell" @click="clickLogin">一键登录</view>
|
||||
<myVerification v-if="codeFlag" @send="verification" class="verification" ref="verification" business="LOGIN" />
|
||||
</u-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<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";
|
||||
export default {
|
||||
components: {
|
||||
myVerification,
|
||||
},
|
||||
props: ["status"],
|
||||
data() {
|
||||
return {
|
||||
uuid,
|
||||
flage: false, //是否验证码验证
|
||||
codeFlag: true,
|
||||
|
||||
// 验证码登录form
|
||||
codeForm: {
|
||||
mobile: "",
|
||||
code: "",
|
||||
},
|
||||
tips: "",
|
||||
clientType: "",
|
||||
seconds: 60,
|
||||
// 验证码登录校验
|
||||
codeRules: {
|
||||
mobile: [
|
||||
{
|
||||
validator: (rule, value, callback) => {
|
||||
return this.$u.test.mobile(value);
|
||||
},
|
||||
message: "手机号码不正确",
|
||||
trigger: ["blur"],
|
||||
},
|
||||
],
|
||||
code: [
|
||||
{
|
||||
min: 4,
|
||||
max: 6,
|
||||
required: true,
|
||||
message: "请输入验证码",
|
||||
trigger: ["blur"],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
// 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
|
||||
mounted() {
|
||||
this.$refs.validateCodeForm.setRules(this.codeRules);
|
||||
//#ifdef H5
|
||||
this.clientType = "H5";
|
||||
//#endif
|
||||
//#ifdef APP-PLUS
|
||||
this.clientType = "APP";
|
||||
//#endif
|
||||
},
|
||||
watch: {
|
||||
flage(val) {
|
||||
if (val) {
|
||||
if (this.$refs.uCode.canGetCode) {
|
||||
// 模拟向后端请求验证码
|
||||
uni.showLoading({
|
||||
title: "正在获取验证码",
|
||||
});
|
||||
sendMobile(this.codeForm.mobile).then((res) => {
|
||||
uni.hideLoading();
|
||||
// 这里此提示会被this.start()方法中的提示覆盖
|
||||
if (res.data.success) {
|
||||
this.$refs.uCode.start();
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: res.data.message,
|
||||
duration: 2000,
|
||||
icon: "none",
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
this.$u.toast("请倒计时结束后再发送");
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
// 验证码验证
|
||||
verification(val) {
|
||||
this.flage = val == this.$store.state.verificationKey ? true : false;
|
||||
},
|
||||
// 登录
|
||||
submit() {
|
||||
if (!this.status) {
|
||||
uni.showToast({
|
||||
title: "请您阅读并同意用户协议以及隐私政策",
|
||||
duration: 2000,
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
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) {
|
||||
storage.setUserInfo(user.data.result);
|
||||
storage.setHasLogin(true);
|
||||
// 登录成功
|
||||
uni.showToast({
|
||||
title: "登录成功!",
|
||||
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",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
uni.switchTab({
|
||||
url: "/pages/tabbar/home/index",
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
clickLogin() {
|
||||
this.$emit("open", "click");
|
||||
},
|
||||
|
||||
codeChange(text) {
|
||||
console.log(text);
|
||||
this.tips = text;
|
||||
},
|
||||
end() {},
|
||||
/**获取验证码 */
|
||||
getCode() {
|
||||
if (this.tips == "重新获取") {
|
||||
this.codeFlag = true;
|
||||
|
||||
uni.showLoading({
|
||||
title: "加载中",
|
||||
});
|
||||
setTimeout(() => {
|
||||
this.$refs.verification.hide();
|
||||
uni.hideLoading();
|
||||
}, 2000);
|
||||
}
|
||||
if (!this.$u.test.mobile(this.codeForm.mobile)) {
|
||||
uni.showToast({
|
||||
title: "请输入正确手机号",
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
if (!this.flage) {
|
||||
this.$refs.verification.hide();
|
||||
return false;
|
||||
}
|
||||
},
|
||||
start() {
|
||||
this.$u.toast("验证码已发送");
|
||||
this.flage = false;
|
||||
|
||||
this.codeFlag = false;
|
||||
this.$refs.verification.hide();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./login.scss");
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
@import url("./mp-codeLogin.scss");
|
||||
|
||||
// #endif
|
||||
</style>
|
||||
73
pages/passport/login.scss
Normal file
73
pages/passport/login.scss
Normal file
@@ -0,0 +1,73 @@
|
||||
.sub-title {
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
.cell {
|
||||
margin: 40rpx 0;
|
||||
}
|
||||
.login-ball {
|
||||
background-image: linear-gradient(25deg, #fa123b, #ff6b35, #ff9f28, #ffcc03);
|
||||
border-bottom-left-radius: 300rpx;
|
||||
height: 400rpx;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/deep/ .u-form-item--right__content__slot {
|
||||
width: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 48rpx;
|
||||
color: #000;
|
||||
text-align: center;
|
||||
}
|
||||
.privacy {
|
||||
font-size: 24upx;
|
||||
color: #999;
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
bottom: 50rpx;
|
||||
}
|
||||
span {
|
||||
color: $aider-light-color;
|
||||
}
|
||||
.form {
|
||||
padding: 0 72rpx;
|
||||
}
|
||||
.divider {
|
||||
margin: 30rpx 0 !important;
|
||||
}
|
||||
.submit {
|
||||
height: 80rpx;
|
||||
line-height: 80rpx;
|
||||
|
||||
background-image: linear-gradient(90deg, #ff6b35, #ff9f28, #ffcc03);
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
font-size: 30rpx;
|
||||
border-radius: 100px;
|
||||
}
|
||||
.logo {
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
text-align: center;
|
||||
transform: scale(2.5);
|
||||
}
|
||||
.logo-cell {
|
||||
text-align: center;
|
||||
}
|
||||
.text-tips {
|
||||
text-align: center;
|
||||
color: #ff9f28;
|
||||
}
|
||||
.tips {
|
||||
position: absolute;
|
||||
bottom: 10rpx;
|
||||
width: 100%;
|
||||
|
||||
text-align: center;
|
||||
}
|
||||
132
pages/passport/login.vue
Normal file
132
pages/passport/login.vue
Normal file
@@ -0,0 +1,132 @@
|
||||
<template>
|
||||
<view v-if="mpWechatLogin">
|
||||
<!-- 背景 -->
|
||||
<view class="login-ball small"></view>
|
||||
|
||||
<view class="logo-cell">
|
||||
<image class="logo" src="/static/logo.png" mode="aspectFit"></image>
|
||||
</view>
|
||||
<view class="title">LiLi商城</view>
|
||||
|
||||
<!-- 验证码登录 -->
|
||||
<codeLogin @open="open" :status="value" v-if="login && loginData.code" />
|
||||
<!-- 账号密码登录 -->
|
||||
<onClickLogin @open="open" :status="value" v-if="login && loginData.click" />
|
||||
<view class="form"> </view>
|
||||
|
||||
<!-- 隐私政策 -->
|
||||
<div class="privacy">
|
||||
<u-checkbox-group :icon-size="24" width="45rpx">
|
||||
<u-checkbox v-model="value" active-color="rgb(255, 107, 53)"></u-checkbox>
|
||||
|
||||
</u-checkbox-group>
|
||||
同意<span @click="handleClick('user')">《用户协议》</span>和<span @click="handleClick('privacy')">《隐私政策》</span>
|
||||
</div>
|
||||
</view>
|
||||
</template>
|
||||
<script>
|
||||
import codeLogin from "./codeLogin";
|
||||
import onClickLogin from "./onClickLogin";
|
||||
import { getUserInfo } from "@/api/members";
|
||||
import storage from "@/utils/storage.js";
|
||||
import { loginCallback } from "@/api/connect.js";
|
||||
import { webConnect } from "@/api/connect.js";
|
||||
export default {
|
||||
onShow() {
|
||||
// #ifdef MP-WEIXIN
|
||||
this.mpWechatLogin = false;
|
||||
if (this.$options.filters.isLogin("auth")) {
|
||||
getCurrentPages().length > 1
|
||||
? uni.navigateBack({
|
||||
delta: getCurrentPages().length - 2,
|
||||
})
|
||||
: uni.switchTab({
|
||||
url: "/pages/tabbar/home/index",
|
||||
});
|
||||
} else {
|
||||
uni.navigateTo({
|
||||
url: "/pages/passport/wechatMPLogin",
|
||||
});
|
||||
}
|
||||
// #endif
|
||||
|
||||
//#ifdef H5
|
||||
let isWXBrowser = /micromessenger/i.test(navigator.userAgent);
|
||||
if (isWXBrowser) {
|
||||
webConnect("WECHAT").then((res) => {
|
||||
let data = res.data;
|
||||
if (data.success) {
|
||||
window.location = data.result;
|
||||
}
|
||||
});
|
||||
}
|
||||
//#endif
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
mpWechatLogin: true, //是否加载微信登录
|
||||
value: true, //隐私政策
|
||||
loginData: {
|
||||
code: true, //验证码登录
|
||||
click: false,
|
||||
},
|
||||
login: true, //登录
|
||||
};
|
||||
},
|
||||
watch: {},
|
||||
components: {
|
||||
codeLogin,
|
||||
onClickLogin,
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
if (options && options.state) {
|
||||
this.stateLogin(options.state);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleClick(val) {
|
||||
uni.navigateTo({
|
||||
url: "/pages/mine/help/tips?type=" + val,
|
||||
});
|
||||
},
|
||||
// open 开启另一个模板
|
||||
open(val) {
|
||||
Object.keys(this.loginData).forEach((item) => {
|
||||
this.$set(this.loginData, item, false);
|
||||
});
|
||||
this.$set(this.loginData, val, true);
|
||||
},
|
||||
//联合信息返回登录
|
||||
stateLogin(state) {
|
||||
loginCallback(state).then((res) => {
|
||||
console.log(data);
|
||||
let data = res.data;
|
||||
if (data.success) {
|
||||
storage.setAccessToken(data.result.accessToken);
|
||||
storage.setRefreshToken(data.result.refreshToken);
|
||||
// 登录成功
|
||||
uni.showToast({
|
||||
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",
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./login.scss");
|
||||
</style>
|
||||
9
pages/passport/mp-codeLogin.scss
Normal file
9
pages/passport/mp-codeLogin.scss
Normal file
@@ -0,0 +1,9 @@
|
||||
.verification {
|
||||
}
|
||||
/deep/ .u-form-item {
|
||||
margin: 40rpx 0 !important;
|
||||
padding: 40rpx 0 !important;
|
||||
}
|
||||
.submit {
|
||||
margin-top: 40rpx;
|
||||
}
|
||||
278
pages/passport/onClickLogin.vue
Normal file
278
pages/passport/onClickLogin.vue
Normal file
@@ -0,0 +1,278 @@
|
||||
<template>
|
||||
<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>
|
||||
<div>{{item.title}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<view class="text-tips cell" @click="clickCodeLogin">账号密码登录</view>
|
||||
</u-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { webConnect, openIdLogin } from "@/api/connect.js";
|
||||
|
||||
import { getUserInfo } from "@/api/members";
|
||||
import storage from "@/utils/storage.js";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loginList: [
|
||||
{
|
||||
icon: "weixin-circle-fill",
|
||||
color: "#00a327",
|
||||
title: "微信",
|
||||
code: "WECHAT",
|
||||
},
|
||||
{
|
||||
icon: "qq-circle-fill",
|
||||
color: "#38ace9",
|
||||
title: "QQ",
|
||||
code: "QQ",
|
||||
},
|
||||
{
|
||||
icon: "apple-fill",
|
||||
color: "#000000",
|
||||
title: "Apple",
|
||||
code: "APPLE",
|
||||
},
|
||||
],
|
||||
tips: "",
|
||||
};
|
||||
},
|
||||
props: ["status"],
|
||||
mounted() {
|
||||
//#ifdef APP-PLUS
|
||||
//如果是app 加载支持的登录方式
|
||||
let _this = this;
|
||||
uni.getProvider({
|
||||
service: "oauth",
|
||||
success: (result) => {
|
||||
_this.loginList = result.provider.map((value) => {
|
||||
//展示title
|
||||
let title = "";
|
||||
//系统code
|
||||
let code = "";
|
||||
//颜色
|
||||
let color = "#8b8b8b";
|
||||
//图标
|
||||
let icon = "";
|
||||
//uni 联合登录 code
|
||||
let appcode = "";
|
||||
switch (value) {
|
||||
case "weixin":
|
||||
icon = "weixin-circle-fill";
|
||||
color = "#00a327";
|
||||
title = "微信";
|
||||
code = "WECHAT";
|
||||
break;
|
||||
case "qq":
|
||||
icon = "qq-circle-fill";
|
||||
color = "#38ace9";
|
||||
title = "QQ";
|
||||
code = "QQ";
|
||||
break;
|
||||
case "apple":
|
||||
icon = "apple-fill";
|
||||
color = "#000000";
|
||||
title = "Apple";
|
||||
code = "APPLE";
|
||||
break;
|
||||
}
|
||||
return {
|
||||
title: title,
|
||||
code: code,
|
||||
color: color,
|
||||
icon: icon,
|
||||
appcode: value,
|
||||
};
|
||||
});
|
||||
},
|
||||
fail: (error) => {
|
||||
console.log("获取登录通道失败", error);
|
||||
},
|
||||
});
|
||||
//#endif
|
||||
|
||||
//特殊平台,登录方式需要过滤
|
||||
// #ifdef H5
|
||||
this.methodFilter(["QQ"]);
|
||||
// #endif
|
||||
|
||||
//微信小程序,只支持微信登录
|
||||
// #ifdef MP-WEIXIN
|
||||
this.methodFilter(["WECHAT"]);
|
||||
// #endif
|
||||
},
|
||||
|
||||
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");
|
||||
});
|
||||
this.loginList = way;
|
||||
},
|
||||
|
||||
toLogin(connectLogin) {
|
||||
if (!this.status) {
|
||||
uni.showToast({
|
||||
title: "请您阅读并同意用户协议以及隐私政策",
|
||||
duration: 2000,
|
||||
icon: "none",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// #ifdef H5
|
||||
let code = connectLogin.code;
|
||||
webConnect(code).then((res) => {
|
||||
let data = res.data;
|
||||
if (data.success) {
|
||||
window.location = data.result;
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef APP-PLUS
|
||||
this.nonH5OpenId(connectLogin);
|
||||
// #endif
|
||||
},
|
||||
clickCodeLogin() {
|
||||
this.$emit("open", "code");
|
||||
},
|
||||
|
||||
//非h5 获取openid
|
||||
async nonH5OpenId(item) {
|
||||
let _this = this;
|
||||
//获取各个openid
|
||||
await uni.login({
|
||||
provider: item.appcode,
|
||||
// #ifdef MP-ALIPAY
|
||||
scopes: "auth_user", //支付宝小程序需设置授权类型
|
||||
// #endif
|
||||
success: function (res) {
|
||||
uni.setStorageSync("type", item.code);
|
||||
//微信小程序意外的其它方式直接在storage中写入openid
|
||||
// #ifndef MP-WEIXIN
|
||||
uni.setStorageSync("openid", res.authResult.openid);
|
||||
// #endif
|
||||
},
|
||||
fail(e) {
|
||||
console.log(e);
|
||||
uni.showToast({
|
||||
title: "第三方登录暂不可用!",
|
||||
icon: "none",
|
||||
duration: 3000,
|
||||
});
|
||||
},
|
||||
complete(e) {
|
||||
//获取用户信息
|
||||
uni.getUserInfo({
|
||||
provider: item.appcode,
|
||||
success: function (infoRes) {
|
||||
//写入用户信息
|
||||
uni.setStorageSync("nickname", infoRes.userInfo.nickName);
|
||||
uni.setStorageSync("avatar", infoRes.userInfo.avatarUrl);
|
||||
|
||||
// #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
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
_this.goOpenidLogin("APP");
|
||||
//#endif
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
//openid 登录
|
||||
goOpenidLogin(clientType) {
|
||||
let _this = this;
|
||||
// 获取准备好的参数,进行登录系统
|
||||
let params = {
|
||||
uuid: uni.getStorageSync("openid"), //联合登陆id
|
||||
source: uni.getStorageSync("type"), //联合登陆类型
|
||||
nickname: uni.getStorageSync("nickname"), // 昵称
|
||||
avatar: uni.getStorageSync("avatar"), // 头像
|
||||
uniAccessToken: uni.getStorageSync("uni_access_token"), //第三方token
|
||||
};
|
||||
openIdLogin(params, clientType).then((res) => {
|
||||
if (!res.data.success) {
|
||||
let errormessage = "第三方登录暂不可用";
|
||||
uni.showToast({
|
||||
// title: '未绑定第三方账号',
|
||||
title: errormessage,
|
||||
icon: "none",
|
||||
duration: 3000,
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
storage.setAccessToken(res.data.result.accessToken);
|
||||
storage.setRefreshToken(res.data.result.refreshToken);
|
||||
// 登录成功
|
||||
uni.showToast({
|
||||
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",
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
//微信小程序获取openid
|
||||
async weixinMPOpenID(res) {
|
||||
let openId = "";
|
||||
await miniProgramLogin(res.code).then((res) => {
|
||||
uni.setStorageSync("openid", res.data);
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
@import url("./login.scss");
|
||||
|
||||
.submit {
|
||||
margin: 80rpx 0 40rpx 0;
|
||||
}
|
||||
|
||||
.login-list {
|
||||
display: flex;
|
||||
padding: 40rpx 0;
|
||||
justify-content: space-between;
|
||||
|
||||
.login-item {
|
||||
font-size: 24rpx;
|
||||
text-align: center;
|
||||
|
||||
> * {
|
||||
margin: 4rpx 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
0
pages/passport/register.vue
Normal file
0
pages/passport/register.vue
Normal file
185
pages/passport/restPassword.vue
Normal file
185
pages/passport/restPassword.vue
Normal file
@@ -0,0 +1,185 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<view class="wrapper">
|
||||
<view class="input-content">
|
||||
<view class="input-item" v-if="step === 0">
|
||||
<view class="input-item-title">
|
||||
<image src="/static/login/user.png"></image>
|
||||
</view>
|
||||
<input type="text" v-model="form.account" placeholder="请输入账户名" placeholder-class="input-empty" maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 0">
|
||||
<view class="input-item-title">
|
||||
<image class="img-code-icon" src="/static/login/code.png"></image>
|
||||
</view>
|
||||
<input v-model="form.img_code" placeholder="请输入图片验证码" placeholder-class="input-empty" maxlength="4"
|
||||
@confirm="toLogin" />
|
||||
<image :src="validate_url" class="img_code" mode="" @click="getValidImgUrl"></image>
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 1">
|
||||
<view class="input-item-title">
|
||||
<image src="/static/login/user.png"></image>
|
||||
<view class="phone-number">+86</view>
|
||||
<image class="vertical" src="/static/vertical-line.svg"></image>
|
||||
</view>
|
||||
<input type="mobile" v-model="form.mobile" disabled="true" placeholder="请输入手机号码" placeholder-class="input-empty" maxlength="11"
|
||||
/>
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 1">
|
||||
<view class="input-item-title">
|
||||
<image class="img-code-icon" src="/static/login/code.png"></image>
|
||||
</view>
|
||||
<input v-model="form.img_code_phone" placeholder="请输入图片验证码" placeholder-class="input-empty"
|
||||
maxlength="4" @confirm="toLogin" />
|
||||
<image :src="validate_url" class="img_code" mode="" @click="getValidImgUrl"></image>
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 1">
|
||||
<view class="input-item-title">
|
||||
<image src="/static/login/pwd2.png"></image>
|
||||
</view>
|
||||
<input v-model="form.sms_code" placeholder="请输入验证码" placeholder-class="input-empty" maxlength="4"
|
||||
@confirm="toLogin" />
|
||||
<view class="get-captcha" @click="handleGetCapcha">{{ sendTime === 0 ? '获取验证码' : sendTime + 's后重新获取' }}</view>
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 2">
|
||||
<view class="input-item-title">
|
||||
<image src="/static/login/pwd2.png"></image>
|
||||
</view>
|
||||
<input type="password" v-model="form.password" placeholder="请输入新密码" placeholder-class="input-empty" maxlength="20"
|
||||
@confirm="toLogin" />
|
||||
</view>
|
||||
<view class="input-item" v-if="step === 2">
|
||||
<view class="input-item-title">
|
||||
<image src="/static/login/pwd2.png"></image>
|
||||
</view>
|
||||
<input type="password" v-model="form.rep_password" placeholder="请再次输入密码" placeholder-class="input-empty" maxlength="20"
|
||||
@confirm="toLogin" />
|
||||
</view>
|
||||
<button class="confirm-btn" @click="toNext">{{ step === 0 ? '验证账号' : (step==1?'下一步':'确定') }}</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
validAccount,
|
||||
sendFindPasswordSms,
|
||||
validFindPasswordSms,
|
||||
changePassword
|
||||
} from '@/api/passport.js';
|
||||
import {
|
||||
getValidateCodeUrl
|
||||
} from '@/api/common.js';
|
||||
import * as RegExp from '@/utils/RegExp.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
validate_url: '',
|
||||
sendTime: 0,
|
||||
form: {},
|
||||
step: 0,
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
this.$nextTick(this.getValidImgUrl)
|
||||
},
|
||||
methods: {
|
||||
handleGetCapcha() {
|
||||
if (this.sendTime == 0) {
|
||||
sendFindPasswordSms(this.form.uuid,this.form.img_code_phone).then(res => { //发送验证码
|
||||
if (res.statusCode == 200) {
|
||||
this.sendTime = 60;
|
||||
let timer = setInterval(() => {
|
||||
this.sendTime--;
|
||||
if (this.sendTime === 0) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
getValidImgUrl() { //获取图片验证码
|
||||
const uuid = this.step === 0 ? '' : this.form.uuid
|
||||
this.validate_url = getValidateCodeUrl('FIND_PASSWORD',uuid)
|
||||
},
|
||||
toNext() {
|
||||
// TODO 验证
|
||||
if (this.step === 0) {
|
||||
const { account,img_code } = this.form
|
||||
validAccount(img_code, account).then(res=>{
|
||||
if(res.statusCode==200){
|
||||
this.step = 1
|
||||
this.form.mobile = res.data.mobile
|
||||
this.form.uname = res.data.uname
|
||||
this.form.uuid = res.data.uuid
|
||||
console.log(this.form)
|
||||
this.getValidImgUrl()
|
||||
}
|
||||
|
||||
});
|
||||
} else if (this.step == 1) {
|
||||
const { uuid, sms_code } = this.form
|
||||
validFindPasswordSms(uuid,sms_code).then((res) => {
|
||||
if(res.statusCode==200){
|
||||
this.step = 2;
|
||||
this.sendTime = 0;
|
||||
this.getValidImgUrl()
|
||||
}
|
||||
|
||||
})
|
||||
}else{
|
||||
const { password,uuid,rep_password } = this.form
|
||||
if(!password){
|
||||
this.$api.msg('请输入密码')
|
||||
return;
|
||||
}
|
||||
if(!RegExp.password.test(password)){
|
||||
this.$api.msg('密码应为6-20位英文或数字!')
|
||||
return ;
|
||||
}
|
||||
if(password!=rep_password){
|
||||
this.$api.msg('两次输入密码不一致')
|
||||
return;
|
||||
}
|
||||
changePassword(password,uuid).then(res=>{
|
||||
if(res.statusCode==200){
|
||||
this.$api.msg('修改密码成功!')
|
||||
setTimeout(function() {
|
||||
uni.reLaunch({
|
||||
url:"/pages/passport/login"
|
||||
})
|
||||
}, 500);
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import './login.scss';
|
||||
|
||||
.container {
|
||||
padding-top: 0;
|
||||
|
||||
.img_code {
|
||||
width: 140rpx;
|
||||
height: 48rpx;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.img-code-icon {
|
||||
width: 44rpx;
|
||||
height: 35rpx;
|
||||
}
|
||||
|
||||
.input-content {
|
||||
margin-top: 300rpx;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
BIN
pages/passport/static/logo-title.png
Normal file
BIN
pages/passport/static/logo-title.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
224
pages/passport/wechatMPLogin.vue
Normal file
224
pages/passport/wechatMPLogin.vue
Normal file
@@ -0,0 +1,224 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<u-modal v-model="showWxAuth" :title="projectName+'商城'" :show-confirm-button="false">
|
||||
|
||||
<div class="tips">
|
||||
为了更好地用户体验,需要您授权手机号
|
||||
</div>
|
||||
<button class="register" type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
|
||||
去授权
|
||||
</button>
|
||||
</u-modal>
|
||||
<view class="wx-auth-container">
|
||||
<div class="box">
|
||||
<view class="logo-info">
|
||||
<text class="title">欢迎进入{{ projectName }}商城</text>
|
||||
|
||||
</view>
|
||||
<view class="small-tips">
|
||||
<view>为您提供优质服务,{{ projectName }}需要获取以下信息</view>
|
||||
<view>您的公开信息(昵称、头像等)</view>
|
||||
</view>
|
||||
<view class="btns">
|
||||
<button type="primary" open-type="getUserInfo" class="btn-auth"
|
||||
@getuserinfo="hidenWxAuth()">确认微信授权</button>
|
||||
</view>
|
||||
</div>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
mpAutoLogin
|
||||
} from "@/api/connect.js";
|
||||
|
||||
import {
|
||||
getUserInfo
|
||||
} from "@/api/members";
|
||||
import storage from "@/utils/storage.js";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
show: true,
|
||||
// 默认不显示
|
||||
showWxAuth: false,
|
||||
// 授权信息展示,商城名称
|
||||
projectName: "LiLi",
|
||||
//微信返回信息,用于揭秘信息,获取sessionkey
|
||||
code: '',
|
||||
//微信昵称
|
||||
nickName: '',
|
||||
//微信头像
|
||||
image: '',
|
||||
};
|
||||
},
|
||||
|
||||
components: {},
|
||||
props: {},
|
||||
|
||||
methods: {
|
||||
hidenWxAuth() {
|
||||
this.showWxAuth = true;
|
||||
let that = this;
|
||||
//------执行Login---------
|
||||
uni.login({
|
||||
success: (res) => {
|
||||
that.code = res.code;
|
||||
uni.getUserInfo({
|
||||
provider: "weixin",
|
||||
success: function(infoRes) {
|
||||
that.nickName = infoRes.userInfo.nickName;
|
||||
that.image = infoRes.userInfo.avatarUrl;
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
getPhoneNumber(e) {
|
||||
let iv = e.detail.iv;
|
||||
let encryptedData = e.detail.encryptedData;
|
||||
if (!e.detail.encryptedData) {
|
||||
uni.showToast({
|
||||
title: "请授予手机号码获取权限!",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
let code = this.code;
|
||||
let image = this.image;
|
||||
let nickName = this.nickName;
|
||||
mpAutoLogin({
|
||||
encryptedData,
|
||||
iv,
|
||||
code,
|
||||
image,
|
||||
nickName,
|
||||
}).then((res) => {
|
||||
storage.setAccessToken(res.data.result.accessToken);
|
||||
storage.setRefreshToken(res.data.result.refreshToken);
|
||||
// 登录成功
|
||||
uni.showToast({
|
||||
title: "登录成功!",
|
||||
icon: "none",
|
||||
});
|
||||
//获取用户信息
|
||||
getUserInfo().then((user) => {
|
||||
storage.setUserInfo(user.data.result);
|
||||
storage.setHasLogin(true);
|
||||
setTimeout(() => {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
}, 500);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
<style>
|
||||
/*微信授权*/
|
||||
page {
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.wx-auth-container {
|
||||
width: 100%;
|
||||
margin-top: 20%;
|
||||
}
|
||||
|
||||
.logo-info {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-start;
|
||||
flex-direction: row;
|
||||
align-items: flex-start;
|
||||
padding: 20rpx;
|
||||
|
||||
flex-direction: column;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
image {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
text-align: center;
|
||||
-webkit-transform: scale(2.5);
|
||||
transform: scale(2.5);
|
||||
}
|
||||
|
||||
.logo-info-img {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 50%;
|
||||
border: none;
|
||||
}
|
||||
|
||||
text.title,
|
||||
text.shop {
|
||||
display: inline-block;
|
||||
font-size: 60rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
text.shop {
|
||||
display: inline-block;
|
||||
font-size: 55rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.box {
|
||||
margin: 0 32rpx;
|
||||
}
|
||||
|
||||
/* 文字提示*/
|
||||
.small-tips {
|
||||
width: 94%;
|
||||
padding: 20rpx;
|
||||
font-size: 24rpx;
|
||||
margin: 0 0 20rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.auth-button {
|
||||
padding: 10px 20px;
|
||||
width: calc(100% - 20 * 4rpx);
|
||||
}
|
||||
|
||||
.tips {
|
||||
width: 80%;
|
||||
text-align: left;
|
||||
margin: 6% 10%;
|
||||
margin-top: 48rpx;
|
||||
line-height: 1.75;
|
||||
}
|
||||
|
||||
.register {
|
||||
color: #00a327 !important;
|
||||
border: none !important;
|
||||
background: #fff !important;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.btn-auth {
|
||||
width: 92%;
|
||||
margin: 0 auto 100rpx;
|
||||
|
||||
border-radius: 100px;
|
||||
}
|
||||
|
||||
.btns {
|
||||
margin-top: 100rpx;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user