1
0
mirror of synced 2025-12-23 20:57:56 +08:00

feat(editor): 数据源字段选择器增加编辑按钮

This commit is contained in:
roymondchen
2024-03-26 16:12:01 +08:00
parent f92127e3d6
commit 66e16452a8
3 changed files with 83 additions and 32 deletions

View File

@@ -0,0 +1,46 @@
import { computed, ref } from 'vue';
import type { DataSourceSchema } from '@tmagic/schema';
import DataSourceConfigPanel from '@editor/layouts/sidebar/data-source/DataSourceConfigPanel.vue';
import type { DataSourceService } from '@editor/services/dataSource';
export const useDataSourceEdit = (dataSourceService?: DataSourceService) => {
const dialogTitle = ref('');
const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
const dataSourceValues = ref<Record<string, any>>({});
const editable = computed(() => dataSourceService?.get('editable') ?? true);
const editHandler = (id: string) => {
if (!editDialog.value) return;
dataSourceValues.value = {
...dataSourceService?.getDataSourceById(id),
};
dialogTitle.value = `编辑${dataSourceValues.value.title || ''}`;
editDialog.value.show();
};
const submitDataSourceHandler = (value: DataSourceSchema) => {
if (value.id) {
dataSourceService?.update(value);
} else {
dataSourceService?.add(value);
}
editDialog.value?.hide();
};
return {
dialogTitle,
editDialog,
dataSourceValues,
editable,
editHandler,
submitDataSourceHandler,
};
};