implementado filtro26
This commit is contained in:
parent
ba0e116a92
commit
5124844773
18 changed files with 3247 additions and 3257 deletions
21
README.md
21
README.md
|
|
@ -97,10 +97,12 @@ export type tipoEliTabelaConsulta<T> = {
|
|||
|
||||
// Definição de Filtro Avançado
|
||||
filtroAvancado?: Array<{
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
coluna: keyof T;
|
||||
operador: string; // ex: "=", "like", ">="
|
||||
entrada: any; // Definição do componente, ex: ["texto", { ... }]
|
||||
/** Função que gera o filtro com base no valor recebido do input */
|
||||
filtro: (valor: unknown) => tipoFiltro<T>;
|
||||
/** Definição do componente de entrada, ex: ["texto", { ... }] */
|
||||
entrada: any;
|
||||
}>;
|
||||
};
|
||||
```
|
||||
|
|
@ -129,7 +131,7 @@ Use o helper `celulaTabela` para criar definições de células com segurança d
|
|||
|
||||
```vue
|
||||
<script setup lang="ts">
|
||||
import { EliTabela, celulaTabela } from "eli-vue";
|
||||
import { EliTabela, celulaTabela, criarFiltro26 } from "eli-vue";
|
||||
import type { tipoEliTabelaConsulta } from "eli-vue";
|
||||
import { UsuarioService } from "@/services/UsuarioService";
|
||||
import { BadgeCheck, Pencil, Plus } from "lucide-vue-next";
|
||||
|
|
@ -170,15 +172,16 @@ const tabelaConfig: tipoEliTabelaConsulta<Usuario> = {
|
|||
filtroAvancado: [
|
||||
{
|
||||
rotulo: "Nome",
|
||||
coluna: "nome",
|
||||
operador: "like",
|
||||
// definição do input: ["tipo", opcoes]
|
||||
chave: "nome",
|
||||
// Função que retorna o objeto de filtro estruturado
|
||||
filtro: (valor: unknown) => criarFiltro26({ nome: { like: valor as string } }),
|
||||
// Definição do input: ["tipo", opcoes]
|
||||
entrada: ["texto", { rotulo: "Nome do usuário" }] as any
|
||||
},
|
||||
{
|
||||
rotulo: "Ativo?",
|
||||
coluna: "ativo",
|
||||
operador: "=",
|
||||
chave: "ativo",
|
||||
filtro: (valor: unknown) => criarFiltro26({ ativo: { "=": valor } }),
|
||||
entrada: ["selecao", {
|
||||
rotulo: "Status",
|
||||
itens: () => [
|
||||
|
|
|
|||
6068
dist/eli-vue.es.js
vendored
6068
dist/eli-vue.es.js
vendored
File diff suppressed because one or more lines are too long
40
dist/eli-vue.umd.js
vendored
40
dist/eli-vue.umd.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -18,12 +18,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
erro: import("vue").Ref<string | null, string | null>;
|
||||
linhas: import("vue").Ref<unknown[], unknown[]>;
|
||||
linhasPaginadas: import("vue").ComputedRef<unknown[]>;
|
||||
filtrosAvancadosAtivos: import("vue").ComputedRef<{
|
||||
coluna: string;
|
||||
valor: any;
|
||||
operador: "=" | "!=" | ">" | ">=" | "<" | "<=" | "like" | "in" | "isNull";
|
||||
ou?: boolean | undefined;
|
||||
}[]>;
|
||||
filtrosAvancadosAtivos: import("vue").ComputedRef<tipoFiltro<any>[]>;
|
||||
quantidadeFiltrada: import("vue").ComputedRef<number>;
|
||||
quantidade: import("vue").Ref<number, number>;
|
||||
menuAberto: import("vue").Ref<number | null, number | null>;
|
||||
|
|
@ -60,7 +55,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
parametrosConsultaAtuais: import("vue").ComputedRef<{
|
||||
atualizarConsulta: () => Promise<void>;
|
||||
editarLista: (novaLista: any[]) => Promise<any[]>;
|
||||
filtros?: tipoFiltro[];
|
||||
filtros?: import("p-comuns").tipoFiltro26<any>[] | undefined;
|
||||
coluna_ordem?: string | number | symbol | undefined;
|
||||
direcao_ordem?: "asc" | "desc";
|
||||
offSet?: number;
|
||||
|
|
@ -88,13 +83,13 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
salvarModalColunas: (cfg: EliTabelaColunasConfig) => void;
|
||||
modalFiltroAberto: import("vue").Ref<boolean, boolean>;
|
||||
filtrosUi: import("vue").Ref<{
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
valor: any;
|
||||
}[], {
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
valor: any;
|
||||
}[] | {
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
valor: any;
|
||||
}[]>;
|
||||
salvarFiltrosAvancados: (novo: any[]) => void;
|
||||
|
|
@ -861,8 +856,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
};
|
||||
filtrosBase: {
|
||||
type: PropType<Array<{
|
||||
coluna: string | number | symbol;
|
||||
operador: import("p-comuns").operadores | keyof typeof import("p-comuns").operadores;
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
filtro: (valor: unknown) => import("p-comuns").tipoFiltro26<any>;
|
||||
entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada;
|
||||
}>>;
|
||||
required: true;
|
||||
|
|
@ -873,7 +869,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
};
|
||||
}>, {
|
||||
linhas: import("vue").Ref<{
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
entrada: readonly ["texto", {
|
||||
rotulo: string;
|
||||
placeholder?: string | undefined;
|
||||
|
|
@ -928,15 +924,13 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
densidade?: import("../..").CampoDensidade | undefined;
|
||||
variante?: import("../..").CampoVariante | undefined;
|
||||
}];
|
||||
operador: string;
|
||||
valor: any;
|
||||
}[], {
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada;
|
||||
operador: string;
|
||||
valor: any;
|
||||
}[] | {
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
entrada: readonly ["texto", {
|
||||
rotulo: string;
|
||||
placeholder?: string | undefined;
|
||||
|
|
@ -991,15 +985,15 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
densidade?: import("../..").CampoDensidade | undefined;
|
||||
variante?: import("../..").CampoVariante | undefined;
|
||||
}];
|
||||
operador: string;
|
||||
valor: any;
|
||||
}[]>;
|
||||
opcoesParaAdicionar: import("vue").ComputedRef<{
|
||||
coluna: string | number | symbol;
|
||||
operador: import("p-comuns").operadores | keyof typeof import("p-comuns").operadores;
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
filtro: (valor: unknown) => import("p-comuns").tipoFiltro26<any>;
|
||||
entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada;
|
||||
}[]>;
|
||||
colunaParaAdicionar: import("vue").Ref<string, string>;
|
||||
chaveParaAdicionar: import("vue").Ref<string, string>;
|
||||
componenteEntrada: (entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada) => import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
||||
value: {
|
||||
type: PropType<string | null | undefined>;
|
||||
|
|
@ -1352,8 +1346,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
emitSalvar: () => void;
|
||||
emitLimpar: () => void;
|
||||
rotuloDoFiltro: (f: {
|
||||
coluna: string | number | symbol;
|
||||
operador: import("p-comuns").operadores | keyof typeof import("p-comuns").operadores;
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
filtro: (valor: unknown) => import("p-comuns").tipoFiltro26<any>;
|
||||
entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada;
|
||||
}) => string;
|
||||
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
||||
|
|
@ -1367,8 +1362,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
};
|
||||
filtrosBase: {
|
||||
type: PropType<Array<{
|
||||
coluna: string | number | symbol;
|
||||
operador: import("p-comuns").operadores | keyof typeof import("p-comuns").operadores;
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
filtro: (valor: unknown) => import("p-comuns").tipoFiltro26<any>;
|
||||
entrada: import("../EliEntrada/tiposEntradas").ComponenteEntrada;
|
||||
}>>;
|
||||
required: true;
|
||||
|
|
|
|||
|
|
@ -2,10 +2,9 @@ import { type PropType } from "vue";
|
|||
import type { ComponenteEntrada } from "../EliEntrada/tiposEntradas";
|
||||
import type { tipoEliTabelaConsulta } from "./types-eli-tabela";
|
||||
type FiltroBase<T> = NonNullable<tipoEliTabelaConsulta<T>["filtroAvancado"]>[number];
|
||||
type LinhaFiltro<T> = {
|
||||
coluna: keyof T;
|
||||
type LinhaFiltro = {
|
||||
chave: string;
|
||||
entrada: ComponenteEntrada;
|
||||
operador: string;
|
||||
valor: any;
|
||||
};
|
||||
declare function rotuloDoFiltro(f: FiltroBase<any>): string;
|
||||
|
|
@ -26,7 +25,7 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
};
|
||||
}>, {
|
||||
linhas: import("vue").Ref<{
|
||||
coluna: string | number | symbol;
|
||||
chave: string;
|
||||
entrada: readonly ["texto", {
|
||||
rotulo: string;
|
||||
placeholder?: string | undefined;
|
||||
|
|
@ -81,10 +80,9 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
densidade?: import("../..").CampoDensidade | undefined;
|
||||
variante?: import("../..").CampoVariante | undefined;
|
||||
}];
|
||||
operador: string;
|
||||
valor: any;
|
||||
}[], LinhaFiltro<any>[] | {
|
||||
coluna: string | number | symbol;
|
||||
}[], LinhaFiltro[] | {
|
||||
chave: string;
|
||||
entrada: readonly ["texto", {
|
||||
rotulo: string;
|
||||
placeholder?: string | undefined;
|
||||
|
|
@ -139,15 +137,15 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|||
densidade?: import("../..").CampoDensidade | undefined;
|
||||
variante?: import("../..").CampoVariante | undefined;
|
||||
}];
|
||||
operador: string;
|
||||
valor: any;
|
||||
}[]>;
|
||||
opcoesParaAdicionar: import("vue").ComputedRef<{
|
||||
coluna: string | number | symbol;
|
||||
operador: import("p-comuns").operadores | keyof typeof import("p-comuns").operadores;
|
||||
chave: string;
|
||||
rotulo: string;
|
||||
filtro: (valor: unknown) => import("p-comuns").tipoFiltro26<any>;
|
||||
entrada: ComponenteEntrada;
|
||||
}[]>;
|
||||
colunaParaAdicionar: import("vue").Ref<string, string>;
|
||||
chaveParaAdicionar: import("vue").Ref<string, string>;
|
||||
componenteEntrada: (entrada: ComponenteEntrada) => import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
||||
value: {
|
||||
type: PropType<string | null | undefined>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export type EliTabelaFiltroAvancadoSalvo<T> = Array<{
|
||||
coluna: keyof T;
|
||||
valor: any;
|
||||
valor: T[keyof T];
|
||||
}>;
|
||||
export declare function carregarFiltroAvancado<T>(nomeTabela: string): EliTabelaFiltroAvancadoSalvo<T>;
|
||||
export declare function salvarFiltroAvancado<T>(nomeTabela: string, filtros: EliTabelaFiltroAvancadoSalvo<T>): void;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import type { LucideIcon } from "lucide-vue-next";
|
||||
import type { operadores, zFiltro } from "p-comuns";
|
||||
import type { tipoFiltro26 } from "p-comuns";
|
||||
export type tipoFiltro<T> = tipoFiltro26<T>;
|
||||
import type { tipoResposta } from "p-respostas";
|
||||
import type { ComponenteEntrada } from "../EliEntrada/tiposEntradas";
|
||||
import type { tiposTabelaCelulas, tipoTabelaCelula } from "./celulas/tiposTabelaCelulas";
|
||||
export type tipoFiltro = ReturnType<(typeof zFiltro)["parse"]>;
|
||||
export type tipoComponenteCelulaBase<T extends tipoTabelaCelula> = readonly [
|
||||
T,
|
||||
tiposTabelaCelulas[T]
|
||||
|
|
@ -52,7 +52,7 @@ export type tipoEliTabelaAcao<T> = {
|
|||
exibir?: boolean | ((linha: T) => Promise<boolean> | boolean);
|
||||
};
|
||||
export type parametrosConsulta<T> = {
|
||||
filtros?: tipoFiltro[];
|
||||
filtros?: tipoFiltro26<T>[];
|
||||
coluna_ordem?: keyof T;
|
||||
direcao_ordem?: "asc" | "desc";
|
||||
offSet?: number;
|
||||
|
|
@ -115,8 +115,13 @@ export type tipoEliTabelaConsulta<T> = {
|
|||
}) => void;
|
||||
}[];
|
||||
filtroAvancado?: {
|
||||
coluna: keyof T;
|
||||
operador: operadores | keyof typeof operadores;
|
||||
/** Identificador único do filtro (usado para persistência) */
|
||||
chave: string;
|
||||
/** Rótulo exibido no select de adicionar filtro */
|
||||
rotulo: string;
|
||||
/** vai gerar filtro e mescla com os filtros já existentes */
|
||||
filtro: (valor: unknown) => tipoFiltro26<T>;
|
||||
/** componente de entrada que vai receber o valor para o filtro */
|
||||
entrada: ComponenteEntrada;
|
||||
}[];
|
||||
};
|
||||
|
|
|
|||
1
dist/types/index.d.ts
vendored
1
dist/types/index.d.ts
vendored
|
|
@ -8,6 +8,7 @@ export { EliOlaMundo };
|
|||
export { EliBotao };
|
||||
export { EliBadge };
|
||||
export { EliCartao };
|
||||
export { criarFiltro26 } from "p-comuns";
|
||||
export * from "./componentes/EliEntrada";
|
||||
export * from "./componentes/EliTabela";
|
||||
export * from "./tipos";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "eli-vue",
|
||||
"version": "0.1.102",
|
||||
"version": "0.1.105",
|
||||
"private": false,
|
||||
"main": "./dist/eli-vue.umd.js",
|
||||
"module": "./dist/eli-vue.es.js",
|
||||
|
|
|
|||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
|
|
@ -19,7 +19,7 @@ importers:
|
|||
version: 0.563.0(vue@3.5.28(typescript@5.9.3))
|
||||
p-comuns:
|
||||
specifier: git+https://git2.idz.one/publico/_comuns.git
|
||||
version: git+https://git2.idz.one/publico/_comuns.git#303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.3.6)
|
||||
version: git+https://git2.idz.one/publico/_comuns.git#64ddd6ad8af5e09a81d247fb1b23c2b05731d321(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.3.6)
|
||||
p-respostas:
|
||||
specifier: git+https://git2.idz.one/publico/_respostas.git
|
||||
version: git+https://git2.idz.one/publico/_respostas.git#8c24d790ace7255404745dcbdf12c5396e8b9843(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)
|
||||
|
|
@ -659,9 +659,9 @@ packages:
|
|||
encoding:
|
||||
optional: true
|
||||
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf:
|
||||
resolution: {commit: 303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf, repo: https://git2.idz.one/publico/_comuns.git, type: git}
|
||||
version: 0.304.0
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#64ddd6ad8af5e09a81d247fb1b23c2b05731d321:
|
||||
resolution: {commit: 64ddd6ad8af5e09a81d247fb1b23c2b05731d321, repo: https://git2.idz.one/publico/_comuns.git, type: git}
|
||||
version: 0.310.0
|
||||
peerDependencies:
|
||||
cross-fetch: 4.1.0
|
||||
dayjs: ^1.11.18
|
||||
|
|
@ -1273,14 +1273,14 @@ snapshots:
|
|||
dependencies:
|
||||
whatwg-url: 5.0.0
|
||||
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.1.4):
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#64ddd6ad8af5e09a81d247fb1b23c2b05731d321(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.1.4):
|
||||
dependencies:
|
||||
cross-fetch: 4.1.0
|
||||
dayjs: 1.11.19
|
||||
uuid: 13.0.0
|
||||
zod: 4.1.4
|
||||
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.3.6):
|
||||
p-comuns@git+https://git2.idz.one/publico/_comuns.git#64ddd6ad8af5e09a81d247fb1b23c2b05731d321(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.3.6):
|
||||
dependencies:
|
||||
cross-fetch: 4.1.0
|
||||
dayjs: 1.11.19
|
||||
|
|
@ -1289,7 +1289,7 @@ snapshots:
|
|||
|
||||
p-respostas@git+https://git2.idz.one/publico/_respostas.git#8c24d790ace7255404745dcbdf12c5396e8b9843(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0):
|
||||
dependencies:
|
||||
p-comuns: git+https://git2.idz.one/publico/_comuns.git#303832ba8c4ee87cbdc6ae80ff12a56da6ce37cf(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.1.4)
|
||||
p-comuns: git+https://git2.idz.one/publico/_comuns.git#64ddd6ad8af5e09a81d247fb1b23c2b05731d321(cross-fetch@4.1.0)(dayjs@1.11.19)(uuid@13.0.0)(zod@4.1.4)
|
||||
zod: 4.1.4
|
||||
transitivePeerDependencies:
|
||||
- cross-fetch
|
||||
|
|
|
|||
|
|
@ -193,14 +193,12 @@ export default defineComponent({
|
|||
|
||||
/** Filtro avançado (config + estado modal) */
|
||||
const modalFiltroAberto = ref(false)
|
||||
type LinhaFiltroUI<T> = {
|
||||
coluna: keyof T
|
||||
type LinhaFiltroUI = {
|
||||
chave: string
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic value
|
||||
valor: any
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic ui
|
||||
const filtrosUi = ref<Array<LinhaFiltroUI<any>>>(
|
||||
const filtrosUi = ref<Array<LinhaFiltroUI>>(
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic load
|
||||
carregarFiltroAvancado<any>(props.tabela.nome) as any,
|
||||
)
|
||||
|
|
@ -238,29 +236,23 @@ export default defineComponent({
|
|||
else void carregar()
|
||||
}
|
||||
|
||||
const filtrosAvancadosAtivos = computed<tipoFiltro[]>(() => {
|
||||
// Operador vem travado na definição (`tabela.filtroAvancado`).
|
||||
const base = (props.tabela.filtroAvancado ?? []) as Array<{
|
||||
coluna: string
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic operator
|
||||
operador: any
|
||||
}>
|
||||
// biome-ignore lint/suspicious/noExplicitAny: generic
|
||||
const filtrosAvancadosAtivos = computed<tipoFiltro<any>[]>(() => {
|
||||
const base = props.tabela.filtroAvancado ?? []
|
||||
|
||||
return (filtrosUi.value ?? [])
|
||||
.filter((f) => f && f.coluna !== undefined)
|
||||
.map((f) => {
|
||||
const b = base.find((x) => String(x.coluna) === String(f.coluna))
|
||||
if (!b) return null
|
||||
return (
|
||||
(filtrosUi.value ?? [])
|
||||
.filter((f) => f && f.chave !== undefined)
|
||||
.map((f) => {
|
||||
const b = base.find((x) => String(x.chave) === String(f.chave))
|
||||
if (!b) return null
|
||||
|
||||
return {
|
||||
coluna: String(b.coluna),
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic operator
|
||||
operador: b.operador as any,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic value
|
||||
valor: (f as any).valor,
|
||||
} as tipoFiltro
|
||||
})
|
||||
.filter(Boolean) as tipoFiltro[]
|
||||
// O filtro já vem pronto da função definida na configuração
|
||||
return b.filtro(f.valor)
|
||||
})
|
||||
// biome-ignore lint/suspicious/noExplicitAny: generic
|
||||
.filter(Boolean) as tipoFiltro<any>[]
|
||||
)
|
||||
})
|
||||
|
||||
/** Alias reativo da prop tabela */
|
||||
|
|
@ -647,7 +639,8 @@ export default defineComponent({
|
|||
const offset = (paginaAtual.value - 1) * limite
|
||||
|
||||
const parametrosConsulta: {
|
||||
filtros?: tipoFiltro[]
|
||||
// biome-ignore lint/suspicious/noExplicitAny: generic
|
||||
filtros?: tipoFiltro<any>[]
|
||||
coluna_ordem?: never
|
||||
direcao_ordem?: "asc" | "desc"
|
||||
offSet: number
|
||||
|
|
|
|||
|
|
@ -14,11 +14,13 @@
|
|||
</div>
|
||||
|
||||
<div v-else class="eli-tabela-modal-filtro__lista">
|
||||
<div v-for="(linha, idx) in linhas" :key="String(linha.coluna)" class="eli-tabela-modal-filtro__linha">
|
||||
<div v-for="(linha, idx) in linhas" :key="String(linha.chave)" class="eli-tabela-modal-filtro__linha">
|
||||
<div class="eli-tabela-modal-filtro__entrada">
|
||||
<component
|
||||
:is="componenteEntrada(linha.entrada)"
|
||||
v-model:value="linha.valor"
|
||||
:value="linha.valor"
|
||||
@update:value="(v: any) => (linha.valor = v)"
|
||||
@input="(v: any) => (linha.valor = v)"
|
||||
:opcoes="opcoesEntrada(linha.entrada)"
|
||||
density="compact"
|
||||
/>
|
||||
|
|
@ -38,12 +40,12 @@
|
|||
|
||||
<div class="eli-tabela-modal-filtro__acoes">
|
||||
<select
|
||||
v-model="colunaParaAdicionar"
|
||||
v-model="chaveParaAdicionar"
|
||||
class="eli-tabela-modal-filtro__select"
|
||||
:disabled="!opcoesParaAdicionar.length"
|
||||
>
|
||||
<option disabled value="">Selecione um filtro…</option>
|
||||
<option v-for="o in opcoesParaAdicionar" :key="String(o.coluna)" :value="String(o.coluna)">
|
||||
<option v-for="o in opcoesParaAdicionar" :key="String(o.chave)" :value="String(o.chave)">
|
||||
{{ rotuloDoFiltro(o) }}
|
||||
</option>
|
||||
</select>
|
||||
|
|
@ -51,7 +53,7 @@
|
|||
type="button"
|
||||
class="eli-tabela-modal-filtro__botao"
|
||||
@click="adicionar"
|
||||
:disabled="!colunaParaAdicionar"
|
||||
:disabled="!chaveParaAdicionar"
|
||||
>
|
||||
Adicionar
|
||||
</button>
|
||||
|
|
@ -80,33 +82,23 @@ import {
|
|||
EliEntradaNumero,
|
||||
EliEntradaTexto,
|
||||
} from "../EliEntrada"
|
||||
import type {
|
||||
ComponenteEntrada,
|
||||
TipoEntrada,
|
||||
} from "../EliEntrada/tiposEntradas"
|
||||
import type { ComponenteEntrada } from "../EliEntrada/tiposEntradas"
|
||||
import type { tipoEliTabelaConsulta } from "./types-eli-tabela"
|
||||
|
||||
type FiltroBase<T> = NonNullable<
|
||||
tipoEliTabelaConsulta<T>["filtroAvancado"]
|
||||
>[number]
|
||||
|
||||
type LinhaFiltro<T> = {
|
||||
coluna: keyof T
|
||||
type LinhaFiltro = {
|
||||
chave: string
|
||||
entrada: ComponenteEntrada
|
||||
operador: string
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic value
|
||||
valor: any
|
||||
}
|
||||
|
||||
function isTipoEntrada(v: unknown): v is TipoEntrada {
|
||||
return v === "texto" || v === "numero" || v === "dataHora"
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic typing needed
|
||||
function rotuloDoFiltro(f: FiltroBase<any>) {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic access
|
||||
const rotulo = (f?.entrada?.[1] as any)?.rotulo
|
||||
return rotulo ? String(rotulo) : String(f?.coluna ?? "Filtro")
|
||||
return f.rotulo
|
||||
}
|
||||
|
||||
export default defineComponent({
|
||||
|
|
@ -114,7 +106,7 @@ export default defineComponent({
|
|||
props: {
|
||||
aberto: { type: Boolean, required: true },
|
||||
filtrosBase: {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic filter type
|
||||
// biome-ignore lint/suspicious/noExplicitAny: generic component
|
||||
type: Array as PropType<Array<FiltroBase<any>>>,
|
||||
required: true,
|
||||
},
|
||||
|
|
@ -131,19 +123,18 @@ export default defineComponent({
|
|||
salvar: (_linhas: any[]) => true,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic value
|
||||
const linhas = ref<Array<LinhaFiltro<any>>>([])
|
||||
const linhas = ref<Array<LinhaFiltro>>([])
|
||||
|
||||
const colunaParaAdicionar = ref<string>("")
|
||||
const chaveParaAdicionar = ref<string>("")
|
||||
|
||||
const colunasDisponiveis = computed(() =>
|
||||
(props.filtrosBase ?? []).map((b) => String(b.coluna)),
|
||||
const chavesDisponiveis = computed(() =>
|
||||
(props.filtrosBase ?? []).map((b) => String(b.chave)),
|
||||
)
|
||||
|
||||
const opcoesParaAdicionar = computed(() => {
|
||||
const usadas = new Set(linhas.value.map((l) => String(l.coluna)))
|
||||
const usadas = new Set(linhas.value.map((l) => String(l.chave)))
|
||||
return (props.filtrosBase ?? []).filter(
|
||||
(b) => !usadas.has(String(b.coluna)),
|
||||
(b) => !usadas.has(String(b.chave)),
|
||||
)
|
||||
})
|
||||
|
||||
|
|
@ -169,42 +160,30 @@ export default defineComponent({
|
|||
function normalizarModelo() {
|
||||
const base = props.filtrosBase ?? []
|
||||
const modelo = Array.isArray(props.modelo) ? props.modelo : []
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic model
|
||||
linhas.value = modelo.map((m: any) => {
|
||||
// operador vem travado no base
|
||||
const baseItem =
|
||||
base.find((b) => String(b.coluna) === String(m.coluna)) ?? base[0]
|
||||
const entrada = (baseItem?.entrada ?? m.entrada) as ComponenteEntrada
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic column
|
||||
const col = (baseItem?.coluna ?? m.coluna) as any
|
||||
const op = String(baseItem?.operador ?? "=")
|
||||
const val = m.valor ?? valorInicialPorEntrada(entrada)
|
||||
linhas.value = modelo
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic model item
|
||||
.map((m: any) => {
|
||||
const baseItem =
|
||||
base.find((b) => String(b.chave) === String(m.chave)) ?? base[0]
|
||||
|
||||
return {
|
||||
coluna: col,
|
||||
operador: op,
|
||||
entrada,
|
||||
valor: val,
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic cast
|
||||
} as LinhaFiltro<any>
|
||||
})
|
||||
if (!baseItem) return null
|
||||
|
||||
// se vazio e existe base, adiciona 1 linha default
|
||||
// não auto-adiciona; usuário escolhe quais filtros quer usar
|
||||
const entrada = (baseItem.entrada ?? m.entrada) as ComponenteEntrada
|
||||
const chave = String(baseItem.chave ?? m.chave)
|
||||
const val = m.valor ?? valorInicialPorEntrada(entrada)
|
||||
|
||||
// se algum filtro mudou a coluna para valor inválido, ajusta
|
||||
for (const l of linhas.value) {
|
||||
if (!colunasDisponiveis.value.includes(String(l.coluna))) continue
|
||||
l.operador = String(
|
||||
base.find((b) => String(b.coluna) === String(l.coluna))?.operador ??
|
||||
"=",
|
||||
)
|
||||
// sanity
|
||||
if (l.entrada && !isTipoEntrada(l.entrada[0])) {
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic sanity
|
||||
l.entrada = ["texto", { rotulo: "Valor" }] as any
|
||||
}
|
||||
}
|
||||
return {
|
||||
chave: chave,
|
||||
entrada,
|
||||
valor: val,
|
||||
} as LinhaFiltro
|
||||
})
|
||||
.filter(Boolean) as LinhaFiltro[]
|
||||
|
||||
// se algum filtro mudou a chave para valor inválido, ajusta
|
||||
linhas.value = linhas.value.filter((l) =>
|
||||
chavesDisponiveis.value.includes(String(l.chave)),
|
||||
)
|
||||
}
|
||||
|
||||
watch(
|
||||
|
|
@ -216,24 +195,21 @@ export default defineComponent({
|
|||
)
|
||||
|
||||
function adicionar() {
|
||||
if (!colunaParaAdicionar.value) return
|
||||
if (!chaveParaAdicionar.value) return
|
||||
const b0 = (props.filtrosBase ?? []).find(
|
||||
(b) => String(b.coluna) === String(colunaParaAdicionar.value),
|
||||
(b) => String(b.chave) === String(chaveParaAdicionar.value),
|
||||
)
|
||||
if (!b0) return
|
||||
// evita repetição
|
||||
if (linhas.value.some((l) => String(l.coluna) === String(b0.coluna)))
|
||||
return
|
||||
if (linhas.value.some((l) => String(l.chave) === String(b0.chave))) return
|
||||
|
||||
linhas.value.push({
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic column
|
||||
coluna: b0.coluna as any,
|
||||
chave: String(b0.chave),
|
||||
entrada: b0.entrada,
|
||||
operador: String(b0.operador ?? "="),
|
||||
valor: valorInicialPorEntrada(b0.entrada),
|
||||
})
|
||||
|
||||
colunaParaAdicionar.value = ""
|
||||
chaveParaAdicionar.value = ""
|
||||
}
|
||||
|
||||
function remover(idx: number) {
|
||||
|
|
@ -252,7 +228,7 @@ export default defineComponent({
|
|||
emit(
|
||||
"salvar",
|
||||
linhas.value.map((l) => ({
|
||||
coluna: l.coluna,
|
||||
chave: l.chave,
|
||||
valor: l.valor,
|
||||
})),
|
||||
)
|
||||
|
|
@ -261,12 +237,11 @@ export default defineComponent({
|
|||
return {
|
||||
linhas,
|
||||
opcoesParaAdicionar,
|
||||
colunaParaAdicionar,
|
||||
chaveParaAdicionar,
|
||||
componenteEntrada,
|
||||
opcoesEntrada,
|
||||
adicionar,
|
||||
remover,
|
||||
// exibimos operador fixo só como texto
|
||||
emitFechar,
|
||||
emitSalvar,
|
||||
emitLimpar,
|
||||
|
|
|
|||
|
|
@ -16,15 +16,12 @@ function normalizarConfig(valor: unknown): EliTabelaColunasConfig {
|
|||
return { visiveis: [], invisiveis: [] }
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic config
|
||||
const v = valor as any
|
||||
const v = valor as EliTabelaColunasConfig
|
||||
const visiveis = Array.isArray(v.visiveis)
|
||||
? // biome-ignore lint/suspicious/noExplicitAny: dynamic array item
|
||||
v.visiveis.filter((x: any) => typeof x === "string")
|
||||
? v.visiveis.filter((x: unknown) => typeof x === "string")
|
||||
: []
|
||||
const invisiveis = Array.isArray(v.invisiveis)
|
||||
? // biome-ignore lint/suspicious/noExplicitAny: dynamic array item
|
||||
v.invisiveis.filter((x: any) => typeof x === "string")
|
||||
? v.invisiveis.filter((x: unknown) => typeof x === "string")
|
||||
: []
|
||||
return { visiveis, invisiveis }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export type EliTabelaFiltroAvancadoSalvo<T> = Array<{
|
||||
coluna: keyof T
|
||||
// biome-ignore lint/suspicious/noExplicitAny: dynamic value
|
||||
valor: any
|
||||
|
||||
valor: T[keyof T]
|
||||
}>
|
||||
|
||||
function key(nomeTabela: string) {
|
||||
|
|
@ -17,8 +17,7 @@ export function carregarFiltroAvancado<T>(
|
|||
const parsed = JSON.parse(raw)
|
||||
return Array.isArray(parsed)
|
||||
? (parsed as EliTabelaFiltroAvancadoSalvo<T>)
|
||||
: // biome-ignore lint/suspicious/noExplicitAny: dynamic cast
|
||||
([] as any)
|
||||
: ([] as unknown as EliTabelaFiltroAvancadoSalvo<T>)
|
||||
} catch {
|
||||
return [] as unknown as EliTabelaFiltroAvancadoSalvo<T>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import type { LucideIcon } from "lucide-vue-next"
|
||||
import type { operadores, zFiltro } from "p-comuns"
|
||||
import type { tipoFiltro26 } from "p-comuns"
|
||||
|
||||
export type tipoFiltro<T> = tipoFiltro26<T>
|
||||
|
||||
import type { tipoResposta } from "p-respostas"
|
||||
import type { ComponenteEntrada } from "../EliEntrada/tiposEntradas"
|
||||
import type {
|
||||
|
|
@ -7,9 +10,6 @@ import type {
|
|||
tipoTabelaCelula,
|
||||
} from "./celulas/tiposTabelaCelulas"
|
||||
|
||||
// `p-comuns` expõe `zFiltro` (schema). Inferimos o tipo a partir do `parse`.
|
||||
export type tipoFiltro = ReturnType<(typeof zFiltro)["parse"]>
|
||||
|
||||
export type tipoComponenteCelulaBase<T extends tipoTabelaCelula> = readonly [
|
||||
T,
|
||||
tiposTabelaCelulas[T],
|
||||
|
|
@ -72,7 +72,7 @@ export type tipoEliTabelaAcao<T> = {
|
|||
}
|
||||
|
||||
export type parametrosConsulta<T> = {
|
||||
filtros?: tipoFiltro[]
|
||||
filtros?: tipoFiltro26<T>[]
|
||||
coluna_ordem?: keyof T
|
||||
direcao_ordem?: "asc" | "desc"
|
||||
offSet?: number
|
||||
|
|
@ -143,8 +143,13 @@ export type tipoEliTabelaConsulta<T> = {
|
|||
}[]
|
||||
|
||||
filtroAvancado?: {
|
||||
coluna: keyof T
|
||||
operador: operadores | keyof typeof operadores
|
||||
/** Identificador único do filtro (usado para persistência) */
|
||||
chave: string
|
||||
/** Rótulo exibido no select de adicionar filtro */
|
||||
rotulo: string
|
||||
/** vai gerar filtro e mescla com os filtros já existentes */
|
||||
filtro: (valor: unknown) => tipoFiltro26<T>
|
||||
/** componente de entrada que vai receber o valor para o filtro */
|
||||
entrada: ComponenteEntrada
|
||||
}[]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,10 +18,10 @@ export { EliBotao }
|
|||
export { EliBadge }
|
||||
export { EliCartao }
|
||||
|
||||
export { criarFiltro26 } from "p-comuns"
|
||||
export * from "./componentes/EliEntrada"
|
||||
// Exportar tudo (componentes + types + helpers) de Tabela e Entrada
|
||||
export * from "./componentes/EliTabela"
|
||||
|
||||
// Exportar tipos compartilhados (ex: CartaoStatus)
|
||||
export * from "./tipos"
|
||||
|
||||
|
|
|
|||
|
|
@ -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