(config, messages = null)
| 144 | * @param {Array} messages - 要导出的消息 |
| 145 | */ |
| 146 | export const exportConfig = (config, messages = null) => { |
| 147 | try { |
| 148 | const configToExport = { |
| 149 | ...config, |
| 150 | messages: messages || loadMessages(), // 包含消息数据 |
| 151 | exportTime: new Date().toISOString(), |
| 152 | version: '1.0', |
| 153 | }; |
| 154 | |
| 155 | const dataStr = JSON.stringify(configToExport, null, 2); |
| 156 | const dataBlob = new Blob([dataStr], { type: 'application/json' }); |
| 157 | |
| 158 | const link = document.createElement('a'); |
| 159 | link.href = URL.createObjectURL(dataBlob); |
| 160 | link.download = `playground-config-${new Date().toISOString().split('T')[0]}.json`; |
| 161 | link.click(); |
| 162 | |
| 163 | URL.revokeObjectURL(link.href); |
| 164 | |
| 165 | } catch (error) { |
| 166 | console.error('导出配置失败:', error); |
| 167 | } |
| 168 | }; |
| 169 | |
| 170 | /** |
| 171 | * 从文件导入配置(包含消息) |
no test coverage detected