s-auth-modal.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <!-- 规格弹窗 -->
  3. <su-popup :show="authType !== ''" round="10" :showClose="true" @close="closeAuthModal">
  4. <view class="login-wrap">
  5. <!-- 标题栏 -->
  6. <view class="head-box " v-if="['smsLogin', 'accountLogin','register'].includes(authType)">
  7. <view class="ss-flex ss-m-b-20">
  8. <view
  9. :class="[isActive=='accountLogin' ?`head-title ss-m-r-40 head-title-animation`:`head-title-active ss-m-r-40`]"
  10. @tap="isActive='accountLogin';showAuthModal('accountLogin','accountLogin')">
  11. {{t('account.account_login')}}
  12. </view>
  13. <view
  14. :class="[isActive=='smsLogin'?`head-title head-title-line head-title-animation ss-m-r-40`:` ss-m-r-40 head-title-active head-title-line`]"
  15. @tap="isActive='smsLogin';showAuthModal('smsLogin','smsLogin')">
  16. {{t('account.sms_login')}}
  17. </view>
  18. <view
  19. :class="[isActive=='register' ?`head-title head-title-line head-title-animation`:`head-title-active head-title-line`]"
  20. @tap="isActive='register';showAuthModal('register','register')" >
  21. <!-- v-if="linkId" -->
  22. {{t('account.register')}}
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 用户协议的勾选 -->
  27. <view v-if="[ 'smsLogin','accountLogin','register'].includes(authType)" class="agreement-box ss-flex ss-row-center"
  28. :class="{ shake: currentProtocol }">
  29. <label class="radio ss-flex ss-col-center" @tap="onChange">
  30. <radio :checked="state.protocol" color="var(--ui-BG-Main)" style="transform: scale(0.8)"
  31. @tap.stop="onChange" />
  32. <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
  33. {{t('account.read_and_agree')}}
  34. <view class="tcp-text" @tap.stop="onProtocol('用户协议')">
  35. {{t('account.user_agreement')}}
  36. </view>
  37. <view class="agreement-text">{{t('account.and')}}</view>
  38. <view class="tcp-text" @tap.stop="onProtocol('隐私协议')">
  39. {{t('account.privacy_policy')}}
  40. </view>
  41. </view>
  42. </label>
  43. </view>
  44. <!-- 微信公众号授权登陆 在验证码登录 账号登录中显示-->
  45. <view v-if="['accountLogin', 'smsLogin'].includes(authType)"
  46. class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center">
  47. <view class="wx-login-btn " @tap="thirdLogin('wechat')" v-if=" ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) && sheep.$platform.isWechatInstalled">
  48. <image class=" auto-login-img" :src="sheep.$url.static('/static/images/wechat.png')" />
  49. <text>{{t('account.wechat_authorization_login')}}</text>
  50. </view>
  51. </view>
  52. <!-- 微信公众号授权登陆 在账号注册中显示 -->
  53. <view v-if="['register'].includes(authType)"
  54. class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center">
  55. <view class="wx-login-btn " @tap="thirdRegister('wechat')" v-if=" ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) && sheep.$platform.isWechatInstalled">
  56. <image class=" auto-login-img" :src="sheep.$url.static('/static/images/wechat.png')" />
  57. <text>{{t('account.wechat_authorization_register')}}</text>
  58. </view>
  59. </view>
  60. <!-- 1. 微信公众号授权登录 第一次登陆时弹窗绑定手机号 accountLogin -->
  61. <officialAccountFirstLogin v-if="authType === 'officialAccountFirstLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
  62. <!-- 1. 账号密码登录 accountLogin -->
  63. <account-login v-if="authType === 'accountLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
  64. <!-- 2. 短信登录 smsLogin -->
  65. <sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
  66. <!-- 注册 -->
  67. <register v-if="authType === 'register'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
  68. <!-- 3. 忘记密码 resetPassword-->
  69. <!-- <reset-password v-if="authType === 'resetPassword'" /> -->
  70. <!-- 4. 绑定手机号 changeMobile -->
  71. <change-mobile v-if="authType === 'changeMobile'" />
  72. <!-- 5. 修改密码 changePassword-->
  73. <changePassword v-if="authType === 'changePassword'" />
  74. <!-- 6. 微信小程序授权 -->
  75. <mp-authorization v-if="authType === 'mpAuthorization'" />
  76. <!-- 绑定支付宝账号 -->
  77. <alipay-account v-if="authType === 'alipayAccount'" />
  78. <!-- 绑定银行卡号 -->
  79. <bank-account v-if="authType === 'bankAccount'" />
  80. <!-- 7. 第三方登录 -->
  81. <!-- <view v-if="['accountLogin', 'smsLogin'].includes(authType)" class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"> -->
  82. <!-- 7.1 微信小程序的快捷登录 -->
  83. <!-- <view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
  84. <view class="register-title">还没有账号?</view>
  85. <button class="ss-reset-button login-btn" open-type="getPhoneNumber"
  86. @getphonenumber="getPhoneNumber">
  87. 快捷登录
  88. </button>
  89. <view class="circle" />
  90. </view> -->
  91. <!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
  92. <!-- <button
  93. v-if="
  94. ['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
  95. sheep.$platform.isWechatInstalled
  96. "
  97. @tap="thirdLogin('wechat')"
  98. class="ss-reset-button auto-login-btn"
  99. >
  100. <image
  101. class="auto-login-img"
  102. :src="sheep.$url.static('/static/images/wechat.png')"
  103. />
  104. </button> -->
  105. <!-- 7.3 iOS 登录 TODO 非繁人:等后面搞 App 再弄 -->
  106. <!-- <button v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'" @tap="thirdLogin('apple')"
  107. class="ss-reset-button auto-login-btn">
  108. <image class="auto-login-img" :src="sheep.$url.static('/static/images/apple.png')" />
  109. </button> -->
  110. <!-- </view> -->
  111. <view class="safe-box" />
  112. </view>
  113. </su-popup>
  114. </template>
  115. <script setup>
  116. import {
  117. computed,
  118. reactive,
  119. ref
  120. } from 'vue';
  121. import sheep from '@/sheep';
  122. import accountLogin from './components/account-login.vue';
  123. import smsLogin from './components/sms-login.vue';
  124. import register from './components/register.vue'
  125. import resetPassword from './components/reset-password.vue';
  126. import changeMobile from './components/change-mobile.vue';
  127. import changePassword from './components/change-password.vue';
  128. import mpAuthorization from './components/mp-authorization.vue';
  129. import officialAccountFirstLogin from './components/officialAccountFirstLogin'
  130. import alipayAccount from './components/alipay-account.vue'
  131. import bankAccount from './components/bank-account.vue'
  132. import {
  133. closeAuthModal,
  134. showAuthModal
  135. } from '@/sheep/hooks/useModal';
  136. import wx from "weixin-js-sdk";
  137. import { t } from '@/locale'
  138. const appInfo = computed(() => sheep.$store('app').info);
  139. const linkId = uni.getStorageSync("linkId");
  140. const modalStore = sheep.$store('modal');
  141. // 授权弹窗类型
  142. const authType = computed(() => modalStore.auth);
  143. const isActive = computed(() => modalStore.isActive)
  144. const state = reactive({
  145. protocol: false,
  146. });
  147. const currentProtocol = ref(false);
  148. // 勾选协议
  149. function onChange() {
  150. state.protocol = !state.protocol;
  151. }
  152. // 查看协议
  153. function onProtocol(title) {
  154. closeAuthModal();
  155. sheep.$router.go('/pages/public/richtext', {
  156. title,
  157. });
  158. }
  159. // 点击登录 / 注册事件
  160. function onConfirm(e) {
  161. currentProtocol.value = e;
  162. setTimeout(() => {
  163. currentProtocol.value = false;
  164. }, 1000);
  165. }
  166. /**
  167. * 判断是不是在小程序中
  168. */
  169. // function isInMiniProgram() {
  170. // return new Promise((resolve, reject) => {
  171. // if (typeof wx !== 'undefined' && wx.miniProgram) {
  172. // wx.miniProgram.getEnv((res) => {
  173. // resolve(res.miniprogram);
  174. // });
  175. // } else {
  176. // reject(new Error('wx 或 wx.miniProgram 未定义'));
  177. // }
  178. // });
  179. // }
  180. // 第三方授权登陆(微信小程序、Apple)
  181. const thirdLogin = async (provider) => {
  182. if (!state.protocol) {
  183. currentProtocol.value = true;
  184. setTimeout(() => {
  185. currentProtocol.value = false;
  186. }, 1000);
  187. sheep.$helper.toast(t('account.please_agree'));
  188. return;
  189. }
  190. // if (provider === 'wechat') {
  191. // console.log(isInMiniProgram())
  192. // if( isInMiniProgram()){
  193. // wx.miniProgram.postMessage({
  194. // type: 'getWxCode'
  195. // });
  196. // console.log(isInMiniProgram())
  197. // return;
  198. // }
  199. // }
  200. const loginRes = await sheep.$platform.useProvider(provider).login();
  201. if (loginRes) {
  202. closeAuthModal();
  203. // 触发小程序授权信息弹框
  204. // #ifdef MP-WEIXIN
  205. showAuthModal('mpAuthorization');
  206. // #endif
  207. }
  208. };
  209. // 第三方授权注册
  210. const thirdRegister = async (provider) => {
  211. if (!state.protocol) {
  212. currentProtocol.value = true;
  213. setTimeout(() => {
  214. currentProtocol.value = false;
  215. }, 1000);
  216. sheep.$helper.toast(t('account.please_agree'));
  217. return;
  218. }
  219. // const linkId = uni.getStorageSync("linkId");
  220. // if (!linkId) {
  221. // sheep.$helper.toast(t('account.register_by_sharing_only'));
  222. // return false;
  223. // }
  224. const loginRes = await sheep.$platform.useProvider(provider).register();
  225. if (loginRes) {
  226. closeAuthModal();
  227. // 触发小程序授权信息弹框
  228. // #ifdef MP-WEIXIN
  229. showAuthModal('mpAuthorization');
  230. // #endif
  231. }
  232. };
  233. // 微信小程序的“手机号快速验证”:https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
  234. const getPhoneNumber = async (e) => {
  235. if (e.detail.errMsg !== 'getPhoneNumber:ok') {
  236. sheep.$helper.toast(t('account.quick_login_failed'));
  237. return;
  238. }
  239. let result = await sheep.$platform.useProvider().mobileLogin(e.detail);
  240. if (result) {
  241. closeAuthModal();
  242. }
  243. };
  244. </script>
  245. <style lang="scss" scoped>
  246. @import './index.scss';
  247. .shake {
  248. animation: shake 0.05s linear 4 alternate;
  249. }
  250. @keyframes shake {
  251. from {
  252. transform: translateX(-10rpx);
  253. }
  254. to {
  255. transform: translateX(10rpx);
  256. }
  257. }
  258. .register-box {
  259. position: relative;
  260. justify-content: center;
  261. .register-btn {
  262. color: #999999;
  263. font-size: 30rpx;
  264. font-weight: 500;
  265. }
  266. .register-title {
  267. color: #999999;
  268. font-size: 30rpx;
  269. font-weight: 400;
  270. margin-right: 24rpx;
  271. }
  272. .or-title {
  273. margin: 0 16rpx;
  274. color: #999999;
  275. font-size: 30rpx;
  276. font-weight: 400;
  277. }
  278. .login-btn {
  279. color: var(--ui-BG-Main);
  280. font-size: 30rpx;
  281. font-weight: 500;
  282. }
  283. .circle {
  284. position: absolute;
  285. right: 0rpx;
  286. top: 18rpx;
  287. width: 8rpx;
  288. height: 8rpx;
  289. border-radius: 8rpx;
  290. background: var(--ui-BG-Main);
  291. }
  292. }
  293. .safe-box {
  294. height: calc(constant(safe-area-inset-bottom) / 5 * 3);
  295. height: calc(env(safe-area-inset-bottom) / 5 * 3);
  296. }
  297. .tcp-text {
  298. color: var(--ui-BG-Main);
  299. }
  300. .agreement-text {
  301. color: $dark-9;
  302. }
  303. .wx-login-btn {
  304. width: 100%;
  305. border: 1rpx solid #55b774;
  306. border-radius: 10rpx;
  307. padding: 10rpx 0;
  308. color: #333333;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. font-size: 32rpx;
  313. margin: 0 0 0.625rem 0;
  314. box-sizing: border-box;
  315. text {
  316. margin-left: 20rpx
  317. }
  318. }
  319. .agreement-box {
  320. margin: 40rpx;
  321. }
  322. </style>