fix
This commit is contained in:
parent
cce77e61db
commit
2bf2df8c62
|
|
@ -13,7 +13,6 @@ export const loadSession = (url_login?: string) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = localStorage.getItem("user" + id_site);
|
const user = localStorage.getItem("user" + id_site);
|
||||||
console.log(user);
|
|
||||||
if (user) {
|
if (user) {
|
||||||
const raw = JSON.parse(user);
|
const raw = JSON.parse(user);
|
||||||
w.user = raw.data;
|
w.user = raw.data;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ export const Menu: FC<MenuProp> = (props) => {
|
||||||
let role = props.role;
|
let role = props.role;
|
||||||
role = props.on_init();
|
role = props.on_init();
|
||||||
let menu = get(imenu, role) || [];
|
let menu = get(imenu, role) || [];
|
||||||
console.log(menu);
|
|
||||||
const pathname = getPathname();
|
const pathname = getPathname();
|
||||||
|
|
||||||
const local = useLocal({
|
const local = useLocal({
|
||||||
|
|
@ -59,12 +58,15 @@ export const SideBar: FC<{
|
||||||
depth: number;
|
depth: number;
|
||||||
pm: MenuProp;
|
pm: MenuProp;
|
||||||
mode: "full" | "mini";
|
mode: "full" | "mini";
|
||||||
}> = ({ data, local, depth, pm, mode }) => {
|
}> = ({ data: _data, local, depth, pm, mode }) => {
|
||||||
const PassProp = pm.PassProp;
|
const PassProp = pm.PassProp;
|
||||||
|
|
||||||
|
const data: IMenu[] = (typeof _data[0] === "string" ? [_data] : _data) as any;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
"c-flex c-flex-col c-flex-grow c-mb-1",
|
"c-flex c-flex-col c-flex-grow",
|
||||||
depth > 0 ? " c-overflow-hidden" : ""
|
depth > 0 ? " c-overflow-hidden" : ""
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|
@ -75,12 +77,21 @@ export const SideBar: FC<{
|
||||||
value: item[2],
|
value: item[2],
|
||||||
};
|
};
|
||||||
const find_child = findChild(item, (e: any) => local.open.includes(e));
|
const find_child = findChild(item, (e: any) => local.open.includes(e));
|
||||||
let expand = find_child;
|
if (find_child && !local.open.includes(item)) {
|
||||||
if (find_child && !local.open.includes(item)) local.open.push(item);
|
local.open.push(item);
|
||||||
|
setTimeout(() => {
|
||||||
|
local.render();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof menu.value === "string" && getPathname() === menu.value) {
|
||||||
|
local.active = item;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full c-flex c-flex-col c-overflow-hidden">
|
<div className="w-full c-flex c-flex-col c-overflow-hidden">
|
||||||
<div
|
<div
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
const childs = getChilds(item) || [];
|
const childs = getChilds(item) || [];
|
||||||
if (local.open.includes(item)) {
|
if (local.open.includes(item)) {
|
||||||
local.open = local.open.filter(
|
local.open = local.open.filter(
|
||||||
|
|
@ -89,12 +100,18 @@ export const SideBar: FC<{
|
||||||
} else {
|
} else {
|
||||||
local.open.push(item);
|
local.open.push(item);
|
||||||
}
|
}
|
||||||
local.active = item;
|
|
||||||
local.render();
|
local.render();
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
"hello",
|
||||||
|
!Array.isArray(menu.value) && typeof menu.value === "string"
|
||||||
|
);
|
||||||
if (
|
if (
|
||||||
!Array.isArray(menu.value) &&
|
!Array.isArray(menu.value) &&
|
||||||
typeof menu.value === "string"
|
typeof menu.value === "string"
|
||||||
) {
|
) {
|
||||||
|
await preload(menu.value);
|
||||||
|
console.log("preloaded", preload);
|
||||||
navigate(menu.value);
|
navigate(menu.value);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
@ -104,14 +121,16 @@ export const SideBar: FC<{
|
||||||
depth={depth || 0}
|
depth={depth || 0}
|
||||||
hasChild={Array.isArray(menu.value) && mode === "full"}
|
hasChild={Array.isArray(menu.value) && mode === "full"}
|
||||||
selected={local.active === item}
|
selected={local.active === item}
|
||||||
expand={expand && Array.isArray(menu.value) && mode === "full"}
|
expand={
|
||||||
|
find_child && Array.isArray(menu.value) && mode === "full"
|
||||||
|
}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
>
|
>
|
||||||
{pm.child}
|
{pm.child}
|
||||||
</PassProp>
|
</PassProp>
|
||||||
</div>
|
</div>
|
||||||
<div className="c-flex c-flex-col">
|
<div className="c-flex c-flex-col">
|
||||||
{Array.isArray(menu.value) && expand && mode === "full" ? (
|
{Array.isArray(menu.value) && mode === "full" ? (
|
||||||
<>
|
<>
|
||||||
<SideBar
|
<SideBar
|
||||||
data={menu.value}
|
data={menu.value}
|
||||||
|
|
@ -138,6 +157,7 @@ const getChilds = (data: Array<any>) => {
|
||||||
const children = data[2]; // array index ke-2 bisa berupa array atau string
|
const children = data[2]; // array index ke-2 bisa berupa array atau string
|
||||||
if (Array.isArray(children)) {
|
if (Array.isArray(children)) {
|
||||||
for (let child of children) {
|
for (let child of children) {
|
||||||
|
if (child) {
|
||||||
childs.push(child);
|
childs.push(child);
|
||||||
if (Array.isArray(child[2])) {
|
if (Array.isArray(child[2])) {
|
||||||
const result: any = getChilds(child);
|
const result: any = getChilds(child);
|
||||||
|
|
@ -145,6 +165,7 @@ const getChilds = (data: Array<any>) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return childs;
|
return childs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue