Skip to content

Commit

Permalink
refactor: refactor user album view with custom component
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiinaKin committed Dec 6, 2024
1 parent fc3aadf commit 9c0a3f5
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import kotlinx.serialization.Serializable
@Name("AlbumSelfInsertRequest")
data class AlbumSelfInsertRequest(
val name: String,
val description: String?
val description: String? = null
)

@Serializable
@Name("AlbumManageInsertRequest")
data class AlbumManageInsertRequest(
val userId: Long,
val name: String,
val description: String?
val description: String? = null
)

@Serializable
Expand Down
54 changes: 54 additions & 0 deletions ui/src/components/form/userField/album/AlbumCreateForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<script setup lang="ts">
import { useForm } from "vee-validate";
import { useI18n } from "vue-i18n";
import * as yup from "yup";
import VeeFloatInputText from "@/components/vee-input/VeeFloatInputText.vue";
import Button from "primevue/button";
const { t } = useI18n();
const albumCreateFormSchema = yup.object({
name: yup.string().trim().required(t("myAlbumView.create.dialog.form.verify.name.required")),
description: yup.string().trim(),
});
const { handleSubmit } = useForm({
validationSchema: albumCreateFormSchema
});
const emits = defineEmits(["submit", "cancel"]);
const onSubmit = handleSubmit((values, ctx) => {
emits("submit", values, ctx);
});
const onCancel = () => {
emits("cancel");
};
</script>

<template>
<form @submit="onSubmit" class="flex flex-col gap-4 m-4 w-96">
<div class="flex flex-col gap-2.5 w-full">
<div class="flex flex-col gap-1">
<VeeFloatInputText id="newAlbumName" name="name" :label="t('myAlbumView.create.dialog.form.name')" />
</div>
<div class="flex flex-col gap-1">
<VeeFloatInputText id="newAlbumDesc" name="description" :label="t('myAlbumView.create.dialog.form.description')" />
</div>
</div>
<div class="flex justify-end gap-2">
<Button
type="button"
:label="t('myAlbumView.create.dialog.form.cancelButton')"
severity="secondary"
@click="onCancel"
/>
<Button type="submit" :label="t('myAlbumView.create.dialog.form.submitButton')" />
</div>
</form>
</template>

<style scoped>
</style>
74 changes: 74 additions & 0 deletions ui/src/components/form/userField/album/AlbumEditForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<script setup lang="ts">
import { useForm } from "vee-validate";
import { useI18n } from "vue-i18n";
import * as yup from "yup";
import VeeIftaInputText from "@/components/vee-input/VeeIftaInputText.vue";
import Button from "primevue/button";
const { t } = useI18n();
const albumEditFormSchema = yup.object({
name: yup
.string()
.trim()
.test("at-least-one-field", t("myAlbumView.edit.dialog.form.verify.atLeastOneField"), function () {
return !!(this.parent.name || this.parent.description);
}),
description: yup
.string()
.trim()
.test("at-least-one-field", t("myAlbumView.edit.dialog.form.verify.atLeastOneField"), function () {
return !!(this.parent.name || this.parent.description);
})
});
const { handleSubmit } = useForm({
validationSchema: albumEditFormSchema
});
const { albumDetail } = defineProps(["albumDetail"]);
const emits = defineEmits(["submit", "cancel"]);
const onSubmit = handleSubmit((values, ctx) => {
emits("submit", values, ctx);
});
const onCancel = () => {
emits("cancel");
};
</script>

<template>
<form @submit="onSubmit" class="flex flex-col gap-4 m-4 w-96">
<div class="flex flex-col gap-2.5 w-full">
<div class="flex flex-col gap-1">
<VeeIftaInputText
id="editAlbumName"
name="name"
:placeholder="albumDetail?.name"
:label="t('myAlbumView.edit.dialog.form.name')"
/>
</div>
<div class="flex flex-col gap-1">
<VeeIftaInputText
id="editAlbumDesc"
name="description"
:placeholder="albumDetail?.description"
:label="t('myAlbumView.edit.dialog.form.description')"
/>
</div>
</div>
<div class="flex justify-end gap-2">
<Button
type="button"
:label="t('myAlbumView.edit.dialog.form.cancelButton')"
severity="secondary"
@click="onCancel"
/>
<Button type="submit" :label="t('myAlbumView.edit.dialog.form.submitButton')" />
</div>
</form>
</template>

<style scoped></style>
116 changes: 75 additions & 41 deletions ui/src/locales/zh_cn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,47 +124,81 @@ myImageView:
myImageDialogImageChangeAlbumSuccessMessage: "修改相册成功"
myImageDialogImageChangeAlbumFailedTitle: "修改相册失败"
myAlbumView:
myAlbumCreateButton: "创建相册"
myAlbumTableAlbumId: "相册ID"
myAlbumTableAlbumName: "相册名"
myAlbumTableImageCount: "图片数量"
myAlbumTableIsUncategorized: "未分类相册"
myAlbumTableIsDefault: "默认相册"
myAlbumTableCreateTime: "创建时间"
myAlbumTableOpsTitle: "操作"
myAlbumTableOpsDetail: "查看"
myAlbumTableOpsEdit: "编辑"
myAlbumTableOpsSettingAsDefault: "设为默认"
myAlbumTableOpsDelete: "删除"
myAlbumCreateDialogTitle: "创建相册"
myAlbumCreateDialogAlbumName: "相册名"
myAlbumCreateDialogAlbumDesc: "相册描述"
myAlbumCreateDialogCancelButton: "取消"
myAlbumCreateDialogSubmitButton: "创建"
myAlbumCreateDialogSuccessTitle: "创建成功"
myAlbumCreateDialogFailedTitle: "创建失败"
myAlbumDeleteConfirmDialogTitle: "确认删除"
myAlbumDeleteConfirmDialogWarningTitle: "你确定要删除这个相册吗?"
myAlbumDeleteConfirmDialogWarningContent: "真的会删除,而且无法找回,图片会被移动到未分类相册"
myAlbumDeleteConfirmDialogCancelButton: "取消"
myAlbumDeleteConfirmDialogSubmitButton: "确认删除"
myAlbumDeleteConfirmDialogSuccessTitle: "删除成功"
myAlbumDeleteConfirmDialogFailedTitle: "删除失败"
myAlbumEditDialogTitle: "修改相册"
myAlbumEditDialogAlbumName: "相册名"
myAlbumEditDialogAlbumDesc: "相册描述"
myAlbumEditDialogCancelButton: "取消"
myAlbumEditDialogSubmitButton: "修改"
myAlbumEditDialogSuccessTitle: "修改成功"
myAlbumEditDialogFailedTitle: "修改失败"
myAlbumEditDialogValidationFailedMessage: "相册名和描述不能同时为空"
myAlbumDetailDialogTitle: "相册详情"
myAlbumDetailDialogAlbumName: "相册名"
myAlbumDetailDialogAlbumDesc: "相册描述"
myAlbumDetailDialogAlbumImageCount: "图片数量"
myAlbumDetailDialogAlbumIsUncategorized: "是否为未分类"
myAlbumDetailDialogAlbumIsDefault: "是否默认"
myAlbumDetailDialogAlbumCreateTime: "创建时间"
toolbar:
createButton: "创建相册"
table:
albumId: "相册ID"
albumName: "相册名"
imageCount: "图片数量"
isUncategorized:
title: "是否为未分类"
true: ""
false: ""
isDefault:
title: "默认相册"
true: ""
false: ""
createTime: "创建时间"
ops:
title: "操作"
detail: "查看"
edit: "编辑"
settingAsDefault: "设为默认"
delete: "删除"
create:
dialog:
title: "创建相册"
form:
name: "相册名"
description: "相册描述"
cancelButton: "取消"
submitButton: "创建"
verify:
name:
required: "相册名不能为空"
toast:
successTitle: "创建成功"
failedTitle: "创建失败"
delete:
dialog:
title: "确认删除"
warningTitle: "你确定要删除这个相册吗?"
warningContent: "真的会删除,而且无法找回,图片会被移动到未分类相册"
cancelButton: "取消"
submitButton: "确认删除"
toast:
successTitle: "删除成功"
failedTitle: "删除失败"
edit:
dialog:
title: "修改相册"
form:
name: "相册名"
description: "相册描述"
cancelButton: "取消"
submitButton: "修改"
verify:
atLeastOneField: "相册名和描述不能同时为空"
toast:
successTitle: "修改成功"
failedTitle: "修改失败"
detail:
dialog:
title: "相册详情"
name: "相册名"
description: "相册描述"
imageCount: "图片数量"
isUncategorized:
title: "是否为未分类"
true: ""
false: ""
isDefault:
title: "是否默认"
true: ""
false: ""
createTime: "创建时间"
toast:
failedTitle: "获取相册信息失败"
myProfileView:
toolbar:
title: "我的资料"
Expand Down
Loading

0 comments on commit 9c0a3f5

Please sign in to comment.