u
This commit is contained in:
1 parent
4aaa93df7d
commit
c330e52fd3
66 files changed
+7386
-4
No files matched your search
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* 对比新旧对象,只返回变化字段,同时保留主键
|
||||
* @param {Object} newData 新对象
|
||||
* @param {Object} oldData 旧对象
|
||||
* @param {Array<string>} primaryKeys 主键字段数组
|
||||
* @param {Array<string>} excludeKeys 排除字段(可选)
|
||||
* @returns {{ isChanged: boolean, result: Object }} 明确返回值结构
|
||||
*/
|
||||
export function diffObject(newData, oldData, primaryKeys = [], excludeKeys = []) {
|
||||
const result = {};
|
||||
let isChanged = false;
|
||||
|
||||
// 先把主键字段放入结果
|
||||
for (const pk of primaryKeys) {
|
||||
if (pk in newData) {
|
||||
result[pk] = newData[pk];
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of Object.keys(newData)) {
|
||||
if (excludeKeys.includes(key)) continue;
|
||||
if (key.startsWith("_") || key.startsWith("v_")) continue; // 可选:忽略 v_ 前缀字段
|
||||
|
||||
const newVal = newData[key];
|
||||
const oldVal = oldData[key];
|
||||
|
||||
// 只比较原始类型
|
||||
if (newVal !== oldVal) {
|
||||
result[key] = newVal;
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
return { isChanged, result };
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import mitt from "mitt";
|
||||
|
||||
const emitter = mitt();
|
||||
|
||||
export default emitter;
|
||||
@@ -0,0 +1,5 @@
|
||||
import throttle from "lodash/throttle";
|
||||
|
||||
export function useThrottle(fn, delay = 150) {
|
||||
return throttle(fn, delay);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// utils/uuid.js
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
/**
|
||||
* 获取唯一 ID
|
||||
*/
|
||||
export function getUuid() {
|
||||
const id = uuidv4();
|
||||
return id;
|
||||
}
|
||||
Reference in new issue
Block a user