|
| 1 | +# 消息预览 |
| 2 | + |
| 3 | +我们针对卡片消息和 KMarkdown 消息封装了一套消息预览开发工具:[点击使用](https://github.com/laiyuzenb/kook_message_preview) |
| 4 | + |
| 5 | +## 加载 wasm scripts |
| 6 | + |
| 7 | +有以下两种加载方式 |
| 8 | + |
| 9 | +1. 下载 https://cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js 复制代码 至 html 文件中 的 script 标签中 |
| 10 | + |
| 11 | +```html |
| 12 | +<html> |
| 13 | + <head> |
| 14 | + <meta charset="UTF-8" /> |
| 15 | + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| 16 | + <title>Document</title> |
| 17 | + </head> |
| 18 | + |
| 19 | + <body> |
| 20 | + <script> |
| 21 | + //cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js |
| 22 | + https: 里面的代码 |
| 23 | + </script> |
| 24 | + </body> |
| 25 | +</html> |
| 26 | +``` |
| 27 | + |
| 28 | +2. 使用组件时 传入参数 `external=cdn地址` |
| 29 | + 例如以下代码示例都使用 external https://cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js |
| 30 | + |
| 31 | +```js |
| 32 | +import { MessagePreview } from '@kookapp/kook-message-preview' |
| 33 | + |
| 34 | +export default () => ( |
| 35 | + <MessagePreview external="https://cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js" /> |
| 36 | +) |
| 37 | +``` |
| 38 | + |
| 39 | +## 卡片消息基本使用 |
| 40 | + |
| 41 | +这是一个简单的卡片消息例子 |
| 42 | + |
| 43 | +```jsx |
| 44 | +import { MessagePreview } from '@kookapp/kook-message-preview' |
| 45 | + |
| 46 | +const content = [ |
| 47 | + { |
| 48 | + type: 'card', |
| 49 | + size: 'lg', |
| 50 | + theme: 'warning', |
| 51 | + modules: [ |
| 52 | + { |
| 53 | + type: 'header', |
| 54 | + text: { |
| 55 | + type: 'plain-text', |
| 56 | + content: '近期活动公告', |
| 57 | + }, |
| 58 | + }, |
| 59 | + { |
| 60 | + type: 'divider', |
| 61 | + }, |
| 62 | + { |
| 63 | + type: 'section', |
| 64 | + mode: 'left', |
| 65 | + accessory: { |
| 66 | + type: 'image', |
| 67 | + src: 'https://img.kaiheila.cn/assets/2021-01/FckX3MDe6S02i020.png', |
| 68 | + circle: true, |
| 69 | + }, |
| 70 | + text: { |
| 71 | + type: 'plain-text', |
| 72 | + content: |
| 73 | + '社区将在1月20日开启副本速通挑战,参与本次活动的小伙伴均有礼品相送!', |
| 74 | + }, |
| 75 | + }, |
| 76 | + { |
| 77 | + type: 'section', |
| 78 | + text: { |
| 79 | + type: 'kmarkdown', |
| 80 | + content: '**报名方法**', |
| 81 | + }, |
| 82 | + }, |
| 83 | + { |
| 84 | + type: 'section', |
| 85 | + mode: 'right', |
| 86 | + accessory: { |
| 87 | + type: 'button', |
| 88 | + theme: 'primary', |
| 89 | + value: '123', |
| 90 | + text: { |
| 91 | + type: 'plain-text', |
| 92 | + content: '报名', |
| 93 | + }, |
| 94 | + }, |
| 95 | + text: { |
| 96 | + type: 'kmarkdown', |
| 97 | + content: '点击右侧“报名”按钮,即可完成报名。', |
| 98 | + }, |
| 99 | + }, |
| 100 | + { |
| 101 | + type: 'section', |
| 102 | + text: { |
| 103 | + type: 'kmarkdown', |
| 104 | + content: '**挑战奖励**\n', |
| 105 | + }, |
| 106 | + }, |
| 107 | + { |
| 108 | + type: 'section', |
| 109 | + accessory: {}, |
| 110 | + text: { |
| 111 | + type: 'paragraph', |
| 112 | + cols: 3, |
| 113 | + fields: [ |
| 114 | + { |
| 115 | + type: 'kmarkdown', |
| 116 | + content: '第一名', |
| 117 | + }, |
| 118 | + { |
| 119 | + type: 'kmarkdown', |
| 120 | + content: '第二名', |
| 121 | + }, |
| 122 | + { |
| 123 | + type: 'kmarkdown', |
| 124 | + content: '参与奖', |
| 125 | + }, |
| 126 | + { |
| 127 | + type: 'kmarkdown', |
| 128 | + content: '游戏加速器年卡', |
| 129 | + }, |
| 130 | + { |
| 131 | + type: 'kmarkdown', |
| 132 | + content: '游戏加速器季卡', |
| 133 | + }, |
| 134 | + { |
| 135 | + type: 'kmarkdown', |
| 136 | + content: '游戏加速器月卡', |
| 137 | + }, |
| 138 | + ], |
| 139 | + }, |
| 140 | + }, |
| 141 | + ], |
| 142 | + }, |
| 143 | +] |
| 144 | + |
| 145 | +export default () => ( |
| 146 | + <MessagePreview |
| 147 | + type="card" |
| 148 | + content={content} |
| 149 | + external="https://cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js" |
| 150 | + /> |
| 151 | +) |
| 152 | +``` |
| 153 | + |
| 154 | +## KMarkDown 消息基本使用 |
| 155 | + |
| 156 | +这是一个简单的 kmarkdown 消息例子 |
| 157 | + |
| 158 | +```jsx |
| 159 | +import { MessagePreview } from '@kookapp/kook-message-preview' |
| 160 | + |
| 161 | +const content = `~~删除线~~` |
| 162 | + |
| 163 | +export default () => ( |
| 164 | + <MessagePreview |
| 165 | + type="kmd" |
| 166 | + content={content} |
| 167 | + external="https://cdn.jsdelivr.net/npm/@kookapp/kook-message-preview@0.0.3/dist/markdown-parse.0.0.10.js" |
| 168 | + /> |
| 169 | +) |
| 170 | +``` |
| 171 | + |
| 172 | +## API |
| 173 | + |
| 174 | +| 属性名 | 描述 | 类型 | 默认值 | |
| 175 | +| -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | --------- | |
| 176 | +| type | 消息类型 `'card'`(卡片消息) `'kmd'`(KMarkDown 消息) | `string` | `'card'` | |
| 177 | +| theme | 主题色 `'light' 或 'dark'` | `string` | `'light'` | |
| 178 | +| content | 消息内容:具体可查看[消息编辑器](https://tttt-www.dev.chuanyuapp.com/tools/message-builder.html#/card) 或者 [卡片消息说明](/card_desc) 和 [KMarkDown 消息说明](/kmd_desc) | `string 或 array` | `[]` | |
| 179 | +| external | wasm 资源地址 | `string` | `''` | |
0 commit comments