import $ from "jquery";
import { defineComponent } from "vue";
import "./xInfoCard.less";
import { xU } from "../ventoseUtils";
export const InfoCardCol = defineComponent({
props: ["col"],
computed: {
isHide() {
return this.col.isHide || false;
},
styleLabel() {
return {};
},
vDomLabel() {
return this.col.label;
},
vDomContent() {
return this.col.value;
}
},
render() {
if (this.isHide) {
return null;
}
return (
<>
{this.vDomLabel}
{this.vDomContent}
>
);
}
});
export const InfoCardRow = defineComponent({
props: ["row"],
computed: {
colArray() {
return this?.row?.colArray || false;
},
vDomCol() {
if (this.row) {
return xU.map(this.colArray, col => {
return ;
});
}
return null;
},
styleRow() {
if (this?.row?.style) {
return this.row.style;
}
return "";
}
},
render() {
return (
{this.vDomCol}
);
}
});
export const xInfoCard = defineComponent({
props: ["info", "title"],
methods: {
updateLableStyle(styleObject) {
const styleString = xU
.map(
xU.merge(
{ "min-width": "120px", "text-align": "right" },
styleObject
),
(value, prop) => `${prop}: ${value}`
)
.join(";");
const styleContent = `#${this.id} .ant-descriptions-item-label {${styleString}}`;
if (!this.$styleEle) {
const $form = $(`#${this.id}`);
const $style = $("", { id: `style_${this.id}` });
$form.prepend($style);
this.$styleEle = $style;
}
this.$styleEle.html(styleContent);
}
},
mounted() {
this.$watch(
"info.colLabelWidth",
width => {
if (width) {
xU("width", width);
this.updateLableStyle({ width });
}
},
{
immediate: true,
deep: true
}
);
},
computed: {
id() {
return `InfoCard_${this._.uid}`;
},
colLabelWidth() {
return this?.info?.colLabelWidth || "120px";
},
rowArray() {
return this?.info?.rowArray || false;
},
vDomTitle() {
if (!this.title) {
return null;
}
return (
);
},
vDomDescriptions() {
if (this.rowArray) {
return (
{xU.map(this.rowArray, row => {
return ;
})}
);
}
if (this.$slots.default) {
return this.$slots.default();
}
return null;
}
},
render() {
return (
{this.vDomTitle}
{this.vDomDescriptions}
);
}
});