Browse Source

Pull request #3510: KERNEL-14316 chore:代码调整

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

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

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

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

Loading…
Cancel
Save