fix(app-web): 版本面板「已是最新」不再出更新按钮+行内动作按钮字号钉死 12px
This commit is contained in:
@@ -15,20 +15,25 @@
|
||||
v-model="selected"
|
||||
class="version-picker-select"
|
||||
:disabled="loading || !versions.length"
|
||||
@change="emit('select', selected)"
|
||||
@change="onSelectChange"
|
||||
>
|
||||
<option value="">{{ versions.length ? '请选择要安装的版本' : '暂无可选版本' }}</option>
|
||||
<option v-for="item in versions" :key="item.version" :value="item.version">
|
||||
v{{ item.version }}
|
||||
</option>
|
||||
</select>
|
||||
<!-- 没有选定目标版本就不出按钮:本机已是最新时默认不选中任何版本,
|
||||
更新按钮随之消失,更新日志与回退入口照旧可用 -->
|
||||
<button
|
||||
v-if="selected"
|
||||
type="button"
|
||||
class="version-picker-btn"
|
||||
:disabled="!selected || updating"
|
||||
:disabled="updating"
|
||||
@click="submit"
|
||||
>{{ updating ? '更新中...' : '更新到此版本' }}</button>
|
||||
<div v-if="tip" class="version-picker-tip" :class="{ 'is-warn': isFallback }">{{ tip }}</div>
|
||||
<div v-if="tip || idleTip" class="version-picker-tip" :class="{ 'is-warn': isFallback }">
|
||||
{{ tip || idleTip }}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
@@ -41,11 +46,16 @@
|
||||
* (列表项与判定文案见 shared/utils/version-picker)。
|
||||
* 选到低于本机的版本时给出"回退操作"提示,实际确认框由 doUpdateVersion 再提示一次。
|
||||
* 用户改选时 emit('select', version),页面转发给 useVersionUpdate 以切换更新日志。
|
||||
*
|
||||
* 默认选中口径:仅当列表第一条(最新版)高于本机时才自动选中;本机已是最新或更高时
|
||||
* 不默认选中、连"更新到此版本"按钮一起不出(判定见 pickDefaultVersion)——
|
||||
* 已经是最新版本的人不该再看见更新按钮,但更新日志与旧版本回退照旧可用。
|
||||
*/
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import {
|
||||
classifyTargetVersion,
|
||||
describeTargetVersion,
|
||||
pickDefaultVersion,
|
||||
type ClientVersionItem,
|
||||
} from '@/shared/utils/version-picker'
|
||||
|
||||
@@ -66,6 +76,8 @@ const emit = defineEmits<{
|
||||
}>()
|
||||
|
||||
const selected = ref('')
|
||||
/** 当前选中是否由用户显式改选(是=不被自动默认覆盖;自动默认不改变更新日志视图) */
|
||||
const pickedByUser = ref(false)
|
||||
|
||||
const selectedItem = computed(() =>
|
||||
props.versions.find((item) => item.version === selected.value),
|
||||
@@ -78,24 +90,52 @@ const tip = computed(() =>
|
||||
selected.value ? describeTargetVersion(kind.value, props.currentVersion || '', selected.value) : '',
|
||||
)
|
||||
|
||||
// 列表刷新后选中项可能已不存在(版本被删除):清空选择并通知父组件回退日志,
|
||||
// 避免日志还停留在已下架的版本上;
|
||||
// 无选中时默认选列表第一条(列表按版本号倒序,第一条即最新版)——这只是给「更新到此版本」
|
||||
// 一个默认目标,不触发 select 事件,更新日志保持默认视图(用户主动改选才切换)
|
||||
/**
|
||||
* 没有选中目标版本时的说明:本机已是最新(或更高)时讲清楚"为什么没有更新按钮",
|
||||
* 并提示回退/重装要自己从列表里挑版本。有新版时默认已选中,走 tip 分支,这里不出文案。
|
||||
* 不再复述版本号——面板上方那行"已是最新版本 vX"已经讲过了。
|
||||
*/
|
||||
const idleTip = computed(() => {
|
||||
if (selected.value) return ''
|
||||
const first = props.versions[0]
|
||||
if (!first || !props.currentVersion) return ''
|
||||
const kind = classifyTargetVersion(props.currentVersion, first.version)
|
||||
if (kind === 'newer') return ''
|
||||
return kind === 'older'
|
||||
? '当前版本高于线上发布版本;如需回退或重装,请从列表选择目标版本'
|
||||
: '无需更新;如需回退或重装,请从列表选择目标版本'
|
||||
})
|
||||
|
||||
/** 列表/本机版本变化时同步选中项:用户显式选过就尊重(除非该版本已下架)。 */
|
||||
function syncSelection(list: ClientVersionItem[], current: string) {
|
||||
if (!list.length) {
|
||||
selected.value = ''
|
||||
pickedByUser.value = false
|
||||
return
|
||||
}
|
||||
if (pickedByUser.value) {
|
||||
if (selected.value && list.some((item) => item.version === selected.value)) return
|
||||
// 用户选的版本被删除:清空选择并退回自动默认,同时通知父组件回退日志
|
||||
pickedByUser.value = false
|
||||
selected.value = ''
|
||||
emit('select', '')
|
||||
}
|
||||
selected.value = pickDefaultVersion(current, list)
|
||||
}
|
||||
|
||||
// 版本列表刷新、本机版本异步读到(桌面桥)都会改变"该不该有默认目标":
|
||||
// 两个来源一起观察,避免列表先到(默认选了最新版)本机版本后到(其实已是最新)时按钮还挂着
|
||||
watch(
|
||||
() => props.versions,
|
||||
(list) => {
|
||||
if (selected.value && !list.some((item) => item.version === selected.value)) {
|
||||
selected.value = ''
|
||||
emit('select', '')
|
||||
}
|
||||
if (!selected.value && list.length) {
|
||||
selected.value = list[0].version
|
||||
}
|
||||
},
|
||||
[() => props.versions, () => props.currentVersion],
|
||||
([list, current]) => syncSelection(list, current || ''),
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
function onSelectChange() {
|
||||
pickedByUser.value = Boolean(selected.value)
|
||||
emit('select', selected.value)
|
||||
}
|
||||
|
||||
function submit() {
|
||||
const item = selectedItem.value
|
||||
if (!item) return
|
||||
|
||||
@@ -75,8 +75,10 @@ defineProps<{
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 状态徽章与同排动作按钮共用一套尺寸(12px 字号 + 6px 10px 内边距),
|
||||
否则徽章比按钮矮一截、字也小一号——各 Tab 的按钮样式自己写,徽章只有这里一处。 */
|
||||
.status {
|
||||
padding: 4px 10px;
|
||||
padding: 6px 10px;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
@@ -87,9 +89,11 @@ defineProps<{
|
||||
color: #2ecc71;
|
||||
}
|
||||
|
||||
/* 「失败」永远和「删除」并排出现:底色与文字色取同一个红(rgba .12 + #ff8f8f),
|
||||
别再用更浓的 .18 + #ff6b6b,否则同一排里徽章比按钮更刺眼。 */
|
||||
.status.failed {
|
||||
background: rgba(231, 76, 60, .18);
|
||||
color: #ff6b6b;
|
||||
background: rgba(231, 76, 60, .12);
|
||||
color: #ff8f8f;
|
||||
}
|
||||
|
||||
.status.running {
|
||||
|
||||
@@ -74,6 +74,25 @@ export function classifyTargetVersion(current: string, target: string): TargetVe
|
||||
return 'same'
|
||||
}
|
||||
|
||||
/**
|
||||
* 「指定版本更新」下拉的默认选中项。
|
||||
*
|
||||
* 只有列表第一条(列表按版本号倒序,即最新版)确实高于本机时才默认选中它;
|
||||
* 本机已是最新(同版)或更高(回滚过/灰度)时返回空串——
|
||||
* 否则下拉一打开就停在本机已装的版本上,「更新到此版本」会退化成"一键重装"的假更新按钮:
|
||||
* 用户已经是最新版却还看见一个更新按钮,与本面板的语义冲突。
|
||||
* 本机版本读不到(旧客户端无版本桥 / 浏览器形态)时仍默认选第一条:没有本机版本可比,
|
||||
* 让用户能一键装最新版。
|
||||
*
|
||||
* @returns 默认选中的版本号;空串=不默认选中(等用户显式挑一个版本,回退/重装都走显式选择)
|
||||
*/
|
||||
export function pickDefaultVersion(current: string, versions: ClientVersionItem[]): string {
|
||||
const first = versions[0]
|
||||
if (!first) return ''
|
||||
const kind = classifyTargetVersion(current, first.version)
|
||||
return kind === 'same' || kind === 'older' ? '' : first.version
|
||||
}
|
||||
|
||||
/** 目标版本提示/确认文案(同版与回退必须说清楚,避免用户以为在升级)。 */
|
||||
export function describeTargetVersion(kind: TargetVersionKind, current: string, target: string): string {
|
||||
switch (kind) {
|
||||
|
||||
Reference in New Issue
Block a user