This commit is contained in:
Viet An
2026-06-04 13:57:27 +07:00
parent 2981d9790a
commit 2a1f85c2af
44 changed files with 99 additions and 102 deletions

View File

@@ -315,8 +315,8 @@ async function update() {
data.link = arr1.length === 0 ? null : arr1; data.link = arr1.length === 0 ? null : arr1;
let api = $findapi("useraction"); let api = $findapi("useraction");
record = data.id record = data.id
? await $updateapi("useraction", data, api.params.values) ? await $updateapi("useraction", { data, values: api.params.values })
: await $insertapi("useraction", data, api.params.values); : await $insertapi("useraction", { data, values: api.params.values });
getValue(); getValue();
} }
async function removeImage(v, i) { async function removeImage(v, i) {

View File

@@ -119,7 +119,7 @@ export default {
data = this.$copy(this.current); data = this.$copy(this.current);
data.detail = this.detail; data.detail = this.detail;
} }
let rs = data.id ? await this.$updateapi(this.api, data) : await this.$insertapi(this.api, data); let rs = data.id ? await this.$updateapi(this.api, data) : await this.$insertapi(this.api, { data });
if (!rs) return; if (!rs) return;
this.detail = undefined; this.detail = undefined;
if (this.current) { if (this.current) {

View File

@@ -270,7 +270,9 @@ async function update() {
if (!record.value.creator) record.value.creator = store.login.id; if (!record.value.creator) record.value.creator = store.login.id;
record.value.updater = store.login.id; record.value.updater = store.login.id;
record.update_time = new Date(); record.update_time = new Date();
let rs = record.value.id ? await $updateapi("company", record.value) : await $insertapi("company", record.value); let rs = record.value.id
? await $updateapi("company", record.value)
: await $insertapi("company", { data: record.value });
if (rs === "error") return; if (rs === "error") return;
if (!record.value.id) $snackbar(`Khách hàng đã được khởi tạo với mã <b>${rs.code}</b>`, "Success"); if (!record.value.id) $snackbar(`Khách hàng đã được khởi tạo với mã <b>${rs.code}</b>`, "Success");
record.value.id = rs.id; record.value.id = rs.id;

View File

@@ -567,7 +567,7 @@ async function update() {
customerData.update_time = new Date(); customerData.update_time = new Date();
let res = isNewCustomer.value let res = isNewCustomer.value
? await $insertapi("customer", customerData, undefined, false) ? await $insertapi("customer", { data: customerData, notify: false })
: await $patchapi("customer", customerData, undefined, false); : await $patchapi("customer", customerData, undefined, false);
if (!res || res === "error") return; if (!res || res === "error") return;
@@ -579,7 +579,7 @@ async function update() {
indPayload.customer = customerId; indPayload.customer = customerId;
if (individualData.value.id) if (individualData.value.id)
await $patchapi("individual", { ...indPayload, id: individualData.value.id }, undefined, false); await $patchapi("individual", { ...indPayload, id: individualData.value.id }, undefined, false);
else await $insertapi("individual", indPayload, undefined, false); else await $insertapi("individual", { data: indPayload, notify: false });
} else if (isOrganization.value) { } else if (isOrganization.value) {
let orgPayload = $resetNull({ ...organizationData.value }); let orgPayload = $resetNull({ ...organizationData.value });
orgPayload.customer = customerId; orgPayload.customer = customerId;
@@ -587,7 +587,7 @@ async function update() {
if (organizationData.value.id) { if (organizationData.value.id) {
orgRes = await $patchapi("organization", { ...orgPayload, id: organizationData.value.id }, undefined, false); orgRes = await $patchapi("organization", { ...orgPayload, id: organizationData.value.id }, undefined, false);
} else { } else {
orgRes = await $insertapi("organization", orgPayload, undefined, false); orgRes = await $insertapi("organization", { data: orgPayload, notify: false });
} }
if (orgRes && orgRes.id) { if (orgRes && orgRes.id) {
organizationId = orgRes.id; organizationId = orgRes.id;
@@ -622,7 +622,7 @@ async function update() {
validLocalPeople.forEach((lp) => { validLocalPeople.forEach((lp) => {
if (!lp.id) { if (!lp.id) {
const payload = { ...lp, ...commonPayload }; const payload = { ...lp, ...commonPayload };
$insertapi(apiName, payload); $insertapi(apiName, { data: payload });
} }
}); });
@@ -638,12 +638,10 @@ async function update() {
// Ảnh // Ảnh
if (record.value.image && record.value.image.length > 0) { if (record.value.image && record.value.image.length > 0) {
await $insertapi( await $insertapi("customerfile", {
"customerfile", data: record.value.image.map((v) => ({ ref: customerId, file: v })),
record.value.image.map((v) => ({ ref: customerId, file: v })), notify: false,
undefined, });
false,
);
} }
const completeData = await $getdata("customer", { id: customerId }, undefined, true); const completeData = await $getdata("customer", { id: customerId }, undefined, true);

View File

@@ -169,7 +169,7 @@ async function createCustomer() {
} }
const customerData = $resetNull({ ...record.value }); const customerData = $resetNull({ ...record.value });
const res = await $insertapi("customer", customerData, undefined, false); const res = await $insertapi("customer", { data: customerData, notify: false });
if (!res || res === "error") return; if (!res || res === "error") return;
const completedData = await $getdata("customer", { const completedData = await $getdata("customer", {

View File

@@ -162,7 +162,7 @@ async function saveSetting() {
msg: "Tên thiết lập không được bỏ trống", msg: "Tên thiết lập không được bỏ trống",
}); });
} }
result = await $insertapi("usersetting", data); result = await $insertapi("usersetting", { data });
} else { } else {
const updatedSetting = { const updatedSetting = {
...$copy(currentsetting), ...$copy(currentsetting),

View File

@@ -13,7 +13,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const res = await $insertapi("IMEI", body.value); const res = await $insertapi("IMEI", { data: body.value });
isLoading.value = false; isLoading.value = false;
if (res !== "error") { if (res !== "error") {
emit("created"); emit("created");

View File

@@ -81,7 +81,7 @@ async function submit() {
id: productVariant.value.product, id: productVariant.value.product,
...body.value, ...body.value,
}) })
: await $insertapi("product", body.value); : await $insertapi("product", { data: body.value });
if (res !== "error") { if (res !== "error") {
if (refreshData) refreshData(); if (refreshData) refreshData();
} }

View File

@@ -86,8 +86,10 @@ async function submit() {
// 1. insert row to Product_Image, get back id // 1. insert row to Product_Image, get back id
if (uploadedImage.value) { if (uploadedImage.value) {
const productImage = await $insertapi("Product_Image", { const productImage = await $insertapi("Product_Image", {
name: uploadedImage.value.name, data: {
path: $buildFileUrl(uploadedImage.value.file), name: uploadedImage.value.name,
path: $buildFileUrl(uploadedImage.value.file),
},
}); });
body.value.image = productImage.id; body.value.image = productImage.id;
} }
@@ -99,7 +101,7 @@ async function submit() {
id: props.variantId, id: props.variantId,
...trimmedBody, ...trimmedBody,
}) })
: await $insertapi("Product_Variant", trimmedBody); : await $insertapi("Product_Variant", { data: trimmedBody });
if (res !== "error") { if (res !== "error") {
if (refreshData) refreshData(); if (refreshData) refreshData();
} }

View File

@@ -47,15 +47,17 @@ async function submit() {
// 1. insert row to Product_Image, get back id // 1. insert row to Product_Image, get back id
if (uploadedImage.value) { if (uploadedImage.value) {
const productImage = await $insertapi("Product_Image", { const productImage = await $insertapi("Product_Image", {
name: uploadedImage.value.name, data: {
path: $buildFileUrl(uploadedImage.value.file), name: uploadedImage.value.name,
path: $buildFileUrl(uploadedImage.value.file),
},
}); });
body.value.image = productImage.id; body.value.image = productImage.id;
} }
// 2. upload to Product_Variant table // 2. upload to Product_Variant table
const trimmedBody = omitBy(body.value, $empty); const trimmedBody = omitBy(body.value, $empty);
const res = await $insertapi("Product_Variant", trimmedBody); const res = await $insertapi("Product_Variant", { data: trimmedBody });
if (res !== "error") { if (res !== "error") {
if (refreshData) refreshData(); if (refreshData) refreshData();
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Battery", body.value); const newRow = await $insertapi("Battery", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("CPU", body.value); const newRow = await $insertapi("CPU", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Camera_System", body.value); const newRow = await $insertapi("Camera_System", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Charging_Technology", body.value); const newRow = await $insertapi("Charging_Technology", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Color", body.value); const newRow = await $insertapi("Color", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Design", body.value); const newRow = await $insertapi("Design", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -10,7 +10,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("External_Storage", body.value); const newRow = await $insertapi("External_Storage", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -10,7 +10,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("GPU", body.value); const newRow = await $insertapi("GPU", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -10,7 +10,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("IP_Rating", body.value); const newRow = await $insertapi("IP_Rating", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -12,7 +12,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Internal_Storage", body.value); const newRow = await $insertapi("Internal_Storage", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -10,7 +10,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Manufacturer", body.value); const newRow = await $insertapi("Manufacturer", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -10,7 +10,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Network_Technology", body.value); const newRow = await $insertapi("Network_Technology", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -11,7 +11,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("OS", body.value); const newRow = await $insertapi("OS", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;

View File

@@ -12,7 +12,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("RAM", body.value); const newRow = await $insertapi("RAM", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -13,7 +13,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("SIM", body.value); const newRow = await $insertapi("SIM", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -16,7 +16,7 @@ const body = ref({
async function submit() { async function submit() {
isLoading.value = true; isLoading.value = true;
const newRow = await $insertapi("Screen", body.value); const newRow = await $insertapi("Screen", { data: body.value });
emit("modalevent", { name: "dataevent", data: newRow }); emit("modalevent", { name: "dataevent", data: newRow });
isLoading.value = false; isLoading.value = false;
} }

View File

@@ -176,7 +176,7 @@ const handleSave = async () => {
...props.data, ...props.data,
name: templateName.value, name: templateName.value,
}; };
response = await $insertapi("Email_Template", insertData); response = await $insertapi("Email_Template", { data: insertData });
} }
if (response && response !== "error") { if (response && response !== "error") {

View File

@@ -533,16 +533,14 @@ const handleSendEmail = async () => {
}); });
} }
const response = await nuxtApp.$insertapi( const response = await nuxtApp.$insertapi("sendemail", {
"sendemail", data: {
{
to: formData.value.content.receiver, to: formData.value.content.receiver,
content: finalEmailHtml, content: finalEmailHtml,
subject: formData.value.content.subject || "Thông báo từ BigDataTech", subject: formData.value.content.subject || "Thông báo từ BigDataTech",
}, },
undefined, notify: false,
false, });
);
if (response !== null) { if (response !== null) {
$snackbar(`Email sent successfully! Sent to ${formData.value.content.receiver.split(";").length} recipient(s)`); $snackbar(`Email sent successfully! Sent to ${formData.value.content.receiver.split(";").length} recipient(s)`);

View File

@@ -173,16 +173,14 @@ const handleSendEmail = async () => {
}); });
} }
const response = await $insertapi( const response = await $insertapi("sendemail", {
"sendemail", data: {
{
to: paymentScheduleItem.value?.txn_detail__transaction__customer__email, to: paymentScheduleItem.value?.txn_detail__transaction__customer__email,
content: finalEmailHtml, content: finalEmailHtml,
subject: replaceTemplateVars(templateProps.value.content.subject) || "Thông báo từ Utopia Villas & Resort", subject: replaceTemplateVars(templateProps.value.content.subject) || "Thông báo từ Utopia Villas & Resort",
}, },
undefined, notify: false,
false, });
);
if (response !== null) { if (response !== null) {
isLoading.value = false; isLoading.value = false;
$snackbar( $snackbar(

View File

@@ -83,7 +83,7 @@ export default {
form.append("type", "image"); form.append("type", "image");
form.append("size", 100); form.append("size", 100);
form.append("user", this.$store.state.login.id); form.append("user", this.$store.state.login.id);
let result = await this.$insertapi("upload", form); let result = await this.$insertapi("upload", { data: form });
if (result === "error") return; if (result === "error") return;
let row = result.rows[0]; let row = result.rows[0];
const file = new File([blod], name, { type: "image/png" }); const file = new File([blod], name, { type: "image/png" });

View File

@@ -129,7 +129,7 @@ export default {
form.append("type", "file"); form.append("type", "file");
form.append("size", this.selected.size); form.append("size", this.selected.size);
form.append("user", this.$store.state.login.id); form.append("user", this.$store.state.login.id);
let result = await this.$insertapi("upload", form); let result = await this.$insertapi("upload", { data: form });
this.loading = false; this.loading = false;
if (result === "error") return; if (result === "error") return;
this.$emit("modalevent", { name: "image", data: result.rows[0] }); this.$emit("modalevent", { name: "image", data: result.rows[0] });

View File

@@ -70,7 +70,7 @@ export default {
return { ref: this.row.id, file: v.id }; return { ref: this.row.id, file: v.id };
}); });
let found = this.$findapi(this.api); let found = this.$findapi(this.api);
let rs = await this.$insertapi(this.api, arr, found.params.values); let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values });
if (rs !== "error") { if (rs !== "error") {
this.files = this.files.concat(rs); this.files = this.files.concat(rs);
this.vbind = undefined; this.vbind = undefined;

View File

@@ -54,7 +54,7 @@ export default {
return { ref: this.row.id, file: v.id }; return { ref: this.row.id, file: v.id };
}); });
let found = this.$findapi(this.api); let found = this.$findapi(this.api);
let rs = await this.$insertapi(this.api, arr, found.params.values); let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values });
if (rs === "error") return; if (rs === "error") return;
this.files = this.files.concat(rs); this.files = this.files.concat(rs);
this.$store.commit("updateState", { this.$store.commit("updateState", {

View File

@@ -80,7 +80,7 @@ export default {
return { ref: this.row.id, file: v.id }; return { ref: this.row.id, file: v.id };
}); });
let found = this.$findapi(this.api); let found = this.$findapi(this.api);
let rs = await this.$insertapi(this.api, arr, found.params.values); let rs = await this.$insertapi(this.api, { data: arr, values: found.params.values });
if (rs === "error") return; if (rs === "error") return;
this.files = this.files.concat(rs); this.files = this.files.concat(rs);
if (this.pagename) { if (this.pagename) {

View File

@@ -275,7 +275,7 @@ async function attachFiles(files) {
product: isForProduct.value ? product.id : undefined, product: isForProduct.value ? product.id : undefined,
})); }));
const result = await $insertapi(isForProduct.value ? "productfile" : "projectfile", payload); const result = await $insertapi(isForProduct.value ? "productfile" : "projectfile", { data: payload });
if (result === "error") { if (result === "error") {
throw new Error("Không thể liên kết tệp"); throw new Error("Không thể liên kết tệp");
} }

View File

@@ -349,14 +349,14 @@ export default {
form.append("type", "image"); form.append("type", "image");
form.append("size", 100); form.append("size", 100);
form.append("user", this.$store.login.id); form.append("user", this.$store.login.id);
let result = await this.$insertapi("upload", form); let result = await this.$insertapi("upload", { data: form });
if (result === "error") return; if (result === "error") return;
this.updateImage(result.rows[0]); this.updateImage(result.rows[0]);
this.showUrl = false; this.showUrl = false;
}, },
async uploadImage(file) { async uploadImage(file) {
this.loading = true; this.loading = true;
let result = await this.$insertapi("upload", file.form); let result = await this.$insertapi("upload", { data: file.form });
this.data.splice(0, 0, result.rows[0]); this.data.splice(0, 0, result.rows[0]);
this.loading = false; this.loading = false;
}, },

View File

@@ -56,7 +56,7 @@ if (!found) upload();
async function doUpload(v, i) { async function doUpload(v, i) {
const file = props.files[i]; const file = props.files[i];
const rs = await $insertapi("upload", file.form, undefined, false); const rs = await $insertapi("upload", { data: file.form, notify: false });
v.status = rs === "error" ? "error" : "success"; v.status = rs === "error" ? "error" : "success";
vfiles.value[i] = v; vfiles.value[i] = v;
const obj = rs.rows[0]; const obj = rs.rows[0];

View File

@@ -205,7 +205,7 @@ export default {
this.msgInfo.push({ message, type: "error" }); this.msgInfo.push({ message, type: "error" });
return (this.isloading = false); return (this.isloading = false);
} }
let result = await this.$insertapi("upload", thefile.form, undefined, false); let result = await this.$insertapi("upload", { data: thefile.form, notify: false });
if (result === "error") { if (result === "error") {
const message = this.$find( const message = this.$find(
this.$store.syspara, this.$store.syspara,
@@ -393,7 +393,7 @@ export default {
}; };
try { try {
const rs = await this.$insertapi("findkey", payload, undefined, false); const rs = await this.$insertapi("findkey", { data: payload, notify: false });
if (rs === "error") throw new Error(); if (rs === "error") throw new Error();
else { else {
this.data = rs.data; this.data = rs.data;
@@ -539,7 +539,7 @@ export default {
file: this.fileInfo.name, file: this.fileInfo.name,
fields: this.setting.detail, fields: this.setting.detail,
}; };
await this.$insertapi("importlog", importLogPayload); await this.$insertapi("importlog", { data: importLogPayload });
const interval = setInterval(() => this.getResult(importLogPayload.code), 2000); const interval = setInterval(() => this.getResult(importLogPayload.code), 2000);
// Lọc bản ghi KHÔNG có id (bản ghi mới) // Lọc bản ghi KHÔNG có id (bản ghi mới)
@@ -553,14 +553,12 @@ export default {
// Gửi lên API - Backend sẽ INSERT // Gửi lên API - Backend sẽ INSERT
let result; let result;
if (this.setting.call_api) { if (this.setting.call_api) {
result = await this.$insertapi( result = await this.$insertapi(this.setting.call_api, {
this.setting.call_api, data: { data: filter, user: this.$store.login.id },
{ data: filter, user: this.$store.login.id }, notify: importLogPayload.code,
undefined, });
importLogPayload.code,
);
} else { } else {
result = await this.$insertapi(this.setting.api, filter, undefined, importLogPayload.code); result = await this.$insertapi(this.setting.api, { data: filter, notify: importLogPayload.code });
} }
this.isloading = false; this.isloading = false;
@@ -640,7 +638,7 @@ export default {
file: this.fileInfo.name, file: this.fileInfo.name,
fields: this.setting.detail, fields: this.setting.detail,
}; };
await this.$insertapi("importlog", importlogPayload); await this.$insertapi("importlog", { data: importlogPayload });
const interval = setInterval(() => this.getResult(importlogPayload.code), 2000); const interval = setInterval(() => this.getResult(importlogPayload.code), 2000);
// Lọc bản ghi CÓ id (bản ghi tồn tại) VÀ KHÔNG CÓ LỖI // Lọc bản ghi CÓ id (bản ghi tồn tại) VÀ KHÔNG CÓ LỖI
@@ -652,12 +650,10 @@ export default {
this.total = filter.length; this.total = filter.length;
// Gửi lên API - Backend sẽ UPDATE // Gửi lên API - Backend sẽ UPDATE
const result = await this.$insertapi( const result = await this.$insertapi(this.setting.call_api || this.setting.api, {
this.setting.call_api || this.setting.api, data: filter,
filter, notify: importlogPayload.code,
undefined, });
importlogPayload.code,
);
this.isloading = false; this.isloading = false;
clearInterval(interval); clearInterval(interval);
this.getResult(importlogPayload.code); this.getResult(importlogPayload.code);

View File

@@ -362,14 +362,14 @@ async function update() {
record.value.updater_time = new Date(); record.value.updater_time = new Date();
let rs = record.value.id let rs = record.value.id
? await $updateapi("people", record.value) ? await $updateapi("people", record.value)
: await $insertapi("people", record.value, undefined, false); : await $insertapi("people", { data: record.value, notify: false });
if (rs === "error") return; if (rs === "error") return;
if (!record.value.id) $snackbar(`Người liên quan đã được khởi tạo với mã <b>${rs.code}</b>`, "Success"); if (!record.value.id) $snackbar(`Người liên quan đã được khởi tạo với mã <b>${rs.code}</b>`, "Success");
record.value.id = rs.id; record.value.id = rs.id;
if (record.value.image ? record.value.image.length > 0 : false) { if (record.value.image ? record.value.image.length > 0 : false) {
let arr = []; let arr = [];
record.image.map((v) => arr.push({ ref: record.value.id, file: v })); record.image.map((v) => arr.push({ ref: record.value.id, file: v }));
await $insertapi("customerfile", arr, undefined, false); await $insertapi("customerfile", { data: arr, notify: false });
} }
let ele = await $getdata("people", { first: true, filter: { id: rs.id } }); let ele = await $getdata("people", { first: true, filter: { id: rs.id } });
emit("update", ele); emit("update", ele);

View File

@@ -158,7 +158,7 @@ export default {
name: "currpass", name: "currpass",
text: "Incorrect password.", text: "Incorrect password.",
}); });
let rs0 = await this.$insertapi("gethash", { text: this.password }, undefined, false); let rs0 = await this.$insertapi("gethash", { data: { text: this.password }, notify: false });
user.password = rs0.rows[0]; user.password = rs0.rows[0];
let rs = await this.$updateapi("user", user, undefined, false); let rs = await this.$updateapi("user", user, undefined, false);
if (rs !== "error") { if (rs !== "error") {

View File

@@ -169,7 +169,7 @@ export default {
}); });
if (rows.length === 0) return; if (rows.length === 0) return;
rows.forEach((v) => (v.expiry = 1)); rows.forEach((v) => (v.expiry = 1));
this.$insertapi("token", rows, undefined, true); this.$insertapi("token", { data: rows });
}, },
}, },
}; };

View File

@@ -319,7 +319,7 @@ export default {
}, },
async createAccount() { async createAccount() {
if (this.checkError()) return; if (this.checkError()) return;
let rs = await this.$insertapi("gethash", { text: this.password }); let rs = await this.$insertapi("gethash", { data: { text: this.password } });
this.hash = rs.rows[0]; this.hash = rs.rows[0];
let data = await this.$getdata("user", { first: true, filter: { username: this.username } }); let data = await this.$getdata("user", { first: true, filter: { username: this.username } });
if (data) { if (data) {
@@ -342,7 +342,7 @@ export default {
if (this.user === "error") return; if (this.user === "error") return;
// add rights // add rights
//let arr = this.$filter(this.common, {category: 'topmenu'}).map(v=>{return {user: this.user.id, function: v.id}}) //let arr = this.$filter(this.common, {category: 'topmenu'}).map(v=>{return {user: this.user.id, function: v.id}})
//let result = await this.$insertapi('userrights', arr) //let result = await this.$insertapi('userrights', { data: arr })
//this.$dialog('Account created successfully.', 'Success', 'Success', 10) //this.$dialog('Account created successfully.', 'Success', 'Success', 10)
this.$emit("close"); this.$emit("close");
}, },

View File

@@ -108,7 +108,7 @@ export default {
first: true, first: true,
params: { filter: { id: this.row.id } }, params: { filter: { id: this.row.id } },
}); });
let rs = await this.$insertapi("gethash", { text: this.password }); let rs = await this.$insertapi("gethash", { data: { text: this.password } });
user.password = rs.rows[0]; user.password = rs.rows[0];
let rs1 = await this.$updateapi("user", user); let rs1 = await this.$updateapi("user", user);
if (rs1 !== "error") this.$emit("close"); if (rs1 !== "error") this.$emit("close");

View File

@@ -1160,43 +1160,44 @@ export default defineNuxtPlugin((nuxtApp) => {
}; };
// insert data // insert data
const insertapi = async function (name, data, values, notify) { const insertapi = async function (name, { data, values, notify = true } = {}) {
try { try {
const found = findapi(name); const api = findapi(name);
const curpath = found.path ? paths.find((x) => x.name === found.path).url : path; const curpath = api.path ? paths.find((x) => x.name === api.path).url : path;
let rs; let rs;
if (Array.isArray(data)) { if (Array.isArray(data)) {
rs = await $fetch(`${curpath}import-data/${found.url.substring(5, found.url.length - 1)}/`, { rs = await $fetch(`${curpath}import-data/${api.url.substring(5, api.url.length - 1)}/`, {
method: "POST", method: "POST",
body: data, body: data,
params: { values, action: "import" }, params: { values, action: "import" },
}); });
} else { } else {
rs = await $fetch(`${curpath}${found.url}`, { rs = await $fetch(`${curpath}${api.url}`, {
method: "POST", method: "POST",
body: data, body: data,
params: { values }, params: { values },
}); });
} }
// update store // update store
if (found.commit) { if (api.commit) {
if ($store[found.commit]) { if ($store[api.commit]) {
const copy = $copy($store[found.commit]); const copy = $copy($store[api.commit]);
const rows = Array.isArray(rs) ? rs : [rs]; const rows = Array.isArray(rs) ? rs : [rs];
rows.forEach((v) => { rows.forEach((v) => {
if (v.id && !v.error) { if (v.id && !v.error) {
let idx = copy.findIndex((x) => x.id === v.id); const idx = copy.findIndex((x) => x.id === v.id);
if (idx >= 0) copy[idx] = v; if (idx >= 0) copy[idx] = v;
else copy.push(v); else copy.push(v);
} }
}); });
$store.commit(found.commit, copy); $store.commit(api.commit, copy);
} }
} }
if (notify !== false) { if (notify) {
$store.lang === "en" $snackbar(
? $snackbar("Data has been successfully saved to the system.", "Success") $store.lang === "en" ? "Data has been successfully saved to the system." : "Dữ liệu đã được lưu vào hệ thống",
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success"); "Success",
);
} }
return rs; return rs;
} catch (err) { } catch (err) {
@@ -1394,8 +1395,8 @@ export default defineNuxtPlugin((nuxtApp) => {
}; };
// insert row // insert row
var insertrow = async function (name, data, values, pagename, notify) { const insertrow = async function (name, data, values, pagename, notify) {
let result = await insertapi(name, data, values, notify); let result = await insertapi(name, { data, values, notify });
if (result === "error" || !pagename || !$store[pagename]) return result; if (result === "error" || !pagename || !$store[pagename]) return result;
let copy = $clone($store[pagename]); let copy = $clone($store[pagename]);
copy.update = { refresh: true }; copy.update = { refresh: true };