index.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. <template>
  2. <div :style="viewColor">
  3. <div class="register_main" :style="{ 'background-image': formItem == 1 ? `url(${domain}/static/images/logo_bgl.png)` : `url(${domain}/static/images/logo_bgh.png)`}">
  4. <view class="system-height" :style="{ height: statusBarHeight }"></view>
  5. <!-- #ifdef APP-PLUS -->
  6. <view class="title-bar" style="height: 43px;">
  7. <view class="icon" @click="home">
  8. <text class="iconfont icon-shouye2"></text>
  9. </view>
  10. 商城登录
  11. </view>
  12. <!-- #endif -->
  13. <div class="register absolute" v-if="!auth_token">
  14. <div class="whiteBg" v-if="formItem === 1">
  15. <view class="login_title">
  16. <view class="title_h">{{current==0 ? "账号登录" : "手机号登录"}}</view>
  17. <view class="title_info" v-if="current==1">首次登录会自动注册</view>
  18. <view class="title_info" v-else>没有账号?<text @click="formItem = 2">立即注册</text></text></view>
  19. </view>
  20. <!--账号登录-->
  21. <div class="list" :hidden="current !== 0">
  22. <form @submit.prevent="submit">
  23. <div class="item">
  24. <input type="text" placeholder="请输入手机号或账号" placeholder-class="placeholder" v-model="account" required />
  25. </div>
  26. <div class="item">
  27. <input type="password" placeholder="填写登录密码" placeholder-class="placeholder" v-model="password" required />
  28. <navigator class="forgetPwd" hover-class="none" url="/pages/users/retrievePassword/index">
  29. 忘记密码
  30. </navigator>
  31. </div>
  32. </form>
  33. </div>
  34. <!--手机号验证码登录-->
  35. <div class="list" :hidden="current !== 1">
  36. <div class="item">
  37. <input type="text" placeholder="输入手机号码" placeholder-class="placeholder" v-model="account" />
  38. </div>
  39. <div class="item">
  40. <input type="text" placeholder="填写验证码" placeholder-class="placeholder" class="codeIput" v-model="captcha" />
  41. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="handleVerify">
  42. {{ text }}
  43. </button>
  44. </div>
  45. </div>
  46. <!--手机号验证码登录-->
  47. <div class="logon" @click="loginMobile" v-if="current ===1">立即登录</div>
  48. <div class="logon" @click="submit" v-else>登录</div>
  49. <div class="tip">
  50. <text v-if="current==0" @click="current = 1">手机号登录</text>
  51. <text v-else @click="current = 0">账号登录</text>
  52. </div>
  53. <div class="protocol acea-row row-between-wrapper">
  54. <checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
  55. <checkbox class="checkbox" :checked="isAgree ? true : false" />
  56. <text class="protocol_text">我已同意<text @click="userAgree" class="font_pro">《用户协议》</text>与<text @click="userPrivacyAgree" class="font_pro">《隐私政策》</text></text>
  57. </checkbox-group>
  58. </div>
  59. <!-- #ifdef APP-PLUS -->
  60. <view class="appLogin" v-if="wechat_phone_switch == 1 || appleShow">
  61. <view class="hds">
  62. <span class="line"></span>
  63. <p>其他方式登录</p>
  64. <span class="line"></span>
  65. </view>
  66. <view class="btn-wrapper">
  67. <view class="btn wx" v-if="wechat_phone_switch == 1" @click="wxLogin">
  68. <span class="iconfont icon-s-weixindenglu1"></span>
  69. </view>
  70. <view class="btn wx btn-apple" @click="appleLogin" v-if="appleShow">
  71. <span class="iconfont icon-s-pingguo"></span>
  72. </view>
  73. </view>
  74. </view>
  75. <!-- #endif -->
  76. </div>
  77. <div class="whiteBg" v-else>
  78. <view class="login_title">
  79. <view class="title_h">注册账号</view>
  80. </view>
  81. <div class="list">
  82. <div class="item">
  83. <input type="text" placeholder="请输入手机号" placeholder-class="placeholder" v-model="account" />
  84. </div>
  85. <div class="item">
  86. <input type="text" placeholder="填写验证码" placeholder-class="placeholder" class="codeIput" v-model="captcha" />
  87. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="handleVerify">
  88. {{ text }}
  89. </button>
  90. </div>
  91. <div class="item">
  92. <input type="password" placeholder="填写您的登录密码" placeholder-class="placeholder" v-model="password" />
  93. </div>
  94. <div class="item" v-if="isShowCode">
  95. <input type="text" placeholder="填写验证码" placeholder-class="placeholder" class="codeIput" v-model="codeVal" />
  96. <div class="code" @click="getcaptcha"><image class="code-img" style="width: 100%;height: 100%;" :src="codeUrl" /></div>
  97. </div>
  98. </div>
  99. <div class="tip">
  100. 已有账号?
  101. <text @click="formItem = 1">立即登录</text>
  102. </div>
  103. <div class="logon" @click="register">注册</div>
  104. <div class="protocol acea-row row-between-wrapper">
  105. <checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
  106. <checkbox class="checkbox" :checked="isAgree ? true : false" />
  107. <text class="protocol_text">我已同意<text @click="userAgree" class="font_pro">《用户协议》</text>与<text @click="userPrivacyAgree" class="font_pro">《隐私政策》</text></text>
  108. </checkbox-group>
  109. </div>
  110. <!-- #ifdef APP-PLUS -->
  111. <view class="appLogin" v-if="!appLoginStatus && !appleLoginStatus">
  112. <view class="hds">
  113. <span class="line"></span>
  114. <p>其他方式登录</p>
  115. <span class="line"></span>
  116. </view>
  117. <view class="btn-wrapper">
  118. <view class="btn wx" @click="wxLogin">
  119. <span class="iconfont icon-s-weixindenglu1"></span>
  120. </view>
  121. <view class="btn wx btn-apple" @click="appleLogin" v-if="appleShow">
  122. <span class="iconfont icon-s-pingguo"></span>
  123. </view>
  124. </view>
  125. </view>
  126. <!-- #endif -->
  127. </div>
  128. <div class="bottom"></div>
  129. </div>
  130. <form report-submit='true' v-if="auth_token">
  131. <view class="register">
  132. <view class="whiteBg">
  133. <view class="login_title">
  134. <view class="title_h">绑定手机号</view>
  135. </view>
  136. <view class="list">
  137. <view class="item">
  138. <input type='number' placeholder='填写手机号码' placeholder-class='placeholder' v-model="account"></input>
  139. </view>
  140. <view class="item">
  141. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" v-model="captcha"></input>
  142. <button class="code" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="handleVerify">
  143. {{ text }}
  144. </button>
  145. </view>
  146. <view class="item">
  147. <input type='password' placeholder='填写登录密码' placeholder-class='placeholder' v-model="password"></input>
  148. </view>
  149. <view class="protocol acea-row">
  150. <checkbox-group class="checkgroup" @change='isAgree=!isAgree'>
  151. <checkbox class="checkbox" :checked="isAgree ? true : false" />
  152. <text class="protocol_text">您已同意<text @click="userAgree" class="font_pro">《用户协议》</text>与<text @click="userPrivacyAgree" class="font_pro">《隐私政策》</text></text>
  153. </checkbox-group>
  154. </view>
  155. </view>
  156. <button form-type="submit" @click="register" class="logon">确认绑定</button>
  157. <button form-type="submit" @click="auth_token = ''" class="logon back">返回</button>
  158. </view>
  159. </view>
  160. </form>
  161. <!-- <view class="copyright" @click="goCopyUrl">{{copyData}}</view> -->
  162. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }" ref="verify"></Verify>
  163. </div>
  164. </div>
  165. </template>
  166. <script>
  167. // +----------------------------------------------------------------------
  168. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  169. // +----------------------------------------------------------------------
  170. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  171. // +----------------------------------------------------------------------
  172. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  173. // +----------------------------------------------------------------------
  174. // | Author: CRMEB Team <admin@crmeb.com>
  175. // +----------------------------------------------------------------------
  176. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  177. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  178. import sendVerifyCode from "@/mixins/SendVerifyCode";
  179. import {
  180. loginH5,
  181. loginMobile,
  182. registerVerify,
  183. register,
  184. getCodeApi,
  185. getUserInfo,
  186. getCaptcha,
  187. appleLogin,
  188. loginMpPhone
  189. } from "@/api/user";
  190. // #ifdef APP-PLUS
  191. import { wechatAppAuth, appleAppAuth } from '@/api/api.js'
  192. // #endif
  193. import attrs, {
  194. required,
  195. alpha_num,
  196. chs_phone
  197. } from "@/utils/validate";
  198. import {
  199. getLogo,
  200. getconfig,
  201. getVersion
  202. } from "@/api/public";
  203. import {
  204. VUE_APP_API_URL,
  205. configMap
  206. } from "@/utils";
  207. import { HTTP_REQUEST_URL } from '@/config/app';
  208. import parser from "@/components/jyf-parser/jyf-parser";
  209. import { commonAuth } from '../../../api/public';
  210. import { mapGetters} from "vuex";
  211. import Verify from '@/components/verify/verify.vue';
  212. const BACK_URL = "login_back_url";
  213. export default {
  214. name: "Login",
  215. mixins: [sendVerifyCode],
  216. components: {
  217. "jyf-parser": parser,
  218. Verify
  219. },
  220. data: function() {
  221. return {
  222. domain: HTTP_REQUEST_URL,
  223. statusBarHeight: statusBarHeight,
  224. current: 1,
  225. account: "",
  226. password: "",
  227. captcha: "",
  228. formItem: 1,
  229. type: "login",
  230. keyCode: "",
  231. codeUrl: "",
  232. codeVal: "",
  233. isShowCode: false,
  234. tagStyle: {
  235. img: 'width:100%;display:block;'
  236. },
  237. isAgree: false,
  238. appLoginStatus: false, // 微信登录强制绑定手机号码状态
  239. appUserInfo: null, // 微信登录保存的用户信息
  240. appleLoginStatus: false, // 苹果登录强制绑定手机号码状态
  241. appleUserInfo: null,
  242. appleShow: false, // 苹果登录版本必须要求ios13以上的
  243. keyLock: true,
  244. auth_token: "",
  245. codeVal: '',
  246. copyright: {}
  247. };
  248. },
  249. computed:{
  250. ...configMap(['login_logo','wechat_phone_switch'], mapGetters(['viewColor'])),
  251. copyData() {
  252. let copy = this.copyright.status == -1 ? this.copyright.year : this.copyright.Copyright
  253. return copy;
  254. }
  255. },
  256. watch: {
  257. formItem: function(nval, oVal) {
  258. if (nval == 1) {
  259. this.type = 'login'
  260. } else {
  261. this.type = 'register'
  262. }
  263. }
  264. },
  265. onLoad() {
  266. let self = this
  267. uni.getSystemInfo({
  268. success: function(res) {
  269. if (res.platform.toLowerCase() == 'ios' && self.getSystem(res.system) >= 13) {
  270. self.appleShow = true
  271. }
  272. }
  273. });
  274. },
  275. mounted: function() {
  276. this.getVersion();
  277. },
  278. onReady(){
  279. let that = this
  280. // #ifdef MP
  281. wx.login({
  282. success (res) {
  283. if (res.code) {
  284. that.codeVal = res.code
  285. } else {
  286. console.log('登录失败!' + res.errMsg)
  287. }
  288. }
  289. })
  290. // #endif
  291. },
  292. methods: {
  293. // #ifdef MP
  294. getPhoneNumber(e) {
  295. let that = this;
  296. if(!that.isAgree){
  297. return that.$util.Tips({
  298. title: '请勾选用户协议与隐私政策'
  299. });
  300. }else{
  301. loginMpPhone({
  302. iv:e.detail.iv,
  303. encryptedData:e.detail.encryptedData,
  304. code:that.codeVal,
  305. auth_token: uni.getStorageSync('auth_token'),
  306. }).then(({
  307. data
  308. }) => {
  309. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  310. that.$Cache.clear(BACK_URL);
  311. that.$store.commit("LOGIN", {
  312. 'token': data.token,
  313. 'time': data.exp
  314. });
  315. that.$store.commit("SETUID", data.user.uid);
  316. that.$store.commit('UPDATE_USERINFO', data.user);
  317. let method
  318. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  319. '/pages/user/index','/pages/plant_grass/index'
  320. ]
  321. if (indexPat.includes(this.getPath(backUrl))) {
  322. method = 'switchTab'
  323. } else {
  324. method = 'navigateTo'
  325. }
  326. if (this.getPath(backUrl) === '/pages/users/login/index') {
  327. uni.switchTab({
  328. url: '/pages/index/index'
  329. });
  330. return
  331. }
  332. uni[method]({
  333. url: backUrl
  334. });
  335. })
  336. .catch(res => {
  337. that.$util.Tips({
  338. title: res
  339. });
  340. });
  341. }
  342. },
  343. // #endif
  344. goCopyUrl() {
  345. // #ifdef H5
  346. location.href = this.copyright.url
  347. // #endif
  348. },
  349. userAgree(){
  350. uni.navigateTo({
  351. url: '/pages/users/user_about/index?from=sys_user_agree'
  352. })
  353. },
  354. userPrivacyAgree(){
  355. uni.navigateTo({
  356. url: '/pages/users/user_about/index?from=sys_userr_privacy'
  357. })
  358. },
  359. getSystem(system) {
  360. if(system.indexOf('iOS') === -1){
  361. return system
  362. }else{
  363. let str = system.split(' ')[1]
  364. if (str.indexOf('.')) {
  365. return Number(str.split('.')[0])
  366. } else {
  367. return Number(str)
  368. }
  369. }
  370. },
  371. home() {
  372. uni.switchTab({
  373. url: '/pages/index/index'
  374. })
  375. },
  376. // 苹果登录
  377. appleLogin() {
  378. let self = this
  379. if(!self.isAgree){
  380. return self.$util.Tips({
  381. title: '请勾选用户协议与隐私政策'
  382. });
  383. }else{
  384. this.account = ''
  385. this.captcha = ''
  386. uni.showLoading({
  387. title: '登录中'
  388. })
  389. uni.login({
  390. provider: 'apple',
  391. timeout: 10000,
  392. success(loginRes) {
  393. uni.getUserInfo({
  394. provider: 'apple',
  395. success: function(infoRes) {
  396. self.appleUserInfo = infoRes.userInfo
  397. self.appleLoginApi()
  398. },
  399. fail() {
  400. uni.showToast({
  401. title: '获取用户信息失败',
  402. icon: 'none',
  403. duration: 2000
  404. })
  405. },
  406. complete() {
  407. uni.hideLoading()
  408. }
  409. });
  410. },
  411. fail(error) {
  412. uni.showToast({
  413. title: '获取用户信息失败',
  414. icon: 'none',
  415. duration: 2000
  416. })
  417. console.log(error)
  418. }
  419. })
  420. }
  421. },
  422. appleLoginApi(){
  423. let that = this
  424. commonAuth({
  425. auth: {
  426. type:'apple',
  427. auth: {
  428. userInfo: that.appleUserInfo,
  429. openId: that.appleUserInfo.openId,
  430. nickname: (that.appleUserInfo.fullName.familyName || '') + (that.appleUserInfo.fullName.giveName || ''),
  431. }
  432. }}).then(res => {
  433. const data = res.data;
  434. if(res.data.status == 200){
  435. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  436. that.$Cache.clear(BACK_URL);
  437. that.$store.commit("LOGIN", {
  438. 'token': data.result.token,
  439. 'time': data.result.exp
  440. });
  441. that.$store.commit("SETUID", data.result.user.uid);
  442. that.$store.commit('UPDATE_USERINFO', data.result.user);
  443. let method
  444. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  445. '/pages/user/index','/pages/plant_grass/index'
  446. ]
  447. if (indexPat.includes(this.getPath(backUrl))) {
  448. method = 'switchTab'
  449. } else {
  450. method = 'navigateTo'
  451. }
  452. if (this.getPath(backUrl) === '/pages/users/login/index') {
  453. uni.switchTab({
  454. url: '/pages/index/index'
  455. });
  456. return
  457. }
  458. uni[method]({
  459. url: backUrl
  460. });
  461. }else{
  462. uni.hideLoading();
  463. that.auth_token = res.data.result.key;
  464. }
  465. }).catch(res => {
  466. uni.hideLoading();
  467. uni.showToast({
  468. title: res.message || res,
  469. icon: 'none',
  470. duration: 2000
  471. });
  472. });
  473. },
  474. // App微信登录
  475. wxLogin() {
  476. if (!this.isAgree) return this.$util.Tips({
  477. title: '请勾选用户协议与隐私政策'
  478. });
  479. let self = this
  480. this.account = ''
  481. this.captcha = ''
  482. uni.showLoading({
  483. title: '登录中'
  484. })
  485. uni.login({
  486. provider: 'weixin',
  487. // onlyAuthorize: true,
  488. success: function(loginRes) {
  489. self.appUserInfo = loginRes
  490. self.wxLoginApi()
  491. },
  492. fail(error) {
  493. uni.showToast({
  494. title: '登录失败',
  495. icon: 'none',
  496. duration: 2000
  497. })
  498. }
  499. });
  500. },
  501. getPath(url) {
  502. if (url.indexOf("?") != -1) {
  503. url = url.split("?")[0];
  504. console.log(url);
  505. }
  506. return url
  507. },
  508. wxLoginApi() {
  509. const that = this
  510. commonAuth({
  511. auth: {
  512. type:'app_wechat',
  513. auth: {
  514. code: that.appUserInfo.authResult.access_token,
  515. openid: that.appUserInfo.authResult.openid,
  516. phone: this.account,
  517. }
  518. }}).then(res => {
  519. const data = res.data;
  520. if(res.data.status == 200){
  521. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  522. that.$Cache.clear(BACK_URL);
  523. that.$store.commit("LOGIN", {
  524. 'token': data.result.token,
  525. 'time': data.result.exp
  526. });
  527. that.$store.commit("SETUID", data.result.user.uid);
  528. that.$store.commit('UPDATE_USERINFO', data.result.user);
  529. let method
  530. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  531. '/pages/user/index','/pages/plant_grass/index'
  532. ]
  533. if (indexPat.includes(this.getPath(backUrl))) {
  534. method = 'switchTab'
  535. } else {
  536. method = 'navigateTo'
  537. }
  538. if (this.getPath(backUrl) === '/pages/users/login/index') {
  539. uni.switchTab({
  540. url: '/pages/index/index'
  541. });
  542. return
  543. }
  544. uni[method]({
  545. url: backUrl
  546. });
  547. }else{
  548. that.auth_token = res.data.result.key;
  549. that.bindStatus = true;
  550. }
  551. uni.hideLoading();
  552. }).catch(res => {
  553. uni.hideLoading();
  554. uni.showToast({
  555. title: res.message || res,
  556. icon: 'none',
  557. duration: 2000
  558. });
  559. });
  560. },
  561. getCode(data) {
  562. let that = this
  563. getCodeApi()
  564. .then(res => {
  565. that.keyCode = res.data.key;
  566. that.code(data);
  567. })
  568. .catch(res => {
  569. that.$util.Tips({
  570. title: res
  571. });
  572. });
  573. },
  574. async loginMobile() {
  575. let that = this;
  576. if (!that.account) return that.$util.Tips({
  577. title: '请输入手机号码'
  578. });
  579. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  580. title: '请输入正确的手机号码'
  581. });
  582. if (!that.captcha) return that.$util.Tips({
  583. title: '请输入验证码'
  584. });
  585. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  586. title: '请输入正确的验证码'
  587. });
  588. if (!that.isAgree) return that.$util.Tips({
  589. title: '请勾选用户协议与隐私政策'
  590. });
  591. loginMobile({
  592. auth_token: uni.getStorageSync('auth_token'),
  593. phone: that.account,
  594. sms_code: that.captcha,
  595. spread: that.$Cache.get("spread"),
  596. // #ifdef APP-PLUS
  597. user_type: 'app',
  598. // #endif
  599. // #ifdef H5
  600. user_type: 'h5',
  601. // #endif
  602. })
  603. .then(({
  604. data
  605. }) => {
  606. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  607. that.$Cache.clear(BACK_URL);
  608. that.$store.commit("LOGIN", {
  609. 'token': data.token,
  610. 'time': data.exp
  611. });
  612. that.$store.commit("SETUID", data.user.uid);
  613. that.$store.commit('UPDATE_USERINFO', data.user);
  614. let method
  615. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  616. '/pages/user/index'
  617. ]
  618. if (indexPat.includes(this.getPath(backUrl))) {
  619. method = 'switchTab'
  620. } else {
  621. method = 'navigateTo'
  622. }
  623. if (this.getPath(backUrl) === '/pages/users/login/index') {
  624. uni.switchTab({
  625. url: '/pages/index/index'
  626. });
  627. return
  628. }
  629. uni[method]({
  630. url: backUrl
  631. });
  632. })
  633. .catch(res => {
  634. that.$util.Tips({
  635. title: res
  636. });
  637. });
  638. },
  639. async register() {
  640. let that = this;
  641. if (!that.account) return that.$util.Tips({
  642. title: '请输入手机号码'
  643. });
  644. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  645. title: '请输入正确的手机号码'
  646. });
  647. if (!that.captcha) return that.$util.Tips({
  648. title: '请输入验证码'
  649. });
  650. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  651. title: '请输入正确的验证码'
  652. });
  653. if (!that.password) return that.$util.Tips({
  654. title: '请输入密码'
  655. });
  656. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
  657. title: '请输入6-16位字母加数字组合'
  658. });
  659. if (!that.isAgree) return that.$util.Tips({
  660. title: '请勾选用户协议与隐私政策'
  661. });
  662. register({
  663. auth_token: this.auth_token || uni.getStorageSync('auth_token'),
  664. phone: that.account,
  665. sms_code: that.captcha,
  666. pwd: that.password,
  667. spread: that.$Cache.get("spread"),
  668. // #ifdef APP-PLUS
  669. user_type: 'app',
  670. // #endif
  671. // #ifdef H5
  672. user_type: 'h5',
  673. // #endif
  674. })
  675. .then(res => {
  676. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  677. that.$Cache.clear(BACK_URL);
  678. that.$store.commit("LOGIN", {
  679. 'token': res.data.token,
  680. 'time': res.data.exp
  681. });
  682. that.$store.commit("SETUID", res.data.user.uid);
  683. that.$store.commit('UPDATE_USERINFO', res.data.user);
  684. uni.switchTab({
  685. url: '/pages/user/index'
  686. })
  687. })
  688. .catch(res => {
  689. that.$util.Tips({
  690. title: res
  691. });
  692. });
  693. },
  694. async code(data) {
  695. let that = this;
  696. if (!that.account) return that.$util.Tips({
  697. title: '请输入手机号码'
  698. });
  699. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  700. title: '请输入正确的手机号码'
  701. });
  702. // if (that.formItem == 2) that.type = "register";
  703. await registerVerify({
  704. phone: that.account,
  705. type: 'login',
  706. key: that.keyCode,
  707. // code: that.codeVal,
  708. toke:data.token,
  709. captchaType: 'blockPuzzle',
  710. captchaVerification: data.captchaVerification
  711. })
  712. .then(res => {
  713. that.$util.Tips({
  714. title: res.message
  715. });
  716. that.sendCode();
  717. })
  718. .catch(res => {
  719. that.$util.Tips({
  720. title: res
  721. });
  722. });
  723. },
  724. getcaptcha() {
  725. let that = this
  726. getCaptcha().then(data => {
  727. // that.codeUrl = `${VUE_APP_API_URL}/sms_captcha?key=${that.keyCode}`;
  728. that.codeUrl = data.data.captcha;
  729. that.keyCode = data.data.key
  730. })
  731. that.isShowCode = true;
  732. },
  733. navTap: function(index) {
  734. this.current = index;
  735. },
  736. getPath(url) {
  737. if (url.indexOf("?") != -1) {
  738. url = url.split("?")[0];
  739. }
  740. return url
  741. },
  742. async submit() {
  743. let that = this;
  744. if (!that.account) return that.$util.Tips({
  745. title: '请输入账号'
  746. });
  747. if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({
  748. title: '请输入正确的账号'
  749. });
  750. if (!that.password) return that.$util.Tips({
  751. title: '请输入密码'
  752. });
  753. if (!that.isAgree) return that.$util.Tips({
  754. title: '请勾选用户协议与隐私政策'
  755. });
  756. loginH5({
  757. auth_token: uni.getStorageSync('auth_token'),
  758. account: that.account,
  759. password: that.password,
  760. spread: that.$Cache.get("spread")
  761. })
  762. .then(({
  763. data
  764. }) => {
  765. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  766. that.$Cache.clear(BACK_URL);
  767. that.$store.commit("LOGIN", {
  768. 'token': data.token,
  769. 'time': data.exp
  770. });
  771. that.$store.commit("SETUID", data.user.uid);
  772. that.$store.commit('UPDATE_USERINFO', data.user);
  773. let method
  774. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  775. '/pages/user/index'
  776. ]
  777. if (indexPat.includes(this.getPath(backUrl))) {
  778. method = 'switchTab'
  779. } else {
  780. method = 'navigateTo'
  781. }
  782. if (this.getPath(backUrl) === '/pages/users/login/index') {
  783. uni.switchTab({
  784. url: '/pages/index/index'
  785. });
  786. return
  787. }
  788. uni[method]({
  789. url: backUrl
  790. });
  791. })
  792. .catch(e => {
  793. that.$util.Tips({
  794. title: e
  795. });
  796. });
  797. },
  798. getVersion() {
  799. getVersion().then(data => {
  800. this.copyright = data.data;
  801. });
  802. },
  803. success(data) {
  804. this.$refs.verify.hide();
  805. this.code(data);
  806. },
  807. handleVerify() {
  808. let that = this;
  809. if (!that.account) return that.$util.Tips({
  810. title: '请输入手机号码'
  811. });
  812. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  813. title: '请输入正确的手机号码'
  814. });
  815. if (!that.isAgree) return that.$util.Tips({
  816. title: '请勾选用户协议与隐私政策'
  817. });
  818. that.$refs.verify.show();
  819. }
  820. }
  821. };
  822. </script>
  823. <style lang="scss" scoped>
  824. /deep/uni-checkbox .uni-checkbox-input,
  825. /deep/checkbox .wx-checkbox-input{
  826. border-radius: 100%;
  827. width: 28rpx;
  828. height: 28rpx;
  829. }
  830. /deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked,
  831. /deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  832. border: 1px solid var(--view-theme)!important;
  833. background-color: var(--view-theme)!important;
  834. }
  835. .register .whiteBg .title_info text{
  836. color: var(--view-theme);
  837. }
  838. .register .list .item .code {
  839. color: var(--view-theme);
  840. }
  841. .title-bar {
  842. position: relative;
  843. display: flex;
  844. align-items: center;
  845. justify-content: center;
  846. font-size: 34rpx;
  847. font-weight: 500;
  848. color: #333333;
  849. line-height: 48rpx;
  850. .icon {
  851. position: absolute;
  852. left: 30rpx;
  853. top: 0;
  854. display: flex;
  855. align-items: center;
  856. justify-content: center;
  857. width: 80rpx;
  858. height: 80rpx;
  859. image {
  860. width: 50rpx;
  861. height: 50rpx;
  862. }
  863. }
  864. }
  865. .code image {
  866. width: 100%;
  867. height: 100%;
  868. }
  869. .protocol_text{
  870. color: #999;
  871. font-size: 24rpx;
  872. }
  873. .protocol{
  874. margin-top: 82rpx;
  875. justify-content: center;
  876. }
  877. .protocol_text{
  878. .font_pro{
  879. color: var(--view-theme);
  880. }
  881. }
  882. .appLogin {
  883. margin-top: 82rpx;
  884. .hds {
  885. display: flex;
  886. justify-content: center;
  887. align-items: center;
  888. font-size: 24rpx;
  889. color: #B4B4B4;
  890. .line {
  891. width: 68rpx;
  892. height: 1rpx;
  893. background: #CCCCCC;
  894. }
  895. p {
  896. margin: 0 20rpx;
  897. }
  898. }
  899. .btn-wrapper {
  900. display: flex;
  901. align-items: center;
  902. justify-content: center;
  903. margin-top: 30rpx;
  904. .btn {
  905. display: flex;
  906. align-items: center;
  907. justify-content: center;
  908. width: 68rpx;
  909. height: 68rpx;
  910. border-radius: 50%;
  911. + .btn {
  912. margin-left: 30rpx;
  913. }
  914. }
  915. .apple-btn {
  916. display: flex;
  917. align-items: center;
  918. justify-content: center;
  919. width: 246rpx;
  920. height: 66rpx;
  921. margin-left: 10rpx;
  922. background: #EAEAEA;
  923. border-radius: 34rpx;
  924. font-size: 24rpx;
  925. .icon-s-pingguo {
  926. color: #333;
  927. margin-right: 10rpx;
  928. font-size: 34rpx;
  929. }
  930. }
  931. .iconfont {
  932. font-size: 40rpx;
  933. color: #fff;
  934. }
  935. .wx {
  936. background-color: #61C64F;
  937. &.btn-apple{
  938. margin-right: 0;
  939. background-color: #333;
  940. }
  941. }
  942. }
  943. }
  944. .whiteBg .logon {
  945. display: flex;
  946. align-items: center;
  947. justify-content: center;
  948. width: 100%;
  949. height: 86rpx;
  950. margin-top: 48rpx;
  951. background-color: var(--view-theme);
  952. border-radius: 120rpx;
  953. color: #FFFFFF;
  954. font-size: 30rpx;
  955. }
  956. .whiteBg .back{
  957. border: 1px solid var(--view-theme);
  958. color: var(--view-theme);
  959. margin-top: 30rpx;
  960. background-color: transparent;
  961. }
  962. .copyright {
  963. position: fixed;
  964. bottom: 30rpx;
  965. left: 0;
  966. width: 100%;
  967. text-align: center;
  968. font-size: 20rpx;
  969. line-height: 28rpx;
  970. color: #9E9E9E;
  971. }
  972. </style>