feat: infra view

pull/3/head
xingyuv 2023-03-23 14:18:16 +08:00
parent 2f466919bd
commit 85b7eeedb5
5 changed files with 199 additions and 4 deletions

View File

@ -0,0 +1,54 @@
<template>
<BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit">
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts" setup name="DataSourceConfigModal">
import { ref, computed, unref } from 'vue'
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { formSchema } from './dataSourceConfig.data'
import { createPost, getPost, updatePost } from '@/api/system/post'
const emit = defineEmits(['success', 'register'])
const isUpdate = ref(true)
const rowId = ref()
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 100,
baseColProps: { span: 24 },
schemas: formSchema,
showActionButtonGroup: false,
actionColOptions: { span: 23 }
})
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
resetFields()
setModalProps({ confirmLoading: false })
isUpdate.value = !!data?.isUpdate
if (unref(isUpdate)) {
const res = await getPost(data.record.id)
rowId.value = res.id
setFieldsValue({ ...res })
}
})
const getTitle = computed(() => (!unref(isUpdate) ? '新增数据源' : '编辑数据源'))
async function handleSubmit() {
try {
const values = await validate()
setModalProps({ confirmLoading: true })
if (unref(isUpdate)) {
await updatePost(values)
} else {
await createPost(values)
}
closeModal()
emit('success')
} finally {
setModalProps({ confirmLoading: false })
}
}
</script>

View File

@ -0,0 +1,65 @@
import { BasicColumn, FormSchema, useRender } from '@/components/Table'
export const columns: BasicColumn[] = [
{
title: '主键编号',
dataIndex: 'id',
width: 100
},
{
title: '数据源名称',
dataIndex: 'name',
width: 180
},
{
title: '数据源连接',
dataIndex: 'url',
width: 100
},
{
title: '用户名',
dataIndex: 'username',
width: 120
},
{
title: '创建时间',
dataIndex: 'createTime',
width: 180,
customRender: ({ text }) => {
return useRender.renderDate(text)
}
}
]
export const formSchema: FormSchema[] = [
{
label: '编号',
field: 'id',
show: false,
component: 'Input'
},
{
label: '数据源名称',
field: 'name',
required: true,
component: 'Input'
},
{
label: '数据源连接',
field: 'url',
required: true,
component: 'Input'
},
{
label: '用户名',
field: 'username',
required: true,
component: 'Input'
},
{
label: '密码',
field: 'password',
required: true,
component: 'Input'
}
]

View File

@ -1,3 +1,79 @@
<template>
<div>开发中</div>
<div>
<BasicTable @register="registerTable">
<template #toolbar>
<a-button type="primary" :preIcon="IconEnum.ADD" @click="handleCreate"> {{ t('action.create') }} </a-button>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[
{ icon: IconEnum.EDIT, label: t('action.edit'), ifShow: record.id !== 0, onClick: handleEdit.bind(null, record) },
{
icon: IconEnum.DELETE,
color: 'error',
label: t('action.delete'),
ifShow: record.id !== 0,
popConfirm: {
title: t('common.delMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record)
}
}
]"
/>
</template>
</template>
</BasicTable>
<DataSourceConfigModal @register="registerModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="DataSourceConfig">
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import DataSourceConfigModal from './DataSourceConfigModal.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { deleteDataSourceConfig, getDataSourceConfigList } from '@/api/infra/dataSourceConfig'
import { columns } from './dataSourceConfig.data'
const { t } = useI18n()
const { createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { reload }] = useTable({
title: '数据源列表',
api: getDataSourceConfigList,
columns,
pagination: false,
useSearchForm: false,
showTableSetting: true,
showIndexColumn: false,
actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right'
}
})
function handleCreate() {
openModal(true, {
isUpdate: false
})
}
function handleEdit(record: Recordable) {
openModal(true, {
record,
isUpdate: true
})
}
async function handleDelete(record: Recordable) {
await deleteDataSourceConfig(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script>

View File

@ -26,14 +26,14 @@
</template>
</template>
</BasicTable>
<PostModal @register="registerModal" @success="reload()" />
<FileConfigModal @register="registerModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="FileConfig">
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import PostModal from './FileConfigModal.vue'
import FileConfigModal from './FileConfigModal.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { deleteFileConfig, getFileConfigPage, testFileConfig, updateFileConfigMaster } from '@/api/infra/fileConfig'

View File

@ -3,7 +3,7 @@
<BasicForm @register="registerForm" />
</BasicModal>
</template>
<script lang="ts" setup name="PostModal">
<script lang="ts" setup name="AreaModal">
import { BasicModal, useModalInner } from '@/components/Modal'
import { BasicForm, useForm } from '@/components/Form'
import { formSchema } from './area.data'