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 3dd6f1247..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,45 +129,4 @@ export const VerticalAlign = { Bottom: "bottom", Stretch: "stretch", }; -export const StartOfWeek = 1; -export const BlankSplitChar = "\u200b \u200b"; - -// 一定返回最终的单位 -export let 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 setPixFormat(func) { - pixFormat = func; -} - -export let 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 setToPix(func) { - toPix = func; -} - 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); +}