register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <template>
  2. <view class="container">
  3. <nav-bar :title="steps == 0?'注册1/2':'创建账号密码2/2'" color="#000"></nav-bar>
  4. <view class="line-box">
  5. <view class="line line-bg" @click="steps = 0"></view>
  6. <view class="line" :class="[ steps == 1?'line-bg':'' ]" @click="steps = 1"></view>
  7. </view>
  8. <view class="wrapper">
  9. <view class="input-content">
  10. <!-- <view class="item-label">用户名</view>
  11. <view class="cu-form-group">
  12. <input
  13. :value="userName"
  14. placeholder="请输入用户名"
  15. data-key="userName"
  16. @input="inputChange"
  17. />
  18. </view> -->
  19. <view class="item-label" v-show="steps == 0">手机号码</view>
  20. <view class="cu-form-group" v-show="steps == 0">
  21. <input
  22. type="number"
  23. :value="phone"
  24. placeholder="请输入登录的手机号码"
  25. maxlength="11"
  26. data-key="phone"
  27. @input="inputChange"
  28. />
  29. </view>
  30. <view class="item-label" v-show="steps == 0">验证码</view>
  31. <view class="cu-form-group padding-right-xs" v-show="steps == 0">
  32. <input
  33. type="number"
  34. :value="code"
  35. placeholder="请输入验证码"
  36. maxlength="6"
  37. data-key="code"
  38. @input="inputChange"
  39. @confirm="toLogin"
  40. />
  41. <text class="send-msg" @click="sendMsg" :disabled="sending">
  42. {{ sendTime }}
  43. </text>
  44. </view>
  45. <view class="item-label" v-show="steps == 1">密码</view>
  46. <view class="cu-form-group" v-show="steps == 1">
  47. <input
  48. :value="password"
  49. :password="showPassword"
  50. placeholder="输入密码"
  51. placeholder-class="input-empty"
  52. maxlength="20"
  53. minlength="8"
  54. data-key="password"
  55. @input="inputChange"
  56. @confirm="toLogin"
  57. />
  58. <u-icon @click="changePassword" class="eye" :class="{ 'eye-active': !showPassword }" name="eye-fill"></u-icon>
  59. </view>
  60. <view v-show="steps == 1">
  61. <u-line-progress class="line-progress" :show-percent="false" :active-color="progressColor" :percent="passwordStrength * 33.3"></u-line-progress>
  62. <view class="password-rules">
  63. <view class="rule-item" v-for="(item, index) in list" :key="index" :class="{ 'rule-valid': item.checked }">
  64. <image
  65. src="@/static/images/jobApplicant/check.svg"
  66. v-if="item.checked"
  67. mode="scaleToFill"
  68. />
  69. <image
  70. src="@/static/images/jobApplicant/border.svg"
  71. v-else
  72. mode="scaleToFill"
  73. />
  74. <text class="rule-text">{{item.label}}</text>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- <view class="cu-form-group" style="margin-top: 32rpx" v-if="required == '是'">
  79. <view class="item-label-code">邀请码</view>
  80. <input
  81. type=""
  82. maxlength="6"
  83. :value="invitation"
  84. placeholder="请填写邀请码(必填)"
  85. data-key="invitation"
  86. @input="inputChange"
  87. @confirm="toLogin"
  88. />
  89. </view> -->
  90. <!-- <view class="cu-form-group" style="margin-top: 32rpx" v-if="required == '否'">
  91. <view class="item-label-code">邀请码</view>
  92. <input
  93. type=""
  94. maxlength="6"
  95. :value="invitation"
  96. placeholder="请填写邀请码(选填)"
  97. data-key="invitation"
  98. @input="inputChange"
  99. @confirm="toLogin"
  100. />
  101. </view> -->
  102. </view>
  103. <button class="confirm-btn" @click="nextStep" v-if="steps == 0">下一步</button>
  104. <button class="confirm-btn" @click="toLogin" v-if="steps == 1">继续</button>
  105. <!-- <view class="footer">
  106. <text
  107. @tap="isShowAgree"
  108. class="cuIcon"
  109. :class="showAgree ? 'cuIcon-radiobox' : 'cuIcon-round'"
  110. >同意</text
  111. >
  112. <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>
  113. <navigator url="/my/setting/xieyi" open-type="navigate"
  114. >《用户服务协议》</navigator
  115. >
  116. </view> -->
  117. </view>
  118. </view>
  119. </template>
  120. <script>
  121. import navBar from "@/components/nav-bar/index.vue";
  122. export default {
  123. data() {
  124. return {
  125. userName: "",
  126. showAgree: false,
  127. code: "",
  128. phone: "",
  129. password: "",
  130. showPassword:true,
  131. required: "否",
  132. sending: false,
  133. sendTime: "获取验证码",
  134. count: 60,
  135. relation: "",
  136. state: "",
  137. invitation: "",
  138. platform: "",
  139. steps:0,
  140. passwordStrength: 0, // 当前满足的条件数
  141. list: [
  142. { name: 'length', label: '最少8位数',checked: false, },
  143. { name: 'number', label: '至少包含1个数字',checked: false, },
  144. { name: 'upper', label: '至少包含一个大写字母',checked: false, }
  145. ],
  146. valueBackup: [],
  147. };
  148. },
  149. components: {
  150. navBar,
  151. },
  152. onLoad() {
  153. // this.invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
  154. this.invitation = this.$queue.getData("invitation")
  155. ? this.$queue.getData("invitation")
  156. : "";
  157. // #ifdef APP-PLUS
  158. this.platform = "app";
  159. //#endif
  160. //#ifdef H5
  161. this.platform = "H5";
  162. // #endif
  163. },
  164. computed: {
  165. progressColor() {
  166. switch (this.passwordStrength) {
  167. case 1:
  168. return 'rgba(214, 44, 1, 1)';
  169. case 2:
  170. return 'rgba(250, 174, 22, 1)';
  171. case 3:
  172. return 'rgba(1, 107, 246, 1)';
  173. default:
  174. return 'rgba(237, 236, 239, 1)';
  175. }
  176. },
  177. },
  178. methods: {
  179. showMa() {
  180. //查询官方邀请码
  181. this.$Request.getT("/app/common/type/4").then((res) => {
  182. if (res.code == 0) {
  183. this.invitationCode = res.data.value;
  184. }
  185. });
  186. },
  187. // 注册邀请码必填
  188. invitationMa() {
  189. this.$Request.getT("/app/common/type/3").then((res) => {
  190. if (res.code == 0) {
  191. this.required = res.data.value;
  192. }
  193. });
  194. },
  195. // 获取新用户优惠券数量
  196. newMa() {
  197. this.$Request.getT("/app/common/type/119").then((res) => {
  198. if (res.code == 0) {
  199. this.amount = res.data.value;
  200. }
  201. });
  202. },
  203. isShowAgree() {
  204. //是否选择协议
  205. this.showAgree = !this.showAgree;
  206. },
  207. sendMsg() {
  208. const { phone } = this;
  209. if (!phone) {
  210. this.$queue.showToast("请输入手机号");
  211. } else if (phone.length !== 11) {
  212. this.$queue.showToast("请输入正确的手机号");
  213. } else if(this.sendTime != '获取验证码'){
  214. return;
  215. }else {
  216. this.$queue.showLoading("正在发送验证码...");
  217. this.$Request.getT("/app/Login/sendMsg/" + phone + "/1").then((res) => {
  218. if (res.code === 0) {
  219. this.sending = true;
  220. this.$queue.showToast("验证码发送成功请注意查收");
  221. this.countDown();
  222. uni.hideLoading();
  223. } else {
  224. uni.hideLoading();
  225. uni.showModal({
  226. showCancel: false,
  227. title: "短信发送失败",
  228. content: res.msg ? res.msg : "请一分钟后再获取验证码",
  229. });
  230. }
  231. });
  232. }
  233. },
  234. countDown() {
  235. const { count } = this;
  236. if (count === 1) {
  237. this.count = 60;
  238. this.sending = false;
  239. this.sendTime = "获取验证码";
  240. } else {
  241. this.count = count - 1;
  242. this.sending = true;
  243. this.sendTime = count - 1 + "秒后重新获取";
  244. setTimeout(this.countDown.bind(this), 1000);
  245. }
  246. },
  247. inputChange(e) {
  248. const key = e.currentTarget.dataset.key;
  249. this[key] = e.detail.value;
  250. if(key == 'password'){
  251. this.checkPasswordStrength(this.password);
  252. }
  253. },
  254. checkPasswordStrength(pwd) {
  255. let strength = 0;
  256. this.list.forEach(item => {
  257. if (item.name === 'length') {
  258. item.checked = pwd.length >= 8;
  259. if (item.checked) strength++;
  260. } else if (item.name === 'number') {
  261. item.checked = /[0-9]/.test(pwd);
  262. if (item.checked) strength++;
  263. } else if (item.name === 'upper') {
  264. item.checked = /[A-Z]/.test(pwd);
  265. if (item.checked) strength++;
  266. }
  267. });
  268. this.passwordStrength = strength;
  269. this.valueBackup = this.list.map(i => i.checked);
  270. },
  271. navBack() {
  272. uni.navigateBack();
  273. },
  274. navTo(url) {
  275. uni.navigateTo({
  276. url,
  277. });
  278. },
  279. // 下一步
  280. nextStep(){
  281. const { phone,code } = this;
  282. if (!phone) {
  283. this.$queue.showToast("请输入手机号");
  284. } else if (!code) {
  285. this.$queue.showToast("请输入验证码");
  286. }else{
  287. this.steps = 1;
  288. }
  289. },
  290. changePassword(){
  291. this.showPassword = !this.showPassword;
  292. },
  293. // 注册
  294. toLogin() {
  295. const { userName, phone, password, code, showAgree, invitation } = this;
  296. if (!phone) {
  297. this.$queue.showToast("请输入手机号");
  298. } else if (!code) {
  299. this.$queue.showToast("请输入验证码");
  300. } else if (!password) {
  301. this.$queue.showToast("请设置密码");
  302. } else if (password.length < 8) {
  303. this.$queue.showToast("密码位数必须大于八位");
  304. } else if (!/(?=.*[A-Z])(?=.*\d)/.test(password)) {
  305. this.$queue.showToast("密码必须包含至少一个大写字母和一个数字");
  306. }else {
  307. // this.invitation = "";
  308. this.logining = true;
  309. this.$queue.showLoading("注册中...");
  310. this.$Request
  311. .post(`/app/Login/registApp`, {
  312. userName: phone,
  313. password: password,
  314. phone: phone,
  315. wxOpenId: this.$queue.getData("openId") ? this.$queue.getData("openId") : "",
  316. // invitation: this.invitation,
  317. platform: this.platform,
  318. msg: code,
  319. })
  320. .then((res) => {
  321. if (res.code === 0) {
  322. this.$queue.showToast("注册成功");
  323. this.$queue.setData("token", res.token);
  324. this.$queue.setData("userId", res.user.userId);
  325. this.$queue.setData("userName", res.user.userName);
  326. this.$queue.setData("phone", res.user.phone);
  327. this.$queue.setData(
  328. "avatar",
  329. res.user.avatar ? res.user.avatar : "../../static/logo.png"
  330. );
  331. this.getUserInfo();
  332. // setTimeout(function () {
  333. // // 这里判断一下看是否是第一次登录如果是就跳到引导页,如果不是就正常跳
  334. // // let firstLogin = uni.getStorageSync("firstLogin") || false;
  335. // console.log("userType:",res.user.userType)
  336. // if (!res.user.userType) {
  337. // uni.navigateTo({
  338. // url: "/pages/my/jobApplicant/guidePage",
  339. // });
  340. // } else {
  341. // uni.switchTab({
  342. // url: "/pages/index/index",
  343. // });
  344. // }
  345. // }, 1000);
  346. } else {
  347. uni.hideLoading();
  348. uni.showModal({
  349. showCancel: false,
  350. title: "注册失败",
  351. content: res.msg,
  352. });
  353. }
  354. });
  355. }
  356. // else {
  357. // this.logining = true;
  358. // this.$queue.showLoading("注册中...");
  359. // this.$Request
  360. // .post(`/app/Login/registApp?msg=${code}`, {
  361. // userName: userName,
  362. // password: password,
  363. // phone: phone,
  364. // openId: this.$queue.getData("openId") ? this.$queue.getData("openId") : "",
  365. // invitation: this.invitation,
  366. // platform: this.platform,
  367. // })
  368. // .then((res) => {
  369. // if (res.code === 0) {
  370. // this.$queue.setData("token", res.token);
  371. // this.$queue.setData("userId", res.user.userId);
  372. // this.$queue.setData("userName", res.user.userName);
  373. // this.$queue.setData("phone", res.user.phone);
  374. // this.$queue.setData(
  375. // "avatar",
  376. // res.user.avatar ? res.user.avatar : "../../static/logo.png"
  377. // );
  378. // this.$queue.setData("invitationCode", res.user.invitationCode);
  379. // this.$queue.setData("inviterCode", res.user.inviterCode);
  380. // this.getUserInfo();
  381. // setTimeout(function () {
  382. // uni.switchTab({
  383. // url: "/pages/index/index",
  384. // });
  385. // }, 1000);
  386. // } else {
  387. // uni.showModal({
  388. // showCancel: false,
  389. // title: "注册失败",
  390. // content: res.msg,
  391. // });
  392. // }
  393. // uni.hideLoading();
  394. // });
  395. // }
  396. },
  397. //获取用户信息
  398. getUserInfo() {
  399. this.$Request.get("/app/user/selectUserById").then((res) => {
  400. if (res.code == 0) {
  401. uni.hideLoading();
  402. this.$queue.setData(
  403. "avatar",
  404. res.data.avatar ? res.data.avatar : "../../static/logo.png"
  405. );
  406. this.$queue.setData("userId", res.data.userId);
  407. this.$queue.setData("userName", res.data.userName);
  408. this.$queue.setData("phone", res.data.phone);
  409. this.$queue.setData("invitationCode", res.data.invitationCode);
  410. this.$queue.setData("inviterCode", res.data.inviterCode);
  411. this.userName = res.data.userName;
  412. this.invitationCode = res.data.invitationCode;
  413. uni.setStorageSync("invitationCode", res.data.invitationCode);
  414. setTimeout(function () {
  415. uni.reLaunch({
  416. url: "/pages/my/jobApplicant/registerSuccess",//pages/my/jobApplicant/registerSuccess
  417. });
  418. }, 1000);
  419. return
  420. } else {
  421. uni.showModal({
  422. showCancel: false,
  423. title: "登录失败",
  424. content: res.msg,
  425. });
  426. this.$queue.logout();
  427. }
  428. });
  429. },
  430. },
  431. };
  432. </script>
  433. <style lang="scss" scoped>
  434. ::v-deep .input-placeholder,.uni-input-placeholder {
  435. color: #9ea1a8;
  436. font-family: DM Sans;
  437. font-size: 28rpx;
  438. font-weight: 400;
  439. text-align: left;
  440. }
  441. page {
  442. height: 100%;
  443. background: #ffffff !important;
  444. }
  445. .item-label {
  446. color: rgba(18, 26, 44, 1);
  447. font-family: Roboto;
  448. font-size: 32rpx;
  449. font-weight: 400;
  450. line-height: 51.2rpx;
  451. letter-spacing: 0px;
  452. text-align: left;
  453. padding-bottom: 8rpx;
  454. margin-top: 32rpx;
  455. }
  456. .cu-form-group {
  457. position: relative;
  458. box-sizing: border-box;
  459. border: 2rpx solid rgba(158, 161, 168, 1);
  460. border-radius: 24rpx;
  461. background: rgba(255, 255, 255, 1);
  462. padding: 8rpx 24rpx !important;
  463. height: 96rpx;
  464. }
  465. .eye{
  466. position: absolute;
  467. top: 50%;
  468. right: 24rpx;
  469. font-size: 48rpx;
  470. transform: translateY(-50%);
  471. }
  472. .eye-active{
  473. color: #016bf6;
  474. }
  475. .line-progress{
  476. margin: 32rpx 0;
  477. }
  478. .footer {
  479. padding-left: 140rpx;
  480. margin-top: 32rpx;
  481. text-align: center;
  482. display: flex;
  483. // color: #FFFFFF;
  484. }
  485. .send-msg {
  486. color: rgba(1, 107, 246, 1);
  487. font-size: 28rpx;
  488. font-weight: 400;
  489. }
  490. .container {
  491. padding-top: 32rpx;
  492. position: relative;
  493. width: 100%;
  494. height: 100%;
  495. overflow: hidden;
  496. background: #ffffff !important;
  497. }
  498. .line-box{
  499. display: flex;
  500. align-items: center;
  501. justify-content: center;
  502. gap: 10rpx;
  503. }
  504. .line{
  505. width: 20px;
  506. height: 4px;
  507. border-radius: 20px;
  508. background-color: rgba(153, 196, 250, 1);
  509. }
  510. .line-bg{
  511. background-color: #016BF6;
  512. }
  513. ::v-deep .u-checkbox__label{
  514. margin-left: 20rpx;
  515. color: rgba(76, 74, 83, 1);
  516. font-family: Roboto;
  517. font-size: 32rpx;
  518. font-weight: 400;
  519. }
  520. .wrapper {
  521. position: relative;
  522. z-index: 90;
  523. background: #ffffff;
  524. padding-bottom: 20px;
  525. }
  526. .input-content {
  527. padding: 32rpx;
  528. box-sizing: border-box;
  529. }
  530. .confirm-btn {
  531. margin: 0 32rpx;
  532. height: 80rpx;
  533. line-height: 80rpx;
  534. border-radius: 60rpx;
  535. background: #016bf6;
  536. color: #fff;
  537. font-size: 32rpx;
  538. font-weight: 400;
  539. &:after {
  540. border-radius: 60px;
  541. }
  542. }
  543. // 密码要求列表
  544. .rule-item {
  545. display: flex;
  546. align-items: center;
  547. margin-bottom: 8rpx;
  548. image{
  549. width: 32rpx;
  550. height: 32rpx;
  551. margin-right: 16rpx;
  552. }
  553. }
  554. .rule-text {
  555. color: #4c4a53;
  556. font-family: Roboto;
  557. font-size: 32rpx;
  558. font-weight: 400;
  559. line-height: 51.2rpx;
  560. text-align: left;
  561. }
  562. .rule-valid .rule-text {
  563. color: #4c4a53;
  564. }
  565. .input-box {
  566. position: relative;
  567. }
  568. .next-btn-active {
  569. background: #2979ff;
  570. }
  571. ::v-deep .u-input {
  572. text-align: left !important;
  573. }
  574. .progress-box {
  575. display: flex;
  576. justify-content: center;
  577. align-items: center;
  578. gap: 24rpx;
  579. padding-top: 40rpx;
  580. box-sizing: border-box;
  581. .progress-item {
  582. width: 40rpx;
  583. height: 8rpx;
  584. background-color: #016bf6;
  585. border-radius: 40rpx;
  586. }
  587. }
  588. </style>