s-auth-modal.vue 7.0 KB

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