s-auth-modal.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <!-- 规格弹窗 -->
  3. <su-popup :show="authType !== ''" round="10" :showClose="true" @close="closeAuthModal">
  4. <view class="login-wrap">
  5. <!-- 1. 账号密码登录 accountLogin -->
  6. <account-login
  7. v-if="authType === 'accountLogin'"
  8. :agreeStatus="state.protocol"
  9. @onConfirm="onConfirm"
  10. />
  11. <!-- 2.短信登录 smsLogin -->
  12. <sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
  13. <!-- 4.忘记密码 resetPassword-->
  14. <reset-password v-if="authType === 'resetPassword'" />
  15. <!-- 5.绑定手机号 changeMobile -->
  16. <change-mobile v-if="authType === 'changeMobile'" />
  17. <!-- 6.修改密码 changePassword-->
  18. <changePassword v-if="authType === 'changePassword'" />
  19. <!-- 8.微信小程序授权 changeUsername-->
  20. <mp-authorization v-if="authType === 'mpAuthorization'" />
  21. <!-- 第三方登录+注册 -->
  22. <view
  23. v-if="['accountLogin', 'smsLogin'].includes(authType)"
  24. class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"
  25. >
  26. <!-- 立即注册&快捷登录 TextButton -->
  27. <view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
  28. <view class="register-title">还没有账号?</view>
  29. <button class="ss-reset-button register-btn" @tap="showAuthModal('smsRegister')">立即注册</button
  30. >
  31. <view class="or-title">或</view>
  32. <button class="ss-reset-button login-btn" @tap="thirdLogin('wechat')">快捷登录</button>
  33. <view class="circle"></view>
  34. </view>
  35. <!-- 公众号|App微信登录 -->
  36. <button
  37. v-if="
  38. ['WechatOfficialAccount', 'App'].includes(sheep.$platform.name) &&
  39. sheep.$platform.isWechatInstalled
  40. "
  41. @tap="thirdLogin('wechat')"
  42. class="ss-reset-button auto-login-btn"
  43. >
  44. <image
  45. class="auto-login-img"
  46. :src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
  47. ></image>
  48. </button>
  49. <!-- iOS登录 -->
  50. <button
  51. v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
  52. @tap="thirdLogin('apple')"
  53. class="ss-reset-button auto-login-btn"
  54. >
  55. <image
  56. class="auto-login-img"
  57. :src="sheep.$url.static('/static/img/shop/platform/apple.png')"
  58. ></image>
  59. </button>
  60. </view>
  61. <view
  62. v-if="['accountLogin', 'smsLogin', 'smsRegister'].includes(authType)"
  63. class="agreement-box ss-flex ss-row-center"
  64. :class="{ shake: currentProtocol }"
  65. >
  66. <label class="radio ss-flex ss-col-center" @tap="onChange">
  67. <radio
  68. :checked="state.protocol"
  69. color="var(--ui-BG-Main)"
  70. style="transform: scale(0.8)"
  71. @tap.stop="onChange"
  72. />
  73. <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
  74. 我已阅读并遵守
  75. <view
  76. class="tcp-text"
  77. @tap.stop="onProtocol(appInfo.user_protocol.id, appInfo.user_protocol.title)"
  78. >
  79. 《{{ appInfo.user_protocol.title }}》
  80. </view>
  81. <view class="agreement-text">与</view>
  82. <view
  83. class="tcp-text"
  84. @tap.stop="onProtocol(appInfo.privacy_protocol.id, appInfo.privacy_protocol.title)"
  85. >
  86. 《{{ appInfo.privacy_protocol.title }}》
  87. </view>
  88. </view>
  89. </label>
  90. </view>
  91. <view class="safe-box"></view>
  92. </view>
  93. </su-popup>
  94. </template>
  95. <script setup>
  96. import { computed, reactive, ref } from 'vue';
  97. import sheep from '@/sheep';
  98. import accountLogin from './components/account-login.vue';
  99. import smsLogin from './components/sms-login.vue';
  100. import resetPassword from './components/reset-password.vue';
  101. import changeMobile from './components/change-mobile.vue';
  102. import changePassword from './components/change-password.vue';
  103. import mpAuthorization from './components/mp-authorization.vue';
  104. import { closeAuthModal, showAuthModal } from '@/sheep/hooks/useModal';
  105. const appInfo = computed(() => sheep.$store('app').info);
  106. const modalStore = sheep.$store('modal');
  107. // 授权弹窗类型
  108. const authType = computed(() => modalStore.auth);
  109. const state = reactive({
  110. protocol: false,
  111. });
  112. const currentProtocol = ref(false);
  113. //勾选协议
  114. function onChange() {
  115. state.protocol = !state.protocol;
  116. }
  117. // 查看协议
  118. function onProtocol(id, title) {
  119. closeAuthModal();
  120. sheep.$router.go('/pages/public/richtext', {
  121. id,
  122. title,
  123. });
  124. }
  125. // 点击登录/注册事件
  126. function onConfirm(e) {
  127. currentProtocol.value = e;
  128. setTimeout(() => {
  129. currentProtocol.value = false;
  130. }, 1000);
  131. }
  132. // 第三方授权登陆
  133. const thirdLogin = async (provider) => {
  134. if (!state.protocol) {
  135. currentProtocol.value = true;
  136. setTimeout(() => {
  137. currentProtocol.value = false;
  138. }, 1000);
  139. sheep.$helper.toast('请勾选同意');
  140. return;
  141. }
  142. const loginRes = await sheep.$platform.useProvider(provider).login();
  143. if (loginRes) {
  144. closeAuthModal();
  145. const userInfo = await sheep.$store('user').getInfo();
  146. // 触发小程序授权信息弹框
  147. // #ifdef MP-WEIXIN
  148. if (userInfo.third_oauth.length > 0) {
  149. const mpThirdOauthInfo = userInfo.third_oauth.find(
  150. (item) => item.platform === 'miniProgram',
  151. );
  152. if (mpThirdOauthInfo && !mpThirdOauthInfo.nickname) {
  153. showAuthModal('mpAuthorization');
  154. }
  155. }
  156. // #endif
  157. }
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. @import './index.scss';
  162. .shake {
  163. animation: shake 0.05s linear 4 alternate;
  164. }
  165. @keyframes shake {
  166. from {
  167. transform: translateX(-10rpx);
  168. }
  169. to {
  170. transform: translateX(10rpx);
  171. }
  172. }
  173. .register-box {
  174. position: relative;
  175. justify-content: center;
  176. .register-btn {
  177. color: #999999;
  178. font-size: 30rpx;
  179. font-weight: 500;
  180. }
  181. .register-title {
  182. color: #999999;
  183. font-size: 30rpx;
  184. font-weight: 400;
  185. margin-right: 24rpx;
  186. }
  187. .or-title {
  188. margin: 0 16rpx;
  189. color: #999999;
  190. font-size: 30rpx;
  191. font-weight: 400;
  192. }
  193. .login-btn {
  194. color: var(--ui-BG-Main);
  195. font-size: 30rpx;
  196. font-weight: 500;
  197. }
  198. .circle {
  199. position: absolute;
  200. right: 0rpx;
  201. top: 18rpx;
  202. width: 8rpx;
  203. height: 8rpx;
  204. border-radius: 8rpx;
  205. background: var(--ui-BG-Main);
  206. }
  207. }
  208. .safe-box {
  209. height: calc(constant(safe-area-inset-bottom) / 5 * 3);
  210. height: calc(env(safe-area-inset-bottom) / 5 * 3);
  211. }
  212. .tcp-text {
  213. color: var(--ui-BG-Main);
  214. }
  215. .agreement-text {
  216. color: $dark-9;
  217. }
  218. </style>