411 lines
15 KiB
JavaScript
411 lines
15 KiB
JavaScript
import './dialog-resource.css'
|
||
import {
|
||
apiGet,
|
||
apiPost,
|
||
formInputClearable,
|
||
horizontalFormOptions,
|
||
inputFileFormItemCommonOptions,
|
||
size1GB,
|
||
size500MB
|
||
} from "../constants.js";
|
||
|
||
function inputFileFormItemUpdateFieldOptions(target) {
|
||
let value = {}
|
||
value[target] = '${event.data.value}'
|
||
return {
|
||
onEvent: {
|
||
success: {
|
||
actions: [
|
||
{
|
||
actionType: 'setValue',
|
||
componentId: 'resource_data_form',
|
||
args: {
|
||
value: value
|
||
}
|
||
}
|
||
]
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function detailForm() {
|
||
return {
|
||
id: 'resource_data_form',
|
||
type: 'form',
|
||
...horizontalFormOptions(),
|
||
horizontal: {
|
||
left: 2,
|
||
},
|
||
body: [
|
||
{
|
||
type: 'hidden',
|
||
name: 'id',
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
name: 'name',
|
||
label: '资源名称',
|
||
required: true,
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'textarea',
|
||
name: 'description',
|
||
label: '资源描述',
|
||
...formInputClearable,
|
||
showCounter: true,
|
||
trimContents: true,
|
||
minRows: 2,
|
||
maxRows: 2,
|
||
},
|
||
{
|
||
type: 'fieldSet',
|
||
title: '资源类型定义',
|
||
body: [
|
||
{
|
||
name: 'resourceType',
|
||
type: 'select',
|
||
label: '资源类型',
|
||
selectFirst: true,
|
||
required: true,
|
||
options: [
|
||
{label: 'API', value: 'API'},
|
||
{label: '文件', value: 'FILE'},
|
||
{label: '数据库', value: 'DATABASE'},
|
||
{label: 'HDFS', value: 'HDFS'},
|
||
{label: 'FTP', value: 'FTP'},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${resourceType === 'API'}",
|
||
type: 'fieldSet',
|
||
body: [
|
||
{
|
||
type: 'input-text',
|
||
label: 'API地址',
|
||
name: 'apiUrl',
|
||
required: true,
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: '用户名',
|
||
name: 'apiUsername',
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-password',
|
||
label: '密码',
|
||
name: 'apiPassword',
|
||
...formInputClearable,
|
||
},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${resourceType === 'FILE'}",
|
||
type: 'fieldSet',
|
||
body: [
|
||
{
|
||
visibleOn: "${!detail}",
|
||
type: 'input-file',
|
||
label: '数据文件',
|
||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||
name: 'filename',
|
||
multiple: false,
|
||
required: true,
|
||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||
...inputFileFormItemUpdateFieldOptions('fileId'),
|
||
},
|
||
{
|
||
visibleOn: "${detail}",
|
||
type: 'input-text',
|
||
label: '文件名称',
|
||
name: 'filename',
|
||
},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${resourceType === 'DATABASE'}",
|
||
type: 'fieldSet',
|
||
body: [
|
||
{
|
||
type: 'select',
|
||
label: '数据库类型',
|
||
name: 'databaseType',
|
||
required: true,
|
||
options: [
|
||
{label: 'MySQL', value: 'MYSQL'},
|
||
{label: 'Oracle', value: 'ORACLE'},
|
||
{label: 'PostgreSQL', value: 'POSTGRESQL'},
|
||
]
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: 'JDBC',
|
||
name: 'databaseJdbc',
|
||
required: true,
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: '用户名',
|
||
name: 'databaseUsername',
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-password',
|
||
label: '密码',
|
||
name: 'databasePassword',
|
||
...formInputClearable,
|
||
},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${resourceType === 'HDFS'}",
|
||
type: 'fieldSet',
|
||
body: [
|
||
{
|
||
visibleOn: "${!static}",
|
||
type: 'input-file',
|
||
label: 'core-site.xml',
|
||
name: 'coreSiteFilename',
|
||
required: true,
|
||
...inputFileFormItemCommonOptions('.xml'),
|
||
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
|
||
},
|
||
{
|
||
visibleOn: "${detail}",
|
||
type: 'input-text',
|
||
label: '文件名称',
|
||
name: 'coreSiteFilename',
|
||
},
|
||
{
|
||
visibleOn: "${!static}",
|
||
type: 'input-file',
|
||
label: 'hdfs-site.xml',
|
||
name: 'hdfsSiteFilename',
|
||
required: true,
|
||
...inputFileFormItemCommonOptions('.xml'),
|
||
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
|
||
},
|
||
{
|
||
visibleOn: "${detail}",
|
||
type: 'input-text',
|
||
label: '文件名称',
|
||
name: 'hdfsSiteFilename',
|
||
},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${resourceType === 'FTP'}",
|
||
type: 'fieldSet',
|
||
body: [
|
||
{
|
||
type: 'input-text',
|
||
label: 'FTP地址',
|
||
name: 'ftpUrl',
|
||
required: true,
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: 'FTP账号',
|
||
name: 'ftpUsername',
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-password',
|
||
label: 'FTP密码',
|
||
name: 'ftpPassword',
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: '相对路径',
|
||
name: 'ftpPath',
|
||
description: '若为空,则使用用户根目录',
|
||
...formInputClearable,
|
||
},
|
||
{
|
||
type: 'input-text',
|
||
label: '文件筛选',
|
||
name: 'ftpRegexFilter',
|
||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||
...formInputClearable,
|
||
},
|
||
]
|
||
},
|
||
]
|
||
},
|
||
{
|
||
type: 'fieldSet',
|
||
title: '资源格式定义',
|
||
className: 'mt-5',
|
||
body: [
|
||
{
|
||
name: 'formatType',
|
||
type: 'select',
|
||
label: '资源格式',
|
||
selectFirst: true,
|
||
required: true,
|
||
options: [
|
||
{label: '无', value: 'NONE'},
|
||
{label: 'Line', value: 'LINE'},
|
||
{label: 'JSON', value: 'JSON'},
|
||
{label: 'JSON Line', value: 'JSON_LINE'},
|
||
{label: 'CSV', value: 'CSV'},
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'JSON' && !detail}",
|
||
type: 'json-schema-editor',
|
||
name: 'jsonSchema',
|
||
label: 'JSON格式',
|
||
description: '(使用JSON Schema格式)',
|
||
required: true,
|
||
enableAdvancedSetting: true,
|
||
mini: true,
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'JSON' && detail}",
|
||
type: 'editor',
|
||
name: 'jsonSchemaText',
|
||
label: 'JSON格式',
|
||
language: 'json',
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'JSON_LINE' && !detail}",
|
||
type: 'json-schema-editor',
|
||
name: 'jsonLineSchema',
|
||
label: 'JSON格式',
|
||
description: 'JSON Line类型请定义单行JSON数据格式(使用JSON Schema格式)',
|
||
required: true,
|
||
enableAdvancedSetting: true,
|
||
mini: true,
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'JSON_LINE' && detail}",
|
||
type: 'editor',
|
||
name: 'jsonLineSchemaText',
|
||
label: 'JSON格式',
|
||
language: 'json',
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'CSV' && !detail}",
|
||
type: 'json-schema-editor',
|
||
name: 'csvSchema',
|
||
label: 'CSV格式',
|
||
description: '请定义单行数据中各个字段的格式(使用JSON Schema格式)',
|
||
required: true,
|
||
enableAdvancedSetting: true,
|
||
mini: true,
|
||
disabledTypes: [
|
||
'object',
|
||
'array',
|
||
'null',
|
||
]
|
||
},
|
||
{
|
||
visibleOn: "${formatType === 'CSV' && detail}",
|
||
type: 'editor',
|
||
name: 'csvSchemaText',
|
||
label: 'JSON格式',
|
||
language: 'json',
|
||
},
|
||
{
|
||
visibleOn: "${detail}",
|
||
type: 'input-text',
|
||
label: '资源示例',
|
||
name: 'exampleFilename',
|
||
},
|
||
{
|
||
visibleOn: "${!detail}",
|
||
type: 'input-file',
|
||
label: '资源示例',
|
||
name: 'exampleFilename',
|
||
description: '可以上传用于作为格式示范的样例数据',
|
||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
|
||
},
|
||
]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
|
||
export function resourceAddDialog() {
|
||
return {
|
||
actionType: 'dialog',
|
||
dialog: {
|
||
title: '新增数据资源',
|
||
size: 'md',
|
||
actions: [
|
||
{
|
||
type: 'reset',
|
||
label: '重置',
|
||
},
|
||
{
|
||
type: 'submit',
|
||
label: '确定',
|
||
level: 'primary',
|
||
}
|
||
],
|
||
body: {
|
||
...detailForm(),
|
||
api: apiPost('${base}/data_resource/save'),
|
||
data: {
|
||
add: true,
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
export function resourceDetailDialog() {
|
||
return {
|
||
actionType: 'dialog',
|
||
dialog: {
|
||
title: '账号详情',
|
||
actions: [],
|
||
size: 'md',
|
||
body: {
|
||
...detailForm(),
|
||
static: true,
|
||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||
data: {
|
||
detail: true,
|
||
}
|
||
},
|
||
}
|
||
}
|
||
}
|
||
|
||
export function resourceEditeDialog() {
|
||
return {
|
||
actionType: 'dialog',
|
||
dialog: {
|
||
title: '账号详情',
|
||
size: 'md',
|
||
actions: [
|
||
{
|
||
type: 'reset',
|
||
label: '重置',
|
||
},
|
||
{
|
||
type: 'submit',
|
||
label: '确定',
|
||
level: 'primary',
|
||
}
|
||
],
|
||
body: {
|
||
...detailForm(),
|
||
api: apiPost('${base}/data_resource/save'),
|
||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||
data: {
|
||
edit: true,
|
||
}
|
||
},
|
||
}
|
||
}
|
||
} |