Browse Source

Merge branch 'final/11.0' of ssh://code.fineres.com:7999/~treecat/dec-fineui into final/11.0

# Conflicts:
#	src/base/single/input/radio/radio.js
research/test
Treecat 2 years ago
parent
commit
269ec1d780
  1. 5
      .eslintrc
  2. 2
      .npmignore
  3. 4
      bi.lessconfig.json
  4. 32
      bin/cli/worker/cli.worker.js
  5. 48
      bin/cli/worker/template/main_thread.helper.t
  6. 13
      bin/cli/worker/template/main_thread/action/action.worker_ability_test.t
  7. 13
      bin/cli/worker/template/main_thread/main_thread.t
  8. 5
      bin/cli/worker/template/main_thread_template.ts
  9. 8
      bin/cli/worker/template/utils/action_type.t
  10. 13
      bin/cli/worker/template/utils/payload_type.t
  11. 24
      bin/cli/worker/template/worker_thread/action/action.worker_ability_test.t
  12. 12
      bin/cli/worker/template/worker_thread/worker_thread.t
  13. 5
      bin/cli/worker/template/worker_thread_template.ts
  14. 528
      demo/config.js
  15. 215
      demo/js/base/button/demo.button.js
  16. 247
      demo/js/case/combo/demo.text_value_combo.js
  17. 5
      demo/js/case/tree/demo.level_tree.js
  18. 3
      demo/js/component/demo.treevaluechoosercombo.js
  19. 4
      demo/js/widget/selecttree/demo.multilayer_select_tree_combo.js
  20. 4
      demo/js/widget/singletree/demo.multilayer_single_tree_combo.js
  21. 4
      demo/js/widget/singletree/demo.single_tree_combo.js
  22. 2
      demo/js/widget/tree/demo.multilayer_select_level_tree.js
  23. 38
      demo/js/widget/tree/demo.multilayer_single_level_tree.js
  24. BIN
      dist/font/iconfont.eot
  25. 516
      dist/font/iconfont.svg
  26. BIN
      dist/font/iconfont.ttf
  27. BIN
      dist/font/iconfont.woff
  28. BIN
      dist/font/iconfont.woff2
  29. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_1.png
  30. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_2.png
  31. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_3.png
  32. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_4.png
  33. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_5.png
  34. BIN
      dist/images/2x/icon/dark/tree_solid_expand_1.png
  35. BIN
      dist/images/2x/icon/dark/tree_solid_expand_2.png
  36. BIN
      dist/images/2x/icon/dark/tree_solid_expand_3.png
  37. BIN
      dist/images/2x/icon/dark/tree_solid_expand_4.png
  38. BIN
      dist/images/2x/icon/dark/tree_solid_expand_5.png
  39. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_1.png
  40. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_2.png
  41. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_3.png
  42. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_4.png
  43. BIN
      dist/images/2x/icon/tree_solid_collapse_1.png
  44. BIN
      dist/images/2x/icon/tree_solid_collapse_2.png
  45. BIN
      dist/images/2x/icon/tree_solid_collapse_3.png
  46. BIN
      dist/images/2x/icon/tree_solid_collapse_4.png
  47. BIN
      dist/images/2x/icon/tree_solid_collapse_5.png
  48. BIN
      dist/images/2x/icon/tree_solid_expand_1.png
  49. BIN
      dist/images/2x/icon/tree_solid_expand_2.png
  50. BIN
      dist/images/2x/icon/tree_solid_expand_3.png
  51. BIN
      dist/images/2x/icon/tree_solid_expand_4.png
  52. BIN
      dist/images/2x/icon/tree_solid_expand_5.png
  53. BIN
      dist/images/2x/icon/tree_solid_vertical_line_2.png
  54. BIN
      dist/images/2x/icon/tree_solid_vertical_line_3.png
  55. BIN
      dist/images/2x/icon/tree_solid_vertical_line_4.png
  56. BIN
      dist/images/2x/icon/tree_vertical_line_1.png
  57. 4
      examples/worker_new/index.js
  58. 4
      examples/worker_new/worker.js
  59. 2
      lodash.md
  60. 4
      package.json
  61. 9
      plugins/webpack-fui-worker-plugin/constants.js
  62. 0
      plugins/webpack-fui-worker-plugin/empty.js
  63. 79
      plugins/webpack-fui-worker-plugin/index.js
  64. 137
      plugins/webpack-fui-worker-plugin/worker-loader.js
  65. 20
      src/base/0.base.js
  66. 20
      src/base/1.pane.js
  67. 9
      src/base/collection/__test__/collection.test.js
  68. 50
      src/base/collection/collection.js
  69. 42
      src/base/combination/bubble.js
  70. 38
      src/base/combination/combo.js
  71. 20
      src/base/combination/expander.js
  72. 40
      src/base/combination/group.button.js
  73. 18
      src/base/combination/group.combo.js
  74. 21
      src/base/combination/group.virtual.js
  75. 36
      src/base/combination/loader.js
  76. 19
      src/base/combination/navigation.js
  77. 34
      src/base/combination/searcher.js
  78. 18
      src/base/combination/switcher.js
  79. 16
      src/base/combination/tab.js
  80. 29
      src/base/combination/tree.button.js
  81. 6
      src/base/context.js
  82. 6
      src/base/el.js
  83. 4
      src/base/foundation/__test__/message.test.js
  84. 76
      src/base/foundation/message.js
  85. 7
      src/base/grid/__test__/grid.test.js
  86. 28
      src/base/grid/grid.js
  87. 9
      src/base/layer/__test__/layer.popover.test.js
  88. 72
      src/base/layer/layer.drawer.js
  89. 80
      src/base/layer/layer.popover.js
  90. 100
      src/base/layer/layer.popup.js
  91. 37
      src/base/layer/layer.searcher.js
  92. 13
      src/base/list/__test__/listview.test.js
  93. 23
      src/base/list/listview.js
  94. 23
      src/base/list/virtualgrouplist.js
  95. 22
      src/base/list/virtuallist.js
  96. 35
      src/base/pager/pager.js
  97. 12
      src/base/single/0.single.js
  98. 28
      src/base/single/1.text.js
  99. 27
      src/base/single/__test__/text.test.js
  100. 11
      src/base/single/a/__test__/a.test.js
  101. Some files were not shown because too many files have changed in this diff Show More

5
.eslintrc

@ -2,7 +2,8 @@
"env": { "env": {
"browser": true, "browser": true,
"node": true, "node": true,
"es6": true "es6": true,
"jest": true
}, },
"globals": { "globals": {
"window": true, "window": true,
@ -30,7 +31,7 @@
"rules": { "rules": {
"no-param-reassign": "off", "no-param-reassign": "off",
"quotes": [2, "double"], "quotes": [2, "double"],
"comma-dangle": ["error", "never"] // 多行对象字面量中要求拖尾逗号 "comma-dangle": ["error", { "arrays": "never", "objects": "always-multiline"}] // 多行对象字面量中要求拖尾逗号
} }
}, { }, {
"files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"], "files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"],

2
.npmignore

@ -40,3 +40,5 @@
!dist/2.0/bi.min.css !dist/2.0/bi.min.css
!bin/* !bin/*
!bin/**/* !bin/**/*
!plugins/*
!plugins/**/*

4
bi.lessconfig.json

@ -38,5 +38,7 @@
"@color-bi-color-toast-normal": "#2C60DB", "@color-bi-color-toast-normal": "#2C60DB",
"@color-bi-color-toast-text": "#000A19", "@color-bi-color-toast-text": "#000A19",
"@color-bi-text-header-background": "rgba(9, 30, 64, 0.9)", "@color-bi-text-header-background": "rgba(9, 30, 64, 0.9)",
"@color-bi-text-header-background-theme-dark": "rgba(255, 255, 255, 0.9)" "@color-bi-text-header-background-theme-dark": "rgba(255, 255, 255, 0.9)",
"@font-down-triangle": "e70b",
"@font-date": "e733"
} }

32
bin/cli/worker/cli.worker.js

@ -1,17 +1,25 @@
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
function scanAndCreate(structure, root = process.cwd()) { function first2UpperCase(str) {
return str.toLowerCase().replace(/( |^)[a-z]/g, L => L.toUpperCase());
}
function scanAndCreate(structure, workerName, root = process.env.INIT_CWD) {
Object.keys(structure) Object.keys(structure)
.forEach(name => { .forEach(name => {
if (typeof structure[name] === 'object') { if (typeof structure[name] === 'object') {
fs.mkdirSync(path.resolve(root, name)); fs.mkdirSync(path.resolve(root, name));
scanAndCreate(structure[name], path.resolve(root, `./${name}`)); scanAndCreate(structure[name], workerName, path.resolve(root, `./${name}`));
} else if (structure[name] === '') { } else if (structure[name] === '') {
fs.appendFileSync(path.resolve(root, name), ''); fs.appendFileSync(path.resolve(root, name), '');
} else if (typeof structure[name] === 'string') { } else if (typeof structure[name] === 'string') {
const content = fs.readFileSync(structure[name]).toString(); let content = fs.readFileSync(structure[name]).toString();
content = content
.replace(/\${WorkerName}/g, first2UpperCase(workerName))
.replace(/\${workerName}/g, workerName);
fs.appendFileSync(path.resolve(root, name), content); fs.appendFileSync(path.resolve(root, name), content);
} }
@ -33,20 +41,26 @@ module.exports = {
const structure = { const structure = {
[`${name}_worker`]: { [`${name}_worker`]: {
'main_thread': { 'main_thread': {
action: {}, action: {
[`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread_template.ts'), 'action.worker_ability_test.ts': path.resolve(__dirname, './template/main_thread/action/action.worker_ability_test.t'),
},
[`${name}_main_thread.ts`]: path.resolve(__dirname, './template/main_thread/main_thread.t'),
}, },
utils: { utils: {
'action_type.ts': '', 'action_type.ts': path.resolve(__dirname, './template/utils/action_type.t'),
'payload_type.ts': path.resolve(__dirname, './template/utils/payload_type.t'),
}, },
'worker_thread': { 'worker_thread': {
action: {}, action: {
[`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread_template.ts'), 'action.worker_ability_test.ts': path.resolve(__dirname, './template/worker_thread/action/action.worker_ability_test.t'),
},
[`${name}_worker_thread.ts`]: path.resolve(__dirname, './template/worker_thread/worker_thread.t'),
}, },
[`${name}_main_thread.helper.ts`]: path.resolve(__dirname, './template/main_thread.helper.t'),
}, },
}; };
scanAndCreate(structure); scanAndCreate(structure, name);
}, },
}; };

48
bin/cli/worker/template/main_thread.helper.t

@ -0,0 +1,48 @@
import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行
// FuiWorkerPlugin中的属性会同步到fui-worker中同时支持loader行内传入属性
// 根据实际需求传入inline返回格式 true -> blob urlfalse -> servicePath
import { workerUrl } from 'fui-worker!./worker_thread/${workerName}_worker_thread';
export class ${WorkerName}WorkerHelper {
private worker: ${WorkerName}MainThreadWorker;
/**
* 拿到helper中的worker
*/
public getWorker() {
if (this.worker) {
return this.worker;
}
this.worker = BI.Workers.createWorker(${WorkerName}MainThreadWorker, {
workerUrl: this.urlFormatter(workerUrl),
workerName: BI.UUID(),
});
return this.worker;
}
/**
* 格式化worker url比如补充一些环境信息到参数里
* 可通过 #hash 将参数传入blob url
* @param url worker url
*/
private urlFormatter(url: string) {
return url;
}
/**
* 终止worker
*/
public terminate() {
this.worker?.terminate();
}
}
// 使用示例
// const workerHelper = new ${WorkerName}WorkerHelper();
// workerHelper.getWorker()
// .testCommunication()
// .then(res => console.log(res));

13
bin/cli/worker/template/main_thread/action/action.worker_ability_test.t

@ -0,0 +1,13 @@
import { WorkerAbilityTestActionType } from '../../utils/action_type';
import { WorkerAbilityTestPayload, WorkerAbilityTestReponse } from '../../utils/payload_type';
export class WorkerAbilityTestMainThreadAction extends BI.Workers.WorkerBaseAction {
/**
* 通信能力检测
*/
public communicationTest(): Promise<WorkerAbilityTestReponse['CommunicationTest']> {
const mainThreadPostTime: WorkerAbilityTestPayload['CommunicationTest'] = Date.now();
return this.controller.requestPromise(WorkerAbilityTestActionType.CommunicationTest, mainThreadPostTime);
}
}

13
bin/cli/worker/template/main_thread/main_thread.t

@ -0,0 +1,13 @@
import { WorkerAbilityTestMainThreadAction } from './action/action.worker_ability_test';
export class ${WorkerName}MainThreadWorker extends BI.Workers.MainThreadWorker {
private communicationTest: WorkerAbilityTestMainThreadAction;
public initActions(): void {
this.communicationTest = this.createAction(WorkerAbilityTestMainThreadAction);
}
public testCommunication() {
return this.communicationTest.communicationTest();
}
}

5
bin/cli/worker/template/main_thread_template.ts

@ -1,5 +0,0 @@
class CrudMainTreadWorker extends BI.Workers.MainThreadWorker {
protected initActions(): void {
// to init some actions
}
}

8
bin/cli/worker/template/utils/action_type.t

@ -0,0 +1,8 @@
/*
* Worker 事务标识
* 每类事务有命名空间, 包含多个具体事务
*/
export const enum WorkerAbilityTestActionType {
CommunicationTest = 'CommunicationTest',
}

13
bin/cli/worker/template/utils/payload_type.t

@ -0,0 +1,13 @@
/**
* 跨线程通信各事务的发送数据类型声明
*/
export interface WorkerAbilityTestPayload {
CommunicationTest: number;
}
/**
* 跨线程通信各事务的响应数据类型声明
*/
export interface WorkerAbilityTestReponse {
CommunicationTest: number;
}

24
bin/cli/worker/template/worker_thread/action/action.worker_ability_test.t

@ -0,0 +1,24 @@
import { WorkerAbilityTestActionType } from '../../utils/action_type';
import { WorkerAbilityTestPayload, WorkerAbilityTestReponse } from '../../utils/payload_type';
export class WorkerAbilityTestWorkerThreadAction extends BI.Workers.WorkerBaseAction {
protected addActionHandler(): void {
this.controller.addActionHandler(
WorkerAbilityTestActionType.CommunicationTest,
this.communicationTest.bind(this)
);
}
/**
* 通信能力检测的处理器
*/
private communicationTest(
payload: WorkerAbilityTestPayload['CommunicationTest']
): WorkerAbilityTestReponse['CommunicationTest'] {
const mainThreadPostTime = payload;
// 收到主线程信息的耗时
const workerGetMessageDuration = Date.now() - mainThreadPostTime;
return workerGetMessageDuration;
}
}

12
bin/cli/worker/template/worker_thread/worker_thread.t

@ -0,0 +1,12 @@
// TODO: 这边需要先import fineui资源
import { WorkerAbilityTestWorkerThreadAction } from './action/action.worker_ability_test';
class ${WorkerName}WorkerTreadWorker extends BI.Workers.WorkerThreadWorker {
public communicationTest: WorkerAbilityTestWorkerThreadAction;
public initActions(): void {
this.communicationTest = this.createAction(WorkerAbilityTestWorkerThreadAction);
}
}
export const ${workerName}WorkerTreadWorker = BI.Workers.createWorker(${WorkerName}WorkerTreadWorker);

5
bin/cli/worker/template/worker_thread_template.ts

@ -1,5 +0,0 @@
class CrudWorkerTreadWorker extends BI.Workers.MainThreadWorker {
protected initActions(): void {
// to init some actions
}
}

528
demo/config.js

File diff suppressed because it is too large Load Diff

215
demo/js/base/button/demo.button.js

@ -1,277 +1,304 @@
(function () {
var JokerIcon = BI.inherit(BI.Widget, {
render: function () {
var self = this;
return {
type: "bi.label",
cls: "anim-rotate",
ref: function(ref) {
self.text = ref;
},
};
},
loading: function () {
this.text.setText("🤡");
},
loaded: function () {
this.text.setText("");
},
});
BI.shortcut("demo.joker.icon", JokerIcon);
}());
Demo.Button = BI.inherit(BI.Widget, { Demo.Button = BI.inherit(BI.Widget, {
props: { props: {
baseCls: "demo-button" baseCls: "demo-button",
}, },
render: function () { render: function () {
var items = [{ var items = [{
type: "bi.button", type: "bi.button",
text: "一般按钮", text: "一般按钮1111111111111",
level: "common", level: "common",
height: 30 whiteSpace: "nowrap",
width: 100,
height: 30,
handler() {
console.log("触发点击事件");
this.loading();
setTimeout(() => {
this.loaded();
}, 5 * 1000);
},
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示成功状态按钮", text: "表示成功状态按钮",
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示警告状态的按钮", text: "表示警告状态的按钮",
level: "warning", level: "warning",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示错误状态的按钮", text: "表示错误状态的按钮",
level: "error", level: "error",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示忽略状态的按钮", text: "表示忽略状态的按钮",
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "普通灰化按钮", text: "普通灰化按钮",
disabled: true, disabled: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "忽略状态灰化按钮", text: "忽略状态灰化按钮",
disabled: true, disabled: true,
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "带图标的按钮", text: "带图标的按钮",
// level: 'ignore', // level: 'ignore',
iconCls: "close-font", iconCls: "close-font",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "一般按钮", text: "一般按钮",
block: true, block: true,
level: "common", level: "common",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示成功状态按钮", text: "表示成功状态按钮",
block: true, block: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示警告状态的按钮", text: "表示警告状态的按钮",
block: true, block: true,
level: "warning", level: "warning",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示忽略状态的按钮", text: "表示忽略状态的按钮",
block: true, block: true,
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "普通灰化按钮", text: "普通灰化按钮",
block: true, block: true,
disabled: true, disabled: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "忽略状态灰化按钮", text: "忽略状态灰化按钮",
block: true, block: true,
disabled: true, disabled: true,
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "带图标的按钮", text: "带图标的按钮",
block: true, block: true,
// level: 'ignore', // level: 'ignore',
iconCls: "close-font", iconCls: "close-font",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "一般按钮", text: "一般按钮",
clear: true, clear: true,
level: "common", level: "common",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示成功状态按钮", text: "表示成功状态按钮",
clear: true, clear: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示警告状态的按钮", text: "表示警告状态的按钮",
clear: true, clear: true,
level: "warning", level: "warning",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "表示忽略状态的按钮", text: "表示忽略状态的按钮",
clear: true, clear: true,
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "普通灰化按钮", text: "普通灰化按钮",
clear: true, clear: true,
disabled: true, disabled: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "忽略状态灰化按钮", text: "忽略状态灰化按钮",
clear: true, clear: true,
disabled: true, disabled: true,
level: "ignore", level: "ignore",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "带图标的按钮", text: "带图标的按钮",
clear: true, clear: true,
// level: 'ignore', // level: 'ignore',
iconCls: "close-font", iconCls: "close-font",
height: 30 height: 30,
}, { }, {
type: "bi.text_button", type: "bi.text_button",
text: "文字按钮", text: "文字按钮",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "幽灵按钮(common)", text: "幽灵按钮(common)",
ghost: true, ghost: true,
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "幽灵按钮(common)", text: "幽灵按钮(common)",
ghost: true, ghost: true,
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "幽灵按钮(common)", text: "幽灵按钮(common)",
ghost: true, ghost: true,
level: "warning", level: "warning",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "幽灵按钮(common)", text: "幽灵按钮(common)",
ghost: true, ghost: true,
level: "error", level: "error",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "幽灵按钮(common)", text: "幽灵按钮(common)",
ghost: true, ghost: true,
level: "success", level: "success",
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "幽灵按钮(common)灰化", text: "幽灵按钮(common)灰化",
disabled: true, disabled: true,
ghost: true, ghost: true,
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "弹出bubble", text: "弹出bubble",
bubble: function () { bubble: function () {
return BI.parseInt(Math.random() * 100) % 10 + "提示" return BI.parseInt(Math.random() * 100) % 10 + "提示";
}, },
handler: function () { handler: function () {
BI.Msg.toast("1111"); BI.Msg.toast("1111");
}, },
height: 30 height: 30,
}, { }, {
type: "bi.button", type: "bi.button",
text: "图标在上面的按钮,而且可以自动撑开高度", text: "自动撑开",
iconCls: "close-font", iconCls: "close-font",
iconGap: 24, // textHeight: 32,
iconPosition: "top" // height: 32,
},{ iconGap: 64,
type: "bi.button",
text: "自动撑开高度",
iconCls: "close-font",
textHeight: 32,
iconGap: 24,
vgap: 16, vgap: 16,
hgap: 100, hgap: 100,
iconPosition: "top" iconPosition: "bottom",
}, { }, {
type: "bi.button", type: "bi.button",
text: "图标在下面的按钮", text: "图标在下面的按钮",
iconCls: "close-font", iconCls: "close-font",
iconPosition: "bottom" iconPosition: "bottom",
}, { }, {
type: "bi.button", type: "bi.button",
text: "图标在左边的按钮", text: "图标在左边的按钮",
iconCls: "close-font", iconCls: "close-font",
iconPosition: "left" iconPosition: "left",
}, { }, {
type: "bi.button", type: "bi.button",
text: "图标在右边的按钮", text: "图标在右边的按钮",
iconCls: "close-font", iconCls: "close-font",
iconPosition: "right" iconPosition: "right",
}, { }, {
type: "bi.button", type: "bi.button",
text: "浅色的一般按钮", text: "浅色的一般按钮",
iconCls: "plus-font", iconCls: "plus-font",
light: true light: true,
}, { }, {
type: "bi.button", type: "bi.button",
text: "浅色的成功按钮", text: "浅色的成功按钮",
level: "success", level: "success",
iconCls: "plus-font", iconCls: "plus-font",
light: true light: true,
}, { }, {
type: "bi.button", type: "bi.button",
text: "浅色的警告按钮", text: "浅色的警告按钮",
level: "warning", level: "warning",
iconCls: "plus-font", iconCls: "plus-font",
light: true light: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "浅色的失败按钮", text: "浅色的失败按钮",
level: "error", level: "error",
cls: "hover-mask", cls: "hover-mask",
light: true light: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
level: "common", level: "common",
plain: true plain: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
level: "success", level: "success",
plain: true plain: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
level: "error", level: "error",
plain: true plain: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
level: "warning", level: "warning",
plain: true plain: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
level: "ignore", level: "ignore",
plain: true plain: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
@ -282,20 +309,82 @@ Demo.Button = BI.inherit(BI.Widget, {
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "朴素的按钮",
plain: true, plain: true,
disabled: true disabled: true,
}, { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "点我,更改图标", text: "点我,更改图标",
handler() { handler() {
this.i = this.i === undefined ? 0 : ++this.i; this.i = this.i === undefined ? 0 : ++this.i;
const arr = ["text-background-font", "check-mark-ha-font", "close-font", "search-font", "date-change-h-font"]; const arr = ["text-background-font", "check-mark-ha-font", "close-font", "search-font", "date-change-h-font"];
if(this.i >= arr.length) { if (this.i >= arr.length) {
this.i = 0; this.i = 0;
} }
this.setIcon(arr[this.i]); this.setIcon(arr[this.i]);
}, },
height: 24 height: 24,
}, {
type: "bi.button",
text: "带加载的按钮",
handler() {
console.log("触发点击事件");
this.loading();
setTimeout(() => {
this.loaded();
}, 5 * 1000);
},
}, {
type: "bi.button",
text: "带加载的按钮",
iconCls: "circle-close-font",
handler() {
console.log("触发点击事件");
this.loading();
setTimeout(() => {
this.loaded();
}, 5 * 1000);
},
}, {
type: "bi.button",
clear: true,
text: "带加载的按钮",
iconCls: "circle-close-font",
handler() {
console.log("触发点击事件");
this.loading();
setTimeout(() => {
this.loaded();
}, 5 * 1000);
},
}, {
type: "bi.button",
text: "加载中的按钮",
loading: true,
handler() {
console.log("我是无法被触发的!");
},
}, {
type: "bi.button",
text: "自定义图标按钮(点我修改)",
icon: {
type: "demo.joker.icon",
},
handler() {
console.log("触发点击事件");
this.loading();
setTimeout(() => {
this.loaded();
}, 5 * 1000);
},
}, {
type: "bi.button",
text: "文字偏左的按钮",
textAlign: "left",
width: 200,
}, {
type: "bi.button",
text: "小于最小宽度的按钮",
width: 50,
}]; }];
return { return {
@ -305,10 +394,10 @@ Demo.Button = BI.inherit(BI.Widget, {
hgap: 20, hgap: 20,
items: BI.map(items, function (index, value) { items: BI.map(items, function (index, value) {
return { return {
el: value el: value,
} };
}) }),
}; };
} },
}); });
BI.shortcut("demo.button", Demo.Button); BI.shortcut("demo.button", Demo.Button);

247
demo/js/case/combo/demo.text_value_combo.js

@ -6,58 +6,207 @@ Demo.TextValueCombo = BI.inherit(BI.Widget, {
baseCls: "" baseCls: ""
}, },
render: function () { render: function () {
var combo, wrapper; var combo1, combo2;
var items = [{
text: "MVC-1",
iconCls: "date-font",
value: 1
}, {
text: "MVC-2",
iconCls: "search-font",
value: 2
}, {
text: "MVC-3",
iconCls: "pull-right-font",
value: 3
}];
// 创建下拉框各种场景用例
return { return {
type: "bi.button_group", type: "bi.vertical",
items: [{ vgap: 20,
type: "bi.text_value_combo", hgap: 20,
ref: function () { items: [
combo = this; this.createCombo("无初始值,带提示文字", {
}, type: "bi.text_value_combo",
text: "默认值", ref: (ref) => {
value: 22, this.combo1 = ref;
width: 300, },
items: [{ defaultText: "请选择",
text: "MVC-1", width: 300,
iconCls: "date-font", items: items,
value: 1 listeners: [
}, { {
text: "MVC-2", eventName: BI.TextValueCombo.EVENT_CHANGE,
iconCls: "search-font", action: function () {
value: 2 console.log(this.getValue());
}
}
]
}),
this.createCombo("自动根据value匹配text", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
value: 1,
items: items,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("无初始值,可以清空", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
items: items,
allowClear: true,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("有初始值,可以清空", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
defaultText: "请选择",
width: 300,
value: 1,
items: items,
allowClear: true,
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("有初始值,value不匹配,自动标红,指定标红文字", {
type: "bi.text_value_combo",
ref: function () {
combo = this;
},
width: 300,
text: "MVC-111",
value: 111,
items: items,
allowClear: true,
defaultText: "请选择",
warningTitle: "value值不合法",
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}),
this.createCombo("无初始值,外部受控调用setValue", {
type: "bi.vertical",
items: [
{
type: "bi.text_value_combo",
ref: function () {
combo1 = this;
},
width: 300,
items: items,
allowClear: true,
defaultText: "请选择",
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}, {
el: {
type: "bi.button",
text: "setValue(1)",
handler: function () {
combo1.setValue();
},
},
vgap: 10,
}
]
}),
this.createCombo("无初始值,外部受控调用setStatus", {
type: "bi.vertical",
items: [
{
type: "bi.text_value_combo",
ref: function () {
combo2 = this;
},
width: 300,
items: items,
allowClear: true,
defaultText: "请选择",
listeners: [
{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
console.log(this.getValue());
}
}
]
}, {
el: {
type: "bi.button",
text: "setStatus()",
handler: function () {
combo2.setStatus("error");
},
},
vgap: 10,
}
]
})
]
};
},
createCombo: function (text, combo) {
return {
type: "bi.vertical",
items: [
{
el: {
type: "bi.label",
textAlign: "left",
text,
},
bgap: 10
}, { }, {
text: "MVC-3", el: combo,
iconCls: "pull-right-font", bgap: 10,
value: 3 },
}] ]
}, {
type: "bi.search_multi_text_value_combo",
items: Demo.CONSTANTS.ITEMS,
width: 200,
value: {
type: 1,
value: ["1", "2", "3"]
}
}, {
type: "bi.button",
width: 90,
height: 25,
handler: function () {
wrapper.populate();
}
}, {
type: 'bi.label',
height: 1000
}],
ref: function () {
wrapper = this;
},
layouts: [{
type: "bi.vertical",
vgap: 20
}]
}; };
} }
}); });
BI.shortcut("demo.text_value_combo", Demo.TextValueCombo); BI.shortcut("demo.text_value_combo", Demo.TextValueCombo);

5
demo/js/case/tree/demo.level_tree.js

@ -42,6 +42,11 @@ Demo.Func = BI.inherit(BI.Widget, {
pId: 1, pId: 1,
text: "子项3", text: "子项3",
value: 13 value: 13
}, {
id: 111,
pId: 11,
text: "子项1-1",
value: 111
}, { }, {
id: 21, id: 21,
pId: 2, pId: 2,

3
demo/js/component/demo.treevaluechoosercombo.js

@ -10,7 +10,8 @@ Demo.TreeValueChooser = BI.inherit(BI.Widget, {
// items: BI.deepClone(Demo.CONSTANTS.TREEITEMS), // items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
callback(BI.deepClone(Demo.CONSTANTS.TREEITEMS)); callback(BI.deepClone(Demo.CONSTANTS.TREEITEMS));
} },
defaultText: "请选择",
}); });
return { return {
type: "bi.vertical", type: "bi.vertical",

4
demo/js/widget/selecttree/demo.multilayer_select_tree_combo.js

@ -16,7 +16,7 @@ Demo.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, {
ref: function (_ref) { ref: function (_ref) {
self.tree = _ref; self.tree = _ref;
}, },
text: "默认值", defaultText: "请选择",
items: items, items: items,
width: 300, width: 300,
value: ["第五级文件1"] value: ["第五级文件1"]
@ -40,4 +40,4 @@ Demo.MultiLayerSelectTreeCombo = BI.inherit(BI.Widget, {
} }
}); });
BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiLayerSelectTreeCombo); BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiLayerSelectTreeCombo);

4
demo/js/widget/singletree/demo.multilayer_single_tree_combo.js

@ -16,7 +16,7 @@ Demo.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, {
ref: function (_ref) { ref: function (_ref) {
self.tree = _ref; self.tree = _ref;
}, },
text: "默认值", defaultText: "请选择",
items: items, items: items,
width: 300 width: 300
}, { }, {
@ -39,4 +39,4 @@ Demo.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, {
} }
}); });
BI.shortcut("demo.multilayer_single_tree_combo", Demo.MultiLayerSingleTreeCombo); BI.shortcut("demo.multilayer_single_tree_combo", Demo.MultiLayerSingleTreeCombo);

4
demo/js/widget/singletree/demo.single_tree_combo.js

@ -16,7 +16,7 @@ Demo.SingleTreeCombo = BI.inherit(BI.Widget, {
ref: function (_ref) { ref: function (_ref) {
self.tree = _ref; self.tree = _ref;
}, },
text: "默认值", defaultText: "请选择",
items: items, items: items,
width: 300, width: 300,
value: "11" value: "11"
@ -40,4 +40,4 @@ Demo.SingleTreeCombo = BI.inherit(BI.Widget, {
} }
}); });
BI.shortcut("demo.single_tree_combo", Demo.SingleTreeCombo); BI.shortcut("demo.single_tree_combo", Demo.SingleTreeCombo);

2
demo/js/widget/tree/demo.multilayer_select_level_tree.js

@ -33,7 +33,7 @@ Demo.MultiLayerSelectLevelTree = BI.inherit(BI.Widget, {
height: 25, height: 25,
text: "setValue (第二级文件1)", text: "setValue (第二级文件1)",
handler: function () { handler: function () {
tree.setValue(["第二级文件1"]); tree.setValue(["11"]);
} }
}, },
height: 25 height: 25

38
demo/js/widget/tree/demo.multilayer_single_level_tree.js

@ -46,27 +46,27 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, {
mounted: function () { mounted: function () {
var tree = [ var tree = [
// {id: -2, pId: 0, value: "根目录1", text: "根目录1"}, // {id: -2, pId: 0, value: "根目录1", text: "根目录1"},
{id: -1, pId: 0, value: "根目录", text: "根目录"}, { id: -1, pId: 0, value: "根目录", text: "根目录" },
{id: 1, pId: -1, value: "第一级目录1", text: "第一级目录1"}, { id: 1, pId: -1, value: "第一级目录1", text: "第一级目录1" },
{id: 11, pId: 1, value: "第二级文件1", text: "第二级文件1"}, { id: 11, pId: 1, value: "第二级文件1", text: "第二级文件1" },
{id: 12, pId: 1, value: "第二级目录2", text: "第二级目录2"}, { id: 12, pId: 1, value: "第二级目录2", text: "第二级目录2", disabled: true },
{id: 121, pId: 12, value: "第三级目录1", text: "第三级目录1"}, { id: 121, pId: 12, value: "第三级目录1", text: "第三级目录1" },
{id: 122, pId: 12, value: "第三级文件1", text: "第三级文件1"}, { id: 122, pId: 12, value: "第三级文件1", text: "第三级文件1" },
{id: 1211, pId: 121, value: "第四级目录1", text: "第四级目录1"}, { id: 1211, pId: 121, value: "第四级目录1", text: "第四级目录1" },
{id: 2, pId: -1, value: "第一级目录2", text: "第一级目录2"}, { id: 2, pId: -1, value: "第一级目录2", text: "第一级目录2" },
{id: 21, pId: 2, value: "第二级目录3", text: "第二级目录3"}, { id: 21, pId: 2, value: "第二级目录3", text: "第二级目录3" },
{id: 22, pId: 2, value: "第二级文件2", text: "第二级文件2"}, { id: 22, pId: 2, value: "第二级文件2", text: "第二级文件2" },
{id: 211, pId: 21, value: "第三级目录2", text: "第三级目录2"}, { id: 211, pId: 21, value: "第三级目录2", text: "第三级目录2" },
{id: 212, pId: 21, value: "第三级文件2", text: "第三级文件2"}, { id: 212, pId: 21, value: "第三级文件2", text: "第三级文件2" },
{id: 2111, pId: 211, value: "第四级文件1", text: "第四级文件1"}, { id: 2111, pId: 211, value: "第四级文件1", text: "第四级文件1" },
{id: 3, pId: -1, value: "第一级目录3", text: "第一级目录3"}, { id: 3, pId: -1, value: "第一级目录3", text: "第一级目录3" },
{id: 31, pId: 3, value: "第二级文件2", text: "第二级文件2"}, { id: 31, pId: 3, value: "第二级文件2", text: "第二级文件2" },
{id: 33, pId: 3, value: "第二级目录3", text: "第二级目录1"}, { id: 33, pId: 3, value: "第二级目录3", text: "第二级目录1" },
{id: 32, pId: 3, value: "第二级文件3", text: "第二级文件3"}, { id: 32, pId: 3, value: "第二级文件3", text: "第二级文件3" },
{id: 331, pId: 33, value: "第三级文件1", text: "第三级文件1"} { id: 331, pId: 33, value: "第三级文件1", text: "第三级文件1" }
]; ];
this.tree.populate(tree); this.tree.populate(tree);
} }
}); });
BI.shortcut("demo.multilayer_single_level_tree", Demo.MultiLayerSingleLevelTree); BI.shortcut("demo.multilayer_single_level_tree", Demo.MultiLayerSingleLevelTree);

BIN
dist/font/iconfont.eot vendored

Binary file not shown.

516
dist/font/iconfont.svg vendored

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 673 KiB

After

Width:  |  Height:  |  Size: 699 KiB

BIN
dist/font/iconfont.ttf vendored

Binary file not shown.

BIN
dist/font/iconfont.woff vendored

Binary file not shown.

BIN
dist/font/iconfont.woff2 vendored

Binary file not shown.

BIN
dist/images/2x/icon/dark/tree_solid_collapse_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 371 B

After

Width:  |  Height:  |  Size: 394 B

BIN
dist/images/2x/icon/dark/tree_solid_collapse_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 454 B

After

Width:  |  Height:  |  Size: 473 B

BIN
dist/images/2x/icon/dark/tree_solid_collapse_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 494 B

After

Width:  |  Height:  |  Size: 509 B

BIN
dist/images/2x/icon/dark/tree_solid_collapse_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 476 B

BIN
dist/images/2x/icon/dark/tree_solid_collapse_5.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 417 B

After

Width:  |  Height:  |  Size: 434 B

BIN
dist/images/2x/icon/dark/tree_solid_expand_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 308 B

After

Width:  |  Height:  |  Size: 330 B

BIN
dist/images/2x/icon/dark/tree_solid_expand_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 393 B

After

Width:  |  Height:  |  Size: 409 B

BIN
dist/images/2x/icon/dark/tree_solid_expand_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 431 B

After

Width:  |  Height:  |  Size: 466 B

BIN
dist/images/2x/icon/dark/tree_solid_expand_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 401 B

After

Width:  |  Height:  |  Size: 415 B

BIN
dist/images/2x/icon/dark/tree_solid_expand_5.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 352 B

After

Width:  |  Height:  |  Size: 376 B

BIN
dist/images/2x/icon/dark/tree_solid_vertical_line_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 216 B

BIN
dist/images/2x/icon/dark/tree_solid_vertical_line_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

After

Width:  |  Height:  |  Size: 233 B

BIN
dist/images/2x/icon/dark/tree_solid_vertical_line_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

BIN
dist/images/2x/icon/dark/tree_solid_vertical_line_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 215 B

BIN
dist/images/2x/icon/tree_solid_collapse_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 495 B

BIN
dist/images/2x/icon/tree_solid_collapse_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 505 B

After

Width:  |  Height:  |  Size: 581 B

BIN
dist/images/2x/icon/tree_solid_collapse_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 547 B

After

Width:  |  Height:  |  Size: 619 B

BIN
dist/images/2x/icon/tree_solid_collapse_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 515 B

After

Width:  |  Height:  |  Size: 580 B

BIN
dist/images/2x/icon/tree_solid_collapse_5.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 468 B

After

Width:  |  Height:  |  Size: 538 B

BIN
dist/images/2x/icon/tree_solid_expand_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 336 B

After

Width:  |  Height:  |  Size: 392 B

BIN
dist/images/2x/icon/tree_solid_expand_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 419 B

After

Width:  |  Height:  |  Size: 476 B

BIN
dist/images/2x/icon/tree_solid_expand_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 458 B

After

Width:  |  Height:  |  Size: 513 B

BIN
dist/images/2x/icon/tree_solid_expand_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 429 B

After

Width:  |  Height:  |  Size: 477 B

BIN
dist/images/2x/icon/tree_solid_expand_5.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 381 B

After

Width:  |  Height:  |  Size: 434 B

BIN
dist/images/2x/icon/tree_solid_vertical_line_2.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 217 B

After

Width:  |  Height:  |  Size: 233 B

BIN
dist/images/2x/icon/tree_solid_vertical_line_3.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 255 B

After

Width:  |  Height:  |  Size: 255 B

BIN
dist/images/2x/icon/tree_solid_vertical_line_4.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 B

After

Width:  |  Height:  |  Size: 215 B

BIN
dist/images/2x/icon/tree_vertical_line_1.png vendored

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 B

After

Width:  |  Height:  |  Size: 216 B

4
examples/worker_new/index.js

@ -42,7 +42,7 @@ const HeartBeatCheckAction = BI.inherit(BI.Workers.WorkerBaseAction, {
} }
}); });
var WorkerThreadWorker = BI.inherit(BI.Workers.MainThreadWorker, { var MainThreadWorker = BI.inherit(BI.Workers.MainThreadWorker, {
initActions: function() { initActions: function() {
this.cookieAction = this.createAction(CookieAction); this.cookieAction = this.createAction(CookieAction);
@ -64,7 +64,7 @@ var WorkerThreadWorker = BI.inherit(BI.Workers.MainThreadWorker, {
} }
}); });
var mainThreadWorker = new WorkerThreadWorker({ var mainThreadWorker = BI.Workers.createWorker(MainThreadWorker, {
workerUrl: "./worker_new/worker.js", workerUrl: "./worker_new/worker.js",
workerName: "demo" workerName: "demo"
}); });

4
examples/worker_new/worker.js

@ -58,7 +58,7 @@ const HeartBeatCheckAction = BI.inherit(BI.Workers.WorkerBaseAction, {
} }
}); });
var WorkerThreadWorker = BI.inherit(BI.Workers.WorkerThreadWorker, { var MainThreadWorker = BI.inherit(BI.Workers.WorkerThreadWorker, {
initActions: function() { initActions: function() {
this.cookieAction = this.createAction(CookieAction); this.cookieAction = this.createAction(CookieAction);
@ -75,6 +75,6 @@ var WorkerThreadWorker = BI.inherit(BI.Workers.WorkerThreadWorker, {
} }
}); });
var workerThreadWorker = new WorkerThreadWorker(); var workerThreadWorker = BI.Workers.createWorker(MainThreadWorker);
workerThreadWorker.fetchCookie(); workerThreadWorker.fetchCookie();

2
lodash.md

@ -1 +1 @@
lodash core plus="debounce,throttle,get,set,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject,initial,cloneDeep,clamp,isPlainObject,take,takeRight,without,difference,defaultsDeep,trim,merge,groupBy,uniqBy,before,after,unescape" lodash core plus="debounce,throttle,get,set,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject,initial,cloneDeep,clamp,isPlainObject,take,takeRight,without,difference,defaultsDeep,trim,merge,groupBy,uniqBy,before,after,unescape,chunk"

4
package.json

@ -1,6 +1,6 @@
{ {
"name": "fineui", "name": "fineui",
"version": "2.0.20220720140353", "version": "2.0.20220826175704",
"description": "fineui", "description": "fineui",
"main": "dist/fineui_without_conflict.min.js", "main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts", "types": "dist/lib/index.d.ts",
@ -11,7 +11,7 @@
"@babel/core": "^7.17.4", "@babel/core": "^7.17.4",
"@babel/polyfill": "7.6.0", "@babel/polyfill": "7.6.0",
"@fui/babel-preset-fineui": "^2.0.0", "@fui/babel-preset-fineui": "^2.0.0",
"@fui/eslint-plugin": "1.0.15", "@fui/eslint-plugin": "^1.0.15",
"@types/node": "15.6.1", "@types/node": "15.6.1",
"autoprefixer": "9.6.1", "autoprefixer": "9.6.1",
"babel-loader": "8.0.6", "babel-loader": "8.0.6",

9
plugins/webpack-fui-worker-plugin/constants.js

@ -0,0 +1,9 @@
const WorkerPluginName = 'FuiWorkerPlugin';
const WorkerLoaderName = 'FuiWorkerWorkerLoader';
const FileNamePrefix = 'worker-';
module.exports = {
WorkerPluginName,
WorkerLoaderName,
FileNamePrefix,
};

0
bin/cli/worker/template/action_type.ts → plugins/webpack-fui-worker-plugin/empty.js

79
plugins/webpack-fui-worker-plugin/index.js

@ -0,0 +1,79 @@
/*
* worker-plugin
*/
const path = require('path');
const webpack = require('webpack');
const { WorkerPluginName } = require('./constants');
const ModuleFilenameHelpers = require('webpack/lib/ModuleFilenameHelpers');
class FuiWorkerPlugin {
constructor(options = {}) {
this.options = options;
}
apply(compiler) {
// 为主线程构建添加 __WORKER__ 环境变量, 构建中区分不同线程源码, 实现代码拆减
compiler.hooks.afterPlugins.tap(WorkerPluginName, compiler => {
new webpack.DefinePlugin({
// __WORKER__ 表示当前所在线程是否是 worker 线程
// 主线程构建中为 false
__WORKER__: false,
}).apply(compiler);
});
// 添加自定义的worker entry-loader
compiler.hooks.afterResolvers.tap(WorkerPluginName, compiler => {
/**
* https://webpack.js.org/configuration/resolve/#resolveloader
* 使用 resolveloader 添加自定义的 worker loader
*/
if (!compiler.options.resolveLoader) {
compiler.options.resolveLoader = {
alias: {},
};
}
if (!compiler.options.resolveLoader.alias) {
compiler.options.resolveLoader.alias = {};
}
// 动态添加 worker 的 worker-loader, 命名为 "fui-worker"
compiler.options.resolveLoader.alias['fui-worker'] = path.resolve(__dirname, './worker-loader.js');
});
// 将FuiWorkerPlugin的参数传递给fui-worker loader
compiler.hooks.compilation.tap(WorkerPluginName, compilation => {
compilation.hooks.normalModuleLoader.tap(WorkerPluginName, (context, module) => {
// 仅提供给fui-worker
const fuiLoader = module.loaders.find(loader => loader.loader.indexOf('fui-worker') !== -1);
if (fuiLoader) {
const resource = module.resource;
if (!resource) return;
// fui-worker通过options读取
context.options = context.options || {};
const index = resource.indexOf('?');
if (ModuleFilenameHelpers.matchObject(
this.options,
index < 0 ? resource : resource.substr(0, index)
)) {
for (const key of Object.keys(this.options)) {
// 忽略关键属性
if (key === "include" || key === "exclude" || key === "test") {
continue;
}
context.options[key] = this.options[key];
}
}
}
})
})
}
}
module.exports = FuiWorkerPlugin;

137
plugins/webpack-fui-worker-plugin/worker-loader.js

@ -0,0 +1,137 @@
/*
* fui-worker worker-loader
*/
const webpack = require('webpack');
const loaderUtils = require('loader-utils');
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
const { WorkerLoaderName, FileNamePrefix } = require('./constants');
const { resolve } = require('path');
// 正常 loader 处理逻辑
function loader() {
const callback = this.async();
this.cacheable(false);
// 过滤掉当前的 worker-loader, 保留 worker 侧构建需要的其他 loader(babel-loader/ts-loader 等)
const otherLoaders = this.loaders.filter((loader, index) => {
if (index === this.loaderIndex) {
return false;
}
return true;
});
/**
* 拼接构建需要的 loader 字符串, 用于指定 childCompiler 的构建 loader
* 比如: /path/to/babel-loader/lib/index.js!/path/to/ts-loader/index.js!
*/
const loaderPath = otherLoaders.reduce((pre, loader) => `${pre}${loader.path}!`, '');
/**
* worker 独立构建的 entry
* 构建 loader + worker 源码入口文件路径
*
* https://webpack.js.org/concepts/loaders/#inline
* `!!` 实现在 childCompiler 中忽略其他所有 loader, 只保留主构建的 loader
* 不然 worker 入口在 childCompiler 中会继续由 worker-loader 处理, 造成死循环
*/
const workerEntry = `!!${loaderPath}${this.resourcePath}`;
// 把资源纳入构建流程的依赖, 实现 dev 模式下的 watch
this.addDependency(workerEntry);
// 生成的 service 独立 bundle 名称
const entryFileName = `${FileNamePrefix}index`;
// 获取传递给 loader 的 options
const options = Object.assign(loaderUtils.getOptions(this) || {}, this.options);
// 创建 childCompiler, 用于实现 worker 构建为独立 js 资源
const childCompiler = this._compilation.createChildCompiler(WorkerLoaderName, {
globalObject: 'this',
});
childCompiler.context = this._compiler.context;
// 指定独立构建的 entry 和生成 js 资源名称
new SingleEntryPlugin(this.context, workerEntry, entryFileName).apply(childCompiler);
// 设置 worker 侧的环境变量
new webpack.DefinePlugin({
__WORKER__: true,
}).apply(childCompiler);
// 添加 window 全局对象, 映射为 worker 线程全局对象 self
// 如果在 worker 源码中添加, 可能没有前置到所有引用模块前
new webpack.BannerPlugin({
banner: 'self.window = self;',
raw: true,
entryOnly: true,
}).apply(childCompiler);
// 去除源码中的less css引用
const regExp = /\.(css|less)$/;
new webpack.NormalModuleReplacementPlugin(
regExp,
result => {
if (regExp.test(result.request)) {
result.request = resolve(__dirname, './empty.js');
}
if (regExp.test(result.resource)) {
result.resource = resolve(__dirname, './empty.js');
}
},
).apply(childCompiler);
const subCache = `subcache ${__dirname} ${workerEntry}`;
childCompiler.hooks.compilation.tap(WorkerLoaderName, compilation => {
if (compilation.cache) {
if (!compilation.cache[subCache]) compilation.cache[subCache] = {};
compilation.cache = compilation.cache[subCache];
}
});
childCompiler.runAsChild((error, entries, compilation) => {
if (!error && compilation.errors && compilation.errors.length) {
// eslint-disable-next-line no-param-reassign
error = compilation.errors[0];
}
// compatible with Array (v4) and Set (v5) prototypes
const entry = entries && entries[0] && entries[0].files.values().next().value;
if (!error && !entry) {
// eslint-disable-next-line no-param-reassign
error = Error(`${WorkerLoaderName}, no entry for ${workerEntry}`);
}
if (error) {
return callback(error);
}
// 支持blob url形式
return options.inline
? callback(
null,
// 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理
// 添加 @ts-nocheck 避免 ts-check 报错
// 修复export const 下 const不会被转译的问题
`// @ts-nocheck
const blob = new Blob([${JSON.stringify(compilation.assets[entry].source())}]);
const workerUrl = window.URL.createObjectURL(blob);
export default workerUrl;
`
)
: callback(
null,
`// @ts-nocheck
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)};
export default servicePath;
`
)
});
return;
}
module.exports = loader;

20
src/base/0.base.js

@ -1,11 +1,9 @@
BI.prepares.push(function () { BI.Resizers = new BI.ResizeController();
BI.Resizers = new BI.ResizeController(); BI.Layers = new BI.LayerController();
BI.Layers = new BI.LayerController(); BI.Maskers = new BI.MaskersController();
BI.Maskers = new BI.MaskersController(); BI.Bubbles = new BI.BubblesController();
BI.Bubbles = new BI.BubblesController(); BI.Tooltips = new BI.TooltipsController();
BI.Tooltips = new BI.TooltipsController(); BI.Popovers = new BI.PopoverController();
BI.Popovers = new BI.PopoverController(); BI.Drawers = new BI.DrawerController();
BI.Drawers = new BI.DrawerController(); BI.Broadcasts = new BI.BroadcastController();
BI.Broadcasts = new BI.BroadcastController(); BI.StyleLoaders = new BI.StyleLoaderManager();
BI.StyleLoaders = new BI.StyleLoaderManager();
});

20
src/base/1.pane.js

@ -15,7 +15,7 @@ BI.Pane = BI.inherit(BI.Widget, {
loadingText: "", loadingText: "",
loadingSize: "small", loadingSize: "small",
overlap: true, overlap: true,
onLoaded: BI.emptyFn onLoaded: BI.emptyFn,
}); });
}, },
@ -32,8 +32,8 @@ BI.Pane = BI.inherit(BI.Widget, {
}, },
cls: "bi-tips", cls: "bi-tips",
text: o.tipText, text: o.tipText,
height: 25 height: 25,
}] }],
}); });
} }
}, },
@ -42,7 +42,7 @@ BI.Pane = BI.inherit(BI.Widget, {
var self = this, o = this.options; var self = this, o = this.options;
var loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({ var loadingAnimation = BI.createWidget(BI.Providers.getProvider("bi.provider.system").getLoading({
loadingSize: o.loadingSize, loadingSize: o.loadingSize,
context: this context: this,
})); }));
// pane在同步方式下由items决定tipText的显示与否 // pane在同步方式下由items决定tipText的显示与否
// loading的异步情况下由loaded后对面板的populate的时机决定 // loading的异步情况下由loaded后对面板的populate的时机决定
@ -53,7 +53,7 @@ BI.Pane = BI.inherit(BI.Widget, {
type: "bi.center_adapt", type: "bi.center_adapt",
cls: "loading-container", cls: "loading-container",
items: this._getLoadingTipItems(loadingAnimation), items: this._getLoadingTipItems(loadingAnimation),
element: BI.Layers.make(this.getName() + "-loading", this) element: BI.Layers.make(this.getName() + "-loading", this),
}); });
} }
BI.Layers.show(self.getName() + "-loading"); BI.Layers.show(self.getName() + "-loading");
@ -63,7 +63,7 @@ BI.Pane = BI.inherit(BI.Widget, {
type: "bi.center_adapt", type: "bi.center_adapt",
element: this, element: this,
cls: "loading-container", cls: "loading-container",
items: this._getLoadingTipItems(loadingAnimation) items: this._getLoadingTipItems(loadingAnimation),
}); });
} }
self.fireEvent(BI.Pane.EVENT_LOADING); self.fireEvent(BI.Pane.EVENT_LOADING);
@ -78,12 +78,12 @@ BI.Pane = BI.inherit(BI.Widget, {
var self = this, o = this.options; var self = this, o = this.options;
var loadingTipItems = [{ var loadingTipItems = [{
type: "bi.horizontal_adapt", type: "bi.horizontal_adapt",
items: [loadingTip] items: [loadingTip],
}]; }];
BI.isNotEmptyString(o.loadingText) && loadingTipItems.push({ BI.isNotEmptyString(o.loadingText) && loadingTipItems.push({
type: "bi.text", type: "bi.text",
text: o.loadingText, text: o.loadingText,
tgap: this._getSize(10) tgap: this._getSize(10),
}); });
return [{ return [{
@ -91,7 +91,7 @@ BI.Pane = BI.inherit(BI.Widget, {
ref: function (_ref) { ref: function (_ref) {
self._loading = _ref; self._loading = _ref;
}, },
items: loadingTipItems items: loadingTipItems,
}]; }];
}, },
@ -125,7 +125,7 @@ BI.Pane = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
this.options.items = items || []; this.options.items = items || [];
this.check(); this.check();
} },
}); });
BI.Pane.EVENT_LOADED = "EVENT_LOADED"; BI.Pane.EVENT_LOADED = "EVENT_LOADED";
BI.Pane.EVENT_LOADING = "EVENT_LOADING"; BI.Pane.EVENT_LOADING = "EVENT_LOADING";

9
src/base/collection/__test__/collection.test.js

@ -5,7 +5,6 @@
*/ */
describe("CollectionTest", function () { describe("CollectionTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -15,7 +14,7 @@ describe("CollectionTest", function () {
for (var i = 0; i < cellCount; i++) { for (var i = 0; i < cellCount; i++) {
items[i] = { items[i] = {
type: "bi.label", type: "bi.label",
text: i text: i,
}; };
} }
var grid = BI.Test.createWidget({ var grid = BI.Test.createWidget({
@ -28,11 +27,11 @@ describe("CollectionTest", function () {
x: index % 10 * 50, x: index % 10 * 50,
y: Math.floor(index / 10) * 50, y: Math.floor(index / 10) * 50,
width: 50, width: 50,
height: 50 height: 50,
}; };
} },
}); });
// TODO 列表展示类控件不知道该测什么,先标记一下 // TODO 列表展示类控件不知道该测什么,先标记一下
grid.destroy(); grid.destroy();
}); });
}); });

50
src/base/collection/collection.js

@ -24,7 +24,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
items: [], items: [],
itemFormatter: function (item, index) { itemFormatter: function (item, index) {
return item; return item;
} },
}); });
}, },
@ -38,7 +38,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
self._scrollLock = false; self._scrollLock = false;
}, 1000 / 60); }, 1000 / 60);
this.container = BI._lazyCreateWidget({ this.container = BI._lazyCreateWidget({
type: "bi.absolute" type: "bi.absolute",
}); });
this.element.scroll(function () { this.element.scroll(function () {
if (self._scrollLock === true) { if (self._scrollLock === true) {
@ -49,7 +49,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
self._calculateChildrenToRender(); self._calculateChildrenToRender();
self.fireEvent(BI.CollectionView.EVENT_SCROLL, { self.fireEvent(BI.CollectionView.EVENT_SCROLL, {
scrollLeft: o.scrollLeft, scrollLeft: o.scrollLeft,
scrollTop: o.scrollTop scrollTop: o.scrollTop,
}); });
}); });
// 兼容一下 // 兼容一下
@ -58,7 +58,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (o.overflowY === false) { if (o.overflowY === false) {
scrollable = false; scrollable = false;
} else { } else {
scrollable = "y" scrollable = "y";
} }
} else { } else {
if (o.overflowY === false) { if (o.overflowY === false) {
@ -71,7 +71,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
scrollable: scrollable, scrollable: scrollable,
scrolly: scrolly, scrolly: scrolly,
scrollx: scrollx, scrollx: scrollx,
items: [this.container] items: [this.container],
}); });
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue); self.populate(newValue);
@ -84,7 +84,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
// mounted之后绑定事件 // mounted之后绑定事件
mounted: function () { mounted: function () {
var o = this.options; var o = this.options;
if (o.scrollLeft !== 0 || o.scrollTop !== 0) { if (o.scrollLeft !== 0 || o.scrollTop !== 0) {
this.element.scrollTop(o.scrollTop); this.element.scrollTop(o.scrollTop);
this.element.scrollLeft(o.scrollLeft); this.element.scrollLeft(o.scrollLeft);
@ -101,10 +101,10 @@ BI.CollectionView = BI.inherit(BI.Widget, {
for (var index = 0, len = o.items.length; index < len; index++) { for (var index = 0, len = o.items.length; index < len; index++) {
var cellMetadatum = o.cellSizeAndPositionGetter(index); var cellMetadatum = o.cellSizeAndPositionGetter(index);
if (cellMetadatum.height == null || isNaN(cellMetadatum.height) || if (BI.isNull(cellMetadatum.height) || isNaN(cellMetadatum.height) ||
cellMetadatum.width == null || isNaN(cellMetadatum.width) || BI.isNull(cellMetadatum.width) || isNaN(cellMetadatum.width) ||
cellMetadatum.x == null || isNaN(cellMetadatum.x) || BI.isNull(cellMetadatum.x) || isNaN(cellMetadatum.x) ||
cellMetadatum.y == null || isNaN(cellMetadatum.y)) { BI.isNull(cellMetadatum.y) || isNaN(cellMetadatum.y)) {
throw Error(); throw Error();
} }
@ -124,16 +124,18 @@ BI.CollectionView = BI.inherit(BI.Widget, {
_cellRenderers: function (height, width, x, y) { _cellRenderers: function (height, width, x, y) {
this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y); this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y);
return this._cellGroupRenderer(); return this._cellGroupRenderer();
}, },
_cellGroupRenderer: function () { _cellGroupRenderer: function () {
var self = this, o = this.options; var self = this;
var rendered = []; var rendered = [];
BI.each(this._lastRenderedCellIndices, function (i, index) { BI.each(this._lastRenderedCellIndices, function (i, index) {
var cellMetadata = self._sectionManager.getCellMetadata(index); var cellMetadata = self._sectionManager.getCellMetadata(index);
rendered.push(cellMetadata); rendered.push(cellMetadata);
}); });
return rendered; return rendered;
}, },
@ -167,16 +169,16 @@ BI.CollectionView = BI.inherit(BI.Widget, {
var topMap = BI.invert(tops); var topMap = BI.invert(tops);
// 存储上下左右四个边界 // 存储上下左右四个边界
var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {}; var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {};
var assertMinBorder = function (border, offset) { function assertMinBorder(border, offset) {
if (border[offset] == null) { if (BI.isNull(border[offset])) {
border[offset] = Number.MAX_VALUE; border[offset] = Number.MAX_VALUE;
} }
}; }
var assertMaxBorder = function (border, offset) { function assertMaxBorder(border, offset) {
if (border[offset] == null) { if (BI.isNull(border[offset])) {
border[offset] = 0; border[offset] = 0;
} }
}; }
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1]; var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
@ -194,7 +196,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
this.renderedCells[index].el.element.css("left", datum.x / BI.pixRatio + BI.pixUnit); this.renderedCells[index].el.element.css("left", datum.x / BI.pixRatio + BI.pixUnit);
// } // }
// if (this.renderedCells[index]._top !== datum.y) { // if (this.renderedCells[index]._top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y / BI.pixRatio + BI.pixUnit); this.renderedCells[index].el.element.css("top", datum.y / BI.pixRatio + BI.pixUnit);
// } // }
renderedCells.push(child = this.renderedCells[index]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
@ -202,11 +204,11 @@ BI.CollectionView = BI.inherit(BI.Widget, {
child = BI._lazyCreateWidget(BI.extend({ child = BI._lazyCreateWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: datum.width, width: datum.width,
height: datum.height height: datum.height,
}, item, { }, item, {
cls: (item.cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), cls: (item.cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x, _left: datum.x,
_top: datum.y _top: datum.y,
})); }));
renderedCells.push({ renderedCells.push({
el: child, el: child,
@ -280,7 +282,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
var minY = BI.max(topBorder); var minY = BI.max(topBorder);
var maxY = BI.min(bottomBorder); var maxY = BI.min(bottomBorder);
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; this.renderRange = { minX: minX, minY: minY, maxX: maxX, maxY: maxY };
} }
}, },
@ -339,7 +341,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.options.overflowX !== !!b) { if (this.options.overflowX !== !!b) {
this.options.overflowX = !!b; this.options.overflowX = !!b;
BI.nextTick(function () { BI.nextTick(function () {
self.element.css({overflowX: b ? "auto" : "hidden"}); self.element.css({ overflowX: b ? "auto" : "hidden" });
}); });
} }
}, },
@ -349,7 +351,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.options.overflowY !== !!b) { if (this.options.overflowY !== !!b) {
this.options.overflowY = !!b; this.options.overflowY = !!b;
BI.nextTick(function () { BI.nextTick(function () {
self.element.css({overflowY: b ? "auto" : "hidden"}); self.element.css({ overflowY: b ? "auto" : "hidden" });
}); });
} }
}, },
@ -396,7 +398,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
this.restore(); this.restore();
} }
this._populate(items); this._populate(items);
} },
}); });
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
BI.shortcut("bi.collection_view", BI.CollectionView); BI.shortcut("bi.collection_view", BI.CollectionView);

42
src/base/combination/bubble.js

@ -6,17 +6,18 @@
BI.Bubble = BI.inherit(BI.Widget, { BI.Bubble = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.Bubble.superclass._defaultConfig.apply(this, arguments); var conf = BI.Bubble.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-popper", baseCls: (conf.baseCls || "") + " bi-popper",
attributes: { attributes: {
tabIndex: -1 tabIndex: -1,
}, },
trigger: "click", // click || hover || click-hover || "" trigger: "click", // click || hover || click-hover || ""
toggle: true, toggle: true,
direction: "", direction: "",
placement: "bottom-start", // top-start/top/top-end/bottom-start/bottom/bottom-end/left-start/left/left-end/right-start/right/right-end placement: "bottom-start", // top-start/top/top-end/bottom-start/bottom/bottom-end/left-start/left/left-end/right-start/right/right-end
logic: { logic: {
dynamic: true dynamic: true,
}, },
container: null, // popupview放置的容器,默认为this.element container: null, // popupview放置的容器,默认为this.element
isDefaultInit: false, isDefaultInit: false,
@ -81,11 +82,11 @@
}); });
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [ items: [
{ el: this.combo } { el: this.combo }
] ],
})))); }))));
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
}, },
@ -104,14 +105,14 @@
_initPullDownAction: function () { _initPullDownAction: function () {
var self = this, o = this.options; var self = this, o = this.options;
var evs = (this.options.trigger || "").split(","); var evs = (this.options.trigger || "").split(",");
var st = function (e) { function st (e) {
if (o.stopEvent) { if (o.stopEvent) {
e.stopEvent(); e.stopEvent();
} }
if (o.stopPropagation) { if (o.stopPropagation) {
e.stopPropagation(); e.stopPropagation();
} }
}; }
var enterPopup = false; var enterPopup = false;
@ -171,7 +172,7 @@
} }
}, BI.EVENT_RESPONSE_TIME, { }, BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false "trailing": false,
}); });
self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) { self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) {
debounce(e); debounce(e);
@ -194,7 +195,7 @@
} }
}, BI.EVENT_RESPONSE_TIME, { }, BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false "trailing": false,
}); });
self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) { self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) {
debounce(e); debounce(e);
@ -217,23 +218,25 @@
} }
}); });
break; break;
default:
break;
} }
}); });
}, },
_initCombo: function () { _initCombo: function () {
this.combo = BI.createWidget(this.options.el, { this.combo = BI.createWidget(this.options.el, {
value: this.options.value value: this.options.value,
}); });
}, },
_assertPopupView: function () { _assertPopupView: function () {
var self = this, o = this.options; var self = this, o = this.options;
if (this.popupView == null) { if (BI.isNull(this.popupView)) {
this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, {
type: "bi.bubble_popup_view", type: "bi.bubble_popup_view",
showArrow: o.showArrow, showArrow: o.showArrow,
value: o.value value: o.value,
}, this); }, this);
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
@ -258,7 +261,7 @@
element: this.options.container || this, element: this.options.container || this,
items: [ items: [
{ el: this.popupView } { el: this.popupView }
] ],
}); });
this._rendered = true; this._rendered = true;
} }
@ -286,6 +289,7 @@
return; return;
} }
this._hideView(e); this._hideView(e);
return true; return true;
}, },
@ -319,7 +323,7 @@
}, },
_popupView: function (e) { _popupView: function (e) {
var self = this, o = this.options; var o = this.options;
this._assertPopupViewRender(); this._assertPopupViewRender();
this.fireEvent(BI.Bubble.EVENT_BEFORE_POPUPVIEW); this.fireEvent(BI.Bubble.EVENT_BEFORE_POPUPVIEW);
// popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下 // popupVisible是为了获取其宽高, 放到可视范围之外以防止在IE下闪一下
@ -335,22 +339,22 @@
options: { options: {
offset: function () { offset: function () {
return [o.adjustXOffset, (o.showArrow ? 12 : 0) + (o.adjustYOffset + o.adjustLength)]; return [o.adjustXOffset, (o.showArrow ? 12 : 0) + (o.adjustYOffset + o.adjustLength)];
} },
} },
}]; }];
if (this.options.showArrow) { if (this.options.showArrow) {
modifiers.push({ modifiers.push({
name: "arrow", name: "arrow",
options: { options: {
padding: 4, padding: 4,
element: this.popupView.arrow.element[0] element: this.popupView.arrow.element[0],
} },
}); });
} }
this.popper = BI.Popper.createPopper(this.combo.element[0], this.popupView.element[0], { this.popper = BI.Popper.createPopper(this.combo.element[0], this.popupView.element[0], {
placement: o.placement, placement: o.placement,
strategy: "fixed", strategy: "fixed",
modifiers: modifiers modifiers: modifiers,
}); });
// this.adjustHeight(e); // this.adjustHeight(e);
@ -478,7 +482,7 @@
this.popper && this.popper.destroy(); this.popper && this.popper.destroy();
this.popper = null; this.popper = null;
this.popupView && this.popupView._destroy(); this.popupView && this.popupView._destroy();
} },
}); });
BI.Bubble.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; BI.Bubble.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
BI.Bubble.EVENT_CHANGE = "EVENT_CHANGE"; BI.Bubble.EVENT_CHANGE = "EVENT_CHANGE";

38
src/base/combination/combo.js

@ -1,26 +1,28 @@
!(function () { !(function () {
var needHideWhenAnotherComboOpen = {}; var needHideWhenAnotherComboOpen = {};
var currentOpenedCombos = {}; var currentOpenedCombos = {};
/** /**
* @class BI.Combo * @class BI.Combo
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.Combo = BI.inherit(BI.Bubble, { BI.Combo = BI.inherit(BI.Bubble, {
_const: { _const: {
TRIANGLE_LENGTH: 12 TRIANGLE_LENGTH: 12,
}, },
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""), baseCls: (conf.baseCls || "") + " bi-combo" + (BI.isIE() ? " hack" : ""),
attributes: { attributes: {
tabIndex: -1 tabIndex: -1,
}, },
trigger: "click", // click || hover || click-hover || "" trigger: "click", // click || hover || click-hover || ""
toggle: true, toggle: true,
direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight||right,innerLeft||innerRight||innerLeft direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right||right,innerRight||right,innerLeft||innerRight||innerLeft
logic: { logic: {
dynamic: true dynamic: true,
}, },
container: null, // popupview放置的容器,默认为this.element container: null, // popupview放置的容器,默认为this.element
isDefaultInit: false, isDefaultInit: false,
@ -42,7 +44,7 @@
popup: {}, popup: {},
comboClass: "bi-combo-popup", comboClass: "bi-combo-popup",
hoverClass: "bi-combo-hover", hoverClass: "bi-combo-hover",
belowMouse: false belowMouse: false,
}); });
}, },
@ -90,11 +92,11 @@
}); });
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, { }, BI.LogicFactory.createLogic("vertical", BI.extend(o.logic, {
items: [ items: [
{ el: this.combo } { el: this.combo }
] ],
})))); }))));
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
BI.Resizers.add(this.getName(), BI.bind(function (e) { BI.Resizers.add(this.getName(), BI.bind(function (e) {
@ -107,11 +109,11 @@
_assertPopupView: function () { _assertPopupView: function () {
var self = this, o = this.options; var self = this, o = this.options;
if (this.popupView == null) { if (BI.isNull(this.popupView)) {
this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, { this.popupView = BI.createWidget(BI.isFunction(this.options.popup) ? this.options.popup() : this.options.popup, {
type: "bi.popup_view", type: "bi.popup_view",
showArrow: o.showArrow, showArrow: o.showArrow,
value: o.value value: o.value,
}, this); }, this);
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
@ -195,7 +197,7 @@
offset: function () { offset: function () {
return { return {
left: e.pageX, left: e.pageX,
top: e.pageY top: e.pageY,
}; };
}, },
bounds: function () { bounds: function () {
@ -204,7 +206,7 @@
x: e.offsetX, x: e.offsetX,
y: e.offsetY, y: e.offsetY,
width: 0, width: 0,
height: 24 height: 24,
}; };
}, },
outerWidth: function () { outerWidth: function () {
@ -212,8 +214,8 @@
}, },
outerHeight: function () { outerHeight: function () {
return 24; return 24;
} },
} },
} : this.combo; } : this.combo;
switch (o.direction) { switch (o.direction) {
case "bottom": case "bottom":
@ -280,10 +282,12 @@
delete p.adaptHeight; delete p.adaptHeight;
p.dir = "right"; p.dir = "right";
break; break;
default:
break;
} }
if ("adaptHeight" in p) { if ("adaptHeight" in p) {
this.resetListHeight(p["adaptHeight"]); this.resetListHeight(p.adaptHeight);
} }
var width = this.combo.element.outerWidth(); var width = this.combo.element.outerWidth();
var height = this.combo.element.outerHeight(); var height = this.combo.element.outerHeight();
@ -293,16 +297,16 @@
offsetStyle: o.offsetStyle, offsetStyle: o.offsetStyle,
adjustXOffset: o.adjustXOffset, adjustXOffset: o.adjustXOffset,
adjustYOffset: o.adjustYOffset, adjustYOffset: o.adjustYOffset,
offset: this.combo.element.offset() offset: this.combo.element.offset(),
}); });
if ("left" in p) { if ("left" in p) {
this.popupView.element.css({ this.popupView.element.css({
left: p.left left: p.left,
}); });
} }
if ("top" in p) { if ("top" in p) {
this.popupView.element.css({ this.popupView.element.css({
top: p.top top: p.top,
}); });
} }
this.position = p; this.position = p;
@ -322,7 +326,7 @@
this.popupView && this.popupView._destroy(); this.popupView && this.popupView._destroy();
delete needHideWhenAnotherComboOpen[this.getName()]; delete needHideWhenAnotherComboOpen[this.getName()];
delete currentOpenedCombos[this.getName()]; delete currentOpenedCombos[this.getName()];
} },
}); });
BI.Combo.closeAll = function () { BI.Combo.closeAll = function () {
BI.each(currentOpenedCombos, function (i, combo) { BI.each(currentOpenedCombos, function (i, combo) {

20
src/base/combination/expander.js

@ -17,7 +17,7 @@ BI.Expander = BI.inherit(BI.Widget, {
el: {}, el: {},
popup: {}, popup: {},
expanderClass: "bi-expander-popup", expanderClass: "bi-expander-popup",
hoverClass: "bi-expander-hover" hoverClass: "bi-expander-hover",
}); });
}, },
@ -66,7 +66,7 @@ BI.Expander = BI.inherit(BI.Widget, {
element: this, element: this,
items: [ items: [
{ el: this.expander } { el: this.expander }
] ],
}); });
o.isDefaultInit && this._assertPopupView(); o.isDefaultInit && this._assertPopupView();
if (this.expander.isOpened() === true) { if (this.expander.isOpened() === true) {
@ -122,10 +122,12 @@ BI.Expander = BI.inherit(BI.Widget, {
} }
}, BI.EVENT_RESPONSE_TIME, { }, BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false "trailing": false,
})); }));
} }
break; break;
default:
break;
} }
}); });
}, },
@ -136,16 +138,16 @@ BI.Expander = BI.inherit(BI.Widget, {
_assertPopupView: function () { _assertPopupView: function () {
var self = this, o = this.options; var self = this, o = this.options;
if (this.popupView == null) { if (BI.isNull(this.popupView)) {
this.popupView = BI.createWidget(this.options.popup, { this.popupView = BI.createWidget(this.options.popup, {
type: "bi.button_group", type: "bi.button_group",
cls: "expander-popup", cls: "expander-popup",
layouts: [{ layouts: [{
type: "bi.vertical", type: "bi.vertical",
hgap: 0, hgap: 0,
vgap: 0 vgap: 0,
}], }],
value: o.value value: o.value,
}, this); }, this);
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -170,7 +172,7 @@ BI.Expander = BI.inherit(BI.Widget, {
element: this, element: this,
items: [ items: [
{ el: this.popupView } { el: this.popupView }
] ],
}); });
this._rendered = true; this._rendered = true;
} }
@ -255,6 +257,7 @@ BI.Expander = BI.inherit(BI.Widget, {
if (this.expander.options.id === id) { if (this.expander.options.id === id) {
return this.expander; return this.expander;
} }
return this.popupView && this.popupView.getNodeById(id); return this.popupView && this.popupView.getNodeById(id);
}, },
@ -262,12 +265,13 @@ BI.Expander = BI.inherit(BI.Widget, {
if (this.expander.getValue() === value) { if (this.expander.getValue() === value) {
return this.expander; return this.expander;
} }
return this.popupView && this.popupView.getNodeByValue(value); return this.popupView && this.popupView.getNodeByValue(value);
}, },
destroy: function () { destroy: function () {
BI.Expander.superclass.destroy.apply(this, arguments); BI.Expander.superclass.destroy.apply(this, arguments);
} },
}); });
BI.Expander.EVENT_EXPAND = "EVENT_EXPAND"; BI.Expander.EVENT_EXPAND = "EVENT_EXPAND";
BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE"; BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE";

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

@ -15,8 +15,8 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
layouts: [{ layouts: [{
type: "bi.center", type: "bi.center",
hgap: 0, hgap: 0,
vgap: 0 vgap: 0,
}] }],
}); });
}, },
@ -25,7 +25,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
var behaviors = {}; var behaviors = {};
BI.each(o.behaviors, function (key, rule) { BI.each(o.behaviors, function (key, rule) {
behaviors[key] = BI.BehaviorFactory.createBehavior(key, { behaviors[key] = BI.BehaviorFactory.createBehavior(key, {
rule: rule rule: rule,
}); });
}); });
this.behaviors = behaviors; this.behaviors = behaviors;
@ -42,9 +42,8 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
}, },
_createBtns: function (items) { _createBtns: function (items) {
var o = this.options;
return BI.createWidgets(BI.createItems(items, { return BI.createWidgets(BI.createItems(items, {
type: "bi.text_button" type: "bi.text_button",
}), this); }), this);
}, },
@ -66,6 +65,8 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
case BI.ButtonGroup.CHOOSE_TYPE_NONE: case BI.ButtonGroup.CHOOSE_TYPE_NONE:
self.setValue([]); self.setValue([]);
break; break;
default:
break;
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj);
@ -89,23 +90,26 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return BI.extend({}, layouts[i], { return BI.extend({}, layouts[i], {
items: [ items: [
BI.extend({}, layouts[i].el, { BI.extend({}, layouts[i].el, {
el: it el: it,
}) })
] ],
}); });
}); });
} }
return btns; return btns;
}, },
_packageSimpleItems: function (btns) { _packageSimpleItems: function (btns) {
var o = this.options; var o = this.options;
return BI.map(o.items, function (i, item) { return BI.map(o.items, function (i, item) {
if (BI.stripEL(item) === item) { if (BI.stripEL(item) === item) {
return btns[i]; return btns[i];
} }
return BI.extend({}, item, { return BI.extend({}, item, {
el: btns[i] el: btns[i],
}); });
}); });
}, },
@ -122,12 +126,14 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
lay = BI.formatEL(lay.items[0]).el; lay = BI.formatEL(lay.items[0]).el;
} }
lay.items = items; lay.items = items;
return layout; return layout;
}, },
// 如果是一个简单的layout // 如果是一个简单的layout
_isSimpleLayout: function () { _isSimpleLayout: function () {
var o = this.options; var o = this.options;
return BI.isArray(o.layouts) ? (o.layouts.length === 1 && !BI.isArray(o.items[0])) : true; return BI.isArray(o.layouts) ? (o.layouts.length === 1 && !BI.isArray(o.items[0])) : true;
}, },
@ -140,12 +146,12 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
}, },
prependItems: function (items) { prependItems: function (items) {
var o = this.options;
var btns = this._btnsCreator.apply(this, arguments); var btns = this._btnsCreator.apply(this, arguments);
this.buttons = BI.concat(btns, this.buttons); this.buttons = BI.concat(btns, this.buttons);
if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) { if (this._isSimpleLayout() && this.layouts && this.layouts.prependItems) {
this.layouts.prependItems(btns); this.layouts.prependItems(btns);
return; return;
} }
@ -154,13 +160,13 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
}, },
addItems: function (items) { addItems: function (items) {
var o = this.options;
var btns = this._btnsCreator.apply(this, arguments); var btns = this._btnsCreator.apply(this, arguments);
this.buttons = BI.concat(this.buttons, btns); this.buttons = BI.concat(this.buttons, btns);
// 如果是一个简单的layout // 如果是一个简单的layout
if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) { if (this._isSimpleLayout() && this.layouts && this.layouts.addItems) {
this.layouts.addItems(btns); this.layouts.addItems(btns);
return; return;
} }
@ -257,6 +263,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
v.push(item.getValue()); v.push(item.getValue());
} }
}); });
return v; return v;
}, },
@ -267,6 +274,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
v.push(item.getValue()); v.push(item.getValue());
} }
}); });
return v; return v;
}, },
@ -285,6 +293,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
btns.push(item); btns.push(item);
} }
}); });
return btns; return btns;
}, },
@ -295,6 +304,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
btns.push(item); btns.push(item);
} }
}); });
return btns; return btns;
}, },
@ -303,9 +313,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
BI.any(this.buttons, function (i, item) { BI.any(this.buttons, function (i, item) {
if (item.isEnabled() && item.getValue() === value) { if (item.isEnabled() && item.getValue() === value) {
index = i; index = i;
return true; return true;
} }
}); });
return index; return index;
}, },
@ -314,9 +326,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
BI.any(this.buttons, function (i, item) { BI.any(this.buttons, function (i, item) {
if (item.isEnabled() && item.options.id === id) { if (item.isEnabled() && item.options.id === id) {
node = item; node = item;
return true; return true;
} }
}); });
return node; return node;
}, },
@ -325,9 +339,11 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
BI.any(this.buttons, function (i, item) { BI.any(this.buttons, function (i, item) {
if (item.isEnabled() && item.getValue() === value) { if (item.isEnabled() && item.getValue() === value) {
node = item; node = item;
return true; return true;
} }
}); });
return node; return node;
}, },
@ -349,14 +365,14 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
destroy: function () { destroy: function () {
BI.ButtonGroup.superclass.destroy.apply(this, arguments); BI.ButtonGroup.superclass.destroy.apply(this, arguments);
this.options.items = []; this.options.items = [];
} },
}); });
BI.extend(BI.ButtonGroup, { BI.extend(BI.ButtonGroup, {
CHOOSE_TYPE_SINGLE: BI.Selection.Single, CHOOSE_TYPE_SINGLE: BI.Selection.Single,
CHOOSE_TYPE_MULTI: BI.Selection.Multi, CHOOSE_TYPE_MULTI: BI.Selection.Multi,
CHOOSE_TYPE_ALL: BI.Selection.All, CHOOSE_TYPE_ALL: BI.Selection.All,
CHOOSE_TYPE_NONE: BI.Selection.None, CHOOSE_TYPE_NONE: BI.Selection.None,
CHOOSE_TYPE_DEFAULT: BI.Selection.Default CHOOSE_TYPE_DEFAULT: BI.Selection.Default,
}); });
BI.ButtonGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.ButtonGroup.EVENT_CHANGE = "EVENT_CHANGE";

18
src/base/combination/group.combo.js

@ -15,7 +15,7 @@ BI.ComboGroup = BI.inherit(BI.Widget, {
isNeedAdjustHeight: false, isNeedAdjustHeight: false,
isNeedAdjustWidth: false, isNeedAdjustWidth: false,
el: {type: "bi.text_button", text: "", value: ""}, el: { type: "bi.text_button", text: "", value: "" },
items: [], items: [],
popup: { popup: {
@ -23,10 +23,10 @@ BI.ComboGroup = BI.inherit(BI.Widget, {
type: "bi.button_tree", type: "bi.button_tree",
chooseType: 0, chooseType: 0,
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}] }],
} },
} },
}); });
}, },
@ -71,9 +71,9 @@ BI.ComboGroup = BI.inherit(BI.Widget, {
el: item, el: item,
popup: BI.extend({}, o.popup, { popup: BI.extend({}, o.popup, {
el: BI.extend({ el: BI.extend({
items: children items: children,
}, o.popup.el) }, o.popup.el),
}) }),
}); });
this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -89,7 +89,7 @@ BI.ComboGroup = BI.inherit(BI.Widget, {
setValue: function (v) { setValue: function (v) {
this.combo.setValue(v); this.combo.setValue(v);
} },
}); });
BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE";

21
src/base/combination/group.virtual.js

@ -6,8 +6,8 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
layouts: [{ layouts: [{
type: "bi.center", type: "bi.center",
hgap: 0, hgap: 0,
vgap: 0 vgap: 0,
}] }],
}); });
}, },
@ -29,9 +29,10 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
var o = this.options; var o = this.options;
var map = this.buttonMap = {}; var map = this.buttonMap = {};
var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts]; var layouts = BI.isArray(o.layouts) ? o.layouts : [o.layouts];
for (var i = layouts.length - 1; i > 0; i--) { for (let i = layouts.length - 1; i > 0; i--) {
items = BI.map(items, function (k, it) { items = BI.map(items, function (k, it) {
var el = BI.stripEL(it); var el = BI.stripEL(it);
return BI.extend({}, layouts[i], { return BI.extend({}, layouts[i], {
items: [ items: [
BI.extend({}, layouts[i].el, { BI.extend({}, layouts[i].el, {
@ -40,13 +41,14 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
if (BI.isKey(map[el.value])) { if (BI.isKey(map[el.value])) {
map[el.value] = _ref; map[el.value] = _ref;
} }
} },
}, el) }, el),
}) })
] ],
}); });
}); });
} }
return items; return items;
}, },
@ -60,6 +62,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
lay = BI.formatEL(lay.items[0]).el; lay = BI.formatEL(lay.items[0]).el;
} }
lay.items = items; lay.items = items;
return layout; return layout;
}, },
@ -93,6 +96,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
} }
} }
}); });
return v; return v;
}, },
@ -119,6 +123,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
} }
} }
}); });
return v; return v;
}, },
@ -130,10 +135,10 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
this.layouts = BI.createWidget(BI.extend({ element: this }, this._packageLayout(items))); this.layouts = BI.createWidget(BI.extend({ element: this }, this._packageLayout(items)));
} else { } else {
this.layouts.populate(items, { this.layouts.populate(items, {
context: this context: this,
}); });
} }
} },
}); });
BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE"; BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE";

36
src/base/combination/loader.js

@ -14,12 +14,12 @@ BI.Loader = BI.inherit(BI.Widget, {
isDefaultInit: true, // 是否默认初始化数据 isDefaultInit: true, // 是否默认初始化数据
logic: { logic: {
dynamic: true, dynamic: true,
scrolly: true scrolly: true,
}, },
// 下面是button_group的属性 // 下面是button_group的属性
el: { el: {
type: "bi.button_group" type: "bi.button_group",
}, },
items: [], items: [],
@ -31,14 +31,14 @@ BI.Loader = BI.inherit(BI.Widget, {
prev: false, prev: false,
next: {}, next: {},
hasPrev: BI.emptyFn, hasPrev: BI.emptyFn,
hasNext: BI.emptyFn hasNext: BI.emptyFn,
}); });
}, },
_prevLoad: function () { _prevLoad: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.prev.setLoading(); this.prev.setLoading();
o.itemsCreator.apply(this, [{times: --this.times}, function () { o.itemsCreator.apply(this, [{ times: --this.times }, function () {
self.prev.setLoaded(); self.prev.setLoaded();
self.prependItems.apply(self, arguments); self.prependItems.apply(self, arguments);
}]); }]);
@ -47,7 +47,7 @@ BI.Loader = BI.inherit(BI.Widget, {
_nextLoad: function () { _nextLoad: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.next.setLoading(); this.next.setLoading();
o.itemsCreator.apply(this, [{times: ++this.times}, function () { o.itemsCreator.apply(this, [{ times: ++this.times }, function () {
self.next.setLoaded(); self.next.setLoaded();
self.addItems.apply(self, arguments); self.addItems.apply(self, arguments);
}]); }]);
@ -61,7 +61,7 @@ BI.Loader = BI.inherit(BI.Widget, {
} }
if (o.prev !== false) { if (o.prev !== false) {
this.prev = BI.createWidget(BI.extend({ this.prev = BI.createWidget(BI.extend({
type: "bi.loading_bar" type: "bi.loading_bar",
}, o.prev)); }, o.prev));
this.prev.on(BI.Controller.EVENT_CHANGE, function (type) { this.prev.on(BI.Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
@ -76,9 +76,9 @@ BI.Loader = BI.inherit(BI.Widget, {
items: o.items, items: o.items,
behaviors: {}, behaviors: {},
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}], }],
value: o.value value: o.value,
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -89,7 +89,7 @@ BI.Loader = BI.inherit(BI.Widget, {
if (o.next !== false) { if (o.next !== false) {
this.next = BI.createWidget(BI.extend({ this.next = BI.createWidget(BI.extend({
type: "bi.loading_bar" type: "bi.loading_bar",
}, o.next)); }, o.next));
this.next.on(BI.Controller.EVENT_CHANGE, function (type) { this.next.on(BI.Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) { if (type === BI.Events.CLICK) {
@ -99,11 +99,11 @@ BI.Loader = BI.inherit(BI.Widget, {
} }
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({
scrolly: true scrolly: true,
}, o.logic, { }, o.logic, {
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.prev, this.button_group, this.next) items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.prev, this.button_group, this.next),
})))); }))));
o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () { o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () {
@ -122,9 +122,10 @@ BI.Loader = BI.inherit(BI.Widget, {
if (BI.isNumber(o.count)) { if (BI.isNumber(o.count)) {
return this.count < o.count; return this.count < o.count;
} }
return !!o.hasPrev.apply(this, [{ return !!o.hasPrev.apply(this, [{
times: this.times, times: this.times,
count: this.count count: this.count,
}]); }]);
}, },
@ -133,9 +134,10 @@ BI.Loader = BI.inherit(BI.Widget, {
if (BI.isNumber(o.count)) { if (BI.isNumber(o.count)) {
return this.count < o.count; return this.count < o.count;
} }
return !!o.hasNext.apply(this, [{ return !!o.hasNext.apply(this, [{
times: this.times, times: this.times,
count: this.count count: this.count,
}]); }]);
}, },
@ -168,13 +170,14 @@ BI.Loader = BI.inherit(BI.Widget, {
_populate: function (items) { _populate: function (items) {
var self = this, o = this.options; var self = this, o = this.options;
if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) {
o.itemsCreator.apply(this, [{times: 1}, function () { o.itemsCreator.apply(this, [{ times: 1 }, function () {
if (arguments.length === 0) { if (arguments.length === 0) {
throw new Error("参数不能为空"); throw new Error("参数不能为空");
} }
self.populate.apply(self, arguments); self.populate.apply(self, arguments);
o.onLoaded(); o.onLoaded();
}]); }]);
return false; return false;
} }
this.options.items = items; this.options.items = items;
@ -195,6 +198,7 @@ BI.Loader = BI.inherit(BI.Widget, {
this.prev.invisible(); this.prev.invisible();
} }
} }
return true; return true;
}, },
@ -255,7 +259,7 @@ BI.Loader = BI.inherit(BI.Widget, {
destroy: function () { destroy: function () {
BI.Loader.superclass.destroy.apply(this, arguments); BI.Loader.superclass.destroy.apply(this, arguments);
} },
}); });
BI.Loader.EVENT_CHANGE = "EVENT_CHANGE"; BI.Loader.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.loader", BI.Loader); BI.shortcut("bi.loader", BI.Loader);

19
src/base/combination/navigation.js

@ -7,7 +7,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
direction: "bottom", // top, bottom, left, right, custom direction: "bottom", // top, bottom, left, right, custom
logic: { logic: {
dynamic: false dynamic: false,
}, },
single: false, single: false,
showIndex: false, showIndex: false,
@ -17,22 +17,22 @@ BI.Navigation = BI.inherit(BI.Widget, {
}, },
afterCardCreated: BI.emptyFn, afterCardCreated: BI.emptyFn,
afterCardShow: BI.emptyFn afterCardShow: BI.emptyFn,
}); });
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); this.tab = BI.createWidget(this.options.tab, { type: "bi.button_group" });
this.cardMap = {}; this.cardMap = {};
this.showIndex = 0; this.showIndex = 0;
this.layout = BI.createWidget({ this.layout = BI.createWidget({
type: "bi.card" type: "bi.card",
}); });
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout),
})))); }))));
@ -45,16 +45,17 @@ BI.Navigation = BI.inherit(BI.Widget, {
cardCreator: function (v) { cardCreator: function (v) {
var card = o.cardCreator(v); var card = o.cardCreator(v);
self.cardMap[v] = card; self.cardMap[v] = card;
return card; return card;
}, },
afterCardCreated: BI.bind(this.afterCardCreated, this), afterCardCreated: BI.bind(this.afterCardCreated, this),
afterCardShow: BI.bind(this.afterCardShow, this) afterCardShow: BI.bind(this.afterCardShow, this),
}); });
if (BI.isFunction(o.showIndex)) { if (BI.isFunction(o.showIndex)) {
this.__watch(o.showIndex, function (context, newValue) { this.__watch(o.showIndex, function (context, newValue) {
self.setSelect(newValue); self.setSelect(newValue);
}) });
} }
}, },
@ -161,7 +162,7 @@ BI.Navigation = BI.inherit(BI.Widget, {
destroy: function () { destroy: function () {
BI.Navigation.superclass.destroy.apply(this, arguments); BI.Navigation.superclass.destroy.apply(this, arguments);
} },
}); });
BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE"; BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE";

34
src/base/combination/searcher.js

@ -28,17 +28,17 @@ BI.Searcher = BI.inherit(BI.Widget, {
}, },
el: { el: {
type: "bi.search_editor" type: "bi.search_editor",
}, },
popup: { popup: {
type: "bi.searcher_view" type: "bi.searcher_view",
}, },
adapter: null, adapter: null,
masker: { // masker层 masker: { // masker层
offset: {} offset: {},
} },
}); });
}, },
@ -46,7 +46,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
var self = this, o = this.options; var self = this, o = this.options;
this.editor = BI.createWidget(o.el, { this.editor = BI.createWidget(o.el, {
type: "bi.search_editor" type: "bi.search_editor",
}); });
BI.createWidget({ BI.createWidget({
@ -58,13 +58,13 @@ BI.Searcher = BI.inherit(BI.Widget, {
bgap: o.bgap, bgap: o.bgap,
vgap: o.vgap, vgap: o.vgap,
hgap: o.hgap, hgap: o.hgap,
items: [this.editor] items: [this.editor],
}); });
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, { var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false "trailing": false,
}); });
this.editor.on(BI.Controller.EVENT_CHANGE, function (type) { this.editor.on(BI.Controller.EVENT_CHANGE, function (type) {
switch (type) { switch (type) {
@ -82,6 +82,8 @@ BI.Searcher = BI.inherit(BI.Widget, {
self._pauseSearch(); self._pauseSearch();
} }
break; break;
default:
break;
} }
}); });
}, },
@ -91,7 +93,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) {
this.popupView = BI.createWidget(o.popup, { this.popupView = BI.createWidget(o.popup, {
type: "bi.searcher_view", type: "bi.searcher_view",
chooseType: o.chooseType chooseType: o.chooseType,
}); });
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -109,6 +111,8 @@ BI.Searcher = BI.inherit(BI.Widget, {
values.push(obj.getValue()); values.push(obj.getValue());
o.adapter && o.adapter.setValue(values); o.adapter && o.adapter.setValue(values);
break; break;
default:
break;
} }
} }
self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj);
@ -121,7 +125,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
if (o.masker && !BI.Maskers.has(this.getName())) { if (o.masker && !BI.Maskers.has(this.getName())) {
BI.Maskers.create(this.getName(), o.adapter, BI.extend({ BI.Maskers.create(this.getName(), o.adapter, BI.extend({
container: this, container: this,
render: this.popupView render: this.popupView,
}, o.masker), this); }, o.masker), this);
} }
}, },
@ -140,7 +144,6 @@ BI.Searcher = BI.inherit(BI.Widget, {
}, },
_pauseSearch: function () { _pauseSearch: function () {
var o = this.options, name = this.getName();
this._stop = true; this._stop = true;
BI.nextTick(function (name) { BI.nextTick(function (name) {
BI.Maskers.hide(name); BI.Maskers.hide(name);
@ -153,7 +156,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
}, },
_stopSearch: function () { _stopSearch: function () {
var o = this.options, name = this.getName(); var name = this.getName();
this._stop = true; this._stop = true;
BI.Maskers.hide(name); BI.Maskers.hide(name);
if (this._isSearching === true) { if (this._isSearching === true) {
@ -175,13 +178,14 @@ BI.Searcher = BI.inherit(BI.Widget, {
this.popupView.populate(find, match, keyword); this.popupView.populate(find, match, keyword);
o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue());
self.fireEvent(BI.Searcher.EVENT_SEARCHING); self.fireEvent(BI.Searcher.EVENT_SEARCHING);
return; return;
} }
this.popupView.loading && this.popupView.loading(); this.popupView.loading && this.popupView.loading();
o.onSearch({ o.onSearch({
times: 1, times: 1,
keyword: keyword, keyword: keyword,
selectedValues: o.adapter && o.adapter.getValue() selectedValues: o.adapter && o.adapter.getValue(),
}, function (searchResult, matchResult) { }, function (searchResult, matchResult) {
if (!self._stop && keyword === self.editor.getValue()) { if (!self._stop && keyword === self.editor.getValue()) {
var args = [].slice.call(arguments); var args = [].slice.call(arguments);
@ -203,6 +207,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
if (BI.isEmptyString(res[res.length - 1])) { if (BI.isEmptyString(res[res.length - 1])) {
res = res.slice(0, res.length - 1); res = res.slice(0, res.length - 1);
} }
return BI.isNull(res) ? "" : res[res.length - 1]; return BI.isNull(res) ? "" : res[res.length - 1];
} }
}, },
@ -246,6 +251,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
hasMatched: function () { hasMatched: function () {
this._assertPopupView(); this._assertPopupView();
return this.popupView.hasMatched(); return this.popupView.hasMatched();
}, },
@ -288,8 +294,8 @@ BI.Searcher = BI.inherit(BI.Widget, {
if (BI.isNull(this.popupView)) { if (BI.isNull(this.popupView)) {
return o.popup.value; return o.popup.value;
} }
return this.popupView.getValue();
return this.popupView.getValue();
}, },
populate: function (result, searchResult, keyword) { populate: function (result, searchResult, keyword) {
@ -319,7 +325,7 @@ BI.Searcher = BI.inherit(BI.Widget, {
setWaterMark: function (v) { setWaterMark: function (v) {
this.editor.setWaterMark(v); this.editor.setWaterMark(v);
} },
}); });
BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE"; BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE";
BI.Searcher.EVENT_START = "EVENT_START"; BI.Searcher.EVENT_START = "EVENT_START";

18
src/base/combination/switcher.js

@ -18,7 +18,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
adapter: null, adapter: null,
masker: {}, masker: {},
switcherClass: "bi-switcher-popup", switcherClass: "bi-switcher-popup",
hoverClass: "bi-switcher-hover" hoverClass: "bi-switcher-hover",
}); });
}, },
@ -66,7 +66,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
element: this, element: this,
items: [ items: [
{ el: this.switcher } { el: this.switcher }
] ],
}); });
o.isDefaultInit && (this._assertPopupView()); o.isDefaultInit && (this._assertPopupView());
}, },
@ -119,7 +119,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
} }
}, BI.EVENT_RESPONSE_TIME, { }, BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false "trailing": false,
})); }));
} }
break; break;
@ -129,7 +129,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
_initSwitcher: function () { _initSwitcher: function () {
this.switcher = BI.createWidget(this.options.el, { this.switcher = BI.createWidget(this.options.el, {
value: this.options.value value: this.options.value,
}); });
}, },
@ -143,9 +143,9 @@ BI.Switcher = BI.inherit(BI.Widget, {
layouts: [{ layouts: [{
type: "bi.vertical", type: "bi.vertical",
hgap: 0, hgap: 0,
vgap: 0 vgap: 0,
}], }],
value: o.value value: o.value,
}, this); }, this);
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -160,7 +160,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
element: this, element: this,
items: [ items: [
{ el: this.popupView } { el: this.popupView }
] ],
}); });
} }
this._created = true; this._created = true;
@ -265,6 +265,7 @@ BI.Switcher = BI.inherit(BI.Widget, {
if (this.switcher.attr("id") === id) { if (this.switcher.attr("id") === id) {
return this.switcher; return this.switcher;
} }
return this.popupView && this.popupView.getNodeById(id); return this.popupView && this.popupView.getNodeById(id);
}, },
@ -272,12 +273,13 @@ BI.Switcher = BI.inherit(BI.Widget, {
if (this.switcher.getValue() === value) { if (this.switcher.getValue() === value) {
return this.switcher; return this.switcher;
} }
return this.popupView && this.popupView.getNodeByValue(value); return this.popupView && this.popupView.getNodeByValue(value);
}, },
empty: function () { empty: function () {
this.popupView && this.popupView.empty(); this.popupView && this.popupView.empty();
} },
}); });
BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND"; BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND";
BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE"; BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE";

16
src/base/combination/tab.js

@ -9,14 +9,14 @@ BI.Tab = BI.inherit(BI.Widget, {
direction: "top", // top, bottom, left, right, custom direction: "top", // top, bottom, left, right, custom
single: false, // 是不是单页面 single: false, // 是不是单页面
logic: { logic: {
dynamic: false dynamic: false,
}, },
showIndex: false, showIndex: false,
tab: false, tab: false,
cardCreator: function (v) { cardCreator: function (v) {
return BI.createWidget(); return BI.createWidget();
}, },
keepAlives: [] keepAlives: [],
}); });
}, },
@ -30,13 +30,13 @@ BI.Tab = BI.inherit(BI.Widget, {
} }
this.cardMap = {}; this.cardMap = {};
this.layout = BI.createWidget({ this.layout = BI.createWidget({
type: "bi.card" type: "bi.card",
}); });
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout),
})))); }))));
var listener = new BI.ShowListener({ var listener = new BI.ShowListener({
@ -51,7 +51,7 @@ BI.Tab = BI.inherit(BI.Widget, {
afterCardShow: function (v) { afterCardShow: function (v) {
self._deleteOtherCards(v); self._deleteOtherCards(v);
self.curr = v; self.curr = v;
} },
}); });
listener.on(BI.ShowListener.EVENT_CHANGE, function (value) { listener.on(BI.ShowListener.EVENT_CHANGE, function (value) {
self.fireEvent(BI.Tab.EVENT_CHANGE, value, self); self.fireEvent(BI.Tab.EVENT_CHANGE, value, self);
@ -112,7 +112,7 @@ BI.Tab = BI.inherit(BI.Widget, {
}, },
removeTab: function (cardname) { removeTab: function (cardname) {
var self = this, o = this.options; var self = this;
BI.any(this.cardMap, function (name, card) { BI.any(this.cardMap, function (name, card) {
if (BI.isEqual(name, (cardname + ""))) { if (BI.isEqual(name, (cardname + ""))) {
self.layout.deleteCardByName(name); self.layout.deleteCardByName(name);
@ -170,7 +170,7 @@ BI.Tab = BI.inherit(BI.Widget, {
destroy: function () { destroy: function () {
this.cardMap = {}; this.cardMap = {};
BI.Tab.superclass.destroy.apply(this, arguments); BI.Tab.superclass.destroy.apply(this, arguments);
} },
}); });
BI.Tab.EVENT_CHANGE = "EVENT_CHANGE"; BI.Tab.EVENT_CHANGE = "EVENT_CHANGE";

29
src/base/combination/tree.button.js

@ -7,7 +7,7 @@
BI.ButtonTree = BI.inherit(BI.ButtonGroup, { BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.ButtonTree.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.ButtonTree.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-button-tree" baseCls: "bi-button-tree",
}); });
}, },
@ -16,6 +16,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (!BI.isFunction(item.setSelected)) { if (!BI.isFunction(item.setSelected)) {
item.setNotSelectedValue(v); item.setNotSelectedValue(v);
return; return;
} }
if (BI.deepContains(v, item.getValue())) { if (BI.deepContains(v, item.getValue())) {
@ -31,6 +32,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (BI.isFunction(item.setEnabledValue)) { if (BI.isFunction(item.setEnabledValue)) {
item.setEnabledValue(v); item.setEnabledValue(v);
return; return;
} }
if (BI.deepContains(v, item.getValue())) { if (BI.deepContains(v, item.getValue())) {
@ -46,6 +48,7 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (!BI.isFunction(item.setSelected)) { if (!BI.isFunction(item.setSelected)) {
item.setValue(v); item.setValue(v);
return; return;
} }
if (BI.deepContains(v, item.getValue())) { if (BI.deepContains(v, item.getValue())) {
@ -61,12 +64,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) {
v = BI.concat(v, item.getNotSelectedValue()); v = BI.concat(v, item.getNotSelectedValue());
return; return;
} }
if (item.isEnabled() && item.isSelected && !item.isSelected()) { if (item.isEnabled() && item.isSelected && !item.isSelected()) {
v.push(item.getValue()); v.push(item.getValue());
} }
}); });
return v; return v;
}, },
@ -75,12 +80,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) {
v = BI.concat(v, item.getValue()); v = BI.concat(v, item.getValue());
return; return;
} }
if (item.isEnabled() && item.isSelected && item.isSelected()) { if (item.isEnabled() && item.isSelected && item.isSelected()) {
v.push(item.getValue()); v.push(item.getValue());
} }
}); });
return v; return v;
}, },
@ -89,12 +96,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) {
btns = btns.concat(item.getSelectedButtons()); btns = btns.concat(item.getSelectedButtons());
return; return;
} }
if (item.isSelected && item.isSelected()) { if (item.isSelected && item.isSelected()) {
btns.push(item); btns.push(item);
} }
}); });
return btns; return btns;
}, },
@ -103,12 +112,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) {
btns = btns.concat(item.getNotSelectedButtons()); btns = btns.concat(item.getNotSelectedButtons());
return; return;
} }
if (item.isSelected && !item.isSelected()) { if (item.isSelected && !item.isSelected()) {
btns.push(item); btns.push(item);
} }
}); });
return btns; return btns;
}, },
@ -118,12 +129,14 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { if (item.isEnabled() && !BI.isFunction(item.setSelected)) {
leaves = leaves.concat(item.getAllLeaves()); leaves = leaves.concat(item.getAllLeaves());
return; return;
} }
if (item.isEnabled()) { if (item.isEnabled()) {
leaves.push(item); leaves.push(item);
} }
}); });
return leaves; return leaves;
}, },
@ -133,9 +146,11 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
var vs = item.getValue(); var vs = item.getValue();
if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { if (item.isEnabled() && (vs === value || BI.contains(vs, value))) {
index = i; index = i;
return true; return true;
} }
}); });
return index; return index;
}, },
@ -145,14 +160,17 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
if (item.isEnabled()) { if (item.isEnabled()) {
if (item.attr("id") === id) { if (item.attr("id") === id) {
node = item; node = item;
return true; return true;
} else if (BI.isFunction(item.getNodeById)) { } else if (BI.isFunction(item.getNodeById)) {
if (node = item.getNodeById(id)) { node = item.getNodeById(id);
if (node) {
return true; return true;
} }
} }
} }
}); });
return node; return node;
}, },
@ -161,17 +179,20 @@ BI.ButtonTree = BI.inherit(BI.ButtonGroup, {
BI.any(this.buttons, function (i, item) { BI.any(this.buttons, function (i, item) {
if (item.isEnabled()) { if (item.isEnabled()) {
if (BI.isFunction(item.getNodeByValue)) { if (BI.isFunction(item.getNodeByValue)) {
if (node = item.getNodeByValue(value)) { node = item.getNodeByValue(value);
if (node) {
return true; return true;
} }
} else if (item.attr("value") === value) { } else if (item.attr("value") === value) {
node = item; node = item;
return true; return true;
} }
} }
}); });
return node; return node;
} },
}); });
BI.ButtonTree.EVENT_CHANGE = "EVENT_CHANGE"; BI.ButtonTree.EVENT_CHANGE = "EVENT_CHANGE";

6
src/base/context.js

@ -10,13 +10,13 @@ BI.Context = BI.inherit(BI.Widget, {
context: "", context: "",
watch: {}, watch: {},
el: {}, el: {},
items: [] items: [],
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.context = BI.createWidget(o.items[0] || o.el, { this.context = BI.createWidget(o.items[0] || o.el, {
element: this element: this,
}); });
this.context.on(BI.Controller.EVENT_CHANGE, function () { this.context.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -40,6 +40,6 @@ BI.Context = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this.context.populate.apply(this, arguments); this.context.populate.apply(this, arguments);
} },
}); });
BI.shortcut("bi.context", BI.Context); BI.shortcut("bi.context", BI.Context);

6
src/base/el.js

@ -9,14 +9,14 @@ BI.EL = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-el", baseCls: "bi-el",
el: {} el: {},
}); });
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
this.ele = BI.createWidget(o.el, { this.ele = BI.createWidget(o.el, {
element: this element: this,
}); });
this.ele.on(BI.Controller.EVENT_CHANGE, function () { this.ele.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -33,6 +33,6 @@ BI.EL = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this.ele.populate.apply(this, arguments); this.ele.populate.apply(this, arguments);
} },
}); });
BI.shortcut("bi.el", BI.EL); BI.shortcut("bi.el", BI.EL);

4
src/base/foundation/__test__/message.test.js

@ -4,7 +4,6 @@
* Created by windy on 2020/3/9 * Created by windy on 2020/3/9
*/ */
describe("MessageTest", function () { describe("MessageTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -24,7 +23,7 @@ describe("MessageTest", function () {
*/ */
it("toast_hand_close", function (done) { it("toast_hand_close", function (done) {
BI.Msg.toast("message", { BI.Msg.toast("message", {
autoClose: false autoClose: false,
}); });
var body = BI.Widget._renderEngine.createElement("body"); var body = BI.Widget._renderEngine.createElement("body");
expect(body.find(".bi-toast").length).to.equal(1); expect(body.find(".bi-toast").length).to.equal(1);
@ -44,4 +43,3 @@ describe("MessageTest", function () {
expect(body.find(".bi-toast").length).to.equal(1); expect(body.find(".bi-toast").length).to.equal(1);
}); });
}); });

76
src/base/foundation/message.js

@ -3,8 +3,7 @@
* 弹出提示消息框用于模拟阻塞操作通过回调函数实现 * 弹出提示消息框用于模拟阻塞操作通过回调函数实现
* @class BI.Msg * @class BI.Msg
*/ */
BI.Msg = function () { BI.Msg = ((function () {
var $mask, $pop; var $mask, $pop;
var messageShows = []; var messageShows = [];
@ -22,7 +21,7 @@ BI.Msg = function () {
// BI.Msg.prompt(title, message, value, callback, min_width); // BI.Msg.prompt(title, message, value, callback, min_width);
}, },
toast: function (message, options, context) { toast: function (message, options, context) {
BI.isString(options) && (options = { level: options }) BI.isString(options) && (options = { level: options });
options = options || {}; options = options || {};
context = context || BI.Widget._renderEngine.createElement("body"); context = context || BI.Widget._renderEngine.createElement("body");
var level = options.level || "common"; var level = options.level || "common";
@ -41,12 +40,12 @@ BI.Msg = function () {
BI.remove(toastStack, toast.element); BI.remove(toastStack, toast.element);
var _height = BI.SIZE_CONSANTS.TOAST_TOP; var _height = BI.SIZE_CONSANTS.TOAST_TOP;
BI.each(toastStack, function (i, element) { BI.each(toastStack, function (i, element) {
element.css({"top": _height}); element.css({ "top": _height });
_height += element.outerHeight() + 10; _height += element.outerHeight() + 10;
}); });
callback(); callback();
} },
}] }],
}); });
var height = BI.SIZE_CONSANTS.TOAST_TOP; var height = BI.SIZE_CONSANTS.TOAST_TOP;
BI.each(toastStack, function (i, element) { BI.each(toastStack, function (i, element) {
@ -58,20 +57,21 @@ BI.Msg = function () {
items: [{ items: [{
el: toast, el: toast,
left: "50%", left: "50%",
top: height top: height,
}] }],
}); });
toastStack.push(toast.element); toastStack.push(toast.element);
toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); toast.element.css({ "margin-left": -1 * toast.element.outerWidth() / 2 });
toast.element.removeClass("bi-message-leave").addClass("bi-message-enter"); toast.element.removeClass("bi-message-leave").addClass("bi-message-enter");
autoClose && BI.delay(function () { autoClose && BI.delay(function () {
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); toast.element.removeClass("bi-message-enter").addClass("bi-message-leave");
toast.destroy(); toast.destroy?.();
}, 5000); }, 5000);
return function () { return function () {
toast.element.removeClass("bi-message-enter").addClass("bi-message-leave"); toast.element.removeClass("bi-message-enter").addClass("bi-message-leave");
toast.destroy(); toast.destroy?.();
}; };
}, },
_show: function (hasCancel, title, message, callback) { _show: function (hasCancel, title, message, callback) {
@ -82,7 +82,7 @@ BI.Msg = function () {
left: 0, left: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
opacity: 0.5 opacity: 0.5,
}).appendTo("body")); }).appendTo("body"));
$pop = BI.Widget._renderEngine.createElement("<div class=\"bi-message-depend\">").css({ $pop = BI.Widget._renderEngine.createElement("<div class=\"bi-message-depend\">").css({
position: "absolute", position: "absolute",
@ -90,16 +90,16 @@ BI.Msg = function () {
top: 0, top: 0,
left: 0, left: 0,
right: 0, right: 0,
bottom: 0 bottom: 0,
}).appendTo("body"); }).appendTo("body");
var close = function () { function close () {
messageShows[messageShows.length - 1].destroy(); messageShows[messageShows.length - 1].destroy();
messageShows.pop(); messageShows.pop();
if (messageShows.length === 0) { if (messageShows.length === 0) {
$mask.remove(); $mask.remove();
$mask = null; $mask = null;
} }
}; }
var controlItems = []; var controlItems = [];
if (hasCancel === true) { if (hasCancel === true) {
controlItems.push({ controlItems.push({
@ -112,8 +112,8 @@ BI.Msg = function () {
if (BI.isFunction(callback)) { if (BI.isFunction(callback)) {
callback.apply(null, [false]); callback.apply(null, [false]);
} }
} },
} },
}); });
} }
controlItems.push({ controlItems.push({
@ -125,8 +125,8 @@ BI.Msg = function () {
if (BI.isFunction(callback)) { if (BI.isFunction(callback)) {
callback.apply(null, [true]); callback.apply(null, [true]);
} }
} },
} },
}); });
var conf = { var conf = {
element: $pop, element: $pop,
@ -135,7 +135,7 @@ BI.Msg = function () {
{ {
type: "bi.border", type: "bi.border",
attributes: { attributes: {
tabIndex: 1 tabIndex: 1,
}, },
mounted: function () { mounted: function () {
this.element.keyup(function (e) { this.element.keyup(function (e) {
@ -173,8 +173,8 @@ BI.Msg = function () {
text: title || BI.i18nText("BI-Basic_Prompt"), text: title || BI.i18nText("BI-Basic_Prompt"),
textAlign: "left", textAlign: "left",
hgap: 20, hgap: 20,
height: 40 height: 40,
} },
}, },
east: { east: {
el: { el: {
@ -186,13 +186,13 @@ BI.Msg = function () {
if (BI.isFunction(callback)) { if (BI.isFunction(callback)) {
callback.apply(null, [false]); callback.apply(null, [false]);
} }
} },
}, },
width: 56 width: 56,
} },
} },
}, },
height: 40 height: 40,
}, },
center: { center: {
el: BI.isPlainObject(message) ? message : { el: BI.isPlainObject(message) ? message : {
@ -200,8 +200,8 @@ BI.Msg = function () {
vgap: 10, vgap: 10,
hgap: 20, hgap: 20,
whiteSpace: "normal", whiteSpace: "normal",
text: message text: message,
} },
}, },
south: { south: {
el: { el: {
@ -210,25 +210,25 @@ BI.Msg = function () {
el: { el: {
type: "bi.right_vertical_adapt", type: "bi.right_vertical_adapt",
lgap: 10, lgap: 10,
items: controlItems items: controlItems,
}, },
top: 0, top: 0,
left: 20, left: 20,
right: 20, right: 20,
bottom: 0 bottom: 0,
}] }],
}, },
height: 44 height: 44,
} },
}, },
width: 450, width: 450,
height: 200 height: 200,
} }
] ],
}; };
messageShows[messageShows.length] = BI.createWidget(conf); messageShows[messageShows.length] = BI.createWidget(conf);
} },
}; };
}(); })());

7
src/base/grid/__test__/grid.test.js

@ -4,7 +4,6 @@
* Created by windy on 2020/3/20 * Created by windy on 2020/3/20
*/ */
describe("GridTest", function () { describe("GridTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -16,7 +15,7 @@ describe("GridTest", function () {
for (var j = 0; j < columnCount; j++) { for (var j = 0; j < columnCount; j++) {
items[i][j] = { items[i][j] = {
type: "bi.label", type: "bi.label",
text: i + "-" + j text: i + "-" + j,
}; };
} }
} }
@ -33,9 +32,9 @@ describe("GridTest", function () {
}, },
columnWidthGetter: function () { columnWidthGetter: function () {
return 100; return 100;
} },
}); });
// TODO 性能展示类控件,不知道要测啥,标记一下 // TODO 性能展示类控件,不知道要测啥,标记一下
grid.destroy(); grid.destroy();
}); });
}); });

28
src/base/grid/grid.js

@ -27,7 +27,7 @@ BI.GridView = BI.inherit(BI.Widget, {
items: [], items: [],
itemFormatter: function (item, row, col) { itemFormatter: function (item, row, col) {
return item; return item;
} },
}); });
}, },
@ -41,7 +41,7 @@ BI.GridView = BI.inherit(BI.Widget, {
self._scrollLock = false; self._scrollLock = false;
}, 1000 / 60); }, 1000 / 60);
this.container = BI._lazyCreateWidget({ this.container = BI._lazyCreateWidget({
type: "bi.absolute" type: "bi.absolute",
}); });
this.element.scroll(function () { this.element.scroll(function () {
if (self._scrollLock === true) { if (self._scrollLock === true) {
@ -52,7 +52,7 @@ BI.GridView = BI.inherit(BI.Widget, {
self._calculateChildrenToRender(); self._calculateChildrenToRender();
self.fireEvent(BI.GridView.EVENT_SCROLL, { self.fireEvent(BI.GridView.EVENT_SCROLL, {
scrollLeft: o.scrollLeft, scrollLeft: o.scrollLeft,
scrollTop: o.scrollTop scrollTop: o.scrollTop,
}); });
}); });
// 兼容一下 // 兼容一下
@ -61,7 +61,7 @@ BI.GridView = BI.inherit(BI.Widget, {
if (o.overflowY === false) { if (o.overflowY === false) {
scrollable = false; scrollable = false;
} else { } else {
scrollable = "y" scrollable = "y";
} }
} else { } else {
if (o.overflowY === false) { if (o.overflowY === false) {
@ -74,7 +74,7 @@ BI.GridView = BI.inherit(BI.Widget, {
scrollable: scrollable, scrollable: scrollable,
scrolly: scrolly, scrolly: scrolly,
scrollx: scrollx, scrollx: scrollx,
items: [this.container] items: [this.container],
}); });
o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { o.items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) {
self.populate(newValue); self.populate(newValue);
@ -115,7 +115,7 @@ BI.GridView = BI.inherit(BI.Widget, {
_getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) { _getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) {
return { return {
overscanStartIndex: Math.max(0, startIndex - overscanCellsCount), overscanStartIndex: Math.max(0, startIndex - overscanCellsCount),
overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount) overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount),
}; };
}, },
@ -197,20 +197,20 @@ BI.GridView = BI.inherit(BI.Widget, {
child = BI._lazyCreateWidget(BI.extend({ child = BI._lazyCreateWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: columnDatum.size, width: columnDatum.size,
height: rowDatum.size height: rowDatum.size,
}, item, { }, item, {
cls: (item.cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""), cls: (item.cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""),
_rowIndex: rowIndex, _rowIndex: rowIndex,
_columnIndex: columnIndex, _columnIndex: columnIndex,
_left: columnDatum.offset + horizontalOffsetAdjustment, _left: columnDatum.offset + horizontalOffsetAdjustment,
_top: rowDatum.offset + verticalOffsetAdjustment _top: rowDatum.offset + verticalOffsetAdjustment,
}), this); }), this);
renderedCells.push({ renderedCells.push({
el: child, el: child,
left: columnDatum.offset + horizontalOffsetAdjustment, left: columnDatum.offset + horizontalOffsetAdjustment,
top: rowDatum.offset + verticalOffsetAdjustment, top: rowDatum.offset + verticalOffsetAdjustment,
_left: columnDatum.offset + horizontalOffsetAdjustment, _left: columnDatum.offset + horizontalOffsetAdjustment,
_top: rowDatum.offset + verticalOffsetAdjustment _top: rowDatum.offset + verticalOffsetAdjustment,
// _width: columnDatum.size, // _width: columnDatum.size,
// _height: rowDatum.size // _height: rowDatum.size
}); });
@ -258,7 +258,7 @@ BI.GridView = BI.inherit(BI.Widget, {
this.container.attr("items", renderedCells); this.container.attr("items", renderedCells);
this.renderedCells = renderedCells; this.renderedCells = renderedCells;
this.renderedKeys = renderedKeys; this.renderedKeys = renderedKeys;
this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY}; this.renderRange = { minX: minX, minY: minY, maxX: maxX, maxY: maxY };
} }
}, },
@ -279,7 +279,7 @@ BI.GridView = BI.inherit(BI.Widget, {
}, },
_populate: function (items) { _populate: function (items) {
var self = this, o = this.options; var o = this.options;
this._reRange(); this._reRange();
if (items && items !== this.options.items) { if (items && items !== this.options.items) {
this.options.items = items; this.options.items = items;
@ -333,7 +333,7 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.options.overflowX !== !!b) { if (this.options.overflowX !== !!b) {
this.options.overflowX = !!b; this.options.overflowX = !!b;
BI.nextTick(function () { BI.nextTick(function () {
self.element.css({overflowX: b ? "auto" : "hidden"}); self.element.css({ overflowX: b ? "auto" : "hidden" });
}); });
} }
}, },
@ -343,7 +343,7 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.options.overflowY !== !!b) { if (this.options.overflowY !== !!b) {
this.options.overflowY = !!b; this.options.overflowY = !!b;
BI.nextTick(function () { BI.nextTick(function () {
self.element.css({overflowY: b ? "auto" : "hidden"}); self.element.css({ overflowY: b ? "auto" : "hidden" });
}); });
} }
}, },
@ -398,7 +398,7 @@ BI.GridView = BI.inherit(BI.Widget, {
this.restore(); this.restore();
} }
this._populate(items); this._populate(items);
} },
}); });
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
BI.shortcut("bi.grid_view", BI.GridView); BI.shortcut("bi.grid_view", BI.GridView);

9
src/base/layer/__test__/layer.popover.test.js

@ -5,7 +5,6 @@
*/ */
describe("PopoverTest", function () { describe("PopoverTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -17,12 +16,12 @@ describe("PopoverTest", function () {
size: "normal", size: "normal",
header: { header: {
type: "bi.label", type: "bi.label",
text: "这个是header" text: "这个是header",
}, },
body: { body: {
type: "bi.label", type: "bi.label",
text: "这个是body" text: "这个是body",
} },
}).open(id); }).open(id);
BI.delay(function () { BI.delay(function () {
expect(BI.Widget._renderEngine.createElement("body").find(".bi-popup-view .bi-z-index-mask").length).to.equal(1); expect(BI.Widget._renderEngine.createElement("body").find(".bi-popup-view .bi-z-index-mask").length).to.equal(1);
@ -30,4 +29,4 @@ describe("PopoverTest", function () {
done(); done();
}, 100); }, 100);
}); });
}); });

72
src/base/layer/layer.drawer.js

@ -7,7 +7,7 @@ BI.Drawer = BI.inherit(BI.Widget, {
SIZE: { SIZE: {
SMALL: "small", SMALL: "small",
NORMAL: "normal", NORMAL: "normal",
BIG: "big" BIG: "big",
}, },
props: { props: {
baseCls: "bi-drawer bi-card", baseCls: "bi-drawer bi-card",
@ -19,7 +19,7 @@ BI.Drawer = BI.inherit(BI.Widget, {
closable: true, // BI-40839 是否显示右上角的关闭按钮 closable: true, // BI-40839 是否显示右上角的关闭按钮
bodyHgap: 20, bodyHgap: 20,
bodyTgap: 10, bodyTgap: 10,
bodyBgap: 10 bodyBgap: 10,
}, },
render: function () { render: function () {
@ -33,20 +33,20 @@ BI.Drawer = BI.inherit(BI.Widget, {
type: "bi.absolute", type: "bi.absolute",
items: [{ items: [{
el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, { el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, {
extraCls: "bi-font-bold" extraCls: "bi-font-bold",
}) : { }) : {
type: "bi.label", type: "bi.label",
cls: "bi-font-bold", cls: "bi-font-bold",
height: o.headerHeight, height: o.headerHeight,
text: o.header, text: o.header,
title: o.header, title: o.header,
textAlign: "left" textAlign: "left",
}, },
left: 20, left: 20,
top: 0, top: 0,
right: 0, right: 0,
bottom: 0 bottom: 0,
}] }],
}, { }, {
el: o.closable ? { el: o.closable ? {
type: "bi.icon_button", type: "bi.icon_button",
@ -54,15 +54,15 @@ BI.Drawer = BI.inherit(BI.Widget, {
height: o.headerHeight, height: o.headerHeight,
handler: function () { handler: function () {
self.close(); self.close();
} },
} : { } : {
type: "bi.layout" type: "bi.layout",
}, },
width: 56 width: 56,
}], }],
height: o.headerHeight height: o.headerHeight,
}, },
height: o.headerHeight height: o.headerHeight,
}, { }, {
el: { el: {
type: "bi.vertical", type: "bi.vertical",
@ -72,17 +72,17 @@ BI.Drawer = BI.inherit(BI.Widget, {
self.body = this; self.body = this;
}, },
items: [{ items: [{
el: o.body el: o.body,
}] }],
}, },
hgap: o.bodyHgap, hgap: o.bodyHgap,
tgap: o.bodyTgap, tgap: o.bodyTgap,
bgap: o.bodyBgap bgap: o.bodyBgap,
}]; }];
return BI.extend({ return BI.extend({
type: "bi.vtape", type: "bi.vtape",
items: items items: items,
}, this._getSuitableSize()); }, this._getSuitableSize());
}, },
@ -103,12 +103,12 @@ BI.Drawer = BI.inherit(BI.Widget, {
} }
if (o.placement === "top" || o.placement === "bottom") { if (o.placement === "top" || o.placement === "bottom") {
return { return {
height: o.height || size height: o.height || size,
}; };
} }
if (o.placement === "left" || o.placement === "right") { if (o.placement === "left" || o.placement === "right") {
return { return {
width: o.width || size width: o.width || size,
}; };
} }
}, },
@ -120,30 +120,32 @@ BI.Drawer = BI.inherit(BI.Widget, {
self.element.css({ self.element.css({
top: 0, top: 0,
left: "100%", left: "100%",
bottom: 0 bottom: 0,
}); });
break; break;
case "left": case "left":
self.element.css({ self.element.css({
top: 0, top: 0,
right: "100%", right: "100%",
bottom: 0 bottom: 0,
}); });
break; break;
case "top": case "top":
self.element.css({ self.element.css({
left: 0, left: 0,
right: 0, right: 0,
bottom: "100%" bottom: "100%",
}); });
break; break;
case "bottom": case "bottom":
self.element.css({ self.element.css({
left: 0, left: 0,
right: 0, right: 0,
top: "100%" top: "100%",
}); });
break; break;
default:
break;
} }
}, },
@ -154,24 +156,26 @@ BI.Drawer = BI.inherit(BI.Widget, {
switch (o.placement) { switch (o.placement) {
case "right": case "right":
self.element.css({ self.element.css({
transform: "translateX(-" + size.width + "px)" left: "calc(100% - " + size.width + "px)",
}); });
break; break;
case "left": case "left":
self.element.css({ self.element.css({
transform: "translateX(" + size.width + "px)" right: "calc(100% - " + size.width + "px)",
}); });
break; break;
case "top": case "top":
self.element.css({ self.element.css({
transform: "translateY(" + size.height + "px)" bottom: "calc(100% - " + size.height + "px)",
}); });
break; break;
case "bottom": case "bottom":
self.element.css({ self.element.css({
transform: "translateY(-" + size.height + "px)" top: "calc(100% - " + size.height + "px)",
}); });
break; break;
default:
break;
} }
callback && callback(); callback && callback();
}); });
@ -182,17 +186,27 @@ BI.Drawer = BI.inherit(BI.Widget, {
requestAnimationFrame(function () { requestAnimationFrame(function () {
switch (o.placement) { switch (o.placement) {
case "right": case "right":
self.element.css({
left: "100%",
});
break;
case "left": case "left":
self.element.css({ self.element.css({
transform: "translateX(0px)" right: "100%",
}); });
break; break;
case "top": case "top":
self.element.css({
bottom: "100%",
});
break;
case "bottom": case "bottom":
self.element.css({ self.element.css({
transform: "translateY(0px)" top: "100%",
}); });
break; break;
default:
break;
} }
setTimeout(callback, 300); setTimeout(callback, 300);
}); });
@ -213,11 +227,11 @@ BI.Drawer = BI.inherit(BI.Widget, {
}, },
setZindex: function (zindex) { setZindex: function (zindex) {
this.element.css({"z-index": zindex}); this.element.css({ "z-index": zindex });
}, },
destroyed: function () { destroyed: function () {
} },
}); });
BI.shortcut("bi.drawer", BI.Drawer); BI.shortcut("bi.drawer", BI.Drawer);

80
src/base/layer/layer.popover.js

@ -8,9 +8,9 @@ BI.Popover = BI.inherit(BI.Widget, {
SIZE: { SIZE: {
SMALL: "small", SMALL: "small",
NORMAL: "normal", NORMAL: "normal",
BIG: "big" BIG: "big",
}, },
MAX_HEIGHT: 600 MAX_HEIGHT: 600,
}, },
props: function () { props: function () {
@ -18,7 +18,7 @@ BI.Popover = BI.inherit(BI.Widget, {
baseCls: "bi-popover bi-card bi-border-radius", baseCls: "bi-popover bi-card bi-border-radius",
size: "normal", // small, normal, big size: "normal", // small, normal, big
logic: { logic: {
dynamic: false dynamic: false,
}, },
header: null, header: null,
headerHeight: 40, headerHeight: 40,
@ -27,7 +27,7 @@ BI.Popover = BI.inherit(BI.Widget, {
footerHeight: 44, footerHeight: 44,
closable: true, // BI-40839 是否显示右上角的关闭按钮 closable: true, // BI-40839 是否显示右上角的关闭按钮
bodyHgap: BI.SIZE_CONSANTS.H_GAP_SIZE, bodyHgap: BI.SIZE_CONSANTS.H_GAP_SIZE,
bodyTgap: BI.SIZE_CONSANTS.V_GAP_SIZE bodyTgap: BI.SIZE_CONSANTS.V_GAP_SIZE,
}; };
}, },
@ -45,11 +45,11 @@ BI.Popover = BI.inherit(BI.Widget, {
self.startY += deltaY; self.startY += deltaY;
self.element.css({ self.element.css({
left: BI.clamp(self.startX, 0, W - self.element.width()) + "px", left: BI.clamp(self.startX, 0, W - self.element.width()) + "px",
top: BI.clamp(self.startY, 0, H - self.element.height()) + "px" top: BI.clamp(self.startY, 0, H - self.element.height()) + "px",
}); });
// BI-12134 没有什么特别好的方法 // BI-12134 没有什么特别好的方法
BI.Resizers._resize({ BI.Resizers._resize({
target: self.element[0] target: self.element[0],
}); });
}, function () { }, function () {
self.tracker.releaseMouseMoves(); self.tracker.releaseMouseMoves();
@ -66,21 +66,21 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
items: [{ items: [{
el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, { el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, {
extraCls: "bi-font-bold" extraCls: "bi-font-bold",
}) : { }) : {
type: "bi.label", type: "bi.label",
cls: "bi-font-bold", cls: "bi-font-bold",
height: o.headerHeight, height: o.headerHeight,
text: o.header, text: o.header,
title: o.header, title: o.header,
textAlign: "left" textAlign: "left",
}, },
top: 0, top: 0,
bottom: 0, bottom: 0,
left: BI.SIZE_CONSANTS.H_GAP_SIZE, left: BI.SIZE_CONSANTS.H_GAP_SIZE,
right: o.closable ? 0 : BI.SIZE_CONSANTS.H_GAP_SIZE right: o.closable ? 0 : BI.SIZE_CONSANTS.H_GAP_SIZE,
}] }],
} },
}, o.closable ? { }, o.closable ? {
el: { el: {
type: "bi.icon_button", type: "bi.icon_button",
@ -88,13 +88,13 @@ BI.Popover = BI.inherit(BI.Widget, {
height: o.headerHeight, height: o.headerHeight,
handler: function () { handler: function () {
self.close(); self.close();
} },
}, },
width: 56 width: 56,
} : null], } : null],
height: o.headerHeight height: o.headerHeight,
}, },
height: o.headerHeight height: o.headerHeight,
}, o.logic.dynamic ? { }, o.logic.dynamic ? {
el: { el: {
type: "bi.vertical", type: "bi.vertical",
@ -105,14 +105,14 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
css: { css: {
"max-height": this._getSuitableBodyHeight(c.MAX_HEIGHT - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap), "max-height": this._getSuitableBodyHeight(c.MAX_HEIGHT - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap),
"min-height": this._getSuitableBodyHeight(size.height - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap) "min-height": this._getSuitableBodyHeight(size.height - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap),
}, },
items: [{ items: [{
el: o.body el: o.body,
}], }],
hgap: o.bodyHgap, hgap: o.bodyHgap,
tgap: o.bodyTgap tgap: o.bodyTgap,
} },
} : { } : {
el: { el: {
type: "bi.absolute", type: "bi.absolute",
@ -121,9 +121,9 @@ BI.Popover = BI.inherit(BI.Widget, {
left: o.bodyHgap, left: o.bodyHgap,
top: o.bodyTgap, top: o.bodyTgap,
right: o.bodyHgap, right: o.bodyHgap,
bottom: 0 bottom: 0,
}] }],
} },
}]; }];
if (o.footer) { if (o.footer) {
items.push({ items.push({
@ -134,41 +134,39 @@ BI.Popover = BI.inherit(BI.Widget, {
left: BI.SIZE_CONSANTS.H_GAP_SIZE, left: BI.SIZE_CONSANTS.H_GAP_SIZE,
top: 0, top: 0,
right: BI.SIZE_CONSANTS.H_GAP_SIZE, right: BI.SIZE_CONSANTS.H_GAP_SIZE,
bottom: 0 bottom: 0,
}], }],
height: o.footerHeight height: o.footerHeight,
}, },
height: o.footerHeight height: o.footerHeight,
}); });
} }
return BI.extend({ return BI.extend({
items: items, items: items,
width: this._getSuitableWidth(size.width) width: this._getSuitableWidth(size.width),
}, o.logic.dynamic ? { }, o.logic.dynamic ? {
type: "bi.vertical", type: "bi.vertical",
scrolly: false scrolly: false,
} : { } : {
type: "bi.vtape", type: "bi.vtape",
height: this._getSuitableHeight(size.height) height: this._getSuitableHeight(size.height),
}); });
}, },
// mounted之后绑定事件 // mounted之后绑定事件
mounted: function () { mounted: function () {
var self = this; var self = this;
var o = this.options;
this.dragger.element.mousedown(function (e) { this.dragger.element.mousedown(function (e) {
var pos = self.element.offset(); self.startX = self.element[0].offsetLeft;
self.startX = pos.left; self.startY = self.element[0].offsetTop;
self.startY = pos.top;
self.tracker.captureMouseMoves(e); self.tracker.captureMouseMoves(e);
}); });
}, },
_getSuitableBodyHeight: function (height) { _getSuitableBodyHeight: function (height) {
var o = this.options; var o = this.options;
var c = this._constant;
return BI.clamp(height, 0, BI.Widget._renderEngine.createElement("body")[0].clientHeight - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap); return BI.clamp(height, 0, BI.Widget._renderEngine.createElement("body")[0].clientHeight - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap);
}, },
@ -205,7 +203,7 @@ BI.Popover = BI.inherit(BI.Widget, {
return { return {
width: o.width || size.width, width: o.width || size.width,
height: o.height || size.height, height: o.height || size.height,
type: size.type || "default" type: size.type || "default",
}; };
}, },
@ -224,11 +222,11 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
setZindex: function (zindex) { setZindex: function (zindex) {
this.element.css({"z-index": zindex}); this.element.css({ "z-index": zindex });
}, },
destroyed: function () { destroyed: function () {
} },
}); });
BI.shortcut("bi.popover", BI.Popover); BI.shortcut("bi.popover", BI.Popover);
@ -236,7 +234,7 @@ BI.shortcut("bi.popover", BI.Popover);
BI.BarPopover = BI.inherit(BI.Popover, { BI.BarPopover = BI.inherit(BI.Popover, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), {
btns: [BI.i18nText("BI-Basic_OK"), BI.i18nText("BI-Basic_Cancel")] btns: [BI.i18nText("BI-Basic_OK"), BI.i18nText("BI-Basic_Cancel")],
}); });
}, },
@ -254,7 +252,7 @@ BI.BarPopover = BI.inherit(BI.Popover, {
handler: function (v) { handler: function (v) {
self.fireEvent(BI.Popover.EVENT_CANCEL, v); self.fireEvent(BI.Popover.EVENT_CANCEL, v);
self.close(v); self.close(v);
} },
}, { }, {
type: "bi.button", type: "bi.button",
text: this.options.btns[0], text: this.options.btns[0],
@ -263,10 +261,10 @@ BI.BarPopover = BI.inherit(BI.Popover, {
handler: function (v) { handler: function (v) {
self.fireEvent(BI.Popover.EVENT_CONFIRM, v); self.fireEvent(BI.Popover.EVENT_CONFIRM, v);
self.close(v); self.close(v);
} },
}] }],
}); });
} },
}); });
BI.shortcut("bi.bar_popover", BI.BarPopover); BI.shortcut("bi.bar_popover", BI.BarPopover);

100
src/base/layer/layer.popup.js

@ -5,7 +5,7 @@
*/ */
BI.PopupView = BI.inherit(BI.Widget, { BI.PopupView = BI.inherit(BI.Widget, {
_const: { _const: {
TRIANGLE_LENGTH: 12 TRIANGLE_LENGTH: 12,
}, },
_defaultConfig: function (props) { _defaultConfig: function (props) {
return BI.extend(BI.PopupView.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.PopupView.superclass._defaultConfig.apply(this, arguments), {
@ -29,7 +29,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
stopEvent: false, // 是否停止mousedown、mouseup事件 stopEvent: false, // 是否停止mousedown、mouseup事件
stopPropagation: false, // 是否停止mousedown、mouseup向上冒泡 stopPropagation: false, // 是否停止mousedown、mouseup向上冒泡
logic: { logic: {
dynamic: true dynamic: true,
}, },
tool: false, // 自定义工具栏 tool: false, // 自定义工具栏
@ -42,30 +42,32 @@ BI.PopupView = BI.inherit(BI.Widget, {
chooseType: 0, chooseType: 0,
behaviors: {}, behaviors: {},
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}] }],
} },
}); });
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
var fn = function (e) { function fn (e) {
e.stopPropagation(); e.stopPropagation();
}, stop = function (e) { }
function stop (e) {
e.stopEvent(); e.stopEvent();
return false; return false;
}; }
this.element.css({ this.element.css({
"z-index": BI.zIndex_popup, "z-index": BI.zIndex_popup,
"min-width": BI.isNumeric(o.minWidth) ? (o.minWidth / BI.pixRatio + BI.pixUnit) : o.minWidth, "min-width": BI.isNumeric(o.minWidth) ? (o.minWidth / BI.pixRatio + BI.pixUnit) : o.minWidth,
"max-width": BI.isNumeric(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth "max-width": BI.isNumeric(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth,
}).bind({click: fn}); }).bind({ click: fn });
this.element.bind("mousewheel", fn); this.element.bind("mousewheel", fn);
o.stopPropagation && this.element.bind({mousedown: fn, mouseup: fn, mouseover: fn}); o.stopPropagation && this.element.bind({ mousedown: fn, mouseup: fn, mouseover: fn });
o.stopEvent && this.element.bind({mousedown: stop, mouseup: stop, mouseover: stop}); o.stopEvent && this.element.bind({ mousedown: stop, mouseup: stop, mouseover: stop });
this.tool = this._createTool(); this.tool = this._createTool();
this.tab = this._createTab(); this.tab = this._createTab();
this.view = this._createView(); this.view = this._createView();
@ -79,7 +81,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
}); });
BI.createWidget(BI.extend({ BI.createWidget(BI.extend({
element: this element: this,
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
scrolly: false, scrolly: false,
lgap: o.lgap, lgap: o.lgap,
@ -89,11 +91,11 @@ BI.PopupView = BI.inherit(BI.Widget, {
vgap: o.vgap, vgap: o.vgap,
hgap: o.hgap, hgap: o.hgap,
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, BI.extend({ items: BI.LogicFactory.createLogicItemsByDirection(o.direction, BI.extend({
cls: "list-view-outer bi-card list-view-shadow" + (o.primary ? " bi-primary" : "") cls: "list-view-outer bi-card list-view-shadow" + (o.primary ? " bi-primary" : ""),
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tool, this.tab, this.view, this.toolbar) items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tool, this.tab, this.view, this.toolbar),
}))) })))
) ),
})))); }))));
if (o.showArrow) { if (o.showArrow) {
this.arrow = BI.createWidget({ this.arrow = BI.createWidget({
@ -101,19 +103,19 @@ BI.PopupView = BI.inherit(BI.Widget, {
cls: "bi-bubble-arrow", cls: "bi-bubble-arrow",
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
cls: "bubble-arrow" cls: "bubble-arrow",
}] }],
}); });
this.arrowWrapper = BI.createWidget({ this.arrowWrapper = BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
cls: "bi-bubble-arrow-wrapper", cls: "bi-bubble-arrow-wrapper",
items: [{ items: [{
el: this.arrow, el: this.arrow,
}] }],
}); });
// 因为三角符号的原因位置变大了,需要占位 // 因为三角符号的原因位置变大了,需要占位
this.placeholder = BI.createWidget({ this.placeholder = BI.createWidget({
type: "bi.layout" type: "bi.layout",
}); });
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",
@ -123,22 +125,23 @@ BI.PopupView = BI.inherit(BI.Widget, {
left: 0, left: 0,
top: 0, top: 0,
}, { }, {
el: this.placeholder el: this.placeholder,
}] }],
}); });
} }
}, },
_createView: function () { _createView: function () {
var o = this.options; var o = this.options;
this.button_group = BI.createWidget(o.el, {type: "bi.button_group", value: o.value}); this.button_group = BI.createWidget(o.el, { type: "bi.button_group", value: o.value });
this.button_group.element.css({ this.button_group.element.css({
"min-height": BI.isNumeric(o.minHeight) ? (o.minHeight / BI.pixRatio + BI.pixUnit) : o.minHeight, "min-height": BI.isNumeric(o.minHeight) ? (o.minHeight / BI.pixRatio + BI.pixUnit) : o.minHeight,
"padding-top": o.innerVgap / BI.pixRatio + BI.pixUnit, "padding-top": o.innerVgap / BI.pixRatio + BI.pixUnit,
"padding-bottom": o.innerVgap / BI.pixRatio + BI.pixUnit, "padding-bottom": o.innerVgap / BI.pixRatio + BI.pixUnit,
"padding-left": o.innerHgap / BI.pixRatio + BI.pixUnit, "padding-left": o.innerHgap / BI.pixRatio + BI.pixUnit,
"padding-right": o.innerHgap / BI.pixRatio + BI.pixUnit "padding-right": o.innerHgap / BI.pixRatio + BI.pixUnit,
}); });
return this.button_group; return this.button_group;
}, },
@ -147,6 +150,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
if (false === o.tool) { if (false === o.tool) {
return; return;
} }
return BI.createWidget(o.tool); return BI.createWidget(o.tool);
}, },
@ -155,12 +159,13 @@ BI.PopupView = BI.inherit(BI.Widget, {
if (o.tabs.length === 0) { if (o.tabs.length === 0) {
return; return;
} }
return BI.createWidget({ return BI.createWidget({
type: "bi.center", type: "bi.center",
cls: "list-view-tab", cls: "list-view-tab",
height: 25, height: 25,
items: o.tabs, items: o.tabs,
value: o.value value: o.value,
}); });
}, },
@ -177,8 +182,8 @@ BI.PopupView = BI.inherit(BI.Widget, {
items: BI.createItems(o.buttons, { items: BI.createItems(o.buttons, {
once: false, once: false,
shadow: true, shadow: true,
isShadowShowingOnSelected: true isShadowShowingOnSelected: true,
}) }),
}); });
}, },
@ -212,7 +217,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
direction = "bottom"; direction = "bottom";
style = { style = {
// 5表示留出一定的空间 // 5表示留出一定的空间
left: BI.clamp(((middle ? popupWidth : position.width) - adjustXOffset) / 2 - 8, minLeft, maxLeft) left: BI.clamp(((middle ? popupWidth : position.width) - adjustXOffset) / 2 - 8, minLeft, maxLeft),
}; };
wrapperStyle = { wrapperStyle = {
top: o.tgap + o.vgap, top: o.tgap + o.vgap,
@ -225,13 +230,13 @@ BI.PopupView = BI.inherit(BI.Widget, {
right: 0, right: 0,
height: this._const.TRIANGLE_LENGTH, height: this._const.TRIANGLE_LENGTH,
top: -this._const.TRIANGLE_LENGTH, top: -this._const.TRIANGLE_LENGTH,
bottom: "" bottom: "",
}; };
break; break;
case "bottom,left": case "bottom,left":
direction = "bottom"; direction = "bottom";
style = { style = {
right: BI.clamp(((middle ? popupWidth : position.width) + adjustXOffset) / 2 - 8, minRight, maxRight) right: BI.clamp(((middle ? popupWidth : position.width) + adjustXOffset) / 2 - 8, minRight, maxRight),
}; };
wrapperStyle = { wrapperStyle = {
top: o.bgap + o.vgap, top: o.bgap + o.vgap,
@ -244,14 +249,14 @@ BI.PopupView = BI.inherit(BI.Widget, {
right: 0, right: 0,
height: this._const.TRIANGLE_LENGTH, height: this._const.TRIANGLE_LENGTH,
top: -this._const.TRIANGLE_LENGTH, top: -this._const.TRIANGLE_LENGTH,
bottom: "" bottom: "",
}; };
break; break;
case "top": case "top":
case "top,right": case "top,right":
direction = "top"; direction = "top";
style = { style = {
left: BI.clamp(((middle ? popupWidth : position.width) - adjustXOffset) / 2 - 8, minLeft, maxLeft) left: BI.clamp(((middle ? popupWidth : position.width) - adjustXOffset) / 2 - 8, minLeft, maxLeft),
}; };
wrapperStyle = { wrapperStyle = {
bottom: o.bgap + o.vgap, bottom: o.bgap + o.vgap,
@ -270,7 +275,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
case "top,left": case "top,left":
direction = "top"; direction = "top";
style = { style = {
right: BI.clamp(((middle ? popupWidth : position.width) + adjustXOffset) / 2 - 8, minRight, maxRight) right: BI.clamp(((middle ? popupWidth : position.width) + adjustXOffset) / 2 - 8, minRight, maxRight),
}; };
wrapperStyle = { wrapperStyle = {
bottom: o.bgap + o.vgap, bottom: o.bgap + o.vgap,
@ -290,7 +295,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
case "left,bottom": case "left,bottom":
direction = "left"; direction = "left";
style = { style = {
top: BI.clamp(((middle ? popupHeight : position.height) - adjustYOffset) / 2 - 8, minTop, maxTop) top: BI.clamp(((middle ? popupHeight : position.height) - adjustYOffset) / 2 - 8, minTop, maxTop),
}; };
wrapperStyle = { wrapperStyle = {
right: o.rgap + o.hgap, right: o.rgap + o.hgap,
@ -303,13 +308,13 @@ BI.PopupView = BI.inherit(BI.Widget, {
bottom: 0, bottom: 0,
width: this._const.TRIANGLE_LENGTH, width: this._const.TRIANGLE_LENGTH,
right: -this._const.TRIANGLE_LENGTH, right: -this._const.TRIANGLE_LENGTH,
left: "" left: "",
}; };
break; break;
case "left,top": case "left,top":
direction = "left"; direction = "left";
style = { style = {
bottom: BI.clamp(((middle ? popupHeight : position.height) + adjustYOffset) / 2 - 8, minBottom, maxBottom) bottom: BI.clamp(((middle ? popupHeight : position.height) + adjustYOffset) / 2 - 8, minBottom, maxBottom),
}; };
wrapperStyle = { wrapperStyle = {
right: o.rgap + o.hgap, right: o.rgap + o.hgap,
@ -322,14 +327,14 @@ BI.PopupView = BI.inherit(BI.Widget, {
bottom: 0, bottom: 0,
width: this._const.TRIANGLE_LENGTH, width: this._const.TRIANGLE_LENGTH,
right: -this._const.TRIANGLE_LENGTH, right: -this._const.TRIANGLE_LENGTH,
left: "" left: "",
}; };
break; break;
case "right": case "right":
case "right,bottom": case "right,bottom":
direction = "right"; direction = "right";
style = { style = {
top: BI.clamp(((middle ? popupHeight : position.height) - adjustYOffset) / 2 - 8, minTop, maxTop) top: BI.clamp(((middle ? popupHeight : position.height) - adjustYOffset) / 2 - 8, minTop, maxTop),
}; };
wrapperStyle = { wrapperStyle = {
left: o.lgap + o.hgap, left: o.lgap + o.hgap,
@ -342,13 +347,13 @@ BI.PopupView = BI.inherit(BI.Widget, {
bottom: 0, bottom: 0,
width: this._const.TRIANGLE_LENGTH, width: this._const.TRIANGLE_LENGTH,
left: -this._const.TRIANGLE_LENGTH, left: -this._const.TRIANGLE_LENGTH,
right: "" right: "",
}; };
break; break;
case "right,top": case "right,top":
direction = "right"; direction = "right";
style = { style = {
bottom: BI.clamp(((middle ? popupHeight : position.height) + adjustYOffset) / 2 - 8, minBottom, maxBottom) bottom: BI.clamp(((middle ? popupHeight : position.height) + adjustYOffset) / 2 - 8, minBottom, maxBottom),
}; };
wrapperStyle = { wrapperStyle = {
left: o.lgap + o.hgap, left: o.lgap + o.hgap,
@ -361,7 +366,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
bottom: 0, bottom: 0,
width: this._const.TRIANGLE_LENGTH, width: this._const.TRIANGLE_LENGTH,
left: -this._const.TRIANGLE_LENGTH, left: -this._const.TRIANGLE_LENGTH,
right: "" right: "",
}; };
break; break;
case "right,innerRight": case "right,innerRight":
@ -372,8 +377,15 @@ BI.PopupView = BI.inherit(BI.Widget, {
break; break;
case "innerLeft": case "innerLeft":
break; break;
default:
break;
} }
this.element.removeClass("left").removeClass("right").removeClass("top").removeClass("bottom").addClass(direction); this.element
.removeClass("left")
.removeClass("right")
.removeClass("top")
.removeClass("bottom")
.addClass(direction);
this.arrow.element.css(style); this.arrow.element.css(style);
this.arrowWrapper.element.css(wrapperStyle); this.arrowWrapper.element.css(wrapperStyle);
this.placeholder.element.css(placeholderStyle); this.placeholder.element.css(placeholderStyle);
@ -399,7 +411,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0); toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0);
var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVgap; var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVgap;
this.view.resetHeight ? this.view.resetHeight(resetHeight) : this.view.resetHeight ? this.view.resetHeight(resetHeight) :
this.view.element.css({"max-height": resetHeight / BI.pixRatio + BI.pixUnit}); this.view.element.css({ "max-height": resetHeight / BI.pixRatio + BI.pixUnit });
}, },
setValue: function (selectedValues) { setValue: function (selectedValues) {
@ -409,7 +421,7 @@ BI.PopupView = BI.inherit(BI.Widget, {
getValue: function () { getValue: function () {
return this.view.getValue(); return this.view.getValue();
} },
}); });
BI.PopupView.EVENT_CHANGE = "EVENT_CHANGE"; BI.PopupView.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.popup_view", BI.PopupView); BI.shortcut("bi.popup_view", BI.PopupView);

37
src/base/layer/layer.searcher.js

@ -9,35 +9,36 @@
BI.SearcherView = BI.inherit(BI.Pane, { BI.SearcherView = BI.inherit(BI.Pane, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments); var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card", baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card",
tipText: BI.i18nText("BI-No_Select"), tipText: BI.i18nText("BI-No_Select"),
chooseType: BI.Selection.Single, chooseType: BI.Selection.Single,
matcher: {// 完全匹配的构造器 matcher: { // 完全匹配的构造器
type: "bi.button_group", type: "bi.button_group",
behaviors: { behaviors: {
redmark: function () { redmark: function () {
return true; return true;
} },
}, },
items: [], items: [],
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}] }],
}, },
searcher: { searcher: {
type: "bi.button_group", type: "bi.button_group",
behaviors: { behaviors: {
redmark: function () { redmark: function () {
return true; return true;
} },
}, },
items: [], items: [],
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}] }],
} },
}); });
}, },
@ -50,12 +51,12 @@ BI.SearcherView = BI.inherit(BI.Pane, {
behaviors: { behaviors: {
redmark: function () { redmark: function () {
return true; return true;
} },
}, },
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}], }],
value: o.value value: o.value,
}); });
this.matcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) { this.matcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -70,8 +71,8 @@ BI.SearcherView = BI.inherit(BI.Pane, {
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
height: 1, height: 1,
cls: "searcher-view-spliter bi-background" cls: "searcher-view-spliter bi-background",
}] }],
}); });
this.searcher = BI.createWidget(o.searcher, { this.searcher = BI.createWidget(o.searcher, {
type: "bi.button_group", type: "bi.button_group",
@ -79,12 +80,12 @@ BI.SearcherView = BI.inherit(BI.Pane, {
behaviors: { behaviors: {
redmark: function () { redmark: function () {
return true; return true;
} },
}, },
layouts: [{ layouts: [{
type: "bi.vertical" type: "bi.vertical",
}], }],
value: o.value value: o.value,
}); });
this.searcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) { this.searcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
@ -96,7 +97,7 @@ BI.SearcherView = BI.inherit(BI.Pane, {
BI.createWidget({ BI.createWidget({
type: "bi.vertical", type: "bi.vertical",
element: this, element: this,
items: [this.matcher, this.spliter, this.searcher] items: [this.matcher, this.spliter, this.searcher],
}); });
}, },
@ -133,7 +134,7 @@ BI.SearcherView = BI.inherit(BI.Pane, {
hasMatched: function () { hasMatched: function () {
return this.matcher.getAllButtons().length > 0; return this.matcher.getAllButtons().length > 0;
} },
}); });
BI.SearcherView.EVENT_CHANGE = "EVENT_CHANGE"; BI.SearcherView.EVENT_CHANGE = "EVENT_CHANGE";

13
src/base/list/__test__/listview.test.js

@ -6,7 +6,6 @@
// TODO 展示类控件测什么没想好标记一下 // TODO 展示类控件测什么没想好标记一下
describe("ListView && VirtualList", function () { describe("ListView && VirtualList", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
@ -14,16 +13,16 @@ describe("ListView && VirtualList", function () {
var a = BI.Test.createWidget({ var a = BI.Test.createWidget({
type: "bi.list_view", type: "bi.list_view",
el: { el: {
type: "bi.left" type: "bi.left",
}, },
items: BI.map(BI.range(0, 100), function (i, item) { items: BI.map(BI.range(0, 100), function (i, item) {
return BI.extend({}, item, { return BI.extend({}, item, {
type: "bi.label", type: "bi.label",
width: 200, width: 200,
height: 200, height: 200,
text: (i + 1) text: (i + 1),
}); });
}) }),
}); });
a.destroy(); a.destroy();
}); });
@ -39,10 +38,10 @@ describe("ListView && VirtualList", function () {
return BI.extend({}, item, { return BI.extend({}, item, {
type: "bi.label", type: "bi.label",
height: 30, height: 30,
text: (i + 1) + "." + item.text text: (i + 1) + "." + item.text,
}); });
}) }),
}); });
a.destroy(); a.destroy();
}); });
}); });

23
src/base/list/listview.js

@ -16,18 +16,18 @@ BI.ListView = BI.inherit(BI.Widget, {
items: [], items: [],
itemFormatter: function (item, index) { itemFormatter: function (item, index) {
return item; return item;
} },
}; };
}, },
init: function () { init: function () {
var self = this;
this.renderedIndex = -1; this.renderedIndex = -1;
this.cache = {}; this.cache = {};
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
return { return {
type: "bi.vertical", type: "bi.vertical",
items: [BI.extend({ items: [BI.extend({
@ -35,9 +35,9 @@ BI.ListView = BI.inherit(BI.Widget, {
scrolly: false, scrolly: false,
ref: function (_ref) { ref: function (_ref) {
self.container = _ref; self.container = _ref;
} },
}, o.el)], }, o.el)],
element: this element: this,
}; };
}, },
@ -72,10 +72,13 @@ BI.ListView = BI.inherit(BI.Widget, {
var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0; var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0;
var cnt = this.renderedIndex + 1; var cnt = this.renderedIndex + 1;
var lastHeight; var lastHeight;
var getElementHeight = function () {
function getElementHeight() {
return self.container.element.height(); return self.container.element.height();
}; }
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
lastHeight = getElementHeight();
while ((lastHeight) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); var items = o.items.slice(index, index + o.blockSize);
this.container.addItems(items.map(function (item, i) { this.container.addItems(items.map(function (item, i) {
return o.itemFormatter(item, index + i); return o.itemFormatter(item, index + i);
@ -84,16 +87,16 @@ BI.ListView = BI.inherit(BI.Widget, {
this.cache[cnt] = { this.cache[cnt] = {
index: index, index: index,
scrollTop: lastHeight, scrollTop: lastHeight,
height: addedHeight height: addedHeight,
}; };
this.renderedIndex = cnt; this.renderedIndex = cnt;
cnt++; cnt++;
index += o.blockSize; index += o.blockSize;
lastHeight = getElementHeight();
} }
}, },
_calculateBlocksToRender: function () { _calculateBlocksToRender: function () {
var o = this.options;
this._renderMoreIf(); this._renderMoreIf();
}, },
@ -127,7 +130,7 @@ BI.ListView = BI.inherit(BI.Widget, {
destroyed: function () { destroyed: function () {
this.restore(); this.restore();
} },
}); });
BI.shortcut("bi.list_view", BI.ListView); BI.shortcut("bi.list_view", BI.ListView);

23
src/base/list/virtualgrouplist.js

@ -17,7 +17,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
el: {}, el: {},
itemFormatter: function (item, index) { itemFormatter: function (item, index) {
return item; return item;
} },
}; };
}, },
@ -27,13 +27,14 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
return { return {
type: "bi.vertical", type: "bi.vertical",
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
ref: function () { ref: function () {
self.topBlank = this; self.topBlank = this;
} },
}, { }, {
type: "bi.virtual_group", type: "bi.virtual_group",
height: o.rowHeight * o.items.length, height: o.rowHeight * o.items.length,
@ -42,15 +43,15 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
}, },
layouts: [BI.extend({ layouts: [BI.extend({
type: "bi.vertical", type: "bi.vertical",
scrolly: false scrolly: false,
}, o.el)] }, o.el)],
}, { }, {
type: "bi.layout", type: "bi.layout",
ref: function () { ref: function () {
self.bottomBlank = this; self.bottomBlank = this;
} },
}], }],
element: this element: this,
}; };
}, },
@ -87,10 +88,11 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
var minContentHeight = o.scrollTop + height + o.overscanHeight; var minContentHeight = o.scrollTop + height + o.overscanHeight;
var index = (this.renderedIndex + 1) * o.blockSize, cnt = this.renderedIndex + 1; var index = (this.renderedIndex + 1) * o.blockSize, cnt = this.renderedIndex + 1;
var lastHeight; var lastHeight;
var getElementHeight = function () { function getElementHeight () {
return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height(); return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height();
}; }
while ((lastHeight = this.renderedIndex === -1 ? 0 : getElementHeight()) < minContentHeight && index < o.items.length) { lastHeight = this.renderedIndex === -1 ? 0 : getElementHeight();
while (lastHeight < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); var items = o.items.slice(index, index + o.blockSize);
this.container[self.renderedIndex === -1 ? "populate" : "addItems"](items.map(function (item, i) { this.container[self.renderedIndex === -1 ? "populate" : "addItems"](items.map(function (item, i) {
return o.itemFormatter(item, index + i); return o.itemFormatter(item, index + i);
@ -100,6 +102,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
this.renderedIndex = cnt; this.renderedIndex = cnt;
cnt++; cnt++;
index += o.blockSize; index += o.blockSize;
lastHeight = this.renderedIndex === -1 ? 0 : getElementHeight();
} }
}, },
@ -176,7 +179,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
this._populate(items); this._populate(items);
} },
}); });
BI.shortcut("bi.virtual_group_list", BI.VirtualGroupList); BI.shortcut("bi.virtual_group_list", BI.VirtualGroupList);

22
src/base/list/virtuallist.js

@ -15,36 +15,36 @@ BI.VirtualList = BI.inherit(BI.Widget, {
items: [], items: [],
itemFormatter: function (item, index) { itemFormatter: function (item, index) {
return item; return item;
} },
}; };
}, },
init: function () { init: function () {
var self = this;
this.renderedIndex = -1; this.renderedIndex = -1;
this.cache = {}; this.cache = {};
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this;
return { return {
type: "bi.vertical", type: "bi.vertical",
items: [{ items: [{
type: "bi.layout", type: "bi.layout",
ref: function () { ref: function () {
self.topBlank = this; self.topBlank = this;
} },
}, { }, {
type: "bi.vertical", type: "bi.vertical",
scrolly: false, scrolly: false,
ref: function () { ref: function () {
self.container = this; self.container = this;
} },
}, { }, {
type: "bi.layout", type: "bi.layout",
ref: function () { ref: function () {
self.bottomBlank = this; self.bottomBlank = this;
} },
}], }],
}; };
}, },
@ -71,10 +71,11 @@ BI.VirtualList = BI.inherit(BI.Widget, {
var minContentHeight = o.scrollTop + height + o.overscanHeight; var minContentHeight = o.scrollTop + height + o.overscanHeight;
var index = (this.renderedIndex + 1) * o.blockSize, cnt = this.renderedIndex + 1; var index = (this.renderedIndex + 1) * o.blockSize, cnt = this.renderedIndex + 1;
var lastHeight; var lastHeight;
var getElementHeight = function () { function getElementHeight() {
return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height(); return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height();
}; }
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { lastHeight = getElementHeight();
while (lastHeight < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); var items = o.items.slice(index, index + o.blockSize);
this.container.addItems(items.map(function (item, i) { this.container.addItems(items.map(function (item, i) {
return o.itemFormatter(item, index + i); return o.itemFormatter(item, index + i);
@ -84,6 +85,7 @@ BI.VirtualList = BI.inherit(BI.Widget, {
this.renderedIndex = cnt; this.renderedIndex = cnt;
cnt++; cnt++;
index += o.blockSize; index += o.blockSize;
lastHeight = getElementHeight();
} }
}, },
@ -202,7 +204,7 @@ BI.VirtualList = BI.inherit(BI.Widget, {
destroyed: function () { destroyed: function () {
this.cache = {}; this.cache = {};
this.renderedIndex = -1; this.renderedIndex = -1;
} },
}); });
BI.shortcut("bi.virtual_list", BI.VirtualList); BI.shortcut("bi.virtual_list", BI.VirtualList);

35
src/base/pager/pager.js

@ -13,7 +13,7 @@ BI.Pager = BI.inherit(BI.Widget, {
layouts: [{ layouts: [{
type: "bi.horizontal", type: "bi.horizontal",
hgap: 10, hgap: 10,
vgap: 0 vgap: 0,
}], }],
dynamicShow: true, // 是否动态显示上一页、下一页、首页、尾页, 若为false,则指对其设置使能状态 dynamicShow: true, // 是否动态显示上一页、下一页、首页、尾页, 若为false,则指对其设置使能状态
@ -36,12 +36,11 @@ BI.Pager = BI.inherit(BI.Widget, {
return 1; return 1;
}, },
hasPrev: BI.emptyFn, // pages不可用时有效 hasPrev: BI.emptyFn, // pages不可用时有效
hasNext: BI.emptyFn // pages不可用时有效 hasNext: BI.emptyFn, // pages不可用时有效
}); });
}, },
render: function () { render: function () {
var self = this;
this.currPage = BI.result(this.options, "curr"); this.currPage = BI.result(this.options, "curr");
// 翻页太灵敏 // 翻页太灵敏
// this._lock = false; // this._lock = false;
@ -79,13 +78,13 @@ BI.Pager = BI.inherit(BI.Widget, {
view.push({ view.push({
text: prev, text: prev,
value: "prev", value: "prev",
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false),
}); });
} else { } else {
view.push({ view.push({
el: BI.extend({ el: BI.extend({
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false),
}, prev) }, prev),
}); });
} }
} }
@ -95,13 +94,13 @@ BI.Pager = BI.inherit(BI.Widget, {
view.push({ view.push({
text: first, text: first,
value: "first", value: "first",
disabled: !(dict.index > 1 && groups !== 0) disabled: !(dict.index > 1 && groups !== 0),
}); });
if (dict.index > 1 && groups !== 0 && groups !== pages - 1) { if (dict.index > 1 && groups !== 0 && groups !== pages - 1) {
view.push({ view.push({
type: "bi.label", type: "bi.label",
cls: "page-ellipsis", cls: "page-ellipsis",
text: "\u2026" text: "\u2026",
}); });
} }
} }
@ -127,12 +126,12 @@ BI.Pager = BI.inherit(BI.Widget, {
view.push({ view.push({
text: s, text: s,
value: s, value: s,
selected: true selected: true,
}); });
} else { } else {
view.push({ view.push({
text: s, text: s,
value: s value: s,
}); });
} }
} }
@ -143,13 +142,13 @@ BI.Pager = BI.inherit(BI.Widget, {
view.push({ view.push({
type: "bi.label", type: "bi.label",
cls: "page-ellipsis", cls: "page-ellipsis",
text: "\u2026" text: "\u2026",
}); });
} }
view.push({ view.push({
text: last, text: last,
value: "last", value: "last",
disabled: !(pages > groups && dict.end < pages && groups !== 0) disabled: !(pages > groups && dict.end < pages && groups !== 0),
}); });
} }
@ -171,8 +170,8 @@ BI.Pager = BI.inherit(BI.Widget, {
return { return {
el: BI.extend({ el: BI.extend({
disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow) disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow),
}, next) }, next),
}; };
}())); }()));
} }
@ -185,13 +184,13 @@ BI.Pager = BI.inherit(BI.Widget, {
cls: "bi-list-item-select bi-border-radius", cls: "bi-list-item-select bi-border-radius",
height: 23, height: 23,
hgap: v.el ? 0 : 10, hgap: v.el ? 0 : 10,
stopPropagation: true stopPropagation: true,
}, BI.stripEL(v)); }, BI.stripEL(v));
return BI.formatEL(v); return BI.formatEL(v);
}), }),
behaviors: o.behaviors, behaviors: o.behaviors,
layouts: o.layouts layouts: o.layouts,
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
// if (self._lock === true) { // if (self._lock === true) {
@ -220,7 +219,7 @@ BI.Pager = BI.inherit(BI.Widget, {
} }
o.jump.apply(self, [{ o.jump.apply(self, [{
pages: pages, pages: pages,
curr: self.currPage curr: self.currPage,
}]); }]);
self._populate(); self._populate();
self.fireEvent(BI.Pager.EVENT_CHANGE, obj); self.fireEvent(BI.Pager.EVENT_CHANGE, obj);
@ -293,7 +292,7 @@ BI.Pager = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this._populate(); this._populate();
} },
}); });
BI.Pager.EVENT_CHANGE = "EVENT_CHANGE"; BI.Pager.EVENT_CHANGE = "EVENT_CHANGE";
BI.Pager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE"; BI.Pager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE";

12
src/base/single/0.single.js

@ -15,13 +15,14 @@ var delayingTooltips;
BI.Single = BI.inherit(BI.Widget, { BI.Single = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
var conf = BI.Single.superclass._defaultConfig.apply(this, arguments); var conf = BI.Single.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, { return BI.extend(conf, {
readonly: false, readonly: false,
title: null, title: null,
warningTitle: null, warningTitle: null,
tipType: null, // success或warning tipType: null, // success或warning
belowMouse: false, // title是否跟随鼠标 belowMouse: false, // title是否跟随鼠标
enableHover: false enableHover: false,
}); });
}, },
@ -70,7 +71,7 @@ BI.Single = BI.inherit(BI.Widget, {
|| BI.isFunction(o.title) || BI.isFunction(o.warningTitle)) { || BI.isFunction(o.title) || BI.isFunction(o.warningTitle)) {
this.enableHover({ this.enableHover({
belowMouse: o.belowMouse, belowMouse: o.belowMouse,
container: o.container container: o.container,
}); });
} }
}, },
@ -136,7 +137,6 @@ BI.Single = BI.inherit(BI.Widget, {
} }
} }
}, 500); }, 500);
}); });
this.element.on("mouseleave.title" + this.getName(), function (e) { this.element.on("mouseleave.title" + this.getName(), function (e) {
self._e = null; self._e = null;
@ -193,6 +193,7 @@ BI.Single = BI.inherit(BI.Widget, {
if (BI.isFunction(title)) { if (BI.isFunction(title)) {
return title(); return title();
} }
return title; return title;
}, },
@ -201,6 +202,7 @@ BI.Single = BI.inherit(BI.Widget, {
if (BI.isFunction(title)) { if (BI.isFunction(title)) {
return title(); return title();
} }
return title; return title;
}, },
@ -222,6 +224,6 @@ BI.Single = BI.inherit(BI.Widget, {
this.showTimeout = null; this.showTimeout = null;
} }
BI.Tooltips.remove(this.getName()); BI.Tooltips.remove(this.getName());
} },
}); });
BI.shortcut("bi.single", BI.Single); BI.shortcut("bi.single", BI.Single);

28
src/base/single/1.text.js

@ -19,58 +19,58 @@
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
py: "", py: "",
highLight: false highLight: false,
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
if (o.hgap + o.lgap > 0) { if (o.hgap + o.lgap > 0) {
this.element.css({ this.element.css({
"padding-left": (o.hgap + o.lgap) / BI.pixRatio + BI.pixUnit "padding-left": (o.hgap + o.lgap) / BI.pixRatio + BI.pixUnit,
}); });
} }
if (o.hgap + o.rgap > 0) { if (o.hgap + o.rgap > 0) {
this.element.css({ this.element.css({
"padding-right": (o.hgap + o.rgap) / BI.pixRatio + BI.pixUnit "padding-right": (o.hgap + o.rgap) / BI.pixRatio + BI.pixUnit,
}); });
} }
if (o.vgap + o.tgap > 0) { if (o.vgap + o.tgap > 0) {
this.element.css({ this.element.css({
"padding-top": (o.vgap + o.tgap) / BI.pixRatio + BI.pixUnit "padding-top": (o.vgap + o.tgap) / BI.pixRatio + BI.pixUnit,
}); });
} }
if (o.vgap + o.bgap > 0) { if (o.vgap + o.bgap > 0) {
this.element.css({ this.element.css({
"padding-bottom": (o.vgap + o.bgap) / BI.pixRatio + BI.pixUnit "padding-bottom": (o.vgap + o.bgap) / BI.pixRatio + BI.pixUnit,
}); });
} }
if (BI.isWidthOrHeight(o.height)) { if (BI.isWidthOrHeight(o.height)) {
this.element.css({lineHeight: BI.isNumber(o.height) ? (o.height / BI.pixRatio + BI.pixUnit) : o.height}); this.element.css({ lineHeight: BI.isNumber(o.height) ? (o.height / BI.pixRatio + BI.pixUnit) : o.height });
} }
if (BI.isWidthOrHeight(o.lineHeight)) { if (BI.isWidthOrHeight(o.lineHeight)) {
this.element.css({lineHeight: BI.isNumber(o.lineHeight) ? (o.lineHeight / BI.pixRatio + BI.pixUnit) : o.lineHeight}); this.element.css({ lineHeight: BI.isNumber(o.lineHeight) ? (o.lineHeight / BI.pixRatio + BI.pixUnit) : o.lineHeight });
} }
if (BI.isWidthOrHeight(o.maxWidth)) { if (BI.isWidthOrHeight(o.maxWidth)) {
this.element.css({maxWidth: BI.isNumber(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth}); this.element.css({ maxWidth: BI.isNumber(o.maxWidth) ? (o.maxWidth / BI.pixRatio + BI.pixUnit) : o.maxWidth });
} }
this.element.css({ this.element.css({
textAlign: o.textAlign, textAlign: o.textAlign,
whiteSpace: this._getTextWrap(), whiteSpace: this._getTextWrap(),
textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "", textOverflow: o.whiteSpace === "nowrap" ? "ellipsis" : "",
overflow: o.whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(o.height) ? "auto" : "") overflow: o.whiteSpace === "nowrap" ? "" : (BI.isWidthOrHeight(o.height) ? "auto" : ""),
}); });
if (o.handler && o.handler !== BI.emptyFn) { if (o.handler && o.handler !== BI.emptyFn) {
this.text = BI.createWidget({ this.text = BI.createWidget({
type: "bi.layout", type: "bi.layout",
tagName: "span" tagName: "span",
}); });
this.text.element.click(function (e) { this.text.element.click(function (e) {
o.handler.call(self, self.getValue(), self, e); !o.disabled && !o.invalid && o.handler.call(self, self.getValue(), self, e);
}); });
BI.createWidget({ BI.createWidget({
type: "bi.default", type: "bi.default",
element: this, element: this,
items: [this.text] items: [this.text],
}); });
} else { } else {
this.text = this; this.text = this;
@ -108,6 +108,7 @@
_getShowText: function () { _getShowText: function () {
var o = this.options; var o = this.options;
var text = BI.isFunction(o.text) ? o.text() : o.text; var text = BI.isFunction(o.text) ? o.text() : o.text;
return BI.isKey(text) ? BI.Text.formatText(text + "") : text; return BI.isKey(text) ? BI.Text.formatText(text + "") : text;
}, },
@ -153,7 +154,7 @@
BI.Text.superclass.setText.apply(this, arguments); BI.Text.superclass.setText.apply(this, arguments);
this.options.text = text; this.options.text = text;
this._doRedMark(this.options.keyword); this._doRedMark(this.options.keyword);
} },
}); });
var formatters = []; var formatters = [];
BI.Text.addTextFormatter = function (formatter) { BI.Text.addTextFormatter = function (formatter) {
@ -165,6 +166,7 @@
text = formatters[i](text); text = formatters[i](text);
} }
} }
return text; return text;
}; };
BI.shortcut("bi.text", BI.Text); BI.shortcut("bi.text", BI.Text);

27
src/base/single/__test__/text.test.js

@ -2,13 +2,12 @@
* Created by windy on 2018/01/23. * Created by windy on 2018/01/23.
*/ */
describe("TextTest", function () { describe("TextTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
it("setText", function () { it("setText", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text" type: "bi.text",
}); });
text.setText("AAA"); text.setText("AAA");
expect(text.element.text()).to.equal("AAA"); expect(text.element.text()).to.equal("AAA");
@ -20,9 +19,9 @@ describe("TextTest", function () {
*/ */
it("setStyle", function () { it("setStyle", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text" type: "bi.text",
}); });
text.setStyle({"color": "red"}); text.setStyle({ "color": "red" });
expect(text.element.getStyle("color")).to.equal("rgb(255, 0, 0)"); expect(text.element.getStyle("color")).to.equal("rgb(255, 0, 0)");
text.destroy(); text.destroy();
}); });
@ -34,7 +33,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "AAA", text: "AAA",
highLight: true highLight: true,
}); });
expect(text.element.getStyle("color")).to.equal("rgb(54, 133, 242)"); expect(text.element.getStyle("color")).to.equal("rgb(54, 133, 242)");
text.destroy(); text.destroy();
@ -47,7 +46,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
keyword: "A" keyword: "A",
}); });
expect(text.element.children(".bi-keyword-red-mark").length).to.not.equal(0); expect(text.element.children(".bi-keyword-red-mark").length).to.not.equal(0);
text.destroy(); text.destroy();
@ -61,7 +60,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "AAA", text: "AAA",
highLight: true highLight: true,
}); });
text.unHighLight(); text.unHighLight();
expect(text.element.getStyle("color")).to.not.equal("rgb(54, 133, 242)"); expect(text.element.getStyle("color")).to.not.equal("rgb(54, 133, 242)");
@ -75,7 +74,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
keyword: "A" keyword: "A",
}); });
text.unRedMark(); text.unRedMark();
expect(text.element.children(".bi-keyword-red-mark").length).to.equal(0); expect(text.element.children(".bi-keyword-red-mark").length).to.equal(0);
@ -103,7 +102,7 @@ describe("TextTest", function () {
type: "bi.text", type: "bi.text",
text: "我是要标红的A", text: "我是要标红的A",
vgap: 10, vgap: 10,
hgap: 10 hgap: 10,
}); });
expect(text.element.css("padding")).to.equal("10px"); expect(text.element.css("padding")).to.equal("10px");
text.destroy(); text.destroy();
@ -129,7 +128,7 @@ describe("TextTest", function () {
type: "bi.text", type: "bi.text",
text: "我是A", text: "我是A",
lineHeight: 12, lineHeight: 12,
height: 24 height: 24,
}); });
expect(text.element.css("height")).to.equal("24px"); expect(text.element.css("height")).to.equal("24px");
expect(text.element.css("line-height")).to.equal("12px"); expect(text.element.css("line-height")).to.equal("12px");
@ -145,7 +144,7 @@ describe("TextTest", function () {
text: "我是A", text: "我是A",
handler: function () { handler: function () {
text.setText("handler"); text.setText("handler");
} },
}); });
BI.nextTick(function () { BI.nextTick(function () {
text.text.element.click(); text.text.element.click();
@ -162,7 +161,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: "", text: "",
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal(""); expect(text.element.text()).to.equal("");
text.destroy(); text.destroy();
@ -174,7 +173,7 @@ describe("TextTest", function () {
it("text的value属性1", function () { it("text的value属性1", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal("aaaa"); expect(text.element.text()).to.equal("aaaa");
text.destroy(); text.destroy();
@ -187,7 +186,7 @@ describe("TextTest", function () {
var text = BI.Test.createWidget({ var text = BI.Test.createWidget({
type: "bi.text", type: "bi.text",
text: null, text: null,
value: "aaaa" value: "aaaa",
}); });
expect(text.element.text()).to.equal(""); expect(text.element.text()).to.equal("");
text.destroy(); text.destroy();

11
src/base/single/a/__test__/a.test.js

@ -2,16 +2,15 @@
* Created by windy on 2018/01/23. * Created by windy on 2018/01/23.
*/ */
describe("ALinkTest", function () { describe("ALinkTest", function () {
/** /**
* test_author_windy * test_author_windy
*/ */
it("A初始化测试", function () { it("A初始化测试", function () {
var a = BI.Test.createWidget({ var a = BI.Test.createWidget({
type: "bi.a", type: "bi.a",
text: "CCC" text: "CCC",
}); });
expect(a.element.is('a')).to.equal(true); expect(a.element.is("a")).to.equal(true);
a.destroy(); a.destroy();
}); });
@ -23,10 +22,10 @@ describe("ALinkTest", function () {
type: "bi.a", type: "bi.a",
text: "DDD", text: "DDD",
el: { el: {
type: "bi.label" type: "bi.label",
} },
}); });
expect(a.element.is('a') && a.element.hasClass("bi-label")).to.equal(true); expect(a.element.is("a") && a.element.hasClass("bi-label")).to.equal(true);
a.destroy(); a.destroy();
}); });
}); });

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save