Browse Source

Merge branch 'master' of ssh://cloud.finedevelop.com:7999/~kira/fineui

es6
Kira 2 years ago
parent
commit
3066d10d10
  1. 8
      .eslintrc
  2. 4
      .npmignore
  3. 44
      bin/cli/cli.js
  4. 76
      bin/cli/worker/cli.worker.js
  5. 45
      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. 8
      bin/cli/worker/template/utils/action_type.t
  9. 13
      bin/cli/worker/template/utils/payload_type.t
  10. 24
      bin/cli/worker/template/worker_thread/action/action.worker_ability_test.t
  11. 12
      bin/cli/worker/template/worker_thread/worker_thread.t
  12. 700
      demo/js/base/button/demo.button.js
  13. 20
      demo/js/base/tip/demo.title.js
  14. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_1.png
  15. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_2.png
  16. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_3.png
  17. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_4.png
  18. BIN
      dist/images/2x/icon/dark/tree_solid_collapse_5.png
  19. BIN
      dist/images/2x/icon/dark/tree_solid_expand_1.png
  20. BIN
      dist/images/2x/icon/dark/tree_solid_expand_2.png
  21. BIN
      dist/images/2x/icon/dark/tree_solid_expand_3.png
  22. BIN
      dist/images/2x/icon/dark/tree_solid_expand_4.png
  23. BIN
      dist/images/2x/icon/dark/tree_solid_expand_5.png
  24. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_1.png
  25. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_2.png
  26. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_3.png
  27. BIN
      dist/images/2x/icon/dark/tree_solid_vertical_line_4.png
  28. BIN
      dist/images/2x/icon/tree_solid_collapse_1.png
  29. BIN
      dist/images/2x/icon/tree_solid_collapse_2.png
  30. BIN
      dist/images/2x/icon/tree_solid_collapse_3.png
  31. BIN
      dist/images/2x/icon/tree_solid_collapse_4.png
  32. BIN
      dist/images/2x/icon/tree_solid_collapse_5.png
  33. BIN
      dist/images/2x/icon/tree_solid_expand_1.png
  34. BIN
      dist/images/2x/icon/tree_solid_expand_2.png
  35. BIN
      dist/images/2x/icon/tree_solid_expand_3.png
  36. BIN
      dist/images/2x/icon/tree_solid_expand_4.png
  37. BIN
      dist/images/2x/icon/tree_solid_expand_5.png
  38. BIN
      dist/images/2x/icon/tree_solid_vertical_line_2.png
  39. BIN
      dist/images/2x/icon/tree_solid_vertical_line_3.png
  40. BIN
      dist/images/2x/icon/tree_solid_vertical_line_4.png
  41. BIN
      dist/images/2x/icon/tree_vertical_line_1.png
  42. 15
      examples/worker_new.html
  43. 105
      examples/worker_new/index.js
  44. 80
      examples/worker_new/worker.js
  45. 104
      examples/替换loading动画.html
  46. 9
      package.json
  47. 9
      plugins/webpack-fui-worker-plugin/constants.js
  48. 45
      plugins/webpack-fui-worker-plugin/index.js
  49. 109
      plugins/webpack-fui-worker-plugin/worker-loader.js
  50. 27
      src/base/1.pane.js
  51. 29
      src/base/combination/group.button.js
  52. 16
      src/base/combination/group.virtual.js
  53. 23
      src/base/combination/tab.js
  54. 10
      src/base/foundation/message.js
  55. 23
      src/base/layer/layer.drawer.js
  56. 16
      src/base/list/listview.js
  57. 13
      src/base/list/virtualgrouplist.js
  58. 9
      src/base/list/virtuallist.js
  59. 35
      src/base/single/0.single.js
  60. 45
      src/base/single/button/buttons/button.js
  61. 4
      src/base/single/editor/editor.multifile.js
  62. 7
      src/base/single/input/file.js
  63. 20
      src/base/single/label/abstract.label.js
  64. 30
      src/base/single/tip/tip.toast.js
  65. 15
      src/base/single/tip/tip.tooltip.js
  66. 6
      src/case/button/item.multiselect.js
  67. 11
      src/case/button/item.singleselect.radio.js
  68. 30
      src/case/combo/bubblecombo/popup.bubble.js
  69. 1
      src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js
  70. 4
      src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js
  71. 26
      src/case/layer/pane.list.js
  72. 10
      src/case/list/list.select.js
  73. 2
      src/case/ztree/jquery.ztree.core-3.5.js
  74. 23
      src/component/allvaluechooser/abstract.allvaluechooser.js
  75. 7
      src/component/allvaluechooser/pane.allvaluechooser.js
  76. 4
      src/core/2.base.js
  77. 6
      src/core/3.ob.js
  78. 2
      src/core/4.widget.js
  79. 6
      src/core/5.inject.js
  80. 8
      src/core/conflict.js
  81. 2
      src/core/controller/controller.bubbles.js
  82. 23
      src/core/controller/controller.tooltips.js
  83. 74
      src/core/element/element.js
  84. 31
      src/core/element/index.js
  85. 22
      src/core/element/plugins/attr.js
  86. 23
      src/core/element/plugins/class.js
  87. 22
      src/core/element/plugins/css.js
  88. 12
      src/core/element/plugins/data.js
  89. 9
      src/core/element/plugins/empty.js
  90. 32
      src/core/element/plugins/event.js
  91. 15
      src/core/element/plugins/html.js
  92. 31
      src/core/element/plugins/index.js
  93. 6
      src/core/element/plugins/keywordMark.js
  94. 65
      src/core/element/plugins/renderToHtml.js
  95. 50
      src/core/element/plugins/renderToString.js
  96. 10
      src/core/element/plugins/text.js
  97. 9
      src/core/element/plugins/val.js
  98. 4
      src/core/platform/web/config.js
  99. 51
      src/core/system.js
  100. 4
      src/less/base/single/button/button.less
  101. Some files were not shown because too many files have changed in this diff Show More

8
.eslintrc

@ -17,7 +17,6 @@
}, },
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6, "ecmaVersion": 6,
"sourceType": "module", "sourceType": "module",
"ecmaFeatures": { "ecmaFeatures": {
@ -26,7 +25,7 @@
}, },
"plugins": ["@typescript-eslint/eslint-plugin"], "plugins": ["@typescript-eslint/eslint-plugin"],
"overrides": [{ "overrides": [{
"files": ["src/*.js","src/**/*.js", "demo/*.js", "demo/**/*.js", "i18n/**/*.js", "i18n/*.js", "test/**/*.js", "test/*.js"], "files": ["src/*.js","src/**/*.js", "demo/*.js", "demo/**/*.js", "i18n/**/*.js", "i18n/*.js", "test/**/*.js", "test/*.js", "examples/*.js", "examples/**/*.js"],
"extends": "plugin:@fui/es5", "extends": "plugin:@fui/es5",
"rules": { "rules": {
"no-param-reassign": "off", "no-param-reassign": "off",
@ -34,7 +33,10 @@
"comma-dangle": ["error", "never"] // 多行对象字面量中要求拖尾逗号 "comma-dangle": ["error", "never"] // 多行对象字面量中要求拖尾逗号
} }
}, { }, {
"files": ["webpack/*.js", "types/*.ts", "typescript/*.ts","typescript/**/*.ts", "./*.js", "lib/**/*.js", "lib/*.js"], "files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"],
"extends": "plugin:@fui/esnext"
}, {
"files": ["types/*.ts", "typescript/*.ts","typescript/**/*.ts"],
"extends": "plugin:@fui/typescript" "extends": "plugin:@fui/typescript"
}] }]
} }

4
.npmignore

@ -38,3 +38,7 @@
!.eslintrc !.eslintrc
!dist/2.0/jsy.min.css !dist/2.0/jsy.min.css
!dist/2.0/bi.min.css !dist/2.0/bi.min.css
!bin/*
!bin/**/*
!plugins/*
!plugins/**/*

44
bin/cli/cli.js

@ -0,0 +1,44 @@
#!/usr/bin/env node
const workerCmd = require('./worker/cli.worker');
function getArgs (startIndex = 1) {
const args = {};
process.argv
.slice(startIndex, process.argv.length)
.forEach(arg => {
// long arg
if (arg.slice(0, 2) === '--') {
const longArg = arg.split('=');
const longArgFlag = longArg[0].slice(2, longArg[0].length);
const longArgValue = longArg.length > 1 ? longArg[1] : true;
args[longArgFlag] = longArgValue;
// flags
} else if (arg[0] === '-') {
const flags = arg.slice(1, arg.length);
args[flags] = true;
}
});
return args;
}
const cmds = new Map([
['worker', workerCmd],
]);
const baseCmd = 'fui-cli';
const startIndex = process.argv.findIndex(argv => argv.indexOf(baseCmd) !== -1);
if (startIndex === -1) {
throw new Error(`Command ${baseCmd} not found in args`);
}
const cmd = process.argv[startIndex + 1];
if (cmds.has(cmd)) {
cmds.get(cmd)?.exec(getArgs(startIndex + 2));
} else {
throw new Error(`Command ${cmd} not supported`);
}

76
bin/cli/worker/cli.worker.js

@ -0,0 +1,76 @@
const fs = require('fs');
const path = require('path');
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)
.forEach(name => {
if (typeof structure[name] === 'object') {
fs.mkdirSync(path.resolve(root, name));
scanAndCreate(structure[name], workerName, path.resolve(root, `./${name}`));
} else if (structure[name] === '') {
fs.appendFileSync(path.resolve(root, name), '');
} else if (typeof structure[name] === 'string') {
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);
}
});
}
module.exports = {
exec: async args => {
if (!args.init) {
throw new Error(`Command init not found in args`);
}
if (!args.name) {
throw new Error('Command --name=... not found in args');
}
const name = args.name;
const structure = {
[`${name}_worker`]: {
'main_thread': {
action: {
'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: {
'action_type.ts': path.resolve(__dirname, './template/utils/action_type.t'),
'payload_type.ts': path.resolve(__dirname, './template/utils/payload_type.t'),
},
'worker_thread': {
action: {
'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, name);
},
};
// 结构
// -xxx_worker
// -|--main_thread
// -|--|--action
// -|--|--xxx_main_thread.ts
// -|--utils
// -|--|--action_type.ts
// -|--worker_thread
// -|--|--action
// -|--|--worker_main_thread.ts

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

@ -0,0 +1,45 @@
import { ${WorkerName}MainThreadWorker } from './main_thread/${workerName}_main_thread';
// 不需要一起打包的话则不需要引入这行
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比如补充一些环境信息到参数里
* @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();
}
}

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);

700
demo/js/base/button/demo.button.js

@ -4,416 +4,310 @@ Demo.Button = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var items = [{ var items = [{
el: { type: "bi.button",
type: "bi.button", text: "一般按钮",
text: "一般按钮", level: "common",
level: "common", height: 30
height: 30 }, {
} type: "bi.button",
}, { text: "表示成功状态按钮",
el: { level: "success",
type: "bi.button", height: 30
text: "表示成功状态按钮", }, {
level: "success", type: "bi.button",
height: 30 text: "表示警告状态的按钮",
} level: "warning",
}, { height: 30
el: { }, {
type: "bi.button", type: "bi.button",
text: "表示警告状态的按钮", text: "表示错误状态的按钮",
level: "warning", level: "error",
height: 30 height: 30
} }, {
}, { type: "bi.button",
el: { text: "表示忽略状态的按钮",
type: "bi.button", level: "ignore",
text: "表示错误状态的按钮", height: 30
level: "error", }, {
height: 30 type: "bi.button",
} text: "普通灰化按钮",
}, { disabled: true,
el: { level: "success",
type: "bi.button", height: 30
text: "表示忽略状态的按钮", }, {
level: "ignore", type: "bi.button",
height: 30 text: "忽略状态灰化按钮",
} disabled: true,
}, { level: "ignore",
el: { height: 30
type: "bi.button", }, {
text: "普通灰化按钮", type: "bi.button",
disabled: true, text: "带图标的按钮",
level: "success", // level: 'ignore',
height: 30 iconCls: "close-font",
} height: 30
}, { }, {
el: { type: "bi.button",
type: "bi.button", text: "一般按钮",
text: "忽略状态灰化按钮", block: true,
disabled: true, level: "common",
level: "ignore", height: 30
height: 30 }, {
} type: "bi.button",
}, { text: "表示成功状态按钮",
el: { block: true,
type: "bi.button", level: "success",
text: "带图标的按钮", height: 30
// level: 'ignore', }, {
iconCls: "close-font", type: "bi.button",
height: 30 text: "表示警告状态的按钮",
} block: true,
}, { level: "warning",
el: { height: 30
type: "bi.button", }, {
text: "一般按钮", type: "bi.button",
block: true, text: "表示忽略状态的按钮",
level: "common", block: true,
height: 30 level: "ignore",
} height: 30
}, { }, {
el: { type: "bi.button",
type: "bi.button", text: "普通灰化按钮",
text: "表示成功状态按钮", block: true,
block: true, disabled: true,
level: "success", level: "success",
height: 30 height: 30
} }, {
}, { type: "bi.button",
el: { text: "忽略状态灰化按钮",
type: "bi.button", block: true,
text: "表示警告状态的按钮", disabled: true,
block: true, level: "ignore",
level: "warning", height: 30
height: 30 }, {
} type: "bi.button",
}, { text: "带图标的按钮",
el: { block: true,
type: "bi.button", // level: 'ignore',
text: "表示忽略状态的按钮", iconCls: "close-font",
block: true, height: 30
level: "ignore", }, {
height: 30 type: "bi.button",
} text: "一般按钮",
}, { clear: true,
el: { level: "common",
type: "bi.button", height: 30
text: "普通灰化按钮", }, {
block: true, type: "bi.button",
disabled: true, text: "表示成功状态按钮",
level: "success", clear: true,
height: 30 level: "success",
} height: 30
}, { }, {
el: { type: "bi.button",
type: "bi.button", text: "表示警告状态的按钮",
text: "忽略状态灰化按钮", clear: true,
block: true, level: "warning",
disabled: true, height: 30
level: "ignore", }, {
height: 30 type: "bi.button",
} text: "表示忽略状态的按钮",
}, { clear: true,
el: { level: "ignore",
type: "bi.button", height: 30
text: "带图标的按钮", }, {
block: true, type: "bi.button",
// level: 'ignore', text: "普通灰化按钮",
iconCls: "close-font", clear: true,
height: 30 disabled: true,
} level: "success",
}, { height: 30
el: { }, {
type: "bi.button", type: "bi.button",
text: "一般按钮", text: "忽略状态灰化按钮",
clear: true, clear: true,
level: "common", disabled: true,
height: 30 level: "ignore",
} height: 30
}, { }, {
el: { type: "bi.button",
type: "bi.button", text: "带图标的按钮",
text: "表示成功状态按钮", clear: true,
clear: true, // level: 'ignore',
level: "success", iconCls: "close-font",
height: 30 height: 30
} }, {
}, { type: "bi.text_button",
el: { text: "文字按钮",
type: "bi.button", height: 30
text: "表示警告状态的按钮", }, {
clear: true, type: "bi.button",
level: "warning", text: "幽灵按钮(common)",
height: 30 ghost: true,
} height: 30
}, { }, {
el: { type: "bi.button",
type: "bi.button", iconCls: "plus-font",
text: "表示忽略状态的按钮", text: "幽灵按钮(common)",
clear: true, ghost: true,
level: "ignore", height: 30
height: 30 }, {
} type: "bi.button",
}, { iconCls: "plus-font",
el: { text: "幽灵按钮(common)",
type: "bi.button", ghost: true,
text: "普通灰化按钮", level: "warning",
clear: true, height: 30
disabled: true, }, {
level: "success", type: "bi.button",
height: 30 iconCls: "plus-font",
} text: "幽灵按钮(common)",
}, { ghost: true,
el: { level: "error",
type: "bi.button", height: 30
text: "忽略状态灰化按钮", }, {
clear: true, type: "bi.button",
disabled: true, iconCls: "plus-font",
level: "ignore", text: "幽灵按钮(common)",
height: 30 ghost: true,
} level: "success",
}, { height: 30
el: { }, {
type: "bi.button", type: "bi.button",
text: "带图标的按钮", text: "幽灵按钮(common)灰化",
clear: true, disabled: true,
// level: 'ignore', ghost: true,
iconCls: "close-font", height: 30
height: 30 }, {
} type: "bi.button",
}, { text: "弹出bubble",
el: { bubble: function () {
type: "bi.text_button", return BI.parseInt(Math.random() * 100) % 10 + "提示"
text: "文字按钮", },
height: 30 handler: function () {
} BI.Msg.toast("1111");
}, { },
el: { height: 30
type: "bi.button", }, {
text: "幽灵按钮(common)", type: "bi.button",
ghost: true, text: "图标在上面的按钮,而且可以自动撑开高度",
height: 30 iconCls: "close-font",
} iconGap: 24,
}, { iconPosition: "top"
el: {
type: "bi.button",
iconCls: "plus-font",
text: "幽灵按钮(common)",
ghost: true,
height: 30
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "幽灵按钮(common)",
ghost: true,
level: "warning",
height: 30
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "幽灵按钮(common)",
ghost: true,
level: "error",
height: 30
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "幽灵按钮(common)",
ghost: true,
level: "success",
height: 30
}
}, {
el: {
type: "bi.button",
text: "幽灵按钮(common)灰化",
disabled: true,
ghost: true,
height: 30
}
}, {
el: {
type: "bi.button",
text: "弹出bubble",
bubble: function () {
return BI.parseInt(Math.random() * 100) % 10 + "提示"
},
handler: function () {
BI.Msg.toast("1111");
},
height: 30
}
}, {
el: {
type: "bi.button",
text: "图标在上面的按钮,而且可以自动撑开高度",
iconCls: "close-font",
iconGap: 24,
iconPosition: "top"
}
},{ },{
el: { type: "bi.button",
type: "bi.button", text: "自动撑开高度",
text: "自动撑开高度", iconCls: "close-font",
iconCls: "close-font", textHeight: 32,
textHeight: 32, iconGap: 24,
iconGap: 24, vgap: 16,
vgap: 16, hgap: 100,
hgap: 100, iconPosition: "top"
iconPosition: "top" }, {
} type: "bi.button",
}, { text: "图标在下面的按钮",
el: { iconCls: "close-font",
type: "bi.button", iconPosition: "bottom"
text: "图标在下面的按钮", }, {
iconCls: "close-font", type: "bi.button",
iconPosition: "bottom" text: "图标在左边的按钮",
} iconCls: "close-font",
}, { iconPosition: "left"
el: { }, {
type: "bi.button", type: "bi.button",
text: "图标在左边的按钮", text: "图标在右边的按钮",
iconCls: "close-font", iconCls: "close-font",
iconPosition: "left" iconPosition: "right"
} }, {
}, { type: "bi.button",
el: { text: "浅色的一般按钮",
type: "bi.button", iconCls: "plus-font",
text: "图标在右边的按钮", light: true
iconCls: "close-font", }, {
iconPosition: "right" type: "bi.button",
} text: "浅色的成功按钮",
}, { level: "success",
el: { iconCls: "plus-font",
type: "bi.button", light: true
text: "浅色的一般按钮", }, {
iconCls: "plus-font", type: "bi.button",
light: true text: "浅色的警告按钮",
} level: "warning",
}, { iconCls: "plus-font",
el: { light: true
type: "bi.button", }, {
text: "浅色的成功按钮", type: "bi.button",
level: "success", iconCls: "plus-font",
iconCls: "plus-font", text: "浅色的失败按钮",
light: true level: "error",
} cls: "hover-mask",
}, { light: true
el: { }, {
type: "bi.button", type: "bi.button",
text: "浅色的警告按钮", iconCls: "plus-font",
level: "warning", text: "朴素的按钮",
iconCls: "plus-font", level: "common",
light: true plain: true
} }, {
}, { type: "bi.button",
el: { iconCls: "plus-font",
type: "bi.button", text: "朴素的按钮",
iconCls: "plus-font", level: "success",
text: "浅色的失败按钮", plain: true
level: "error", }, {
cls: "hover-mask", type: "bi.button",
light: true iconCls: "plus-font",
} text: "朴素的按钮",
}, { level: "error",
el: { plain: true
type: "bi.button", }, {
iconCls: "plus-font", type: "bi.button",
text: "朴素的按钮", iconCls: "plus-font",
level: "common", text: "朴素的按钮",
plain: true level: "warning",
} plain: true
}, { }, {
el: { type: "bi.button",
type: "bi.button", iconCls: "plus-font",
iconCls: "plus-font", text: "朴素的按钮",
text: "朴素的按钮", level: "ignore",
level: "success", plain: true
plain: true }, {
} type: "bi.button",
}, { iconCls: "plus-font",
el: { plain: true,
type: "bi.button", level: "error",
iconCls: "plus-font", }, {
text: "朴素的按钮", type: "bi.button",
level: "error", iconCls: "plus-font",
plain: true text: "朴素的按钮",
} plain: true,
}, { disabled: true
el: { }, {
type: "bi.button", type: "bi.button",
iconCls: "plus-font", iconCls: "plus-font",
text: "朴素的按钮", text: "点我,更改图标",
level: "warning", handler() {
plain: true 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"];
}, { if(this.i >= arr.length) {
el: { this.i = 0;
type: "bi.button", }
iconCls: "plus-font", this.setIcon(arr[this.i]);
text: "朴素的按钮", },
level: "ignore", height: 24
plain: true
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "朴素的按钮",
level: "ignore",
plain: true,
disabled: true
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "朴素的按钮",
level: "error",
plain: true,
disabled: true
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "朴素的按钮",
level: "common",
plain: true,
disabled: true
}
}, {
el: {
type: "bi.button",
iconCls: "plus-font",
text: "点我,更改图标",
handler() {
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"];
if(this.i >= arr.length) {
this.i = 0;
}
this.setIcon(arr[this.i]);
},
height: 24
}
}]; }];
// BI.each(items, function (i, item) {
// item.el.handler = function () {
// BI.Msg.alert("按钮", this.options.text);
// };
// });
return { return {
type: "bi.left", type: "bi.left",
scrolly: true, scrolly: true,
vgap: 100, vgap: 100,
hgap: 20, hgap: 20,
items: items items: BI.map(items, function (index, value) {
return {
el: value
}
})
}; };
} }
}); });

20
demo/js/base/tip/demo.title.js

@ -30,6 +30,26 @@ Demo.Title = BI.inherit(BI.Widget, {
warningTitle: "自定义title提示效果", warningTitle: "自定义title提示效果",
text: "自定义title提示效果", text: "自定义title提示效果",
textAlign: "center" textAlign: "center"
}, {
type: "bi.label",
cls: "layout-bg3",
height: 50,
title: () => "函数返回值作为title提示",
text: "title提示支持函数",
textAlign: "center"
}, {
type: "bi.label",
cls: "layout-bg4",
height: 50,
title: function () {
return {
level: "success",
text: "自定义title\n提示效果",
textAlign: "center"
};
},
text: "title提示支持对象,作为bi.tooltip的props",
textAlign: "center"
}], }],
hgap: 300, hgap: 300,
vgap: 20 vgap: 20

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

15
examples/worker_new.html

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="http://fanruan.design/fineui/2.0/fineui.min.css" />
<script src="http://fanruan.design/fineui/2.0/fineui.min.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script src="./worker_new/index.js"></script>
</body>
</html>

105
examples/worker_new/index.js

@ -0,0 +1,105 @@
document.cookie = "test=demo";
// worker获取主线程资源
var CookieAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {
this.controller.addActionHandler("Cookie", this.getCookie.bind(this));
},
getCookie: function() {
return document.cookie;
}
});
// 调用worker计算
var FibonacciAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {},
getResult: function(times) {
return this.controller.requestPromise("Fibonacci", { times: times })
.then(function(v) {
console.log(v);
});
}
});
// 主线程与worker多次交互
const HeartBeatCheckAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {
this.controller.addActionHandler("HeartBeatChecked", this.recieveHeartBeatChecked.bind(this));
},
recieveHeartBeatChecked: function (payload) {
console.log("heartbeat: " + payload.time);
},
startHeatBeatCheck: function() {
return this.controller.request("HeartBeatCheckStart");
},
stopHeatBeatCheck: function() {
return this.controller.request("HeartBeatCheckStop");
}
});
var MainThreadWorker = BI.inherit(BI.Workers.MainThreadWorker, {
initActions: function() {
this.cookieAction = this.createAction(CookieAction);
this.fibonacciAction = this.createAction(FibonacciAction);
this.heartBeatCheckAction = this.createAction(HeartBeatCheckAction);
},
calculateFibonacci: function(times) {
this.fibonacciAction.getResult(times);
},
startHeatBeatCheck: function() {
this.heartBeatCheckAction.startHeatBeatCheck();
},
stopHeatBeatCheck: function() {
this.heartBeatCheckAction.stopHeatBeatCheck();
}
});
var mainThreadWorker = BI.Workers.createWorker(MainThreadWorker, {
workerUrl: "./worker_new/worker.js",
workerName: "demo"
});
BI.createWidget({
type: "bi.vertical",
element: "#wrapper",
vgap: 10,
hgap: 10,
items: [
{
type: "bi.button",
text: "点击计算斐波那契数列第40项",
width: 200,
handler: function() {
console.log("click");
mainThreadWorker.calculateFibonacci(40);
}
},
{
type: "bi.button",
text: "开始心跳",
width: 200,
handler: function() {
mainThreadWorker.startHeatBeatCheck();
}
},
{
type: "bi.button",
text: "停止心跳",
width: 200,
handler: function() {
mainThreadWorker.stopHeatBeatCheck();
}
}
]
});

80
examples/worker_new/worker.js

@ -0,0 +1,80 @@
self.importScripts("https://fanruan.design/fineui/fineui_without_jquery_polyfill.js");
var CookieAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {},
getCookie: function() {
return this.controller.requestPromise("Cookie");
}
});
function fibonacci(n) {
if (n === 1 || n === 2) {
return 1;
}
return fibonacci(n - 2) + fibonacci(n - 1);
}
var FibonacciAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {
this.controller.addActionHandler("Fibonacci", this.getResult.bind(this));
},
getResult: function(payload) {
return fibonacci(payload.times);
}
});
const HeartBeatCheckAction = BI.inherit(BI.Workers.WorkerBaseAction, {
addActionHandler: function() {
this.controller.addActionHandler("HeartBeatCheckStart", this.startHeatBeatCheck.bind(this));
this.controller.addActionHandler("HeartBeatCheckStop", this.stopHeatBeatCheck.bind(this));
},
startHeatBeatCheck: function() {
var self = this;
if (!this.timer) {
console.log("heart beat check started");
this.timer = setInterval(function() {
// 模拟请求
setTimeout(function() {
self.controller.request("HeartBeatChecked", {
time: new Date()
});
}, 50);
}, 5 * 1000);
} else {
console.log("heart beat has already started!");
}
},
stopHeatBeatCheck: function() {
console.log("heart beat check stopped");
clearInterval(this.timer);
}
});
var MainThreadWorker = BI.inherit(BI.Workers.WorkerThreadWorker, {
initActions: function() {
this.cookieAction = this.createAction(CookieAction);
this.fibonacciAction = this.createAction(FibonacciAction);
this.heartBeatCheckAction = this.createAction(HeartBeatCheckAction);
},
fetchCookie: function() {
return this.cookieAction.getCookie()
.then(function (v) {
console.log(v);
});
}
});
var workerThreadWorker = BI.Workers.createWorker(MainThreadWorker);
workerThreadWorker.fetchCookie();

104
examples/替换loading动画.html

@ -0,0 +1,104 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="https://fanruan.design/fineui/2.0/fineui_without_normalize.css" />
<!-- <script src="/fineui.js"></script> -->
<script src="https://fanruan.design/fineui/2.0/fineui.js"></script>
</head>
<body>
<div id="wrapper"></div>
<script>
var LoadingPane = BI.inherit(BI.Pane, {});
BI.shortcut("demo.loading_pane", LoadingPane);
var loadingPane;
BI.createWidget({
type: "bi.vertical",
element: "#wrapper",
items: [{
type: "bi.vertical",
items: [{
type: "demo.loading_pane",
width: 800,
height: 600,
cls: "bi-border",
ref: function(ref) {
loadingPane = ref;
},
}, {
type: "bi.left",
rgap: 10,
items: [{
type: "bi.button",
text: "开始loading",
handler: function () {
loadingPane.loading();
},
}, {
type: "bi.button",
text: "停止loading",
handler: function () {
loadingPane.loaded();
},
}, {
type: "bi.button",
text: "设置文字loading",
handler: function () {
BI.config("bi.provider.system", function (provider) {
provider.setLoadingCreator(function () {
return {
type: "bi.label",
text: "我是被替换了的loading"
};
});
});
},
}, {
type: "bi.button",
text: "恢复波浪线loading",
handler: function () {
BI.config("bi.provider.system", function (provider) {
provider.setLoadingCreator(function () {
return {
type: "bi.horizontal",
cls: "bi-loading-widget",
height: 30,
width: 30,
hgap: 5,
vgap: 2.5,
items: [{
type: "bi.layout",
cls: "animate-rect rect1",
height: 25,
width: 2.5
}, {
type: "bi.layout",
cls: "animate-rect rect2",
height: 25,
width: 2.5
}, {
type: "bi.layout",
cls: "animate-rect rect3",
height: 25,
width: 2.5
}]
};
});
});
},
}]
}],
}],
});
</script>
</body>
</html>

9
package.json

@ -1,14 +1,17 @@
{ {
"name": "fineui", "name": "fineui",
"version": "2.0.20220623215302", "version": "2.0.20220727111551",
"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",
"bin": {
"fui-cli": "./bin/cli/cli.js"
},
"devDependencies": { "devDependencies": {
"@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.11", "@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",
@ -47,7 +50,7 @@
"source-map-loader": "0.2.4", "source-map-loader": "0.2.4",
"style-loader": "0.23.1", "style-loader": "0.23.1",
"terser-webpack-plugin": "4.2.3", "terser-webpack-plugin": "4.2.3",
"typescript": "3.5.2", "typescript": "3.9.2",
"webpack": "4.35.2", "webpack": "4.35.2",
"webpack-cli": "3.3.5", "webpack-cli": "3.3.5",
"webpack-dev-server": "3.7.2", "webpack-dev-server": "3.7.2",

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,
};

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

@ -0,0 +1,45 @@
/*
* worker-plugin
*/
const path = require('path');
const webpack = require('webpack');
const { WorkerPluginName } = require('./constants');
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');
});
}
}
module.exports = FuiWorkerPlugin;

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

@ -0,0 +1,109 @@
/*
* fui-worker worker-loader
*/
const webpack = require('webpack');
const loaderUtils = require('loader-utils');
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
const { WorkerLoaderName, FileNamePrefix } = require('./constants');
// 正常 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
loaderUtils.getOptions(this) || {};
// 创建 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);
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);
}
return callback(
null,
// 插入代码的转译和压缩由主构建配置的 babel/ts loader 处理, 不需要 worker-worker 来处理
// 添加 @ts-nocheck 避免 ts-check 报错
`// @ts-nocheck
const servicePath = __webpack_public_path__ + ${JSON.stringify(entry)};
export const workerUrl = servicePath;
`
);
});
return;
}
module.exports = loader;

27
src/base/1.pane.js

@ -40,30 +40,9 @@ BI.Pane = BI.inherit(BI.Widget, {
loading: function () { loading: function () {
var self = this, o = this.options; var self = this, o = this.options;
var isIE = BI.isIE(); var loadingAnimation = BI.Providers.getProvider("bi.provider.system").getLoading({
var loadingAnimation = BI.createWidget({ loadingSize: o.loadingSize,
type: "bi.horizontal", context: this
cls: "bi-loading-widget" + (isIE ? " wave-loading hack" : ""),
height: this._getSize(60),
width: this._getSize(60),
hgap: this._getSize(10),
vgap: 2.5,
items: isIE ? [] : [{
type: "bi.layout",
cls: "animate-rect rect1",
height: this._getSize(50),
width: this._getSize(5)
}, {
type: "bi.layout",
cls: "animate-rect rect2",
height: this._getSize(50),
width: this._getSize(5)
}, {
type: "bi.layout",
cls: "animate-rect rect3",
height: this._getSize(50),
width: this._getSize(5)
}]
}); });
// pane在同步方式下由items决定tipText的显示与否 // pane在同步方式下由items决定tipText的显示与否
// loading的异步情况下由loaded后对面板的populate的时机决定 // loading的异步情况下由loaded后对面板的populate的时机决定

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

@ -197,7 +197,7 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
items = this._packageItems(items, this._packageBtns(this.buttons)); items = this._packageItems(items, this._packageBtns(this.buttons));
} }
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items))); this.layouts = BI.createWidget(BI.extend({ element: this }, this._packageLayout(items)));
}, },
setNotSelectedValue: function (v) { setNotSelectedValue: function (v) {
@ -233,6 +233,23 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
}); });
}, },
setValueMap: function (map) {
map = map || {};
BI.each(this.buttons, function (i, item) {
if (BI.isNotNull(map[item.getValue()])) {
item.setSelected && item.setSelected(true);
} else {
item.setSelected && item.setSelected(false);
}
});
},
setAllSelected: function (v) {
BI.each(this.getAllButtons(), function (i, btn) {
(btn.setSelected || btn.setAllSelected).apply(btn, [v]);
});
},
getNotSelectedValue: function () { getNotSelectedValue: function () {
var v = []; var v = [];
BI.each(this.buttons, function (i, item) { BI.each(this.buttons, function (i, item) {
@ -314,6 +331,16 @@ BI.ButtonGroup = BI.inherit(BI.Widget, {
return node; return node;
}, },
/**
* 滚动到指定的节点
*/
scrollToValue: function (value, scrollIntoViewOptions) {
var node = this.getNodeByValue(value);
if (node) {
node.element[0].scrollIntoView(scrollIntoViewOptions);
}
},
empty: function () { empty: function () {
BI.ButtonGroup.superclass.empty.apply(this, arguments); BI.ButtonGroup.superclass.empty.apply(this, arguments);
this.options.items = []; this.options.items = [];

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

@ -96,6 +96,20 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
return v; return v;
}, },
getNodeByValue: function (value) {
return this.buttonMap[value];
},
/**
* 滚动到指定的节点
*/
scrollToValue: function (value, scrollIntoViewOptions) {
var node = this.getNodeByValue(value);
if (node) {
node.element[0].scrollIntoView(scrollIntoViewOptions);
}
},
getValue: function () { getValue: function () {
var v = []; var v = [];
BI.each(this.buttonMap, function (i, item) { BI.each(this.buttonMap, function (i, item) {
@ -113,7 +127,7 @@ BI.VirtualGroup = BI.inherit(BI.Widget, {
this.options.items = items; this.options.items = items;
items = this._packageBtns(items); items = this._packageBtns(items);
if (!this.layouts) { if (!this.layouts) {
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

23
src/base/combination/tab.js

@ -86,15 +86,18 @@ BI.Tab = BI.inherit(BI.Widget, {
created: function () { created: function () {
var self = this, o = this.options; var self = this, o = this.options;
if (o.showIndex !== false) {
if (BI.isFunction(o.showIndex)) { var showIndex;
var v = this.__watch(o.showIndex, function (context, newValue) { if (BI.isFunction(o.showIndex)) {
self.setSelect(newValue); showIndex = this.__watch(o.showIndex, function (context, newValue) {
}); self.setSelect(newValue);
this.setSelect(v); });
} else { } else {
this.setSelect(o.showIndex); showIndex = o.showIndex;
} }
if (showIndex !== false) {
this.setSelect(showIndex);
} }
}, },
@ -135,7 +138,7 @@ BI.Tab = BI.inherit(BI.Widget, {
getTab: function (v) { getTab: function (v) {
this._assertCard(v); this._assertCard(v);
return this.layout.getCardByName(v); return this.layout.getCardByName(v);
}, },
setValue: function (v) { setValue: function (v) {

10
src/base/foundation/message.js

@ -22,7 +22,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,7 +41,7 @@ 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();
@ -62,16 +62,16 @@ BI.Msg = function () {
}] }]
}); });
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) {

23
src/base/layer/layer.drawer.js

@ -154,22 +154,22 @@ 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;
} }
@ -180,17 +180,26 @@ BI.Drawer = BI.inherit(BI.Widget, {
hide: function (callback) { hide: function (callback) {
var self = this, o = this.options; var self = this, o = this.options;
requestAnimationFrame(function () { requestAnimationFrame(function () {
var size = self._getSuitableSize();
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;
} }
@ -213,7 +222,7 @@ 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 () {

16
src/base/list/listview.js

@ -1,5 +1,5 @@
/** /**
* 表示当前对象 * 边滚动边加载的列表控件
* *
* Created by GUY on 2017/5/23. * Created by GUY on 2017/5/23.
* @class BI.ListView * @class BI.ListView
@ -33,8 +33,8 @@ BI.ListView = BI.inherit(BI.Widget, {
items: [BI.extend({ items: [BI.extend({
type: "bi.vertical", type: "bi.vertical",
scrolly: false, scrolly: false,
ref: function () { ref: function (_ref) {
self.container = this; self.container = _ref;
} }
}, o.el)], }, o.el)],
element: this element: this
@ -69,8 +69,8 @@ BI.ListView = BI.inherit(BI.Widget, {
var self = this, o = this.options; var self = this, o = this.options;
var height = this.element.height(); var height = this.element.height();
var minContentHeight = o.scrollTop + height + o.overscanHeight; var minContentHeight = o.scrollTop + height + o.overscanHeight;
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;
cnt = this.renderedIndex + 1; var cnt = this.renderedIndex + 1;
var lastHeight; var lastHeight;
var getElementHeight = function () { var getElementHeight = function () {
return self.container.element.height(); return self.container.element.height();
@ -112,6 +112,12 @@ BI.ListView = BI.inherit(BI.Widget, {
this.cache = {}; this.cache = {};
}, },
scrollTo: function (scrollTop) {
this.options.scrollTop = scrollTop;
this._calculateBlocksToRender();
this.element.scrollTop(scrollTop);
},
populate: function (items) { populate: function (items) {
if (items && this.options.items !== items) { if (items && this.options.items !== items) {
this.restore(); this.restore();

13
src/base/list/virtualgrouplist.js

@ -62,7 +62,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
}) : o.items; }) : o.items;
this._populate(); this._populate();
this.ticking = false; this.ticking = false;
this.element.scroll(function() { this.element.scroll(function () {
o.scrollTop = self.element.scrollTop(); o.scrollTop = self.element.scrollTop();
if (!self.ticking) { if (!self.ticking) {
requestAnimationFrame(function () { requestAnimationFrame(function () {
@ -123,7 +123,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
} }
this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - this.tree.sumTo(Math.min(end, this.renderedIndex))); this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - this.tree.sumTo(Math.min(end, this.renderedIndex)));
this.container.populate(items.map(function (item, i) { this.container.populate(items.map(function (item, i) {
return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i) return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i);
})); }));
} else { } else {
for (var i = (start < 0 ? 0 : start); i <= end; i++) { for (var i = (start < 0 ? 0 : start); i <= end; i++) {
@ -134,7 +134,7 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
} }
this.container.element.height(o.rowHeight * o.items.length - topHeight); this.container.element.height(o.rowHeight * o.items.length - topHeight);
this.container.populate(items.map(function (item, i) { this.container.populate(items.map(function (item, i) {
return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i) return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i);
})); }));
} }
}, },
@ -162,6 +162,13 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
this.bottomBlank.setHeight(0); this.bottomBlank.setHeight(0);
}, },
// 暂时只支持固定行高的场景
scrollTo: function (scrollTop) {
this.options.scrollTop = scrollTop;
this._calculateBlocksToRender();
this.element.scrollTop(scrollTop);
},
restore: function () { restore: function () {
this.options.scrollTop = 0; this.options.scrollTop = 0;
this._restore(); this._restore();

9
src/base/list/virtuallist.js

@ -46,7 +46,6 @@ BI.VirtualList = BI.inherit(BI.Widget, {
self.bottomBlank = this; self.bottomBlank = this;
} }
}], }],
element: this
}; };
}, },
@ -78,7 +77,7 @@ BI.VirtualList = BI.inherit(BI.Widget, {
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { while ((lastHeight = getElementHeight()) < 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);
}), this); }), this);
var addedHeight = getElementHeight() - lastHeight; var addedHeight = getElementHeight() - lastHeight;
this.tree.set(cnt, addedHeight); this.tree.set(cnt, addedHeight);
@ -177,6 +176,12 @@ BI.VirtualList = BI.inherit(BI.Widget, {
this.container.attr("items", []); this.container.attr("items", []);
}, },
scrollTo: function (scrollTop) {
this.options.scrollTop = scrollTop;
this._calculateBlocksToRender();
this.element.scrollTop(scrollTop);
},
restore: function () { restore: function () {
this.renderedIndex = -1; this.renderedIndex = -1;
this._clearChildren(); this._clearChildren();

35
src/base/single/0.single.js

@ -9,6 +9,9 @@
* @extends BI.Widget * @extends BI.Widget
* @abstract * @abstract
*/ */
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);
@ -17,17 +20,29 @@ BI.Single = BI.inherit(BI.Widget, {
title: null, title: null,
warningTitle: null, warningTitle: null,
tipType: null, // success或warning tipType: null, // success或warning
belowMouse: false // title是否跟随鼠标 belowMouse: false, // title是否跟随鼠标
enableHover: false
}); });
}, },
_showToolTip: function (e, opt) { _showToolTip: function (e, opt) {
opt || (opt = {}); opt || (opt = {});
var self = this, o = this.options; var o = this.options;
var type = this.getTipType() || (this.isEnabled() ? "success" : "warning"); var tooltipOpt = {};
var title = type === "success" ? this.getTitle() : (this.getWarningTitle() || this.getTitle()); var title = this.getTitle();
if (BI.isKey(title)) { if (BI.isPlainObject(title)) {
BI.Tooltips.show(e, this.getName(), title, type, this, opt); tooltipOpt = title;
} else {
tooltipOpt.level = this.getTipType() || "success";
// 由于以前的用法,存在大量disabled:true搭配warningTitle的情况,所以这里做一个兼容,disabled:true的情况下,依然优先显示warningTitle,避免只设置了warningTitle而没有设置title的情况
if (BI.isNull(o.tipType) && !this.isEnabled()) {
tooltipOpt.text = (this.getWarningTitle() || title);
} else {
tooltipOpt.text = tooltipOpt.level === "success" ? title : (this.getWarningTitle() || title);
}
}
if (BI.isKey(tooltipOpt.text)) {
BI.Tooltips.show(e, this.getName(), tooltipOpt, this, opt);
if (o.action) { if (o.action) {
BI.Actions.runAction(o.action, "hover", o, this); BI.Actions.runAction(o.action, "hover", o, this);
} }
@ -51,7 +66,7 @@ BI.Single = BI.inherit(BI.Widget, {
self.setValue(newValue); self.setValue(newValue);
}) : o.value; }) : o.value;
BI.Single.superclass._init.apply(this, arguments); BI.Single.superclass._init.apply(this, arguments);
if (BI.isKey(o.title) || BI.isKey(o.warningTitle) if (o.enableHover || BI.isKey(o.title) || BI.isKey(o.warningTitle)
|| 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,
@ -78,14 +93,16 @@ BI.Single = BI.inherit(BI.Widget, {
this.element.on("mouseenter.title" + this.getName(), function (e) { this.element.on("mouseenter.title" + this.getName(), function (e) {
self._e = e; self._e = e;
if (self.getTipType() === "warning" || (BI.isKey(self.getWarningTitle()) && !self.isEnabled())) { if (self.getTipType() === "warning" || (BI.isKey(self.getWarningTitle()) && !self.isEnabled())) {
delayingTooltips = self.getName();
self.showTimeout = BI.delay(function () { self.showTimeout = BI.delay(function () {
if (BI.isNotNull(self.showTimeout)) { if (BI.isNotNull(self.showTimeout) && delayingTooltips === self.getName()) {
self._showToolTip(self._e || e, opt); self._showToolTip(self._e || e, opt);
} }
}, 200); }, 200);
} else if (self.getTipType() === "success" || self.isEnabled()) { } else if (self.getTipType() === "success" || self.isEnabled()) {
delayingTooltips = self.getName();
self.showTimeout = BI.delay(function () { self.showTimeout = BI.delay(function () {
if (BI.isNotNull(self.showTimeout)) { if (BI.isNotNull(self.showTimeout) && delayingTooltips === self.getName()) {
self._showToolTip(self._e || e, opt); self._showToolTip(self._e || e, opt);
} }
}, 500); }, 500);

45
src/base/single/button/buttons/button.js

@ -24,18 +24,20 @@
if (isVertical(props.iconPosition)) { if (isVertical(props.iconPosition)) {
// 图标高度和文字高度默认相等 // 图标高度和文字高度默认相等
adaptiveHeight += (props.textHeight || 16) * 2; adaptiveHeight += (props.textHeight || 16) * 2;
adaptiveHeight += props.iconGap || 4; adaptiveHeight += props.iconGap || 0;
var tGap = props.tgap || props.vgap || 2; var tGap = props.tgap || props.vgap || 2;
var bGap = props.bgap || props.vgap || 2; var bGap = props.bgap || props.vgap || 2;
adaptiveHeight += (tGap + bGap); adaptiveHeight += (tGap + bGap);
} }
var clearMinWidth = props.block === true || props.clear === true || props.plain;
return BI.extend(conf, { return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""), baseCls: (conf.baseCls || "") + " bi-button" + ((BI.isIE() && BI.isIE9Below()) ? " hack" : ""),
attributes: { attributes: {
tabIndex: 1 tabIndex: 1
}, },
minWidth: (props.block === true || props.clear === true) ? 0 : 80, minWidth: clearMinWidth ? 0 : 80,
height: isVertical(props.iconPosition) ? adaptiveHeight : 24, height: isVertical(props.iconPosition) ? adaptiveHeight : 24,
shadow: props.clear !== true, shadow: props.clear !== true,
isShadowShowingOnSelected: true, isShadowShowingOnSelected: true,
@ -58,13 +60,13 @@
bgap: 0, bgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
iconGap: 4, iconGap: 0,
iconPosition: "left" iconPosition: "left"
}); });
}, },
render: function () { render: function () {
var o = this.options; var o = this.options, self = this;
// 由于button默认情况下有个边框,所以要主动算行高 // 由于button默认情况下有个边框,所以要主动算行高
var lineHeight, textHeight = o.textHeight; var lineHeight, textHeight = o.textHeight;
@ -110,12 +112,12 @@
tgap: o.iconPosition === "top" ? o.iconGap : 0, tgap: o.iconPosition === "top" ? o.iconGap : 0,
bgap: o.iconPosition === "bottom" ? o.iconGap : 0 bgap: o.iconPosition === "bottom" ? o.iconGap : 0
}; };
var items = [this.icon, BI.extend({el: this.text}, gapContainer)]; var items = [this.icon, BI.extend({ el: this.text }, gapContainer)];
if (isVertical(o.iconPosition)) { if (isVertical(o.iconPosition)) {
layoutType = "bi.vertical"; layoutType = "bi.vertical";
} }
if (o.iconPosition === "right" || o.iconPosition === "bottom") { if (o.iconPosition === "right" || o.iconPosition === "bottom") {
items = [BI.extend({el: this.text}, gapContainer), this.icon]; items = [BI.extend({ el: this.text }, gapContainer), this.icon];
} }
BI.createWidget({ BI.createWidget({
type: "bi.center_adapt", type: "bi.center_adapt",
@ -145,29 +147,20 @@
rgap: o.rgap, rgap: o.rgap,
element: this, element: this,
text: o.text, text: o.text,
value: o.value value: o.value,
title: null,
}); });
} }
if (o.block === true) { var classArr = ["block", "clear", "ghost", "plain", "loading", "light"];
this.element.addClass("block"); // 如果 options 对应的属性为 true 则给元素添加 class
} BI.each(classArr, function (_, clz) {
if (o.clear === true) { if (BI.get(o, clz) === true) {
this.element.addClass("clear"); self.element.addClass(clz);
} }
if (o.ghost === true) { });
this.element.addClass("ghost");
}
if (o.plain === true) {
this.element.addClass("plain");
}
if (o.loading === true) {
this.element.addClass("loading");
}
if (o.light === true) {
this.element.addClass("light");
}
if (o.minWidth > 0) { if (o.minWidth > 0) {
this.element.css({"min-width": o.minWidth / BI.pixRatio + BI.pixUnit}); this.element.css({ "min-width": o.minWidth / BI.pixRatio + BI.pixUnit });
} }
}, },

4
src/base/single/editor/editor.multifile.js

@ -71,6 +71,10 @@ BI.MultifileEditor = BI.inherit(BI.Widget, {
this.file.reset(); this.file.reset();
}, },
setUrl: function (v) {
this.file.setUrl(v);
},
setMaxFileLength: function (v) { setMaxFileLength: function (v) {
this.file.setMaxFileLength(v); this.file.setMaxFileLength(v);
}, },

7
src/base/single/input/file.js

@ -655,6 +655,13 @@
}); });
}, },
setUrl: function(v) {
this.options.url = v;
if (this.wrap) {
this.wrap.url = v;
}
},
setMaxFileLength: function (v) { setMaxFileLength: function (v) {
this.options.maxLength = v; this.options.maxLength = v;
if (this.wrap) { if (this.wrap) {

20
src/base/single/label/abstract.label.js

@ -18,10 +18,27 @@
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
highLight: false, highLight: false,
handler: null handler: null,
enableHover: props.title !== null,
}); });
}, },
getTitle: function () {
var title = this.options.title;
var text = this.options.text;
if (BI.isFunction(title)) {
return title();
}
if (BI.isNotNull(title)) {
return title;
}
if (BI.isFunction(text)) {
return text();
}
return text;
},
_createJson: function () { _createJson: function () {
var o = this.options; var o = this.options;
return { return {
@ -374,6 +391,7 @@
setValue: function (v) { setValue: function (v) {
BI.AbstractLabel.superclass.setValue.apply(this, arguments); BI.AbstractLabel.superclass.setValue.apply(this, arguments);
if (!this.isReadOnly()) { if (!this.isReadOnly()) {
this.options.text = v;
this.text.setValue(v); this.text.setValue(v);
} }
} }

30
src/base/single/tip/tip.toast.js

@ -11,7 +11,6 @@ BI.Toast = BI.inherit(BI.Tip, {
minWidth: 100, minWidth: 100,
closableMaxWidth: 410, closableMaxWidth: 410,
maxWidth: 400, maxWidth: 400,
hgap: 8
}, },
_defaultConfig: function () { _defaultConfig: function () {
@ -21,7 +20,10 @@ BI.Toast = BI.inherit(BI.Tip, {
level: "success", // success或warning level: "success", // success或warning
autoClose: true, autoClose: true,
closable: null, closable: null,
vgap: 7, textHeight: 20,
vgap: 10,
innerHgap: 4,
hgap: 8,
}); });
}, },
@ -46,7 +48,7 @@ BI.Toast = BI.inherit(BI.Tip, {
mouseleave: fn, mouseleave: fn,
mousemove: fn mousemove: fn
}); });
var cls = "close-font"; var cls;
switch (o.level) { switch (o.level) {
case "success": case "success":
cls = "toast-success-font"; cls = "toast-success-font";
@ -72,19 +74,18 @@ BI.Toast = BI.inherit(BI.Tip, {
var items = [{ var items = [{
type: "bi.icon_label", type: "bi.icon_label",
cls: cls + " toast-icon", cls: cls + " toast-icon",
width: 36 height: o.textHeight,
}, { }, {
el: BI.isPlainObject(o.text) ? o.text : { el: BI.isPlainObject(o.text) ? o.text : {
type: "bi.label", type: "bi.label",
whiteSpace: "normal", whiteSpace: "normal",
text: o.text, text: o.text,
textHeight: 16, textHeight: o.textHeight,
textAlign: "left" textAlign: "left"
}, },
rgap: hasCloseIcon() ? 0 : this._const.hgap
}]; }];
var columnSize = [36, "fill"]; var columnSize = ["", "fill"];
if (hasCloseIcon()) { if (hasCloseIcon()) {
items.push({ items.push({
@ -93,23 +94,20 @@ BI.Toast = BI.inherit(BI.Tip, {
handler: function () { handler: function () {
self.destroy(); self.destroy();
}, },
width: 36 height: o.textHeight,
}); });
columnSize.push(36); columnSize.push("");
} }
this.text = BI.createWidget({ return {
type: "bi.horizontal", type: "bi.horizontal",
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: BI.HorizontalAlign.Stretch,
element: this,
items: items, items: items,
hgap: o.hgap,
vgap: o.vgap, vgap: o.vgap,
innerHgap: o.innerHgap,
columnSize: columnSize columnSize: columnSize
}); };
},
setText: function (text) {
this.text.setText(text);
}, },
beforeDestroy: function () { beforeDestroy: function () {

15
src/base/single/tip/tip.tooltip.js

@ -7,8 +7,8 @@
*/ */
BI.Tooltip = BI.inherit(BI.Tip, { BI.Tooltip = BI.inherit(BI.Tip, {
_const: { _const: {
hgap: 5, hgap: 8,
vgap: 3 vgap: 4
}, },
_defaultConfig: function () { _defaultConfig: function () {
@ -17,7 +17,8 @@ BI.Tooltip = BI.inherit(BI.Tip, {
text: "", text: "",
level: "success", // success或warning level: "success", // success或warning
stopEvent: false, stopEvent: false,
stopPropagation: false stopPropagation: false,
textAlign: "left",
}); });
}, },
@ -44,10 +45,11 @@ BI.Tooltip = BI.inherit(BI.Tip, {
type: "bi.vertical", type: "bi.vertical",
element: this, element: this,
hgap: this._const.hgap, hgap: this._const.hgap,
innerVgap: this._const.vgap,
items: BI.map(texts, function (i, text) { items: BI.map(texts, function (i, text) {
return { return {
type: "bi.label", type: "bi.label",
textAlign: "left", textAlign: o.textAlign,
whiteSpace: "normal", whiteSpace: "normal",
text: text, text: text,
textHeight: 18 textHeight: 18
@ -58,11 +60,12 @@ BI.Tooltip = BI.inherit(BI.Tip, {
this.text = BI.createWidget({ this.text = BI.createWidget({
type: "bi.label", type: "bi.label",
element: this, element: this,
textAlign: "left", textAlign: o.textAlign,
whiteSpace: "normal", whiteSpace: "normal",
text: o.text, text: o.text,
textHeight: 18, textHeight: 18,
hgap: this._const.hgap hgap: this._const.hgap,
vgap: this._const.vgap,
}); });
} }
}, },

6
src/case/button/item.multiselect.js

@ -20,11 +20,6 @@ BI.MultiSelectItem = BI.inherit(BI.BasicButton, {
this.checkbox = BI.createWidget({ this.checkbox = BI.createWidget({
type: "bi.checkbox" type: "bi.checkbox"
}); });
this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) {
self.setSelected(self.isSelected());
}
});
return { return {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
columnSize: [o.iconWrapperWidth || o.height, "fill"], columnSize: [o.iconWrapperWidth || o.height, "fill"],
@ -74,7 +69,6 @@ BI.MultiSelectItem = BI.inherit(BI.BasicButton, {
doClick: function () { doClick: function () {
BI.MultiSelectItem.superclass.doClick.apply(this, arguments); BI.MultiSelectItem.superclass.doClick.apply(this, arguments);
this.checkbox.setSelected(this.isSelected());
if (this.isValid()) { if (this.isValid()) {
this.fireEvent(BI.MultiSelectItem.EVENT_CHANGE, this.getValue(), this); this.fireEvent(BI.MultiSelectItem.EVENT_CHANGE, this.getValue(), this);
} }

11
src/case/button/item.singleselect.radio.js

@ -28,16 +28,6 @@ BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, {
ref: function (_ref) { ref: function (_ref) {
self.radio = _ref; self.radio = _ref;
}, },
listeners: [
{
eventName: BI.Controller.EVENT_CHANGE,
action: function (type) {
if (type === BI.Events.CLICK) {
self.setSelected(self.isSelected());
}
}
}
],
}] }]
}, { }, {
el: { el: {
@ -82,7 +72,6 @@ BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, {
doClick: function () { doClick: function () {
BI.SingleSelectRadioItem.superclass.doClick.apply(this, arguments); BI.SingleSelectRadioItem.superclass.doClick.apply(this, arguments);
this.radio.setSelected(this.isSelected());
if (this.isValid()) { if (this.isValid()) {
this.fireEvent(BI.SingleSelectRadioItem.EVENT_CHANGE, this.isSelected(), this); this.fireEvent(BI.SingleSelectRadioItem.EVENT_CHANGE, this.isSelected(), this);
} }

30
src/case/combo/bubblecombo/popup.bubble.js

@ -36,7 +36,9 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, {
}, { }, {
text: BI.i18nText(BI.i18nText("BI-Basic_OK")), text: BI.i18nText(BI.i18nText("BI-Basic_OK")),
value: true value: true
}] }],
innerVgap: 16,
innerHgap: 16,
}); });
}, },
@ -48,8 +50,7 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, {
if (BI.isWidget(buttonOpt)) { if (BI.isWidget(buttonOpt)) {
items.push({ items.push({
el: buttonOpt, el: buttonOpt,
lgap: i === 0 ? 15 : 10, lgap: 12,
rgap: i === o.buttons.length - 1 ? 15 : 0
}); });
} else { } else {
items.push({ items.push({
@ -60,14 +61,14 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, {
self.fireEvent(BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON, v); self.fireEvent(BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON, v);
} }
}, buttonOpt), }, buttonOpt),
lgap: i === 0 ? 15 : 10, lgap: 12,
rgap: i === o.buttons.length - 1 ? 15 : 0
}); });
} }
}); });
return BI.createWidget({ return BI.createWidget({
type: "bi.right_vertical_adapt", type: "bi.right_vertical_adapt",
height: 44, innerVgap: o.innerVgap,
innerHgap: o.innerHgap,
items: items items: items
}); });
}, },
@ -79,20 +80,17 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, {
_createView: function () { _createView: function () {
var o = this.options; var o = this.options;
var button = BI.createWidget({ var view = BI.createWidget({
type: "bi.button_group", type: "bi.vertical",
items: [this._createContent()], items: [this._createContent()],
layouts: [{ cls: "bar-popup-container",
type: "bi.vertical", hgap: o.innerHgap,
cls: "bar-popup-container", tgap: o.innerVgap,
hgap: BI.SIZE_CONSANTS.H_GAP_SIZE,
tgap: BI.SIZE_CONSANTS.V_GAP_SIZE
}]
}); });
button.element.css("min-height", o.minHeight - 44); view.element.css("min-height", o.minHeight);
return button; return view;
} }
}); });
BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON = "EVENT_CLICK_TOOLBAR_BUTTON"; BI.BubblePopupBarView.EVENT_CLICK_TOOLBAR_BUTTON = "EVENT_CLICK_TOOLBAR_BUTTON";

1
src/case/combo/searchtextvaluecombo/combo.searchtextvalue.js

@ -33,7 +33,6 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, {
adjustLength: 2, adjustLength: 2,
height: height, height: height,
width: width, width: width,
toggle: false,
ref: function () { ref: function () {
self.combo = this; self.combo = this;
}, },

4
src/case/combo/searchtextvaluecombo/trigger.searchtextvalue.js

@ -24,10 +24,6 @@ BI.SearchTextValueTrigger = BI.inherit(BI.Trigger, {
}, },
width: o.height, width: o.height,
height: o.height, height: o.height,
stopPropagation: true,
handler: function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.TOGGLE);
}
}; };
var stateText = this._digest(o.value, o.items) || o.text; var stateText = this._digest(o.value, o.items) || o.text;

26
src/case/layer/pane.list.js

@ -47,11 +47,15 @@ BI.ListPane = BI.inherit(BI.Pane, {
} }
o.itemsCreator(op, function () { o.itemsCreator(op, function () {
calback.apply(self, arguments); calback.apply(self, arguments);
op.times === 1 && BI.nextTick(function () { o.items = BI.concat(o.items, BI.get(arguments, [0], []));
self.loaded(); if (op.times === 1) {
// callback可能在loading之前执行, check保证显示正确 o.items = BI.get(arguments, [0], []);
self.check(); BI.nextTick(function () {
}); self.loaded();
// callback可能在loading之前执行, check保证显示正确
self.check();
});
}
}); });
}, },
hasNext: o.hasNext, hasNext: o.hasNext,
@ -113,7 +117,7 @@ BI.ListPane = BI.inherit(BI.Pane, {
populate: function (items) { populate: function (items) {
var self = this, o = this.options; var self = this, o = this.options;
if (arguments.length === 0 && (BI.isFunction(this.button_group.attr("itemsCreator")))) {// 接管loader的populate方法 if (arguments.length === 0 && (BI.isFunction(this.button_group.attr("itemsCreator")))) {// 接管loader的populate方法
this.button_group.attr("itemsCreator").apply(this, [{times: 1}, function () { this.button_group.attr("itemsCreator").apply(this, [{ times: 1 }, function () {
if (arguments.length === 0) { if (arguments.length === 0) {
throw new Error("参数不能为空"); throw new Error("参数不能为空");
} }
@ -150,6 +154,16 @@ BI.ListPane = BI.inherit(BI.Pane, {
this.button_group.setValue.apply(this.button_group, arguments); this.button_group.setValue.apply(this.button_group, arguments);
}, },
setAllSelected: function (v) {
if (this.button_group.setAllSelected) {
this.button_group.setAllSelected(v);
} else {
BI.each(this.getAllButtons(), function (i, btn) {
(btn.setSelected || btn.setAllSelected).apply(btn, [v]);
});
}
},
getValue: function () { getValue: function () {
return this.button_group.getValue.apply(this.button_group, arguments); return this.button_group.getValue.apply(this.button_group, arguments);
}, },

10
src/case/list/list.select.js

@ -113,9 +113,13 @@ BI.SelectList = BI.inherit(BI.Widget, {
}, },
setAllSelected: function (v) { setAllSelected: function (v) {
BI.each(this.getAllButtons(), function (i, btn) { if (this.list.setAllSelected) {
(btn.setSelected || btn.setAllSelected).apply(btn, [v]); this.list.setAllSelected(v);
}); } else {
BI.each(this.getAllButtons(), function (i, btn) {
(btn.setSelected || btn.setAllSelected).apply(btn, [v]);
});
}
this.allSelected = !!v; this.allSelected = !!v;
this.toolbar.setSelected(v); this.toolbar.setSelected(v);
this.toolbar.setHalfSelected(false); this.toolbar.setHalfSelected(false);

2
src/case/ztree/jquery.ztree.core-3.5.js

@ -2017,4 +2017,4 @@
var zt = $.fn.zTree, var zt = $.fn.zTree,
$$ = tools.$, $$ = tools.$,
consts = zt.consts; consts = zt.consts;
})(jQuery); })(BI.jQuery);

23
src/component/allvaluechooser/abstract.allvaluechooser.js

@ -40,6 +40,18 @@ BI.AbstractAllValueChooser = BI.inherit(BI.Widget, {
return text; return text;
}, },
_getItemsByTimes: function (items, times) {
var res = [];
for (var i = (times - 1) * this._const.perPage; items[i] && i < times * this._const.perPage; i++) {
res.push(items[i]);
}
return res;
},
_hasNextByTimes: function (items, times) {
return times * this._const.perPage < items.length;
},
_itemsCreator: function (options, callback) { _itemsCreator: function (options, callback) {
var self = this, o = this.options; var self = this, o = this.options;
if (!o.cache || !this.items) { if (!o.cache || !this.items) {
@ -50,13 +62,14 @@ BI.AbstractAllValueChooser = BI.inherit(BI.Widget, {
} else { } else {
call(this.items); call(this.items);
} }
function call (items) {
function call(items) {
var keywords = (options.keywords || []).slice(); var keywords = (options.keywords || []).slice();
if (options.keyword) { if (options.keyword) {
keywords.push(options.keyword); keywords.push(options.keyword);
} }
var resultItems = items; var resultItems = items;
if(BI.isNotEmptyArray(keywords)) { if (BI.isNotEmptyArray(keywords)) {
resultItems = []; resultItems = [];
BI.each(keywords, function (i, kw) { BI.each(keywords, function (i, kw) {
var search = BI.Func.getSearchResult(items, kw); var search = BI.Func.getSearchResult(items, kw);
@ -77,12 +90,12 @@ BI.AbstractAllValueChooser = BI.inherit(BI.Widget, {
return; return;
} }
if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) {
callback({count: resultItems.length}); callback({ count: resultItems.length });
return; return;
} }
callback({ callback({
items: resultItems, items: self._getItemsByTimes(resultItems, options.times),
hasNext: false hasNext: self._hasNextByTimes(resultItems, options.times)
}); });
} }
}, },

7
src/component/allvaluechooser/pane.allvaluechooser.js

@ -50,10 +50,11 @@ BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, {
getValue: function () { getValue: function () {
var val = this.list.getValue() || {}; var val = this.list.getValue() || {};
if (val.type === BI.Selection.All) { if (val.type === BI.Selection.Multi) {
return val.assist; return val.value || [];
} }
return val.value || [];
return BI.difference(BI.map(this.items, "value"), val.value || []);
}, },
populate: function (items) { populate: function (items) {

4
src/core/2.base.js

@ -524,6 +524,10 @@
isWindow: function (obj) { isWindow: function (obj) {
return obj != null && obj == obj.window; return obj != null && obj == obj.window;
},
isPromise: function(obj) {
return !!obj && (BI.isObject(obj) || BI.isFunction(obj)) && BI.isFunction(obj.then);
} }
}); });

6
src/core/3.ob.js

@ -1,5 +1,5 @@
!(function () { !(function () {
function extend () { function extend() {
var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy; var target = arguments[0] || {}, length = arguments.length, i = 1, options, name, src, copy;
for (; i < length; i++) { for (; i < length; i++) {
// Only deal with non-null/undefined values // Only deal with non-null/undefined values
@ -90,11 +90,11 @@
//释放当前对象 //释放当前对象
_purgeRef: function () { _purgeRef: function () {
if (this.options.__ref) { if (this.options.__ref) {
this.options.__ref.call(null); this.options.__ref.call(null, null);
this.options.__ref = null; this.options.__ref = null;
} }
if (this.options.ref) { if (this.options.ref) {
this.options.ref.call(null); this.options.ref.call(null, null);
this.options.ref = null; this.options.ref = null;
} }
}, },

2
src/core/4.widget.js

@ -738,6 +738,8 @@
callLifeHook(this, "destroyed"); callLifeHook(this, "destroyed");
this.destroyed = null; this.destroyed = null;
this._isDestroyed = true; this._isDestroyed = true;
// this._purgeRef(); // 清除ref的时机还是要仔细考虑一下
}, },
_unMount: function () { _unMount: function () {

6
src/core/5.inject.js

@ -81,10 +81,10 @@
BI.service = BI.service || function (xtype, cls) { BI.service = BI.service || function (xtype, cls) {
if (serviceInjection[xtype] != null) { if (serviceInjection[xtype] != null) {
_global.console && console.error("service: [" + xtype + "] 已经注册过了"); _global.console && console.error("service: [" + xtype + "] 已经注册过了");
} else {
serviceInjection[xtype] = cls;
} }
serviceInjection[xtype] = cls;
return function (config) { return function (config) {
return BI.Services.getService(xtype, config); return BI.Services.getService(xtype, config);
}; };
@ -402,8 +402,6 @@
BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) { BI.shortcut = BI.component = BI.shortcut || function (xtype, cls) {
if (kv[xtype] != null) { if (kv[xtype] != null) {
_global.console && console.error("组件: [" + xtype + "] 已经注册过了"); _global.console && console.error("组件: [" + xtype + "] 已经注册过了");
return;
} }
if (cls) { if (cls) {
cls["xtype"] = xtype; cls["xtype"] = xtype;

8
src/core/conflict.js

@ -1,7 +1,7 @@
if (!window.$ && !window.jQuery) { if (!_global.$ && !_global.jQuery) {
window.jQuery = window.$ = BI.jQuery; _global.jQuery = _global.$ = BI.jQuery;
} }
if (!window._) { if (!_global._) {
window._ = BI._; _global._ = BI._;
} }

2
src/core/controller/controller.bubbles.js

@ -30,7 +30,7 @@ BI.BubblesController = BI.inherit(BI.Controller, {
if (!this.storeBubbles[name]) { if (!this.storeBubbles[name]) {
this.storeBubbles[name] = BI.createWidget({ this.storeBubbles[name] = BI.createWidget({
type: "bi.label", type: "bi.text",
cls: "bi-bubble" + " bubble-" + level, cls: "bi-bubble" + " bubble-" + level,
text: text, text: text,
hgap: 5, hgap: 5,

23
src/core/controller/controller.tooltips.js

@ -12,17 +12,25 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
this.showingTips = {};// 存储正在显示的tooltip this.showingTips = {};// 存储正在显示的tooltip
}, },
_createTooltip: function (text, level) { /**
*
* @param opt
* @param opt.text {String} 文本
* @param opt.level {String} 级别, success或warning
* @param opt.textAlign {String} 文本对齐方式, left, center, right
* @returns {*}
* @private
*/
_createTooltip: function (opt) {
return BI.createWidget({ return BI.createWidget({
type: "bi.tooltip", type: "bi.tooltip",
text: text, ...opt,
level: level,
stopEvent: true stopEvent: true
}); });
}, },
// opt: {container: '', belowMouse: false} // opt: {container: '', belowMouse: false}
show: function (e, name, text, level, context, opt) { show: function (e, name, tooltipOpt, context, opt) {
opt || (opt = {}); opt || (opt = {});
var self = this; var self = this;
BI.each(this.showingTips, function (i, tip) { BI.each(this.showingTips, function (i, tip) {
@ -30,7 +38,7 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
}); });
this.showingTips = {}; this.showingTips = {};
if (!this.has(name)) { if (!this.has(name)) {
this.create(name, text, level, opt.container || "body"); this.create(name, tooltipOpt, document.fullscreenElement ? context : (opt.container || "body"));
} }
if (!opt.belowMouse) { if (!opt.belowMouse) {
var offset = context.element.offset(); var offset = context.element.offset();
@ -41,7 +49,6 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
var top = offset.top + bounds.height + 5; var top = offset.top + bounds.height + 5;
} }
var tooltip = this.get(name); var tooltip = this.get(name);
tooltip.setText(text);
tooltip.element.css({ tooltip.element.css({
left: "0px", left: "0px",
top: "0px" top: "0px"
@ -84,9 +91,9 @@ BI.TooltipsController = BI.inherit(BI.Controller, {
return this; return this;
}, },
create: function (name, text, level, context) { create: function (name, tooltipOpt, context) {
if (!this.has(name)) { if (!this.has(name)) {
var tooltip = this._createTooltip(text, level); var tooltip = this._createTooltip(tooltipOpt);
this.add(name, tooltip); this.add(name, tooltip);
BI.createWidget({ BI.createWidget({
type: "bi.absolute", type: "bi.absolute",

74
src/core/element/element.js

@ -0,0 +1,74 @@
import { registFunction } from './plugins';
export function Element(widget, attribs) {
this.l = this.r = this.t = this.b = 0; // 边框
this.marginLeft = this.marginRight = this.marginTop = this.marginBottom = 0; //间距
this.position = {};
this.classMap = {};
this.classList = [];
this.children = [];
this.attribs = attribs || {};
this.styles = {};
// 兼容处理
this['0'] = this;
this.style = {};
if (!widget) {
this.nodeName = 'body';
this.position.x = 0;
this.position.y = 0;
this.attribs.id = 'body';
} else if (BI.isWidget(widget)) {
this.widget = widget;
this.nodeName = widget.options.tagName;
this.textBaseLine = widget.options.textBaseLine;
} else if (BI.isString(widget)) {
this.nodeName = widget;
}
}
initElement(Element);
registFunction(Element);
function initElement(element) {
element.prototype = {
appendChild(child) {
child.parent = this;
if (this.children.push(child) !== 1) {
var sibling = this.children[this.children.length - 2];
sibling.next = child;
child.prev = sibling;
child.next = null;
}
},
append(child) {
child.parent = this;
if (this.children.push(child) !== 1) {
var sibling = this.children[this.children.length - 2];
sibling.next = child;
child.prev = sibling;
child.next = null;
}
},
getParent() {
return this.parent;
},
getSiblings() {
var parent = this.getParent();
return parent ? parent.getChildren() : [this];
},
getChildren() {
return this.children;
},
getBounds() {
return {};
},
width() {
},
height() {
}
};
}

31
src/core/element/index.js

@ -0,0 +1,31 @@
import { Element } from './element';
BI.Element = Element;
BI.Element.renderEngine = {
createElement: (widget) => {
// eslint-disable-next-line no-undef
if (BI.isWidget(widget)) {
var o = widget.options;
if (o.element instanceof Element) {
return o.element;
}
if (typeof o.element === 'string' && o.element !== 'body') {
o.root = false;
return new Element(widget);
}
if (o.root === true) {
return new Element();
}
}
// eslint-disable-next-line no-undef
if (BI.isString(widget)) {
return new Element(widget);
}
return new Element(widget);
},
createFragment() {
return new Element();
}
}

22
src/core/element/plugins/attr.js

@ -0,0 +1,22 @@
export const registAttrFun = (Element) => {
Element.registerFunction('attr', function (key, value) {
var self = this;
if (BI.isObject(key)) {
BI.each(key, (k, v) => {
self.attr(k, v);
});
return this;
}
if (BI.isNull(value)) {
return this.attribs[key];
}
this.attribs[key] = value;
return this;
});
Element.registerFunction('hasAttrib', function (key) {
return this.attribs[key] != null;
});
Element.registerFunction('removeAttr', function (key) {
delete this.attribs[key];
});
};

23
src/core/element/plugins/class.js

@ -0,0 +1,23 @@
export const registClassFun = (Element) => {
Element.registerFunction('addClass', function (classList) {
var self = this;
BI.each(classList.split(' '), (i, cls) => {
if (cls && !self.classMap[cls]) {
self.classList.push(cls);
}
cls && (self.classMap[cls] = true);
});
return this;
});
Element.registerFunction('removeClass', function (classList) {
var self = this;
BI.each(classList.split(' '), (i, cls) => {
if (cls && self.classMap[cls]) {
delete self.classMap[cls];
self.classList.splice(self.classList.indexOf(cls), 1);
}
});
return this;
});
};

22
src/core/element/plugins/css.js

@ -0,0 +1,22 @@
export const registCssFun = (Element) => {
Element.registerFunction('css', function (key, value) {
var self = this;
if (BI.isObject(key)) {
BI.each(key, (k, v) => {
self.css(k, v);
});
return this;
}
key = BI.trim(BI.camelize(key));
return css(this, key, value);
});
};
const css = (elem, key, value) => {
key = BI.trim(BI.camelize(key));
if (BI.isNull(value)) {
return elem.styles[key];
}
elem.styles[key] = value;
return elem;
};

12
src/core/element/plugins/data.js

@ -0,0 +1,12 @@
export const registDataFun = (Element) => {
Element.registerFunction('data', function (key, value) {
if (!this._data) {
this._data = {};
}
if (BI.isNull(value)) {
return this._data[key];
}
this._data[key] = value;
return this;
});
};

9
src/core/element/plugins/empty.js

@ -0,0 +1,9 @@
export const registEmptyFun = (Element) => {
Element.registerFunction('empty', function (text) {
this.children = [];
return this;
});
Element.registerFunction('destroy', function (text) {
return this;
});
};

32
src/core/element/plugins/event.js

@ -0,0 +1,32 @@
var returnThis = function () {
return this;
};
export const registEventFun = (Element) => {
[
'mousedown',
'mouseup',
'mousewheel',
'keydown',
'keyup',
'focus',
'focusin',
'focusout',
'click',
'on',
'off',
'bind',
'unbind',
'trigger',
'hover',
'scroll',
'scrollLeft',
'scrollTop',
'resize',
'show',
'hide',
'dblclick',
'blur',
].forEach((event) => {
Element.registerFunction(event, returnThis);
});
};

15
src/core/element/plugins/html.js

@ -0,0 +1,15 @@
export const registHtmlFun = (Element) => {
Element.registerFunction('html', function (text) {
if (text && text.charAt(0) === '<') {
BI.createWidget({
type: 'bi.html',
element: this.widget,
html: text,
});
this.originalHtml = text;
} else {
this.text = BI.htmlDecode(text);
}
return this;
});
};

31
src/core/element/plugins/index.js

@ -0,0 +1,31 @@
import { registAttrFun } from './attr';
import { registClassFun } from './class';
import { registCssFun } from './css';
import { registDataFun } from './data';
import { registEmptyFun } from './empty';
import { registEventFun } from './event';
import { registHtmlFun } from './html';
import { registKeywordMarkFun } from './keywordMark';
import { registRenderToHtmlFun } from './renderToHtml';
import { registRenderToStringFun } from './renderToString';
import { registTextFun } from './text';
import { registValFun } from './val';
export const registFunction = (Element) => {
var functionMap = {};
Element.registerFunction = (key, fn) => {
Element.prototype[key] = functionMap[key] = fn;
};
registAttrFun(Element);
registClassFun(Element);
registCssFun(Element);
registDataFun(Element);
registEmptyFun(Element);
registEventFun(Element);
registHtmlFun(Element);
registKeywordMarkFun(Element);
registRenderToStringFun(Element);
registRenderToHtmlFun(Element);
registTextFun(Element);
registValFun(Element);
};

6
src/core/element/plugins/keywordMark.js

@ -0,0 +1,6 @@
export const registKeywordMarkFun = (Element) => {
Element.registerFunction('__textKeywordMarked__', function (text) {
this[0].textContent = text;
return this;
});
};

65
src/core/element/plugins/renderToHtml.js

@ -0,0 +1,65 @@
var skipArray = [];
var pxStyle = ['font-size', 'width', 'height'];
var _renderToHtml = function (root) {
var str = '';
if (BI.isNull(root.originalHtml)) {
if (root.tag !== 'body') {
str += `<${root.tag}`;
if (root.classList.length > 0) {
str += ' class="';
BI.each(root.classList, (i, cls) => {
str += ` ${cls}`;
});
str += '"';
}
str += ' style="';
BI.each(root.originalStyles, (key, stl) => {
if (
skipArray.contains(key) ||
(key == 'height' && root.classList.contains('bi-design-components-data-data-table-cell'))
) {
return;
}
key = BI.hyphenate(key);
if (key === 'font-family') {
stl = stl.replace(/\"/g, '');
}
if (pxStyle.contains(key) && BI.isNumeric(stl)) {
stl += 'px';
}
if (BI.isKey(stl)) {
str += ` ${key}:${stl};`;
}
});
str += '"';
BI.each(root.attribs, (key, attr) => {
if (BI.isKey(attr)) {
str += ` ${key}=${attr}`;
}
});
if (root.textContent) {
str += ` title=${root.textContent}`;
}
str += '>';
}
// 特殊处理,spread_table的行列元素是不取配置里的高度的,使用stretch拉伸的(leaves取了高度),但是功能代码里给单元格默认高度了,导致拉伸不了
// 而spread_grid_table的行列元素是取配置里的高度的,拉不拉伸都一样
BI.each(root.children, (i, child) => {
str += _renderToHtml(child);
});
} else {
str += root.originalHtml;
}
if (root.tag !== 'body') {
if (root.textContent) {
str += root.textContent;
}
str += `</${root.tag}>`;
}
return str;
};
export const registRenderToHtmlFun = (Element) => {
Element.registerFunction('renderToHtml', function () {
return _renderToHtml(this);
});
};

50
src/core/element/plugins/renderToString.js

@ -0,0 +1,50 @@
var skipArray = ['width', 'height'];
var _renderToString = function (root) {
var str = '';
if (root.nodeName !== 'body') {
str += `<${root.nodeName}`;
if (root.classList.length > 0) {
str += ' class="';
BI.each(root.classList, (i, cls) => {
str += ` ${cls}`;
});
str += '"';
}
str += ' style="';
BI.each(root.styles, (key, stl) => {
if (skipArray.includes(key)) {
return;
}
key = BI.hyphenate(key);
str += ` ${key}:${stl};`;
});
str += ` width:${root.width}px;`;
str += ` height:${root.height}px;`;
str += ' position: fixed;';
str += ` left: ${root.position.x}px;`;
str += ` top: ${root.position.y}px;`;
str += '"';
BI.each(root.attribs, (key, attr) => {
str += ` ${key}:${attr}`;
});
str += '>';
}
BI.each(root.children, (i, child) => {
str += _renderToString(child);
});
// if (root.htmlContent) {
// str += root.htmlContent;
// }
if (root.nodeName !== 'body') {
if (root.text) {
str += root.text;
}
str += `</${root.nodeName}>`;
}
return str;
};
export const registRenderToStringFun = (Element) => {
Element.registerFunction('renderToString', function () {
return _renderToString(this);
});
};

10
src/core/element/plugins/text.js

@ -0,0 +1,10 @@
export const registTextFun = (Element) => {
Element.registerFunction('setText', function (text) {
this.text = text;
return this;
});
Element.registerFunction('setValue', function (text) {
this.text = text;
return this;
});
};

9
src/core/element/plugins/val.js

@ -0,0 +1,9 @@
export const registValFun = (Element) => {
Element.registerFunction('val', function (value) {
if (BI.isNotNull(value)) {
this.text = `${value}`;
return this;
}
return this.text;
});
};

4
src/core/platform/web/config.js

@ -210,12 +210,12 @@ BI.prepares.push(function () {
}); });
BI.Plugin.configWidget("bi.horizontal_sticky", function (ob) { BI.Plugin.configWidget("bi.horizontal_sticky", function (ob) {
if (!isSupportSticky) { if (!isSupportSticky) {
return BI.extend({}, ob, {type: "bi.horizontal_fill"}); return BI.extend({ scrollx: true }, ob, {type: "bi.horizontal_fill"});
} }
}); });
BI.Plugin.configWidget("bi.vertical_sticky", function (ob) { BI.Plugin.configWidget("bi.vertical_sticky", function (ob) {
if (!isSupportSticky) { if (!isSupportSticky) {
return BI.extend({}, ob, {type: "bi.vertical_fill"}); return BI.extend({ scrolly: true }, ob, {type: "bi.vertical_fill"});
} }
}); });

51
src/core/system.js

@ -19,6 +19,40 @@
TOAST_TOP: 10, TOAST_TOP: 10,
H_GAP_SIZE: "M", H_GAP_SIZE: "M",
V_GAP_SIZE: "S" V_GAP_SIZE: "S"
},
loadingCreator: function(config) {
var loadingSize = (config ? config.loadingSize : "small") || "small";
var isIE = BI.isIE();
function getSize(v) {
return Math.ceil(v / (loadingSize === "small" ? 2 : 1));
}
return {
type: "bi.horizontal",
cls: "bi-loading-widget" + (isIE ? " wave-loading hack" : ""),
height: getSize(60),
width: getSize(60),
hgap: getSize(10),
vgap: 2.5,
items: isIE ? [] : [{
type: "bi.layout",
cls: "animate-rect rect1",
height: getSize(50),
width: getSize(5)
}, {
type: "bi.layout",
cls: "animate-rect rect2",
height: getSize(50),
width: getSize(5)
}, {
type: "bi.layout",
cls: "animate-rect rect3",
height: getSize(50),
width: getSize(5)
}]
};
} }
}; };
@ -29,12 +63,11 @@
"L": 24 "L": 24
}; };
var provider = function () { function provider () {
this.SYSTEM = system; this.SYSTEM = system;
this.setSize = function (opt) { this.setSize = function (opt) {
BI.deepExtend(system, {size: opt}); BI.deepExtend(system, { size: opt });
}; };
this.setResponsiveMode = function (mode) { this.setResponsiveMode = function (mode) {
@ -60,6 +93,10 @@
BI.extend(system.dependencies, moduleConfig); BI.extend(system.dependencies, moduleConfig);
}; };
this.setLoadingCreator = function(creator) {
system.loadingCreator = creator;
};
this.$get = function () { this.$get = function () {
return BI.inherit(BI.OB, { return BI.inherit(BI.OB, {
@ -88,13 +125,17 @@
getDependencies: function () { getDependencies: function () {
return system.dependencies; return system.dependencies;
},
getLoading: function(config) {
return system.loadingCreator(config);
} }
}); });
}; };
}; }
BI.provider("bi.provider.system", provider); BI.provider("bi.provider.system", provider);
})(); }());
BI.prepares.push(function () { BI.prepares.push(function () {
BI.SIZE_CONSANTS = BI.Providers.getProvider("bi.provider.system").getSize(); BI.SIZE_CONSANTS = BI.Providers.getProvider("bi.provider.system").getSize();

4
src/less/base/single/button/button.less

@ -401,6 +401,10 @@ body .bi-button, #body .bi-button {
} }
.bi-basic-button { .bi-basic-button {
// 按钮水波纹需要根据按钮根结点定位
position: relative;
&.button-common, &.button-success, &.button-warning, &.button-error { &.button-common, &.button-success, &.button-warning, &.button-error {
&:after { &:after {
content: ""; content: "";

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

Loading…
Cancel
Save