Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

feat: add annotations form for more extension #801

Merged
merged 3 commits into from
Dec 26, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/form/AnnotationsForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const avaliableAnnotationSettings = computed(() => {

const handleFetchAnnotationSettings = async () => {
try {
console.log([props.group, props.kind]);
ruibaby marked this conversation as resolved.
Show resolved Hide resolved
const { data } =
await apiClient.extension.annotationSetting.listv1alpha1AnnotationSetting(
{
Expand Down Expand Up @@ -148,7 +149,11 @@ const specFormInvalid = ref(true);
const customFormInvalid = ref(true);

const handleSubmit = async () => {
submitForm("specForm");
if (avaliableAnnotationSettings.value.length) {
submitForm("specForm");
} else {
specFormInvalid.value = false;
}
submitForm("customForm");
await nextTick();
};
Expand Down
52 changes: 52 additions & 0 deletions src/modules/contents/pages/components/SinglePageSettingModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { singlePageLabels } from "@/constants/labels";
import { randomUUID } from "@/utils/id";
import { toDatetimeLocal, toISOString } from "@/utils/date";
import { submitForm } from "@formkit/core";
import AnnotationsForm from "@/components/form/AnnotationsForm.vue";

const initialFormState: SinglePage = {
spec: {
Expand Down Expand Up @@ -75,6 +76,8 @@ const onVisibleChange = (visible: boolean) => {
}
};

const annotationsFormRef = ref<InstanceType<typeof AnnotationsForm>>();

const handleSubmit = () => {
if (submitType.value === "publish") {
handlePublish();
Expand All @@ -101,6 +104,20 @@ const handlePublishClick = () => {
};

const handleSave = async () => {
annotationsFormRef.value?.handleSubmit();
await nextTick();

const { customAnnotations, annotations, customFormInvalid, specFormInvalid } =
annotationsFormRef.value || {};
if (customFormInvalid || specFormInvalid) {
return;
}

formState.value.metadata.annotations = {
...annotations,
...customAnnotations,
};

if (props.onlyEmit) {
emit("saved", formState.value);
return;
Expand Down Expand Up @@ -138,6 +155,20 @@ const handleSave = async () => {
};

const handlePublish = async () => {
annotationsFormRef.value?.handleSubmit();
await nextTick();

const { customAnnotations, annotations, customFormInvalid, specFormInvalid } =
annotationsFormRef.value || {};
if (customFormInvalid || specFormInvalid) {
return;
}

formState.value.metadata.annotations = {
...annotations,
...customAnnotations,
};

if (props.onlyEmit) {
emit("published", formState.value);
return;
Expand Down Expand Up @@ -364,6 +395,27 @@ const onPublishTimeChange = (value: string) => {
</div>
</FormKit>

<div class="py-5">
<div class="border-t border-gray-200"></div>
</div>

<div class="md:grid md:grid-cols-4 md:gap-6">
<div class="md:col-span-1">
<div class="sticky top-0">
<span class="text-base font-medium text-gray-900"> 元数据 </span>
</div>
</div>
<div class="mt-5 divide-y divide-gray-100 md:col-span-3 md:mt-0">
<AnnotationsForm
:key="formState.metadata.name"
ref="annotationsFormRef"
:value="formState.metadata.annotations"
kind="SinglePage"
group="content.halo.run"
/>
</div>
</div>

<template #footer>
<VSpace>
<template v-if="publishSupport">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts" setup>
// core libs
import { computed, ref, watch } from "vue";
import { computed, nextTick, ref, watch } from "vue";
import { apiClient } from "@/utils/api-client";

// components
Expand All @@ -15,6 +15,7 @@ import cloneDeep from "lodash.clonedeep";
import { reset } from "@formkit/core";
import { setFocus } from "@/formkit/utils/focus";
import { useThemeCustomTemplates } from "@/modules/interface/themes/composables/use-theme";
import AnnotationsForm from "@/components/form/AnnotationsForm.vue";

const props = withDefaults(
defineProps<{
Expand Down Expand Up @@ -62,7 +63,23 @@ const modalTitle = computed(() => {
return isUpdateMode.value ? "编辑文章分类" : "新增文章分类";
});

const annotationsFormRef = ref<InstanceType<typeof AnnotationsForm>>();

const handleSaveCategory = async () => {
annotationsFormRef.value?.handleSubmit();
await nextTick();

const { customAnnotations, annotations, customFormInvalid, specFormInvalid } =
annotationsFormRef.value || {};
if (customFormInvalid || specFormInvalid) {
return;
}

formState.value.metadata.annotations = {
...annotations,
...customAnnotations,
};

try {
saving.value = true;
if (isUpdateMode.value) {
Expand Down Expand Up @@ -126,56 +143,89 @@ const { templates } = useThemeCustomTemplates("category");
<VModal
:title="modalTitle"
:visible="visible"
:width="600"
:width="700"
@update:visible="onVisibleChange"
>
<FormKit
id="category-form"
name="category-form"
type="form"
name="category-form"
:config="{ validationVisibility: 'submit' }"
@submit="handleSaveCategory"
>
<FormKit
id="displayNameInput"
v-model="formState.spec.displayName"
name="displayName"
label="名称"
type="text"
validation="required|length:0,50"
></FormKit>
<FormKit
v-model="formState.spec.slug"
help="通常作为分类访问地址标识"
name="slug"
label="别名"
type="text"
validation="required|length:0,50"
></FormKit>
<FormKit
v-model="formState.spec.template"
:options="templates"
label="自定义模板"
type="select"
name="template"
></FormKit>
<FormKit
v-model="formState.spec.cover"
help="需要主题适配以支持"
name="cover"
label="封面图"
type="attachment"
validation="length:0,1024"
></FormKit>
<FormKit
v-model="formState.spec.description"
name="description"
help="需要主题适配以支持"
label="描述"
type="textarea"
validation="length:0,200"
></FormKit>
<div>
<div class="md:grid md:grid-cols-4 md:gap-6">
<div class="md:col-span-1">
<div class="sticky top-0">
<span class="text-base font-medium text-gray-900"> 常规 </span>
</div>
</div>
<div class="mt-5 divide-y divide-gray-100 md:col-span-3 md:mt-0">
<FormKit
id="displayNameInput"
v-model="formState.spec.displayName"
name="displayName"
label="名称"
type="text"
validation="required|length:0,50"
></FormKit>
<FormKit
v-model="formState.spec.slug"
help="通常作为分类访问地址标识"
name="slug"
label="别名"
type="text"
validation="required|length:0,50"
></FormKit>
<FormKit
v-model="formState.spec.template"
:options="templates"
label="自定义模板"
type="select"
name="template"
></FormKit>
<FormKit
v-model="formState.spec.cover"
help="需要主题适配以支持"
name="cover"
label="封面图"
type="attachment"
validation="length:0,1024"
></FormKit>
<FormKit
v-model="formState.spec.description"
name="description"
help="需要主题适配以支持"
label="描述"
type="textarea"
validation="length:0,200"
></FormKit>
</div>
</div>
</div>
</FormKit>

<div class="py-5">
<div class="border-t border-gray-200"></div>
</div>

<div class="md:grid md:grid-cols-4 md:gap-6">
<div class="md:col-span-1">
<div class="sticky top-0">
<span class="text-base font-medium text-gray-900"> 元数据 </span>
</div>
</div>
<div class="mt-5 divide-y divide-gray-100 md:col-span-3 md:mt-0">
<AnnotationsForm
:key="formState.metadata.name"
ref="annotationsFormRef"
:value="formState.metadata.annotations"
kind="Category"
group="content.halo.run"
/>
</div>
</div>

<template #footer>
<VSpace>
<SubmitButton
Expand Down
Loading