| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <template>
- <BasicModal type="bottom" v-model:open="getOpen" :isMack="true">
- <view class="login-modal">
- <!-- 右上角关闭按钮 -->
- <view class="login-modal__close" @click="handleClose">暂不登录</view>
-
- <!-- 标题 -->
- <view class="login-modal__title">欢迎登录U店在哪</view>
-
- <!-- 描述 -->
- <view class="login-modal__desc">授权手机号登录,享受更多便利和会员服务</view>
-
- <!-- 一键登录按钮 -->
- <button
- class="login-modal__btn"
- type="primary"
- open-type="getPhoneNumber"
- @getphonenumber="handleGetPhoneNumber"
- :disabled="!agreed"
- >
- 一键登录
- </button>
-
- <!-- 协议同意 -->
- <view class="login-modal__agreement">
- <view class="agreement-checkbox" @click="toggleAgree">
- <view class="checkbox-icon" :class="{ 'checked': agreed }">
- <text v-if="agreed" class="icon-check">✓</text>
- </view>
- </view>
- <text class="agreement-text">我已阅读并同意</text>
- <text class="agreement-link" @click="handlePrivacy">《隐私协议》</text>
- <text class="agreement-text">和</text>
- <text class="agreement-link" @click="handleUserAgreement">《用户协议》</text>
- </view>
- </view>
- </BasicModal>
- </template>
- <script setup>
- import { ref, computed } from 'vue';
- import BasicModal from '@/components/Modal/BasicModal.vue';
- import { DiningUserWechatLogin, GetUserInfo } from '@/api/dining.js';
- import { useUserStore } from '@/store/user.js';
- import { go } from '@/utils/utils.js';
- const props = defineProps({
- open: {
- type: Boolean,
- default: false
- }
- });
- const emit = defineEmits(['update:open', 'success', 'cancel']);
- const agreed = ref(false);
- const userStore = useUserStore();
- const getOpen = computed({
- get: () => props.open,
- set: (val) => emit('update:open', val)
- });
- // 切换同意状态
- const toggleAgree = () => {
- agreed.value = !agreed.value;
- };
- // 处理关闭
- const handleClose = () => {
- getOpen.value = false;
- emit('cancel');
- };
- // 处理获取手机号
- const handleGetPhoneNumber = async (e) => {
- if (!agreed.value) {
- uni.showToast({
- title: '请先同意用户协议和隐私协议',
- icon: 'none'
- });
- return;
- }
- if (!e.detail.code) {
- uni.showToast({
- title: '授权失败,请重试',
- icon: 'none'
- });
- return;
- }
- try {
- const phoneCode = e.detail?.code || "";
- // 登录接口:传 code、phoneCode;手机号明文传递(不加密),有缓存则一并传 phone)
- uni.login({
- success: async (loginRes) => {
- try {
- const res = await DiningUserWechatLogin({
- code: loginRes.code,
- phoneCode: phoneCode || undefined,
- phone: userStore.getPhone || undefined // 明文传递,有缓存则传
- });
- if (res && res.token) {
- userStore.login(res);
- try {
- const userRes = await GetUserInfo();
- const raw = userRes?.data ?? userRes?.result ?? userRes?.userInfo ?? userRes?.user ?? userRes ?? {};
- const userData = typeof raw === 'object' && raw !== null ? raw : {};
- const merged = { ...userStore.getUserInfo, ...userData };
- userStore.setUserInfo(merged);
- } catch (err) {
- console.warn('获取用户信息失败', err);
- }
- getOpen.value = false;
- emit('success', res);
- } else {
- uni.showToast({
- title: res?.msg || '登录失败,请重试',
- icon: 'none'
- });
- }
- } catch (error) {
- console.error('登录失败:', error);
- uni.showToast({
- title: '登录失败,请重试',
- icon: 'none'
- });
- }
- },
- fail: () => {
- uni.showToast({
- title: '获取登录凭证失败',
- icon: 'none'
- });
- }
- });
- } catch (error) {
- console.error('获取手机号失败:', error);
- uni.showToast({
- title: '授权失败,请重试',
- icon: 'none'
- });
- }
- };
- // 处理隐私协议:跳转 webview 打开
- const PRIVACY_URL = 'https://ossfile.ailien.shop/privacy/%E9%9A%90%E7%A7%81%E5%8D%8F%E8%AE%AE931648.html';
- const handlePrivacy = () => {
- go(`/pages/webview/index?url=${encodeURIComponent(PRIVACY_URL)}`);
- };
- // 处理用户协议:与隐私协议一致,跳转 webview 打开
- const USER_AGREEMENT_URL = 'https://ossfile.ailien.shop/privacy/U%E5%BA%97%E5%9C%A8%E8%BF%99-%E5%B9%B3%E5%8F%B0%E8%A7%84%E5%88%99456793.htm';
- const handleUserAgreement = () => {
- go(`/pages/webview/index?url=${encodeURIComponent(USER_AGREEMENT_URL)}`);
- };
- </script>
- <style scoped lang="scss">
- /* 优先级最高,避免被 tabbar 等挡住 */
- :deep(.uni-popup) {
- z-index: 99999 !important;
- }
- :deep(.uni-popup__wrapper) {
- z-index: 99999 !important;
- }
- :deep(.uni-popup__mask) {
- z-index: 99998 !important;
- }
- .login-modal {
- width: 100%;
- background: #FFFFFF;
- border-radius: 24rpx;
- padding: 60rpx 40rpx calc(50rpx + env(safe-area-inset-bottom) + 120rpx);
- position: relative;
- box-sizing: border-box;
- &__close {
- position: absolute;
- top: 30rpx;
- right: 30rpx;
- font-size: 24rpx;
- color: #ccc;
- line-height: 1;
- }
- &__title {
- font-size: 44rpx;
- font-weight: bold;
- color: #010101;
- // text-align: center;
- margin-bottom: 24rpx;
- line-height: 1.2;
- }
- &__desc {
- font-size: 28rpx;
- color: #333333;
- // text-align: center;
- margin-bottom: 60rpx;
- line-height: 1.5;
- }
- &__btn {
- width: 100%;
- height: 88rpx;
- // background: #07C160;
- border-radius: 44rpx;
- color: #FFFFFF;
- font-size: 32rpx;
- font-weight: 500;
- line-height: 88rpx;
- text-align: center;
- border: none;
- margin-bottom: 40rpx;
- padding: 0;
- &::after {
- border: none;
- }
- &[disabled] {
- background: #CCCCCC;
- color: #999999;
- }
- }
- &__agreement {
- display: flex;
- align-items: center;
- justify-content: center;
- flex-wrap: wrap;
- font-size: 24rpx;
- line-height: 1.5;
- .agreement-checkbox {
- margin-right: 8rpx;
- .checkbox-icon {
- width: 32rpx;
- height: 32rpx;
- border: 2rpx solid #CCCCCC;
- border-radius: 50%;
- display: flex;
- align-items: center;
- justify-content: center;
- background: #FFFFFF;
- transition: all 0.3s;
- &.checked {
- background: #07C160;
- border-color: #07C160;
- .icon-check {
- color: #FFFFFF;
- font-size: 20rpx;
- font-weight: bold;
- }
- }
- }
- }
- .agreement-text {
- color: #333333;
- margin: 0 4rpx;
- }
- .agreement-link {
- color: #1677FF;
- margin: 0 4rpx;
- }
- }
- }
- </style>
|