Skip to content

扩展示例库

示例一:发送企业微信通知

当用户点击按钮时,向企业微信推送消息。

扩展配置:

json
{
  "name": "wecom-notify",
  "clicks": [
    {
      "label": "通知客户",
      "handle": "http://mysite.app/api/wecom/notify",
      "confirm": "确定要向客户发送微信通知吗?"
    }
  ]
}

后端实现(Node.js):

javascript
app.post('/api/wecom/notify', async (req, res) => {
  const record = req.body; // 当前行数据
  
  await fetch('https://qyapi.weixin.qq.com/cgi-bin/message/send', {
    method: 'POST',
    body: JSON.stringify({
      touser: record.owner_wecom_id,
      msgtype: 'text',
      text: { content: `订单 ${record.order_no} 已处理完成` }
    })
  });

  res.json({ success: true, message: '通知已发送' });
});

示例二:嵌入自定义图表

在详情页中展示该客户的销售趋势图表。

扩展配置:

json
{
  "name": "sales-chart",
  "views": [
    {
      "label": "销售趋势",
      "type": "embed",
      "handle": "http://mysite.app/api/chart/sales",
      "target": "detail"
    }
  ]
}

后端返回 HTML:

javascript
app.post('/api/chart/sales', async (req, res) => {
  const { _id } = req.body;
  const data = await getSalesData(_id);
  
  res.json({
    success: true,
    html: `<canvas id="chart"></canvas>
           <script>
             // 使用 Chart.js 渲染
           </script>`
  });
});