298 lines
9.1 KiB
Vue
298 lines
9.1 KiB
Vue
<template>
|
|
<aside class="map-tree" aria-label="目标树">
|
|
<div class="tree-head">
|
|
<span class="tree-title">目标树</span>
|
|
<span class="tree-total">{{ visibleCount }} / {{ totalCount }} 个目标</span>
|
|
</div>
|
|
|
|
<div class="tree-scroll">
|
|
<section v-for="g in groups" :key="g.key" class="tree-group">
|
|
<button type="button" class="group-head" @click="$emit('toggle-group', g.key)">
|
|
<svg
|
|
class="chev" :class="{ folded: collapsed[g.key] }"
|
|
viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"
|
|
><path d="M6 9l6 6 6-6" /></svg>
|
|
<span class="group-dot" :style="{ background: g.color }"></span>
|
|
<span class="group-label">{{ g.label }}</span>
|
|
<span class="group-count">{{ g.objectives.length }}</span>
|
|
</button>
|
|
|
|
<div v-if="!collapsed[g.key]" class="group-body">
|
|
<div v-if="g.objectives.length === 0" class="group-empty">
|
|
<span>{{ search || filter !== 'all' ? '无匹配目标' : '该层暂无目标' }}</span>
|
|
<button type="button" class="link-btn" @click="$emit('add-objective', g.key)">去创建</button>
|
|
</div>
|
|
|
|
<div
|
|
v-for="o in g.objectives"
|
|
:key="o.key"
|
|
class="tree-node"
|
|
:class="{ active: activeKey === o.key, dimmed: !!search }"
|
|
draggable="true"
|
|
:title="'拖到画布中的另一个目标上可建立因果连线'"
|
|
@dragstart="onDragStart($event, o)"
|
|
@dragend="$emit('drag-end')"
|
|
@click="$emit('select', o)"
|
|
>
|
|
<div class="tn-row">
|
|
<button
|
|
v-if="o.krs && o.krs.length"
|
|
type="button"
|
|
class="kr-chev"
|
|
:class="{ open: expanded[o.key] }"
|
|
:aria-label="expanded[o.key] ? '收起关键结果' : '展开关键结果'"
|
|
@click.stop="toggleKr(o.key)"
|
|
>
|
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
|
<path d="M9 6l6 6-6 6" />
|
|
</svg>
|
|
</button>
|
|
<span class="tn-level" :class="'dot-' + (o.level || 'gray')" :title="levelText(o.level)"></span>
|
|
<span class="tn-name" :title="o.name">{{ o.name }}</span>
|
|
</div>
|
|
<div class="tn-meta">
|
|
<span class="tn-rate mono" :class="rateClass(o)">{{ o.hasData && o.ratio != null ? Math.round(o.ratio) + '%' : '无数据' }}</span>
|
|
<span class="tn-sep">·</span>
|
|
<span>{{ o.kpiCount }} KPI</span>
|
|
<span class="tn-sep">·</span>
|
|
<span class="tn-owner" :title="o.owner">{{ o.owner || '未设负责人' }}</span>
|
|
</div>
|
|
<ul v-if="expanded[o.key] && o.krs && o.krs.length" class="kr-list" @click.stop>
|
|
<li v-for="(kr, ki) in o.krs" :key="ki" class="kr-item">
|
|
<span class="kr-idx mono">{{ ki + 1 }}</span>
|
|
<span class="kr-name" :title="kr.name">{{ kr.name || '未命名 KR' }}</span>
|
|
<span v-if="kr.target_value != null && kr.target_value !== ''" class="kr-target mono">目标 {{ kr.target_value }}</span>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<div v-if="totalCount === 0" class="tree-empty">
|
|
<p>当前地图还没有任何目标</p>
|
|
<button type="button" class="link-btn" @click="$emit('add-objective', groups[0]?.key)">
|
|
去创建第一个目标
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="tree-foot">
|
|
<svg class="foot-ico" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true">
|
|
<path d="M12 3v6M12 15v6M3 12h6M15 12h6" /><circle cx="12" cy="12" r="3" />
|
|
</svg>
|
|
拖拽目标到画布可建立因果连线
|
|
</div>
|
|
</aside>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { reactive } from 'vue'
|
|
|
|
interface TreeObjective {
|
|
key: string
|
|
index: number
|
|
name: string
|
|
owner?: string
|
|
level?: string
|
|
ratio: number | null
|
|
hasData: boolean
|
|
kpiCount: number
|
|
krs?: any[]
|
|
raw?: any
|
|
dimKey?: string
|
|
}
|
|
interface TreeGroup {
|
|
key: string
|
|
label: string
|
|
color: string
|
|
objectives: TreeObjective[]
|
|
}
|
|
|
|
const props = defineProps<{
|
|
groups: TreeGroup[]
|
|
search: string
|
|
filter: 'all' | 'risk' | 'nodata'
|
|
activeKey: string | null
|
|
collapsed: Record<string, boolean>
|
|
visibleCount: number
|
|
totalCount: number
|
|
}>()
|
|
|
|
const emit = defineEmits<{
|
|
(e: 'select', o: any): void
|
|
(e: 'toggle-group', key: string): void
|
|
(e: 'add-objective', key?: string): void
|
|
(e: 'drag-start', payload: { dimKey: string; index: number; obj: any; event: DragEvent }): void
|
|
(e: 'drag-end'): void
|
|
}>()
|
|
|
|
const expanded = reactive<Record<string, boolean>>({})
|
|
|
|
function toggleKr(key: string) {
|
|
expanded[key] = !expanded[key]
|
|
}
|
|
|
|
function rateClass(o: TreeObjective) {
|
|
if (!o.hasData || o.ratio == null) return 'rate-gray'
|
|
if (o.ratio >= 90) return 'rate-green'
|
|
if (o.ratio >= 60) return 'rate-yellow'
|
|
return 'rate-red'
|
|
}
|
|
|
|
function levelText(level?: string) {
|
|
if (level === 'green') return '达标'
|
|
if (level === 'yellow') return '关注'
|
|
if (level === 'red') return '风险'
|
|
return '无数据'
|
|
}
|
|
|
|
function onDragStart(e: DragEvent, o: TreeObjective) {
|
|
if (!o.dimKey) return
|
|
try {
|
|
e.dataTransfer?.setData('text/plain', o.key)
|
|
if (e.dataTransfer) e.dataTransfer.effectAllowed = 'link'
|
|
} catch { /* 兼容受限浏览器 */ }
|
|
emit('drag-start', { dimKey: o.dimKey, index: o.index, obj: o.raw, event: e })
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.map-tree {
|
|
width: 272px;
|
|
flex: 0 0 272px;
|
|
display: flex;
|
|
flex-direction: column;
|
|
min-height: 0;
|
|
background: var(--bh-bg-card, #fff);
|
|
border: 1px solid #E5E7EB;
|
|
border-radius: 8px;
|
|
overflow: hidden;
|
|
}
|
|
.tree-head {
|
|
display: flex;
|
|
align-items: baseline;
|
|
justify-content: space-between;
|
|
padding: 10px 12px 6px;
|
|
flex-shrink: 0;
|
|
}
|
|
.tree-title { font-size: 13px; font-weight: 700; color: #0F172A; }
|
|
.tree-total { font-size: 11px; color: #94A3B8; }
|
|
.tree-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 8px; }
|
|
.tree-group { margin-bottom: 6px; }
|
|
.group-head {
|
|
width: 100%;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 5px 6px;
|
|
background: transparent;
|
|
border: 0;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
font-size: 12px;
|
|
color: #475569;
|
|
text-align: left;
|
|
}
|
|
.group-head:hover { background: #F6F7F9; }
|
|
.group-dot { width: 8px; height: 8px; border-radius: 2px; }
|
|
.group-label { flex: 1; font-weight: 600; }
|
|
.group-count { font-size: 11px; color: #94A3B8; }
|
|
.chev { width: 12px; height: 12px; transition: transform .15s; color: #94A3B8; }
|
|
.chev.folded { transform: rotate(-90deg); }
|
|
.group-body { padding: 2px 0 4px; }
|
|
.group-empty {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 8px 10px;
|
|
font-size: 11px;
|
|
color: #94A3B8;
|
|
}
|
|
.link-btn {
|
|
border: 0;
|
|
background: transparent;
|
|
color: #635BFF;
|
|
font-size: 11px;
|
|
cursor: pointer;
|
|
padding: 0;
|
|
}
|
|
.link-btn:hover { text-decoration: underline; }
|
|
.tree-node {
|
|
padding: 6px 8px 6px 10px;
|
|
border-radius: 6px;
|
|
border-left: 3px solid transparent;
|
|
cursor: pointer;
|
|
transition: background .12s;
|
|
}
|
|
.tree-node:hover { background: #F6F7F9; }
|
|
.tree-node.active { background: #F1F0FF; border-left-color: #635BFF; }
|
|
.tn-row { display: flex; align-items: center; gap: 5px; }
|
|
.tn-level { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
|
|
.dot-green { background: #00C896; }
|
|
.dot-yellow { background: #F59E0B; }
|
|
.dot-red { background: #EF4444; }
|
|
.dot-gray { background: #CBD5E1; }
|
|
.tn-name {
|
|
font-size: 12.5px;
|
|
color: #0F172A;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.tn-meta {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
margin-top: 2px;
|
|
padding-left: 12px;
|
|
font-size: 11px;
|
|
color: #94A3B8;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
}
|
|
.tn-owner { overflow: hidden; text-overflow: ellipsis; }
|
|
.tn-rate { font-weight: 600; }
|
|
.rate-green { color: #00C896; }
|
|
.rate-yellow { color: #F59E0B; }
|
|
.rate-red { color: #EF4444; }
|
|
.rate-gray { color: #94A3B8; font-weight: 500; }
|
|
.kr-chev {
|
|
border: 0;
|
|
background: transparent;
|
|
padding: 0;
|
|
width: 12px;
|
|
height: 12px;
|
|
color: #94A3B8;
|
|
cursor: pointer;
|
|
flex-shrink: 0;
|
|
}
|
|
.kr-chev svg { width: 12px; height: 12px; transition: transform .15s; }
|
|
.kr-chev.open svg { transform: rotate(90deg); }
|
|
.kr-list { list-style: none; margin: 4px 0 0 19px; padding: 0; }
|
|
.kr-item {
|
|
display: flex;
|
|
align-items: baseline;
|
|
gap: 5px;
|
|
font-size: 11px;
|
|
color: #64748B;
|
|
line-height: 1.5;
|
|
}
|
|
.kr-idx { color: #94A3B8; }
|
|
.kr-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
.kr-target { color: #94A3B8; }
|
|
.tree-empty { padding: 20px 10px; text-align: center; font-size: 12px; color: #94A3B8; }
|
|
.tree-empty p { margin: 0 0 6px; }
|
|
.tree-foot {
|
|
flex-shrink: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 5px;
|
|
padding: 7px 12px;
|
|
border-top: 1px solid #E5E7EB;
|
|
font-size: 11px;
|
|
color: #94A3B8;
|
|
}
|
|
.foot-ico { width: 12px; height: 12px; }
|
|
.mono { font-family: 'IBM Plex Mono', Consolas, monospace; font-variant-numeric: tabular-nums; }
|
|
</style>
|