Files
FE_CPONE/libs/one_global.js
2026-04-27 10:08:27 +07:00

114 lines
2.5 KiB
JavaScript

window.BASE_URL = ""
function one_money(inp, format) {
return numeral(inp).format(format ? format : '0,000')
}
window.one_money = one_money
function one_token() {
return localStorage.getItem('token')
}
window.one_token = one_token
function one_user() {
return JSON.parse(localStorage.getItem('user'))
}
window.one_user = one_user
function one_float(inp) {
try {
let val = parseFloat(inp)
if (isNaN(val)) return 0.0
return val
} catch (e) {
return 0.0
}
}
window.one_float = one_float
function one_logout(urllogout) {
window.urllogout = urllogout
window.urllogout = "/home"
let logout = async function (token) {
try {
var resp = await axios.post(BASE_URL + '/one-api/v1/system/auth/logout',
{ token: token });
if (resp.status != 200) {
return {
status: "ERR",
message: resp.statusText
};
}
let data = resp.data;
return data;
} catch (e) {
return {
status: "ERR",
message: e.message
};
}
}
let x = async () => {
try {
let resp = await logout(window.one_token())
if (resp.status != "OK") {
alert('error')
} else {
window.localStorage.removeItem("token")
window.localStorage.removeItem("user")
location.replace(window.urllogout)
}
} catch (e) {
context.commit("update_login_status", 3)
context.commit("update_login_error_message", e.message)
}
}
x()
// window.location = urllogout
}
window.one_logout = one_logout
var one_moment = function (d) {
return moment(d, "YYYY-MM-DD hh:mm:ss").fromNow()
}
window.oneMoment = one_moment
window.one_moment = one_moment
// NavBar APIs
// async function one_get_menu() {
// try {
// var resp = await axios.post(BASE_URL + '/one-api/mockup/system/menu/get_menu');
// if (resp.status != 200) {
// return {
// status: "ERR",
// message: resp.statusText
// };
// }
// let data = resp.data;
// return data;
// } catch(e) {
// return {
// status: "ERR",
// message: e.message
// };
// }
// }
// window.one_get_menu = one_get_menu
async function xno(input) {
try {
var resp = await axios.get(BASE_URL + '/one-api/v1/su/xno/show/' + input)
return resp.data
} catch (e) {
return input;
}
}
window.xno = xno