|
|
|
@ -15,54 +15,149 @@
|
|
|
|
|
* limitations under the License. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
import { ref, onMounted } from 'vue' |
|
|
|
|
import { ref, onMounted, computed, h } from 'vue' |
|
|
|
|
import { useI18n } from 'vue-i18n' |
|
|
|
|
import { listAlertGroupById } from '@/service/modules/alert-group' |
|
|
|
|
import styles from '../index.module.scss' |
|
|
|
|
import type { IJsonItem } from '../types' |
|
|
|
|
|
|
|
|
|
export function useSqlType(unusedModel: { [field: string]: any }): IJsonItem { |
|
|
|
|
export function useSqlType(model: { [field: string]: any }): IJsonItem[] { |
|
|
|
|
const { t } = useI18n() |
|
|
|
|
|
|
|
|
|
const options = ref([] as { label: string; value: string }[]) |
|
|
|
|
const loading = ref(false) |
|
|
|
|
|
|
|
|
|
const sqlTypes = [ |
|
|
|
|
const querySpan = computed(() => (model.sqlType === '0' ? 6 : 0)) |
|
|
|
|
const emailSpan = computed(() => (model.sendEmail ? 24 : 0)) |
|
|
|
|
const groups = ref([]) |
|
|
|
|
const groupsLoading = ref(false) |
|
|
|
|
const SQL_TYPES = [ |
|
|
|
|
{ |
|
|
|
|
id: '0', |
|
|
|
|
code: t('project.node.sql_type_query') |
|
|
|
|
value: '0', |
|
|
|
|
label: t('project.node.sql_type_query') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
id: '1', |
|
|
|
|
code: t('project.node.sql_type_non_query') |
|
|
|
|
value: '1', |
|
|
|
|
label: t('project.node.sql_type_non_query') |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const getSqlTypes = async () => { |
|
|
|
|
if (loading.value) return |
|
|
|
|
loading.value = true |
|
|
|
|
options.value = sqlTypes.map((item) => ({ |
|
|
|
|
label: item.code, |
|
|
|
|
const getGroups = async () => { |
|
|
|
|
if (groupsLoading.value) return |
|
|
|
|
groupsLoading.value = true |
|
|
|
|
const res = await listAlertGroupById() |
|
|
|
|
groups.value = res.map((item: { id: number; groupName: string }) => ({ |
|
|
|
|
label: item.groupName, |
|
|
|
|
value: item.id |
|
|
|
|
})) |
|
|
|
|
loading.value = false |
|
|
|
|
groupsLoading.value = false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onMounted(() => { |
|
|
|
|
getSqlTypes() |
|
|
|
|
getGroups() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
return [ |
|
|
|
|
{ |
|
|
|
|
type: 'select', |
|
|
|
|
field: 'sqlType', |
|
|
|
|
span: 12, |
|
|
|
|
span: 6, |
|
|
|
|
name: t('project.node.sql_type'), |
|
|
|
|
options: SQL_TYPES, |
|
|
|
|
validate: { |
|
|
|
|
trigger: ['input', 'blur'], |
|
|
|
|
required: true |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: 'switch', |
|
|
|
|
field: 'sendEmail', |
|
|
|
|
span: querySpan, |
|
|
|
|
name: t('project.node.send_email') |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: 'select', |
|
|
|
|
field: 'displayRows', |
|
|
|
|
span: querySpan, |
|
|
|
|
name: t('project.node.log_display'), |
|
|
|
|
options: DISPLAY_ROWS, |
|
|
|
|
props: { |
|
|
|
|
loading: loading |
|
|
|
|
filterable: true, |
|
|
|
|
tag: true |
|
|
|
|
}, |
|
|
|
|
options: options, |
|
|
|
|
validate: { |
|
|
|
|
trigger: ['input', 'blur'], |
|
|
|
|
required: true |
|
|
|
|
validator(unuse, value) { |
|
|
|
|
if (!/^\+?[1-9][0-9]*$/.test(value)) { |
|
|
|
|
return new Error(t('project.node.integer_tips')) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: 'custom', |
|
|
|
|
field: 'displayRowsTips', |
|
|
|
|
span: querySpan, |
|
|
|
|
widget: h( |
|
|
|
|
'div', |
|
|
|
|
{ class: styles['display-rows-tips'] }, |
|
|
|
|
t('project.node.rows_of_result') |
|
|
|
|
) |
|
|
|
|
}, |
|
|
|
|
value: '0' |
|
|
|
|
{ |
|
|
|
|
type: 'input', |
|
|
|
|
field: 'title', |
|
|
|
|
name: t('project.node.title'), |
|
|
|
|
props: { |
|
|
|
|
placeholder: t('project.node.title_tips') |
|
|
|
|
}, |
|
|
|
|
span: emailSpan, |
|
|
|
|
validate: { |
|
|
|
|
trigger: ['input', 'blur'], |
|
|
|
|
required: true, |
|
|
|
|
validator(unuse, value) { |
|
|
|
|
if (model.sendEmail && !value) |
|
|
|
|
return new Error(t('project.node.title_tips')) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
type: 'select', |
|
|
|
|
field: 'groupId', |
|
|
|
|
name: t('project.node.alarm_group'), |
|
|
|
|
options: groups, |
|
|
|
|
span: emailSpan, |
|
|
|
|
props: { |
|
|
|
|
loading: groupsLoading, |
|
|
|
|
placeholder: t('project.node.alarm_group_tips') |
|
|
|
|
}, |
|
|
|
|
validate: { |
|
|
|
|
trigger: ['input', 'blur'], |
|
|
|
|
required: true, |
|
|
|
|
validator(unuse, value) { |
|
|
|
|
if (model.sendEmail && !value) |
|
|
|
|
return new Error(t('project.node.alarm_group_tips')) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const DISPLAY_ROWS = [ |
|
|
|
|
{ |
|
|
|
|
label: '1', |
|
|
|
|
value: 1 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
label: '10', |
|
|
|
|
value: 10 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
label: '25', |
|
|
|
|
value: 25 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
label: '50', |
|
|
|
|
value: 50 |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
label: '100', |
|
|
|
|
value: 100 |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|