index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  1. <template>
  2. <view class="login-wrapper" :data-theme="theme">
  3. <view class="shading">
  4. <!-- <image :src="logoUrl"/> -->
  5. <image :src="logoUrl" />
  6. <!-- <image src="/static/images/logo2.png" v-if="!logoUrl" /> -->
  7. </view>
  8. <view class="whiteBg" v-if="formItem === 1">
  9. <view class="list" v-if="current !== 1">
  10. <form @submit.prevent="submit">
  11. <view class="item">
  12. <view class="acea-row row-middle">
  13. <text class="iconfont icon-phone_"></text>
  14. <input type="number" class="texts" placeholder="输入手机号码" v-model="phone" maxlength="11"
  15. required />
  16. </view>
  17. </view>
  18. <view class="item">
  19. <view class="acea-row row-middle">
  20. <text class="iconfont icon-code_1"></text>
  21. <input type="password" class="texts" placeholder="填写登录密码" maxlength="18" v-model="password"
  22. required />
  23. </view>
  24. </view>
  25. </form>
  26. </view>
  27. <view class="list" v-if="current !== 0 || appLoginStatus || appleLoginStatus">
  28. <view class="item">
  29. <view class="acea-row row-middle">
  30. <text class="iconfont icon-phone_"></text>
  31. <input type="number" class="texts" placeholder="输入手机号码" v-model="phone" maxlength="11" />
  32. </view>
  33. </view>
  34. <view class="item">
  35. <view class="acea-row row-middle">
  36. <text class="iconfont icon-code_1"></text>
  37. <input type="number" placeholder="填写验证码" class="codeIput" v-model="captcha" maxlength="6" />
  38. <button class="code main_color" :disabled="disabled" :class="disabled === true ? 'on' : ''"
  39. @click="code">
  40. {{ text }}
  41. </button>
  42. </view>
  43. </view>
  44. <view class="item" v-if="isShowCode">
  45. <view class="acea-row row-middle">
  46. <text class="iconfont icon-code_1"></text>
  47. <input type="number" placeholder="填写验证码" class="codeIput" v-model="codeVal" maxlength="6" />
  48. <view class="code" @click="again"><img :src="codeUrl" /></view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="protocol acea-row row-between-wrapper">
  53. <checkbox-group class="checkgroup acea-row" @change='isAgree=!isAgree' style="align-items: end;">
  54. <checkbox class="checkbox" :checked="isAgree ? true : false" />
  55. <text class="protocol_text">我已阅读并同意<text @click="userAgree('userinfo')" class="font_pro">《用户协议》</text>与<text
  56. @click="userAgree('userprivacyinfo')" class="font_pro">《隐私协议》</text></text>
  57. </checkbox-group>
  58. </view>
  59. <view class="logon bg_color" @click="loginMobile" v-if="current !== 0">登录</view>
  60. <view class="logon bg_color" @click="submit" v-if="current === 0">登录</view>
  61. <!-- #ifndef APP-PLUS -->
  62. <view class="tips">
  63. <view v-if="current==0" @click="current = 1">快速登录</view>
  64. <view v-if="current==1" @click="current = 0">账号登录</view>
  65. </view>
  66. <!-- #endif -->
  67. <!-- #ifdef APP-PLUS -->
  68. <view class="appLogin" v-if="!appLoginStatus && !appleLoginStatus">
  69. <view class="hds">
  70. <span class="line"></span>
  71. <p>其他方式登录</p>
  72. <span class="line"></span>
  73. </view>
  74. <view class="btn-wrapper">
  75. <view class="btn wx" @click="wxLogin">
  76. <span class="iconfont icon-s-weixindenglu1"></span>
  77. </view>
  78. <view class="btn mima" v-if="current == 1" @click="current =0">
  79. <span class="iconfont icon-s-mimadenglu1"></span>
  80. </view>
  81. <view class="btn yanzheng" v-if="current == 0" @click="current =1">
  82. <span class="iconfont icon-s-yanzhengmadenglu1"></span>
  83. </view>
  84. <view class="btn apple-btn" @click="appleLogin" v-if="appleShow">
  85. <view class="iconfont icon-s-pingguo"></view>
  86. </view>
  87. </view>
  88. </view>
  89. <!-- #endif -->
  90. </view>
  91. <view class="bottom"></view>
  92. <Verify @success="handlerOnVerSuccess" :captchaType="'clickWord'" :imgSize="{ width: '330px', height: '155px' }"
  93. ref="verify"></Verify>
  94. </view>
  95. </template>
  96. <script>
  97. // +----------------------------------------------------------------------
  98. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  99. // +----------------------------------------------------------------------
  100. // | Copyright (c) 2016~2025 https://www.crmeb.com All rights reserved.
  101. // +----------------------------------------------------------------------
  102. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  103. // +----------------------------------------------------------------------
  104. // | Author: CRMEB Team <admin@crmeb.com>
  105. // +----------------------------------------------------------------------
  106. import sendVerifyCode from "@/mixins/SendVerifyCode";
  107. import Verify from '../components/verifition/verify.vue';
  108. import {
  109. loginH5,
  110. loginMobile,
  111. registerVerify,
  112. register,
  113. } from "@/api/user";
  114. let app = getApp();
  115. import {
  116. loginConfigApi,
  117. appAuth,
  118. appleLogin
  119. } from "@/api/public";
  120. import {
  121. VUE_APP_API_URL
  122. } from "@/utils";
  123. import {
  124. Debounce
  125. } from '@/utils/validate.js'
  126. import {
  127. goToAgreement
  128. } from "@/libs/order";
  129. import {
  130. mapGetters
  131. } from "vuex";
  132. import Routine from "../../../libs/routine";
  133. import {
  134. silenceBindingSpread
  135. } from "../../../utils";
  136. const BACK_URL = "login_back_url";
  137. export default {
  138. name: "Login",
  139. mixins: [sendVerifyCode],
  140. components: {
  141. Verify,
  142. },
  143. computed: mapGetters(['userInfo', 'isLogin', 'globalData']),
  144. data: function() {
  145. return {
  146. isAgree: false,
  147. navList: ["快速登录", "账号登录"],
  148. current: 1,
  149. phone: "",
  150. password: "",
  151. captcha: "",
  152. formItem: 1,
  153. type: "login",
  154. logoUrl: "",
  155. keyCode: "",
  156. codeUrl: "",
  157. codeVal: "",
  158. isShowCode: false,
  159. platform: '',
  160. appLoginStatus: false, // 微信登录强制绑定手机号码状态
  161. appUserInfo: {}, // 微信登录保存的用户信息
  162. appleLoginStatus: false, // 苹果登录强制绑定手机号码状态
  163. appleUserInfo: null,
  164. appleShow: false, // 苹果登录版本必须要求ios13以上的
  165. theme: app.globalData.theme,
  166. };
  167. },
  168. watch: {
  169. formItem: function(nval, oVal) {
  170. if (nval == 1) {
  171. this.type = 'login'
  172. } else {
  173. this.type = 'register'
  174. }
  175. }
  176. },
  177. mounted: function() {
  178. this.getCode();
  179. this.getLogoImage();
  180. },
  181. onLoad() {
  182. let self = this
  183. uni.getSystemInfo({
  184. success: function(res) {
  185. if (res.platform.toLowerCase() == 'ios' && res.system.split(' ')[1] >= '13') {
  186. self.appleShow = true
  187. self.platform = res.platform
  188. }
  189. }
  190. });
  191. },
  192. methods: {
  193. userAgree(info) {
  194. goToAgreement(info)
  195. },
  196. // 苹果登录
  197. appleLogin() {
  198. let self = this
  199. this.phone = ''
  200. this.captcha = ''
  201. if (!this.isAgree) return this.$util.Tips({
  202. title: '请勾选用户隐私协议'
  203. });
  204. uni.showLoading({
  205. title: '登录中'
  206. })
  207. uni.login({
  208. provider: 'apple',
  209. timeout: 10000,
  210. success(loginRes) {
  211. uni.hideLoading();
  212. uni.getUserInfo({
  213. provider: 'apple',
  214. success: function(infoRes) {
  215. self.appleUserInfo = infoRes.userInfo
  216. self.appleLoginApi()
  217. },
  218. fail() {
  219. uni.hideLoading();
  220. uni.showToast({
  221. title: '获取用户信息失败',
  222. icon: 'none',
  223. duration: 2000
  224. })
  225. },
  226. complete() {
  227. uni.hideLoading()
  228. }
  229. });
  230. },
  231. fail(error) {
  232. uni.hideLoading()
  233. }
  234. })
  235. },
  236. // 苹果登录Api
  237. appleLoginApi() {
  238. appleLogin({
  239. openId: this.appleUserInfo.openId,
  240. email: this.appleUserInfo.email == undefined ? '' : this.appleUserInfo.email,
  241. identityToken: this.appleUserInfo.identityToken || ''
  242. }).then((res) => {
  243. let data = res.data;
  244. this.$store.commit("LOGIN", {
  245. 'token': data.token
  246. });
  247. if (data.isNew && data.newPeopleCouponList && data.newPeopleCouponList.length !== 0) {
  248. this.$Cache.set('newGift', data.newPeopleCouponList);
  249. } else {
  250. this.$Cache.clear('newGift');
  251. }
  252. this.getUserInfo(data);
  253. }).catch(error => {
  254. uni.hideLoading();
  255. uni.showModal({
  256. title: '提示',
  257. content: `错误信息${error}`,
  258. success: function(res) {
  259. if (res.confirm) {
  260. console.log('用户点击确定');
  261. } else if (res.cancel) {
  262. console.log('用户点击取消');
  263. }
  264. }
  265. });
  266. })
  267. },
  268. // App微信登录
  269. wxLogin: Debounce(function() {
  270. this.phone = ''
  271. this.captcha = ''
  272. let self = this
  273. if (!this.isAgree) return this.$util.Tips({
  274. title: '请勾选用户隐私协议'
  275. });
  276. uni.showLoading({
  277. title: '登录中'
  278. })
  279. uni.login({
  280. provider: 'weixin',
  281. success: function(res) {
  282. uni.hideLoading();
  283. let loginRes = res.authResult;
  284. self.appUserInfo.openId = loginRes.openid;
  285. self.appUserInfo.unionId = loginRes.unionid;
  286. self.appUserInfo.type = self.platform === 'ios' ? 'iosWx' : 'androidWx';
  287. self.wxLoginGo(self.appUserInfo)
  288. },
  289. fail() {
  290. uni.hideLoading()
  291. uni.showToast({
  292. title: '登录失败',
  293. icon: 'none',
  294. duration: 2000
  295. })
  296. }
  297. });
  298. }),
  299. wxLoginGo(userInfo) {
  300. appAuth(userInfo).then(res => {
  301. let data = res.data;
  302. if (data.type === 'register') {
  303. uni.navigateTo({
  304. url: '/pages/users/app_login/index?authKey=' + data.key
  305. })
  306. }
  307. if (data.type === 'login') {
  308. this.$store.commit("LOGIN", {
  309. 'token': data.token
  310. });
  311. this.getUserInfo(data);
  312. }
  313. if (data.isNew && data.newPeopleCouponList && data.newPeopleCouponList.length !== 0) {
  314. this.$Cache.set('newGift', data.newPeopleCouponList);
  315. } else {
  316. this.$Cache.clear('newGift');
  317. }
  318. }).catch(res => {
  319. this.$util.Tips({
  320. title: res
  321. });
  322. });
  323. },
  324. again() {
  325. this.codeUrl =
  326. VUE_APP_API_URL +
  327. "/sms_captcha?" +
  328. "key=" +
  329. this.keyCode +
  330. Date.parse(new Date());
  331. },
  332. getCode() {
  333. let that = this
  334. },
  335. async getLogoImage() {
  336. let that = this;
  337. loginConfigApi().then(res => {
  338. that.logoUrl = res.data.logo ? res.data.logo : '/static/images/logo2.png';
  339. });
  340. },
  341. /**
  342. * 手机号验证码登录
  343. */
  344. loginMobile: Debounce(function() {
  345. let that = this;
  346. if (!that.phone) return that.$util.Tips({
  347. title: '请填写手机号码'
  348. });
  349. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone)) return that.$util.Tips({
  350. title: '请输入正确的手机号码'
  351. });
  352. if (!that.captcha) return that.$util.Tips({
  353. title: '请填写验证码'
  354. });
  355. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  356. title: '请输入正确的验证码'
  357. });
  358. if (!that.isAgree) return that.$util.Tips({
  359. title: '请勾选用户隐私协议'
  360. });
  361. loginMobile({
  362. phone: that.phone,
  363. captcha: that.captcha,
  364. spreadPid: that.$Cache.get("spread")
  365. })
  366. .then(res => {
  367. let data = res.data;
  368. let newTime = Math.round(new Date() / 1000);
  369. this.$store.commit("LOGIN", {
  370. 'token': res.data.token
  371. });
  372. if (data.isNew && data.newPeopleCouponList && data.newPeopleCouponList.length !== 0) {
  373. this.$Cache.set('newGift', data.newPeopleCouponList);
  374. } else {
  375. this.$Cache.clear('newGift');
  376. }
  377. that.getUserInfo(data);
  378. })
  379. .catch(res => {
  380. that.$util.Tips({
  381. title: res
  382. });
  383. });
  384. }),
  385. async register() {
  386. let that = this;
  387. if (!that.phone) return that.$util.Tips({
  388. title: '请填写手机号码'
  389. });
  390. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone)) return that.$util.Tips({
  391. title: '请输入正确的手机号码'
  392. });
  393. if (!this.isAgree) return this.$util.Tips({
  394. title: '请勾选用户隐私协议'
  395. });
  396. if (!that.captcha) return that.$util.Tips({
  397. title: '请填写验证码'
  398. });
  399. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  400. title: '请输入正确的验证码'
  401. });
  402. if (!that.password) return that.$util.Tips({
  403. title: '请填写密码'
  404. });
  405. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
  406. title: '您输入的密码过于简单'
  407. });
  408. register({
  409. phone: that.phone,
  410. captcha: that.captcha,
  411. password: that.password,
  412. spread_spid: that.$Cache.get("spread")
  413. // spread_spid: uni.getStorageSync('spid') || 0
  414. })
  415. .then(res => {
  416. that.$util.Tips({
  417. title: res
  418. });
  419. that.formItem = 1;
  420. })
  421. .catch(res => {
  422. that.$util.Tips({
  423. title: res
  424. });
  425. });
  426. },
  427. //滑块验证成功后
  428. handlerOnVerSuccess(data) {
  429. this.$refs.verify.hide();
  430. this.codeSend();
  431. },
  432. codeSend() {
  433. let that = this;
  434. if (!that.phone) return that.$util.Tips({
  435. title: '请填写手机号码'
  436. });
  437. if (!this.isAgree) return this.$util.Tips({
  438. title: '请勾选用户隐私协议'
  439. });
  440. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone)) return that.$util.Tips({
  441. title: '请输入正确的手机号码'
  442. });
  443. registerVerify(that.phone)
  444. .then(res => {
  445. that.$util.Tips({
  446. title: res.message
  447. });
  448. that.sendCode();
  449. })
  450. .catch(err => {
  451. return that.$util.Tips({
  452. title: err
  453. });
  454. });
  455. },
  456. code: Debounce(function() {
  457. let that = this;
  458. if (!that.phone) return that.$util.Tips({
  459. title: '请填写手机号码'
  460. });
  461. if (!this.isAgree) return this.$util.Tips({
  462. title: '请勾选用户隐私协议'
  463. });
  464. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone)) return that.$util.Tips({
  465. title: '请输入正确的手机号码'
  466. });
  467. that.$refs.verify.show();
  468. }),
  469. navTap: function(index) {
  470. this.current = index;
  471. },
  472. submit: Debounce(function() {
  473. let that = this;
  474. if (!that.phone) return that.$util.Tips({
  475. title: '请填写账号'
  476. });
  477. if (!/^[\w\d]{5,16}$/i.test(that.phone)) return that.$util.Tips({
  478. title: '请输入正确的账号'
  479. });
  480. if (!that.password) return that.$util.Tips({
  481. title: '请填写密码'
  482. });
  483. if (!that.isAgree) return that.$util.Tips({
  484. title: '请勾选用户隐私协议'
  485. });
  486. uni.showLoading({
  487. title: '正在登录中'
  488. });
  489. loginH5({
  490. phone: that.phone,
  491. password: that.password,
  492. spread_spid: that.$Cache.get("spread")
  493. }).then(({
  494. data
  495. }) => {
  496. that.$store.commit("LOGIN", {
  497. 'token': data.token
  498. });
  499. uni.hideLoading();
  500. that.getUserInfo(data);
  501. })
  502. .catch(e => {
  503. uni.hideLoading();
  504. that.$util.Tips({
  505. title: e
  506. });
  507. });
  508. }),
  509. getUserInfo(data) {
  510. this.$store.dispatch("GetTokenIsExist");
  511. //分销绑定
  512. silenceBindingSpread(true, this.globalData.spread);
  513. this.$store.dispatch('GetGlobalConfig');
  514. this.$store.commit('UPDATE_USERINFO', {
  515. avatar: data.avatar,
  516. nickname: data.nickname,
  517. phone: data.phone
  518. });
  519. this.$store.commit("SETUID", data.id);
  520. let backUrl = this.$Cache.get(BACK_URL) || "/pages/index/index";
  521. if (backUrl.indexOf('/pages/users/login/index') !== -1) {
  522. backUrl = '/pages/index/index';
  523. }
  524. // #ifdef MP
  525. if (!this.$Cache.get('wechatQRcode')) Routine.getQrcode()
  526. // #endif
  527. uni.reLaunch({
  528. url: backUrl
  529. });
  530. },
  531. }
  532. };
  533. </script>
  534. <style lang="scss" scoped>
  535. .protocol {
  536. margin: 30rpx 0;
  537. padding-left: 44rpx;
  538. }
  539. .protocol_text {
  540. .font_pro {
  541. @include main_color(theme);
  542. }
  543. }
  544. page {
  545. background: #fff;
  546. }
  547. .appLogin {
  548. margin-top: 60rpx;
  549. .hds {
  550. display: flex;
  551. justify-content: center;
  552. align-items: center;
  553. font-size: 24rpx;
  554. color: #B4B4B4;
  555. .line {
  556. width: 68rpx;
  557. height: 1rpx;
  558. background: #CCCCCC;
  559. }
  560. p {
  561. margin: 0 20rpx;
  562. }
  563. }
  564. .btn-wrapper {
  565. display: flex;
  566. align-items: center;
  567. justify-content: center;
  568. margin-top: 30rpx;
  569. .btn {
  570. display: flex;
  571. align-items: center;
  572. justify-content: center;
  573. width: 68rpx;
  574. height: 68rpx;
  575. border-radius: 50%;
  576. }
  577. .apple-btn {
  578. display: flex;
  579. align-items: center;
  580. justify-content: center;
  581. margin-left: 30rpx;
  582. background: #000;
  583. border-radius: 34rpx;
  584. font-size: 40rpx;
  585. .icon-s-pingguo {
  586. color: #fff;
  587. font-size: 40rpx;
  588. }
  589. }
  590. .iconfont {
  591. font-size: 40rpx;
  592. color: #fff;
  593. }
  594. .wx {
  595. margin-right: 30rpx;
  596. background-color: #61C64F;
  597. }
  598. .mima {
  599. background-color: #28B3E9;
  600. }
  601. .yanzheng {
  602. background-color: #F89C23;
  603. }
  604. }
  605. }
  606. .main_color {
  607. @include main_color(theme);
  608. }
  609. .bg_color {
  610. @include main_bg_color(theme);
  611. }
  612. .code img {
  613. width: 100%;
  614. height: 100%;
  615. }
  616. .acea-row.row-middle {
  617. input {
  618. margin-left: 20rpx;
  619. display: block;
  620. }
  621. }
  622. .login-wrapper {
  623. padding: 30rpx;
  624. .shading {
  625. display: flex;
  626. align-items: center;
  627. justify-content: center;
  628. width: 100%;
  629. /* #ifdef APP-VUE */
  630. margin-top: 50rpx;
  631. /* #endif */
  632. /* #ifndef APP-VUE */
  633. margin-top: 200rpx;
  634. /* #endif */
  635. image {
  636. width: 180rpx;
  637. height: 180rpx;
  638. }
  639. }
  640. .whiteBg {
  641. margin-top: 100rpx;
  642. .list {
  643. border-radius: 16rpx;
  644. overflow: hidden;
  645. .item {
  646. border-bottom: 1px solid #F0F0F0;
  647. background: #fff;
  648. .row-middle {
  649. position: relative;
  650. padding: 16rpx 45rpx;
  651. .texts {
  652. flex: 1;
  653. font-size: 28rpx;
  654. height: 80rpx;
  655. line-height: 80rpx;
  656. display: flex;
  657. justify-content: center;
  658. align-items: center;
  659. }
  660. input {
  661. flex: 1;
  662. font-size: 28rpx;
  663. height: 80rpx;
  664. line-height: 80rpx;
  665. display: flex;
  666. justify-content: center;
  667. align-items: center;
  668. }
  669. .code {
  670. position: absolute;
  671. right: 30rpx;
  672. top: 50%;
  673. color: $theme-color;
  674. font-size: 26rpx;
  675. transform: translateY(-50%);
  676. }
  677. }
  678. }
  679. }
  680. .logon {
  681. display: flex;
  682. align-items: center;
  683. justify-content: center;
  684. width: 100%;
  685. height: 86rpx;
  686. margin-top: 80rpx;
  687. background-color: $theme-color;
  688. border-radius: 120rpx;
  689. color: #FFFFFF;
  690. font-size: 30rpx;
  691. }
  692. .tips {
  693. margin: 30rpx;
  694. text-align: center;
  695. color: #999;
  696. }
  697. }
  698. }
  699. </style>