diff --git a/core/core-frontend/src/custom-component/de-tree/Component.vue b/core/core-frontend/src/custom-component/de-tree/Component.vue index da4869c..69915c2 100644 --- a/core/core-frontend/src/custom-component/de-tree/Component.vue +++ b/core/core-frontend/src/custom-component/de-tree/Component.vue @@ -1,14 +1,13 @@ @@ -92,552 +91,105 @@ default: 'common' } }) -// const { -// element, -// isEdit, -// showPosition, -// canvasStyleData, -// canvasViewInfo, -// dvInfo, -// scale, -// searchCount -// } = toRefs(props) -// const defaultProps = { -// children: 'children', -// label: 'label', -// } -// const data = [ -// { -// label: 'Level one 1', -// children: [ -// { -// label: 'Level two 1-1', -// children: [ -// { -// label: 'Level three 1-1-1', -// }, -// ], -// }, -// ], -// }, -// { -// label: 'Level one 2', -// children: [ -// { -// label: 'Level two 2-1', -// children: [ -// { -// label: 'Level three 2-1-1', -// }, -// ], -// }, -// { -// label: 'Level two 2-2', -// children: [ -// { -// label: 'Level three 2-2-1', -// }, -// ], -// }, -// ], -// }, -// { -// label: 'Level one 3', -// children: [ -// { -// label: 'Level two 3-1', -// children: [ -// { -// label: 'Level three 3-1-1', -// }, -// ], -// }, -// { -// label: 'Level two 3-2', -// children: [ -// { -// label: 'Level three 3-2-1', -// }, -// ], -// }, -// ], -// }, -// ] - -// const titleBackgroundActiveSvgInner = computed(() => { -// return element.value.titleBackground.active.innerImage.replace('board/', '').replace('.svg', '') -// }) - -// const titleBackgroundInActiveSvgInner = computed(() => { -// return element.value.titleBackground.inActive.innerImage.replace('board/', '').replace('.svg', '') -// }) - -// const svgInnerInActiveEnable = itemName => { -// const { backgroundImageEnable, backgroundType, innerImage } = -// element.value.titleBackground.inActive -// return ( -// editableTabsValue.value !== itemName && -// !element.value.titleBackground.multiply && -// element.value.titleBackground?.enable && -// backgroundImageEnable && -// backgroundType === 'innerImage' && -// typeof innerImage === 'string' -// ) -// } - -// const svgInnerActiveEnable = itemName => { -// const { backgroundImageEnable, backgroundType, innerImage } = element.value.titleBackground.active -// return ( -// (editableTabsValue.value === itemName || element.value.titleBackground.multiply) && -// element.value.titleBackground?.enable && -// backgroundImageEnable && -// backgroundType === 'innerImage' && -// typeof innerImage === 'string' -// ) -// } - -// // tooltips 轮播会影响tab 展示 -// const viewToolTipsChange = () => { -// element.value.propValue?.forEach(tabItem => { -// const tMethod = -// editableTabsValue.value === tabItem.name -// ? ChartCarouselTooltip.resume -// : ChartCarouselTooltip.paused -// tabItem.componentData?.forEach(componentItem => { -// tMethod(componentItem.id) -// if (componentItem.component === 'Group') -// componentItem.propValue.forEach(groupItem => { -// tMethod(groupItem.id) -// }) -// }) -// }) -// } - -// const handleMouseEnter = () => { -// state.hoverFlag = true -// } - -// const handleMouseLeave = () => { -// state.hoverFlag = false -// } -// const state = reactive({ -// activeTabName: '', -// curItem: {}, -// textarea: '', -// dialogVisible: false, -// tabShow: true, -// hoverFlag: false -// }) -// const tabsAreaScroll = ref(false) -// const editableTabsValue = ref(null) - -// // 无边框 -// const noBorderColor = ref('none') -// let currentInstance - -// const showTabTitleFlag = computed(() => { -// debugger -// if (element.value && element.value.style && element.value.style?.showTabTitle === false) { -// return false -// } else { -// return element.value.style?.showTabTitle -// } -// }) - -// const isEditMode = computed(() => editMode.value === 'edit' && isEdit.value && !mobileInPc.value) -// const curThemes = isDashboard() ? 'light' : 'dark' -// const calcTabLength = () => { -// setTimeout(() => { -// if (element.value.propValue.length > 1) { -// const containerDom = document.getElementById( -// 'tab-' + element.value.propValue[element.value.propValue.length - 1].name -// ) -// tabsAreaScroll.value = -// containerDom.parentNode.clientWidth > tabComponentRef.value.clientWidth - 100 -// } else { -// tabsAreaScroll.value = false -// } -// }) -// } - -// const beforeHandleCommand = (item, param) => { -// return { -// command: item, -// param: param -// } -// } -// const curPreviewGap = computed(() => -// dvInfo.value.type === 'dashboard' && canvasStyleData.value['dashboard'].gap === 'yes' -// ? canvasStyleData.value['dashboard'].gapSize -// : 0 -// ) - -// function sureCurTitle() { -// state.curItem.title = state.textarea -// state.dialogVisible = false -// snapshotStore.recordSnapshotCache('sureCurTitle') -// } - -// function addTab() { -// const newName = guid() -// const newTab = { -// name: newName, -// title: t('visualization.new_tab'), -// componentData: [], -// closable: true -// } -// element.value.propValue.push(newTab) -// editableTabsValue.value = newTab.name -// snapshotStore.recordSnapshotCache('addTab') -// } - -// function deleteCur(param) { -// state.curItem = param -// let len = element.value.propValue.length -// while (len--) { -// if (element.value.propValue[len].name === param.name) { -// element.value.propValue.splice(len, 1) -// const activeIndex = -// (len - 1 + element.value.propValue.length) % element.value.propValue.length -// editableTabsValue.value = element.value.propValue[activeIndex].name -// state.tabShow = false -// nextTick(() => { -// state.tabShow = true -// }) -// } -// } -// } -// function copyCur(param) { -// addTab() -// const newTabItem = element.value.propValue[element.value.propValue.length - 1] -// const idMap = {} -// const newCanvasId = element.value.id + '--' + newTabItem.name -// newTabItem.componentData = deepCopyTabItemHelper(newCanvasId, param.componentData, idMap) -// dvMainStore.updateCopyCanvasView(idMap) -// } - -// function editCurTitle(param) { -// state.activeTabName = param.name -// state.curItem = param -// state.textarea = param.title -// state.dialogVisible = true -// } - -// function handleCommand(command) { -// switch (command.command) { -// case 'editTitle': -// editCurTitle(command.param) -// break -// case 'deleteCur': -// deleteCur(command.param) -// snapshotStore.recordSnapshotCache('deleteCur') -// break -// case 'copyCur': -// copyCur(command.param) -// snapshotStore.recordSnapshotCache('copyCur') -// break -// } -// } - -// const reloadLinkage = () => { -// // 刷新联动信息 -// if (dvInfo.value.id) { -// const resourceTable = ['canvas', 'canvasDataV', 'edit'].includes(showPosition.value) -// ? 'snapshot' -// : 'core' -// getPanelAllLinkageInfo(dvInfo.value.id, resourceTable).then(rsp => { -// dvMainStore.setNowPanelTrackInfo(rsp.data) -// }) -// } -// } - -// const componentMoveIn = component => { -// element.value.propValue.forEach((tabItem, index) => { -// if (editableTabsValue.value === tabItem.name) { -// //获取主画布当前组件的index -// if (isDashboard()) { -// eventBus.emit('removeMatrixItemById-canvas-main', component.id) -// dvMainStore.setCurComponent({ component: null, index: null }) -// component.canvasId = element.value.id + '--' + tabItem.name -// const refInstance = currentInstance.refs['tabCanvas_' + index][0] -// if (refInstance) { -// const matrixBase = refInstance.getBaseMatrixSize() //矩阵基础大小 -// canvasChangeAdaptor(component, matrixBase) -// component.x = 1 -// component.y = 200 -// component.style.left = 0 -// component.style.top = 0 -// tabItem.componentData.push(component) -// refInstance.addItemBox(component) //在适当的时候初始化布局组件 -// nextTick(() => { -// refInstance.canvasInitImmediately() -// }) -// } -// } else { -// const curIndex = findComponentIndexById(component.id) -// // 从主画布删除 -// dvMainStore.deleteComponent(curIndex) -// dvMainStore.setCurComponent({ component: null, index: null }) -// component.canvasId = element.value.id + '--' + tabItem.name -// dataVTabComponentAdd(component, element.value) -// tabItem.componentData.push(component) -// } -// } -// }) - -// reloadLinkage() -// } - -// const componentMoveOut = component => { -// if (isDashboard()) { -// canvasChangeAdaptor(component, bashMatrixInfo.value, true) -// } -// // 从Tab画布中移除 -// eventBus.emit('removeMatrixItemById-' + component.canvasId, component.id) -// dvMainStore.setCurComponent({ component: null, index: null }) -// // 主画布中添加 -// if (isDashboard()) { -// eventBus.emit('moveOutFromTab-canvas-main', component) -// } else { -// addToMain(component) -// } -// reloadLinkage() -// } - -// const addToMain = component => { -// const { left, top } = element.value.style -// component.style.left = component.style.left + left -// component.style.top = component.style.top + top -// component.canvasId = 'canvas-main' -// dvMainStore.addComponent({ -// component, -// index: undefined, -// isFromGroup: true -// }) -// } - -// const moveActive = computed(() => { -// return tabMoveInActiveId.value && tabMoveInActiveId.value === element.value.id -// }) - -// const headClass = computed(() => { -// if (tabsAreaScroll.value) { -// return 'tab-head-left' -// } else { -// return 'tab-head-' + element.value.style.headHorizontalPosition -// } -// }) - -// const backgroundStyle = backgroundParams => { -// if (backgroundParams) { -// const { -// backdropFilterEnable, -// backdropFilter, -// backgroundColorSelect, -// backgroundColor, -// backgroundImageEnable, -// backgroundType, -// outerImage, -// innerPadding, -// borderRadius -// } = backgroundParams -// let style = { -// padding: innerPadding * scale.value + 'px', -// borderRadius: borderRadius + 'px' -// } -// let colorRGBA = '' -// if (backgroundColorSelect && backgroundColor) { -// colorRGBA = backgroundColor -// } -// if (backgroundImageEnable) { -// if (backgroundType === 'outerImage' && typeof outerImage === 'string') { -// style['background'] = `url(${imgUrlTrans(outerImage)}) no-repeat ${colorRGBA}` -// } else { -// style['background-color'] = colorRGBA -// } -// } else { -// style['background-color'] = colorRGBA -// } -// if (backdropFilterEnable) { -// style['backdrop-filter'] = 'blur(' + backdropFilter + 'px)' -// } -// return style -// } -// return {} -// } - -// const titleStyle = itemName => { -// let style = {} -// if (editableTabsValue.value === itemName) { -// style = { -// textDecoration: element.value.style.textDecoration, -// fontStyle: element.value.style.fontStyle, -// fontWeight: element.value.style.fontWeight, -// fontSize: (element.value.style.activeFontSize || 18) + 'px', -// lineHeight: (element.value.style.activeFontSize || 18) + 'px' -// } -// if (element.value.titleBackground?.enable) { -// style = { -// ...style, -// ...backgroundStyle(element.value.titleBackground.active) -// } -// } -// } else { -// style = { -// textDecoration: element.value.style.textDecoration, -// fontStyle: element.value.style.fontStyle, -// fontWeight: element.value.style.fontWeight, -// fontSize: (element.value.style.fontSize || 16) + 'px', -// lineHeight: (element.value.style.fontSize || 16) + 'px' -// } -// if (element.value.titleBackground?.enable) { -// style = { -// ...style, -// ...backgroundStyle( -// element.value.titleBackground.multiply -// ? element.value.titleBackground.active -// : element.value.titleBackground.inActive -// ) -// } -// } -// } -// return style -// } - -// const fontColor = computed(() => { -// if ( -// element.value && -// element.value.style && -// element.value.style.headFontColor && -// typeof element.value.style.headFontColor === 'string' -// ) { -// return element.value.style.headFontColor -// } else { -// return 'none' -// } -// }) - -// const activeColor = computed(() => { -// if ( -// element.value && -// element.value.style && -// element.value.style.headFontActiveColor && -// typeof element.value.style.headFontActiveColor === 'string' -// ) { -// return element.value.style.headFontActiveColor -// } else { -// return 'none' -// } -// }) - -// const borderActiveColor = computed(() => { -// if ( -// element.value && -// element.value.style && -// element.value.style.headBorderActiveColor && -// typeof element.value.style.headBorderActiveColor === 'string' -// ) { -// return element.value.style.headBorderActiveColor -// } else { -// return 'none' -// } -// }) - -// const titleValid = computed(() => { -// return !!state.textarea && !!state.textarea.trim() -// }) - -// watch( -// () => element.value, -// () => { -// calcTabLength() -// }, -// { deep: true } -// ) - -// const reShow = () => { -// state.tabShow = false -// nextTick(() => { -// state.tabShow = true -// }) -// } - -// watch( -// () => isEditMode.value, -// () => { -// initCarousel() -// } -// ) - -// watch( -// () => editableTabsValue.value, -// () => { -// viewToolTipsChange() -// } -// ) -// const initCarousel = () => { -// carouselTimer && clearInterval(carouselTimer) -// carouselTimer = null -// if (!isEditMode.value) { -// if (element.value.carousel?.enable) { -// const switchTime = (element.value.carousel.time || 5) * 1000 -// let switchCount = 1 -// // 轮播定时器 -// carouselTimer = setInterval(() => { -// // 鼠标移入时 停止轮播 -// if (!state.hoverFlag) { -// const nowIndex = switchCount % element.value.propValue.length -// switchCount++ -// nextTick(() => { -// editableTabsValue.value = element.value.propValue[nowIndex].name -// }) -// } -// }, switchTime) -// } -// } -// } - - onMounted(() => { - console.log(props.view) - initview() - // if (element.value.propValue.length > 0) { - // editableTabsValue.value = element.value.propValue[0].name - // } - // calcTabLength() - // if (['canvas', 'canvasDataV', 'edit'].includes(showPosition.value) && !mobileInPc.value) { - // eventBus.on('onTabMoveIn-' + element.value.id, componentMoveIn) - // eventBus.on('onTabMoveOut-' + element.value.id, componentMoveOut) - // eventBus.on('onTabSortChange-' + element.value.id, reShow) - // } - // currentInstance = getCurrentInstance() - // initCarousel() - // nextTick(() => { - // groupSizeStyleAdaptor(element.value) - // }) - // setTimeout(() => { - // viewToolTipsChange() - // }, 1000) + const state = reactive({ + data:[], + defaultProps:{ children: 'children', label: 'name' } }) - function initview(){ - debugger - getData(props.view).then(res => { - console.log(res,378923749234) - }) - } - // onBeforeUnmount(() => { - // if (['canvas', 'canvasDataV', 'edit'].includes(showPosition.value) && !mobileInPc.value) { - // eventBus.off('onTabMoveIn-' + element.value.id, componentMoveIn) - // eventBus.off('onTabMoveOut-' + element.value.id, componentMoveOut) - // eventBus.off('onTabSortChange-' + element.value.id, reShow) - // } - // }) - // onBeforeMount(() => { - // if (carouselTimer) { - // clearInterval(carouselTimer) - // carouselTimer = null - // } - // }) - + const initReady = ref(false) + const calcData = (view: Chart, callback) => { + const v = JSON.parse(JSON.stringify(view)) + getData(v) + .then(res => { + if (res.code && res.code !== 0) { + } else { + console.log(res,6575) + const resdata:any = res + const flatData = convertToFlatData(resdata.data.fields,resdata.data.tableRow) + state.data = convertToTree(flatData) + debugger + if(resdata?.drillFields.length > 0){ + state.defaultProps.label = resdata.drillFields[0].originName + } + // originName + // 钻取维度drillFields + // state.data = res?.data?.fields ?? [] + initReady.value = true + } + callback?.() + nextTick(() => { + initReady.value = true + }) + }) + .catch(() => { + nextTick(() => { + initReady.value = true + }) + callback?.() + }) + // getData(props.view).then(res => { + // console.log(res,378923749234) + // }) + nextTick(() => { + initReady.value = true + }) + callback?.() +} +function convertToFlatData(fields:any, tableRow:any) { + // 查找需要的字段 + const idField = fields.find(field => field.originName === 'id'); + const parentIdField = fields.find(field => field.originName === 'parentid'); + const orgNameField = fields.find(field => field.originName === 'orgname'); + const orgTypeField = fields.find(field => field.originName === 'orgtype'); + const managerField = fields.find(field => field.originName === 'manager'); + + // 转换数据 + return tableRow.map(row => { + return { + id: row[idField.gisbiName], + parentid: row[parentIdField.gisbiName], + orgname: row[orgNameField.gisbiName], + orgtype: row[orgTypeField.gisbiName], + manager: row[managerField.gisbiName] + }; + }); +} +function convertToTree(data, rootId = '0') { + // 创建一个映射表,用于快速查找节点 + const nodeMap = {}; + // 存储根节点 + const roots = []; + + // 初始化所有节点,添加children属性 + data.forEach(item => { + nodeMap[item.id] = { ...item, children: [] }; + }); + + // 构建树形结构 + data.forEach(item => { + const node = nodeMap[item.id]; + if (item.parentid === rootId || item.parentid === '') { + // 如果是根节点,添加到根节点数组 + roots.push(node); + } else { + // 如果有父节点,将其添加到父节点的children中 + const parent = nodeMap[item.parentid]; + if (parent) { + parent.children.push(node); + } else { + // 如果找不到父节点,也当作根节点处理 + roots.push(node); + } + } + }); + + return roots; +} +onMounted(() => { + console.log(props.view) + }) +defineExpose({ + calcData +}) diff --git a/core/core-frontend/src/views/chart/components/js/panel/charts/others/DeTree.ts b/core/core-frontend/src/views/chart/components/js/panel/charts/others/DeTree.ts index 450aae2..578214d 100644 --- a/core/core-frontend/src/views/chart/components/js/panel/charts/others/DeTree.ts +++ b/core/core-frontend/src/views/chart/components/js/panel/charts/others/DeTree.ts @@ -3,22 +3,24 @@ import { useI18n } from '@/hooks/web/useI18n' const { t } = useI18n() /** - * 富文本图表 + * 树图表 */ -export class RichTextChartView extends AbstractChartView { +export class DeTreeChartView extends AbstractChartView { properties: EditorProperty[] = [ 'background-overall-component', 'border-style', 'threshold', - 'function-cfg' + 'function-cfg', + 'linkage', + 'basic-attributes-selector' ] propertyInner: EditorPropertyInner = { 'background-overall-component': ['all'], 'border-style': ['all'], - threshold: ['tableThreshold'], + 'threshold': ['tableThreshold'], 'function-cfg': ['emptyDataStrategy'] } - axis: AxisType[] = ['xAxis', 'filter'] + axis: AxisType[] = ['xAxis', 'filter','drill'] axisConfig: AxisConfig = { xAxis: { name: `${t('chart.drag_block_table_data_column')} / ${t('chart.dimension_or_quota')}` diff --git a/core/core-frontend/src/views/chart/components/views/index.vue b/core/core-frontend/src/views/chart/components/views/index.vue index 261540b..e267335 100644 --- a/core/core-frontend/src/views/chart/components/views/index.vue +++ b/core/core-frontend/src/views/chart/components/views/index.vue @@ -577,13 +577,8 @@ const queryData = (firstLoad = false) => { } const calcData = params => { - debugger dvMainStore.setLastViewRequestInfo(params.id, params.chartExtRequest) if (chartComponent?.value) { - if (['DeTree'].includes(view.value.type)) { - loading.value = false - return - } loading.value = true if (view.value.isPlugin) { chartComponent?.value?.invokeMethod({ @@ -596,7 +591,7 @@ const calcData = params => { ] }) } else { - console.log(chartComponent,'23213') + console.log(chartComponent.value,'23213') chartComponent?.value?.calcData?.(params, () => { loading.value = false })