All files / src/views/dashboard index.vue

23.4% Statements 11/47
0% Branches 0/18
0% Functions 0/12
28.2% Lines 11/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254                                                            1x                                                                                                 1x                                                   1x 1x 1x                         1x           1x 1x 1x         1x           1x                                                                                                                                                                                                                                    
<script setup>
import { computed, ref } from 'vue'
import { LayoutDashboard } from '@lucide/vue'
import { useRouter } from 'vue-router'
import Button from '@/components/ui/button/button.vue'
import Input from '@/components/ui/input/input.vue'
import FmsTable from '@/components/fms-table/FmsTable.vue'
 
defineOptions({ name: 'Dashboard' })
 
const router = useRouter()
 
// 跳转到详情页(不同 id = 不同路由缓存),用于验证「多参数独立缓存」
function goDetail(id) {
  router.push(`/detail/${id}`)
}
 
/* ---------- fms-table 大数据量 + 单行编辑 demo ---------- */
const TYPE_OPTIONS = [
  { value: 'task', label: '任务' },
  { value: 'job', label: '作业' },
  { value: 'flow', label: '流程' },
  { value: 'alert', label: '告警' },
]
const STATUS_OPTIONS = [
  { value: 'active', label: '启用' },
  { value: 'disabled', label: '禁用' },
  { value: 'pending', label: '待审' },
]
// 额外可编辑文本列数量,与下方业务列合计 20 列
const EXTRA_FIELD_COUNT = 14
 
function makeColumns() {
  const columns = [
    { title: 'ID', dataIndex: 'id', width: 70, editor: { type: 'input', inputType: 'number' } },
    { title: '名称', dataIndex: 'name', width: 120, editor: { type: 'input' } },
    {
      title: '类型',
      dataIndex: 'type',
      width: 90,
      editor: { type: 'select', options: TYPE_OPTIONS },
    },
    {
      title: '状态',
      dataIndex: 'status',
      width: 90,
      editor: { type: 'select', options: STATUS_OPTIONS },
    },
    { title: '启用', dataIndex: 'enabled', width: 64, editor: { type: 'checkbox' } },
    { title: '评分', dataIndex: 'score', width: 80, editor: { type: 'input', inputType: 'number' } },
  ]
  for (let i = 1; i <= EXTRA_FIELD_COUNT; i++) {
    columns.push({
      title: `字段 ${i}`,
      dataIndex: `f${i}`,
      width: 80,
      editor: { type: 'input' },
    })
  }
  return columns
}
 
function makeRows(count) {
  const rows = []
  for (let i = 0; i < count; i++) {
    const row = {
      id: i + 1,
      name: `任务-${String(i + 1).padStart(5, '0')}`,
      type: TYPE_OPTIONS[i % TYPE_OPTIONS.length].value,
      status: STATUS_OPTIONS[i % STATUS_OPTIONS.length].value,
      enabled: i % 2,
      score: Math.round(Math.random() * 1000) / 10,
    }
    for (let j = 1; j <= EXTRA_FIELD_COUNT; j++) row[`f${j}`] = `${i + 1}-${j}`
    rows.push(row)
  }
  return rows
}
 
const DEFAULT_ROW_COUNT = 5000
const columns = ref(makeColumns())
const rowCount = ref(DEFAULT_ROW_COUNT)
const dataSource = ref(makeRows(DEFAULT_ROW_COUNT))
const editCount = ref(0)
 
// 修改行数后重新生成全新数据(行对象全部重建,fms-table 编辑状态随之自然重置)
function regenerate() {
  const count = Math.max(
    1,
    Math.min(100000, Math.floor(Number(rowCount.value)) || DEFAULT_ROW_COUNT),
  )
  rowCount.value = count
  dataSource.value = makeRows(count)
  editCount.value = 0
}
 
// fms-table 编辑提交时回传 (row, col, newValue),这里统计编辑次数
function onCellChange() {
  editCount.value++
}
 
const totalCells = computed(() => columns.value.length * dataSource.value.length)
</script>
 
<template>
  <div class="dashboard-page">
    <header class="dashboard-header">
      <div class="dashboard-heading">
        <div class="dashboard-icon" aria-hidden="true">
          <LayoutDashboard />
        </div>
        <div>
          <h1 class="dashboard-title">工作台 · fms-table Demo</h1>
          <p class="dashboard-desc">
            20 列单行编辑示例:单击单元格进入编辑,Enter 提交,Esc 取消,方向键在单元格间移动。默认
            5000 行(虚拟滚动),可修改行数后「重新生成」。
          </p>
        </div>
      </div>
 
      <div class="dashboard-actions">
        <Button type="primary" @click="goDetail(1)">打开详情 #1</Button>
        <Button type="primary" @click="goDetail(2)">打开详情 #2</Button>
      </div>
    </header>
 
    <section class="demo-card">
      <div class="demo-toolbar">
        <label class="toolbar-field">
          <span class="toolbar-label">行数</span>
          <Input v-model="rowCount" type="number" class="toolbar-input" />
        </label>
        <Button type="primary" @click="regenerate">重新生成</Button>
        <span class="toolbar-meta">
          {{ dataSource.length.toLocaleString() }} 行 × {{ columns.length }} 列(内置序号列不计入),
          共 {{ totalCells.toLocaleString() }} 个单元格 · 已编辑 {{ editCount }} 次
        </span>
      </div>
 
      <div class="demo-table">
        <FmsTable :columns="columns" :data-source="dataSource" row-key="id" @change="onCellChange" />
      </div>
    </section>
  </div>
</template>
 
<style scoped>
.dashboard-page {
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* 页面高度 = fms-content 可视内容高度(100vh - 顶栏40 - 布局gap8 - 页签40 - 内容padding 12+16),
     让滚动条落在表格内部而不是整个页面滚动 */
  height: calc(100vh - 116px);
  color: var(--fms-text);
}
 
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
 
.dashboard-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}
 
.dashboard-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 10px;
  background: color-mix(in srgb, var(--fms-primary) 10%, var(--fms-card));
  color: var(--fms-primary);
 
  :deep(svg) {
    width: 22px;
    height: 22px;
  }
}
 
.dashboard-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}
 
.dashboard-desc {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--fms-text-secondary);
}
 
.dashboard-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
 
/* ---- demo 卡片:工具栏 + 表格 ---- */
.demo-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--fms-border);
  border-radius: 8px;
  background: var(--fms-card);
}
 
.demo-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--fms-border);
}
 
.toolbar-field {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
 
.toolbar-label {
  font-size: 13px;
  color: var(--fms-text-secondary);
}
 
.toolbar-input {
  width: 120px;
}
 
.toolbar-meta {
  margin-left: auto;
  font-size: 12px;
  color: var(--fms-text-secondary);
}
 
.demo-table {
  flex: 1;
  min-height: 0;
}
</style>