updatePassword.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <a-modal
  3. :width="400"
  4. v-model:visible="visible"
  5. title="修改密码"
  6. :confirm-loading="confirmLoading"
  7. @ok="handleOk"
  8. ok-text="确认修改"
  9. cancel-text="取消"
  10. :keyboard="false"
  11. :mask-closable="false"
  12. >
  13. <a-form autocomplete="off">
  14. <p style="width:100%; color: red; text-align: center;margin-bottom: 5px"
  15. v-if="isShowUpdateMsg && updateDatNum >= 60">
  16. 距离上次修改密码已过去{{ updateDatNum }}天,建议修改密码</p>
  17. <a-row :gutter="24">
  18. <a-col :span="24">
  19. <a-form-item label="用户名" :label-col="{span:8}" name="userName">
  20. {{ dataModel.userName }}
  21. </a-form-item>
  22. </a-col>
  23. </a-row>
  24. <a-row :gutter="24">
  25. <a-col :span="24">
  26. <a-form-item label="帐号" :label-col="{span:8}" name="loginID">
  27. {{ dataModel.loginID }}
  28. </a-form-item>
  29. </a-col>
  30. </a-row>
  31. <a-row :gutter="24">
  32. <a-col :span="24">
  33. <a-form-item label="新密码" :label-col="{span:8}" name="pwd_default" v-bind="validateInfos.pwd_default">
  34. <a-input-password v-model:value="dataModel.pwd_default" placeholder="请填写8到16位新密码" type="password"
  35. maxlength="16" minlength="8"/>
  36. </a-form-item>
  37. </a-col>
  38. </a-row>
  39. <a-row :gutter="24">
  40. <a-col :span="24">
  41. <a-form-item label="确认新密码" :label-col="{span:8}" name="pwd_confirm" v-bind="validateInfos.pwd_confirm">
  42. <a-input-password v-model:value="dataModel.pwd_confirm" placeholder="请填写8到16位新密码" type="password"
  43. maxlength="16" minlength="8"/>
  44. </a-form-item>
  45. </a-col>
  46. </a-row>
  47. </a-form>
  48. </a-modal>
  49. </template>
  50. <script lang="ts">
  51. import {defineComponent, reactive, ref} from "vue";
  52. import {Form} from "ant-design-vue";
  53. import {updateUserPassword} from "@/api/system/user";
  54. import {useUserStore} from "@/store/modules/user";
  55. export default defineComponent({
  56. props: {
  57. loadData: {
  58. type: Function,
  59. default: null
  60. }
  61. },
  62. setup() {
  63. const userStore = useUserStore();
  64. const updateDatNum = ref<any>(userStore.getUpdateDayNum);
  65. const visible = ref<boolean>(false);
  66. const confirmLoading = ref<boolean>(false);
  67. const useForm = Form.useForm;
  68. const formState = reactive({
  69. loading: false,
  70. });
  71. const dataModel = ref({userID: '', userName: '', loginID: '', pwd_default: '', pwd_confirm: ''});
  72. const passwordRegex = /(?=.*[a-z_])(?=.*\d)(?=.*[^a-z0-9_])[\S]{8,}/i;
  73. const rulesRef = reactive({
  74. pwd_default: [
  75. {
  76. required: true,
  77. message: '请填写8到16位新密码!',
  78. }, {
  79. min: 8,
  80. max: 16,
  81. message: '密码必须包含字母、数字和特殊字符,且长度要在8到16位。',
  82. trigger: 'blur',
  83. pattern:passwordRegex
  84. }
  85. ],
  86. pwd_confirm: [
  87. {
  88. required: true,
  89. message: '请填写8到16位新密码!',
  90. }, {
  91. min: 8,
  92. max: 16,
  93. message: '密码必须包含字母、数字和特殊字符,且长度要在8到16位。',
  94. trigger: 'blur',
  95. pattern:passwordRegex
  96. }
  97. ]
  98. });
  99. const {validate, validateInfos} = useForm(dataModel, rulesRef);
  100. const isShowUpdateMsg = ref(false);
  101. const show = (userID: any, userName: any, loginID: any, showUpdateMsg: any) => {
  102. console.log(userID, userName, loginID)
  103. visible.value = true;
  104. dataModel.value.userID = userID;
  105. dataModel.value.userName = userName;
  106. dataModel.value.loginID = loginID;
  107. dataModel.value.pwd_default = "";
  108. dataModel.value.pwd_confirm = "";
  109. isShowUpdateMsg.value = showUpdateMsg;
  110. };
  111. const handleOk = () => {
  112. validate().then(() => {
  113. updateUserPassword(dataModel.value).then(result => {
  114. if (result) {
  115. visible.value = false;
  116. userStore.setUpdateDayNum();
  117. updateDatNum.value = 0;
  118. }
  119. });
  120. });
  121. };
  122. const handleCancel = () => {
  123. visible.value = false;
  124. };
  125. return {
  126. dataModel,
  127. visible,
  128. confirmLoading,
  129. show,
  130. handleOk,
  131. handleCancel,
  132. formState,
  133. validateInfos,
  134. validate,
  135. updateDatNum,
  136. isShowUpdateMsg
  137. };
  138. },
  139. created() {
  140. },
  141. })
  142. </script>