This commit is contained in:
Viet An
2026-05-20 15:48:05 +07:00
parent 087b05a0b8
commit a52c33706a
20 changed files with 86 additions and 106 deletions

View File

@@ -106,9 +106,7 @@ async function download() {
if (!svg) { if (!svg) {
console.error("QR Code SVG element not found after waiting."); console.error("QR Code SVG element not found after waiting.");
$snackbar(isVietnamese.value ? "Không tìm thấy mã QR để tải xuống." : "QR Code not found for download.", { $snackbar(isVietnamese.value ? "Không tìm thấy mã QR để tải xuống." : "QR Code not found for download.", "Error");
type: "is-danger",
});
return; return;
} }
@@ -135,7 +133,7 @@ async function download() {
linkElement.click(); linkElement.click();
URL.revokeObjectURL(url); URL.revokeObjectURL(url);
$snackbar(isVietnamese.value ? "Đã tải xuống mã QR!" : "QR Code downloaded!", { type: "is-success" }); $snackbar(isVietnamese.value ? "Đã tải xuống mã QR!" : "QR Code downloaded!", "Error");
}; };
image.src = url; image.src = url;
} }

View File

@@ -269,7 +269,7 @@ async function update() {
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", 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>`, "Thành công", "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;
let ele = await $getdata("company", { id: rs.id }, null, true); let ele = await $getdata("company", { id: rs.id }, null, true);
emit("update", ele); emit("update", ele);

View File

@@ -712,7 +712,7 @@ async function update() {
} }
if (rs === "error") { if (rs === "error") {
$snackbar("Có lỗi xảy ra khi lưu dữ liệu", "Lỗi", "Error"); $snackbar("Có lỗi xảy ra khi lưu dữ liệu", "Error");
return; return;
} }
record.value.id = rs.id; record.value.id = rs.id;
@@ -725,7 +725,6 @@ async function update() {
`${ `${
isVietnamese.value ? "Khách hàng đã được khởi tạo với mã" : "Customer has been created with code" isVietnamese.value ? "Khách hàng đã được khởi tạo với mã" : "Customer has been created with code"
} <b>${rs.code}</b>`, } <b>${rs.code}</b>`,
"Thành công",
"Success", "Success",
); );
} else { } else {
@@ -733,7 +732,6 @@ async function update() {
`${ `${
isVietnamese.value ? "Khách hàng đã được cập nhật với mã" : "Customer has been updated with code" isVietnamese.value ? "Khách hàng đã được cập nhật với mã" : "Customer has been updated with code"
} <b>${rs.code}</b>`, } <b>${rs.code}</b>`,
"Thành công",
"Success", "Success",
); );
} }

View File

@@ -345,7 +345,7 @@ export default {
}, },
copy(value) { copy(value) {
this.$copyToClipboard(value); this.$copyToClipboard(value);
this.$snackbar("Đã copy vào clipboard.", "Copy", "Success"); this.$snackbar("Đã copy vào clipboard", "Success");
}, },
openPhone() { openPhone() {
this.showmodal = { this.showmodal = {

View File

@@ -177,7 +177,7 @@ async function saveSetting() {
copy[idx] = result; copy[idx] = result;
store.commit("settings", copy); store.commit("settings", copy);
} }
$snackbar("Lưu thiết lập thành công", undefined, "Success"); $snackbar("Lưu thiết lập thành công", "Success");
emit("modalevent", { name: "updatesetting", data: result }); emit("modalevent", { name: "updatesetting", data: result });
emit("close"); emit("close");
} }

View File

@@ -48,7 +48,7 @@ export default {
result = await this.$updateapi(name, record); result = await this.$updateapi(name, record);
} else result = await this.$deleteapi(name, id); } else result = await this.$deleteapi(name, id);
if (result === "error") return this.$dialog("Đã xảy ra lỗi, xóa dữ liệu thất bại", "Lỗi", "Error"); if (result === "error") return this.$dialog("Đã xảy ra lỗi, xóa dữ liệu thất bại", "Lỗi", "Error");
this.$snackbar("Dữ liệu đã được xoá khỏi hệ thống", undefined, "Success"); this.$snackbar("Dữ liệu đã được xoá khỏi hệ thống", "Success");
let arr = Array.isArray(id) ? id : [{ id: id }]; let arr = Array.isArray(id) ? id : [{ id: id }];
let copy = this.$copy(this.$store.state[pagename].data); let copy = this.$copy(this.$store.state[pagename].data);
arr.map((x) => { arr.map((x) => {

View File

@@ -40,10 +40,10 @@ async function saveEditImage() {
}); });
props.loadImages(); props.loadImages();
$snackbar("Đã cập nhật ảnh thành công", "Thành công", "Success"); $snackbar("Đã cập nhật ảnh thành công", "Success");
} catch (error) { } catch (error) {
console.error("Error updating image", error); console.error("Error updating image", error);
$snackbar("Cập nhật ảnh thất bại", "Lỗi", "Error"); $snackbar("Cập nhật ảnh thất bại", "Error");
} }
resetEditRefs(); resetEditRefs();

View File

@@ -284,11 +284,11 @@ async function onUploaded(uploadedFiles) {
if (attachedCount > 0) { if (attachedCount > 0) {
loadImages(); loadImages();
$snackbar(`Đã thêm ${attachedCount} ảnh thành công`, "Thành công", "Success"); $snackbar(`Đã thêm ${attachedCount} ảnh thành công`, "Success");
} }
} catch (error) { } catch (error) {
console.error("Error attaching images:", error); console.error("Error attaching images:", error);
$snackbar("Không thể thêm ảnh, vui lòng thử lại", "Lỗi", "Error"); $snackbar("Không thể thêm ảnh, vui lòng thử lại", "Error");
} }
} }
@@ -297,10 +297,10 @@ async function deleteImage(image) {
await $deleteapi(isForProduct.value ? "productfile" : "projectfile", image.id); await $deleteapi(isForProduct.value ? "productfile" : "projectfile", image.id);
await $deleteapi("file", image.file); await $deleteapi("file", image.file);
loadImages(); loadImages();
$snackbar("Đã xóa ảnh thành công", "Thành công", "Success"); $snackbar("Đã xóa ảnh thành công", "Success");
} catch (error) { } catch (error) {
console.error("Error deleting image:", error); console.error("Error deleting image:", error);
$snackbar("Xóa ảnh không thành công", "Lỗi", "Error"); $snackbar("Xóa ảnh không thành công", "Error");
} }
} }
@@ -317,7 +317,7 @@ async function excel() {
found.url = "exportcsv/File/"; found.url = "exportcsv/File/";
found.params.filter = { code__in: images.value.map((v) => v.file__code) }; found.params.filter = { code__in: images.value.map((v) => v.file__code) };
const rs = await $getapi([found]); const rs = await $getapi([found]);
if (rs === "error") return $snackbar("Đã xảy ra lỗi. Vui lòng thử lại."); if (rs === "error") return $snackbar("Đã xảy ra lỗi. Vui lòng thử lại.", "Error");
const url = window.URL.createObjectURL(new Blob([rs[0].data])); const url = window.URL.createObjectURL(new Blob([rs[0].data]));
const link = document.createElement("a"); const link = document.createElement("a");
const fileName = `${$dayjs(new Date()).format("YYYYMMDDhhmmss")}-data.csv`; const fileName = `${$dayjs(new Date()).format("YYYYMMDDhhmmss")}-data.csv`;

View File

@@ -308,7 +308,7 @@ export default {
setTimeout(() => document.getElementById("url").focus(), 100); setTimeout(() => document.getElementById("url").focus(), 100);
}, },
checkUrl() { checkUrl() {
if (this.$empty(this.url)) return this.$snackbar(`Đường dẫn không hợp lệ`, undefined, "Error"); if (this.$empty(this.url)) return this.$snackbar("Đường dẫn không hợp lệ", "Error");
let self = this; let self = this;
this.loading = true; this.loading = true;
this.$axios this.$axios

View File

@@ -76,11 +76,11 @@ async function confirmChange() {
); );
if (result === "error" || !result) { if (result === "error" || !result) {
$snackbar("Cập nhật thất bại", "Lỗi", "Error"); $snackbar("Cập nhật thất bại", "Error");
return; return;
} }
$snackbar("Cập nhật trạng thái thành công", "Thành công", "Success"); $snackbar("Cập nhật trạng thái thành công", "Success");
// Phát sự kiện để component cha (hoặc bảng) cập nhật lại dữ liệu // Phát sự kiện để component cha (hoặc bảng) cập nhật lại dữ liệu
emit("modalevent", { emit("modalevent", {
@@ -94,7 +94,7 @@ async function confirmChange() {
close(); close();
} catch (error) { } catch (error) {
console.error("Lỗi đổi trạng thái:", error); console.error("Lỗi đổi trạng thái:", error);
$snackbar("Có lỗi xảy ra", "Lỗi", "Error"); $snackbar("Có lỗi xảy ra", "Error");
} finally { } finally {
isSaving.value = false; isSaving.value = false;
} }

View File

@@ -193,7 +193,7 @@ export default {
let thefile = this.$upload(file, "file", 1); let thefile = this.$upload(file, "file", 1);
if (thefile.error) { if (thefile.error) {
this.$snackbar(thefile.text, undefined, "Error"); this.$snackbar(thefile.text, "Error");
return (this.isloading = false); return (this.isloading = false);
} }
if (!(thefile.name.search(".xls") > 0 || thefile.name.search(".xlsx") > 0)) { if (!(thefile.name.search(".xls") > 0 || thefile.name.search(".xlsx") > 0)) {

View File

@@ -361,7 +361,7 @@ async function update() {
? await $updateapi("people", record.value) ? await $updateapi("people", record.value)
: await $insertapi("people", record.value, undefined, false); : await $insertapi("people", record.value, undefined, 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>`, "Thành công", "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 = [];

View File

@@ -203,7 +203,7 @@ export default {
}, },
copy(value) { copy(value) {
this.$copyToClipboard(value); this.$copyToClipboard(value);
this.$snackbar("Đã copy vào clipboard.", "Copy", "Success"); this.$snackbar("Đã copy vào clipboard.", "Success");
}, },
openPhone() { openPhone() {
this.showmodal = { this.showmodal = {

View File

@@ -1,10 +1,12 @@
<template> <template>
<div class="is-flex is-align-items-center is-gap-1"> <div class="is-flex is-align-items-center is-gap-1">
<Icon <div style="width: 18px; height: 18px">
name="material-symbols:cancel-rounded" <Icon
:size="18" name="material-symbols:cancel-rounded"
class="has-text-danger-80" :size="18"
/> class="has-text-danger-80"
/>
</div>
<p <p
v-html="content" v-html="content"
class="control is-expanded" class="control is-expanded"
@@ -14,12 +16,5 @@
<script setup> <script setup>
const props = defineProps({ const props = defineProps({
content: String, content: String,
title: String,
}); });
const { $store } = useNuxtApp();
function cancel() {
$store.commit("updateStore", { name: "showmodal", data: undefined });
}
</script> </script>

View File

@@ -5,10 +5,4 @@
const props = defineProps({ const props = defineProps({
content: String, content: String,
}); });
const { $store } = useNuxtApp();
function cancel() {
$store.commit("updateStore", { name: "showmodal", data: undefined });
}
</script> </script>

View File

@@ -1,34 +1,12 @@
<template>
<div
class="snackbar is-flex is-align-items-center is-gap-3 pl-3 pr-1.5 py-2 rounded-md has-background-grey-25 has-text-white"
>
<component
:is="resolvedComponent"
v-bind="vbind"
@close="$emit('close')"
/>
<button
@click="$emit('close')"
class="button is-ghost is-small"
>
<span class="icon">
<Icon
name="material-symbols:close-rounded"
:size="18"
/>
</span>
</button>
</div>
</template>
<script setup> <script setup>
import { defineAsyncComponent } from "vue"; import { defineAsyncComponent } from "vue";
import { useStore } from "@/stores/index"; import { useStore } from "@/stores/index";
import Info from "@/components/snackbar/Info.vue";
import Success from "@/components/snackbar/Success.vue";
import Error from "@/components/snackbar/Error.vue";
const props = defineProps({ const props = defineProps({
component: String, component: String,
width: String,
height: String,
vbind: Object, vbind: Object,
title: String,
}); });
const store = useStore(); const store = useStore();
@@ -58,6 +36,40 @@ watchEffect(() => {
}); });
setTimeout(() => store.commit("snackbar", undefined), 3900); setTimeout(() => store.commit("snackbar", undefined), 3900);
</script> </script>
<template>
<div
class="snackbar is-flex is-align-items-center is-gap-3 pl-3 pr-1.5 py-2 rounded-md has-background-grey-25 has-text-white"
>
<Info
v-if="component === 'Info'"
v-bind="vbind"
@close="$emit('close')"
/>
<Success
v-if="component === 'Success'"
v-bind="vbind"
@close="$emit('close')"
/>
<Error
v-if="component === 'Error'"
v-bind="vbind"
@close="$emit('close')"
/>
<button
@click="$emit('close')"
class="button is-ghost is-small"
>
<span class="icon">
<Icon
name="material-symbols:close-rounded"
:size="18"
/>
</span>
</button>
</div>
</template>
<style scoped> <style scoped>
.snackbar { .snackbar {
position: fixed; position: fixed;

View File

@@ -1,10 +1,12 @@
<template> <template>
<div class="is-flex is-align-items-center is-gap-1"> <div class="is-flex is-align-items-center is-gap-1">
<Icon <div style="width: 18px; height: 18px">
name="material-symbols:check-circle-rounded" <Icon
:size="18" name="material-symbols:check-circle-rounded"
class="has-text-success-70" :size="18"
/> class="has-text-success-70"
/>
</div>
<p <p
v-html="content" v-html="content"
class="control is-expanded" class="control is-expanded"
@@ -14,12 +16,5 @@
<script setup> <script setup>
const props = defineProps({ const props = defineProps({
content: String, content: String,
title: String,
}); });
const { $store } = useNuxtApp();
function cancel() {
$store.commit("updateStore", { name: "showmodal", data: undefined });
}
</script> </script>

View File

@@ -110,7 +110,7 @@ export default {
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");
else { else {
this.$snackbar("Có lỗi xảy ra. Hãy thử lại một lần nữa", undefined, "Error"); this.$snackbar("Có lỗi xảy ra. Hãy thử lại một lần nữa", "Error");
} }
}, },
checkPassword() { checkPassword() {

View File

@@ -39,25 +39,13 @@ export default defineNuxtPlugin((nuxtApp) => {
$store.commit("showmodal", data); $store.commit("showmodal", data);
}; };
const snackbar = function (content, title, type, width, height) { const snackbar = function (content, component = "Info") {
content = typeof content == "string" ? content : JSON.stringify(content); $store.commit("snackbar", {
component,
const vtitle = vbind: {
type === "Success" content: typeof content == "string" ? content : JSON.stringify(content),
? `<span class="has-text-primary">${title}</span>` },
: type === "Error" });
? `<span class="has-text-danger">${title}</span>`
: title;
const data = {
id: $id(),
component: type || "Info",
vbind: { content },
title: vtitle,
width: width || "600px",
height: height || "100px",
};
$store.commit("snackbar", data);
}; };
const getLink = function (val) { const getLink = function (val) {

View File

@@ -1227,8 +1227,8 @@ export default defineNuxtPlugin((nuxtApp) => {
} }
if (notify !== false) { if (notify !== false) {
$store.lang === "en" $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success") ? $snackbar("Data has been successfully saved to the system.", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success"); : $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success");
} }
return rs; return rs;
} catch (err) { } catch (err) {
@@ -1264,8 +1264,8 @@ export default defineNuxtPlugin((nuxtApp) => {
} }
if (notify !== false) { if (notify !== false) {
$store.lang === "en" $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success") ? $snackbar("Data has been successfully saved to the system.", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success"); : $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success");
} }
return rs; return rs;
} catch (err) { } catch (err) {
@@ -1289,8 +1289,8 @@ export default defineNuxtPlugin((nuxtApp) => {
if (notify !== false) { if (notify !== false) {
$store.lang === "en" $store.lang === "en"
? $snackbar("Data has been successfully saved to the system.", "Success", "Success") ? $snackbar("Data has been successfully saved to the system.", "Success")
: $snackbar("Dữ liệu đã được lưu vào hệ thống", "Thành công", "Success"); : $snackbar("Dữ liệu đã được lưu vào hệ thống", "Success");
} }
return rs; return rs;
} catch (err) { } catch (err) {