← 返回 Skills 市场
chenxiaoyu0124-web

AntV S2 海量数据表格指南

作者 chenxiaoyu0124-web · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
145
总下载
0
收藏
0
当前安装
2
版本数
在 OpenClaw 中安装
/install antd-table-s2-guide
功能描述
AntV S2 表格渲染千万级数据,支持透视、明细表、多维分析,提供性能优化和Vue3集成方案。
使用说明 (SKILL.md)

AntV S2 海量数据表格指南

核心概念

import { PivotSheet, TableSheet, S2Options, S2Event } from '@antv/s2'

// PivotSheet - 透视分析表(行头+列头交叉)
// TableSheet - 明细表(扁平数据,无行列头)

Vue3 集成模板

\x3Ctemplate>
  \x3Cdiv ref="containerRef" class="s2-container" />
\x3C/template>

\x3Cscript setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { PivotSheet } from '@antv/s2'

const containerRef = ref\x3CHTMLDivElement>()

let s2Instance: PivotSheet | null = null

onMounted(() => {
  const container = containerRef.value!
  s2Instance = new PivotSheet(container, s2Options)
  s2Instance.render()
})

onBeforeUnmount(() => {
  s2Instance?.dispose()
})
\x3C/script>

\x3Cstyle scoped>
.s2-container {
  width: 100%;
  height: 600px; /* 必须有明确高度 */
}
\x3C/style>

透视表配置

const s2Options: S2Options = {
  width: 800,
  height: 600,
  hierarchyType: 'grid', // 'grid' | 'tree'

  // 数据字段定义
  fields: {
    rows: ['province', 'city'],      // 行维度
    columns: ['category', 'product'], // 列维度
    values: ['sales', 'profit'],      // 度量值
    valueInCols: true,                // 指标在列头展示
  },

  // 数据
  data: rawData,

  // 主题
  theme: {
    name: 'default',
    palette: {
      // 自定义条件格式色阶
      condition: {
        positive: { fill: '#29A294' },
        negative: { fill: '#E86452' },
      },
    },
  },

  // 交互
  interaction: {
    hoverHighlight: true,
    selectedCellsSpotlight: true,
    linkFields: ['product'], // 可点击的字段
  },
}

性能优化

1. 虚拟滚动(大数据量必备)

const s2Options: S2Options = {
  // S2 默认开启虚拟滚动,但需要确保:
  // 1. 容器有明确高度
  // 2. 不要关闭 frozenRowCount / frozenColCount 中的大量行列
  frozenRowCount: 1,   // 只冻结表头
  frozenColCount: 0,   // 冻结列越多性能越差
  scrollSpeedRatio: {
    horizontal: 0.3,    // 水平滚动速度
    vertical: 0.3,
  },
}

2. 条件格式优化

// ❌ 避免:每个单元格都计算样式
// ✅ 正确:用内置条件格式规则
const conditions = {
  text: [
    {
      field: 'status',
      mapping: (value) => {
        if (value === '异常') return { fill: '#E86452', textFill: '#fff' }
        return {}
      },
    },
  ],
  background: [
    {
      field: 'sales',
      mapping: (value) => {
        // 用线性插值,不要用分段判断
        const ratio = Math.min(Math.abs(value) / 10000, 1)
        return { fill: `rgba(232, 100, 82, ${ratio * 0.3})` }
      },
    },
  ],
}

3. 大数据量数据准备

// ❌ 前端一次性处理 10 万+ 行
// ✅ 分页加载 + 服务端聚合
async function loadData(page: number, size: number) {
  const res = await fetch(`/api/data?page=${page}&size=${size}`)
  return res.json()
}

// S2 支持动态更新数据
s2Instance.setData(newData)

4. 减少不必要的重渲染

// ❌ 频繁更新
watch(searchQuery, () => {
  s2Instance.setData(filteredData) // 每次输入都触发
})

// ✅ 防抖更新
import { useDebounceFn } from '@vueuse/core'
const debouncedUpdate = useDebounceFn((data) => {
  s2Instance.setData(data)
}, 300)

watch(searchQuery, () => {
  debouncedUpdate(filteredData.value)
})

明细表(TableSheet)

import { TableSheet } from '@antv/s2'

const tableSheet = new TableSheet(container, {
  fields: {
    columns: ['id', 'name', 'value', 'status', 'date'],
  },
  data: tableData,
  // 明细表专用配置
  style: {
    cellCfg: {
      width: 120,
      height: 36,
    },
  },
})

常用事件

// 单元格点击
s2Instance.on(S2Event.DATA_CELL_CLICK, (event) => {
  console.log('clicked:', event)
})

// 链接字段点击
s2Instance.on(S2Event.GLOBAL_LINK_FIELD_JUMP, (data) => {
  window.open(data.fieldValue)
})

// 排序
s2Instance.on(S2Event.RANGE_SORTED, (data) => {
  console.log('sorted:', data)
})

踩坑记录

  1. 容器必须有明确高度,否则 S2 无法计算虚拟滚动区域
  2. frozenColCount 不要超过 3,冻结列越多渲染压力越大
  3. setData 会重新渲染,大数据量时配合防抖使用
  4. theme 修改要重新调用 setTheme(),不能直接改 options
  5. Vue3 中要在 onBeforeUnmount 调用 dispose(),否则内存泄漏
安全使用建议
This skill is a documentation-style guide and appears internally consistent. Before using code from the guide in production: (1) review and adapt the example fetch endpoints to point at your trusted backends (do not paste secrets into requests or query parameters), (2) verify package versions and compatibility with your project, (3) test large-data behavior in a development environment, and (4) note the metadata (author/licensing/pricing) in clawhub.json if you plan to purchase or distribute — the skill itself does not perform any network calls or require credentials.
能力评估
Purpose & Capability
The name/description (AntV S2 large-data table guide) matches the SKILL.md content: code samples, Vue3 integration, and performance tips. There are no unexpected required binaries, environment variables, or credentials.
Instruction Scope
SKILL.md contains only documentation and example code for S2 usage, data loading patterns, and event handlers. The only network reference is an example fetch('/api/data?page=...'), which is a normal example for data loading and not an instruction to contact a hidden endpoint. The guide does not instruct reading local files, accessing unrelated env vars, or exfiltrating data.
Install Mechanism
No install spec and no code files beyond documentation — this is the lowest-risk pattern (instruction-only). Nothing is downloaded or written to disk by the skill itself.
Credentials
The skill declares no required environment variables, credentials, or config paths. There are no requests for secrets or unrelated API keys in the content.
Persistence & Privilege
always is false and the skill is user-invocable. It does not request persistent presence or attempt to modify other skills or system settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install antd-table-s2-guide
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /antd-table-s2-guide 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.0
新增定价,内容不变
v1.0.0
初始发布:Vue3集成+性能调优+踩坑
元数据
Slug antd-table-s2-guide
版本 1.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 2
常见问题

AntV S2 海量数据表格指南 是什么?

AntV S2 表格渲染千万级数据,支持透视、明细表、多维分析,提供性能优化和Vue3集成方案。 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 145 次。

如何安装 AntV S2 海量数据表格指南?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install antd-table-s2-guide」即可一键安装,无需额外配置。

AntV S2 海量数据表格指南 是免费的吗?

是的,AntV S2 海量数据表格指南 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

AntV S2 海量数据表格指南 支持哪些平台?

AntV S2 海量数据表格指南 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 AntV S2 海量数据表格指南?

由 chenxiaoyu0124-web(@chenxiaoyu0124-web)开发并维护,当前版本 v1.1.0。

💬 留言讨论