refactor layout
This commit is contained in:
@@ -1,4 +1,49 @@
|
||||
<template>
|
||||
<t-navbar
|
||||
fixed
|
||||
:z-index="20"
|
||||
:title="routeNavBarTitle"
|
||||
left-arrow
|
||||
@left-click="$router.back()"
|
||||
>
|
||||
<template #right>
|
||||
<div
|
||||
v-if="pageNavBarRight.icon || pageNavBarRight.text"
|
||||
class="nav-right-slot"
|
||||
>
|
||||
<t-badge
|
||||
v-if="pageNavBarRight.icon && pageNavBarRight.badge !== undefined"
|
||||
class="badge"
|
||||
:count="pageNavBarRight.badge"
|
||||
:max-count="99"
|
||||
:show-zero="false"
|
||||
>
|
||||
<button class="button" type="button" :disabled="pageNavBarRight.disabled" @click="handlePageNavBarRightAction">
|
||||
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
|
||||
</button>
|
||||
</t-badge>
|
||||
<button
|
||||
v-else-if="pageNavBarRight.icon"
|
||||
class="button"
|
||||
type="button"
|
||||
:disabled="pageNavBarRight.disabled"
|
||||
@click="handlePageNavBarRightAction"
|
||||
>
|
||||
<t-icon :name="pageNavBarRight.icon" size="1.25rem" />
|
||||
</button>
|
||||
<button
|
||||
v-else
|
||||
class="nav-text"
|
||||
type="button"
|
||||
:disabled="pageNavBarRight.disabled"
|
||||
:style="{ color: pageNavBarRight.disabled ? 'var(--td-text-color-disabled)' : pageNavBarRight.textColor || 'var(--td-text-color-primary, #333)' }"
|
||||
:class="{ clickable: !!pageNavBarRight.action, disabled: pageNavBarRight.disabled }"
|
||||
@click="handlePageNavBarRightAction"
|
||||
v-text="pageNavBarRight.text"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</t-navbar>
|
||||
<div v-can="corePermissionCodes.userRole.read" class="user-role-assign">
|
||||
<div class="user-menu">
|
||||
<t-dropdown-menu>
|
||||
@@ -44,18 +89,59 @@ import { Message } from "@/utils/message";
|
||||
import { RoleAPI, type ModuleCode, type Role as UserRole, useUserStore } from "timi-web-api";
|
||||
import ManagedUserAPI from "@/api/ManagedUserAPI";
|
||||
import { useCurrentStoreStore } from "@/store/currentStoreStore";
|
||||
import { useNavBarStore } from "@/store/navBarStore";
|
||||
import type { Role } from "@/store/permissionSettingsStore";
|
||||
import type { ManagedUser } from "@/types/ManagedUser";
|
||||
import { getErrorMessage } from "@/utils/error";
|
||||
import { corePermissionCodes, gaoRoleCodes } from "@/utils/permission";
|
||||
|
||||
const pageNavBarRight = reactive({
|
||||
icon: "",
|
||||
badge: undefined as number | undefined,
|
||||
text: "",
|
||||
textColor: "",
|
||||
disabled: false,
|
||||
action: undefined as (() => void | Promise<void>) | undefined
|
||||
});
|
||||
|
||||
function setPageNavBarRightText(value?: string, color?: string, action?: () => void | Promise<void>): void {
|
||||
pageNavBarRight.text = value || "";
|
||||
pageNavBarRight.textColor = color || "";
|
||||
pageNavBarRight.disabled = false;
|
||||
pageNavBarRight.action = action;
|
||||
if (value) {
|
||||
pageNavBarRight.badge = undefined;
|
||||
pageNavBarRight.icon = "";
|
||||
}
|
||||
}
|
||||
|
||||
function clearPageNavBarRight(): void {
|
||||
Object.assign(pageNavBarRight, { icon: "", badge: undefined, text: "", textColor: "", disabled: false, action: undefined });
|
||||
}
|
||||
|
||||
async function handlePageNavBarRightAction(): Promise<void> {
|
||||
if (pageNavBarRight.disabled || !pageNavBarRight.action) {
|
||||
return;
|
||||
}
|
||||
await pageNavBarRight.action();
|
||||
}
|
||||
|
||||
import type { Role } from "@/store/permissionSettingsStore";
|
||||
|
||||
defineOptions({
|
||||
name: "UserRoleAssign"
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const navBarStore = useNavBarStore();
|
||||
|
||||
const routeNavBarTitle = computed(() => {
|
||||
switch (route.name) {
|
||||
case "UserRoleAssign":
|
||||
return "用户授权角色";
|
||||
case "UserRoleAssignFromUser":
|
||||
return "配置角色";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
});
|
||||
const moduleCode: ModuleCode = "GAO";
|
||||
const allStoreFilterValue = "__ALL_STORES__";
|
||||
|
||||
@@ -281,7 +367,7 @@ onMounted(async () => {
|
||||
userStore.hasPermissions(corePermissionCodes.userRole.create)
|
||||
&& userStore.hasPermissions(corePermissionCodes.userRole.delete)
|
||||
) {
|
||||
navBarStore.setRightText("保存", "var(--td-brand-color)", saveRoleList);
|
||||
setPageNavBarRightText("保存", "var(--td-brand-color)", saveRoleList);
|
||||
}
|
||||
try {
|
||||
await loadData();
|
||||
@@ -290,7 +376,7 @@ onMounted(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => navBarStore.clearRight());
|
||||
onUnmounted(() => clearPageNavBarRight());
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
@@ -318,5 +404,46 @@ onUnmounted(() => navBarStore.clearRight());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nav-right-slot {
|
||||
width: 6rem;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
|
||||
.badge {
|
||||
:deep(.t-badge__content) {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.button,
|
||||
.nav-text {
|
||||
color: var(--td-text-color-primary, #333);
|
||||
border: none;
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
background: transparent;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.button {
|
||||
&:disabled {
|
||||
color: var(--td-text-color-disabled);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-text {
|
||||
font: inherit;
|
||||
cursor: default;
|
||||
|
||||
&.clickable { cursor: pointer; }
|
||||
&.disabled { cursor: not-allowed; }
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user