better-staridc-MNBT
1<template>
2 <div class="td-plugin-page">
3 <div class="td-plugin-head">
4 <div class="td-plugin-title">
5 <i class="mdi mdi-puzzle"></i>
6 <span>{{ title || '插件页面' }}</span>
7 </div>
8 <div class="td-plugin-actions">
9 <t-button theme="default" variant="outline" size="small" @click="reload" :loading="loading">
10 <i class="mdi mdi-refresh"></i> 刷新
11 </t-button>
12 <t-button theme="default" variant="outline" size="small" @click="openInNewTab">
13 <i class="mdi mdi-open-in-new"></i> 新窗口
14 </t-button>
15 </div>
16 </div>
17 <div class="td-plugin-frame-wrap">
18 <div v-if="loading" class="td-plugin-loading">
19 <t-loading text="插件页面加载中…" size="large" />
20 </div>
21 <div v-if="!iframeSrc" class="td-plugin-empty">
22 <i class="mdi mdi-alert-circle-outline"></i>
23 <span>未指定插件页面</span>
24 </div>
25 <iframe
26 v-show="!loading && iframeSrc"
27 ref="iframeRef"
28 :src="iframeSrc"
29 @load="onLoad"
30 frameborder="0"
31 class="td-plugin-iframe"
32 ></iframe>
33 </div>
34 </div>
35</template>
36
37<script setup>
38import { ref, computed, watch } from 'vue'
39import { useRoute } from 'vue-router'
40
41const route = useRoute()
42const iframeRef = ref(null)
43const loading = ref(true)
44
45const p = computed(() => route.query.p || '')
46const page = computed(() => route.query.page || 'index')
47const title = computed(() => route.query.title || route.meta.title || '')
48const iframeSrc = computed(() => {
49 if (!p.value) return ''
50 const params = new URLSearchParams({
51 p: String(p.value),
52 page: String(page.value),
53 })
54 return './plugin.php?' + params.toString()
55})
56
57function onLoad() {
58 loading.value = false
59}
60
61function reload() {
62 if (!iframeRef.value) return
63 loading.value = true
64 const src = iframeRef.value.src
65 iframeRef.value.src = 'about:blank'
66 setTimeout(() => {
67 if (iframeRef.value) iframeRef.value.src = src
68 }, 50)
69}
70
71function openInNewTab() {
72 if (iframeSrc.value) window.open(iframeSrc.value, '_blank')
73}
74
75watch(
76 () => route.fullPath,
77 () => {
78 if (iframeSrc.value) loading.value = true
79 },
80)
81</script>
82
83<style scoped>
84.td-plugin-page {
85 display: flex;
86 flex-direction: column;
87 height: 100%;
88 min-height: calc(100vh - var(--td-header-height));
89 background: var(--td-bg);
90}
91.td-plugin-head {
92 display: flex;
93 align-items: center;
94 justify-content: space-between;
95 padding: 12px 20px;
96 background: var(--td-surface);
97 border-bottom: 1px solid var(--td-border);
98 gap: 12px;
99}
100.td-plugin-title {
101 display: flex;
102 align-items: center;
103 gap: 8px;
104 font-size: 15px;
105 font-weight: 600;
106 color: var(--td-text);
107 min-width: 0;
108}
109.td-plugin-title i {
110 font-size: 18px;
111 color: var(--td-brand);
112 flex-shrink: 0;
113}
114.td-plugin-title span {
115 overflow: hidden;
116 text-overflow: ellipsis;
117 white-space: nowrap;
118}
119.td-plugin-actions {
120 display: flex;
121 gap: 8px;
122 flex-shrink: 0;
123}
124.td-plugin-frame-wrap {
125 flex: 1;
126 position: relative;
127 overflow: hidden;
128 background: var(--td-bg);
129}
130.td-plugin-loading {
131 position: absolute;
132 inset: 0;
133 display: grid;
134 place-items: center;
135 background: var(--td-bg);
136 z-index: 2;
137}
138.td-plugin-empty {
139 position: absolute;
140 inset: 0;
141 display: flex;
142 flex-direction: column;
143 align-items: center;
144 justify-content: center;
145 gap: 8px;
146 color: var(--td-text-placeholder);
147 font-size: 13px;
148}
149.td-plugin-empty i {
150 font-size: 38px;
151 color: #cbd5e1;
152}
153.td-plugin-iframe {
154 width: 100%;
155 height: 100%;
156 border: none;
157 display: block;
158 min-height: calc(100vh - var(--td-header-height) - 52px);
159 background: #fff;
160}
161</style>