feat: 登录信息加密传输
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import type { EasyFlowFormSchema } from '#/adapter/form';
|
||||
import type {EasyFlowFormSchema} from '#/adapter/form';
|
||||
|
||||
import { computed, markRaw, onMounted, ref } from 'vue';
|
||||
import {computed, markRaw, nextTick, onMounted, ref} from 'vue';
|
||||
|
||||
import { ProfileBaseSetting } from '@easyflow/common-ui';
|
||||
import {ProfileBaseSetting} from '@easyflow/common-ui';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
import {ElMessage} from 'element-plus';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
import {api} from '#/api/request';
|
||||
import Cropper from '#/components/upload/Cropper.vue';
|
||||
import { $t } from '#/locales';
|
||||
import { useAuthStore } from '#/store';
|
||||
import {$t} from '#/locales';
|
||||
import {useAuthStore} from '#/store';
|
||||
|
||||
const { fetchUserInfo } = useAuthStore();
|
||||
const profileBaseSettingRef = ref();
|
||||
@@ -48,9 +48,16 @@ onMounted(async () => {
|
||||
});
|
||||
async function getInfo() {
|
||||
loading.value = true;
|
||||
const data = await fetchUserInfo();
|
||||
await profileBaseSettingRef.value.getFormApi().setValues(data);
|
||||
loading.value = false;
|
||||
try {
|
||||
const data = await fetchUserInfo();
|
||||
await nextTick();
|
||||
const formApi = profileBaseSettingRef.value?.getFormApi?.();
|
||||
if (formApi) {
|
||||
await formApi.setValues(data);
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
const loading = ref(false);
|
||||
const updateLoading = ref(false);
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<script setup lang="ts">
|
||||
import type { EasyFlowFormSchema } from '#/adapter/form';
|
||||
import type {EasyFlowFormSchema} from '#/adapter/form';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import {computed, ref} from 'vue';
|
||||
import {useRoute, useRouter} from 'vue-router';
|
||||
|
||||
import { ProfilePasswordSetting, z } from '@easyflow/common-ui';
|
||||
import { preferences } from '@easyflow/preferences';
|
||||
import { useUserStore } from '@easyflow/stores';
|
||||
import {ProfilePasswordSetting, z} from '@easyflow/common-ui';
|
||||
import {preferences} from '@easyflow/preferences';
|
||||
import {useUserStore} from '@easyflow/stores';
|
||||
|
||||
import { ElMessage } from 'element-plus';
|
||||
import {ElMessage} from 'element-plus';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
import { $t } from '#/locales';
|
||||
import { useAuthStore } from '#/store';
|
||||
import { isStrongPassword } from '#/utils/password-policy';
|
||||
import {getCredentialKeyApi} from '#/api';
|
||||
import {api} from '#/api/request';
|
||||
import {$t} from '#/locales';
|
||||
import {useAuthStore} from '#/store';
|
||||
import {encryptCredentialPayload} from '#/utils/credential-encryption';
|
||||
import {isStrongPassword} from '#/utils/password-policy';
|
||||
|
||||
const profilePasswordSettingRef = ref();
|
||||
const authStore = useAuthStore();
|
||||
@@ -87,7 +89,14 @@ const updateLoading = ref(false);
|
||||
async function handleSubmit(values: any) {
|
||||
updateLoading.value = true;
|
||||
try {
|
||||
const res = await api.post('/api/v1/sysAccount/updatePassword', values);
|
||||
const encryptedPayload = await encryptCredentialPayload(
|
||||
getCredentialKeyApi,
|
||||
values,
|
||||
);
|
||||
const res = await api.post(
|
||||
'/api/v1/sysAccount/updatePassword',
|
||||
encryptedPayload,
|
||||
);
|
||||
if (res.errorCode === 0) {
|
||||
ElMessage.success($t('message.success'));
|
||||
const userInfo = await authStore.fetchUserInfo();
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import type { FormInstance } from 'element-plus';
|
||||
import type {FormInstance} from 'element-plus';
|
||||
import {ElForm, ElFormItem, ElInput, ElMessage} from 'element-plus';
|
||||
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import {onMounted, ref, watch} from 'vue';
|
||||
|
||||
import { EasyFlowFormModal, EasyFlowInputPassword } from '@easyflow/common-ui';
|
||||
import {EasyFlowFormModal, EasyFlowInputPassword} from '@easyflow/common-ui';
|
||||
|
||||
import { ElForm, ElFormItem, ElInput, ElMessage } from 'element-plus';
|
||||
|
||||
import { api } from '#/api/request';
|
||||
import {getCredentialKeyApi} from '#/api';
|
||||
import {api} from '#/api/request';
|
||||
import DictSelect from '#/components/dict/DictSelect.vue';
|
||||
// import Cropper from '#/components/upload/Cropper.vue';
|
||||
import UploadAvatar from '#/components/upload/UploadAvatar.vue';
|
||||
import { $t } from '#/locales';
|
||||
import { isStrongPassword } from '#/utils/password-policy';
|
||||
import {$t} from '#/locales';
|
||||
import {encryptCredentialPayload} from '#/utils/credential-encryption';
|
||||
import {isStrongPassword} from '#/utils/password-policy';
|
||||
|
||||
const emit = defineEmits(['reload']);
|
||||
// vue
|
||||
@@ -107,26 +108,33 @@ function openDialog(row: any) {
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
function save() {
|
||||
saveForm.value?.validate((valid) => {
|
||||
saveForm.value?.validate(async (valid) => {
|
||||
if (valid) {
|
||||
btnLoading.value = true;
|
||||
const { confirmPassword: _confirmPassword, ...payload } = entity.value;
|
||||
api
|
||||
.post(
|
||||
try {
|
||||
const {
|
||||
confirmPassword: _confirmPassword,
|
||||
password,
|
||||
...payload
|
||||
} = entity.value;
|
||||
if (isAdd.value) {
|
||||
payload.passwordCredential = await encryptCredentialPayload(
|
||||
getCredentialKeyApi,
|
||||
{ password },
|
||||
);
|
||||
}
|
||||
const res = await api.post(
|
||||
isAdd.value ? 'api/v1/sysAccount/save' : 'api/v1/sysAccount/update',
|
||||
payload,
|
||||
)
|
||||
.then((res) => {
|
||||
btnLoading.value = false;
|
||||
if (res.errorCode === 0) {
|
||||
ElMessage.success(res.message);
|
||||
emit('reload');
|
||||
closeDialog();
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
btnLoading.value = false;
|
||||
});
|
||||
);
|
||||
if (res.errorCode === 0) {
|
||||
ElMessage.success(res.message);
|
||||
emit('reload');
|
||||
closeDialog();
|
||||
}
|
||||
} finally {
|
||||
btnLoading.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user