forked from wangjiadong/comp
Merge branch 'main' of http://182.92.169.222:3000/zhc077/hnjd_comp
commit
5d15242106
12 changed files with 984 additions and 6 deletions
@ -0,0 +1,38 @@ |
||||
package org.jeecg.modules.demo.homepage.controller; |
||||
|
||||
import io.swagger.annotations.Api; |
||||
import io.swagger.annotations.ApiOperation; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
import org.jeecg.common.api.vo.Result; |
||||
import org.jeecg.modules.demo.homepage.service.UserHomePageService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* @Description: 用户登录首页 |
||||
* @Author: Z.H.C |
||||
* @CreateTime: 2024-07-16 09:20 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Api(tags = "河南机电比赛系统-用户登录首页") |
||||
@RestController |
||||
@RequestMapping("/user/login/homepage") |
||||
@Slf4j |
||||
public class UserHomePageController { |
||||
|
||||
@Autowired |
||||
private UserHomePageService homePageService; |
||||
|
||||
@ApiOperation(value = "河南机电-学校首页", notes = "河南机电-学校首页") |
||||
@GetMapping(value = "/school") |
||||
public Result composite(HttpServletRequest req) { |
||||
Map<String, Object> result = homePageService.homePage4School(); |
||||
return Result.ok(result); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@ |
||||
package org.jeecg.modules.demo.homepage.service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public interface UserHomePageService { |
||||
|
||||
Map<String, Object> homePage4Depart(String departId); |
||||
|
||||
Map<String, Object> homePage4School(); |
||||
|
||||
} |
@ -0,0 +1,237 @@ |
||||
package org.jeecg.modules.demo.homepage.service; |
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
||||
import org.jeecg.common.util.ComputeUtils; |
||||
import org.jeecg.common.util.DateUtils; |
||||
import org.jeecg.modules.demo.abilityEvaluation.entity.DepartAbilityEvaluation; |
||||
import org.jeecg.modules.demo.abilityEvaluation.service.IDepartAbilityEvaluationService; |
||||
import org.jeecg.modules.demo.abilityEvaluation.service.IPersonalAbilityEvaluationCollectService; |
||||
import org.jeecg.modules.demo.abilityEvaluation.service.IPersonalAbilityEvaluationService; |
||||
import org.jeecg.modules.demo.annual.entity.Annual; |
||||
import org.jeecg.modules.demo.annual.service.IAnnualService; |
||||
import org.jeecg.modules.demo.annualCompPoint.entity.AnnualCompPoint; |
||||
import org.jeecg.modules.demo.annualCompPoint.service.IAnnualCompPointService; |
||||
import org.jeecg.modules.demo.annualScore.entity.DepartCompTotalScore; |
||||
import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore; |
||||
import org.jeecg.modules.demo.annualScore.service.IDepartCompTotalScoreService; |
||||
import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService; |
||||
import org.jeecg.modules.demo.annualScore.service.IPersonalCompTotalScoreService; |
||||
import org.jeecg.modules.demo.annualcomp.entity.AnnualComp; |
||||
import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService; |
||||
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.AnnualCompetitionProjectRegistration; |
||||
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.IAnnualCompetitionProjectRegistrationService; |
||||
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.ITeamManagementService; |
||||
import org.jeecg.modules.demo.comp.entity.Comp; |
||||
import org.jeecg.modules.demo.comp.service.ICompService; |
||||
import org.jeecg.modules.demo.homepage.vo.HomePageCompVo; |
||||
import org.jeecg.modules.demo.projectlevel.entity.Projectlevel; |
||||
import org.jeecg.modules.demo.projectlevel.service.IProjectlevelService; |
||||
import org.jeecg.modules.system.entity.SysDepart; |
||||
import org.jeecg.modules.system.service.ISysDepartService; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.stereotype.Service; |
||||
import org.springframework.util.ObjectUtils; |
||||
|
||||
import java.math.RoundingMode; |
||||
import java.text.DecimalFormat; |
||||
import java.util.*; |
||||
import java.util.stream.Collectors; |
||||
|
||||
/** |
||||
* @Description: TODO |
||||
* @Author: Z.H.C |
||||
* @CreateTime: 2024-07-16 09:28 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Service |
||||
public class UserHomePageServiceImpl implements UserHomePageService { |
||||
|
||||
@Autowired |
||||
private IAnnualCompPointService iAnnualCompPointService; |
||||
|
||||
@Autowired |
||||
private IAnnualCompService iAnnualCompService; |
||||
|
||||
@Autowired |
||||
private ICompService iCompService; |
||||
|
||||
// @Autowired
|
||||
// private ICompTypeService iCompTypeService;
|
||||
//
|
||||
@Autowired |
||||
private ISysDepartService iSysDepartService; |
||||
|
||||
@Autowired |
||||
private IDepartCompTotalScoreService iDepartCompTotalScoreService; |
||||
|
||||
@Autowired |
||||
private IAnnualCompetitionProjectRegistrationService iAnnualCompetitionProjectRegistrationService; |
||||
|
||||
@Autowired |
||||
private ITeamManagementService iTeamManagementService; |
||||
|
||||
// @Autowired
|
||||
// private IAwardPersionService iAwardPersionService;
|
||||
//
|
||||
// @Autowired
|
||||
// private ISysUserService iSysUserService;
|
||||
|
||||
@Autowired |
||||
private IPersonalCompTotalScoreService iPersonalCompTotalScoreService; |
||||
|
||||
@Autowired |
||||
private IPersonalCompScoreService iPersonalCompScoreService; |
||||
|
||||
@Autowired |
||||
private IDepartAbilityEvaluationService iDepartAbilityEvaluationService; |
||||
|
||||
@Autowired |
||||
private IPersonalAbilityEvaluationService iPersonalAbilityEvaluationService; |
||||
|
||||
@Autowired |
||||
private IPersonalAbilityEvaluationCollectService iPersonalAbilityEvaluationCollectService; |
||||
|
||||
@Autowired |
||||
private IAnnualService iAnnualService; |
||||
|
||||
@Autowired |
||||
private IProjectlevelService iProjectlevelService; |
||||
|
||||
|
||||
@Override |
||||
public Map<String, Object> homePage4Depart(String departId) { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public Map<String, Object> homePage4School() { |
||||
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>(); |
||||
|
||||
int currentYear = DateUtils.getCurrentYear(); |
||||
//当前年度
|
||||
Annual annual = iAnnualService.getOne(new LambdaQueryWrapper<Annual>().eq(Annual::getAnnualName, currentYear + "")); |
||||
|
||||
List<AnnualComp> annualCompList = iAnnualCompService.list(new LambdaQueryWrapper<AnnualComp>() |
||||
.eq(AnnualComp::getAnnualid, annual.getId())); |
||||
|
||||
Set<String> compIds = Optional.ofNullable(annualCompList).orElse(new LinkedList<>()).stream().map(obj -> obj.getId()).collect(Collectors.toSet()); |
||||
List<AnnualCompPoint> annualCompPointList = iAnnualCompPointService.list(new LambdaQueryWrapper<AnnualCompPoint>().in(AnnualCompPoint::getAnnualCompId, compIds)); |
||||
|
||||
//未评奖的项目为进行中
|
||||
List<AnnualCompPoint> pj0PointList = Optional.ofNullable(annualCompPointList).orElse(new LinkedList<>()).stream().filter(bo -> "0".equals(bo.getIsPj())).collect(Collectors.toList()); |
||||
Map<String, Object> countMap = this.convertProjectLevel(annualCompPointList); |
||||
countMap.put("本年度已开展比赛项目数", annualCompPointList.size()); |
||||
countMap.put("本年度参加比赛队伍数", 0); |
||||
countMap.put("正在进行的比赛数", pj0PointList.size()); |
||||
int donePointCount = annualCompPointList.size() - pj0PointList.size(); |
||||
countMap.put("已完成的比赛", donePointCount); |
||||
countMap.put("未完成的比赛", pj0PointList.size()); |
||||
if (donePointCount > 0) { |
||||
DecimalFormat decimalFormat = new DecimalFormat(); |
||||
decimalFormat.setMaximumFractionDigits(2); // 保留两位小数
|
||||
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); // 设置具体的进位机制
|
||||
double val = ComputeUtils.div2(donePointCount, annualCompPointList.size()); |
||||
countMap.put("已完成比赛比率", val); |
||||
} else { |
||||
countMap.put("已完成比赛比率", 0); |
||||
} |
||||
|
||||
Set<String> annualCompPointIds = Optional.ofNullable(annualCompPointList).orElse(new ArrayList<>()).stream().map(annualCompPoint -> annualCompPoint.getId()).collect(Collectors.toSet()); |
||||
if (!ObjectUtils.isEmpty(annualCompPointIds)) { |
||||
//报名表,只存本次的报名编号和项目id
|
||||
List<AnnualCompetitionProjectRegistration> annualCompetitionProjectRegistrationList = iAnnualCompetitionProjectRegistrationService |
||||
.list(new LambdaQueryWrapper<AnnualCompetitionProjectRegistration>() |
||||
.in(AnnualCompetitionProjectRegistration::getAnnualCompid, annualCompPointIds) |
||||
.eq(AnnualCompetitionProjectRegistration::getEntryFormat, "1")); |
||||
countMap.put("本年度参加比赛队伍数", annualCompetitionProjectRegistrationList.size()); |
||||
} |
||||
resultMap.putAll(countMap); |
||||
|
||||
|
||||
List<Map<String, Object>> abilityList = new LinkedList<>(); |
||||
List<Integer> years = DateUtils.getLastxYear(2); |
||||
List<Annual> annualList = iAnnualService.list(new LambdaQueryWrapper<Annual>().in(Annual::getAnnualName, years).orderByAsc(Annual::getAnnualName)); |
||||
Optional.ofNullable(annualList).orElse(new LinkedList<>()).stream().forEach(bo -> { |
||||
Map<String, Object> abilityResultMap = new LinkedHashMap<>(); |
||||
List<DepartAbilityEvaluation> departAbilityEvaluations = iDepartAbilityEvaluationService.list(new LambdaQueryWrapper<DepartAbilityEvaluation>() |
||||
.eq(DepartAbilityEvaluation::getAnnualId, bo.getId())); |
||||
List<DepartAbilityEvaluation> vos = new LinkedList<>(); |
||||
Map<String, List<DepartAbilityEvaluation>> capacityIdListMap = Optional.ofNullable(departAbilityEvaluations).orElse(new LinkedList<>()).stream() |
||||
.collect(Collectors.groupingBy(DepartAbilityEvaluation::getCapacityId)); |
||||
//遍历分组后的结果
|
||||
Optional.ofNullable(capacityIdListMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { |
||||
List<DepartAbilityEvaluation> departAbilityEvaluationList = value; |
||||
double sum = departAbilityEvaluationList.stream().mapToDouble(obj -> obj.getValue()).sum(); |
||||
DecimalFormat decimalFormat = new DecimalFormat(); |
||||
decimalFormat.setMaximumFractionDigits(2); // 保留两位小数
|
||||
decimalFormat.setRoundingMode(RoundingMode.HALF_UP); // 设置具体的进位机制
|
||||
double val = ComputeUtils.div2(sum, departAbilityEvaluationList.size()); |
||||
DepartAbilityEvaluation vo = new DepartAbilityEvaluation(); |
||||
vo.setAnnualId(bo.getId()); |
||||
vo.setValue(val); |
||||
vo.setCapacityId(key); |
||||
vo.setCapacityName(departAbilityEvaluationList.get(0).getCapacityName()); |
||||
vos.add(vo); |
||||
}); |
||||
abilityResultMap.put(bo.getAnnualName(), vos); |
||||
abilityList.add(abilityResultMap); |
||||
}); |
||||
resultMap.put("近2年能力分析", abilityList); |
||||
|
||||
|
||||
List<HomePageCompVo> scoreList4Point = new LinkedList<>(); |
||||
List<PersonalCompScore> personalCompScores = iPersonalCompScoreService.list(new LambdaQueryWrapper<PersonalCompScore>().eq(PersonalCompScore::getAnnualCompP, annualCompPointIds)); |
||||
Map<String, List<PersonalCompScore>> AnnualCompPointIdsMap = Optional.ofNullable(personalCompScores).orElse(new LinkedList<>()).stream() |
||||
.collect(Collectors.groupingBy(PersonalCompScore::getAnnualCompP)); |
||||
Optional.ofNullable(AnnualCompPointIdsMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { |
||||
double sum = value.stream().mapToDouble(obj -> obj.getScore()).sum(); |
||||
HomePageCompVo vo = new HomePageCompVo(); |
||||
AnnualCompPoint point = iAnnualCompPointService.getById(key); |
||||
vo.setAnnualCompPointName(point.getObjName()); |
||||
AnnualComp annualComp = iAnnualCompService.getById(point.getAnnualCompId()); |
||||
if (!ObjectUtils.isEmpty(annualComp)) { |
||||
Comp comp = iCompService.getById(annualComp.getCompid()); |
||||
if (!ObjectUtils.isEmpty(comp)) { |
||||
vo.setCompName(comp.getCompName()); |
||||
} |
||||
} |
||||
vo.setTotalScore(sum); |
||||
scoreList4Point.add(vo); |
||||
}); |
||||
scoreList4Point.stream().sorted(Comparator.comparing(HomePageCompVo::getTotalScore)).collect(Collectors.toList()); |
||||
resultMap.put("本年度项目积分排名", scoreList4Point); |
||||
|
||||
|
||||
List<HomePageCompVo> scoreList4Depart = new LinkedList<>(); |
||||
List<DepartCompTotalScore> departCompTotalScoreList = iDepartCompTotalScoreService.list(new LambdaQueryWrapper<DepartCompTotalScore>() |
||||
.eq(DepartCompTotalScore::getAnnualId, annual.getId())); |
||||
Map<String, List<DepartCompTotalScore>> departCompTotalScoresMap = Optional.ofNullable(departCompTotalScoreList).orElse(new LinkedList<>()).stream() |
||||
.collect(Collectors.groupingBy(DepartCompTotalScore::getDepet)); |
||||
Optional.ofNullable(departCompTotalScoresMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { |
||||
double sum = value.stream().mapToDouble(obj -> obj.getScore()).sum(); |
||||
HomePageCompVo vo = new HomePageCompVo(); |
||||
SysDepart depart = iSysDepartService.getById(key); |
||||
vo.setCompOrganName(depart.getDepartName()); |
||||
vo.setTotalScore(sum); |
||||
scoreList4Depart.add(vo); |
||||
}); |
||||
scoreList4Depart.stream().sorted(Comparator.comparing(HomePageCompVo::getTotalScore)).collect(Collectors.toList()); |
||||
resultMap.put("本年度全校部门积分排名", scoreList4Depart); |
||||
return resultMap; |
||||
} |
||||
|
||||
Map<String, Object> convertProjectLevel(List<AnnualCompPoint> annualCompPointList) { |
||||
Map<String, Object> map = new LinkedHashMap<>(); |
||||
Map<String, List<AnnualCompPoint>> objLevelIdsMap = Optional.ofNullable(annualCompPointList).orElse(new LinkedList<>()).stream() |
||||
.collect(Collectors.groupingBy(AnnualCompPoint::getObjLevel)); |
||||
Optional.ofNullable(objLevelIdsMap).orElse(new LinkedHashMap<>()).forEach((key, value) -> { |
||||
Map<String, Object> levelMap = new LinkedHashMap<>(); |
||||
Projectlevel projectlevel = iProjectlevelService.getById(key); |
||||
levelMap.put(projectlevel.getName(), value.size()); |
||||
map.putAll(levelMap); |
||||
}); |
||||
return map; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,57 @@ |
||||
package org.jeecg.modules.demo.homepage.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
import org.jeecg.modules.demo.projectlevel.entity.Projectlevel; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: TODO |
||||
* @Author: Z.H.C |
||||
* @CreateTime: 2023-11-29 15:52 |
||||
* @Version: 1.0 |
||||
*/ |
||||
@Data |
||||
public class HomePageCompVo implements Serializable { |
||||
|
||||
@ApiModelProperty(value = "比赛id") |
||||
private String compId; |
||||
|
||||
@ApiModelProperty(value = "年度比赛项目名称") |
||||
private String annualCompPointName; |
||||
|
||||
/** |
||||
* 比赛名称 |
||||
*/ |
||||
@ApiModelProperty(value = "比赛名称") |
||||
private String compName; |
||||
|
||||
// @ApiModelProperty(value = "部门id")
|
||||
// private String compOrganId;
|
||||
|
||||
@ApiModelProperty(value = "部门名称") |
||||
private String compOrganName; |
||||
//
|
||||
// @ApiModelProperty(value = "奖项名称")
|
||||
// private String awardName;
|
||||
//
|
||||
@ApiModelProperty(value = "项目总积分") |
||||
private double totalScore; |
||||
//
|
||||
// @ApiModelProperty(value = "年度比赛项目数")
|
||||
// private Integer annualCompPointNumber;
|
||||
//
|
||||
// @ApiModelProperty(value = "获取人数")
|
||||
// private Integer awardNumber;
|
||||
//
|
||||
// @ApiModelProperty(value = "获取比率")
|
||||
// private String awardRatio;
|
||||
//
|
||||
// @ApiModelProperty(value = "年度比赛状态")
|
||||
// private String status;
|
||||
//
|
||||
// @ApiModelProperty(value = "比赛级别list")
|
||||
// private Projectlevel projectLevelList;
|
||||
|
||||
} |
@ -0,0 +1,35 @@ |
||||
package org.jeecg.modules.demo.homepage.vo; |
||||
|
||||
import io.swagger.annotations.ApiModelProperty; |
||||
import lombok.Data; |
||||
|
||||
import java.io.Serializable; |
||||
|
||||
/** |
||||
* @Description: TODO |
||||
* @Author: Z.H.C |
||||
* @CreateTime: 2023-11-30 16:08 |
||||
* @Version: 1.0 |
||||
*/ |
||||
|
||||
@Data |
||||
public class Last5YearDataVo implements Serializable { |
||||
|
||||
// @ApiModelProperty(value = "主键")
|
||||
// private String id;
|
||||
|
||||
/** |
||||
* 比赛名称 |
||||
*/ |
||||
// @ApiModelProperty(value = "比赛名称")
|
||||
// private String compName;
|
||||
|
||||
@ApiModelProperty(value = "年度") |
||||
private String year; |
||||
|
||||
@ApiModelProperty(value = "比赛数量") |
||||
private Integer compCount; |
||||
|
||||
@ApiModelProperty(value = "参赛人数量") |
||||
private Integer personCount; |
||||
} |
@ -0,0 +1,249 @@ |
||||
<template> |
||||
<div> |
||||
<!--引用表格--> |
||||
<BasicTable @register="registerTable" :rowSelection="rowSelection"> |
||||
<!--插槽:table标题--> |
||||
<template #tableTitle> |
||||
<a-button type="primary" @click="handleAdd" preIcon="ant-design:plus-outlined"> 新增 |
||||
</a-button> |
||||
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出 |
||||
</a-button> |
||||
<!-- <j-upload-button type="primary" preIcon="ant-design:import-outlined" @click="onImportXls">导入</j-upload-button> |
||||
<a-dropdown v-if="selectedRowKeys.length > 0"> |
||||
<template #overlay> |
||||
<a-menu> |
||||
<a-menu-item key="1" @click="batchHandleDelete"> |
||||
<Icon icon="ant-design:delete-outlined"></Icon> |
||||
删除 |
||||
</a-menu-item> |
||||
</a-menu> |
||||
</template> |
||||
<a-button>批量操作 |
||||
<Icon icon="mdi:chevron-down"></Icon> |
||||
</a-button> |
||||
</a-dropdown>--> |
||||
</template> |
||||
<!--操作栏--> |
||||
<template #action="{ record }"> |
||||
<!-- <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)"/>--> |
||||
<TableAction :actions="getTableAction(record)"/> |
||||
<!--<TableAction |
||||
:stopButtonPropagation="true" |
||||
:actions="[ |
||||
{ |
||||
label: '1', |
||||
// type: 'link', |
||||
size: 'small', |
||||
icon: 'ant-design:plus-circle-outlined', |
||||
onClick: add.bind(null, record), |
||||
}, |
||||
{ |
||||
label: '2', |
||||
// type: 'link', |
||||
size: 'small', |
||||
icon: 'fa6-regular:pen-to-square', |
||||
onClick: editor.bind(null, record), |
||||
}, |
||||
{ |
||||
label: '3', |
||||
// color: 'error', |
||||
icon: 'ic:outline-delete-outline', |
||||
popConfirm: { |
||||
title: '确定删除该数据吗?', |
||||
confirm: del.bind(null, record), |
||||
}, |
||||
}, |
||||
]" |
||||
/>--> |
||||
</template> |
||||
<!--字段回显插槽--> |
||||
<template #htmlSlot="{text}"> |
||||
<div v-html="text"></div> |
||||
</template> |
||||
<!--省市区字段回显插槽--> |
||||
<template #pcaSlot="{text}"> |
||||
{{ getAreaTextByCode(text) }} |
||||
</template> |
||||
<template #fileSlot="{text}"> |
||||
<span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span> |
||||
<a-button v-else :ghost="true" type="primary" preIcon="ant-design:download-outlined" |
||||
size="small" @click="downloadFile(text)">下载 |
||||
</a-button> |
||||
</template> |
||||
</BasicTable> |
||||
<!-- 表单区域 --> |
||||
<CmsArticleModal @register="registerModal" @success="handleSuccess"></CmsArticleModal> |
||||
</div> |
||||
</template> |
||||
|
||||
<script lang="ts" name="cms-cmsArticle" setup> |
||||
import {ref} from 'vue'; |
||||
import {BasicTable, TableAction} from '/@/components/Table'; |
||||
import {useModal} from '/@/components/Modal'; |
||||
import {useListPage} from '/@/hooks/system/useListPage' |
||||
import CmsArticleModal from './components/CmsArticleModal.vue' |
||||
import {columns, searchFormSchema} from './CmsArticle.data'; |
||||
import { |
||||
batchDelete, |
||||
deleteOne, |
||||
getExportUrl, |
||||
getImportUrl, |
||||
listzwh, |
||||
updateStatus |
||||
} from './CmsArticle.api'; |
||||
// import {updateStatus} from './CmsArticle.api'; |
||||
import {Update} from "/@/views/topic/Topic.api"; |
||||
import {defHttp} from "/@/utils/http/axios"; |
||||
// import { downloadFile } from '/@/utils/common/renderUtils'; |
||||
const checkedKeys = ref<Array<string | number>>([]); |
||||
//注册model |
||||
const [registerModal, {openModal}] = useModal(); |
||||
//注册table数据 |
||||
const {prefixCls, tableContext, onExportXls, onImportXls} = useListPage({ |
||||
tableProps: { |
||||
title: '文章', |
||||
api: listzwh, |
||||
columns, |
||||
canResize: false, |
||||
formConfig: { |
||||
//labelWidth: 120, |
||||
schemas: searchFormSchema, |
||||
autoSubmitOnEnter: true, |
||||
showAdvancedButton: true, |
||||
fieldMapToNumber: [], |
||||
fieldMapToTime: [], |
||||
}, |
||||
actionColumn: { |
||||
width: 180, |
||||
fixed: 'right' |
||||
}, |
||||
}, |
||||
exportConfig: { |
||||
name: "文章", |
||||
url: getExportUrl, |
||||
}, |
||||
importConfig: { |
||||
url: getImportUrl, |
||||
success: handleSuccess |
||||
}, |
||||
}) |
||||
|
||||
const [registerTable, {reload}, {rowSelection, selectedRowKeys}] = tableContext |
||||
|
||||
/** |
||||
* 新增事件 |
||||
*/ |
||||
function handleAdd() { |
||||
openModal(true, { |
||||
isUpdate: false, |
||||
showFooter: true, |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 编辑事件 |
||||
*/ |
||||
function handleEdit(record: Recordable) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true, |
||||
showFooter: true, |
||||
}); |
||||
} |
||||
|
||||
function update2(record: Recordable, val) { |
||||
record.status = val; |
||||
updateStatus(record) |
||||
//第2种方法 |
||||
// defHttp.post({ url: '/cms/cmsArticle/operationStatus', params: record }); |
||||
reload() |
||||
} |
||||
|
||||
/** |
||||
* 详情 |
||||
*/ |
||||
function handleDetail(record: Recordable) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true, |
||||
showFooter: false, |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 删除事件 |
||||
*/ |
||||
async function handleDelete(record) { |
||||
await deleteOne({id: record.id}, handleSuccess); |
||||
} |
||||
|
||||
/** |
||||
* 批量删除事件 |
||||
*/ |
||||
async function batchHandleDelete() { |
||||
await batchDelete({ids: selectedRowKeys.value}, handleSuccess); |
||||
} |
||||
|
||||
/** |
||||
* 成功回调 |
||||
*/ |
||||
function handleSuccess() { |
||||
(selectedRowKeys.value = []) && reload(); |
||||
} |
||||
|
||||
/** |
||||
* 操作栏 |
||||
*/ |
||||
function getTableAction(record) { |
||||
const actions = [ |
||||
{ |
||||
label: '编辑', |
||||
onClick: handleEdit.bind(null, record), |
||||
}, |
||||
{ |
||||
label: '删除', |
||||
popConfirm: { |
||||
title: '是否确认删除', |
||||
confirm: handleDelete.bind(null, record), |
||||
} |
||||
} |
||||
]; |
||||
if (record.status == "1") { |
||||
actions.unshift({ |
||||
label: '取消发布', |
||||
onClick: update2.bind(null,record, "0"), |
||||
}); |
||||
} |
||||
if (record.status == "0") { |
||||
actions.unshift({ |
||||
label: '发布', |
||||
onClick: update2.bind(null,record, "1"), |
||||
}); |
||||
} |
||||
return actions; |
||||
} |
||||
|
||||
/** |
||||
* 下拉操作栏 |
||||
*/ |
||||
function getDropDownAction(record) { |
||||
return [ |
||||
{ |
||||
label: '详情', |
||||
onClick: handleDetail.bind(null, record), |
||||
}, { |
||||
label: '删除', |
||||
popConfirm: { |
||||
title: '是否确认删除', |
||||
confirm: handleDelete.bind(null, record), |
||||
} |
||||
} |
||||
] |
||||
} |
||||
|
||||
|
||||
</script> |
||||
|
||||
<style scoped> |
||||
|
||||
</style> |
@ -0,0 +1,315 @@ |
||||
<template> |
||||
<div> |
||||
<!--引用表格--> |
||||
<BasicTable |
||||
@register="registerTable" |
||||
:rowSelection="rowSelection" |
||||
:expandedRowKeys="expandedRowKeys" |
||||
@expand="handleExpand" |
||||
@fetch-success="onFetchSuccess" |
||||
> |
||||
<!--插槽:table标题--> |
||||
<template #tableTitle> |
||||
<!-- <a-button type="primary" @click="handleCreate" preIcon="ant-design:plus-outlined"> 新增 |
||||
</a-button>--> |
||||
<a-button type="primary" preIcon="ant-design:export-outlined" @click="onExportXls"> 导出 |
||||
</a-button> |
||||
<!--<a-dropdown v-if="selectedRowKeys.length > 0"> |
||||
<template #overlay> |
||||
<a-menu> |
||||
<a-menu-item key="1" @click="batchHandleDelete"> |
||||
<Icon icon="ant-design:delete-outlined"></Icon> |
||||
删除 |
||||
</a-menu-item> |
||||
</a-menu> |
||||
</template> |
||||
<a-button |
||||
>批量操作 |
||||
<Icon icon="ant-design:down-outlined"></Icon> |
||||
</a-button> |
||||
</a-dropdown>--> |
||||
</template> |
||||
<!--操作栏--> |
||||
<template #action="{ record }"> |
||||
<TableAction :actions="getTableAction(record)"/> |
||||
</template> |
||||
</BasicTable> |
||||
<!-- 表单区域 --> |
||||
<CmsColumnModal @register="registerModal" @success="handleSuccess"></CmsColumnModal> |
||||
</div> |
||||
</template> |
||||
|
||||
<script lang="ts" name="cms-cmsColumn" setup> |
||||
import {ref, computed, unref} from 'vue'; |
||||
import {BasicTable, useTable, TableAction} from '/@/components/Table'; |
||||
import {useModal} from '/@/components/Modal'; |
||||
import CmsColumnModal from './components/CmsColumnModal.vue' |
||||
import {columns, searchFormSchema} from './CmsColumn.data'; |
||||
import { |
||||
list, |
||||
batchDelete, |
||||
getImportUrl, |
||||
getExportUrl, |
||||
getChildList, |
||||
getChildListBatch, |
||||
deleteOne |
||||
} from './CmsColumn.api'; |
||||
import {useListPage} from '/@/hooks/system/useListPage' |
||||
// import {downloadFile} from '/@/utils/common/renderUtils'; |
||||
|
||||
const expandedRowKeys = ref([]); |
||||
// const checkedKeys = ref<Array<string | number>>([]); |
||||
//注册model |
||||
const [registerModal, {openModal}] = useModal(); |
||||
//注册table数据 |
||||
const {prefixCls, tableContext, onExportXls, onImportXls} = useListPage({ |
||||
tableProps: { |
||||
title: 'cms栏目', |
||||
api: list, |
||||
columns, |
||||
canResize: false, |
||||
formConfig: { |
||||
//labelWidth: 120, |
||||
schemas: searchFormSchema, |
||||
autoSubmitOnEnter: true, |
||||
showAdvancedButton: true, |
||||
fieldMapToNumber: [], |
||||
fieldMapToTime: [], |
||||
}, |
||||
actionColumn: { |
||||
width: 180, |
||||
fixed: 'right' |
||||
}, |
||||
isTreeTable: true, |
||||
}, |
||||
exportConfig: { |
||||
name: "cms栏目", |
||||
url: getExportUrl, |
||||
}, |
||||
importConfig: { |
||||
url: getImportUrl, |
||||
success: handleSuccess |
||||
}, |
||||
}); |
||||
|
||||
//注册table数据 |
||||
const [registerTable, {reload,collapseAll,updateTableDataRecord, findTableDataRecord,getDataSource}, {rowSelection, selectedRowKeys}] = tableContext |
||||
|
||||
/** |
||||
* 新增事件 |
||||
*/ |
||||
function handleCreate() { |
||||
openModal(true, { |
||||
isUpdate: false, |
||||
}); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 编辑事件 |
||||
*/ |
||||
function handleEdit(record: Recordable) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true, |
||||
showFooter: true, |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 详情 |
||||
*/ |
||||
function handleDetail(record: Recordable) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: true, |
||||
showFooter: false, |
||||
}); |
||||
} |
||||
|
||||
/** |
||||
* 删除事件 |
||||
*/ |
||||
async function handleDelete(record) { |
||||
await deleteOne({id: record.id}, importSuccess); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 批量删除事件 |
||||
*/ |
||||
async function batchHandleDelete() { |
||||
const ids = selectedRowKeys.value.filter((item) => !item.includes('loading')); |
||||
await batchDelete({ ids: ids }, importSuccess); |
||||
} |
||||
|
||||
/** |
||||
* 导入 |
||||
*/ |
||||
function importSuccess() { |
||||
//update-begin---author:wangshuai ---date:20220530 for:[issues/54]树字典,勾选,然后批量删除,系统错误------------ |
||||
(selectedRowKeys.value = []) && reload(); |
||||
//update-end---author:wangshuai ---date:20220530 for:[issues/54]树字典,勾选,然后批量删除,系统错误-------------- |
||||
} |
||||
|
||||
/** |
||||
/** |
||||
* 添加下级 |
||||
*/ |
||||
function handleAddSub(record) { |
||||
openModal(true, { |
||||
record, |
||||
isUpdate: false, |
||||
}); |
||||
} |
||||
/** |
||||
* 成功回调 |
||||
*/ |
||||
async function handleSuccess({ isUpdate,isSubAdd, values, expandedArr }) { |
||||
if (isUpdate) { |
||||
//编辑回调 |
||||
updateTableDataRecord(values.id, values); |
||||
} else { |
||||
if (!values['pid']) { |
||||
//新增根节点 |
||||
reload(); |
||||
} else { |
||||
//新增子集 |
||||
//update-begin-author:liusq---date:20230411--for: [issue/4550]分类字典数据量过多会造成数据查询时间过长--- |
||||
if(isSubAdd){ |
||||
await expandTreeNode(values.pid); |
||||
//update-end-author:liusq---date:20230411--for: [issue/4550]分类字典数据量过多会造成数据查询时间过长--- |
||||
}else{ |
||||
expandedRowKeys.value = []; |
||||
for (let key of unref(expandedArr)) { |
||||
await expandTreeNode(key); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 接口请求成功后回调 |
||||
*/ |
||||
function onFetchSuccess(result) { |
||||
getDataByResult(result.items) && loadDataByExpandedRows(); |
||||
} |
||||
/** |
||||
* 根据已展开的行查询数据(用于保存后刷新时异步加载子级的数据) |
||||
*/ |
||||
async function loadDataByExpandedRows() { |
||||
if (unref(expandedRowKeys).length > 0) { |
||||
const res = await getChildListBatch({ parentIds: unref(expandedRowKeys).join(',') }); |
||||
if (res.success && res.result.records.length > 0) { |
||||
//已展开的数据批量子节点 |
||||
let records = res.result.records; |
||||
const listMap = new Map(); |
||||
for (let item of records) { |
||||
let pid = item['pid']; |
||||
if (unref(expandedRowKeys).includes(pid)) { |
||||
let mapList = listMap.get(pid); |
||||
if (mapList == null) { |
||||
mapList = []; |
||||
} |
||||
mapList.push(item); |
||||
listMap.set(pid, mapList); |
||||
} |
||||
} |
||||
let childrenMap = listMap; |
||||
let fn = (list) => { |
||||
if (list) { |
||||
list.forEach((data) => { |
||||
if (unref(expandedRowKeys).includes(data.id)) { |
||||
data.children = getDataByResult(childrenMap.get(data.id)); |
||||
fn(data.children); |
||||
} |
||||
}); |
||||
} |
||||
}; |
||||
fn(getDataSource()); |
||||
} |
||||
} |
||||
} |
||||
/** |
||||
* 处理数据集 |
||||
*/ |
||||
function getDataByResult(result) { |
||||
if (result && result.length > 0) { |
||||
return result.map((item) => { |
||||
//判断是否标记了带有子节点 |
||||
if (item['hasChild'] == '1') { |
||||
let loadChild = { id: item.id + '_loadChild', name: 'loading...', isLoading: true }; |
||||
item.children = [loadChild]; |
||||
} |
||||
return item; |
||||
}); |
||||
} |
||||
} |
||||
/** |
||||
*树节点展开合并 |
||||
* */ |
||||
async function handleExpand(expanded, record) { |
||||
// 判断是否是展开状态,展开状态(expanded)并且存在子集(children)并且未加载过(isLoading)的就去查询子节点数据 |
||||
if (expanded) { |
||||
expandedRowKeys.value.push(record.id); |
||||
if (record.children.length > 0 && !!record.children[0].isLoading) { |
||||
let result = await getChildList({ pid: record.id }); |
||||
if (result && result.length > 0) { |
||||
record.children = getDataByResult(result); |
||||
} else { |
||||
record.children = null; |
||||
record.hasChild = '0'; |
||||
} |
||||
} |
||||
} else { |
||||
let keyIndex = expandedRowKeys.value.indexOf(record.id); |
||||
if (keyIndex >= 0) { |
||||
expandedRowKeys.value.splice(keyIndex, 1); |
||||
} |
||||
} |
||||
} |
||||
/** |
||||
*操作表格后处理树节点展开合并 |
||||
* */ |
||||
async function expandTreeNode(key) { |
||||
let record:any = findTableDataRecord(key); |
||||
if(!expandedRowKeys.value.includes(key)){ |
||||
expandedRowKeys.value.push(key); |
||||
} |
||||
let result = await getChildList({ pid: key }); |
||||
if (result && result.length > 0) { |
||||
record.children = getDataByResult(result); |
||||
} else { |
||||
record.children = null; |
||||
record.hasChild = '0'; |
||||
} |
||||
updateTableDataRecord(key, record); |
||||
} |
||||
/** |
||||
* 操作栏 |
||||
*/ |
||||
function getTableAction(record) { |
||||
return [ |
||||
/* { |
||||
label: '编辑', |
||||
onClick: handleEdit.bind(null, record), |
||||
}, |
||||
{ |
||||
label: '删除', |
||||
popConfirm: { |
||||
title: '确定删除吗?', |
||||
confirm: handleDelete.bind(null, record), |
||||
}, |
||||
}, |
||||
{ |
||||
label: '添加下级', |
||||
onClick: handleAddSub.bind(null, { pid: record.id }), |
||||
},*/ |
||||
]; |
||||
} |
||||
</script> |
||||
|
||||
<style scoped> |
||||
|
||||
</style> |
Loading…
Reference in new issue