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

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

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

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

@ -77,7 +77,8 @@ export default {
this.newChart(config.option) this.newChart(config.option)
// //
this.updateChart() // this.updateChart()
this.updateData()
} else { } else {
// //
this.newChart(this.config.option) this.newChart(this.config.option)
@ -96,9 +97,7 @@ export default {
this.chart.render() this.chart.render()
this.registerEvent() this.registerEvent()
}, },
/** // G2PlotdataKeydataKey
* @description: 只更新数据
*/
updateData () { updateData () {
this.getCurrentOption().then(({ data, config }) => { this.getCurrentOption().then(({ data, config }) => {
if (data.success) { if (data.success) {
@ -123,23 +122,23 @@ export default {
/** /**
* 更新组件 * 更新组件
*/ */
updateChart () { // updateChart () {
if (this.isPreview) { // if (this.isPreview) {
this.getCurrentOption().then(({ data, config }) => { // this.getCurrentOption().then(({ data, config }) => {
if (data.success) { // if (data.success) {
// // //
config = this.buildOption(config, data) // config = this.buildOption(config, data)
this.changeChartConfig(config) // this.changeChartConfig(config)
this.chart.update(config.option) // this.chart.update(config.option)
} else { // } else {
config.option.data = this.plotList.find(plot => plot.name === config.name)?.option.data // config.option.data = this.plotList.find(plot => plot.name === config.name)?.option.data
this.chart.update(config.option) // this.chart.update(config.option)
} // }
}) // })
} else { // } else {
this.updateChartData(this.config) // this.updateChartData(this.config)
} // }
}, // },
/** /**
* 注册事件 * 注册事件
*/ */
@ -182,7 +181,7 @@ export default {
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const option = config.option const option = config.option
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
const setting = config.setting // const setting = config.setting
if (this.config.optionHandler) { if (this.config.optionHandler) {
try { try {
// config // config
@ -225,3 +224,20 @@ export default {
} }
</style> </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)) const iconList = svgFiles.keys()?.map(item => svgFiles(item))
export default { export default {
getNameList () { getNameList () {
console.log(iconList)
return iconList?.map(item => { return iconList?.map(item => {
return item?.default?.id?.split('-')[1] 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 设置时的配置不传则为当前组件的配置 * @param settingConfig 设置时的配置不传则为当前组件的配置

Loading…
Cancel
Save