push code

This commit is contained in:
gin
2024-06-15 14:59:52 +07:00
commit b519879332
84 changed files with 20222 additions and 0 deletions

41
src/helpers/CountDown.js Normal file
View File

@@ -0,0 +1,41 @@
class CountDown {
endTime = 0;
interval
callback
constructor(endTime, callback, start = false) {
this.endTime = endTime
this.callback = callback;
if(start) {
this.start();
}
}
start() {
this.interval = setInterval(() => {
const t = ((this.endTime - Date.now()) / 1000) >> 0;
if (t >= 0) {
const hh = (t / 3600) >> 0;
const mm = ((t - hh * 3600) / 60) >> 0
const ss = t % 60
if(this.callback) {
this.callback(hh, mm, ss, t)
}
} else {
this.stop();
}
}, 500);
}
restart(endTime) {
this.stop();
this.endTime = endTime;
this.start();
}
stop(){
clearInterval(this.interval)
}
}
export default CountDown

33
src/helpers/format.js Normal file
View File

@@ -0,0 +1,33 @@
import moment from "moment"
export function formatNumber(value, minFraction = 0, maxFraction = 3 ){
try {
var formatter = new Intl.NumberFormat('en-US', {
minimumFractionDigits: minFraction,
maximumFractionDigits: maxFraction
});
return formatter.format(value);
} catch (error) {
console.log(error)
return value
}
}
export function formatDateTime(time, format="YYYY-MM-DD HH:mm:ss") {
return moment(time).utcOffset("Asean/Ho_Chi_Minh").format(format)
}
export function formatTransactionStatus(value) {
switch (value) {
case 0:
return 'Chờ xử lý'
case 1:
return 'Thành công'
case 2:
return 'Thất bại'
case "all":
return 'Tất cả'
default:
return 'N/A'
}
}

4
src/helpers/redirect.js Normal file
View File

@@ -0,0 +1,4 @@
export function gotoChat() {
window.open(import.meta.env.VITE_APP_CHAT_URL + `?token=${localStorage.getItem('accessToken')}`, "_self");
}

16
src/helpers/request.js Normal file
View File

@@ -0,0 +1,16 @@
async function handleRequest(request, throwError = false) {
if (!throwError) {
try {
return await request
} catch (error) {
console.log(error)
return error
}
}
return request
}
export {
handleRequest
}