人员台账单位和通用字段查询初步实现,还需进一步优化,钻取列表未做。

This commit is contained in:
廖德云 2025-02-13 01:51:44 +08:00
parent 1ef1384fa8
commit 2a746146f0
3 changed files with 352 additions and 1240 deletions

View File

@ -1,352 +0,0 @@
<template>
<view>
<view class="container" id="top1">
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
</uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
</picker>
</uni-col>
</uni-row>
</view>
<!-- ECharts图表 -->
<view class="chart-container">
<l-echart ref="chart" @finished="initChart" />
</view>
<!-- 数据表格 -->
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="personnelList.length > 0">
<uni-col :span="3">
<view class="titleStyle">序号</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">姓名</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">性别</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">年龄</view>
</uni-col>
<uni-col :span="6">
<view class="titleStyle">操作</view>
</uni-col>
</uni-row>
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<view v-for="(item, index) in personnelList">
<uni-col :span="3">
<view class="dataStyle">
{{ index + 1 }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.xm }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.xb_dictText }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.nl }}
</view>
</uni-col>
<uni-col :span="6">
<view class="dataStyle">
<button size="mini" type="primary" @click="detail(item)">详情</button>
</view>
</uni-col>
</view>
</uni-row>
</scroll-view>
</view>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import * as echarts from 'echarts';
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
// tableData
const bottomHeight = ref(0);
//
const chart = ref(null);
const fieldList = ref([
{
label: '性别',
value: 'xb'
},
{
label: '年龄',
value: 'nl'
},
{
label: '学历',
value: 'rylb1'
}
]); //
const selectedOrgCode = ref(''); // orgCode
const selectedOrgCodeLabel = ref('请选择单位'); //
const selectedField = ref(''); //
const selectedFieldLabel = ref('请选择字段'); //
const orgCodeGroupData = ref([]); //orgcode
const chartData = ref({}); //
const personnelList = ref([]); // initChart
const chartOption = ref({});
function detail(record) {
// console.log(record)
uni.navigateTo({
url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
});
}
onMounted(() => {
// #ifdef APP
getHeight();
// #endif
});
// #ifdef APP
const getHeight = () => {
//
const systemInfo = uni.getSystemInfoSync();
const screenHeight = systemInfo.screenHeight;
//
const query = uni.createSelectorQuery();
//
query
.select('#top1')
.boundingClientRect((rect1) => {
//
const topComponentsHeight = rect1.height;
//
bottomHeight.value = screenHeight - topComponentsHeight - 415;
})
.exec();
};
// #endif
// ECharts length departChange
//
const initChart = () => {
setTimeout(async () => {
if (!chart.value) return;
const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value);
}, 300);
};
//
const updateChart = () => {};
// orgCode children
const groupByOrgCode = (orgCode, data) => {
//
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
// null
if (filteredData.length === 0) {
return null;
}
// fieldValue
const groupedByFieldValue = {};
filteredData.forEach((item) => {
if (!groupedByFieldValue[item.fieldValue]) {
groupedByFieldValue[item.fieldValue] = {
number: 0,
ldhth: []
};
}
groupedByFieldValue[item.fieldValue].number += item.number;
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
});
//
const result = {
orgCode: orgCode,
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({
fieldValue: fieldValue,
number: groupedByFieldValue[fieldValue].number,
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] //
})),
children: []
};
// orgCode
const nextLevelOrgCodes = new Set();
filteredData.forEach((item) => {
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
nextLevelOrgCodes.add(nextLevelOrgCode);
}
});
//
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
const child = groupByOrgCode(nextLevelOrgCode, data);
if (child) {
result.children.push(child);
}
});
return result;
};
//
const fetchStatisticsData = async () => {
if (!selectedOrgCode.value || !selectedField.value) return;
try {
const res = await cxcRyDatAstatistics({
orgCode: selectedOrgCode.value,
field: selectedField.value
});
console.log(res);
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
console.log(orgCodeGroupData.value);
chartData.value = orgCodeGroupData.value;
// updateChart();
} catch (error) {
console.error('获取统计数据失败:', error);
}
};
// delimiter
const fetchPersonnelList = async (ldhthList) => {
try {
const res = await cxcRyDatAstatisticsDetails({
ldhth: ldhthList
});
console.log(res);
personnelList.value = res.data;
} catch (error) {
console.error('获取人员列表失败:', error);
}
};
//
const onOrgCodeChange = (e, data) => {
selectedOrgCode.value = e;
console.log(data.value.title);
selectedOrgCodeLabel.value = data.value.title;
fetchStatisticsData();
};
const onFieldChange = (e) => {
const index = e.detail.value;
selectedField.value = fieldList.value[index].value;
selectedFieldLabel.value = fieldList.value[index].label;
fetchStatisticsData();
};
const onChartClick = (e) => {
const { ldhth } = chartData.value;
if (ldhth && ldhth.length > 0) {
fetchPersonnelList(ldhth);
}
};
</script>
<style scoped>
.container {
margin: 20, 20, 20, 20rpx;
}
.input-group {
display: flex;
gap: 20rpx;
margin-bottom: 30rpx;
}
.input {
flex: 1;
border: 1rpx solid #ddd;
padding: 15rpx;
border-radius: 8rpx;
}
.query-btn {
background: #007aff;
color: white;
padding: 0 40rpx;
border-radius: 8rpx;
}
.stats-box {
display: flex;
justify-content: space-around;
margin: 30rpx 0;
padding: 20rpx;
background: #f8f8f8;
border-radius: 12rpx;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.label {
font-size: 24rpx;
color: #666;
}
.value {
font-size: 36rpx;
font-weight: bold;
color: #0000ff;
}
.chart-container {
height: 800rpx;
margin-top: 20rpx;
}
.titleStyle {
font-size: 12px;
color: #747474;
line-height: 30px;
height: 30px;
background: #f2f9fc;
text-align: center;
vertical-align: middle;
border-left: 1px solid #919191;
border-bottom: 1px solid #919191;
}
/* 内容样式 */
.dataStyle {
max-font-size: 14px;
/* 最大字体限制 */
min-font-size: 10px;
/* 最小字体限制 */
font-size: 12px;
color: #00007f;
line-height: 30px;
height: 30px;
font-weight: 500;
text-align: center;
vertical-align: middle;
border-bottom: 1px solid #919191;
border-left: 1px solid #919191;
text-overflow: ellipsis;
}
</style>

View File

@ -1,730 +0,0 @@
<template>
<view>
<view class="container" id="top1">
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
</uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
</picker>
</uni-col>
</uni-row>
</view>
<!-- ECharts图表 -->
<view class="chart-container">
<l-echart ref="chart" @finished="initChart" />
</view>
<!-- 数据表格 -->
<uni-row style="margin-top: 10px; margin-left: 30rpx; margin-right: 30rpx" v-if="personnelList.length > 0">
<uni-col :span="3">
<view class="titleStyle">序号</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">姓名</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">性别</view>
</uni-col>
<uni-col :span="5">
<view class="titleStyle">年龄</view>
</uni-col>
<uni-col :span="6">
<view class="titleStyle">操作</view>
</uni-col>
</uni-row>
<scroll-view scroll-y :style="{ height: bottomHeight + 'px' }">
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<view v-for="(item, index) in personnelList">
<uni-col :span="3">
<view class="dataStyle">
{{ index + 1 }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.xm }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.xb_dictText }}
</view>
</uni-col>
<uni-col :span="5">
<view class="dataStyle">
{{ item.nl }}
</view>
</uni-col>
<uni-col :span="6">
<view class="dataStyle">
<button size="mini" type="primary" @click="detail(item)">详情</button>
</view>
</uni-col>
</view>
</uni-row>
</scroll-view>
</view>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import * as echarts from 'echarts';
import { cxcRyDatAstatistics, cxcRyDatAstatisticsDetails } from '@/api/renyuan.js';
// tableData
const bottomHeight = ref(0);
//
const chart = ref(null);
const fieldList = ref([
{
label: '性别',
value: 'xb'
},
{
label: '年龄',
value: 'nl'
},
{
label: '学历',
value: 'rylb1'
}
]); //
const selectedOrgCode = ref(''); // orgCode
const selectedOrgCodeLabel = ref('请选择单位'); //
const selectedField = ref(''); //
const selectedFieldLabel = ref('请选择字段'); //
const orgCodeGroupData = ref([]); //orgcode
const chartData = ref({}); //
const personnelList = ref([]); // initChart
const chartOption = ref({});
function detail(record) {
// console.log(record)
uni.navigateTo({
url: '/pages/views/renliziyuan/renyuanxinxi/detail?data=' + encodeURIComponent(JSON.stringify(record))
});
}
onMounted(() => {
// #ifdef APP
getHeight();
// #endif
});
// #ifdef APP
const getHeight = () => {
//
const systemInfo = uni.getSystemInfoSync();
const screenHeight = systemInfo.screenHeight;
//
const query = uni.createSelectorQuery();
//
query
.select('#top1')
.boundingClientRect((rect1) => {
//
const topComponentsHeight = rect1.height;
//
bottomHeight.value = screenHeight - topComponentsHeight - 415;
})
.exec();
};
// #endif
// ECharts length departChange
//
const initChart = () => {
setTimeout(async () => {
if (!chart.value) return;
const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value);
}, 300);
};
//
const updateChart = () => {
if (!chart) return;
chartOption.value = transformToEChartsFormat(chartData.value);
//
setTimeout(async () => {
if (!chart.value) return;
const myChart = await chart.value.init(echarts);
myChart.setOption(chartOption.value);
myChart.on('click', (params) => {
try {
console.log(JSON.stringify(params.seriesIndex));
} catch (error) {
console.error('Error stringifying params:', error);
}
personnelList.value = fetchPersonnelList(params.seriesName);
});
}, 300);
};
// orgCode children
const groupByOrgCode = (orgCode, data) => {
//
const filteredData = data.filter((item) => item.orgCode.startsWith(orgCode));
// null
if (filteredData.length === 0) {
return null;
}
// fieldValue
const groupedByFieldValue = {};
filteredData.forEach((item) => {
if (!groupedByFieldValue[item.fieldValue]) {
groupedByFieldValue[item.fieldValue] = {
number: 0,
ldhth: []
};
}
groupedByFieldValue[item.fieldValue].number += item.number;
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
});
//
const result = {
orgCode: orgCode,
fieldValues: Object.keys(groupedByFieldValue).map((fieldValue) => ({
fieldValue: fieldValue,
number: groupedByFieldValue[fieldValue].number,
ldhth: [...new Set(groupedByFieldValue[fieldValue].ldhth)] //
})),
children: []
};
// orgCode
const nextLevelOrgCodes = new Set();
filteredData.forEach((item) => {
if (item.orgCode !== orgCode && item.orgCode.startsWith(orgCode)) {
const nextLevelOrgCode = item.orgCode.substring(0, orgCode.length + 3);
nextLevelOrgCodes.add(nextLevelOrgCode);
}
});
//
nextLevelOrgCodes.forEach((nextLevelOrgCode) => {
const child = groupByOrgCode(nextLevelOrgCode, data);
if (child) {
result.children.push(child);
}
});
return result;
};
//
const transformData = (selectOrgCode, inputData) => {
try {
//
const currentLevelData = {};
// orgCode
const childrenData = {};
//
inputData.forEach((item) => {
const { orgCode, fieldValue, number, ldhth } = item;
// orgCode
const currentOrgCode = selectOrgCode;
// orgCode
if (orgCode.startsWith(currentOrgCode) && orgCode.length > currentOrgCode.length) {
// orgCode
const childOrgCode = orgCode.slice(0, currentOrgCode.length + 3);
if (!childrenData[childOrgCode]) {
childrenData[childOrgCode] = {};
}
if (!childrenData[childOrgCode][fieldValue]) {
childrenData[childOrgCode][fieldValue] = { number: 0, ldhth: [] };
}
childrenData[childOrgCode][fieldValue].number += number;
childrenData[childOrgCode][fieldValue].ldhth.push(ldhth);
}
//
if (!currentLevelData[fieldValue]) {
currentLevelData[fieldValue] = { number: 0, ldhth: [] };
}
currentLevelData[fieldValue].number += number;
currentLevelData[fieldValue].ldhth.push(ldhth);
});
//
const formattedCurrentLevelData = Object.keys(currentLevelData).map((fieldValue) => ({
fieldValue,
number: currentLevelData[fieldValue].number,
ldhth: currentLevelData[fieldValue].ldhth.join(',')
}));
//
const formattedChildrenData = Object.keys(childrenData).map((childOrgCode) => ({
orgCode: childOrgCode,
data: Object.keys(childrenData[childOrgCode]).map((fieldValue) => ({
fieldValue,
number: childrenData[childOrgCode][fieldValue].number,
ldhth: childrenData[childOrgCode][fieldValue].ldhth.join(',')
}))
}));
console.log({
orgCode: selectOrgCode,
data: formattedCurrentLevelData,
children: formattedChildrenData
});
//
return {
orgCode: selectOrgCode,
data: formattedCurrentLevelData,
children: formattedChildrenData
};
} catch (error) {
console.log(error);
//TODO handle the exception
}
};
const transformToEChartsFormat = (data) => {
const result = {
xAxis: { data: [] },
legend: { data: [] },
series: []
};
// orgCodeseries
const seriesMap = {};
try {
data.forEach((item) => {
const orgCode = item.orgCode;
// orgCodeseries
if (!seriesMap[orgCode]) {
seriesMap[orgCode] = { name: orgCode, type: 'bar', data: [] };
result.xAxis.data.push(orgCode);
}
item.data.forEach((field) => {
const fieldValue = field.fieldValue;
// fieldValue
if (!result.legend.data.includes(fieldValue)) {
result.legend.data.push(fieldValue);
}
// seriesMapseriesfieldValue
seriesMap[orgCode].data[fieldValue] = seriesMap[orgCode].data[fieldValue] || 0;
// number
seriesMap[orgCode].data[fieldValue] += field.number;
});
});
// seriesMapresult.series
for (let orgCode in seriesMap) {
// seriesMapdata
seriesMap[orgCode].data = result.legend.data.map((value) => seriesMap[orgCode].data[value] || 0);
result.series.push(seriesMap[orgCode]);
}
} catch (error) {
//TODO handle the exception
}
const Option = {
title: {
text: '人员年龄分组统计',
padding: [0, 0, 0, 30]
},
toolbox: {
padding: [0, 30, 0, 0],
show: true,
feature: {
//
restore: {
show: true //
},
saveAsImage: {
show: true //
}
}
},
legend: {
data: result.legend,
itemGap: 5,
padding: [0, 15, 0, 15],
y: 'bottom',
itemHeight: 8, //
itemWidth: 8, //
type: 'scroll'
},
xAxis: {
type: 'category',
data: result.xAxis,
axisLabel: {
color: '#7F84B5',
fontWeight: 300,
interval: 0,
rotate: 0
},
padding: [0, 10, 0, 10],
axisTick: {
show: false //线
},
axisLine: {
show: false //线
}
},
yAxis: [
{
show: true,
boundaryGap: false, //线
type: 'value',
// name: 'Budget (million USD)',
// data: this.yList,
minInterval: 1,
axisLabel: {
interval: 0
},
splitLine: {
show: true,
lineStyle: {
//线
type: 'dashed'
}
},
axisTick: {
show: true //线
},
axisLine: {
show: false //线
}
}
],
series: result.series
};
return Option;
};
//
const countUniqueOrgCodes = (data) => {
// Set orgCode
const orgCodeSet = new Set();
//
for (let i = 0; i < data.length; i++) {
// orgCode Set
orgCodeSet.add(data[i].orgCode);
}
// Set orgCode
return orgCodeSet.size;
};
//
function getRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
//echartoption
const convertToEChartsOption = (data) => {
// orgCode fieldValue
const groupedData = {};
//
data.forEach((item) => {
const { orgCode, fieldValue, number } = item;
if (!groupedData[orgCode]) {
groupedData[orgCode] = {};
}
groupedData[orgCode][fieldValue] = number;
});
// orgCode
const orgCodes = Object.keys(groupedData);
console.log(orgCodes, groupedData);
let labels = [];
let datasets = [];
let xDatas = [];
// orgCode
if (orgCodes.length === 1) {
const singleOrgCode = orgCodes[0];
const singleOrgData = groupedData[singleOrgCode];
console.log('单个', singleOrgCode, singleOrgData);
labels = Object.keys(singleOrgData);
console.log('单个labels', labels);
xDatas = labels;
datasets = [
{
type: 'bar',
data: labels.map((label, index) => {
return {
value: singleOrgData[label],
itemStyle: {
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
}
};
})
}
];
console.log('单个的数据', xDatas, labels, datasets);
} else {
// orgCode
const allFieldValues = new Set();
orgCodes.forEach((orgCode) => {
const fieldValues = Object.keys(groupedData[orgCode]);
fieldValues.forEach((fieldValue) => allFieldValues.add(fieldValue));
});
const sortedFieldValues = Array.from(allFieldValues).sort();
console.log('多个数据', sortedFieldValues);
labels = sortedFieldValues;
xDatas = orgCodes;
datasets = orgCodes.map((orgCode) => {
const dataPoints = sortedFieldValues.map((fieldValue, index) => {
return {
value: groupedData[orgCode][fieldValue] || 0,
itemStyle: {
color: ['#5470C6', '#91CC75', '#FAC858', '#EE6666', '#73C0DE'][index]
}
};
});
return {
name: orgCode,
type: 'bar',
data: dataPoints
};
});
}
console.log(labels, orgCodes, datasets);
// ECharts option
const option = {
title: {
text: '人员年龄分组统计',
padding: [0, 0, 0, 30]
},
toolbox: {
padding: [0, 30, 0, 0],
show: true,
feature: {
//
restore: {
show: true //
},
saveAsImage: {
show: true //
}
}
},
legend: {
data: labels,
itemGap: 5,
padding: [0, 15, 0, 15],
y: 'bottom',
itemHeight: 8, //
itemWidth: 8, //
type: 'scroll'
},
xAxis: {
type: 'category',
data: xDatas,
axisLabel: {
color: '#7F84B5',
fontWeight: 300,
interval: 0,
rotate: 0
},
padding: [0, 10, 0, 10],
axisTick: {
show: false //线
},
axisLine: {
show: false //线
}
},
yAxis: [
{
show: true,
boundaryGap: false, //线
type: 'value',
// name: 'Budget (million USD)',
// data: this.yList,
minInterval: 1,
axisLabel: {
interval: 0
},
splitLine: {
show: true,
lineStyle: {
//线
type: 'dashed'
}
},
axisTick: {
show: true //线
},
axisLine: {
show: false //线
}
}
],
series: datasets
};
return option;
};
//
const fetchStatisticsData = async () => {
if (!selectedOrgCode.value || !selectedField.value) return;
try {
const res = await cxcRyDatAstatistics({
orgCode: selectedOrgCode.value,
field: selectedField.value
});
console.log(res);
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
console.log(orgCodeGroupData.value);
chartData.value = orgCodeGroupData.value.children;
// updateChart();
} catch (error) {
console.error('获取统计数据失败:', error);
}
};
// delimiter
const fetchPersonnelList = async (ldhthList) => {
try {
const res = await cxcRyDatAstatisticsDetails({
ldhth: ldhthList
});
console.log(res);
personnelList.value = res.data;
} catch (error) {
console.error('获取人员列表失败:', error);
}
};
//
const onOrgCodeChange = (e, data) => {
selectedOrgCode.value = e;
console.log(data.value.title);
selectedOrgCodeLabel.value = data.value.title;
fetchStatisticsData();
};
const onFieldChange = (e) => {
const index = e.detail.value;
selectedField.value = fieldList.value[index].value;
selectedFieldLabel.value = fieldList.value[index].label;
fetchStatisticsData();
};
const onChartClick = (e) => {
const { ldhth } = chartData.value;
if (ldhth && ldhth.length > 0) {
fetchPersonnelList(ldhth);
}
};
</script>
<style scoped>
.container {
margin: 20, 20, 20, 20rpx;
}
.input-group {
display: flex;
gap: 20rpx;
margin-bottom: 30rpx;
}
.input {
flex: 1;
border: 1rpx solid #ddd;
padding: 15rpx;
border-radius: 8rpx;
}
.query-btn {
background: #007aff;
color: white;
padding: 0 40rpx;
border-radius: 8rpx;
}
.stats-box {
display: flex;
justify-content: space-around;
margin: 30rpx 0;
padding: 20rpx;
background: #f8f8f8;
border-radius: 12rpx;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.label {
font-size: 24rpx;
color: #666;
}
.value {
font-size: 36rpx;
font-weight: bold;
color: #0000ff;
}
.chart-container {
height: 800rpx;
margin-top: 20rpx;
}
.titleStyle {
font-size: 12px;
color: #747474;
line-height: 30px;
height: 30px;
background: #f2f9fc;
text-align: center;
vertical-align: middle;
border-left: 1px solid #919191;
border-bottom: 1px solid #919191;
}
/* 内容样式 */
.dataStyle {
max-font-size: 14px;
/* 最大字体限制 */
min-font-size: 10px;
/* 最小字体限制 */
font-size: 12px;
color: #00007f;
line-height: 30px;
height: 30px;
font-weight: 500;
text-align: center;
vertical-align: middle;
border-bottom: 1px solid #919191;
border-left: 1px solid #919191;
text-overflow: ellipsis;
}
</style>

View File

@ -2,19 +2,17 @@
<view>
<view class="container" id="top1">
<uni-row style="margin-bottom: 10rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24"><uni-title :title="'所选单位ID'" align="left" type="h4"></uni-title></uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<uni-col :span="5"><uni-title :title="'选择单位'" align="left" type="h4"></uni-title></uni-col>
<uni-col :span="19">
<trq-depart-select v-model="selectedOrgCode" returnCodeOrID="orgCode" @change="onOrgCodeChange"></trq-depart-select>
</uni-col>
</uni-row>
<uni-row style="margin-bottom: 20rpx; margin-left: 30rpx; margin-right: 30rpx">
<uni-col :span="24">
<picker mode="selector" :range="fieldList" range-key="label" @change="onFieldChange">
<view class="picker">选择字段: {{ selectedFieldLabel }}</view>
</picker>
<uni-col :span="5"><uni-title :title="'选择字段'" align="left" type="h4"></uni-title></uni-col>
<uni-col :span="19">
<uni-data-select v-model="selectedField" :localdata="fieldList" @change="onFieldChange"></uni-data-select>
</uni-col>
</uni-row>
</view>
@ -87,15 +85,15 @@ const bottomHeight = ref(0);
const chart = ref(null);
const fieldList = ref([
{
label: '性别',
text: '性别',
value: 'xb'
},
{
label: '年龄',
text: '年龄',
value: 'nl'
},
{
label: '学历',
text: '学历',
value: 'rylb1'
}
]); //
@ -103,10 +101,10 @@ const selectedOrgCode = ref(''); // 当前选择的单位 orgCode
const selectedOrgCodeLabel = ref('请选择单位'); //
const selectedField = ref(''); //
const selectedFieldLabel = ref('请选择字段'); //
const orgCodeGroupData = ref([]); //orgcode
const orgCodeGroupData = ref([]); //orgcode
const chartData = ref({}); //
const personnelList = ref([]); // initChart
const fieldValues = ref([]);
const chartOption = ref({});
function detail(record) {
@ -153,91 +151,209 @@ const initChart = () => {
};
//
const updateChart = () => {
const updateChart = (tempchartData) => {
//
setTimeout(async () => {
if (!chart.value) return;
const myChart = await chart.value.init(echarts);
chartOption.value = transformDataForEcharts(chartData.value, selectedOrgCode.value);
console.log(tempchartData);
let temp = JSON.parse(JSON.stringify(tempchartData[0].children));
let xData = [];
let seriesData = [];
console.log(1, temp);
// transformDataForEcharts
temp.forEach((item) => {
xData.push(item.name);
});
for (let i = 0; i < fieldValues.value.length; i++) {
let tempData = [];
temp.forEach((item) => {
if (item.data[i]) {
tempData.push(item.data[i]);
} else {
tempData.push(0);
}
});
seriesData.push({ name: fieldValues.value[i], type: 'bar', data: tempData });
}
console.log(xData, seriesData, fieldValues.value);
myChart.setOption({
xAxis: {
type: 'category',
data: chartOption.value.categories.map((code) => `${code}${chartOption.value.children ? ' ▶' : ''}`)
data: xData
},
yAxis: { type: 'value' },
series: chartOption.value.series,
series: seriesData,
tooltip: { trigger: 'axis' },
legend: { data: chartOption.value.series.map((s) => s.name) }
legend: { data: fieldValues.value }
});
//
myChart.on('click', (params) => {
const clickedCode = params.name.split(' ')[0];
const nextData = transformDataForEcharts(originalData, clickedCode);
if (nextData.categories.length > 0) {
historyStack.push(currentLevel);
currentLevel = clickedCode;
renderChart(nextData);
} else if (nextData.children) {
historyStack.push(currentLevel);
currentLevel = clickedCode;
chartData = transformDataForEcharts(originalData, currentLevel);
renderChart(chartData);
} else {
console.log('已是最末级节点');
}
// console.log(params.name, params.seriesIndex, params.dataIndex);
console.log(orgCodeGroupData.value);
let updateData = findNodeByOrgCode(orgCodeGroupData.value, params.name);
console.log(updateData);
// updateChart(updateData);
});
}, 300);
};
//
/**
* 从树状数据中根据 orgCode 获取节点及其子节点数据
* @param {Array} treeData 树状数据
* @param {string} targetOrgCode 目标 orgCode
* @returns {Object|null} 匹配的节点及其子节点数据未找到返回 null
*/
function findNodeByOrgCode(treeData, targetOrgCode) {
// console.log(treeData, targetOrgCode);
for (const node of treeData) {
//
if (node.name === targetOrgCode) {
return node;
}
//
if (node.children && node.children.length > 0) {
const found = findNodeByOrgCode(node.children, targetOrgCode);
if (found) return found;
}
}
return null;
}
//fieldValue
function collectUniqueKeyValues(tree, key) {
const uniqueValues = new Set(); // 使Set
function traverse(node) {
if (node[key] !== undefined) {
uniqueValues.add(node[key]);
}
if (node.children && Array.isArray(node.children)) {
node.children.forEach((child) => traverse(child));
}
}
tree.forEach((node) => traverse(node)); // tree
return Array.from(uniqueValues); // Set
}
//
// const result = findNodeByOrgCode(echartData, "A01A01A01A01");
// console.log(result);
/**
* 转换数据为支持钻取的ECharts格式
* @param {Array} data 原始数据
* @param {string} currentOrgCode 当前组织编码
* @returns {Object} 包含当前层级数据和子节点信息的对象
* @param {string} selectOrgCode 当前选择的组织编码
* @returns {Object} 包含当前层级数据和子节点信息的对象 符合echart的格式
*/
function transformDataForEcharts(data, currentOrgCode = '') {
// +3
const currentLevel = currentOrgCode.length;
const nextLevel = currentLevel + 3;
console.log(currentLevel, nextLevel, currentOrgCode, data);
//
const currentLevelData = data.filter((item) => item.orgCode.length === currentLevel && (currentLevel === 0 || item.orgCode === currentOrgCode));
console.log(1);
console.log(currentLevelData);
//
const children = data
.filter(
(item) => item.orgCode.startsWith(currentOrgCode) && item.orgCode.length === nextLevel && (currentLevel === 0 || item.orgCode.slice(0, currentLevel) === currentOrgCode)
)
.map((item) => ({
orgCode: item.orgCode,
hasChildren: data.some((d) => d.orgCode.startsWith(item.orgCode) && d.orgCode.length === nextLevel + 3)
}));
console.log(2, children);
// fieldValue
const fieldGroups = currentLevelData.reduce((acc, curr) => {
const key = curr.fieldValue;
if (!acc[key]) {
acc[key] = {
name: key,
data: []
};
//-----------------------------------------------------------------------------------------
function transformData(selectOrgCode, data) {
const nodes = new Map();
//fieldValue data[] fieldValue
fieldValues.value = collectUniqueKeyValues(data, 'fieldValue');
// orgCode
function getHierarchy(orgCode) {
const hierarchy = [];
for (let i = selectOrgCode.length; i <= orgCode.length; i += 3) {
hierarchy.push(orgCode.substring(0, i));
}
acc[key].data.push(curr.number);
return acc;
}, {});
// console.log('hierarchy', hierarchy);
return hierarchy;
}
// orgCode
function getParentCode(code) {
if (code.length <= 3) return null;
return code.substring(0, code.length - 3);
}
// series
let tempArrayValue = new Array(fieldValues.value.length).fill(0);
//
data.forEach((entry) => {
const hierarchy = getHierarchy(entry.orgCode);
hierarchy.forEach((code) => {
if (!nodes.has(code)) {
nodes.set(code, {
orgCode: code,
type: 'bar',
data: JSON.parse(JSON.stringify(tempArrayValue)), // data[0, 0]
children: []
});
}
});
// console.log('fieldValues', fieldValues.value, fieldValues.value.length, hierarchy);
// data
const node = nodes.get(entry.orgCode);
const fieldValue = parseInt(entry.fieldValue, 10);
for (let i = 0; i < fieldValues.value.length; i++) {
if (fieldValue === parseInt(fieldValues.value[i], 10)) {
// console.log(555, i, fieldValue, fieldValues.value[i], entry.number);
node.data[i] += entry.number;
}
}
// console.log(11, node);
//
for (let i = 0; i < hierarchy.length - 1; i++) {
const parentCode = hierarchy[i];
const childCode = hierarchy[i + 1];
const parentNode = nodes.get(parentCode);
const childNode = nodes.get(childCode);
if (!parentNode.children.some((c) => c.orgCode === childCode)) {
parentNode.children.push(childNode);
}
}
});
// data
function computeData(node) {
if (node.children.length === 0) return;
node.data = JSON.parse(JSON.stringify(tempArrayValue));
node.children.forEach((child) => {
computeData(child);
for (let i = 0; i < fieldValues.value.length; i++) {
// console.log(666, i, node.data[i], child.data[i]);
node.data[i] += child.data[i];
}
});
}
//
const rootNodes = [];
nodes.forEach((node, code) => {
const parentCode = getParentCode(code);
// console.log(parentCode);
if (!parentCode || !nodes.has(parentCode)) {
rootNodes.push(node);
}
});
// data
rootNodes.forEach((root) => computeData(root));
// console.log('rootNodes', rootNodes);
//
function formatTree(node) {
return {
categories: currentLevelData.map((d) => d.orgCode),
series: Object.values(fieldGroups),
children: children.length > 0 ? children : null
name: node.orgCode,
type: 'bar',
data: node.data,
children: node.children.map((child) => formatTree(child))
};
}
// 使
// let currentLevel = 'A01A01'; //
// let chartData = transformDataForEcharts(originalData, currentLevel);
return rootNodes.map((root) => formatTree(root));
}
//-----------------------------------------------------------------------------------------
// orgCode children deepseek
@ -253,12 +369,14 @@ const groupByOrgCode = (orgCode, data) => {
// fieldValue
const groupedByFieldValue = {};
filteredData.forEach((item) => {
// console.log(item.orgCode, 11, groupedByFieldValue[item.fieldValue]);
if (!groupedByFieldValue[item.fieldValue]) {
groupedByFieldValue[item.fieldValue] = {
number: 0,
ldhth: []
};
}
// console.log(item.orgCode, 22, groupedByFieldValue[item.fieldValue]);
groupedByFieldValue[item.fieldValue].number += item.number;
groupedByFieldValue[item.fieldValue].ldhth.push(...item.ldhth.split(','));
});
@ -274,6 +392,8 @@ const groupByOrgCode = (orgCode, data) => {
children: []
};
console.log('本级', result);
// orgCode
const nextLevelOrgCodes = new Set();
filteredData.forEach((item) => {
@ -291,11 +411,10 @@ const groupByOrgCode = (orgCode, data) => {
}
});
console.log('全部', result);
return result;
};
//-----------------------------------------------------------------------------------------
// then
const fetchStatisticsData = async () => {
if (!selectedOrgCode.value || !selectedField.value) return;
@ -306,9 +425,9 @@ const fetchStatisticsData = async () => {
});
// console.log(res); //deepseek
orgCodeGroupData.value = groupByOrgCode(selectedOrgCode.value, res);
console.log(orgCodeGroupData.value);
chartData.value = orgCodeGroupData.value.children;
updateChart();
chartData.value = transformData(selectedOrgCode.value, res);
// console.log(chartData.value);
updateChart(chartData.value);
} catch (error) {
console.error('获取统计数据失败:', error);
}
@ -336,10 +455,21 @@ const onOrgCodeChange = (e, data) => {
};
const onFieldChange = (e) => {
const index = e.detail.value;
selectedField.value = fieldList.value[index].value;
selectedFieldLabel.value = fieldList.value[index].label;
console.log(e);
try {
selectedField.value = e;
for (var index = 0; index < fieldList.length; index++) {
var element = array[index];
if (element.value === e) {
selectedFieldLabel.value = element.text;
}
}
console.log(selectedFieldLabel);
fetchStatisticsData();
} catch (error) {
//TODO handle the exception
console.log(error);
}
};
const onChartClick = (e) => {
@ -349,90 +479,154 @@ const onChartClick = (e) => {
}
};
</script>
<style scoped>
/* 颜色变量 */
:root {
--primary-blue: #409eff;
--deep-blue: #2c7be5;
--light-blue: #ecf5ff;
--gradient-start: #6b8cff;
--gradient-end: #4364f7;
--hover-blue: #66b1ff;
}
/* 全局容器 */
.container {
margin: 20, 20, 20, 20rpx;
}
.input-group {
display: flex;
gap: 20rpx;
margin-bottom: 30rpx;
}
.input {
flex: 1;
border: 1rpx solid #ddd;
padding: 15rpx;
border-radius: 8rpx;
}
.query-btn {
background: #007aff;
color: white;
padding: 0 40rpx;
border-radius: 8rpx;
}
.stats-box {
display: flex;
justify-content: space-around;
margin: 30rpx 0;
padding: 20rpx;
background: #f8f8f8;
border-radius: 12rpx;
}
.stat-item {
display: flex;
flex-direction: column;
align-items: center;
}
.label {
font-size: 24rpx;
color: #666;
}
.value {
font-size: 36rpx;
font-weight: bold;
color: #0000ff;
margin: 10rpx 10rpx;
padding: 10rpx;
background: linear-gradient(145deg, #f5f9ff, var(--light-blue));
border-radius: 24rpx;
box-shadow: 0 8rpx 24rpx rgba(64, 158, 255, 0.15);
border: 2rpx solid rgba(64, 158, 255, 0.1);
}
/* 图表容器 */
.chart-container {
height: 800rpx;
margin-top: 20rpx;
height: 50vh;
margin: 20rpx 0;
border-radius: 24rpx;
overflow: hidden;
background: #ffffff;
box-shadow: 0 8rpx 32rpx rgba(64, 158, 255, 0.12);
border: 2rpx solid rgba(64, 158, 255, 0.08);
}
/* 表格标题行 */
.titleStyle {
font-size: 28rpx;
font-weight: 600;
color: #ffffff;
background: linear-gradient(135deg, var(--gradient-start), var(--gradient-end));
padding: 28rpx 0;
border-radius: 16rpx 16rpx 0 0;
box-shadow: 0 4rpx 12rpx rgba(67, 100, 247, 0.2);
letter-spacing: 1rpx;
}
/* 数据行 */
.dataStyle {
font-size: 28rpx;
color: #3a466b;
padding: 32rpx 0;
background: #ffffff;
border-bottom: 2rpx solid #f0f6ff;
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.dataStyle:hover {
background: #f8fbff;
transform: translateY(-2rpx);
}
/* 操作按钮 */
button[type='primary'] {
background: linear-gradient(135deg, var(--primary-blue), var(--deep-blue));
border: none;
border-radius: 12rpx;
padding: 12rpx 32rpx;
font-size: 26rpx;
box-shadow: 0 6rpx 16rpx rgba(64, 158, 255, 0.3);
transition: all 0.25s ease;
}
button[type='primary']:active {
transform: scale(0.96);
box-shadow: 0 4rpx 8rpx rgba(64, 158, 255, 0.3);
background: linear-gradient(135deg, var(--deep-blue), var(--primary-blue));
}
/* 滚动区域 */
scroll-view {
background: #ffffff;
border-radius: 0 0 16rpx 16rpx;
box-shadow: 0 8rpx 24rpx rgba(0, 35, 111, 0.08);
}
/* 输入框聚焦效果 */
.trq-depart-select:focus-within {
box-shadow: 0 0 0 4rpx rgba(64, 158, 255, 0.2);
border-color: var(--primary-blue);
}
/* 加载动画优化 */
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20rpx);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.container > * {
animation: fadeIn 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}
/* 自定义滚动条美化 */
::-webkit-scrollbar {
width: 8rpx;
background: rgba(64, 158, 255, 0.05);
}
::-webkit-scrollbar-thumb {
background: linear-gradient(45deg, var(--primary-blue), var(--deep-blue));
border-radius: 12rpx;
border: 2rpx solid white;
}
/* 筛选行间距优化 */
.filter-row {
margin: 30rpx 0;
padding: 20rpx 0;
border-radius: 16rpx;
}
/* 响应式调整优化 */
@media (max-width: 768px) {
.chart-container {
height: 55vh;
border-radius: 20rpx;
}
.titleStyle {
font-size: 12px;
color: #747474;
line-height: 30px;
height: 30px;
background: #f2f9fc;
text-align: center;
vertical-align: middle;
border-left: 1px solid #919191;
border-bottom: 1px solid #919191;
font-size: 26rpx;
padding: 24rpx 0;
}
/* 内容样式 */
.dataStyle {
max-font-size: 14px;
/* 最大字体限制 */
min-font-size: 10px;
/* 最小字体限制 */
font-size: 12px;
color: #00007f;
line-height: 30px;
height: 30px;
font-weight: 500;
text-align: center;
vertical-align: middle;
border-bottom: 1px solid #919191;
border-left: 1px solid #919191;
text-overflow: ellipsis;
button[type='primary'] {
padding: 10rpx 24rpx;
font-size: 24rpx;
}
}
/* 数据行高亮效果 */
.data-row:nth-child(even) {
background: rgba(236, 245, 255, 0.3);
}
.data-row:hover {
box-shadow: 0 4rpx 12rpx rgba(64, 158, 255, 0.1);
}
</style>