Browse Source

KERNEL-14512 refact: 调整 behavior 的位置

es6
Treecat 1 year ago
parent
commit
7b8b310651
  1. 17
      src/base/behavior/0.behavior.js
  2. 34
      src/base/behavior/behavior.highlight.js
  3. 25
      src/base/behavior/behavior.redmark.js
  4. 26
      src/base/behavior/index.js
  5. 2
      src/base/combination/group.button.js

17
src/base/behavior/0.behavior.js

@ -0,0 +1,17 @@
/**
* guy
* 行为控件
*/
import { OB, extend } from "@/core";
export class Behavior extends OB {
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
rule: () => true,
});
}
doBehavior() {
}
}

34
src/base/behavior/behavior.highlight.js

@ -0,0 +1,34 @@
/**
* guy
*/
import { isFunction, each } from "@/core";
import { Single } from "../single/0.single";
import { Behavior } from "./0.behavior";
export class HighlightBehavior extends Behavior {
doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
{ rule } = this.options;
each(items, (i, item) => {
if (item instanceof Single) {
const rules = rule(item.getValue(), item);
function doBe(run) {
if (run === true) {
item.doHighLight && item.doHighLight(...args);
} else {
item.unHighLight && item.unHighLight(...args);
}
}
if (isFunction(rules)) {
rules(doBe);
} else {
doBe(rules);
}
} else {
item.doBehavior && item.doBehavior(...args);
}
});
}
}

25
src/base/behavior/behavior.redmark.js

@ -0,0 +1,25 @@
/**
* guy
* 标红行为
*/
import { Behavior } from "./0.behavior";
import { each } from "@/core";
import { Single } from "../single/0.single";
export class RedMarkBehavior extends Behavior {
doBehavior(items) {
const args = Array.prototype.slice.call(arguments, 1),
{ rule } = this.options;
each(items, (i, item) => {
if (item instanceof Single) {
if (rule(item.getValue(), item)) {
item.doRedMark && item.doRedMark(...args);
} else {
item.doRedMark && item.unRedMark(...args);
}
} else {
item.doBehavior && item.doBehavior(...args);
}
});
}
}

26
src/base/behavior/index.js

@ -0,0 +1,26 @@
import { HighlightBehavior } from "./behavior.highlight";
import { RedMarkBehavior } from "./behavior.redmark";
export const BehaviorFactory = {
createBehavior (key, options) {
let Behavior;
switch (key) {
case "highlight":
Behavior = HighlightBehavior;
break;
case "redmark":
Behavior = RedMarkBehavior;
break;
default:
}
return new Behavior(options);
},
};
export { Behavior } from "./0.behavior";
export {
HighlightBehavior,
RedMarkBehavior
};

2
src/base/combination/group.button.js

@ -26,10 +26,10 @@ import {
deepContains,
has,
any,
BehaviorFactory,
Events
} from "@/core";
import { TextButton } from "../single";
import { BehaviorFactory } from "../behavior";
/**
* Created by GUY on 2015/6/26.

Loading…
Cancel
Save