Files
im/pages/common/login/index.vue
T

382 lines
12 KiB
Vue
Raw Normal View History

2025-11-07 09:56:20 +08:00
<template>
2025-11-27 07:40:32 +08:00
<view class="page_container">
<view class="login">
<view class="logo">
2025-12-27 07:08:30 +08:00
<img :src="cdn(config.app_logo)" alt="" />
2025-11-27 07:40:32 +08:00
<view class="title">欢迎使用{{ config.name }}</view>
</view>
<u-tabs v-if="1 == 2" :list="list" :current="active" @click="click"></u-tabs>
<u-form class="loginForm" labelPosition="top" :model="loginInfo" :labelStyle="{
fontSize: '14px',
marginTop: '20rpx',
width: 'max-content',
}" ref="loginForm">
<u-form-item v-if="active === 0" label="" prop="phoneNumber">
<u-input v-model="loginInfo.phoneNumber" border="surround" placeholder="请输入手机号码" clearable>
<view slot="prefix" class="phoneNumber_areacode" @click="showPicker">
<text class="areacode_content">+{{ loginInfo.region }}</text>
<u-icon class="arrow_down" name="arrow-down"></u-icon>
</view>
</u-input>
</u-form-item>
<u-form-item v-if="active === 1" label="" prop="email">
<u-input v-model="loginInfo.email" border="surround" placeholder="请输入您的邮箱" clearable>
</u-input>
</u-form-item>
<u-form-item v-if="active > 1 || isPwdLogin" label="" prop="password">
<u-input v-model="loginInfo.password" border="surround" placeholder="请输入密码" :password="!eying"
clearable>
<u-icon @click="updateEye" slot="suffix" :name="eying ? 'eye-off' : 'eye'">
</u-icon>
</u-input>
</u-form-item>
<u-form-item v-if="active <= 1 && !isPwdLogin" label="" prop="verificationCode">
<u-input v-model="loginInfo.verificationCode" border="surround" placeholder="请输入验证码">
2026-01-09 20:22:25 +08:00
<view class="code_btn" slot="suffix" @click="getCode">{{ count !== 0 ? `${count} s` : "获取验证码" }}
2025-11-27 07:40:32 +08:00
</view>
</u-input>
</u-form-item>
</u-form>
<view v-if="active <= 1" class="other">
<text @click="toRegisterOrForget(false)">忘记密码</text>
<text class="forget" @click="toggleLoginMethod">{{ isPwdLogin ? "验证码登录" : "密码登录" }}</text>
</view>
<view class="login-btn">
<u-button :loading="loading" type="primary" @click="startLogin" :disabled="!canLogin">
登录
</u-button>
</view>
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
<AreaPicker ref="AreaPicker" @chooseArea="chooseArea" />
</view>
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
<view class="action_bar">
<text>还没有账号<text class="register" @click="toRegisterOrForget(true)">立即注册</text></text>
<text style="margin-bottom: 16rpx" @click="copy">{{ appversion }}</text>
</view>
</view>
2025-11-07 09:56:20 +08:00
</template>
<script>
2025-11-27 07:40:32 +08:00
import { mapGetters } from "vuex";
import { v4 as uuidv4 } from "uuid";
import md5 from "md5";
import { businessLogin, businessSendSms } from "@/api/login";
import AreaPicker from "@/components/AreaPicker";
import { checkLoginError } from "@/util/common";
import { SmsUserFor } from "@/constant";
import IMSDK from "openim-uniapp-polyfill";
2025-12-27 07:08:30 +08:00
import util from "@/util/index.js"
2026-01-01 04:15:30 +08:00
import config from "@/common/config";
import {getDbDir,toastWithCallback} from "@/util/common.js";
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
let timer;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
export default {
components: {
AreaPicker,
},
data() {
return {
list: [{
name: '手机号',
}, {
name: '邮箱',
}],
loginInfo: {
email: "",
phoneNumber: "",
password: "",
region: "86",
verificationCode: "",
},
appversion: 0,
eying: false,
loading: false,
count: 0,
isPwdLogin: true,
active: 0,
};
},
computed: {
...mapGetters(["config"]),
canLogin() {
return (
(this.loginInfo.phoneNumber || this.loginInfo.email) &&
(this.loginInfo.password || this.loginInfo.verificationCode)
);
},
},
onLoad(options) {
const _this = this;
2025-12-05 16:10:52 +08:00
// #ifdef APP
2025-11-27 07:40:32 +08:00
plus.runtime.getProperty(plus.runtime.appid, (inf) => {
2025-12-17 09:13:15 +08:00
//console.log(inf);
2025-11-27 07:40:32 +08:00
_this.appversion = inf.version
});
// if(options.isRedirect){
// plus.navigator.closeSplashscreen();
// }
2025-12-05 16:10:52 +08:00
// #endif
2025-11-27 07:40:32 +08:00
this.init();
},
methods: {
2025-12-27 07:08:30 +08:00
...util,
2025-11-27 07:40:32 +08:00
click({ index }) {
this.active = index;
},
copy() {
uni.setClipboardData({
showToast: false,
data: version,
success: function () {
uni.showToast({
icon: "none",
title: "复制成功",
});
},
});
},
init() {
this.loginInfo.region = uni.getStorageSync("last_areaCode") || "86";
this.loginInfo.email = uni.getStorageSync("last_email") || "";
this.loginInfo.phoneNumber = uni.getStorageSync("last_phoneNumber") || "";
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
if (process.env.NODE_ENV == 'development') {
this.loginInfo.email = "commiu@outlook.com";
this.loginInfo.password = "qwe123";
}
2026-01-15 22:50:35 +08:00
//plus.navigator.closeSplashscreen();
2025-11-27 07:40:32 +08:00
},
updateEye() {
this.eying = !this.eying;
},
toRegisterOrForget(isRegister) {
2026-01-01 04:15:30 +08:00
uni.$u.route("/pages/common/registerOrForget/index", {
2025-11-27 07:40:32 +08:00
isRegister,
});
},
async startLogin() {
2026-01-09 09:15:59 +08:00
this.loading = true;
this.saveLoginInfo();
let data = {};
try {
data = await businessLogin({
mobile: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
region: `+${this.loginInfo.region}`,
password: this.isPwdLogin ? md5(this.loginInfo.password) : "",
platform: uni.$u.os(),
type: this.active === 0 ? 'mobile' : 'email',
code: this.loginInfo.verificationCode,
});
const { imToken, userID } = data;
this.saveLoginProfile(data);
this.$store.commit("user/SET_AUTH_DATA", data);
this.loginInfo.password = "";
// #ifdef APP
// await IMSDK.asyncApi(IMSDK.IMMethods.Login, uuidv4(), {
// userID,
// token: imToken,
// });
plus.runtime.restart();
// #endif
} catch (err) {
console.error(err);
uni.$u.toast(checkLoginError(err));
}
this.loading = false;
2025-11-27 07:40:32 +08:00
},
saveLoginProfile(data) {
const { imToken, token, userID } = data;
uni.setStorage({ key: "IMUserID", data: userID, });
uni.setStorage({ key: "IMToken", data: imToken, });
uni.setStorage({ key: "BusinessToken", data: token, });
},
saveLoginInfo() {
uni.setStorage({key: "last_areaCode",data: this.loginInfo.region,});
uni.setStorage({key: "last_phoneNumber",data: this.loginInfo.phoneNumber,});
uni.setStorage({key: "last_email",data: this.loginInfo.email,});
},
showPicker() {
this.$refs.AreaPicker.init();
},
chooseArea(areaCode) {
this.loginInfo.region = areaCode;
},
toggleLoginMethod() {
this.isPwdLogin = !this.isPwdLogin;
},
getCode() {
if (!this.loginInfo.phoneNumber) {
uni.$u.toast("请先输入手机号!");
return;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
if (this.count !== 0) {
return;
}
2026-01-09 20:22:25 +08:00
const options = {
mobile: this.loginInfo.phoneNumber,
email: this.loginInfo.email,
region: `+${this.loginInfo.region}`,
event: "login",
type:"mobile"
};
2025-11-27 07:40:32 +08:00
businessSendSms(options)
.then(() => {
uni.$u.toast("验证码已发送!");
this.startCount();
})
.catch((err) => {
console.error(err);
uni.$u.toast(checkLoginError(err));
});
},
startCount() {
if (timer) {
clearInterval(timer);
}
this.count = 60;
timer = setInterval(() => {
if (this.count > 0) {
this.count--;
}
}, 1000);
},
},
};
2025-11-07 09:56:20 +08:00
</script>
<style lang="scss" scoped>
2025-11-27 07:40:32 +08:00
.page_container {
justify-content: space-between;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.login {
color: #0c1c33;
padding: 10vh 80rpx 0;
background: linear-gradient(180deg,
rgba(0, 137, 255, 0.1) 0%,
rgba(255, 255, 255, 0) 100%);
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.title {
font-size: 34rpx;
font-weight: 700;
margin-bottom: 64rpx;
// color: $u-primary;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.logo {
display: flex;
flex-direction: column;
2025-12-05 16:10:52 +08:00
justify-content: flex-start;
2025-12-27 07:08:30 +08:00
align-items: center;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
img {
2026-01-09 09:15:59 +08:00
border-radius: 32rpx;
2025-11-27 07:40:32 +08:00
width: 160rpx;
height: 160rpx;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.loginType {
margin-bottom: 36rpx;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
&-item {
margin-right: 68rpx;
font-size: 28rpx;
font-weight: 400;
border-radius: 4rpx;
padding: 2rpx 0;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
&-active {
color: $u-primary;
border-bottom: 4rpx solid $u-primary;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.loginForm {
.phoneNumber-code {
display: flex;
align-items: center;
font-size: 36rpx;
border-right: 2rpx solid #d8d8d8;
margin-right: 58rpx;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.code {
font-weight: 400;
margin-right: 20rpx;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.icon {
margin-right: 40rpx;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.eye {
.image {
width: 44rpx;
height: 32rpx;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.code_btn {
color: $u-primary;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.other {
display: flex;
flex-direction: row;
justify-content: space-between;
margin: 8rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.forget {
color: $u-primary;
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.login-btn {
margin-top: 8vh;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.agreement {
display: flex;
align-items: flex-start;
margin-top: 36rpx;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.detail {
font-size: 24rpx;
font-weight: 400;
color: $u-primary;
}
}
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.action_bar {
display: flex;
justify-content: center;
flex-direction: column;
text-align: center;
margin-bottom: 96rpx;
font-size: 24rpx;
font-weight: 400;
color: $u-tips-color;
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.register {
color: $u-primary;
}
2025-11-07 09:56:20 +08:00
2025-11-27 07:40:32 +08:00
.tap_line {
width: 1px;
margin: 0 24rpx;
background-color: #999;
transform: scale(0.5, 0.8);
}
}
}
2025-11-23 01:01:52 +08:00
</style>