462 lines
15 KiB
Vue
462 lines
15 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, reactive, ref } from 'vue'
|
|
import { useI18n } from 'vue-i18n'
|
|
import type { UploadFile, UploadFiles } from 'element-plus'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import { Refresh, UploadFilled } from '@element-plus/icons-vue'
|
|
import http, { apiErrorMessage } from '../api/http'
|
|
|
|
type UpdatePlatform = 'Android' | 'Ios'
|
|
type UpdateChannel = 'Production' | 'Staging'
|
|
type UpdateStatus = 'Draft' | 'Published' | 'Archived'
|
|
|
|
interface AppUpdateRelease {
|
|
id: string
|
|
platform: UpdatePlatform
|
|
channel: UpdateChannel
|
|
version: string
|
|
nativeVersion: string
|
|
status: UpdateStatus
|
|
releaseNotes?: string
|
|
fileName: string
|
|
fileSize: number
|
|
sha256: string
|
|
createdByUserName: string
|
|
createdAt: string
|
|
publishedByUserName?: string
|
|
publishedAt?: string
|
|
}
|
|
|
|
interface PageResult<T> {
|
|
items: T[]
|
|
nextCursor?: string
|
|
hasMore: boolean
|
|
pageSize: number
|
|
}
|
|
|
|
const loading = ref(false)
|
|
const { locale, t } = useI18n()
|
|
const uploadBusy = ref(false)
|
|
const rows = ref<AppUpdateRelease[]>([])
|
|
const cursors = ref<string[]>([])
|
|
const nextCursor = ref<string>()
|
|
const hasMore = ref(false)
|
|
const uploadVisible = ref(false)
|
|
const selectedBundle = ref<File>()
|
|
const uploadFiles = ref<UploadFiles>([])
|
|
const filter = reactive({
|
|
page: 1,
|
|
pageSize: 20,
|
|
platform: '',
|
|
channel: '',
|
|
})
|
|
const form = reactive({
|
|
platform: 'Android' as UpdatePlatform,
|
|
channel: 'Production' as UpdateChannel,
|
|
version: '',
|
|
nativeVersion: '1.0',
|
|
releaseNotes: '',
|
|
})
|
|
|
|
function formatTime(value?: string) {
|
|
if (!value) return '—'
|
|
return new Date(value).toLocaleString(locale.value, { hour12: false })
|
|
}
|
|
|
|
function formatBytes(value: number) {
|
|
if (value < 1024) return `${value} B`
|
|
if (value < 1024 ** 2) return `${(value / 1024).toFixed(1)} KB`
|
|
return `${(value / 1024 ** 2).toFixed(1)} MB`
|
|
}
|
|
|
|
function platformLabel(value: UpdatePlatform) {
|
|
return value === 'Android' ? 'Android' : 'iOS'
|
|
}
|
|
|
|
function channelLabel(value: UpdateChannel) {
|
|
return t(`appUpdates.channels.${value}`)
|
|
}
|
|
|
|
function statusLabel(value: UpdateStatus) {
|
|
return t(`appUpdates.statuses.${value}`)
|
|
}
|
|
|
|
function statusType(value: UpdateStatus) {
|
|
return value === 'Published'
|
|
? 'success'
|
|
: value === 'Archived'
|
|
? 'info'
|
|
: 'warning'
|
|
}
|
|
|
|
async function loadReleases() {
|
|
loading.value = true
|
|
try {
|
|
const params: Record<string, string | number | undefined> = {
|
|
cursor: cursors.value.at(-1),
|
|
pageSize: filter.pageSize,
|
|
}
|
|
if (filter.platform) params.platform = filter.platform
|
|
if (filter.channel) params.channel = filter.channel
|
|
const { data } = await http.get<PageResult<AppUpdateRelease>>(
|
|
'/app-updates/releases',
|
|
{ params },
|
|
)
|
|
rows.value = data.items
|
|
hasMore.value = data.hasMore
|
|
nextCursor.value = data.nextCursor
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
function search() {
|
|
filter.page = 1
|
|
cursors.value = []
|
|
nextCursor.value = undefined
|
|
loadReleases()
|
|
}
|
|
|
|
async function nextPage() {
|
|
if (!nextCursor.value || loading.value) return
|
|
cursors.value.push(nextCursor.value)
|
|
filter.page++
|
|
await loadReleases()
|
|
}
|
|
|
|
async function previousPage() {
|
|
if (!cursors.value.length || loading.value) return
|
|
cursors.value.pop()
|
|
filter.page--
|
|
await loadReleases()
|
|
}
|
|
|
|
function openUpload() {
|
|
Object.assign(form, {
|
|
platform: 'Android',
|
|
channel: 'Production',
|
|
version: '',
|
|
nativeVersion: '1.0',
|
|
releaseNotes: '',
|
|
})
|
|
selectedBundle.value = undefined
|
|
uploadFiles.value = []
|
|
uploadVisible.value = true
|
|
}
|
|
|
|
function handleBundleChange(file: UploadFile, files: UploadFiles) {
|
|
uploadFiles.value = files.slice(-1)
|
|
selectedBundle.value = file.raw
|
|
}
|
|
|
|
function handleBundleRemove() {
|
|
selectedBundle.value = undefined
|
|
uploadFiles.value = []
|
|
}
|
|
|
|
async function uploadRelease() {
|
|
if (!selectedBundle.value) {
|
|
ElMessage.warning(t('appUpdates.messages.selectZip'))
|
|
return
|
|
}
|
|
if (!form.version.trim() || !form.nativeVersion.trim()) {
|
|
ElMessage.warning(t('appUpdates.messages.versionRequired'))
|
|
return
|
|
}
|
|
|
|
const body = new FormData()
|
|
body.append('bundle', selectedBundle.value)
|
|
body.append('platform', form.platform)
|
|
body.append('channel', form.channel)
|
|
body.append('version', form.version.trim())
|
|
body.append('nativeVersion', form.nativeVersion.trim())
|
|
body.append('releaseNotes', form.releaseNotes.trim())
|
|
|
|
uploadBusy.value = true
|
|
try {
|
|
await http.post('/app-updates/releases', body, {
|
|
timeout: 10 * 60 * 1000,
|
|
})
|
|
ElMessage.success(t('appUpdates.messages.uploaded'))
|
|
uploadVisible.value = false
|
|
await loadReleases()
|
|
} catch (error) {
|
|
ElMessage.error(apiErrorMessage(error))
|
|
} finally {
|
|
uploadBusy.value = false
|
|
}
|
|
}
|
|
|
|
async function publishRelease(tableRow: Record<string, unknown>) {
|
|
const row = tableRow as unknown as AppUpdateRelease
|
|
const isRollback = row.status === 'Archived'
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
isRollback
|
|
? t('appUpdates.messages.rollbackConfirm', { platform: platformLabel(row.platform), native: row.nativeVersion, version: row.version })
|
|
: t('appUpdates.messages.publishConfirm', { version: row.version }),
|
|
t(isRollback ? 'appUpdates.messages.rollbackTitle' : 'appUpdates.messages.publishTitle'),
|
|
{
|
|
type: isRollback ? 'warning' : 'info',
|
|
confirmButtonText: t(isRollback ? 'appUpdates.confirmRollback' : 'appUpdates.publish'), cancelButtonText: t('appUpdates.cancel'),
|
|
},
|
|
)
|
|
await http.post(`/app-updates/releases/${row.id}/publish`)
|
|
ElMessage.success(t(isRollback ? 'appUpdates.messages.rolledBack' : 'appUpdates.messages.published'))
|
|
await loadReleases()
|
|
} catch (error) {
|
|
if (error === 'cancel' || error === 'close') return
|
|
ElMessage.error(apiErrorMessage(error))
|
|
}
|
|
}
|
|
|
|
async function deleteRelease(tableRow: Record<string, unknown>) {
|
|
const row = tableRow as unknown as AppUpdateRelease
|
|
try {
|
|
await ElMessageBox.confirm(
|
|
t('appUpdates.messages.deleteConfirm', { version: row.version, file: row.fileName }), t('appUpdates.messages.deleteTitle'),
|
|
{
|
|
type: 'warning',
|
|
confirmButtonText: t('appUpdates.delete'), cancelButtonText: t('appUpdates.cancel'),
|
|
},
|
|
)
|
|
await http.delete(`/app-updates/releases/${row.id}`)
|
|
ElMessage.success(t('appUpdates.messages.deleted'))
|
|
await loadReleases()
|
|
} catch (error) {
|
|
if (error === 'cancel' || error === 'close') return
|
|
ElMessage.error(apiErrorMessage(error))
|
|
}
|
|
}
|
|
|
|
onMounted(loadReleases)
|
|
</script>
|
|
|
|
<template>
|
|
<section class="update-panel">
|
|
<header class="update-heading">
|
|
<div>
|
|
<span>SELF-HOSTED OTA</span>
|
|
<h3>{{ t('appUpdates.title') }}</h3><p>{{ t('appUpdates.description') }}</p>
|
|
</div>
|
|
<div class="heading-actions">
|
|
<el-button :icon="Refresh" :loading="loading" @click="loadReleases">
|
|
{{ t('appUpdates.refresh') }}
|
|
</el-button>
|
|
<el-button type="primary" :icon="UploadFilled" @click="openUpload">
|
|
{{ t('appUpdates.upload') }}
|
|
</el-button>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="update-rules">
|
|
<strong>{{ t('appUpdates.boundary') }}</strong><span>{{ t('appUpdates.webOnly') }}</span><span>{{ t('appUpdates.nativeBoundary') }}</span><span>{{ t('appUpdates.autoRollback') }}</span>
|
|
</div>
|
|
|
|
<div class="update-filter">
|
|
<el-select v-model="filter.platform" clearable :placeholder="t('appUpdates.allPlatforms')">
|
|
<el-option label="Android" value="Android" />
|
|
<el-option label="iOS" value="Ios" />
|
|
</el-select>
|
|
<el-select v-model="filter.channel" clearable :placeholder="t('appUpdates.allChannels')">
|
|
<el-option :label="t('appUpdates.production')" value="Production" /><el-option :label="t('appUpdates.staging')" value="Staging" />
|
|
</el-select>
|
|
<el-button type="primary" @click="search">{{ t('appUpdates.search') }}</el-button>
|
|
</div>
|
|
|
|
<el-table v-loading="loading" :data="rows" stripe>
|
|
<el-table-column :label="t('appUpdates.version')" min-width="142">
|
|
<template #default="{ row }">
|
|
<strong class="version">{{ row.version }}</strong>
|
|
<small>{{ t('appUpdates.nativeVersionValue', { version: row.nativeVersion }) }}</small>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.target')" width="132">
|
|
<template #default="{ row }">
|
|
{{ platformLabel(row.platform) }} · {{ channelLabel(row.channel) }}
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.status')" width="94">
|
|
<template #default="{ row }">
|
|
<el-tag :type="statusType(row.status)" effect="plain">
|
|
{{ statusLabel(row.status) }}
|
|
</el-tag>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.releaseNotes')" min-width="210" show-overflow-tooltip>
|
|
<template #default="{ row }">{{ row.releaseNotes || '—' }}</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.bundle')" min-width="205" show-overflow-tooltip>
|
|
<template #default="{ row }">
|
|
<span class="file-name">{{ row.fileName }}</span>
|
|
<small>{{ formatBytes(row.fileSize) }} · {{ row.sha256.slice(0, 12) }}…</small>
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.time')" width="168">
|
|
<template #default="{ row }">
|
|
{{ formatTime(row.publishedAt || row.createdAt) }}
|
|
</template>
|
|
</el-table-column>
|
|
<el-table-column :label="t('appUpdates.actions')" fixed="right" width="152">
|
|
<template #default="{ row }">
|
|
<el-button
|
|
v-if="row.status !== 'Published'"
|
|
link
|
|
type="primary"
|
|
@click="publishRelease(row)"
|
|
>
|
|
{{ t(row.status === 'Archived' ? 'appUpdates.rollback' : 'appUpdates.publish') }}
|
|
</el-button>
|
|
<el-button
|
|
v-if="row.status !== 'Published'"
|
|
link
|
|
type="danger"
|
|
@click="deleteRelease(row)"
|
|
>
|
|
{{ t('appUpdates.delete') }}
|
|
</el-button>
|
|
<span v-else class="active-label">{{ t('appUpdates.active') }}</span>
|
|
</template>
|
|
</el-table-column>
|
|
<template #empty>
|
|
<span>{{ t('appUpdates.empty') }}</span>
|
|
</template>
|
|
</el-table>
|
|
|
|
<div v-if="cursors.length || hasMore" class="cursor-pager">
|
|
<el-button :disabled="!cursors.length || loading" @click="previousPage">{{ t('appUpdates.previous') }}</el-button><span>{{ t('appUpdates.page', { page: filter.page }) }}</span><el-button type="primary" :disabled="!hasMore || loading" @click="nextPage">{{ t('appUpdates.next') }}</el-button>
|
|
</div>
|
|
|
|
<el-dialog
|
|
v-model="uploadVisible"
|
|
:title="t('appUpdates.uploadTitle')"
|
|
width="min(620px, 92vw)"
|
|
destroy-on-close
|
|
>
|
|
<el-form label-position="top">
|
|
<div class="form-grid">
|
|
<el-form-item :label="t('appUpdates.platform')">
|
|
<el-select v-model="form.platform">
|
|
<el-option label="Android" value="Android" />
|
|
<el-option label="iOS" value="Ios" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item :label="t('appUpdates.channel')">
|
|
<el-select v-model="form.channel">
|
|
<el-option :label="t('appUpdates.production')" value="Production" /><el-option :label="t('appUpdates.staging')" value="Staging" />
|
|
</el-select>
|
|
</el-form-item>
|
|
<el-form-item :label="t('appUpdates.hotVersion')">
|
|
<el-input v-model="form.version" :placeholder="t('appUpdates.versionPlaceholder')" />
|
|
</el-form-item>
|
|
<el-form-item :label="t('appUpdates.compatibleNative')"><el-input v-model="form.nativeVersion" :placeholder="t('appUpdates.nativePlaceholder')" />
|
|
</el-form-item>
|
|
</div>
|
|
<el-form-item :label="t('appUpdates.releaseNotes')">
|
|
<el-input
|
|
v-model="form.releaseNotes"
|
|
type="textarea"
|
|
:rows="3"
|
|
maxlength="1000"
|
|
show-word-limit
|
|
:placeholder="t('appUpdates.notesPlaceholder')"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item :label="t('appUpdates.updateZip')">
|
|
<el-upload
|
|
v-model:file-list="uploadFiles"
|
|
accept=".zip,application/zip"
|
|
:auto-upload="false"
|
|
:limit="1"
|
|
:on-change="handleBundleChange"
|
|
:on-remove="handleBundleRemove"
|
|
>
|
|
<el-button :icon="UploadFilled">{{ t('appUpdates.selectZip') }}</el-button>
|
|
<template #tip>
|
|
<div class="el-upload__tip">
|
|
{{ t('appUpdates.zipHint') }}
|
|
</div>
|
|
</template>
|
|
</el-upload>
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button @click="uploadVisible = false">{{ t('appUpdates.cancel') }}</el-button>
|
|
<el-button type="primary" :loading="uploadBusy" @click="uploadRelease">
|
|
{{ t('appUpdates.uploadDraft') }}
|
|
</el-button>
|
|
</template>
|
|
</el-dialog>
|
|
</section>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.update-panel {
|
|
background: #fff;
|
|
border: 1px solid #d8dee1;
|
|
min-width: 0;
|
|
}
|
|
|
|
.update-heading {
|
|
align-items: center;
|
|
border-bottom: 1px solid #d8dee1;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 16px 18px;
|
|
}
|
|
|
|
.update-heading span {
|
|
color: #5f6f7d;
|
|
font-family: "Cascadia Mono", Consolas, monospace;
|
|
font-size: 10px;
|
|
letter-spacing: .09em;
|
|
}
|
|
|
|
.update-heading h3 { font-size: 17px; margin: 3px 0 4px; }
|
|
.update-heading p { color: #526273; font-size: 12px; margin: 0; }
|
|
.heading-actions { display: flex; gap: 8px; }
|
|
|
|
.update-rules {
|
|
align-items: center;
|
|
background: #f5f8f7;
|
|
border-bottom: 1px solid #e0e6e5;
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 8px 18px;
|
|
padding: 10px 18px;
|
|
}
|
|
|
|
.update-rules strong { color: #1f7468; font-size: 11px; }
|
|
.update-rules span { color: #526273; font-size: 11px; }
|
|
.update-rules span::before { content: "·"; margin-right: 8px; }
|
|
|
|
.update-filter {
|
|
display: flex;
|
|
gap: 9px;
|
|
padding: 14px 18px 0;
|
|
}
|
|
|
|
.update-filter .el-select { width: 160px; }
|
|
.version,
|
|
.file-name { display: block; font-family: "Cascadia Mono", Consolas, monospace; }
|
|
.version { color: #1f7468; font-size: 13px; }
|
|
.file-name { font-size: 11px; }
|
|
small { color: #5f6f7d; display: block; font-size: 10px; margin-top: 4px; }
|
|
.active-label { color: #1f7468; font-size: 11px; font-weight: 700; }
|
|
.el-table { margin-top: 12px; }
|
|
.cursor-pager { align-items:center; display:flex; gap:10px; justify-content:flex-end; padding:16px 18px; }
|
|
.cursor-pager span { color:#5f6f7d; font-size:11px; }
|
|
.form-grid { display: grid; gap: 0 14px; grid-template-columns: 1fr 1fr; }
|
|
.form-grid .el-select { width: 100%; }
|
|
|
|
@media (max-width: 720px) {
|
|
.update-heading { align-items: flex-start; display: block; }
|
|
.heading-actions { margin-top: 12px; }
|
|
.update-filter { flex-wrap: wrap; }
|
|
.update-filter .el-select { flex: 1 1 140px; }
|
|
.form-grid { display: block; }
|
|
}
|
|
</style>
|