feat: 版本推送默认展示全部项目版本; 公告列表显示关联项目
This commit is contained in:
1 parent
c4b00cbf85
commit
5b73d0921d
6 files changed
+71
-20
No files matched your search
@@ -29,27 +29,33 @@ class AnnouncementController extends Controller
|
|||||||
$params = [];
|
$params = [];
|
||||||
|
|
||||||
if ($keyword !== '') {
|
if ($keyword !== '') {
|
||||||
$where .= ' AND (title LIKE ? OR content LIKE ?)';
|
$where .= ' AND (a.title LIKE ? OR a.content LIKE ?)';
|
||||||
$params[] = "%{$keyword}%";
|
$params[] = "%{$keyword}%";
|
||||||
$params[] = "%{$keyword}%";
|
$params[] = "%{$keyword}%";
|
||||||
}
|
}
|
||||||
if ($type !== '' && in_array($type, ['system', 'update', 'promo', 'notice'], true)) {
|
if ($type !== '' && in_array($type, ['system', 'update', 'promo', 'notice'], true)) {
|
||||||
$where .= ' AND type = ?';
|
$where .= ' AND a.type = ?';
|
||||||
$params[] = $type;
|
$params[] = $type;
|
||||||
}
|
}
|
||||||
if ($target !== '' && in_array($target, ['all', 'admin', 'agent', 'client'], true)) {
|
if ($target !== '' && in_array($target, ['all', 'admin', 'agent', 'client'], true)) {
|
||||||
$where .= ' AND target = ?';
|
$where .= ' AND a.target = ?';
|
||||||
$params[] = $target;
|
$params[] = $target;
|
||||||
}
|
}
|
||||||
if ($status !== '') {
|
if ($status !== '') {
|
||||||
$where .= ' AND status = ?';
|
$where .= ' AND a.status = ?';
|
||||||
$params[] = (int) $status;
|
$params[] = (int) $status;
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = (int) $db->fetchColumn("SELECT COUNT(*) FROM {$db->table('announcements')} {$where}", $params);
|
$total = (int) $db->fetchColumn(
|
||||||
|
"SELECT COUNT(*) FROM {$db->table('announcements')} a {$where}",
|
||||||
|
$params
|
||||||
|
);
|
||||||
$list = $db->fetchAll(
|
$list = $db->fetchAll(
|
||||||
"SELECT * FROM {$db->table('announcements')} {$where}
|
"SELECT a.*, p.name AS project_name
|
||||||
ORDER BY is_top DESC, id DESC
|
FROM {$db->table('announcements')} a
|
||||||
|
LEFT JOIN {$db->table('projects')} p ON p.id = a.project_id
|
||||||
|
{$where}
|
||||||
|
ORDER BY a.is_top DESC, a.id DESC
|
||||||
LIMIT {$offset}, {$pageSize}",
|
LIMIT {$offset}, {$pageSize}",
|
||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,6 +14,42 @@ class ProjectVersionController extends Controller
|
|||||||
private const ALLOWED_EXT = ['zip', 'tar', 'gz', 'tgz', '7z', 'exe', 'dmg', 'apk', 'msi', 'pkg', 'rar', 'bin'];
|
private const ALLOWED_EXT = ['zip', 'tar', 'gz', 'tgz', '7z', 'exe', 'dmg', 'apk', 'msi', 'pkg', 'rar', 'bin'];
|
||||||
private const MAX_SIZE = 200 * 1024 * 1024; // 200MB
|
private const MAX_SIZE = 200 * 1024 * 1024; // 200MB
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全部版本列表(跨项目,管理页默认展示)
|
||||||
|
* GET /api/versions?project_id=
|
||||||
|
*/
|
||||||
|
public function allList(): void
|
||||||
|
{
|
||||||
|
$user = $this->getCurrentUser() ?: [];
|
||||||
|
$projectId = !empty($_GET['project_id']) ? (int) $_GET['project_id'] : null;
|
||||||
|
|
||||||
|
$db = Database::getInstance();
|
||||||
|
$scope = VersionService::scope($user);
|
||||||
|
$where = $scope['where'];
|
||||||
|
$params = $scope['params'];
|
||||||
|
|
||||||
|
if ($projectId) {
|
||||||
|
$where .= ' AND v.project_id = ?';
|
||||||
|
$params[] = $projectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = $db->fetchAll(
|
||||||
|
"SELECT v.*, p.name AS project_name
|
||||||
|
FROM {$db->table('project_versions')} v
|
||||||
|
LEFT JOIN {$db->table('projects')} p ON p.id = v.project_id
|
||||||
|
WHERE {$where}
|
||||||
|
ORDER BY v.id DESC",
|
||||||
|
$params
|
||||||
|
);
|
||||||
|
|
||||||
|
$list = array_map(
|
||||||
|
static fn (array $row): array => beijingTimeFields($row, ['created_at', 'updated_at']),
|
||||||
|
$list
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->success($list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 版本列表
|
* 版本列表
|
||||||
* GET /api/projects/{projectId}/versions
|
* GET /api/projects/{projectId}/versions
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ $router->group('api', function ($router) {
|
|||||||
$router->post('installations/batch-delete', [InstallationController::class, 'batchDelete']);
|
$router->post('installations/batch-delete', [InstallationController::class, 'batchDelete']);
|
||||||
|
|
||||||
// 项目版本/安装包管理 (发布仅 admin/project_admin; agent 只读)
|
// 项目版本/安装包管理 (发布仅 admin/project_admin; agent 只读)
|
||||||
|
$router->get('versions', [ProjectVersionController::class, 'allList']);
|
||||||
$router->get('projects/{projectId}/versions', [ProjectVersionController::class, 'list']);
|
$router->get('projects/{projectId}/versions', [ProjectVersionController::class, 'list']);
|
||||||
$router->get('projects/{projectId}/versions/{id}', [ProjectVersionController::class, 'detail']);
|
$router->get('projects/{projectId}/versions/{id}', [ProjectVersionController::class, 'detail']);
|
||||||
$router->post('projects/{projectId}/versions', [ProjectVersionController::class, 'create']);
|
$router->post('projects/{projectId}/versions', [ProjectVersionController::class, 'create']);
|
||||||
|
|||||||
@@ -4,6 +4,10 @@ import request from './index'
|
|||||||
* 项目版本/安装包 API
|
* 项目版本/安装包 API
|
||||||
*/
|
*/
|
||||||
const versionApi = {
|
const versionApi = {
|
||||||
|
/** 全部版本(默认页) */
|
||||||
|
all(params) {
|
||||||
|
return request.get('/versions', { params })
|
||||||
|
},
|
||||||
list(projectId, params) {
|
list(projectId, params) {
|
||||||
return request.get(`/projects/${projectId}/versions`, { params })
|
return request.get(`/projects/${projectId}/versions`, { params })
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -53,6 +53,9 @@
|
|||||||
<el-table-column prop="target" label="对象" width="90" align="center">
|
<el-table-column prop="target" label="对象" width="90" align="center">
|
||||||
<template #default="{ row }">{{ targetLabel(row.target) }}</template>
|
<template #default="{ row }">{{ targetLabel(row.target) }}</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
<el-table-column prop="project_name" label="关联项目" width="130" show-overflow-tooltip>
|
||||||
|
<template #default="{ row }">{{ row.project_name || (row.project_id ? row.project_id : '全部项目') }}</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column prop="is_popup" label="弹窗" width="80" align="center">
|
<el-table-column prop="is_popup" label="弹窗" width="80" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="row.is_popup == 1 ? 'danger' : 'info'" size="small">{{ row.is_popup == 1 ? '是' : '否' }}</el-tag>
|
<el-tag :type="row.is_popup == 1 ? 'danger' : 'info'" size="small">{{ row.is_popup == 1 ? '是' : '否' }}</el-tag>
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="projectId"
|
v-model="projectId"
|
||||||
placeholder="选择项目"
|
placeholder="全部项目"
|
||||||
|
clearable
|
||||||
style="width: 200px"
|
style="width: 200px"
|
||||||
:loading="projectsLoading"
|
:loading="projectsLoading"
|
||||||
@change="onProjectChange"
|
@change="onProjectChange"
|
||||||
@@ -17,12 +18,12 @@
|
|||||||
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
|
<el-option v-for="p in projects" :key="p.id" :label="p.name" :value="p.id" />
|
||||||
</el-select>
|
</el-select>
|
||||||
<el-button
|
<el-button
|
||||||
v-if="canPublish && projectId"
|
v-if="canPublish"
|
||||||
type="primary"
|
type="primary"
|
||||||
:icon="Upload"
|
:icon="Upload"
|
||||||
@click="openUploadDialog"
|
@click="openUploadDialog"
|
||||||
>发布新版本</el-button>
|
>发布新版本</el-button>
|
||||||
<el-button :icon="Refresh" circle @click="refresh" :disabled="!projectId" />
|
<el-button :icon="Refresh" circle @click="refresh" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -44,6 +45,10 @@
|
|||||||
class="data-table"
|
class="data-table"
|
||||||
:max-height="560"
|
:max-height="560"
|
||||||
>
|
>
|
||||||
|
<el-table-column type="selection" width="50" align="center" fixed="left" v-if="false" />
|
||||||
|
<el-table-column prop="project_name" label="项目" width="130" show-overflow-tooltip>
|
||||||
|
<template #default="{ row }">{{ row.project_name || row.project_id }}</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column prop="version" label="版本号" width="120">
|
<el-table-column prop="version" label="版本号" width="120">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag v-if="row.is_latest == 1" type="success" size="small" style="margin-right:6px">最新</el-tag>
|
<el-tag v-if="row.is_latest == 1" type="success" size="small" style="margin-right:6px">最新</el-tag>
|
||||||
@@ -205,6 +210,7 @@ const canPublish = computed(() => ['admin', 'project_admin'].includes(user.value
|
|||||||
|
|
||||||
const projects = ref([])
|
const projects = ref([])
|
||||||
const projectsLoading = ref(false)
|
const projectsLoading = ref(false)
|
||||||
|
/** 空/null = 全部项目 */
|
||||||
const projectId = ref(route.query.project_id ? Number(route.query.project_id) : null)
|
const projectId = ref(route.query.project_id ? Number(route.query.project_id) : null)
|
||||||
const list = ref([])
|
const list = ref([])
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
@@ -262,10 +268,6 @@ async function fetchProjects() {
|
|||||||
let data = res.data.list || res.data || []
|
let data = res.data.list || res.data || []
|
||||||
if (!Array.isArray(data)) data = []
|
if (!Array.isArray(data)) data = []
|
||||||
projects.value = data
|
projects.value = data
|
||||||
if (!projectId.value && data.length) {
|
|
||||||
projectId.value = Number(data[0].id)
|
|
||||||
await refresh()
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
projects.value = []
|
projects.value = []
|
||||||
} finally {
|
} finally {
|
||||||
@@ -274,13 +276,11 @@ async function fetchProjects() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh() {
|
||||||
if (!projectId.value) {
|
|
||||||
list.value = []
|
|
||||||
return
|
|
||||||
}
|
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await versionApi.list(projectId.value)
|
const params = {}
|
||||||
|
if (projectId.value) params.project_id = projectId.value
|
||||||
|
const res = await versionApi.all(params)
|
||||||
list.value = Array.isArray(res.data) ? res.data : []
|
list.value = Array.isArray(res.data) ? res.data : []
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@@ -296,7 +296,7 @@ function onProjectChange() {
|
|||||||
|
|
||||||
function openUploadDialog() {
|
function openUploadDialog() {
|
||||||
if (!projectId.value) {
|
if (!projectId.value) {
|
||||||
ElMessage.warning('请先选择项目')
|
ElMessage.warning('请先在右上角选择要发布到的项目')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uploadVisible.value = true
|
uploadVisible.value = true
|
||||||
@@ -407,6 +407,7 @@ async function handleDelete(row) {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
fetchProjects()
|
fetchProjects()
|
||||||
|
refresh()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user