index.vue 17 KB

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