savepassword.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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" :model="pwdForm" :label-width="130" :rules="rules">
  11. <uni-forms-item class="text-bold text-black" label="新密码" name="newPassword">
  12. <uni-easyinput type="password" v-model="pwdForm.newPassword"/>
  13. </uni-forms-item>
  14. <uni-forms-item class="text-bold text-black" label="确认密码" name="confirmPassword">
  15. <uni-easyinput type="password" v-model="pwdForm.confirmPassword"/>
  16. </uni-forms-item>
  17. <view class="margin-top text-center">
  18. <button class="cu-btn bg-zblue border lg margin-top" style="width: 100%;" @tap="submit">保存</button>
  19. </view>
  20. </uni-forms>
  21. </view>
  22. </view>
  23. </template>
  24. <script setup lang="ts">
  25. import CuCustom from '@/colorui/components/cu-custom.vue'
  26. import {reactive, ref} from "vue";
  27. import {useUserStore} from "@/store/userStore";
  28. import UniForms from "@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
  29. import UniFormsItem from "@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
  30. import UniEasyinput from "@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue";
  31. import MessageUtils from "@/utils/MessageUtils";
  32. import Auth from "@/api/Auth";
  33. const fontValue=ref(Auth.getfontSize());
  34. const userStore = useUserStore()
  35. const pwdFormX = ref();
  36. const pwdForm = reactive({
  37. newPassword: '',
  38. confirmPassword: ''
  39. })
  40. const equalToPassword = (rule:any, value:any,data:any, callback:(err?:string)=>{}) => {
  41. if (pwdForm.newPassword !== value) {
  42. callback('两次输入的密码不一致')
  43. } else {
  44. return true
  45. }
  46. }
  47. const rules = {
  48. newPassword: {
  49. rules: [
  50. { required: true, errorMessage: '新密码不能为空', trigger: 'blur' },
  51. {
  52. minLength: 5,
  53. maxLength: 10,
  54. errorMessage: '长度在 {minLength} 到 {maxLength} 个字符',
  55. }
  56. ]
  57. },
  58. confirmPassword: {
  59. rules: [
  60. { required: true, errorMessage: '确认密码不能为空', trigger: 'blur' },
  61. { required: true, validateFunction: equalToPassword, trigger: 'blur' }
  62. ]
  63. }
  64. }
  65. /** 提交按钮 */
  66. function submit() {
  67. if(pwdForm.newPassword==null||pwdForm.newPassword==''||pwdForm.newPassword==undefined){
  68. MessageUtils.message('请输入安全密码!')
  69. return;
  70. }
  71. else{
  72. if(pwdForm.newPassword!=pwdForm.confirmPassword){
  73. MessageUtils.message('两次输入的密码不一致!')
  74. return;
  75. }
  76. }
  77. var name = userStore.getUser()?.name;
  78. console.log(name);
  79. uni.setStorageSync(name,pwdForm.newPassword);
  80. uni.navigateBack();
  81. }
  82. </script>
  83. <style scoped>
  84. </style>