261 lines
6.9 KiB
Vue
261 lines
6.9 KiB
Vue
<!-- 页面编号:R-09;用途:人物人生事时间轴与同页新增。 -->
|
||
<template>
|
||
<view class="timeline-page" :class="stateClasses">
|
||
<ModulePageBackground module="records" />
|
||
<view class="page-header">
|
||
<PageHeader title="人生事" action="新增" @action="createLifeEvent" />
|
||
</view>
|
||
<view v-if="timelineState === 'loading'" class="page-loading">
|
||
<AppLoading
|
||
text="正在读取人生事"
|
||
:description="`请稍候,正在整理${personName}的重要节点。`"
|
||
/>
|
||
</view>
|
||
<view v-else class="page-content">
|
||
<view class="person-lead">
|
||
<text>{{ personName }}</text>
|
||
<text>值得回望的人生节点</text>
|
||
</view>
|
||
<template v-if="timelineState === 'ready' && lifeEvents.length">
|
||
<view v-for="event in lifeEvents" :key="event.id" class="timeline-card">
|
||
<text>{{ event.year }}</text>
|
||
<text>{{ event.title }}</text>
|
||
<text>{{ event.place }}</text>
|
||
<text>{{ event.description }}</text>
|
||
</view>
|
||
<AppButton block label="新增人生事" @click="createLifeEvent" />
|
||
</template>
|
||
<view v-else class="state-card">
|
||
<text>
|
||
{{ timelineState === "error" ? "人生事暂不可用" : "还没有人生事" }}
|
||
</text>
|
||
<text>
|
||
{{
|
||
timelineState === "error"
|
||
? "请稍后重新查看,已有记录不会受到影响。"
|
||
: "从毕业、成家或重要迁居开始记录。"
|
||
}}
|
||
</text>
|
||
<AppButton
|
||
:type="timelineState === 'error' ? 'secondary' : 'primary'"
|
||
block
|
||
:label="timelineState === 'error' ? '重新查看' : '新增人生事'"
|
||
@click="
|
||
timelineState === 'error'
|
||
? (timelineState = 'ready')
|
||
: createLifeEvent()
|
||
"
|
||
/>
|
||
</view>
|
||
</view>
|
||
<AppDialog
|
||
:visible="dialogVisible"
|
||
eyebrow="人生事"
|
||
title="记录一个人生节点"
|
||
confirm-text="保存记录"
|
||
cancel-text="取消"
|
||
show-cancel
|
||
@confirm="saveLifeEvent"
|
||
@cancel="dialogVisible = false"
|
||
>
|
||
<view class="dialog-form">
|
||
<input v-model="lifeEventForm.title" placeholder="事件名称" />
|
||
<input v-model="lifeEventForm.year" placeholder="年份或日期" />
|
||
<input v-model="lifeEventForm.place" placeholder="地点(选填)" />
|
||
<textarea
|
||
v-model="lifeEventForm.description"
|
||
auto-height
|
||
placeholder="写下这段经历"
|
||
/>
|
||
<text v-if="formError">{{ formError }}</text>
|
||
</view>
|
||
</AppDialog>
|
||
<AppToast :visible="toastVisible" message="人生事已保存" />
|
||
</view>
|
||
</template>
|
||
<script setup>
|
||
import { computed, onUnmounted, reactive, ref } from "vue";
|
||
import { onLoad } from "@dcloudio/uni-app";
|
||
import AppButton from "@/components/AppButton.vue";
|
||
import AppDialog from "@/components/AppDialog.vue";
|
||
import AppLoading from "@/components/AppLoading.vue";
|
||
import AppToast from "@/components/AppToast.vue";
|
||
import ModulePageBackground from "@/components/ModulePageBackground.vue";
|
||
import PageHeader from "@/components/PageHeader.vue";
|
||
const personName = ref("汤文清");
|
||
const lifeEvents = ref([
|
||
{
|
||
id: 1,
|
||
title: "大学毕业",
|
||
year: "2018 年 6 月",
|
||
place: "杭州",
|
||
description: "完成学业,带着家人的祝福走向新的生活。",
|
||
},
|
||
{
|
||
id: 2,
|
||
title: "结为连理",
|
||
year: "2022 年 10 月",
|
||
place: "汤氏祖居",
|
||
description: "在家人见证下组成新的家庭。",
|
||
},
|
||
]);
|
||
const timelineState = ref("loading");
|
||
const dialogVisible = ref(false);
|
||
const toastVisible = ref(false);
|
||
const formError = ref("");
|
||
const lifeEventForm = reactive({
|
||
title: "",
|
||
year: "",
|
||
place: "",
|
||
description: "",
|
||
});
|
||
let timer = null;
|
||
const stateClasses = computed(() => ({
|
||
"timeline-state--loading": timelineState.value === "loading",
|
||
"timeline-state--empty": timelineState.value === "empty",
|
||
"timeline-state--error": timelineState.value === "error",
|
||
}));
|
||
onLoad((q) => {
|
||
personName.value = String(q.personName || "汤文清");
|
||
timelineState.value = ["loading", "empty", "error"].includes(q.state)
|
||
? q.state
|
||
: "ready";
|
||
});
|
||
const createLifeEvent = () => {
|
||
Object.assign(lifeEventForm, {
|
||
title: "",
|
||
year: "",
|
||
place: "",
|
||
description: "",
|
||
});
|
||
formError.value = "";
|
||
dialogVisible.value = true;
|
||
};
|
||
const saveLifeEvent = () => {
|
||
if (!lifeEventForm.title.trim() || !lifeEventForm.year.trim()) {
|
||
formError.value = "请填写事件名称和年份";
|
||
return;
|
||
}
|
||
lifeEvents.value.unshift({ id: Date.now(), ...lifeEventForm });
|
||
timelineState.value = "ready";
|
||
dialogVisible.value = false;
|
||
toastVisible.value = true;
|
||
timer = setTimeout(() => (toastVisible.value = false), 1800);
|
||
};
|
||
onUnmounted(() => {
|
||
if (timer) clearTimeout(timer);
|
||
});
|
||
</script>
|
||
<style scoped lang="scss">
|
||
@use "../../styles/adaptive-frame-profiles.scss" as adaptive;
|
||
|
||
.timeline-page {
|
||
display: flex;
|
||
min-height: 100vh;
|
||
flex-direction: column;
|
||
background: $paper;
|
||
}
|
||
.page-header,
|
||
.page-loading,
|
||
.page-content {
|
||
z-index: 1;
|
||
}
|
||
.page-loading {
|
||
min-height: calc(100vh - 100rpx);
|
||
}
|
||
.page-content {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 16rpx;
|
||
padding: 18rpx 24rpx 72rpx;
|
||
}
|
||
.person-lead {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
justify-content: space-between;
|
||
gap: 8rpx 18rpx;
|
||
min-height: 62rpx;
|
||
align-items: center;
|
||
padding: 0 20rpx;
|
||
color: $ink-muted;
|
||
font-size: 22rpx;
|
||
background: url("/static/assets/modules/genealogy/transparent/section-divider.png")
|
||
center/100% auto no-repeat;
|
||
}
|
||
.person-lead text:first-child {
|
||
color: $brand-red;
|
||
font-weight: 700;
|
||
}
|
||
.timeline-card,
|
||
.state-card {
|
||
box-sizing: border-box;
|
||
padding: 34rpx 46rpx;
|
||
@include adaptive.adaptive-records-content;
|
||
}
|
||
.timeline-card > text,
|
||
.state-card > text {
|
||
display: block;
|
||
}
|
||
.timeline-card > text:first-child {
|
||
color: $brand-red;
|
||
font-size: 20rpx;
|
||
}
|
||
.timeline-card > text:nth-child(2) {
|
||
margin-top: 6rpx;
|
||
color: $ink;
|
||
font-size: 31rpx;
|
||
font-weight: 700;
|
||
}
|
||
.timeline-card > text:nth-child(3) {
|
||
margin-top: 8rpx;
|
||
color: $ink-muted;
|
||
font-size: 21rpx;
|
||
}
|
||
.timeline-card > text:last-child {
|
||
margin-top: 10rpx;
|
||
color: $ink;
|
||
font-size: 23rpx;
|
||
line-height: 1.55;
|
||
}
|
||
.state-card {
|
||
min-height: 340rpx;
|
||
padding-top: 78rpx;
|
||
text-align: center;
|
||
}
|
||
.state-card > text:first-child {
|
||
color: $ink;
|
||
font-size: 35rpx;
|
||
font-weight: 700;
|
||
}
|
||
.state-card > text:nth-child(2) {
|
||
margin-top: 18rpx;
|
||
color: $ink-muted;
|
||
font-size: 24rpx;
|
||
line-height: 1.65;
|
||
}
|
||
.state-card .app-button {
|
||
margin-top: 28rpx;
|
||
}
|
||
.dialog-form {
|
||
width: 100%;
|
||
margin: 18rpx 0;
|
||
}
|
||
.dialog-form input,
|
||
.dialog-form textarea {
|
||
width: 100%;
|
||
min-height: 66rpx;
|
||
margin-top: 8rpx;
|
||
padding: 12rpx 20rpx;
|
||
box-sizing: border-box;
|
||
color: $ink;
|
||
font-size: 22rpx;
|
||
@include adaptive.adaptive-records-field;
|
||
}
|
||
.dialog-form text {
|
||
display: block;
|
||
margin-top: 8rpx;
|
||
color: $brand-red;
|
||
font-size: 20rpx;
|
||
}
|
||
</style>
|