Files
FE_CPONE/apps/modules/system/system-bkp.js
2026-04-27 10:08:27 +07:00

124 lines
3.9 KiB
JavaScript

// 1 => LOADING
// 2 => DONE
// 3 => ERROR
import * as menu_api from "../../api/system/menu.js"
export default {
namespaced: true,
state: {
search : '',
search_status: 0,
search_error_message: "",
menu_level_0: [],
menu_level_1: [],
menu_level_2: [],
total_menu: 0,
//sipe add breadcrumb dan hak akses
bread_crumb : "",
is_page_allowed : true,
dashboard: "",
//tambahan jumlah notification
notification_count: 0,
change_password_dialog: false,
change_password_error: ""
},
mutations: {
update_change_password_dialog(state,val) {
state.change_password_dialog = val
},
update_change_password_error(state,val) {
state.change_password_error= val
},
update_bread_crumb(state,val) {
state.bread_crumb = val
},
update_dashboard(state,val) {
state.dashboard= val
},
update_page_allowed(state,val) {
state.is_page_allowed = val
},
update_search(state,val) {
state.search=val
},
update_search_error_message(state,status) {
state.search_error_message = status
},
update_search_status(state,status) {
state.search_status = status
},
update_menu_level_0 (state, data) {
state.menu_level_0 = data
},
update_menu_level_1 (state, data) {
state.menu_level_1 = data
},
update_menu_level_2 (state, data) {
state.menu_level_2 = data
}
},
actions: {
async get_menu(context) {
context.commit("update_search_status",1)
try {
let resp= await menu_api.get_menu(one_token())
if (resp.status != "OK") {
context.commit("update_search_status",3)
context.commit("update_search_error_message",resp.message)
} else {
context.commit("update_search_status",2)
context.commit("update_search_error_message","")
let x = resp.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])
// let data = {
// total : resp.data.total,
// records : resp.data.records
// }
// context.commit("update_status", data)
}
//sipe :
// tambahan get bread_crumb
resp = await menu_api.get_bread_crumb(one_token())
if (resp.status != "OK") {
context.commit("update_search_status",3)
context.commit("update_search_error_message",resp.message)
} else {
context.commit("update_search_status",2)
context.commit("update_search_error_message","")
context.commit("update_bread_crumb",resp.data.bread_crumb)
context.commit("update_page_allowed",resp.data.is_page_allowed)
context.commit("update_dashboard",resp.data.dashboard)
}
} catch(e) {
context.commit("update_search_status",3)
context.commit("update_search_error_message", e.message )
}
},
async change_password(context,prm) {
try {
let resp = await menu_api.change_password(prm)
if (resp.status != "OK") {
context.commit("update_change_password_error",resp.message)
} else {
context.commit("update_change_password_error","")
}
} catch(e) {
console.log(e)
}
}
}
}