register.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <template>
  2. <view class="login-wrapper" :style="colorStyle">
  3. <view class="login-top"></view>
  4. <view class="shading">
  5. <image :src="logoUrl" v-if="logoUrl" />
  6. <image src="../static/logo2.png" v-else />
  7. </view>
  8. <view class="whiteBg">
  9. <view class="tips">
  10. <view class="tips-btn on">
  11. <view>注册账号</view>
  12. <view class="line"></view>
  13. </view>
  14. </view>
  15. <view class="list">
  16. <view class="item">
  17. <view class="acea-row row-middle">
  18. <image src="../static/phone_1.png" class="itemImg-add"></image>
  19. <input type="text" placeholder="输入手机号码" v-model="account" maxlength="11" />
  20. </view>
  21. </view>
  22. <view class="item">
  23. <view class="acea-row row-middle">
  24. <image src="../static/phone_1.png" class="itemImg-add"></image>
  25. <input type="text" placeholder="输入邀请码" v-model="spread_spid" maxlength="11" />
  26. </view>
  27. </view>
  28. <view class="item">
  29. <view class="acea-row row-middle">
  30. <image src="../static/code_2.png" class="item-img"></image>
  31. <input type="text" placeholder="填写验证码" maxlength="6" class="codeIput" v-model="captcha" />
  32. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  33. {{ text }}
  34. </button>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="logon" @click="loginMobile">注册</view>
  39. <!-- #ifdef H5 -->
  40. <view class="logon" style="margin-top: 20rpx;" @click="domApp">下载APP</view>
  41. <!-- #endif -->
  42. <view class="protocol">
  43. <checkbox-group @change='ChangeIsDefault'>
  44. <checkbox :class="inAnimation?'trembling':''" @animationend='inAnimation=false'
  45. :checked="protocol ? true : false" />已阅读并同意 <text class="main-color"
  46. @click="privacy('user')">《用户协议》</text>
  47. 与<text class="main-color" @click="privacy('privacy ')">《隐私协议》</text>
  48. </checkbox-group>
  49. </view>
  50. </view>
  51. <view class="bottom"></view>
  52. <Verify @success="success" :captchaType="'blockPuzzle'" :imgSize="{ width: '330px', height: '155px' }"
  53. ref="verify"></Verify>
  54. <view class="copyright" v-if="copyrightContext">{{copyrightContext}}</view>
  55. </view>
  56. </template>
  57. <script>
  58. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  59. import sendVerifyCode from "@/mixins/SendVerifyCode";
  60. import {
  61. getAppVersion
  62. } from '@/api/api.js';
  63. import {
  64. loginMobile,
  65. registerVerify,
  66. getCodeApi,
  67. getUserInfo,
  68. } from "@/api/user";
  69. import attrs, {
  70. required,
  71. alpha_num,
  72. chs_phone
  73. } from "@/utils/validate";
  74. import {
  75. validatorDefaultCatch
  76. } from "@/utils/dialog";
  77. import {
  78. getLogo
  79. } from "@/api/public";
  80. // import cookie from "@/utils/store/cookie";
  81. import {
  82. VUE_APP_API_URL
  83. } from "@/utils";
  84. // #ifdef APP-PLUS
  85. import {
  86. wechatAppAuth
  87. } from '@/api/api.js'
  88. // #endif
  89. const BACK_URL = "login_back_url";
  90. import colors from '@/mixins/color.js';
  91. import Verify from '../components/verify/verify.vue';
  92. export default {
  93. name: "Login",
  94. components: {
  95. Verify
  96. },
  97. mixins: [sendVerifyCode, colors],
  98. data: function() {
  99. return {
  100. inAnimation: false,
  101. protocol: false,
  102. account: "",
  103. password: "",
  104. spread_spid: '',
  105. captcha: "",
  106. type: "login",
  107. logoUrl: "",
  108. keyCode: "",
  109. keyLock: true,
  110. copyrightContext: ''
  111. };
  112. },
  113. onLoad(res) {
  114. let self = this;
  115. if (res.spid) {
  116. self.spread_spid = res.spid;
  117. }
  118. },
  119. mounted: function() {
  120. // this.getCode();
  121. this.getLogoImage();
  122. this.spread_spid = this.$Cache.get("spid");
  123. if (!this.spid) {
  124. this.spread_spid = this.$Cache.get("spid");
  125. }
  126. },
  127. methods: {
  128. // #ifdef H5
  129. domApp() {
  130. const bool = navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger';
  131. if (bool) {
  132. uni.showModal({
  133. title: '提示',
  134. content: '无法在微信中下载,请用浏览器打开下载',
  135. showCancel: false,
  136. });
  137. } else {
  138. getAppVersion().then((res) => {
  139. console.log(res, 'res');
  140. window.open(res.data.apk)
  141. }).catch((err) => {
  142. console.log(err, 'err');
  143. })
  144. }
  145. },
  146. // #endif
  147. ChangeIsDefault(e) {
  148. this.$set(this, 'protocol', !this.protocol);
  149. },
  150. success(data) {
  151. this.$refs.verify.hide()
  152. getCodeApi()
  153. .then(res => {
  154. this.keyCode = res.data.key;
  155. this.getCode(data);
  156. })
  157. .catch(res => {
  158. this.$util.Tips({
  159. title: res
  160. });
  161. });
  162. },
  163. code() {
  164. let that = this
  165. if (!that.protocol) {
  166. this.inAnimation = true
  167. return that.$util.Tips({
  168. title: '请先阅读并同意协议'
  169. });
  170. }
  171. if (!that.account) return that.$util.Tips({
  172. title: '请填写手机号码'
  173. });
  174. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  175. title: '请输入正确的手机号码'
  176. });
  177. this.$refs.verify.show()
  178. },
  179. async getLogoImage() {
  180. let that = this;
  181. getLogo(2).then(res => {
  182. that.logoUrl = res.data.logo_url;
  183. that.copyrightContext = res.data.copyrightContext;
  184. });
  185. },
  186. async loginMobile() {
  187. let that = this;
  188. if (!that.protocol) {
  189. this.inAnimation = true
  190. return that.$util.Tips({
  191. title: '请先阅读并同意协议'
  192. });
  193. }
  194. if (!that.account) return that.$util.Tips({
  195. title: '请填写手机号码'
  196. });
  197. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  198. title: '请输入正确的手机号码'
  199. });
  200. if (!that.captcha) return that.$util.Tips({
  201. title: '请填写验证码'
  202. });
  203. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  204. title: '请输入正确的验证码'
  205. });
  206. if (this.keyLock) {
  207. this.keyLock = !this.keyLock
  208. } else {
  209. return that.$util.Tips({
  210. title: '请勿重复点击'
  211. });
  212. }
  213. loginMobile({
  214. phone: that.account,
  215. captcha: that.captcha,
  216. spread_spid: that.spread_spid
  217. })
  218. .then(res => {
  219. let data = res.data;
  220. that.$store.commit("LOGIN", {
  221. 'token': data.token,
  222. 'time': data.expires_time - this.$Cache.time()
  223. });
  224. let backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  225. that.$Cache.clear(BACK_URL);
  226. uni.showToast({
  227. title: '注册成功'
  228. });
  229. getUserInfo().then(res => {
  230. this.keyLock = true
  231. that.$store.commit("SETUID", res.data.uid);
  232. that.$store.commit("UPDATE_USERINFO", res.data);
  233. if (backUrl.indexOf('/pages/users/login/index') !== -1) {
  234. backUrl = '/pages/index/index';
  235. }
  236. // uni.reLaunch({
  237. // url: backUrl
  238. // });
  239. })
  240. })
  241. .catch(res => {
  242. this.keyLock = true
  243. that.$util.Tips({
  244. title: res
  245. });
  246. });
  247. },
  248. async getCode(data) {
  249. console.log('data-------', data);
  250. let that = this;
  251. if (!that.account) return that.$util.Tips({
  252. title: '请填写手机号码'
  253. });
  254. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  255. title: '请输入正确的手机号码'
  256. });
  257. await registerVerify({
  258. phone: that.account,
  259. type: that.type,
  260. key: that.keyCode,
  261. captchaType: 'blockPuzzle',
  262. captchaVerification: data.captchaVerification
  263. })
  264. .then(res => {
  265. that.$util.Tips({
  266. title: res.msg
  267. });
  268. that.sendCode();
  269. })
  270. .catch(res => {
  271. that.$util.Tips({
  272. title: res
  273. });
  274. });
  275. },
  276. privacy(type) {
  277. uni.navigateTo({
  278. url: "/pages/users/privacy/index?type=" + type
  279. })
  280. }
  281. }
  282. };
  283. </script>
  284. <style lang="scss">
  285. .copyright {
  286. width: 650rpx;
  287. position: fixed;
  288. bottom: 30rpx;
  289. left: 50%;
  290. margin-left: -325rpx;
  291. font-size: 20rpx;
  292. color: #999999;
  293. text-align: center;
  294. .domain {
  295. color: #478BF1;
  296. margin-left: 6rpx;
  297. }
  298. }
  299. .itemImg-add {
  300. width: 24rpx;
  301. height: 34rpx;
  302. }
  303. .item-img {
  304. width: 28rpx;
  305. height: 32rpx;
  306. }
  307. /deep/uni-checkbox .uni-checkbox-input {
  308. margin-top: -6rpx;
  309. }
  310. .appLogin {
  311. margin-top: 60rpx;
  312. .hds {
  313. display: flex;
  314. justify-content: center;
  315. align-items: center;
  316. font-size: 24rpx;
  317. color: #B4B4B4;
  318. .line {
  319. width: 68rpx;
  320. height: 1rpx;
  321. background: #CCCCCC;
  322. }
  323. p {
  324. margin: 0 20rpx;
  325. }
  326. }
  327. .btn-wrapper {
  328. display: flex;
  329. align-items: center;
  330. justify-content: center;
  331. margin-top: 30rpx;
  332. .btn {
  333. display: flex;
  334. align-items: center;
  335. justify-content: center;
  336. width: 68rpx;
  337. height: 68rpx;
  338. border-radius: 50%;
  339. }
  340. .apple-btn {
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. width: 246rpx;
  345. height: 66rpx;
  346. margin-left: 30rpx;
  347. background: #EAEAEA;
  348. border-radius: 34rpx;
  349. font-size: 24rpx;
  350. .icon-s-pingguo {
  351. color: #333;
  352. margin-right: 10rpx;
  353. font-size: 34rpx;
  354. }
  355. }
  356. .iconfont {
  357. font-size: 40rpx;
  358. color: #fff;
  359. }
  360. .wx {
  361. background-color: #61C64F;
  362. }
  363. .mima {
  364. background-color: #28B3E9;
  365. }
  366. .yanzheng {
  367. background-color: #F89C23;
  368. }
  369. .pingguo {
  370. margin-left: 60rpx;
  371. background-color: #000;
  372. }
  373. }
  374. }
  375. .main-color {
  376. color: var(--view-theme);
  377. }
  378. .code img {
  379. width: 100%;
  380. height: 100%;
  381. }
  382. .acea-row.row-middle {
  383. input {
  384. margin-left: 20rpx;
  385. display: block;
  386. }
  387. }
  388. .login-wrapper {
  389. .login-top {
  390. height: 358rpx;
  391. background-color: var(--view-theme);
  392. background-image: url(../static/login.png);
  393. background-size: cover;
  394. background-repeat: no-repeat;
  395. image {
  396. width: 101%;
  397. height: 100%;
  398. }
  399. }
  400. .shading {
  401. display: flex;
  402. align-items: center;
  403. justify-content: center;
  404. width: 100%;
  405. margin-top: -230rpx;
  406. position: relative;
  407. z-index: 8;
  408. image {
  409. width: 180rpx;
  410. height: 180rpx;
  411. top: 40rpx;
  412. }
  413. }
  414. .whiteBg {
  415. background-color: #fff;
  416. margin: -30rpx 56rpx 0rpx 56rpx;
  417. box-shadow: 0px 2px 14px 0px rgba(0, 0, 0, 0.08);
  418. border-radius: 8px;
  419. padding: 60rpx;
  420. position: relative;
  421. z-index: 6;
  422. .tips {
  423. display: flex;
  424. align-items: center;
  425. justify-content: center;
  426. height: 50rpx;
  427. margin: 40rpx;
  428. color: #999;
  429. .tips-btn {
  430. margin: 0 31rpx 0 48rpx;
  431. color: #999999;
  432. font-weight: bold;
  433. font-size: 32rpx;
  434. /* Safari 与 Chrome */
  435. .line {
  436. width: 80rpx;
  437. height: 6rpx;
  438. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  439. border-radius: 2px;
  440. margin: 10rpx auto 0 auto;
  441. animation: myfirst .3s;
  442. -webkit-animation: myfirst .3s;
  443. }
  444. .none {
  445. width: 80rpx;
  446. background: #fff;
  447. height: 6rpx;
  448. }
  449. }
  450. @keyframes myfirst {
  451. 0% {
  452. width: 0rpx;
  453. }
  454. 100% {
  455. width: 80rpx;
  456. }
  457. }
  458. @-webkit-keyframes myfirst
  459. /* Safari 与 Chrome */
  460. {
  461. 0% {
  462. width: 0rpx;
  463. }
  464. 100% {
  465. width: 80rpx;
  466. }
  467. }
  468. .tips-btn.on {
  469. font-size: 36rpx;
  470. color: var(--view-theme);
  471. }
  472. }
  473. .list {
  474. border-radius: 16rpx;
  475. overflow: hidden;
  476. .forgetPwd {
  477. text-align: right;
  478. margin-top: 10rpx;
  479. color: #666666;
  480. font-size: 24rpx;
  481. }
  482. .item {
  483. border-bottom: 1px solid #F0F0F0;
  484. background: #fff;
  485. .row-middle {
  486. position: relative;
  487. padding: 16rpx 25rpx;
  488. input {
  489. flex: 1;
  490. font-size: 28rpx;
  491. height: 80rpx;
  492. }
  493. .code {
  494. position: absolute;
  495. right: 30rpx;
  496. top: 50%;
  497. color: var(--view-theme);
  498. font-size: 26rpx;
  499. transform: translateY(-50%);
  500. }
  501. }
  502. }
  503. }
  504. .logon {
  505. display: flex;
  506. align-items: center;
  507. justify-content: center;
  508. width: 100%;
  509. height: 86rpx;
  510. margin-top: 48rpx;
  511. background: linear-gradient(135deg, var(--view-minorColor) 0%, var(--view-theme) 100%);
  512. border-radius: 120rpx;
  513. color: #FFFFFF;
  514. font-size: 30rpx;
  515. }
  516. }
  517. .protocol {
  518. margin-top: 40rpx;
  519. color: #999999;
  520. font-size: 24rpx;
  521. }
  522. .trembling {
  523. animation: shake 0.6s;
  524. }
  525. @keyframes shake {
  526. 0%,
  527. 100% {
  528. -webkit-transform: translateX(0);
  529. }
  530. 10%,
  531. 30%,
  532. 50%,
  533. 70%,
  534. 90% {
  535. -webkit-transform: translateX(-5rpx);
  536. }
  537. 20%,
  538. 40%,
  539. 60%,
  540. 80% {
  541. -webkit-transform: translateX(5rpx);
  542. }
  543. }
  544. @-o-keyframes shake {
  545. /* Opera */
  546. 0%,
  547. 100% {
  548. -webkit-transform: translateX(0);
  549. }
  550. 10%,
  551. 30%,
  552. 50%,
  553. 70%,
  554. 90% {
  555. -webkit-transform: translateX(-5rpx);
  556. }
  557. 20%,
  558. 40%,
  559. 60%,
  560. 80% {
  561. -webkit-transform: translateX(5rpx);
  562. }
  563. }
  564. @-webkit-keyframes shake {
  565. /* Safari 和 Chrome */
  566. 0%,
  567. 100% {
  568. -webkit-transform: translateX(0);
  569. }
  570. 10%,
  571. 30%,
  572. 50%,
  573. 70%,
  574. 90% {
  575. -webkit-transform: translateX(-5rpx);
  576. }
  577. 20%,
  578. 40%,
  579. 60%,
  580. 80% {
  581. -webkit-transform: translateX(5rpx);
  582. }
  583. }
  584. @-moz-keyframes shake {
  585. /* Firefox */
  586. 0%,
  587. 100% {
  588. -moz-transform: translateX(0);
  589. }
  590. 10%,
  591. 30%,
  592. 50%,
  593. 70%,
  594. 90% {
  595. -moz-transform: translateX(-5rpx);
  596. }
  597. 20%,
  598. 40%,
  599. 60%,
  600. 80% {
  601. -moz-transform: translateX(5rpx);
  602. }
  603. }
  604. }
  605. </style>