Files
westone-ui/globalstore/globalstore.js
2024-08-28 09:02:07 +07:00

81 lines
2.6 KiB
JavaScript

const URL = "../json/jsonformatter.json";
const URLBread = "../json/breadcumb.json";
const store = {
namespaced: true,
state() {
return {
menu_level_0: [],
menu_level_1: [],
menu_level_2: [],
drawer: false,
bread_crumb: "",
search_error_message: "",
branch: {},
is_page_allowed: true,
dashboard: ""
};
},
mutations: {
update_menu_level_0(state, data) {
state.menu_level_0 = data
},
update_bread_crumb(state, val) {
state.bread_crumb = val
},
update_menu_level_1(state, data) {
state.menu_level_1 = data
},
update_menu_level_2(state, data) {
state.menu_level_2 = data
},
update_branch(state, val) {
state.branch = val
},
update_search_error_message(state, val) {
state.search_error_message = val
},
update_page_allowed(state, val) {
state.is_page_allowed = val
},
update_dashboard(state, val) {
state.dashboard = val
},
update_drawer(state, payload) {
state.drawer = payload;
},
},
actions: {
async loadMenuData(context) {
try {
let resp = await axios.get(URL);
if (resp.data.status != "OK") {
console.error('Gagal get api:');
} else {
let x = resp.data.data
if (x[0])
context.commit("update_menu_level_0", x[0]['p_0'])
if (x[1])
context.commit("update_menu_level_1", x[1])
if (x[2])
context.commit("update_menu_level_2", x[2])
}
// tambahan get bread_crumb
resp = await axios.get(URLBread)
if (resp.data.status != "OK") {
context.commit("update_search_error_message", resp.message)
} else {
context.commit("update_search_error_message", "")
context.commit("update_bread_crumb", resp.data.data.bread_crumb)
context.commit("update_branch", resp.data.data.branch)
context.commit("update_page_allowed", resp.data.is_page_allowed)
context.commit("update_dashboard", resp.data.dashboard)
}
} catch (error) {
console.error('Error loading menu data:', error);
}
},
}
};
export default store