register.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  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. <u-checkbox-group :wrap="true" @change="preventChange">
  63. <u-checkbox shape="circle"
  64. v-for="(item, index) in list" :key="index"
  65. :name="item.name"
  66. v-model="item.checked"
  67. :readonly="true"
  68. >
  69. {{item.label}}
  70. </u-checkbox>
  71. </u-checkbox-group>
  72. </view>
  73. <!-- <view class="cu-form-group" style="margin-top: 32rpx" v-if="required == '是'">
  74. <view class="item-label-code">邀请码</view>
  75. <input
  76. type=""
  77. maxlength="6"
  78. :value="invitation"
  79. placeholder="请填写邀请码(必填)"
  80. data-key="invitation"
  81. @input="inputChange"
  82. @confirm="toLogin"
  83. />
  84. </view> -->
  85. <!-- <view class="cu-form-group" style="margin-top: 32rpx" v-if="required == '否'">
  86. <view class="item-label-code">邀请码</view>
  87. <input
  88. type=""
  89. maxlength="6"
  90. :value="invitation"
  91. placeholder="请填写邀请码(选填)"
  92. data-key="invitation"
  93. @input="inputChange"
  94. @confirm="toLogin"
  95. />
  96. </view> -->
  97. </view>
  98. <button class="confirm-btn" @click="nextStep" v-if="steps == 0">下一步</button>
  99. <button class="confirm-btn" @click="toLogin" v-if="steps == 1">继续</button>
  100. <!-- <view class="footer">
  101. <text
  102. @tap="isShowAgree"
  103. class="cuIcon"
  104. :class="showAgree ? 'cuIcon-radiobox' : 'cuIcon-round'"
  105. >同意</text
  106. >
  107. <navigator url="/my/setting/mimi" open-type="navigate">《隐私政策》</navigator>
  108. <navigator url="/my/setting/xieyi" open-type="navigate"
  109. >《用户服务协议》</navigator
  110. >
  111. </view> -->
  112. </view>
  113. </view>
  114. </template>
  115. <script>
  116. import navBar from "@/components/nav-bar/index.vue";
  117. export default {
  118. data() {
  119. return {
  120. userName: "",
  121. showAgree: false,
  122. code: "",
  123. phone: "",
  124. password: "",
  125. showPassword:true,
  126. required: "否",
  127. sending: false,
  128. sendTime: "获取验证码",
  129. count: 60,
  130. relation: "",
  131. state: "",
  132. invitation: "",
  133. platform: "",
  134. steps:0,
  135. passwordStrength: 0, // 当前满足的条件数
  136. list: [
  137. { name: 'length', label: '最少8位数',checked: false, },
  138. { name: 'number', label: '至少包含1个数字',checked: false, },
  139. { name: 'upper', label: '只要包含一个大写字母',checked: false, }
  140. ],
  141. valueBackup: [],
  142. };
  143. },
  144. components: {
  145. navBar,
  146. },
  147. onLoad() {
  148. // this.invitation = this.$queue.getData('inviterCode') ? this.$queue.getData('inviterCode') : '';
  149. this.invitation = this.$queue.getData("invitation")
  150. ? this.$queue.getData("invitation")
  151. : "";
  152. // #ifdef APP-PLUS
  153. this.platform = "app";
  154. //#endif
  155. //#ifdef H5
  156. this.platform = "H5";
  157. // #endif
  158. },
  159. computed: {
  160. progressColor() {
  161. switch (this.passwordStrength) {
  162. case 1:
  163. return 'rgba(214, 44, 1, 1)';
  164. case 2:
  165. return 'rgba(250, 174, 22, 1)';
  166. case 3:
  167. return 'rgba(1, 107, 246, 1)';
  168. default:
  169. return 'rgba(237, 236, 239, 1)';
  170. }
  171. },
  172. },
  173. methods: {
  174. showMa() {
  175. //查询官方邀请码
  176. this.$Request.getT("/app/common/type/4").then((res) => {
  177. if (res.code == 0) {
  178. this.invitationCode = res.data.value;
  179. }
  180. });
  181. },
  182. // 注册邀请码必填
  183. invitationMa() {
  184. this.$Request.getT("/app/common/type/3").then((res) => {
  185. if (res.code == 0) {
  186. this.required = res.data.value;
  187. }
  188. });
  189. },
  190. // 获取新用户优惠券数量
  191. newMa() {
  192. this.$Request.getT("/app/common/type/119").then((res) => {
  193. if (res.code == 0) {
  194. this.amount = res.data.value;
  195. }
  196. });
  197. },
  198. isShowAgree() {
  199. //是否选择协议
  200. this.showAgree = !this.showAgree;
  201. },
  202. sendMsg() {
  203. const { phone } = this;
  204. if (!phone) {
  205. this.$queue.showToast("请输入手机号");
  206. } else if (phone.length !== 11) {
  207. this.$queue.showToast("请输入正确的手机号");
  208. } else {
  209. this.$queue.showLoading("正在发送验证码...");
  210. this.$Request.getT("/app/Login/sendMsg/" + phone + "/1").then((res) => {
  211. if (res.code === 0) {
  212. this.sending = true;
  213. this.$queue.showToast("验证码发送成功请注意查收");
  214. this.countDown();
  215. uni.hideLoading();
  216. } else {
  217. uni.hideLoading();
  218. uni.showModal({
  219. showCancel: false,
  220. title: "短信发送失败",
  221. content: res.msg ? res.msg : "请一分钟后再获取验证码",
  222. });
  223. }
  224. });
  225. }
  226. },
  227. countDown() {
  228. const { count } = this;
  229. if (count === 1) {
  230. this.count = 60;
  231. this.sending = false;
  232. this.sendTime = "获取验证码";
  233. } else {
  234. this.count = count - 1;
  235. this.sending = true;
  236. this.sendTime = count - 1 + "秒后重新获取";
  237. setTimeout(this.countDown.bind(this), 1000);
  238. }
  239. },
  240. inputChange(e) {
  241. const key = e.currentTarget.dataset.key;
  242. this[key] = e.detail.value;
  243. if(key == 'password'){
  244. this.checkPasswordStrength(this.password);
  245. }
  246. },
  247. checkPasswordStrength(pwd) {
  248. let strength = 0;
  249. this.list.forEach(item => {
  250. if (item.name === 'length') {
  251. item.checked = pwd.length >= 8;
  252. if (item.checked) strength++;
  253. } else if (item.name === 'number') {
  254. item.checked = /[0-9]/.test(pwd) && pwd.length >= 8;
  255. if (item.checked) strength++;
  256. } else if (item.name === 'upper') {
  257. item.checked = /[A-Z]/.test(pwd) && pwd.length >= 8;
  258. if (item.checked) strength++;
  259. }
  260. });
  261. this.passwordStrength = strength;
  262. this.valueBackup = this.list.map(i => i.checked);
  263. },
  264. preventChange() {
  265. this.list.forEach((item, index) => {
  266. item.checked = this.valueBackup[index];
  267. });
  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. openId: 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/index/index",
  415. // });
  416. // }, 1000);
  417. } else {
  418. uni.showModal({
  419. showCancel: false,
  420. title: "登录失败",
  421. content: res.msg,
  422. });
  423. this.$queue.logout();
  424. }
  425. });
  426. },
  427. },
  428. };
  429. </script>
  430. <style lang="scss" scoped>
  431. ::v-deep .input-placeholder,.uni-input-placeholder {
  432. color: #9ea1a8;
  433. font-family: DM Sans;
  434. font-size: 28rpx;
  435. font-weight: 400;
  436. text-align: left;
  437. }
  438. page {
  439. height: 100%;
  440. background: #ffffff !important;
  441. }
  442. .item-label {
  443. color: rgba(18, 26, 44, 1);
  444. font-family: Roboto;
  445. font-size: 32rpx;
  446. font-weight: 400;
  447. line-height: 51.2rpx;
  448. letter-spacing: 0px;
  449. text-align: left;
  450. padding-bottom: 8rpx;
  451. margin-top: 32rpx;
  452. }
  453. .cu-form-group {
  454. position: relative;
  455. box-sizing: border-box;
  456. border: 2rpx solid rgba(158, 161, 168, 1);
  457. border-radius: 24rpx;
  458. background: rgba(255, 255, 255, 1);
  459. padding: 8rpx 24rpx !important;
  460. height: 96rpx;
  461. }
  462. .eye{
  463. position: absolute;
  464. top: 50%;
  465. right: 24rpx;
  466. font-size: 48rpx;
  467. transform: translateY(-50%);
  468. }
  469. .eye-active{
  470. color: #016bf6;
  471. }
  472. .line-progress{
  473. margin: 32rpx 0;
  474. }
  475. .footer {
  476. padding-left: 140rpx;
  477. margin-top: 32rpx;
  478. text-align: center;
  479. display: flex;
  480. // color: #FFFFFF;
  481. }
  482. .send-msg {
  483. color: rgba(1, 107, 246, 1);
  484. font-size: 28rpx;
  485. font-weight: 400;
  486. }
  487. .container {
  488. padding-top: 32rpx;
  489. position: relative;
  490. width: 100%;
  491. height: 100%;
  492. overflow: hidden;
  493. background: #ffffff !important;
  494. }
  495. .line-box{
  496. display: flex;
  497. align-items: center;
  498. justify-content: center;
  499. gap: 10rpx;
  500. }
  501. .line{
  502. width: 20px;
  503. height: 4px;
  504. border-radius: 20px;
  505. background-color: rgba(153, 196, 250, 1);
  506. }
  507. .line-bg{
  508. background-color: #016BF6;
  509. }
  510. ::v-deep .u-checkbox__label{
  511. margin-left: 20rpx;
  512. color: rgba(76, 74, 83, 1);
  513. font-family: Roboto;
  514. font-size: 32rpx;
  515. font-weight: 400;
  516. }
  517. .wrapper {
  518. position: relative;
  519. z-index: 90;
  520. background: #ffffff;
  521. padding-bottom: 20px;
  522. }
  523. .input-content {
  524. padding: 32rpx;
  525. box-sizing: border-box;
  526. }
  527. .confirm-btn {
  528. margin: 0 32rpx;
  529. height: 80rpx;
  530. line-height: 80rpx;
  531. border-radius: 60rpx;
  532. background: #016bf6;
  533. color: #fff;
  534. font-size: 32rpx;
  535. font-weight: 400;
  536. &:after {
  537. border-radius: 60px;
  538. }
  539. }
  540. </style>