项目初始化

This commit is contained in:
2026-03-24 11:40:47 +08:00
parent 61d3520d11
commit fc00fb634c
4 changed files with 923 additions and 990 deletions

View File

@@ -7,17 +7,9 @@
</div> </div>
<div class="erp-section erp-upper-section"> <div class="erp-section erp-upper-section">
<div <div v-for="item in getComponentsBySortRange(1, 3)" :key="item.sort" class="erp-col erp-col-1-3">
v-for="item in getComponentsBySortRange(1, 3)"
:key="item.sort"
class="erp-col erp-col-1-3"
>
<div class="erp-card"> <div class="erp-card">
<component <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -25,17 +17,9 @@
<div class="erp-section erp-middle-section"> <div class="erp-section erp-middle-section">
<div class="erp-col erp-col-1-2"> <div class="erp-col erp-col-1-2">
<div class="erp-inner-layout"> <div class="erp-inner-layout">
<div <div v-for="item in getComponentsBySortRange(4, 5)" :key="item.sort" class="erp-col erp-col-1-2">
v-for="item in getComponentsBySortRange(4, 5)"
:key="item.sort"
class="erp-col erp-col-1-2"
>
<div class="erp-card"> <div class="erp-card">
<component <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -54,17 +38,9 @@
<div class="erp-section erp-lower-section"> <div class="erp-section erp-lower-section">
<div class="erp-col erp-col-1-2"> <div class="erp-col erp-col-1-2">
<div class="erp-inner-layout"> <div class="erp-inner-layout">
<div <div v-for="item in getComponentsBySortRange(7, 8)" :key="item.sort" class="erp-col erp-col-1-2">
v-for="item in getComponentsBySortRange(7, 8)"
:key="item.sort"
class="erp-col erp-col-1-2"
>
<div class="erp-card"> <div class="erp-card">
<component <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -83,85 +59,79 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch, onMounted, defineAsyncComponent } from 'vue'; import { ref, watch, onMounted, defineAsyncComponent } from 'vue';
import { useRoute } from 'vue-router'; import { useRoute } from 'vue-router';
import type { Component } from 'vue'; import type { Component } from 'vue';
import ChartTop from './components/ChartTop.vue'; import ChartTop from './components/ChartTop.vue';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo'; import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo';
const route = useRoute(); const route = useRoute();
// 1. 完善类型定义,避免 any 类型 const FormValues = ref({
const FormValues = ref({ yearDate: route.query.yearDate || '',
yearDate: route.query.yearDate || '' });
});
// 2. 定义组件映射的类型 interface ComponentMap {
interface ComponentMap {
[key: string]: Component; [key: string]: Component;
} }
// 3. 初始化时赋空数组,避免 undefined 问题 const componentMap = ref<ComponentMap>({});
const componentMap = ref<ComponentMap>({}); const chartData = ref<MyChartInfo[]>([]);
const chartData = ref<MyChartInfo[]>([]);
// 4. 优化空值处理 const getSortValue = (item: MyChartInfo) => Number(item.sort ?? 0);
const getComponentBySort = (sort: number): MyChartInfo | undefined => {
const getComponentBySort = (sort: number): MyChartInfo | undefined => {
if (!chartData.value.length) return undefined; if (!chartData.value.length) return undefined;
return chartData.value.find(item => item.sort === sort); return chartData.value.find((item) => getSortValue(item) === sort);
}; };
const getComponentsBySortRange = (start: number, end: number): MyChartInfo[] => { const getComponentsBySortRange = (start: number, end: number): MyChartInfo[] => {
if (!chartData.value.length) return []; if (!chartData.value.length) return [];
return chartData.value.filter(item => item.sort >= start && item.sort <= end); return chartData.value.filter((item) => {
}; const sort = getSortValue(item);
return sort >= start && sort <= end;
});
};
// 5. 优化组件加载函数 const loadComponent = (vueName: string) => {
const loadComponent = (vueName: string) => {
return defineAsyncComponent({ return defineAsyncComponent({
loader: () => import(`./components/${vueName}.vue`), loader: () => import(`./components/${vueName}.vue`),
delay: 200, delay: 200,
timeout: 5000 timeout: 5000,
}); });
}; };
// 6. 封装数据获取逻辑 async function getChartList() {
async function getChartList() {
try { try {
const reqParams = { const reqParams = {
chartCode: 'erp' chartCode: 'erp',
}; };
const res = await myChartInfoListAll(reqParams); const res = await myChartInfoListAll(reqParams);
chartData.value = res || []; chartData.value = res || [];
// 排序确保顺序正确 chartData.value.sort((a, b) => getSortValue(a) - getSortValue(b));
chartData.value.sort((a, b) => a.sort - b.sort);
} catch (error) { } catch (error) {
console.error('获取数据失败:', error); console.error('获取数据失败:', error);
chartData.value = []; chartData.value = [];
} }
} }
// 7. 监听路由参数变化 watch(
watch(
() => route.query.yearDate, () => route.query.yearDate,
(newVal) => { (newVal) => {
FormValues.value.yearDate = newVal || ''; FormValues.value.yearDate = newVal || '';
}, },
{ {
deep: true, deep: true,
immediate: true immediate: true,
} },
); );
onMounted(async () => { onMounted(async () => {
try { try {
await getChartList(); await getChartList();
const newComponentMap: ComponentMap = {}; const newComponentMap: ComponentMap = {};
// 获取唯一的组件名称 const uniqueComponents = [...new Set(chartData.value.map((item) => item.vueName))];
const uniqueComponents = [...new Set(chartData.value.map(item => item.vueName))];
// 加载所有需要的组件
for (const vueName of uniqueComponents) { for (const vueName of uniqueComponents) {
if (vueName) { if (vueName) {
newComponentMap[vueName] = loadComponent(vueName); newComponentMap[vueName] = loadComponent(vueName);
@@ -172,11 +142,11 @@ onMounted(async () => {
} catch (error) { } catch (error) {
console.error('加载图表数据失败:', error); console.error('加载图表数据失败:', error);
} }
}); });
</script> </script>
<style scoped> <style scoped>
.erp-layout-container { .erp-layout-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
@@ -187,49 +157,49 @@ onMounted(async () => {
box-sizing: border-box; box-sizing: border-box;
background-color: transparent; background-color: transparent;
overflow: hidden; overflow: hidden;
} }
.erp-section { .erp-section {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.erp-top-header { .erp-top-header {
height: 10%; height: 10%;
} }
.erp-upper-section, .erp-upper-section,
.erp-middle-section, .erp-middle-section,
.erp-lower-section { .erp-lower-section {
height: 30%; height: 30%;
} }
.erp-col { .erp-col {
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.erp-col-1-3 { .erp-col-1-3 {
width: calc((100% - 4px) / 3); width: calc((100% - 4px) / 3);
} }
.erp-col-1-2 { .erp-col-1-2 {
width: calc((100% - 2px) / 2); width: calc((100% - 2px) / 2);
} }
.erp-inner-layout { .erp-inner-layout {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
} }
.erp-card { .erp-card {
width: 100%; width: 100%;
height: 100%; height: 100%;
background-color: rgba(15, 52, 96, 0.1); background-color: rgba(15, 52, 96, 0.1);
@@ -245,19 +215,19 @@ onMounted(async () => {
backdrop-filter: blur(2px); backdrop-filter: blur(2px);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
min-height: 0; min-height: 0;
} }
.full-card { .full-card {
width: 100%; width: 100%;
} }
.erp-card:hover { .erp-card:hover {
box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2); box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2);
border-color: rgba(60, 156, 255, 0.6); border-color: rgba(60, 156, 255, 0.6);
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.erp-card h3 { .erp-card h3 {
font-size: 16px; font-size: 16px;
margin-bottom: 8px; margin-bottom: 8px;
letter-spacing: 1px; letter-spacing: 1px;
@@ -265,27 +235,27 @@ onMounted(async () => {
-webkit-background-clip: text; -webkit-background-clip: text;
-webkit-text-fill-color: transparent; -webkit-text-fill-color: transparent;
font-weight: 600; font-weight: 600;
} }
.erp-card p { .erp-card p {
font-size: 13px; font-size: 13px;
opacity: 0.75; opacity: 0.75;
color: #b4c7e7; color: #b4c7e7;
text-align: center; text-align: center;
line-height: 1.5; line-height: 1.5;
} }
.empty-card { .empty-card {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100%; height: 100%;
color: #88a0c2; color: #88a0c2;
font-size: 14px; font-size: 14px;
} }
/* 优化移动端样式 */ /* 优化移动端样式 */
@media (max-width: 1600px) { @media (max-width: 1600px) {
.erp-layout-container { .erp-layout-container {
padding: 2px; padding: 2px;
gap: 2px; gap: 2px;
@@ -311,9 +281,9 @@ onMounted(async () => {
.erp-card p { .erp-card p {
font-size: 12px; font-size: 12px;
} }
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.erp-layout-container { .erp-layout-container {
flex-direction: column; flex-direction: column;
height: auto; height: auto;
@@ -343,9 +313,9 @@ onMounted(async () => {
.erp-card { .erp-card {
padding: 8px; /* 增加移动端内边距,提升体验 */ padding: 8px; /* 增加移动端内边距,提升体验 */
} }
} }
@media (max-height: 900px) { @media (max-height: 900px) {
.erp-layout-container { .erp-layout-container {
padding: 2px; padding: 2px;
gap: 2px; gap: 2px;
@@ -363,5 +333,5 @@ onMounted(async () => {
.erp-card p { .erp-card p {
font-size: 12px; font-size: 12px;
} }
} }
</style> </style>

View File

@@ -8,44 +8,20 @@
<div class="work-section work-main-section"> <div class="work-section work-main-section">
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(1, 3)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(1, 3)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(4, 5)" :key="item.sort" class="work-card work-card-1-2">
v-for="item in getComponentsBySortRange(4, 5)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-2"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(6, 7)" :key="item.sort" class="work-card work-card-1-2">
v-for="item in getComponentsBySortRange(6, 7)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-2"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -53,36 +29,46 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import type { Component } from 'vue';
import ChartTop from './components/ChartTop.vue'; import { useRoute } from 'vue-router';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo'; import ChartTop from './components/ChartTop.vue';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo';
const route = useRoute(); const route = useRoute();
const FormValues = ref({ const FormValues = ref({
yearDate: route.query.yearDate yearDate: route.query.yearDate || '',
}); });
watch( watch(
() => route.query.yearDate, () => route.query.yearDate,
(newVal) => { (newVal) => {
FormValues.value.yearDate = newVal; FormValues.value.yearDate = newVal || '';
}, },
{ {
deep: true, deep: true,
immediate: true immediate: true,
},
);
interface ComponentMap {
[key: string]: Component;
} }
);
const componentMap = ref({}); const componentMap = ref<ComponentMap>({});
const chartData = ref([]); const chartData = ref<MyChartInfo[]>([]);
const getComponentsBySortRange = (start, end) => { const getSortValue = (item: MyChartInfo) => Number(item.sort ?? 0);
return chartData.value.filter(item => item.sort >= start && item.sort <= end);
};
const loadComponent = async (vueName) => { const getComponentsBySortRange = (start: number, end: number): MyChartInfo[] => {
return chartData.value.filter((item) => {
const sort = getSortValue(item);
return sort >= start && sort <= end;
});
};
const loadComponent = async (vueName: string): Promise<Component | null> => {
try { try {
const module = await import(`./components/${vueName}.vue`); const module = await import(`./components/${vueName}.vue`);
return module.default; return module.default;
@@ -90,42 +76,42 @@ const loadComponent = async (vueName) => {
console.error('加载组件失败', error); console.error('加载组件失败', error);
return null; return null;
} }
}; };
async function getChartList(){ async function getChartList() {
try { try {
const reqParams = { const reqParams = {
chartCode: 'home' chartCode: 'home',
} };
const res = await myChartInfoListAll(reqParams) const res = await myChartInfoListAll(reqParams);
chartData.value = res || [] chartData.value = res || [];
} catch (error) { } catch (error) {
console.error('获取数据失败:', error); console.error('获取数据失败:', error);
chartData.value = [] chartData.value = [];
}
} }
}
onMounted(async () => { onMounted(async () => {
try { try {
await getChartList(); await getChartList();
chartData.value = chartData.value.sort((a, b) => a.sort - b.sort);
const newComponentMap = {}; const newComponentMap: ComponentMap = {};
const uniqueComponents = [...new Set(chartData.value.map(item => item.vueName))]; const uniqueComponents = [...new Set(chartData.value.map((item) => item.vueName))];
for (const vueName of uniqueComponents) { for (const vueName of uniqueComponents) {
const component = await loadComponent(vueName); if (vueName) {
if (component) { newComponentMap[vueName] = loadComponent(vueName);
newComponentMap[vueName] = component;
} }
} }
componentMap.value = newComponentMap; componentMap.value = newComponentMap;
} catch (error) { } catch (error) {
console.error('加载图表数据失败:', error); console.error('加载图表数据失败:', error);
} }
}); });
</script> </script>
<style scoped> <style scoped>
.work-layout-container { .work-layout-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
@@ -136,51 +122,51 @@ onMounted(async () => {
box-sizing: border-box; box-sizing: border-box;
background-color: transparent; background-color: transparent;
overflow: hidden; overflow: hidden;
} }
.work-section { .work-section {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-top-header { .work-top-header {
height: 10%; height: 10%;
} }
.work-main-section { .work-main-section {
height: 90%; height: 90%;
flex-direction: column; flex-direction: column;
} }
/* 行样式 */ /* 行样式 */
.work-row { .work-row {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-row-1-3 { .work-row-1-3 {
height: calc((100% - 4px) / 3); height: calc((100% - 4px) / 3);
} }
/* 一行 3 个时的卡片宽度 */ /* 一行 3 个时的卡片宽度 */
.work-card-1-3 { .work-card-1-3 {
width: calc((100% - 4px) / 3); width: calc((100% - 4px) / 3);
height: 100%; height: 100%;
} }
/* 一行 2 个时的卡片宽度 */ /* 一行 2 个时的卡片宽度 */
.work-card-1-2 { .work-card-1-2 {
width: calc((100% - 2px) / 2); width: calc((100% - 2px) / 2);
height: 100%; height: 100%;
} }
.work-card { .work-card {
width: 100%; width: 100%;
background-color: rgba(15, 52, 96, 0.1); background-color: rgba(15, 52, 96, 0.1);
border: 1px solid rgba(26, 80, 139, 0.3); border: 1px solid rgba(26, 80, 139, 0.3);
@@ -196,20 +182,20 @@ onMounted(async () => {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
min-height: 0; min-height: 0;
margin: 0; margin: 0;
} }
.full-card { .full-card {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.work-card:hover { .work-card:hover {
box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2); box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2);
border-color: rgba(60, 156, 255, 0.6); border-color: rgba(60, 156, 255, 0.6);
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.work-card h3 { .work-card h3 {
font-size: 16px; font-size: 16px;
margin-bottom: 8px; margin-bottom: 8px;
letter-spacing: 1px; letter-spacing: 1px;
@@ -217,35 +203,35 @@ onMounted(async () => {
-webkit-background-clip: text; -webkit-background-clip: text;
-webkit-text-fill-color: transparent; -webkit-text-fill-color: transparent;
font-weight: 600; font-weight: 600;
} }
.work-card p { .work-card p {
font-size: 13px; font-size: 13px;
opacity: 0.75; opacity: 0.75;
color: #b4c7e7; color: #b4c7e7;
text-align: center; text-align: center;
line-height: 1.5; line-height: 1.5;
} }
.empty-card { .empty-card {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100%; height: 100%;
color: #88a0c2; color: #88a0c2;
font-size: 14px; font-size: 14px;
} }
@media (max-width: 1600px) { @media (max-width: 1600px) {
.work-card h3 { .work-card h3 {
font-size: 14px; font-size: 14px;
} }
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.work-layout-container { .work-layout-container {
flex-direction: column; flex-direction: column;
height: auto; height: auto;
@@ -267,9 +253,9 @@ onMounted(async () => {
height: 120px; height: 120px;
margin-bottom: 2px; margin-bottom: 2px;
} }
} }
@media (max-height: 900px) { @media (max-height: 900px) {
.work-card h3 { .work-card h3 {
font-size: 14px; font-size: 14px;
margin-bottom: 6px; margin-bottom: 6px;
@@ -277,5 +263,5 @@ onMounted(async () => {
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
</style> </style>

View File

@@ -8,44 +8,20 @@
<div class="work-section work-main-section"> <div class="work-section work-main-section">
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(1, 3)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(1, 3)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(4, 6)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(4, 6)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
<div class="work-row work-row-1-3"> <div class="work-row work-row-1-3">
<div <div v-for="item in getComponentsBySortRange(7, 9)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(7, 9)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -53,36 +29,46 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import type { Component } from 'vue';
import ChartTop from './components/ChartTop.vue'; import { useRoute } from 'vue-router';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo'; import ChartTop from './components/ChartTop.vue';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo';
const route = useRoute(); const route = useRoute();
const FormValues = ref({ const FormValues = ref({
yearDate: route.query.year yearDate: route.query.yearDate || '',
}); });
watch( watch(
() => route.query.yearDate, () => route.query.yearDate,
(newVal) => { (newVal) => {
FormValues.value.yearDate = newVal; FormValues.value.yearDate = newVal || '';
}, },
{ {
deep: true, deep: true,
immediate: true immediate: true,
},
);
interface ComponentMap {
[key: string]: Component;
} }
);
const componentMap = ref({}); const componentMap = ref<ComponentMap>({});
const chartData = ref([]); const chartData = ref<MyChartInfo[]>([]);
const getComponentsBySortRange = (start, end) => { const getSortValue = (item: MyChartInfo) => Number(item.sort ?? 0);
return chartData.value.filter(item => item.sort >= start && item.sort <= end);
};
const loadComponent = async (vueName) => { const getComponentsBySortRange = (start: number, end: number): MyChartInfo[] => {
return chartData.value.filter((item) => {
const sort = getSortValue(item);
return sort >= start && sort <= end;
});
};
const loadComponent = async (vueName: string): Promise<Component | null> => {
try { try {
const module = await import(`./components/${vueName}.vue`); const module = await import(`./components/${vueName}.vue`);
return module.default; return module.default;
@@ -90,42 +76,42 @@ const loadComponent = async (vueName) => {
console.error('加载组件失败', error); console.error('加载组件失败', error);
return null; return null;
} }
}; };
async function getChartList(){ async function getChartList() {
try { try {
const reqParams = { const reqParams = {
chartCode: 'sys' chartCode: 'sys',
} };
const res = await myChartInfoListAll(reqParams) const res = await myChartInfoListAll(reqParams);
chartData.value = res || [] chartData.value = res || [];
} catch (error) { } catch (error) {
console.error('获取数据失败:', error); console.error('获取数据失败:', error);
chartData.value = [] chartData.value = [];
}
} }
}
onMounted(async () => { onMounted(async () => {
try { try {
await getChartList(); await getChartList();
chartData.value = chartData.value.sort((a, b) => a.sort - b.sort);
const newComponentMap = {}; const newComponentMap: ComponentMap = {};
const uniqueComponents = [...new Set(chartData.value.map(item => item.vueName))]; const uniqueComponents = [...new Set(chartData.value.map((item) => item.vueName))];
for (const vueName of uniqueComponents) { for (const vueName of uniqueComponents) {
const component = await loadComponent(vueName); if (vueName) {
if (component) { newComponentMap[vueName] = loadComponent(vueName);
newComponentMap[vueName] = component;
} }
} }
componentMap.value = newComponentMap; componentMap.value = newComponentMap;
} catch (error) { } catch (error) {
console.error('加载图表数据失败:', error); console.error('加载图表数据失败:', error);
} }
}); });
</script> </script>
<style scoped> <style scoped>
.work-layout-container { .work-layout-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
@@ -136,43 +122,43 @@ onMounted(async () => {
box-sizing: border-box; box-sizing: border-box;
background-color: transparent; background-color: transparent;
overflow: hidden; overflow: hidden;
} }
.work-section { .work-section {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-top-header { .work-top-header {
height: 10%; height: 10%;
} }
.work-main-section { .work-main-section {
height: 90%; height: 90%;
flex-direction: column; flex-direction: column;
} }
.work-row { .work-row {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-row-1-3 { .work-row-1-3 {
height: calc((100% - 4px) / 3); height: calc((100% - 4px) / 3);
} }
.work-card-1-3 { .work-card-1-3 {
width: calc((100% - 4px) / 3); width: calc((100% - 4px) / 3);
height: 100%; height: 100%;
} }
.work-card { .work-card {
width: 100%; width: 100%;
background-color: rgba(15, 52, 96, 0.1); background-color: rgba(15, 52, 96, 0.1);
border: 1px solid rgba(26, 80, 139, 0.3); border: 1px solid rgba(26, 80, 139, 0.3);
@@ -188,20 +174,20 @@ onMounted(async () => {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
min-height: 0; min-height: 0;
margin: 0; margin: 0;
} }
.full-card { .full-card {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.work-card:hover { .work-card:hover {
box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2); box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2);
border-color: rgba(60, 156, 255, 0.6); border-color: rgba(60, 156, 255, 0.6);
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.work-card h3 { .work-card h3 {
font-size: 16px; font-size: 16px;
margin-bottom: 8px; margin-bottom: 8px;
letter-spacing: 1px; letter-spacing: 1px;
@@ -209,35 +195,35 @@ onMounted(async () => {
-webkit-background-clip: text; -webkit-background-clip: text;
-webkit-text-fill-color: transparent; -webkit-text-fill-color: transparent;
font-weight: 600; font-weight: 600;
} }
.work-card p { .work-card p {
font-size: 13px; font-size: 13px;
opacity: 0.75; opacity: 0.75;
color: #b4c7e7; color: #b4c7e7;
text-align: center; text-align: center;
line-height: 1.5; line-height: 1.5;
} }
.empty-card { .empty-card {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100%; height: 100%;
color: #88a0c2; color: #88a0c2;
font-size: 14px; font-size: 14px;
} }
@media (max-width: 1600px) { @media (max-width: 1600px) {
.work-card h3 { .work-card h3 {
font-size: 14px; font-size: 14px;
} }
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.work-layout-container { .work-layout-container {
flex-direction: column; flex-direction: column;
height: auto; height: auto;
@@ -258,9 +244,9 @@ onMounted(async () => {
height: 120px; height: 120px;
margin-bottom: 2px; margin-bottom: 2px;
} }
} }
@media (max-height: 900px) { @media (max-height: 900px) {
.work-card h3 { .work-card h3 {
font-size: 14px; font-size: 14px;
margin-bottom: 6px; margin-bottom: 6px;
@@ -268,5 +254,5 @@ onMounted(async () => {
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
</style> </style>

View File

@@ -7,35 +7,19 @@
</div> </div>
<div class="work-section work-main-section"> <div class="work-section work-main-section">
<div class="work-col work-col-1-3 work-left-col"> <div class="work-col work-col-1-3 work-left-col">
<div <div v-for="item in getComponentsBySortRange(1, 3)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(1, 3)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
<div class="work-col work-col-1-3 work-middle-col"> <div class="work-col work-col-1-3 work-middle-col">
<div <div :key="getComponentBySort(4)?.sort" class="work-card work-card-2-3" v-if="getComponentBySort(4)">
:key="getComponentBySort(4)?.sort"
class="work-card work-card-2-3"
v-if="getComponentBySort(4)"
>
<component <component
:is="componentMap[getComponentBySort(4).vueName]" :is="componentMap[getComponentBySort(4).vueName]"
:formParams="FormValues" :formParams="FormValues"
v-if="componentMap[getComponentBySort(4).vueName]" v-if="componentMap[getComponentBySort(4).vueName]"
/> />
</div> </div>
<div <div :key="getComponentBySort(5)?.sort" class="work-card work-card-1-3" v-if="getComponentBySort(5)">
:key="getComponentBySort(5)?.sort"
class="work-card work-card-1-3"
v-if="getComponentBySort(5)"
>
<component <component
:is="componentMap[getComponentBySort(5).vueName]" :is="componentMap[getComponentBySort(5).vueName]"
:formParams="FormValues" :formParams="FormValues"
@@ -44,16 +28,8 @@
</div> </div>
</div> </div>
<div class="work-col work-col-1-3 work-right-col"> <div class="work-col work-col-1-3 work-right-col">
<div <div v-for="item in getComponentsBySortRange(6, 8)" :key="item.sort" class="work-card work-card-1-3">
v-for="item in getComponentsBySortRange(6, 8)" <component :is="componentMap[item.vueName]" :formParams="FormValues" v-if="componentMap[item.vueName]" />
:key="item.sort"
class="work-card work-card-1-3"
>
<component
:is="componentMap[item.vueName]"
:formParams="FormValues"
v-if="componentMap[item.vueName]"
/>
</div> </div>
</div> </div>
</div> </div>
@@ -61,40 +37,50 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch, onMounted } from 'vue'; import { ref, watch, onMounted } from 'vue';
import { useRoute } from 'vue-router'; import type { Component } from 'vue';
import ChartTop from './components/ChartTop.vue'; import { useRoute } from 'vue-router';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo'; import ChartTop from './components/ChartTop.vue';
import { MyChartInfo, myChartInfoListAll } from '@jeesite/biz/api/biz/myChartInfo';
const route = useRoute(); const route = useRoute();
const FormValues = ref({ const FormValues = ref({
yearDate: route.query.yearDate yearDate: route.query.yearDate || '',
}); });
watch( watch(
() => route.query.yearDate, () => route.query.yearDate,
(newVal) => { (newVal) => {
FormValues.value.yearDate = newVal; FormValues.value.yearDate = newVal || '';
}, },
{ {
deep: true, deep: true,
immediate: true immediate: true,
},
);
interface ComponentMap {
[key: string]: Component;
} }
);
const componentMap = ref({}); const componentMap = ref<ComponentMap>({});
const chartData = ref([]); const chartData = ref<MyChartInfo[]>([]);
const getComponentBySort = (sort) => { const getSortValue = (item: MyChartInfo) => Number(item.sort ?? 0);
return chartData.value.find(item => item.sort === sort);
};
const getComponentsBySortRange = (start, end) => { const getComponentBySort = (sort: number): MyChartInfo | undefined => {
return chartData.value.filter(item => item.sort >= start && item.sort <= end); return chartData.value.find((item) => getSortValue(item) === sort);
}; };
const loadComponent = async (vueName) => { const getComponentsBySortRange = (start: number, end: number): MyChartInfo[] => {
return chartData.value.filter((item) => {
const sort = getSortValue(item);
return sort >= start && sort <= end;
});
};
const loadComponent = async (vueName: string): Promise<Component | null> => {
try { try {
const module = await import(`./components/${vueName}.vue`); const module = await import(`./components/${vueName}.vue`);
return module.default; return module.default;
@@ -102,42 +88,42 @@ const loadComponent = async (vueName) => {
console.error('加载组件失败', error); console.error('加载组件失败', error);
return null; return null;
} }
}; };
async function getChartList(){ async function getChartList() {
try { try {
const reqParams = { const reqParams = {
chartCode: 'work' chartCode: 'work',
} };
const res = await myChartInfoListAll(reqParams) const res = await myChartInfoListAll(reqParams);
chartData.value = res || [] chartData.value = res || [];
} catch (error) { } catch (error) {
console.error('获取数据失败:', error); console.error('获取数据失败:', error);
chartData.value = [] chartData.value = [];
}
} }
}
onMounted(async () => { onMounted(async () => {
try { try {
await getChartList(); await getChartList();
chartData.value = chartData.value.sort((a, b) => a.sort - b.sort);
const newComponentMap = {}; const newComponentMap: ComponentMap = {};
const uniqueComponents = [...new Set(chartData.value.map(item => item.vueName))]; const uniqueComponents = [...new Set(chartData.value.map((item) => item.vueName))];
for (const vueName of uniqueComponents) { for (const vueName of uniqueComponents) {
const component = await loadComponent(vueName); if (vueName) {
if (component) { newComponentMap[vueName] = loadComponent(vueName);
newComponentMap[vueName] = component;
} }
} }
componentMap.value = newComponentMap; componentMap.value = newComponentMap;
} catch (error) { } catch (error) {
console.error('加载图表数据失败:', error); console.error('加载图表数据失败:', error);
} }
}); });
</script> </script>
<style scoped> <style scoped>
.work-layout-container { .work-layout-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: flex; display: flex;
@@ -148,49 +134,51 @@ onMounted(async () => {
box-sizing: border-box; box-sizing: border-box;
background-color: transparent; background-color: transparent;
overflow: hidden; overflow: hidden;
} }
.work-section { .work-section {
width: 100%; width: 100%;
display: flex; display: flex;
gap: 2px; gap: 2px;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-top-header { .work-top-header {
height: 10%; height: 10%;
} }
.work-main-section { .work-main-section {
height: 90%; height: 90%;
} }
.work-col { .work-col {
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
overflow: hidden; overflow: hidden;
} }
.work-col-1-3 { .work-col-1-3 {
width: calc((100% - 4px) / 3); width: calc((100% - 4px) / 3);
} }
.work-left-col, .work-middle-col, .work-right-col { .work-left-col,
.work-middle-col,
.work-right-col {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 2px; gap: 2px;
} }
.work-card-1-3 { .work-card-1-3 {
height: calc((100% - 4px) / 3); height: calc((100% - 4px) / 3);
} }
.work-card-2-3 { .work-card-2-3 {
height: calc(2 * ((100% - 4px) / 3) + 2px); height: calc(2 * ((100% - 4px) / 3) + 2px);
} }
.work-card { .work-card {
width: 100%; width: 100%;
background-color: rgba(15, 52, 96, 0.1); background-color: rgba(15, 52, 96, 0.1);
border: 1px solid rgba(26, 80, 139, 0.3); border: 1px solid rgba(26, 80, 139, 0.3);
@@ -206,20 +194,20 @@ onMounted(async () => {
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
min-height: 0; min-height: 0;
margin: 0; margin: 0;
} }
.full-card { .full-card {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.work-card:hover { .work-card:hover {
box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2); box-shadow: 0 4px 12px rgba(60, 156, 255, 0.2);
border-color: rgba(60, 156, 255, 0.6); border-color: rgba(60, 156, 255, 0.6);
transition: all 0.3s ease; transition: all 0.3s ease;
} }
.work-card h3 { .work-card h3 {
font-size: 16px; font-size: 16px;
margin-bottom: 8px; margin-bottom: 8px;
letter-spacing: 1px; letter-spacing: 1px;
@@ -227,26 +215,26 @@ onMounted(async () => {
-webkit-background-clip: text; -webkit-background-clip: text;
-webkit-text-fill-color: transparent; -webkit-text-fill-color: transparent;
font-weight: 600; font-weight: 600;
} }
.work-card p { .work-card p {
font-size: 13px; font-size: 13px;
opacity: 0.75; opacity: 0.75;
color: #b4c7e7; color: #b4c7e7;
text-align: center; text-align: center;
line-height: 1.5; line-height: 1.5;
} }
.empty-card { .empty-card {
display: flex; display: flex;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
height: 100%; height: 100%;
color: #88a0c2; color: #88a0c2;
font-size: 14px; font-size: 14px;
} }
@media (max-width: 1600px) { @media (max-width: 1600px) {
.work-layout-container { .work-layout-container {
padding: 2px; padding: 2px;
gap: 2px; gap: 2px;
@@ -272,9 +260,9 @@ onMounted(async () => {
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.work-layout-container { .work-layout-container {
flex-direction: column; flex-direction: column;
height: auto; height: auto;
@@ -293,21 +281,24 @@ onMounted(async () => {
width: 100%; width: 100%;
height: auto; height: auto;
} }
.work-left-col, .work-middle-col, .work-right-col { .work-left-col,
.work-middle-col,
.work-right-col {
flex-direction: column; flex-direction: column;
height: auto; height: auto;
gap: 2px; gap: 2px;
} }
.work-card-1-3, .work-card-2-3 { .work-card-1-3,
.work-card-2-3 {
height: 120px; height: 120px;
margin-bottom: 2px; margin-bottom: 2px;
} }
.work-card { .work-card {
padding: 2px; padding: 2px;
} }
} }
@media (max-height: 900px) { @media (max-height: 900px) {
.work-layout-container { .work-layout-container {
padding: 2px; padding: 2px;
gap: 2px; gap: 2px;
@@ -325,5 +316,5 @@ onMounted(async () => {
.work-card p { .work-card p {
font-size: 12px; font-size: 12px;
} }
} }
</style> </style>