feat(数据集): 跨源单源查询

This commit is contained in:
dataeaseShu
2025-04-15 11:53:45 +08:00
committed by 王嘉豪
parent cce556f15e
commit 17deb9c2df
10 changed files with 81 additions and 15 deletions

View File

@@ -11,6 +11,7 @@ import { nameTrim } from '@/utils/utils'
export interface DatasetOrFolder {
name: string
action?: string
isCross?: boolean
id?: number | string
pid?: number | string
nodeType: 'folder' | 'dataset'
@@ -63,6 +64,7 @@ export interface Dataset {
id: string
pid: string
name: string
isCross?: boolean
union?: Array<{}>
allFields?: Array<{}>
}

View File

@@ -1,6 +1,10 @@
export default {
common: {
empty: ' ',
cross_source: 'Cross-source',
single_source: 'Single-source',
source_tips:
'The data set is cross-source. Please check the syntax of other SQL nodes to confirm whether the type should be changed to cross-source?',
associated_chart: 'Associated chart',
associated_chart_first: 'First level associated chart',
changing_the_display:

View File

@@ -1,6 +1,9 @@
export default {
common: {
empty: '',
cross_source: '跨源',
single_source: '單源',
source_tips: '資料集存在跨來源情況請檢查其他 SQL 節點的語法是否確認將類型改為跨來源?',
other_levels: '除層級一外,其他層級無須進行查詢條件配置',
tree_structure: '下拉樹的結構不能為空',
associated_chart: '關聯圖表',

View File

@@ -1,6 +1,9 @@
export default {
common: {
empty: '',
cross_source: '跨源',
single_source: '单源',
source_tips: '数据集存在跨源情况请检查其他 SQL 节点的语法是否确认将类型改为跨源?',
other_levels: '除层级一外,其他层级无需进行查询条件配置',
tree_structure: '下拉树的结构不能为空',
associated_chart: '关联图表',

View File

@@ -24,7 +24,9 @@ import {
onBeforeUnmount,
shallowRef,
computed,
h
inject,
h,
Ref
} from 'vue'
import { debounce } from 'lodash-es'
import { useI18n } from '@/hooks/web/useI18n'
@@ -100,7 +102,7 @@ const state = reactive({
})
const datasourceTableData = shallowRef([])
const isCross = inject<Ref>('isCross')
const paginationConfig = reactive({
currentPage: 1,
pageSize: 10,
@@ -260,7 +262,13 @@ const getNodeField = ({ datasourceId, tableName }) => {
table: tableName,
sql: ''
}
getTableField({ datasourceId, info: JSON.stringify(info), tableName, type: 'db' })
getTableField({
datasourceId,
info: JSON.stringify(info),
tableName,
type: 'db',
isCross: isCross.value
})
.then(res => {
gridData.value = res as unknown as Field[]
})
@@ -418,6 +426,7 @@ const getSQLPreview = () => {
parseVariable()
dataPreviewLoading.value = true
getPreviewSql({
isCross: isCross.value,
sql: Base64.encode((sql = setNameIdTrans('name', 'id', codeCom.value.state.doc.toString()))),
datasourceId: sqlNode.value.datasourceId,
sqlVariableDetails: JSON.stringify(state.variables)

View File

@@ -18,6 +18,7 @@ import nothingTree from '@/assets/img/nothing-tree.png'
import { BusiTreeRequest } from '@/models/tree/TreeNode'
import { filterFreeFolder } from '@/utils/utils'
export interface Tree {
isCross: boolean
name: string
value?: string | number
id: string | number
@@ -47,6 +48,7 @@ const treeRef = ref()
const filterText = ref('')
let union = []
let allfields = []
let isCross = false
const datasetForm = reactive({
pid: '',
name: ''
@@ -156,6 +158,7 @@ const createInit = (type, data: Tree, exec, name: string) => {
if (type === 'dataset') {
union = data.union
allfields = data.allfields
isCross = data.isCross
}
if (data.id) {
const request = { leaf: false, weight: 7 } as BusiTreeRequest
@@ -264,6 +267,7 @@ const saveDataset = () => {
if (nodeType.value === 'dataset') {
params.union = union
params.allFields = allfields
params.isCross = isCross
}
if (cmd.value === 'move' && !checkPid(params.pid)) {
return

View File

@@ -43,6 +43,7 @@ const props = defineProps({
const primaryColor = computed(() => {
return appearanceStore.themeColor === 'custom' ? appearanceStore.customColor : '#3370FF'
})
const isCross = inject<Ref>('isCross')
const iconName = {
left: icon_leftAssociation,
@@ -230,7 +231,8 @@ const saveSqlNode = (val: SqlNode, cb) => {
id: id,
info: state.visualNode.info,
tableName,
type: 'sql'
type: 'sql',
isCross: isCross.value
}).then(res => {
nodeField.value = res as unknown as Field[]
nodeField.value.forEach(ele => {
@@ -273,7 +275,8 @@ const closeSqlNode = () => {
id,
info,
tableName,
type: 'sql'
type: 'sql',
isCross: isCross.value
}).then(res => {
const idOriginNameMap = allfields.value.reduce((pre, next) => {
pre[`${next.datasetTableId}${next.originName}`] = next.id
@@ -914,6 +917,7 @@ const drop_handler = ev => {
id: currentNode.value.id,
info: currentNode.value.info,
tableName,
isCross: isCross.value,
type
})
.then(res => {

View File

@@ -1,11 +1,13 @@
<script lang="ts" setup>
import { ref, reactive } from 'vue'
import { ref, reactive, inject, type Ref } from 'vue'
import UnionFieldList from './UnionFieldList.vue'
import UnionItemEdit from './UnionItemEdit.vue'
import type { Field, NodeType, UnionType, Node } from './util'
import { getTableField } from '@/api/dataset'
import { cloneDeep } from 'lodash-es'
const isCross = inject<Ref>('isCross')
const changeParentFields = val => {
parent.currentDsFields = val
}
@@ -69,10 +71,15 @@ const initState = () => {
}
const getParams = (obj: Node) => {
return ['datasourceId', 'id', 'info', 'tableName', 'type'].reduce((pre, next) => {
pre[next] = obj[next]
return pre
}, {})
return ['datasourceId', 'id', 'info', 'tableName', 'type'].reduce(
(pre, next) => {
pre[next] = obj[next]
return pre
},
{
isCross: isCross.value
}
)
}
const getFields = async () => {
const [n, p] = props.editArr as Node[]

View File

@@ -116,6 +116,7 @@ const currentField = ref({
name: '',
idArr: []
})
const isCross = ref(false)
let isUpdate = false
const fieldTypes = index => {
@@ -362,6 +363,7 @@ const editeSave = () => {
...nodeInfo,
name: datasetName.value,
union,
isCross: isCross.value,
allFields: allfields.value,
nodeType: 'dataset'
})
@@ -731,6 +733,7 @@ const initEdite = async () => {
}
datasetName.value = nodeInfo.name
allfields.value = res.allFields || []
isCross.value = res.isCross || false
dfsUnion(arr, res.union || [])
const [fir] = res.union as { currentDs: { datasourceId: string } }[]
dataSource.value = fir?.currentDs?.datasourceId
@@ -834,6 +837,7 @@ const getIconName = (type: number) => {
const allfields = ref([])
provide('allfields', allfields)
provide('isCross', isCross)
let num = +new Date()
@@ -1248,7 +1252,7 @@ const verify = () => {
const arr = []
dfsNodeList(arr, datasetDrag.value.getNodeList())
datasetPreviewLoading.value = true
getPreviewData({ union: arr, allFields: allfieldsCopy })
getPreviewData({ union: arr, allFields: allfieldsCopy, isCross: isCross.value })
.then(() => {
ElMessage.success(t('data_set.validation_succeeded'))
})
@@ -1416,7 +1420,7 @@ const datasetSave = () => {
creatDsFolder.value.createInit(
'dataset',
{ id: pid || '0', union, allfields: allfields.value },
{ id: pid || '0', union, allfields: allfields.value, isCross: isCross.value },
'',
datasetName.value
)
@@ -1433,7 +1437,7 @@ const datasetPreview = () => {
const arr = []
dfsNodeList(arr, datasetDrag.value.getNodeList())
datasetPreviewLoading.value = true
getPreviewData({ union: arr, allFields: allfields.value })
getPreviewData({ union: arr, allFields: allfields.value, isCross: isCross.value })
.then(res => {
columns.value = generateColumns((res.data.fields as Field[]) || [])
tableData.value = (res.data.data as Array<{}>) || []
@@ -1623,6 +1627,24 @@ const handleClick = () => {
})
}
const sourceChange = val => {
if (val) return
if (crossDatasources.value) {
isCross.value = !val
ElMessageBox.confirm(t('common.source_tips'), {
confirmButtonText: t('dataset.confirm'),
cancelButtonText: t('common.cancel'),
showCancelButton: true,
confirmButtonType: 'primary',
type: 'warning',
autofocus: false,
showClose: false
}).then(() => {
isCross.value = val
})
}
}
const finish = res => {
const { id, pid, name } = res
datasetName.value = name
@@ -1718,7 +1740,7 @@ const getIconNameCalc = (deType, extField, dimension = false) => {
<div class="container dataset-db" @mouseup="mouseupDrag">
<p v-show="!showLeft" class="arrow-right" @click="showLeft = true">
<el-icon>
<Icon name="icon_right_outlined"><icon_right_outlined class="svg-icon" /></Icon>
<Icon><icon_right_outlined class="svg-icon" /></Icon>
</el-icon>
</p>
<div
@@ -1735,6 +1757,14 @@ const getIconNameCalc = (deType, extField, dimension = false) => {
:style="{ width: LeftWidth + 'px' }"
>
<div class="table-list-top">
<el-switch
style="margin-bottom: 8px"
v-model="isCross"
@change="sourceChange"
:active-text="$t('common.cross_source')"
:inactive-text="$t('common.single_source')"
/>
<p class="select-ds">
{{ t('data_set.select_data_source') }}
<span class="left-outlined">

View File

@@ -205,7 +205,7 @@ const selectDataset = row => {
Object.assign(dsTableDetail, row)
userDrawer.value = true
dsTableDataLoading.value = true
getTableField({ tableName: row.tableName, datasourceId: nodeInfo.id })
getTableField({ tableName: row.tableName, datasourceId: nodeInfo.id, isCross: false })
.then(res => {
state.dsTableData = res.data
})