index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  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. {{$t(pageTitle)}}
  14. </view>
  15. <!-- #endif -->
  16. <view class="page-msg">
  17. <view class="title">
  18. {{pageType == 1?$t('绑定手机号'):$t('手机号登录')}}
  19. </view>
  20. <view class="tip">
  21. {{pageType == 1?$t('登录注册需绑定手机号'):$t('首次登录会自动注册')}}
  22. </view>
  23. </view>
  24. <view class="page-form">
  25. <view class="item">
  26. <input type='number' :placeholder='$t(`填写手机号码`)' 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='$t(`填写验证码`)' 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. {{$t(`${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'>{{$t(`已阅读并同意`)}}</text>
  46. <text class="main-color" @click.stop="privacy(4)">{{$t(`《用户协议》`)}}</text>
  47. {{$t(`与`)}}<text class="main-color" @click.stop="privacy(3)">{{$t(`《隐私协议》`)}}</text>
  48. </checkbox-group>
  49. </view>
  50. <Verify @success="success" :captchaType="'clickWord'" :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/index.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. if (options.authKey) {
  112. this.authKey = options.authKey
  113. }
  114. // #ifdef MP
  115. if (wx.getPrivacySetting) {
  116. this.canGetPrivacySetting = true
  117. }
  118. // #endif
  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. uni.showToast({
  154. title: this.$t('请先阅读并同意协议'),
  155. icon: 'none',
  156. duration: 2000
  157. });
  158. return false
  159. }
  160. if (!that.phone) {
  161. that.$util.Tips({
  162. title: that.$t(`请填写手机号码`)
  163. });
  164. return false
  165. }
  166. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) {
  167. that.$util.Tips({
  168. title: that.$t(`请输入正确的手机号码`)
  169. });
  170. return false
  171. }
  172. if (!that.captcha) {
  173. return that.$util.Tips({
  174. title: that.$t(`请填写验证码`)
  175. });
  176. return false
  177. }
  178. return true
  179. },
  180. isLogin() {
  181. if (!this.rules()) return
  182. uni.showLoading({
  183. title: this.$t(`正在登录中`)
  184. });
  185. Routine.getCode()
  186. .then(code => {
  187. phoneLogin({
  188. code,
  189. spread_spid: app.globalData.spid,
  190. spread_code: app.globalData.code,
  191. phone: this.phone,
  192. captcha: this.captcha,
  193. }).then(res => {
  194. uni.hideLoading();
  195. let time = res.data.expires_time - this.$Cache.time();
  196. this.$store.commit('LOGIN', {
  197. token: res.data.token,
  198. time: time
  199. });
  200. this.getUserInfo(res.data.bindName);
  201. })
  202. .catch(err => {
  203. uni.hideLoading();
  204. uni.showToast({
  205. title: err,
  206. icon: 'none',
  207. duration: 2000
  208. });
  209. });
  210. })
  211. .catch(err => {
  212. console.log(err)
  213. });
  214. },
  215. phoneAuth(key) {
  216. uni.showLoading({
  217. title: this.$t(`正在登录中`)
  218. });
  219. let met
  220. // #ifdef MP
  221. met = phoneLogin
  222. // #endif
  223. // #ifndef MP
  224. met = wechatBindingPhone
  225. // #endif
  226. met({
  227. phone: this.phone,
  228. captcha: this.captcha,
  229. key
  230. }).then(res => {
  231. let time = res.data.expires_time - this.$Cache.time();
  232. this.$store.commit('LOGIN', {
  233. token: res.data.token,
  234. time: time
  235. });
  236. this.getUserInfo(res.data.bindName);
  237. }).catch(error => {
  238. uni.hideLoading()
  239. this.$util.Tips({
  240. title: error
  241. })
  242. })
  243. },
  244. /**
  245. * 获取个人用户信息
  246. */
  247. getUserInfo(new_user) {
  248. let that = this;
  249. getUserInfo().then(res => {
  250. uni.hideLoading();
  251. that.userInfo = res.data;
  252. that.$store.commit('SETUID', res.data.uid);
  253. that.$store.commit('UPDATE_USERINFO', res.data);
  254. if (new_user) {
  255. this.isShow = true
  256. } else {
  257. // #ifdef MP
  258. that.$util.Tips({
  259. title: that.$t(`登录成功`),
  260. icon: 'success'
  261. }, {
  262. tab: 3,
  263. url: this.configData.wechat_auth_switch ? 2 : 1
  264. });
  265. // #endif
  266. // #ifndef MP
  267. that.$util.Tips({
  268. title: that.$t(`登录成功`),
  269. icon: 'success'
  270. }, {
  271. url: this.backUrl || 'pages/user/index'
  272. });
  273. // #endif
  274. }
  275. });
  276. },
  277. success(data) {
  278. this.$refs.verify.hide()
  279. let that = this;
  280. verifyCode().then(res => {
  281. registerVerify(that.phone, 'reset', res.data.key, this.captchaType, data.captchaVerification)
  282. .then(res => {
  283. that.$util.Tips({
  284. title: res.msg
  285. });
  286. that.sendCode();
  287. }).catch(err => {
  288. return that.$util.Tips({
  289. title: err
  290. });
  291. });
  292. });
  293. },
  294. /**
  295. * 发送验证码
  296. *
  297. */
  298. async code() {
  299. let that = this;
  300. if (!that.phone) return that.$util.Tips({
  301. title: that.$t(`请填写手机号码`)
  302. });
  303. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  304. title: that.$t(`请输入正确的手机号码`)
  305. });
  306. this.$refs.verify.show();
  307. return;
  308. },
  309. ChangeIsDefault() {
  310. this.$set(this, 'protocol', !this.protocol);
  311. },
  312. closeEdit() {
  313. this.isShow = false
  314. this.$util.Tips({
  315. title: this.$t(`登录成功`),
  316. icon: 'success'
  317. }, {
  318. tab: 3,
  319. url: 2
  320. });
  321. },
  322. editSuccess() {
  323. this.isShow = false
  324. },
  325. back() {
  326. uni.navigateBack({
  327. delta: this.configData.wechat_auth_switch ? 2 : 1
  328. })
  329. },
  330. privacy(type) {
  331. uni.navigateTo({
  332. url: "/pages/users/privacy/index?type=" + type
  333. })
  334. },
  335. }
  336. }
  337. </script>
  338. <style lang="scss" scoped>
  339. .wrapper {
  340. background-color: #fff;
  341. min-height: 100vh;
  342. position: relative;
  343. .bag {
  344. position: absolute;
  345. top: 0;
  346. left: 0;
  347. width: 750rpx;
  348. height: 460rpx;
  349. background: var(--view-linear);
  350. }
  351. .page-msg {
  352. padding-top: 160rpx;
  353. margin-left: 72rpx;
  354. .title {
  355. font-size: 48rpx;
  356. font-weight: 500;
  357. color: #333333;
  358. line-height: 68rpx;
  359. }
  360. .tip {
  361. font-size: 28rpx;
  362. font-weight: 400;
  363. color: #333333;
  364. line-height: 40rpx;
  365. }
  366. }
  367. .page-form {
  368. width: 606rpx;
  369. margin: 100rpx auto 0 auto;
  370. .item {
  371. width: 100%;
  372. height: 88rpx;
  373. background: #F5F5F5;
  374. border-radius: 45rpx;
  375. padding: 24rpx 48rpx;
  376. margin-bottom: 32rpx;
  377. input {
  378. width: 100%;
  379. height: 100%;
  380. font-size: 32rpx;
  381. }
  382. .placeholder {
  383. color: #BBBBBB;
  384. font-size: 28rpx;
  385. }
  386. input.codeIput {
  387. width: 300rpx;
  388. }
  389. .line {
  390. width: 2rpx;
  391. height: 28rpx;
  392. background: #CCCCCC;
  393. }
  394. .code {
  395. font-size: 28rpx;
  396. color: var(--view-theme);
  397. background-color: rgba(255, 255, 255, 0);
  398. }
  399. .code.on {
  400. color: #BBBBBB !important;
  401. }
  402. }
  403. .btn {
  404. width: 606rpx;
  405. height: 88rpx;
  406. background: var(--view-theme);
  407. border-radius: 200rpx 200rpx 200rpx 200rpx;
  408. display: flex;
  409. justify-content: center;
  410. align-items: center;
  411. font-size: 32rpx;
  412. font-family: PingFang SC-Regular, PingFang SC;
  413. font-weight: 400;
  414. color: #FFFFFF;
  415. line-height: 44rpx;
  416. margin-top: 48rpx;
  417. letter-spacing: 1px;
  418. }
  419. }
  420. }
  421. .title-bar {
  422. position: relative;
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. font-size: 34rpx;
  427. font-weight: 500;
  428. color: #333333;
  429. line-height: 48rpx;
  430. }
  431. .icon {
  432. position: absolute;
  433. left: 30rpx;
  434. top: 0;
  435. display: flex;
  436. align-items: center;
  437. justify-content: center;
  438. width: 80rpx;
  439. height: 80rpx;
  440. image {
  441. width: 35rpx;
  442. height: 35rpx;
  443. }
  444. }
  445. .protocol {
  446. position: fixed;
  447. bottom: 52rpx;
  448. left: 0;
  449. width: 100%;
  450. margin: 0 auto;
  451. color: #999999;
  452. font-size: 24rpx;
  453. line-height: 22rpx;
  454. text-align: center;
  455. bottom: calc(52rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  456. bottom: calc(52rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  457. .main-color {
  458. color: var(--view-theme);
  459. }
  460. .trembling {
  461. animation: shake 0.6s;
  462. }
  463. }
  464. /deep/ uni-checkbox .uni-checkbox-input {
  465. width: 28rpx;
  466. height: 28rpx;
  467. }
  468. /deep/ uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked::before {
  469. font-size: 24rpx;
  470. }
  471. /deep/ uni-checkbox .uni-checkbox-wrapper {
  472. margin-bottom: 1px;
  473. }
  474. /*checkbox 选项框大小 */
  475. /deep/ checkbox .wx-checkbox-input {
  476. width: 28rpx;
  477. height: 28rpx;
  478. }
  479. /*checkbox选中后样式 */
  480. /deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  481. background: white;
  482. }
  483. /*checkbox选中后图标样式 */
  484. /deep/ checkbox .wx-checkbox-input.wx-checkbox-input-checked::before {
  485. width: 28rpx;
  486. height: 28rpx;
  487. line-height: 28rpx;
  488. text-align: center;
  489. font-size: 22rpx;
  490. background: transparent;
  491. transform: translate(-50%, -50%) scale(1);
  492. -webkit-transform: translate(-50%, -50%) scale(1);
  493. }
  494. </style>