forgetPwd.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 if(this.sendTime != '获取验证码'){
  112. return;
  113. }else {
  114. this.$queue.showLoading("正在发送验证码...");
  115. this.$Request.getT("/app/Login/sendMsg/" + phone + "/forget").then((res) => {
  116. if (res.code === 0) {
  117. this.sending = true;
  118. this.$queue.showToast("验证码发送成功请注意查收");
  119. this.countDown();
  120. uni.hideLoading();
  121. } else {
  122. uni.hideLoading();
  123. uni.showModal({
  124. showCancel: false,
  125. title: "短信发送失败",
  126. content: res.msg ? res.msg : "请一分钟后再获取验证码",
  127. });
  128. }
  129. });
  130. }
  131. },
  132. countDown() {
  133. const {count} = this;
  134. if (count === 1) {
  135. this.count = 60;
  136. this.sending = false;
  137. this.sendTime = "获取验证码";
  138. } else {
  139. this.count = count - 1;
  140. this.sending = true;
  141. this.sendTime = count - 1 + "秒后重新获取";
  142. setTimeout(this.countDown.bind(this), 1000);
  143. }
  144. },
  145. inputChange(e) {
  146. const key = e.currentTarget.dataset.key;
  147. this[key] = e.detail.value;
  148. if(key == 'password'){
  149. this.checkPasswordStrength(this.password);
  150. }
  151. },
  152. checkPasswordStrength(pwd) {
  153. let strength = 0;
  154. this.list.forEach(item => {
  155. if (item.name === 'length') {
  156. item.checked = pwd.length >= 8;
  157. if (item.checked) strength++;
  158. } else if (item.name === 'number') {
  159. item.checked = /[0-9]/.test(pwd);
  160. if (item.checked) strength++;
  161. } else if (item.name === 'upper') {
  162. item.checked = /[A-Z]/.test(pwd);
  163. if (item.checked) strength++;
  164. }
  165. });
  166. this.passwordStrength = strength;
  167. this.valueBackup = this.list.map(i => i.checked);
  168. },
  169. navBack() {
  170. uni.navigateBack();
  171. },
  172. navTo(url) {
  173. uni.navigateTo({
  174. url,
  175. });
  176. },
  177. toLogin() {
  178. const {phone,password,code} = this;
  179. if (!phone) {
  180. this.$queue.showToast("请输入手机号");
  181. } else if (!code) {
  182. this.$queue.showToast("请输入验证码");
  183. }else if (!password) {
  184. this.$queue.showToast("请设置密码");
  185. } else if (password.length < 8) {
  186. this.$queue.showToast("密码位数必须大于八位");
  187. } else if (!/(?=.*[A-Z])(?=.*\d)/.test(password)) {
  188. this.$queue.showToast("密码必须包含至少一个大写字母和一个数字");
  189. } else {
  190. this.logining = true;
  191. this.$queue.showLoading("正在修改密码中...");
  192. this.$Request
  193. .post("/app/Login/forgetPwd", {
  194. pwd: password,
  195. phone: phone,
  196. msg: code,
  197. })
  198. .then((res) => {
  199. uni.hideLoading();
  200. if (res.code === 0) {
  201. uni.navigateTo({
  202. url: "/pages/public/loginphone?type=1",
  203. });
  204. } else {
  205. uni.showModal({
  206. showCancel: false,
  207. title: "密码找回失败",
  208. content: res.msg,
  209. });
  210. }
  211. });
  212. }
  213. },
  214. },
  215. };
  216. </script>
  217. <style lang="scss">
  218. page {
  219. background: #ffffff !important;
  220. }
  221. ::v-deep .input-placeholder,.uni-input-placeholder {
  222. color: #9ea1a8;
  223. font-family: DM Sans;
  224. font-size: 28rpx;
  225. font-weight: 400;
  226. text-align: left;
  227. }
  228. ::v-deep .u-checkbox__label{
  229. margin-left: 20rpx;
  230. color: rgba(76, 74, 83, 1);
  231. font-family: Roboto;
  232. font-size: 32rpx;
  233. font-weight: 400;
  234. }
  235. .container {
  236. padding-top: 32rpx;
  237. position: relative;
  238. width: 100%;
  239. height: 100%;
  240. overflow: hidden;
  241. background: #ffffff;
  242. }
  243. .wrapper {
  244. position: relative;
  245. z-index: 90;
  246. background: #ffffff;
  247. padding-bottom: 20px;
  248. }
  249. .input-content {
  250. padding: 32rpx;
  251. box-sizing: border-box;
  252. }
  253. .item-label {
  254. color: rgba(18, 26, 44, 1);
  255. font-family: Roboto;
  256. font-size: 32rpx;
  257. font-weight: 400;
  258. line-height: 51.2rpx;
  259. letter-spacing: 0px;
  260. text-align: left;
  261. padding-bottom: 8rpx;
  262. margin-top: 32rpx;
  263. }
  264. .cu-form-group {
  265. position: relative;
  266. box-sizing: border-box;
  267. border: 2rpx solid rgba(158, 161, 168, 1);
  268. border-radius: 24rpx;
  269. background: rgba(255, 255, 255, 1);
  270. padding: 8rpx 24rpx !important;
  271. height: 96rpx;
  272. }
  273. .send-msg {
  274. color: rgba(1, 107, 246, 1);
  275. font-size: 28rpx;
  276. font-weight: 400;
  277. }
  278. .eye{
  279. position: absolute;
  280. top: 50%;
  281. right: 24rpx;
  282. font-size: 48rpx;
  283. transform: translateY(-50%);
  284. }
  285. .eye-active{
  286. color: #016bf6;
  287. }
  288. .line-progress{
  289. margin: 32rpx 0;
  290. }
  291. .confirm-btn {
  292. height: 80rpx;
  293. line-height: 80rpx;
  294. border-radius: 60rpx;
  295. margin: 0 32rpx;
  296. background: #016bf6;
  297. color: #fff;
  298. font-size: 32rpx;
  299. font-weight: 400;
  300. &:after {
  301. border-radius: 60px;
  302. }
  303. }
  304. // 密码要求列表
  305. .password-rules {
  306. margin-top: 20rpx;
  307. }
  308. .rule-item {
  309. display: flex;
  310. align-items: center;
  311. margin-bottom: 12rpx;
  312. image{
  313. width: 32rpx;
  314. height: 32rpx;
  315. margin-right: 16rpx;
  316. }
  317. }
  318. .rule-text {
  319. color: #4c4a53;
  320. font-family: Roboto;
  321. font-size: 32rpx;
  322. font-weight: 400;
  323. line-height: 51.2rpx;
  324. text-align: left;
  325. }
  326. .rule-valid .rule-text {
  327. color: #4c4a53;
  328. }
  329. .input-box {
  330. position: relative;
  331. }
  332. .next-btn-active {
  333. background: #2979ff;
  334. }
  335. ::v-deep .u-input {
  336. text-align: left !important;
  337. }
  338. .progress-box {
  339. display: flex;
  340. justify-content: center;
  341. align-items: center;
  342. gap: 24rpx;
  343. padding-top: 40rpx;
  344. box-sizing: border-box;
  345. .progress-item {
  346. width: 40rpx;
  347. height: 8rpx;
  348. background-color: #016bf6;
  349. border-radius: 40rpx;
  350. }
  351. }
  352. </style>