Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit 16792a0

Browse files
author
Steffan
committed
update evaluate method
1 parent 227246f commit 16792a0

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/node_modules
22
yarn-error.log
33
.DS_Store
4+
.history
45
.idea

src/field.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default {
4646

4747
get() {
4848

49-
if (this.enable && !this.Fields.evaluate(this.enable)) {
49+
if (!this.Fields.evaluate(this.enable)) {
5050
return assign({disabled: 'true'}, this.attrs);
5151
}
5252

src/fields.vue

+26-24
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import FieldSelect from './components/Select.vue';
1919
import FieldRange from './components/Range.vue';
2020
import FieldNumber from './components/Number.vue';
21-
import {assign, each, get, parse, isArray, isString, isUndefined, set, warn} from './util';
21+
import {assign, each, get, parse, isArray, isString, isFunction, isUndefined, set, warn} from './util';
2222
2323
export default {
2424
@@ -72,29 +72,6 @@
7272
this.$emit('change', value, field);
7373
},
7474
75-
evaluate(expression, values = this.values) {
76-
77-
try {
78-
79-
if (isUndefined(expression)) {
80-
return true;
81-
}
82-
83-
if (isString(expression)) {
84-
expression = parse(expression);
85-
}
86-
87-
return expression.call(this, values, {
88-
$match, $get: key => get(values, key)
89-
});
90-
91-
} catch (e) {
92-
warn(e);
93-
}
94-
95-
return true;
96-
},
97-
9875
prepare(config = this.config, prefix = this.prefix) {
9976
10077
const arr = isArray(config), fields = [];
@@ -126,6 +103,31 @@
126103
});
127104
128105
return fields;
106+
},
107+
108+
evaluate(expression, values = this.values) {
109+
110+
try {
111+
112+
if (isUndefined(expression)) {
113+
return true;
114+
}
115+
116+
if (isString(expression)) {
117+
expression = parse(expression);
118+
}
119+
120+
if (isFunction(expression)) {
121+
return expression.call(this, values, {$match, $get: key => get(values, key)});
122+
}
123+
124+
return expression;
125+
126+
} catch (e) {
127+
warn(e);
128+
}
129+
130+
return true;
129131
}
130132
131133
}

src/util.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ export function warn(message, color = '#DB6B00') {
2323
log(message, color);
2424
}
2525

26+
export function isObject(obj) {
27+
return obj !== null && typeof obj === 'object';
28+
}
29+
2630
export function isString(val) {
2731
return typeof val === 'string';
2832
}
2933

30-
export function isObject(obj) {
31-
return obj !== null && typeof obj === 'object';
34+
export function isFunction(val) {
35+
return typeof val === 'function';
3236
}
3337

3438
export function isUndefined(val) {

0 commit comments

Comments
 (0)