179 lines
4.5 KiB
Vue
179 lines
4.5 KiB
Vue
<template>
|
||
<view class="login-wrapper bg-liner">
|
||
<!-- 返回按钮 -->
|
||
<view class="back-btn" @click="goBack">
|
||
<uni-icons fontFamily="znicons" size="24" color="#333">
|
||
{{ zniconsMap["zn-nav-arrow-left"] }}
|
||
</uni-icons>
|
||
</view>
|
||
|
||
<!-- 头部内容 -->
|
||
<view class="login-header">
|
||
<!-- 卡通形象 -->
|
||
<image class="w-full h-full" :src="logo" mode="widthFix" />
|
||
</view>
|
||
|
||
<!-- 协议勾选 -->
|
||
<view class="login-agreement flex flex-items-center">
|
||
<CheckBox v-model="isAgree">
|
||
<text class="font-size-12 color-525866">我已阅读并同意</text>
|
||
<text
|
||
class="font-size-12 color-2D91FF ml-4 mr-4"
|
||
@click.stop="handleAgreeClick('service')"
|
||
>《服务协议》</text
|
||
>
|
||
<text class="font-size-12 color-525866">和</text>
|
||
<text
|
||
class="font-size-12 color-2D91FF ml-4 mr-4"
|
||
@click.stop="handleAgreeClick('privacy')"
|
||
>《隐私协议》</text
|
||
>
|
||
<text class="font-size-12 color-525866">,\n</text>
|
||
<text class="font-size-12 color-525866 ml-30">授权与账号关联操作</text>
|
||
</CheckBox>
|
||
</view>
|
||
|
||
<!-- 按钮区域 -->
|
||
<view class="login-btn-area">
|
||
<!-- 同意隐私协议并获取手机号按钮 -->
|
||
|
||
<button
|
||
v-if="!isAgree"
|
||
class="login-btn"
|
||
type="primary"
|
||
@click="handleAgreeAndGetPhone"
|
||
>
|
||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||
微信一键登录
|
||
</button>
|
||
|
||
<button
|
||
v-if="isAgree && !appStore.tokenExpired"
|
||
class="login-btn"
|
||
type="primary"
|
||
open-type="getPhoneNumber"
|
||
@getphonenumber="getPhoneNumber"
|
||
>
|
||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||
微信一键登录
|
||
</button>
|
||
|
||
<button
|
||
v-if="isAgree && appStore.tokenExpired"
|
||
class="login-btn"
|
||
type="primary"
|
||
@click="handleLogin"
|
||
>
|
||
<uni-icons type="weixin" size="20" color="#fff"></uni-icons>
|
||
微信一键登录
|
||
</button>
|
||
</view>
|
||
|
||
<AgreePopup
|
||
ref="agreePopup"
|
||
:visible="visible"
|
||
:agreement="computedAgreement"
|
||
@close="visible = false"
|
||
/>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref, computed } from "vue";
|
||
import {
|
||
getServiceAgreement,
|
||
getPrivacyAgreement,
|
||
} from "@/request/api/LoginApi";
|
||
import { onLogin, goBack } from "@/hooks/useGoLogin";
|
||
import CheckBox from "@/components/CheckBox/index.vue";
|
||
import AgreePopup from "./components/AgreePopup/index.vue";
|
||
import { zniconsMap } from "@/static/fonts/znicons.js";
|
||
import { getCurrentConfig } from "@/constant/base";
|
||
import { useAppStore } from "@/store";
|
||
const appStore = useAppStore();
|
||
|
||
const isAgree = ref(false);
|
||
const visible = ref(false);
|
||
const serviceAgreement = ref("");
|
||
const privacyAgreement = ref("");
|
||
// 协议类型
|
||
const AgreeType = ref("service");
|
||
const logo = computed(() => getCurrentConfig().logo);
|
||
|
||
// 同意隐私协议并获取手机号
|
||
const handleAgreeAndGetPhone = () => {
|
||
if (!isAgree.value) {
|
||
uni.showToast({
|
||
title: "请先同意服务协议和隐私协议",
|
||
icon: "none",
|
||
});
|
||
return;
|
||
}
|
||
};
|
||
|
||
const getPhoneNumber = (e) => {
|
||
onLogin(e)
|
||
.then(() => {
|
||
uni.showToast({
|
||
title: "登录成功",
|
||
icon: "success",
|
||
});
|
||
goBack();
|
||
})
|
||
.catch(() => {});
|
||
};
|
||
|
||
const handleLogin = () => {
|
||
console.log("handleLogin");
|
||
onLogin()
|
||
.then(() => {
|
||
uni.showToast({
|
||
title: "登录成功",
|
||
icon: "success",
|
||
});
|
||
appStore.setTokenExpired(false);
|
||
goBack();
|
||
})
|
||
.catch(() => {});
|
||
};
|
||
|
||
// 处理同意协议点击事件
|
||
const handleAgreeClick = (type) => {
|
||
visible.value = true;
|
||
AgreeType.value = type;
|
||
};
|
||
|
||
// 计算协议类型
|
||
const computedAgreement = computed(() => {
|
||
if (AgreeType.value === "service") {
|
||
return serviceAgreement.value;
|
||
} else {
|
||
return privacyAgreement.value;
|
||
}
|
||
});
|
||
|
||
// 获取服务协议数据
|
||
const getServiceAgreementData = async () => {
|
||
const { data } = await getServiceAgreement();
|
||
serviceAgreement.value = data;
|
||
};
|
||
|
||
getServiceAgreementData();
|
||
|
||
// 获取隐私协议数据
|
||
const getPrivacyAgreementData = async () => {
|
||
const { data } = await getPrivacyAgreement();
|
||
privacyAgreement.value = data;
|
||
};
|
||
|
||
getPrivacyAgreementData();
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@import "./styles/index.scss";
|
||
@font-face {
|
||
font-family: znicons;
|
||
src: url("@/static/fonts/znicons.ttf");
|
||
}
|
||
</style>
|