UNPKG

@antdv/pro-field

Version:

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

161 lines (160 loc) 5.63 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)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; import { createVNode as _createVNode, Fragment as _Fragment, mergeProps as _mergeProps } from "vue"; import { useStyle } from "@antdv/pro-provider"; import { classNames, objectToMap, oneOfType, proFieldParsingText, stringType } from "@antdv/pro-utils"; import { Radio, Spin } from "ant-design-vue"; import { FormItemInputContext } from "ant-design-vue/es/form/FormItemContext"; import { useConfigContextInject } from "ant-design-vue/lib/config-provider/context"; import { computed, defineComponent, ref } from "vue"; import { buildProFieldProp } from "../props.mjs"; import { fieldSelectProps, useFieldFetchData } from "../Select/index.mjs"; const fieldRadioProps = buildProFieldProp(__spreadValues({ options: oneOfType([String, Number, Array]), radioType: stringType() }, fieldSelectProps)); var stdin_default = defineComponent({ name: "FieldRadio", props: fieldRadioProps, inheritAttrs: false, emits: { "update:value": (val) => true }, setup(props, { expose, emit }) { const { getPrefixCls } = useConfigContextInject(); const layoutClassName = getPrefixCls("pro-field-radio"); const radioRef = ref(); const formItemContext = FormItemInputContext.useInject(); const [loading, options, fetchData] = useFieldFetchData(props); const { wrapSSR, hashId } = useStyle("FieldRadioRadio", (token) => { return { [`.${layoutClassName}-error`]: { span: { color: token.colorError } }, [`.${layoutClassName}-warning`]: { span: { color: token.colorWarning } }, [`.${layoutClassName}-vertical`]: { [`${token.antCls}-radio-wrapper`]: { display: "flex", marginInlineEnd: 0 } } }; }); expose(__spreadProps(__spreadValues({}, radioRef.value || {}), { fetchData: (keyWord) => fetchData(keyWord) })); return () => { var _b, _c, _d, _e, _f; const _a = props, { radioType, value, renderFormItem, mode, render, text } = _a, rest = __objRest(_a, [ "radioType", "value", "renderFormItem", "mode", "render", "text" ]); const textValue = text != null ? text : value; if (loading.value) { return _createVNode(Spin, { "size": "small" }, null); } if (mode === "read") { const optionsValueEnum = ((_b = options.value) == null ? void 0 : _b.length) ? (_c = options.value) == null ? void 0 : _c.reduce((pre, cur) => { var _a2; return __spreadProps(__spreadValues({}, pre), { [(_a2 = cur.value) != null ? _a2 : ""]: cur.label }); }, {}) : void 0; const dom = _createVNode(_Fragment, null, [proFieldParsingText(textValue, objectToMap(rest.valueEnum || optionsValueEnum))]); if (render) { return (_d = render(textValue, computed(() => __spreadValues({ mode }, rest.fieldProps)), dom)) != null ? _d : null; } return dom; } if (mode === "edit") { const dom = wrapSSR(_createVNode(Radio.Group, _mergeProps({ "ref": radioRef, "optionType": radioType }, rest.fieldProps, { "class": classNames((_e = rest.fieldProps) == null ? void 0 : _e.class, { [`${layoutClassName}-error`]: (formItemContext == null ? void 0 : formItemContext.status) === "error", [`${layoutClassName}-warning`]: (formItemContext == null ? void 0 : formItemContext.status) === "warning" }, hashId.value, `${layoutClassName}-${rest.fieldProps.layout || "horizontal"}`), "value": value, "onUpdate:value": (val) => { emit("update:value", val); }, "options": options.value }), null)); if (renderFormItem) { return (_f = renderFormItem(textValue, computed(() => __spreadProps(__spreadValues({ mode }, rest.fieldProps), { value, options: options.value, loading: loading.value })), dom)) != null ? _f : null; } return dom; } return null; }; } }); export { stdin_default as default, fieldRadioProps };