Files
frontend-app/pages/login_package/login/login.vue
T
2025-09-03 13:12:44 +08:00

280 lines
7.5 KiB
Vue

<template>
<view class="login_warp">
<view class="login_logo_warp">
<view style="text-align: center;">
<up-image src="/static/logo.png" width="90" height="118" bgColor="#f1f6ff00" radius="10"></up-image>
</view>
<!-- <view style="margin-top: 20rpx;">
<up-image src="/static/logo_z.png" width="100" height="40" bgColor="#f1f6ff00"></up-image>
</view> -->
</view>
<view class="login_info">
<view class="login_info_item">
<up-input placeholder="请输入手机号/账户名称" border="surround" v-model="form.name" :customStyle="inputCss"
@change="checkNameParam"></up-input>
</view>
<!-- 密码登录 -->
<view class="login_info_item" v-if="loginWay === 'password'">
<up-input placeholder="请输入密码" border="surround" v-model="form.password" :customStyle="inputCss"
:type="isShow ? 'text' : 'password'" @change="checkParam">
<template #suffix style="margin-right: 10rpx;">
<up-image v-if="isShow" src="/static/login/show.png" width="20" height="20" bgColor="#f1f6ff00"
@click="isShow = false;"></up-image>
<up-image v-else src="/static/login/hidden.png" width="20" height="20" bgColor="#f1f6ff00"
@click="isShow = true;"></up-image>
</template>
</up-input>
</view>
<!-- 验证码登录 -->
<view class="login_info_item" v-else>
<up-input placeholder="请输入验证码" border="surround" v-model="form.code" :customStyle="inputCss">
<template #suffix style="margin-right: 10rpx;">
<view v-if="countdown" class="code-warp">
<up-count-down :time="60 * 1000" format="ss" @finish="countdown = false"></up-count-down>
<text style="margin-left: 10rpx;">s</text>
</view>
<view v-else @click="getMobileCode" class="code_msg">
获取验证码
</view>
</template>
</up-input>
</view>
<view class="login_comm_but login_comm_but_yes" @click="loginFun">
<text style="margin-left: 10rpx;">登录</text>
</view>
<view class="cut_way_warp">
<view v-if="loginWay === 'password'" @click="loginWay = 'code'">验证码登录</view>
<view v-if="loginWay === 'code'" @click="loginWay = 'password'">密码登录登录</view>
<view @click="jumpForgot">忘记密码</view>
<view @click="jumpRegister">注册</view>
</view>
</view>
<view class="policy_warp">
<up-checkbox name="isCheck" usedAlone v-model:checked="isPolicy" shape="circle" activeColor="#7934F6" size="19"
iconSize="18">
<template #label>
<text>已阅读并同意</text>
<text class="policy_a_warp" @click="jumpUserAgreement">《服务协议》</text>
<text>、</text>
<text class="policy_a_warp" @click="jumpPrivacyAgreement">《隐私政策》</text>
<text>、</text>
<text class="policy_a_warp" @click="jumpProductAgreement">《售后保障协议》</text>
</template>
</up-checkbox>
</view>
<up-toast ref="uToastRef"></up-toast>
</view>
</template>
<script>
import InputCodeComm from '@/components/code-comm/code-comm.vue';
import { SMS_TYPE } from '@/utils/enumUtils.js';
import { getUserList } from '@/api/common.js';
import { loginbysms, loginbypw } from '@/api/auth.js';
import { setStorageFun, TOKEN_NAME, USER_KEY, USER_DATA, USER_LOGIN_TIME } from '@/utils/auth.js';
import CryptoJS from 'crypto-js';
export default {
components: {
InputCodeComm,
},
data() {
return {
form: {
name: null,
password: null,
code: null
},
inputCss: {
"height": '80rpx',
"background": "#F3F3F3FF",
"border-radius": "30rpx",
"border": "0rpx",
"padding-left": "16px",
},
loginWay: 'password',
isShow: false,// 是否显示
isPolicy: false,// 是否同意
countdown: false,// 清空倒计时
}
},
methods: {
jumpHome() {
// const sysPlatform = getCurrentSysPlatform();
// if(sysPlatform === "android"){
// uni.switchTab({
// url: '/pages/message/message',
// })
// }else{
uni.switchTab({
url: '/pages/home/home',
})
// }
},
async loginFun() {
const then = this;
const form = this.form;
const params = {}
if (!this.isPolicy) {
this.$refs.uToastRef.show({
type: 'error',
message: "请阅读完相关协议以及政策,并且勾选同意选项",
});
return;
}
let response = {};
if (this.loginWay === 'password') {
params.mobile = form.name;
params.password = CryptoJS.MD5(form.password).toString();
response = await loginbypw(params);
} else {
params.mobile = form.name;
params.smsCode = form.code;
response = await loginbysms(params);
}
const data = response.data;
setStorageFun(TOKEN_NAME, data.token);
// 用于无感登录
setStorageFun(USER_KEY, '');
const userInfo = {
avatar: data.avatarUrl,
name: data.name,
userId: data.userId,
grade: data.grade,
inviteCode: data.inviteCode,
};
setStorageFun(USER_DATA, userInfo);
// 当前登录得时间戳
let currentTimeStamp = new Date().getTime();
setStorageFun(USER_LOGIN_TIME, currentTimeStamp);
this.$refs.uToastRef.show({
type: 'success',
message: response.msg,
});
setTimeout(() => {
then.jumpHome();
}, 2000);
},
checkNameParam(val) {
// console.log("val",val);
},
checkParam(val) {
// console.log("val",val);
},
/**
* 获取手机验证码
*/
async getMobileCode() {
const form = this.form;
if (!form.name) {
this.$refs.uToastRef.show({
type: 'error',
message: "请输入账号",
});
return;
}
this.countdown = true;
const params = {
mobile: form.name,
type: SMS_TYPE.LOGIN,
}
const response = await getUserList(params);
console.log("responseresponseresponse", response);
if (response && response.bizcode === 100) {
this.$refs.uToastRef.show({
type: 'success',
message: response.msg,
});
} else {
this.countdown = false;
}
},
jumpForgot(){
uni.navigateTo({
url: "/pages/rwa_package/setting/forgot-pass?type=3",
})
},
jumpRegister() {
uni.navigateTo({
url: "/pages/login_package/register/register",
})
},
// 用户协议
jumpUserAgreement() {
uni.navigateTo({
url: '/pages/mine_package/mine_user_agreement/mine_user_agreement?backPath=login'
})
},
// 隐私协议
jumpPrivacyAgreement() {
uni.navigateTo({
url: '/pages/mine_package/mine_privacy_agreement/mine_privacy_agreement?backPath=login'
})
},
// 售后保障协议
jumpProductAgreement() {
uni.navigateTo({
url: '/pages/mine_package/mine_product_agreement/mine_product_agreement?backPath=login'
})
},
}
}
</script>
<style lang="scss" scoped>
.login_warp {
height: calc(100vh - 460rpx);
padding: 250rpx 50rpx 0;
}
.login_logo_warp {
display: grid;
justify-content: center;
}
.login_info {
margin-top: 60rpx;
.login_info_item {
margin-bottom: 40rpx;
}
.code_msg {
font-size: 36rpx;
color: $app-bt-bj;
}
}
.login_comm_but {
background: #CCCCCC;
border-radius: 20rpx;
width: 100%;
text-align: center;
font-weight: 500;
font-size: 32rpx;
color: #999999;
padding: 28rpx 0;
display: flex;
justify-content: center;
}
.login_comm_but_yes {
background: $app-bt-bj;
color: #ffffff;
}
.cut_way_warp {
display: flex;
justify-content: space-between;
font-weight: 500;
font-size: 28rpx;
color: #999999;
margin-top: 20rpx;
}
</style>