password.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-gradual-blue" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">修改密码</block>
  6. </cu-custom>
  7. <form @submit="formSubmit">
  8. <view class="cu-form-group margin-top">
  9. <view class="title"> <text class="red-color">*</text> 旧密码</view>
  10. <input placeholder="请输入原密码" type="password" v-model="inputForm.oldPassword" name="oldPassword"></input>
  11. </view>
  12. <view class="cu-form-group">
  13. <view class="title"><text class="red-color">*</text>新密码</view>
  14. <input placeholder="请输入新密码" type="password" v-model="inputForm.newPassword" name="newPassword"></input>
  15. </view>
  16. <view class="cu-form-group">
  17. <view class="title"><text class="red-color">*</text>确认新密码</view>
  18. <input placeholder="请确认新密码" type="password" v-model="inputForm.confirmNewPassword" name="confirmNewPassword"></input>
  19. </view>
  20. <view class="info">注意:密码须同时包含大小写字母、数字及特殊字符,长度 8-20 位</view>
  21. <view class="padding-xl">
  22. <button form-type="submit" class="cu-btn block bg-blue margin-tb-sm lg" >提交</button>
  23. </view>
  24. </form>
  25. </view>
  26. </template>
  27. <script>
  28. import userService from "@/api/sys/userService"
  29. import * as $auth from "@/common/auth"
  30. var graceChecker = require("@/common/graceChecker.js");
  31. export default {
  32. onShow() {
  33. this.$auth.checkLogin()
  34. },
  35. data () {
  36. return {
  37. loading: false,
  38. inputForm: {
  39. oldPassword: '',
  40. newPassword: '',
  41. confirmNewPassword: ''
  42. }
  43. }
  44. },
  45. methods:{
  46. formSubmit: function (e) {
  47. // 原有 graceChecker 规则保留
  48. var rule = [
  49. {name:"oldPassword", checkType:"notnull", errorMsg:"密码不能为空"},
  50. {name:"newPassword", checkType:"notnull", errorMsg:"新密码不能为空"},
  51. {name:"confirmNewPassword", checkType:"notnull", errorMsg:"确认新密码不能为空"},
  52. {name:"confirmNewPassword", checkType:"same", checkRule:this.inputForm.newPassword, errorMsg:"两次输入的新密码不一致,请重新输入!"}
  53. ];
  54. var formData = e.detail.value;
  55. if(!graceChecker.check(formData, rule)){
  56. uni.showToast({title: graceChecker.error, icon:"none"});
  57. return;
  58. }
  59. /* ========== 新规则校验 ========== */
  60. const pwd = this.inputForm.newPassword;
  61. if(pwd.length<8 || pwd.length>20){
  62. uni.showToast({icon:'none',title:'密码长度为 8-20 位'});
  63. return;
  64. }
  65. // 必须同时包含:大写、小写、数字、特殊字符
  66. if(!/(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^A-Za-z0-9])/.test(pwd)){
  67. uni.showToast({icon:'none',title:'密码须同时包含大小写字母、数字及特殊字符'});
  68. return;
  69. }
  70. /* ========== 提交后台 ========== */
  71. uni.showLoading();
  72. userService.savePwd(this.inputForm).then(({data})=>{
  73. uni.showToast({title:data, icon:"success"});
  74. const which = $auth.whichLogin();
  75. uni.reLaunch({url: which=='dzf' ? '/pages/login/dzflogin' : '/pages/login/login'});
  76. }).catch(()=>{});
  77. }
  78. }
  79. }
  80. </script>
  81. <style>
  82. .btn-logout {
  83. margin-top: 100upx;
  84. width: 80%;
  85. border-radius: 50upx;
  86. font-size: 16px;
  87. color: #fff;
  88. background: linear-gradient(to right, #365fff, #36bbff);
  89. }
  90. .btn-logout-hover {
  91. background: linear-gradient(to right, #365fdd, #36bbfa);
  92. }
  93. .cu-form-group .title {
  94. min-width: calc(4em + 40px);
  95. }
  96. .info{
  97. margin-top: 30rpx;
  98. font-size: 30rpx;
  99. color: #333;
  100. padding-left: 20rpx;
  101. }
  102. </style>