提交 7573a60c 作者: 方治民

feat: 实现切换数据库类型自动填充表单项默认值

上级 e331c308
import { BasicColumn, FormProps } from '@/components/Table' import { BasicColumn, FormProps } from '@/components/Table'
interface Option { export interface Option {
label: string label: string
value: string value: string
property?: { property?: {
driver?: string driver?: string
url?: string url?: string
username?: string
} }
disabled?: boolean disabled?: boolean
} }
...@@ -20,6 +21,7 @@ export const options: Option[] = [ ...@@ -20,6 +21,7 @@ export const options: Option[] = [
property: { property: {
driver: 'org.postgresql.Driver', driver: 'org.postgresql.Driver',
url: 'jdbc:postgresql://127.0.0.1:5432/basic-boot', url: 'jdbc:postgresql://127.0.0.1:5432/basic-boot',
username: 'postgres',
}, },
}, },
{ {
...@@ -28,6 +30,7 @@ export const options: Option[] = [ ...@@ -28,6 +30,7 @@ export const options: Option[] = [
property: { property: {
driver: 'org.h2.Driver', driver: 'org.h2.Driver',
url: 'jdbc:h2:file:~/h2_basic;DB_CLOSE_ON_EXIT=FALSE', url: 'jdbc:h2:file:~/h2_basic;DB_CLOSE_ON_EXIT=FALSE',
username: 'sa',
}, },
}, },
{ {
...@@ -36,16 +39,13 @@ export const options: Option[] = [ ...@@ -36,16 +39,13 @@ export const options: Option[] = [
property: { property: {
driver: 'com.mysql.cj.jdbc.Driver', driver: 'com.mysql.cj.jdbc.Driver',
url: 'jdbc:mysql://127.0.0.1:3306/basic-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai', url: 'jdbc:mysql://127.0.0.1:3306/basic-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai',
username: 'root',
}, },
disabled: true, disabled: true,
}, },
{ {
label: '其他数据库', label: '其他数据库',
value: 'custom', value: 'custom',
property: {
driver: '',
url: '',
},
}, },
] ]
...@@ -104,6 +104,7 @@ export function getDataSource() { ...@@ -104,6 +104,7 @@ export function getDataSource() {
export function getFormConfig(): Partial<FormProps> { export function getFormConfig(): Partial<FormProps> {
return { return {
layout: 'inline', layout: 'inline',
name: 'query',
colon: true, colon: true,
compact: true, compact: true,
schemas: [ schemas: [
......
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
import { Icon } from '/@/components/Icon' import { Icon } from '/@/components/Icon'
import { BasicForm, useForm } from '/@/components/Form' import { BasicForm, useForm } from '/@/components/Form'
import { BasicModal, useModalInner } from '/@/components/Modal' import { BasicModal, useModalInner } from '/@/components/Modal'
import { options } from './data' import { options, Option } from './data'
const [registerModal] = useModalInner((data) => { const [registerModal] = useModalInner((data) => {
console.log(data) console.log(data)
}) })
const [registerEditForm] = useForm({ const [registerEditForm, { setFieldsValue }] = useForm({
colon: true, colon: true,
labelWidth: 120, labelWidth: 120,
showActionButtonGroup: false, showActionButtonGroup: false,
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
component: 'Select', component: 'Select',
componentProps: { componentProps: {
options, options,
onChange: (_: string, item: Option) => {
setFieldsValue({
driver: item?.property?.driver ?? '',
url: item?.property?.url ?? '',
username: item?.property?.username ?? '',
})
},
}, },
colProps: { span: 24 }, colProps: { span: 24 },
}, },
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import { Icon } from '/@/components/Icon' import { Icon } from '/@/components/Icon'
import { useModal } from '/@/components/Modal' import { useModal } from '/@/components/Modal'
import { ActionItem, BasicColumn, BasicTable, EditRecordRow, useTable, TableAction } from '/@/components/Table' import { ActionItem, BasicColumn, BasicTable, EditRecordRow, useTable, TableAction } from '/@/components/Table'
import Modal from './Modal.vue' import EditModal from './edit.vue'
import { getColumns, getDataSource, getFormConfig } from './data' import { getColumns, getDataSource, getFormConfig } from './data'
const [registerTable] = useTable({ const [registerTable] = useTable({
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
] ]
} }
const [registerModal, { openModal, setModalProps }] = useModal() const [registerEditModal, { openModal, setModalProps }] = useModal()
// 新增/编辑打开窗口 // 新增/编辑打开窗口
const editHandler = (type: '新增' | '编辑', data?: Recordable) => { const editHandler = (type: '新增' | '编辑', data?: Recordable) => {
...@@ -96,7 +96,7 @@ ...@@ -96,7 +96,7 @@
</BasicTable> </BasicTable>
<!-- 新增/编辑弹窗 --> <!-- 新增/编辑弹窗 -->
<Modal @register="registerModal" /> <EditModal @register="registerEditModal" />
</template> </template>
<style lang="less" scoped> <style lang="less" scoped>
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论