[Core] [Source] [Metadata] Refactor metadata er diagram

This commit is contained in:
qianmoQ 2024-04-18 16:52:46 +08:00
parent 419e198c9a
commit bc9c1318a5
5 changed files with 34 additions and 30 deletions

View File

@ -21,6 +21,7 @@ export interface TableModel
autoIncrement?: string autoIncrement?: string
database?: DatabaseModel database?: DatabaseModel
columns?: Array<ColumnModel> columns?: Array<ColumnModel>
code?: string
} }
export class TableRequest export class TableRequest

View File

@ -266,6 +266,15 @@ const createAdminRouter = (router: any) => {
type: 'statement' type: 'statement'
}, },
component: () => import('@/views/pages/admin/source/SourceTableStatement.vue') component: () => import('@/views/pages/admin/source/SourceTableStatement.vue')
},
{
path: 'd/:database/t/erDiagram/:table',
meta: {
title: 'common.source',
isRoot: false,
type: 'erDiagram'
},
component: () => import('@/views/pages/admin/source/SourceTableErDiagram.vue')
} }
] ]
}, },

View File

@ -27,9 +27,11 @@
<span>{{ $t('source.common.statement') }}</span> <span>{{ $t('source.common.statement') }}</span>
</div> </div>
</TabsTrigger> </TabsTrigger>
<TabsTrigger value="erDiagram" class="cursor-pointer"> <TabsTrigger value="erDiagram" class="cursor-pointer" @click="handlerChange">
<Wind :size="18" class="mr-2"/> <div class="flex space-x-2">
{{ $t('source.common.erDiagram') }} <Wind :size="18"/>
<span>{{ $t('source.common.erDiagram') }}</span>
</div>
</TabsTrigger> </TabsTrigger>
</TabsList> </TabsList>
</template> </template>

View File

@ -8,26 +8,14 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, watch } from 'vue' import { defineComponent, watch } from 'vue'
import ColumnService from '@/services/column' import ColumnService from '@/services/column.ts'
import { StructureModel } from '@/model/structure.ts'
import { toNumber } from 'lodash'
import CircularLoading from '@/views/components/loading/CircularLoading.vue' import CircularLoading from '@/views/components/loading/CircularLoading.vue'
import ErDiagram from '@/views/components/diagram/ErDiagram.vue' import ErDiagram from '@/views/components/diagram/ErDiagram.vue'
import { ErDiagramOptions } from '@/views/components/diagram/ErDiagramOptions' import { ErDiagramOptions } from '@/views/components/diagram/ErDiagramOptions.ts'
export default defineComponent({ export default defineComponent({
name: 'TableErDiagram', name: 'SourceTableErDiagram',
components: { ErDiagram, CircularLoading }, components: { ErDiagram, CircularLoading },
props: {
info: {
type: Object as () => StructureModel | null
}
},
created()
{
this.handlerInitialize()
this.watchId()
},
data() data()
{ {
return { return {
@ -35,29 +23,34 @@ export default defineComponent({
options: null as unknown as ErDiagramOptions options: null as unknown as ErDiagramOptions
} }
}, },
created()
{
this.handlerInitialize()
this.watchChange()
},
methods: { methods: {
handlerInitialize() handlerInitialize()
{ {
this.loading = true const code = this.$route?.params.table as string
if (this.info) { if (code) {
ColumnService.getAllByTable(toNumber(this.info.applyId)) this.loading = true
ColumnService.getAllByTable(code)
.then(response => { .then(response => {
if (response.status) { if (response.status && response.data?.length > 0) {
const table = response.data[0]
this.options = new ErDiagramOptions() this.options = new ErDiagramOptions()
this.options.table = { id: toNumber(this.info?.applyId), name: this.info?.title as string } this.options.table = { id: table.id, name: table.name }
this.options.columns = response.data this.options.columns = response.data
} }
}) })
.finally(() => this.loading = false) .finally(() => this.loading = false)
} }
}, },
watchId() watchChange()
{ {
watch( watch(
() => this.info, () => this.$route?.params.table,
() => { () => this.handlerInitialize()
this.handlerInitialize()
}
) )
} }
} }

View File

@ -127,7 +127,6 @@ import { Label } from '@/components/ui/label'
import { Input } from '@/components/ui/input' import { Input } from '@/components/ui/input'
import { ToastUtils } from '@/utils/toast' import { ToastUtils } from '@/utils/toast'
import { Textarea } from '@/components/ui/textarea' import { Textarea } from '@/components/ui/textarea'
import { toNumber } from 'lodash'
export default defineComponent({ export default defineComponent({
name: 'SourceTableInfo', name: 'SourceTableInfo',
@ -182,7 +181,7 @@ export default defineComponent({
type: SqlType.ALTER, type: SqlType.ALTER,
value: this.dataInfo.autoIncrement value: this.dataInfo.autoIncrement
} }
TableService.getData(toNumber(this.dataInfo.id), configure) TableService.getData(this.dataInfo.code as string, configure)
.then(response => { .then(response => {
if (response.status) { if (response.status) {
ToastUtils.success(this.$t('source.tip.resetAutoIncrementSuccess').replace('$VALUE', this.dataInfo?.autoIncrement as string)) ToastUtils.success(this.$t('source.tip.resetAutoIncrementSuccess').replace('$VALUE', this.dataInfo?.autoIncrement as string))