mirror of https://github.com/halo-dev/halo
feat: refine i18n for dashboard widgets config form (#7511)
#### What type of PR is this? /area ui /kind improvement /milestone 2.21.x #### What this PR does / why we need it: Refine i18n for dashboard widgets config form. #### Which issue(s) this PR fixes: Fixes https://github.com/halo-dev/halo/issues/7508 #### Special notes for your reviewer: #### Does this PR introduce a user-facing change? ```release-note None ```pull/7516/head^2
parent
c604952914
commit
4093435b0e
|
@ -1,8 +1,8 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { FormKitSchemaDefinition } from "@formkit/core";
|
import type { FormKitSchemaDefinition } from "@formkit/core";
|
||||||
import { VButton, VModal, VSpace } from "@halo-dev/components";
|
import { VButton, VLoading, VModal, VSpace } from "@halo-dev/components";
|
||||||
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
||||||
import { computed, toRaw, useTemplateRef } from "vue";
|
import { onMounted, ref, toRaw, useTemplateRef } from "vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
widgetDefinition: DashboardWidgetDefinition;
|
widgetDefinition: DashboardWidgetDefinition;
|
||||||
|
@ -14,8 +14,24 @@ const emit = defineEmits<{
|
||||||
(e: "save", config: Record<string, unknown>): void;
|
(e: "save", config: Record<string, unknown>): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const formSchema = computed(() => {
|
const formSchema = ref<FormKitSchemaDefinition>();
|
||||||
return props.widgetDefinition.configFormKitSchema as FormKitSchemaDefinition;
|
const isLoading = ref(false);
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
const { configFormKitSchema } = props.widgetDefinition || {};
|
||||||
|
const isFunction = typeof configFormKitSchema === "function";
|
||||||
|
|
||||||
|
try {
|
||||||
|
isLoading.value = true;
|
||||||
|
const schema = isFunction
|
||||||
|
? await configFormKitSchema()
|
||||||
|
: configFormKitSchema;
|
||||||
|
formSchema.value = (schema || []) as FormKitSchemaDefinition;
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
} finally {
|
||||||
|
isLoading.value = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const initialConfig =
|
const initialConfig =
|
||||||
|
@ -35,6 +51,7 @@ function onSubmit(config: Record<string, unknown>) {
|
||||||
@close="emit('close')"
|
@close="emit('close')"
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
|
<VLoading v-if="isLoading" />
|
||||||
<FormKit
|
<FormKit
|
||||||
v-if="formSchema"
|
v-if="formSchema"
|
||||||
:id="widgetDefinition.id"
|
:id="widgetDefinition.id"
|
||||||
|
|
|
@ -65,7 +65,7 @@ function handleSaveConfig(config: Record<string, unknown>) {
|
||||||
class="absolute z-[100] hidden h-8 right-0 top-0 rounded-tr-lg bg-gray-100 overflow-hidden group-hover/grid-item:inline-flex items-center"
|
class="absolute z-[100] hidden h-8 right-0 top-0 rounded-tr-lg bg-gray-100 overflow-hidden group-hover/grid-item:inline-flex items-center"
|
||||||
>
|
>
|
||||||
<ActionButton
|
<ActionButton
|
||||||
v-if="widgetDefinition?.configFormKitSchema?.length"
|
v-if="widgetDefinition?.configFormKitSchema"
|
||||||
class="bg-black"
|
class="bg-black"
|
||||||
@click="configModalVisible = true"
|
@click="configModalVisible = true"
|
||||||
>
|
>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { i18n } from "@/locales";
|
||||||
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
import type { DashboardWidgetDefinition } from "@halo-dev/console-shared";
|
||||||
import { markRaw } from "vue";
|
import { markRaw } from "vue";
|
||||||
import CommentStatsWidget from "./presets/comments/CommentStatsWidget.vue";
|
import CommentStatsWidget from "./presets/comments/CommentStatsWidget.vue";
|
||||||
|
@ -16,10 +17,12 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:post:stats",
|
id: "core:post:stats",
|
||||||
component: markRaw(PostStatsWidget),
|
component: markRaw(PostStatsWidget),
|
||||||
group: "core.dashboard.widgets.groups.post",
|
group: "core.dashboard.widgets.groups.post",
|
||||||
configFormKitSchema: [
|
configFormKitSchema: () => [
|
||||||
{
|
{
|
||||||
$formkit: "checkbox",
|
$formkit: "checkbox",
|
||||||
label: "Enable animation",
|
label: i18n.global.t(
|
||||||
|
"core.dashboard.widgets.common_form.fields.enable_animation.label"
|
||||||
|
),
|
||||||
name: "enable_animation",
|
name: "enable_animation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -37,7 +40,6 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:post:recent-published",
|
id: "core:post:recent-published",
|
||||||
component: markRaw(RecentPublishedWidget),
|
component: markRaw(RecentPublishedWidget),
|
||||||
group: "core.dashboard.widgets.groups.post",
|
group: "core.dashboard.widgets.groups.post",
|
||||||
configFormKitSchema: [],
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
defaultSize: {
|
defaultSize: {
|
||||||
w: 6,
|
w: 6,
|
||||||
|
@ -51,10 +53,12 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:singlepage:stats",
|
id: "core:singlepage:stats",
|
||||||
component: markRaw(SinglePageStatsWidget),
|
component: markRaw(SinglePageStatsWidget),
|
||||||
group: "core.dashboard.widgets.groups.page",
|
group: "core.dashboard.widgets.groups.page",
|
||||||
configFormKitSchema: [
|
configFormKitSchema: () => [
|
||||||
{
|
{
|
||||||
$formkit: "checkbox",
|
$formkit: "checkbox",
|
||||||
label: "Enable animation",
|
label: i18n.global.t(
|
||||||
|
"core.dashboard.widgets.common_form.fields.enable_animation.label"
|
||||||
|
),
|
||||||
name: "enable_animation",
|
name: "enable_animation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -73,10 +77,12 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:comment:stats",
|
id: "core:comment:stats",
|
||||||
component: markRaw(CommentStatsWidget),
|
component: markRaw(CommentStatsWidget),
|
||||||
group: "core.dashboard.widgets.groups.comment",
|
group: "core.dashboard.widgets.groups.comment",
|
||||||
configFormKitSchema: [
|
configFormKitSchema: () => [
|
||||||
{
|
{
|
||||||
$formkit: "checkbox",
|
$formkit: "checkbox",
|
||||||
label: "Enable animation",
|
label: i18n.global.t(
|
||||||
|
"core.dashboard.widgets.common_form.fields.enable_animation.label"
|
||||||
|
),
|
||||||
name: "enable_animation",
|
name: "enable_animation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -95,7 +101,6 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:comment:pending",
|
id: "core:comment:pending",
|
||||||
component: markRaw(PendingCommentsWidget),
|
component: markRaw(PendingCommentsWidget),
|
||||||
group: "core.dashboard.widgets.groups.comment",
|
group: "core.dashboard.widgets.groups.comment",
|
||||||
configFormKitSchema: [],
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
defaultSize: {
|
defaultSize: {
|
||||||
w: 6,
|
w: 6,
|
||||||
|
@ -108,10 +113,12 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:user:stats",
|
id: "core:user:stats",
|
||||||
component: markRaw(UserStatsWidget),
|
component: markRaw(UserStatsWidget),
|
||||||
group: "core.dashboard.widgets.groups.user",
|
group: "core.dashboard.widgets.groups.user",
|
||||||
configFormKitSchema: [
|
configFormKitSchema: () => [
|
||||||
{
|
{
|
||||||
$formkit: "checkbox",
|
$formkit: "checkbox",
|
||||||
label: "Enable animation",
|
label: i18n.global.t(
|
||||||
|
"core.dashboard.widgets.common_form.fields.enable_animation.label"
|
||||||
|
),
|
||||||
name: "enable_animation",
|
name: "enable_animation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -129,10 +136,12 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:view:stats",
|
id: "core:view:stats",
|
||||||
component: markRaw(ViewsStatsWidget),
|
component: markRaw(ViewsStatsWidget),
|
||||||
group: "core.dashboard.widgets.groups.other",
|
group: "core.dashboard.widgets.groups.other",
|
||||||
configFormKitSchema: [
|
configFormKitSchema: () => [
|
||||||
{
|
{
|
||||||
$formkit: "checkbox",
|
$formkit: "checkbox",
|
||||||
label: "Enable animation",
|
label: i18n.global.t(
|
||||||
|
"core.dashboard.widgets.common_form.fields.enable_animation.label"
|
||||||
|
),
|
||||||
name: "enable_animation",
|
name: "enable_animation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -174,7 +183,6 @@ export const internalWidgetDefinitions: DashboardWidgetDefinition[] = [
|
||||||
id: "core:notifications",
|
id: "core:notifications",
|
||||||
component: markRaw(NotificationWidget),
|
component: markRaw(NotificationWidget),
|
||||||
group: "core.dashboard.widgets.groups.other",
|
group: "core.dashboard.widgets.groups.other",
|
||||||
configFormKitSchema: [],
|
|
||||||
defaultConfig: {},
|
defaultConfig: {},
|
||||||
defaultSize: {
|
defaultSize: {
|
||||||
w: 6,
|
w: 6,
|
||||||
|
|
|
@ -68,7 +68,10 @@ export interface DashboardWidgetDefinition {
|
||||||
id: string; // 小部件唯一标识符
|
id: string; // 小部件唯一标识符
|
||||||
component: Raw<Component>; // 小部件 Vue 组件
|
component: Raw<Component>; // 小部件 Vue 组件
|
||||||
group: string; // 小部件分组,用于在小部件库中分类显示
|
group: string; // 小部件分组,用于在小部件库中分类显示
|
||||||
configFormKitSchema?: Record<string, unknown>[]; // 配置表单 FormKit 定义
|
configFormKitSchema?:
|
||||||
|
| Record<string, unknown>[]
|
||||||
|
| (() => Promise<Record<string, unknown>[]>)
|
||||||
|
| (() => Record<string, unknown>[]); // 配置表单 FormKit 定义,支持异步函数
|
||||||
defaultConfig?: Record<string, unknown>; // 默认配置
|
defaultConfig?: Record<string, unknown>; // 默认配置
|
||||||
defaultSize: { // 默认尺寸
|
defaultSize: { // 默认尺寸
|
||||||
w: number; // 宽度(网格单位),根据不同屏幕尺寸,网格单位不同,可参考:{ lg: 12, md: 12, sm: 6, xs: 4 }
|
w: number; // 宽度(网格单位),根据不同屏幕尺寸,网格单位不同,可参考:{ lg: 12, md: 12, sm: 6, xs: 4 }
|
||||||
|
|
|
@ -27,7 +27,10 @@ export interface DashboardWidgetDefinition {
|
||||||
id: string;
|
id: string;
|
||||||
component: Raw<Component>;
|
component: Raw<Component>;
|
||||||
group: string;
|
group: string;
|
||||||
configFormKitSchema?: Record<string, unknown>[];
|
configFormKitSchema?:
|
||||||
|
| Record<string, unknown>[]
|
||||||
|
| (() => Promise<Record<string, unknown>[]>)
|
||||||
|
| (() => Record<string, unknown>[]);
|
||||||
defaultConfig?: Record<string, unknown>;
|
defaultConfig?: Record<string, unknown>;
|
||||||
defaultSize: {
|
defaultSize: {
|
||||||
w: number;
|
w: number;
|
||||||
|
|
|
@ -24,6 +24,10 @@ core:
|
||||||
aggregate_role: Aggregate Role
|
aggregate_role: Aggregate Role
|
||||||
dashboard:
|
dashboard:
|
||||||
widgets:
|
widgets:
|
||||||
|
common_form:
|
||||||
|
fields:
|
||||||
|
enable_animation:
|
||||||
|
label: Enable animation
|
||||||
presets:
|
presets:
|
||||||
recent_published:
|
recent_published:
|
||||||
publishTime: Publish Time {publishTime}
|
publishTime: Publish Time {publishTime}
|
||||||
|
|
|
@ -51,6 +51,10 @@ core:
|
||||||
actions:
|
actions:
|
||||||
setting: Setting
|
setting: Setting
|
||||||
widgets:
|
widgets:
|
||||||
|
common_form:
|
||||||
|
fields:
|
||||||
|
enable_animation:
|
||||||
|
label: Enable animation
|
||||||
groups:
|
groups:
|
||||||
post: Post
|
post: Post
|
||||||
page: Page
|
page: Page
|
||||||
|
|
|
@ -120,6 +120,10 @@ core:
|
||||||
label: 部件
|
label: 部件
|
||||||
toast:
|
toast:
|
||||||
nest_warning: 不能将堆叠部件添加到堆叠部件中
|
nest_warning: 不能将堆叠部件添加到堆叠部件中
|
||||||
|
common_form:
|
||||||
|
fields:
|
||||||
|
enable_animation:
|
||||||
|
label: 启用动画
|
||||||
dashboard_designer:
|
dashboard_designer:
|
||||||
title: 编辑仪表盘
|
title: 编辑仪表盘
|
||||||
actions:
|
actions:
|
||||||
|
|
|
@ -120,6 +120,10 @@ core:
|
||||||
label: 部件
|
label: 部件
|
||||||
toast:
|
toast:
|
||||||
nest_warning: 不能將堆疊部件添加到堆疊部件中
|
nest_warning: 不能將堆疊部件添加到堆疊部件中
|
||||||
|
common_form:
|
||||||
|
fields:
|
||||||
|
enable_animation:
|
||||||
|
label: 啟用動畫
|
||||||
dashboard_designer:
|
dashboard_designer:
|
||||||
title: 編輯儀表盤
|
title: 編輯儀表盤
|
||||||
actions:
|
actions:
|
||||||
|
|
Loading…
Reference in New Issue