s-auth-modal.vue 7.5 KB

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