integration.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <template>
  2. <div class="center-shell">
  3. <header>
  4. <div class="center-head-row">
  5. <n-button text @click="router.push('/app-center')">
  6. 返回应用中心
  7. </n-button>
  8. <n-space :wrap="true">
  9. <n-button secondary @click="loadAll">
  10. 刷新
  11. </n-button>
  12. <n-button type="primary" @click="openEditor(null)">
  13. 新增集成入口
  14. </n-button>
  15. </n-space>
  16. </div>
  17. <h1>集成中心</h1>
  18. <p>统一登记开放接口、Webhook 和第三方平台入口,入口打开仍由后端校验状态和权限。</p>
  19. </header>
  20. <section class="integration-summary">
  21. <div v-for="item in summaryCards" :key="item.name" class="summary-card">
  22. <n-icon :component="item.icon" />
  23. <strong>{{ item.count }}</strong>
  24. <span>{{ item.name }}</span>
  25. </div>
  26. </section>
  27. <section class="entry-panel">
  28. <div class="panel-head">
  29. <div>
  30. <strong>集成应用定义</strong>
  31. <p>{{ total }} 个入口 · {{ enabledCount }} 个启用</p>
  32. </div>
  33. <n-select
  34. v-model:value="platformType"
  35. clearable
  36. class="mode-select"
  37. placeholder="集成类型"
  38. :options="platformOptions"
  39. @update:value="loadApps"
  40. />
  41. </div>
  42. <n-spin :show="loading">
  43. <div v-if="apps.length" class="entry-grid">
  44. <AppCard
  45. v-for="app in apps"
  46. :key="app.id"
  47. :app="app"
  48. @open="openApp"
  49. @config="openEditor"
  50. @toggle="toggleApp"
  51. @delete="deleteApp"
  52. />
  53. </div>
  54. <n-empty v-else-if="!loading" description="暂无集成访问入口" />
  55. </n-spin>
  56. <div v-if="total > pagination.pageSize" class="entry-pagination">
  57. <n-pagination
  58. v-model:page="pagination.pageNum"
  59. v-model:page-size="pagination.pageSize"
  60. :item-count="total"
  61. :page-sizes="[6, 12, 24]"
  62. show-size-picker
  63. @update:page="loadApps"
  64. @update:page-size="handlePageSizeChange"
  65. />
  66. </div>
  67. </section>
  68. <AppEditorDrawer
  69. v-model:show="editorVisible"
  70. :app="editingApp"
  71. :suites="suites"
  72. @saved="loadAll"
  73. />
  74. </div>
  75. </template>
  76. <script setup>
  77. import { CloudUploadOutline, GitNetworkOutline, LinkOutline, PaperPlaneOutline } from '@vicons/ionicons5'
  78. import { useMessage } from 'naive-ui'
  79. import { computed, onMounted, ref } from 'vue'
  80. import { useRouter } from 'vue-router'
  81. import {
  82. businessAppDetail,
  83. businessAppOpenInfo,
  84. businessAppPage,
  85. businessSuiteSummary,
  86. deleteBusinessApp,
  87. updateBusinessAppStatus,
  88. } from '@/api/business-app'
  89. import { useDict } from '@/composables/useDict'
  90. import AppCard from './components/AppCard.vue'
  91. import AppEditorDrawer from './components/AppEditorDrawer.vue'
  92. const router = useRouter()
  93. const message = useMessage()
  94. const { dict } = useDict('ai_business_app_platform_type')
  95. const suites = ref([])
  96. const apps = ref([])
  97. const loading = ref(false)
  98. const editorVisible = ref(false)
  99. const editingApp = ref(null)
  100. const platformType = ref(null)
  101. const total = ref(0)
  102. const pagination = ref({
  103. pageNum: 1,
  104. pageSize: 6,
  105. })
  106. const enabledCount = computed(() => apps.value.filter(item => item.status === 1).length)
  107. const platformIconMap = {
  108. api: LinkOutline,
  109. webhook: CloudUploadOutline,
  110. collaboration: PaperPlaneOutline,
  111. external: GitNetworkOutline,
  112. }
  113. const platformOptions = computed(() => dict.value.ai_business_app_platform_type || [])
  114. const summaryCards = computed(() => platformOptions.value.map(item => ({
  115. name: item.label,
  116. count: countByPlatform(item.value),
  117. icon: platformIconMap[item.value] || LinkOutline,
  118. })))
  119. onMounted(loadAll)
  120. async function loadAll() {
  121. await Promise.all([loadSuites(), loadApps()])
  122. }
  123. async function loadSuites() {
  124. const res = await businessSuiteSummary()
  125. suites.value = res.data || []
  126. }
  127. async function loadApps() {
  128. loading.value = true
  129. try {
  130. const res = await businessAppPage({
  131. pageNum: pagination.value.pageNum,
  132. pageSize: pagination.value.pageSize,
  133. appType: 'INTEGRATION',
  134. })
  135. const records = res.data?.records || []
  136. apps.value = platformType.value
  137. ? records.filter(item => parseOptions(item.options).platformType === platformType.value)
  138. : records
  139. total.value = platformType.value ? apps.value.length : Number(res.data?.total || 0)
  140. }
  141. finally {
  142. loading.value = false
  143. }
  144. }
  145. async function openEditor(app) {
  146. if (app?.id) {
  147. try {
  148. const res = await businessAppDetail(app.id)
  149. editingApp.value = { ...app, ...(res.data || {}) }
  150. }
  151. catch {
  152. editingApp.value = { ...app }
  153. }
  154. }
  155. else {
  156. editingApp.value = {
  157. appType: 'INTEGRATION',
  158. entryMode: 'API',
  159. entryUrl: '/app-center/integration',
  160. appCode: '',
  161. appName: '',
  162. status: 1,
  163. }
  164. }
  165. editorVisible.value = true
  166. }
  167. async function openApp(app) {
  168. const res = await businessAppOpenInfo(app.id)
  169. const info = res.data || {}
  170. if (!info.canOpen) {
  171. message.warning(info.message || '集成入口暂不可打开')
  172. return
  173. }
  174. if (info.openType === 'EXTERNAL' || /^https?:\/\//i.test(info.targetUrl || '')) {
  175. window.open(info.targetUrl, '_blank', 'noopener,noreferrer')
  176. return
  177. }
  178. router.push(info.targetUrl || '/app-center/integration')
  179. }
  180. async function toggleApp(app) {
  181. await updateBusinessAppStatus(app.id, app.status === 1 ? 0 : 1)
  182. message.success(app.status === 1 ? '集成入口已停用' : '集成入口已启用')
  183. await loadApps()
  184. }
  185. function deleteApp(app) {
  186. window.$dialog?.warning({
  187. title: '删除集成入口',
  188. content: `确定删除“${app.appName || app.appCode}”吗?`,
  189. positiveText: '删除',
  190. negativeText: '取消',
  191. onPositiveClick: async () => {
  192. await deleteBusinessApp(app.id)
  193. message.success('集成入口已删除')
  194. await loadAll()
  195. },
  196. })
  197. }
  198. function handlePageSizeChange(pageSize) {
  199. pagination.value.pageSize = pageSize
  200. pagination.value.pageNum = 1
  201. loadApps()
  202. }
  203. function countByPlatform(platform) {
  204. return apps.value.filter(item => parseOptions(item.options).platformType === platform).length
  205. }
  206. function parseOptions(value) {
  207. try {
  208. return value ? JSON.parse(value) : {}
  209. }
  210. catch {
  211. return {}
  212. }
  213. }
  214. </script>
  215. <style scoped>
  216. @import './shared-center.css';
  217. .center-head-row,
  218. .panel-head {
  219. display: flex;
  220. justify-content: space-between;
  221. gap: 12px;
  222. align-items: center;
  223. }
  224. .integration-summary {
  225. display: grid;
  226. grid-template-columns: repeat(4, minmax(0, 1fr));
  227. gap: 12px;
  228. margin-bottom: 16px;
  229. }
  230. .summary-card,
  231. .entry-panel {
  232. border: 1px solid #e5e7eb;
  233. border-radius: 8px;
  234. background: #fff;
  235. }
  236. .summary-card {
  237. display: grid;
  238. grid-template-columns: 42px minmax(0, 1fr);
  239. gap: 10px;
  240. align-items: center;
  241. min-height: 86px;
  242. padding: 14px;
  243. }
  244. .summary-card .n-icon {
  245. grid-row: span 2;
  246. width: 42px;
  247. height: 42px;
  248. color: #2563eb;
  249. font-size: 24px;
  250. }
  251. .summary-card strong,
  252. .summary-card span {
  253. display: block;
  254. }
  255. .summary-card strong {
  256. color: #111827;
  257. font-size: 22px;
  258. line-height: 1;
  259. }
  260. .summary-card span {
  261. color: #6b7280;
  262. font-size: 12px;
  263. }
  264. .entry-panel {
  265. padding: 16px;
  266. }
  267. .panel-head {
  268. margin-bottom: 14px;
  269. }
  270. .panel-head strong {
  271. color: #111827;
  272. font-size: 15px;
  273. }
  274. .panel-head p {
  275. margin: 4px 0 0;
  276. }
  277. .mode-select {
  278. width: 190px;
  279. }
  280. .entry-grid {
  281. display: grid;
  282. grid-template-columns: repeat(2, minmax(0, 1fr));
  283. gap: 12px;
  284. }
  285. .entry-pagination {
  286. display: flex;
  287. justify-content: flex-end;
  288. margin-top: 14px;
  289. }
  290. @media (max-width: 960px) {
  291. .integration-summary,
  292. .entry-grid {
  293. grid-template-columns: repeat(2, minmax(0, 1fr));
  294. }
  295. }
  296. @media (max-width: 620px) {
  297. .center-head-row,
  298. .panel-head {
  299. align-items: stretch;
  300. flex-direction: column;
  301. }
  302. .integration-summary,
  303. .entry-grid {
  304. grid-template-columns: 1fr;
  305. }
  306. .mode-select {
  307. width: 100%;
  308. }
  309. }
  310. </style>