index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  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. goDetail("https://www.shuibeibyg.com/shenhe.html")
  148. }
  149. const goDetail = (url) => {
  150. const webviewPageUrl = `/pages/webview/privacy?path=${url}`;
  151. uni.navigateTo({
  152. url: webviewPageUrl,
  153. fail: (err) => {
  154. console.error("跳转到webview页面失败:", err);
  155. uni.showToast({
  156. title: "跳转失败,请重试",
  157. icon: "none",
  158. duration: 1500,
  159. });
  160. },
  161. });
  162. };
  163. // Get logo image
  164. const getLogoImage = async () => {
  165. try {
  166. const res = await getLogo();
  167. logoUrl.value = res.data.logoUrl || "/static/images/logo2.png";
  168. } catch (err) {
  169. console.error(err);
  170. }
  171. };
  172. // 验证码登录
  173. const loginMobile = async () => {
  174. if (!account.value)
  175. return uni.showToast({
  176. title: "请填写手机号码",
  177. icon: "none"
  178. });
  179. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  180. return uni.showToast({
  181. title: "请输入正确的手机号码",
  182. icon: "none"
  183. });
  184. if (!captcha.value)
  185. return uni.showToast({
  186. title: "请填写验证码",
  187. icon: "none"
  188. });
  189. if (!/^[\w\d]+$/i.test(captcha.value))
  190. return uni.showToast({
  191. title: "请输入正确的验证码",
  192. icon: "none"
  193. });
  194. if (!aloneChecked.value) {
  195. return Toast({
  196. title: "请阅读并同意用户协议和隐私政策",
  197. icon: "none"
  198. });
  199. }
  200. try {
  201. const res = await loginMobileApi({
  202. phone: account.value,
  203. captcha: captcha.value,
  204. platformType: "app",
  205. spread_spid: Cache.get("spread"),
  206. inviteCode: inviteCode.value,
  207. });
  208. // 使用 LOGIN action 保存 token 到缓存
  209. appStore.LOGIN({
  210. token: res.data.token
  211. });
  212. // 保存过期时间(999天后过期)
  213. const expiresTime = Math.round(new Date() / 1000) + 999 * 24 * 60 * 60;
  214. Cache.set(EXPIRES_TIME, expiresTime, 0);
  215. await getUserInfoFn(res.data);
  216. } catch (res) {
  217. const message = typeof res === "object" ? res.message : res;
  218. uni.showToast({
  219. title: message,
  220. icon: "none"
  221. });
  222. }
  223. };
  224. // 注册
  225. const registerFn = async () => {
  226. if (!account.value)
  227. return uni.showToast({
  228. title: "请填写手机号码",
  229. icon: "none"
  230. });
  231. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  232. return uni.showToast({
  233. title: "请输入正确的手机号码",
  234. icon: "none"
  235. });
  236. if (!captcha.value)
  237. return uni.showToast({
  238. title: "请填写验证码",
  239. icon: "none"
  240. });
  241. if (!/^[\w\d]+$/i.test(captcha.value))
  242. return uni.showToast({
  243. title: "请输入正确的验证码",
  244. icon: "none"
  245. });
  246. if (!password.value)
  247. return uni.showToast({
  248. title: "请填写密码",
  249. icon: "none"
  250. });
  251. // 正则1:验证长度6-18位
  252. const lengthReg = /^.{6,18}$/;
  253. // 正则2:必须包含至少1个数字(\d)和至少1个字母(a-zA-Z)
  254. const hasNumAndLetterReg = /(?=.*\d)(?=.*[a-zA-Z])/;
  255. if (!lengthReg.test(password.value)) {
  256. return uni.showToast({
  257. title: "密码长度必须为6-18位",
  258. icon: "none"
  259. });
  260. } else if (!hasNumAndLetterReg.test(password.value)) {
  261. return uni.showToast({
  262. title: "密码必须同时包含数字和字母",
  263. icon: "none"
  264. });
  265. }
  266. try {
  267. const res = await register({
  268. account: account.value,
  269. captcha: captcha.value,
  270. password: password.value,
  271. spread: Cache.get("spread"),
  272. });
  273. uni.showToast({
  274. title: res.message,
  275. icon: "none"
  276. });
  277. formItem.value = 1;
  278. } catch (res) {
  279. uni.showToast({
  280. title: res.message,
  281. icon: "none"
  282. });
  283. }
  284. };
  285. // 发送验证码
  286. const code = async () => {
  287. if (!account.value)
  288. return uni.showToast({
  289. title: "请填写手机号码",
  290. icon: "none"
  291. });
  292. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(account.value))
  293. return uni.showToast({
  294. title: "请输入正确的手机号码",
  295. icon: "none"
  296. });
  297. if (formItem.value === 2) type.value = "register";
  298. try {
  299. const res = await registerVerify(account.value);
  300. uni.showToast({
  301. title: res.message,
  302. icon: "none"
  303. });
  304. sendCode();
  305. } catch (err) {
  306. uni.showToast({
  307. title: err.message,
  308. icon: "none"
  309. });
  310. }
  311. };
  312. // Navigation tab switch
  313. const navTap = (index) => {
  314. current.value = index;
  315. };
  316. // 账号密码登录
  317. const submit = async () => {
  318. if (!account.value) return Toast({
  319. title: "请填写账号",
  320. icon: "none"
  321. });
  322. if (!/^[\w\d]{5,16}$/i.test(account.value))
  323. return Toast({
  324. title: "请输入正确的账号",
  325. icon: "none"
  326. });
  327. if (!password.value) return Toast({
  328. title: "请填写密码",
  329. icon: "none"
  330. });
  331. if (!aloneChecked.value) {
  332. return Toast({
  333. title: "请阅读并同意用户协议和隐私政策",
  334. icon: "none"
  335. });
  336. }
  337. try {
  338. const {
  339. data
  340. } = await loginH5({
  341. account: account.value,
  342. password: password.value,
  343. platformType: "app",
  344. spread: Cache.get("spread"),
  345. });
  346. appStore.LOGIN({
  347. token: data.token
  348. });
  349. // 保存过期时间(999天后过期)
  350. const expiresTime = Math.round(new Date() / 1000) + 999 * 24 * 60 * 60;
  351. Cache.set(EXPIRES_TIME, expiresTime, 0);
  352. await getUserInfoFn(data);
  353. } catch (err) {
  354. const message = typeof err === "object" ? err.message : err;
  355. uni.showToast({
  356. title: message,
  357. icon: "none",
  358. });
  359. }
  360. };
  361. // 订阅已加入的群组
  362. // function getGroupchatListFn(uid) {
  363. // getGroupchatList({
  364. // userId: uid
  365. // }).then((res) => {
  366. // if (res && res.data && res.data.length > 0) {
  367. // //订阅群消息
  368. // var groupIds = res.data;
  369. // GoEasy.im.subscribeGroup({
  370. // groupIds: groupIds,
  371. // onSuccess: function() {
  372. // //订阅成功
  373. // console.log("Group message subscribe successfully.");
  374. // },
  375. // onFailed: function(error) {
  376. // //订阅失败
  377. // console.log(
  378. // "Failed to subscribe group message, code:" +
  379. // error.code +
  380. // " content:" +
  381. // error.content
  382. // );
  383. // },
  384. // });
  385. // }
  386. // });
  387. // }
  388. const getUserInfoFn = async (data) => {
  389. try {
  390. appStore.SETUID(data.uid);
  391. const res = await getUserInfo();
  392. appStore.UPDATE_USERINFO(res.data);
  393. userInfo.value = res.data;
  394. // connect({
  395. // id: appStore.uid?.toString(),
  396. // data: {
  397. // avatar: appStore.$userInfo?.avatar,
  398. // nickname: appStore.$userInfo?.nickname,
  399. // phone: appStore.$userInfo?.phone,
  400. // uid: appStore.uid?.toString(),
  401. // },
  402. // });
  403. // 订阅已加入的群组
  404. // await getGroupchatListFn(data.uid);
  405. if(merchantId.value != ''){
  406. let obj ={
  407. merchantId:merchantId.value,
  408. userId:res.data.userId
  409. }
  410. await footprintScanFn(obj)
  411. }else{
  412. console.log('============')
  413. appStore.UPDATE_MERCHANT_ID('')
  414. Toast({ title: "登录成功" });
  415. backHome();
  416. }
  417. } catch (err) {
  418. console.error(err);
  419. uni.showToast({
  420. title: err.msg,
  421. icon: "none"
  422. });
  423. }
  424. };
  425. const backHome = () => {
  426. if(userInfo.value.merchant && userInfo.value.merchant.id){
  427. uni.navigateTo({
  428. url:"/pages/merchantCenter/index"
  429. })
  430. }else{
  431. uni.switchTab({
  432. url: "/pages/index/index",
  433. });
  434. }
  435. };
  436. const footprintScanFn =async (data) => {
  437. const res = await footprintScan(data);
  438. Toast({ title: "登录成功" });
  439. backHome();
  440. }
  441. onLoad(() => {
  442. console.log(appStore.$wxConfig)
  443. merchantId.value = appStore.merchantId || '';
  444. getLogoImage();
  445. });
  446. onMounted(() => {
  447. uni.getSystemInfo({
  448. success(res) {
  449. platform.value = res.platform.toLowerCase();
  450. if (platform.value === "ios" && res.system.split(" ")[1] >= 13) {
  451. appleShow.value = true;
  452. }
  453. },
  454. });
  455. });
  456. </script>
  457. <style lang="scss" scoped>
  458. ::v-deep .u-status-bar {
  459. background: transparent;
  460. background-color: transparent !important;
  461. }
  462. ::v-deep .u-navbar__content {
  463. background: transparent;
  464. background-color: transparent !important;
  465. }
  466. .login-wrapper {
  467. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/login@2x.png');
  468. background-repeat: no-repeat;
  469. background-size: 100% 624rpx;
  470. background-color: #FFFFFF;
  471. }
  472. .appLogin {
  473. .hds {
  474. display: flex;
  475. justify-content: center;
  476. align-items: center;
  477. font-size: 24rpx;
  478. color: #b4b4b4;
  479. .line {
  480. width: 68rpx;
  481. height: 1rpx;
  482. background: #cccccc;
  483. }
  484. p {
  485. margin: 0 20rpx;
  486. }
  487. }
  488. .btn-wrapper {
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. margin-top: 30rpx;
  493. .btn {
  494. display: flex;
  495. align-items: center;
  496. justify-content: center;
  497. width: 68rpx;
  498. height: 68rpx;
  499. border-radius: 50%;
  500. }
  501. .apple-btn {
  502. display: flex;
  503. align-items: center;
  504. justify-content: center;
  505. margin-left: 30rpx;
  506. background: #000;
  507. border-radius: 34rpx;
  508. font-size: 40rpx;
  509. .icon-s-pingguo {
  510. color: #fff;
  511. font-size: 40rpx;
  512. }
  513. }
  514. .iconfont {
  515. font-size: 40rpx;
  516. color: #fff;
  517. }
  518. .wx {
  519. margin-right: 30rpx;
  520. background-color: #61c64f;
  521. }
  522. .mima {
  523. background-color: #28b3e9;
  524. }
  525. .yanzheng {
  526. background-color: #f89c23;
  527. }
  528. }
  529. }
  530. .code img {
  531. width: 100%;
  532. height: 100%;
  533. }
  534. .acea-row.row-middle {
  535. input {
  536. margin-left: 20rpx;
  537. display: block;
  538. }
  539. }
  540. .login-wrapper {
  541. .shading {
  542. padding: 72rpx 78rpx;
  543. display: flex;
  544. justify-content: center;
  545. flex-direction: column;
  546. view {
  547. color: #333333;
  548. font-size: 36rpx;
  549. font-weight: bold;
  550. &:first-child {
  551. font-size: 48rpx;
  552. margin-bottom: 16rpx;
  553. }
  554. }
  555. }
  556. .whiteBg {
  557. margin-top: 100rpx;
  558. background: #FFFFFF;
  559. border-radius: 48rpx 48rpx 0rpx 0rpx;
  560. .whiteBg-tab {
  561. color: #666666;
  562. display: flex;
  563. align-items: center;
  564. height: 88rpx;
  565. text-align: center;
  566. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/logintab1.png');
  567. background-repeat: no-repeat;
  568. background-size: cover;
  569. .active {
  570. width: 407rpx;
  571. view {
  572. color: #F8C008;
  573. font-weight: bold;
  574. position: relative;
  575. &::after {
  576. left: 50%;
  577. bottom: -12rpx;
  578. content: '';
  579. transform: translateX(-50%);
  580. position: absolute;
  581. width: 32rpx;
  582. height: 8rpx;
  583. background: #F8C008;
  584. border-radius: 4rpx;
  585. }
  586. }
  587. }
  588. .noActive {
  589. flex: 1;
  590. }
  591. }
  592. .whiteBg-tabs {
  593. //background: url('https://sb-admin.oss-cn-shenzhen.aliyuncs.com/shuibei-mini/new-mini/logintab.png');
  594. background-repeat: no-repeat;
  595. background-size: cover;
  596. }
  597. .list {
  598. padding: 0 80rpx;
  599. margin-top: 120rpx;
  600. .item {
  601. display: flex;
  602. height: 88rpx;
  603. align-items: center;
  604. justify-content: space-between;
  605. padding: 0 8rpx 0 24rpx;
  606. background: #F9F7F0;
  607. border-radius: 16rpx;
  608. margin-bottom: 32rpx;
  609. .texts {
  610. flex: 1;
  611. font-size: 28rpx;
  612. }
  613. .code {
  614. padding: 0;
  615. margin: 0;
  616. width: 188rpx;
  617. display: flex;
  618. align-items: center;
  619. height: 72rpx;
  620. justify-content: center;
  621. background: #FFFFFF;
  622. border-radius: 16rpx;
  623. color: #F8C008;
  624. font-size: 28rpx;
  625. font-weight: bold;
  626. border: none;
  627. &::after {
  628. width: 0;
  629. border: none;
  630. }
  631. }
  632. }
  633. }
  634. .logon {
  635. display: flex;
  636. align-items: center;
  637. justify-content: center;
  638. height: 88rpx;
  639. background-color: #F8C008;
  640. border-radius: 16rpx;
  641. color: #333333;
  642. font-size: 32rpx;
  643. font-weight: bold;
  644. }
  645. }
  646. .privacy-box {
  647. font-size: 24rpx;
  648. padding: 0 80rpx;
  649. display: flex;
  650. align-items: center;
  651. image {
  652. width: 28rpx;
  653. height: 28rpx;
  654. margin-right: 8rpx;
  655. }
  656. .privacy-text {
  657. color: #F8C008;
  658. vertical-align: top;
  659. }
  660. }
  661. }
  662. .footer {
  663. padding: 48rpx 80rpx;
  664. }
  665. .back_extend {
  666. //position: fixed;
  667. //top: 50px;
  668. //left: 10px;
  669. //font-size: 26rpx;
  670. //color: #999;
  671. }
  672. </style>