UNPKG

@antdv/pro-field

Version:

原子信息组件,统一 ProForm、ProTable、ProList、Filter 等组件里面的字段定义。

118 lines (117 loc) 4.31 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); import { createVNode as _createVNode, Fragment as _Fragment, mergeProps as _mergeProps } from "vue"; import { useIntl } from "@antdv/pro-provider"; import { boolType, numberType, oneOfType, stringType, vNodeType } from "@antdv/pro-utils"; import { InputNumber } from "ant-design-vue"; import { computed, defineComponent } from "vue"; import { buildProFieldProp } from "../props.mjs"; import { getColorByRealValue, getRealTextWithPrecision, getSymbolByRealValue, toNumber } from "./util.mjs"; const fieldPercentProps = buildProFieldProp({ prefix: vNodeType(), suffix: vNodeType(), value: oneOfType([Number, String]), precision: numberType(), showColor: boolType(), showSymbol: oneOfType([Boolean, Function]), placeholder: stringType() }); var stdin_default = defineComponent({ name: "FieldPercent", props: fieldPercentProps, inheritAttrs: false, slots: Object, emits: { "update:value": (val) => true }, setup(props, { slots, emit }) { const intl = useIntl(); return () => { var _a, _b, _c; const { text, value, prefix = (_a = slots.prefix) == null ? void 0 : _a.call(slots), suffix = (_c = (_b = slots.suffix) == null ? void 0 : _b.call(slots)) != null ? _c : "%", precision, mode, showColor = false, render, renderFormItem, fieldProps, placeholder, showSymbol: propsShowSymbol } = props; const textValue = text != null ? text : value; const placeholderValue = placeholder || intl.getMessage("tableForm.inputPlaceholder", "\u8BF7\u8F93\u5165"); const realValue = typeof textValue === "string" && textValue.includes("%") ? toNumber(textValue.replace("%", "")) : toNumber(textValue); const showSymbol = typeof propsShowSymbol === "function" ? propsShowSymbol == null ? void 0 : propsShowSymbol(textValue) : propsShowSymbol; if (mode === "read") { const style = showColor ? { color: getColorByRealValue(realValue) } : {}; const dom = _createVNode("span", { "style": style }, [prefix && _createVNode("span", null, [prefix]), showSymbol && _createVNode(_Fragment, null, [getSymbolByRealValue(realValue), " "]), getRealTextWithPrecision(Math.abs(realValue), precision), suffix && suffix]); if (render) { return render(textValue, computed(() => __spreadProps(__spreadValues({ mode }, fieldProps), { prefix, precision, showSymbol, suffix })), dom); } return dom; } if (mode === "edit" || mode === "update") { const dom = _createVNode(InputNumber, _mergeProps({ "formatter": (v) => { if (v && prefix) { return `${prefix} ${v}`.replace(/\B(?=(?:\d{3})+(?!\d)$)/g, ","); } return v; }, "parser": (v) => v ? v.replace(/.*\s|,/g, "") : "", "placeholder": placeholderValue, "value": value, "onUpdate:value": (val) => { emit("update:value", val); } }, fieldProps), null); if (renderFormItem) { return renderFormItem(textValue, computed(() => __spreadValues({ mode, value }, fieldProps)), dom); } return dom; } return null; }; } }); export { stdin_default as default };