godeep-states 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +158 -0
- package/dist/module.d.mts +8 -0
- package/dist/module.json +9 -0
- package/dist/module.mjs +28 -0
- package/dist/runtime/composables/useHeader.d.ts +2 -0
- package/dist/runtime/composables/useHeader.js +33 -0
- package/dist/runtime/plugin.d.ts +2 -0
- package/dist/runtime/plugin.js +3 -0
- package/dist/runtime/server/api/[...slug].d.ts +2 -0
- package/dist/runtime/server/api/[...slug].js +66 -0
- package/dist/runtime/server/routes/robots.d.ts +2 -0
- package/dist/runtime/server/routes/robots.js +37 -0
- package/dist/runtime/server/routes/robots.txt.d.ts +2 -0
- package/dist/runtime/server/routes/robots.txt.js +37 -0
- package/dist/runtime/server/tsconfig.json +3 -0
- package/dist/runtime/stores/.vscode/settings.json +3 -0
- package/dist/runtime/stores/avaliacoes.d.ts +53 -0
- package/dist/runtime/stores/avaliacoes.js +63 -0
- package/dist/runtime/stores/banner.d.ts +6 -0
- package/dist/runtime/stores/banner.js +88 -0
- package/dist/runtime/stores/busca.d.ts +8 -0
- package/dist/runtime/stores/busca.js +51 -0
- package/dist/runtime/stores/cadastro.d.ts +6 -0
- package/dist/runtime/stores/cadastro.js +117 -0
- package/dist/runtime/stores/carrinho.d.ts +8 -0
- package/dist/runtime/stores/carrinho.js +219 -0
- package/dist/runtime/stores/categoria.d.ts +10 -0
- package/dist/runtime/stores/categoria.js +137 -0
- package/dist/runtime/stores/configuracoes.d.ts +16 -0
- package/dist/runtime/stores/configuracoes.js +85 -0
- package/dist/runtime/stores/dados-cadastrais.d.ts +7 -0
- package/dist/runtime/stores/dados-cadastrais.js +89 -0
- package/dist/runtime/stores/enderecos.d.ts +7 -0
- package/dist/runtime/stores/enderecos.js +217 -0
- package/dist/runtime/stores/favoritos.d.ts +7 -0
- package/dist/runtime/stores/favoritos.js +120 -0
- package/dist/runtime/stores/filtros.d.ts +9 -0
- package/dist/runtime/stores/filtros.js +63 -0
- package/dist/runtime/stores/home.d.ts +5 -0
- package/dist/runtime/stores/home.js +59 -0
- package/dist/runtime/stores/login.d.ts +13 -0
- package/dist/runtime/stores/login.js +195 -0
- package/dist/runtime/stores/menus.d.ts +5 -0
- package/dist/runtime/stores/menus.js +35 -0
- package/dist/runtime/stores/newsletter.d.ts +6 -0
- package/dist/runtime/stores/newsletter.js +80 -0
- package/dist/runtime/stores/pagamentos.d.ts +5 -0
- package/dist/runtime/stores/pagamentos.js +35 -0
- package/dist/runtime/stores/paginas.d.ts +5 -0
- package/dist/runtime/stores/paginas.js +35 -0
- package/dist/runtime/stores/pedidos.d.ts +7 -0
- package/dist/runtime/stores/pedidos.js +59 -0
- package/dist/runtime/stores/produto.d.ts +9 -0
- package/dist/runtime/stores/produto.js +141 -0
- package/dist/runtime/stores/redes-sociais.d.ts +5 -0
- package/dist/runtime/stores/redes-sociais.js +38 -0
- package/dist/runtime/stores/vitrine.d.ts +13 -0
- package/dist/runtime/stores/vitrine.js +192 -0
- package/dist/runtime/types.d.ts +7 -0
- package/dist/runtime/utils/alerta.d.ts +10 -0
- package/dist/runtime/utils/alerta.js +7 -0
- package/dist/runtime/utils/erros.d.ts +15 -0
- package/dist/runtime/utils/erros.js +20 -0
- package/dist/types.d.mts +3 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# godeep-states
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![License][license-src]][license-href]
|
|
6
|
+
[![Nuxt][nuxt-src]][nuxt-href]
|
|
7
|
+
|
|
8
|
+
Módulo Nuxt que fornece stores Pinia e rotas de servidor para integração com a API GoDeep, removendo a responsabilidade de gerenciamento de estado do front-end do cliente.
|
|
9
|
+
|
|
10
|
+
- [✨ Release Notes](/CHANGELOG.md)
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- 🗄️ Stores Pinia pré-configurados para todas as funcionalidades do GoDeep
|
|
15
|
+
- 🔌 Rotas de servidor para proxy de API
|
|
16
|
+
- 🔄 Persistência de estado com sessionStorage
|
|
17
|
+
- 📦 Integração completa com godeep-types
|
|
18
|
+
- 🚀 Auto-descoberta de stores pelo Nuxt
|
|
19
|
+
|
|
20
|
+
## Quick Setup
|
|
21
|
+
|
|
22
|
+
Instale o módulo na sua aplicação Nuxt:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install godeep-states
|
|
26
|
+
# ou
|
|
27
|
+
bun add godeep-states
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Adicione o módulo ao seu `nuxt.config.ts`:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export default defineNuxtConfig({
|
|
34
|
+
modules: ['godeep-states'],
|
|
35
|
+
|
|
36
|
+
// Configure as variáveis de ambiente necessárias
|
|
37
|
+
runtimeConfig: {
|
|
38
|
+
public: {
|
|
39
|
+
urlApi: process.env.URL_API,
|
|
40
|
+
token: process.env.TOKEN_API,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Configure as variáveis de ambiente no seu `.env`:
|
|
47
|
+
|
|
48
|
+
```env
|
|
49
|
+
URL_API=https://sua-api-godeep.com
|
|
50
|
+
TOKEN_API=seu-token-aqui
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Pronto! Os stores estarão disponíveis automaticamente na sua aplicação ✨
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Stores Disponíveis
|
|
57
|
+
|
|
58
|
+
O módulo fornece os seguintes stores Pinia:
|
|
59
|
+
|
|
60
|
+
- `storeCarrinho` - Gerenciamento de carrinho de compras
|
|
61
|
+
- `storeHome` - Dados da página inicial
|
|
62
|
+
- `storeProduto` - Detalhes e informações de produtos
|
|
63
|
+
- `storeVitrine` - Listagens e vitrines de produtos
|
|
64
|
+
- `storeCategoria` - Categorias de produtos
|
|
65
|
+
- `storeBusca` - Resultados de busca
|
|
66
|
+
- `storeFavoritos` - Lista de favoritos
|
|
67
|
+
- `storeLogin` - Autenticação e login
|
|
68
|
+
- `storeCadastro` - Cadastro de usuários
|
|
69
|
+
- `storePedidos` - Histórico de pedidos
|
|
70
|
+
- `storeEnderecos` - Gerenciamento de endereços
|
|
71
|
+
- `storePagamentos` - Métodos de pagamento
|
|
72
|
+
- `storeConfiguracoes` - Configurações da loja
|
|
73
|
+
- `storeMenus` - Menus de navegação
|
|
74
|
+
- `storeBanner` - Banners promocionais
|
|
75
|
+
- `storeNewsletter` - Inscrições em newsletter
|
|
76
|
+
- `storePaginas` - Páginas estáticas
|
|
77
|
+
- `storeRedesSociais` - Links de redes sociais
|
|
78
|
+
- `storeAvaliacoes` - Avaliações de produtos
|
|
79
|
+
- `storeFiltros` - Filtros de busca
|
|
80
|
+
- `storeDadosCadastrais` - Dados cadastrais do usuário
|
|
81
|
+
|
|
82
|
+
## Uso
|
|
83
|
+
|
|
84
|
+
Os stores são auto-importados pelo Nuxt. Você pode usá-los diretamente nos seus componentes:
|
|
85
|
+
|
|
86
|
+
```vue
|
|
87
|
+
<script setup lang="ts">
|
|
88
|
+
const carrinhoStore = storeCarrinho()
|
|
89
|
+
const homeStore = storeHome()
|
|
90
|
+
|
|
91
|
+
// Usar os stores
|
|
92
|
+
await homeStore.buscarHome()
|
|
93
|
+
await carrinhoStore.adicionarProdutosCarrinho([...])
|
|
94
|
+
</script>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Rotas de Servidor
|
|
98
|
+
|
|
99
|
+
O módulo também fornece rotas de servidor:
|
|
100
|
+
|
|
101
|
+
- `/api/front-api/**` - Proxy para a API GoDeep
|
|
102
|
+
- `/robots` - Endpoint para robots.txt
|
|
103
|
+
- `/robots.txt` - Endpoint alternativo para robots.txt
|
|
104
|
+
|
|
105
|
+
## Dependências
|
|
106
|
+
|
|
107
|
+
Este módulo requer:
|
|
108
|
+
- `godeep-types` - Tipos TypeScript e funções de tradução
|
|
109
|
+
- `pinia` - Gerenciamento de estado
|
|
110
|
+
- `pinia-plugin-persistedstate` - Persistência de estado
|
|
111
|
+
|
|
112
|
+
## Contribution
|
|
113
|
+
|
|
114
|
+
<details>
|
|
115
|
+
<summary>Desenvolvimento local</summary>
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
# Instalar dependências
|
|
119
|
+
npm install
|
|
120
|
+
|
|
121
|
+
# Gerar stubs de tipos
|
|
122
|
+
npm run dev:prepare
|
|
123
|
+
|
|
124
|
+
# Desenvolver com o playground
|
|
125
|
+
npm run dev
|
|
126
|
+
|
|
127
|
+
# Build do playground
|
|
128
|
+
npm run dev:build
|
|
129
|
+
|
|
130
|
+
# Executar ESLint
|
|
131
|
+
npm run lint
|
|
132
|
+
npm run lint:fix
|
|
133
|
+
|
|
134
|
+
# Executar testes
|
|
135
|
+
npm run test
|
|
136
|
+
npm run test:watch
|
|
137
|
+
|
|
138
|
+
# Verificar tipos
|
|
139
|
+
npm run typecheck
|
|
140
|
+
|
|
141
|
+
# Publicar nova versão
|
|
142
|
+
npm run release
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
</details>
|
|
146
|
+
|
|
147
|
+
<!-- Badges -->
|
|
148
|
+
[npm-version-src]: https://img.shields.io/npm/v/godeep-states/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
149
|
+
[npm-version-href]: https://npmjs.com/package/godeep-states
|
|
150
|
+
|
|
151
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/godeep-states.svg?style=flat&colorA=020420&colorB=00DC82
|
|
152
|
+
[npm-downloads-href]: https://npm.chart.dev/godeep-states
|
|
153
|
+
|
|
154
|
+
[license-src]: https://img.shields.io/npm/l/godeep-states.svg?style=flat&colorA=020420&colorB=00DC82
|
|
155
|
+
[license-href]: https://npmjs.com/package/godeep-states
|
|
156
|
+
|
|
157
|
+
[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt
|
|
158
|
+
[nuxt-href]: https://nuxt.com
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineNuxtModule, createResolver, addPlugin, addServerHandler } from '@nuxt/kit';
|
|
2
|
+
|
|
3
|
+
const module$1 = defineNuxtModule({
|
|
4
|
+
meta: {
|
|
5
|
+
name: "godeep-states",
|
|
6
|
+
configKey: "godeepStates"
|
|
7
|
+
},
|
|
8
|
+
// Default configuration options of the Nuxt module
|
|
9
|
+
defaults: {},
|
|
10
|
+
setup(_options, _nuxt) {
|
|
11
|
+
const resolver = createResolver(import.meta.url);
|
|
12
|
+
addPlugin(resolver.resolve("./runtime/plugin"));
|
|
13
|
+
addServerHandler({
|
|
14
|
+
route: "/api/front-api/**",
|
|
15
|
+
handler: resolver.resolve("./runtime/server/api/[...slug]")
|
|
16
|
+
});
|
|
17
|
+
addServerHandler({
|
|
18
|
+
route: "/robots",
|
|
19
|
+
handler: resolver.resolve("./runtime/server/routes/robots")
|
|
20
|
+
});
|
|
21
|
+
addServerHandler({
|
|
22
|
+
route: "/robots.txt",
|
|
23
|
+
handler: resolver.resolve("./runtime/server/routes/robots.txt")
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export { module$1 as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getHeader, getCookie } from "h3";
|
|
2
|
+
export default async function useHeader(event, token) {
|
|
3
|
+
const headers = {
|
|
4
|
+
"Content-Type": "application/json",
|
|
5
|
+
"Accept": "application/json"
|
|
6
|
+
};
|
|
7
|
+
if (token) {
|
|
8
|
+
headers.Authorization = `Bearer ${token}`;
|
|
9
|
+
}
|
|
10
|
+
if (!token) {
|
|
11
|
+
const cookieToken = getCookie(event, "token");
|
|
12
|
+
if (cookieToken) {
|
|
13
|
+
headers.Authorization = `Bearer ${cookieToken}`;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
const cartId = getHeader(event, "cart-id") || getCookie(event, "cart.id");
|
|
17
|
+
if (cartId) {
|
|
18
|
+
headers["cart-id"] = cartId;
|
|
19
|
+
}
|
|
20
|
+
const userAgent = getHeader(event, "user-agent");
|
|
21
|
+
if (userAgent) {
|
|
22
|
+
headers["User-Agent"] = userAgent;
|
|
23
|
+
}
|
|
24
|
+
const referer = getHeader(event, "referer");
|
|
25
|
+
if (referer) {
|
|
26
|
+
headers.Referer = referer;
|
|
27
|
+
}
|
|
28
|
+
const origin = getHeader(event, "origin");
|
|
29
|
+
if (origin) {
|
|
30
|
+
headers.Origin = origin;
|
|
31
|
+
}
|
|
32
|
+
return headers;
|
|
33
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getRequestURL,
|
|
3
|
+
getQuery,
|
|
4
|
+
readBody,
|
|
5
|
+
createError,
|
|
6
|
+
defineEventHandler
|
|
7
|
+
} from "h3";
|
|
8
|
+
import useHeader from "../../composables/useHeader.js";
|
|
9
|
+
import { extrairMensagensErro } from "../../utils/erros.js";
|
|
10
|
+
export default defineEventHandler(async (event) => {
|
|
11
|
+
const config = useRuntimeConfig();
|
|
12
|
+
const urlApi = config.public.urlApi || config.urlApi || process.env.URL_API || "";
|
|
13
|
+
const token = config.public.token || config.token || process.env.TOKEN_API || "";
|
|
14
|
+
if (!urlApi) {
|
|
15
|
+
throw createError({
|
|
16
|
+
statusCode: 500,
|
|
17
|
+
message: "URL_API n\xE3o configurada"
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const requestUrl = getRequestURL(event);
|
|
21
|
+
const fullPath = requestUrl.pathname;
|
|
22
|
+
const targetUrl = `${urlApi}${fullPath}`;
|
|
23
|
+
const method = event.method;
|
|
24
|
+
const clientHeaders = await useHeader(event, token);
|
|
25
|
+
const query = getQuery(event);
|
|
26
|
+
const queryString = new URLSearchParams(
|
|
27
|
+
query
|
|
28
|
+
).toString();
|
|
29
|
+
const finalUrl = queryString ? `${targetUrl}?${queryString}` : targetUrl;
|
|
30
|
+
const options = {
|
|
31
|
+
method,
|
|
32
|
+
headers: clientHeaders,
|
|
33
|
+
body: null
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
console.log("finalUrl", finalUrl);
|
|
37
|
+
console.log("method", method);
|
|
38
|
+
if (method === "POST" || method === "PUT" || method === "PATCH") {
|
|
39
|
+
const body = await readBody(event);
|
|
40
|
+
if (body && Object.keys(body).length > 0) {
|
|
41
|
+
options.body = JSON.stringify(body);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const response = await fetch(finalUrl, options);
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
const errorData = await response.json().catch(() => ({}));
|
|
47
|
+
const { mensagemGeral, mensagensErro } = extrairMensagensErro(
|
|
48
|
+
errorData,
|
|
49
|
+
"Erro ao conectar com a API externa"
|
|
50
|
+
);
|
|
51
|
+
throw createError({
|
|
52
|
+
status: response.status,
|
|
53
|
+
message: mensagemGeral,
|
|
54
|
+
data: mensagensErro
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return await response.json();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
const errorObject = error;
|
|
60
|
+
return createError({
|
|
61
|
+
status: 500,
|
|
62
|
+
message: errorObject?.message ?? "Erro ao conectar com a API externa",
|
|
63
|
+
data: errorObject?.data ?? {}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineEventHandler, setHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
const urlApi = config.urlApi;
|
|
6
|
+
const token = config.token;
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(`${urlApi}/api/front-api/robots`, {
|
|
9
|
+
method: "GET",
|
|
10
|
+
headers: {
|
|
11
|
+
"Authorization": `Bearer ${token}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"Accept": "application/json"
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`API retornou status ${response.status}`);
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
let robotsContent = "User-agent: *\nAllow: /";
|
|
21
|
+
if (data.dados && Array.isArray(data.dados) && data.dados.length > 0) {
|
|
22
|
+
robotsContent = data.dados[0];
|
|
23
|
+
} else if (typeof data.dados === "string") {
|
|
24
|
+
robotsContent = data.dados;
|
|
25
|
+
} else if (data.dados) {
|
|
26
|
+
robotsContent = String(data.dados);
|
|
27
|
+
}
|
|
28
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
29
|
+
setHeader(event, "Cache-Control", "public, max-age=3600, s-maxage=3600");
|
|
30
|
+
return robotsContent;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Erro ao buscar robots.txt da API:", error);
|
|
33
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
34
|
+
setHeader(event, "Cache-Control", "public, max-age=300");
|
|
35
|
+
return "User-agent: *\nAllow: /";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineEventHandler, setHeader } from "h3";
|
|
2
|
+
import { useRuntimeConfig } from "#imports";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
const urlApi = config.urlApi;
|
|
6
|
+
const token = config.token;
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(`${urlApi}/api/front-api/robots`, {
|
|
9
|
+
method: "GET",
|
|
10
|
+
headers: {
|
|
11
|
+
"Authorization": `Bearer ${token}`,
|
|
12
|
+
"Content-Type": "application/json",
|
|
13
|
+
"Accept": "application/json"
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error(`API retornou status ${response.status}`);
|
|
18
|
+
}
|
|
19
|
+
const data = await response.json();
|
|
20
|
+
let robotsContent = "User-agent: *\nAllow: /";
|
|
21
|
+
if (data.dados && Array.isArray(data.dados) && data.dados.length > 0) {
|
|
22
|
+
robotsContent = data.dados[0];
|
|
23
|
+
} else if (typeof data.dados === "string") {
|
|
24
|
+
robotsContent = data.dados;
|
|
25
|
+
} else if (data.dados) {
|
|
26
|
+
robotsContent = String(data.dados);
|
|
27
|
+
}
|
|
28
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
29
|
+
setHeader(event, "Cache-Control", "public, max-age=3600, s-maxage=3600");
|
|
30
|
+
return robotsContent;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error("Erro ao buscar robots.txt da API:", error);
|
|
33
|
+
setHeader(event, "Content-Type", "text/plain; charset=utf-8");
|
|
34
|
+
setHeader(event, "Cache-Control", "public, max-age=300");
|
|
35
|
+
return "User-agent: *\nAllow: /";
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { StorefrontFormularioAvaliacao } from 'godeep-types/types';
|
|
2
|
+
export declare const storeAvaliacoes: import("pinia").StoreDefinition<"avaliacoes", {
|
|
3
|
+
carregando: boolean;
|
|
4
|
+
formularioAvaliacao: StorefrontFormularioAvaliacao;
|
|
5
|
+
}, {
|
|
6
|
+
recuperarFormularioAvaliacao: (state: {
|
|
7
|
+
carregando: boolean;
|
|
8
|
+
formularioAvaliacao: {
|
|
9
|
+
idProduto?: number | undefined;
|
|
10
|
+
nota?: number | undefined;
|
|
11
|
+
nome?: string | undefined;
|
|
12
|
+
ip?: string | undefined;
|
|
13
|
+
email?: string | undefined;
|
|
14
|
+
titulo?: string | undefined;
|
|
15
|
+
comentario?: string | undefined;
|
|
16
|
+
cidade?: string | undefined;
|
|
17
|
+
dataAvaliacao?: string | undefined;
|
|
18
|
+
};
|
|
19
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
20
|
+
carregando: boolean;
|
|
21
|
+
formularioAvaliacao: StorefrontFormularioAvaliacao;
|
|
22
|
+
}>) => {
|
|
23
|
+
idProduto?: number | undefined;
|
|
24
|
+
nota?: number | undefined;
|
|
25
|
+
nome?: string | undefined;
|
|
26
|
+
ip?: string | undefined;
|
|
27
|
+
email?: string | undefined;
|
|
28
|
+
titulo?: string | undefined;
|
|
29
|
+
comentario?: string | undefined;
|
|
30
|
+
cidade?: string | undefined;
|
|
31
|
+
dataAvaliacao?: string | undefined;
|
|
32
|
+
};
|
|
33
|
+
formularioAvaliacaoCarregando: (state: {
|
|
34
|
+
carregando: boolean;
|
|
35
|
+
formularioAvaliacao: {
|
|
36
|
+
idProduto?: number | undefined;
|
|
37
|
+
nota?: number | undefined;
|
|
38
|
+
nome?: string | undefined;
|
|
39
|
+
ip?: string | undefined;
|
|
40
|
+
email?: string | undefined;
|
|
41
|
+
titulo?: string | undefined;
|
|
42
|
+
comentario?: string | undefined;
|
|
43
|
+
cidade?: string | undefined;
|
|
44
|
+
dataAvaliacao?: string | undefined;
|
|
45
|
+
};
|
|
46
|
+
} & import("pinia").PiniaCustomStateProperties<{
|
|
47
|
+
carregando: boolean;
|
|
48
|
+
formularioAvaliacao: StorefrontFormularioAvaliacao;
|
|
49
|
+
}>) => boolean;
|
|
50
|
+
}, {
|
|
51
|
+
resetarFormularioAvaliacao(): Promise<void>;
|
|
52
|
+
enviarAvaliacao(avaliacao: StorefrontFormularioAvaliacao): Promise<void>;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { traduzirEnviarAvaliacao } from "godeep-types/translate";
|
|
2
|
+
import { defineStore } from "pinia";
|
|
3
|
+
import { alerta } from "../utils/alerta.js";
|
|
4
|
+
const formularioAvaliacaoDefault = {
|
|
5
|
+
idProduto: 0,
|
|
6
|
+
nota: 0,
|
|
7
|
+
nome: "",
|
|
8
|
+
ip: "",
|
|
9
|
+
email: "",
|
|
10
|
+
titulo: "",
|
|
11
|
+
comentario: ""
|
|
12
|
+
};
|
|
13
|
+
export const storeAvaliacoes = defineStore("avaliacoes", {
|
|
14
|
+
state: () => ({
|
|
15
|
+
carregando: false,
|
|
16
|
+
formularioAvaliacao: formularioAvaliacaoDefault
|
|
17
|
+
}),
|
|
18
|
+
getters: {
|
|
19
|
+
recuperarFormularioAvaliacao: (state) => state.formularioAvaliacao,
|
|
20
|
+
formularioAvaliacaoCarregando: (state) => state.carregando
|
|
21
|
+
},
|
|
22
|
+
actions: {
|
|
23
|
+
async resetarFormularioAvaliacao() {
|
|
24
|
+
this.formularioAvaliacao = formularioAvaliacaoDefault;
|
|
25
|
+
this.carregando = false;
|
|
26
|
+
},
|
|
27
|
+
async enviarAvaliacao(avaliacao) {
|
|
28
|
+
try {
|
|
29
|
+
if (this.formularioAvaliacao.idProduto === 0 || this.formularioAvaliacao.nota === 0 || this.formularioAvaliacao.nome === "" || this.formularioAvaliacao.email === "" || this.formularioAvaliacao.titulo === "" || this.formularioAvaliacao.comentario === "") {
|
|
30
|
+
alerta.adicionar({
|
|
31
|
+
titulo: "Erro",
|
|
32
|
+
descricao: "Formul\xE1rio incompleto",
|
|
33
|
+
cor: "error",
|
|
34
|
+
variantes: ["dashed", "soft"]
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
this.carregando = true;
|
|
39
|
+
await $fetch("/api/front-api/comentarios", {
|
|
40
|
+
method: "POST",
|
|
41
|
+
body: traduzirEnviarAvaliacao(avaliacao)
|
|
42
|
+
});
|
|
43
|
+
this.carregando = false;
|
|
44
|
+
alerta.adicionar({
|
|
45
|
+
titulo: "Avalia\xE7\xE3o enviada com sucesso!",
|
|
46
|
+
descricao: "Sua avalia\xE7\xE3o ser\xE1 publicada ap\xF3s an\xE1lise.",
|
|
47
|
+
cor: "success",
|
|
48
|
+
variantes: ["dashed", "soft"]
|
|
49
|
+
});
|
|
50
|
+
this.resetarFormularioAvaliacao();
|
|
51
|
+
} catch {
|
|
52
|
+
this.carregando = false;
|
|
53
|
+
alerta.adicionar({
|
|
54
|
+
titulo: "Erro",
|
|
55
|
+
descricao: "Erro ao enviar avalia\xE7\xE3o",
|
|
56
|
+
cor: "error",
|
|
57
|
+
variantes: ["dashed", "soft"]
|
|
58
|
+
});
|
|
59
|
+
this.resetarFormularioAvaliacao();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { traduzirBanners } from "godeep-types/translate";
|
|
2
|
+
import { defineStore } from "pinia";
|
|
3
|
+
export const storeBanners = defineStore("banners", {
|
|
4
|
+
state: () => ({
|
|
5
|
+
banners: [],
|
|
6
|
+
bannersCache: {},
|
|
7
|
+
carregando: false
|
|
8
|
+
}),
|
|
9
|
+
getters: {
|
|
10
|
+
recuperarBanners: (state) => state.banners,
|
|
11
|
+
bannersCarregando: (state) => state.carregando
|
|
12
|
+
},
|
|
13
|
+
actions: {
|
|
14
|
+
async resetarBanners() {
|
|
15
|
+
this.banners = [];
|
|
16
|
+
this.carregando = false;
|
|
17
|
+
},
|
|
18
|
+
async buscarBanners(posicao = "", localizacao = "", local = "", slug = "", usarCache = true) {
|
|
19
|
+
try {
|
|
20
|
+
this.carregando = true;
|
|
21
|
+
const chaveCache = `${posicao}-${localizacao}-${local}-${slug}`;
|
|
22
|
+
console.log(`Chave do cache: ${chaveCache}`);
|
|
23
|
+
if (usarCache && this.bannersCache[chaveCache]) {
|
|
24
|
+
console.log(
|
|
25
|
+
`Cache encontrado para ${chaveCache}:`,
|
|
26
|
+
this.bannersCache[chaveCache].length
|
|
27
|
+
);
|
|
28
|
+
this.banners = this.bannersCache[chaveCache];
|
|
29
|
+
this.carregando = false;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
console.log(`Cache n\xE3o encontrado para ${chaveCache}, buscando...`);
|
|
33
|
+
const query = new URLSearchParams();
|
|
34
|
+
if (localizacao) {
|
|
35
|
+
query.append("localizacao", localizacao);
|
|
36
|
+
}
|
|
37
|
+
if (local) {
|
|
38
|
+
query.append("local", local);
|
|
39
|
+
}
|
|
40
|
+
if (posicao) {
|
|
41
|
+
query.append("posicao", posicao);
|
|
42
|
+
}
|
|
43
|
+
let url = `/api/front-api/banners`;
|
|
44
|
+
if (slug && slug !== "mock") {
|
|
45
|
+
url = `/mocks/${slug}.json`;
|
|
46
|
+
} else if (localizacao) {
|
|
47
|
+
url = `/mocks/${localizacao}.json`;
|
|
48
|
+
} else if (posicao) {
|
|
49
|
+
url = `/mocks/${posicao}.json`;
|
|
50
|
+
}
|
|
51
|
+
console.log(
|
|
52
|
+
`Buscando banners: slug=${slug}, localizacao=${localizacao}, posicao=${posicao}, url=${url}`
|
|
53
|
+
);
|
|
54
|
+
const resposta = await $fetch(url);
|
|
55
|
+
const dados = resposta?.dados ?? [];
|
|
56
|
+
console.log(`Dados recebidos:`, dados.length, dados);
|
|
57
|
+
const bannersTraduzidos = traduzirBanners(dados);
|
|
58
|
+
console.log(`Banners traduzidos:`, bannersTraduzidos.length);
|
|
59
|
+
this.banners = bannersTraduzidos;
|
|
60
|
+
if (usarCache) {
|
|
61
|
+
this.bannersCache[chaveCache] = bannersTraduzidos;
|
|
62
|
+
console.log(
|
|
63
|
+
`Banners salvos no cache com chave: ${chaveCache}, quantidade: ${bannersTraduzidos.length}`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
console.log(`Banners carregados para ${posicao}:`, this.banners.length);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error(`Erro ao buscar banners para ${posicao}:`, error);
|
|
69
|
+
this.banners = [];
|
|
70
|
+
} finally {
|
|
71
|
+
this.carregando = false;
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
recuperarBannersDoCache(posicao = "", localizacao = "", local = "", slug = "") {
|
|
75
|
+
const chaveCache = `${posicao}-${localizacao}-${local}-${slug}`;
|
|
76
|
+
console.log(
|
|
77
|
+
`Recuperando do cache: chave=${chaveCache}, cache keys:`,
|
|
78
|
+
Object.keys(this.bannersCache)
|
|
79
|
+
);
|
|
80
|
+
const resultado = this.bannersCache[chaveCache];
|
|
81
|
+
console.log(`Resultado do cache:`, resultado?.length ?? 0);
|
|
82
|
+
return resultado;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
persist: {
|
|
86
|
+
storage: piniaPluginPersistedstate.sessionStorage()
|
|
87
|
+
}
|
|
88
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StorefrontCardItem } from 'godeep-types/types';
|
|
2
|
+
export declare const storeBusca: import("pinia").StoreDefinition<"busca", {
|
|
3
|
+
resultados: StorefrontCardItem[];
|
|
4
|
+
carregando: boolean;
|
|
5
|
+
mostrarResultados: boolean;
|
|
6
|
+
abrirResultados: boolean;
|
|
7
|
+
maisBuscados: boolean;
|
|
8
|
+
}, {}, {}>;
|