mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-06 03:57:56 +08:00
feat(editor): 新增数据源时先选类型
This commit is contained in:
parent
c5a1c2db76
commit
2bd86d2101
@ -14,18 +14,21 @@
|
|||||||
:values="fieldValues"
|
:values="fieldValues"
|
||||||
:parentValues="model[name]"
|
:parentValues="model[name]"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
|
:width="width"
|
||||||
@submit="fieldChange"
|
@submit="fieldChange"
|
||||||
></MFormDrawer>
|
></MFormDrawer>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
import { TMagicButton, tMagicMessageBox } from '@tmagic/design';
|
||||||
import { FieldProps, FormConfig, FormState, MFormDrawer } from '@tmagic/form';
|
import { type FieldProps, type FormConfig, type FormState, MFormDrawer } from '@tmagic/form';
|
||||||
import { MagicTable } from '@tmagic/table';
|
import { MagicTable } from '@tmagic/table';
|
||||||
|
|
||||||
|
import type { Services } from '@editor/type';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'MEditorDataSourceFields',
|
name: 'MEditorDataSourceFields',
|
||||||
});
|
});
|
||||||
@ -43,10 +46,14 @@ const props = withDefaults(
|
|||||||
|
|
||||||
const emit = defineEmits(['change']);
|
const emit = defineEmits(['change']);
|
||||||
|
|
||||||
|
const services = inject<Services>('services');
|
||||||
|
|
||||||
const addDialog = ref<InstanceType<typeof MFormDrawer>>();
|
const addDialog = ref<InstanceType<typeof MFormDrawer>>();
|
||||||
const fieldValues = ref<Record<string, any>>({});
|
const fieldValues = ref<Record<string, any>>({});
|
||||||
const filedTitle = ref('');
|
const filedTitle = ref('');
|
||||||
|
|
||||||
|
const width = computed(() => globalThis.document.body.clientWidth - (services?.uiService.get('columnWidth').left || 0));
|
||||||
|
|
||||||
const newHandler = () => {
|
const newHandler = () => {
|
||||||
fieldValues.value = {};
|
fieldValues.value = {};
|
||||||
filedTitle.value = '新增属性';
|
filedTitle.value = '新增属性';
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
<TMagicButton v-if="editable" class="create-code-button" type="primary" size="small" @click="createCodeBlock"
|
<TMagicButton v-if="editable" class="create-code-button" type="primary" size="small" @click="createCodeBlock"
|
||||||
>新增</TMagicButton
|
>新增</TMagicButton
|
||||||
>
|
>
|
||||||
|
<slot name="code-block-panel-search"></slot>
|
||||||
</div>
|
</div>
|
||||||
</slot>
|
</slot>
|
||||||
|
|
||||||
|
@ -2,7 +2,24 @@
|
|||||||
<TMagicScrollbar class="data-source-list-panel m-editor-dep-list-panel">
|
<TMagicScrollbar class="data-source-list-panel m-editor-dep-list-panel">
|
||||||
<div class="search-wrapper">
|
<div class="search-wrapper">
|
||||||
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
<SearchInput @search="filterTextChangeHandler"></SearchInput>
|
||||||
<TMagicButton v-if="editable" type="primary" size="small" @click="addHandler">新增</TMagicButton>
|
<TMagicPopover v-if="editable" placement="right">
|
||||||
|
<template #reference>
|
||||||
|
<TMagicButton type="primary" size="small">新增</TMagicButton>
|
||||||
|
</template>
|
||||||
|
<div class="data-source-list-panel-add-menu">
|
||||||
|
<ToolButton
|
||||||
|
v-for="(item, index) in datasourceTypeList"
|
||||||
|
:data="{
|
||||||
|
type: 'button',
|
||||||
|
text: item.text,
|
||||||
|
handler: () => {
|
||||||
|
addHandler(item.type);
|
||||||
|
},
|
||||||
|
}"
|
||||||
|
:key="index"
|
||||||
|
></ToolButton>
|
||||||
|
</div>
|
||||||
|
</TMagicPopover>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 数据源列表 -->
|
<!-- 数据源列表 -->
|
||||||
@ -12,7 +29,7 @@
|
|||||||
ref="editDialog"
|
ref="editDialog"
|
||||||
:disabled="!editable"
|
:disabled="!editable"
|
||||||
:values="dataSourceValues"
|
:values="dataSourceValues"
|
||||||
:title="typeof dataSourceValues.id !== 'undefined' ? `编辑${dataSourceValues.title}` : '新增'"
|
:title="dialogTitle"
|
||||||
@submit="submitDataSourceHandler"
|
@submit="submitDataSourceHandler"
|
||||||
></DataSourceConfigPanel>
|
></DataSourceConfigPanel>
|
||||||
</TMagicScrollbar>
|
</TMagicScrollbar>
|
||||||
@ -21,10 +38,11 @@
|
|||||||
<script setup lang="ts" name="MEditorDataSourceListPanel">
|
<script setup lang="ts" name="MEditorDataSourceListPanel">
|
||||||
import { computed, inject, ref } from 'vue';
|
import { computed, inject, ref } from 'vue';
|
||||||
|
|
||||||
import { TMagicButton, TMagicScrollbar } from '@tmagic/design';
|
import { TMagicButton, TMagicPopover, TMagicScrollbar } from '@tmagic/design';
|
||||||
import type { DataSourceSchema } from '@tmagic/schema';
|
import type { DataSourceSchema } from '@tmagic/schema';
|
||||||
|
|
||||||
import SearchInput from '@editor/components/SearchInput.vue';
|
import SearchInput from '@editor/components/SearchInput.vue';
|
||||||
|
import ToolButton from '@editor/components/ToolButton.vue';
|
||||||
import type { Services } from '@editor/type';
|
import type { Services } from '@editor/type';
|
||||||
|
|
||||||
import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
|
import DataSourceConfigPanel from './DataSourceConfigPanel.vue';
|
||||||
@ -40,12 +58,26 @@ const editDialog = ref<InstanceType<typeof DataSourceConfigPanel>>();
|
|||||||
|
|
||||||
const dataSourceValues = ref<Record<string, any>>({});
|
const dataSourceValues = ref<Record<string, any>>({});
|
||||||
|
|
||||||
const editable = computed(() => dataSourceService?.get('editable') ?? true);
|
const dialogTitle = ref('');
|
||||||
|
|
||||||
const addHandler = () => {
|
const editable = computed(() => dataSourceService?.get('editable') ?? true);
|
||||||
|
const datasourceTypeList = computed(() =>
|
||||||
|
[
|
||||||
|
{ text: '基础', type: 'base' },
|
||||||
|
{ text: 'HTTP', type: 'http' },
|
||||||
|
].concat(dataSourceService?.get('datasourceTypeList') ?? []),
|
||||||
|
);
|
||||||
|
|
||||||
|
const addHandler = (type: string) => {
|
||||||
if (!editDialog.value) return;
|
if (!editDialog.value) return;
|
||||||
|
|
||||||
dataSourceValues.value = {};
|
dataSourceValues.value = {
|
||||||
|
type,
|
||||||
|
};
|
||||||
|
|
||||||
|
const datasourceType = datasourceTypeList.value.find((item) => item.type === type);
|
||||||
|
|
||||||
|
dialogTitle.value = `新增${datasourceType?.text || ''}`;
|
||||||
|
|
||||||
editDialog.value.show();
|
editDialog.value.show();
|
||||||
};
|
};
|
||||||
@ -57,6 +89,8 @@ const editHandler = (id: string) => {
|
|||||||
...dataSourceService?.getDataSourceById(id),
|
...dataSourceService?.getDataSourceById(id),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dialogTitle.value = `新增${dataSourceValues.value.title || ''}`;
|
||||||
|
|
||||||
editDialog.value.show();
|
editDialog.value.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ class DataSource extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getFormConfig(type = 'base') {
|
public getFormConfig(type = 'base') {
|
||||||
return getFormConfig(type, this.get('datasourceTypeList'), this.get('configs'));
|
return getFormConfig(type, this.get('configs'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public setFormConfig(type: string, config: FormConfig) {
|
public setFormConfig(type: string, config: FormConfig) {
|
||||||
|
@ -15,3 +15,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.data-source-list-panel-add-menu {
|
||||||
|
.tmagic-design-button {
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
span {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
import type { FormConfig } from '@tmagic/form';
|
import type { FormConfig } from '@tmagic/form';
|
||||||
|
|
||||||
import type { DatasourceTypeOption } from '@editor/type';
|
export default function (): FormConfig {
|
||||||
|
|
||||||
export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormConfig {
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
name: 'id',
|
name: 'id',
|
||||||
@ -11,12 +9,7 @@ export default function (datasourceTypeList: DatasourceTypeOption[] = []): FormC
|
|||||||
{
|
{
|
||||||
name: 'type',
|
name: 'type',
|
||||||
text: '类型',
|
text: '类型',
|
||||||
type: 'select',
|
type: 'hidden',
|
||||||
options: [
|
|
||||||
{ text: '基础', value: 'base' },
|
|
||||||
{ text: 'HTTP', value: 'http' },
|
|
||||||
...datasourceTypeList.map((item) => ({ text: item.text, value: item.type })),
|
|
||||||
],
|
|
||||||
defaultValue: 'base',
|
defaultValue: 'base',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
import { FormConfig } from '@tmagic/form';
|
import { FormConfig } from '@tmagic/form';
|
||||||
import { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
import { DataSchema, DataSourceSchema } from '@tmagic/schema';
|
||||||
|
|
||||||
import { DatasourceTypeOption } from '@editor/type';
|
|
||||||
|
|
||||||
import BaseFormConfig from './formConfigs/base';
|
import BaseFormConfig from './formConfigs/base';
|
||||||
import HttpFormConfig from './formConfigs/http';
|
import HttpFormConfig from './formConfigs/http';
|
||||||
|
|
||||||
const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption[]): FormConfig => [
|
const fillConfig = (config: FormConfig): FormConfig => [
|
||||||
...BaseFormConfig(datasourceTypeList),
|
...BaseFormConfig(),
|
||||||
...config,
|
...config,
|
||||||
{
|
{
|
||||||
type: 'panel',
|
type: 'panel',
|
||||||
@ -33,18 +31,14 @@ const fillConfig = (config: FormConfig, datasourceTypeList: DatasourceTypeOption
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const getFormConfig = (
|
export const getFormConfig = (type: string, configs: Record<string, FormConfig>): FormConfig => {
|
||||||
type: string,
|
|
||||||
datasourceTypeList: DatasourceTypeOption[],
|
|
||||||
configs: Record<string, FormConfig>,
|
|
||||||
): FormConfig => {
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'base':
|
case 'base':
|
||||||
return fillConfig([], datasourceTypeList);
|
return fillConfig([]);
|
||||||
case 'http':
|
case 'http':
|
||||||
return fillConfig(HttpFormConfig, datasourceTypeList);
|
return fillConfig(HttpFormConfig);
|
||||||
default:
|
default:
|
||||||
return fillConfig(configs[type] || [], datasourceTypeList);
|
return fillConfig(configs[type] || []);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ export const guid = (digit = 8): string =>
|
|||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
|
|
||||||
export const getValueByKeyPath: any = (keys: string, value: Record<string | number, any>) => {
|
export const getValueByKeyPath: any = (keys: string, value: Record<string | number, any> = {}) => {
|
||||||
const path = keys.split('.');
|
const path = keys.split('.');
|
||||||
const pathLength = path.length;
|
const pathLength = path.length;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user