Skip to content

Commit

Permalink
feat(projects): perf page manage_role
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Apr 24, 2024
1 parent 8f5a6b1 commit 5594558
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/components/advanced/table-header-operation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function refresh() {
</script>

<template>
<ASpace wrap class="justify-end lt-sm:w-200px">
<div class="flex flex-wrap justify-end gap-x-12px gap-y-8px lt-sm:(w-200px py-12px)">
<slot name="prefix"></slot>
<slot name="default">
<AButton size="small" ghost type="primary" @click="add">
Expand All @@ -62,7 +62,7 @@ function refresh() {
</AButton>
<TableColumnSetting v-model:columns="columns" />
<slot name="suffix"></slot>
</ASpace>
</div>
</template>

<style scoped></style>
3 changes: 3 additions & 0 deletions src/store/modules/theme/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ export function getAntdTheme(colors: App.Theme.ThemeColor, darkMode: boolean) {
},
algorithm: [darkMode ? darkAlgorithm : defaultAlgorithm],
components: {
Button: {
controlHeightSM: 28
},
Menu: {
colorSubItemBg: 'transparent'
}
Expand Down
24 changes: 21 additions & 3 deletions src/views/manage/role/index.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="tsx">
import { computed, shallowRef } from 'vue';
import { Button, Popconfirm, Tag } from 'ant-design-vue';
import { useElementSize } from '@vueuse/core';
import { fetchGetRoleList } from '@/service/api';
// import { useAppStore } from '@/store/modules/app';
import { useTable, useTableOperate } from '@/hooks/common/table';
Expand All @@ -10,6 +12,16 @@ import RoleSearch from './modules/role-search.vue';
// const appStore = useAppStore();
const wrapperEl = shallowRef<HTMLElement | null>(null);
const { height: wrapperElHeight } = useElementSize(wrapperEl);
const scrollConfig = computed(() => {
return {
y: wrapperElHeight.value - 72,
x: 702
};
});
const { columns, columnChecks, data, loading, getData, mobilePagination, searchParams, resetSearchParams } = useTable({
apiFn: fetchGetRoleList,
apiParams: {
Expand Down Expand Up @@ -123,7 +135,12 @@ function edit(id: number) {
<template>
<div class="min-h-500px flex-col-stretch gap-16px overflow-hidden lt-sm:overflow-auto">
<RoleSearch v-model:model="searchParams" @reset="resetSearchParams" @search="getData" />
<ACard :title="$t('page.manage.role.title')" :bordered="false" class="sm:flex-1-hidden card-wrapper">
<ACard
:title="$t('page.manage.role.title')"
:bordered="false"
:body-style="{ flex: 1, overflow: 'hidden' }"
class="flex-col-stretch sm:flex-1-hidden card-wrapper"
>
<template #extra>
<TableHeaderOperation
v-model:columns="columnChecks"
Expand All @@ -135,14 +152,15 @@ function edit(id: number) {
/>
</template>
<ATable
ref="wrapperEl"
:columns="columns"
:data-source="data"
:loading="loading"
row-key="id"
size="small"
:pagination="mobilePagination"
:scroll="{ x: 702 }"
class="sm:h-full"
:scroll="scrollConfig"
class="h-full"
/>
<RoleOperateDrawer
v-model:visible="drawerVisible"
Expand Down
36 changes: 17 additions & 19 deletions src/views/manage/role/modules/button-auth-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ const tree = shallowRef<DataNode[]>([]);
async function getAllButtons() {
// request
tree.value = [
{ key: '01', title: 'button1', code: 'code1' },
{ key: '02', title: 'button2', code: 'code2' },
{ key: '03', title: 'button3', code: 'code3' },
{ key: '04', title: 'button4', code: 'code4' },
{ key: '05', title: 'button5', code: 'code5' },
{ key: '06', title: 'button6', code: 'code6' },
{ key: '07', title: 'button7', code: 'code7' },
{ key: '08', title: 'button8', code: 'code8' },
{ key: '09', title: 'button9', code: 'code9' },
{ key: '10', title: 'button10', code: 'code10' }
{ key: 1, title: 'button1', code: 'code1' },
{ key: 2, title: 'button2', code: 'code2' },
{ key: 3, title: 'button3', code: 'code3' },
{ key: 4, title: 'button4', code: 'code4' },
{ key: 5, title: 'button5', code: 'code5' },
{ key: 6, title: 'button6', code: 'code6' },
{ key: 7, title: 'button7', code: 'code7' },
{ key: 8, title: 'button8', code: 'code8' },
{ key: 9, title: 'button9', code: 'code9' },
{ key: 10, title: 'button10', code: 'code10' }
];
}
Expand Down Expand Up @@ -70,16 +70,14 @@ init();

<template>
<AModal v-model:open="visible" :title="title" class="w-480px">
<ATree v-model:checked-keys="checks" :tree-data="tree" checkable class="h-280px" />
<ATree v-model:checked-keys="checks" :tree-data="tree" checkable :height="280" class="h-280px" />
<template #footer>
<ASpace>
<AButton size="small" class="mt-16px" @click="closeModal">
{{ $t('common.cancel') }}
</AButton>
<AButton type="primary" size="small" class="mt-16px" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
</ASpace>
<AButton size="small" class="mt-16px" @click="closeModal">
{{ $t('common.cancel') }}
</AButton>
<AButton type="primary" size="small" class="mt-16px" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
</template>
</AModal>
</template>
Expand Down
68 changes: 39 additions & 29 deletions src/views/manage/role/modules/menu-auth-modal.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<script setup lang="ts">
import { computed, shallowRef, watch } from 'vue';
import type { SelectProps } from 'ant-design-vue';
import type { DataNode } from 'ant-design-vue/es/tree';
import { $t } from '@/locales';
import { fetchGetAllPages, fetchGetMenuTree } from '@/service/api';
Expand Down Expand Up @@ -32,10 +34,10 @@ async function getHome() {
home.value = 'home';
}
async function updateHome(val: string) {
async function updateHome(val: SelectProps['value']) {
// request
home.value = val;
home.value = val as string;
}
const pages = shallowRef<string[]>([]);
Expand All @@ -57,22 +59,41 @@ const pageSelectOptions = computed(() => {
return opts;
});
const tree = shallowRef<Api.SystemManage.MenuTree[]>([]);
const tree = shallowRef<DataNode[]>([]);
async function getTree() {
const { error, data } = await fetchGetMenuTree();
if (!error) {
tree.value = data;
tree.value = recursiveTransform(data);
}
}
function recursiveTransform(data: Api.SystemManage.MenuTree[]): DataNode[] {
return data.map(item => {
const { id: key, label } = item;
if (item.children) {
return {
key,
title: label,
children: recursiveTransform(item.children)
};
}
return {
key,
title: label
};
});
}
const checks = shallowRef<number[]>([]);
async function getChecks() {
console.log(props.roleId);
// request
checks.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21];
checks.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21];
}
function handleSubmit() {
Expand All @@ -84,11 +105,11 @@ function handleSubmit() {
closeModal();
}
function init() {
async function init() {
getHome();
getPages();
getTree();
getChecks();
await getTree();
await getChecks();
}
watch(visible, val => {
Expand All @@ -99,32 +120,21 @@ watch(visible, val => {
</script>

<template>
<NModal v-model:show="visible" :title="title" preset="card" class="w-480px">
<AModal v-model:open="visible" :title="title" class="w-480px">
<div class="flex-y-center gap-16px pb-12px">
<div>{{ $t('page.manage.menu.home') }}</div>
<NSelect :value="home" :options="pageSelectOptions" size="small" class="w-160px" @update:value="updateHome" />
<ASelect :value="home" :options="pageSelectOptions" class="w-240px" @update:value="updateHome" />
</div>
<NTree
v-model:checked-keys="checks"
:data="tree"
key-field="id"
checkable
expand-on-click
virtual-scroll
block-line
class="h-280px"
/>
<ATree v-model:checked-keys="checks" :tree-data="tree" checkable :height="280" class="h-280px" />
<template #footer>
<NSpace justify="end">
<NButton size="small" class="mt-16px" @click="closeModal">
{{ $t('common.cancel') }}
</NButton>
<NButton type="primary" size="small" class="mt-16px" @click="handleSubmit">
{{ $t('common.confirm') }}
</NButton>
</NSpace>
<AButton size="small" class="mt-16px" @click="closeModal">
{{ $t('common.cancel') }}
</AButton>
<AButton type="primary" size="small" class="mt-16px" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
</template>
</NModal>
</AModal>
</template>

<style scoped></style>
4 changes: 2 additions & 2 deletions src/views/manage/role/modules/role-operate-drawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ watch(visible, () => {
<ButtonAuthModal v-model:visible="buttonAuthVisible" :role-id="roleId" />
</ASpace>
<template #footer>
<ASpace :size="16">
<div class="flex-y-center justify-end gap-12px">
<AButton @click="closeDrawer">{{ $t('common.cancel') }}</AButton>
<AButton type="primary" @click="handleSubmit">{{ $t('common.confirm') }}</AButton>
</ASpace>
</div>
</template>
</ADrawer>
</template>
Expand Down

0 comments on commit 5594558

Please sign in to comment.