apk包区分sdk和without sdk
Some checks are pending
CI / Test (ubuntu-latest) (push) Waiting to run
CI / Test (windows-latest) (push) Waiting to run
CI / Lint (ubuntu-latest) (push) Waiting to run
CI / Lint (windows-latest) (push) Waiting to run
CI / Check (ubuntu-latest) (push) Waiting to run
CI / Check (windows-latest) (push) Waiting to run
CI / CI OK (push) Blocked by required conditions
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Waiting to run
Deploy Website on push / Deploy Push Playground Ftp (push) Waiting to run
Deploy Website on push / Deploy Push Docs Ftp (push) Waiting to run
Deploy Website on push / Deploy Push Antd Ftp (push) Waiting to run
Deploy Website on push / Deploy Push Element Ftp (push) Waiting to run
Deploy Website on push / Deploy Push Naive Ftp (push) Waiting to run
Release Drafter / update_release_draft (push) Waiting to run

This commit is contained in:
hahwu 2026-05-07 15:35:49 +08:00
parent 5cc74ac42c
commit ae7c75abc5
2 changed files with 82 additions and 32 deletions

View File

@ -2,18 +2,25 @@ import { requestClient } from '#/api/request';
export namespace ApkApi {
export type Environment = 'dev' | 'prod' | 'stable';
export type PackageType = 'with_sdk' | 'without_sdk';
export interface PackageItem {
downloadPath: string;
env: Environment;
packageType: PackageType;
exists: boolean;
fileName: string;
size: number;
uploadedAt: string;
version: string;
}
export interface EnvironmentPackages {
env: Environment;
variants: Partial<Record<PackageType, PackageItem>>;
}
}
export async function getApkPackagesApi() {
return requestClient.get<ApkApi.PackageItem[]>('/apk/packages');
return requestClient.get<ApkApi.EnvironmentPackages[]>('/apk/packages');
}

View File

@ -14,8 +14,9 @@ const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
const accessStore = useAccessStore();
const loading = ref(false);
const downloadingEnv = ref<ApkApi.Environment | ''>('');
const packages = ref<ApkApi.PackageItem[]>([]);
const downloadingKey = ref('');
const packages = ref<ApkApi.EnvironmentPackages[]>([]);
const packageTypes: ApkApi.PackageType[] = ['with_sdk', 'without_sdk'];
const envLabelMap: Record<ApkApi.Environment, string> = {
dev: '开发环境',
@ -29,6 +30,16 @@ const envDescriptionMap: Record<ApkApi.Environment, string> = {
prod: '用于正式对外发布。',
};
const packageTypeLabelMap: Record<ApkApi.PackageType, string> = {
with_sdk: '包含 SDK',
without_sdk: '不包含 SDK',
};
const packageTypeDescriptionMap: Record<ApkApi.PackageType, string> = {
with_sdk: '适合渠道联调、SDK 验证和三方能力测试。',
without_sdk: '适合纯净包验证、基础功能测试和问题排查。',
};
async function loadPackages() {
loading.value = true;
try {
@ -57,8 +68,11 @@ function formatTime(value: string) {
return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
}
function resolveDownloadUrl(env: ApkApi.Environment) {
return `${apiURL.replace(/\/$/, '')}/apk/download/${env}`;
function resolveDownloadUrl(item: ApkApi.PackageItem) {
if (item.downloadPath) {
return `${apiURL.replace(/\/$/, '')}${item.downloadPath}`;
}
return `${apiURL.replace(/\/$/, '')}/apk/download/${item.env}?packageType=${item.packageType}`;
}
function resolveDownloadName(item: ApkApi.PackageItem, disposition: null | string) {
@ -90,9 +104,9 @@ async function downloadPackage(item: ApkApi.PackageItem) {
return;
}
downloadingEnv.value = item.env;
downloadingKey.value = `${item.env}:${item.packageType}`;
try {
const response = await fetch(resolveDownloadUrl(item.env), {
const response = await fetch(resolveDownloadUrl(item), {
headers: {
Authorization: `Bearer ${accessStore.accessToken}`,
},
@ -118,12 +132,23 @@ async function downloadPackage(item: ApkApi.PackageItem) {
message.success(`开始下载 ${downloadName}`);
} catch (error) {
console.error(error);
message.error(`${envLabelMap[item.env]} APK 下载失败`);
message.error(`${envLabelMap[item.env]} ${packageTypeLabelMap[item.packageType]} APK 下载失败`);
} finally {
downloadingEnv.value = '';
downloadingKey.value = '';
}
}
function getVariantItem(
envPackages: ApkApi.EnvironmentPackages,
packageType: ApkApi.PackageType,
) {
return envPackages.variants[packageType];
}
function getDownloadKey(env: ApkApi.Environment, packageType: ApkApi.PackageType) {
return `${env}:${packageType}`;
}
onMounted(() => {
loadPackages();
});
@ -134,42 +159,60 @@ onMounted(() => {
<div class="space-y-4 p-4">
<Card title="客户端下载说明">
<TypographyParagraph>
当前页面展示 devstableprod 三套客户端 APK
当前页面展示 devstableprod 三套环境下的 SDK 包和非 SDK
Jenkins 通过后端上传接口更新包后这里会自动展示最新版本并支持后台下载
</TypographyParagraph>
<Button :loading="loading" type="primary" @click="loadPackages">刷新列表</Button>
</Card>
<div v-if="packages.length" class="grid gap-4 md:grid-cols-2 xl:grid-cols-3">
<Card v-for="item in packages" :key="item.env" :title="envLabelMap[item.env]">
<Card v-for="envPackages in packages" :key="envPackages.env" :title="envLabelMap[envPackages.env]">
<Space wrap>
<Tag :color="item.exists ? 'green' : 'default'">
{{ item.exists ? '已上传' : '暂无包' }}
</Tag>
<Tag color="blue">{{ item.env }}</Tag>
<Tag color="blue">{{ envPackages.env }}</Tag>
</Space>
<TypographyParagraph class="mt-4 text-gray-500">
{{ envDescriptionMap[item.env] }}
{{ envDescriptionMap[envPackages.env] }}
</TypographyParagraph>
<div class="space-y-2 text-sm leading-6">
<div>文件名{{ item.fileName || '-' }}</div>
<div>版本号{{ item.version || '-' }}</div>
<div>文件大小{{ formatSize(item.size) }}</div>
<div>上传时间{{ formatTime(item.uploadedAt) }}</div>
</div>
<div class="mt-4">
<Button
block
type="primary"
:disabled="!item.exists"
:loading="downloadingEnv === item.env"
@click="downloadPackage(item)"
<div class="mt-4 space-y-4">
<div
v-for="packageType in packageTypes"
:key="getDownloadKey(envPackages.env, packageType)"
class="rounded-lg border border-gray-200 p-4"
>
下载 APK
</Button>
<div class="flex items-center justify-between gap-2">
<div class="text-sm font-medium text-gray-900">
{{ packageTypeLabelMap[packageType] }}
</div>
<Tag :color="getVariantItem(envPackages, packageType)?.exists ? 'green' : 'default'">
{{ getVariantItem(envPackages, packageType)?.exists ? '已上传' : '暂无包' }}
</Tag>
</div>
<TypographyParagraph class="mt-3 text-gray-500">
{{ packageTypeDescriptionMap[packageType] }}
</TypographyParagraph>
<div class="space-y-2 text-sm leading-6">
<div>文件名{{ getVariantItem(envPackages, packageType)?.fileName || '-' }}</div>
<div>版本号{{ getVariantItem(envPackages, packageType)?.version || '-' }}</div>
<div>文件大小{{ formatSize(getVariantItem(envPackages, packageType)?.size || 0) }}</div>
<div>上传时间{{ formatTime(getVariantItem(envPackages, packageType)?.uploadedAt || '') }}</div>
</div>
<div class="mt-4">
<Button
block
type="primary"
:disabled="!getVariantItem(envPackages, packageType)?.exists"
:loading="downloadingKey === getDownloadKey(envPackages.env, packageType)"
@click="downloadPackage(getVariantItem(envPackages, packageType) as ApkApi.PackageItem)"
>
下载 APK
</Button>
</div>
</div>
</div>
</Card>
</div>