better-staridc-MNBT
1<template>
2 <div class="td-page">
3 <div class="td-page-head">
4 <div>
5 <h3 class="td-page-title"><i class="mdi mdi-puzzle"></i>插件管理</h3>
6 <p class="td-page-subtitle">查看、安装、启用与卸载系统插件</p>
7 </div>
8 <t-button theme="default" variant="outline" @click="load">
9 <i class="mdi mdi-refresh"></i> 刷新
10 </t-button>
11 </div>
12
13 <!-- 已启用插件设置入口 -->
14 <div v-if="settingsTabs.length" class="td-set-card">
15 <div class="td-set-card-hd">
16 <div>
17 <h4>已启用插件设置入口</h4>
18 <p>点击进入对应插件的设置页面</p>
19 </div>
20 </div>
21 <div class="td-set-card-bd">
22 <div class="entry-row">
23 <t-link
24 v-for="tab in settingsTabs"
25 :key="tab.plugin"
26 theme="primary"
27 hover="color"
28 class="entry-item"
29 @click="goEntry(tab)"
30 >
31 {{ tab.title }}
32 </t-link>
33 </div>
34 </div>
35 </div>
36
37 <div class="td-table-wrap">
38 <t-table
39 row-key="slug"
40 :data="rows"
41 :columns="columns"
42 :loading="loading"
43 stripe
44 bordered
45 >
46 <template #slug="{ row }">
47 <code class="td-code">{{ row.slug }}</code>
48 </template>
49
50 <template #status="{ row }">
51 <span class="td-chip td-chip-success" v-if="row.enabled">
52 <i class="mdi mdi-check-circle"></i> 已启用
53 </span>
54 <span class="td-chip td-chip-default" v-else-if="row.installed">
55 <i class="mdi mdi-pause-circle"></i> 已安装
56 </span>
57 <span class="td-chip td-chip-warning" v-else>
58 <i class="mdi mdi-download"></i> 未安装
59 </span>
60 </template>
61
62 <template #description="{ row }">
63 <span class="td-text-mute td-text-sm">{{ row.description || '-' }}</span>
64 </template>
65
66 <template #op="{ row }">
67 <div class="td-row-actions">
68 <t-button
69 v-if="!row.installed"
70 theme="primary"
71 variant="text"
72 size="small"
73 :loading="busySlug === row.slug"
74 @click="install(row)"
75 >
76 <i class="mdi mdi-download"></i> 安装
77 </t-button>
78 <t-button
79 v-else-if="!row.enabled"
80 theme="primary"
81 variant="text"
82 size="small"
83 :loading="busySlug === row.slug"
84 @click="enable(row)"
85 >
86 <i class="mdi mdi-play"></i> 启用
87 </t-button>
88 <t-button
89 v-else
90 theme="warning"
91 variant="text"
92 size="small"
93 :loading="busySlug === row.slug"
94 @click="disable(row)"
95 >
96 <i class="mdi mdi-pause"></i> 禁用
97 </t-button>
98 <t-button
99 v-if="row.installed"
100 theme="danger"
101 variant="text"
102 size="small"
103 :loading="busySlug === row.slug"
104 @click="uninstall(row)"
105 >
106 <i class="mdi mdi-delete"></i> 卸载
107 </t-button>
108 </div>
109 </template>
110 </t-table>
111 </div>
112 </div>
113</template>
114
115<script setup>
116import { ref, computed, onMounted } from 'vue'
117import { useRouter } from 'vue-router'
118import { MessagePlugin, DialogPlugin } from 'tdesign-vue-next'
119import {
120 listPlugin,
121 setPluginEnabled,
122 installPlugin,
123 uninstallPlugin,
124} from '@/admin/api/plugin'
125
126const router = useRouter()
127
128const loading = ref(false)
129const rows = ref([])
130const busySlug = ref('')
131
132const boot = window.__TD_BOOT__ || {}
133const settingsTabs = computed(() => {
134 const tabs = boot.pluginSettingsTabs
135 return Array.isArray(tabs) ? tabs : []
136})
137
138const columns = [
139 { colKey: 'slug', title: '标识', width: 180, col: 'slug' },
140 { colKey: 'name', title: '名称', minWidth: 140 },
141 { colKey: 'version', title: '版本', width: 100 },
142 { colKey: 'author', title: '作者', width: 140 },
143 { colKey: 'status', title: '状态', width: 110, col: 'status' },
144 { colKey: 'description', title: '说明', minWidth: 200, col: 'description' },
145 { colKey: 'op', title: '操作', width: 200, fixed: 'right' },
146]
147
148function goEntry(tab) {
149 if (tab.url) {
150 router.push(tab.url)
151 }
152}
153
154async function load() {
155 loading.value = true
156 const r = await listPlugin()
157 loading.value = false
158 if (r.ok && r.data) {
159 rows.value = r.data.rows || []
160 }
161}
162
163async function install(row) {
164 busySlug.value = row.slug
165 const r = await installPlugin(row.slug)
166 busySlug.value = ''
167 if (r.ok) {
168 MessagePlugin.success('安装成功')
169 load()
170 }
171}
172
173async function enable(row) {
174 busySlug.value = row.slug
175 const r = await setPluginEnabled(row.slug, true)
176 busySlug.value = ''
177 if (r.ok) {
178 MessagePlugin.success('已启用')
179 load()
180 }
181}
182
183async function disable(row) {
184 busySlug.value = row.slug
185 const r = await setPluginEnabled(row.slug, false)
186 busySlug.value = ''
187 if (r.ok) {
188 MessagePlugin.success('已禁用')
189 load()
190 }
191}
192
193function uninstall(row) {
194 const dialog = DialogPlugin.confirm({
195 header: '卸载插件',
196 body: `确定卸载插件「${row.name || row.slug}」吗?卸载后该插件的功能将不可用。`,
197 confirmBtn: { content: '卸载', theme: 'danger' },
198 onConfirm: async () => {
199 busySlug.value = row.slug
200 const r = await uninstallPlugin(row.slug)
201 busySlug.value = ''
202 dialog.destroy()
203 if (r.ok) {
204 MessagePlugin.success('已卸载')
205 load()
206 }
207 },
208 onClose: () => dialog.destroy(),
209 })
210}
211
212onMounted(load)
213</script>
214
215<style scoped>
216.entry-row {
217 display: flex;
218 flex-wrap: wrap;
219 gap: 12px 18px;
220}
221.entry-item {
222 font-size: 13px;
223}
224</style>