@antdv/pro-utils
Version:
@antdv/pro-utils
182 lines (181 loc) • 5.36 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var stdin_exports = {};
__export(stdin_exports, {
ProFieldBadgeColor: () => ProFieldBadgeColor,
objectToMap: () => objectToMap,
proFieldParsingText: () => proFieldParsingText
});
module.exports = __toCommonJS(stdin_exports);
var import_vue = require("vue");
var import_ant_design_vue = require("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 (0, import_vue.createVNode)(import_ant_design_vue.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 (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "success",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
Error: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "error",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
Default: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "default",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
Processing: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "processing",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
Warning: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "warning",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
success: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "success",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
error: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "error",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
default: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "default",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
processing: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "processing",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
},
warning: (_, {
slots
}) => {
var _a;
return (0, import_vue.createVNode)(import_ant_design_vue.Badge, {
"status": "warning",
"text": (_a = slots.default) == null ? void 0 : _a.call(slots)
}, null);
}
};
function proFieldParsingText(text, valueEnumParams, key) {
if (Array.isArray(text)) {
return (0, import_vue.createVNode)(import_ant_design_vue.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 (0, import_vue.createVNode)(import_vue.Fragment, null, [(text == null ? void 0 : text.label) || text]);
}
const {
status,
color
} = domText;
const Status = TableStatus[status || "Init"];
if (Status) {
return (0, import_vue.createVNode)(Status, {
"key": key
}, {
default: () => [domText.text]
});
}
if (color) {
return (0, import_vue.createVNode)(ProFieldBadgeColor, {
"key": key,
"color": color
}, {
default: () => [domText.text]
});
}
return (0, import_vue.createVNode)(import_vue.Fragment, null, [domText.text || domText]);
}