index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <view class="wrapper" :style="colorStyle">
  3. <view class="bag">
  4. <img :src="imgHost+'/statics/images/users/login-bg.jpg'" alt="" srcset="">
  5. </view>
  6. <view class="system-height" :style="{ height: statusBarHeight }"></view>
  7. <!-- #ifdef MP -->
  8. <view class="title-bar" style="height: 43px;">
  9. <view class="icon" @click="back" v-if="!isHome">
  10. <image src="../static/left.png"></image>
  11. </view>
  12. <view class="icon" @click="home" v-else>
  13. <image src="../static/home.png"></image>
  14. </view>
  15. {{pageTitle}}
  16. </view>
  17. <!-- #endif -->
  18. <view class="page-msg">
  19. <view class="title">
  20. {{pageType == 1?'绑定手机号':'手机号登录'}}
  21. </view>
  22. <view class="tip">
  23. {{pageType == 1?'登录注册需绑定手机号':'首次登录会自动注册'}}
  24. </view>
  25. </view>
  26. <view class="page-form">
  27. <view class="item">
  28. <input type='number' placeholder='填写手机号码' placeholder-class='placeholder' v-model="phone"
  29. :maxlength="11"></input>
  30. </view>
  31. <view class="item acea-row row-between-wrapper">
  32. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' :maxlength="6"
  33. class="codeIput" v-model="captcha"></input>
  34. <view class="line">
  35. </view>
  36. <button class="code font-num" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  37. {{ text }}
  38. </button>
  39. </view>
  40. <view class="btn" @click="submitData">
  41. {{pageType == 1 ? '绑定手机号' : '立即登录'}}
  42. </view>
  43. </view>
  44. <view class="protocol" v-if="pageType == 0 && !canGetPrivacySetting">
  45. <checkbox-group @click.stop='ChangeIsDefault'>
  46. <checkbox :class="inAnimation?'trembling':''" @animationend='inAnimation=false'
  47. :checked="protocol ? true : false" /> <text @click.stop='ChangeIsDefault'>已阅读并同意</text>
  48. <text class="main-color" @click.stop="privacy('user')">《用户协议》</text>
  49. 与<text class="main-color" @click.stop="privacy('privacy')">《隐私协议》</text>
  50. </checkbox-group>
  51. </view>
  52. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }"
  53. ref="verify"></Verify>
  54. <editUserModal :isShow="isShow" @closeEdit="closeEdit" @editSuccess="editSuccess">
  55. </editUserModal>
  56. <!-- #ifdef MP -->
  57. <privacyAgreementPopup v-if="canGetPrivacySetting" @onReject="onReject" @onAgree="onAgree">
  58. </privacyAgreementPopup>
  59. <!-- #endif -->
  60. </view>
  61. </template>
  62. <script>
  63. const app = getApp();
  64. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  65. import { HTTP_REQUEST_URL } from '@/config/app';
  66. import sendVerifyCode from "@/mixins/SendVerifyCode";
  67. import colors from '@/mixins/color.js';
  68. import editUserModal from '@/components/eidtUserModal/index.vue'
  69. import privacyAgreementPopup from '@/components/privacyAgreementPopup/index.vue'
  70. import {
  71. bindingUserPhone,
  72. verifyCode,
  73. registerVerify,
  74. updatePhone
  75. } from '@/api/api.js';
  76. import {
  77. loginMobile,
  78. getCodeApi,
  79. getUserInfo,
  80. phoneSilenceAuth
  81. } from "@/api/user.js";
  82. import {
  83. phoneLogin,
  84. wechatBindingPhone
  85. } from '@/api/public.js'
  86. import Routine from '@/libs/routine';
  87. import Verify from '../components/verify/verify.vue';
  88. import Cache from '@/utils/cache';
  89. export default {
  90. mixins: [sendVerifyCode, colors],
  91. components: {
  92. Verify,
  93. editUserModal,
  94. privacyAgreementPopup
  95. },
  96. data() {
  97. return {
  98. imgHost: HTTP_REQUEST_URL,
  99. statusBarHeight: statusBarHeight,
  100. pageType: 1, // 0 登录 1 绑定手机
  101. phone: '',
  102. captcha: '',
  103. text: '获取验证码',
  104. isShow: false,
  105. protocol: false,
  106. inAnimation: false,
  107. authKey: "",
  108. backUrl: "",
  109. pageTitle: '绑定手机号',
  110. configData: Cache.get('BASIC_CONFIG'),
  111. canGetPrivacySetting: false,
  112. }
  113. },
  114. onLoad(options) {
  115. // #ifdef MP
  116. if (wx.getPrivacySetting) {
  117. this.canGetPrivacySetting = true
  118. }
  119. // #endif
  120. if (options.authKey) {
  121. this.authKey = options.authKey
  122. }
  123. this.backUrl = options.backUrl || ''
  124. if (options.pageType) {
  125. this.pageType = options.pageType || 1
  126. this.pageTitle = options.pageType == 1 ? '绑定手机号' : '手机号登录'
  127. }
  128. let pages = getCurrentPages();
  129. let prePage = pages[pages.length - 2];
  130. if (prePage && prePage.route == 'pages/order_addcart/order_addcart') {
  131. this.isHome = true;
  132. } else {
  133. this.isHome = false;
  134. }
  135. },
  136. methods: {
  137. onAgree() {
  138. this.protocol = true
  139. },
  140. submitData() {
  141. let that = this;
  142. if (this.pageType == 0) {
  143. this.isLogin()
  144. return
  145. }
  146. if (!this.rules()) return
  147. if (!this.authKey) {
  148. let key = this.$Cache.get('snsapiKey');
  149. this.phoneAuth(key)
  150. } else {
  151. this.phoneAuth(this.authKey)
  152. }
  153. },
  154. rules() {
  155. let that = this;
  156. if (!this.protocol && this.pageType == 0) {
  157. this.$util.Tips({
  158. title: '请先阅读并同意协议'
  159. });
  160. return false
  161. }
  162. if (!that.phone) {
  163. this.$util.Tips({
  164. title: '请填写手机号码'
  165. });
  166. return false
  167. }
  168. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) {
  169. this.$util.Tips({
  170. title: '请输入正确的手机号码'
  171. });
  172. return false
  173. }
  174. if (!that.captcha) {
  175. this.$util.Tips({
  176. title: '请填写验证码'
  177. });
  178. return false
  179. }
  180. return true
  181. },
  182. isLogin() {
  183. if (!this.rules()) return
  184. uni.showLoading({
  185. title: '正在登录中'
  186. });
  187. Routine.getCode()
  188. .then(code => {
  189. phoneLogin({
  190. code,
  191. spread_spid: app.globalData.spid,
  192. spread_code: app.globalData.code,
  193. phone: this.phone,
  194. captcha: this.captcha,
  195. }).then(res => {
  196. uni.hideLoading();
  197. let time = res.data.expires_time - this.$Cache.time();
  198. this.$store.commit('LOGIN', {
  199. token: res.data.token,
  200. time: time
  201. });
  202. this.getUserInfo(res.data.store_user_avatar);
  203. })
  204. .catch(err => {
  205. uni.hideLoading();
  206. uni.showToast({
  207. title: err,
  208. icon: 'none',
  209. duration: 2000
  210. });
  211. });
  212. })
  213. .catch(err => {
  214. console.log(err)
  215. });
  216. },
  217. phoneAuth(key) {
  218. uni.showLoading({
  219. title: '正在登录中'
  220. });
  221. let met
  222. // #ifdef MP
  223. met = phoneLogin
  224. // #endif
  225. // #ifndef MP
  226. met = wechatBindingPhone
  227. // #endif
  228. met({
  229. phone: this.phone,
  230. captcha: this.captcha,
  231. key
  232. }).then(res => {
  233. let time = res.data.expires_time - this.$Cache.time();
  234. this.$store.commit('LOGIN', {
  235. token: res.data.token,
  236. time: time
  237. });
  238. this.getUserInfo(res.data.store_user_avatar);
  239. }).catch(error => {
  240. uni.hideLoading()
  241. this.$util.Tips({
  242. title: error
  243. })
  244. })
  245. },
  246. /**
  247. * 获取个人用户信息
  248. */
  249. getUserInfo(new_user) {
  250. let that = this;
  251. getUserInfo().then(res => {
  252. uni.hideLoading();
  253. that.userInfo = res.data;
  254. that.$store.commit('SETUID', res.data.uid);
  255. that.$store.commit('UPDATE_USERINFO', res.data);
  256. if (new_user) {
  257. this.isShow = true
  258. } else {
  259. // #ifdef MP
  260. that.$util.Tips({
  261. title: '登录成功',
  262. icon: 'success'
  263. }, {
  264. tab: 3,
  265. url: this.configData.wechat_auth_switch ? 2 : 1
  266. });
  267. // #endif
  268. // #ifndef MP
  269. // that.$util.Tips({
  270. // title: '登录成功',
  271. // icon: 'success'
  272. // }, {
  273. // tab: 4,
  274. // url: this.backUrl || '/pages/user/index'
  275. // });
  276. that.wechatPhone();
  277. // #endif
  278. }
  279. });
  280. },
  281. wechatPhone() {
  282. this.$Cache.clear('snsapiKey');
  283. if (this.backUrl) {
  284. let url = uni.getStorageSync('snRouter');
  285. if (!url) {
  286. url = '/pages/index/index';
  287. }
  288. this.$util.Tips({
  289. title: '登录成功',
  290. icon: 'success'
  291. }, {
  292. tab: 4,
  293. url: this.url || '/pages/user/index'
  294. });
  295. } else {
  296. uni.reLaunch({
  297. url: '/pages/user/index'
  298. })
  299. }
  300. },
  301. success(data) {
  302. this.$refs.verify.hide()
  303. let that = this;
  304. verifyCode().then(res => {
  305. let obj ={
  306. phone: that.phone,
  307. type: 'reset',
  308. key: res.data.key,
  309. captchaType: 'blockPuzzle',
  310. captchaVerification: data.captchaVerification
  311. }
  312. registerVerify(obj)
  313. .then(res => {
  314. that.$util.Tips({
  315. title: res.msg
  316. });
  317. that.sendCode();
  318. }).catch(err => {
  319. return that.$util.Tips({
  320. title: err
  321. });
  322. });
  323. });
  324. },
  325. /**
  326. * 发送验证码
  327. *
  328. */
  329. async code() {
  330. let that = this;
  331. if (!that.phone) return that.$util.Tips({
  332. title: '请填写手机号码'
  333. });
  334. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  335. title: '请输入正确的手机号码'
  336. });
  337. this.$refs.verify.show();
  338. return;
  339. },
  340. ChangeIsDefault() {
  341. this.$set(this, 'protocol', !this.protocol);
  342. },
  343. closeEdit() {
  344. this.isShow = false
  345. this.$util.Tips({
  346. title: '登录成功',
  347. icon: 'success'
  348. }, {
  349. tab: 3,
  350. url: 2
  351. });
  352. },
  353. editSuccess() {
  354. this.isShow = false
  355. },
  356. back() {
  357. uni.navigateBack({
  358. delta: this.configData.wechat_auth_switch ? 2 : 1
  359. })
  360. },
  361. privacy(type) {
  362. uni.navigateTo({
  363. url: "/pages/users/privacy/index?type=" + type
  364. })
  365. },
  366. }
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. .wrapper {
  371. background-color: #fff;
  372. min-height: 100vh;
  373. position: relative;
  374. .bag {
  375. position: absolute;
  376. top: 0;
  377. left: 0;
  378. width: 100%;
  379. z-index: 0;
  380. /* #ifdef H5 */
  381. z-index: 0;
  382. /* #endif */
  383. img {
  384. width: 100%;
  385. height: 544rpx;
  386. }
  387. }
  388. .page-msg {
  389. padding-top: 160rpx;
  390. margin-left: 72rpx;
  391. z-index: 2;
  392. position: relative;
  393. .title {
  394. font-size: 48rpx;
  395. font-weight: 500;
  396. color: #333333;
  397. line-height: 68rpx;
  398. }
  399. .tip {
  400. font-size: 28rpx;
  401. font-weight: 400;
  402. color: #333333;
  403. line-height: 40rpx;
  404. }
  405. }
  406. .page-form {
  407. width: 606rpx;
  408. margin: 100rpx auto 0 auto;
  409. z-index: 2;
  410. position: relative;
  411. .item {
  412. width: 100%;
  413. height: 88rpx;
  414. background: #F5F5F5;
  415. border-radius: 45rpx;
  416. padding: 24rpx 48rpx;
  417. margin-bottom: 32rpx;
  418. input {
  419. width: 100%;
  420. height: 100%;
  421. font-size: 32rpx;
  422. }
  423. .placeholder {
  424. color: #BBBBBB;
  425. font-size: 28rpx;
  426. }
  427. input.codeIput {
  428. width: 300rpx;
  429. }
  430. .line {
  431. width: 2rpx;
  432. height: 28rpx;
  433. background: #CCCCCC;
  434. }
  435. .code {
  436. font-size: 28rpx;
  437. color: var(--view-theme);
  438. background-color: rgba(255, 255, 255, 0);
  439. }
  440. .code.on {
  441. color: #BBBBBB !important;
  442. }
  443. }
  444. .btn {
  445. width: 606rpx;
  446. height: 88rpx;
  447. background: var(--view-theme);
  448. border-radius: 200rpx 200rpx 200rpx 200rpx;
  449. display: flex;
  450. justify-content: center;
  451. align-items: center;
  452. font-size: 32rpx;
  453. font-family: PingFang SC-Regular, PingFang SC;
  454. font-weight: 400;
  455. color: #FFFFFF;
  456. line-height: 44rpx;
  457. margin-top: 48rpx;
  458. letter-spacing: 1px;
  459. }
  460. }
  461. }
  462. .title-bar {
  463. position: relative;
  464. display: flex;
  465. align-items: center;
  466. justify-content: center;
  467. font-size: 34rpx;
  468. font-weight: 500;
  469. color: #333333;
  470. line-height: 48rpx;
  471. }
  472. .icon {
  473. position: absolute;
  474. left: 30rpx;
  475. top: 0;
  476. display: flex;
  477. align-items: center;
  478. justify-content: center;
  479. width: 86rpx;
  480. height: 86rpx;
  481. image {
  482. width: 40rpx;
  483. height: 40rpx;
  484. }
  485. }
  486. .protocol {
  487. position: fixed;
  488. bottom: 52rpx;
  489. left: 0;
  490. width: 100%;
  491. margin: 0 auto;
  492. color: #999999;
  493. font-size: 24rpx;
  494. line-height: 22rpx;
  495. text-align: center;
  496. bottom: calc(52rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  497. bottom: calc(52rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  498. .main-color {
  499. color: var(--view-theme);
  500. }
  501. .trembling {
  502. animation: shake 0.6s;
  503. }
  504. }
  505. /deep/ uni-checkbox .uni-checkbox-input {
  506. width: 28rpx;
  507. height: 28rpx;
  508. }
  509. /deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked::before {
  510. font-size: 24rpx;
  511. }
  512. /deep/ uni-checkbox .uni-checkbox-wrapper {
  513. margin-bottom: 1px;
  514. }
  515. /*checkbox 选项框大小 */
  516. /deep/ checkbox .wx-checkbox-input {
  517. width: 28rpx;
  518. height: 28rpx;
  519. }
  520. /*checkbox选中后样式 */
  521. /deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  522. background: white;
  523. }
  524. /*checkbox选中后图标样式 */
  525. /deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  526. width: 28rpx;
  527. height: 28rpx;
  528. line-height: 28rpx;
  529. text-align: center;
  530. font-size: 22rpx;
  531. background: transparent;
  532. transform: translate(-50%, -50%) scale(1);
  533. -webkit-transform: translate(-50%, -50%) scale(1);
  534. }
  535. </style>