Skip to content

Claude Code Skill

@fu/matrix 的 Claude Code Skill,让 AI 助手能够理解并帮助你使用 Matrix 工具函数。

功能特点

  • 函数查询:询问任何 Matrix 函数的作用、参数和返回值
  • 使用场景:了解何时应该使用哪些工具函数
  • 代码示例:获取实用的代码示例和最佳实践
  • 场景判断:帮助你判断当前环境并选择合适的函数

触发场景

当你向 Claude Code 询问以下内容时,Skill 会自动激活:

  • 询问 Matrix 有哪些函数可用
  • 需要实现环境检测、数据格式化、平台判断等功能
  • 需要使用存储、防抖节流、登录认证、页面跳转等操作
  • 询问字符串/数字格式化、浏览器操作等

使用方法

在 Claude Code 中直接提问,例如:

如何使用 Matrix 检测当前是否在期货 App 中?
Matrix 有哪些数字格式化的函数?
帮我用 debounce 函数包装一个搜索接口

快速参考

环境检测

函数说明
isPC()检测是否为 PC 环境
isIPhone()检测是否为 iPhone 环境
isGPhone()检测是否为安卓环境
isHarmony()检测是否为鸿蒙环境
isInFuturesApp()检测是否在期货 App 中
isInThsApp()检测是否在同花顺 App 中
isDark()检测当前是否为暗色主题

数字格式化

函数说明
formatNumber(value, options)格式化数字,可设置精度、分隔符、前后缀
formatPercent(value, options)格式化百分比,支持带 % 的字符串输入

存储

函数说明
createLocalStorage(key)创建本地存储实例
createSessionStorage(key)创建会话存储实例

性能优化

函数说明
debounce(fn, delay)防抖函数
throttle(fn, interval)节流函数

登录认证

函数说明
login()跳转客户端登录页面
isLogin()检查当前登录状态
checkLogin(cb)校验登录状态,未登录则跳转

页面跳转

函数说明
jumpWeb(url, title)移动端页面跳转
goBack()移动端返回上一页
jumpFenshi(code)移动端跳转分时图

CDN 使用

使用 CDN 引入时,window 上会暴露以下全局对象:

全局对象说明
window.fuMatrix包含所有工具函数的全局对象
window.MatrixToolsMatrix WebMCP Client 实例
window.executeMatrixTool底层全局执行函数

Claude Code Skill 安装

bash
claude plugin install matrix@futures-plugins-frontend

安装后,Claude Code 会自动识别 Matrix 相关问题,直接提问即可使用。

@fu/matrix 安装

bash
npm install @fu/matrix

pnpm add @fu/matrix

或 CDN:

html
<script src="https://futures-test.10jqka.com.cn/matrix/lib/matrix-latest.min.js"></script>

示例

格式化数字:

ts
formatNumber(1234.56)                           // "1,234.56"
formatNumber(1234.56, { precision: 0 })         // "1,235"
formatNumber(1234.56, { prefix: '¥' })          // "¥1,234.56"
formatPercent("50%")                             // "50.00%"
formatPercent(0.5, { precision: 0 })            // "50%"

存储:

ts
const storage = createLocalStorage('myapp');
storage.set('theme', 'dark');
storage.get('theme');          // → 'dark'
storage.setMultiple({ a: 1, b: 2 });
storage.rm('a');
storage.clean();

登录校验:

ts
if (!isLogin()) {
  login();
}

checkLogin(() => {
  console.log('已登录,执行后续逻辑');
});

环境检测:

ts
if (isInFuturesApp()) {
  // 在期货App中
}

if (isDark()) {
  document.body.classList.add('dark');
}