feat: 适配验证列表页加导出/导入脚本按钮
This commit is contained in:
@@ -2,8 +2,12 @@
|
|||||||
<div>
|
<div>
|
||||||
<h2>适配验证</h2>
|
<h2>适配验证</h2>
|
||||||
<el-card style="margin-top: 20px">
|
<el-card style="margin-top: 20px">
|
||||||
<div style="margin-bottom: 12px">
|
<div style="margin-bottom: 12px;display:flex;gap:8px">
|
||||||
<el-button @click="fetchAll" :icon="Refresh">刷新</el-button>
|
<el-button @click="fetchAll" :icon="Refresh">刷新</el-button>
|
||||||
|
<el-button @click="exportScripts" :loading="exporting">导出脚本</el-button>
|
||||||
|
<el-upload :auto-upload="false" :show-file-list="false" accept=".zip" :on-change="importScripts">
|
||||||
|
<el-button :loading="importing">导入脚本</el-button>
|
||||||
|
</el-upload>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-table :data="sites" v-loading="loading" stripe size="small" empty-text="暂无访问记录">
|
<el-table :data="sites" v-loading="loading" stripe size="small" empty-text="暂无访问记录">
|
||||||
@@ -66,9 +70,31 @@
|
|||||||
import api from '../api'
|
import api from '../api'
|
||||||
import { Refresh } from '@element-plus/icons-vue'
|
import { Refresh } from '@element-plus/icons-vue'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false), exporting = ref(false), importing = ref(false)
|
||||||
const sites = ref([])
|
const sites = ref([])
|
||||||
|
|
||||||
|
const exportScripts = async () => {
|
||||||
|
exporting.value = true
|
||||||
|
try {
|
||||||
|
const r = await api.get('/admin/scripts/export', { responseType: 'blob' })
|
||||||
|
const a = document.createElement('a')
|
||||||
|
a.href = URL.createObjectURL(new Blob([r.data]))
|
||||||
|
a.download = 'scripts.zip'; a.click(); URL.revokeObjectURL(a.href)
|
||||||
|
} catch { ElMessage.error('导出失败') }
|
||||||
|
finally { exporting.value = false }
|
||||||
|
}
|
||||||
|
|
||||||
|
const importScripts = async (file) => {
|
||||||
|
importing.value = true
|
||||||
|
try {
|
||||||
|
const fd = new FormData(); fd.append('file', file.raw)
|
||||||
|
const r = await api.post('/admin/scripts/import', fd)
|
||||||
|
ElMessage.success('导入完成: ' + ((r.data?.ok || 0) + ' 成功, ' + (r.data?.fail || 0) + ' 失败'))
|
||||||
|
fetchAll()
|
||||||
|
} catch { ElMessage.error('导入失败') }
|
||||||
|
finally { importing.value = false }
|
||||||
|
}
|
||||||
|
|
||||||
const friendlyTime = (t) => {
|
const friendlyTime = (t) => {
|
||||||
if (!t) return null
|
if (!t) return null
|
||||||
const d = new Date(t), now = new Date()
|
const d = new Date(t), now = new Date()
|
||||||
|
|||||||
Reference in New Issue
Block a user