Separate system accounts and household people, add generation directory and consented member location sharing
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<script setup>
|
||||
import {ref,computed,watch} from 'vue'
|
||||
import {bridge,snapshot} from '../composables/bridge.js'
|
||||
const data=ref(null),error=ref(''),busy=ref(false),draft=ref(null),target=ref(''),confirm=ref(false)
|
||||
const active=computed(()=>snapshot.value.loggedIn&&snapshot.value.page==='members')
|
||||
const homes=computed(()=>(snapshot.value.state.households||[]).filter(h=>h.id!==snapshot.value.state.familyId))
|
||||
let epoch=0
|
||||
async function load(){const e=++epoch;try{const value=await bridge().api('/api/members');if(e===epoch)data.value=value}catch(err){if(e===epoch)error.value=err.message}}
|
||||
watch([active,()=>snapshot.value.state.familyId,()=>snapshot.value.session],()=>{epoch++;data.value=null;draft.value=null;error.value='';target.value='';confirm.value=false;busy.value=false;if(active.value)load()},{immediate:true})
|
||||
function edit(member){draft.value=member?{id:member.id,revision:member.revision,personId:member.personId,name:member.name,label:member.label,status:member.status}:{name:'',personId:'',label:'',status:'active',revision:0}}
|
||||
async function save(){if(busy.value)return;busy.value=true;error.value='';const e=epoch;try{await bridge().api('/api/members',draft.value);if(e!==epoch)return;draft.value=null;await load();await bridge().refresh()}catch(err){if(e===epoch)error.value=err.message}finally{busy.value=false}}
|
||||
async function share(){if(busy.value)return;busy.value=true;error.value='';const e=epoch;try{await bridge().api('/api/genealogy/share',{targetFamilyId:target.value,confirm:confirm.value});if(e!==epoch)return;confirm.value=false;target.value='';await load();await bridge().refresh()}catch(err){if(e===epoch)error.value=err.message}finally{busy.value=false}}
|
||||
</script>
|
||||
<template><section v-if="active" class="panel">
|
||||
<div class="d-flex justify-content-between flex-wrap gap-3"><div><h2>家庭成员</h2><p class="text-secondary">登记真实家人。老人、孩子无需账号;亲属关系与登录权限分别管理。</p></div><button v-if="data?.canManage" class="btn btn-primary align-self-start" @click="edit()">+ 登记成员</button></div>
|
||||
<p v-if="error" class="alert alert-danger" role="alert">{{error}}</p>
|
||||
<form v-if="draft" class="border rounded p-3 mb-4" @submit.prevent="save">
|
||||
<h3 class="fs-5">{{draft.id?'编辑成员关系':'登记家庭成员'}}</h3>
|
||||
<label v-if="!draft.id" class="d-block mb-3">关联已有族谱人物<select class="form-select" v-model="draft.personId"><option value="">新建人物(尚未录入族谱)</option><option v-for="p in data?.candidates||[]" :key="p.id" :value="p.id">{{p.name}}</option></select></label>
|
||||
<label v-if="!draft.personId" class="d-block mb-3">姓名<input v-model="draft.name" class="form-control" maxlength="80" required></label><p v-else-if="draft.id">人物:{{draft.name}}。姓名、生平及亲属关系在族谱中维护,仍遵守五代限制。</p>
|
||||
<div class="row g-3"><label class="col-md-6">家庭称呼/身份备注<input v-model="draft.label" class="form-control" maxlength="60" placeholder="例如:妈妈、长子、亲友"></label><label class="col-md-6">成员状态<select v-model="draft.status" class="form-select"><option value="active">当前成员</option><option value="away">暂住外地</option><option value="historical">历史成员</option></select></label></div>
|
||||
<p class="small text-secondary mt-2">称呼是本家庭的备注,不自动建立父母、配偶关系或授予管理权限。迁居、历史成员状态不会删除人物和经历。</p>
|
||||
<div class="d-flex gap-2"><button class="btn btn-primary" :disabled="busy">保存成员</button><button type="button" class="btn btn-outline-secondary" :disabled="busy" @click="draft=null">取消</button></div>
|
||||
</form>
|
||||
<div class="row g-3"><article v-for="m in data?.items||[]" :key="m.id" class="col-md-6 col-xl-4"><div class="card h-100"><div class="card-body"><h3 class="fs-5">{{m.name}} <span v-if="m.self" class="badge text-bg-success">本人</span></h3><p>{{m.label||'家庭身份待补充'}} · {{({active:'当前成员',away:'暂住外地',historical:'历史成员'})[m.status]}}</p><p class="small text-secondary">{{m.hasAccount?'已有关联账号':'无需注册账号'}}{{m.lifeStatus==='deceased'?' · 已故':''}}</p><button v-if="data.canManage" class="btn btn-sm btn-outline-secondary" @click="edit(m)">编辑成员关系</button></div></div></article></div>
|
||||
<p v-if="data&&!data.items.length" class="alert alert-info mt-3">还没有登记成员。已有族谱人物可直接关联,避免重复建人。</p>
|
||||
<details v-if="snapshot.platformAdmin" class="border-top pt-3 mt-4"><summary>与相关家庭共用族谱</summary><p class="small text-secondary mt-2">相关家庭共用人物与亲属关系;活动、设备、位置授权继续独立。现有同名人物不会自动合并,需核对身份。世代范围限制继续有效。</p><p>当前已关联:{{data?.genealogyHomes?.map(h=>h.name).join('、')}}</p><form @submit.prevent="share"><label>关联家庭<select v-model="target" class="form-select" required><option value="">请选择</option><option v-for="h in homes" :value="h.id" :key="h.id">{{h.name}}</option></select></label><label class="d-flex gap-2 my-3"><input v-model="confirm" type="checkbox" required>确认双方族谱人物与关系共用,有族谱查看权限的账号可以查看合并后的族谱</label><button class="btn btn-outline-primary" :disabled="busy||!confirm||!target">确认共用族谱</button></form></details>
|
||||
</section></template>
|
||||
Reference in New Issue
Block a user