s-auth-modal.vue 6.6 KB

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