This commit is contained in:
Viet An
2026-05-27 09:17:52 +07:00
parent cc3bb9cfb5
commit 29ff3f2598
4 changed files with 41 additions and 26 deletions

View File

@@ -94,10 +94,11 @@ export default defineNuxtPlugin(() => {
const clone = function (obj) {
if (obj === null || typeof obj !== "object" || "isActiveClone" in obj) return obj;
let temp;
if (obj instanceof Date)
var temp = new obj.constructor(); //or new Date(obj);
else var temp = obj.constructor();
for (var key in obj) {
temp = new obj.constructor(); //or new Date(obj);
else temp = obj.constructor();
for (let key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
obj["isActiveClone"] = null;
temp[key] = clone(obj[key]);
@@ -117,9 +118,9 @@ export default defineNuxtPlugin(() => {
if (html ? html.indexOf("<") < 0 : false) {
return length ? (html.length > length ? html.substring(0, length) + "..." : html) : html;
}
var tmp = document.createElement("DIV");
const tmp = document.createElement("DIV");
tmp.innerHTML = html;
var val = tmp.textContent || tmp.innerText || "";
const val = tmp.textContent || tmp.innerText || "";
return length ? (val.length > length ? val.substring(0, length) + "..." : val) : val;
};
@@ -190,14 +191,15 @@ export default defineNuxtPlugin(() => {
//calculate
try {
let value = this.$calc(val);
let result;
if (isNaN(value) || value === Number.POSITIVE_INFINITY || value === Number.NEGATIVE_INFINITY) {
var result = { success: false, value: value };
result = { success: false, value };
} else {
value = value === true || value === false ? value : formatUnit(value, unit, decimal, true, decimal);
var result = { success: true, value: value };
result = { success: true, value };
}
} catch (err) {
var result = { success: false, value: undefined };
result = { success: false, value: undefined };
}
return result;
};
@@ -295,7 +297,7 @@ export default defineNuxtPlugin(() => {
const arrayMove = function (arr, old_index, new_index) {
if (new_index >= arr.length) {
var k = new_index - arr.length + 1;
let k = new_index - arr.length + 1;
while (k--) {
arr.push(undefined);
}
@@ -423,12 +425,12 @@ export default defineNuxtPlugin(() => {
//======================Export===============================
const exportExcel = async function (data, filename, fields) {
var _filename = filename + ".xlsx";
let list = [];
const _filename = filename + ".xlsx";
const list = [];
data.map((v) => {
let ele = {};
fields.map((x) => {
let label = stripHtml(x.label);
const ele = {};
fields.forEach((x) => {
const label = stripHtml(x.label);
ele[label] = v[x.name];
});
list.push(ele);
@@ -441,8 +443,8 @@ export default defineNuxtPlugin(() => {
this.SheetNames = [];
this.Sheets = {};
}
var exportBook = new Workbook();
var worksheet = XLSX.utils.json_to_sheet(list);
const exportBook = new Workbook();
const worksheet = XLSX.utils.json_to_sheet(list);
exportBook.SheetNames.push("sheet1");
exportBook.Sheets.sheet1 = worksheet;
XLSX.writeFile(exportBook, _filename);
@@ -456,6 +458,7 @@ export default defineNuxtPlugin(() => {
filter,
id,
empty,
toRawDeep,
copy,
clone,
remove,