diff --git a/src/pages/node/list/index.vue b/src/pages/node/list/index.vue index 40aad6f38c1e4257ae70b1b626c5588602653c59..09369158f9e29f05d29e42d18594b16fbbe9f451 100644 --- a/src/pages/node/list/index.vue +++ b/src/pages/node/list/index.vue @@ -179,6 +179,7 @@ import NodeLayout from './node-layout' import NodeOperation from './components/node_operation.vue' import { isIpAndPort } from '@/utils/validate' import { mapState } from 'vuex' +import { deepClone } from '@/utils/obj' export default { components: { NodeLayout, @@ -338,7 +339,7 @@ export default { item['status'] = 1 this.list = [...this.list] // 获取到节点调用一次编辑接口 - const query = JSON.parse(JSON.stringify(item)) + const query = deepClone(item) query.type = '' editNode(query) } else { @@ -438,7 +439,7 @@ export default { cancelText: '取消', onOk: () => { // 注册 - let query = JSON.parse(JSON.stringify(record)) + let query = deepClone(record) query.checkStatus = true query.type = 'edit' editNode(query).then((res) => { diff --git a/src/utils/obj.js b/src/utils/obj.js new file mode 100644 index 0000000000000000000000000000000000000000..765d9b408cadacb86861429de2f8d227fedcf7a3 --- /dev/null +++ b/src/utils/obj.js @@ -0,0 +1,48 @@ +// 深拷贝简单的对象或数组 +export function deepClone(obj) { + return JSON.parse(JSON.stringify(obj)); + } + +/** + * 深度克隆对象(针对复杂的对象或数组) + * @param {any} obj - 需要克隆的对象 + * @returns {any} 克隆后的对象 + */ +function isObject(obj) { + return (typeof obj === 'object' && obj !== null) || typeof obj === 'function'; +} + +export function deepCloneV2(obj, seen = new WeakMap()) { + if (!isObject(obj)) { + return obj; + } + + if (seen.has(obj)) { + return seen.get(obj); + } + + let cloneObj; + + if (obj instanceof Date) { + cloneObj = new Date(obj); + } else if (obj instanceof RegExp) { + cloneObj = new RegExp(obj); + } else { + cloneObj = Array.isArray(obj) ? [] : {}; + } + + seen.set(obj, cloneObj); + + for (const key in obj) { + if (obj.hasOwnProperty(key)) { + cloneObj[key] = deepClone(obj[key], seen); + } + } + + return cloneObj; +} + +// 数组去重 +export function unique(arr) { + return [...new Set(arr)]; + } \ No newline at end of file