UNPKG

@antdv/pro-field

Version:

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

149 lines (148 loc) 5.64 kB
var __defProp = Object.defineProperty; 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; }; import { createVNode as _createVNode, mergeProps as _mergeProps } from "vue"; import { proTheme, useIntl } from "@antdv/pro-provider"; import { arrayType, numberType, oneOfType, stringType } from "@antdv/pro-utils"; import { Input, InputNumber, Space } from "ant-design-vue"; import { computed, defineComponent } from "vue"; import { buildProFieldProp } from "../props.mjs"; const fieldDigitRangeProps = buildProFieldProp({ value: arrayType(), placeholder: oneOfType([String, Array]), separator: stringType(), separatorWidth: numberType() }); var stdin_default = defineComponent({ name: "FieldDigitRange", props: fieldDigitRangeProps, inheritAttrs: false, emits: { "update:value": (val) => true }, setup(props, { emit }) { const intl = useIntl(); const { token } = proTheme.useToken(); return () => { const { text, value, mode: type, render, placeholder, renderFormItem, fieldProps, separator = "~", separatorWidth = 30 } = props; const textValue = text != null ? text : value; const { id } = fieldProps; if (type === "read") { const getContent = (number) => { var _a; const digit = new Intl.NumberFormat(void 0, __spreadValues({ minimumSignificantDigits: 2 }, (fieldProps == null ? void 0 : fieldProps.intlProps) || {})).format(Number(number)); return ((_a = fieldProps == null ? void 0 : fieldProps.formatter) == null ? void 0 : _a.call(fieldProps, digit)) || digit; }; const dom = _createVNode("span", null, [getContent(textValue[0]), " ", separator, " ", getContent(textValue[1])]); if (render) { return render(textValue, computed(() => __spreadValues({ mode: type, value }, fieldProps)), dom); } return dom; } if (type === "edit" || type === "update") { const handleGroupBlur = () => { if (Array.isArray(value)) { const [value0, value1] = value; if (typeof value0 === "number" && typeof value1 === "number" && value0 > value1) { emit("update:value", [value1, value0]); } else if (value0 === void 0 && value1 === void 0) { emit("update:value", void 0); } } }; const placeholderValue = (fieldProps == null ? void 0 : fieldProps.placeholder) || placeholder || [intl.getMessage("tableForm.inputPlaceholder", "\u8BF7\u8F93\u5165"), intl.getMessage("tableForm.inputPlaceholder", "\u8BF7\u8F93\u5165")]; const getInputNumberPlaceholder = (index) => Array.isArray(placeholderValue) ? placeholderValue[index] : placeholderValue; const Compact = Space.Compact || Input.Group; const compactProps = Space.Compact ? {} : { compact: true }; const dom = _createVNode("div", { "onBlur": handleGroupBlur }, [_createVNode(Compact, compactProps, { default: () => { var _a; return [_createVNode(InputNumber, _mergeProps(fieldProps, { "placeholder": getInputNumberPlaceholder(0), "id": id != null ? id : `${id}-0`, "style": { width: `calc((100% - ${separatorWidth}px) / 2)` }, "value": value == null ? void 0 : value[0], "onUpdate:value": (val) => { emit("update:value", [val === null ? void 0 : val, value == null ? void 0 : value[1]]); } }), null), _createVNode(Input, { "style": { width: `${separatorWidth}px`, textAlign: "center", borderInlineStart: 0, borderInlineEnd: 0, pointerEvents: "none", backgroundColor: (_a = token.value) == null ? void 0 : _a.colorBgContainer }, "placeholder": separator, "disabled": true }, null), _createVNode(InputNumber, _mergeProps(fieldProps, { "placeholder": getInputNumberPlaceholder(1), "id": id != null ? id : `${id}-1`, "style": { width: `calc((100% - ${separatorWidth}px) / 2)`, borderInlineStart: 0 }, "value": value == null ? void 0 : value[1], "onUpdate:value": (val) => { emit("update:value", [value == null ? void 0 : value[0], val === null ? void 0 : val]); } }), null)]; } })]); if (renderFormItem) { return renderFormItem(textValue, computed(() => __spreadValues({ mode: type, value }, fieldProps)), dom); } return dom; } return null; }; } }); export { stdin_default as default, fieldDigitRangeProps };