Merge pull request #11490 from dataease/pr@dev-v2@feat_dataset-params

feat(仪表板): 数据集计算字段支持设置参数
This commit is contained in:
王嘉豪 2024-08-12 14:58:07 +08:00 committed by GitHub
commit 4d981db499
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 104 additions and 45 deletions

View File

@ -45,6 +45,7 @@ import DragInfo from '@/components/visualization/common/DragInfo.vue'
import { activeWatermark } from '@/components/watermark/watermark' import { activeWatermark } from '@/components/watermark/watermark'
import { personInfoApi } from '@/api/user' import { personInfoApi } from '@/api/user'
import PopArea from '@/custom-component/pop-area/Component.vue' import PopArea from '@/custom-component/pop-area/Component.vue'
import DatasetParamsComponent from '@/components/visualization/DatasetParamsComponent.vue'
const snapshotStore = snapshotStoreWithOut() const snapshotStore = snapshotStoreWithOut()
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
@ -203,6 +204,7 @@ const isShowArea = ref(false)
const svgFilterAttrs = ['width', 'height', 'top', 'left', 'rotate', 'backgroundColor'] const svgFilterAttrs = ['width', 'height', 'top', 'left', 'rotate', 'backgroundColor']
const commonFilterAttrs = ['width', 'height', 'top', 'left', 'rotate'] const commonFilterAttrs = ['width', 'height', 'top', 'left', 'rotate']
const userViewEnlargeRef = ref(null) const userViewEnlargeRef = ref(null)
const customDatasetParamsRef = ref(null)
const linkJumpRef = ref(null) const linkJumpRef = ref(null)
const linkageRef = ref(null) const linkageRef = ref(null)
const mainDomId = ref('editor-' + canvasId.value) const mainDomId = ref('editor-' + canvasId.value)
@ -1346,6 +1348,10 @@ const userViewEnlargeOpen = (opt, item) => {
) )
} }
const datasetParamsInit = item => {
customDatasetParamsRef.value?.optInit(item)
}
const initSnapshotTimer = () => { const initSnapshotTimer = () => {
snapshotTimer.value = setInterval(() => { snapshotTimer.value = setInterval(() => {
snapshotStore.snapshotCatchToStore() snapshotStore.snapshotCatchToStore()
@ -1531,6 +1537,7 @@ defineExpose({
@onDragging="onDragging($event, item, index)" @onDragging="onDragging($event, item, index)"
@onResizing="onResizing($event, item, index)" @onResizing="onResizing($event, item, index)"
@userViewEnlargeOpen="userViewEnlargeOpen($event, item)" @userViewEnlargeOpen="userViewEnlargeOpen($event, item)"
@datasetParamsInit="datasetParamsInit(item)"
@linkJumpSetOpen="linkJumpSetOpen(item)" @linkJumpSetOpen="linkJumpSetOpen(item)"
@linkageSetOpen="linkageSetOpen(item)" @linkageSetOpen="linkageSetOpen(item)"
> >
@ -1596,6 +1603,7 @@ defineExpose({
<user-view-enlarge ref="userViewEnlargeRef"></user-view-enlarge> <user-view-enlarge ref="userViewEnlargeRef"></user-view-enlarge>
<link-jump-set ref="linkJumpRef"></link-jump-set> <link-jump-set ref="linkJumpRef"></link-jump-set>
<linkage-set ref="linkageRef"></linkage-set> <linkage-set ref="linkageRef"></linkage-set>
<dataset-params-component ref="customDatasetParamsRef"></dataset-params-component>
</div> </div>
</template> </template>

View File

@ -90,7 +90,7 @@ const { config, showPosition, index, canvasStyleData, canvasViewInfo, dvInfo, se
toRefs(props) toRefs(props)
let currentInstance let currentInstance
const component = ref(null) const component = ref(null)
const emits = defineEmits(['userViewEnlargeOpen', 'onPointClick']) const emits = defineEmits(['userViewEnlargeOpen', 'datasetParamsInit', 'onPointClick'])
const htmlToImage = () => { const htmlToImage = () => {
setTimeout(() => { setTimeout(() => {
@ -254,6 +254,7 @@ const deepScale = computed(() => scale.value / 100)
:show-position="showPosition" :show-position="showPosition"
:class="{ 'wrapper-edit-bar-active': active }" :class="{ 'wrapper-edit-bar-active': active }"
@userViewEnlargeOpen="opt => emits('userViewEnlargeOpen', opt)" @userViewEnlargeOpen="opt => emits('userViewEnlargeOpen', opt)"
@datasetParamsInit="() => emits('datasetParamsInit')"
></component-edit-bar> ></component-edit-bar>
<component-selector <component-selector
v-if=" v-if="

View File

@ -17,9 +17,11 @@ import { XpackComponent } from '@/components/plugin'
import PopArea from '@/custom-component/pop-area/Component.vue' import PopArea from '@/custom-component/pop-area/Component.vue'
import CanvasFilterBtn from '@/custom-component/canvas-filter-btn/Component.vue' import CanvasFilterBtn from '@/custom-component/canvas-filter-btn/Component.vue'
import { useEmitt } from '@/hooks/web/useEmitt' import { useEmitt } from '@/hooks/web/useEmitt'
import DatasetParamsComponent from '@/components/visualization/DatasetParamsComponent.vue'
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
const { pcMatrixCount, curComponent, mobileInPc, canvasState } = storeToRefs(dvMainStore) const { pcMatrixCount, curComponent, mobileInPc, canvasState } = storeToRefs(dvMainStore)
const openHandler = ref(null) const openHandler = ref(null)
const customDatasetParamsRef = ref(null)
const props = defineProps({ const props = defineProps({
canvasStyleData: { canvasStyleData: {
@ -377,6 +379,9 @@ const popAreaAvailable = computed(
const filterBtnShow = computed( const filterBtnShow = computed(
() => popAreaAvailable.value && popComponentData.value && popComponentData.value.length > 0 () => popAreaAvailable.value && popComponentData.value && popComponentData.value.length > 0
) )
const datasetParamsInit = item => {
customDatasetParamsRef.value?.optInit(item)
}
defineExpose({ defineExpose({
restore restore
@ -428,10 +433,12 @@ defineExpose({
:scale="mobileInPc ? 100 : scaleMin" :scale="mobileInPc ? 100 : scaleMin"
:is-selector="props.isSelector" :is-selector="props.isSelector"
@userViewEnlargeOpen="userViewEnlargeOpen($event, item)" @userViewEnlargeOpen="userViewEnlargeOpen($event, item)"
@datasetParamsInit="datasetParamsInit(item)"
@onPointClick="onPointClick" @onPointClick="onPointClick"
/> />
<user-view-enlarge ref="userViewEnlargeRef"></user-view-enlarge> <user-view-enlarge ref="userViewEnlargeRef"></user-view-enlarge>
</div> </div>
<dataset-params-component ref="customDatasetParamsRef"></dataset-params-component>
<XpackComponent ref="openHandler" jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvT3BlbkhhbmRsZXI=" /> <XpackComponent ref="openHandler" jsname="L2NvbXBvbmVudC9lbWJlZGRlZC1pZnJhbWUvT3BlbkhhbmRsZXI=" />
</template> </template>

View File

@ -31,6 +31,7 @@
:show-position="showPosition" :show-position="showPosition"
:canvas-id="canvasId" :canvas-id="canvasId"
@userViewEnlargeOpen="userViewEnlargeOpen" @userViewEnlargeOpen="userViewEnlargeOpen"
@datasetParamsInit="datasetParamsInit"
@linkJumpSetOpen="linkJumpSetOpen" @linkJumpSetOpen="linkJumpSetOpen"
@linkageSetOpen="linkageSetOpen" @linkageSetOpen="linkageSetOpen"
></component-edit-bar> ></component-edit-bar>
@ -132,6 +133,7 @@ const {
const { editorMap, areaData, isCtrlOrCmdDown } = storeToRefs(composeStore) const { editorMap, areaData, isCtrlOrCmdDown } = storeToRefs(composeStore)
const emit = defineEmits([ const emit = defineEmits([
'userViewEnlargeOpen', 'userViewEnlargeOpen',
'datasetParamsInit',
'onStartResize', 'onStartResize',
'onStartMove', 'onStartMove',
'onDragging', 'onDragging',
@ -324,6 +326,10 @@ const userViewEnlargeOpen = opt => {
emit('userViewEnlargeOpen', opt) emit('userViewEnlargeOpen', opt)
} }
const datasetParamsInit = opt => {
emit('datasetParamsInit', opt)
}
const getPointStyle = point => { const getPointStyle = point => {
let { width, height } = defaultStyle.value let { width, height } = defaultStyle.value
const { sizeX, sizeY } = element.value const { sizeX, sizeY } = element.value

View File

@ -60,7 +60,7 @@
effect="dark" effect="dark"
placement="top" placement="top"
content="输入计算数据" content="输入计算数据"
v-if="barShowCheck('datasetParams')" v-if="barShowCheck('datasetParams') && datasetParamsSetShow"
> >
<span> <span>
<el-icon class="bar-base-icon" @click="datasetParamsInit"> <el-icon class="bar-base-icon" @click="datasetParamsInit">
@ -199,6 +199,7 @@ import { ElMessage, ElTooltip, ElButton } from 'element-plus-secondary'
import CustomTabsSort from '@/custom-component/de-tabs/CustomTabsSort.vue' import CustomTabsSort from '@/custom-component/de-tabs/CustomTabsSort.vue'
import { exportPivotExcel } from '@/views/chart/components/js/panel/common/common_table' import { exportPivotExcel } from '@/views/chart/components/js/panel/common/common_table'
import { XpackComponent } from '@/components/plugin' import { XpackComponent } from '@/components/plugin'
import DatasetParamsComponent from '@/components/visualization/DatasetParamsComponent.vue'
const dvMainStore = dvMainStoreWithOut() const dvMainStore = dvMainStoreWithOut()
const snapshotStore = snapshotStoreWithOut() const snapshotStore = snapshotStoreWithOut()
const copyStore = copyStoreWithOut() const copyStore = copyStoreWithOut()
@ -206,6 +207,7 @@ const customTabsSortRef = ref(null)
const authShow = computed(() => !dvInfo.value.weight || dvInfo.value.weight > 3) const authShow = computed(() => !dvInfo.value.weight || dvInfo.value.weight > 3)
const emits = defineEmits([ const emits = defineEmits([
'userViewEnlargeOpen', 'userViewEnlargeOpen',
'datasetParamsInit',
'closePreview', 'closePreview',
'showViewDetails', 'showViewDetails',
'amRemoveItem', 'amRemoveItem',
@ -434,6 +436,7 @@ const deleteComponent = () => {
const datasetParamsInit = () => { const datasetParamsInit = () => {
// do init // do init
emits('datasetParamsInit')
} }
const copyComponent = () => { const copyComponent = () => {
@ -562,6 +565,10 @@ const initCurFields = () => {
} }
// -End // -End
const datasetParamsSetShow = computed(() => {
return canvasViewInfo.value[element.value.id]?.calParams?.length > 0
})
onMounted(() => { onMounted(() => {
if (element.value.component === 'UserView') { if (element.value.component === 'UserView') {
eventBus.on('initCurFields-' + element.value.id, initCurFields) eventBus.on('initCurFields-' + element.value.id, initCurFields)

View File

@ -1,29 +1,21 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue' import { computed, reactive, ref } from 'vue'
import { useI18n } from '@/hooks/web/useI18n' import { useI18n } from '@/hooks/web/useI18n'
import { deepCopy } from '@/utils/utils' import { deepCopy } from '@/utils/utils'
import DeUpload from '@/components/visualization/common/DeUpload.vue' import { useEmitt } from '@/hooks/web/useEmitt'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { ElMessage } from 'element-plus-secondary'
const { t } = useI18n() const { t } = useI18n()
const loading = ref(false) const loading = ref(false)
const rules = {
name: [
{
required: true,
message: t('commons.input_content'),
trigger: 'change'
},
{
max: 50,
message: t('commons.char_can_not_more_50'),
trigger: 'change'
}
]
}
const subject = ref() const subject = ref()
const subjectDialogShow = ref(false) const subjectDialogShow = ref(false)
const optType = ref('new') const dvMainStore = dvMainStoreWithOut()
const { canvasViewInfo } = storeToRefs(dvMainStore)
const state = reactive({
viewId: null
})
const curDataSetParamsInfo = ref([]) const curDataSetParamsInfo = ref([])
const resetForm = () => { const resetForm = () => {
@ -31,53 +23,87 @@ const resetForm = () => {
subjectDialogShow.value = false subjectDialogShow.value = false
} }
const subjectForm = ref(null) const subjectForm = ref(null)
const title = computed(() => (optType.value === 'new' ? '新建主题' : '编辑主题')) const rules = ref({})
const optInit = (subjectItem, opt) => { const optInit = item => {
optType.value = opt if (item) {
state.viewId = item.id
const chartInfo = canvasViewInfo.value[state.viewId]
curDataSetParamsInfo.value = deepCopy(chartInfo.calParams)
subjectDialogShow.value = true subjectDialogShow.value = true
curDataSetParamsInfo.value = subjectItem }
} }
const saveSubject = () => { const saveSubject = () => {
subject.value.validate(result => { if (disabledCheck.value) {
if (result) { ElMessage.error('请输入正确参数')
emits('finish', subjectForm.value) return
} }
canvasViewInfo.value[state.viewId]['calParams'] = curDataSetParamsInfo.value
useEmitt().emitter.emit('calcData-' + state.viewId, canvasViewInfo.value[state.viewId])
resetForm()
}
const disabledCheck = computed(() => {
return (
!curDataSetParamsInfo.value ||
(curDataSetParamsInfo.value &&
curDataSetParamsInfo.value.filter(item => item.value === null || item.value === undefined)
.length > 0)
)
}) })
const statesCheck = () => {
return subjectDialogShow.value
}
const handleDialogClick = e => {
e.preventDefault()
e.stopPropagation()
} }
defineExpose({ defineExpose({
optInit, optInit,
statesCheck,
resetForm resetForm
}) })
const emits = defineEmits(['finish']) const emits = defineEmits(['finish'])
const onImgChange = imgUrl => {
subjectForm.value.coverUrl = imgUrl
}
</script> </script>
<template> <template>
<el-dialog <el-dialog
v-loading="loading" v-loading="loading"
:title="title" title="计算参数输入"
v-model="subjectDialogShow" v-model="subjectDialogShow"
width="400px" width="400px"
:before-close="resetForm" :before-close="resetForm"
@click="handleDialogClick"
> >
<el-form <el-form
v-if="subjectDialogShow"
label-position="top" label-position="top"
require-asterisk-position="right"
ref="subject" ref="subject"
:model="subjectForm" :model="subjectForm"
:rules="rules" :rules="rules"
> >
<el-form-item v-for="paramsItem in curDataSetParamsInfo" class="form-item" prop="name"> <el-form-item
v-for="paramsItem in curDataSetParamsInfo"
:key="paramsItem"
class="form-item"
:prop="'value_' + paramsItem.name"
>
<template #label> <template #label>
<label class="m-label"> {{ paramsItem.name }} </label> <label class="m-label">
计算字段[{{ paramsItem.name }}] <span style="color: red">*</span>
</label>
</template> </template>
<el-input v-model="paramsItem.value" /> <el-input-number
style="width: 100%"
v-model="paramsItem.value"
placeholder="请输入一个数字"
controls-position="right"
/>
</el-form-item> </el-form-item>
</el-form> </el-form>
<template #footer> <template #footer>

View File

@ -361,7 +361,7 @@ const calcData = (view, callback) => {
chartData.value = res?.data as Partial<Chart['data']> chartData.value = res?.data as Partial<Chart['data']>
emit('onDrillFilters', res?.drillFilters) emit('onDrillFilters', res?.drillFilters)
dvMainStore.setViewDataDetails(view.id, chartData.value) dvMainStore.setViewDataDetails(view.id, res)
renderChart(res) renderChart(res)
} }
callback?.() callback?.()

View File

@ -377,7 +377,7 @@ const calcData = (view: Chart, callback) => {
state.totalItems = res?.totalItems state.totalItems = res?.totalItems
const curViewInfo = canvasViewInfo.value[element.value.id] const curViewInfo = canvasViewInfo.value[element.value.id]
curViewInfo['curFields'] = res.data.fields curViewInfo['curFields'] = res.data.fields
dvMainStore.setViewDataDetails(element.value.id, state.data) dvMainStore.setViewDataDetails(element.value.id, res)
initReady.value = true initReady.value = true
initCurFields(res) initCurFields(res)
} }
@ -398,7 +398,7 @@ const calcData = (view: Chart, callback) => {
state.totalItems = 0 state.totalItems = 0
const curViewInfo = canvasViewInfo.value[element.value.id] const curViewInfo = canvasViewInfo.value[element.value.id]
curViewInfo['curFields'] = [] curViewInfo['curFields'] = []
dvMainStore.setViewDataDetails(element.value.id, state.data) dvMainStore.setViewDataDetails(element.value.id, state.viewDataInfo)
initReady.value = true initReady.value = true
initCurFields(curViewInfo) initCurFields(curViewInfo)
callback?.() callback?.()

View File

@ -1189,8 +1189,12 @@ export const dvMainStore = defineStore('dataVisualization', {
mobileLayout: false mobileLayout: false
} }
}, },
setViewDataDetails(viewId, dataInfo) { setViewDataDetails(viewId, chartDataInfo) {
this.canvasViewDataInfo[viewId] = dataInfo this.canvasViewDataInfo[viewId] = chartDataInfo.data
const viewInfo = this.canvasViewInfo[viewId]
if (viewInfo.tableId !== chartDataInfo.tableId) {
this.canvasViewInfo[viewId]['calcParams'] = chartDataInfo.calcParams || null
}
}, },
getViewDataDetails(viewId) { getViewDataDetails(viewId) {
return this.canvasViewDataInfo[viewId] return this.canvasViewDataInfo[viewId]

View File

@ -180,7 +180,7 @@ const calcData = async (view, callback) => {
dynamicAreaId.value = country.value + dynamicAreaId.value dynamicAreaId.value = country.value + dynamicAreaId.value
} }
} }
dvMainStore.setViewDataDetails(view.id, chartData.value) dvMainStore.setViewDataDetails(view.id, res)
if ( if (
!res.drill && !res.drill &&
!res.chartExtRequest?.filter?.length && !res.chartExtRequest?.filter?.length &&

View File

@ -136,7 +136,7 @@ const calcData = (view: Chart, callback, resetPageInfo = true) => {
} else { } else {
chartData.value = res?.data as Partial<Chart['data']> chartData.value = res?.data as Partial<Chart['data']>
state.totalItems = res?.totalItems state.totalItems = res?.totalItems
dvMainStore.setViewDataDetails(view.id, chartData.value) dvMainStore.setViewDataDetails(view.id, res)
emit('onDrillFilters', res?.drillFilters) emit('onDrillFilters', res?.drillFilters)
renderChart(res as unknown as Chart, resetPageInfo) renderChart(res as unknown as Chart, resetPageInfo)
} }