Skip to content

Commit

Permalink
feat(projects): 添加表格页面示例
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Dec 12, 2021
1 parent 230a50a commit 51c744c
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/AppProvider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@
import { NConfigProvider, NElement, zhCN, dateZhCN } from 'naive-ui';
import { NaiveProvider } from '@/components';
import { useThemeStore } from '@/store';
import { useDarkMode } from '@/composables';
import { useDarkMode, useGlobalEvent } from '@/composables';
const theme = useThemeStore();
const { naiveTheme } = useDarkMode();
const { initGlobalEventListener } = useGlobalEvent();
function init() {
initGlobalEventListener();
}
init();
</script>
<style></style>
12 changes: 6 additions & 6 deletions src/components/common/LoadingEmptyWrapper/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<n-spin :show="true" :size="loadingSize" />
</div>
<div v-show="isEmpty" class="absolute-center">
<div class="relative text-primary" :class="emptyNetworkClass">
<svg-empty-data />
<p class="absolute left-0 bottom-[20%] w-full text-center">{{ emptyDesc }}</p>
<div class="relative" :class="emptyNetworkClass">
<svg-empty-data class="text-primary" />
<p class="absolute-lb w-full text-center">{{ emptyDesc }}</p>
</div>
</div>
<div v-show="!network" class="absolute-center">
<div
class="relative text-primary"
class="relative"
:class="[{ 'cursor-pointer': showNetworkReload }, emptyNetworkClass]"
@click="handleReload"
>
<svg-network-error />
<p class="absolute-lb bottom-[20%] w-full text-center">{{ networkErrorDesc }}</p>
<svg-network-error class="text-primary" />
<p class="absolute-lb w-full text-center">{{ networkErrorDesc }}</p>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/composables/events/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useAuthChangeEvent } from './auth';

export function useGlobalEvent() {
/** 初始化全局监听事件 */
function initGlobalListener() {
function initGlobalEventListener() {
useAuthChangeEvent();
}

return {
initGlobalListener
initGlobalEventListener
};
}
1 change: 1 addition & 0 deletions src/interface/common/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type RouteKey =
| 'component'
| 'component_button'
| 'component_card'
| 'component_table'
| 'multi-menu'
| 'multi-menu_first'
| 'multi-menu_first_second'
Expand Down
8 changes: 8 additions & 0 deletions src/router/constant/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,14 @@ const routeConstMap = new Map<RouteKey, RouteConst>([
title: '卡片'
}
],
[
'component_table',
{
name: 'component_table',
path: '/component/table',
title: '表格'
}
],
[
'multi-menu',
{
Expand Down
12 changes: 11 additions & 1 deletion src/router/modules/component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { RouteRecordRaw } from 'vue-router';
import { BasicLayout } from '@/layouts';
import { ComponentButton, ComponentCard } from '@/views';
import { ComponentButton, ComponentCard, ComponentTable } from '@/views';
import { routeName, routePath, routeTitle } from '../constant';

const component: RouteRecordRaw = {
Expand Down Expand Up @@ -33,6 +33,16 @@ const component: RouteRecordRaw = {
requiresAuth: true,
keepAlive: true
}
},
{
name: routeName('component_table'),
path: routePath('component_table'),
component: ComponentTable,
meta: {
title: routeTitle('component_table'),
requiresAuth: true,
keepAlive: true
}
}
]
};
Expand Down
3 changes: 2 additions & 1 deletion src/views/component/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ComponentButton from './button/index.vue';
import ComponentCard from './card/index.vue';
import ComponentTable from './table/index.vue';

export { ComponentButton, ComponentCard };
export { ComponentButton, ComponentCard, ComponentTable };
85 changes: 85 additions & 0 deletions src/views/component/table/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<template>
<div>
<n-card title="表格" class="h-full shadow-sm rounded-16px">
<n-space :vertical="true">
<n-space>
<n-button @click="getDataSource">有数据</n-button>
<n-button @click="getEmptyDataSource">空数据</n-button>
</n-space>
<loading-empty-wrapper class="h-480px" :loading="loading" :empty="empty">
<n-data-table :columns="columns" :data="dataSource" :flex-height="true" class="h-480px" />
</loading-empty-wrapper>
</n-space>
</n-card>
</div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { NCard, NSpace, NButton, NDataTable } from 'naive-ui';
import type { DataTableColumn } from 'naive-ui';
import { LoadingEmptyWrapper } from '@/components';
import { useLoadingEmpty } from '@/hooks';
import { getRandomInterger } from '@/utils';
interface DataSource {
name: string;
age: number;
address: string;
}
const { loading, startLoading, endLoading, empty, setEmpty } = useLoadingEmpty();
const columns: DataTableColumn[] = [
{
title: 'Name',
key: 'name',
align: 'center'
},
{
title: 'Age',
key: 'age'
},
{
title: 'Address',
key: 'address'
}
];
const dataSource = ref<DataSource[]>([]);
function createDataSource(): DataSource[] {
return Array(100)
.fill(1)
.map((item, index) => {
return {
name: `Name${index}`,
age: getRandomInterger(30, 20),
address: '中国'
};
});
}
function getDataSource() {
startLoading();
setTimeout(() => {
dataSource.value = createDataSource();
endLoading();
setEmpty(!dataSource.value.length);
}, 1000);
}
function getEmptyDataSource() {
startLoading();
setTimeout(() => {
dataSource.value = [];
endLoading();
setEmpty(!dataSource.value.length);
}, 1000);
}
onMounted(() => {
getDataSource();
});
</script>
<style scoped></style>

1 comment on commit 51c744c

@vercel
Copy link

@vercel vercel bot commented on 51c744c Dec 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.