s-auth-modal.vue 7.3 KB

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