ts
This commit is contained in:
98
src_typescript/main2.ts
Normal file
98
src_typescript/main2.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
"use strict";
|
||||
|
||||
interface AdminFunction {
|
||||
capNhatTrangThaiMenu(hideMenuBig: boolean): void;
|
||||
add_product_to_category(id: string): void;
|
||||
run_search(holder: string): void;
|
||||
searchSelect(holder: string): void;
|
||||
update_product_hot(id: string): void;
|
||||
}
|
||||
|
||||
const AdminFunction: AdminFunction = (() => {
|
||||
function capNhatTrangThaiMenu(hideMenuBig: boolean): void {
|
||||
if (hideMenuBig === false) {
|
||||
$('#js-admin-content-container').addClass('show-large-menu');
|
||||
} else {
|
||||
$('#js-admin-content-container').removeClass('show-large-menu');
|
||||
}
|
||||
|
||||
$('#js-menu-big').toggleClass('hidden', hideMenuBig);
|
||||
$('#js-menu-small').toggleClass('hidden', !hideMenuBig);
|
||||
$('#js-form-search').toggleClass('menu-hide', hideMenuBig);
|
||||
localStorage.setItem(hideMenuBig ? 'menu_big' : 'menu_small', 'hidden');
|
||||
localStorage.removeItem(hideMenuBig ? 'menu_small' : 'menu_big');
|
||||
}
|
||||
|
||||
function debounce(func: (...args: any[]) => void, wait: number, immediate: boolean) {
|
||||
let timeout: ReturnType<typeof setTimeout> | null = null;
|
||||
return function (this: HTMLInputElement, ...args: any[]) {
|
||||
const context = this;
|
||||
const later = function () {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
};
|
||||
const callNow = immediate && !timeout;
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
function add_product_to_category(id: string): void {
|
||||
$('#status_' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>');
|
||||
setTimeout(() => {
|
||||
$('#status_' + id).html('');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function run_search(holder: string): void {
|
||||
$(holder).keyup(debounce(function (this: HTMLInputElement) { // Ensure 'this' context is of type HTMLInputElement
|
||||
//const inputString = $(this).val();
|
||||
$('#js-show-search').show();
|
||||
}, 300, false) as any); // Cast debounce to any to avoid type inference issues
|
||||
|
||||
$('body').click(function () {
|
||||
$("#js-show-search").hide();
|
||||
});
|
||||
}
|
||||
|
||||
function update_product_hot(id: string): void {
|
||||
$('#js-status-hottype-' + id).html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Đang xử lý..</span>');
|
||||
setTimeout(() => {
|
||||
$('#js-status-hottype-' + id).html('');
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function searchSelect(holder: string): void {
|
||||
$(holder).select2();
|
||||
}
|
||||
|
||||
function checkForm(status: boolean) {
|
||||
$('#overlay').addClass('active');
|
||||
$('.status-notificatiom').addClass('active');
|
||||
if (status == true) {
|
||||
$('.status-notificatiom .content').html(`<i class="fa fa-check"></i> <b>Cập nhật thành công</b>
|
||||
<p>Đơn hàng #000-368 đã được cập nhật thành công</p>`);
|
||||
}
|
||||
else {
|
||||
$('.status-notificatiom .content').html(`<i class="fa-solid fa-triangle-exclamation"></i> <b>Lỗi cập nhật</b><p>Có một số vấn đề với hoạt động của bạn.</p>`);
|
||||
}
|
||||
}
|
||||
function closeForm() {
|
||||
$('#overlay').removeClass('active');
|
||||
$('.status-notificatiom').removeClass('active');
|
||||
}
|
||||
|
||||
return {
|
||||
capNhatTrangThaiMenu,
|
||||
add_product_to_category,
|
||||
run_search,
|
||||
searchSelect,
|
||||
update_product_hot,
|
||||
checkForm,
|
||||
closeForm
|
||||
};
|
||||
})();
|
||||
16
tsconfig.json
Normal file
16
tsconfig.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"moduleResolution": "node" // Thay đổi giá trị này từ 'classic' thành 'node'
|
||||
},
|
||||
"include": ["./src_typescript/main2.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
15
vite.config.ts
Normal file
15
vite.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: 'dist',
|
||||
minify: false,
|
||||
rollupOptions: {
|
||||
output: {
|
||||
entryFileNames: '[name].js', // Đổi tên của các file JavaScript đầu ra
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user