Files
opc/frontend/src/views/ToolkitView.vue
T
小K a5692bfd7d feat: OPC 平台初版(Go+PG backend / Vue frontend)+ 尚数网融合方案 + db/0824 数据库备份
- backend: 25 张表 schema/seed,config 指向 127.0.0.1:15432 opc 库
- docs: 尚数网七维融合方案、行业老炮切入方案、竞品分析等
- db/0824/opc_0824.sql(.gz): pg_dump 全量备份(25 表,含数据)
2026-08-24 13:44:40 +08:00

245 lines
9.4 KiB
Vue

<template>
<div>
<div class="hero-banner" style="background: linear-gradient(135deg, #4338ca 0%, #db2777 100%);">
<div class="hero-text">
<h1>OPC 工具箱 · 即用即得</h1>
<p>面向数据 / 跨境 / 法律 / 设计背景的 OPC 创业者 — 一键生成合规文件、品牌方案、商业画布</p>
</div>
<div class="hero-actions">
<span class="top-tag" style="background: rgba(255,255,255,0.2); color: #fff;">15 件工具</span>
</div>
</div>
<!-- 分类 Tabs -->
<div class="card" style="margin-bottom: 16px;">
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
<button
v-for="d in domains"
:key="d.value"
class="btn"
:class="{ 'btn-primary': activeDomain === d.value }"
@click="activeDomain = d.value"
>
<el-icon><component :is="d.icon" /></el-icon>
{{ d.label }} <span style="opacity: 0.6; margin-left: 4px;">{{ d.count }}</span>
</button>
</div>
</div>
<!-- 工具卡片 -->
<div class="row-3">
<div v-for="tool in filteredTools" :key="tool.id" class="resource-card" @click="openTool(tool)">
<div style="display: flex; justify-content: space-between; align-items: center;">
<span class="tag" :class="domainColor(tool.domain)">{{ domainLabel(tool.domain) }}</span>
<span class="tag" :class="tool.status === 'available' ? 'tag-green' : tool.status === 'beta' ? 'tag-orange' : 'tag-gray'">{{ tool.status === 'available' ? '可用' : tool.status === 'beta' ? '内测' : '即将上线' }}</span>
</div>
<h4 style="margin-top: 8px;">{{ tool.name }}</h4>
<div class="desc" style="min-height: 60px;">{{ tool.description }}</div>
<div style="margin-top: 10px; display: flex; justify-content: space-between; align-items: center;">
<span class="tag tag-cyan">v{{ tool.version }}</span>
<span style="font-size: 12px; color: var(--text-muted);">🎁 {{ tool.free_quota }}</span>
</div>
<div style="margin-top: 12px; display: flex; justify-content: flex-end;">
<button class="btn btn-primary" style="font-size: 12px;">
<el-icon><Promotion /></el-icon> 立即使用
</button>
</div>
</div>
</div>
<div v-if="filteredTools.length === 0" class="empty">该分类暂无工具</div>
<!-- 工具运行抽屉 -->
<el-drawer v-model="drawerOpen" :title="currentTool?.name" size="640px" :close-on-click-modal="false">
<div v-if="currentTool">
<div style="margin-bottom: 16px; padding: 12px 14px; background: rgba(82,134,255,0.1); border-radius: 8px; color: var(--text-muted); font-size: 12px;">
{{ currentTool.description }}
</div>
<div v-if="!result">
<div v-for="f in fields" :key="f.key" style="margin-bottom: 14px;">
<div style="font-size: 13px; margin-bottom: 6px; color: var(--text-muted);">
{{ f.label }} <span v-if="f.required" style="color: var(--danger);">*</span>
</div>
<el-input
v-if="f.type === 'text'"
v-model="form[f.key]"
:placeholder="f.placeholder || ''"
/>
<el-input
v-else-if="f.type === 'textarea'"
v-model="form[f.key]"
type="textarea"
:rows="4"
:placeholder="f.placeholder || ''"
/>
<el-input-number
v-else-if="f.type === 'number'"
v-model="form[f.key]"
style="width: 100%;"
/>
<el-select v-else-if="f.type === 'select'" v-model="form[f.key]" :placeholder="f.placeholder || '请选择'" style="width: 100%;">
<el-option v-for="opt in f.options" :key="opt" :label="opt" :value="opt" />
</el-select>
<el-select v-else-if="f.type === 'multiselect'" v-model="form[f.key]" multiple :placeholder="f.placeholder || '可多选'" style="width: 100%;">
<el-option v-for="opt in f.options" :key="opt" :label="opt" :value="opt" />
</el-select>
</div>
<div style="margin-top: 20px; display: flex; gap: 8px; justify-content: flex-end;">
<button class="btn" @click="drawerOpen = false">取消</button>
<button class="btn btn-primary" :disabled="running" @click="runTool">
<el-icon><Promotion /></el-icon>
{{ running ? '运行中...' : '运行工具' }}
</button>
</div>
</div>
<!-- 结果 -->
<div v-else>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;">
<div>
<span class="tag tag-green">运行成功</span>
<span style="margin-left: 8px; font-size: 12px; color: var(--text-muted);">耗时 {{ result.duration_ms }} ms</span>
</div>
<div style="display: flex; gap: 8px;">
<button class="btn" @click="result = null">重新运行</button>
<button class="btn" @click="copyResult">
<el-icon><CopyDocument /></el-icon> 复制结果
</button>
</div>
</div>
<!-- 评分卡 -->
<div v-if="result.score !== undefined" class="card" style="margin-bottom: 16px; background: linear-gradient(135deg, var(--bg-card), var(--bg-card-2));">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<div style="font-size: 12px; color: var(--text-muted);">综合评分</div>
<div style="font-size: 36px; font-weight: 700; color: var(--primary-light);">{{ result.score.toFixed(1) }}</div>
</div>
<div style="text-align: right;">
<div style="font-size: 12px; color: var(--text-muted);">判定</div>
<div :class="['tag', 'tag-' + scoreTag(result.score)]" style="font-size: 14px; padding: 4px 10px;">
{{ scoreLabel(result.score) }}
</div>
</div>
</div>
</div>
<!-- 各个引擎的结果渲染 -->
<component :is="resultRenderer" :output="result.output" />
</div>
</div>
</el-drawer>
</div>
</template>
<script setup>
import { ref, computed, onMounted, h, markRaw } from 'vue'
import api from '../api'
import * as ElIcons from '@element-plus/icons-vue'
import { renderResult } from './toolkit/resultRenderers.jsx'
const tools = ref([])
const activeDomain = ref('all')
const drawerOpen = ref(false)
const currentTool = ref(null)
const form = ref({})
const running = ref(false)
const result = ref(null)
const domains = computed(() => {
const dm = { 'all': { label: '全部工具', icon: 'Menu', count: tools.value.length } }
const grouped = {}
for (const t of tools.value) {
const d = t.domain || 'platform'
grouped[d] = (grouped[d] || 0) + 1
}
for (const [k, v] of Object.entries(grouped)) {
dm[k] = { label: domainLabel(k), icon: domainIcon(k), count: v }
}
return dm
})
const filteredTools = computed(() => {
if (activeDomain.value === 'all') return tools.value
return tools.value.filter(t => (t.domain || 'platform') === activeDomain.value)
})
const fields = computed(() => {
if (!currentTool.value?.template?.fields) return []
return currentTool.value.template.fields
})
const resultRenderer = computed(() => {
if (!result.value) return null
return markRaw({ render() { return renderResult(result.value.output, currentTool.value?.template?.engine) } })
})
function domainLabel(d) {
return { 'cross-border': '跨境数据', 'legal': '法律合规', 'design': '设计生成', 'general': '通用战略', 'platform': '平台工具' }[d] || d
}
function domainColor(d) {
return { 'cross-border': 'tag-purple', 'legal': 'tag-red', 'design': 'tag-cyan', 'general': 'tag-blue', 'platform': 'tag-orange' }[d] || 'tag-gray'
}
function domainIcon(d) {
return { 'cross-border': 'Promotion', 'legal': 'Lock', 'design': 'Brush', 'general': 'Compass', 'platform': 'Cpu' }[d] || 'Tools'
}
function scoreTag(s) {
if (s >= 85) return 'green'
if (s >= 70) return 'cyan'
if (s >= 50) return 'orange'
return 'red'
}
function scoreLabel(s) {
if (s >= 85) return '优秀'
if (s >= 70) return '良好'
if (s >= 50) return '需改进'
return '高风险'
}
function openTool(tool) {
currentTool.value = tool
form.value = {}
result.value = null
// 预填默认值
for (const f of (tool.template?.fields || [])) {
if (f.type === 'multiselect') form.value[f.key] = []
else if (f.type === 'number') form.value[f.key] = null
else form.value[f.key] = ''
}
drawerOpen.value = true
}
async function runTool() {
running.value = true
try {
const data = await api.runTool(currentTool.value.id, form.value)
result.value = data
} catch (e) {
console.error(e)
} finally {
running.value = false
}
}
async function copyResult() {
const text = JSON.stringify(result.value.output, null, 2)
try {
await navigator.clipboard.writeText(text)
alert('结果已复制到剪贴板')
} catch (e) {
alert('复制失败:' + e.message)
}
}
onMounted(async () => {
tools.value = await api.listTools()
})
</script>
<style scoped>
.resource-card { cursor: pointer; transition: all 0.2s; }
.resource-card:hover { transform: translateY(-2px); border-color: var(--primary-light); }
</style>