From 071b74a780e71cb9169a1beaa22f99eed549e97f Mon Sep 17 00:00:00 2001 From: Treecat Date: Thu, 6 Apr 2023 14:16:15 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14316=20chore:=20=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../combo.textvaluecheck.js | 1 + .../fineui/src/case/trigger/trigger.text.js | 1 + .../src/case/trigger/trigger.text.select.js | 2 +- packages/fineui/src/core/2.base.js | 193 ++++-------------- .../src/core/utils/events/mousemovetracker.js | 12 +- 5 files changed, 46 insertions(+), 163 deletions(-) diff --git a/packages/fineui/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js b/packages/fineui/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js index dff524e94..4d261d588 100644 --- a/packages/fineui/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js +++ b/packages/fineui/src/case/combo/textvaluecheckcombo/combo.textvaluecheck.js @@ -39,6 +39,7 @@ export class TextValueCheckCombo extends Widget { height: toPix(o.height, 2), text: o.text, value: o.value, + defaultText: o.defaultText }); this.popup = createWidget({ type: TextValueCheckComboPopup.xtype, diff --git a/packages/fineui/src/case/trigger/trigger.text.js b/packages/fineui/src/case/trigger/trigger.text.js index dfe9cef1b..cce8cf6d6 100644 --- a/packages/fineui/src/case/trigger/trigger.text.js +++ b/packages/fineui/src/case/trigger/trigger.text.js @@ -47,6 +47,7 @@ export class TextTrigger extends Trigger { height: o.height, text: text || o.defaultText, tipType: o.tipType, + title: o.title, warningTitle: o.warningTitle, hgap: o.textHgap, vgap: o.textVgap, diff --git a/packages/fineui/src/case/trigger/trigger.text.select.js b/packages/fineui/src/case/trigger/trigger.text.select.js index 48af5c5de..730a9feff 100644 --- a/packages/fineui/src/case/trigger/trigger.text.select.js +++ b/packages/fineui/src/case/trigger/trigger.text.select.js @@ -43,7 +43,7 @@ export class SelectTextTrigger extends Trigger { textTgap: o.textTgap, textBgap: o.textBgap, tipType: o.tipType, - title: null, + title: o.title, allowClear: o.allowClear, listeners: [ { diff --git a/packages/fineui/src/core/2.base.js b/packages/fineui/src/core/2.base.js index 288709927..4e0a3dea4 100644 --- a/packages/fineui/src/core/2.base.js +++ b/packages/fineui/src/core/2.base.js @@ -8,8 +8,7 @@ import { Widget } from "./4.widget"; import { createWidget } from "./5.inject"; import { prepares, _global } from "./0.foundation"; import { CRYPT_TYPE, aesDecrypt, aesEncrypt } from "./structure/aes"; -import { Date as DateEnum } from "./func/date"; - +import { Date as DateEnum, getMonthDays } from "./func/date"; /** * todo: 理论这么写,逻辑没问题,摇个人把这个 BI 干掉 @@ -29,9 +28,7 @@ function _apply(name) { 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] = BI._.isFunction(args[1]) ? traverse(args[1], args[2]) : args[1]; return BI._[name](...args); }; @@ -60,24 +57,7 @@ export function warn(message) { } 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 = ""; for (let i = 0; i < 16; i++) { const r = _global.parseInt(f.length * Math.random(), 10); @@ -102,18 +82,12 @@ export function createWidgets(items, options, context) { options || (options = {}); } - return map(flatten(items), (i, item) => - createWidget(item, deepClone(options), context) - ); + return map(flatten(items), (i, item) => createWidget(item, deepClone(options), context)); } export function createItems(data, innerAttr, outerAttr) { - innerAttr = isArray(innerAttr) - ? innerAttr - : makeArray(flatten(data).length, innerAttr || {}); - outerAttr = isArray(outerAttr) - ? outerAttr - : makeArray(flatten(data).length, outerAttr || {}); + innerAttr = isArray(innerAttr) ? innerAttr : makeArray(flatten(data).length, innerAttr || {}); + outerAttr = isArray(outerAttr) ? outerAttr : makeArray(flatten(data).length, outerAttr || {}); return map(data, (i, item) => { if (isArray(item)) { @@ -157,7 +131,7 @@ export function packageItems(items, layouts) { items: [ extend({}, layouts[i].el, { el: it, - }) + }), ], }) ); @@ -186,21 +160,9 @@ export function trans2Element(widgets) { } // 集合相关方法 -BI._.each( - [ - "where", - "findWhere", - "invoke", - "pluck", - "shuffle", - "sample", - "toArray", - "size" - ], - name => { - BI[name] = _apply(name); - } -); +BI._.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], name => { + BI[name] = _apply(name); +}); BI._.each( [ "get", @@ -223,7 +185,7 @@ BI._.each( "indexBy", "countBy", "partition", - "clamp" + "clamp", ], name => { if (name === "any") { @@ -398,9 +360,7 @@ export function remove(obj, target, context) { if (isArray(obj)) { for (i = 0; i < obj.length; i++) { if ( - (targetIsFunction && - (target === obj[i] || - target.apply(context, [i, obj[i]]) === true)) || + (targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i])) ) { obj.splice(i--, 1); @@ -409,9 +369,7 @@ export function remove(obj, target, context) { } else { each(obj, (i, v) => { if ( - (targetIsFunction && - (target === obj[i] || - target.apply(context, [i, obj[i]]) === true)) || + (targetIsFunction && (target === obj[i] || target.apply(context, [i, obj[i]]) === true)) || (!targetIsFunction && contains(target, obj[i])) ) { delete obj[i]; @@ -450,11 +408,7 @@ export function abc2Int(string) { str = string.toUpperCase(); for (let i = 0, len = str.length; i < len; ++i) { 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; } } @@ -489,7 +443,7 @@ export function int2Abc(num) { "W", "X", "Y", - "Z" + "Z", ]; let idx = num, str = ""; @@ -530,7 +484,7 @@ BI._.each( "range", "take", "takeRight", - "uniqBy" + "uniqBy", ], name => { BI[name] = _apply(name); @@ -658,7 +612,7 @@ BI._.each( "isUndefined", "zipObject", "cloneDeep", - "pickBy" + "pickBy", ], name => { BI[name] = _apply(name); @@ -730,10 +684,7 @@ export function init() { while (prepares && prepares.length > 0) { prepares.shift()(); } - while ( - _global.___fineuiExposedFunction && - _global.___fineuiExposedFunction.length > 0 - ) { + while (_global.___fineuiExposedFunction && _global.___fineuiExposedFunction.length > 0) { _global.___fineuiExposedFunction.shift()(); } BI.initialized = true; @@ -778,12 +729,7 @@ export function isWidthOrHeight(w) { if (typeof w === "number") { return w >= 0; } 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); } } @@ -842,9 +788,7 @@ export function isDeepMatch(object, attrs) { export function contains(obj, target, fromIndex) { 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) { @@ -943,21 +887,9 @@ export function deepDiff(object, other) { } // 通用方法 -BI._.each( - [ - "uniqueId", - "result", - "chain", - "iteratee", - "unescape", - "before", - "after", - "chunk" - ], - name => { - BI[name] = (...args) => BI._[name](...args); - } -); +BI._.each(["uniqueId", "result", "chain", "iteratee", "unescape", "before", "after", "chunk"], name => { + BI[name] = (...args) => BI._[name](...args); +}); export const uniqueId = BI.uniqueId; export const result = BI.result; export const chain = BI.chain; @@ -968,21 +900,9 @@ export const after = BI.after; export const chunk = BI.chunk; // 事件相关方法 -BI._.each( - [ - "bind", - "once", - "partial", - "debounce", - "throttle", - "delay", - "defer", - "wrap" - ], - name => { - BI[name] = (...args) => BI._[name](...args); - } -); +BI._.each(["bind", "once", "partial", "debounce", "throttle", "delay", "defer", "wrap"], name => { + BI[name] = (...args) => BI._[name](...args); +}); export const bind = BI.bind; export const once = BI.once; export const partial = BI.partial; @@ -1058,7 +978,7 @@ export const nextTick = (function () { }); } }; -}()); +})(); // 数字相关方法 BI._.each(["random"], name => { @@ -1081,11 +1001,7 @@ export function parseInt(number) { export function parseSafeInt(value) { const MAX_SAFE_INTEGER = 9007199254740991; - return value - ? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) - : value === 0 - ? value - : 0; + return value ? clamp(parseInt(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) : value === 0 ? value : 0; } export function parseFloat(number) { @@ -1113,9 +1029,7 @@ export function isInteger(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) { @@ -1372,10 +1286,7 @@ export function parseDateTime(str, fmt) { const otherlength = 2; a[0] = str.substring(0, yearlength); 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); let i = 0, @@ -1406,11 +1317,7 @@ export function parseDateTime(str, fmt) { case "%b": case "%B": 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; break; } @@ -1455,7 +1362,7 @@ export function parseDateTime(str, fmt) { m = today.getMonth(); } if (_global.isNaN(d)) { - d = today.getDate(); + d = Math.min(getMonthDays(getDate(y, m)), today.getDate()); } if (_global.isNaN(hr)) { hr = today.getHours(); @@ -1476,10 +1383,7 @@ export function parseDateTime(str, fmt) { if (a[i].search(/[a-zA-Z]+/) !== -1) { let t = -1; 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; break; } @@ -1546,25 +1450,13 @@ export function getDate(...args) { break; // new Date(year, month, day, hour, minute, second, millisecond) 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; default: dt = new Date(); 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(); // BI-33791 1901年以前的东8区标准是GMT+0805, 统一无论是什么时间,都以整的0800这样的为基准 const localOffset = dt.getTimezoneOffset() * 60000; // 获得当地时间偏移的毫秒数 @@ -1611,15 +1503,7 @@ export function getTime() { break; // new Date(year, month, day, hour, minute, second, millisecond) 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; default: dt = new Date(); @@ -1627,11 +1511,8 @@ export function getTime() { } if (isNotNull(BI.timeZone)) { // 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(); } - diff --git a/packages/fineui/src/core/utils/events/mousemovetracker.js b/packages/fineui/src/core/utils/events/mousemovetracker.js index 84255c70d..ea25782ae 100644 --- a/packages/fineui/src/core/utils/events/mousemovetracker.js +++ b/packages/fineui/src/core/utils/events/mousemovetracker.js @@ -84,7 +84,7 @@ export class MouseMoveTracker { // The mouse may move faster then the animation frame does. // Use `requestAnimationFrame` to avoid over-updating. this._animationFrameID = - requestAnimationFrame(this._didMouseMove); + requestAnimationFrame(() => this._didMouseMove(event)); } this._x = x; @@ -92,17 +92,17 @@ export class MouseMoveTracker { event.preventDefault ? event.preventDefault() : (event.returnValue = false); } - _didMouseMove() { + _didMouseMove(event) { this._animationFrameID = null; - this._onMove(this._deltaX, this._deltaY); + this._onMove(this._deltaX, this._deltaY, event); this._deltaX = 0; this._deltaY = 0; } - _onMouseUp() { + _onMouseUp(event) { if (this._animationFrameID) { - this._didMouseMove(); + this._didMouseMove(event); } - this._onMoveEnd(); + this._onMoveEnd(event); } }