password.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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">注意:新密码长度必须在6-16位,并且同时包含字母和数字</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. var graceChecker = require("@/common/graceChecker.js");
  30. export default {
  31. onShow() {
  32. this.$auth.checkLogin()
  33. },
  34. data () {
  35. return {
  36. loading: false,
  37. inputForm: {
  38. oldPassword: '',
  39. newPassword: '',
  40. confirmNewPassword: ''
  41. }
  42. }
  43. },
  44. methods:{
  45. formSubmit: function(e) {
  46. //定义表单规则
  47. var rule = [
  48. {name:"oldPassword", checkType : "notnull", checkRule:"", errorMsg:"密码不能为空"},
  49. {name:"newPassword", checkType : "notnull", checkRule:"", errorMsg:"新密码不能为空"},
  50. {name:"confirmNewPassword", checkType : "notnull", checkRule:"", errorMsg:"确认新密码不能为空"},
  51. {name:"confirmNewPassword", checkType : "same", checkRule: this.inputForm.newPassword, errorMsg:"两次输入的新密码不一致,请重新输入!"}
  52. ];
  53. //进行表单检查
  54. var formData = e.detail.value;
  55. var checkRes = graceChecker.check(formData, rule);
  56. if(checkRes){
  57. uni.showLoading()
  58. if (this.newPassword && (this.newPassword.length < 6 || this.newPassword.length > 16)) {
  59. uni.showToast({
  60. icon: 'none',
  61. title: '密码长度为6-16位'
  62. });
  63. return;
  64. } else if (!(/\d/.test(this.newPassword) && /[a-zA-Z]/.test(this.newPassword))) {
  65. uni.showToast({
  66. icon: 'none',
  67. title: '密码必须包含字母+数字'
  68. });
  69. return;
  70. }
  71. userService.savePwd(this.inputForm).then(({data}) => {
  72. uni.showToast({title:data, icon:"success"});
  73. uni.navigateTo({
  74. url: '/pages/user/person/person'
  75. })
  76. }).catch((e)=>{
  77. })
  78. }else{
  79. uni.showToast({ title: graceChecker.error, icon: "none" });
  80. }
  81. }
  82. }
  83. }
  84. </script>
  85. <style>
  86. .btn-logout {
  87. margin-top: 100upx;
  88. width: 80%;
  89. border-radius: 50upx;
  90. font-size: 16px;
  91. color: #fff;
  92. background: linear-gradient(to right, #365fff, #36bbff);
  93. }
  94. .btn-logout-hover {
  95. background: linear-gradient(to right, #365fdd, #36bbfa);
  96. }
  97. .cu-form-group .title {
  98. min-width: calc(4em + 40px);
  99. }
  100. .info{
  101. margin-top: 30rpx;
  102. font-size: 30rpx;
  103. color: #333;
  104. padding-left: 20rpx;
  105. }
  106. </style>