wujingjing
2025-02-27 45833cf0bcafc65a9a9c755b4efc43bd5d98941a
src/components/chat/chatComponents/summaryCom/components/recordSetTable/RecordSetTable.vue
@@ -5,7 +5,7 @@
         <template v-if="visibleParams && visibleParams.length > 0 && showFilter">
            <component
               class="flex-0 m-2 first-of-type:ml-0"
               :class="{ invisible: showMode2 === DisplayModeType2.Map}"
               :class="{ hidden: isMap && showMode2 === DisplayModeType2.Map }"
               v-model="visibleParams[index].value"
               v-for="(item, index) in visibleParams as any"
               :key="item.id"
@@ -18,6 +18,8 @@
            ></component>
         </template>
         <el-button v-if="showMode2 === DisplayModeType2.List || showMode === DisplayModeType.List" class="ml-auto"  @click="exportExcel">导出Excel</el-button>
         <DisplayMode
            v-if="isTotalTable"
            class="ml-auto"
@@ -26,6 +28,8 @@
            :modeTypeMap="displayModeTypeMap"
            @change="displayModeChange"
         />
         <div class="ml-auto space-x-2 flex-items-center" v-if="isMap || !isTotalTable">
            <ColFilter
               v-if="(!isMap && !isTotalTable) || (isMap && showMode2 === DisplayModeType2.List && !isTotalTable)"
@@ -61,8 +65,8 @@
               class="w-full h-full"
               highlightCurrentRow
               :rowClassName="tableRowClassName"
               cellClassName="text-sm"
               headerCellClassName="text-sm"
               cellClassName=""
               headerCellClassName=""
            >
               <DefineColumns v-slot="{ cols }">
                  <template v-for="item in colList" :key="item.prop">
@@ -116,21 +120,14 @@
      </div>
      <div class="flex-auto" v-if="isMap && showMode2 === DisplayModeType2.Map">
         <MapView :data="data" @equipClick="showCurve" @closeInfoWindow="closeInfoWindow"/>
         <MapView :data="data" @equipClick="showCurve" @closeInfoWindow="closeInfoWindow" />
      </div>
      <div class="flex-auto" v-resize="debounceResizeChart" v-show="showMode === DisplayModeType.Chart">
         <div ref="chartRef" style="height: 25rem"></div>
      </div>
      <div class="mt-5 relative"  v-if="chartDlgIsShow&& metricsList.length>0">
         <span class="absolute right-[10px] top-[5px]  ywifont ywicon-guanbi text-[#528abe] font-bold cursor-pointer" style="z-index: 2;" @click="closeChartDlg"></span>
         <el-tabs  v-model="activeTab" type="border-card" >
         <el-tab-pane lazy v-for="(item, index) in metricsList" :key="`${chartDlgKey}_${index}`" :label="item.title" :name="index"
            ><RecordSetDialog :modelValue="true" :isDialog="false" height="20rem" :metrics="item"
         /></el-tab-pane>
      </el-tabs>
      </div>
      <EquipCurve v-model:isShow="chartDlgIsShow" class="mt-5" :data="equipCurveMapRow" :quotaChartCol="data?.quota_chart?.col" />
      <InfoDetail class="text-base" v-model="infoDetailIsShow" :item="detailMapRow" :colList="colList" />
   </div>
@@ -141,6 +138,7 @@
import * as echarts from 'echarts';
import type { TableInstance } from 'element-plus';
import { chunk, sortBy } from 'lodash-es';
import EquipCurve from './components/EquipCurve.vue';
import type { CSSProperties } from 'vue';
import { computed, nextTick, onMounted, reactive, ref, shallowRef, watchEffect, type PropType } from 'vue';
import { PATH_ICON } from '../../../common';
@@ -153,11 +151,11 @@
import MapView from './map/Map.vue';
import { curveQuery } from '/@/api/ai/chat';
import ColFilter from '/@/components/table/colFilter/ColFilter.vue';
import { TableCol } from '/@/components/table/colFilter/types';
import type { TableCol } from '/@/components/table/colFilter/types';
import { axisLabelFormatter } from '/@/utils/chart';
import { LocalPlus } from '/@/utils/storage';
import { debounce, getTextWidth, toPercent } from '/@/utils/util';
import RecordSetDialog from '../recordSet/RecordSetDialog.vue';
import { debounce, downloadExcel, getTextWidth, toPercent } from '/@/utils/util';
import { isSharePage } from '/@/stores/chatRoom';
const props = defineProps({
   data: {
@@ -181,6 +179,13 @@
      type: Boolean,
      default: false,
   },
   reportIndex: {
      type: Number,
      default: 0,
   },
   historyId: {
      type: String,
   },
});
const [DefineColumns, ReuseColumns] = createReusableTemplate<{
@@ -200,10 +205,13 @@
const isTotalTable = computed(() => checkIsTotalTable(props.data));
const checkHasAddRateCol = (current) => {
   return current.find((item) => item.title === '比例' && item.type === 'text');
};
const getTableCols = (propsData) => {
   const current = propsData?.cols ?? [];
   if (checkIsTotalTable(propsData)) {
   if (checkIsTotalTable(propsData) && !checkHasAddRateCol(current)) {
      current.push({
         title: '比例',
         type: 'text',
@@ -224,7 +232,8 @@
const getTableValues = (propsData) => {
   const agg_count_col = propsData?.agg_count_col;
   const current = (propsData?.values ?? []) as Array<any[]>;
   if (checkIsTotalTable(propsData)) {
   if (checkIsTotalTable(propsData)&& !current.find(item=>item[0]==='合计') ) {
      const last = current[current.length - 1];
      const lastItemIndex = last?.length > 0 ? last.length - 1 : 0;
      valueColIndex = agg_count_col ?? lastItemIndex;
@@ -351,7 +360,7 @@
};
const getItemMap = (arr: any[], defaultProps = 'ID', isMultiple = false) => {
   if (!arr || arr.length === 0) return {};
   const result = arr.reduce((acc, curr) => {
      if (isMultiple) {
         if (!acc.get(curr[defaultProps])) {
@@ -404,8 +413,6 @@
   return result;
};
/**
 * 计算每一列的宽度
 * 1)总宽小于容器宽:直接按比例分
@@ -413,7 +420,7 @@
 * 3)计算完的宽度放在 colList.value 的 width 属性上
 * @param width
 */
const calcColWidth = (width) => {
   // 返回所有标题字符串
   const maxStrList = tableCols.value.map((item, index) => {
@@ -539,7 +546,7 @@
      borderColor: BORDER_COLOR,
      borderWidth: `${THICK_BORDER_WIDTH}px`,
      color: '#7331a5',
      fontSize: '0.875rem',
      // fontSize: '0.875rem',
      ...extraStyle,
   };
};
@@ -558,7 +565,7 @@
      borderWidth: `${THICK_BORDER_WIDTH}px`,
      backgroundColor: COL_HEADER_CELL_BG_COLOR,
      fontWeight: 700,
      fontSize: '0.875rem',
      // fontSize: '0.875rem',
      color: '#000',
      ...extraStyle,
   };
@@ -689,7 +696,7 @@
const queryLoading = ref(false);
let orderDimName = '';
const queryUpdate = async (val?: any, item?: any) => {
   const historyId = (props as any).originData.historyId;
   const historyId = props.historyId;
   let res = null;
   if (item) {
@@ -712,6 +719,7 @@
         agent_key: props.data.agent_key,
         filter_json: JSON.stringify(filterList),
         order_dim_name: orderDimName,
         result_group_index: props.reportIndex,
      };
      res = await curveQuery(params);
      queryLoading.value = true;
@@ -1153,33 +1161,20 @@
};
const chartDlgIsShow = ref(false);
const chartDlgKey= ref('');
const activeTab = ref(0);
const metricsList = ref([]);
const resetTab = () => {
   activeTab.value = 0;
};
const equipCurveMapRow = ref(null);
const showCurve = (row) => {
   resetTab();
   if (isSharePage.value) return;
   if (!row) return;
   equipCurveMapRow.value = row;
   chartDlgIsShow.value = true;
   const quotaChartCol = props.data?.quota_chart?.col;
   if (!quotaChartCol) {
      chartDlgKey.value = '';
      metricsList.value = [];
   } else {
      const str = row[quotaChartCol] ?? '[]'
      chartDlgKey.value = str;
      metricsList.value = JSON.parse(str);
   }
};
const closeInfoWindow  =()=>{
const closeInfoWindow = () => {
   closeChartDlg();
}
const closeChartDlg = () =>{
};
const closeChartDlg = () => {
   chartDlgIsShow.value = false;
}
   equipCurveMapRow.value = null;
};
const tableRowClick = (row) => {
   if (isMap.value) {
@@ -1195,6 +1190,24 @@
   showInfoDetail(row);
};
const exportExcel = () => {
   const data = tableValues.value;
   console.log("🚀 ~ data:", data)
   const keyLabelMap = new Map(colList.value.map((item) => [item.prop, item.label]));
   console.log("🚀 ~ keyLabelMap:", keyLabelMap)
   const excelData = data.map((item) => {
      const excelItem = {};
      item.forEach((item, index) => {
         const label  = keyLabelMap.get(index+'');
         if(!label) return;
         excelItem[label] = item;
      });
      return excelItem;
   });
   console.log("🚀 ~ excelData:", excelData)
   downloadExcel(excelData, props.data.title);
};
defineExpose({
   updateAll,
@@ -1202,6 +1215,4 @@
   updateIndexSummary,
});
</script>
<style scoped lang="scss">
</style>
<style scoped lang="scss"></style>