register.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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 {
  214. this.$queue.showLoading("正在发送验证码...");
  215. this.$Request.getT("/app/Login/sendMsg/" + phone + "/1").then((res) => {
  216. if (res.code === 0) {
  217. this.sending = true;
  218. this.$queue.showToast("验证码发送成功请注意查收");
  219. this.countDown();
  220. uni.hideLoading();
  221. } else {
  222. uni.hideLoading();
  223. uni.showModal({
  224. showCancel: false,
  225. title: "短信发送失败",
  226. content: res.msg ? res.msg : "请一分钟后再获取验证码",
  227. });
  228. }
  229. });
  230. }
  231. },
  232. countDown() {
  233. const { count } = this;
  234. if (count === 1) {
  235. this.count = 60;
  236. this.sending = false;
  237. this.sendTime = "获取验证码";
  238. } else {
  239. this.count = count - 1;
  240. this.sending = true;
  241. this.sendTime = count - 1 + "秒后重新获取";
  242. setTimeout(this.countDown.bind(this), 1000);
  243. }
  244. },
  245. inputChange(e) {
  246. const key = e.currentTarget.dataset.key;
  247. this[key] = e.detail.value;
  248. if(key == 'password'){
  249. this.checkPasswordStrength(this.password);
  250. }
  251. },
  252. checkPasswordStrength(pwd) {
  253. let strength = 0;
  254. this.list.forEach(item => {
  255. if (item.name === 'length') {
  256. item.checked = pwd.length >= 8;
  257. if (item.checked) strength++;
  258. } else if (item.name === 'number') {
  259. item.checked = /[0-9]/.test(pwd);
  260. if (item.checked) strength++;
  261. } else if (item.name === 'upper') {
  262. item.checked = /[A-Z]/.test(pwd);
  263. if (item.checked) strength++;
  264. }
  265. });
  266. this.passwordStrength = strength;
  267. this.valueBackup = this.list.map(i => i.checked);
  268. },
  269. navBack() {
  270. uni.navigateBack();
  271. },
  272. navTo(url) {
  273. uni.navigateTo({
  274. url,
  275. });
  276. },
  277. // 下一步
  278. nextStep(){
  279. const { phone,code } = this;
  280. if (!phone) {
  281. this.$queue.showToast("请输入手机号");
  282. } else if (!code) {
  283. this.$queue.showToast("请输入验证码");
  284. }else{
  285. this.steps = 1;
  286. }
  287. },
  288. changePassword(){
  289. this.showPassword = !this.showPassword;
  290. },
  291. // 注册
  292. toLogin() {
  293. const { userName, phone, password, code, showAgree, invitation } = this;
  294. if (!phone) {
  295. this.$queue.showToast("请输入手机号");
  296. } else if (!code) {
  297. this.$queue.showToast("请输入验证码");
  298. } else if (!password) {
  299. this.$queue.showToast("请设置密码");
  300. } else if (password.length < 8) {
  301. this.$queue.showToast("密码位数必须大于八位");
  302. } else if (!/(?=.*[A-Z])(?=.*\d)/.test(password)) {
  303. this.$queue.showToast("密码必须包含至少一个大写字母和一个数字");
  304. }else {
  305. // this.invitation = "";
  306. this.logining = true;
  307. this.$queue.showLoading("注册中...");
  308. this.$Request
  309. .post(`/app/Login/registApp`, {
  310. userName: phone,
  311. password: password,
  312. phone: phone,
  313. wxOpenId: this.$queue.getData("openId") ? this.$queue.getData("openId") : "",
  314. // invitation: this.invitation,
  315. platform: this.platform,
  316. msg: code,
  317. })
  318. .then((res) => {
  319. if (res.code === 0) {
  320. this.$queue.showToast("注册成功");
  321. this.$queue.setData("token", res.token);
  322. this.$queue.setData("userId", res.user.userId);
  323. this.$queue.setData("userName", res.user.userName);
  324. this.$queue.setData("phone", res.user.phone);
  325. this.$queue.setData(
  326. "avatar",
  327. res.user.avatar ? res.user.avatar : "../../static/logo.png"
  328. );
  329. this.getUserInfo();
  330. setTimeout(function () {
  331. // 这里判断一下看是否是第一次登录如果是就跳到引导页,如果不是就正常跳
  332. // let firstLogin = uni.getStorageSync("firstLogin") || false;
  333. console.log("userType:",res.user.userType)
  334. if (!res.user.userType) {
  335. uni.navigateTo({
  336. url: "/pages/my/jobApplicant/guidePage",
  337. });
  338. } else {
  339. uni.switchTab({
  340. url: "/pages/index/index",
  341. });
  342. }
  343. }, 1000);
  344. } else {
  345. uni.hideLoading();
  346. uni.showModal({
  347. showCancel: false,
  348. title: "注册失败",
  349. content: res.msg,
  350. });
  351. }
  352. });
  353. }
  354. // else {
  355. // this.logining = true;
  356. // this.$queue.showLoading("注册中...");
  357. // this.$Request
  358. // .post(`/app/Login/registApp?msg=${code}`, {
  359. // userName: userName,
  360. // password: password,
  361. // phone: phone,
  362. // openId: this.$queue.getData("openId") ? this.$queue.getData("openId") : "",
  363. // invitation: this.invitation,
  364. // platform: this.platform,
  365. // })
  366. // .then((res) => {
  367. // if (res.code === 0) {
  368. // this.$queue.setData("token", res.token);
  369. // this.$queue.setData("userId", res.user.userId);
  370. // this.$queue.setData("userName", res.user.userName);
  371. // this.$queue.setData("phone", res.user.phone);
  372. // this.$queue.setData(
  373. // "avatar",
  374. // res.user.avatar ? res.user.avatar : "../../static/logo.png"
  375. // );
  376. // this.$queue.setData("invitationCode", res.user.invitationCode);
  377. // this.$queue.setData("inviterCode", res.user.inviterCode);
  378. // this.getUserInfo();
  379. // setTimeout(function () {
  380. // uni.switchTab({
  381. // url: "/pages/index/index",
  382. // });
  383. // }, 1000);
  384. // } else {
  385. // uni.showModal({
  386. // showCancel: false,
  387. // title: "注册失败",
  388. // content: res.msg,
  389. // });
  390. // }
  391. // uni.hideLoading();
  392. // });
  393. // }
  394. },
  395. //获取用户信息
  396. getUserInfo() {
  397. this.$Request.get("/app/user/selectUserById").then((res) => {
  398. if (res.code == 0) {
  399. uni.hideLoading();
  400. this.$queue.setData(
  401. "avatar",
  402. res.data.avatar ? res.data.avatar : "../../static/logo.png"
  403. );
  404. this.$queue.setData("userId", res.data.userId);
  405. this.$queue.setData("userName", res.data.userName);
  406. this.$queue.setData("phone", res.data.phone);
  407. this.$queue.setData("invitationCode", res.data.invitationCode);
  408. this.$queue.setData("inviterCode", res.data.inviterCode);
  409. this.userName = res.data.userName;
  410. this.invitationCode = res.data.invitationCode;
  411. uni.setStorageSync("invitationCode", res.data.invitationCode);
  412. setTimeout(function () {
  413. uni.switchTab({
  414. url: "pages/my/jobApplicant/registerSuccess",//pages/my/jobApplicant/registerSuccess
  415. });
  416. }, 1000);
  417. return
  418. } else {
  419. uni.showModal({
  420. showCancel: false,
  421. title: "登录失败",
  422. content: res.msg,
  423. });
  424. this.$queue.logout();
  425. }
  426. });
  427. },
  428. },
  429. };
  430. </script>
  431. <style lang="scss" scoped>
  432. ::v-deep .input-placeholder,.uni-input-placeholder {
  433. color: #9ea1a8;
  434. font-family: DM Sans;
  435. font-size: 28rpx;
  436. font-weight: 400;
  437. text-align: left;
  438. }
  439. page {
  440. height: 100%;
  441. background: #ffffff !important;
  442. }
  443. .item-label {
  444. color: rgba(18, 26, 44, 1);
  445. font-family: Roboto;
  446. font-size: 32rpx;
  447. font-weight: 400;
  448. line-height: 51.2rpx;
  449. letter-spacing: 0px;
  450. text-align: left;
  451. padding-bottom: 8rpx;
  452. margin-top: 32rpx;
  453. }
  454. .cu-form-group {
  455. position: relative;
  456. box-sizing: border-box;
  457. border: 2rpx solid rgba(158, 161, 168, 1);
  458. border-radius: 24rpx;
  459. background: rgba(255, 255, 255, 1);
  460. padding: 8rpx 24rpx !important;
  461. height: 96rpx;
  462. }
  463. .eye{
  464. position: absolute;
  465. top: 50%;
  466. right: 24rpx;
  467. font-size: 48rpx;
  468. transform: translateY(-50%);
  469. }
  470. .eye-active{
  471. color: #016bf6;
  472. }
  473. .line-progress{
  474. margin: 32rpx 0;
  475. }
  476. .footer {
  477. padding-left: 140rpx;
  478. margin-top: 32rpx;
  479. text-align: center;
  480. display: flex;
  481. // color: #FFFFFF;
  482. }
  483. .send-msg {
  484. color: rgba(1, 107, 246, 1);
  485. font-size: 28rpx;
  486. font-weight: 400;
  487. }
  488. .container {
  489. padding-top: 32rpx;
  490. position: relative;
  491. width: 100%;
  492. height: 100%;
  493. overflow: hidden;
  494. background: #ffffff !important;
  495. }
  496. .line-box{
  497. display: flex;
  498. align-items: center;
  499. justify-content: center;
  500. gap: 10rpx;
  501. }
  502. .line{
  503. width: 20px;
  504. height: 4px;
  505. border-radius: 20px;
  506. background-color: rgba(153, 196, 250, 1);
  507. }
  508. .line-bg{
  509. background-color: #016BF6;
  510. }
  511. ::v-deep .u-checkbox__label{
  512. margin-left: 20rpx;
  513. color: rgba(76, 74, 83, 1);
  514. font-family: Roboto;
  515. font-size: 32rpx;
  516. font-weight: 400;
  517. }
  518. .wrapper {
  519. position: relative;
  520. z-index: 90;
  521. background: #ffffff;
  522. padding-bottom: 20px;
  523. }
  524. .input-content {
  525. padding: 32rpx;
  526. box-sizing: border-box;
  527. }
  528. .confirm-btn {
  529. margin: 0 32rpx;
  530. height: 80rpx;
  531. line-height: 80rpx;
  532. border-radius: 60rpx;
  533. background: #016bf6;
  534. color: #fff;
  535. font-size: 32rpx;
  536. font-weight: 400;
  537. &:after {
  538. border-radius: 60px;
  539. }
  540. }
  541. // 密码要求列表
  542. .rule-item {
  543. display: flex;
  544. align-items: center;
  545. margin-bottom: 8rpx;
  546. image{
  547. width: 32rpx;
  548. height: 32rpx;
  549. margin-right: 16rpx;
  550. }
  551. }
  552. .rule-text {
  553. color: #4c4a53;
  554. font-family: Roboto;
  555. font-size: 32rpx;
  556. font-weight: 400;
  557. line-height: 51.2rpx;
  558. text-align: left;
  559. }
  560. .rule-valid .rule-text {
  561. color: #4c4a53;
  562. }
  563. .input-box {
  564. position: relative;
  565. }
  566. .next-btn-active {
  567. background: #2979ff;
  568. }
  569. ::v-deep .u-input {
  570. text-align: left !important;
  571. }
  572. .progress-box {
  573. display: flex;
  574. justify-content: center;
  575. align-items: center;
  576. gap: 24rpx;
  577. padding-top: 40rpx;
  578. box-sizing: border-box;
  579. .progress-item {
  580. width: 40rpx;
  581. height: 8rpx;
  582. background-color: #016bf6;
  583. border-radius: 40rpx;
  584. }
  585. }
  586. </style>