Compare commits
29 Commits
0.1.5
...
18507bc337
| Author | SHA1 | Date | |
|---|---|---|---|
| 18507bc337 | |||
| 78923ddb6e | |||
| 1d37ce42dc | |||
| 04509006a4 | |||
| 2ba8004240 | |||
| 339ac6727f | |||
| c95279d96b | |||
|
|
7f73251c5e | ||
|
|
3112c82bb2 | ||
|
|
6088623415 | ||
|
|
7731b2fbd6 | ||
|
|
d4421aece4 | ||
|
|
1c8638b8d4 | ||
|
|
72d81bdf47 | ||
| 9e78646d20 | |||
| 0ba348cc64 | |||
| 4e79ecd56b | |||
| 4a67f85dcb | |||
| 173cf3771b | |||
| 173ddfd05f | |||
| c593dd0273 | |||
| c8460c8e81 | |||
|
|
3fdfc3c883 | ||
|
|
460e213e0e | ||
|
|
e192c3778a | ||
|
|
5c594ea563 | ||
| f22fcb6f16 | |||
| 1b84c5419f | |||
| 7fe137ce4f |
2
.env.example
Normal file
2
.env.example
Normal file
@@ -0,0 +1,2 @@
|
||||
VITE_API_IMPLEMENTATION=django
|
||||
VITE_DJANGO_BASE_URL=http://localhost:7000
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@ node_modules
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
.env
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
|
||||
81
AGENTS.md
Normal file
81
AGENTS.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# Don Confiao - Frontend
|
||||
|
||||
## Tech Stack
|
||||
- **Framework:** Vue 3 (Composition API)
|
||||
- **UI Library:** Vuetify 3
|
||||
- **Routing:** Vue Router 4 (auto-routes con `unplugin-vue-router`)
|
||||
- **State:** Pinia
|
||||
- **HTTP:** Axios
|
||||
- **Build:** Vite
|
||||
- **Linting:** ESLint
|
||||
|
||||
## Project Structure
|
||||
```
|
||||
src/
|
||||
├── assets/ # Imágenes, iconos estáticos
|
||||
├── components/ # Componentes Vue reutilizables
|
||||
├── layouts/ # Layouts de página
|
||||
├── pages/ # Vistas (auto-routed desde文件名)
|
||||
├── plugins/ # Configuración de Vuetify, etc.
|
||||
├── router/ # Configuración de rutas
|
||||
├── services/ # API services (auth.js, etc.)
|
||||
├── stores/ # Pinia stores
|
||||
└── styles/ # SCSS settings
|
||||
```
|
||||
|
||||
## Important Conventions
|
||||
|
||||
### Auto-imports
|
||||
- Componentes en `src/components/` se auto-importan por nombre
|
||||
- Los archivos en `src/pages/*.vue` se routing automáticamente via `unplugin-vue-router`
|
||||
- Alias `@` = `src/`
|
||||
|
||||
### Pages (CRITICAL)
|
||||
**Siempre importar componentes en los archivos de página:**
|
||||
```vue
|
||||
<template>
|
||||
<MiComponente />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import MiComponente from '@/components/MiComponente.vue';
|
||||
</script>
|
||||
```
|
||||
|
||||
### Componentes
|
||||
- Usar Composition API (`<script setup>` o `export default { }`)
|
||||
- Naming: PascalCase (ej: `LoginDialog.vue`, `CartGrid.vue`)
|
||||
- Componentes de página van en `pages/`, componentes reutilizables en `components/`
|
||||
|
||||
### Servicios API
|
||||
- Ubicación: `src/services/`
|
||||
- Usar Axios para HTTP requests
|
||||
- JWT tokens en localStorage (`access_token`, `refresh_token`)
|
||||
|
||||
### Routing
|
||||
- Rutas automáticas basadas en archivos en `src/pages/`
|
||||
- No requiere configuración manual en `router/index.js`
|
||||
|
||||
## Environment Variables
|
||||
- `VITE_DJANGO_BASE_URL` - URL del backend Django
|
||||
|
||||
## Commands
|
||||
```bash
|
||||
npm run dev # Desarrollo (puerto 3000)
|
||||
npm run build # Producción
|
||||
npm run preview # Preview build
|
||||
npm run lint # ESLint fix
|
||||
```
|
||||
|
||||
## Common Issues
|
||||
1. **Página en blanco:** Verificar que los componentes en `src/pages/*.vue` tengan import explícito
|
||||
2. **Errores de lint:** Ejecutar `npm run lint`
|
||||
|
||||
## Git Commits
|
||||
**Antes de hacer commit:**
|
||||
1. Pedir permiso al usuario
|
||||
2. Mostrar resumen de los cambios que se incluirán
|
||||
|
||||
**Formato de mensajes:**
|
||||
- Usar prefijo `#<numero>` para referenciar el issue (ej: `#28 feat: add login` donde #28 es el número del issue en GitHub/GitLab)
|
||||
- Prefijos válidos: `feat`, `fix`, `chore`, `docs`, `refactor`, `style`
|
||||
636
package-lock.json
generated
636
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@mdi/font": "7.4.47",
|
||||
"axios": "^1.13.5",
|
||||
"core-js": "^3.37.1",
|
||||
"roboto-fontface": "*",
|
||||
"vee-validate": "^4.14.6",
|
||||
|
||||
1
src/assets/icons/tryton-icon.svg
Normal file
1
src/assets/icons/tryton-icon.svg
Normal file
@@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="256" height="256" version="1.0"><path d="M256 196.25c0 40.122-21.534 60.038-64.603 59.747H67.495C22.498 255.997 0 236.663 0 197.994V60.184C0 20.06 22.016 0 66.049 0h124.384C234.144 0 256 20.206 256 60.62v135.63" style="text-align:start;line-height:125%;-inkscape-font-specification:Kimberley" font-size="108.872" font-weight="400" fill="#1b2019" font-family="Kimberley"/><path d="M19.006 169.515c5.949-3.124 17.076 1.966 22.115 10.12 4.518 7.31 27.406 14.114 35.516 10.558 5.412-2.372 6.779-5.378 7.202-15.844.798-19.685-3.636-35.098-17.99-62.536-7.205-13.77-14.753-29-16.775-33.835C47.052 73.14 41.601 64.6 36.961 59c-9.876-11.91-10.183-15.164-2.078-22.074C47.02 26.581 67.52 43.327 63.095 59.97c-2.178 8.191 2.003 20.14 15.85 45.295 16.431 29.85 33.084 41.94 43.03 31.243 2.57-2.763 5.759-18.178 8.698-42.04 4.421-35.889 4.399-38.037-.47-45.252-8.418-12.475-.48-25.42 12.84-20.943 13.43 4.513 22.192 22.778 13.775 28.714-3.735 2.633-4.942 10.29-6.636 42.097-2.173 40.785-.53 51.7 8.609 57.187 8.121 4.876 10.946 3.885 28.067-9.889 18.167-14.612 25.636-24.069 26.115-33.067.446-8.37 5.992-12.847 14.832-11.972 5.635.56 8.15 2.41 11.3 8.312 6.431 12.053 4.589 19.71-5.212 21.667-7.987 1.592-21.708 19.27-42.815 55.16-22.288 37.897-27.173 41.845-52.152 42.147-10.268.123-24.634-3.295-58.453-13.914-24.663-7.746-48.043-14.468-51.957-14.943-14.142-1.708-21.187-24.12-9.51-30.257z" fill="#ededed"/></svg>
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
@@ -16,7 +16,7 @@
|
||||
required
|
||||
class="mr-4"
|
||||
></v-autocomplete>
|
||||
<v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>
|
||||
<!-- <v-btn color="primary" @click="openModal">Agregar Cliente</v-btn> -->
|
||||
<CreateCustomerModal ref="customerModal" @customerCreated="handleNewCustomer"/>
|
||||
</v-col>
|
||||
<v-col lg="4">
|
||||
|
||||
70
src/components/Login.vue
Normal file
70
src/components/Login.vue
Normal file
@@ -0,0 +1,70 @@
|
||||
<template>
|
||||
<h1>Login</h1>
|
||||
|
||||
<v-form ref="loginForm" @submit.prevent="onSubmit">
|
||||
<v-text-field
|
||||
v-model="username"
|
||||
label="Usuario"
|
||||
:rules="[requiredRule]"
|
||||
required
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="password"
|
||||
label="Contraseña"
|
||||
type="password"
|
||||
:rules="[requiredRule]"
|
||||
required
|
||||
/>
|
||||
|
||||
<v-btn type="submit" color="primary">Entrar</v-btn>
|
||||
|
||||
<v-alert v-if="error" type="error" class="mt-2">{{ error }}</v-alert>
|
||||
</v-form>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AuthService from '@/services/auth';
|
||||
|
||||
export default {
|
||||
name: 'DonConfiao',
|
||||
|
||||
data() {
|
||||
return {
|
||||
username: '',
|
||||
password: '',
|
||||
error: '',
|
||||
};
|
||||
},
|
||||
|
||||
methods: {
|
||||
requiredRule(value) {
|
||||
return !!value || 'Este campo es obligatorio';
|
||||
},
|
||||
|
||||
async onSubmit() {
|
||||
this.error = '';
|
||||
|
||||
const form = this.$refs.loginForm;
|
||||
const isValid = await form.validate();
|
||||
|
||||
if (!isValid) return;
|
||||
|
||||
if (!this.username || !this.password) {
|
||||
this.error = 'Usuario y contraseña son obligatorios';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await AuthService.login({
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
});
|
||||
this.$router.push({ path: '/' });
|
||||
} catch (e) {
|
||||
const msg = e?.response?.data?.message ?? e.message;
|
||||
this.error = msg ?? 'Error al iniciar sesión';
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
69
src/components/LoginDialog.vue
Normal file
69
src/components/LoginDialog.vue
Normal file
@@ -0,0 +1,69 @@
|
||||
<template>
|
||||
<v-dialog v-model="show" max-width="400">
|
||||
<v-card>
|
||||
<v-card-title class="headline">Iniciar sesión</v-card-title>
|
||||
<v-card-text>
|
||||
<v-form ref="form" @submit.prevent="onSubmit">
|
||||
<v-text-field
|
||||
v-model="username"
|
||||
label="Usuario"
|
||||
:rules="[required]"
|
||||
required
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="password"
|
||||
label="Contraseña"
|
||||
type="password"
|
||||
:rules="[required]"
|
||||
required
|
||||
/>
|
||||
<v-alert v-if="error" type="error" class="mt-2">{{ error }}</v-alert>
|
||||
</v-form>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions>
|
||||
<v-spacer />
|
||||
<v-btn text @click="show = false">Cancelar</v-btn>
|
||||
<v-btn color="primary" @click="onSubmit">Entrar</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AuthService from '@/services/auth';
|
||||
|
||||
export default {
|
||||
name: 'LoginDialog',
|
||||
data: () => ({
|
||||
show: false,
|
||||
username: '',
|
||||
password: '',
|
||||
error: '',
|
||||
}),
|
||||
methods: {
|
||||
required(v) {
|
||||
return !!v || 'Campo obligatorio';
|
||||
},
|
||||
async onSubmit() {
|
||||
this.error = '';
|
||||
const form = this.$refs.form;
|
||||
if (!(await form.validate())) return;
|
||||
|
||||
try {
|
||||
await AuthService.login({
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
});
|
||||
this.show = false;
|
||||
this.$emit('login-success');
|
||||
} catch (e) {
|
||||
this.error = e.message ?? 'Error al iniciar sesión';
|
||||
}
|
||||
},
|
||||
open() {
|
||||
this.show = true;
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
32
src/components/Logout.vue
Normal file
32
src/components/Logout.vue
Normal file
@@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<v-container class="d-flex flex-column align-center justify-center" style="height: 100vh;">
|
||||
<v-progress-circular indeterminate color="primary" />
|
||||
<p class="mt-4">Cerrando sesión…</p>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import AuthService from '@/services/auth';
|
||||
|
||||
export default {
|
||||
name: 'DonConfiao',
|
||||
mounted() {
|
||||
this.logout();
|
||||
},
|
||||
methods: {
|
||||
logout() {
|
||||
AuthService.logout();
|
||||
this.$router.push({
|
||||
path: '/autenticarse'
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
p {
|
||||
font-size: 1.1rem;
|
||||
color: #555;
|
||||
}
|
||||
</style>
|
||||
@@ -3,11 +3,22 @@
|
||||
<v-app-bar-nav-icon variant="text" @click.stop="drawer = !drawer"></v-app-bar-nav-icon>
|
||||
<v-toolbar-title>Menu</v-toolbar-title>
|
||||
<v-spacer></v-spacer>
|
||||
<template v-if="$vuetify.display.mdAndUp">
|
||||
<v-btn icon="mdi-magnify" variant="text"></v-btn>
|
||||
<v-btn icon="mdi-filter" variant="text"></v-btn>
|
||||
</template>
|
||||
<v-btn icon="mdi-dots-vertical" variant="text"></v-btn>
|
||||
<v-btn
|
||||
v-if="!isAuthenticated"
|
||||
prepend-icon="mdi-login"
|
||||
variant="text"
|
||||
@click="navigate('/autenticarse')"
|
||||
>
|
||||
Login
|
||||
</v-btn>
|
||||
<v-btn
|
||||
v-else
|
||||
prepend-icon="mdi-logout"
|
||||
variant="text"
|
||||
@click="logout"
|
||||
>
|
||||
Logout
|
||||
</v-btn>
|
||||
</v-app-bar>
|
||||
<v-navigation-drawer v-model="drawer"
|
||||
:location="$vuetify.display.mobile ? 'bottom' : undefined"
|
||||
@@ -40,12 +51,15 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import trytonIcon from '../assets/icons/tryton-icon.svg';
|
||||
import AuthService from '@/services/auth';
|
||||
export default {
|
||||
name: 'NavBar',
|
||||
data: () => ({
|
||||
drawer: false,
|
||||
group: null,
|
||||
showAdminMenu: false,
|
||||
isAuthenticated: false,
|
||||
menuItems: [
|
||||
{ title: 'Inicio', route: '/', icon: 'mdi-home'},
|
||||
{ title: 'Comprar', route:'/comprar', icon: 'mdi-cart'},
|
||||
@@ -55,14 +69,26 @@
|
||||
{ title: 'Cuadres de tarro', route: '/cuadres_de_tarro', icon: 'mdi-chart-bar'},
|
||||
{ title: 'CSV Tryton', route: '/ventas_para_tryton', icon: 'mdi-file-table'},
|
||||
{ title: 'Compra adm', route: '/compra_admin', icon: 'mdi-cart'},
|
||||
{ title: 'Actualizar Productos De Tryton', route: '/sincronizar_productos_tryton', icon: 'trytonIcon'},
|
||||
{ title: 'Actualizar Clientes De Tryton', route: '/sincronizar_clientes_tryton', icon: 'trytonIcon'},
|
||||
{ title: 'Actualizar Ventas Tryton', route: '/sincronizar_ventas_tryton', icon: 'trytonIcon'}
|
||||
],
|
||||
}),
|
||||
mounted() {
|
||||
this.checkAuth();
|
||||
},
|
||||
watch: {
|
||||
group () {
|
||||
this.drawer = false
|
||||
},
|
||||
$route() {
|
||||
this.checkAuth();
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
checkAuth() {
|
||||
this.isAuthenticated = AuthService.isAuthenticated();
|
||||
},
|
||||
navigate(route) {
|
||||
this.$router.push(route);
|
||||
},
|
||||
@@ -73,6 +99,11 @@
|
||||
toggleAdminMenu() {
|
||||
this.showAdminMenu = !this.showAdminMenu;
|
||||
},
|
||||
logout() {
|
||||
AuthService.logout();
|
||||
this.isAuthenticated = false;
|
||||
this.$router.push('/');
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
required
|
||||
class="mr-4"
|
||||
></v-autocomplete>
|
||||
<v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>
|
||||
<!--<v-btn color="primary" @click="openModal">Agregar Cliente</v-btn>-->
|
||||
<CreateCustomerModal ref="customerModal" @customerCreated="handleNewCustomer"/>
|
||||
</v-col>
|
||||
<v-col lg="4">
|
||||
|
||||
202
src/components/catalog/Card.vue
Normal file
202
src/components/catalog/Card.vue
Normal file
@@ -0,0 +1,202 @@
|
||||
<template>
|
||||
<v-card class="product-card">
|
||||
<v-row no-gutters align="center" class="w-100 py-3 px-2">
|
||||
<v-col cols="12" md="3" class="d-flex justify-center">
|
||||
<v-img :src="product.img" class="product-img" contain></v-img>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" md="5">
|
||||
<v-card-title class="product-name">{{ product.name }}</v-card-title>
|
||||
<v-card-subtitle class="product-description">{{ product.description }}</v-card-subtitle>
|
||||
<div class="prices mt-3">
|
||||
<div class="price-unit">
|
||||
<span class="price-label">Precio unitario</span>
|
||||
<span class="price-value">{{ currency(product.price) }}</span>
|
||||
</div>
|
||||
<div class="price-total">
|
||||
<span class="price-label">Precio total</span>
|
||||
<span class="price-value total">{{ currency(product.price * product.quantity) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" md="4" class="d-flex align-center justify-md-end justify-center mt-3 mt-md-0">
|
||||
<div class="quantity-controls">
|
||||
<v-btn icon small class="qty-btn" @click="decrease(product)">
|
||||
<v-icon small>mdi-minus</v-icon>
|
||||
</v-btn>
|
||||
<v-text-field
|
||||
v-model.number="product.quantity"
|
||||
type="number"
|
||||
min="0"
|
||||
class="quantity-input"
|
||||
dense
|
||||
outlined
|
||||
hide-details
|
||||
aria-label="Cantidad"
|
||||
@input="handleQuantityChange"
|
||||
/>
|
||||
<v-btn icon small class="qty-btn qty-btn-add" @click="handleIncrease">
|
||||
<v-icon small>mdi-plus</v-icon>
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
product: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
increase: {
|
||||
type: Function,
|
||||
required: true
|
||||
},
|
||||
decrease: {
|
||||
type: Function,
|
||||
required: true
|
||||
},
|
||||
currency: {
|
||||
type: Function,
|
||||
required: true
|
||||
},
|
||||
updateQuantity: {
|
||||
type: Function,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleIncrease() {
|
||||
this.increase(this.product);
|
||||
this.$emit('add-to-cart', this.product);
|
||||
},
|
||||
handleQuantityChange(value) {
|
||||
this.updateQuantity(this.product);
|
||||
if (this.product.quantity > 0) {
|
||||
this.$emit('add-to-cart', this.product);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.product-card {
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 12px;
|
||||
background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
.product-card:hover {
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
||||
transform: translateY(-2px);
|
||||
border-color: #bdbdbd;
|
||||
}
|
||||
.product-img {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
border-radius: 10px;
|
||||
object-fit: cover;
|
||||
background: #fff;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
.product-name {
|
||||
font-size: 1.1rem;
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
line-height: 1.3;
|
||||
padding: 0 0 4px 0;
|
||||
}
|
||||
.product-description {
|
||||
font-size: 0.85rem;
|
||||
color: #7f8c8d;
|
||||
line-height: 1.4;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
.prices {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
}
|
||||
.price-unit, .price-total {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.price-label {
|
||||
font-size: 0.75rem;
|
||||
color: #95a5a6;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.5px;
|
||||
}
|
||||
.price-value {
|
||||
font-size: 0.95rem;
|
||||
font-weight: 600;
|
||||
color: #2c3e50;
|
||||
}
|
||||
.price-value.total {
|
||||
color: #27ae60;
|
||||
font-size: 1.1rem;
|
||||
}
|
||||
.quantity-controls {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
background: #f5f5f5;
|
||||
border-radius: 25px;
|
||||
padding: 4px;
|
||||
}
|
||||
.quantity-input {
|
||||
max-width: 70px;
|
||||
}
|
||||
.quantity-input input {
|
||||
text-align: center;
|
||||
font-weight: 600;
|
||||
}
|
||||
.qty-btn {
|
||||
min-width: 32px !important;
|
||||
height: 32px !important;
|
||||
border-radius: 50% !important;
|
||||
background: #fff;
|
||||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.qty-btn:hover {
|
||||
background: #e0e0e0;
|
||||
}
|
||||
.qty-btn-add {
|
||||
background: #27ae60;
|
||||
color: white;
|
||||
}
|
||||
.qty-btn-add:hover {
|
||||
background: #219a52 !important;
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
.product-img {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.product-card {
|
||||
border-radius: 8px;
|
||||
}
|
||||
.product-img {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
}
|
||||
.product-name {
|
||||
font-size: 1rem;
|
||||
text-align: center;
|
||||
}
|
||||
.prices {
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
141
src/components/catalog/Cart.vue
Normal file
141
src/components/catalog/Cart.vue
Normal file
@@ -0,0 +1,141 @@
|
||||
<template>
|
||||
<v-card>
|
||||
<v-card-title class="d-flex align-center">
|
||||
<v-icon class="mr-2">mdi-cart</v-icon>
|
||||
Carrito
|
||||
<v-chip v-if="cartCount" color="primary" class="ml-2">{{ cartCount }}</v-chip>
|
||||
</v-card-title>
|
||||
|
||||
<v-divider></v-divider>
|
||||
|
||||
<v-card-text v-if="cartItems.length === 0" class="text-center grey--text">
|
||||
El carrito está vacío
|
||||
</v-card-text>
|
||||
|
||||
<v-list v-else density="compact" max-height="300" class="overflow-y-auto">
|
||||
<v-list-item v-for="item in cartItems" :key="item.id">
|
||||
<template v-slot:prepend>
|
||||
<v-avatar size="40" rounded>
|
||||
<v-img :src="item.img" cover></v-img>
|
||||
</v-avatar>
|
||||
</template>
|
||||
|
||||
<v-list-item-title>{{ item.name }}</v-list-item-title>
|
||||
<v-list-item-subtitle class="d-flex align-center">
|
||||
<div class="quantity-controls">
|
||||
<v-btn small text class="qty-btn" @click="decreaseQuantity(item.id)"
|
||||
><v-icon small>mdi-minus</v-icon></v-btn
|
||||
>
|
||||
<v-text-field
|
||||
:model-value="item.quantity"
|
||||
@update:model-value="updateQuantity(item.id, $event)"
|
||||
type="number"
|
||||
min="1"
|
||||
density="compact"
|
||||
variant="outlined"
|
||||
hide-details
|
||||
class="qty-input"
|
||||
/>
|
||||
<v-btn small text class="qty-btn" @click="increaseQuantity(item.id)"
|
||||
><v-icon small>mdi-plus</v-icon></v-btn
|
||||
>
|
||||
</div>
|
||||
<span class="ml-2">x {{ currency(item.price) }}</span>
|
||||
</v-list-item-subtitle>
|
||||
|
||||
<template v-slot:append>
|
||||
<div class="d-flex align-center">
|
||||
<strong>{{ currency(item.price * item.quantity) }}</strong>
|
||||
<v-btn
|
||||
icon="mdi-delete"
|
||||
size="small"
|
||||
variant="text"
|
||||
color="red"
|
||||
class="ml-2"
|
||||
@click="$emit('remove', item.id)"
|
||||
></v-btn>
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</v-list>
|
||||
|
||||
<v-divider v-if="cartItems.length > 0"></v-divider>
|
||||
|
||||
<v-card-text v-if="cartItems.length > 0">
|
||||
<div class="d-flex justify-space-between align-center">
|
||||
<strong>Total:</strong>
|
||||
<strong class="text-h6">{{ currency(cartTotal) }}</strong>
|
||||
</div>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions v-if="cartItems.length > 0">
|
||||
<v-btn color="primary" block @click="$emit('checkout')">
|
||||
Finalizar Compra
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'Cart',
|
||||
props: {
|
||||
cartItems: {
|
||||
type: Array,
|
||||
default: () => []
|
||||
},
|
||||
currency: {
|
||||
type: Function,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
emits: ['remove', 'checkout', 'update-quantity'],
|
||||
computed: {
|
||||
cartCount() {
|
||||
return this.cartItems.reduce((sum, item) => sum + item.quantity, 0);
|
||||
},
|
||||
cartTotal() {
|
||||
return this.cartItems.reduce((sum, item) => sum + (item.price * item.quantity), 0);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
updateQuantity(itemId, newQuantity) {
|
||||
const qty = parseInt(newQuantity) || 1;
|
||||
this.$emit('update-quantity', { itemId, quantity: qty });
|
||||
},
|
||||
increaseQuantity(itemId) {
|
||||
const item = this.cartItems.find(i => i.id === itemId);
|
||||
if (item) {
|
||||
this.$emit('update-quantity', { itemId, quantity: item.quantity + 1 });
|
||||
}
|
||||
},
|
||||
decreaseQuantity(itemId) {
|
||||
const item = this.cartItems.find(i => i.id === itemId);
|
||||
if (item && item.quantity > 1) {
|
||||
this.$emit('update-quantity', { itemId, quantity: item.quantity - 1 });
|
||||
} else if (item) {
|
||||
this.$emit('remove', itemId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.qty-input {
|
||||
width: 70px;
|
||||
}
|
||||
.qty-input input {
|
||||
text-align: center;
|
||||
}
|
||||
.quantity-controls {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
.qty-btn {
|
||||
min-width: 28px !important;
|
||||
height: 28px !important;
|
||||
border-radius: 14px !important;
|
||||
}
|
||||
</style>
|
||||
7
src/pages/autenticarse.vue
Normal file
7
src/pages/autenticarse.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<Login />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
//
|
||||
</script>
|
||||
181
src/pages/catalog.vue
Normal file
181
src/pages/catalog.vue
Normal file
@@ -0,0 +1,181 @@
|
||||
<template>
|
||||
<v-container fluid>
|
||||
<v-row>
|
||||
<v-col cols="12" md="9">
|
||||
<v-card-title>
|
||||
<span class="headline">Catálogo</span>
|
||||
</v-card-title>
|
||||
<v-list-item v-for="item in items" :key="item.id" class="catalog-item">
|
||||
<Card :product="item" :increase="increase" :decrease="decrease" :currency="currency" :updateQuantity="updateQuantity" @add-to-cart="addToCart"/>
|
||||
</v-list-item>
|
||||
</v-col>
|
||||
|
||||
<v-col cols="12" md="3">
|
||||
<div class="cart-sidebar">
|
||||
<Cart
|
||||
:cart-items="cartItems"
|
||||
:currency="currency"
|
||||
@remove="removeFromCart"
|
||||
@checkout="goToCheckout"
|
||||
@update-quantity="updateCartQuantity"
|
||||
/>
|
||||
</div>
|
||||
</v-col>
|
||||
</v-row>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Card from '@/components/catalog/Card.vue';
|
||||
import Cart from '@/components/catalog/Cart.vue';
|
||||
import { useCartStore } from '@/stores/cart';
|
||||
import { inject } from 'vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
Card,
|
||||
Cart
|
||||
},
|
||||
setup() {
|
||||
const cartStore = useCartStore();
|
||||
return { cartStore };
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
api: inject('api'),
|
||||
items: [],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
cartItems: {
|
||||
get() {
|
||||
return this.cartStore.items;
|
||||
},
|
||||
set(value) {
|
||||
this.cartStore.items = value;
|
||||
}
|
||||
},
|
||||
cartCount() {
|
||||
return this.cartStore.cartCount;
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.fetchProducts();
|
||||
},
|
||||
methods: {
|
||||
fetchProducts() {
|
||||
this.api.getProducts()
|
||||
.then(data => {
|
||||
this.items = data.map(product => ({
|
||||
...product,
|
||||
quantity: 0,
|
||||
img: product.img || `https://picsum.photos/300/200?random=${product.id}`
|
||||
}));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
increase(item) {
|
||||
item.quantity = Number(item.quantity) + 1;
|
||||
this.addToCart(item);
|
||||
},
|
||||
decrease(item) {
|
||||
item.quantity = Math.max(0, Number(item.quantity) - 1);
|
||||
if (item.quantity === 0) {
|
||||
this.removeFromCart(item.id);
|
||||
} else {
|
||||
this.addToCart(item);
|
||||
}
|
||||
},
|
||||
updateQuantity(item) {
|
||||
if (item.quantity > 0) {
|
||||
this.addToCart(item);
|
||||
} else {
|
||||
this.removeFromCart(item.id);
|
||||
}
|
||||
},
|
||||
addToCart(item) {
|
||||
if (item.quantity <= 0) return;
|
||||
this.cartStore.addItem(item);
|
||||
},
|
||||
removeFromCart(itemId) {
|
||||
this.cartStore.removeItem(itemId);
|
||||
const item = this.items.find(i => i.id === itemId);
|
||||
if (item) {
|
||||
item.quantity = 0;
|
||||
}
|
||||
},
|
||||
updateCartQuantity({ itemId, quantity }) {
|
||||
this.cartStore.updateQuantity({ itemId, quantity });
|
||||
const productItem = this.items.find(i => i.id === itemId);
|
||||
if (productItem) {
|
||||
productItem.quantity = quantity;
|
||||
}
|
||||
},
|
||||
goToCheckout() {
|
||||
this.$router.push('/comprar');
|
||||
},
|
||||
currency(val) {
|
||||
if (val == null) return '-';
|
||||
return new Intl.NumberFormat('es-CO', { style: 'currency', currency: 'COP', minimumFractionDigits: 0 }).format(val);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.headline {
|
||||
font-weight: bold;
|
||||
}
|
||||
.catalog-item {
|
||||
padding-top: 12px;
|
||||
padding-bottom: 12px;
|
||||
}
|
||||
.cart-sidebar {
|
||||
position: sticky;
|
||||
top: 80px;
|
||||
}
|
||||
.product-img {
|
||||
width: 150px;
|
||||
height: 100px;
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
}
|
||||
.quantity-controls {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 8px;
|
||||
}
|
||||
.prices .price-line {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.quantity-input {
|
||||
max-width: 90px;
|
||||
}
|
||||
.quantity-input input {
|
||||
text-align: center;
|
||||
}
|
||||
.qty-btn {
|
||||
min-width: 36px !important;
|
||||
height: 36px !important;
|
||||
border-radius: 18px !important;
|
||||
}
|
||||
@media (max-width: 960px) {
|
||||
.cart-sidebar {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: auto;
|
||||
z-index: 100;
|
||||
}
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.product-img {
|
||||
width: 120px;
|
||||
height: 80px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
7
src/pages/salir.vue
Normal file
7
src/pages/salir.vue
Normal file
@@ -0,0 +1,7 @@
|
||||
<template>
|
||||
<Logout />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
//
|
||||
</script>
|
||||
79
src/pages/sincronizar_clientes_tryton.vue
Normal file
79
src/pages/sincronizar_clientes_tryton.vue
Normal file
@@ -0,0 +1,79 @@
|
||||
<template>
|
||||
<div>
|
||||
<CodeDialog @code-verified="(verified) => showComponent = verified"/>
|
||||
</div>
|
||||
<v-container class="fill-height d-flex align-center justify-center">
|
||||
<v-card class="pa-6" max-width="600" elevation="4">
|
||||
<v-card-title class="text-h5 font-weight-bold text-center">
|
||||
🔄 Sincronización de Clientes
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<p>
|
||||
Esta acción sincronizará los <strong>clientes</strong> desde el sistema
|
||||
<strong>Tryton</strong> hacia la plataforma.
|
||||
</p>
|
||||
<v-alert type="warning" dense border="start" border-color="warning">
|
||||
<strong>Advertencia:</strong> Este proceso podría tardar varios minutos
|
||||
y reemplazar datos existentes en la plataforma.
|
||||
Asegúrese de que la información en Tryton esté actualizada antes de
|
||||
continuar.
|
||||
</v-alert>
|
||||
<p class="mt-4">
|
||||
Durante la sincronización, no se podrán modificar productos en la
|
||||
plataforma para evitar conflictos.
|
||||
</p>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions class="justify-center">
|
||||
<v-btn color="primary" @click="startSync">
|
||||
Iniciar Sincronización
|
||||
</v-btn>
|
||||
<v-btn text @click="$router.push('/')">
|
||||
Cancelar
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
|
||||
|
||||
<v-data-table :items="checked_tryton_parties"></v-data-table>
|
||||
<v-data-table :items="created_customers"></v-data-table>
|
||||
<v-data-table :items="failed_parties"></v-data-table>
|
||||
<v-data-table :items="untouched_customers"></v-data-table>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CodeDialog from '../components/CodeDialog.vue'
|
||||
import { inject } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'CustomersFromTryton',
|
||||
data() {
|
||||
return {
|
||||
api: inject('api'),
|
||||
checked_tryton_parties: [],
|
||||
created_customers: [],
|
||||
failed_parties: [],
|
||||
untouched_customers: [],
|
||||
updated_customers: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
startSync() {
|
||||
this.api.getCustomersFromTryton()
|
||||
.then(response => {
|
||||
// Manejar la respuesta exitosa
|
||||
this.checked_tryton_parties = response.checked_tryton_parties.map(id => ({ id }));
|
||||
this.created_customers = response.created_customers.map(id => ({ id }));
|
||||
this.failed_parties = response.failed_parties.map(id => ({ id }));
|
||||
this.untouched_customers = response.untouched_customers.map(id => ({ id }));
|
||||
})
|
||||
.catch(error => {
|
||||
// Manejar el error
|
||||
console.error("Error al sincronizar clientes:", error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
60
src/pages/sincronizar_productos_tryton.vue
Normal file
60
src/pages/sincronizar_productos_tryton.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<div>
|
||||
<CodeDialog @code-verified="(verified) => showComponent = verified"/>
|
||||
</div>
|
||||
<v-container class="fill-height d-flex align-center justify-center">
|
||||
<v-card class="pa-6" max-width="600" elevation="4">
|
||||
<v-card-title class="text-h5 font-weight-bold text-center">
|
||||
🔄 Sincronización de Productos
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<p>
|
||||
Esta acción sincronizará los <strong>productos</strong> desde el sistema
|
||||
<strong>Tryton</strong> hacia la plataforma.
|
||||
</p>
|
||||
<v-alert type="warning" dense border="start" border-color="warning">
|
||||
<strong>Advertencia:</strong> Este proceso podría tardar varios minutos
|
||||
y reemplazar datos existentes en la plataforma.
|
||||
Asegúrese de que la información en Tryton esté actualizada antes de
|
||||
continuar.
|
||||
</v-alert>
|
||||
<p class="mt-4">
|
||||
Durante la sincronización, no se podrán modificar productos en la
|
||||
plataforma para evitar conflictos.
|
||||
</p>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions class="justify-center">
|
||||
<v-btn color="primary" @click="startSync">
|
||||
Iniciar Sincronización
|
||||
</v-btn>
|
||||
<v-btn text @click="$router.push('/')">
|
||||
Cancelar
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
<v-data-table :items="productos_tryton"></v-data-table>
|
||||
</v-container>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CodeDialog from '../components/CodeDialog.vue'
|
||||
import { inject } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'ProductsFromTryton',
|
||||
data() {
|
||||
return {
|
||||
api: inject('api'),
|
||||
productos_tryton: [{}],
|
||||
showComponent: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
startSync() {
|
||||
this.productos_tryton = this.api.getProductsFromTryton()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
63
src/pages/sincronizar_ventas_tryton.vue
Normal file
63
src/pages/sincronizar_ventas_tryton.vue
Normal file
@@ -0,0 +1,63 @@
|
||||
<template>
|
||||
<div>
|
||||
<CodeDialog @code-verified="(verified) => showComponent = verified"/>
|
||||
</div>
|
||||
<v-container class="fill-height d-flex align-center justify-center">
|
||||
<v-card class="pa-6" max-width="600" elevation="4">
|
||||
<v-card-title class="text-h5 font-weight-bold text-center">
|
||||
🔄 Sincronización de Ventas
|
||||
</v-card-title>
|
||||
|
||||
<v-card-text>
|
||||
<p>
|
||||
Esta acción sincronizará las <strong>ventas</strong> desde el sistema
|
||||
<strong>Tryton</strong> hacia la plataforma.
|
||||
</p>
|
||||
<v-alert type="warning" dense border="start" border-color="warning">
|
||||
<strong>Advertencia:</strong> Este proceso podría tardar varios minutos
|
||||
y reemplazar datos existentes en la plataforma.
|
||||
Asegúrese de que la información en Tryton esté actualizada antes de
|
||||
continuar.
|
||||
</v-alert>
|
||||
</v-card-text>
|
||||
|
||||
<v-card-actions class="justify-center">
|
||||
<v-btn color="primary" @click="startSync">
|
||||
Iniciar Sincronización
|
||||
</v-btn>
|
||||
<v-btn text @click="$router.push('/')">
|
||||
Cancelar
|
||||
</v-btn>
|
||||
</v-card-actions>
|
||||
</v-card>
|
||||
<v-data-table :items="ventas_tryton_failed"></v-data-table>
|
||||
<v-data-table :items="ventas_tryton_successful"></v-data-table>
|
||||
</v-container>
|
||||
</template>
|
||||
<script>
|
||||
import CodeDialog from '../components/CodeDialog.vue';
|
||||
import { inject } from 'vue';
|
||||
|
||||
export default {
|
||||
name: 'SalesToTryton',
|
||||
data() {
|
||||
return {
|
||||
api: inject('api'),
|
||||
ventas_tryton: [],
|
||||
showComponent: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
startSync() {
|
||||
this.api.sendSalesToTryton()
|
||||
.then(response => {
|
||||
this.ventas_tryton_failed = response.failed.map(id => ({ id }));
|
||||
this.ventas_tryton_successful = response.successful.map(id => ({ id }));
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error al sincronizar las ventas", error);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -50,6 +50,18 @@ class Api {
|
||||
getCSVForTryton() {
|
||||
return this.apiImplementation.getCSVForTryton();
|
||||
}
|
||||
|
||||
getProductsFromTryton() {
|
||||
return this.apiImplementation.getProductsFromTryton();
|
||||
}
|
||||
|
||||
getCustomersFromTryton() {
|
||||
return this.apiImplementation.getCustomersFromTryton();
|
||||
}
|
||||
|
||||
sendSalesToTryton(){
|
||||
return this.apiImplementation.sendSalesToTryton();
|
||||
}
|
||||
}
|
||||
|
||||
export default Api;
|
||||
|
||||
72
src/services/auth.js
Normal file
72
src/services/auth.js
Normal file
@@ -0,0 +1,72 @@
|
||||
class AuthService {
|
||||
static TOKEN_KEY = 'access_token';
|
||||
static REFRESH_KEY = 'refresh_token';
|
||||
|
||||
static async login(credentials) {
|
||||
const url = `${import.meta.env.VITE_DJANGO_BASE_URL}/api/token/`;
|
||||
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(credentials),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
let errMsg = resp.statusText;
|
||||
try {
|
||||
const errData = await resp.json();
|
||||
errMsg = errData?.detail ?? errData?.message ?? errMsg;
|
||||
} catch (_) { /* ignore */ }
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
|
||||
if (data.access && data.refresh) {
|
||||
localStorage.setItem(this.TOKEN_KEY, data.access);
|
||||
localStorage.setItem(this.REFRESH_KEY, data.refresh);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
static getAccessToken() {
|
||||
return localStorage.getItem(this.TOKEN_KEY);
|
||||
}
|
||||
|
||||
static getRefreshToken() {
|
||||
return localStorage.getItem(this.REFRESH_KEY);
|
||||
}
|
||||
|
||||
static async refresh() {
|
||||
const refresh = this.getRefreshToken();
|
||||
if (!refresh) throw new Error('No refresh token');
|
||||
|
||||
const url = `${import.meta.env.VITE_DJANGO_BASE_URL}/api/token/refresh/`;
|
||||
const resp = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ refresh }),
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
const errData = await resp.json().catch(() => ({}));
|
||||
throw new Error(errData?.detail ?? resp.statusText);
|
||||
}
|
||||
|
||||
const data = await resp.json();
|
||||
localStorage.setItem(this.TOKEN_KEY, data.access);
|
||||
return data.access;
|
||||
}
|
||||
|
||||
static isAuthenticated() {
|
||||
return !!this.getAccessToken();
|
||||
}
|
||||
|
||||
static logout() {
|
||||
localStorage.removeItem(this.TOKEN_KEY);
|
||||
localStorage.removeItem(this.REFRESH_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
export default AuthService;
|
||||
@@ -1,8 +1,19 @@
|
||||
import AuthService from '@/services/auth';
|
||||
import http from '@/services/http';
|
||||
|
||||
class DjangoApi {
|
||||
constructor() {
|
||||
this.base = import.meta.env.VITE_DJANGO_BASE_URL;
|
||||
}
|
||||
|
||||
getRequest(url) {
|
||||
return http.get(url).then(r => r.data);
|
||||
}
|
||||
|
||||
postRequest(url, payload) {
|
||||
return http.post(url, payload).then(r => r.data);
|
||||
}
|
||||
|
||||
getCustomers() {
|
||||
const url = this.base + '/don_confiao/api/customers/';
|
||||
return this.getRequest(url);
|
||||
@@ -63,44 +74,20 @@ class DjangoApi {
|
||||
return this.getRequest(url);
|
||||
}
|
||||
|
||||
getRequest(url) {
|
||||
return new Promise ((resolve, reject) => {
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
resolve(data);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
getProductsFromTryton(){
|
||||
const url = this.base + '/don_confiao/api/importar_productos_de_tryton';
|
||||
return this.postRequest(url, {});
|
||||
}
|
||||
|
||||
postRequest(url, content) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(content)
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
reject(new Error(`Error ${response.status}: ${response.statusText}`));
|
||||
} else {
|
||||
response.json().then(data => {
|
||||
if (!data) {
|
||||
reject(new Error('La respuesta no es un JSON válido'));
|
||||
} else {
|
||||
resolve(data);
|
||||
getCustomersFromTryton(){
|
||||
const url = this.base + '/don_confiao/api/importar_clientes_de_tryton';
|
||||
return this.postRequest(url, {});
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => reject(error));
|
||||
});
|
||||
|
||||
sendSalesToTryton(){
|
||||
const url = this.base + '/don_confiao/api/enviar_ventas_a_tryton';
|
||||
return this.postRequest(url, {});
|
||||
}
|
||||
}
|
||||
|
||||
export default DjangoApi;
|
||||
export default DjangoApi;
|
||||
|
||||
44
src/services/http.js
Normal file
44
src/services/http.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import axios from 'axios';
|
||||
import AuthService from '@/services/auth';
|
||||
|
||||
const http = axios.create({
|
||||
baseURL: import.meta.env.VITE_DJANGO_BASE_URL,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
http.interceptors.request.use(
|
||||
config => {
|
||||
const token = AuthService.getAccessToken();
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
error => Promise.reject(error)
|
||||
);
|
||||
|
||||
http.interceptors.response.use(
|
||||
response => response,
|
||||
async error => {
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (error.response?.status === 401 && !originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
try {
|
||||
const newAccess = await AuthService.refresh();
|
||||
originalRequest.headers.Authorization = `Bearer ${newAccess}`;
|
||||
return http.request(originalRequest);
|
||||
} catch (refreshError) {
|
||||
AuthService.logout();
|
||||
window.location.href = '/autenticarse';
|
||||
return Promise.reject(refreshError);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default http;
|
||||
43
src/stores/cart.js
Normal file
43
src/stores/cart.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useCartStore = defineStore('cart', {
|
||||
state: () => ({
|
||||
items: []
|
||||
}),
|
||||
getters: {
|
||||
cartCount: (state) => state.items.reduce((sum, item) => sum + item.quantity, 0),
|
||||
cartTotal: (state) => state.items.reduce((sum, item) => sum + (item.price * item.quantity), 0)
|
||||
},
|
||||
actions: {
|
||||
addItem(product) {
|
||||
const existing = this.items.find(i => i.id === product.id)
|
||||
if (existing) {
|
||||
existing.quantity = product.quantity
|
||||
} else {
|
||||
this.items.push({
|
||||
id: product.id,
|
||||
name: product.name,
|
||||
img: product.img,
|
||||
price: product.price,
|
||||
quantity: product.quantity,
|
||||
measuring_unit: product.measuring_unit || 'Unidad'
|
||||
})
|
||||
}
|
||||
},
|
||||
removeItem(itemId) {
|
||||
const index = this.items.findIndex(i => i.id === itemId)
|
||||
if (index > -1) {
|
||||
this.items.splice(index, 1)
|
||||
}
|
||||
},
|
||||
updateQuantity({ itemId, quantity }) {
|
||||
const item = this.items.find(i => i.id === itemId)
|
||||
if (item) {
|
||||
item.quantity = quantity
|
||||
}
|
||||
},
|
||||
clearCart() {
|
||||
this.items = []
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -50,7 +50,7 @@ export default defineConfig({
|
||||
} },
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url))
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
extensions: [
|
||||
'.js',
|
||||
|
||||
Reference in New Issue
Block a user