修改创建模板.

This commit is contained in:
lijiahang
2023-09-29 23:45:01 +08:00
parent 05af36a578
commit b77257c746
3 changed files with 197 additions and 111 deletions

View File

@@ -1,7 +1,6 @@
.layout-container { .layout-container {
background-color: var(--color-fill-2); background-color: var(--color-fill-2);
// fixme padding: 16px 16px 0 16px;
// padding: 16px 16px 0 16px;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
} }
@@ -67,6 +66,15 @@
} }
} }
.card-list-item {
transition-property: all;
}
.card-list-item:hover {
transform: translateY(-4px);
box-shadow: 2px 2px 12px rgba(0, 0, 0, .15);
}
.usn { .usn {
user-select: none; user-select: none;
} }

View File

@@ -1,4 +1,5 @@
import { PaginationProps, TableRowSelection } from '@arco-design/web-vue'; import { PaginationProps, TableRowSelection } from '@arco-design/web-vue';
import { reactive } from 'vue';
/** /**
* 默认分页 * 默认分页
@@ -23,3 +24,43 @@ export const defaultRowSelection = (): TableRowSelection => {
onlyCurrent: true, onlyCurrent: true,
}; };
}; };
/**
* 创建列表分页
*/
export const usePagination = (): PaginationProps => {
return reactive({
total: 0,
current: 1,
pageSize: 10,
showTotal: true,
showPageSize: true,
pageSizeOptions: [10, 20, 30, 50, 100]
});
};
/**
* 创建卡片列表分页
*/
export const useCardPagination = (): PaginationProps => {
return reactive({
total: 0,
current: 1,
pageSize: 18,
showTotal: true,
showPageSize: true,
pageSizeOptions: [12, 18, 36, 48, 96]
});
};
/**
* 创建行选择器
*/
export const useRowSelection = (type = 'checkbox'): TableRowSelection => {
return {
type: type as any,
showCheckedAll: true,
onlyCurrent: true,
};
};

View File

@@ -1,53 +1,73 @@
<template> <template>
<div class="card-list-layout"> <div class="card-list-layout">
<!-- 头部固定 --> <!-- 头部部分-固定 -->
<div class="card-list-layout-top" :style="{width: `calc(100% - ${menuWidth}px)`}"> <div class="card-list-layout-header" :style="{width: headerWidth}">
<!-- 路由面包屑 --> <div class="card-list-layout-header-wrapper">
<Breadcrumb /> <!-- 信息部分 -->
<!-- header --> <div class="card-list-info">
<div class="card-list-header"> <!-- 路由面包屑 -->
<!-- 左侧固定 --> <Breadcrumb />
<div class="card-list-header-left"> <!-- 分页部分 -->
<a-space> <div class="pagination-wrapper">
<!-- 创建 --> <a-pagination size="mini"
<div class="header-icon-wrapper"> v-model:current="pagination.current"
<icon-plus /> v-model:page-size="pagination.pageSize"
</div> v-bind="pagination" />
<!-- 条件显示 --> </div>
</a-space>
</div> </div>
<!-- 右侧固定 --> <!-- 操作部分 -->
<div class="card-list-header-right"> <div class="card-list-handler">
<a-space> <!-- 左侧固定 -->
<!-- 搜索框 --> <div class="card-list-handler-left">
<a-input size="small" placeholder="输入名称/地址"> <a-space>
<template #suffix> <!-- 创建 -->
<div class="header-icon-wrapper" title="创建">
<icon-plus />
</div>
<!-- 条件显示 -->
</a-space>
</div>
<!-- 右侧固定 -->
<div class="card-list-handler-right">
<a-space>
<!-- 搜索框 -->
<a-input size="small"
placeholder="输入名称/地址"
allow-clear />
<!-- 过滤 -->
<div class="header-icon-wrapper" title="选择过滤条件">
<icon-filter />
</div>
<!-- 搜索 -->
<div class="header-icon-wrapper" title="搜索">
<icon-search /> <icon-search />
</template> </div>
</a-input> <!-- 重置 -->
<!-- 条件 --> <div class="header-icon-wrapper" title="重置">
<div class="header-icon-wrapper"> <icon-refresh />
<icon-filter /> </div>
</div> </a-space>
<!-- 刷新 --> </div>
<div class="header-icon-wrapper">
<icon-refresh />
</div>
</a-space>
</div> </div>
</div> </div>
</div> </div>
<!-- 固定身体 --> <!-- 身体部分 -->
<div class="card-list-layout-body"> <div class="card-list-layout-body">
<!-- 卡片列表 --> <!-- 卡片列表 -->
<a-row v-if="list.length === 0" <a-row v-if="list.length !== 0"
:gutter="cardLayoutGutter"> :gutter="cardLayoutGutter">
<!-- 添加卡片 -->
<a-col v-if="createCardPosition === 'head'" v-bind="cardLayoutCols">
<CreateCard :card-height="cardHeight" :create-card-description="createCardDescription" />
</a-col>
<!-- 数据卡片 --> <!-- 数据卡片 -->
<a-col v-for="item in list" <a-col v-for="item in list"
:key="item.id" :key="item.id"
v-bind="cardLayoutCols"> v-bind="cardLayoutCols">
<a-card class="general-card card-list-item" <a-card class="general-card card-list-item"
:style="{ height: `${cardHeight}px` }"
:body-style="{ height: 'calc(100% - 58px)' }"
:bordered="false" :bordered="false"
:hoverable="true"> :hoverable="true">
<template #title> <template #title>
@@ -59,29 +79,19 @@
</a-card> </a-card>
</a-col> </a-col>
<!-- 添加卡片 --> <!-- 添加卡片 -->
<a-col v-bind="cardLayoutCols"> <a-col v-if="createCardPosition === 'tail'" v-bind="cardLayoutCols">
<a-card class="general-card card-list-item" <CreateCard :card-height="cardHeight" :create-card-description="createCardDescription" />
:body-style="{ height: '100%' }"
:bordered="false"
:hoverable="true">
<div class="create-card-body">
<icon-plus class="create-card-body-icon" />
<span class="create-card-body-text">点击进行创建</span>
</div>
</a-card>
</a-col> </a-col>
</a-row> </a-row>
<!-- 空列表 --> <!-- 空列表 -->
<template v-else> <template v-else>
<a-card class="general-card empty-list-card" <a-card class="general-card empty-list-card"
:style="{ height: `${cardHeight * 2 + 16}px` }"
:body-style="{ height: '100%' }"> :body-style="{ height: '100%' }">
<a-empty description="暂无数据 点击进行创建" /> <a-empty :class="{'empty-list-card-body': true, 'empty-list-card-body-creatable': emptyToCreate }"
:description="emptyDescription" />
</a-card> </a-card>
</template> </template>
<!-- 翻页区域 -->
<div>
page 区域
</div>
</div> </div>
</div> </div>
</template> </template>
@@ -93,21 +103,30 @@
</script> </script>
<script setup lang="ts"> <script setup lang="ts">
import { computed, ref } from 'vue'; import { compile, computed, h, ref } from 'vue';
import { useAppStore } from '@/store'; import { useAppStore } from '@/store';
import { useCardPagination } from '@/types/table';
const appStore = useAppStore(); const appStore = useAppStore();
const menuWidth = computed(() => { const headerWidth = computed(() => {
return appStore.menu && !appStore.topMenu && !appStore.hideMenu const menuWidth = appStore.menu && !appStore.topMenu && !appStore.hideMenu
? appStore.menuCollapse ? 48 : appStore.menuWidth ? appStore.menuCollapse ? 48 : appStore.menuWidth
: 0; : 0;
return `calc(100% - ${menuWidth}px)`;
}); });
// props
const pagination = useCardPagination();
const cardHeight = 120;
const createCardDescription = '点击此处进行创建';
const emptyToCreate = true;
const emptyDescription = '暂无数据 点击此处进行创建';
// head tail false
const createCardPosition = 'head';
const cardLayoutGutter = [ const cardLayoutGutter = [
{ xs: 16, sm: 16, md: 16 }, { xs: 16, sm: 16, md: 16 },
{ xs: 16, sm: 16, md: 16 } { xs: 16, sm: 16, md: 16 }
]; ];
const cardLayoutCols = { const cardLayoutCols = {
xs: 24, xs: 24,
sm: 12, sm: 12,
@@ -116,56 +135,80 @@
xl: 6, xl: 6,
xxl: 4, xxl: 4,
}; };
const list = ref<Array<any>>([]); const list = ref<Array<any>>([]);
for (let i = 0; i < 18; i++) { for (let i = 0; i < 270; i++) {
list.value.push({ list.value.push({
id: i + 1, id: i + 1,
name: `名称 ${i + 1}`, name: `名称 ${i + 1}`,
host: `192.168.1.${i}` host: `192.168.1.${i}`
}); });
} }
pagination.total = 270;
// 创建卡片
const CreateCard = {
props: ['cardHeight', 'createCardDescription'],
setup(props: { cardHeight: any; createCardDescription: any; }) {
return () => {
return h(compile(`
<a-card class="general-card card-list-item create-card"
:style="{ height: '${props.cardHeight}px' }"
:body-style="{ height: '100%' }"
:bordered="false"
:hoverable="true">
<div class="create-card-body">
<icon-plus class="create-card-body-icon" />
<span class="create-card-body-text">${props.createCardDescription}</span>
</div>
</a-card>
`));
};
}
};
</script> </script>
<style scoped lang="less"> <style scoped lang="less">
@header-height: 48; @header-info-height: 48px;
@top-width: 16 + 24 + 16 + 48 + 16; @header-handler-height: 48px;
@header-height-px: @{header-height}px; @top-height: 16 + @header-info-height + @header-handler-height + 12px;
@top-width-px: @{top-width}px;
@card-height: 120;
@card-height-px: @{card-height}px;
@empty-list-card-height: 120 * 2 + 16;
@empty-list-card-height-px: @{empty-list-card-height}px;
.card-list-layout-body {
margin-top: @top-width-px;
}
.card-list-layout { .card-list-layout {
&-top { &-header {
padding: 16px; margin: -16px -16px 0 -16px;
padding: 16px 16px 12px 16px;
position: fixed; position: fixed;
background: var(--color-fill-2); background: var(--color-fill-2);
z-index: 999; z-index: 999;
height: @top-width-px; height: @top-height;
transition: none; transition: none;
&-wrapper {
background: var(--color-bg-4);
padding: 0 12px;
border-radius: 4px;
}
} }
&-body { &-body {
padding: 0 16px 16px 16px; margin-top: @top-height - 16px;
padding-top: 4px;
} }
.card-list-header { .card-list-info {
height: @header-info-height;
border-bottom: 1px solid var(--color-border-2);
display: flex;
justify-content: space-between;
align-items: center;
}
.card-list-handler {
height: @header-handler-height;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
background: var(--color-bg-4);
height: @header-height-px;
padding: 12px;
margin-top: 16px;
&-left { &-left {
display: flex; display: flex;
@@ -184,8 +227,8 @@
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 27px;
height: 27px; height: 27px;
padding: 6px;
color: var(--color-text-2); color: var(--color-text-2);
background: var(--color-fill-2); background: var(--color-fill-2);
border-radius: 2px; border-radius: 2px;
@@ -198,45 +241,39 @@
background: var(--color-fill-3); background: var(--color-fill-3);
} }
.card-list-item { :deep(.create-card) {
height: @card-height-px;
transition-property: all;
}
.card-list-item:hover { &-body {
transform: translateY(-4px); width: 100%;
box-shadow: 2px 2px 12px rgba(0, 0, 0, .15); height: 100%;
} display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
cursor: pointer;
.create-card-body { &-icon {
width: 100%; font-size: 18px;
height: 100%; margin-bottom: 4px;
display: flex; }
align-items: center;
flex-direction: column;
justify-content: center;
cursor: pointer;
&-icon {
font-size: 18px;
margin-bottom: 4px;
}
&-text {
color: rgb(var(--arcoblue-6)) !important;
} }
} }
.empty-list-card { .empty-list-card {
height: @empty-list-card-height-px;
}
.empty-list { &-body {
height: 100%; height: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
flex-direction: column; justify-content: center;
justify-content: center; flex-direction: column;
padding: 0;
}
&-body-creatable {
cursor: pointer;
}
} }
</style> </style>