Browse Source

Pull request #3448: refact: KERNEL-14316 去掉 jQuery 以外的全局变量

Merge in VISUAL/fineui from ~TREECAT/fineui:es6 to es6

* commit '412824a83d77bac285d8b93372937a80310116cf':
  refact: KERNEL-14316 去掉 jQuery 以外的全局变量
es6
treecat-罗群 2 years ago
parent
commit
a9aa5e6d3a
  1. 4
      package.json
  2. 28
      rollup.config.js
  3. 18
      src/core/0.foundation.js
  4. 392
      src/core/2.base.js
  5. 8
      src/core/3.ob.js
  6. 207
      src/core/4.widget.js
  7. 1
      src/core/5.inject.js
  8. 1
      src/core/controller/controller.resizer.js
  9. 147
      src/core/func/alias.js
  10. 1
      src/core/func/date.js
  11. 5
      src/core/index.js
  12. 1
      src/core/loader/loader.style.js
  13. 1
      src/core/platform/web/function.js
  14. 6
      src/core/platform/web/jquery/_jquery.js
  15. 1
      src/core/platform/web/jquery/fn.js
  16. 2
      src/core/platform/web/jquery/jquery.mousewheel.js
  17. 7
      src/core/structure/aes.js
  18. 2
      src/core/structure/prefixIntervalTree.js
  19. 72
      src/core/system.js
  20. 1
      src/core/utils/events/mousemovetracker.js
  21. 1
      src/core/utils/events/wheelhandler.js
  22. 6
      test/prepare.js
  23. 47
      test/utils.js

4
package.json

@ -12,6 +12,10 @@
"@fui/babel-preset-fineui": "^3.0.0", "@fui/babel-preset-fineui": "^3.0.0",
"@fui/eslint-plugin": "^1.0.19", "@fui/eslint-plugin": "^1.0.19",
"@juggle/resize-observer": "^3.4.0", "@juggle/resize-observer": "^3.4.0",
"@rollup/plugin-alias": "4.0.3",
"@rollup/plugin-babel": "6.0.3",
"@rollup/plugin-commonjs": "24.0.1",
"@rollup/plugin-node-resolve": "15.0.1",
"@types/node": "15.6.1", "@types/node": "15.6.1",
"@typescript-eslint/eslint-plugin": "2.33.0", "@typescript-eslint/eslint-plugin": "2.33.0",
"@typescript-eslint/parser": "2.33.0", "@typescript-eslint/parser": "2.33.0",

28
rollup.config.js

@ -3,10 +3,11 @@ const alias = require("@rollup/plugin-alias");
const resolve = require("@rollup/plugin-node-resolve"); const resolve = require("@rollup/plugin-node-resolve");
const commonjs = require("@rollup/plugin-commonjs"); const commonjs = require("@rollup/plugin-commonjs");
const path = require("path"); const path = require("path");
// import { fileURLToPath } from "url";
// import path from "path";
// const __dirname = path.dirname(fileURLToPath(import.meta.url)); /**
* todo: 删除根目录下的 babel.config.js然后移入到这个文件
*/
const input = "src/index.js"; const input = "src/index.js";
module.exports = [ module.exports = [
@ -16,24 +17,23 @@ module.exports = [
{ {
file: "dist/fineui.esm.js", file: "dist/fineui.esm.js",
format: "esm", format: "esm",
sourcemap: true sourcemap: true,
} },
], ],
plugins: [ plugins: [
alias({ alias({
entries: [ entries: [
{ find: "@", replacement: path.resolve(__dirname, "src") } { find: "@", replacement: path.resolve(__dirname, "src") },
] ],
}), }),
resolve(), resolve(),
babel({ babel({
babelHelpers: "runtime", babelHelpers: "inline",
presets: ["@babel/preset-env"],
plugins: [ plugins: [
["@babel/plugin-proposal-decorators", { legacy: true }] ["@babel/plugin-proposal-decorators", { legacy: true }],
] ],
}), }),
commonjs() commonjs(),
] ],
} },
]; ];

18
src/core/0.foundation.js vendored

@ -1,9 +1,7 @@
/* eslint-disable eqeqeq */
/** /**
* Created by richie on 15/7/8. * Created by richie on 15/7/8.
*/ *
/** * 初始化 _global 对象为什么不是 globalThis
* 初始化BI对象
*/ */
let _global = undefined; let _global = undefined;
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
@ -20,9 +18,9 @@ if (_global) {
_global._global = _global; _global._global = _global;
} }
if (_global.BI == null) { const prepares = [];
_global.BI = { prepares: [] };
} export {
if (_global.BI.prepares == null) { _global,
_global.BI.prepares = []; prepares
} };

392
src/core/2.base.js

@ -3,6 +3,18 @@
* Create By GUY 2014\11\17 * Create By GUY 2014\11\17
* *
*/ */
import _ from "./1.lodash";
import { Widget } from "./4.widget";
import { createWidget } from "./5.inject";
import { prepares, _global } from "./0.foundation";
import { CRYPT_TYPE, aesDecrypt, aesEncrypt } from "./structure/aes";
/**
* todo: 理论这么写逻辑没问题摇个人把这个 BI 干掉
*/
const BI = { _ };
function traverse(func, context) { function traverse(func, context) {
return function (value, key, obj) { return function (value, key, obj) {
return func.call(context, key, value, obj); return func.call(context, key, value, obj);
@ -16,7 +28,9 @@ function _apply(name) {
function _applyFunc(name) { function _applyFunc(name) {
return function () { return function () {
const args = Array.prototype.slice.call(arguments, 0); const args = Array.prototype.slice.call(arguments, 0);
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; args[1] = BI._.isFunction(args[1])
? traverse(args[1], args[2])
: args[1];
return BI._[name](...args); return BI._[name](...args);
}; };
@ -45,7 +59,24 @@ export function warn(message) {
} }
export function UUID() { export function UUID() {
const f = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"]; const f = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"a",
"b",
"c",
"d",
"e",
"f"
];
let str = ""; let str = "";
for (let i = 0; i < 16; i++) { for (let i = 0; i < 16; i++) {
const r = _global.parseInt(f.length * Math.random(), 10); const r = _global.parseInt(f.length * Math.random(), 10);
@ -56,7 +87,7 @@ export function UUID() {
} }
export function isWidget(widget) { export function isWidget(widget) {
return widget instanceof BI.Widget; return widget instanceof Widget;
} }
export function createWidgets(items, options, context) { export function createWidgets(items, options, context) {
@ -70,31 +101,37 @@ export function createWidgets(items, options, context) {
options || (options = {}); options || (options = {});
} }
return map(flatten(items), (i, item) => BI.createWidget(item, deepClone(options), context)); return map(flatten(items), (i, item) =>
createWidget(item, deepClone(options), context)
);
} }
export function createItems(data, innerAttr, outerAttr) { export function createItems(data, innerAttr, outerAttr) {
innerAttr = isArray(innerAttr) ? innerAttr : makeArray(flatten(data).length, innerAttr || {}); innerAttr = isArray(innerAttr)
outerAttr = isArray(outerAttr) ? outerAttr : makeArray(flatten(data).length, outerAttr || {}); ? innerAttr
: makeArray(flatten(data).length, innerAttr || {});
outerAttr = isArray(outerAttr)
? outerAttr
: makeArray(flatten(data).length, outerAttr || {});
return map(data, (i, item) => { return map(data, (i, item) => {
if (isArray(item)) { if (isArray(item)) {
return createItems(item, innerAttr, outerAttr); return createItems(item, innerAttr, outerAttr);
} }
if (item instanceof BI.Widget) { if (item instanceof Widget) {
return extend({}, innerAttr.shift(), outerAttr.shift(), { return extend({}, innerAttr.shift(), outerAttr.shift(), {
type: null, type: null,
el: item, el: item,
}); });
} }
if (innerAttr[0] instanceof BI.Widget) { if (innerAttr[0] instanceof Widget) {
outerAttr.shift(); outerAttr.shift();
return extend({}, item, { return extend({}, item, {
el: innerAttr.shift(), el: innerAttr.shift(),
}); });
} }
if (item.el instanceof BI.Widget) { if (item.el instanceof Widget) {
innerAttr.shift(); innerAttr.shift();
return extend({}, outerAttr.shift(), { type: null }, item); return extend({}, outerAttr.shift(), { type: null }, item);
@ -114,13 +151,15 @@ export function createItems(data, innerAttr, outerAttr) {
// 用容器包装items // 用容器包装items
export function packageItems(items, layouts) { export function packageItems(items, layouts) {
for (let i = layouts.length - 1; i >= 0; i--) { for (let i = layouts.length - 1; i >= 0; i--) {
items = map(items, (k, it) => extend({}, layouts[i], { items = map(items, (k, it) =>
extend({}, layouts[i], {
items: [ items: [
extend({}, layouts[i].el, { extend({}, layouts[i].el, {
el: it, el: it,
}) })
], ],
})); })
);
} }
return items; return items;
@ -138,7 +177,7 @@ export function formatEL(obj) {
// 剥开EL // 剥开EL
export function stripEL(obj) { export function stripEL(obj) {
return obj.type && obj || obj.el || obj; return (obj.type && obj) || obj.el || obj;
} }
export function trans2Element(widgets) { export function trans2Element(widgets) {
@ -146,19 +185,53 @@ export function trans2Element(widgets) {
} }
// 集合相关方法 // 集合相关方法
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => { BI._.each(
[
"where",
"findWhere",
"invoke",
"pluck",
"shuffle",
"sample",
"toArray",
"size"
],
name => {
BI[name] = _apply(name); BI[name] = _apply(name);
}); }
BI._.each([ );
"get", "set", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", BI._.each(
"sortBy", "groupBy", "indexBy", "countBy", "partition", "clamp" [
], name => { "get",
"set",
"each",
"map",
"reduce",
"reduceRight",
"find",
"filter",
"reject",
"every",
"all",
"some",
"any",
"max",
"min",
"sortBy",
"groupBy",
"indexBy",
"countBy",
"partition",
"clamp"
],
name => {
if (name === "any") { if (name === "any") {
BI[name] = _applyFunc("some"); BI[name] = _applyFunc("some");
} else { } else {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);
} }
}); }
);
export const where = BI.where; export const where = BI.where;
export const findWhere = BI.findWhere; export const findWhere = BI.findWhere;
export const invoke = BI.invoke; export const invoke = BI.invoke;
@ -323,13 +396,23 @@ export function remove(obj, target, context) {
let i; let i;
if (isArray(obj)) { if (isArray(obj)) {
for (i = 0; i < obj.length; i++) { for (i = 0; i < obj.length; i++) {
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { if (
(targetIsFunction &&
(target === obj[i] ||
target.apply(context, [i, obj[i]]) === true)) ||
(!targetIsFunction && contains(target, obj[i]))
) {
obj.splice(i--, 1); obj.splice(i--, 1);
} }
} }
} else { } else {
each(obj, (i, v) => { each(obj, (i, v) => {
if ((targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i]))) { if (
(targetIsFunction &&
(target === obj[i] ||
target.apply(context, [i, obj[i]]) === true)) ||
(!targetIsFunction && contains(target, obj[i]))
) {
delete obj[i]; delete obj[i];
} }
}); });
@ -362,10 +445,15 @@ export function array2String(array) {
export function abc2Int(string) { export function abc2Int(string) {
let idx = 0; let idx = 0;
const start = "A", str = string.toUpperCase(); const start = "A",
str = string.toUpperCase();
for (let i = 0, len = str.length; i < len; ++i) { for (let i = 0, len = str.length; i < len; ++i) {
idx = str.charAt(i).charCodeAt(0) - start.charCodeAt(0) + 26 * idx + 1; idx = str.charAt(i).charCodeAt(0) - start.charCodeAt(0) + 26 * idx + 1;
if (idx > (2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) / 26) { if (
idx >
(2147483646 - str.charAt(i).charCodeAt(0) + start.charCodeAt(0)) /
26
) {
return 0; return 0;
} }
} }
@ -374,8 +462,36 @@ export function abc2Int(string) {
} }
export function int2Abc(num) { export function int2Abc(num) {
const DIGITS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]; const DIGITS = [
let idx = num, str = ""; "A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
"P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
"X",
"Y",
"Z"
];
let idx = num,
str = "";
if (num === 0) { if (num === 0) {
return ""; return "";
} }
@ -392,12 +508,33 @@ export function int2Abc(num) {
} }
// 数组相关的方法 // 数组相关的方法
BI._.each([ BI._.each(
"first", "initial", "last", "rest", "compact", "flatten", "without", "union", "intersection", [
"difference", "zip", "unzip", "object", "indexOf", "lastIndexOf", "sortedIndex", "range", "take", "takeRight", "uniqBy" "first",
], name => { "initial",
"last",
"rest",
"compact",
"flatten",
"without",
"union",
"intersection",
"difference",
"zip",
"unzip",
"object",
"indexOf",
"lastIndexOf",
"sortedIndex",
"range",
"take",
"takeRight",
"uniqBy"
],
name => {
BI[name] = _apply(name); BI[name] = _apply(name);
}); }
);
BI._.each(["findIndex", "findLastIndex"], name => { BI._.each(["findIndex", "findLastIndex"], name => {
BI[name] = _applyFunc(name); BI[name] = _applyFunc(name);
}); });
@ -484,14 +621,48 @@ export function uniq(array, isSorted, iteratee, context) {
} }
// 对象相关方法 // 对象相关方法
BI._.each([ BI._.each(
"keys", "allKeys", "values", "pairs", "invert", "create", "functions", "extend", "extendOwn", [
"defaults", "clone", "property", "propertyOf", "matcher", "isEqual", "isMatch", "isEmpty", "keys",
"isElement", "isNumber", "isString", "isArray", "isObject", "isPlainObject", "isArguments", "isFunction", "isFinite", "allKeys",
"isBoolean", "isDate", "isRegExp", "isError", "isNaN", "isUndefined", "zipObject", "cloneDeep", "pickBy" "values",
], name => { "pairs",
"invert",
"create",
"functions",
"extend",
"extendOwn",
"defaults",
"clone",
"property",
"propertyOf",
"matcher",
"isEqual",
"isMatch",
"isEmpty",
"isElement",
"isNumber",
"isString",
"isArray",
"isObject",
"isPlainObject",
"isArguments",
"isFunction",
"isFinite",
"isBoolean",
"isDate",
"isRegExp",
"isError",
"isNaN",
"isUndefined",
"zipObject",
"cloneDeep",
"pickBy"
],
name => {
BI[name] = _apply(name); BI[name] = _apply(name);
}); }
);
export const keys = BI.keys; export const keys = BI.keys;
export const allKeys = BI.allKeys; export const allKeys = BI.allKeys;
export const values = BI.values; export const values = BI.values;
@ -555,10 +726,13 @@ export function inherit(sp, overrides) {
export function init() { export function init() {
// 先把准备环境准备好 // 先把准备环境准备好
while (BI.prepares && BI.prepares.length > 0) { while (prepares && prepares.length > 0) {
BI.prepares.shift()(); prepares.shift()();
} }
while (_global.___fineuiExposedFunction && _global.___fineuiExposedFunction.length > 0) { while (
_global.___fineuiExposedFunction &&
_global.___fineuiExposedFunction.length > 0
) {
_global.___fineuiExposedFunction.shift()(); _global.___fineuiExposedFunction.shift()();
} }
BI.initialized = true; BI.initialized = true;
@ -593,8 +767,8 @@ export function isKey(key) {
// 忽略大小写的等于 // 忽略大小写的等于
export function isCapitalEqual(a, b) { export function isCapitalEqual(a, b) {
a = isNull(a) ? a : (`${a}`).toLowerCase(); a = isNull(a) ? a : `${a}`.toLowerCase();
b = isNull(b) ? b : (`${b}`).toLowerCase(); b = isNull(b) ? b : `${b}`.toLowerCase();
return isEqual(a, b); return isEqual(a, b);
} }
@ -603,7 +777,12 @@ export function isWidthOrHeight(w) {
if (typeof w === "number") { if (typeof w === "number") {
return w >= 0; return w >= 0;
} else if (typeof w === "string") { } else if (typeof w === "string") {
return /^\d{1,3}(\.\d)?%$/.test(w) || w === "auto" || /^\d+(\.\d+)?px$/.test(w) || /^calc/.test(w); return (
/^\d{1,3}(\.\d)?%$/.test(w) ||
w === "auto" ||
/^\d+(\.\d+)?px$/.test(w) ||
/^calc/.test(w)
);
} }
} }
@ -643,7 +822,8 @@ export const deepClone = BI._.cloneDeep;
export const deepExtend = BI._.merge; export const deepExtend = BI._.merge;
export function isDeepMatch(object, attrs) { export function isDeepMatch(object, attrs) {
const attrsKeys = keys(attrs), length = attrsKeys.length; const attrsKeys = keys(attrs),
length = attrsKeys.length;
if (object === null) { if (object === null) {
return !length; return !length;
} }
@ -661,7 +841,9 @@ export function isDeepMatch(object, attrs) {
export function contains(obj, target, fromIndex) { export function contains(obj, target, fromIndex) {
if (!BI._.isArrayLike(obj)) obj = values(obj); if (!BI._.isArrayLike(obj)) obj = values(obj);
return indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0; return (
indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0
);
} }
export function deepContains(obj, copy) { export function deepContains(obj, copy) {
@ -760,9 +942,21 @@ export function deepDiff(object, other) {
} }
// 通用方法 // 通用方法
BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => { BI._.each(
[
"uniqueId",
"result",
"chain",
"iteratee",
"unescape",
"before",
"after",
"chunk"
],
name => {
BI[name] = (...args) => BI._[name](...args); BI[name] = (...args) => BI._[name](...args);
}); }
);
export const uniqueId = BI.uniqueId; export const uniqueId = BI.uniqueId;
export const result = BI.result; export const result = BI.result;
export const chain = BI.chain; export const chain = BI.chain;
@ -773,9 +967,21 @@ export const after = BI.after;
export const chunk = BI.chunk; export const chunk = BI.chunk;
// 事件相关方法 // 事件相关方法
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => { BI._.each(
[
"bind",
"once",
"partial",
"debounce",
"throttle",
"delay",
"defer",
"wrap"
],
name => {
BI[name] = (...args) => BI._[name](...args); BI[name] = (...args) => BI._[name](...args);
}); }
);
export const bind = BI.bind; export const bind = BI.bind;
export const once = BI.once; export const once = BI.once;
export const partial = BI.partial; export const partial = BI.partial;
@ -846,9 +1052,9 @@ export const nextTick = (function () {
} }
// $flow-disable-line // $flow-disable-line
if (!cb && typeof Promise !== "undefined") { if (!cb && typeof Promise !== "undefined") {
return new Promise(((resolve, reject) => { return new Promise((resolve, reject) => {
_resolve = resolve; _resolve = resolve;
})); });
} }
}; };
}()); }());
@ -876,7 +1082,9 @@ export function parseSafeInt(value) {
return value return value
? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) ? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
: (value === 0 ? value : 0); : value === 0
? value
: 0;
} }
export function parseFloat(number) { export function parseFloat(number) {
@ -904,7 +1112,9 @@ export function isInteger(number) {
} }
export function isNumeric(number) { export function isNumeric(number) {
return !_global.isNaN(_global.parseFloat(number)) && _global.isFinite(number); return (
!_global.isNaN(_global.parseFloat(number)) && _global.isFinite(number)
);
} }
export function isFloat(number) { export function isFloat(number) {
@ -951,11 +1161,11 @@ export function trim(...args) {
} }
export function toUpperCase(string) { export function toUpperCase(string) {
return (`${string}`).toLocaleUpperCase(); return `${string}`.toLocaleUpperCase();
} }
export function toLowerCase(string) { export function toLowerCase(string) {
return (`${string}`).toLocaleLowerCase(); return `${string}`.toLocaleLowerCase();
} }
export function isEndWithBlank(string) { export function isEndWithBlank(string) {
@ -970,9 +1180,7 @@ export function stripQuotes(str) {
const a = str.charCodeAt(0); const a = str.charCodeAt(0);
const b = str.charCodeAt(str.length - 1); const b = str.charCodeAt(str.length - 1);
return a === b && (a === 0x22 || a === 0x27) return a === b && (a === 0x22 || a === 0x27) ? str.slice(1, -1) : str;
? str.slice(1, -1)
: str;
} }
// background-color => backgroundColor // background-color => backgroundColor
@ -1002,9 +1210,9 @@ export function isEmptyString(str) {
*/ */
export function encrypt(type, text, key) { export function encrypt(type, text, key) {
switch (type) { switch (type) {
case BI.CRYPT_TYPE.AES: case CRYPT_TYPE.AES:
default: default:
return BI.aesEncrypt(text, key); return aesEncrypt(text, key);
} }
} }
@ -1017,9 +1225,9 @@ export function encrypt(type, text, key) {
*/ */
export function decrypt(type, text, key) { export function decrypt(type, text, key) {
switch (type) { switch (type) {
case BI.CRYPT_TYPE.AES: case CRYPT_TYPE.AES:
default: default:
return BI.aesDecrypt(text, key); return aesDecrypt(text, key);
} }
} }
@ -1033,7 +1241,6 @@ export function escape(string) {
return string.replace(/('|\\)/g, "\\$1"); return string.replace(/('|\\)/g, "\\$1");
} }
/** /**
* 让字符串通过指定字符做补齐的函数 * 让字符串通过指定字符做补齐的函数
* *
@ -1130,7 +1337,9 @@ export function checkDateVoid(YY, MM, DD, minDate, maxDate) {
export function checkDateLegal(str) { export function checkDateLegal(str) {
const ar = str.match(/\d+/g); const ar = str.match(/\d+/g);
const YY = ar[0] | 0, MM = ar[1] | 0, DD = ar[2] | 0; const YY = ar[0] | 0,
MM = ar[1] | 0,
DD = ar[2] | 0;
if (ar.length <= 1) { if (ar.length <= 1) {
return true; return true;
} }
@ -1162,10 +1371,14 @@ export function parseDateTime(str, fmt) {
const otherlength = 2; const otherlength = 2;
a[0] = str.substring(0, yearlength); a[0] = str.substring(0, yearlength);
a[1] = str.substring(yearlength, yearlength + otherlength); a[1] = str.substring(yearlength, yearlength + otherlength);
a[2] = str.substring(yearlength + otherlength, yearlength + otherlength * 2); a[2] = str.substring(
yearlength + otherlength,
yearlength + otherlength * 2
);
} }
const b = fmt.match(/%./g); const b = fmt.match(/%./g);
let i = 0, j = 0; let i = 0,
j = 0;
let hr = 0; let hr = 0;
let min = 0; let min = 0;
let sec = 0; let sec = 0;
@ -1186,13 +1399,17 @@ export function parseDateTime(str, fmt) {
case "%Y": case "%Y":
case "%y": case "%y":
y = _global.parseInt(a[i], 10); y = _global.parseInt(a[i], 10);
(y < 100) && (y += (y > 29) ? 1900 : 2000); y < 100 && (y += y > 29 ? 1900 : 2000);
break; break;
case "%b": case "%b":
case "%B": case "%B":
for (j = 0; j < 12; ++j) { for (j = 0; j < 12; ++j) {
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { if (
BI.getMonthName(j)
.substr(0, a[i].length)
.toLowerCase() === a[i].toLowerCase()
) {
m = j; m = j;
break; break;
} }
@ -1258,7 +1475,10 @@ export function parseDateTime(str, fmt) {
if (a[i].search(/[a-zA-Z]+/) !== -1) { if (a[i].search(/[a-zA-Z]+/) !== -1) {
let t = -1; let t = -1;
for (j = 0; j < 12; ++j) { for (j = 0; j < 12; ++j) {
if (BI.getMonthName(j).substr(0, a[i].length).toLowerCase() === a[i].toLowerCase()) { if (
BI.getMonthName(j).substr(0, a[i].length).toLowerCase() ===
a[i].toLowerCase()
) {
t = j; t = j;
break; break;
} }
@ -1273,7 +1493,7 @@ export function parseDateTime(str, fmt) {
m = a[i] - 1; m = a[i] - 1;
} else if (_global.parseInt(a[i], 10) > 31 && y === 0) { } else if (_global.parseInt(a[i], 10) > 31 && y === 0) {
y = _global.parseInt(a[i], 10); y = _global.parseInt(a[i], 10);
(y < 100) && (y += (y > 29) ? 1900 : 2000); y < 100 && (y += y > 29 ? 1900 : 2000);
} else if (d === 0) { } else if (d === 0) {
d = a[i]; d = a[i];
} }
@ -1325,13 +1545,25 @@ export function getDate(...args) {
break; break;
// new Date(year, month, day, hour, minute, second, millisecond) // new Date(year, month, day, hour, minute, second, millisecond)
case 7: case 7:
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); dt = new Date(
args[0],
args[1],
args[2],
args[3],
args[4],
args[5],
args[6]
);
break; break;
default: default:
dt = new Date(); dt = new Date();
break; break;
} }
if (isNotNull(BI.timeZone) && (arguments.length === 0 || (arguments.length === 1 && isNumber(arguments[0])))) { if (
isNotNull(BI.timeZone) &&
(arguments.length === 0 ||
(arguments.length === 1 && isNumber(arguments[0])))
) {
const localTime = dt.getTime(); const localTime = dt.getTime();
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准 // BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数
@ -1378,7 +1610,15 @@ export function getTime() {
break; break;
// new Date(year, month, day, hour, minute, second, millisecond) // new Date(year, month, day, hour, minute, second, millisecond)
case 7: case 7:
dt = new Date(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); dt = new Date(
args[0],
args[1],
args[2],
args[3],
args[4],
args[5],
args[6]
);
break; break;
default: default:
dt = new Date(); dt = new Date();
@ -1386,9 +1626,13 @@ export function getTime() {
} }
if (isNotNull(BI.timeZone)) { if (isNotNull(BI.timeZone)) {
// BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准 // BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准
return dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000; return (
dt.getTime() - BI.timeZone - new Date().getTimezoneOffset() * 60000
);
} }
return dt.getTime(); return dt.getTime();
} }
export const lodashUtils = BI._;

8
src/core/3.ob.js

@ -1,4 +1,4 @@
import { isFunction, isArray, isObject, isArguments, reduce, bind } from "./2.base"; import { isFunction, isArray, isObject, isArguments, reduce, bind, each } from "./2.base";
function obExtend() { function obExtend() {
const target = arguments[0] || {}, length = arguments.length; const target = arguments[0] || {}, length = arguments.length;
@ -65,14 +65,14 @@ export class OB {
_initListeners() { _initListeners() {
if (this.options.listeners !== null) { if (this.options.listeners !== null) {
BI._.each(this.options.listeners, (lis, eventName) => { each(this.options.listeners, (eventName, lis) => {
if (isFunction(lis)) { if (isFunction(lis)) {
this.on(eventName, lis); this.on(eventName, lis);
return; return;
} }
if (isArray(lis)) { if (isArray(lis)) {
BI._.each(lis, l => { lis.forEach(l => {
this.on(eventName, l); this.on(eventName, l);
}); });
@ -161,7 +161,7 @@ export class OB {
const fns = this._getEvents()[eventName]; const fns = this._getEvents()[eventName];
if (isArray(fns)) { if (isArray(fns)) {
const newFns = []; const newFns = [];
BI._.each(fns, ifn => { fns.forEach(ifn => {
if (ifn !== fn) { if (ifn !== fn) {
newFns.push(ifn); newFns.push(ifn);
} }

207
src/core/4.widget.js

@ -6,12 +6,27 @@
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
*/ */
import { isFunction, isArray, each, extend, isPlainObject, isNull, uniqueId, isWidget, isWidthOrHeight, isKey, remove, any, isNotNull } from "./2.base"; import {
isFunction,
isArray,
each,
extend,
isPlainObject,
isNull,
uniqueId,
isWidget,
isWidthOrHeight,
isKey,
remove,
any,
isNotNull
} from "./2.base";
import { OB } from "./3.ob"; import { OB } from "./3.ob";
import { Providers, _lazyCreateWidget } from "./5.inject"; import { Providers, _lazyCreateWidget } from "./5.inject";
import { DOM } from "./utils"; import { DOM } from "./utils";
import { Events, emptyFn, pixFormat } from "./constant"; import { Events, emptyFn, pixFormat } from "./constant";
import { Plugin } from "./6.plugin"; import { Plugin } from "./6.plugin";
import { _global } from "./0.foundation";
const cancelAnimationFrame = const cancelAnimationFrame =
_global.cancelAnimationFrame || _global.cancelAnimationFrame ||
@ -21,10 +36,17 @@ const cancelAnimationFrame =
_global.msCancelAnimationFrame || _global.msCancelAnimationFrame ||
_global.clearTimeout; _global.clearTimeout;
const requestAnimationFrame = _global.requestAnimationFrame || _global.webkitRequestAnimationFrame || _global.mozRequestAnimationFrame || _global.oRequestAnimationFrame || _global.msRequestAnimationFrame || _global.setTimeout; const requestAnimationFrame =
_global.requestAnimationFrame ||
_global.webkitRequestAnimationFrame ||
_global.mozRequestAnimationFrame ||
_global.oRequestAnimationFrame ||
_global.msRequestAnimationFrame ||
_global.setTimeout;
function callLifeHook(self, life) { function callLifeHook(self, life) {
let hooks = [], hook; let hooks = [],
hook;
hook = self[life]; hook = self[life];
if (hook) { if (hook) {
hooks = hooks.concat(isArray(hook) ? hook : [hook]); hooks = hooks.concat(isArray(hook) ? hook : [hook]);
@ -56,15 +78,13 @@ export class Widget extends OB {
baseCls: "", baseCls: "",
extraCls: "", extraCls: "",
cls: "", cls: "",
css: null, css: null
// vdom: false // vdom: false
}); });
} }
_constructor () { _constructor() {}
}
// 覆盖父类的_constructor方法,widget不走ob的生命周期 // 覆盖父类的_constructor方法,widget不走ob的生命周期
_constructed() { _constructed() {
@ -134,7 +154,10 @@ export class Widget extends OB {
const init = () => { const init = () => {
// 加个保险 // 加个保险
if (initCallbackCalled === true) { if (initCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeInit内部的写法,callback只能执行一次"); _global.console &&
console.error(
"组件: 请检查beforeInit内部的写法,callback只能执行一次"
);
return; return;
} }
@ -143,7 +166,10 @@ export class Widget extends OB {
const render = () => { const render = () => {
// 加个保险 // 加个保险
if (renderCallbackCalled === true) { if (renderCallbackCalled === true) {
_global.console && console.error("组件: 请检查beforeRender内部的写法,callback只能执行一次"); _global.console &&
console.error(
"组件: 请检查beforeRender内部的写法,callback只能执行一次"
);
return; return;
} }
@ -154,9 +180,11 @@ export class Widget extends OB {
if (this.options.beforeRender || this.beforeRender) { if (this.options.beforeRender || this.beforeRender) {
this.__async = true; this.__async = true;
const beforeRenderResult = (this.options.beforeRender || this.beforeRender).call(this, render); const beforeRenderResult = (
this.options.beforeRender || this.beforeRender
).call(this, render);
if (beforeRenderResult instanceof Promise) { if (beforeRenderResult instanceof Promise) {
beforeRenderResult.then(render).catch(e => { beforeRenderResult.then(render).catch((e) => {
_global.console && console.error(e); _global.console && console.error(e);
render(); render();
}); });
@ -169,9 +197,11 @@ export class Widget extends OB {
if (this.options.beforeInit || this.beforeInit) { if (this.options.beforeInit || this.beforeInit) {
this.__asking = true; this.__asking = true;
const beforeInitResult = (this.options.beforeInit || this.beforeInit).call(this, init); const beforeInitResult = (
this.options.beforeInit || this.beforeInit
).call(this, init);
if (beforeInitResult instanceof Promise) { if (beforeInitResult instanceof Promise) {
beforeInitResult.then(init).catch(e => { beforeInitResult.then(init).catch((e) => {
_global.console && console.error(e); _global.console && console.error(e);
init(); init();
}); });
@ -211,12 +241,14 @@ export class Widget extends OB {
this._initElementWidth(); this._initElementWidth();
this._initElementHeight(); this._initElementHeight();
if (o._baseCls || o.baseCls || o.extraCls) { if (o._baseCls || o.baseCls || o.extraCls) {
this.element.addClass(`${o._baseCls || ""} ${o.baseCls || ""} ${o.extraCls || ""}`); this.element.addClass(
`${o._baseCls || ""} ${o.baseCls || ""} ${o.extraCls || ""}`
);
} }
if (o.cls) { if (o.cls) {
if (isFunction(o.cls)) { if (isFunction(o.cls)) {
let cls = this.__watch(o.cls, (context, newValue) => { let cls = this.__watch(o.cls, (context, newValue) => {
this.element.removeClass(cls).addClass(cls = newValue); this.element.removeClass(cls).addClass((cls = newValue));
}); });
this.element.addClass(cls); this.element.addClass(cls);
} else { } else {
@ -240,7 +272,7 @@ export class Widget extends OB {
newValue[k] = ""; newValue[k] = "";
} }
} }
this.element.css(css = newValue); this.element.css((css = newValue));
}); });
this.element.css(css); this.element.css(css);
} else { } else {
@ -252,9 +284,16 @@ export class Widget extends OB {
__watch(getter, handler, options) { __watch(getter, handler, options) {
if (_global.Fix) { if (_global.Fix) {
this._watchers = this._watchers || []; this._watchers = this._watchers || [];
const watcher = new Fix.Watcher(null, () => getter.call(this, this), (handler && (v => { const watcher = new Fix.Watcher(
null,
() => getter.call(this, this),
(handler &&
((v) => {
handler.call(this, this, v); handler.call(this, this, v);
})) || emptyFn, extend({ deep: true }, options)); })) ||
emptyFn,
extend({ deep: true }, options)
);
this._watchers.push(() => { this._watchers.push(() => {
watcher.teardown(); watcher.teardown();
}); });
@ -277,7 +316,8 @@ export class Widget extends OB {
if (isWidget(o.element)) { if (isWidget(o.element)) {
this.element = this.options.element.element; this.element = this.options.element.element;
this._parent = o.element; this._parent = o.element;
this._parent._children && this._parent.addWidget(this.widgetName, this); this._parent._children &&
this._parent.addWidget(this.widgetName, this);
} else if (o.element) { } else if (o.element) {
this.element = Widget._renderEngine.createElement(this); this.element = Widget._renderEngine.createElement(this);
this._isRoot = true; this._isRoot = true;
@ -308,9 +348,11 @@ export class Widget extends OB {
_initVisual() { _initVisual() {
const o = this.options; const o = this.options;
if (o.invisible) { if (o.invisible) {
const invisible = o.invisible = isFunction(o.invisible) ? this.__watch(o.invisible, (context, newValue) => { const invisible = (o.invisible = isFunction(o.invisible)
? this.__watch(o.invisible, (context, newValue) => {
this.setVisible(!newValue); this.setVisible(!newValue);
}) : o.invisible; })
: o.invisible);
if (invisible) { if (invisible) {
// 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性 // 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性
this.__setElementVisible(false); this.__setElementVisible(false);
@ -322,17 +364,21 @@ export class Widget extends OB {
const o = this.options; const o = this.options;
if (o.disabled || o.invalid) { if (o.disabled || o.invalid) {
if (this.options.disabled) { if (this.options.disabled) {
const disabled = o.disabled = isFunction(o.disabled) ? this.__watch(o.disabled, (context, newValue) => { const disabled = (o.disabled = isFunction(o.disabled)
? this.__watch(o.disabled, (context, newValue) => {
this.setEnable(!newValue); this.setEnable(!newValue);
}) : o.disabled; })
: o.disabled);
if (disabled) { if (disabled) {
this.setEnable(false); this.setEnable(false);
} }
} }
if (this.options.invalid) { if (this.options.invalid) {
const invalid = o.invalid = isFunction(o.invalid) ? this.__watch(o.invalid, (context, newValue) => { const invalid = (o.invalid = isFunction(o.invalid)
? this.__watch(o.invalid, (context, newValue) => {
this.setValid(!newValue); this.setValid(!newValue);
}) : o.invalid; })
: o.invalid);
if (invalid) { if (invalid) {
this.setValid(false); this.setValid(false);
} }
@ -365,10 +411,17 @@ export class Widget extends OB {
_initElement() { _initElement() {
this.__isMounting = true; this.__isMounting = true;
// 当开启worker模式时,可以通过$render来实现另一种效果 // 当开启worker模式时,可以通过$render来实现另一种效果
const workerMode = Providers.getProvider("bi.provider.system").getWorkerMode(); const workerMode =
const render = isFunction(this.options.render) ? this.options.render : (workerMode ? (this.$render || this.render) : this.render); Providers.getProvider("bi.provider.system").getWorkerMode();
const render = isFunction(this.options.render)
? this.options.render
: workerMode
? this.$render || this.render
: this.render;
let els = render && render.call(this); let els = render && render.call(this);
els = this.options.configRender ? this.options.configRender.call(this, els) : els; els = this.options.configRender
? this.options.configRender.call(this, els)
: els;
els = Plugin.getRender(this.options.type, els); els = Plugin.getRender(this.options.type, els);
if (isPlainObject(els)) { if (isPlainObject(els)) {
els = [els]; els = [els];
@ -378,7 +431,7 @@ export class Widget extends OB {
each(els, (i, el) => { each(els, (i, el) => {
if (el) { if (el) {
_lazyCreateWidget(el, { _lazyCreateWidget(el, {
element: this, element: this
}); });
} }
}); });
@ -400,16 +453,34 @@ export class Widget extends OB {
* @private * @private
*/ */
_mount(force, deep, lifeHook, predicate, layer) { _mount(force, deep, lifeHook, predicate, layer) {
if (!force && (this._isMounted || !this.isVisible() || this.__asking === true || !(this._isRoot === true || (this._parent && this._parent._isMounted === true)))) { if (
!force &&
(this._isMounted ||
!this.isVisible() ||
this.__asking === true ||
!(
this._isRoot === true ||
(this._parent && this._parent._isMounted === true)
))
) {
return false; return false;
} }
layer = layer || 0; layer = layer || 0;
lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount"); lifeHook !== false &&
!this.__async &&
callLifeHook(this, "beforeMount");
this._isMounted = true; this._isMounted = true;
this.__isMounting = false; this.__isMounting = false;
for (const key in this._children) { for (const key in this._children) {
const child = this._children[key]; const child = this._children[key];
child._mount && child._mount(deep ? force : false, deep, lifeHook, predicate, layer + 1); child._mount &&
child._mount(
deep ? force : false,
deep,
lifeHook,
predicate,
layer + 1
);
} }
if (this._parent) { if (this._parent) {
if (!this._parent.isEnabled()) { if (!this._parent.isEnabled()) {
@ -484,7 +555,9 @@ export class Widget extends OB {
} }
// 递归将所有子组件使能 // 递归将所有子组件使能
each(this._children, (i, child) => { each(this._children, (i, child) => {
!child._manualSetEnable && child._setEnable && child._setEnable(enable); !child._manualSetEnable &&
child._setEnable &&
child._setEnable(enable);
}); });
} }
@ -532,7 +605,10 @@ export class Widget extends OB {
this.__setElementVisible(true); this.__setElementVisible(true);
this._mount(); this._mount();
if (o.animation && !lastVisible) { if (o.animation && !lastVisible) {
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`).addClass(`${o.animation}-enter`); this.element
.removeClass(`${o.animation}-leave`)
.removeClass(`${o.animation}-leave-active`)
.addClass(`${o.animation}-enter`);
if (this._requestAnimationFrame) { if (this._requestAnimationFrame) {
cancelAnimationFrame(this._requestAnimationFrame); cancelAnimationFrame(this._requestAnimationFrame);
} }
@ -544,12 +620,17 @@ export class Widget extends OB {
clearTimeout(this._animationDuring); clearTimeout(this._animationDuring);
} }
this._animationDuring = setTimeout(() => { this._animationDuring = setTimeout(() => {
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`); this.element
.removeClass(`${o.animation}-enter`)
.removeClass(`${o.animation}-enter-active`);
}, o.animationDuring); }, o.animationDuring);
} }
} else if (visible === false) { } else if (visible === false) {
if (o.animation && lastVisible) { if (o.animation && lastVisible) {
this.element.removeClass(`${o.animation}-enter`).removeClass(`${o.animation}-enter-active`).addClass(`${o.animation}-leave`); this.element
.removeClass(`${o.animation}-enter`)
.removeClass(`${o.animation}-enter-active`)
.addClass(`${o.animation}-leave`);
if (this._requestAnimationFrame) { if (this._requestAnimationFrame) {
cancelAnimationFrame(this._requestAnimationFrame); cancelAnimationFrame(this._requestAnimationFrame);
} }
@ -561,7 +642,9 @@ export class Widget extends OB {
clearTimeout(this._animationDuring); clearTimeout(this._animationDuring);
} }
this._animationDuring = setTimeout(() => { this._animationDuring = setTimeout(() => {
this.element.removeClass(`${o.animation}-leave`).removeClass(`${o.animation}-leave-active`); this.element
.removeClass(`${o.animation}-leave`)
.removeClass(`${o.animation}-leave-active`);
this.__setElementVisible(false); this.__setElementVisible(false);
}, o.animationDuring); }, o.animationDuring);
} else { } else {
@ -687,21 +770,13 @@ export class Widget extends OB {
return this.element.css(name, value); return this.element.css(name, value);
} }
getText() { getText() {}
}
setText(text) {
} setText(text) {}
getValue() { getValue() {}
} setValue(value) {}
setValue(value) {
}
isEnabled() { isEnabled() {
return this.options.disabled === true ? false : !this.options._disabled; return this.options.disabled === true ? false : !this.options._disabled;
@ -851,8 +926,10 @@ export class Widget extends OB {
} }
} }
let context = null, current = null; let context = null,
const contextStack = [], currentStack = []; current = null;
const contextStack = [],
currentStack = [];
Widget.pushContext = function (_context) { Widget.pushContext = function (_context) {
if (context) contextStack.push(context); if (context) contextStack.push(context);
@ -901,7 +978,7 @@ export function useStore(_store) {
}, },
set(target, key, value) { set(target, key, value) {
return Reflect.set(origin, key, value); return Reflect.set(origin, key, value);
}, }
}); });
current._store = function () { current._store = function () {
origin = (_store || currentStore).apply(this, arguments); origin = (_store || currentStore).apply(this, arguments);
@ -967,25 +1044,31 @@ export function watch(vm, watch, handler) {
const innerHandler = watch[key]; const innerHandler = watch[key];
if (isArray(handler)) { if (isArray(handler)) {
for (let i = 0; i < handler.length; i++) { for (let i = 0; i < handler.length; i++) {
watchers.push(Fix.watch(vm.model, key, innerHandler, { watchers.push(
store: vm, Fix.watch(vm.model, key, innerHandler, {
})); store: vm
})
);
} }
} else { } else {
watchers.push(Fix.watch(vm.model, key, innerHandler, { watchers.push(
store: vm, Fix.watch(vm.model, key, innerHandler, {
})); store: vm
})
);
} }
} }
// vm中一定有_widget // vm中一定有_widget
Widget.current._watchers || (Widget.current._watchers = []); Widget.current._watchers || (Widget.current._watchers = []);
Widget.current._watchers = Widget.current._watchers.concat(watchers); Widget.current._watchers =
Widget.current._watchers.concat(watchers);
return; return;
} }
handler = watch; handler = watch;
watch = vm; watch = vm;
Widget.current.$watchDelayCallbacks || (Widget.current.$watchDelayCallbacks = []); Widget.current.$watchDelayCallbacks ||
(Widget.current.$watchDelayCallbacks = []);
Widget.current.$watchDelayCallbacks.push([watch, handler]); Widget.current.$watchDelayCallbacks.push([watch, handler]);
} }
} }
@ -1065,7 +1148,7 @@ Widget.registerRenderEngine({
}, },
createFragment() { createFragment() {
return document.createDocumentFragment(); return document.createDocumentFragment();
}, }
}); });
export function mount(widget, container, predicate, hydrate) { export function mount(widget, container, predicate, hydrate) {
@ -1087,7 +1170,7 @@ export function mount(widget, container, predicate, hydrate) {
const c = Widget._renderEngine.createElement; const c = Widget._renderEngine.createElement;
DOM.patchProps(widget.element, c(c(container).children()[0])); DOM.patchProps(widget.element, c(c(container).children()[0]));
const triggerLifeHook = w => { const triggerLifeHook = (w) => {
w.beforeMount && w.beforeMount(); w.beforeMount && w.beforeMount();
w.mounted && w.mounted(); w.mounted && w.mounted();
each(w._children, (i, child) => { each(w._children, (i, child) => {

1
src/core/5.inject.js

@ -4,6 +4,7 @@ import { Widget } from "./4.widget";
import { Plugin } from "./6.plugin"; import { Plugin } from "./6.plugin";
import { aspect } from "./structure"; import { aspect } from "./structure";
import { Events } from "./constant"; import { Events } from "./constant";
import { _global } from "./0.foundation";
const moduleInjection = {}, moduleInjectionMap = { const moduleInjection = {}, moduleInjectionMap = {
components: {}, components: {},

1
src/core/controller/controller.resizer.js

@ -6,6 +6,7 @@
import { Controller } from "./0.controller"; import { Controller } from "./0.controller";
import { isNull, each, debounce, isNotNull, isFunction } from "../2.base"; import { isNull, each, debounce, isNotNull, isFunction } from "../2.base";
import { Widget } from "../4.widget"; import { Widget } from "../4.widget";
import { _global } from "../0.foundation";
export class ResizeController extends Controller { export class ResizeController extends Controller {
init() { init() {

147
src/core/func/alias.js

@ -1,20 +1,9 @@
import { each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseDateTime, values } from "../2.base"; import { each, isFunction, isNull, isObject, isPlainObject, keys, leftPad, parseDateTime, values } from "../2.base";
import { replaceAll } from "./string"; import { replaceAll } from "./string";
import { getFullDayName, getMonthName, getTimezone } from "./date"; import { getFullDayName, getMonthName, getTimezone } from "./date";
import { _global } from "../0.foundation";
let _global; export const specialCharsMap = {};
if (typeof window !== "undefined") {
_global = window;
} else if (typeof global !== "undefined") {
_global = global;
} else if (typeof self !== "undefined") {
_global = self;
} else {
_global = this;
}
if (!_global.BI) {
_global.BI = {};
}
function isEmpty(value) { function isEmpty(value) {
// 判断是否为空值 // 判断是否为空值
@ -88,7 +77,7 @@ function _eFormat(text, fmt) {
// 格式化指数的部分 // 格式化指数的部分
magnitude = formatExponential(format, magnitude, magnitudeNeg); magnitude = formatExponential(format, magnitude, magnitudeNeg);
return neg + num + "E" + magnitude; return `${neg + num}E${magnitude}`;
} }
// 获取format格式规定的数量级的形式 // 获取format格式规定的数量级的形式
@ -100,7 +89,7 @@ function _eFormat(text, fmt) {
format = format.split(/e/ig)[1]; format = format.split(/e/ig)[1];
while (num.length < format.length) { while (num.length < format.length) {
num = "0" + num; num = `0${num}`;
} }
// 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了 // 如果magnitudeNeg是一个"-",而且num正好全是0,那么就别显示负号了
@ -151,8 +140,9 @@ function _eFormat(text, fmt) {
// 判断num通过round函数之后是否有进位 // 判断num通过round函数之后是否有进位
function isValueCarried(num) { function isValueCarried(num) {
let roundNum = Math.round(num); let roundNum = Math.round(num);
num = (num + "").split(".")[0]; num = (`${num}`).split(".")[0];
roundNum = (roundNum + "").split(".")[0]; roundNum = (`${roundNum}`).split(".")[0];
return num.length !== roundNum.length; return num.length !== roundNum.length;
} }
} }
@ -171,6 +161,7 @@ function _dealNumberPrecision(text, fright) {
precision++; precision++;
} }
} }
return Number(text).toFixed(precision); return Number(text).toFixed(precision);
} }
@ -181,7 +172,7 @@ function _dealNumberPrecision(text, fright) {
* 数字格式 * 数字格式
*/ */
function _numberFormat(text, format) { function _numberFormat(text, format) {
text = text + ""; text = `${text}`;
// 在调用数字格式的时候如果text里没有任何数字则不处理 // 在调用数字格式的时候如果text里没有任何数字则不处理
if (!(/[0-9]/.test(text)) || !format) { if (!(/[0-9]/.test(text)) || !format) {
@ -192,14 +183,14 @@ function _numberFormat(text, format) {
const numMod = format.indexOf(";"); const numMod = format.indexOf(";");
if (numMod > -1) { if (numMod > -1) {
if (text >= 0) { if (text >= 0) {
return _numberFormat(text + "", format.substring(0, numMod)); return _numberFormat(`${text}`, format.substring(0, numMod));
} }
return _numberFormat((-text) + "", format.substring(numMod + 1));
return _numberFormat(`${-text}`, format.substring(numMod + 1));
} else { } else {
// 兼容格式处理负数的情况(copy:fr-jquery.format.js) // 兼容格式处理负数的情况(copy:fr-jquery.format.js)
if (+text < 0 && format.charAt(0) !== "-") { if (+text < 0 && format.charAt(0) !== "-") {
return _numberFormat((-text) + "", "-" + format); return _numberFormat(`${-text}`, `-${format}`);
} }
} }
@ -218,19 +209,19 @@ function _numberFormat(text, format) {
let right = _dealWithRight(tright, fright); let right = _dealWithRight(tright, fright);
if (right.leftPlus) { if (right.leftPlus) {
// 小数点后有进位 // 小数点后有进位
tleft = parseInt(tleft) + 1 + ""; tleft = `${parseInt(tleft) + 1}`;
tleft = isNaN(tleft) ? "1" : tleft; tleft = isNaN(tleft) ? "1" : tleft;
} }
right = right.num; right = right.num;
let left = _dealWithLeft(tleft, fleft); let left = _dealWithLeft(tleft, fleft);
if (!(/[0-9]/.test(left))) { if (!(/[0-9]/.test(left))) {
left = left + "0"; left = `${left}0`;
} }
if (!(/[0-9]/.test(right))) { if (!(/[0-9]/.test(right))) {
return left + right; return left + right;
} else { } else {
return left + "." + right; return `${left}.${right}`;
} }
} }
@ -272,7 +263,7 @@ function _dealWithRight(tright, fright) {
if (numReg) { if (numReg) {
const num = numReg[0]; const num = numReg[0];
const orilen = num.length; const orilen = num.length;
let newnum = parseInt(num) + 1 + ""; let newnum = `${parseInt(num) + 1}`;
// 进位到整数部分 // 进位到整数部分
if (newnum.length > orilen) { if (newnum.length > orilen) {
newnum = newnum.substring(1); newnum = newnum.substring(1);
@ -284,6 +275,7 @@ function _dealWithRight(tright, fright) {
} }
} }
result.num = right; result.num = right;
return result; return result;
} }
@ -324,7 +316,7 @@ function _dealWithLeft(tleft, fleft) {
if (com) { if (com) {
combo = com[0].length - 1; combo = com[0].length - 1;
} }
left = "," + left; left = `,${left}`;
} }
break; break;
default : default :
@ -345,15 +337,16 @@ function _dealWithLeft(tleft, fleft) {
newstr = ""; newstr = "";
let n = res.length - 1 - combo; let n = res.length - 1 - combo;
for (; n >= 0; n = n - combo) { for (; n >= 0; n = n - combo) {
newstr = res.substring(n, combo) + "," + newstr; newstr = `${res.substring(n, combo)},${newstr}`;
} }
const lres = res.substring(0, n + combo); const lres = res.substring(0, n + combo);
if (!isEmpty(lres)) { if (!isEmpty(lres)) {
newstr = lres + "," + newstr; newstr = `${lres},${newstr}`;
} }
} }
left = left.replace(/[0-9]+,/, newstr); left = left.replace(/[0-9]+,/, newstr);
} }
return left; return left;
} }
@ -367,7 +360,7 @@ export const cjkEncode = function (text) {
for (let i = 0; i < text.length; i++) { for (let i = 0; i < text.length; i++) {
const code = text.charCodeAt(i); const code = text.charCodeAt(i);
if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]". if (code >= 128 || code === 91 || code === 93) {// 91 is "[", 93 is "]".
newText += "[" + code.toString(16) + "]"; newText += `[${code.toString(16)}]`;
} else { } else {
newText += text.charAt(i); newText += text.charAt(i);
} }
@ -401,7 +394,7 @@ export const cjkDecode = function (text) {
const subText = text.substring(i + 1, rightIdx); const subText = text.substring(i + 1, rightIdx);
// james:主要是考虑[CDATA[]]这样的值的出现 // james:主要是考虑[CDATA[]]这样的值的出现
if (subText.length > 0) { if (subText.length > 0) {
ch = String.fromCharCode(eval("0x" + subText)); ch = String.fromCharCode(eval(`0x${subText}`));
} }
i = rightIdx; i = rightIdx;
@ -424,13 +417,11 @@ const SPECIAL_TAGS = {
"\n": "&#10;", "\n": "&#10;",
}; };
export const htmlEncode = function (text) { export const htmlEncode = function (text) {
return isNull(text) ? "" : replaceAll(text + "", keys(SPECIAL_TAGS).join("|"), function (v) { return isNull(text) ? "" : replaceAll(`${text}`, keys(SPECIAL_TAGS).join("|"), v => SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v);
return SPECIAL_TAGS[v] ? SPECIAL_TAGS[v] : v;
});
}; };
// html decode // html decode
export const htmlDecode = function (text) { export const htmlDecode = function (text) {
return isNull(text) ? "" : replaceAll(text + "", values(SPECIAL_TAGS).join("|"), function (v) { return isNull(text) ? "" : replaceAll(`${text}`, values(SPECIAL_TAGS).join("|"), v => {
switch (v) { switch (v) {
case "&amp;": case "&amp;":
return "&"; return "&";
@ -453,7 +444,7 @@ export const htmlDecode = function (text) {
export const cjkEncodeDO = function (o) { export const cjkEncodeDO = function (o) {
if (isPlainObject(o)) { if (isPlainObject(o)) {
const result = {}; const result = {};
each(o, function (v, k) { each(o, (v, k) => {
if (!(typeof v === "string")) { if (!(typeof v === "string")) {
v = jsonEncode(v); v = jsonEncode(v);
} }
@ -461,8 +452,10 @@ export const cjkEncodeDO = function (o) {
k = cjkEncode(k); k = cjkEncode(k);
result[k] = cjkEncode(v); result[k] = cjkEncode(v);
}); });
return result; return result;
} }
return o; return o;
}; };
@ -485,18 +478,20 @@ export const jsonEncode = function (o) {
const encodeString = function (s) { const encodeString = function (s) {
if (/["\\\x00-\x1f]/.test(s)) { if (/["\\\x00-\x1f]/.test(s)) {
return "\"" + s.replace(/([\x00-\x1f\\"])/g, function (a, b) { return `"${s.replace(/([\x00-\x1f\\"])/g, (a, b) => {
let c = m[b]; let c = m[b];
if (c) { if (c) {
return c; return c;
} }
c = b.charCodeAt(); c = b.charCodeAt();
return "\\u00" +
Math.floor(c / 16).toString(16) + return `\\u00${
(c % 16).toString(16); Math.floor(c / 16).toString(16)
}) + "\""; }${(c % 16).toString(16)}`;
})}"`;
} }
return "\"" + s + "\"";
return `"${s}"`;
}; };
const encodeArray = function (o) { const encodeArray = function (o) {
@ -517,6 +512,7 @@ export const jsonEncode = function (o) {
} }
} }
a.push("]"); a.push("]");
return a.join(""); return a.join("");
}; };
@ -560,12 +556,11 @@ export const jsonEncode = function (o) {
} }
} }
a.push("}"); a.push("}");
return a.join("");
return a.join("");
}; };
export const jsonDecode = function (text) { export const jsonDecode = function (text) {
let jo; let jo;
try { try {
jo = JSON.parse(text); jo = JSON.parse(text);
@ -578,7 +573,7 @@ export const jsonDecode = function (text) {
* 比如var str = "{'a':'b'}",这种形式的字符串转换为JSON就会抛异常 * 比如var str = "{'a':'b'}",这种形式的字符串转换为JSON就会抛异常
*/ */
try { try {
jo = new Function("return " + text)() || {}; jo = new Function(`return ${text}`)() || {};
} catch (e) { } catch (e) {
// do nothing // do nothing
} }
@ -594,6 +589,7 @@ export const jsonDecode = function (text) {
if (!json || typeof json !== "string") { if (!json || typeof json !== "string") {
return false; return false;
} }
return json.indexOf("__time__") !== -1; return json.indexOf("__time__") !== -1;
} }
@ -612,7 +608,7 @@ export const jsonDecode = function (text) {
} }
return o; return o;
})(jo); }(jo));
}; };
/** /**
@ -624,34 +620,31 @@ export const jsonDecode = function (text) {
* BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a * BI.getEncodeURL("design/{tableName}/{fieldName}",{tableName: "A", fieldName: "a"}) // design/A/a
*/ */
export const getEncodeURL = function (urlTemplate, param) { export const getEncodeURL = function (urlTemplate, param) {
return replaceAll(urlTemplate, "\\{(.*?)\\}", function (ori, str) { return replaceAll(urlTemplate, "\\{(.*?)\\}", (ori, str) => encodeURIComponent(isObject(param) ? param[str] : param));
return encodeURIComponent(isObject(param) ? param[str] : param);
});
}; };
export const encodeURIComponent = function (url) { export const encodeURIComponent = function (url) {
BI.specialCharsMap = BI.specialCharsMap || {};
url = url || ""; url = url || "";
url = replaceAll(url + "", keys(BI.specialCharsMap || []).join("|"), function (str) { url = replaceAll(`${url}`, keys(specialCharsMap || []).join("|"), str => {
switch (str) { switch (str) {
case "\\": case "\\":
return BI.specialCharsMap["\\\\"] || str; return specialCharsMap["\\\\"] || str;
default: default:
return BI.specialCharsMap[str] || str; return specialCharsMap[str] || str;
} }
}); });
return _global.encodeURIComponent(url); return _global.encodeURIComponent(url);
}; };
export const decodeURIComponent = function (url) { export const decodeURIComponent = function (url) {
const reserveSpecialCharsMap = {}; const reserveSpecialCharsMap = {};
each(BI.specialCharsMap, function (initialChar, encodeChar) { each(specialCharsMap, (initialChar, encodeChar) => {
reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar; reserveSpecialCharsMap[encodeChar] = initialChar === "\\\\" ? "\\" : initialChar;
}); });
url = url || ""; url = url || "";
url = replaceAll(url + "", keys(reserveSpecialCharsMap || []).join("|"), function (str) { url = replaceAll(`${url}`, keys(reserveSpecialCharsMap || []).join("|"), str => reserveSpecialCharsMap[str] || str);
return reserveSpecialCharsMap[str] || str;
});
return _global.decodeURIComponent(url); return _global.decodeURIComponent(url);
}; };
@ -676,7 +669,7 @@ export const contentFormat = function (cv, fmt) {
cv = new Date(cv); cv = new Date(cv);
} else { } else {
// 字符串类型转化为date类型 // 字符串类型转化为date类型
cv = new Date(Date.parse(("" + cv).replace(/-|\./g, "/"))); cv = new Date(Date.parse((`${cv}`).replace(/-|\./g, "/")));
} }
} }
if (!isInvalidDate(cv) && !isNull(cv)) { if (!isInvalidDate(cv) && !isNull(cv)) {
@ -692,6 +685,7 @@ export const contentFormat = function (cv, fmt) {
} }
// ¤ - 货币格式 // ¤ - 货币格式
text = text.replace(/¤/g, "¥"); text = text.replace(/¤/g, "¥");
return text; return text;
}; };
@ -753,6 +747,7 @@ export const str2Date = function (str, format) {
return null; return null;
} }
const fmt = parseFmt(format); const fmt = parseFmt(format);
return parseDateTime(str, fmt); return parseDateTime(str, fmt);
}; };
@ -777,8 +772,8 @@ export const date2Str = function (date, format) {
const ch = format.charAt(i); const ch = format.charAt(i);
if (flagch !== ch) { if (flagch !== ch) {
result += compileJFmt({ result += compileJFmt({
char: flagch, "char": flagch,
str: str, str,
len: i - start, len: i - start,
}, date); }, date);
flagch = ch; flagch = ch;
@ -789,22 +784,23 @@ export const date2Str = function (date, format) {
} }
} }
result += compileJFmt({ result += compileJFmt({
char: flagch, "char": flagch,
str: str, str,
len: len - start, len: len - start,
}, date); }, date);
} }
return result; return result;
function compileJFmt(jfmt, date) { function compileJFmt(jfmt, date) {
let str = jfmt.str, len = jfmt.len, ch = jfmt["char"]; let str = jfmt.str, len = jfmt.len, ch = jfmt.char;
switch (ch) { switch (ch) {
case "E": // 星期 case "E": // 星期
str = getFullDayName(date.getDay()); str = getFullDayName(date.getDay());
break; break;
case "y": // 年 case "y": // 年
if (len <= 3) { if (len <= 3) {
str = (date.getFullYear() + "").slice(2, 4); str = (`${date.getFullYear()}`).slice(2, 4);
} else { } else {
str = date.getFullYear(); str = date.getFullYear();
} }
@ -815,12 +811,12 @@ export const date2Str = function (date, format) {
} else if (len < 2) { } else if (len < 2) {
str = date.getMonth() + 1; str = date.getMonth() + 1;
} else { } else {
str = leftPad(date.getMonth() + 1 + "", 2, "0"); str = leftPad(`${date.getMonth() + 1}`, 2, "0");
} }
break; break;
case "d": // 日 case "d": // 日
if (len > 1) { if (len > 1) {
str = leftPad(date.getDate() + "", 2, "0"); str = leftPad(`${date.getDate()}`, 2, "0");
} else { } else {
str = date.getDate(); str = date.getDate();
} }
@ -831,28 +827,28 @@ export const date2Str = function (date, format) {
hour = 12; hour = 12;
} }
if (len > 1) { if (len > 1) {
str = leftPad(hour + "", 2, "0"); str = leftPad(`${hour}`, 2, "0");
} else { } else {
str = hour; str = hour;
} }
break; break;
case "H": // 时(24) case "H": // 时(24)
if (len > 1) { if (len > 1) {
str = leftPad(date.getHours() + "", 2, "0"); str = leftPad(`${date.getHours()}`, 2, "0");
} else { } else {
str = date.getHours(); str = date.getHours();
} }
break; break;
case "m": case "m":
if (len > 1) { if (len > 1) {
str = leftPad(date.getMinutes() + "", 2, "0"); str = leftPad(`${date.getMinutes()}`, 2, "0");
} else { } else {
str = date.getMinutes(); str = date.getMinutes();
} }
break; break;
case "s": case "s":
if (len > 1) { if (len > 1) {
str = leftPad(date.getSeconds() + "", 2, "0"); str = leftPad(`${date.getSeconds()}`, 2, "0");
} else { } else {
str = date.getSeconds(); str = date.getSeconds();
} }
@ -867,6 +863,7 @@ export const date2Str = function (date, format) {
str = jfmt.str; str = jfmt.str;
break; break;
} }
return str; return str;
} }
}; };
@ -878,10 +875,11 @@ export const object2Number = function (value) {
if (typeof value === "number") { if (typeof value === "number") {
return value; return value;
} }
const str = value + ""; const str = `${value}`;
if (str.indexOf(".") === -1) { if (str.indexOf(".") === -1) {
return parseInt(str); return parseInt(str);
} }
return parseFloat(str); return parseFloat(str);
}; };
@ -894,7 +892,7 @@ export const object2Date = function (obj) {
} else if (typeof obj === "number") { } else if (typeof obj === "number") {
return new Date(obj); return new Date(obj);
} }
let str = obj + ""; let str = `${obj}`;
str = str.replace(/-/g, "/"); str = str.replace(/-/g, "/");
const dt = new Date(str); const dt = new Date(str);
if (!isInvalidDate(dt)) { if (!isInvalidDate(dt)) {
@ -902,7 +900,6 @@ export const object2Date = function (obj) {
} }
return new Date(); return new Date();
}; };
export const object2Time = function (obj) { export const object2Time = function (obj) {
@ -912,14 +909,14 @@ export const object2Time = function (obj) {
if (obj instanceof Date) { if (obj instanceof Date) {
return obj; return obj;
} }
let str = obj + ""; let str = `${obj}`;
str = str.replace(/-/g, "/"); str = str.replace(/-/g, "/");
let dt = new Date(str); let dt = new Date(str);
if (!isInvalidDate(dt)) { if (!isInvalidDate(dt)) {
return dt; return dt;
} }
if (str.indexOf("/") === -1 && str.indexOf(":") !== -1) { if (str.indexOf("/") === -1 && str.indexOf(":") !== -1) {
dt = new Date("1970/01/01 " + str); dt = new Date(`1970/01/01 ${str}`);
if (!isInvalidDate(dt)) { if (!isInvalidDate(dt)) {
return dt; return dt;
} }
@ -928,6 +925,6 @@ export const object2Time = function (obj) {
if (!isInvalidDate(dt)) { if (!isInvalidDate(dt)) {
return dt; return dt;
} }
return new Date();
return new Date();
}; };

1
src/core/func/date.js

@ -3,6 +3,7 @@ import { getDate, getTime, parseInt } from "../2.base";
import { i18nText } from "../utils"; import { i18nText } from "../utils";
import { StartOfWeek } from "../constant"; import { StartOfWeek } from "../constant";
import { isKhtml } from "../platform/web"; import { isKhtml } from "../platform/web";
import { _global } from "../0.foundation";
const SECOND = 1000; const SECOND = 1000;
const MINUTE = 60 * SECOND; const MINUTE = 60 * SECOND;

5
src/core/index.js

@ -14,10 +14,10 @@ export { PopoverController } from "./controller/controller.popover";
export { ResizeController } from "./controller/controller.resizer"; export { ResizeController } from "./controller/controller.resizer";
export { TooltipsController } from "./controller/controller.tooltips"; export { TooltipsController } from "./controller/controller.tooltips";
export * from "./decorator";
export * from "./2.base"; export * from "./2.base";
export * from "./3.ob"; export * from "./3.ob";
export * from "./4.widget"; export * from "./4.widget";
export * from "./5.inject"; export * from "./5.inject";
export * from "./6.plugin"; export * from "./6.plugin";
export * from "./system"; export * from "./system";
@ -32,3 +32,6 @@ export * from "./logic";
export * from "./wrapper"; export * from "./wrapper";
export * from "./platform/web"; export * from "./platform/web";
export * from "./utils"; export * from "./utils";
export { shortcut, provider } from "./decorator";

1
src/core/loader/loader.style.js

@ -5,6 +5,7 @@
*/ */
import { extend, isNotNull } from "../2.base"; import { extend, isNotNull } from "../2.base";
import { OB } from "../3.ob"; import { OB } from "../3.ob";
import { _global } from "../0.foundation";
export class StyleLoaderManager extends OB { export class StyleLoaderManager extends OB {
_defaultConfig() { _defaultConfig() {

1
src/core/platform/web/function.js

@ -1,5 +1,6 @@
// 浏览器相关方法 // 浏览器相关方法
import { isString } from "../../2.base"; import { isString } from "../../2.base";
import { _global } from "../../0.foundation";
let __isIE; let __isIE;

6
src/core/platform/web/jquery/_jquery.js vendored

@ -1,3 +1,7 @@
import jQuery from "jquery"; import jQuery from "jquery";
import { _global } from "@/core/0.foundation";
BI.jQuery = BI.$ = jQuery; // todo:先垫着,不然开发会崩
_global.BI = _global.BI || {};
_global.BI.jQuery = _global.BI.$ = jQuery;

1
src/core/platform/web/jquery/fn.js vendored

@ -3,6 +3,7 @@ import { htmlEncode } from "../../../func";
import { toUpperCase, remove, camelize, isKey, isNull, isNotEmptyString, map, hyphenate } from "../../../2.base"; import { toUpperCase, remove, camelize, isKey, isNull, isNotEmptyString, map, hyphenate } from "../../../2.base";
import { makeFirstPY } from "../../../utils"; import { makeFirstPY } from "../../../utils";
import { createWidget } from "../../../5.inject"; import { createWidget } from "../../../5.inject";
import { _global } from "../../../0.foundation";
BI.jQuery.fn.extend({ BI.jQuery.fn.extend({

2
src/core/platform/web/jquery/jquery.mousewheel.js

@ -1,3 +1,5 @@
import { _global } from "../../../0.foundation";
/* eslint-disable */ /* eslint-disable */
/* ! /* !
* jQuery Mousewheel 3.1.13 * jQuery Mousewheel 3.1.13

7
src/core/structure/aes.js

@ -7,10 +7,11 @@ code.google.com/p/crypto-js/wiki/License
/** /**
* CryptoJS core components. * CryptoJS core components.
*/ */
BI.CRYPT_TYPE = BI.CRYPT_TYPE || {};
BI.CRYPT_TYPE.AES = "aes";
const CryptoJS = CryptoJS || (function (Math, undefined) {
export const CRYPT_TYPE = { AES: "aes" };
const CryptoJS = (function (Math, undefined) {
/** /**
* CryptoJS namespace. * CryptoJS namespace.
*/ */

2
src/core/structure/prefixIntervalTree.js

@ -1,3 +1,5 @@
import { _global } from "../0.foundation";
// 线段树 // 线段树
const parent = function (node) { const parent = function (node) {
return Math.floor(node / 2); return Math.floor(node / 2);

72
src/core/system.js

@ -3,7 +3,8 @@
* @version 2.0 * @version 2.0
* Created by windy on 2021/6/30 * Created by windy on 2021/6/30
*/ */
import { deepExtend, extend, inherit } from "./2.base"; import { prepares } from "./0.foundation";
import { deepExtend, extend, inherit, object } from "./2.base";
import { OB } from "./3.ob"; import { OB } from "./3.ob";
import { Providers } from "./5.inject"; import { Providers } from "./5.inject";
import { provider } from "./decorator"; import { provider } from "./decorator";
@ -68,6 +69,39 @@ const sizeMap = {
L: 24, L: 24,
}; };
class SystemProviderOB extends OB {
getSize () {
const size = system.size;
const H_GAP_SIZE = sizeMap[size.H_GAP_SIZE];
const V_GAP_SIZE = sizeMap[size.V_GAP_SIZE];
return extend({}, size, {
H_GAP_SIZE,
V_GAP_SIZE,
});
}
getResponsiveMode () {
return system.responsiveMode;
}
getWorkerMode () {
return system.workerMode;
}
getLayoutOptimize () {
return system.layoutOptimize;
}
getDependencies () {
return system.dependencies;
}
getLoading(config) {
return system.loadingCreator(config);
}
}
@provider() @provider()
export class SystemProvider { export class SystemProvider {
static xtype = "bi.provider.system"; static xtype = "bi.provider.system";
@ -106,39 +140,7 @@ export class SystemProvider {
}; };
$get() { $get() {
return inherit(OB, { return SystemProviderOB;
getSize () {
const size = system.size;
const H_GAP_SIZE = sizeMap[size.H_GAP_SIZE];
const V_GAP_SIZE = sizeMap[size.V_GAP_SIZE];
return extend({}, size, {
H_GAP_SIZE,
V_GAP_SIZE,
});
},
getResponsiveMode () {
return system.responsiveMode;
},
getWorkerMode () {
return system.workerMode;
},
getLayoutOptimize () {
return system.layoutOptimize;
},
getDependencies () {
return system.dependencies;
},
getLoading(config) {
return system.loadingCreator(config);
},
});
} }
} }
@ -146,7 +148,7 @@ export const SIZE_CONSANTS = {};
// 不再增加线型的配置了,之后不维护前置版本直接删掉,都用实线连接线 // 不再增加线型的配置了,之后不维护前置版本直接删掉,都用实线连接线
export const STYLE_CONSTANTS = {}; export const STYLE_CONSTANTS = {};
BI.prepares.push(() => { prepares.push(() => {
extend(SIZE_CONSANTS, Providers.getProvider("bi.provider.system").getSize()); extend(SIZE_CONSANTS, Providers.getProvider("bi.provider.system").getSize());
STYLE_CONSTANTS.LINK_LINE_TYPE = SIZE_CONSANTS.LIST_ITEM_HEIGHT === 24 ? "dashed" : "solid"; STYLE_CONSTANTS.LINK_LINE_TYPE = SIZE_CONSANTS.LIST_ITEM_HEIGHT === 24 ? "dashed" : "solid";
}); });

1
src/core/utils/events/mousemovetracker.js

@ -1,5 +1,6 @@
import { EventListener } from "./eventlistener"; import { EventListener } from "./eventlistener";
import { bind } from "../../2.base"; import { bind } from "../../2.base";
import { _global } from "../../0.foundation";
const cancelAnimationFrame = const cancelAnimationFrame =
_global.cancelAnimationFrame || _global.cancelAnimationFrame ||

1
src/core/utils/events/wheelhandler.js

@ -1,4 +1,5 @@
import { bind } from "../../2.base"; import { bind } from "../../2.base";
import { _global } from "../../0.foundation";
const PIXEL_STEP = 10; const PIXEL_STEP = 10;
const LINE_HEIGHT = 40; const LINE_HEIGHT = 40;

6
test/prepare.js

@ -1,6 +0,0 @@
!(function () {
// 先把准备环境准备好
while(BI.prepares && BI.prepares.length > 0) {
BI.prepares.shift()();
}
})();

47
test/utils.js

@ -1,47 +0,0 @@
!(function () {
BI.Test = {};
BI._.extend(BI.Test, {
createWidget: function (widgetJson) {
var widget = BI.createWidget(BI.extend(widgetJson, {
root: true
}));
widget.element.appendTo("body");
return widget;
},
/**
* 模拟一次输入框的keydown事件
*/
triggerKeyDown: function (element, value, keyCode, callback) {
// keydown
var e = BI.$.Event("keydown");
e.keyCode = keyCode;
element.trigger(e);
// input
BI.isNotNull(value) && element.val(value);
var e1 = BI.$.Event("input");
e1.originalEvent = {};
e1.keyCode = keyCode;
element.trigger(e1);
// keyup 至少等300ms后触发
var e2 = BI.$.Event("keyup");
e2.keyCode = keyCode;
element.trigger(e2);
BI.delay(function () {
callback();
}, 300);
},
/**
* 模拟一次鼠标hover
*/
triggerMouseover: function (element, callback) {
// keydown
var e = BI.$.Event("mouseover");
element.trigger(e);
callback && callback();
}
})
})();
Loading…
Cancel
Save