forgetPwd.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="container">
  3. <navBar title="忘记密码" color="#000" />
  4. <view class="wrapper">
  5. <view class="input-content">
  6. <view class="item-label" v-show="steps == 0">手机号码</view>
  7. <view class="cu-form-group" v-show="steps == 0">
  8. <input type="number" :value="phone" placeholder="请输入手机号" maxlength="11" data-key="phone"
  9. @input="inputChange" />
  10. </view>
  11. <view class="item-label" v-show="steps == 0">验证码</view>
  12. <view class="cu-form-group" v-show="steps == 0">
  13. <input type="number" :value="code" placeholder="请输入验证码" maxlength="6" data-key="code"
  14. @input="inputChange" @confirm="toLogin" />
  15. <text class="send-msg" @click="sendMsg" :disabled="sending">
  16. {{ sendTime }}
  17. </text>
  18. </view>
  19. <view class="item-label">密码</view>
  20. <view class="cu-form-group">
  21. <input :value="password" :password="showPassword" placeholder="请输入新密码" placeholder-class="input-empty"
  22. maxlength="20" minlength="8" data-key="password" @input="inputChange" @confirm="toLogin" />
  23. <u-icon @click="changePassword" class="eye" :class="{ 'eye-active': !showPassword }"
  24. name="eye-fill"></u-icon>
  25. </view>
  26. <view>
  27. <u-line-progress class="line-progress" :show-percent="false" :active-color="progressColor"
  28. :percent="passwordStrength * 33.3"></u-line-progress>
  29. <view class="password-rules">
  30. <view class="rule-item" v-for="(item, index) in list" :key="index" :class="{ 'rule-valid': item.checked }">
  31. <image
  32. src="@/static/images/jobApplicant/check.svg"
  33. v-if="item.checked"
  34. mode="scaleToFill"
  35. />
  36. <image
  37. src="@/static/images/jobApplicant/border.svg"
  38. v-else
  39. mode="scaleToFill"
  40. />
  41. <text class="rule-text">{{item.label}}</text>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <button class="confirm-btn" @click="toLogin">立即找回</button>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import navBar from "@/components/nav-bar/index.vue";
  52. export default {
  53. data() {
  54. return {
  55. code: "",
  56. phone: "",
  57. password: "",
  58. sending: false,
  59. sendTime: "获取验证码",
  60. count: 60,
  61. logining: false,
  62. showPassword:true,
  63. steps: 0,
  64. passwordStrength: 0, // 当前满足的条件数
  65. list: [{
  66. name: 'length',
  67. label: '最少8位数',
  68. checked: false,
  69. },
  70. {
  71. name: 'number',
  72. label: '至少包含1个数字',
  73. checked: false,
  74. },
  75. {
  76. name: 'upper',
  77. label: '至少包含一个大写字母',
  78. checked: false,
  79. }
  80. ],
  81. valueBackup: [],
  82. };
  83. },
  84. components: {
  85. navBar,
  86. },
  87. computed: {
  88. progressColor() {
  89. switch (this.passwordStrength) {
  90. case 1:
  91. return 'rgba(214, 44, 1, 1)';
  92. case 2:
  93. return 'rgba(250, 174, 22, 1)';
  94. case 3:
  95. return 'rgba(1, 107, 246, 1)';
  96. default:
  97. return 'rgba(237, 236, 239, 1)';
  98. }
  99. },
  100. },
  101. methods: {
  102. changePassword(){
  103. this.showPassword = !this.showPassword;
  104. },
  105. sendMsg() {
  106. const {phone} = this;
  107. if (!phone) {
  108. this.$queue.showToast("请输入手机号");
  109. } else if (phone.length !== 11) {
  110. this.$queue.showToast("请输入正确的手机号");
  111. } else {
  112. this.$queue.showLoading("正在发送验证码...");
  113. this.$Request.getT("/app/Login/sendMsg/" + phone + "/forget").then((res) => {
  114. if (res.code === 0) {
  115. this.sending = true;
  116. this.$queue.showToast("验证码发送成功请注意查收");
  117. this.countDown();
  118. uni.hideLoading();
  119. } else {
  120. uni.hideLoading();
  121. uni.showModal({
  122. showCancel: false,
  123. title: "短信发送失败",
  124. content: res.msg ? res.msg : "请一分钟后再获取验证码",
  125. });
  126. }
  127. });
  128. }
  129. },
  130. countDown() {
  131. const {count} = this;
  132. if (count === 1) {
  133. this.count = 60;
  134. this.sending = false;
  135. this.sendTime = "获取验证码";
  136. } else {
  137. this.count = count - 1;
  138. this.sending = true;
  139. this.sendTime = count - 1 + "秒后重新获取";
  140. setTimeout(this.countDown.bind(this), 1000);
  141. }
  142. },
  143. inputChange(e) {
  144. const key = e.currentTarget.dataset.key;
  145. this[key] = e.detail.value;
  146. if(key == 'password'){
  147. this.checkPasswordStrength(this.password);
  148. }
  149. },
  150. checkPasswordStrength(pwd) {
  151. let strength = 0;
  152. this.list.forEach(item => {
  153. if (item.name === 'length') {
  154. item.checked = pwd.length >= 8;
  155. if (item.checked) strength++;
  156. } else if (item.name === 'number') {
  157. item.checked = /[0-9]/.test(pwd);
  158. if (item.checked) strength++;
  159. } else if (item.name === 'upper') {
  160. item.checked = /[A-Z]/.test(pwd);
  161. if (item.checked) strength++;
  162. }
  163. });
  164. this.passwordStrength = strength;
  165. this.valueBackup = this.list.map(i => i.checked);
  166. },
  167. navBack() {
  168. uni.navigateBack();
  169. },
  170. navTo(url) {
  171. uni.navigateTo({
  172. url,
  173. });
  174. },
  175. toLogin() {
  176. const {phone,password,code} = this;
  177. if (!phone) {
  178. this.$queue.showToast("请输入手机号");
  179. } else if (!code) {
  180. this.$queue.showToast("请输入验证码");
  181. }else if (!password) {
  182. this.$queue.showToast("请设置密码");
  183. } else if (password.length < 8) {
  184. this.$queue.showToast("密码位数必须大于八位");
  185. } else if (!/(?=.*[A-Z])(?=.*\d)/.test(password)) {
  186. this.$queue.showToast("密码必须包含至少一个大写字母和一个数字");
  187. } else {
  188. this.logining = true;
  189. this.$queue.showLoading("正在修改密码中...");
  190. this.$Request
  191. .post("/app/Login/forgetPwd", {
  192. pwd: password,
  193. phone: phone,
  194. msg: code,
  195. })
  196. .then((res) => {
  197. uni.hideLoading();
  198. if (res.code === 0) {
  199. uni.navigateTo({
  200. url: "/pages/public/loginphone?type=1",
  201. });
  202. } else {
  203. uni.showModal({
  204. showCancel: false,
  205. title: "密码找回失败",
  206. content: res.msg,
  207. });
  208. }
  209. });
  210. }
  211. },
  212. },
  213. };
  214. </script>
  215. <style lang="scss">
  216. page {
  217. background: #ffffff !important;
  218. }
  219. ::v-deep .input-placeholder,.uni-input-placeholder {
  220. color: #9ea1a8;
  221. font-family: DM Sans;
  222. font-size: 28rpx;
  223. font-weight: 400;
  224. text-align: left;
  225. }
  226. ::v-deep .u-checkbox__label{
  227. margin-left: 20rpx;
  228. color: rgba(76, 74, 83, 1);
  229. font-family: Roboto;
  230. font-size: 32rpx;
  231. font-weight: 400;
  232. }
  233. .container {
  234. padding-top: 32rpx;
  235. position: relative;
  236. width: 100%;
  237. height: 100%;
  238. overflow: hidden;
  239. background: #ffffff;
  240. }
  241. .wrapper {
  242. position: relative;
  243. z-index: 90;
  244. background: #ffffff;
  245. padding-bottom: 20px;
  246. }
  247. .input-content {
  248. padding: 32rpx;
  249. box-sizing: border-box;
  250. }
  251. .item-label {
  252. color: rgba(18, 26, 44, 1);
  253. font-family: Roboto;
  254. font-size: 32rpx;
  255. font-weight: 400;
  256. line-height: 51.2rpx;
  257. letter-spacing: 0px;
  258. text-align: left;
  259. padding-bottom: 8rpx;
  260. margin-top: 32rpx;
  261. }
  262. .cu-form-group {
  263. position: relative;
  264. box-sizing: border-box;
  265. border: 2rpx solid rgba(158, 161, 168, 1);
  266. border-radius: 24rpx;
  267. background: rgba(255, 255, 255, 1);
  268. padding: 8rpx 24rpx !important;
  269. height: 96rpx;
  270. }
  271. .send-msg {
  272. color: rgba(1, 107, 246, 1);
  273. font-size: 28rpx;
  274. font-weight: 400;
  275. }
  276. .eye{
  277. position: absolute;
  278. top: 50%;
  279. right: 24rpx;
  280. font-size: 48rpx;
  281. transform: translateY(-50%);
  282. }
  283. .eye-active{
  284. color: #016bf6;
  285. }
  286. .line-progress{
  287. margin: 32rpx 0;
  288. }
  289. .confirm-btn {
  290. height: 80rpx;
  291. line-height: 80rpx;
  292. border-radius: 60rpx;
  293. margin: 0 32rpx;
  294. background: #016bf6;
  295. color: #fff;
  296. font-size: 32rpx;
  297. font-weight: 400;
  298. &:after {
  299. border-radius: 60px;
  300. }
  301. }
  302. // 密码要求列表
  303. .password-rules {
  304. margin-top: 20rpx;
  305. }
  306. .rule-item {
  307. display: flex;
  308. align-items: center;
  309. margin-bottom: 12rpx;
  310. image{
  311. width: 32rpx;
  312. height: 32rpx;
  313. margin-right: 16rpx;
  314. }
  315. }
  316. .rule-text {
  317. color: #4c4a53;
  318. font-family: Roboto;
  319. font-size: 32rpx;
  320. font-weight: 400;
  321. line-height: 51.2rpx;
  322. text-align: left;
  323. }
  324. .rule-valid .rule-text {
  325. color: #4c4a53;
  326. }
  327. .input-box {
  328. position: relative;
  329. }
  330. .next-btn-active {
  331. background: #2979ff;
  332. }
  333. ::v-deep .u-input {
  334. text-align: left !important;
  335. }
  336. .progress-box {
  337. display: flex;
  338. justify-content: center;
  339. align-items: center;
  340. gap: 24rpx;
  341. padding-top: 40rpx;
  342. box-sizing: border-box;
  343. .progress-item {
  344. width: 40rpx;
  345. height: 8rpx;
  346. background-color: #016bf6;
  347. border-radius: 40rpx;
  348. }
  349. }
  350. </style>