feat: show collaboration record creators

This commit is contained in:
gin
2026-05-27 20:29:27 +08:00
parent d26a012edb
commit 98eae63435
9 changed files with 203 additions and 43 deletions
+12 -2
View File
@@ -16,6 +16,7 @@ export interface CollaborationRecordListCommand extends BasePageQuery {
brand?: string;
goods?: string;
cooperationPlatform?: string;
creatorId?: number;
purchaseBeginTime?: string;
purchaseEndTime?: string;
}
@@ -89,6 +90,8 @@ export interface CollaborationRecordPageResponse {
completeDate?: string;
requirements?: string;
remark?: string;
creatorId?: number;
creatorName?: string;
tasksNum: number;
completedTasksNum: number;
purchaseSettlementStatus: SettlementStatusDTO;
@@ -182,12 +185,19 @@ export const getCollaborationOptionsApi = () => {
);
};
export const getCollaborationMonthlyStatisticsApi = (year: number) => {
export interface CollaborationMonthlyStatisticsCommand {
year: number;
creatorId?: number;
}
export const getCollaborationMonthlyStatisticsApi = (
params: CollaborationMonthlyStatisticsCommand
) => {
return http.request<ResponseData<CollaborationMonthlyStatisticsResponse[]>>(
"get",
"/collaboration/record/monthly-statistics",
{
params: { year }
params
}
);
};
@@ -30,6 +30,9 @@ const {
deadlineRange,
purchaseRange,
optionMap,
creatorOptions,
isAdmin,
getUserDisplayName,
multipleSelection,
onSearch,
onSortChanged,
@@ -93,6 +96,22 @@ function openDialog(
class="!w-[180px]"
/>
</el-form-item>
<el-form-item v-if="isAdmin" label="创建者" prop="creatorId">
<el-select
v-model="searchFormParams.creatorId"
placeholder="请选择创建者"
clearable
filterable
class="!w-[160px]"
>
<el-option
v-for="item in creatorOptions"
:key="item.userId"
:label="getUserDisplayName(item)"
:value="item.userId"
/>
</el-select>
</el-form-item>
<el-form-item label="合作平台" prop="cooperationPlatform">
<el-select
v-model="searchFormParams.cooperationPlatform"
@@ -4,6 +4,8 @@ import { ElMessageBox, Sort } from "element-plus";
import { computed, onMounted, reactive, ref, toRaw, unref } from "vue";
import { CommonUtils } from "@/utils/common";
import { PaginationProps } from "@pureadmin/table";
import { getUserListApi, UserDTO } from "@/api/system/user";
import { useUserStoreHook } from "@/store/modules/user";
import {
CollaborationOptionResponse,
CollaborationRecordListCommand,
@@ -20,7 +22,14 @@ const statusTypeMap = {
PARTIAL: "warning"
};
function getUserDisplayName(user: UserDTO) {
return user.nickname || user.username || "";
}
export function useCollaborationRecordHook() {
const userStore = useUserStoreHook();
const isAdmin = computed(() => userStore.roles?.includes("admin"));
const defaultSort: Sort = {
prop: "deadline",
order: "descending"
@@ -36,6 +45,7 @@ export function useCollaborationRecordHook() {
const searchFormParams = reactive<CollaborationRecordListCommand>({
brand: "",
goods: "",
creatorId: undefined,
cooperationPlatform: undefined
});
@@ -55,6 +65,7 @@ export function useCollaborationRecordHook() {
const dataList = ref<CollaborationRecordPageResponse[]>([]);
const optionMap = ref<Record<string, string[]>>({});
const creatorOptions = ref<UserDTO[]>([]);
const pageLoading = ref(true);
const multipleSelection = ref<number[]>([]);
const sortState = ref<Sort>(defaultSort);
@@ -63,6 +74,12 @@ export function useCollaborationRecordHook() {
{ type: "selection", align: "left" },
{ label: "品牌", prop: "brand", minWidth: 120 },
{ label: "物品", prop: "goods", minWidth: 120 },
{
label: "创建者",
prop: "creatorName",
minWidth: 110,
hide: !isAdmin.value
},
{ label: "合作平台", prop: "cooperationPlatform", minWidth: 110 },
{ label: "留存方式", prop: "retainedMethod", minWidth: 100 },
{ label: "购入方式", prop: "purchaseMethod", minWidth: 100 },
@@ -126,8 +143,9 @@ export function useCollaborationRecordHook() {
function renderStatus(status, size) {
if (!status) return "";
const type = statusTypeMap[status.status] || "info";
return (
<el-tag size={size} type={statusTypeMap[status.status]} effect="plain">
<el-tag size={size} type={type} effect="plain">
{status.label}
</el-tag>
);
@@ -195,6 +213,12 @@ export function useCollaborationRecordHook() {
);
}
async function getCreatorOptions() {
if (!isAdmin.value) return;
const { data } = await getUserListApi({ pageNum: 1, pageSize: 1000 });
creatorOptions.value = data.rows;
}
async function handleDelete(row: CollaborationRecordPageResponse) {
await deleteCollaborationRecordApi([row.recordId]);
message(`您删除了编号为${row.recordId}的合作记录`, { type: "success" });
@@ -237,6 +261,7 @@ export function useCollaborationRecordHook() {
onMounted(() => {
getOptions();
getCreatorOptions();
getRecordList();
});
@@ -250,6 +275,9 @@ export function useCollaborationRecordHook() {
deadlineRange,
purchaseRange,
optionMap,
creatorOptions,
isAdmin,
getUserDisplayName,
multipleSelection,
onSearch,
onSortChanged,
@@ -5,8 +5,16 @@ defineOptions({
name: "CollaborationStatistics"
});
const { chartRef, selectedYear, yearOptions, getStatistics } =
useCollaborationStatisticsHook();
const {
chartRef,
selectedYear,
selectedCreatorId,
yearOptions,
creatorOptions,
isAdmin,
getUserDisplayName,
getStatistics
} = useCollaborationStatisticsHook();
</script>
<template>
@@ -15,18 +23,36 @@ const { chartRef, selectedYear, yearOptions, getStatistics } =
<template #header>
<div class="card-header">
<span>月度统计</span>
<el-select
v-model="selectedYear"
class="!w-[140px]"
@change="getStatistics"
>
<el-option
v-for="year in yearOptions"
:key="year"
:label="`${year}年`"
:value="year"
/>
</el-select>
<div class="filters">
<el-select
v-if="isAdmin"
v-model="selectedCreatorId"
placeholder="全部用户"
clearable
filterable
class="!w-[160px]"
@change="getStatistics"
>
<el-option
v-for="user in creatorOptions"
:key="user.userId"
:label="getUserDisplayName(user)"
:value="user.userId"
/>
</el-select>
<el-select
v-model="selectedYear"
class="!w-[140px]"
@change="getStatistics"
>
<el-option
v-for="year in yearOptions"
:key="year"
:label="`${year}年`"
:value="year"
/>
</el-select>
</div>
</div>
</template>
<div ref="chartRef" class="chart" />
@@ -41,6 +67,11 @@ const { chartRef, selectedYear, yearOptions, getStatistics } =
justify-content: space-between;
}
.filters {
display: flex;
gap: 12px;
}
.chart {
width: 100%;
height: 600px;
@@ -1,10 +1,19 @@
import { onMounted, ref } from "vue";
import { computed, onMounted, ref } from "vue";
import * as echarts from "echarts";
import { getCollaborationMonthlyStatisticsApi } from "@/api/collaboration/record";
import {
CollaborationMonthlyStatisticsResponse,
getCollaborationMonthlyStatisticsApi
} from "@/api/collaboration/record";
import { getUserListApi, UserDTO } from "@/api/system/user";
import { useUserStoreHook } from "@/store/modules/user";
export function useCollaborationStatisticsHook() {
const userStore = useUserStoreHook();
const isAdmin = computed(() => userStore.roles?.includes("admin"));
const currentYear = new Date().getFullYear();
const selectedYear = ref(currentYear);
const selectedCreatorId = ref<number>();
const creatorOptions = ref<UserDTO[]>([]);
const yearOptions = Array.from(
{ length: currentYear - 2012 },
(_, index) => currentYear - index
@@ -13,13 +22,24 @@ export function useCollaborationStatisticsHook() {
let chart: echarts.ECharts | undefined;
async function getStatistics() {
const { data } = await getCollaborationMonthlyStatisticsApi(
selectedYear.value
);
const { data } = await getCollaborationMonthlyStatisticsApi({
year: selectedYear.value,
creatorId: selectedCreatorId.value
});
renderChart(data);
}
function renderChart(data) {
async function getCreatorOptions() {
if (!isAdmin.value) return;
const { data } = await getUserListApi({ pageNum: 1, pageSize: 1000 });
creatorOptions.value = data.rows;
}
function getUserDisplayName(user: UserDTO) {
return user.nickname || user.username || "";
}
function renderChart(data: CollaborationMonthlyStatisticsResponse[]) {
chart?.dispose();
chart = echarts.init(chartRef.value);
chart.setOption({
@@ -71,6 +91,7 @@ export function useCollaborationStatisticsHook() {
}
onMounted(() => {
getCreatorOptions();
getStatistics();
window.addEventListener("resize", resizeChart);
});
@@ -78,7 +99,11 @@ export function useCollaborationStatisticsHook() {
return {
chartRef,
selectedYear,
selectedCreatorId,
yearOptions,
creatorOptions,
isAdmin,
getUserDisplayName,
getStatistics
};
}