|
78 | 78 | </div>
|
79 | 79 | </div>
|
80 | 80 | </div>
|
| 81 | + <div class="agent-actions"> |
| 82 | + <button |
| 83 | + class="btn btn-publish" |
| 84 | + @click="publishAgent" |
| 85 | + :disabled="isPublishing" |
| 86 | + :class="{ loading: isPublishing }" |
| 87 | + > |
| 88 | + <i class="bi bi-cloud-upload" v-if="!isPublishing"></i> |
| 89 | + <div class="spinner" v-if="isPublishing"></div> |
| 90 | + {{ isPublishing ? '发布中...' : '发布' }} |
| 91 | + </button> |
| 92 | + </div> |
81 | 93 | </div>
|
82 | 94 | </div>
|
83 | 95 | </div>
|
@@ -1165,6 +1177,9 @@ export default {
|
1165 | 1177 | const schemaInitializing = ref(false)
|
1166 | 1178 | const schemaStatistics = ref(null)
|
1167 | 1179 |
|
| 1180 | + // 发布相关数据 |
| 1181 | + const isPublishing = ref(false) |
| 1182 | + |
1168 | 1183 | // 方法
|
1169 | 1184 | const setActiveTab = (tab) => {
|
1170 | 1185 | activeTab.value = tab
|
@@ -1846,6 +1861,82 @@ export default {
|
1846 | 1861 | const hideMessage = () => {
|
1847 | 1862 | message.show = false
|
1848 | 1863 | }
|
| 1864 | +
|
| 1865 | + // 发布智能体 |
| 1866 | + const publishAgent = async () => { |
| 1867 | + if (isPublishing.value) return |
| 1868 | +
|
| 1869 | + try { |
| 1870 | + isPublishing.value = true |
| 1871 | + showMessage('开始发布智能体...', 'info') |
| 1872 | +
|
| 1873 | + // 1. 获取智能体配置的数据源 |
| 1874 | + const agentDatasources = await datasourceApi.getAgentDatasources(agent.id) |
| 1875 | + if (!agentDatasources || agentDatasources.length === 0) { |
| 1876 | + throw new Error('智能体未配置数据源,请先配置数据源') |
| 1877 | + } |
| 1878 | +
|
| 1879 | + // 2. 使用正常的 agentId 进行 schema 初始化 |
| 1880 | + const enabledDatasources = agentDatasources.filter(ds => ds.isActive === 1) |
| 1881 | + if (enabledDatasources.length === 0) { |
| 1882 | + throw new Error('没有启用的数据源,请先启用至少一个数据源') |
| 1883 | + } |
| 1884 | +
|
| 1885 | + // 3. 为每个启用的数据源获取表列表并初始化 |
| 1886 | + for (const agentDatasource of enabledDatasources) { |
| 1887 | + const datasource = agentDatasource.datasource |
| 1888 | + showMessage(`正在初始化数据源: ${datasource.name}...`, 'info') |
| 1889 | + |
| 1890 | + // 获取数据源的所有表 |
| 1891 | + const tablesResponse = await fetch(`/api/agent/${agent.id}/schema/datasources/${datasource.id}/tables`) |
| 1892 | + if (!tablesResponse.ok) { |
| 1893 | + console.warn(`获取数据源 ${datasource.name} 的表列表失败`) |
| 1894 | + continue |
| 1895 | + } |
| 1896 | + |
| 1897 | + const tablesResult = await tablesResponse.json() |
| 1898 | + if (!tablesResult.success || !tablesResult.data) { |
| 1899 | + console.warn(`数据源 ${datasource.name} 没有可用的表`) |
| 1900 | + continue |
| 1901 | + } |
| 1902 | +
|
| 1903 | + // 使用正常的 agentId 初始化 schema |
| 1904 | + const initResponse = await fetch(`/api/agent/${agent.id}/schema/init`, { |
| 1905 | + method: 'POST', |
| 1906 | + headers: { |
| 1907 | + 'Content-Type': 'application/json' |
| 1908 | + }, |
| 1909 | + body: JSON.stringify({ |
| 1910 | + datasourceId: datasource.id, |
| 1911 | + tables: tablesResult.data // 使用所有表 |
| 1912 | + }) |
| 1913 | + }) |
| 1914 | +
|
| 1915 | + if (!initResponse.ok) { |
| 1916 | + console.warn(`数据源 ${datasource.name} 初始化失败`) |
| 1917 | + continue |
| 1918 | + } |
| 1919 | +
|
| 1920 | + const initResult = await initResponse.json() |
| 1921 | + if (!initResult.success) { |
| 1922 | + console.warn(`数据源 ${datasource.name} 初始化失败: ${initResult.message}`) |
| 1923 | + continue |
| 1924 | + } |
| 1925 | + } |
| 1926 | +
|
| 1927 | + // 4. 发布成功 |
| 1928 | + showMessage('智能体发布成功!所有配置的数据源已完成初始化', 'success') |
| 1929 | + |
| 1930 | + // 可以在这里更新智能体状态为已发布 |
| 1931 | + // await updateAgentStatus('published') |
| 1932 | + |
| 1933 | + } catch (error) { |
| 1934 | + console.error('发布智能体失败:', error) |
| 1935 | + showMessage(`发布失败: ${error.message}`, 'error') |
| 1936 | + } finally { |
| 1937 | + isPublishing.value = false |
| 1938 | + } |
| 1939 | + } |
1849 | 1940 |
|
1850 | 1941 | const getMessageIcon = (type) => {
|
1851 | 1942 | const iconMap = {
|
@@ -2175,6 +2266,9 @@ export default {
|
2175 | 2266 | showMessage,
|
2176 | 2267 | hideMessage,
|
2177 | 2268 | getMessageIcon,
|
| 2269 | + // 发布相关 |
| 2270 | + publishAgent, |
| 2271 | + isPublishing, |
2178 | 2272 | // 预设问题方法
|
2179 | 2273 | presetQuestions,
|
2180 | 2274 | addPresetQuestion,
|
@@ -2508,6 +2602,58 @@ html {
|
2508 | 2602 | flex: 1;
|
2509 | 2603 | }
|
2510 | 2604 |
|
| 2605 | +.agent-actions { |
| 2606 | + display: flex; |
| 2607 | + align-items: center; |
| 2608 | + gap: 12px; |
| 2609 | +} |
| 2610 | +
|
| 2611 | +.btn-publish { |
| 2612 | + padding: 10px 20px; |
| 2613 | + background: linear-gradient(135deg, #52c41a, #73d13d); |
| 2614 | + color: white; |
| 2615 | + border: none; |
| 2616 | + border-radius: 6px; |
| 2617 | + font-size: 14px; |
| 2618 | + font-weight: 500; |
| 2619 | + cursor: pointer; |
| 2620 | + display: flex; |
| 2621 | + align-items: center; |
| 2622 | + gap: 6px; |
| 2623 | + transition: all 0.3s ease; |
| 2624 | + box-shadow: 0 2px 8px rgba(82, 196, 26, 0.25); |
| 2625 | +} |
| 2626 | +
|
| 2627 | +.btn-publish:hover:not(:disabled) { |
| 2628 | + background: linear-gradient(135deg, #389e0d, #52c41a); |
| 2629 | + transform: translateY(-1px); |
| 2630 | + box-shadow: 0 4px 12px rgba(82, 196, 26, 0.35); |
| 2631 | +} |
| 2632 | +
|
| 2633 | +.btn-publish:disabled { |
| 2634 | + opacity: 0.6; |
| 2635 | + cursor: not-allowed; |
| 2636 | + transform: none; |
| 2637 | +} |
| 2638 | +
|
| 2639 | +.btn-publish.loading { |
| 2640 | + pointer-events: none; |
| 2641 | +} |
| 2642 | +
|
| 2643 | +.btn-publish .spinner { |
| 2644 | + width: 14px; |
| 2645 | + height: 14px; |
| 2646 | + border: 2px solid rgba(255, 255, 255, 0.3); |
| 2647 | + border-top: 2px solid white; |
| 2648 | + border-radius: 50%; |
| 2649 | + animation: spin 1s linear infinite; |
| 2650 | +} |
| 2651 | +
|
| 2652 | +@keyframes spin { |
| 2653 | + 0% { transform: rotate(0deg); } |
| 2654 | + 100% { transform: rotate(360deg); } |
| 2655 | +} |
| 2656 | +
|
2511 | 2657 | .agent-avatar .avatar-icon {
|
2512 | 2658 | width: 64px;
|
2513 | 2659 | height: 64px;
|
|
0 commit comments