feat(version): 桌面端更新面板支持指定版本安装
- 新增公开接口 GET /api/version/list(最近 50 条,字段口径同管理端列表), 桌面端下拉不再拼 OSS 地址(版本包被删后拼地址会 404) - 更新面板(登录页 + 首页)加「指定版本更新」选择器:默认选中最新版, 可选全部已发布版本(含回退),回退/同版给出明确文案与二次确认 - 客户端无需发版:do_update_app(file_url) 本就接受任意版本包直链
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
<template>
|
||||
<div class="version-picker">
|
||||
<div class="version-picker-head">
|
||||
<span class="version-picker-title">指定版本更新</span>
|
||||
<button
|
||||
type="button"
|
||||
class="version-picker-refresh"
|
||||
:disabled="loading"
|
||||
@click="emit('reload')"
|
||||
>{{ loading ? '加载中...' : '刷新列表' }}</button>
|
||||
</div>
|
||||
<div v-if="error" class="version-picker-error">{{ error }}</div>
|
||||
<template v-else>
|
||||
<select v-model="selected" class="version-picker-select" :disabled="loading || !versions.length">
|
||||
<option value="">{{ versions.length ? '请选择要安装的版本' : '暂无可选版本' }}</option>
|
||||
<option v-for="item in versions" :key="item.version" :value="item.version">
|
||||
v{{ item.version }}{{ item.createdAt ? ` · ${item.createdAt}` : '' }}
|
||||
</option>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
class="version-picker-btn"
|
||||
:disabled="!selected || updating"
|
||||
@click="submit"
|
||||
>{{ updating ? '更新中...' : '更新到此版本' }}</button>
|
||||
<div v-if="tip" class="version-picker-tip" :class="{ 'is-warn': isFallback }">{{ tip }}</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 「指定版本更新」选择器(登录页 / 首页更新面板共用)。
|
||||
*
|
||||
* 只负责选择与提示;版本列表加载、下载安装流程都在 useVersionUpdate 里
|
||||
* (列表项与判定文案见 shared/utils/version-picker)。
|
||||
* 选到低于本机的版本时给出"回退操作"提示,实际确认框由 doUpdateVersion 再提示一次。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
classifyTargetVersion,
|
||||
describeTargetVersion,
|
||||
type ClientVersionItem,
|
||||
} from '@/shared/utils/version-picker'
|
||||
|
||||
const props = defineProps<{
|
||||
versions: ClientVersionItem[]
|
||||
/** 本机当前版本(空串=未读到,如旧客户端无版本桥) */
|
||||
currentVersion?: string
|
||||
loading?: boolean
|
||||
error?: string
|
||||
updating?: boolean
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update', item: ClientVersionItem): void
|
||||
(e: 'reload'): void
|
||||
}>()
|
||||
|
||||
const selected = ref('')
|
||||
|
||||
const selectedItem = computed(() =>
|
||||
props.versions.find((item) => item.version === selected.value),
|
||||
)
|
||||
|
||||
const kind = computed(() => classifyTargetVersion(props.currentVersion || '', selected.value))
|
||||
const isFallback = computed(() => kind.value === 'older')
|
||||
|
||||
const tip = computed(() =>
|
||||
selected.value ? describeTargetVersion(kind.value, props.currentVersion || '', selected.value) : '',
|
||||
)
|
||||
|
||||
// 列表刷新后选中项可能已不存在(版本被删除):清空选择,避免误装;
|
||||
// 无选中时默认选列表第一条(列表按版本号倒序,第一条即最新版)
|
||||
watch(
|
||||
() => props.versions,
|
||||
(list) => {
|
||||
if (selected.value && !list.some((item) => item.version === selected.value)) {
|
||||
selected.value = ''
|
||||
}
|
||||
if (!selected.value && list.length) {
|
||||
selected.value = list[0].version
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function submit() {
|
||||
const item = selectedItem.value
|
||||
if (!item) return
|
||||
emit('update', item)
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.version-picker {
|
||||
margin-top: 10px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.version-picker-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.version-picker-title {
|
||||
font-size: 12.5px;
|
||||
font-weight: 600;
|
||||
color: #4e6479;
|
||||
}
|
||||
|
||||
.version-picker-refresh {
|
||||
padding: 0;
|
||||
font-size: 11.5px;
|
||||
color: #71808d;
|
||||
background: transparent;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.version-picker-refresh:hover:not(:disabled) {
|
||||
color: #3498db;
|
||||
}
|
||||
|
||||
.version-picker-refresh:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.version-picker-error {
|
||||
font-size: 12px;
|
||||
color: #b8860b;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.version-picker-select {
|
||||
width: 100%;
|
||||
padding: 5px 6px;
|
||||
font-size: 12.5px;
|
||||
color: #333;
|
||||
background: #fff;
|
||||
border: 1px solid #d5e6f2;
|
||||
border-radius: 6px;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.version-picker-btn {
|
||||
width: 100%;
|
||||
margin-top: 6px;
|
||||
padding: 5px 12px;
|
||||
font-size: 12.5px;
|
||||
color: #fff;
|
||||
background: #3498db;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.version-picker-btn:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.version-picker-btn:disabled {
|
||||
opacity: 0.6;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.version-picker-tip {
|
||||
margin-top: 6px;
|
||||
font-size: 11.5px;
|
||||
line-height: 1.6;
|
||||
color: #8293a5;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* 回退提示用醒目色:低于本机的版本必须让用户看清"这是回退" */
|
||||
.version-picker-tip.is-warn {
|
||||
color: #b8860b;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user