style(schema,editor,data-source): 代码块类型定义中content去掉string类型

This commit is contained in:
roymondchen 2026-04-09 15:28:03 +08:00
parent b3f4e42716
commit b2888962df
6 changed files with 21 additions and 12 deletions

View File

@ -16,6 +16,7 @@ export default defineConfig([
'*/**/public/**/*',
'*/**/types/**/*',
'*/**/*.config.ts',
'./tepm/**/*',
'vite-env.d.ts',
]),
...eslintConfig(path.join(path.dirname(fileURLToPath(import.meta.url)), 'tsconfig.json')),

View File

@ -79,9 +79,9 @@ export default class HttpDataSource extends DataSource<HttpDataSourceSchema> {
/** 请求函数 */
#fetch?: RequestFunction;
/** 请求前需要执行的函数队列 */
#beforeRequest: ((...args: any[]) => any)[] = [];
#beforeRequest: (Function | ((...args: any[]) => any))[] = [];
/** 请求后需要执行的函数队列 */
#afterRequest: ((...args: any[]) => any)[] = [];
#afterRequest: (Function | ((...args: any[]) => any))[] = [];
#type = 'http';

View File

@ -88,7 +88,7 @@ const width = defineModel<number>('width', { default: 670 });
const boxVisible = defineModel<boolean>('visible', { default: false });
const props = defineProps<{
content: CodeBlockContent;
content: Omit<CodeBlockContent, 'content'> & { content: string };
disabled?: boolean;
isDataSource?: boolean;
dataSourceType?: string;

View File

@ -42,7 +42,7 @@ const props = withDefaults(defineProps<FieldProps<DataSourceMethodsConfig>>(), {
const emit = defineEmits(['change']);
const codeConfig = ref<CodeBlockContent>();
const codeConfig = ref<Omit<CodeBlockContent, 'content'> & { content: string }>();
const codeBlockEditorRef = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
let editIndex = -1;
@ -72,10 +72,14 @@ const methodColumns: ColumnConfig[] = [
{
text: '编辑',
handler: (method: CodeBlockContent, index: number) => {
let codeContent = method.content || '({ params, dataSource, app }) => {\n // place your code here\n}';
let codeContent: string = '({ params, dataSource, app }) => {\n // place your code here\n}';
if (typeof codeContent !== 'string') {
codeContent = codeContent.toString();
if (method.content) {
if (typeof method.content !== 'string') {
codeContent = method.content.toString();
} else {
codeContent = method.content;
}
}
codeConfig.value = {

View File

@ -8,7 +8,7 @@ import CodeBlockEditor from '@editor/components/CodeBlockEditor.vue';
import type { Services } from '@editor/type';
export const useCodeBlockEdit = (codeBlockService: Services['codeBlockService']) => {
const codeConfig = ref<CodeBlockContent>();
const codeConfig = ref<Omit<CodeBlockContent, 'content'> & { content: string }>();
const codeId = ref<string>();
const codeBlockEditorRef = useTemplateRef<InstanceType<typeof CodeBlockEditor>>('codeBlockEditor');
@ -36,10 +36,14 @@ export const useCodeBlockEdit = (codeBlockService: Services['codeBlockService'])
return;
}
let codeContent = codeBlock.content;
let codeContent = '';
if (typeof codeContent !== 'string') {
codeContent = codeContent.toString();
if (codeBlock.content) {
if (typeof codeBlock.content !== 'string') {
codeContent = codeBlock.content.toString();
} else {
codeContent = codeBlock.content;
}
}
codeConfig.value = {

View File

@ -186,7 +186,7 @@ export interface CodeBlockContent {
/** 代码块名称 */
name: string;
/** 代码块内容 */
content: ((...args: any[]) => any) | string;
content: ((...args: any[]) => any) | Function;
/** 参数定义 */
params: CodeParam[] | [];
/** 注释 */