Browse Source

KERNEL-14316 chore:代码调整

es6
Treecat 2 years ago
parent
commit
3d08899ec4
  1. 283
      packages/fineui/src/core/2.base.js
  2. 4
      packages/fineui/src/core/utils/i18n.js

283
packages/fineui/src/core/2.base.js

@ -10,10 +10,7 @@ import { prepares, _global } from "./0.foundation";
import { CRYPT_TYPE, aesDecrypt, aesEncrypt } from "./structure/aes";
import { Date as DateEnum, getMonthDays } from "./func/date";
/**
* todo: 理论这么写逻辑没问题摇个人把这个 BI 干掉
*/
const BI = { _ };
const lodashFns = {};
function traverse(func, context) {
return function (value, key, obj) {
@ -22,15 +19,15 @@ function traverse(func, context) {
}
function _apply(name) {
return function () {
return BI._[name](...arguments);
return _[name](...arguments);
};
}
function _applyFunc(name) {
return function () {
const args = Array.prototype.slice.call(arguments, 0);
args[1] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1];
args[1] = _.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1];
return BI._[name](...args);
return _[name](...args);
};
}
@ -160,10 +157,10 @@ export function trans2Element(widgets) {
}
// 集合相关方法
BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => {
BI[name] = _apply(name);
_.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => {
lodashFns[name] = _apply(name);
});
BI._.each(
_.each(
[
"get",
"set",
@ -189,41 +186,41 @@ BI._.each(
],
name => {
if (name === "any") {
BI[name] = _applyFunc("some");
lodashFns[name] = _applyFunc("some");
} else {
BI[name] = _applyFunc(name);
lodashFns[name] = _applyFunc(name);
}
}
);
export const where = BI.where;
export const findWhere = BI.findWhere;
export const invoke = BI.invoke;
export const pluck = BI.pluck;
export const shuffle = BI.shuffle;
export const sample = BI.sample;
export const toArray = BI.toArray;
export const size = BI.size;
export const get = BI.get;
export const set = BI.set;
export const each = BI.each;
export const map = BI.map;
export const reduce = BI.reduce;
export const reduceRight = BI.reduceRight;
export const find = BI.find;
export const filter = BI.filter;
export const reject = BI.reject;
export const every = BI.every;
export const all = BI.all;
export const some = BI.some;
export const any = BI.any;
export const max = BI.max;
export const min = BI.min;
export const sortBy = BI.sortBy;
export const groupBy = BI.groupBy;
export const indexBy = BI.indexBy;
export const countBy = BI.countBy;
export const partition = BI.partition;
export const clamp = BI.clamp;
export const where = lodashFns.where;
export const findWhere = lodashFns.findWhere;
export const invoke = lodashFns.invoke;
export const pluck = lodashFns.pluck;
export const shuffle = lodashFns.shuffle;
export const sample = lodashFns.sample;
export const toArray = lodashFns.toArray;
export const size = lodashFns.size;
export const get = lodashFns.get;
export const set = lodashFns.set;
export const each = lodashFns.each;
export const map = lodashFns.map;
export const reduce = lodashFns.reduce;
export const reduceRight = lodashFns.reduceRight;
export const find = lodashFns.find;
export const filter = lodashFns.filter;
export const reject = lodashFns.reject;
export const every = lodashFns.every;
export const all = lodashFns.all;
export const some = lodashFns.some;
export const any = lodashFns.any;
export const max = lodashFns.max;
export const min = lodashFns.min;
export const sortBy = lodashFns.sortBy;
export const groupBy = lodashFns.groupBy;
export const indexBy = lodashFns.indexBy;
export const countBy = lodashFns.countBy;
export const partition = lodashFns.partition;
export const clamp = lodashFns.clamp;
// 数数
export function count(from, to, predicate) {
@ -291,7 +288,7 @@ export function concat(obj1, obj2) {
return map([].slice.apply(arguments), (idx, v) => v).join("");
}
if (isArray(obj1)) {
return BI._.concat.apply([], arguments);
return _.concat.apply([], arguments);
}
if (isObject(obj1)) {
return extend.apply({}, arguments);
@ -463,7 +460,7 @@ export function int2Abc(num) {
}
// 数组相关的方法
BI._.each(
_.each(
[
"first",
"initial",
@ -487,34 +484,34 @@ BI._.each(
"uniqBy",
],
name => {
BI[name] = _apply(name);
lodashFns[name] = _apply(name);
}
);
BI._.each(["findIndex", "findLastIndex"], name => {
BI[name] = _applyFunc(name);
_.each(["findIndex", "findLastIndex"], name => {
lodashFns[name] = _applyFunc(name);
});
export const first = BI.first;
export const initial = BI.initial;
export const last = BI.last;
export const rest = BI.rest;
export const compact = BI.compact;
export const flatten = BI.flatten;
export const without = BI.without;
export const union = BI.union;
export const intersection = BI.intersection;
export const difference = BI.difference;
export const zip = BI.zip;
export const unzip = BI.unzip;
export const object = BI.object;
export const indexOf = BI.indexOf;
export const lastIndexOf = BI.lastIndexOf;
export const sortedIndex = BI.sortedIndex;
export const range = BI.range;
export const take = BI.take;
export const takeRight = BI.takeRight;
export const uniqBy = BI.uniqBy;
export const findIndex = BI.findIndex;
export const findLastIndex = BI.findLastIndex;
export const first = lodashFns.first;
export const initial = lodashFns.initial;
export const last = lodashFns.last;
export const rest = lodashFns.rest;
export const compact = lodashFns.compact;
export const flatten = lodashFns.flatten;
export const without = lodashFns.without;
export const union = lodashFns.union;
export const intersection = lodashFns.intersection;
export const difference = lodashFns.difference;
export const zip = lodashFns.zip;
export const unzip = lodashFns.unzip;
export const object = lodashFns.object;
export const indexOf = lodashFns.indexOf;
export const lastIndexOf = lodashFns.lastIndexOf;
export const sortedIndex = lodashFns.sortedIndex;
export const range = lodashFns.range;
export const take = lodashFns.take;
export const takeRight = lodashFns.takeRight;
export const uniqBy = lodashFns.uniqBy;
export const findIndex = lodashFns.findIndex;
export const findLastIndex = lodashFns.findLastIndex;
// 构建一个长度为length的数组
export function makeArray(length, value) {
@ -572,11 +569,11 @@ export function uniq(array, isSorted, iteratee, context) {
}
iteratee && (iteratee = traverse(iteratee, context));
return BI._.uniq.call(BI._, array, isSorted, iteratee, context);
return _.uniq.call(_, array, isSorted, iteratee, context);
}
// 对象相关方法
BI._.each(
_.each(
[
"keys",
"allKeys",
@ -615,53 +612,53 @@ BI._.each(
"pickBy",
],
name => {
BI[name] = _apply(name);
lodashFns[name] = _apply(name);
}
);
export const keys = BI.keys;
export const allKeys = BI.allKeys;
export const values = BI.values;
export const pairs = BI.pairs;
export const invert = BI.invert;
export const create = BI.create;
export const functions = BI.functions;
export const extend = BI.extend;
export const extendOwn = BI.extendOwn;
export const defaults = BI.defaults;
export const clone = BI.clone;
export const property = BI.property;
export const propertyOf = BI.propertyOf;
export const matcher = BI.matcher;
export const isEqual = BI.isEqual;
export const isMatch = BI.isMatch;
export const isEmpty = BI.isEmpty;
export const isElement = BI.isElement;
export const isNumber = BI.isNumber;
export const isString = BI.isString;
export const isArray = BI.isArray;
export const isObject = BI.isObject;
export const isPlainObject = BI.isPlainObject;
export const isArguments = BI.isArguments;
export const isFunction = BI.isFunction;
export const isFinite = BI.isFinite;
export const isBoolean = BI.isBoolean;
export const isDate = BI.isDate;
export const isRegExp = BI.isRegExp;
export const isError = BI.isError;
export const isNaN = BI.isNaN;
export const isUndefined = BI.isUndefined;
export const zipObject = BI.zipObject;
export const cloneDeep = BI.cloneDeep;
export const pickBy = BI.pickBy;
BI._.each(["mapObject", "findKey", "pick", "omit", "tap"], name => {
BI[name] = _applyFunc(name);
export const keys = lodashFns.keys;
export const allKeys = lodashFns.allKeys;
export const values = lodashFns.values;
export const pairs = lodashFns.pairs;
export const invert = lodashFns.invert;
export const create = lodashFns.create;
export const functions = lodashFns.functions;
export const extend = lodashFns.extend;
export const extendOwn = lodashFns.extendOwn;
export const defaults = lodashFns.defaults;
export const clone = lodashFns.clone;
export const property = lodashFns.property;
export const propertyOf = lodashFns.propertyOf;
export const matcher = lodashFns.matcher;
export const isEqual = lodashFns.isEqual;
export const isMatch = lodashFns.isMatch;
export const isEmpty = lodashFns.isEmpty;
export const isElement = lodashFns.isElement;
export const isNumber = lodashFns.isNumber;
export const isString = lodashFns.isString;
export const isArray = lodashFns.isArray;
export const isObject = lodashFns.isObject;
export const isPlainObject = lodashFns.isPlainObject;
export const isArguments = lodashFns.isArguments;
export const isFunction = lodashFns.isFunction;
export const isFinite = lodashFns.isFinite;
export const isBoolean = lodashFns.isBoolean;
export const isDate = lodashFns.isDate;
export const isRegExp = lodashFns.isRegExp;
export const isError = lodashFns.isError;
export const isNaN = lodashFns.isNaN;
export const isUndefined = lodashFns.isUndefined;
export const zipObject = lodashFns.zipObject;
export const cloneDeep = lodashFns.cloneDeep;
export const pickBy = lodashFns.pickBy;
_.each(["mapObject", "findKey", "pick", "omit", "tap"], name => {
lodashFns[name] = _applyFunc(name);
});
export const mapObject = BI.mapObject;
export const findKey = BI.findKey;
export const pick = BI.pick;
export const omit = BI.omit;
export const tap = BI.tap;
export const mapObject = lodashFns.mapObject;
export const findKey = lodashFns.findKey;
export const pick = lodashFns.pick;
export const omit = lodashFns.omit;
export const tap = lodashFns.tap;
export function inherit(sp, overrides) {
function sb() {
@ -696,10 +693,10 @@ export function has(obj, keys) {
return false;
}
return every(keys, (i, key) => BI._.has(obj, key));
return every(keys, (i, key) => _.has(obj, key));
}
return BI._.has(...arguments);
return _.has(...arguments);
}
export function freeze(value) {
@ -765,8 +762,8 @@ export function isPromise(obj) {
return !!obj && (isObject(obj) || isFunction(obj)) && isFunction(obj.then);
}
export const deepClone = BI._.cloneDeep;
export const deepExtend = BI._.merge;
export const deepClone = _.cloneDeep;
export const deepExtend = _.merge;
export function isDeepMatch(object, attrs) {
const attrsKeys = keys(attrs),
@ -786,7 +783,7 @@ export function isDeepMatch(object, attrs) {
}
export function contains(obj, target, fromIndex) {
if (!BI._.isArrayLike(obj)) obj = values(obj);
if (!_.isArrayLike(obj)) obj = values(obj);
return indexOf(obj, target, typeof fromIndex === "number" && fromIndex) >= 0;
}
@ -887,30 +884,30 @@ export function deepDiff(object, other) {
}
// 通用方法
BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => {
BI[name] = (...args) => BI._[name](...args);
_.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => {
lodashFns[name] = (...args) => _[name](...args);
});
export const uniqueId = BI.uniqueId;
export const result = BI.result;
export const chain = BI.chain;
export const iteratee = BI.iteratee;
export const unescape = BI.unescape;
export const before = BI.before;
export const after = BI.after;
export const chunk = BI.chunk;
export const uniqueId = lodashFns.uniqueId;
export const result = lodashFns.result;
export const chain = lodashFns.chain;
export const iteratee = lodashFns.iteratee;
export const unescape = lodashFns.unescape;
export const before = lodashFns.before;
export const after = lodashFns.after;
export const chunk = lodashFns.chunk;
// 事件相关方法
BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => {
BI[name] = (...args) => BI._[name](...args);
_.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => {
lodashFns[name] = (...args) => _[name](...args);
});
export const bind = BI.bind;
export const once = BI.once;
export const partial = BI.partial;
export const debounce = BI.debounce;
export const throttle = BI.throttle;
export const delay = BI.delay;
export const defer = BI.defer;
export const wrap = BI.wrap;
export const bind = lodashFns.bind;
export const once = lodashFns.once;
export const partial = lodashFns.partial;
export const debounce = lodashFns.debounce;
export const throttle = lodashFns.throttle;
export const delay = lodashFns.delay;
export const defer = lodashFns.defer;
export const wrap = lodashFns.wrap;
export const nextTick = (function () {
const callbacks = [];
@ -981,10 +978,10 @@ export const nextTick = (function () {
})();
// 数字相关方法
BI._.each(["random"], name => {
BI[name] = _apply(name);
_.each(["random"], name => {
lodashFns[name] = _apply(name);
});
export const random = BI.random;
export const random = lodashFns.random;
export function parseInt(number) {
let radix = 10;
@ -1072,7 +1069,7 @@ export function average(array, iteratee, context) {
}
export function trim(...args) {
return BI._.trim(...args);
return _.trim(...args);
}
export function toUpperCase(string) {

4
packages/fineui/src/core/utils/i18n.js

@ -15,8 +15,8 @@ export function addI18n(i18n) {
}
export function i18nText(key) {
// eslint-disable-next-line no-var
let localeText = i18nStore[key] || (_global.BI && BI.i18n && BI.i18n[key]) || "";
const i18n = i18nStore || _global?.BI?.i18n || {};
let localeText = i18n[key] || "";
if (!localeText) {
localeText = key;
}

Loading…
Cancel
Save