mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-11-14 20:53:41 +08:00
optimize(manage): replace Object.assign with jsonClone for safer data handling in model initialization
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { useBoolean } from '@sa/hooks';
|
import { useBoolean } from '@sa/hooks';
|
||||||
import { enableStatusOptions } from '@/constants/business';
|
import { enableStatusOptions } from '@/constants/business';
|
||||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||||
@@ -72,7 +73,7 @@ function handleInitModel() {
|
|||||||
model.value = createDefaultModel();
|
model.value = createDefaultModel();
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
Object.assign(model.value, props.rowData);
|
Object.assign(model.value, jsonClone(props.rowData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { toRaw } from 'vue';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { enableStatusOptions } from '@/constants/business';
|
import { enableStatusOptions } from '@/constants/business';
|
||||||
import { translateOptions } from '@/utils/common';
|
import { translateOptions } from '@/utils/common';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
@@ -15,14 +17,10 @@ const emit = defineEmits<Emits>();
|
|||||||
|
|
||||||
const model = defineModel<Api.SystemManage.RoleSearchParams>('model', { required: true });
|
const model = defineModel<Api.SystemManage.RoleSearchParams>('model', { required: true });
|
||||||
|
|
||||||
|
const defaultModel = jsonClone(toRaw(model.value));
|
||||||
|
|
||||||
function resetModel() {
|
function resetModel() {
|
||||||
model.value = {
|
Object.assign(model.value, defaultModel);
|
||||||
current: 1,
|
|
||||||
size: 10,
|
|
||||||
roleName: null,
|
|
||||||
roleCode: null,
|
|
||||||
status: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function search() {
|
function search() {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { enableStatusOptions, userGenderOptions } from '@/constants/business';
|
import { enableStatusOptions, userGenderOptions } from '@/constants/business';
|
||||||
import { fetchGetAllRoles } from '@/service/api';
|
import { fetchGetAllRoles } from '@/service/api';
|
||||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||||
@@ -93,7 +94,7 @@ function handleInitModel() {
|
|||||||
model.value = createDefaultModel();
|
model.value = createDefaultModel();
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
Object.assign(model.value, props.rowData);
|
Object.assign(model.value, jsonClone(props.rowData));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed } from 'vue';
|
import { computed, toRaw } from 'vue';
|
||||||
|
import { jsonClone } from '@sa/utils';
|
||||||
import { enableStatusOptions, userGenderOptions } from '@/constants/business';
|
import { enableStatusOptions, userGenderOptions } from '@/constants/business';
|
||||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||||
import { translateOptions } from '@/utils/common';
|
import { translateOptions } from '@/utils/common';
|
||||||
@@ -30,17 +31,10 @@ const rules = computed<Record<RuleKey, App.Global.FormRule>>(() => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const defaultModel = jsonClone(toRaw(model.value));
|
||||||
|
|
||||||
function resetModel() {
|
function resetModel() {
|
||||||
model.value = {
|
Object.assign(model.value, defaultModel);
|
||||||
current: 1,
|
|
||||||
size: 10,
|
|
||||||
status: null,
|
|
||||||
userName: null,
|
|
||||||
userGender: null,
|
|
||||||
nickName: null,
|
|
||||||
userPhone: null,
|
|
||||||
userEmail: null
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function reset() {
|
async function reset() {
|
||||||
|
|||||||
Reference in New Issue
Block a user