login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <!-- 微信公众号的登录回调页 -->
  2. <template>
  3. <view />
  4. <su-popup :show="selectSocialUsers" type="center" round="10" :isMaskClick="false">
  5. <view class="head-nav">
  6. <view class="head-box">
  7. <view class="ss-flex ss-m-b-20">
  8. <view class="isActive head-title">
  9. {{ t('account.select_account_login') }}
  10. </view>
  11. </view>
  12. </view>
  13. </view>
  14. <view>
  15. <scroll-view class="side-menu-wrap" scroll-y style="height:600rpx">
  16. <view v-for="user in state.socialUsers" :key="user.username" class="ss-flex"
  17. style="padding: 20rpx;margin: 0 auto;width: 520rpx;" @click="selectUser(user.username)">
  18. <image :src="user.avatar"
  19. style="width:100rpx;height:100rpx;border-radius: 50%;margin-right:20rpx" />
  20. <view>{{user.username}}</view>
  21. </view>
  22. <view v-if="!state.socialUsers.length" style="padding: 20rpx;width: 520rpx;text-align: center;margin-top: 100rpx;">
  23. {{ t('account.wechat_no_bind') }}
  24. </view>
  25. </scroll-view>
  26. </view>
  27. </su-popup>
  28. <su-popup :show="isPopup" round="10" :isMaskClick="false">
  29. <view>
  30. <view class="head-box">
  31. <view class="ss-flex ss-m-b-20">
  32. <view class="isActive head-title">
  33. {{ t('account.wechat_register') }}
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 表单项 -->
  38. <uni-forms v-model="state.model" :rules="state.rules" validateTrigger="bind"
  39. labelWidth="140" labelAlign="center" class="loginUniForm">
  40. <uni-forms-item name="username" :label="t('account.username')" class="loginUniFormItem" :error-message="state.usernameErrorMsg">
  41. <uni-easyinput :placeholder="t('account.enter_username')" v-model="state.registerReqVO.username" :inputBorder="false"
  42. :clearable="false" @blur="verifyUsername">
  43. <template v-slot:right>
  44. <view v-if="!state.verifyUsername" class="icon">
  45. <image style :src="sheep.$url.static('/static/images/shibai.png')" />
  46. </view>
  47. <view v-else class="icon">
  48. <image :src="sheep.$url.static('/static/images/chenggong.png')" />
  49. </view>
  50. </template>
  51. </uni-easyinput>
  52. </uni-forms-item>
  53. <uni-forms-item name="mobile" :label="t('account.phone_number')" class="mobile loginUniFormItem ss-p-t-10" :error-message="state.mobileErrorMsg">
  54. <phoneInternationalInput :verify-username="state.verifyUsername" @input="mobileInput"/>
  55. </uni-forms-item>
  56. <uni-forms-item name="code" :label="t('account.verification_code')" class="loginUniFormItem">
  57. <uni-easyinput :placeholder="t('account.enter_verification_code')" v-model="state.model.code" :inputBorder="false" type="number"
  58. maxlength="4">
  59. </uni-easyinput>
  60. </uni-forms-item>
  61. </uni-forms>
  62. <view
  63. style="display: flex;justify-content: space-between;padding: 40rpx;padding-bottom: 0rpx;padding-bottom: 40rpx">
  64. <button class="ss-reset-button login-btn-start" @tap="officialRegister"> {{ t('account.register') }} </button>
  65. </view>
  66. </view>
  67. </su-popup>
  68. </template>
  69. <script setup>
  70. import {
  71. ref,
  72. reactive,
  73. unref,
  74. computed,
  75. onBeforeMount
  76. } from 'vue';
  77. import sheep from '@/sheep';
  78. import {
  79. onLoad
  80. } from '@dcloudio/uni-app';
  81. import {
  82. showAuthModal,
  83. closeAuthModal,
  84. getSmsCode,
  85. getSmsTimer
  86. } from '@/sheep/hooks/useModal';
  87. import {
  88. code,
  89. mobile
  90. } from '@/sheep/validate/form';
  91. import AuthUtil from '@/sheep/api/member/auth';
  92. import phoneInternationalInput from '@/sheep/components/s-auth-modal/components/phone-international-input.vue';
  93. import { t } from '@/locale'
  94. const mobileInput = (mobile,mobileError)=>{
  95. state.model.mobile = mobile;
  96. state.mobileErrorMsg = mobileError;
  97. }
  98. // 数据
  99. const state = reactive({
  100. verifyUsername: false,
  101. usernameErrorMsg:'',
  102. mobileErrorMsg:'',
  103. openid: '',
  104. socialUsers: [],
  105. registerReqVO: {
  106. type: 31,
  107. code: "",
  108. state: "",
  109. username: "",
  110. },
  111. isMobileEnd: false, // 手机号输入完毕
  112. codeText: '获取验证码',
  113. model: {
  114. mobile: '', // 手机号
  115. code: '', // 验证码
  116. scene: 1
  117. },
  118. rules: {
  119. code,
  120. mobile,
  121. },
  122. });
  123. const isPopup = ref(false);
  124. const selectSocialUsers = ref(false);
  125. // 定义修改状态的方法
  126. function updateIsPopup() {
  127. isPopup.value = true;
  128. }
  129. // 打开用户的选择列表,如果有账户并且多个的话
  130. function updateSocialUsers(openid, socialUsers) {
  131. selectSocialUsers.value = true;
  132. state.openid = openid;
  133. state.socialUsers = socialUsers;
  134. console.log("updateSocialUsers条用了,这时state.socialUsers是", state.socialUsers)
  135. }
  136. // 选登录的用户
  137. async function selectUser(username) {
  138. console.log(username)
  139. // 提交数据
  140. const {
  141. code
  142. } = await AuthUtil.selectUsernameLogin({
  143. openId: state.openid,
  144. username
  145. });
  146. if (code === 0) {
  147. // closeAuthModal();
  148. // 检测 H5 登录回调
  149. let returnUrl = uni.getStorageSync('returnUrl');
  150. if (returnUrl) {
  151. uni.removeStorage('returnUrl');
  152. location.replace(returnUrl);
  153. } else {
  154. uni.switchTab({
  155. url: '/',
  156. });
  157. }
  158. }
  159. }
  160. let lastUsername = ref('')
  161. async function verifyUsername(e) {
  162. const username = e.detail.value;
  163. if (username == '' || username == lastUsername.value) {
  164. // 为空或者没改东西,不调校验
  165. return false;
  166. }
  167. lastUsername.value = username
  168. // 提交数据
  169. const {
  170. data
  171. } = await AuthUtil.verifyUsername(username);
  172. // false就是已经有这个用户名,不可以用。true是没有,可以改
  173. console.log(data)
  174. if(data){
  175. state.usernameErrorMsg = ''
  176. state.verifyUsername = data
  177. }else {
  178. state.usernameErrorMsg = t('account.username_exists')
  179. state.verifyUsername = data
  180. }
  181. }
  182. // 直接点微信注册,或者点微信登录,但没账号的都提示注册
  183. async function officialRegister() {
  184. // 没有linkId 不给注册
  185. const linkId = uni.getStorageSync("linkId");
  186. // if (!linkId) {
  187. // sheep.$helper.toast(t('account.register_by_sharing_only'));
  188. // return false;
  189. // }
  190. state.registerReqVO.linkId = linkId
  191. const {
  192. code
  193. } = await AuthUtil.OfficialEnterLogin(state.model, state.registerReqVO);
  194. // 提交数据
  195. if (code === 0) {
  196. closeAuthModal();
  197. // 检测 H5 登录回调
  198. let returnUrl = uni.getStorageSync('returnUrl');
  199. if (returnUrl) {
  200. uni.removeStorage('returnUrl');
  201. location.replace(returnUrl);
  202. } else {
  203. uni.switchTab({
  204. url: '/',
  205. });
  206. }
  207. }
  208. }
  209. onBeforeMount(async () => {
  210. const options = {}
  211. new URLSearchParams(location.search).forEach((value, key) => {
  212. options[key] = value;
  213. });
  214. state.registerReqVO.code = options.code
  215. state.registerReqVO.state = options.state
  216. })
  217. onLoad(async (options) => {
  218. // #ifdef H5
  219. // 将 search 参数赋值到 options 中,方便下面解析
  220. new URLSearchParams(location.search).forEach((value, key) => {
  221. options[key] = value;
  222. });
  223. const event = options.event;
  224. const code = options.code;
  225. const state = options.state;
  226. if (event === 'login') { // 场景一:登录
  227. const res = await sheep.$platform.useProvider().login(code, state)
  228. console.log("login.vue的res", res)
  229. if (!res) {
  230. uni.showModal({
  231. title: t('setting.prompt'),
  232. content: t('account.wechat_no_account'),
  233. confirmColor: '#0e932e', //确定字体颜色
  234. showCancel: false, //没有取消按钮的弹框
  235. buttonText: t('common.confirm'),
  236. success: function(res) {
  237. if (res.confirm) {
  238. sheep.$router.go('/pages/index/index')
  239. }
  240. }
  241. });
  242. return false
  243. }
  244. if (res.data.socialUsers != null) {
  245. updateSocialUsers(res.data.openid, res.data.socialUsers)
  246. return false
  247. }
  248. } else if (event === 'register') {
  249. const res = await sheep.$platform.useProvider().register(code, state)
  250. updateIsPopup()
  251. return false
  252. } else if (event === 'bind') { // 场景二:绑定
  253. await sheep.$platform.useProvider().bind(code, state);
  254. }
  255. // 检测 H5 登录回调
  256. let returnUrl = uni.getStorageSync('returnUrl');
  257. if (returnUrl) {
  258. uni.removeStorage('returnUrl');
  259. location.replace(returnUrl);
  260. } else {
  261. uni.switchTab({
  262. url: '/',
  263. });
  264. }
  265. // #endif
  266. });
  267. </script>
  268. <style lang="scss" scoped>
  269. .icon {
  270. display: flex;
  271. align-items: center;
  272. margin-right: 7rpx
  273. }
  274. .icon image {
  275. width: 35rpx;
  276. height: 35rpx;
  277. }
  278. @keyframes title-animation {
  279. 0% {
  280. font-size: 32rpx;
  281. }
  282. 100% {
  283. font-size: 36rpx;
  284. }
  285. }
  286. .login-wrap {
  287. padding: 50rpx 34rpx;
  288. min-height: 500rpx;
  289. background-color: #fff;
  290. border-radius: 20rpx 20rpx 0 0;
  291. }
  292. .head-box {
  293. padding: 40rpx 40rpx 0;
  294. .head-title {
  295. min-width: 160rpx;
  296. font-size: 36rpx;
  297. font-weight: bold;
  298. color: #333333;
  299. line-height: 36rpx;
  300. }
  301. .head-title-active {
  302. width: 160rpx;
  303. font-size: 32rpx;
  304. font-weight: 600;
  305. color: #999;
  306. line-height: 36rpx;
  307. }
  308. .head-title-animation {
  309. animation-name: title-animation;
  310. animation-duration: 0.1s;
  311. animation-timing-function: ease-out;
  312. animation-fill-mode: forwards;
  313. }
  314. .head-title-line {
  315. position: relative;
  316. &::before {
  317. content: '';
  318. width: 1rpx;
  319. height: 34rpx;
  320. background-color: #e4e7ed;
  321. position: absolute;
  322. left: -30rpx;
  323. top: 50%;
  324. transform: translateY(-50%);
  325. }
  326. }
  327. .head-subtitle {
  328. font-size: 26rpx;
  329. font-weight: 400;
  330. color: #afb6c0;
  331. text-align: left;
  332. display: flex;
  333. }
  334. }
  335. // .code-btn[disabled] {
  336. // background-color: #fff;
  337. // }
  338. .code-btn-start {
  339. width: 160rpx;
  340. height: 56rpx;
  341. line-height: normal;
  342. border: 2rpx solid var(--ui-BG-Main);
  343. border-radius: 28rpx;
  344. font-size: 26rpx;
  345. font-weight: 400;
  346. color: var(--ui-BG-Main);
  347. opacity: 1;
  348. }
  349. .forgot-btn {
  350. width: 160rpx;
  351. line-height: 56rpx;
  352. font-size: 30rpx;
  353. font-weight: 500;
  354. color: #999;
  355. }
  356. .login-btn-start {
  357. width: 158rpx;
  358. height: 56rpx;
  359. line-height: normal;
  360. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  361. border-radius: 28rpx;
  362. font-size: 26rpx;
  363. font-weight: 500;
  364. color: #fff;
  365. }
  366. .type-btn {
  367. padding: 20rpx;
  368. margin: 40rpx auto;
  369. width: 200rpx;
  370. font-size: 30rpx;
  371. font-weight: 500;
  372. color: #999999;
  373. }
  374. .auto-login-box {
  375. width: 100%;
  376. .auto-login-btn {
  377. width: 68rpx;
  378. height: 68rpx;
  379. border-radius: 50%;
  380. margin: 0 30rpx;
  381. }
  382. .auto-login-img {
  383. width: 68rpx;
  384. height: 68rpx;
  385. border-radius: 50%;
  386. }
  387. }
  388. .agreement-box {
  389. margin: 80rpx auto 0;
  390. .protocol-check {
  391. transform: scale(0.7);
  392. }
  393. .agreement-text {
  394. font-size: 26rpx;
  395. font-weight: 500;
  396. color: #999999;
  397. .tcp-text {
  398. color: var(--ui-BG-Main);
  399. }
  400. }
  401. }
  402. // 修改密码
  403. .editPwd-btn-box {
  404. .save-btn {
  405. width: 690rpx;
  406. line-height: 70rpx;
  407. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  408. border-radius: 35rpx;
  409. font-size: 28rpx;
  410. font-weight: 500;
  411. color: #ffffff;
  412. }
  413. .forgot-btn {
  414. width: 690rpx;
  415. line-height: 70rpx;
  416. font-size: 28rpx;
  417. font-weight: 500;
  418. color: #999999;
  419. }
  420. }
  421. .code-btn-start {
  422. color: #55b774;
  423. border: 1px solid #55b774;
  424. }
  425. .disabled {
  426. border: 1px solid #f7f7f7;
  427. }
  428. .agreement-box {
  429. margin: 20rpx 0;
  430. }
  431. .login-btn-start {
  432. background: rgb(14, 147, 46);
  433. width: 100%;
  434. height: 80rpx;
  435. font-size: 32rpx;
  436. }
  437. .loginUniForm {
  438. margin: 40rpx;
  439. border: 1rpx solid #d6d6d6;
  440. padding: 10rpx 15rpx;
  441. border-radius: 10rpx;
  442. }
  443. .loginUniFormItem {
  444. border-bottom: 1rpx solid #d6d6d6;
  445. padding-bottom: 10rpx;
  446. }
  447. .loginUniFormItem:last-child {
  448. border-bottom: none;
  449. padding-top: 10rpx;
  450. }
  451. ::v-deep .loginUniFormItem .uni-forms-item__inner {
  452. padding-bottom: 0;
  453. }
  454. ::v-deep .loginUniFormItem .uni-error-message {
  455. bottom: -20rpx;
  456. }
  457. </style>