s-auth-modal.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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. 忘记密码 resetPassword-->
  14. <reset-password v-if="authType === 'resetPassword'" />
  15. <!-- 4. 绑定手机号 changeMobile -->
  16. <change-mobile v-if="authType === 'changeMobile'" />
  17. <!-- 5. 修改密码 changePassword-->
  18. <changePassword v-if="authType === 'changePassword'" />
  19. <!-- 6. 微信小程序授权 -->
  20. <mp-authorization v-if="authType === 'mpAuthorization'" />
  21. <!-- 7. 第三方登录 -->
  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. <!-- 7.1 微信小程序的快捷登录 -->
  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. <!-- 7.2 微信的公众号、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. <!-- 7.3 iOS 登录 TODO 芋艿:等后面搞 App 再弄 -->
  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. <!-- 用户协议的勾选 -->
  61. <view
  62. v-if="['accountLogin', 'smsLogin'].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"/>
  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. // 查看协议 TODO 芋艿:协议
  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. // 第三方授权登陆(微信小程序、Apple)
  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. // 触发小程序授权信息弹框
  146. // #ifdef MP-WEIXIN
  147. showAuthModal('mpAuthorization');
  148. // #endif
  149. }
  150. };
  151. // 微信小程序的“手机号快速验证”:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
  152. const getPhoneNumber = async (e) => {
  153. if (e.detail.errMsg !== 'getPhoneNumber:ok') {
  154. sheep.$helper.toast('快捷登录失败');
  155. return;
  156. }
  157. let result = await sheep.$platform.useProvider().mobileLogin(e.detail);
  158. if (result) {
  159. debugger
  160. closeAuthModal();
  161. }
  162. };
  163. </script>
  164. <style lang="scss" scoped>
  165. @import './index.scss';
  166. .shake {
  167. animation: shake 0.05s linear 4 alternate;
  168. }
  169. @keyframes shake {
  170. from {
  171. transform: translateX(-10rpx);
  172. }
  173. to {
  174. transform: translateX(10rpx);
  175. }
  176. }
  177. .register-box {
  178. position: relative;
  179. justify-content: center;
  180. .register-btn {
  181. color: #999999;
  182. font-size: 30rpx;
  183. font-weight: 500;
  184. }
  185. .register-title {
  186. color: #999999;
  187. font-size: 30rpx;
  188. font-weight: 400;
  189. margin-right: 24rpx;
  190. }
  191. .or-title {
  192. margin: 0 16rpx;
  193. color: #999999;
  194. font-size: 30rpx;
  195. font-weight: 400;
  196. }
  197. .login-btn {
  198. color: var(--ui-BG-Main);
  199. font-size: 30rpx;
  200. font-weight: 500;
  201. }
  202. .circle {
  203. position: absolute;
  204. right: 0rpx;
  205. top: 18rpx;
  206. width: 8rpx;
  207. height: 8rpx;
  208. border-radius: 8rpx;
  209. background: var(--ui-BG-Main);
  210. }
  211. }
  212. .safe-box {
  213. height: calc(constant(safe-area-inset-bottom) / 5 * 3);
  214. height: calc(env(safe-area-inset-bottom) / 5 * 3);
  215. }
  216. .tcp-text {
  217. color: var(--ui-BG-Main);
  218. }
  219. .agreement-text {
  220. color: $dark-9;
  221. }
  222. </style>