index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <div class="login-wrapper bglogin">
  3. <up-navbar title="登录" placeholder>
  4. <template #left>
  5. <!-- <view-->
  6. <!-- v-if="appStore?.$wxConfig?.auditModeEnabled"-->
  7. <!-- @click="backHome"-->
  8. <!-- >-->
  9. <!-- <image src="@/static/images/tabbar/1-001.png" style="height: 40rpx;width: 40rpx;"></image>-->
  10. <!-- </view>-->
  11. <view
  12. class="back_extend"
  13. v-if="appStore?.$wxConfig?.auditModeEnabled"
  14. @click="backHome"
  15. >
  16. {{ "<" }} 回到首页
  17. </view>
  18. </template>
  19. </up-navbar>
  20. <div class="shading">
  21. <view class="">Hello!</view>
  22. <view class="">欢迎来到水贝搬运工</view>
  23. </div>
  24. <div class="whiteBg" v-if="formItem === 1">
  25. <view class="whiteBg-tab whiteBg-tabimg" :class="{'whiteBg-tabs whiteBg-tabsimg':current == 1}">
  26. <view @click="current = item.type" :class="{active:current != index,noActive:current == index}" class="whiteBg-tab-li" v-for="(item,index) in navList" :key="index">
  27. <view class="">{{ item.name }}</view>
  28. </view>
  29. </view>
  30. <div class="list">
  31. <div class="item">
  32. <input type="text" maxlength="11" class="texts" placeholder="输入手机号码" v-model="account" required />
  33. </div>
  34. <template v-if="current == 0">
  35. <div class="item">
  36. <input type="password" class="texts" placeholder="填写登录密码" v-model="password" required />
  37. </div>
  38. </template>
  39. <template v-else-if="current == 1">
  40. <div class="item">
  41. <input type="number" placeholder="填写验证码" class="texts" v-model="captcha" maxlength="6" />
  42. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  43. {{ text }}
  44. </button>
  45. </div>
  46. <div class="item">
  47. <input type="text" class="texts" placeholder="输入邀请码(非必填)" v-model="inviteCode" />
  48. </div>
  49. </template>
  50. </div>
  51. <div class="privacy-box" @click="aloneChecked = !aloneChecked">
  52. <image v-if="aloneChecked" src="/static/images/select-active@2x.png" mode=""></image>
  53. <image v-else src="/static/images/select@2x.png" mode=""></image>
  54. <view class="">我已阅读并同意</view>
  55. <view class="privacy-text" @click.stop="openPrivacy">《用户协议》</view>
  56. <view class="privacy-text" @click.stop="openPrivacy">《隐私政策》</view>
  57. </div>
  58. <view class="footer">
  59. <div class="logon" @click="loginMobile" v-if="current !== 0">登录</div>
  60. <div class="logon" @click="submit" v-if="current === 0">登录</div>
  61. </view>
  62. </div>
  63. </div>
  64. </template>
  65. <script setup>
  66. import {
  67. ref,
  68. watch,
  69. onMounted
  70. } from "vue";
  71. import {
  72. onLoad
  73. } from "@dcloudio/uni-app";
  74. import {
  75. useAppStore
  76. } from "@/stores/app";
  77. import {
  78. loginH5,
  79. loginMobile as loginMobileApi,
  80. registerVerify,
  81. register,
  82. getUserInfo,
  83. } from "@/api/user";
  84. import {
  85. getLogo,
  86. appAuth,
  87. appleLogin
  88. } from "@/api/public";
  89. import {
  90. VUE_APP_API_URL
  91. } from "@/utils";
  92. import {
  93. useSendCode
  94. } from "@/hooks/useSendCode";
  95. import Cache from "@/utils/cache";
  96. import {
  97. useToast
  98. } from "@/hooks/useToast.js";
  99. // import {
  100. // useGoEasy
  101. // } from "@/plugin/goeasy";
  102. // import {
  103. // getGroupchatList
  104. // } from "@/api/customerService";
  105. import { footprintScan } from "@/api/merchant.js";
  106. import {
  107. EXPIRES_TIME
  108. } from "@/config/cache";
  109. const appStore = useAppStore();
  110. const {
  111. Toast
  112. } = useToast();
  113. // const {
  114. // connect,
  115. // GoEasy
  116. // } = useGoEasy();
  117. const BACK_URL = "login_back_url";
  118. // Reactive state
  119. const navList = ref([{name:"快速登录",type:1}, {name:"账号登录",type:0}]);
  120. const current = ref(1);
  121. const account = ref("");
  122. const inviteCode = ref(""); // 邀请码
  123. const password = ref("");
  124. const captcha = ref("");
  125. const formItem = ref(1);
  126. const type = ref("login");
  127. const logoUrl = ref("");
  128. const keyCode = ref("");
  129. const codeUrl = ref("");
  130. const codeVal = ref("");
  131. const platform = ref("");
  132. const appleShow = ref(false);
  133. const aloneChecked = ref(false);
  134. const merchantId = ref('');
  135. const userInfo = ref({});
  136. // Watch formItem to update type
  137. watch(formItem, (newVal) => {
  138. type.value = newVal === 1 ? "login" : "register";
  139. });
  140. const {
  141. disabled,
  142. text,
  143. sendCode
  144. } = useSendCode();
  145. function openPrivacy() {
  146. void plus.runtime.openWeb("https://www.shuibeibyg.com/shenhe.html");
  147. }
  148. // Get logo image
  149. const getLogoImage = async () => {
  150. try {
  151. const res = await getLogo();
  152. logoUrl.value = res.data.logoUrl || "/static/images/logo2.png";
  153. } catch (err) {
  154. console.error(err);
  155. }
  156. };
  157. // 验证码登录
  158. const loginMobile = async () => {
  159. if (!account.value)
  160. return uni.showToast({
  161. title: "请填写手机号码",
  162. icon: "none"
  163. });
  164. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  165. return uni.showToast({
  166. title: "请输入正确的手机号码",
  167. icon: "none"
  168. });
  169. if (!captcha.value)
  170. return uni.showToast({
  171. title: "请填写验证码",
  172. icon: "none"
  173. });
  174. if (!/^[\w\d]+$/i.test(captcha.value))
  175. return uni.showToast({
  176. title: "请输入正确的验证码",
  177. icon: "none"
  178. });
  179. if (!aloneChecked.value) {
  180. return Toast({
  181. title: "请阅读并同意用户协议和隐私政策",
  182. icon: "none"
  183. });
  184. }
  185. try {
  186. const res = await loginMobileApi({
  187. phone: account.value,
  188. captcha: captcha.value,
  189. platformType: "app",
  190. spread_spid: Cache.get("spread"),
  191. inviteCode: inviteCode.value,
  192. });
  193. // 使用 LOGIN action 保存 token 到缓存
  194. appStore.LOGIN({
  195. token: res.data.token
  196. });
  197. // 保存过期时间(999天后过期)
  198. const expiresTime = Math.round(new Date() / 1000) + 999 * 24 * 60 * 60;
  199. Cache.set(EXPIRES_TIME, expiresTime, 0);
  200. await getUserInfoFn(res.data);
  201. } catch (res) {
  202. const message = typeof res === "object" ? res.message : res;
  203. uni.showToast({
  204. title: message,
  205. icon: "none"
  206. });
  207. }
  208. };
  209. // 注册
  210. const registerFn = async () => {
  211. if (!account.value)
  212. return uni.showToast({
  213. title: "请填写手机号码",
  214. icon: "none"
  215. });
  216. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  217. return uni.showToast({
  218. title: "请输入正确的手机号码",
  219. icon: "none"
  220. });
  221. if (!captcha.value)
  222. return uni.showToast({
  223. title: "请填写验证码",
  224. icon: "none"
  225. });
  226. if (!/^[\w\d]+$/i.test(captcha.value))
  227. return uni.showToast({
  228. title: "请输入正确的验证码",
  229. icon: "none"
  230. });
  231. if (!password.value)
  232. return uni.showToast({
  233. title: "请填写密码",
  234. icon: "none"
  235. });
  236. // 正则1:验证长度6-18位
  237. const lengthReg = /^.{6,18}$/;
  238. // 正则2:必须包含至少1个数字(\d)和至少1个字母(a-zA-Z)
  239. const hasNumAndLetterReg = /(?=.*\d)(?=.*[a-zA-Z])/;
  240. if (!lengthReg.test(password.value)) {
  241. return uni.showToast({
  242. title: "密码长度必须为6-18位",
  243. icon: "none"
  244. });
  245. } else if (!hasNumAndLetterReg.test(password.value)) {
  246. return uni.showToast({
  247. title: "密码必须同时包含数字和字母",
  248. icon: "none"
  249. });
  250. }
  251. try {
  252. const res = await register({
  253. account: account.value,
  254. captcha: captcha.value,
  255. password: password.value,
  256. spread: Cache.get("spread"),
  257. });
  258. uni.showToast({
  259. title: res.message,
  260. icon: "none"
  261. });
  262. formItem.value = 1;
  263. } catch (res) {
  264. uni.showToast({
  265. title: res.message,
  266. icon: "none"
  267. });
  268. }
  269. };
  270. // 发送验证码
  271. const code = async () => {
  272. if (!account.value)
  273. return uni.showToast({
  274. title: "请填写手机号码",
  275. icon: "none"
  276. });
  277. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  278. return uni.showToast({
  279. title: "请输入正确的手机号码",
  280. icon: "none"
  281. });
  282. if (formItem.value === 2) type.value = "register";
  283. try {
  284. const res = await registerVerify(account.value);
  285. uni.showToast({
  286. title: res.message,
  287. icon: "none"
  288. });
  289. sendCode();
  290. } catch (err) {
  291. uni.showToast({
  292. title: err.message,
  293. icon: "none"
  294. });
  295. }
  296. };
  297. // Navigation tab switch
  298. const navTap = (index) => {
  299. current.value = index;
  300. };
  301. // 账号密码登录
  302. const submit = async () => {
  303. if (!account.value) return Toast({
  304. title: "请填写账号",
  305. icon: "none"
  306. });
  307. if (!/^[\w\d]{5,16}$/i.test(account.value))
  308. return Toast({
  309. title: "请输入正确的账号",
  310. icon: "none"
  311. });
  312. if (!password.value) return Toast({
  313. title: "请填写密码",
  314. icon: "none"
  315. });
  316. if (!aloneChecked.value) {
  317. return Toast({
  318. title: "请阅读并同意用户协议和隐私政策",
  319. icon: "none"
  320. });
  321. }
  322. try {
  323. const {
  324. data
  325. } = await loginH5({
  326. account: account.value,
  327. password: password.value,
  328. platformType: "app",
  329. spread: Cache.get("spread"),
  330. });
  331. appStore.LOGIN({
  332. token: data.token
  333. });
  334. // 保存过期时间(999天后过期)
  335. const expiresTime = Math.round(new Date() / 1000) + 999 * 24 * 60 * 60;
  336. Cache.set(EXPIRES_TIME, expiresTime, 0);
  337. await getUserInfoFn(data);
  338. } catch (err) {
  339. const message = typeof err === "object" ? err.message : err;
  340. uni.showToast({
  341. title: message,
  342. icon: "none",
  343. });
  344. }
  345. };
  346. // 订阅已加入的群组
  347. // function getGroupchatListFn(uid) {
  348. // getGroupchatList({
  349. // userId: uid
  350. // }).then((res) => {
  351. // if (res && res.data && res.data.length > 0) {
  352. // //订阅群消息
  353. // var groupIds = res.data;
  354. // GoEasy.im.subscribeGroup({
  355. // groupIds: groupIds,
  356. // onSuccess: function() {
  357. // //订阅成功
  358. // console.log("Group message subscribe successfully.");
  359. // },
  360. // onFailed: function(error) {
  361. // //订阅失败
  362. // console.log(
  363. // "Failed to subscribe group message, code:" +
  364. // error.code +
  365. // " content:" +
  366. // error.content
  367. // );
  368. // },
  369. // });
  370. // }
  371. // });
  372. // }
  373. const getUserInfoFn = async (data) => {
  374. try {
  375. appStore.SETUID(data.uid);
  376. const res = await getUserInfo();
  377. appStore.UPDATE_USERINFO(res.data);
  378. userInfo.value = res.data;
  379. // connect({
  380. // id: appStore.uid?.toString(),
  381. // data: {
  382. // avatar: appStore.$userInfo?.avatar,
  383. // nickname: appStore.$userInfo?.nickname,
  384. // phone: appStore.$userInfo?.phone,
  385. // uid: appStore.uid?.toString(),
  386. // },
  387. // });
  388. // 订阅已加入的群组
  389. // await getGroupchatListFn(data.uid);
  390. if(merchantId.value != ''){
  391. let obj ={
  392. merchantId:merchantId.value,
  393. userId:res.data.userId
  394. }
  395. await footprintScanFn(obj)
  396. }else{
  397. console.log('============')
  398. appStore.UPDATE_MERCHANT_ID('')
  399. Toast({ title: "登录成功" });
  400. backHome();
  401. }
  402. } catch (err) {
  403. console.error(err);
  404. uni.showToast({
  405. title: err.msg,
  406. icon: "none"
  407. });
  408. }
  409. };
  410. const backHome = () => {
  411. if(userInfo.value.merchant && userInfo.value.merchant.id){
  412. uni.navigateTo({
  413. url:"/pages/merchantCenter/index"
  414. })
  415. }else{
  416. uni.switchTab({
  417. url: "/pages/index/index",
  418. });
  419. }
  420. };
  421. const footprintScanFn =async (data) => {
  422. const res = await footprintScan(data);
  423. Toast({ title: "登录成功" });
  424. backHome();
  425. }
  426. onLoad(() => {
  427. console.log(appStore.$wxConfig)
  428. merchantId.value = appStore.merchantId || '';
  429. getLogoImage();
  430. });
  431. onMounted(() => {
  432. uni.getSystemInfo({
  433. success(res) {
  434. platform.value = res.platform.toLowerCase();
  435. if (platform.value === "ios" && res.system.split(" ")[1] >= 13) {
  436. appleShow.value = true;
  437. }
  438. },
  439. });
  440. });
  441. </script>
  442. <style lang="scss" scoped>
  443. ::v-deep .u-status-bar {
  444. background: transparent;
  445. background-color: transparent !important;
  446. }
  447. ::v-deep .u-navbar__content {
  448. background: transparent;
  449. background-color: transparent !important;
  450. }
  451. .login-wrapper {
  452. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/login@2x.png');
  453. background-repeat: no-repeat;
  454. background-size: 100% 624rpx;
  455. background-color: #FFFFFF;
  456. }
  457. .appLogin {
  458. .hds {
  459. display: flex;
  460. justify-content: center;
  461. align-items: center;
  462. font-size: 24rpx;
  463. color: #b4b4b4;
  464. .line {
  465. width: 68rpx;
  466. height: 1rpx;
  467. background: #cccccc;
  468. }
  469. p {
  470. margin: 0 20rpx;
  471. }
  472. }
  473. .btn-wrapper {
  474. display: flex;
  475. align-items: center;
  476. justify-content: center;
  477. margin-top: 30rpx;
  478. .btn {
  479. display: flex;
  480. align-items: center;
  481. justify-content: center;
  482. width: 68rpx;
  483. height: 68rpx;
  484. border-radius: 50%;
  485. }
  486. .apple-btn {
  487. display: flex;
  488. align-items: center;
  489. justify-content: center;
  490. margin-left: 30rpx;
  491. background: #000;
  492. border-radius: 34rpx;
  493. font-size: 40rpx;
  494. .icon-s-pingguo {
  495. color: #fff;
  496. font-size: 40rpx;
  497. }
  498. }
  499. .iconfont {
  500. font-size: 40rpx;
  501. color: #fff;
  502. }
  503. .wx {
  504. margin-right: 30rpx;
  505. background-color: #61c64f;
  506. }
  507. .mima {
  508. background-color: #28b3e9;
  509. }
  510. .yanzheng {
  511. background-color: #f89c23;
  512. }
  513. }
  514. }
  515. .code img {
  516. width: 100%;
  517. height: 100%;
  518. }
  519. .acea-row.row-middle {
  520. input {
  521. margin-left: 20rpx;
  522. display: block;
  523. }
  524. }
  525. .login-wrapper {
  526. .shading {
  527. padding: 72rpx 78rpx;
  528. display: flex;
  529. justify-content: center;
  530. flex-direction: column;
  531. view {
  532. color: #333333;
  533. font-size: 36rpx;
  534. font-weight: bold;
  535. &:first-child {
  536. font-size: 48rpx;
  537. margin-bottom: 16rpx;
  538. }
  539. }
  540. }
  541. .whiteBg {
  542. margin-top: 100rpx;
  543. background: #FFFFFF;
  544. border-radius: 48rpx 48rpx 0rpx 0rpx;
  545. .whiteBg-tab {
  546. color: #666666;
  547. display: flex;
  548. align-items: center;
  549. height: 88rpx;
  550. text-align: center;
  551. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/logintab1.png');
  552. background-repeat: no-repeat;
  553. background-size: cover;
  554. .active {
  555. width: 407rpx;
  556. view {
  557. color: #F8C008;
  558. font-weight: bold;
  559. position: relative;
  560. &::after {
  561. left: 50%;
  562. bottom: -12rpx;
  563. content: '';
  564. transform: translateX(-50%);
  565. position: absolute;
  566. width: 32rpx;
  567. height: 8rpx;
  568. background: #F8C008;
  569. border-radius: 4rpx;
  570. }
  571. }
  572. }
  573. .noActive {
  574. flex: 1;
  575. }
  576. }
  577. .whiteBg-tabs {
  578. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/logintab.png');
  579. background-repeat: no-repeat;
  580. background-size: cover;
  581. }
  582. .list {
  583. padding: 0 80rpx;
  584. margin-top: 120rpx;
  585. .item {
  586. display: flex;
  587. height: 88rpx;
  588. align-items: center;
  589. justify-content: space-between;
  590. padding: 0 8rpx 0 24rpx;
  591. background: #F9F7F0;
  592. border-radius: 16rpx;
  593. margin-bottom: 32rpx;
  594. .texts {
  595. flex: 1;
  596. font-size: 28rpx;
  597. }
  598. .code {
  599. padding: 0;
  600. margin: 0;
  601. width: 188rpx;
  602. display: flex;
  603. align-items: center;
  604. height: 72rpx;
  605. justify-content: center;
  606. background: #FFFFFF;
  607. border-radius: 16rpx;
  608. color: #F8C008;
  609. font-size: 28rpx;
  610. font-weight: bold;
  611. border: none;
  612. &::after {
  613. width: 0;
  614. border: none;
  615. }
  616. }
  617. }
  618. }
  619. .logon {
  620. display: flex;
  621. align-items: center;
  622. justify-content: center;
  623. height: 88rpx;
  624. background-color: #F8C008;
  625. border-radius: 16rpx;
  626. color: #333333;
  627. font-size: 32rpx;
  628. font-weight: bold;
  629. }
  630. }
  631. .privacy-box {
  632. font-size: 24rpx;
  633. padding: 0 80rpx;
  634. display: flex;
  635. align-items: center;
  636. image {
  637. width: 28rpx;
  638. height: 28rpx;
  639. margin-right: 8rpx;
  640. }
  641. .privacy-text {
  642. color: #F8C008;
  643. vertical-align: top;
  644. }
  645. }
  646. }
  647. .footer {
  648. padding: 48rpx 80rpx;
  649. }
  650. .back_extend {
  651. //position: fixed;
  652. //top: 50px;
  653. //left: 10px;
  654. //font-size: 26rpx;
  655. //color: #999;
  656. }
  657. </style>