password.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. 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. //定义表单规则
  48. var rule = [
  49. {name:"oldPassword", checkType : "notnull", checkRule:"", errorMsg:"密码不能为空"},
  50. {name:"newPassword", checkType : "notnull", checkRule:"", errorMsg:"新密码不能为空"},
  51. {name:"confirmNewPassword", checkType : "notnull", checkRule:"", errorMsg:"确认新密码不能为空"},
  52. {name:"confirmNewPassword", checkType : "same", checkRule: this.inputForm.newPassword, errorMsg:"两次输入的新密码不一致,请重新输入!"}
  53. ];
  54. //进行表单检查
  55. var formData = e.detail.value;
  56. var checkRes = graceChecker.check(formData, rule);
  57. if(checkRes){
  58. console.log(this.inputForm.newPassword)
  59. uni.showLoading()
  60. if (this.inputForm.newPassword && (this.inputForm.newPassword.length < 6 || this.inputForm.newPassword.length > 16)) {
  61. uni.showToast({
  62. icon: 'none',
  63. title: '密码长度为6-16位'
  64. });
  65. return;
  66. } else if (!(/\d/.test(this.inputForm.newPassword) && /[a-zA-Z]/.test(this.inputForm.newPassword))) {
  67. uni.showToast({
  68. icon: 'none',
  69. title: '密码必须包含字母+数字'
  70. });
  71. return;
  72. }
  73. let which=$auth.whichLogin();
  74. userService.savePwd(this.inputForm).then(({data}) => {
  75. uni.showToast({title:data, icon:"success"});
  76. if(which=='dzf'){
  77. uni.reLaunch({
  78. url: '/pages/login/dzflogin'
  79. });
  80. }else{
  81. uni.reLaunch({
  82. url: '/pages/login/login'
  83. });
  84. }
  85. }).catch((e)=>{
  86. })
  87. }else{
  88. uni.showToast({ title: graceChecker.error, icon: "none" });
  89. }
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. .btn-logout {
  96. margin-top: 100upx;
  97. width: 80%;
  98. border-radius: 50upx;
  99. font-size: 16px;
  100. color: #fff;
  101. background: linear-gradient(to right, #365fff, #36bbff);
  102. }
  103. .btn-logout-hover {
  104. background: linear-gradient(to right, #365fdd, #36bbfa);
  105. }
  106. .cu-form-group .title {
  107. min-width: calc(4em + 40px);
  108. }
  109. .info{
  110. margin-top: 30rpx;
  111. font-size: 30rpx;
  112. color: #333;
  113. padding-left: 20rpx;
  114. }
  115. </style>