[Core] [Dashboard] Optimize the way to obtain the dashboard

This commit is contained in:
qianmoQ 2024-04-14 22:24:30 +08:00
parent c73fffe9d1
commit 3864ad7f21
7 changed files with 14 additions and 9 deletions

View File

@ -12,5 +12,6 @@ export default {
deleteTip2: 'Warning: This cannot be undone. ',
deleteTip3: 'To confirm, type [ $NAME ] in the box below',
publishSuccess: 'Dashboard [ $VALUE ] published successfully',
notFound: 'Dashboard [ $VALUE ] not found',
}
}

View File

@ -12,5 +12,6 @@ export default {
deleteTip2: '警告:此操作无法撤消。 ',
deleteTip3: '要确认,请在下面的框中键入 [ $NAME ]',
publishSuccess: '仪表板 [ $VALUE ] 发布成功',
notFound: '仪表板 [ $VALUE ] 不存在',
}
}

View File

@ -12,6 +12,7 @@ export interface DashboardModel
updateTime?: string
user?: UserModel
reports?: ReportModel[]
code?: string
}
export class DashboardRequest

View File

@ -129,7 +129,7 @@ const createAdminRouter = (router: any) => {
component: () => import('@/views/pages/admin/dashboard/DashboardHome.vue')
},
{
path: 'dashboard/info/:id/preview',
path: 'dashboard/preview/:code',
meta: {
title: 'common.dashboard',
isRoot: false
@ -137,7 +137,7 @@ const createAdminRouter = (router: any) => {
component: () => import('@/views/pages/admin/dashboard/DashboardPreview.vue')
},
{
path: 'dashboard/info/:id?',
path: 'dashboard/info/:code?',
meta: {
title: 'common.dashboard',
isRoot: false

View File

@ -13,7 +13,7 @@
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-6">
<Card title-class="p-2 pl-4 pr-4" v-for="item in data">
<template #title>
<RouterLink :to="`/admin/dashboard/info/${item.id}/preview`" target="_blank">{{ item.name }}</RouterLink>
<RouterLink :to="`/admin/dashboard/preview/${item.code}`" target="_blank">{{ item.name }}</RouterLink>
</template>
<template #extra>
<DropdownMenu class="justify-items-end">
@ -22,7 +22,7 @@
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuItem class="cursor-pointer">
<RouterLink :to="`/admin/dashboard/info/${item.id}`" target="_blank" class="flex items-center">
<RouterLink :to="`/admin/dashboard/info/${item.code}`" target="_blank" class="flex items-center">
<Pencil :size="15" class="mr-1"/>
{{ $t('dashboard.common.modify') }}
</RouterLink>

View File

@ -15,7 +15,6 @@ import { ToastUtils } from '@/utils/toast'
import { useRouter } from 'vue-router'
import { DashboardModel } from '@/model/dashboard'
import DashboardEditor from '@/views/pages/admin/dashboard/components/DashboardEditor.vue'
import { toNumber } from 'lodash'
export default defineComponent({
name: 'DashboardInfo',
@ -37,10 +36,10 @@ export default defineComponent({
{
const router = useRouter()
const params = router.currentRoute.value.params
const id = params['id']
if (id) {
const code = params['code'] as string
if (code) {
this.loading = true
DashboardService.getById(toNumber(id))
DashboardService.getByCode(code)
.then(response => {
if (response.status) {
this.dataInfo = response.data

View File

@ -2,6 +2,7 @@
<div class="w-full">
<Loader2 v-if="loading" class="w-full justify-center animate-spin mt-10"/>
<DashboardView v-else-if="data" :layouts="JSON.parse(data.configure as string)"/>
<Alert v-else type="error" :title="$t('dashboard.tip.notFound').replace('$VALUE', $router.currentRoute?.value?.params['code'])"/>
</div>
</template>
@ -12,10 +13,12 @@ import DashboardService from '@/services/dashboard'
import { useRouter } from 'vue-router'
import DashboardView from '@/views/pages/admin/dashboard/components/DashboardView.vue'
import { DashboardModel } from '@/model/dashboard'
import Alert from '@/views/ui/alert'
export default defineComponent({
name: 'DashboardPreview',
components: {
Alert,
DashboardView,
Loader2
},
@ -36,7 +39,7 @@ export default defineComponent({
this.loading = true
const router = useRouter()
const params = router.currentRoute.value.params
DashboardService.getById(params['id'] as unknown as number)
DashboardService.getByCode(params['code'] as string)
.then(response => {
if (response.status) {
this.data = response.data