bkp
This commit is contained in:
parent
67dc4c465a
commit
92662a0b13
20 changed files with 1005 additions and 774 deletions
|
|
@ -10,6 +10,7 @@ import { ArrowDown, ArrowUp, MoreVertical } from "lucide-vue-next";
|
|||
import { codigosResposta } from "p-respostas";
|
||||
import EliTabelaCaixaDeBusca from "./EliTabelaCaixaDeBusca.vue";
|
||||
import EliTabelaPaginacao from "./EliTabelaPaginacao.vue";
|
||||
import EliTabelaCelula from "./celulas/EliTabelaCelula.vue";
|
||||
import type { EliTabelaConsulta } from "./types-eli-tabela";
|
||||
|
||||
export default defineComponent({
|
||||
|
|
@ -131,15 +132,6 @@ export default defineComponent({
|
|||
menuAberto.value = null;
|
||||
}
|
||||
|
||||
function normalizarFilhos(filhos: unknown) {
|
||||
// `VNodeChild` pode ser null/undefined/boolean.
|
||||
// Para a assinatura de `h()`, normalizamos para string vazia.
|
||||
if (filhos === null || filhos === undefined || filhos === false) {
|
||||
return "";
|
||||
}
|
||||
return filhos as never;
|
||||
}
|
||||
|
||||
function obterClasseAlinhamento(alinhamento?: string) {
|
||||
if (alinhamento === "direita") {
|
||||
return "eli-tabela__celula--direita";
|
||||
|
|
@ -157,34 +149,23 @@ export default defineComponent({
|
|||
return typeof largura === "number" ? `${largura}px` : String(largura);
|
||||
}
|
||||
|
||||
function renderConteudoCelula(valor: unknown, coluna: (typeof props.tabela.colunas)[number]) {
|
||||
const filhos = normalizarFilhos(valor);
|
||||
const truncar = Boolean(coluna.truncar);
|
||||
|
||||
if (!truncar) {
|
||||
return filhos;
|
||||
function obterTooltipCelula(celula: unknown) {
|
||||
if (!Array.isArray(celula)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Só truncamos de forma segura quando o conteúdo é textual.
|
||||
if (typeof filhos !== "string" && typeof filhos !== "number") {
|
||||
return filhos;
|
||||
const tipo = celula[0];
|
||||
const dados = celula[1] as any;
|
||||
|
||||
if (tipo === "textoSimples") {
|
||||
return typeof dados?.texto === "string" ? dados.texto : undefined;
|
||||
}
|
||||
|
||||
const tooltip = String(filhos);
|
||||
if (tipo === "numero") {
|
||||
return typeof dados?.numero === "number" ? String(dados.numero) : undefined;
|
||||
}
|
||||
|
||||
return h(
|
||||
"span",
|
||||
{
|
||||
class: "eli-tabela__celula-conteudo",
|
||||
style: coluna.largura_maxima
|
||||
? {
|
||||
maxWidth: obterMaxWidth(coluna.largura_maxima),
|
||||
}
|
||||
: undefined,
|
||||
title: tooltip,
|
||||
},
|
||||
tooltip
|
||||
);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function renderErro(mensagem: string) {
|
||||
|
|
@ -557,19 +538,45 @@ export default defineComponent({
|
|||
{ class: "eli-tabela__tbody" },
|
||||
linhas.value.map((linha, i) => {
|
||||
const celulas = colunas.map((coluna, j) =>
|
||||
h(
|
||||
"td",
|
||||
{
|
||||
class: [
|
||||
"eli-tabela__td",
|
||||
coluna.acao ? "eli-tabela__td--clicavel" : undefined,
|
||||
obterClasseAlinhamento(coluna.alinhamento),
|
||||
],
|
||||
key: `${i}-${j}`,
|
||||
onClick: coluna.acao ? () => coluna.acao?.() : undefined,
|
||||
},
|
||||
renderConteudoCelula(coluna.celula(linha as never), coluna)
|
||||
)
|
||||
(() => {
|
||||
const celula = coluna.celula(linha as never);
|
||||
const truncar = Boolean(coluna.truncar);
|
||||
const tooltip = truncar ? obterTooltipCelula(celula) : undefined;
|
||||
|
||||
const conteudo = h(EliTabelaCelula, {
|
||||
celula: celula as never,
|
||||
});
|
||||
|
||||
const conteudoFinal = truncar
|
||||
? h(
|
||||
"span",
|
||||
{
|
||||
class: "eli-tabela__celula-conteudo",
|
||||
style: coluna.largura_maxima
|
||||
? {
|
||||
maxWidth: obterMaxWidth(coluna.largura_maxima),
|
||||
}
|
||||
: undefined,
|
||||
title: tooltip,
|
||||
},
|
||||
conteudo
|
||||
)
|
||||
: conteudo;
|
||||
|
||||
return h(
|
||||
"td",
|
||||
{
|
||||
class: [
|
||||
"eli-tabela__td",
|
||||
coluna.acao ? "eli-tabela__td--clicavel" : undefined,
|
||||
obterClasseAlinhamento(coluna.alinhamento),
|
||||
],
|
||||
key: `${i}-${j}`,
|
||||
onClick: coluna.acao ? () => coluna.acao?.() : undefined,
|
||||
},
|
||||
conteudoFinal
|
||||
);
|
||||
})()
|
||||
);
|
||||
|
||||
if (temAcoes) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue