password.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view>
  4. <cu-custom bgImage="/static/bg.png" :isBack="true">
  5. <template v-slot:content>
  6. <text class="text-black">修改密码</text>
  7. </template>
  8. </cu-custom>
  9. <view class="padding">
  10. <uni-forms ref="pwdFormX" :label-width="130" :model="pwdForm" :rules="rules">
  11. <uni-forms-item class="text-bold text-black" label="旧密码" name="oldPassword">
  12. <uni-easyinput type="password" v-model="pwdForm.oldPassword"/>
  13. </uni-forms-item>
  14. <uni-forms-item class="text-bold text-black" label="新密码" name="newPassword">
  15. <uni-easyinput type="password" v-model="pwdForm.newPassword"/>
  16. </uni-forms-item>
  17. <uni-forms-item class="text-bold text-black" label="确认密码" name="confirmPassword">
  18. <uni-easyinput type="password" v-model="pwdForm.confirmPassword"/>
  19. </uni-forms-item>
  20. <view class="margin-top text-center">
  21. <button class="cu-btn bg-zblue border lg margin-top" style="width: 100%;" @tap="submit">保存</button>
  22. </view>
  23. </uni-forms>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup lang="ts">
  28. import CuCustom from '@/colorui/components/cu-custom.vue'
  29. import {reactive, ref} from "vue";
  30. import UniForms from "@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
  31. import UniFormsItem from "@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
  32. import UniEasyinput from "@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue";
  33. import UserApi from "@/api/UserApi";
  34. import MessageUtils from "@/utils/MessageUtils";
  35. import Auth from "@/api/Auth";
  36. const fontValue=ref(Auth.getfontSize());
  37. const pwdFormX = ref();
  38. const pwdForm = reactive({
  39. oldPassword: '',
  40. newPassword: '',
  41. confirmPassword: ''
  42. })
  43. const equalToPassword = (rule:any, value:any,data:any, callback:(err?:string)=>{}) => {
  44. if (pwdForm.newPassword !== value) {
  45. callback('两次输入的密码不一致')
  46. } else {
  47. return true
  48. }
  49. }
  50. const rules = {
  51. oldPassword: {
  52. rules: [
  53. { required: true, errorMessage: '旧密码不能为空', trigger: 'blur' }
  54. ]
  55. },
  56. newPassword: {
  57. rules: [
  58. { required: true, errorMessage: '新密码不能为空', trigger: 'blur' },
  59. {
  60. minLength: 5,
  61. maxLength: 10,
  62. errorMessage: '长度在 {minLength} 到 {maxLength} 个字符',
  63. }
  64. ]
  65. },
  66. confirmPassword: {
  67. rules: [
  68. { required: true, errorMessage: '确认密码不能为空', trigger: 'blur' },
  69. { required: true, validateFunction: equalToPassword, trigger: 'blur' }
  70. ]
  71. }
  72. }
  73. /** 提交按钮 */
  74. function submit() {
  75. pwdFormX.value.validate().then(() => {
  76. UserApi.updateUserPwd(pwdForm.oldPassword, pwdForm.newPassword).then(
  77. () => {
  78. pwdForm.oldPassword = '';
  79. pwdForm.newPassword = '';
  80. pwdForm.confirmPassword = '';
  81. MessageUtils.success('修改成功');
  82. uni.navigateBack()
  83. }
  84. )
  85. })
  86. }
  87. </script>
  88. <style scoped>
  89. </style>