changes
This commit is contained in:
@@ -18,7 +18,8 @@ dayjs.locale("vi");
|
||||
|
||||
export default defineNuxtPlugin((nuxtApp) => {
|
||||
const route = useRoute();
|
||||
const { $id, $empty, $store } = nuxtApp;
|
||||
const store = useStore();
|
||||
const { $id, $empty } = nuxtApp;
|
||||
|
||||
const dialog = function (content, title, type, duration, width, height, vbind) {
|
||||
content = typeof content === "string" ? content : JSON.stringify(content);
|
||||
@@ -38,11 +39,11 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
height: height || "100px",
|
||||
};
|
||||
|
||||
$store.commit("showmodal", data);
|
||||
store.commit("showmodal", data);
|
||||
};
|
||||
|
||||
const snackbar = function (content, component = "Info") {
|
||||
$store.commit("snackbar", {
|
||||
store.commit("snackbar", {
|
||||
component,
|
||||
vbind: {
|
||||
content: typeof content === "string" ? content : JSON.stringify(content),
|
||||
@@ -315,8 +316,8 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
};
|
||||
|
||||
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) {
|
||||
|
||||
@@ -12,10 +12,10 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
];
|
||||
|
||||
const store = useStore();
|
||||
const { $copy, $updateSeriesFields, $snackbar, $store, $remove, $dialog } = nuxtApp;
|
||||
const { $copy, $updateSeriesFields, $snackbar, $remove, $dialog } = nuxtApp;
|
||||
|
||||
const requestLogin = function () {
|
||||
$store.commit("login", undefined);
|
||||
store.commit("login", undefined);
|
||||
window.location.href = `https://${mode === "dev" ? "dev." : ""}login.utopia.com.vn/signin?module=${module}&link=${window.location.origin}`;
|
||||
};
|
||||
|
||||
@@ -47,7 +47,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
if (found) {
|
||||
const apiWithReady = {
|
||||
...$copy(found),
|
||||
ready: Boolean($store[apiName]),
|
||||
ready: Boolean(store[apiName]),
|
||||
};
|
||||
apisWithReady.push(apiWithReady);
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
const api = apis.find((api) => api.name === v.name);
|
||||
const url = getpath(v.path) + (v.url || api.url);
|
||||
const params = v.params || api.params || {};
|
||||
params.login = $store.login?.id;
|
||||
params.login = store.login?.id;
|
||||
return { url, params };
|
||||
});
|
||||
const data = await Promise.all(arr.map(({ url, params }) => $fetch(url, { params })));
|
||||
@@ -69,7 +69,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
list[i].data = v;
|
||||
if (list[i].commit) {
|
||||
const data = v.rows ? v.rows : v;
|
||||
$store.commit(list[i].commit, data);
|
||||
store.commit(list[i].commit, data);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
@@ -85,8 +85,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
const insertapi = async function (name, { data, values, notify = true } = {}) {
|
||||
try {
|
||||
const api = findapi(name);
|
||||
const curpath = api.path ? paths.find((x) => x.name === api.path).url : path;
|
||||
const curpath = getpath(api.path);
|
||||
let rs;
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
rs = await $fetch(`${curpath}import-data/${api.url.substring(5, api.url.length - 1)}/`, {
|
||||
method: "POST",
|
||||
@@ -102,8 +103,8 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
// update store
|
||||
if (api.commit) {
|
||||
if ($store[api.commit]) {
|
||||
const copy = $copy($store[api.commit]);
|
||||
if (store[api.commit]) {
|
||||
const copy = $copy(store[api.commit]);
|
||||
const rows = Array.isArray(rs) ? rs : [rs];
|
||||
rows.forEach((v) => {
|
||||
if (v.id && !v.error) {
|
||||
@@ -112,12 +113,12 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
else copy.push(v);
|
||||
}
|
||||
});
|
||||
$store.commit(api.commit, copy);
|
||||
store.commit(api.commit, copy);
|
||||
}
|
||||
}
|
||||
if (notify) {
|
||||
$snackbar(
|
||||
$store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
|
||||
store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
|
||||
"Success",
|
||||
);
|
||||
}
|
||||
@@ -144,9 +145,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
});
|
||||
|
||||
if (api.commit) {
|
||||
const index = $store[api.commit] ? $store[api.commit].findIndex((v) => v.id === rs.id) : -1;
|
||||
const index = store[api.commit] ? store[api.commit].findIndex((v) => v.id === rs.id) : -1;
|
||||
if (index >= 0) {
|
||||
const copy = $copy($store[api.commit]);
|
||||
const copy = $copy(store[api.commit]);
|
||||
if (Array.isArray(rs)) {
|
||||
rs.forEach((r) => {
|
||||
const index = copy.findIndex((v) => v.id === r.id);
|
||||
@@ -155,13 +156,13 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
} else {
|
||||
copy[index] = rs;
|
||||
}
|
||||
$store.commit(api.commit, copy);
|
||||
store.commit(api.commit, copy);
|
||||
}
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
$snackbar(
|
||||
$store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
|
||||
store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
|
||||
"Success",
|
||||
);
|
||||
}
|
||||
@@ -173,7 +174,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
};
|
||||
|
||||
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++) {
|
||||
@@ -196,7 +197,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
} else {
|
||||
result = doFind(copy);
|
||||
}
|
||||
$store.commit("pagetrack", copy);
|
||||
store.commit("pagetrack", copy);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -221,7 +222,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
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);
|
||||
@@ -234,7 +235,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
copy.api = copyApi;
|
||||
copy.origin_api = copy;
|
||||
}
|
||||
$store.commit(pagename, copy);
|
||||
store.commit(pagename, copy);
|
||||
return copy;
|
||||
};
|
||||
|
||||
@@ -303,19 +304,19 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
|
||||
const 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 = cloneDeep($store[pagename]);
|
||||
if (result === "error" || !pagename || !store[pagename]) return result;
|
||||
let copy = cloneDeep(store[pagename]);
|
||||
copy.update = { refresh: true };
|
||||
$store.commit(pagename, copy);
|
||||
store.commit(pagename, copy);
|
||||
return result;
|
||||
};
|
||||
|
||||
const updaterow = 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 = cloneDeep($store[pagename]);
|
||||
if (result === "error" || !pagename || !store[pagename]) return result;
|
||||
let copy = cloneDeep(store[pagename]);
|
||||
copy.update = { refresh: true };
|
||||
$store.commit(pagename, copy);
|
||||
store.commit(pagename, copy);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -335,7 +336,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
});
|
||||
|
||||
if (api.commit) {
|
||||
const copy = $copy($store[api.commit]);
|
||||
const copy = $copy(store[api.commit]);
|
||||
if (Array.isArray(id)) {
|
||||
rs.forEach((element) => {
|
||||
const index = copy.findIndex((v) => v.id === element.id);
|
||||
@@ -345,7 +346,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
const index = copy.findIndex((v) => v.id === id);
|
||||
if (index >= 0) $remove(copy, index);
|
||||
}
|
||||
$store.commit(api.name, copy);
|
||||
store.commit(api.name, copy);
|
||||
}
|
||||
return id;
|
||||
} catch (err) {
|
||||
@@ -375,16 +376,16 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
|
||||
const deleterow = async function (name, id, pagename) {
|
||||
const result = await deleteapi(name, id);
|
||||
if (result === "error" || !pagename || !$store[pagename]) return result;
|
||||
const copy = cloneDeep($store[pagename]);
|
||||
if (result === "error" || !pagename || !store[pagename]) return result;
|
||||
const copy = cloneDeep(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 = cloneDeep($store[pagename]);
|
||||
let copy = cloneDeep(store[pagename]);
|
||||
let rows = Array.isArray(row) ? row : [row];
|
||||
rows.map((x) => {
|
||||
let idx = copy.data.findIndex((v) => v.id === x.id);
|
||||
@@ -395,7 +396,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
}
|
||||
});
|
||||
copy.update = { data: copy.data };
|
||||
$store.commit(pagename, copy);
|
||||
store.commit(pagename, copy);
|
||||
};
|
||||
|
||||
const buildFileUrl = (file) => {
|
||||
@@ -476,31 +477,32 @@ export default defineNuxtPlugin((nuxtApp) => {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
const getEditRights = (right = "edit", { code, category } = {}) => {
|
||||
return true;
|
||||
if (!["edit", "view"].includes(right)) throw new Error(`right ${right} is not one of ['edit', 'view']`);
|
||||
|
||||
const getRight = (rightObj) => {
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user