|
|
@@ -0,0 +1,72 @@
|
|
|
+//比较对象的值
|
|
|
+export function contrastObj(newval, oldval) {
|
|
|
+ let reg = /^[A-Za-z]+$/;
|
|
|
+ for (let key in newval) {
|
|
|
+ if(typeof newval[key]=='string'){
|
|
|
+ if (reg.test(key) && !(newval[key] instanceof Array) && (newval[key] != oldval[key] && (newval[key] || oldval[key]))) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
+
|
|
|
+//比较数组的值(有序)
|
|
|
+export function contrastList(newlist, oldlist) {
|
|
|
+ if (newlist.length != oldlist.length) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ let reg = /^[A-Za-z]+$/;
|
|
|
+ for (var i = 0; i < newlist.length; i++) {
|
|
|
+ for (let newitem in newlist[i]) {
|
|
|
+ for (let olditem in oldlist[i]) {
|
|
|
+ if (!reg.test(newitem)) {
|
|
|
+ delete newlist[i].newitem
|
|
|
+ }
|
|
|
+ if (!reg.test(oldlist[i])) {
|
|
|
+ delete oldlist[i].olditem
|
|
|
+ }
|
|
|
+ if (newitem == olditem) {
|
|
|
+ if (!(newlist[i][newitem] instanceof Array)) {
|
|
|
+ if (newlist[i][newitem] != oldlist[i][olditem]) {
|
|
|
+ console.log(newitem, i, newlist[i][newitem], oldlist[i][olditem])
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+//比较数组的值(无序)
|
|
|
+export function contrastList2(newlist, oldlist) {
|
|
|
+ if (newlist.length != oldlist.length) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ let reg = /^[A-Za-z]+$/;
|
|
|
+ for (var i = 0; i < newlist.length; i++) {
|
|
|
+ for (var j = 0; j < oldlist.length; j++) {
|
|
|
+ for (let newitem in newlist[i]) {
|
|
|
+ for (let olditem in oldlist[j]) {
|
|
|
+ if (newlist[i].id == oldlist[j].id) {
|
|
|
+ if (!reg.test(newitem)) {
|
|
|
+ delete newlist[i].newitem
|
|
|
+ }
|
|
|
+ if (!reg.test(oldlist[j])) {
|
|
|
+ delete oldlist[j].olditem
|
|
|
+ }
|
|
|
+ if (newitem == olditem) {
|
|
|
+ if (!(newlist[i][newitem] instanceof Array)) {
|
|
|
+ if (newlist[i][newitem] != oldlist[j][olditem]) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|