This commit is contained in:
Viet An
2026-07-02 09:07:59 +07:00
parent 1fc8532ed8
commit e91f0d22c4
52 changed files with 131 additions and 159 deletions

View File

@@ -79,7 +79,6 @@
import { onMounted, defineAsyncComponent, shallowRef, watchEffect } from "vue"; import { onMounted, defineAsyncComponent, shallowRef, watchEffect } from "vue";
const emit = defineEmits(["close", "remove", "select", "dataevent", "update"]); const emit = defineEmits(["close", "remove", "select", "dataevent", "update"]);
const { $store } = useNuxtApp();
const props = defineProps({ const props = defineProps({
component: String, component: String,

View File

@@ -167,7 +167,7 @@ const props = defineProps({
searchfield: Array, searchfield: Array,
}); });
const { $copy, $dialog, $empty, $find, $findapi, $findIndex, $getdata, $id, $nonAccent, $store } = useNuxtApp(); const { $copy, $dialog, $empty, $find, $findapi, $findIndex, $getdata, $nonAccent, $store } = useNuxtApp();
const emit = defineEmits(["option", "modalevent"]); const emit = defineEmits(["option", "modalevent"]);
const suggestions = ref([]); const suggestions = ref([]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,4 @@
<script setup> <script setup>
const { $dayjs } = useNuxtApp();
const props = defineProps({ const props = defineProps({
date: String, date: String,
}); });

View File

@@ -21,7 +21,7 @@
</template> </template>
<script setup> <script setup>
const emit = defineEmits(["close"]); const emit = defineEmits(["close"]);
const { $store, $getdata, $patchapi, $updatepage } = useNuxtApp(); const { $getdata, $patchapi, $updatepage } = useNuxtApp();
const props = defineProps({ const props = defineProps({
row: Object, row: Object,
pagename: String, pagename: String,

View File

@@ -1,6 +1,5 @@
<script setup> <script setup>
const props = defineProps(["row", "pagename"]); const props = defineProps(["row", "pagename"]);
const { $copyToClipboard } = useNuxtApp();
const phone = props.row.customer__phone || props.row.party__phone || props.row.phone; const phone = props.row.customer__phone || props.row.party__phone || props.row.phone;
const format = (s) => `${s.slice(0, 3)} ${s.slice(3, 6)} ${s.slice(6, 20)}`; const format = (s) => `${s.slice(0, 3)} ${s.slice(3, 6)} ${s.slice(6, 20)}`;

View File

@@ -68,17 +68,14 @@
></Modal> ></Modal>
</template> </template>
<script setup> <script setup>
import { computed, ref } from "vue";
import { useNuxtApp } from "#app";
import CustomerForm from "~/components/customer/CustomerForm.vue"; import CustomerForm from "~/components/customer/CustomerForm.vue";
import CustomerView from "~/components/customer/CustomerView.vue"; import CustomerView from "~/components/customer/CustomerView.vue";
import Modal from "~/components/Modal.vue"; import Modal from "~/components/Modal.vue";
import ImageGallery from "~/components/media/ImageGallery.vue"; import ImageGallery from "~/components/media/ImageGallery.vue";
const nuxtApp = useNuxtApp(); const { $dialog } = useNuxtApp();
const { $dialog } = nuxtApp;
const store = useStore(); const store = useStore();
var props = defineProps({ const props = defineProps({
pagename: String, pagename: String,
row: Object, row: Object,
application: Object, application: Object,
@@ -86,8 +83,7 @@ var props = defineProps({
handleCustomer: Function, handleCustomer: Function,
}); });
const lang = computed(() => store.lang); const isVietnamese = computed(() => store.lang === "vi");
const isVietnamese = computed(() => lang.value === "vi");
const emit = defineEmits(["modalevent", "close"]); const emit = defineEmits(["modalevent", "close"]);
var viewport = 5; var viewport = 5;
var tabs = [ var tabs = [

View File

@@ -282,7 +282,7 @@
</button> </button>
<button <button
class="button is-light" class="button is-light"
@click="exportPdf(docid, { filename: record.code })" @click="$exportPdf(docid, { filename: record.code })"
> >
In thông tin In thông tin
</button> </button>

View File

@@ -438,7 +438,7 @@ const props = defineProps({
filterData: Object, filterData: Object,
width: String, width: String,
}); });
const { $copy, $stripHtml, $arrayMove, $snackbar, $copyToClipboard } = useNuxtApp(); const { $copy, $stripHtml, $arrayMove, $snackbar } = useNuxtApp();
const emit = defineEmits(["modalevent", "changepos", "close"]); const emit = defineEmits(["modalevent", "changepos", "close"]);
const store = useStore(); const store = useStore();
const { colorchoice } = store; const { colorchoice } = store;

View File

@@ -455,7 +455,7 @@
<script setup> <script setup>
import { ref } from "vue"; import { ref } from "vue";
const store = useStore(); const store = useStore();
const { $id, $copy, $empty, $stripHtml, $calc, $remove, $copyToClipboard } = useNuxtApp(); const { $id, $copy, $empty, $calc, $remove, $copyToClipboard } = useNuxtApp();
var props = defineProps({ var props = defineProps({
pagename: String, pagename: String,
field: Object, field: Object,

View File

@@ -149,7 +149,6 @@ const {
$parseNum, $parseNum,
$multiSort, $multiSort,
$remove, $remove,
$stripHtml,
$unique, $unique,
} = useNuxtApp(); } = useNuxtApp();
const store = useStore(); const store = useStore();

View File

@@ -246,7 +246,7 @@
import CreateTemplate from "~/components/datatable/CreateTemplate"; import CreateTemplate from "~/components/datatable/CreateTemplate";
import FilterOption from "~/components/datatable/FilterOption.vue"; import FilterOption from "~/components/datatable/FilterOption.vue";
import TableOption from "~/components/datatable/TableOption.vue"; import TableOption from "~/components/datatable/TableOption.vue";
const { $id, $copy, $empty, $stripHtml } = useNuxtApp(); const { $id, $copy, $empty } = useNuxtApp();
const props = defineProps({ const props = defineProps({
event: Object, event: Object,
currentField: Object, currentField: Object,

View File

@@ -119,7 +119,7 @@ const props = defineProps({
data: Object, data: Object,
focus: Boolean, focus: Boolean,
}); });
const { $empty, $copy, $copyToClipboard, $stripHtml, $patchapi, $insertapi, $findIndex, $snackbar } = useNuxtApp(); const { $empty, $copy, $patchapi, $insertapi, $findIndex, $snackbar } = useNuxtApp();
const radioOption = ref(); const radioOption = ref();
const login = { id: 1 }; const login = { id: 1 };
const errors = ref([]); const errors = ref([]);

View File

@@ -3,7 +3,7 @@ const props = defineProps({
variant: Object, variant: Object,
}); });
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["created"]); const emit = defineEmits(["created"]);
const isLoading = ref(false); const isLoading = ref(false);
const body = ref({ const body = ref({

View File

@@ -5,7 +5,7 @@ import { isEqual, omitBy } from "es-toolkit";
const emit = defineEmits(["created"]); const emit = defineEmits(["created"]);
const { $buildFileUrl, $copy, $empty, $getdata, $insertapi, $patchapi } = useNuxtApp(); const { $buildFileUrl, $copy, $empty, $insertapi } = useNuxtApp();
const isPending = ref(false); const isPending = ref(false);
const defaultBody = ref({ const defaultBody = ref({
product: null, product: null,

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,7 +1,7 @@
<script setup> <script setup>
import InputNumber from "~/components/common/InputNumber.vue"; import InputNumber from "~/components/common/InputNumber.vue";
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,7 +1,7 @@
<script setup> <script setup>
import InputNumber from "~/components/common/InputNumber.vue"; import InputNumber from "~/components/common/InputNumber.vue";
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,7 +1,7 @@
<script setup> <script setup>
import InputNumber from "~/components/common/InputNumber.vue"; import InputNumber from "~/components/common/InputNumber.vue";
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
const { $empty, $insertapi } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const emit = defineEmits(["modalevent"]); const emit = defineEmits(["modalevent"]);
const isLoading = ref(false); const isLoading = ref(false);

View File

@@ -2,7 +2,6 @@
import InventoryHighlightCard from "~/components/inventory/InventoryHighlightCard.vue"; import InventoryHighlightCard from "~/components/inventory/InventoryHighlightCard.vue";
import InventoryTable from "~/components/inventory/InventoryTable.vue"; import InventoryTable from "~/components/inventory/InventoryTable.vue";
const { $store } = useNuxtApp();
const inventoryHighlights = [ const inventoryHighlights = [
{ {
name: "Tổng số SKU", name: "Tổng số SKU",

View File

@@ -5,7 +5,6 @@ const props = defineProps({
}); });
const emit = defineEmits(["selectInvItem", "unselect"]); const emit = defineEmits(["selectInvItem", "unselect"]);
const { $dayjs } = useNuxtApp();
</script> </script>
<template> <template>

View File

@@ -2,9 +2,6 @@
const props = defineProps({ const props = defineProps({
invItem: Object, invItem: Object,
}); });
const { $dayjs, $formatNum } = useNuxtApp();
const emit = defineEmits("unselect");
</script> </script>
<template> <template>
@@ -14,7 +11,7 @@ const emit = defineEmits("unselect");
> >
<div class="card"> <div class="card">
<button <button
@click="emit('unselect')" @click="$emit('unselect')"
class="button is-white rounded-full has-text-grey absolute size-8 is-flex is-justify-content-center is-align-items-center" class="button is-white rounded-full has-text-grey absolute size-8 is-flex is-justify-content-center is-align-items-center"
style="z-index: 1; right: 0.5rem; top: 0.5rem" style="z-index: 1; right: 0.5rem; top: 0.5rem"
> >

View File

@@ -191,15 +191,12 @@
</template> </template>
<script setup> <script setup>
import { useNuxtApp } from "nuxt/app";
import { ref, computed, onMounted, watch, markRaw } from "vue";
import EmailForm1 from "./forms/EmailForm1.vue"; import EmailForm1 from "./forms/EmailForm1.vue";
import Template1 from "~/components/marketing/email/Template1.vue"; import Template1 from "~/components/marketing/email/Template1.vue";
import Modal from "~/components/Modal.vue"; import Modal from "~/components/Modal.vue";
import MappingConfigurator from "~/components/marketing/email/MappingConfigurator.vue"; import MappingConfigurator from "~/components/marketing/email/MappingConfigurator.vue";
import JobConfigurator from "~/components/marketing/email/JobConfigurator.vue"; import JobConfigurator from "~/components/marketing/email/JobConfigurator.vue";
const nuxtApp = useNuxtApp();
const { $getdata, $snackbar, $deleteapi, $getEditRights } = useNuxtApp(); const { $getdata, $snackbar, $deleteapi, $getEditRights } = useNuxtApp();
const showmodal = ref(); const showmodal = ref();
const activeTab = ref("content"); const activeTab = ref("content");

View File

@@ -1,6 +1,4 @@
<script setup> <script setup>
const { $buildFileUrl, $copyToClipboard } = useNuxtApp();
const props = defineProps({ const props = defineProps({
className: String, className: String,
image: Object, image: Object,
@@ -8,14 +6,12 @@ const props = defineProps({
downloadImage: Function, downloadImage: Function,
openDeleteImageConfirm: Function, openDeleteImageConfirm: Function,
}); });
const url = $buildFileUrl(props.image.file__file);
</script> </script>
<template> <template>
<div :class="['buttons has-addons', className]"> <div :class="['buttons has-addons', className]">
<button <button
class="button is-small is-white" class="button is-small is-white"
@click="$copyToClipboard(url)" @click="$copyToClipboard($buildFileUrl(props.image.file__file))"
title="Sao chép link" title="Sao chép link"
> >
<span class="icon"> <span class="icon">

View File

@@ -38,7 +38,7 @@
/> />
</template> </template>
<script setup> <script setup>
const { $copy, $getpath, $download } = useNuxtApp(); const { $copy, $getpath } = useNuxtApp();
const emit = defineEmits(["remove", "close"]); const emit = defineEmits(["remove", "close"]);
const props = defineProps({ const props = defineProps({
files: Object, files: Object,

View File

@@ -13,7 +13,7 @@
class="file-input" class="file-input"
ref="file-input" ref="file-input"
type="file" type="file"
:id="docid" :id="$id()"
:multiple="multiple ?? true" :multiple="multiple ?? true"
name="resume" name="resume"
@change="doChange" @change="doChange"
@@ -52,14 +52,13 @@ const props = defineProps({
}); });
const emit = defineEmits(["files"]); const emit = defineEmits(["files"]);
const { $id, $snackbar, $upload } = useNuxtApp(); const { $snackbar, $upload } = useNuxtApp();
const fileInput = useTemplateRef("file-input"); const fileInput = useTemplateRef("file-input");
const vtype = props.type || ["image"]; const vtype = props.type || ["image"];
const files = ref(); // files selected in <input> const files = ref(); // files selected in <input>
const dataFiles = ref(); // files returned by $upload const dataFiles = ref(); // files returned by $upload
const showmodal = ref(); const showmodal = ref();
const docid = $id();
function getFileExtension(fileName) { function getFileExtension(fileName) {
if (!fileName || typeof fileName !== "string") return ""; if (!fileName || typeof fileName !== "string") return "";

View File

@@ -10,7 +10,7 @@ const props = defineProps({
viewImage: Function, viewImage: Function,
}); });
const { $buildFileUrl, $formatFileSize, $getpath, $patchapi, $snackbar } = useNuxtApp(); const { $buildFileUrl, $getpath, $patchapi, $snackbar } = useNuxtApp();
const url = $buildFileUrl(props.image.file__file); const url = $buildFileUrl(props.image.file__file);

View File

@@ -201,9 +201,7 @@
/> />
</template> </template>
<script setup> <script setup>
import { ref } from "vue";
import { debounce } from "es-toolkit"; import { debounce } from "es-toolkit";
import { useNuxtApp } from "#app";
import FileUpload from "~/components/media/FileUpload.vue"; import FileUpload from "~/components/media/FileUpload.vue";
import ImageCard from "~/components/media/ImageCard.vue"; import ImageCard from "~/components/media/ImageCard.vue";

View File

@@ -3,8 +3,6 @@ const props = defineProps({
invoice: Object, invoice: Object,
}); });
const { $dayjs } = useNuxtApp();
const historyItems = [ const historyItems = [
{ {
id: 1, id: 1,

View File

@@ -2,7 +2,6 @@
const props = defineProps({ const props = defineProps({
invoice: Object, invoice: Object,
}); });
const { $formatNum } = useNuxtApp();
</script> </script>
<template> <template>

View File

@@ -5,7 +5,7 @@ const props = defineProps({
invoice: Object, invoice: Object,
}); });
const { $getdata, $formatNum } = useNuxtApp(); const { $getdata } = useNuxtApp();
const invoiceDetails = ref([]); const invoiceDetails = ref([]);
onMounted(async () => { onMounted(async () => {
invoiceDetails.value = await $getdata("Invoice_Detail", { filter: { invoice: props.invoice.id } }); invoiceDetails.value = await $getdata("Invoice_Detail", { filter: { invoice: props.invoice.id } });

View File

@@ -9,7 +9,6 @@ const props = defineProps({
invoice: Object, invoice: Object,
}); });
const { $dayjs, $formatNum } = useNuxtApp();
const emit = defineEmits(["unselect"]); const emit = defineEmits(["unselect"]);
const tabs = [ const tabs = [

View File

@@ -164,7 +164,7 @@
</button> </button>
<button <button
class="button is-light has-text-black" class="button is-light has-text-black"
@click="exportPdf(docid, { filename: record.code })" @click="$exportPdf(docid, { filename: record.code })"
> >
{{ findLang("print") }} {{ findLang("print") }}
</button> </button>

View File

@@ -4,7 +4,7 @@ const props = defineProps({
deleteable: Boolean, deleteable: Boolean,
invalid: Boolean, invalid: Boolean,
}); });
const { $deleteapi, $formatNum, $snackbar } = useNuxtApp(); const { $deleteapi, $snackbar } = useNuxtApp();
const posStore = usePosStore(); const posStore = usePosStore();
const showConfirmModal = ref(); const showConfirmModal = ref();
const isDeleting = ref(false); const isDeleting = ref(false);

View File

@@ -7,7 +7,7 @@ import useOrderInfo from "~/components/pos/composables/useOrderInfo";
import SearchBox from "~/components/SearchBox.vue"; import SearchBox from "~/components/SearchBox.vue";
const store = useStore(); const store = useStore();
const { $insertapi, $formatNum } = useNuxtApp(); const { $insertapi } = useNuxtApp();
const posStore = usePosStore(); const posStore = usePosStore();
const { carts, isPending, activeCartId, invalidCartItems, addresses, orderInfo } = storeToRefs(posStore); const { carts, isPending, activeCartId, invalidCartItems, addresses, orderInfo } = storeToRefs(posStore);

View File

@@ -1,17 +1,16 @@
<script setup> <script setup>
import useOrderInfo from "~/components/pos/composables/useOrderInfo";
const props = defineProps({ const props = defineProps({
invoiceId: Number, invoiceId: Number,
finalizeOrder: Function, finalizeOrder: Function,
}); });
const { activeCartItems } = useActiveCart(); const { total } = useOrderInfo();
const subtotal = computed(() => {
return activeCartItems.value?.reduce((prev, curr) => prev + curr.imei__variant__price, 0);
});
</script> </script>
<template> <template>
<div class="is-flex is-flex-direction-column is-gap-2 is-align-items-center"> <div class="is-flex is-flex-direction-column is-gap-2 is-align-items-center">
<NuxtImg <NuxtImg
:src="qr(subtotal)" :src="$qr(total)"
class="h-full max-h-140" class="h-full max-h-140"
alt="VietQR code" alt="VietQR code"
/> />

View File

@@ -19,6 +19,3 @@
</div> </div>
</div> </div>
</template> </template>
<script setup>
const { $store, $requestLogin } = useNuxtApp();
</script>

View File

@@ -8,6 +8,9 @@ import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter"; import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
import "dayjs/locale/vi"; import "dayjs/locale/vi";
import { deburr } from "es-toolkit"; import { deburr } from "es-toolkit";
import html2pdf from "html2pdf.js";
import html2canvas from "html2canvas-pro";
dayjs.extend(weekday); dayjs.extend(weekday);
dayjs.extend(weekOfYear); dayjs.extend(weekOfYear);
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
@@ -19,7 +22,7 @@ dayjs.locale("vi");
export default defineNuxtPlugin((nuxtApp) => { export default defineNuxtPlugin((nuxtApp) => {
const route = useRoute(); const route = useRoute();
const store = useStore(); const store = useStore();
const { $id, $empty } = nuxtApp; const { $id, $copy, $empty } = nuxtApp;
const dialog = function (content, title, type, duration, width, height, vbind) { const dialog = function (content, title, type, duration, width, height, vbind) {
content = typeof content === "string" ? content : JSON.stringify(content); content = typeof content === "string" ? content : JSON.stringify(content);
@@ -98,7 +101,7 @@ export default defineNuxtPlugin((nuxtApp) => {
}; };
const dummy = function (data, count) { const dummy = function (data, count) {
let list = this.$copy(data); let list = $copy(data);
for (let index = 0; index < count; index++) { for (let index = 0; index < count; index++) {
if (data.length < index + 1) list.push({ dummy: true }); if (data.length < index + 1) list.push({ dummy: true });
} }
@@ -167,7 +170,7 @@ export default defineNuxtPlugin((nuxtApp) => {
}; };
const change = function (obj1, obj2, list) { const change = function (obj1, obj2, list) {
var change = false; let change = false;
if (list) { if (list) {
list.map((v) => { list.map((v) => {
if (obj1[v] !== obj2[v]) change = true; if (obj1[v] !== obj2[v]) change = true;
@@ -233,6 +236,65 @@ export default defineNuxtPlugin((nuxtApp) => {
return id; return id;
}; };
const exportPdf = async (docid, { filename = "file", format = "a4", orientation = "portrait" } = {}) => {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
const opt = {
margin: 3,
filename: `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.pdf`,
jsPDF: { format, orientation, unit: "mm" },
html2canvas: { scale: 3, useCORS: true },
image: { type: "jpeg", quality: 1 },
pagebreak: {
mode: ["avoid-all", "css", "legacy"],
before: ".page-break-before",
after: ".page-break-after",
avoid: ".avoid-page-break",
},
};
try {
await new Promise((r) => requestAnimationFrame(r));
await html2pdf().set(opt).from(target).save();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return opt.filename;
};
const exportImage = async (docid, filename = "file") => {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
try {
await new Promise((r) => requestAnimationFrame(r));
const canvas = await html2canvas(target);
const link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.png`;
link.click();
link.remove();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return filename;
};
const download = async function (url, fileName) { const download = async function (url, fileName) {
const name = dayjs(new Date()).format("YYYYMMDDhhmmss") + "-" + fileName; const name = dayjs(new Date()).format("YYYYMMDDhhmmss") + "-" + fileName;
const response = await fetch(url); const response = await fetch(url);
@@ -480,6 +542,27 @@ export default defineNuxtPlugin((nuxtApp) => {
return new Intl.NumberFormat("en", { notation: "compact" }).format(Number(amount)); return new Intl.NumberFormat("en", { notation: "compact" }).format(Number(amount));
} }
function qr(amount, qrVars = {}) {
const defaultQRVars = {
bankId: "BIDV",
accountNo: "1222198820",
accountName: "Nguyen Viet An",
template: "Rxp4lcv",
description: "Thanh toan ERP",
};
const finalVars = {
...defaultQRVars,
...qrVars,
};
const { bankId, accountNo, template, description, accountName } = finalVars;
const qrSrc = `https://img.vietqr.io/image/${bankId}-${accountNo}-${template}.png?amount=${amount}&addInfo=${description}&accountName=${accountName}`;
return qrSrc;
}
return { return {
provide: { provide: {
dialog, dialog,
@@ -495,6 +578,8 @@ export default defineNuxtPlugin((nuxtApp) => {
copyToClipboard, copyToClipboard,
nonAccent, nonAccent,
linkID, linkID,
exportPdf,
exportImage,
vnmoney, vnmoney,
createMeta, createMeta,
dayjs, dayjs,
@@ -504,6 +589,7 @@ export default defineNuxtPlugin((nuxtApp) => {
numberToVietnamese, numberToVietnamese,
formatDateVN, formatDateVN,
shortenCurrency, shortenCurrency,
qr,
}, },
}; };
}); });

View File

@@ -1,28 +0,0 @@
import dayjs from "dayjs";
import html2canvas from "html2canvas-pro";
export default async function exportImage(docid, filename = "file") {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
try {
await new Promise((r) => requestAnimationFrame(r));
const canvas = await html2canvas(target);
const link = document.createElement("a");
link.href = canvas.toDataURL("image/png");
link.download = `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.png`;
link.click();
link.remove();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return filename;
}

View File

@@ -1,35 +0,0 @@
import dayjs from "dayjs";
import html2pdf from "html2pdf.js";
export default async function exportPdf(docid, { filename = "file", format = "a4", orientation = "portrait" } = {}) {
const target = document.getElementById(docid);
const ignored = target.querySelectorAll(".ignore");
ignored.forEach((el) => el.style.setProperty("display", "none", "important"));
// Xóa cache ảnh để lần export sau không bị lỗi
target.querySelectorAll("img").forEach((img) => (img.src = `${img.src}`));
const restoreIcons = swapIconsForExport(target);
const opt = {
margin: 3,
filename: `${filename}-${dayjs().format("YYYYMMDDHHmmss")}.pdf`,
jsPDF: { format, orientation, unit: "mm" },
html2canvas: { scale: 3, useCORS: true },
image: { type: "jpeg", quality: 1 },
pagebreak: {
mode: ["avoid-all", "css", "legacy"],
before: ".page-break-before",
after: ".page-break-after",
avoid: ".avoid-page-break",
},
};
try {
await new Promise((r) => requestAnimationFrame(r));
await html2pdf().set(opt).from(target).save();
} finally {
restoreIcons();
ignored.forEach((el) => el.style.removeProperty("display"));
}
return opt.filename;
}

View File

@@ -1,20 +0,0 @@
export default function qr(amount, qrVars = {}) {
const defaultQRVars = {
bankId: "BIDV",
accountNo: "1222198820",
accountName: "Nguyen Viet An",
template: "Rxp4lcv",
description: "Thanh toan ERP",
};
const finalVars = {
...defaultQRVars,
...qrVars,
};
const { bankId, accountNo, template, description, accountName } = finalVars;
const qrSrc = `https://img.vietqr.io/image/${bankId}-${accountNo}-${template}.png?amount=${amount}&addInfo=${description}&accountName=${accountName}`;
return qrSrc;
}