1007 lines
33 KiB
Vue
1007 lines
33 KiB
Vue
<template>
|
||
<view class="settings-page" :class="`settings-state--${pageState}`">
|
||
<GenealogyPageBackground />
|
||
<view class="page-header"
|
||
><PageHeader title="家谱设置" custom-back @back="requestBack"
|
||
/></view>
|
||
|
||
<view class="page-content">
|
||
<AppLoading
|
||
v-if="pageState === 'loading'"
|
||
text="正在读取家谱设置"
|
||
description="请稍候,正在同步当前家谱信息。"
|
||
/>
|
||
|
||
<view v-else-if="pageState === 'form'" class="settings-card">
|
||
<text class="settings-card__title">编辑家谱信息</text>
|
||
<view v-if="lifecycleStatus === GENEALOGY_LIFECYCLE_STATUS.ARCHIVED" class="lifecycle-note">
|
||
<text>这部家谱已归档</text>
|
||
<text>归档期间可以查看内容,但不能修改。恢复后可继续编辑。</text>
|
||
</view>
|
||
<text class="settings-card__note"
|
||
>带红色星号的内容不能为空;其余内容可按需要补充。</text
|
||
>
|
||
|
||
<view class="field-row">
|
||
<text class="field-row__label"
|
||
><text class="required-mark">*</text>姓氏</text
|
||
>
|
||
<input
|
||
v-model="form.surname"
|
||
maxlength="4"
|
||
placeholder="请输入姓氏"
|
||
placeholder-class="placeholder"
|
||
@input="clearFieldError('surname')"
|
||
/>
|
||
</view>
|
||
<text v-if="fieldErrors.surname" class="field-error">{{
|
||
fieldErrors.surname
|
||
}}</text>
|
||
|
||
<view class="field-row">
|
||
<text class="field-row__label"
|
||
><text class="required-mark">*</text>谱名</text
|
||
>
|
||
<input
|
||
v-model="form.genealogyName"
|
||
maxlength="24"
|
||
placeholder="请输入家谱名称"
|
||
placeholder-class="placeholder"
|
||
@input="clearFieldError('genealogyName')"
|
||
/>
|
||
</view>
|
||
<text v-if="fieldErrors.genealogyName" class="field-error">{{
|
||
fieldErrors.genealogyName
|
||
}}</text>
|
||
|
||
<view
|
||
class="field-row field-row--selector"
|
||
role="button"
|
||
aria-label="选择所在地区"
|
||
@click="openRegionPicker"
|
||
>
|
||
<text class="field-row__label"
|
||
><text class="required-mark">*</text>所在地区</text
|
||
>
|
||
<text
|
||
class="region-selector-value"
|
||
:class="{ 'region-selector-value--placeholder': !regionDisplay }"
|
||
>{{
|
||
regionDisplay ||
|
||
(regionLoading
|
||
? "正在加载地区…"
|
||
: regionPickerError || "请选择所在地区")
|
||
}}</text
|
||
>
|
||
<image
|
||
class="region-selector-chevron"
|
||
src="/static/assets/foundation/transparent/chevron-right.png"
|
||
mode="aspectFit"
|
||
aria-hidden="true"
|
||
/>
|
||
</view>
|
||
<text v-if="fieldErrors.regionCode" class="field-error">{{
|
||
fieldErrors.regionCode
|
||
}}</text>
|
||
|
||
<view class="field-row">
|
||
<text class="field-row__label">堂号</text>
|
||
<input
|
||
v-model="form.ancestralHall"
|
||
maxlength="12"
|
||
placeholder="请输入堂号"
|
||
placeholder-class="placeholder"
|
||
/>
|
||
</view>
|
||
<view class="field-row">
|
||
<text class="field-row__label">所在地</text>
|
||
<input
|
||
v-model="form.originPlace"
|
||
maxlength="30"
|
||
placeholder="请输入所在地"
|
||
placeholder-class="placeholder"
|
||
/>
|
||
</view>
|
||
<view class="field-row">
|
||
<text class="field-row__label">详细地址</text>
|
||
<input
|
||
v-model="form.addressDetail"
|
||
maxlength="60"
|
||
placeholder="请输入详细地址"
|
||
placeholder-class="placeholder"
|
||
/>
|
||
</view>
|
||
|
||
<view class="intro-field">
|
||
<text class="intro-field__label">家谱简介</text>
|
||
<textarea
|
||
v-model="form.intro"
|
||
maxlength="200"
|
||
auto-height
|
||
placeholder="记录家谱缘由、迁徙或家训"
|
||
placeholder-class="placeholder"
|
||
/>
|
||
</view>
|
||
|
||
<view class="cover-field">
|
||
<view>
|
||
<text class="cover-field__label">封面图片</text>
|
||
<text class="cover-field__hint">{{
|
||
coverOssId
|
||
? "当前已有封面;重新选择后会用新图片替换。"
|
||
: "图片上传成功后,会作为家谱封面保存。"
|
||
}}</text>
|
||
</view>
|
||
<button
|
||
class="upload-button"
|
||
:disabled="isUploading || isSubmitting"
|
||
@click="uploadCover"
|
||
>
|
||
{{ isUploading ? "上传中…" : "选择图片" }}
|
||
</button>
|
||
<text v-if="coverFileName" class="upload-receipt"
|
||
>已上传:{{ coverFileName }}</text
|
||
>
|
||
<button v-if="coverOssId" class="remove-cover-button" :disabled="isUploading || isSubmitting" @click="clearCover">移除封面</button>
|
||
</view>
|
||
<text v-if="uploadError" class="field-error">{{ uploadError }}</text>
|
||
|
||
<view class="access-rule">
|
||
<text class="access-rule__label">访问规则</text>
|
||
<view
|
||
class="access-rule__options"
|
||
role="radiogroup"
|
||
aria-label="家谱访问规则"
|
||
>
|
||
<view
|
||
v-for="option in GENEALOGY_ACCESS_PRESET_OPTIONS"
|
||
:key="option.value"
|
||
class="access-rule__option"
|
||
:class="{
|
||
'access-rule__option--active':
|
||
form.accessPreset === option.value,
|
||
}"
|
||
role="radio"
|
||
:aria-checked="form.accessPreset === option.value"
|
||
:aria-label="option.label"
|
||
@click="form.accessPreset = option.value"
|
||
>{{ option.label }}</view
|
||
>
|
||
</view>
|
||
</view>
|
||
|
||
<text v-if="submitError" class="submit-error">{{ submitError }}</text>
|
||
<AppButton
|
||
block
|
||
:disabled="isSubmitting || isUploading || lifecycleStatus === GENEALOGY_LIFECYCLE_STATUS.ARCHIVED"
|
||
:label="isSubmitting ? '正在保存…' : '保存设置'"
|
||
@click="submitUpdate"
|
||
/>
|
||
<view v-if="canArchive || canRestore" class="lifecycle-actions">
|
||
<text>{{ canRestore ? "需要继续维护这部家谱时,可以恢复编辑。" : "暂时不再维护时,可以归档;内容仍可查看。" }}</text>
|
||
<AppButton
|
||
block
|
||
type="secondary"
|
||
:disabled="lifecycleSubmitting"
|
||
:label="lifecycleSubmitting ? '正在处理' : canRestore ? '恢复家谱' : '归档家谱'"
|
||
@click="requestLifecycleChange"
|
||
/>
|
||
</view>
|
||
<view
|
||
v-if="canDeletePermanently || permanentDeletionDisabledReason"
|
||
class="permanent-deletion"
|
||
>
|
||
<text>永久删除家谱</text>
|
||
<text>{{
|
||
canDeletePermanently
|
||
? "该操作会永久删除家谱及其业务内容,无法从回收站恢复。"
|
||
: permanentDeletionDisabledReason
|
||
}}</text>
|
||
<AppButton
|
||
block
|
||
type="secondary"
|
||
:disabled="!canDeletePermanently || permanentDeletionSubmitting"
|
||
label="永久删除家谱"
|
||
@click="openPermanentDeletion"
|
||
/>
|
||
</view>
|
||
</view>
|
||
|
||
<view v-else class="state-card">
|
||
<text>{{ stateCopy.title }}</text>
|
||
<text>{{ stateCopy.copy }}</text>
|
||
<AppButton block :label="stateCopy.action" @click="handleStateAction" />
|
||
</view>
|
||
</view>
|
||
<AppDialog
|
||
:visible="lifecycleDialogVisible"
|
||
eyebrow="家谱状态"
|
||
:title="canRestore ? '恢复这部家谱?' : '归档这部家谱?'"
|
||
:message="canRestore ? '恢复后可继续修改家谱内容。' : '归档后内容仍可查看,但暂时不能修改。'"
|
||
:confirm-text="lifecycleSubmitting ? '正在处理' : canRestore ? '确认恢复' : '确认归档'"
|
||
cancel-text="取消"
|
||
show-cancel
|
||
:close-on-mask="false"
|
||
@confirm="confirmLifecycleChange"
|
||
@cancel="lifecycleDialogVisible = false"
|
||
/>
|
||
<AppDialog
|
||
:visible="discardVisible"
|
||
eyebrow="未保存修改"
|
||
title="放弃家谱设置修改?"
|
||
message="当前修改还没有保存。"
|
||
confirm-text="确认放弃"
|
||
cancel-text="继续编辑"
|
||
show-cancel
|
||
:close-on-mask="false"
|
||
@confirm="confirmDiscard"
|
||
@cancel="cancelDiscard"
|
||
/>
|
||
<AppDialog
|
||
:visible="permanentDeletionVisible"
|
||
eyebrow="高风险操作"
|
||
title="永久删除这部家谱?"
|
||
:message="`请输入完整谱名“${form.genealogyName}”,并通过账号短信验证。删除后无法恢复。`"
|
||
:confirm-text="permanentDeletionSubmitting ? '正在删除' : '确认永久删除'"
|
||
cancel-text="取消"
|
||
show-cancel
|
||
:close-on-mask="false"
|
||
@confirm="confirmPermanentDeletion"
|
||
@cancel="closePermanentDeletion"
|
||
>
|
||
<input
|
||
v-model="permanentDeletionConfirmationName"
|
||
class="deletion-dialog-input"
|
||
maxlength="24"
|
||
:placeholder="`输入谱名:${form.genealogyName}`"
|
||
/>
|
||
<view class="deletion-code-row">
|
||
<input
|
||
v-model.trim="permanentDeletionSmsCode"
|
||
class="deletion-dialog-input"
|
||
type="number"
|
||
maxlength="4"
|
||
:placeholder="`验证码将发送至 ${deletionVerificationPhoneMasked}`"
|
||
/>
|
||
<AppButton
|
||
compact
|
||
type="secondary"
|
||
:disabled="permanentDeletionSubmitting || deletionCodeSending || deletionCodeCooldown > 0"
|
||
:label="deletionCodeButtonLabel"
|
||
@click="sendPermanentDeletionCode"
|
||
/>
|
||
</view>
|
||
<text v-if="permanentDeletionError" class="submit-error">{{ permanentDeletionError }}</text>
|
||
</AppDialog>
|
||
|
||
<RegionPickerDialog
|
||
ref="regionPickerDialog"
|
||
close-on-mask
|
||
@select="selectRegion"
|
||
@loading-change="regionLoading = $event"
|
||
@error-change="regionPickerError = $event"
|
||
@transient-change="regionPickerVisible = $event"
|
||
/>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, onMounted, reactive, ref } from "vue";
|
||
import { onBackPress, onLoad, onUnload } from "@dcloudio/uni-app";
|
||
import AppButton from "@/components/AppButton.vue";
|
||
import AppDialog from "@/components/AppDialog.vue";
|
||
import AppLoading from "@/components/AppLoading.vue";
|
||
import GenealogyPageBackground from "@/components/genealogy/PageBackground.vue";
|
||
import RegionPickerDialog from "@/components/genealogy/RegionPickerDialog.vue";
|
||
import PageHeader from "@/components/PageHeader.vue";
|
||
import {
|
||
GENEALOGY_LIFECYCLE_STATUS
|
||
} from "@/services/api/genealogy-contract.js";
|
||
import {
|
||
createRequestController,
|
||
isRequestCancelled
|
||
} from "@/services/api/request-controller.js";
|
||
import { genealogyApi } from "@/services/api/genealogy-service.js";
|
||
import { getRequestErrorMessage } from "@/services/api/request-error-message.js";
|
||
import {
|
||
GENEALOGY_ACCESS_PRESET,
|
||
GENEALOGY_ACCESS_PRESET_OPTIONS,
|
||
isGenealogyAccessPreset,
|
||
toApiGenealogyAccess,
|
||
} from "@/utils/genealogy/access-policy.js";
|
||
import {
|
||
isImagePickCancelled,
|
||
pickAndUploadImage,
|
||
} from "@/utils/media-upload.js";
|
||
import { createDiscardConfirmation } from "@/utils/discard-confirmation.js";
|
||
import { genealogyContext } from "@/utils/genealogy/context.js";
|
||
import { createNonIdempotentWriteGuard } from "@/utils/non-idempotent-write-guard.js";
|
||
import { goBack, handleBackPress, returnTo } from "@/utils/navigation/gateway.js";
|
||
|
||
const genealogyId = ref("");
|
||
const pageState = ref("loading");
|
||
const form = reactive({
|
||
surname: "",
|
||
genealogyName: "",
|
||
ancestralHall: "",
|
||
originPlace: "",
|
||
addressDetail: "",
|
||
intro: "",
|
||
accessPreset: GENEALOGY_ACCESS_PRESET.MEMBER_ONLY,
|
||
});
|
||
const fieldErrors = reactive({
|
||
surname: "",
|
||
genealogyName: "",
|
||
regionCode: "",
|
||
});
|
||
const submitError = ref("");
|
||
const isSubmitting = ref(false);
|
||
const isUploading = ref(false);
|
||
const uploadError = ref("");
|
||
const coverOssId = ref(null);
|
||
const coverFileName = ref("");
|
||
const lifecycleStatus = ref(GENEALOGY_LIFECYCLE_STATUS.NORMAL);
|
||
const canArchive = ref(false);
|
||
const canRestore = ref(false);
|
||
const canDeletePermanently = ref(false);
|
||
const permanentDeletionDisabledReason = ref("");
|
||
const deletionVerificationPhoneMasked = ref("");
|
||
const lifecycleDialogVisible = ref(false);
|
||
const lifecycleSubmitting = ref(false);
|
||
const permanentDeletionVisible = ref(false);
|
||
const permanentDeletionConfirmationName = ref("");
|
||
const permanentDeletionSmsCode = ref("");
|
||
const permanentDeletionError = ref("");
|
||
const permanentDeletionSubmitting = ref(false);
|
||
const deletionCodeSending = ref(false);
|
||
const deletionCodeCooldown = ref(0);
|
||
const currentRegionCode = ref("");
|
||
const currentRegionDisplay = ref("");
|
||
const selectedRegion = ref(null);
|
||
const regionPickerTrail = ref([]);
|
||
const regionPickerDialog = ref(null);
|
||
const regionPickerError = ref("");
|
||
const regionLoading = ref(false);
|
||
const regionPickerVisible = ref(false);
|
||
const settingsBaseline = ref("");
|
||
const discardVisible = ref(false);
|
||
const settingsReadRequestController = createRequestController();
|
||
const deletionCapabilityReadRequestController = createRequestController();
|
||
const genealogyLifecycleRequestController = createRequestController();
|
||
const deletionCodeRequestController = createRequestController();
|
||
const permanentDeletionRequestController = createRequestController();
|
||
const coverUploadRequestController = createRequestController();
|
||
const settingsSaveRequestController = createRequestController();
|
||
// 封面上传、归档和设置保存属于独立操作。分别持有取消槽,避免后发操作
|
||
// 取消前一条仍在收敛的请求,留下无法解释的加载状态。
|
||
let pageActive = true;
|
||
let deletionCodeTimer = null;
|
||
const permanentDeletionGuard = createNonIdempotentWriteGuard();
|
||
|
||
const discardConfirmation = createDiscardConfirmation((visible) => {
|
||
discardVisible.value = visible;
|
||
});
|
||
const requestDiscardConfirmation = discardConfirmation.request;
|
||
const confirmDiscard = discardConfirmation.confirm;
|
||
const cancelDiscard = discardConfirmation.cancel;
|
||
|
||
const hasValidContext = computed(() => /^[1-9]\d*$/.test(genealogyId.value));
|
||
const regionDisplay = computed(() =>
|
||
regionPickerTrail.value.length
|
||
? regionPickerTrail.value.map((regionNode) => regionNode.label).join(" / ")
|
||
: currentRegionDisplay.value,
|
||
);
|
||
const settingsSnapshot = computed(() => JSON.stringify({
|
||
...form,
|
||
regionCode: selectedRegion.value?.regionCode || currentRegionCode.value,
|
||
coverOssId: coverOssId.value || null,
|
||
}));
|
||
const isDirty = computed(() =>
|
||
pageState.value === "form" &&
|
||
Boolean(settingsBaseline.value) &&
|
||
settingsSnapshot.value !== settingsBaseline.value,
|
||
);
|
||
const deletionCodeButtonLabel = computed(() =>
|
||
deletionCodeSending.value
|
||
? "正在发送"
|
||
: deletionCodeCooldown.value > 0
|
||
? `${deletionCodeCooldown.value}s 后重发`
|
||
: "发送验证码",
|
||
);
|
||
const stateCopy = computed(() => {
|
||
if (pageState.value === "success") {
|
||
return {
|
||
title: "家谱设置已保存",
|
||
copy: "家谱设置已保存。",
|
||
action: "返回家谱总览",
|
||
};
|
||
}
|
||
if (!hasValidContext.value) {
|
||
return {
|
||
title: "暂时无法打开家谱设置",
|
||
copy: "未找到家谱信息,请返回后重新进入。",
|
||
action: "返回上一页",
|
||
};
|
||
}
|
||
return {
|
||
title: "家谱设置暂时无法读取",
|
||
copy: "请检查网络后重新读取。",
|
||
action: "重新读取",
|
||
};
|
||
});
|
||
|
||
const clearFieldError = (field) => {
|
||
fieldErrors[field] = "";
|
||
submitError.value = "";
|
||
};
|
||
const validate = () => {
|
||
fieldErrors.surname = form.surname.trim() ? "" : "请填写姓氏";
|
||
fieldErrors.genealogyName = form.genealogyName.trim() ? "" : "请填写谱名";
|
||
fieldErrors.regionCode =
|
||
selectedRegion.value?.regionCode || currentRegionCode.value
|
||
? ""
|
||
: "请选择所在地区";
|
||
return (
|
||
!fieldErrors.surname &&
|
||
!fieldErrors.genealogyName &&
|
||
!fieldErrors.regionCode
|
||
);
|
||
};
|
||
|
||
const openRegionPicker = async () => {
|
||
if (isSubmitting.value || isUploading.value || regionLoading.value) return;
|
||
await regionPickerDialog.value?.open(currentRegionCode.value);
|
||
};
|
||
const selectRegion = ({ region, trail }) => {
|
||
selectedRegion.value = region;
|
||
currentRegionCode.value = region.regionCode;
|
||
regionPickerTrail.value = trail;
|
||
fieldErrors.regionCode = "";
|
||
regionPickerError.value = "";
|
||
};
|
||
|
||
const loadSettings = async () => {
|
||
if (!hasValidContext.value) {
|
||
pageState.value = "invalid";
|
||
return;
|
||
}
|
||
pageState.value = "loading";
|
||
try {
|
||
const settings = await genealogyApi.getGenealogySettings(genealogyId.value, {
|
||
requestController: settingsReadRequestController,
|
||
});
|
||
if (!pageActive) return;
|
||
if (!isGenealogyAccessPreset(settings.accessPreset)) {
|
||
pageState.value = "error";
|
||
return;
|
||
}
|
||
Object.assign(form, {
|
||
surname: settings.surname,
|
||
genealogyName: settings.genealogyName,
|
||
ancestralHall: settings.ancestralHall,
|
||
originPlace: settings.originPlace,
|
||
addressDetail: settings.addressDetail,
|
||
intro: settings.intro,
|
||
accessPreset: settings.accessPreset,
|
||
});
|
||
currentRegionCode.value = settings.regionCode;
|
||
currentRegionDisplay.value = settings.regionFullName || settings.regionName;
|
||
coverOssId.value = settings.coverFile?.ossId ?? null;
|
||
coverFileName.value = settings.coverFile?.fileName || "";
|
||
lifecycleStatus.value = settings.lifecycleStatus;
|
||
canArchive.value = settings.canArchive;
|
||
canRestore.value = settings.canRestore;
|
||
pageState.value = "form";
|
||
settingsBaseline.value = settingsSnapshot.value;
|
||
try {
|
||
const deletionCapability = await genealogyApi.getPermanentDeletionCapability(
|
||
genealogyId.value,
|
||
{ requestController: deletionCapabilityReadRequestController },
|
||
);
|
||
if (!pageActive) return;
|
||
canDeletePermanently.value = deletionCapability.canDeletePermanently;
|
||
permanentDeletionDisabledReason.value = deletionCapability.disabledReasons.join(";");
|
||
deletionVerificationPhoneMasked.value = deletionCapability.phoneMasked;
|
||
} catch (error) {
|
||
if (!pageActive || isRequestCancelled(error)) return;
|
||
canDeletePermanently.value = false;
|
||
permanentDeletionDisabledReason.value = "永久注销资格暂时无法读取,请稍后重试。";
|
||
deletionVerificationPhoneMasked.value = "";
|
||
}
|
||
} catch (error) {
|
||
if (!pageActive || isRequestCancelled(error)) return;
|
||
pageState.value = "error";
|
||
}
|
||
};
|
||
const requestLifecycleChange = () => {
|
||
if ((!canArchive.value && !canRestore.value) || lifecycleSubmitting.value) return;
|
||
submitError.value = "";
|
||
lifecycleDialogVisible.value = true;
|
||
};
|
||
const confirmLifecycleChange = async () => {
|
||
if ((!canArchive.value && !canRestore.value) || lifecycleSubmitting.value) return;
|
||
lifecycleSubmitting.value = true;
|
||
try {
|
||
const lifecycleResult = canRestore.value
|
||
? await genealogyApi.restoreGenealogy(genealogyId.value, {
|
||
requestController: genealogyLifecycleRequestController,
|
||
})
|
||
: await genealogyApi.archiveGenealogy(genealogyId.value, {
|
||
requestController: genealogyLifecycleRequestController,
|
||
});
|
||
if (!pageActive) return;
|
||
lifecycleStatus.value = lifecycleResult.lifecycleStatus;
|
||
canArchive.value = lifecycleResult.canArchive;
|
||
canRestore.value = lifecycleResult.canRestore;
|
||
const deletionCapability = await genealogyApi.getPermanentDeletionCapability(
|
||
genealogyId.value,
|
||
{ requestController: genealogyLifecycleRequestController },
|
||
);
|
||
canDeletePermanently.value = deletionCapability.canDeletePermanently;
|
||
permanentDeletionDisabledReason.value = deletionCapability.disabledReasons.join(";");
|
||
deletionVerificationPhoneMasked.value = deletionCapability.phoneMasked;
|
||
lifecycleDialogVisible.value = false;
|
||
} catch (error) {
|
||
if (!pageActive || isRequestCancelled(error)) return;
|
||
submitError.value = getRequestErrorMessage(error, canRestore.value ? "家谱恢复失败,请稍后重试。" : "家谱归档失败,请稍后重试。");
|
||
lifecycleDialogVisible.value = false;
|
||
} finally {
|
||
if (pageActive) lifecycleSubmitting.value = false;
|
||
}
|
||
};
|
||
|
||
const stopDeletionCodeCooldown = () => {
|
||
if (deletionCodeTimer) clearInterval(deletionCodeTimer);
|
||
deletionCodeTimer = null;
|
||
};
|
||
const startDeletionCodeCooldown = (seconds) => {
|
||
stopDeletionCodeCooldown();
|
||
deletionCodeCooldown.value = seconds;
|
||
deletionCodeTimer = setInterval(() => {
|
||
deletionCodeCooldown.value = Math.max(0, deletionCodeCooldown.value - 1);
|
||
if (deletionCodeCooldown.value === 0) stopDeletionCodeCooldown();
|
||
}, 1000);
|
||
};
|
||
const openPermanentDeletion = () => {
|
||
if (!canDeletePermanently.value || permanentDeletionSubmitting.value) return;
|
||
permanentDeletionConfirmationName.value = "";
|
||
permanentDeletionSmsCode.value = "";
|
||
permanentDeletionError.value = "";
|
||
permanentDeletionVisible.value = true;
|
||
};
|
||
const closePermanentDeletion = () => {
|
||
if (permanentDeletionSubmitting.value || deletionCodeSending.value) return;
|
||
permanentDeletionVisible.value = false;
|
||
permanentDeletionError.value = "";
|
||
};
|
||
const sendPermanentDeletionCode = async () => {
|
||
if (!canDeletePermanently.value || deletionCodeSending.value || permanentDeletionSubmitting.value || deletionCodeCooldown.value > 0) return;
|
||
deletionCodeSending.value = true;
|
||
permanentDeletionError.value = "";
|
||
try {
|
||
await genealogyApi.sendPermanentDeletionCode(
|
||
genealogyId.value,
|
||
{ requestController: deletionCodeRequestController },
|
||
);
|
||
if (!pageActive || !permanentDeletionVisible.value) return;
|
||
startDeletionCodeCooldown(60);
|
||
} catch (error) {
|
||
if (pageActive && permanentDeletionVisible.value && !isRequestCancelled(error)) {
|
||
permanentDeletionError.value = getRequestErrorMessage(error, "删除验证码发送失败,请稍后重试。");
|
||
}
|
||
} finally {
|
||
if (pageActive) deletionCodeSending.value = false;
|
||
}
|
||
};
|
||
const confirmPermanentDeletion = async () => {
|
||
if (!canDeletePermanently.value || permanentDeletionSubmitting.value) return;
|
||
if (permanentDeletionConfirmationName.value.trim() !== form.genealogyName.trim()) {
|
||
permanentDeletionError.value = "输入的谱名与当前家谱不一致。";
|
||
return;
|
||
}
|
||
if (!/^\d{4}$/.test(permanentDeletionSmsCode.value)) {
|
||
permanentDeletionError.value = "请输入4位短信验证码。";
|
||
return;
|
||
}
|
||
const payload = {
|
||
confirmationName: permanentDeletionConfirmationName.value,
|
||
smsCode: permanentDeletionSmsCode.value,
|
||
};
|
||
const deletionAttempt = permanentDeletionGuard.begin(payload);
|
||
if (deletionAttempt === null) {
|
||
permanentDeletionError.value = "上次删除结果待确认,请先返回家谱列表刷新,不要重复提交。";
|
||
return;
|
||
}
|
||
permanentDeletionSubmitting.value = true;
|
||
permanentDeletionError.value = "";
|
||
try {
|
||
await genealogyApi.deleteGenealogyPermanently(
|
||
genealogyId.value,
|
||
payload,
|
||
{ requestController: permanentDeletionRequestController },
|
||
);
|
||
if (!pageActive) return;
|
||
genealogyContext.invalidateCurrentGenealogyId();
|
||
permanentDeletionVisible.value = false;
|
||
await returnTo("G01");
|
||
} catch (error) {
|
||
const isOutcomeUnknown = permanentDeletionGuard.recordFailure(deletionAttempt, error);
|
||
if (!pageActive) return;
|
||
permanentDeletionError.value = isOutcomeUnknown
|
||
? "删除结果待确认,请返回家谱列表刷新,不要重复提交。"
|
||
: getRequestErrorMessage(error, "永久删除失败,请核对验证码后重试。");
|
||
if (!isOutcomeUnknown && isRequestCancelled(error)) permanentDeletionError.value = "";
|
||
} finally {
|
||
if (pageActive) permanentDeletionSubmitting.value = false;
|
||
}
|
||
};
|
||
|
||
const uploadCover = async () => {
|
||
if (isUploading.value || isSubmitting.value) return;
|
||
isUploading.value = true;
|
||
uploadError.value = "";
|
||
try {
|
||
const coverUpload = await pickAndUploadImage({
|
||
requestController: coverUploadRequestController,
|
||
});
|
||
if (!pageActive) return;
|
||
coverOssId.value = coverUpload.ossId;
|
||
coverFileName.value = coverUpload.fileName || "封面图片";
|
||
} catch (error) {
|
||
if (
|
||
pageActive &&
|
||
!isImagePickCancelled(error) &&
|
||
!isRequestCancelled(error)
|
||
) {
|
||
uploadError.value = getRequestErrorMessage(error, "封面图片上传失败,请稍后重试");
|
||
}
|
||
} finally {
|
||
if (pageActive) isUploading.value = false;
|
||
}
|
||
};
|
||
|
||
const clearCover = () => {
|
||
if (isUploading.value || isSubmitting.value) return;
|
||
coverOssId.value = null;
|
||
coverFileName.value = "";
|
||
uploadError.value = "";
|
||
};
|
||
|
||
const submitUpdate = async () => {
|
||
if (isSubmitting.value || isUploading.value || !validate()) return;
|
||
const access = toApiGenealogyAccess(form.accessPreset);
|
||
if (!access) {
|
||
submitError.value = "请选择家谱开放方式";
|
||
return;
|
||
}
|
||
isSubmitting.value = true;
|
||
submitError.value = "";
|
||
try {
|
||
await genealogyApi.updateGenealogy(
|
||
genealogyId.value,
|
||
{
|
||
surname: form.surname,
|
||
genealogyName: form.genealogyName,
|
||
regionCode: selectedRegion.value?.regionCode || currentRegionCode.value,
|
||
ancestralHall: form.ancestralHall,
|
||
originPlace: form.originPlace,
|
||
addressDetail: form.addressDetail,
|
||
intro: form.intro,
|
||
coverOssId: coverOssId.value,
|
||
...access,
|
||
},
|
||
{ requestController: settingsSaveRequestController },
|
||
);
|
||
if (!pageActive) return;
|
||
pageState.value = "success";
|
||
} catch (error) {
|
||
if (!pageActive || isRequestCancelled(error)) return;
|
||
submitError.value = getRequestErrorMessage(error, "家谱设置保存失败,请稍后重试");
|
||
} finally {
|
||
if (pageActive) isSubmitting.value = false;
|
||
}
|
||
};
|
||
|
||
const returnToOverview = () =>
|
||
hasValidContext.value
|
||
? returnTo("G05", { genealogyId: genealogyId.value })
|
||
: goBack();
|
||
const requestBack = async () => {
|
||
if (regionPickerVisible.value) {
|
||
regionPickerDialog.value?.close();
|
||
return true;
|
||
}
|
||
if (lifecycleDialogVisible.value) {
|
||
lifecycleDialogVisible.value = false;
|
||
return true;
|
||
}
|
||
if (permanentDeletionVisible.value) {
|
||
closePermanentDeletion();
|
||
return true;
|
||
}
|
||
if (discardVisible.value) {
|
||
cancelDiscard();
|
||
return true;
|
||
}
|
||
if (isSubmitting.value || isUploading.value || lifecycleSubmitting.value || permanentDeletionSubmitting.value || deletionCodeSending.value) return true;
|
||
if (isDirty.value && !(await requestDiscardConfirmation())) return false;
|
||
return returnToOverview();
|
||
};
|
||
const handleStateAction = () =>
|
||
pageState.value === "success" ? returnToOverview() : loadSettings();
|
||
|
||
onLoad((query) => {
|
||
genealogyId.value = String(query?.genealogyId || "");
|
||
});
|
||
onMounted(() => {
|
||
void loadSettings();
|
||
});
|
||
onBackPress((event) => handleBackPress(event, requestBack));
|
||
onUnload(() => {
|
||
pageActive = false;
|
||
settingsReadRequestController.abort();
|
||
deletionCapabilityReadRequestController.abort();
|
||
genealogyLifecycleRequestController.abort();
|
||
deletionCodeRequestController.abort();
|
||
permanentDeletionRequestController.abort();
|
||
coverUploadRequestController.abort();
|
||
settingsSaveRequestController.abort();
|
||
stopDeletionCodeCooldown();
|
||
discardConfirmation.dispose();
|
||
});
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@import "../../styles/adaptive-frame-profiles.scss";
|
||
|
||
.settings-page {
|
||
display: flex;
|
||
min-height: 100vh;
|
||
flex-direction: column;
|
||
background: $paper;
|
||
}
|
||
.page-header,
|
||
.page-content {
|
||
z-index: 1;
|
||
}
|
||
.page-content {
|
||
flex: 1;
|
||
padding: 24rpx 32rpx calc(72rpx + env(safe-area-inset-bottom));
|
||
}
|
||
.settings-card,
|
||
.state-card {
|
||
@include adaptive-genealogy-state-panel;
|
||
box-sizing: border-box;
|
||
}
|
||
.settings-card {
|
||
padding: 42rpx 38rpx;
|
||
}
|
||
.settings-card__title,
|
||
.settings-card__note,
|
||
.field-error,
|
||
.submit-error {
|
||
display: block;
|
||
}
|
||
.settings-card__title {
|
||
color: $ink;
|
||
font-family: STKaiti, KaiTi, serif;
|
||
font-size: clamp(20px, 40rpx, 26px);
|
||
font-weight: 700;
|
||
}
|
||
.settings-card__note {
|
||
margin-top: 12rpx;
|
||
color: $ink-muted;
|
||
font-size: clamp(15px, 24rpx, 18px);
|
||
line-height: 1.55;
|
||
}
|
||
.field-row {
|
||
display: flex;
|
||
min-height: 100rpx;
|
||
align-items: center;
|
||
margin-top: 22rpx;
|
||
padding: 0 20rpx;
|
||
border: 1rpx solid rgba(128, 89, 49, 0.34);
|
||
border-radius: 12rpx;
|
||
background: rgba(255, 252, 245, 0.7);
|
||
}
|
||
.field-row__label {
|
||
width: 184rpx;
|
||
flex: 0 0 auto;
|
||
color: $ink;
|
||
font-family: STKaiti, KaiTi, serif;
|
||
font-size: clamp(17px, 30rpx, 22px);
|
||
font-weight: 700;
|
||
white-space: nowrap;
|
||
}
|
||
.required-mark {
|
||
display: inline-block;
|
||
margin-right: 4rpx;
|
||
color: $brand-red;
|
||
font-size: clamp(16px, 26rpx, 20px);
|
||
line-height: 1;
|
||
transform: translateY(-3rpx);
|
||
}
|
||
.field-row input {
|
||
min-width: 0;
|
||
min-height: var(--app-touch-min);
|
||
flex: 1;
|
||
color: $ink;
|
||
font-size: clamp(16px, 28rpx, 20px);
|
||
}
|
||
.field-row--selector {
|
||
justify-content: space-between;
|
||
cursor: pointer;
|
||
}
|
||
.region-selector-value {
|
||
min-width: 0;
|
||
flex: 1;
|
||
color: $ink;
|
||
font-size: clamp(16px, 28rpx, 20px);
|
||
text-align: right;
|
||
overflow-wrap: anywhere;
|
||
}
|
||
.permanent-deletion { margin-top: 30rpx; padding: 24rpx; border: 1rpx solid rgba(158, 37, 27, .34); border-radius: 10rpx; background: rgba(158, 37, 27, .05); }
|
||
.permanent-deletion > text { display: block; color: $ink-muted; font-size: clamp(13px, 22rpx, 16px); line-height: 1.55; }
|
||
.permanent-deletion > text:first-child { color: $brand-red; font-size: clamp(16px, 27rpx, 20px); font-weight: 700; }
|
||
.permanent-deletion > text + text { margin-top: 8rpx; }
|
||
.permanent-deletion .app-button { margin-top: 18rpx; }
|
||
.deletion-dialog-input { width: 100%; min-height: var(--app-touch-min); margin-top: 14rpx; padding: 0 18rpx; box-sizing: border-box; border: 1rpx solid rgba(158, 37, 27, .3); border-radius: 8rpx; background: rgba(255, 255, 255, .7); }
|
||
.deletion-code-row { display: flex; align-items: center; gap: 12rpx; }
|
||
.deletion-code-row .deletion-dialog-input { min-width: 0; flex: 1; }
|
||
.deletion-code-row .app-button { width: auto; flex: 0 0 auto; margin-top: 14rpx; }
|
||
.lifecycle-note,
|
||
.lifecycle-actions {
|
||
margin-top: 20rpx;
|
||
padding: 20rpx 22rpx;
|
||
border: 1rpx solid rgba(159, 23, 15, 0.26);
|
||
border-radius: 10rpx;
|
||
background: rgba(159, 23, 15, 0.05);
|
||
}
|
||
.lifecycle-note text,
|
||
.lifecycle-actions text { display: block; color: $ink-muted; font-size: clamp(14px, 22rpx, 17px); line-height: 1.55; }
|
||
.lifecycle-note text:first-child { color: $brand-red; font-weight: 700; }
|
||
.lifecycle-actions .app-button { margin-top: 18rpx; }
|
||
.region-selector-chevron {
|
||
width: 28rpx;
|
||
height: 28rpx;
|
||
margin-left: 12rpx;
|
||
flex: 0 0 auto;
|
||
opacity: 0.7;
|
||
}
|
||
.region-selector-value--placeholder,
|
||
.placeholder {
|
||
color: #ab9a86;
|
||
}
|
||
.intro-field,
|
||
.cover-field {
|
||
margin-top: 22rpx;
|
||
padding: 20rpx;
|
||
border: 1rpx solid rgba(128, 89, 49, 0.34);
|
||
border-radius: 12rpx;
|
||
background: rgba(255, 252, 245, 0.7);
|
||
}
|
||
.intro-field__label,
|
||
.cover-field__label {
|
||
display: block;
|
||
color: $ink;
|
||
font-family: STKaiti, KaiTi, serif;
|
||
font-size: clamp(17px, 30rpx, 22px);
|
||
font-weight: 700;
|
||
}
|
||
.intro-field textarea {
|
||
display: block;
|
||
width: 100%;
|
||
min-height: 120rpx;
|
||
margin-top: 14rpx;
|
||
color: $ink;
|
||
font-size: clamp(16px, 27rpx, 20px);
|
||
line-height: 1.55;
|
||
}
|
||
.cover-field {
|
||
display: grid;
|
||
gap: 12rpx;
|
||
}
|
||
.cover-field__hint {
|
||
display: block;
|
||
margin-top: 6rpx;
|
||
color: $ink-muted;
|
||
font-size: clamp(13px, 21rpx, 16px);
|
||
line-height: 1.45;
|
||
}
|
||
.upload-button {
|
||
justify-self: start;
|
||
min-height: 88rpx;
|
||
margin: 0;
|
||
padding: 0 20rpx;
|
||
border: 1rpx solid rgba(159, 23, 15, 0.42);
|
||
border-radius: 8rpx;
|
||
background: transparent;
|
||
color: $brand-red;
|
||
font-size: clamp(14px, 22rpx, 17px);
|
||
}
|
||
.upload-receipt {
|
||
color: $ink-muted;
|
||
font-size: clamp(13px, 21rpx, 16px);
|
||
overflow-wrap: anywhere;
|
||
}
|
||
.remove-cover-button {
|
||
justify-self: start;
|
||
min-height: 72rpx;
|
||
margin: 0;
|
||
padding: 0 18rpx;
|
||
border: 1rpx solid rgba($brand-red, 0.38);
|
||
border-radius: 8rpx;
|
||
background: transparent;
|
||
color: $brand-red;
|
||
font-size: clamp(13px, 21rpx, 16px);
|
||
}
|
||
.remove-cover-button::after { border: 0; }
|
||
.field-error,
|
||
.submit-error {
|
||
margin-top: 10rpx;
|
||
color: $brand-red;
|
||
font-size: clamp(15px, 24rpx, 18px);
|
||
line-height: 1.5;
|
||
}
|
||
.access-rule {
|
||
margin-top: 28rpx;
|
||
}
|
||
.access-rule__label {
|
||
color: $ink;
|
||
font-family: STKaiti, KaiTi, serif;
|
||
font-size: clamp(17px, 31rpx, 22px);
|
||
font-weight: 700;
|
||
}
|
||
.access-rule__options {
|
||
display: flex;
|
||
margin-top: 16rpx;
|
||
gap: 16rpx;
|
||
}
|
||
.access-rule__option {
|
||
flex: 1;
|
||
display: flex;
|
||
min-height: 88rpx;
|
||
box-sizing: border-box;
|
||
align-items: center;
|
||
justify-content: center;
|
||
padding: 20rpx 12rpx;
|
||
border: 1rpx solid rgba(128, 89, 49, 0.34);
|
||
border-radius: 12rpx;
|
||
color: $ink-muted;
|
||
font-size: clamp(15px, 25rpx, 18px);
|
||
text-align: center;
|
||
}
|
||
.access-rule__option--active {
|
||
border-color: $brand-red;
|
||
background: rgba(159, 23, 15, 0.07);
|
||
color: $brand-red;
|
||
font-weight: 700;
|
||
}
|
||
.settings-card .app-button {
|
||
margin-top: 32rpx;
|
||
}
|
||
.state-card {
|
||
min-height: 340rpx;
|
||
padding: 78rpx 52rpx 50rpx;
|
||
text-align: center;
|
||
}
|
||
.state-card text {
|
||
display: block;
|
||
}
|
||
.state-card text:first-child {
|
||
color: $ink;
|
||
font-family: STKaiti, KaiTi, serif;
|
||
font-size: clamp(19px, 35rpx, 24px);
|
||
font-weight: 700;
|
||
}
|
||
.state-card text:nth-child(2) {
|
||
margin-top: 18rpx;
|
||
color: $ink-muted;
|
||
font-size: clamp(15px, 24rpx, 18px);
|
||
line-height: 1.65;
|
||
}
|
||
.state-card .app-button {
|
||
margin-top: 28rpx;
|
||
}
|
||
</style>
|