UNPKG

@antdv/pro-utils

Version:

@antdv/pro-utils

163 lines (162 loc) 3.93 kB
import { createVNode as _createVNode, Fragment as _Fragment } from "vue"; import { Badge, Space } from "ant-design-vue"; function getType(obj) { const type = Object.prototype.toString.call(obj).match(/^\[object (.*)\]$/)[1].toLowerCase(); if (type === "string" && typeof obj === "object") return "object"; if (obj === null) return "null"; if (obj === void 0) return "undefined"; return type; } const ProFieldBadgeColor = (props, { slots }) => { var _a; return _createVNode(Badge, { "color": props.color, "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }; function objectToMap(value) { if (getType(value) === "map") { return value; } return new Map(Object.entries(value || {})); } const TableStatus = { Success: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "success", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, Error: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "error", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, Default: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "default", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, Processing: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "processing", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, Warning: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "warning", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, success: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "success", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, error: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "error", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, default: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "default", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, processing: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "processing", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); }, warning: (_, { slots }) => { var _a; return _createVNode(Badge, { "status": "warning", "text": (_a = slots.default) == null ? void 0 : _a.call(slots) }, null); } }; function proFieldParsingText(text, valueEnumParams, key) { if (Array.isArray(text)) { return _createVNode(Space, { "key": key, "size": 2, "wrap": true }, { default: () => [text.map((value, index) => proFieldParsingText(value, valueEnumParams, index))], split: () => "," }); } const valueEnum = objectToMap(valueEnumParams); if (!valueEnum.has(text) && !valueEnum.has(`${text}`)) { return (text == null ? void 0 : text.label) || text; } const domText = valueEnum.get(text) || valueEnum.get(`${text}`); if (!domText) { return _createVNode(_Fragment, null, [(text == null ? void 0 : text.label) || text]); } const { status, color } = domText; const Status = TableStatus[status || "Init"]; if (Status) { return _createVNode(Status, { "key": key }, { default: () => [domText.text] }); } if (color) { return _createVNode(ProFieldBadgeColor, { "key": key, "color": color }, { default: () => [domText.text] }); } return _createVNode(_Fragment, null, [domText.text || domText]); } export { ProFieldBadgeColor, objectToMap, proFieldParsingText };