Compare commits

..

2 Commits

Author SHA1 Message Date
c212f628c5 fix: 🐛 不能在computed里修改data 2025-04-01 12:15:39 +08:00
53f887d0d6 fix: 🐛 管理员按钮错误消失 2025-04-01 12:15:13 +08:00
2 changed files with 116 additions and 48 deletions

View File

@ -50,7 +50,7 @@ router.beforeEach(async (to, from, next) => {
if (!userState.token && storageToken) restoreToken(storageToken); if (!userState.token && storageToken) restoreToken(storageToken);
// 4. Vuex 有 token但还没有动态路由获取用户资源, 生成动态路由 // 4. Vuex 有 token但还没有动态路由获取用户资源, 生成动态路由
if (userState.token && dynamicRoutes.length === 0) loadRoutes(userState.isAdmin, next); if (userState.token && dynamicRoutes.length === 0) loadRoutes(userState, next);
// 5. 放行 // 5. 放行
next(); next();
@ -88,13 +88,13 @@ function restoreToken(token) {
} }
/** 生成并加载动态路由 */ /** 生成并加载动态路由 */
async function loadRoutes(isAdmin, next) { async function loadRoutes(userState, next) {
try { try {
await store.dispatch('user/getUserInfo')
const routesResource = await store.dispatch("user/getRoutesResource"); const routesResource = await store.dispatch("user/getRoutesResource");
dynamicRoutes = generateIndexRouter(routesResource); dynamicRoutes = generateIndexRouter(routesResource);
router.addRoutes(dynamicRoutes); router.addRoutes(dynamicRoutes);
if (userState.isAdmin) {
if (isAdmin) {
router.addRoutes([systemSettings]); router.addRoutes([systemSettings]);
} }
} catch (err) { } catch (err) {

View File

@ -166,7 +166,10 @@ export default {
workHourStatistics: {} workHourStatistics: {}
}, },
quarterData: {}, quarterData: {},
teamTreeData: {
options: [],
idChildrenMap: {} idChildrenMap: {}
}
}; };
}, },
computed:{ computed:{
@ -191,9 +194,7 @@ export default {
return moment(this.quarterStartTime).subtract(1, 'quarters').valueOf(); return moment(this.quarterStartTime).subtract(1, 'quarters').valueOf();
}, },
options() { options() {
const idChildrenMap = {}; return this.teamTreeData.options;
const options = this.listToTreeData(this.teamList,{id:0},'parentTeamId',idChildrenMap);
return options;
} }
}, },
watch:{ watch:{
@ -202,8 +203,11 @@ export default {
// this.getTeamList(); // this.getTeamList();
this.getTeamOverview(); this.getTeamOverview();
}, },
teamList(){ teamList: {
this.idChildrenMap = {} immediate: true,
handler(newTeamList) {
this.updateTeamTree(newTeamList);
}
} }
}, },
created(){ created(){
@ -216,32 +220,80 @@ export default {
...mapActions({ ...mapActions({
getTeamList: 'teamResource/getTeamList', getTeamList: 'teamResource/getTeamList',
}), }),
listToTreeData(list, parent, pid, map) { /**
const res = [] * 将扁平的团队列表转换为树形结构
map[parent.id]=[] * @param {Array} list - 原始团队列表数据
parent.visible = false */
if(parent.teamType===0){ updateTeamTree(list) {
parent.visible = true //
map[parent.id].push({id: parent.id, teamName:parent.teamName }) // key: IDvalue:
}else{ const parentChildMap = {};
// key: IDvalue:
const idChildrenMap = {};
//
list.forEach(item => { list.forEach(item => {
if (item[pid] === parent.id) { // ID0
// , const pid = item.parentTeamId || 0;
// item.id pid //
const children = this.listToTreeData(list, item, pid, map) if (!parentChildMap[pid]) {
// , parentChildMap[pid] = [];
if (children.length > 0) {
item.children = children
} }
if(item.visible){ //
parent.visible = true parentChildMap[pid].push(item);
res.push(item) });
map[parent.id].push({id: item.id, teamName:item.teamName })
/**
* 递归构建树形结构
* @param {number} parentId - 父团队ID
* @returns {Array} - 返回构建好的树形结构数组
*/
const buildTree = (parentId = 0) => {
//
const children = parentChildMap[parentId] || [];
//
idChildrenMap[parentId] = [];
// 使reduceacc
return children.reduce((acc, node) => {
// 0
if (node.teamType === 0) {
//
idChildrenMap[parentId].push({
id: node.id,
teamName: node.teamName
});
//
acc.push(node);
return acc;
} }
//
//
const subTree = buildTree(node.id);
//
if (subTree.length > 0) {
//
node.children = subTree;
//
acc.push(node);
//
idChildrenMap[parentId].push({
id: node.id,
teamName: node.teamName
});
} }
}) return acc;
} }, []);
return res };
//
// options:
// idChildrenMap:
this.teamTreeData = {
options: buildTree(),
idChildrenMap
};
}, },
async getQuarterStatistics(){ async getQuarterStatistics(){
const { data } = await getQuarterStatistics({ const { data } = await getQuarterStatistics({
@ -253,15 +305,26 @@ export default {
} }
}, },
async getTeamOverview(teamId) { async getTeamOverview(teamId) {
// const { quarterStartTime, quarterEndTime } = quarter2Timestamp(this.quarter); const { data } = await getTeamOverview({
// const lastQuarterStartTime = moment(quarterStartTime).subtract(1, 'quarters').valueOf(); lastQuarterStartTime: this.lastQuarterStartTime,
// const aQuarterAgo = moment(quarterStartTime).subtract(1, 'quarters').valueOf(); quarterStartTime: this.quarterStartTime,
// const { quarterStartTime:lastQuarterStartTime, quarterEndTime:lastQuarterEndTime } = quarter2Timestamp(timestamp2Quarter(aQuarterAgo)); teamId
const { data } = await getTeamOverview({ lastQuarterStartTime: this.lastQuarterStartTime, quarterStartTime: this.quarterStartTime, teamId }); });
if(data) { if(data) {
// this.teamProfiles = data; // ID使0
const currentTeamId = teamId ?? 0;
// idChildrenMap
const teamChildren = this.teamTreeData.idChildrenMap[currentTeamId] || [];
// ID
const ids = data.map(team => team.teamId); const ids = data.map(team => team.teamId);
const needFillChildren = this.idChildrenMap[teamId??0].filter(child=>!ids.includes(child.id));
//
const needFillChildren = teamChildren.filter(child => !ids.includes(child.id));
//
const filledChildren = needFillChildren.map(child => ({ const filledChildren = needFillChildren.map(child => ({
teamType: 0, teamType: 0,
disabled: true, disabled: true,
@ -278,7 +341,12 @@ export default {
deliveredStoryCompareLast: null, deliveredStoryCompareLast: null,
projectCurrentQuarter: [] projectCurrentQuarter: []
})); }));
//
this.teamProfiles = [...data, ...filledChildren]; this.teamProfiles = [...data, ...filledChildren];
} else {
//
this.teamProfiles = [];
} }
}, },
async getYearStatistics(){ async getYearStatistics(){