implementado filtro26
This commit is contained in:
parent
ba0e116a92
commit
5124844773
18 changed files with 3247 additions and 3257 deletions
|
|
@ -283,8 +283,11 @@ const _filtrarPorBusca = (lista: Linha[], texto?: string) => {
|
|||
)
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
const _comparar = (op: string, valLine: any, valFiltro: any): boolean => {
|
||||
const _comparar = (
|
||||
op: string,
|
||||
valLine: unknown,
|
||||
valFiltro: unknown,
|
||||
): boolean => {
|
||||
switch (op) {
|
||||
case "=":
|
||||
return valLine == valFiltro
|
||||
|
|
@ -318,13 +321,30 @@ const _comparar = (op: string, valLine: any, valFiltro: any): boolean => {
|
|||
}
|
||||
}
|
||||
|
||||
const _filtrarAvancado = (lista: Linha[], filtros?: tipoFiltro[]) => {
|
||||
const _filtrarAvancado = (lista: Linha[], filtros?: tipoFiltro<Linha>[]) => {
|
||||
if (!filtros?.length) return [...lista]
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
return lista.filter((linha: any) =>
|
||||
filtros.every((f) =>
|
||||
_comparar(String(f.operador), linha?.[String(f.coluna)], f.valor),
|
||||
),
|
||||
|
||||
return lista.filter((linha) =>
|
||||
filtros.every((f) => {
|
||||
// f é um objeto { [coluna]: { [op]: valor } }
|
||||
// Percorremos as colunas (chaves)
|
||||
return Object.entries(f).every(([coluna, condicoes]) => {
|
||||
// Ignorar chaves de lógica complexa por enquanto no playground
|
||||
if (coluna === "AND" || coluna === "OR") return true
|
||||
|
||||
const valLinha = linha[coluna as keyof Linha]
|
||||
|
||||
// Se condicoes for objeto { op: val }
|
||||
if (typeof condicoes === "object" && condicoes !== null) {
|
||||
return Object.entries(condicoes).every(([op, val]) =>
|
||||
_comparar(op, valLinha, val),
|
||||
)
|
||||
}
|
||||
// Se for valor direto (igualdade implícita? ou erro?)
|
||||
// Vamos assumir igualdade se não for objeto
|
||||
return _comparar("=", valLinha, condicoes)
|
||||
})
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -347,8 +367,14 @@ const delay = (ms: number) =>
|
|||
|
||||
// -- API PÚBLICA SIMULADA --
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
export async function api_ler(params: any) {
|
||||
export async function api_ler(params: {
|
||||
texto_busca?: string
|
||||
filtros?: tipoFiltro<Linha>[]
|
||||
coluna_ordem?: keyof Linha
|
||||
direcao_ordem?: "asc" | "desc"
|
||||
limit?: number
|
||||
offSet?: number
|
||||
}) {
|
||||
await delay(600) // simula latência de rede
|
||||
|
||||
// 1. Filtro
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { BadgeCheck, Eye, Pencil, Plus, Trash2 } from "lucide-vue-next"
|
||||
import { criarFiltro26, type tipoFiltro26 } from "p-comuns"
|
||||
import { codigosResposta } from "p-respostas"
|
||||
import { defineComponent, ref } from "vue"
|
||||
import type { ComponenteEntrada } from "@/componentes/EliEntrada/tiposEntradas"
|
||||
|
|
@ -297,21 +298,36 @@ export default defineComponent({
|
|||
acoesLinha: acoesLinha,
|
||||
filtroAvancado: [
|
||||
{
|
||||
coluna: "empreendedor",
|
||||
operador: "like",
|
||||
chave: "empreendedor",
|
||||
rotulo: "Empreendedor",
|
||||
filtro: (valor: unknown) =>
|
||||
criarFiltro26({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
empreendedor: { like: valor as string } as any,
|
||||
}) as tipoFiltro26<Linha>,
|
||||
entrada: ["texto", { rotulo: "Empreendedor" }] as ComponenteEntrada,
|
||||
},
|
||||
{
|
||||
coluna: "documento",
|
||||
operador: "like",
|
||||
chave: "documento",
|
||||
rotulo: "Documento",
|
||||
filtro: (valor: unknown) =>
|
||||
criarFiltro26({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
documento: { like: valor as string } as any,
|
||||
}) as tipoFiltro26<Linha>,
|
||||
entrada: [
|
||||
"texto",
|
||||
{ rotulo: "Documento", formato: "cpfCnpj" },
|
||||
] as ComponenteEntrada,
|
||||
},
|
||||
{
|
||||
coluna: "email",
|
||||
operador: "like",
|
||||
chave: "email",
|
||||
rotulo: "E-mail",
|
||||
filtro: (valor: unknown) =>
|
||||
criarFiltro26({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: playground
|
||||
email: { like: valor as string } as any,
|
||||
}) as tipoFiltro26<Linha>,
|
||||
entrada: [
|
||||
"texto",
|
||||
{ rotulo: "E-mail", formato: "email" },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue