index.vue 12 KB

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