UNPKG

yanzhen-design-vue

Version:

117 lines (116 loc) 3.95 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const vue = require("vue"); const utilsVue = require("@yanzhen-libs/utils-vue"); const lodashEs = require("lodash-es"); require("../../../hooks/index.cjs"); const utils = require("@yanzhen-libs/utils"); const inputNumber = require("./input-number.cjs"); const input = require("./input.cjs"); const index = require("../../../hooks/use-progress/index.cjs"); function useInputNumber(props, emit, context) { const instance = vue.getCurrentInstance(); const _ref = vue.ref(null); const attrs = vue.useAttrs(); const { progressBarNum, showProgress, convertSuffix } = index.useProgress(props); const nativeRef = vue.computed(() => props.native); const nativeTagRef = vue.computed(() => props.nativeTag); const nativeConfig = vue.computed(() => { if (utilsVue.unref(nativeRef)) { const nativeProps = lodashEs.pick(props, ...Object.keys(inputNumber.AntInputNumber.props)); const cSuffix = utilsVue.unref(convertSuffix); if (cSuffix) { nativeProps.suffix = cSuffix; } if (props.showThousan) { nativeProps.formatter = (value) => { if (value) { let val = value.toString(); const numStrList = val.split("."); const strlist = numStrList.map((str, index2) => { if (index2 === 1) return str; return str.replace(/\B(?=(\d{3})+(?!\d))/g, ","); }); val = strlist.join("."); return val; } return ""; }; nativeProps.parser = (value) => { return value.replace(/\$\s?|(,*)/g, ""); }; } return nativeProps; } return lodashEs.pick(props, ...Object.keys(input.AntInput.props)); }); const nativeProxyProps = utilsVue.useProxyProps(nativeConfig, inputNumber.inputNumberEmits, { emit // filter: key => { // switch (key as string) { // case 'onUpdate:value': // case 'onUpdate:beginTime': // case 'onUpdate:endTime': // return false; // } // return true; // }, }); const propsRef = vue.computed(() => { return vue.mergeProps(utilsVue.unref(attrs), utilsVue.unref(nativeProxyProps)); }); const textRef = vue.computed(() => { const txt = utilsVue.unref(propsRef).value; if (utils.isEmptyValue(txt)) return ""; const nativeTagFormatter = props.nativeTagFormatter; if (lodashEs.isFunction(nativeTagFormatter)) { return nativeTagFormatter(txt, props, instance); } return txt; }); function digitUppercase(n) { const fraction = ["角", "分"]; const digit = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]; const unit = [ ["元", "万", "亿"], ["", "拾", "佰", "仟"] ]; const head = n < 0 ? "负" : ""; n = Math.abs(n); let s = ""; for (const [i, element] of fraction.entries()) { s += (digit[Math.floor(n * 10 * 10 ** i) % 10] + element).replace(/零./, ""); } s = s || "整"; n = Math.floor(n); for (let i1 = 0; i1 < unit[0].length && n > 0; i1++) { let p = ""; for (let j = 0; j < unit[1].length && n > 0; j++) { p = digit[n % 10] + unit[1][j] + p; n = Math.floor(n / 10); } s = p.replace(/(零.)*零$/, "").replace(/^$/, "零") + unit[0][i1] + s; } return head + s.replace(/(零.)*零元/, "元").replace(/(零.)+/g, "零").replace(/^整$/, "零元整"); } const upperMoney = vue.computed(() => { const value = propsRef.value.value; const numValue = lodashEs.toNumber(value); if (!Number.isNaN(numValue)) { return digitUppercase(numValue); } return void 0; }); return { _ref, propsRef, nativeRef, nativeTagRef, progressBarNum, showProgress, digitUppercase, upperMoney, textRef }; } exports.useInputNumber = useInputNumber;