This commit is contained in:
Viet An
2026-06-10 15:39:58 +07:00
parent 22c284f1ef
commit d0b12dc647
11 changed files with 305 additions and 283 deletions

View File

@@ -21,7 +21,7 @@ export default defineNuxtPlugin((nuxtApp) => {
};
/**
* @param {ApiName | ApiName[]} apiNames
* @param {ApiName | ApiName[]} name
*/
const findapi = function (name) {
const result = Array.isArray(name)
@@ -322,19 +322,20 @@ export default defineNuxtPlugin((nuxtApp) => {
*/
const deleteapi = async function (name, id) {
try {
const found = findapi(name);
const api = findapi(name);
let rs;
if (!Array.isArray(id)) {
rs = await $fetch(`${path}${found.url_detail}${id}`, {
rs = await $fetch(`${path}${api.url_detail}${id}`, {
method: "delete",
});
} else {
rs = await $fetch(`${path}import-data/${found.url.substring(5, found.url.length - 1)}/`, id, {
rs = await $fetch(`${path}import-data/${api.url.substring(5, api.url.length - 1)}/`, {
params: { action: "delete" },
body: id.map((id) => ({ id })),
});
}
if (found.commit) {
const copy = $copy($store[found.commit]);
if (api.commit) {
const copy = $copy($store[api.commit]);
if (!Array.isArray(id)) {
const index = copy.findIndex((v) => v.id === id);
if (index >= 0) $remove(copy, index);
@@ -344,13 +345,13 @@ export default defineNuxtPlugin((nuxtApp) => {
if (index >= 0) $remove(copy, index);
});
}
$store.commit(found.name, copy);
$store.commit(api.name, copy);
}
return id;
} catch (err) {
console.error(err);
if (err.response) {
let content = `<span>Đã xảy ra lỗi, xóa dữ liệu không thành công</span>`;
let content = `<p>Đã xảy ra lỗi, xóa dữ liệu không thành công.</p>`;
if (err.response.data)
content += `<p class="mt-2 has-text-grey-dark">
<sapn class="icon-text">Chi tiết<SvgIcon class="ml-1" v-bind="{name: 'right.svg', type: 'dark', size: 20}"></SvgIcon></span></p>