diff --git a/app/components/viewer/Filters.vue b/app/components/viewer/Filters.vue
deleted file mode 100644
index 570ce61..0000000
--- a/app/components/viewer/Filters.vue
+++ /dev/null
@@ -1,227 +0,0 @@
-
-
-
-
-
- - {
- if (tab !== activeFilterTab) filterTabChange(tab);
- }
- "
- >
- Lọc theo {{ tab }}
-
-
-
-
-
{
- // toggle all
- if (localFilterStates.cartIds.length === carts.length) {
- localFilterStates.cartIds = [];
- } else {
- localFilterStates.cartIds = carts.map((c) => c.id);
- }
- }
- "
- >
- Tất cả
-
- {{ productCount }}
-
-
-
-
-
-
-
{
- // toggle all
- if (localFilterStates.dealerIds.length === dealers.length) {
- localFilterStates.dealerIds = [];
- } else {
- localFilterStates.dealerIds = dealers.map((c) => c.id);
- }
- }
- "
- >
- Tất cả
-
- {{ productCount }}
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/components/viewer/LayerSetting.vue b/app/components/viewer/LayerSetting.vue
deleted file mode 100644
index 0e00a28..0000000
--- a/app/components/viewer/LayerSetting.vue
+++ /dev/null
@@ -1,65 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/app/components/viewer/LayerSettingList.vue b/app/components/viewer/LayerSettingList.vue
deleted file mode 100644
index dfab83f..0000000
--- a/app/components/viewer/LayerSettingList.vue
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
- -
- {{ layersetting.name }}
-
-
-
- Bạn chưa tạo thiết lập layer nào.
-
-
diff --git a/app/components/viewer/LayerSettingSave.vue b/app/components/viewer/LayerSettingSave.vue
deleted file mode 100644
index 40b4e62..0000000
--- a/app/components/viewer/LayerSettingSave.vue
+++ /dev/null
@@ -1,127 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ errors.find((v) => v.name === "name").msg }}
-
-
-
-
-
diff --git a/app/components/viewer/Legends.vue b/app/components/viewer/Legends.vue
deleted file mode 100644
index 59f03c6..0000000
--- a/app/components/viewer/Legends.vue
+++ /dev/null
@@ -1,368 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- - {
- if (statusMode !== mode) emit('switchStatusMode', mode);
- }
- "
- >
- {{ mode }}
-
-
-
-
-
emit('updateFilters', { statusIds: [id] })"
- >
-
-
-
- {{ productCountByStatus[id] || 0 }}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/app/components/viewer/ProductNoteHistory.vue b/app/components/viewer/ProductNoteHistory.vue
deleted file mode 100644
index ba67b4f..0000000
--- a/app/components/viewer/ProductNoteHistory.vue
+++ /dev/null
@@ -1,166 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- | Sản phẩm |
- Nội dung |
- Người tạo |
- Thời gian |
-
-
-
-
- |
- {{ note.ref__trade_code }}
- |
-
- {{ note.detail }}
- |
- {{ note.username || note.user__username }} |
-
- {{ new Date(note.create_time).toLocaleString("vi-VN") }}
- |
-
-
-
-
-
-
-
diff --git a/app/components/viewer/Search.vue b/app/components/viewer/Search.vue
deleted file mode 100644
index 8a6be8a..0000000
--- a/app/components/viewer/Search.vue
+++ /dev/null
@@ -1,205 +0,0 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/app/components/viewer/Viewer.vue b/app/components/viewer/Viewer.vue
deleted file mode 100644
index 222ab1f..0000000
--- a/app/components/viewer/Viewer.vue
+++ /dev/null
@@ -1,1081 +0,0 @@
-
-
-
-
-
-
-
diff --git a/app/components/viewer/utils/aps-init.js b/app/components/viewer/utils/aps-init.js
deleted file mode 100644
index 6ac7734..0000000
--- a/app/components/viewer/utils/aps-init.js
+++ /dev/null
@@ -1,77 +0,0 @@
-export const utopiaUrn =
- "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC8yNi4wMS4xNiUyMC0lMjBFeHBvcnQlMjBUTUIlMjAtJTIwUGhhbiUyMG1lbS5kd2c";
-export const blankUrn =
- "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6cGtxYjhrbHBnZWtsZ2tlbHBzanBoYzljMm5neXhtbjY0cXZocHNhcXVodjQ2emVuLWJhc2ljLWFwcC9ibGFuay5kd2c";
-
-export async function getAccessToken(callback) {
- try {
- const { access_token, expires_in } = await $fetch("/api/apsAuthToken");
- callback(access_token, expires_in);
- } catch (err) {
- console.error("Could not obtain access token. Error:", err);
- }
-}
-
-export function loadModel(viewer, urn, xform) {
- return new Promise((resolve, reject) => {
- function onDocumentLoadSuccess(doc) {
- const viewable = doc.getRoot().getDefaultGeometry();
- const options = {
- keepCurrentModels: true,
- };
- if (xform) {
- options.placementTransform = xform;
- }
- viewer.loadDocumentNode(doc, viewable, options).then(resolve).catch(reject);
- }
- function onDocumentLoadFailure(code, message, errors) {
- reject({ code, message, errors });
- }
- viewer.setLightPreset(0);
- Autodesk.Viewing.Document.load(`urn:${urn}`, onDocumentLoadSuccess, onDocumentLoadFailure);
- });
-}
-
-function showNotification(message) {
- const overlay = document.getElementById("overlay");
- overlay.innerHTML = `
${message}
`;
- overlay.style.display = "flex";
-}
-
-function clearNotification() {
- const overlay = document.getElementById("overlay");
- overlay.innerHTML = "";
- overlay.style.display = "none";
-}
-
-export async function setupModelSelection(viewer) {
- if (window.onModelSelectedTimeout) {
- clearTimeout(window.onModelSelectedTimeout);
- delete window.onModelSelectedTimeout;
- }
-
- try {
- const res = await $fetch(`/api/models/${utopiaUrn}/status`);
- const { status } = res;
- switch (status.status) {
- case "n/a":
- showNotification(`Model has not been translated.`);
- break;
- case "inprogress":
- showNotification(`Model is being translated (${status.progress})...`);
- window.onModelSelectedTimeout = setTimeout(onModelSelected, 5000, viewer, utopiaUrn);
- break;
- case "failed":
- showNotification(
- `Translation failed.
${status.messages.map((msg) => `- ${JSON.stringify(msg)}
`).join("")}
`,
- );
- break;
- default:
- clearNotification();
- loadModel(viewer, utopiaUrn);
- break;
- }
- } catch (err) {
- console.error("Could not load model. Error:", err);
- }
-}
diff --git a/app/components/viewer/utils/aps-viewer.js b/app/components/viewer/utils/aps-viewer.js
deleted file mode 100644
index 968494d..0000000
--- a/app/components/viewer/utils/aps-viewer.js
+++ /dev/null
@@ -1,112 +0,0 @@
-import { blankUrn, utopiaUrn } from "@/components/viewer/utils/aps-init";
-import { isNotNil } from "es-toolkit";
-
-function isTemInsideLand(landBounds, temBounds) {
- const tolerance = 0.007;
- return (
- landBounds.min.x - temBounds.min.x <= tolerance &&
- landBounds.min.y - temBounds.min.y <= tolerance &&
- landBounds.max.x - temBounds.max.x >= -tolerance &&
- landBounds.max.y - temBounds.max.y >= -tolerance
- );
-}
-
-export function findTemInside(land, tems) {
- const temInside = tems.find((tem) => {
- const temBounds = tem.bounds[0];
-
- for (const landBounds of land.bounds) {
- if (isTemInsideLand(landBounds, temBounds)) return true;
- }
- });
-
- return temInside;
-}
-
-export const getTradeCodeFromTem = (tem) => tem.properties.find((prop) => prop.displayName === "LO").displayValue;
-export const objIsTem = (obj) => obj.name && obj.name.startsWith("Blk003");
-export const objIsLand = (obj) => {
- const layerProp = obj.properties.find((prop) => prop.displayName === "Layer");
- if (!layerProp) return false;
- const globalWidthProp = obj.properties.find((prop) => prop.displayName === "Global width");
- return (
- (layerProp.displayValue === "1-bodim" || layerProp.displayValue === "0") /* special case - Z.E02.02A */ &&
- globalWidthProp.displayValue === 0
- );
-};
-
-export function findLandByTradeCode(trade_code, lands, temsInside) {
- const foundTemIndex = temsInside.findIndex((tem) => tem && getTradeCodeFromTem(tem) === trade_code);
- return foundTemIndex >= 0 ? [lands[foundTemIndex], foundTemIndex] : undefined;
-}
-
-export function pan(viewer) {
- const navigation = viewer.navigation;
- const position = navigation.getPosition();
- const target = navigation.getTarget();
-
- // offset both target and position to maintain angle
- const panOffset = new THREE.Vector3(2, 0, 0);
- navigation.setPosition(position.clone().add(panOffset));
- navigation.setTarget(target.clone().add(panOffset));
-}
-
-export function unloadUnusedExtensions(viewer) {
- viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, (e) => {
- if (["Autodesk.Measure", "Autodesk.DocumentBrowser", "Autodesk.DefaultTools.NavTools"].includes(e.extensionId)) {
- viewer.unloadExtension(e.extensionId);
- }
- });
-}
-
-export function addTemSelectionListener(viewer, products, openProductViewModal, openNoPermissionModal) {
- viewer.addEventListener(
- Autodesk.Viewing.AGGREGATE_SELECTION_CHANGED_EVENT,
- (e) => {
- viewer.clearSelection();
- if (e.selections.length !== 1) return;
- const [selectedObj] = e.selections;
- const { model, dbIdArray } = selectedObj;
- if (dbIdArray.length !== 1) return;
-
- if (model.loader.svfUrn === utopiaUrn) {
- const [dbId] = dbIdArray;
- viewer.getProperties(dbId, (obj) => {
- if (!objIsTem(obj)) return;
-
- const trade_code = getTradeCodeFromTem(obj);
- const product = products.find((p) => p.trade_code === trade_code);
- product ? openProductViewModal(product) : openNoPermissionModal();
- });
- } else if (model.loader.svf.isSceneBuilder) {
- const [dbId] = dbIdArray;
- const product = products.find((p) => p.id === dbId);
- product ? openProductViewModal(product) : openNoPermissionModal();
- } else if (model.loader.svfUrn === blankUrn) {
- viewer.clearSelection(); // make unselectable
- }
- },
- (err) => console.error(err),
- );
-}
-
-export function getLayerNames() {
- const { viewer } = window;
- if (!viewer) return;
- if (!viewer.impl) return;
-
- const layerNames = viewer.impl.layers.indexToLayer
- .filter((obj) => isNotNil(obj)) // not counting root
- .filter((obj) => obj.visible)
- .map(({ layer }) => layer.name)
- .sort((a, b) => a.localeCompare(b));
-
- return layerNames;
-}
-
-export function applyLayerSetting(layersetting, store) {
- const { viewer } = window;
- viewer.setLayerVisible(null, false); // first, hide everything
- viewer.setLayerVisible(layersetting?.detail || null, true); // show specific ones, or all if there's no setting
- store.commit("layersetting", layersetting);
-}
diff --git a/app/components/viewer/utils/dom.js b/app/components/viewer/utils/dom.js
deleted file mode 100644
index b810de0..0000000
--- a/app/components/viewer/utils/dom.js
+++ /dev/null
@@ -1,37 +0,0 @@
-export async function renderSvg(relativePath) {
- const svgRes = await fetch(relativePath);
- const svgText = await svgRes.text();
- const parser = new DOMParser();
- const svgDoc = parser.parseFromString(svgText, "image/svg+xml");
- const svgElement = svgDoc.documentElement;
-
- return svgElement;
-}
-
-export function html(tag, props = {}, children = []) {
- const element = document.createElement(tag);
-
- Object.entries(props).forEach(([key, value]) => {
- if (key === "textContent" || key === "innerHTML") {
- element[key] = value;
- } else if (key === "style" && typeof value === "object") {
- Object.assign(element.style, value);
- } else if (key === "class") {
- element.className = value;
- } else if (key.startsWith("on")) {
- element.addEventListener(key.slice(2).toLowerCase(), value);
- } else {
- element.setAttribute(key, value);
- }
- });
-
- children.flat().forEach((child) => {
- if (typeof child === "string") {
- element.appendChild(document.createTextNode(child));
- } else if (child instanceof Node) {
- element.appendChild(child);
- }
- });
-
- return element;
-}
diff --git a/app/components/viewer/utils/geometry.js b/app/components/viewer/utils/geometry.js
deleted file mode 100644
index 00c79d2..0000000
--- a/app/components/viewer/utils/geometry.js
+++ /dev/null
@@ -1,94 +0,0 @@
-export class GeometryCallback {
- constructor(viewer, vpXform) {
- this.viewer = viewer;
- this.vpXform = vpXform;
- this.lines = [];
- }
-
- onLineSegment(x1, y1, x2, y2) {
- let pt1 = new THREE.Vector3().set(x1, y1, 0).applyMatrix4(this.vpXform);
- let pt2 = new THREE.Vector3().set(x2, y2, 0).applyMatrix4(this.vpXform);
-
- this.lines.push({
- x1: pt1.x,
- y1: pt1.y,
- x2: pt2.x,
- y2: pt2.y,
- });
- }
-}
-
-export function getBounds(dbId, frags) {
- let fragIds = frags.fragments.dbId2fragId[dbId];
- if (typeof fragIds === "number") {
- fragIds = [fragIds];
- }
-
- const bounds = fragIds.map((fId) => {
- const bound = new THREE.Box3();
- const boundsCallback = new Autodesk.Viewing.Private.BoundsCallback(bound);
- const mesh = frags.getVizmesh(fId);
- const vbr = new Autodesk.Viewing.Private.VertexBufferReader(mesh.geometry, viewer.impl.use2dInstancing);
- vbr.enumGeomsForObject(dbId, boundsCallback);
- return bound;
- });
-
- return bounds;
-}
-
-export function extractPoints(lines) {
- const tolerance = 0.001;
- const allPoints = [];
-
- for (let i = 0; i < lines.length; i++) {
- const { x1, y1, x2, y2 } = lines[i];
- allPoints.push({ x: x1, y: y1 });
- allPoints.push({ x: x2, y: y2 });
- }
-
- const pointsDeduped = [];
-
- for (let i = 0; i < allPoints.length; i++) {
- const element = allPoints[i];
-
- const notFound = !pointsDeduped.find(
- (pt) => Math.abs(pt.x - element.x) < tolerance && Math.abs(pt.y - element.y) < tolerance,
- );
- if (notFound) pointsDeduped.push(element);
- }
-
- return pointsDeduped;
-}
-
-export function sortByAngle(points) {
- // Calculate centroid
- const centroid = new THREE.Vector3();
- points.forEach((v) => centroid.add(v));
- centroid.divideScalar(points.length);
-
- // Sort by angle around centroid
- return points.slice().sort((a, b) => {
- const angleA = Math.atan2(a.y - centroid.y, a.x - centroid.x);
- const angleB = Math.atan2(b.y - centroid.y, b.x - centroid.x);
- return angleA - angleB;
- });
-}
-
-export function getColorByIndex(i) {
- const colors = ["magenta", "red", "orange", "yellow", "chartreuse", "green", "blue"];
- if (i === 0) return "black";
- return colors[i % 7];
-}
-
-/**
- * - THREE.Color: `{ r: number, g: number, b: number }`
- * - THREE.Vector4: `{ x: number, y: number, z: number, w: number }`
- *
- * @param {string} colorStr e.g. `'#ff0000'`, `'white'`, `'hotpink'`
- * @returns A Vector4 object
- */
-export function colorStrToVector4(colorStr) {
- const color = new THREE.Color().setStyle(colorStr);
- const vector4 = new THREE.Vector4(color.r, color.g, color.b, 1);
- return vector4;
-}
diff --git a/app/pages/index.vue b/app/pages/index.vue
index 35f7d44..14a6f55 100644
--- a/app/pages/index.vue
+++ b/app/pages/index.vue
@@ -15,7 +15,7 @@
{{ tab[$store.lang] }}
{{ subtab[$store.lang] }}
@@ -40,14 +40,17 @@
/>
-
+
diff --git a/app/plugins/00-datatable.js b/app/plugins/00-datatable.js
index fbf9f37..46570e4 100644
--- a/app/plugins/00-datatable.js
+++ b/app/plugins/00-datatable.js
@@ -421,6 +421,7 @@ export default defineNuxtPlugin(() => {
return {
provide: {
+ store,
find,
findIndex,
filter,
diff --git a/app/plugins/01-common.js b/app/plugins/01-common.js
index 49ee0b3..f16fd56 100644
--- a/app/plugins/01-common.js
+++ b/app/plugins/01-common.js
@@ -1,6 +1,4 @@
-// nuxt 3 - plugins/my-plugin.ts
import { useRoute } from "vue-router";
-import { useStore } from "~/stores/index";
import dayjs from "dayjs";
import weekday from "dayjs/plugin/weekday";
import weekOfYear from "dayjs/plugin/weekOfYear";
@@ -17,10 +15,9 @@ dayjs.extend(isSameOrBefore);
dayjs.extend(isSameOrAfter);
dayjs.locale("vi");
-export default defineNuxtPlugin(() => {
+export default defineNuxtPlugin((nuxtApp) => {
const route = useRoute();
- const { $id, $empty } = useNuxtApp();
- const store = useStore();
+ const { $id, $empty, $store } = nuxtApp;
const dialog = function (content, title, type, duration, width, height, vbind) {
content = typeof content === "string" ? content : JSON.stringify(content);
let vtitle = type === "Success" ? `
${title}` : title;
@@ -33,7 +30,7 @@ export default defineNuxtPlugin(() => {
width: width || "600px",
height: height || "100px",
};
- store.commit("showmodal", data);
+ $store.commit("showmodal", data);
};
const snackbar = function (content, title, type, width, height) {
@@ -48,7 +45,7 @@ export default defineNuxtPlugin(() => {
width: width || "600px",
height: height || "100px",
};
- store.commit("snackbar", data);
+ $store.commit("snackbar", data);
};
const getLink = function (val) {
@@ -379,8 +376,8 @@ export default defineNuxtPlugin(() => {
};
const lang = function (code) {
- let field = store.common.find((v) => v.code === code);
- return field ? field[store.lang] : "";
+ let field = $store.common.find((v) => v.code === code);
+ return field ? field[$store.lang] : "";
};
const createMeta = function (metainfo) {
diff --git a/app/plugins/02-connection.js b/app/plugins/02-connection.js
index c94da63..92b56f4 100644
--- a/app/plugins/02-connection.js
+++ b/app/plugins/02-connection.js
@@ -1,8 +1,4 @@
-// nuxt 3 - plugins/my-plugin.ts
-import { useStore } from "~/stores/index";
-import axios from "axios";
-
-export default defineNuxtPlugin(() => {
+export default defineNuxtPlugin((nuxtApp) => {
const module = "application";
const mode = "dev";
const paths = [
@@ -1001,13 +997,12 @@ export default defineNuxtPlugin(() => {
params: {},
},
];
- const store = useStore();
- const { $copy, $clone, $updateSeriesFields, $snackbar, $remove, $dialog } = useNuxtApp();
+ const { $copy, $clone, $updateSeriesFields, $snackbar, $store, $remove, $dialog } = nuxtApp;
const requestLogin = function () {
- store.commit("login", undefined);
- store.commit("layersetting", undefined);
- store.commit("lastlegendfiltertab", "Giỏ hàng");
+ $store.commit("login", undefined);
+ $store.commit("layersetting", undefined);
+ $store.commit("lastlegendfiltertab", "Giỏ hàng");
window.location.href = `https://${mode === "dev" ? "dev." : ""}login.utopia.com.vn/signin?module=${module}&link=${window.location.origin}`;
};
@@ -1022,17 +1017,19 @@ export default defineNuxtPlugin(() => {
return $copy(result);
};
- const readyapi = function (list) {
- var array = [];
- list.forEach((element) => {
- let found = apis.find((v) => v.name === element);
+ const readyapi = function (apiNames) {
+ const apisWithReady = [];
+ apiNames.forEach((apiName) => {
+ const found = apis.find((v) => v.name === apiName);
if (found) {
- let ele = JSON.parse(JSON.stringify(found));
- ele.ready = store[element] ? true : false;
- array.push(ele);
+ const apiWithReady = {
+ ...$copy(found),
+ ready: Boolean($store[apiName]),
+ };
+ apisWithReady.push(apiWithReady);
}
});
- return array;
+ return apisWithReady;
};
// get data
@@ -1042,16 +1039,15 @@ export default defineNuxtPlugin(() => {
let found = apis.find((api) => api.name === v.name);
let url = (v.path ? paths.find((x) => x.name === v.path).url : path) + (v.url ? v.url : found.url);
let params = v.params ? v.params : found.params === undefined ? {} : found.params;
- params.login = store.login ? store.login.id : undefined;
- return { url: url, params: params };
+ params.login = $store.login ? $store.login.id : undefined;
+ return { url, params };
});
- //let data = await Promise.all(arr.map(v=>axios.get(v.url, {params: v.params})))
let data = await Promise.all(arr.map((v) => $fetch(v.url, { params: v.params })));
data.map((v, i) => {
list[i].data = v;
if (list[i].commit) {
let data = v.rows ? v.rows : v;
- store.commit(list[i].commit, data);
+ $store.commit(list[i].commit, data);
}
});
return list;
@@ -1067,20 +1063,24 @@ export default defineNuxtPlugin(() => {
let found = findapi(name);
let curpath = found.path ? paths.find((x) => x.name === found.path).url : path;
var rs;
- if (!Array.isArray(data))
- rs = await axios.post(`${curpath}${found.url}`, data, {
- params: { values: values },
+ if (!Array.isArray(data)) {
+ rs = await $fetch(`${curpath}${found.url}`, {
+ method: "POST",
+ body: data,
+ params: { values },
});
- else {
- let params = { action: "import", values: values };
- rs = await axios.post(`${curpath}import-data/${found.url.substring(5, found.url.length - 1)}/`, data, {
- params: params,
+ } else {
+ let params = { action: "import", values };
+ rs = await $fetch(`${curpath}import-data/${found.url.substring(5, found.url.length - 1)}/`, {
+ method: "POST",
+ body: data,
+ params,
});
}
// update store
if (found.commit) {
- if (store[found.commit]) {
- let copy = JSON.parse(JSON.stringify(store[found.commit]));
+ if ($store[found.commit]) {
+ let copy = JSON.parse(JSON.stringify($store[found.commit]));
let rows = Array.isArray(rs.data) ? rs.data : [rs.data];
rows.map((v) => {
if (v.id && !v.error) {
@@ -1089,11 +1089,11 @@ export default defineNuxtPlugin(() => {
else copy.push(v);
}
});
- store.commit(found.commit, copy);
+ $store.commit(found.commit, copy);
}
}
if (notify !== false) {
- store.lang === "en"
+ $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success");
}
@@ -1110,25 +1110,27 @@ export default defineNuxtPlugin(() => {
let found = findapi(name);
let curpath = found.path ? paths.find((x) => x.name === found.path).url : path;
let updateUrl = found.url_detail ? found.url_detail : found.url;
- let rs = await axios.put(`${curpath}${updateUrl}${data.id}/`, data, {
- params: { values: values ? values : found.params.values },
+ let rs = await $fetch(`${curpath}${updateUrl}${data.id}/`, {
+ method: "PUT",
+ body: data,
+ params: { values: values || found.params.values },
});
if (found.commit) {
- let index = store[found.commit] ? store[found.commit].findIndex((v) => v.id === rs.data.id) : -1;
+ let index = $store[found.commit] ? $store[found.commit].findIndex((v) => v.id === rs.id) : -1;
if (index >= 0) {
- var copy = JSON.parse(JSON.stringify(store[found.commit]));
- if (Array.isArray(rs.data) === false) copy[index] = rs.data;
+ var copy = $copy($store[found.commit]);
+ if (Array.isArray(rs) === false) copy[index] = rs;
else {
- rs.data.forEach((v) => {
+ rs.forEach((v) => {
let index = copy.findIndex((v) => v.id === v.id);
if (index >= 0) copy[index] = v;
});
}
- store.commit(found.commit, copy);
+ $store.commit(found.commit, copy);
}
}
if (notify !== false) {
- store.lang === "en"
+ $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success");
}
@@ -1145,15 +1147,19 @@ export default defineNuxtPlugin(() => {
let found = findapi(name);
let curpath = found.path ? paths.find((x) => x.name === found.path).url : path;
let updateUrl = found.url_detail ? found.url_detail : found.url;
- let rs = await axios.patch(`${curpath}${updateUrl}${data.id}/`, data, {
- params: { values: values ? values : found.params?.values },
+
+ const rs = await $fetch(`${curpath}${updateUrl}${data.id}/`, {
+ method: "PATCH",
+ body: data,
+ params: { values: values || found.params?.values },
});
+
if (notify !== false) {
- store.lang === "en"
+ $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success");
}
- return rs.data;
+ return rs;
} catch (err) {
console.log(err);
return "error";
@@ -1161,7 +1167,7 @@ export default defineNuxtPlugin(() => {
};
const findpage = function (arr) {
- var copy = $copy(store.pagetrack);
+ var copy = $copy($store.pagetrack);
var doFind = function () {
let found = undefined;
for (let i = 1; i <= 30; i++) {
@@ -1184,7 +1190,7 @@ export default defineNuxtPlugin(() => {
} else {
result = doFind(copy);
}
- store.commit("pagetrack", copy);
+ $store.commit("pagetrack", copy);
return result;
};
@@ -1209,7 +1215,7 @@ export default defineNuxtPlugin(() => {
const setpage = function (pagename, row, api) {
let json = row.detail;
let fields = $updateSeriesFields(json.fields);
- let copy = store[pagename] || getpage();
+ let copy = $store[pagename] || getpage();
copy.fields = fields;
copy.setting = $copy(row);
if (json.filters) copy.filters = $copy(json.filters);
@@ -1222,7 +1228,7 @@ export default defineNuxtPlugin(() => {
copy.api = copyApi;
copy.origin_api = copy;
}
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
return copy;
};
@@ -1289,30 +1295,30 @@ export default defineNuxtPlugin(() => {
// insert row
var insertrow = async function (name, data, values, pagename, notify) {
let result = await insertapi(name, data, values, notify);
- if (result === "error" || !pagename || !store[pagename]) return result;
- let copy = $clone(store[pagename]);
+ if (result === "error" || !pagename || !$store[pagename]) return result;
+ let copy = $clone($store[pagename]);
copy.update = { refresh: true };
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
return result;
};
// update row
const updaterow = async function (name, data, values, pagename, notify) {
let result = await updateapi(name, data, values, notify);
- if (result === "error" || !pagename || !store[pagename]) return result;
- let copy = $clone(store[pagename]);
+ if (result === "error" || !pagename || !$store[pagename]) return result;
+ let copy = $clone($store[pagename]);
copy.update = { refresh: true };
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
return result;
};
// patch row
const patchrow = async function (name, data, values, pagename, notify) {
let result = await patchapi(name, data, values, notify);
- if (result === "error" || !pagename || !store[pagename]) return result;
- let copy = $clone(store[pagename]);
+ if (result === "error" || !pagename || !$store[pagename]) return result;
+ let copy = $clone($store[pagename]);
copy.update = { refresh: true };
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
return result;
};
@@ -1328,11 +1334,11 @@ export default defineNuxtPlugin(() => {
else {
let params = { action: "delete" };
rs = await $fetch(`${path}import-data/${found.url.substring(5, found.url.length - 1)}/`, id, {
- params: params,
+ params,
});
}
if (found.commit) {
- let copy = JSON.parse(JSON.stringify(store[found.commit]));
+ let copy = JSON.parse(JSON.stringify($store[found.commit]));
if (!Array.isArray(id)) {
let index = copy.findIndex((v) => v.id === id);
if (index >= 0) $remove(copy, index);
@@ -1342,7 +1348,7 @@ export default defineNuxtPlugin(() => {
if (index >= 0) $remove(copy, index);
});
}
- store.commit(found.name, copy);
+ $store.commit(found.name, copy);
console.log("copy", copy);
}
return id;
@@ -1363,16 +1369,16 @@ export default defineNuxtPlugin(() => {
// delete row
const deleterow = async function (name, id, pagename) {
let result = await deleteapi(name, id);
- if (result === "error" || !pagename || !store[pagename]) return result;
- let copy = $clone(store[pagename]);
+ if (result === "error" || !pagename || !$store[pagename]) return result;
+ let copy = $clone($store[pagename]);
copy.update = { refresh: true };
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
return result;
};
// update page
const updatepage = function (pagename, row, action) {
- let copy = $clone(store[pagename]);
+ let copy = $clone($store[pagename]);
let rows = Array.isArray(row) ? row : [row];
rows.map((x) => {
let idx = copy.data.findIndex((v) => v.id === x.id);
@@ -1383,7 +1389,7 @@ export default defineNuxtPlugin(() => {
}
});
copy.update = { data: copy.data };
- store.commit(pagename, copy);
+ $store.commit(pagename, copy);
};
const buildFileUrl = (file) => {
@@ -1472,25 +1478,25 @@ export default defineNuxtPlugin(() => {
return right === "edit" ? rightObj && rightObj.is_edit : Boolean(rightObj);
};
- if (store.rights.length === 0) return true; // full rights
+ if ($store.rights.length === 0) return true; // full rights
if (code && category) {
// if passed, must pass both
- const foundRight = store.rights.find(
+ const foundRight = $store.rights.find(
({ setting__category, setting__code }) => setting__category === category && setting__code === code,
);
return getRight(foundRight);
} else {
- const { tab, subtab } = store.tabinfo;
+ const { tab, subtab } = $store.tabinfo;
let isTabEdit;
let isSubTabEdit;
- const tabRight = store.rights.find((rights) => rights.setting === tab.id);
+ const tabRight = $store.rights.find((rights) => rights.setting === tab.id);
isTabEdit = getRight(tabRight);
if (!subtab) isSubTabEdit = false;
else {
- const subTabRight = store.rights.find((rights) => rights.setting === subtab.id);
+ const subTabRight = $store.rights.find((rights) => rights.setting === subtab.id);
isSubTabEdit = getRight(subTabRight);
}
@@ -1589,7 +1595,6 @@ export default defineNuxtPlugin(() => {
deleteapi,
deleterow,
updatepage,
- store,
requestLogin,
buildFileUrl,
generateDocument,
diff --git a/app/plugins/03-api-loader.js b/app/plugins/03-api-loader.js
index 9a5576f..233d671 100644
--- a/app/plugins/03-api-loader.js
+++ b/app/plugins/03-api-loader.js
@@ -1,10 +1,10 @@
export default defineNuxtPlugin(async (nuxtApp) => {
- const { $getapi, $readyapi } = useNuxtApp();
+ const { $getapi, $readyapi } = nuxtApp;
let connlist = $readyapi([
"datatype",
+ "common",
"filterchoice",
"colorchoice",
- "common",
"textalign",
"placement",
"colorscheme",
@@ -17,9 +17,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
"settingtype",
"settingclass",
"sex",
- "legaltype",
- "cart",
]);
- let filter = connlist.filter((v) => !v.ready);
- if (filter.length > 0) await $getapi(filter);
+ let notReadyConns = connlist.filter((v) => !v.ready);
+ if (notReadyConns.length > 0) await $getapi(notReadyConns);
});
diff --git a/app/plugins/04-components.js b/app/plugins/04-components.js
index d29953e..6cc5973 100644
--- a/app/plugins/04-components.js
+++ b/app/plugins/04-components.js
@@ -13,7 +13,6 @@ import ExportsDamaged from "@/components/exports/ExportsDamaged.vue";
import ExportsInternal from "@/components/exports/ExportsInternal.vue";
import ExportsAssembled from "@/components/exports/ExportsAssembled.vue";
import InventoryTransfer from "@/components/inventory-transfer/InventoryTransfer.vue";
-import InventoryCount from "@/components/inventory-count/InventoryCount.vue";
import CashBook from "@/components/cash-book/CashBook.vue";
import NCC from "@/components/report/NCC.vue";
import Customers from "@/components/report/Customers.vue";
@@ -58,7 +57,6 @@ import MenuCollab from "~/components/menu/MenuCollab.vue";
import MenuNote from "~/components/menu/MenuNote.vue";
import MenuPayment from "~/components/menu/MenuPayment.vue";
import ScrollBox from "~/components/datatable/ScrollBox.vue";
-import Viewer from "~/components/viewer/Viewer.vue";
import Product from "~/components/product/Product.vue";
import Reservation from "~/components/modal/Reservation.vue";
import UserMainTab from "~/components/modal/UserMainTab.vue";
@@ -128,7 +126,6 @@ const components = {
MenuAdd,
MenuCollab,
MenuNote,
- Viewer,
Product,
UserMainTab,
InternalAccount,
@@ -155,7 +152,6 @@ const components = {
ExportsInternal,
ExportsAssembled,
InventoryTransfer,
- InventoryCount,
CashBook,
NCC,
Customers,