s-auth-modal.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <!-- 规格弹窗 -->
  3. <su-popup :show="authType !== ''" round="20" :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
  13. v-if="authType === 'smsLogin'"
  14. :agreeStatus="state.protocol"
  15. @onConfirm="onConfirm"
  16. />
  17. <!-- 3. 忘记密码 resetPassword-->
  18. <reset-password v-if="authType === 'resetPassword'" />
  19. <!-- 4. 绑定手机号 changeMobile -->
  20. <change-mobile v-if="authType === 'changeMobile'" />
  21. <!-- 5. 修改密码 changePassword-->
  22. <changePassword v-if="authType === 'changePassword'" />
  23. <!-- 6. 微信小程序授权 -->
  24. <mp-authorization v-if="authType === 'mpAuthorization'" />
  25. <!-- 7. 第三方登录 -->
  26. <view
  27. v-if="['accountLogin', 'smsLogin'].includes(authType)"
  28. class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"
  29. >
  30. <!-- 7.1 微信小程序的快捷登录 -->
  31. <view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
  32. <view class="register-title">还没有账号?</view>
  33. <button
  34. class="ss-reset-button login-btn"
  35. open-type="getPhoneNumber"
  36. @getphonenumber="getPhoneNumber"
  37. >
  38. 快捷登录
  39. </button>
  40. <view class="circle" />
  41. </view>
  42. <!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
  43. <button
  44. v-if="
  45. ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
  46. sheep.$platform.isWechatInstalled
  47. "
  48. @tap="thirdLogin('wechat')"
  49. class="ss-reset-button auto-login-btn"
  50. >
  51. <image
  52. class="auto-login-img"
  53. :src="sheep.$url.static('/static/img/shop/platform/wechat.png')"
  54. />
  55. </button>
  56. <!-- 7.3 iOS 登录 TODO 芋艿:等后面搞 App 再弄 -->
  57. <button
  58. v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
  59. @tap="thirdLogin('apple')"
  60. class="ss-reset-button auto-login-btn"
  61. >
  62. <image
  63. class="auto-login-img"
  64. :src="sheep.$url.static('/static/img/shop/platform/apple.png')"
  65. />
  66. </button>
  67. </view>
  68. <!-- 同意选项 -->
  69. <view class="agreement-option ss-m-b-20">
  70. <label class="radio ss-flex ss-col-center" @tap="onAgree">
  71. <view class="check_box" @tap.stop="onAgree">
  72. <image v-if="state.protocol" class="check_icon" src="/static/check_icon.png"></image>
  73. <image v-else class="check_icon" src="/static/check_icon1.png"></image>
  74. </view>
  75. <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
  76. 我已阅读并同意遵守
  77. <view class="tcp-text" @tap.stop="onProtocol('用户协议')"> 《用户协议》 </view>
  78. <view class="agreement-text">与</view>
  79. <view class="tcp-text" @tap.stop="onProtocol('隐私协议')"> 《隐私协议》 </view>
  80. </view>
  81. </label>
  82. </view>
  83. <view class="safe-box" />
  84. </view>
  85. </su-popup>
  86. </template>
  87. <script setup>
  88. import { computed, reactive, ref } from 'vue';
  89. import sheep from '@/common';
  90. import accountLogin from './components/account-login.vue';
  91. import smsLogin from './components/sms-login.vue';
  92. import resetPassword from './components/reset-password.vue';
  93. import changeMobile from './components/change-mobile.vue';
  94. import changePassword from './components/change-password.vue';
  95. import mpAuthorization from './components/mp-authorization.vue';
  96. import { closeAuthModal, showAuthModal } from '@/common/hooks/useModal';
  97. const modalStore = sheep.$store('modal');
  98. // 授权弹窗类型
  99. const authType = computed(() => modalStore.auth);
  100. const state = reactive({
  101. protocol: null, // null表示未选择,true表示同意,false表示拒绝
  102. });
  103. const currentProtocol = ref(false);
  104. // 同意协议
  105. function onAgree() {
  106. state.protocol = !state.protocol;
  107. }
  108. // 查看协议
  109. function onProtocol(title) {
  110. closeAuthModal();
  111. sheep.$router.go('/pages/public/richtext', {
  112. title,
  113. });
  114. }
  115. // 点击登录 / 注册事件
  116. function onConfirm(e) {
  117. currentProtocol.value = e;
  118. setTimeout(() => {
  119. currentProtocol.value = false;
  120. }, 1000);
  121. }
  122. // 第三方授权登陆(微信小程序、Apple)
  123. const thirdLogin = async (provider) => {
  124. if (state.protocol !== true) {
  125. currentProtocol.value = true;
  126. setTimeout(() => {
  127. currentProtocol.value = false;
  128. }, 1000);
  129. if (state.protocol === false) {
  130. sheep.$helper.toast('您已拒绝协议,无法继续登录');
  131. } else {
  132. sheep.$helper.toast('请选择是否同意协议');
  133. }
  134. return;
  135. }
  136. const loginRes = await sheep.$platform.useProvider(provider).login();
  137. if (loginRes) {
  138. const userInfo = await sheep.$store('user').getInfo();
  139. closeAuthModal();
  140. // 如果用户已经有头像和昵称,不需要再次授权
  141. if (userInfo.avatar && userInfo.nickname) {
  142. return;
  143. }
  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. closeAuthModal();
  159. }
  160. };
  161. </script>
  162. <style lang="scss" scoped>
  163. @import './index.scss';
  164. .shake {
  165. animation: shake 0.05s linear 4 alternate;
  166. }
  167. @keyframes shake {
  168. from {
  169. transform: translateX(-10rpx);
  170. }
  171. to {
  172. transform: translateX(10rpx);
  173. }
  174. }
  175. .register-box {
  176. position: relative;
  177. justify-content: center;
  178. .register-btn {
  179. color: #999999;
  180. font-size: 30rpx;
  181. font-weight: 500;
  182. }
  183. .register-title {
  184. color: #999999;
  185. font-size: 30rpx;
  186. font-weight: 400;
  187. margin-right: 24rpx;
  188. }
  189. .or-title {
  190. margin: 0 16rpx;
  191. color: #999999;
  192. font-size: 30rpx;
  193. font-weight: 400;
  194. }
  195. .login-btn {
  196. color: var(--ui-BG-Main);
  197. font-size: 30rpx;
  198. font-weight: 500;
  199. }
  200. .circle {
  201. position: absolute;
  202. right: 0rpx;
  203. top: 18rpx;
  204. width: 8rpx;
  205. height: 8rpx;
  206. border-radius: 8rpx;
  207. background: var(--ui-BG-Main);
  208. }
  209. }
  210. .safe-box {
  211. height: calc(constant(safe-area-inset-bottom) / 5 * 3);
  212. height: calc(env(safe-area-inset-bottom) / 5 * 3);
  213. }
  214. .agreement-option {
  215. width: 100%;
  216. display: flex;
  217. justify-content: center;
  218. padding-top: 40rpx;
  219. .check_box{
  220. padding-right: 10rpx;
  221. .check_icon{
  222. width: 24rpx;
  223. height: 24rpx;
  224. }
  225. }
  226. .agreement-text {
  227. font-weight: 400;
  228. font-size: 24rpx;
  229. color: #222222;
  230. .tcp-text {
  231. color: #24D688;
  232. }
  233. }
  234. }
  235. </style>