123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371 |
- <template>
- <!-- 规格弹窗 -->
- <su-popup :show="authType !== ''" round="10" :showClose="true" @close="closeAuthModal">
- <view class="login-wrap">
- <!-- 标题栏 -->
- <view class="head-box " v-if="['smsLogin', 'accountLogin','register'].includes(authType)">
-
- <view class="ss-flex ss-m-b-20">
- <view
- :class="[isActive=='accountLogin' ?`head-title ss-m-r-40 head-title-animation`:`head-title-active ss-m-r-40`]"
- @tap="isActive='accountLogin';showAuthModal('accountLogin','accountLogin')">
-
- {{t('account.account_login')}}
- </view>
- <view
- :class="[isActive=='smsLogin'?`head-title head-title-line head-title-animation ss-m-r-40`:` ss-m-r-40 head-title-active head-title-line`]"
- @tap="isActive='smsLogin';showAuthModal('smsLogin','smsLogin')">
-
- {{t('account.sms_login')}}
- </view>
- <view
- :class="[isActive=='register' ?`head-title head-title-line head-title-animation`:`head-title-active head-title-line`]"
- @tap="isActive='register';showAuthModal('register','register')" >
- <!-- v-if="linkId" -->
- {{t('account.register')}}
- </view>
- </view>
- </view>
- <!-- 用户协议的勾选 -->
- <view v-if="[ 'smsLogin','accountLogin','register'].includes(authType)" class="agreement-box ss-flex ss-row-center"
- :class="{ shake: currentProtocol }">
- <label class="radio ss-flex ss-col-center" @tap="onChange">
- <radio :checked="state.protocol" color="var(--ui-BG-Main)" style="transform: scale(0.8)"
- @tap.stop="onChange" />
- <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
- {{t('account.read_and_agree')}}
- <view class="tcp-text" @tap.stop="onProtocol('用户协议')">
- {{t('account.user_agreement')}}
- </view>
- <view class="agreement-text">{{t('account.and')}}</view>
- <view class="tcp-text" @tap.stop="onProtocol('隐私协议')">
- {{t('account.privacy_policy')}}
- </view>
- </view>
- </label>
- </view>
-
- <!-- 微信公众号授权登陆 在验证码登录 账号登录中显示-->
- <view v-if="['accountLogin', 'smsLogin'].includes(authType)"
- class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center">
- <view class="wx-login-btn " @tap="thirdLogin('wechat')" v-if=" ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) && sheep.$platform.isWechatInstalled">
- <image class=" auto-login-img" :src="sheep.$url.static('/static/images/wechat.png')" />
- <text>{{t('account.wechat_authorization_login')}}</text>
- </view>
- </view>
- <!-- 微信公众号授权登陆 在账号注册中显示 -->
- <view v-if="['register'].includes(authType)"
- class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center">
- <view class="wx-login-btn " @tap="thirdRegister('wechat')" v-if=" ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) && sheep.$platform.isWechatInstalled">
-
- <image class=" auto-login-img" :src="sheep.$url.static('/static/images/wechat.png')" />
-
- <text>{{t('account.wechat_authorization_register')}}</text>
- </view>
- </view>
- <!-- 1. 微信公众号授权登录 第一次登陆时弹窗绑定手机号 accountLogin -->
- <officialAccountFirstLogin v-if="authType === 'officialAccountFirstLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
-
- <!-- 1. 账号密码登录 accountLogin -->
- <account-login v-if="authType === 'accountLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
- <!-- 2. 短信登录 smsLogin -->
- <sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
-
- <!-- 注册 -->
- <register v-if="authType === 'register'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
- <!-- 3. 忘记密码 resetPassword-->
- <!-- <reset-password v-if="authType === 'resetPassword'" /> -->
- <!-- 4. 绑定手机号 changeMobile -->
- <change-mobile v-if="authType === 'changeMobile'" />
- <!-- 5. 修改密码 changePassword-->
- <changePassword v-if="authType === 'changePassword'" />
- <!-- 6. 微信小程序授权 -->
- <mp-authorization v-if="authType === 'mpAuthorization'" />
-
- <!-- 绑定支付宝账号 -->
- <alipay-account v-if="authType === 'alipayAccount'" />
-
- <!-- 绑定银行卡号 -->
- <bank-account v-if="authType === 'bankAccount'" />
- <!-- 7. 第三方登录 -->
- <!-- <view v-if="['accountLogin', 'smsLogin'].includes(authType)" class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"> -->
- <!-- 7.1 微信小程序的快捷登录 -->
- <!-- <view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
- <view class="register-title">还没有账号?</view>
- <button class="ss-reset-button login-btn" open-type="getPhoneNumber"
- @getphonenumber="getPhoneNumber">
- 快捷登录
- </button>
- <view class="circle" />
- </view> -->
- <!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
- <!-- <button
- v-if="
- ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
- sheep.$platform.isWechatInstalled
- "
- @tap="thirdLogin('wechat')"
- class="ss-reset-button auto-login-btn"
- >
- <image
- class="auto-login-img"
- :src="sheep.$url.static('/static/images/wechat.png')"
- />
- </button> -->
- <!-- 7.3 iOS 登录 TODO 非繁人:等后面搞 App 再弄 -->
- <!-- <button v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'" @tap="thirdLogin('apple')"
- class="ss-reset-button auto-login-btn">
- <image class="auto-login-img" :src="sheep.$url.static('/static/images/apple.png')" />
- </button> -->
- <!-- </view> -->
- <view class="safe-box" />
- </view>
- </su-popup>
- </template>
- <script setup>
- import {
- computed,
- reactive,
- ref
- } from 'vue';
- import sheep from '@/sheep';
- import accountLogin from './components/account-login.vue';
- import smsLogin from './components/sms-login.vue';
- import register from './components/register.vue'
- import resetPassword from './components/reset-password.vue';
- import changeMobile from './components/change-mobile.vue';
- import changePassword from './components/change-password.vue';
- import mpAuthorization from './components/mp-authorization.vue';
- import officialAccountFirstLogin from './components/officialAccountFirstLogin'
- import alipayAccount from './components/alipay-account.vue'
- import bankAccount from './components/bank-account.vue'
-
- import {
- closeAuthModal,
- showAuthModal
- } from '@/sheep/hooks/useModal';
- import wx from "weixin-js-sdk";
- import { t } from '@/locale'
- const appInfo = computed(() => sheep.$store('app').info);
- const linkId = uni.getStorageSync("linkId");
- const modalStore = sheep.$store('modal');
- // 授权弹窗类型
- const authType = computed(() => modalStore.auth);
- const isActive = computed(() => modalStore.isActive)
- const state = reactive({
- protocol: false,
- });
- const currentProtocol = ref(false);
- // 勾选协议
- function onChange() {
- state.protocol = !state.protocol;
- }
- // 查看协议
- function onProtocol(title) {
- closeAuthModal();
- sheep.$router.go('/pages/public/richtext', {
- title,
- });
- }
- // 点击登录 / 注册事件
- function onConfirm(e) {
- currentProtocol.value = e;
- setTimeout(() => {
- currentProtocol.value = false;
- }, 1000);
- }
-
- /**
- * 判断是不是在小程序中
- */
- // function isInMiniProgram() {
- // return new Promise((resolve, reject) => {
- // if (typeof wx !== 'undefined' && wx.miniProgram) {
- // wx.miniProgram.getEnv((res) => {
- // resolve(res.miniprogram);
- // });
- // } else {
- // reject(new Error('wx 或 wx.miniProgram 未定义'));
- // }
- // });
- // }
- // 第三方授权登陆(微信小程序、Apple)
- const thirdLogin = async (provider) => {
- if (!state.protocol) {
- currentProtocol.value = true;
- setTimeout(() => {
- currentProtocol.value = false;
- }, 1000);
- sheep.$helper.toast(t('account.please_agree'));
- return;
- }
-
- // if (provider === 'wechat') {
- // console.log(isInMiniProgram())
- // if( isInMiniProgram()){
- // wx.miniProgram.postMessage({
- // type: 'getWxCode'
- // });
- // console.log(isInMiniProgram())
- // return;
- // }
- // }
-
- const loginRes = await sheep.$platform.useProvider(provider).login();
- if (loginRes) {
- closeAuthModal();
- // 触发小程序授权信息弹框
- // #ifdef MP-WEIXIN
- showAuthModal('mpAuthorization');
- // #endif
- }
- };
- // 第三方授权注册
- const thirdRegister = async (provider) => {
- if (!state.protocol) {
- currentProtocol.value = true;
- setTimeout(() => {
- currentProtocol.value = false;
- }, 1000);
- sheep.$helper.toast(t('account.please_agree'));
- return;
- }
- // const linkId = uni.getStorageSync("linkId");
- // if (!linkId) {
- // sheep.$helper.toast(t('account.register_by_sharing_only'));
- // return false;
- // }
- const loginRes = await sheep.$platform.useProvider(provider).register();
- if (loginRes) {
- closeAuthModal();
- // 触发小程序授权信息弹框
- // #ifdef MP-WEIXIN
- showAuthModal('mpAuthorization');
- // #endif
- }
- };
-
- // 微信小程序的“手机号快速验证”:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
- const getPhoneNumber = async (e) => {
- if (e.detail.errMsg !== 'getPhoneNumber:ok') {
- sheep.$helper.toast(t('account.quick_login_failed'));
- return;
- }
- let result = await sheep.$platform.useProvider().mobileLogin(e.detail);
- if (result) {
- closeAuthModal();
- }
- };
- </script>
- <style lang="scss" scoped>
- @import './index.scss';
- .shake {
- animation: shake 0.05s linear 4 alternate;
- }
- @keyframes shake {
- from {
- transform: translateX(-10rpx);
- }
- to {
- transform: translateX(10rpx);
- }
- }
- .register-box {
- position: relative;
- justify-content: center;
- .register-btn {
- color: #999999;
- font-size: 30rpx;
- font-weight: 500;
- }
- .register-title {
- color: #999999;
- font-size: 30rpx;
- font-weight: 400;
- margin-right: 24rpx;
- }
- .or-title {
- margin: 0 16rpx;
- color: #999999;
- font-size: 30rpx;
- font-weight: 400;
- }
- .login-btn {
- color: var(--ui-BG-Main);
- font-size: 30rpx;
- font-weight: 500;
- }
- .circle {
- position: absolute;
- right: 0rpx;
- top: 18rpx;
- width: 8rpx;
- height: 8rpx;
- border-radius: 8rpx;
- background: var(--ui-BG-Main);
- }
- }
- .safe-box {
- height: calc(constant(safe-area-inset-bottom) / 5 * 3);
- height: calc(env(safe-area-inset-bottom) / 5 * 3);
- }
- .tcp-text {
- color: var(--ui-BG-Main);
- }
- .agreement-text {
- color: $dark-9;
- }
- .wx-login-btn {
- width: 100%;
- border: 1rpx solid #55b774;
- border-radius: 10rpx;
- padding: 10rpx 0;
- color: #333333;
- display: flex;
- align-items: center;
- justify-content: center;
- font-size: 32rpx;
- margin: 0 0 0.625rem 0;
- box-sizing: border-box;
- text {
- margin-left: 20rpx
- }
- }
- .agreement-box {
- margin: 40rpx;
- }
- </style>
|