fix: 修复自定义JS数据集,编辑、保存接口不存在的情况

main
wu.jian2 2 years ago
parent 166c2b5f63
commit 5b821d0d46

@ -353,7 +353,7 @@
import ParamsSettingDialog from './ParamsSettingDialog.vue'
import OutputFieldDialog from './OutputFieldDialog.vue'
import FieldFillDialog from './FieldFillDialog.vue'
import { nameCheckRepeat, datasetAddorUpdate, getDataset, getDatasetTypeList } from 'packages/js/utils/datasetConfigService'
import { nameCheckRepeat, datasetAdd, datasetUpdate, getDataset, getCategoryTree } from 'packages/js/utils/datasetConfigService'
import { codemirror } from 'vue-codemirror'
import 'codemirror/mode/javascript/javascript'
import 'codemirror/lib/codemirror.css'
@ -457,7 +457,7 @@ export default {
},
methods: {
async init () {
this.categoryData = await getDatasetTypeList({ tableName: 'r_dataset', moduleCode: this.appCode })
this.categoryData = await getCategoryTree({ tableName: 'dataset', moduleCode: this.appCode })
if (this.typeId) {
this.dataForm.typeId = this.typeId
this.$nextTick(() => {
@ -520,8 +520,8 @@ export default {
fieldList: outputFieldList
}
}
// const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
datasetAddorUpdate(form).then(() => {
const datasetSave = this.dataForm.id === '' ? datasetAdd : datasetUpdate
datasetSave(form).then(() => {
this.$message.success('操作成功')
this.$parent.init(false)
this.$parent.setType = null

@ -200,6 +200,7 @@
/>
<component
:is="componentData.component"
v-if="datasetType"
ref="EditForm"
:key="componentData.key"
:config="componentData.config"

@ -77,7 +77,8 @@ export default {
this.newChart(config.option)
//
this.updateChart()
// this.updateChart()
this.updateData()
} else {
//
this.newChart(this.config.option)
@ -96,9 +97,7 @@ export default {
this.chart.render()
this.registerEvent()
},
/**
* @description: 只更新数据
*/
// G2PlotdataKeydataKey
updateData () {
this.getCurrentOption().then(({ data, config }) => {
if (data.success) {
@ -123,23 +122,23 @@ export default {
/**
* 更新组件
*/
updateChart () {
if (this.isPreview) {
this.getCurrentOption().then(({ data, config }) => {
if (data.success) {
//
config = this.buildOption(config, data)
this.changeChartConfig(config)
this.chart.update(config.option)
} else {
config.option.data = this.plotList.find(plot => plot.name === config.name)?.option.data
this.chart.update(config.option)
}
})
} else {
this.updateChartData(this.config)
}
},
// updateChart () {
// if (this.isPreview) {
// this.getCurrentOption().then(({ data, config }) => {
// if (data.success) {
// //
// config = this.buildOption(config, data)
// this.changeChartConfig(config)
// this.chart.update(config.option)
// } else {
// config.option.data = this.plotList.find(plot => plot.name === config.name)?.option.data
// this.chart.update(config.option)
// }
// })
// } else {
// this.updateChartData(this.config)
// }
// },
/**
* 注册事件
*/
@ -182,7 +181,7 @@ export default {
// eslint-disable-next-line no-unused-vars
const option = config.option
// eslint-disable-next-line no-unused-vars
const setting = config.setting
// const setting = config.setting
if (this.config.optionHandler) {
try {
// config
@ -225,3 +224,20 @@ export default {
}
</style>
function generateRandomData() {
const data = [];
function generateRandomValue() {
//
return Math.random().toString(36).substr(2, 7);
}
for (let i = 0; i < 10; i++) {
const obj = {
key1: generateRandomValue(),
key2: generateRandomValue(),
key3: generateRandomValue()
};
data.push(obj);
}
return data;
}

@ -3,7 +3,6 @@ const svgFiles = require.context('./svg', true, /\.svg$/)
const iconList = svgFiles.keys()?.map(item => svgFiles(item))
export default {
getNameList () {
console.log(iconList)
return iconList?.map(item => {
return item?.default?.id?.split('-')[1]
}) || []

@ -63,9 +63,36 @@ export default {
}
},
// 组件仅更新数据
changeData () {},
changeData () { },
// 组件仅更新样式
changeStyle () {},
changeStyle () {
this.config = _.cloneDeep(this.config)
// 遍历config.setting将config.setting中的值赋值给config.option中对应的optionField
this.config.setting.forEach(set => {
if (set.optionField) {
const optionField = set.optionField.split('.')
let option = this.config.option
optionField.forEach((field, index) => {
if (index === optionField.length - 1) {
// 数据配置时,必须有值才更新
if ((set.tabName === 'data' && set.value) || set.tabName === 'custom') {
option[field] = set.value
}
} else {
option = option[field]
}
})
}
})
if (this.config.optionHandler) {
try {
// 此处函数处理config
eval(this.config.optionHandler)
} catch (e) {
console.error(e)
}
}
},
/**
* 初始化组件时获取后端返回的数据, 返回数据和当前组件的配置
* @param settingConfig 设置时的配置不传则为当前组件的配置

Loading…
Cancel
Save