From cffd97f4508f7b6fcc2add0e0f7ed94b457ed412 Mon Sep 17 00:00:00 2001 From: zsmj Date: Tue, 16 May 2023 11:21:42 +0800 Subject: [PATCH] =?UTF-8?q?BI-126203=20fix:=20=E3=80=906.0.10=E5=86=92?= =?UTF-8?q?=E7=83=9F=E3=80=91=E8=AE=BE=E7=BD=AE=E5=91=A8=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E4=BA=8E=E5=91=A8=E6=97=A5=EF=BC=8C=E6=97=A5=E6=9C=9F=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E4=BB=8D=E7=84=B6=E4=BB=A5=E5=91=A8=E4=B8=80=E5=BC=80?= =?UTF-8?q?=E5=A7=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fineui/src/bundle.js | 6 +- packages/fineui/src/core/constant/index.js | 1 + packages/fineui/src/core/constant/var.js | 42 ------ .../fineui/src/core/constant/writable.var.js | 139 ++++++++++++++++++ 4 files changed, 142 insertions(+), 46 deletions(-) create mode 100644 packages/fineui/src/core/constant/writable.var.js diff --git a/packages/fineui/src/bundle.js b/packages/fineui/src/bundle.js index 92ba6cfcf..7d9f259d1 100644 --- a/packages/fineui/src/bundle.js +++ b/packages/fineui/src/bundle.js @@ -1,6 +1,7 @@ import * as fuiExport from "./index"; import * as injectFn from "@/core/5.inject"; import { _global } from "@/core/0.foundation"; +import {_defineVarProperties} from "@/core/constant/writable.var"; _global.BI = _global.BI || {}; @@ -14,7 +15,4 @@ Object.assign(_global, { Object.assign(_global.BI, fuiExport, injectFn); -Object.defineProperty(_global.BI, "EVENT_BLUR", { - set: fuiExport.setEventBlur, - get: () => fuiExport.EVENT_BLUR -}); +_defineVarProperties(_global.BI) diff --git a/packages/fineui/src/core/constant/index.js b/packages/fineui/src/core/constant/index.js index 205529687..34aa468c5 100644 --- a/packages/fineui/src/core/constant/index.js +++ b/packages/fineui/src/core/constant/index.js @@ -1,2 +1,3 @@ export { Events } from "./events"; export * from "./var"; +export * from "./writable.var" diff --git a/packages/fineui/src/core/constant/var.js b/packages/fineui/src/core/constant/var.js index 06bca51f6..bf1c68e10 100644 --- a/packages/fineui/src/core/constant/var.js +++ b/packages/fineui/src/core/constant/var.js @@ -1,24 +1,15 @@ /** * 常量 */ -import { isNumber } from "../2.base"; -import { Cache } from "../structure/cache"; -import { _global } from "../0.foundation"; - -export let EVENT_BLUR = _global.localStorage ? Cache.getItem("event.blur", {typeConversion: true, defaultValue: true}) : true; -export const setEventBlur = (v) => { EVENT_BLUR = v, Cache.setItem("event.blur", v) }; export const MAX = 0xfffffffffffffff; export const MIN = -0xfffffffffffffff; -export const EVENT_RESPONSE_TIME = 200; export const zIndex_layer = 1e5; export const zIndex_popover = 1e6; export const zIndex_popup = 1e7; export const zIndex_masker = 1e8; export const zIndex_tip = 1e9; export const emptyStr = ""; -export const pixUnit = "px"; -export const pixRatio = 1; export const empty = null; export const Key = { 48: "0", @@ -138,37 +129,4 @@ export const VerticalAlign = { Bottom: "bottom", Stretch: "stretch", }; -export const StartOfWeek = 1; -export const BlankSplitChar = "\u200b \u200b"; - -// 一定返回最终的单位 -export function pixFormat(pix, border) { - if (!isNumber(pix)) { - return pix; - } - if (pixUnit === "px") { - return (pix / pixRatio - (border || 0)) + pixUnit; - } - const length = pix / pixRatio + pixUnit; - if (border > 0) { - return `calc(${length} - ${`${border}px`})`; - } - - return length; -} - -export function toPix(pix, border) { - if (!isNumber(pix)) { - return pix; - } - if (pixUnit === "px") { - return pix - (border || 0) * pixRatio; - } - if (border > 0) { - return `calc(${pix / pixRatio + pixUnit} - ${`${border}px`})`; - } - - return pix; -} - export function emptyFn() {} diff --git a/packages/fineui/src/core/constant/writable.var.js b/packages/fineui/src/core/constant/writable.var.js new file mode 100644 index 000000000..63c363507 --- /dev/null +++ b/packages/fineui/src/core/constant/writable.var.js @@ -0,0 +1,139 @@ +/** + * 可写的常量 + */ +import { isNumber } from "../2.base"; +import { _global } from "../0.foundation"; +import { Cache } from "../structure"; + +const PropertyDescriptors = {}; + +export let EVENT_RESPONSE_TIME = 200; +PropertyDescriptors["EVENT_RESPONSE_TIME"] = { + enumerable: true, + configurable: true, + get: function() { + return EVENT_RESPONSE_TIME; + }, + set: function(newVal) { + EVENT_RESPONSE_TIME = newVal; + } +}; + + +export let pixUnit = "px"; +PropertyDescriptors["pixUnit"] = { + enumerable: true, + configurable: true, + get: function() { + return pixUnit; + }, + set: function(newVal) { + pixUnit = newVal; + } +}; + +export let pixRatio = 1; +PropertyDescriptors["pixRatio"] = { + enumerable: true, + configurable: true, + get: function() { + return pixRatio; + }, + set: function(newVal) { + pixRatio = newVal; + } +}; + +export let StartOfWeek = 1; +PropertyDescriptors["StartOfWeek"] = { + enumerable: true, + configurable: true, + get: function() { + return StartOfWeek; + }, + set: function(newVal) { + StartOfWeek = newVal; + } +}; + +export let BlankSplitChar = "\u200b \u200b"; +PropertyDescriptors["BlankSplitChar"] = { + enumerable: true, + configurable: true, + get: function() { + return BlankSplitChar; + }, + set: function(newVal) { + BlankSplitChar = newVal; + } +}; + + +// 一定返回最终的单位 +export function pixFormat(pix, border) { + if (!isNumber(pix)) { + return pix; + } + if (pixUnit === "px") { + return (pix / pixRatio - (border || 0)) + pixUnit; + } + const length = pix / pixRatio + pixUnit; + if (border > 0) { + return `calc(${length} - ${`${border}px`})`; + } + + return length; +} +PropertyDescriptors["pixFormat"] = { + enumerable: true, + configurable: true, + get: function() { + return pixFormat; + }, + set: function(newVal) { + pixFormat = newVal; + } +}; + + +export function toPix(pix, border) { + if (!isNumber(pix)) { + return pix; + } + if (pixUnit === "px") { + return pix - (border || 0) * pixRatio; + } + if (border > 0) { + return `calc(${pix / pixRatio + pixUnit} - ${`${border}px`})`; + } + + return pix; +} +PropertyDescriptors["toPix"] = { + enumerable: true, + configurable: true, + get: function() { + return toPix; + }, + set: function(newVal) { + toPix = newVal; + } +}; + + +export let EVENT_BLUR = _global.localStorage ? Cache.getItem("event.blur", {typeConversion: true, defaultValue: true}) : true; +PropertyDescriptors["EVENT_BLUR"] = { + enumerable: true, + configurable: true, + get: function() { + return EVENT_BLUR; + }, + set: function(newVal) { + EVENT_BLUR = newVal + Cache.setItem("event.blur", newVal) + } +}; + +export function _defineVarProperties(libName) { + Object.defineProperties(libName, PropertyDescriptors); +}