@fastcar/core 0.3.6 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/db.d.ts +1 -0
- package/package.json +1 -1
- package/src/db.ts +1 -1
- package/src/model/DataMap.ts +18 -5
- package/target/db.js +1 -1
- package/target/model/DataMap.js +15 -4
package/db.d.ts
CHANGED
package/package.json
CHANGED
package/src/db.ts
CHANGED
|
@@ -173,7 +173,7 @@ export enum DesignMeta {
|
|
|
173
173
|
mapping = "db:mapping", //映射描述
|
|
174
174
|
dbFields = "db:fields", //数据库名-ts名
|
|
175
175
|
sqlSession = "SqlSession",
|
|
176
|
-
isSerial = "isSerial", //sql会话
|
|
176
|
+
isSerial = "db:isSerial", //sql会话
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
export interface DataSourceManager {
|
package/src/model/DataMap.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type FIELDTYPE = {
|
|
2
2
|
field: string;
|
|
3
3
|
order?: boolean; //是否为倒序 order true为倒序
|
|
4
|
-
compare?: (a: any, b: any) =>
|
|
4
|
+
compare?: (a: any, b: any) => -1 | 0 | 1; // -1 0 1 //-1为小 0为相等 1为大
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export default class DataMap<K, V extends Object> extends Map<K, V> {
|
|
@@ -32,22 +32,35 @@ export default class DataMap<K, V extends Object> extends Map<K, V> {
|
|
|
32
32
|
if (!sorts || sorts?.length == 0) {
|
|
33
33
|
return list;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
list.sort((a, b) => {
|
|
37
37
|
let resultNum = 0;
|
|
38
38
|
sorts.some((f, index) => {
|
|
39
|
+
let cindex = index + 1;
|
|
39
40
|
let field = f.field;
|
|
40
41
|
let aValue = Reflect.get(a, field);
|
|
41
42
|
let bValue = Reflect.get(b, field);
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
|
|
44
|
+
if (f.compare) {
|
|
45
|
+
let flag = f.compare(aValue, bValue);
|
|
46
|
+
if (flag == 0) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
resultNum = flag > 0 ? cindex : -cindex;
|
|
50
|
+
} else {
|
|
51
|
+
if (aValue == bValue) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
resultNum = aValue > bValue ? cindex : -cindex;
|
|
56
|
+
}
|
|
44
57
|
|
|
45
58
|
//降序则倒着
|
|
46
59
|
if (f.order) {
|
|
47
60
|
resultNum = -resultNum;
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
return
|
|
63
|
+
return true;
|
|
51
64
|
});
|
|
52
65
|
return resultNum;
|
|
53
66
|
});
|
package/target/db.js
CHANGED
|
@@ -46,5 +46,5 @@ var DesignMeta;
|
|
|
46
46
|
DesignMeta["mapping"] = "db:mapping";
|
|
47
47
|
DesignMeta["dbFields"] = "db:fields";
|
|
48
48
|
DesignMeta["sqlSession"] = "SqlSession";
|
|
49
|
-
DesignMeta["isSerial"] = "isSerial";
|
|
49
|
+
DesignMeta["isSerial"] = "db:isSerial";
|
|
50
50
|
})(DesignMeta || (exports.DesignMeta = DesignMeta = {}));
|
package/target/model/DataMap.js
CHANGED
|
@@ -23,20 +23,31 @@ class DataMap extends Map {
|
|
|
23
23
|
if (!sorts || sorts?.length == 0) {
|
|
24
24
|
return list;
|
|
25
25
|
}
|
|
26
|
-
let total = sorts.length;
|
|
27
26
|
list.sort((a, b) => {
|
|
28
27
|
let resultNum = 0;
|
|
29
28
|
sorts.some((f, index) => {
|
|
29
|
+
let cindex = index + 1;
|
|
30
30
|
let field = f.field;
|
|
31
31
|
let aValue = Reflect.get(a, field);
|
|
32
32
|
let bValue = Reflect.get(b, field);
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
if (f.compare) {
|
|
34
|
+
let flag = f.compare(aValue, bValue);
|
|
35
|
+
if (flag == 0) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
resultNum = flag > 0 ? cindex : -cindex;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (aValue == bValue) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
resultNum = aValue > bValue ? cindex : -cindex;
|
|
45
|
+
}
|
|
35
46
|
//降序则倒着
|
|
36
47
|
if (f.order) {
|
|
37
48
|
resultNum = -resultNum;
|
|
38
49
|
}
|
|
39
|
-
return
|
|
50
|
+
return true;
|
|
40
51
|
});
|
|
41
52
|
return resultNum;
|
|
42
53
|
});
|