- | {{ head?.name }} |
+ {{ head?.name }} |
-
- | {{ item?.[head?.name] }} |
+
+ | {{ item?.[head?.name?.toLowerCase()] }} |
diff --git a/src/pinia/products.js b/src/pinia/products.js
index 2ece7ad..059a012 100644
--- a/src/pinia/products.js
+++ b/src/pinia/products.js
@@ -1,17 +1,20 @@
import {defineStore} from "pinia";
+import {DBService, post} from "@/services/apiReq";
-export const productos = defineStore('products', {
+export const useProductStore = defineStore('products', {
state: () => ({
productos: [],
+ filter: {}
}),
- getters: {
- getProducts() {
-
- }
- },
actions: {
- fetchProducts() {
+ async fetchProducts() {
+ let response = await post("/get", {
+ limit: this.filter.limit,
+ page: this.filter.page,
+ table: 'Productos',
+ }, DBService)
+ this.productos = response.data?.rows;
}
}
})
\ No newline at end of file
diff --git a/src/pinia/ui.js b/src/pinia/ui.js
index dbb2c51..efdf3d3 100644
--- a/src/pinia/ui.js
+++ b/src/pinia/ui.js
@@ -4,6 +4,8 @@ export const useUi = defineStore('ui', {
state: () => ({
currentMenu: null,
selectedMenu: null,
+ intro: true,
+ login: true,
}),
getters: {},
actions: {
@@ -11,5 +13,9 @@ export const useUi = defineStore('ui', {
if (!state) this.selectedMenu = null;
this.currentMenu = state;
},
+ reset() {
+ this.currentMenu = null;
+ this.selectedMenu = null;
+ }
}
})
\ No newline at end of file
diff --git a/src/pinia/user.js b/src/pinia/user.js
new file mode 100644
index 0000000..3affc1e
--- /dev/null
+++ b/src/pinia/user.js
@@ -0,0 +1,60 @@
+import {defineStore} from "pinia";
+import {authUrl, post, site_name} from "../services/apiReq.js";
+import axios from "axios";
+import {clear, getObject, saveObject} from "@/services/storage";
+import {show} from "@/services/notification";
+
+export const useUserStore = defineStore('user', {
+ state: () => ({
+ user: null,
+ }),
+ getters: {},
+ actions: {
+ async login(email, password) {
+ clear();
+ let response = await axios.post(authUrl + '/login', {email, password, site_name, panel: 0});
+ const {User, message} = response.data;
+ let user = User;
+ if (message) {
+ show(response.data.message);
+ }
+ /*
+ if (user.role !== 'super-admin' && user.role !== 'mod-admin' && user.role !== 'admin') {
+ show("Usuario no encontrado");
+
+ return;
+ }
+ */
+
+ if (user) {
+ this.user = user;
+ saveObject("user", user);
+ return true;
+ }
+ return false;
+ },
+ logout() {
+ clear();
+ location.reload();
+ },
+ async get() {
+ // || Api request
+ let _user = getObject("user");
+ if (!_user) return;
+ else {
+ let response = await axios.post(authUrl + '/user', _user);
+ _user = response.data?.user;
+ if (_user) {
+ this.user = _user;
+ saveObject("user", _user);
+ }
+ }
+ },
+ async getUser() {
+ if (!this.user) {
+ await this.get();
+ }
+ return this.user;
+ }
+ }
+});
\ No newline at end of file
diff --git a/src/router/index.js b/src/router/index.js
index 40eebe9..b654738 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,27 +1,22 @@
-import { createRouter, createWebHistory } from 'vue-router'
+import {createRouter, createWebHashHistory} from 'vue-router'
import HomeView from '../views/HomeView.vue'
const routes = [
- {
- path: '/',
- name: 'home',
- component: HomeView
- },
- {
- path: '/about',
- name: 'about',
- // route level code-splitting
- // this generates a separate chunk (about.[hash].js) for this route
- // which is lazy-loaded when the route is visited.
- component: function () {
- return import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
+ {
+ path: '/',
+ name: 'home',
+ component: HomeView
+ },
+ {
+ path: '/login',
+ name: 'login',
+ component: () => import('../views/Login.vue')
}
- }
]
const router = createRouter({
- history: createWebHistory(process.env.BASE_URL),
- routes
+ history: createWebHashHistory(process.env.BASE_URL),
+ routes
})
export default router
diff --git a/src/services/apiReq.js b/src/services/apiReq.js
new file mode 100644
index 0000000..ac7b187
--- /dev/null
+++ b/src/services/apiReq.js
@@ -0,0 +1,135 @@
+import axios from "axios";
+import {show} from "./notification";
+
+export const site_name = "DPStock.db";
+export const backendUrl = "https://backend.digitalpower.ar";
+
+//export const databaseUrl = "https://database.digitalpower.ar";
+//export const authUrl = "https://auth.digitalpower.ar";
+export const authUrl = "http://localhost:3013";
+export const databaseUrl = "http://localhost:3014";
+
+const Service = axios.create({
+ baseURL: `${backendUrl}/api`,
+});
+export const DBService = axios.create({
+ baseURL: `${databaseUrl}/api`,
+});
+export const AuthService = axios.create({
+ baseURL: `${authUrl}/`,
+});
+
+let user = {token: null, id: null, site_name: null};
+if (localStorage.getItem("user") !== "undefined") user = JSON.parse(localStorage?.getItem("user"))
+if (localStorage.getItem("user") !== "undefined")
+ user = JSON.parse(localStorage.getItem("user"));
+
+
+let config = {
+ headers: {
+ Authorization: `Bearer ${user?.token}`,
+ Accept: "application/json",
+ "Content-Type": "application/json",
+ },
+};
+export const post = (path, body, service = Service) => {
+ if (!user) {
+ user = JSON.parse(localStorage.getItem("user"));
+ config = {
+ headers: {
+ Authorization: `Bearer ${user?.token}`,
+ Accept: "application/json",
+ "Content-Type": "application/json",
+ },
+ };
+ console.log("USER", user);
+ }
+ if (!body) {
+ body = {};
+ }
+ if (!body?.site_name) body.site_name = user?.site_name ?? site_name;
+ if (user?.id) body.user_id = user?.id;
+
+ return new Promise(async (resolve) => {
+ service
+ .post(path, body, config)
+ .then((response) => {
+ let message = response?.message ?? response.data?.message;
+ let status = response?.status ?? response.data?.status;
+
+ if (response.data?.data) response = response?.data;
+ if (message) {
+ show(message);
+ }
+
+ setTimeout(() => {
+ if (response?.data?.redirect) {
+ location.href = response?.data?.redirect;
+ }
+ }, 1000);
+
+ if (status === 401) {
+ location.href = "/admin";
+ }
+ resolve(response);
+ })
+ .catch((err) => {
+ console.log(err)
+ if (err?.response?.status === 401) {
+ //localStorage.removeItem("dp_user");
+ //location.href = "/#/login";
+ }
+ if (err?.response?.data?.message) {
+ show(err?.response?.data?.message);
+ } else
+ show("Ha ocurrido un error, intente mas tarde");
+ })
+ .finally(() => {
+ });
+ });
+};
+export const files = (path, body) => {
+ if (body?.append) {
+ body.append("site_name", user?.site_name);
+ if (user?.id) body.append("user_id", user?.id);
+
+ } else {
+ body.site_name = user?.site_name;
+ if (user?.id) body.user_id = user?.id;
+
+ }
+
+ return new Promise((resolve) => {
+ Service
+ .post(path, body, {
+ headers: {
+ "Content-Type": "multipart/form-data",
+ Authorization: `Bearer ${user?.token}`,
+ Accept: "application/json",
+ },
+ })
+ .then((response) => {
+ if (response.data?.message) {
+ show(response.data.message);
+ }
+ setTimeout(() => {
+ if (response?.data?.data?.redirect)
+ location.href = response?.data?.data?.redirect;
+ }, 1000);
+
+ if (response.data?.status === 401) {
+ location.href = "/admin";
+ }
+
+ resolve(response.data);
+ })
+ .catch((err) => {
+ if (err?.response?.status === 401) {
+ location.href = "/#/login";
+ }
+ show("Ha ocurrido un error, intente mas tarde");
+ })
+ .finally(() => {
+ });
+ });
+};
diff --git a/src/services/notification.js b/src/services/notification.js
new file mode 100644
index 0000000..9b019b1
--- /dev/null
+++ b/src/services/notification.js
@@ -0,0 +1,63 @@
+export const show = (text, audio) => {
+ let html = `
+ ${text}
+ `;
+ let element = document.createElement("div");
+ element.innerHTML = html;
+ element.classList.add("notification");
+ element.classList.add("notification-enter");
+
+ const container = document.getElementById("notification-container");
+ container?.appendChild(element);
+ PlayNotificationAudio(audio)
+ setTimeout(() => {
+ element.classList.remove("notification-enter")
+ element.classList.add("notification-exit");
+ }, 3000);
+ setTimeout(() => {
+ element.remove();
+ }, 3240);
+}
+
+export const ConfirmModal = () => {
+ return new Promise((resolve) => {
+ let container = document.getElementById("app-layout");
+ let html = document.createElement("div");
+ html.setAttribute("id", "confirmModal");
+ html.innerHTML = `
+
+
+
+
Alerta
+
+
+
¿Esta seguro que desea continuar con esta accion? Es posible que no tenga retroceso
+
+
+
+
+ `;
+ container?.appendChild(html);
+
+ const confirm = document.getElementById("confirmModalButton");
+ const cancel = document.getElementById("cancelModalButton")
+
+ confirm?.addEventListener("click", (e) => {
+ html.remove();
+ resolve(true);
+ })
+ cancel?.addEventListener("click", (e) => {
+ html.remove();
+ resolve(false);
+ })
+ })
+}
+
+export function PlayNotificationAudio(path = '/notification.mp3') {
+ const audio = new Audio(path);
+ audio.play()
+
+}
\ No newline at end of file
diff --git a/src/services/storage.js b/src/services/storage.js
new file mode 100644
index 0000000..7b2cefc
--- /dev/null
+++ b/src/services/storage.js
@@ -0,0 +1,13 @@
+export function clear() {
+ localStorage.clear();
+}
+
+export function saveObject(key, object) {
+ localStorage.setItem(key, JSON.stringify(object));
+}
+
+export function getObject(key) {
+ const item = localStorage.getItem(key);
+ if (item) return JSON.parse(item);
+ return null;
+}
\ No newline at end of file
diff --git a/src/styles/digitalpower.css b/src/styles/digitalpower.css
index 885b4cd..0e17d0c 100644
--- a/src/styles/digitalpower.css
+++ b/src/styles/digitalpower.css
@@ -382,7 +382,7 @@ p {
[fade] {
animation-name: fadeAnim;
- animation-duration: 0.2s;
+ animation-duration: .5s;
}
[delayedfade] {
diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue
index 41533c8..553a7a5 100644
--- a/src/views/HomeView.vue
+++ b/src/views/HomeView.vue
@@ -11,11 +11,20 @@ import Table from "@/components/productos/Table.vue";
import {computed, onMounted, ref} from "vue";
import Filters from "@/components/productos/Filters.vue";
import {useUi} from "@/pinia/ui";
+import {show} from "@/services/notification";
+import {useUserStore} from "@/pinia/user";
const ui = useUi();
+const userStore = useUserStore()
const headers = computed(() => {
const producto = productos.value?.[0];
- if (!producto) return [];
+ if (!producto) return [
+ {value: 'Nombre', name: 'Nombre'},
+ {value: 'Precio', name: 'Precio'},
+ {value: 'Stock', name: 'Stock'},
+ {value: 'Vendidos', name: 'Vendidos'},
+ {value: 'Acciones', name: 'Acciones'},
+ ];
return Object.keys(producto).map((x) => {
return {value: x, name: x};
diff --git a/src/views/Login.vue b/src/views/Login.vue
new file mode 100644
index 0000000..cf7e295
--- /dev/null
+++ b/src/views/Login.vue
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
\ No newline at end of file