@@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `packages` (
|
|||||||
`vlog_count` INT DEFAULT 0 COMMENT 'Vlog数量',
|
`vlog_count` INT DEFAULT 0 COMMENT 'Vlog数量',
|
||||||
`video_count` INT DEFAULT 0 COMMENT '视频数量',
|
`video_count` INT DEFAULT 0 COMMENT '视频数量',
|
||||||
`photo_count` INT DEFAULT 0 COMMENT '照片数量',
|
`photo_count` INT DEFAULT 0 COMMENT '照片数量',
|
||||||
|
`tourism_file_ids` VARCHAR(2048) DEFAULT NULL COMMENT '景区素材ID集合(逗号分隔)',
|
||||||
`tenant_id` VARCHAR(64) DEFAULT NULL COMMENT '租户ID',
|
`tenant_id` VARCHAR(64) DEFAULT NULL COMMENT '租户ID',
|
||||||
`company` VARCHAR(128) DEFAULT NULL COMMENT '所属公司',
|
`company` VARCHAR(128) DEFAULT NULL COMMENT '所属公司',
|
||||||
`is_del` TINYINT(1) DEFAULT 0 COMMENT '是否删除 0-否 1-是',
|
`is_del` TINYINT(1) DEFAULT 0 COMMENT '是否删除 0-否 1-是',
|
||||||
|
|||||||
+12
-1
@@ -29,6 +29,8 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* qrcode information
|
* qrcode information
|
||||||
@@ -89,7 +91,8 @@ public class QrCodeController {
|
|||||||
if (result.getResp_code() == 0){
|
if (result.getResp_code() == 0){
|
||||||
Tourism tourism = tourismService.getTourismById(qrCode.getTourismId());
|
Tourism tourism = tourismService.getTourismById(qrCode.getTourismId());
|
||||||
Assert.notNull(tourism, "请选择景区数据");
|
Assert.notNull(tourism, "请选择景区数据");
|
||||||
qrCode.setTenantId(tourism.getTenantId());
|
// qrCode.setTenantId(tourism.getTenantId());
|
||||||
|
qrCode.setTenantId(qrCode.getTenantId());
|
||||||
qrCode.setCodeId(codeId);
|
qrCode.setCodeId(codeId);
|
||||||
qrCode.setFilePath(result.getData().get("filePath").toString());
|
qrCode.setFilePath(result.getData().get("filePath").toString());
|
||||||
qrCode.setFileId(result.getData().get("fileId").toString());
|
qrCode.setFileId(result.getData().get("fileId").toString());
|
||||||
@@ -221,6 +224,14 @@ public class QrCodeController {
|
|||||||
if (vlogCount != null) plan.setVlogCount(vlogCount);
|
if (vlogCount != null) plan.setVlogCount(vlogCount);
|
||||||
if (videoCount != null) plan.setVideoCount(videoCount);
|
if (videoCount != null) plan.setVideoCount(videoCount);
|
||||||
if (photoCount != null) plan.setPhotoCount(photoCount);
|
if (photoCount != null) plan.setPhotoCount(photoCount);
|
||||||
|
// 景区素材ID集合存储到套餐表
|
||||||
|
if (body.getTourismFileIds() != null && !body.getTourismFileIds().isEmpty()) {
|
||||||
|
String idsStr = body.getTourismFileIds().stream()
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.map(String::valueOf)
|
||||||
|
.collect(Collectors.joining(","));
|
||||||
|
plan.setTourismFileIds(idsStr);
|
||||||
|
}
|
||||||
packagePlanService.saveOrUpdate(plan);
|
packagePlanService.saveOrUpdate(plan);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+44
-12
@@ -4,6 +4,7 @@ import com.central.common.model.PageResult;
|
|||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.order.feign.FileCenterService;
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.model.TourismFile;
|
import com.central.order.model.TourismFile;
|
||||||
|
import com.central.order.model.vo.TourismFileGroupVO;
|
||||||
import com.central.order.service.ITourismFileService;
|
import com.central.order.service.ITourismFileService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -18,10 +19,7 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tourism File information
|
* 景区资源文件控制器
|
||||||
*
|
|
||||||
* @author lsl
|
|
||||||
* @date 2025-2-19 17:51:47
|
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@@ -37,25 +35,25 @@ public class TourismFileController {
|
|||||||
private FileCenterService fileCenterService;
|
private FileCenterService fileCenterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 列表(原接口,保留)
|
||||||
*/
|
*/
|
||||||
@Operation(summary = "查询列表")
|
@Operation(summary = "查询列表")
|
||||||
@Parameters({
|
@Parameters({
|
||||||
@Parameter(name = "page",description = "分页起始位置",required = true,in=ParameterIn.QUERY),
|
@Parameter(name = "page", description = "分页起始位置", required = true, in = ParameterIn.QUERY),
|
||||||
@Parameter(name = "limit",description = "分页结束位置",required = true,in=ParameterIn.QUERY)
|
@Parameter(name = "limit", description = "分页结束位置", required = true, in = ParameterIn.QUERY)
|
||||||
})
|
})
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public PageResult list(@RequestParam Map<String, Object> params) {
|
public PageResult list(@RequestParam Map<String, Object> params) {
|
||||||
PageResult<TourismFile> pageResult = tourismFileService.findList(params);
|
PageResult<TourismFile> pageResult = tourismFileService.findList(params);
|
||||||
if (pageResult.getCount()>0){
|
if (pageResult.getCount() > 0) {
|
||||||
for (TourismFile tourismFile: pageResult.getData()){
|
for (TourismFile tourismFile : pageResult.getData()) {
|
||||||
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
|
tourismFile.setImageUrl(fileCenterService.getViewUrlByPath(tourismFile.getImageUrl()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pageResult;
|
return pageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping()
|
@PostMapping
|
||||||
public Result saveOrUpdate(@RequestBody TourismFile tourismFile) {
|
public Result saveOrUpdate(@RequestBody TourismFile tourismFile) {
|
||||||
return tourismFileService.saveOrUpdateTourismFile(tourismFile);
|
return tourismFileService.saveOrUpdateTourismFile(tourismFile);
|
||||||
}
|
}
|
||||||
@@ -67,12 +65,46 @@ public class TourismFileController {
|
|||||||
if (tourismFile == null) {
|
if (tourismFile == null) {
|
||||||
return Result.failed("暂无数据");
|
return Result.failed("暂无数据");
|
||||||
}
|
}
|
||||||
return Result.succeed(tourismFile,"获取成功");
|
return Result.succeed(tourismFile, "获取成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public Result delete(@PathVariable Long id) {
|
public Result delete(@PathVariable Long id) {
|
||||||
tourismFileService.removeById(id);
|
tourismFileService.removeById(id);
|
||||||
return Result.succeed( "操作成功");
|
return Result.succeed("操作成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新接口:按租户分组返回景区资源(以景区为组)
|
||||||
|
* 逻辑:先根据租户获取其及子租户下的所有景区,再根据景区获取资源文件
|
||||||
|
* 注意:保留原 /tourism/files 接口不变
|
||||||
|
*/
|
||||||
|
@Operation(summary = "按租户分组返回景区资源")
|
||||||
|
@GetMapping("/grouped/by-tenant")
|
||||||
|
public PageResult<TourismFileGroupVO> listGroupedByTenant(@RequestParam Map<String, Object> params) {
|
||||||
|
try {
|
||||||
|
return tourismFileService.findFilesGroupedByTenant(params);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("按租户分组查询景区资源失败", e);
|
||||||
|
return PageResult.<TourismFileGroupVO>builder().data(java.util.Collections.emptyList()).resp_code(1).count(0L).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 按景区ID获取资源列表
|
||||||
|
*/
|
||||||
|
@Operation(summary = "按景区ID获取资源列表")
|
||||||
|
@GetMapping("/byTourism/{tourismId}")
|
||||||
|
public Result listByTourismId(@PathVariable("tourismId") Long tourismId) {
|
||||||
|
java.util.List<TourismFile> list = tourismFileService.getByTourismId(tourismId);
|
||||||
|
if (list != null) {
|
||||||
|
for (TourismFile f : list) {
|
||||||
|
try {
|
||||||
|
if (f != null && f.getImageUrl() != null) {
|
||||||
|
f.setImageUrl(fileCenterService.getViewUrlByPath(f.getImageUrl()));
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.succeed(list, "操作成功");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+15
@@ -92,4 +92,19 @@ public class VideoTemplateController {
|
|||||||
return Result.failed("获取失败");
|
return Result.failed("获取失败");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据模板ID(templateId)获取模板信息")
|
||||||
|
@GetMapping("/templateId/{templateId}")
|
||||||
|
public Result<VideoTemplate> getByTemplateId(@PathVariable String templateId) {
|
||||||
|
try {
|
||||||
|
VideoTemplate template = videoTemplateService.lambdaQuery()
|
||||||
|
.eq(VideoTemplate::getTemplateId, templateId)
|
||||||
|
.last("limit 1")
|
||||||
|
.one();
|
||||||
|
return Result.succeed(template);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("根据模板ID查询模板失败, templateId={}", templateId, e);
|
||||||
|
return Result.failed("查询失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+10
-10
@@ -10,23 +10,23 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tourism File information
|
* 景区资源文件 Mapper
|
||||||
*
|
|
||||||
* @author lsl
|
|
||||||
* @date 2025-2-17 17:52:54
|
|
||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface TourismFileMapper extends SuperMapper<TourismFile> {
|
public interface TourismFileMapper extends SuperMapper<TourismFile> {
|
||||||
/**
|
/**
|
||||||
* 分页查询用户列表
|
* 分页查询列表
|
||||||
*
|
|
||||||
* @param page
|
|
||||||
* @param params
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
List<TourismFile> findList(Page<TourismFile> page, @Param("p") Map<String, Object> params);
|
List<TourismFile> findList(Page<TourismFile> page, @Param("p") Map<String, Object> params);
|
||||||
|
|
||||||
// ID查询
|
/** 按景区ID查询 */
|
||||||
List<TourismFile> getByTourismId(@Param("tourismId") Long tourismId);
|
List<TourismFile> getByTourismId(@Param("tourismId") Long tourismId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据景区ID集合批量查询资源文件(可选过滤 type/status/description)
|
||||||
|
*/
|
||||||
|
List<TourismFile> findByTourismIds(@Param("tourismIds") List<Long> tourismIds,
|
||||||
|
@Param("type") Integer type,
|
||||||
|
@Param("status") Integer status,
|
||||||
|
@Param("description") String description);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,10 @@ public class PackagePlan extends SuperEntity {
|
|||||||
@Schema(description = "照片数量")
|
@Schema(description = "照片数量")
|
||||||
private Integer photoCount;
|
private Integer photoCount;
|
||||||
|
|
||||||
|
@Schema(description = "景区素材ID集合(逗号分隔)")
|
||||||
|
private String tourismFileIds;
|
||||||
|
|
||||||
|
|
||||||
@Schema(description = "租户ID")
|
@Schema(description = "租户ID")
|
||||||
private String tenantId;
|
private String tenantId;
|
||||||
|
|
||||||
|
|||||||
+5
@@ -4,6 +4,8 @@ import com.central.order.model.QrCode;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "二维码与套餐创建/修改请求体")
|
@Schema(description = "二维码与套餐创建/修改请求体")
|
||||||
public class QrcodeWithPlanDTO {
|
public class QrcodeWithPlanDTO {
|
||||||
@@ -18,5 +20,8 @@ public class QrcodeWithPlanDTO {
|
|||||||
|
|
||||||
@Schema(description = "照片数量")
|
@Schema(description = "照片数量")
|
||||||
private Integer photoCount;
|
private Integer photoCount;
|
||||||
|
|
||||||
|
@Schema(description = "景区素材ID集合(ID 数组)")
|
||||||
|
private List<Long> tourismFileIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package com.central.order.model.vo;
|
||||||
|
|
||||||
|
import com.central.order.model.TourismFile;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Schema(description = "景区资源")
|
||||||
|
public class TourismFileGroupVO {
|
||||||
|
|
||||||
|
private Long tourismId;
|
||||||
|
|
||||||
|
private String tourismName;
|
||||||
|
|
||||||
|
private List<TourismFile> files;
|
||||||
|
}
|
||||||
+9
-23
@@ -4,37 +4,23 @@ import com.central.common.model.PageResult;
|
|||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.common.service.ISuperService;
|
import com.central.common.service.ISuperService;
|
||||||
import com.central.order.model.TourismFile;
|
import com.central.order.model.TourismFile;
|
||||||
|
import com.central.order.model.vo.TourismFileGroupVO;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
|
||||||
* Firmware file information
|
|
||||||
*
|
|
||||||
* @author lsl
|
|
||||||
* @date 2024-12-19 17:52:54
|
|
||||||
*/
|
|
||||||
public interface ITourismFileService extends ISuperService<TourismFile> {
|
public interface ITourismFileService extends ISuperService<TourismFile> {
|
||||||
/**
|
|
||||||
* 列表
|
|
||||||
* @param params
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
PageResult<TourismFile> findList(Map<String, Object> params);
|
PageResult<TourismFile> findList(Map<String, Object> params);
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建
|
|
||||||
*
|
|
||||||
* @param tourismFile
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Result saveOrUpdateTourismFile(TourismFile tourismFile) ;
|
|
||||||
|
|
||||||
/**
|
Result saveOrUpdateTourismFile(TourismFile tourismFile);
|
||||||
* id查询
|
|
||||||
* @param id
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
List<TourismFile> getByTourismId(Long id);
|
List<TourismFile> getByTourismId(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
PageResult<TourismFileGroupVO> findFilesGroupedByTenant(Map<String, Object> params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+99
-14
@@ -4,42 +4,49 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import com.central.common.model.PageResult;
|
import com.central.common.model.PageResult;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.common.service.impl.SuperServiceImpl;
|
import com.central.common.service.impl.SuperServiceImpl;
|
||||||
|
import com.central.order.feign.FileCenterService;
|
||||||
import com.central.order.mapper.TourismFileMapper;
|
import com.central.order.mapper.TourismFileMapper;
|
||||||
|
import com.central.order.mapper.TourismMapper;
|
||||||
|
import com.central.order.model.Tourism;
|
||||||
import com.central.order.model.TourismFile;
|
import com.central.order.model.TourismFile;
|
||||||
|
import com.central.order.model.vo.TourismFileGroupVO;
|
||||||
import com.central.order.service.ITourismFileService;
|
import com.central.order.service.ITourismFileService;
|
||||||
|
import com.central.order.service.ITourismService;
|
||||||
|
import com.central.common.feign.UserService;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Order information
|
|
||||||
*
|
|
||||||
* @author lsl
|
|
||||||
* @date 2024-12-19 17:52:54
|
|
||||||
*/
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class TourismFileServiceImpl extends SuperServiceImpl<TourismFileMapper, TourismFile> implements ITourismFileService {
|
public class TourismFileServiceImpl extends SuperServiceImpl<TourismFileMapper, TourismFile> implements ITourismFileService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TourismMapper tourismMapper;
|
||||||
|
@Autowired
|
||||||
|
private FileCenterService fileCenterService;
|
||||||
|
@Autowired
|
||||||
|
private UserService userCenterService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表
|
* 鍒嗛〉鍒楄〃
|
||||||
* @param params
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public PageResult<TourismFile> findList(Map<String, Object> params){
|
public PageResult<TourismFile> findList(Map<String, Object> params) {
|
||||||
Page<TourismFile> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
Page<TourismFile> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
List<TourismFile> list = baseMapper.findList(page, params);
|
List<TourismFile> list = baseMapper.findList(page, params);
|
||||||
return PageResult.<TourismFile>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
return PageResult.<TourismFile>builder().data(list).resp_code(0).count(page.getTotal()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result saveOrUpdateTourismFile(TourismFile tourismFile) {
|
public Result saveOrUpdateTourismFile(TourismFile tourismFile) {
|
||||||
boolean result = saveOrUpdate(tourismFile);
|
boolean result = saveOrUpdate(tourismFile);
|
||||||
return result ? Result.succeed(tourismFile, "操作成功") : Result.failed("操作失败");
|
return result ? Result.succeed(tourismFile, "成功") : Result.failed("失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -47,4 +54,82 @@ public class TourismFileServiceImpl extends SuperServiceImpl<TourismFileMapper,
|
|||||||
return baseMapper.getByTourismId(id);
|
return baseMapper.getByTourismId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<TourismFileGroupVO> findFilesGroupedByTenant(Map<String, Object> params) {
|
||||||
|
List<TourismFileGroupVO> result = new ArrayList<>();
|
||||||
|
if (params == null) params = new HashMap<>();
|
||||||
|
String tenantId = MapUtils.getString(params, "tenantId");
|
||||||
|
Boolean includeChildren = MapUtils.getBoolean(params, "includeChildren", true);
|
||||||
|
Integer type = MapUtils.getInteger(params, "type", null);
|
||||||
|
Integer status = MapUtils.getInteger(params, "status", null);
|
||||||
|
String description = MapUtils.getString(params, "description", null);
|
||||||
|
Long filterTourismId = null;
|
||||||
|
try { filterTourismId = MapUtils.getLong(params, "tourismId", null); } catch (Exception ignored) {}
|
||||||
|
Integer pageNo = MapUtils.getInteger(params, "page", 1);
|
||||||
|
Integer pageSize = MapUtils.getInteger(params, "limit", 10);
|
||||||
|
|
||||||
|
// 兼容:未显式传入租户,尝试从上下文获取当前查询租户
|
||||||
|
if (tenantId == null || tenantId.isEmpty()) {
|
||||||
|
try {
|
||||||
|
tenantId = com.central.common.context.TenantQueryOverrideContext.getTenantId();
|
||||||
|
if (tenantId == null || tenantId.isEmpty()) {
|
||||||
|
tenantId = com.central.common.context.LoginUserContextHolder.getCurrentTenantId();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("获取当前查询租户失败: {}", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (tenantId == null || tenantId.isEmpty()) {
|
||||||
|
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(0L).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算租户集合
|
||||||
|
List<String> tenantIds;
|
||||||
|
if (Boolean.FALSE.equals(includeChildren)) {
|
||||||
|
tenantIds = Collections.singletonList(tenantId);
|
||||||
|
} else {
|
||||||
|
tenantIds = userCenterService.getSonTenantIds(tenantId);
|
||||||
|
if (tenantIds == null || tenantIds.isEmpty()) {
|
||||||
|
tenantIds = Collections.singletonList(tenantId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建分页查询景区
|
||||||
|
com.baomidou.mybatisplus.extension.plugins.pagination.Page<Tourism> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNo, pageSize);
|
||||||
|
Map<String, Object> p = new HashMap<>();
|
||||||
|
p.put("tenantIds", tenantIds);
|
||||||
|
if (filterTourismId != null && filterTourismId > 0) {
|
||||||
|
p.put("tourismId", filterTourismId);
|
||||||
|
}
|
||||||
|
List<Tourism> tourisms = tourismMapper.findList(page, p);
|
||||||
|
long total = page.getTotal();
|
||||||
|
if (tourisms == null || tourisms.isEmpty()) {
|
||||||
|
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(total).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 批量查询资源文件(只查本页景区)
|
||||||
|
List<Long> pageTourismIds = tourisms.stream().map(Tourism::getId).collect(Collectors.toList());
|
||||||
|
List<TourismFile> files = baseMapper.findByTourismIds(pageTourismIds, type, status, description);
|
||||||
|
Map<Long, List<TourismFile>> grouped = files == null ? new HashMap<>() : files.stream().collect(Collectors.groupingBy(TourismFile::getTourismId));
|
||||||
|
|
||||||
|
for (Tourism t : tourisms) {
|
||||||
|
TourismFileGroupVO vo = new TourismFileGroupVO();
|
||||||
|
vo.setTourismId(t.getId());
|
||||||
|
vo.setTourismName(t.getTourismName());
|
||||||
|
List<TourismFile> list = grouped.getOrDefault(t.getId(), Collections.emptyList());
|
||||||
|
// 转换 URL
|
||||||
|
List<TourismFile> converted = new ArrayList<>(list.size());
|
||||||
|
for (TourismFile f : list) {
|
||||||
|
if (f != null && f.getImageUrl() != null) {
|
||||||
|
try { f.setImageUrl(fileCenterService.getViewUrlByPath(f.getImageUrl())); } catch (Exception ignored) {}
|
||||||
|
}
|
||||||
|
converted.add(f);
|
||||||
|
}
|
||||||
|
vo.setFiles(converted);
|
||||||
|
result.add(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return PageResult.<TourismFileGroupVO>builder().data(result).resp_code(0).count(total).build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
<mapper namespace="com.central.order.mapper.TourismFileMapper">
|
<mapper namespace="com.central.order.mapper.TourismFileMapper">
|
||||||
@@ -12,4 +12,30 @@
|
|||||||
<select id="getByTourismId" resultMap="TourismFileResultMap">
|
<select id="getByTourismId" resultMap="TourismFileResultMap">
|
||||||
SELECT * FROM tourisms_files WHERE tourism_id = #{tourismId}
|
SELECT * FROM tourisms_files WHERE tourism_id = #{tourismId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="findByTourismIds" resultType="com.central.order.model.TourismFile">
|
||||||
|
SELECT *
|
||||||
|
FROM tourisms_files
|
||||||
|
<where>
|
||||||
|
<if test="tourismIds != null and tourismIds.size > 0">
|
||||||
|
tourism_id IN
|
||||||
|
<foreach collection="tourismIds" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
<if test="type != null">
|
||||||
|
AND type = #{type}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
AND status = #{status}
|
||||||
|
</if>
|
||||||
|
<if test="description != null and description != ''">
|
||||||
|
AND description LIKE CONCAT('%', #{description}, '%')
|
||||||
|
</if>
|
||||||
|
<!-- 仅查询未删除数据 -->
|
||||||
|
AND (is_del = 0 OR is_del IS NULL)
|
||||||
|
</where>
|
||||||
|
ORDER BY id DESC
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
<if test="(p.tenantIds == null or p.tenantIds.size == 0) and p.tenantId != null and p.tenantId != ''">
|
<if test="(p.tenantIds == null or p.tenantIds.size == 0) and p.tenantId != null and p.tenantId != ''">
|
||||||
AND t.tenant_id = #{p.tenantId}
|
AND t.tenant_id = #{p.tenantId}
|
||||||
</if>
|
</if>
|
||||||
|
<if test="p.tourismName != null and p.tourismName != ''">
|
||||||
|
AND t.tourism_name LIKE CONCAT('%', #{p.tourismName}, '%')
|
||||||
|
</if>
|
||||||
</where>
|
</where>
|
||||||
ORDER BY t.id DESC
|
ORDER BY t.id DESC
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.3" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: com.alibaba:fastjson:1.2.54" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.16.22" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-test:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-context:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-aop:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-beans:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-expression:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-starter-logging:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-classic:1.2.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: ch.qos.logback:logback-core:1.2.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.10.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.apache.logging.log4j:log4j-api:2.10.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:jul-to-slf4j:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: javax.annotation:javax.annotation-api:1.3.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.19" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework.boot:spring-boot-test-autoconfigure:2.0.8.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: com.jayway.jsonpath:json-path:2.4.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:json-smart:2.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.minidev:accessors-smart:1.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.ow2.asm:asm:5.0.4" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.assertj:assertj-core:3.9.1" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.mockito:mockito-core:2.15.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy:1.7.11" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: net.bytebuddy:byte-buddy-agent:1.7.11" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.objenesis:objenesis:2.6" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.skyscreamer:jsonassert:1.5.0" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: com.vaadin.external.google:android-json:0.0.20131108.vaadin1" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-core:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-jcl:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:5.0.12.RELEASE" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.xmlunit:xmlunit-core:2.5.1" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -22,12 +22,10 @@ export default [
|
|||||||
routes: [
|
routes: [
|
||||||
{ path: '/orders/order.html', component: '@/pages/orders/Order' },
|
{ path: '/orders/order.html', component: '@/pages/orders/Order' },
|
||||||
{ path: '/orders/orderFiles.html', component: '@/pages/orders/OrderFile' },
|
{ path: '/orders/orderFiles.html', component: '@/pages/orders/OrderFile' },
|
||||||
{ path: '/orders/qrcode.html', component: '@/pages/orders/Qrcode' },
|
|
||||||
{ path: '/orders/tourism.html', component: '@/pages/orders/Tourism' },
|
{ path: '/orders/tourism.html', component: '@/pages/orders/Tourism' },
|
||||||
{ path: '/orders/tourismFile.html', component: '@/pages/orders/TourismFile' },
|
{ path: '/orders/tourismFile.html', component: '@/pages/orders/TourismFile' },
|
||||||
{ path: '/orders/homeCarousel.html', component: '@/pages/orders/HomeCarousel' },
|
{ path: '/orders/homeCarousel.html', component: '@/pages/orders/HomeCarousel' },
|
||||||
{ path: '/orders/refund.html', component: '@/pages/orders/Refund' },
|
{ path: '/orders/refund.html', component: '@/pages/orders/Refund' },
|
||||||
{ path: '/orders/statistics.html', component: '@/pages/orders/Statistics' },
|
|
||||||
{ path: '/orders/profitSharing.html', component: '@/pages/orders/ProfitSharing' },
|
{ path: '/orders/profitSharing.html', component: '@/pages/orders/ProfitSharing' },
|
||||||
{ path: '/orders/profit-sharing/statistics.html', component: '@/pages/orders/ProfitSharing/Statistics' },
|
{ path: '/orders/profit-sharing/statistics.html', component: '@/pages/orders/ProfitSharing/Statistics' },
|
||||||
{ path: '/orders/videoTemplate.html', component: '@/pages/orders/VideoTemplate' },
|
{ path: '/orders/videoTemplate.html', component: '@/pages/orders/VideoTemplate' },
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { QueryFilter } from '@ant-design/pro-components';
|
import { QueryFilter } from '@ant-design/pro-components';
|
||||||
|
import { Button } from 'antd';
|
||||||
import TenantSelector from '@/components/ui/TenantSelector';
|
import TenantSelector from '@/components/ui/TenantSelector';
|
||||||
import { tenantApi } from '@/services/tenant';
|
import { tenantApi } from '@/services/tenant';
|
||||||
|
|
||||||
export interface SearchBarPlusProps {
|
export interface SearchBarPlusProps {
|
||||||
// QueryFilter 透传属性(常用)
|
// QueryFilter 常用属性
|
||||||
defaultCollapsed?: boolean;
|
defaultCollapsed?: boolean;
|
||||||
split?: boolean;
|
split?: boolean;
|
||||||
span?: number | { xs?: number; sm?: number; md?: number; lg?: number; xl?: number; xxl?: number };
|
span?: number | { xs?: number; sm?: number; md?: number; lg?: number; xl?: number; xxl?: number };
|
||||||
@@ -14,12 +15,14 @@ export interface SearchBarPlusProps {
|
|||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
// 是否显示租户筛选(默认显示)
|
// 是否显示租户筛选(默认显示)
|
||||||
showTenant?: boolean;
|
showTenant?: boolean;
|
||||||
// 租户变化回调:用于触发表格 reload 等
|
// 租户变化回调:用于触发表格 reload
|
||||||
onTenantChanged?: (tenantId: string, includeChildren: boolean) => void;
|
onTenantChanged?: (tenantId: string, includeChildren: boolean) => void;
|
||||||
// 租户筛选放置位置:start 放在最前,end 放在最后(默认 start)
|
// 租户筛选放置位置:start 放在最前,end 放在最后(默认 start)
|
||||||
tenantPosition?: 'start' | 'end';
|
tenantPosition?: 'start' | 'end';
|
||||||
// 是否调用后端“切换查询租户”接口(默认不调用,避免跨页面副作用)
|
// 是否调用后端“切换查询租户”接口(默认不调用,避免跨页面副作用)
|
||||||
useSwitchTenant?: boolean;
|
useSwitchTenant?: boolean;
|
||||||
|
// 是否隐藏重置按钮(默认 false)
|
||||||
|
hideReset?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
||||||
@@ -33,6 +36,7 @@ const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
|||||||
onTenantChanged,
|
onTenantChanged,
|
||||||
tenantPosition = 'start',
|
tenantPosition = 'start',
|
||||||
useSwitchTenant = false,
|
useSwitchTenant = false,
|
||||||
|
hideReset = false,
|
||||||
}) => {
|
}) => {
|
||||||
const handleFinish = async (values: Record<string, any>) => {
|
const handleFinish = async (values: Record<string, any>) => {
|
||||||
try {
|
try {
|
||||||
@@ -52,6 +56,17 @@ const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
|||||||
span={span as any}
|
span={span as any}
|
||||||
form={form}
|
form={form}
|
||||||
onFinish={handleFinish}
|
onFinish={handleFinish}
|
||||||
|
submitter={
|
||||||
|
hideReset
|
||||||
|
? {
|
||||||
|
render: (props: any) => [
|
||||||
|
<Button key="submit" type="primary" onClick={() => props?.form?.submit?.()}>
|
||||||
|
查询
|
||||||
|
</Button>,
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{showTenant && tenantPosition === 'start' ? <TenantSelector /> : null}
|
{showTenant && tenantPosition === 'start' ? <TenantSelector /> : null}
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
import React, { useState } from 'react';
|
|
||||||
import { PageContainer, ProTable } from '@ant-design/pro-components';
|
|
||||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
|
||||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
|
||||||
import { PlusOutlined } from '@ant-design/icons';
|
|
||||||
import { ordersApi } from '@/services/orders';
|
|
||||||
import QrcodeForm, { QrcodeItem } from './components/QrcodeForm';
|
|
||||||
|
|
||||||
const QrcodePage: React.FC = () => {
|
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
|
||||||
const [editOpen, setEditOpen] = useState(false);
|
|
||||||
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
|
|
||||||
const [params, setParams] = useState<Record<string, any>>({});
|
|
||||||
|
|
||||||
const columns: any[] = [
|
|
||||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
|
||||||
{ title: '名称', dataIndex: 'name' },
|
|
||||||
{ title: '链接', dataIndex: 'url', ellipsis: true },
|
|
||||||
{ title: '类型', dataIndex: 'type' },
|
|
||||||
{ title: '状态', dataIndex: 'status', render: (v: number) => <Tag color={v === 1 ? 'green' : 'default'}>{v === 1 ? '启用' : '禁用'}</Tag> },
|
|
||||||
{
|
|
||||||
title: '操作', key: 'action',
|
|
||||||
render: (_: any, record: QrcodeItem) => (
|
|
||||||
<Space>
|
|
||||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
|
||||||
<Popconfirm title={`确认删除二维码[${record.name}]?`} onConfirm={async () => {
|
|
||||||
const hide = message.loading('删除中...');
|
|
||||||
try {
|
|
||||||
await ordersApi.deleteQrcode(record.id!);
|
|
||||||
message.success('删除成功');
|
|
||||||
} catch (e) {
|
|
||||||
message.error('删除失败');
|
|
||||||
} finally { hide(); }
|
|
||||||
}}>
|
|
||||||
<a style={{ color: '#1677ff' }}>删除</a>
|
|
||||||
</Popconfirm>
|
|
||||||
</Space>
|
|
||||||
)
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PageContainer header={{ title: '二维码管理' }}>
|
|
||||||
<SearchBarPlus
|
|
||||||
defaultCollapsed
|
|
||||||
split
|
|
||||||
span={8}
|
|
||||||
onTenantChanged={() => { /* 仅触发表格刷新 */ }}
|
|
||||||
onFinish={async (values) => setParams(values)}
|
|
||||||
/>
|
|
||||||
<ActionBar left={<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</GradientButton>} />
|
|
||||||
<GlassCard>
|
|
||||||
<ProTable<QrcodeItem>
|
|
||||||
rowKey="id"
|
|
||||||
request={(p) => ordersApi.qrcodeList({ ...(p as any), ...params })}
|
|
||||||
columns={columns}
|
|
||||||
search={false}
|
|
||||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
|
||||||
/>
|
|
||||||
</GlassCard>
|
|
||||||
|
|
||||||
<QrcodeForm
|
|
||||||
title="新增二维码"
|
|
||||||
open={createOpen}
|
|
||||||
onOpenChange={setCreateOpen}
|
|
||||||
onFinish={async (values) => {
|
|
||||||
const hide = message.loading('保存中...');
|
|
||||||
try {
|
|
||||||
await ordersApi.saveOrUpdateQrcode(values);
|
|
||||||
message.success('新增成功');
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
message.error('保存失败');
|
|
||||||
return false;
|
|
||||||
} finally { hide(); }
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<QrcodeForm
|
|
||||||
title="编辑二维码"
|
|
||||||
open={editOpen}
|
|
||||||
initialValues={current}
|
|
||||||
onOpenChange={setEditOpen}
|
|
||||||
onFinish={async (values) => {
|
|
||||||
const hide = message.loading('保存中...');
|
|
||||||
try {
|
|
||||||
await ordersApi.saveOrUpdateQrcode({ ...(current as any), ...values });
|
|
||||||
message.success('修改成功');
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
message.error('修改失败');
|
|
||||||
return false;
|
|
||||||
} finally { hide(); }
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</PageContainer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default QrcodePage;
|
|
||||||
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
|
||||||
import { PageContainer } from '@ant-design/pro-components';
|
|
||||||
import { Card, Col, Row, Statistic, DatePicker, Space, message, Form } from 'antd';
|
|
||||||
import { SearchBarPlus } from '@/components/ui';
|
|
||||||
import { ordersApi } from '@/services/orders';
|
|
||||||
|
|
||||||
const { RangePicker } = DatePicker;
|
|
||||||
|
|
||||||
const StatisticsPage: React.FC = () => {
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [stat, setStat] = useState<any>({});
|
|
||||||
const [range, setRange] = useState<any>();
|
|
||||||
|
|
||||||
const load = async (p?: any) => {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
|
||||||
const res = await ordersApi.dashboard(p);
|
|
||||||
setStat(res?.data || res);
|
|
||||||
} catch (e) {
|
|
||||||
message.error('加载统计失败');
|
|
||||||
} finally { setLoading(false); }
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => { load(); }, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<PageContainer header={{ title: '订单统计' }}>
|
|
||||||
<SearchBarPlus
|
|
||||||
defaultCollapsed
|
|
||||||
split
|
|
||||||
span={8}
|
|
||||||
onTenantChanged={() => load(range)}
|
|
||||||
onFinish={async (values) => {
|
|
||||||
const v = (values as any)?.timeRange;
|
|
||||||
const base: any = {};
|
|
||||||
if (v && v.length === 2) {
|
|
||||||
base.startTime = v[0]?.toISOString();
|
|
||||||
base.endTime = v[1]?.toISOString();
|
|
||||||
}
|
|
||||||
// 合并租户筛选参数
|
|
||||||
const r = { ...values, ...base } as any;
|
|
||||||
delete r.timeRange;
|
|
||||||
setRange(r);
|
|
||||||
await load(r);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Form.Item name="timeRange" label="时间范围">
|
|
||||||
<RangePicker showTime />
|
|
||||||
</Form.Item>
|
|
||||||
</SearchBarPlus>
|
|
||||||
|
|
||||||
<Row gutter={16}>
|
|
||||||
<Col span={6}><Card loading={loading}><Statistic title="订单总数" value={stat?.totalOrders || 0} /></Card></Col>
|
|
||||||
<Col span={6}><Card loading={loading}><Statistic title="支付总额" value={stat?.totalAmount || 0} precision={2} /></Card></Col>
|
|
||||||
<Col span={6}><Card loading={loading}><Statistic title="退款总额" value={stat?.refundAmount || 0} precision={2} /></Card></Col>
|
|
||||||
<Col span={6}><Card loading={loading}><Statistic title="转化率" value={stat?.conversionRate || 0} suffix="%" /></Card></Col>
|
|
||||||
</Row>
|
|
||||||
</PageContainer>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default StatisticsPage;
|
|
||||||
|
|
||||||
+26
-4
@@ -7,9 +7,30 @@ export interface QrcodeItem {
|
|||||||
type?: number;
|
type?: number;
|
||||||
url?: string;
|
url?: string;
|
||||||
status?: number;
|
status?: number;
|
||||||
|
// 以下为景区二维码列表中使用到的扩展字段(仅类型声明,不影响表单)
|
||||||
|
tourismId?: number;
|
||||||
|
codeId?: string;
|
||||||
|
waylineId?: string;
|
||||||
|
viewUrl?: string;
|
||||||
|
deviceSn?: string;
|
||||||
|
price?: number | string;
|
||||||
|
templateId?: string;
|
||||||
|
enableVideoEdit?: number; // 0: 否 1: 开启
|
||||||
|
isTest?: number; // 0: 否 1: 是
|
||||||
|
qrcodeType?: number; // 1: 游客下单 2: 定时巡查 其他: 其他
|
||||||
|
showVideoEditOnly?: number; // 0: 否 1: 是
|
||||||
|
materialCount?: number;
|
||||||
|
enableProfit?: number; // 0: 否 1: 是
|
||||||
|
payeeAccount?: string;
|
||||||
|
payeeType?: 'MERCHANT_ID' | 'PERSONAL_OPENID' | string;
|
||||||
|
profitRate?: number;
|
||||||
|
appId?: string;
|
||||||
|
vlogCount?: number;
|
||||||
|
videoCount?: number;
|
||||||
|
photoCount?: number;
|
||||||
|
tourismFileIds?: number[];
|
||||||
}
|
}
|
||||||
|
export interface QrcodeFormProps {
|
||||||
export interface QrcodeFormProps {
|
|
||||||
open: boolean;
|
open: boolean;
|
||||||
title: string;
|
title: string;
|
||||||
initialValues?: Partial<QrcodeItem>;
|
initialValues?: Partial<QrcodeItem>;
|
||||||
@@ -30,9 +51,10 @@ const QrcodeForm: React.FC<QrcodeFormProps> = ({ open, title, initialValues, onO
|
|||||||
<ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入名称' }]} />
|
<ProFormText name="name" label="名称" rules={[{ required: true, message: '请输入名称' }]} />
|
||||||
<ProFormText name="url" label="地址" />
|
<ProFormText name="url" label="地址" />
|
||||||
<ProFormSelect name="type" label="类型" valueEnum={{ 1: '类型一', 2: '类型二' }} />
|
<ProFormSelect name="type" label="类型" valueEnum={{ 1: '类型一', 2: '类型二' }} />
|
||||||
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '启用', 0: '禁用' }} initialValue={1} />
|
<ProFormSelect name="status" label="状态" valueEnum={{ 1: '禁用', 0: '启用' }} initialValue={1} />
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default QrcodeForm;
|
export default QrcodeItem;
|
||||||
|
|
||||||
@@ -0,0 +1,319 @@
|
|||||||
|
import React, { useMemo, useRef, useState } from 'react';
|
||||||
|
import { Modal, Popconfirm, Space, Tag, message, Button } from 'antd';
|
||||||
|
import { ProTable, type ActionType } from '@ant-design/pro-components';
|
||||||
|
import { GradientButton } from '@/components/ui';
|
||||||
|
import { PlusOutlined, CopyOutlined } from '@ant-design/icons';
|
||||||
|
import { ordersApi } from '@/services/orders';
|
||||||
|
import { QrcodeItem } from './QrcodeItem';
|
||||||
|
import QrcodeTourismForm from './QrcodeTourismForm';
|
||||||
|
|
||||||
|
export interface QrcodeListModalProps {
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (v: boolean) => void;
|
||||||
|
tourismId: number;
|
||||||
|
tourismName?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QrcodeListModal: React.FC<QrcodeListModalProps> = ({ open, onOpenChange, tourismId, tourismName }) => {
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
|
const [current, setCurrent] = useState<QrcodeItem | undefined>(undefined);
|
||||||
|
const [previewOpen, setPreviewOpen] = useState(false);
|
||||||
|
const [previewImage, setPreviewImage] = useState<string>('');
|
||||||
|
|
||||||
|
// 模板ID -> 模板名称(通过接口懒加载)
|
||||||
|
const templateNameMapRef = useRef<Record<string, string>>({});
|
||||||
|
const templateInflightRef = useRef<Record<string, Promise<any>>>({});
|
||||||
|
const [tplTick, setTplTick] = useState(0); // 用于触发渲染
|
||||||
|
const title = useMemo(() => `打卡点二维码列表${tourismName ? `(${tourismName})` : ''}`, [tourismName]);
|
||||||
|
|
||||||
|
const ensureTemplateName = (tplId?: string) => {
|
||||||
|
if (!tplId) return '-';
|
||||||
|
const map = templateNameMapRef.current;
|
||||||
|
if (map[tplId]) return map[tplId];
|
||||||
|
if (!templateInflightRef.current[tplId]) {
|
||||||
|
templateInflightRef.current[tplId] = ordersApi
|
||||||
|
.getVideoTemplateByTemplateId(tplId)
|
||||||
|
.then((tpl: any) => {
|
||||||
|
const name = tpl?.templateName || tpl?.name || '-';
|
||||||
|
map[tplId] = name;
|
||||||
|
setTplTick((v) => v + 1);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
map[tplId] = '-';
|
||||||
|
setTplTick((v) => v + 1);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
delete templateInflightRef.current[tplId];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return '-';
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: any[] = [
|
||||||
|
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||||
|
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||||
|
{ title: '名称', dataIndex: 'name', width: 140 },
|
||||||
|
{
|
||||||
|
title: 'Code',
|
||||||
|
dataIndex: 'codeId',
|
||||||
|
width: 220,
|
||||||
|
render: (codeId: string) => {
|
||||||
|
if (!codeId) return '-';
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||||
|
<span style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{codeId}</span>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<CopyOutlined />}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(codeId)
|
||||||
|
.then(() => message.success('Code已复制'))
|
||||||
|
.catch(() => message.error('复制失败'));
|
||||||
|
}}
|
||||||
|
style={{ flexShrink: 0 }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '航线ID',
|
||||||
|
dataIndex: 'waylineId',
|
||||||
|
width: 220,
|
||||||
|
render: (waylineId: string) => {
|
||||||
|
if (!waylineId) return '-';
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||||
|
<span style={{ flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{waylineId}</span>
|
||||||
|
<Button
|
||||||
|
type="text"
|
||||||
|
size="small"
|
||||||
|
icon={<CopyOutlined />}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
navigator.clipboard
|
||||||
|
.writeText(waylineId)
|
||||||
|
.then(() => message.success('航线ID已复制'))
|
||||||
|
.catch(() => message.error('复制失败'));
|
||||||
|
}}
|
||||||
|
style={{ flexShrink: 0 }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '二维码',
|
||||||
|
dataIndex: 'viewUrl',
|
||||||
|
width: 100,
|
||||||
|
render: (url: string) => {
|
||||||
|
if (!url) return '-';
|
||||||
|
return (
|
||||||
|
<img
|
||||||
|
src={url}
|
||||||
|
alt="二维码" style={{ width: 60, height: 60, cursor: 'pointer', objectFit: 'contain' }}
|
||||||
|
onClick={() => {
|
||||||
|
setPreviewImage(url);
|
||||||
|
setPreviewOpen(true);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ title: '设备SN', dataIndex: 'deviceSn', width: 150 },
|
||||||
|
{
|
||||||
|
title: '价格',
|
||||||
|
dataIndex: 'price',
|
||||||
|
width: 100,
|
||||||
|
render: (price: string | number) => {
|
||||||
|
if (!price && price !== 0) return '-';
|
||||||
|
const priceNum = typeof price === 'string' ? parseFloat(price) : price;
|
||||||
|
if (Number.isNaN(priceNum)) return '-';
|
||||||
|
return `¥${(priceNum / 100).toFixed(2)}`;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 90,
|
||||||
|
render: (v: number) => <Tag color={v === 0 ? 'green' : 'red'}>{v === 0 ? '启用' : '禁用'}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '模板名称',
|
||||||
|
dataIndex: 'templateId',
|
||||||
|
width: 160,
|
||||||
|
render: (tplId?: string) => ensureTemplateName(tplId),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '一键成片',
|
||||||
|
dataIndex: 'enableVideoEdit',
|
||||||
|
width: 100,
|
||||||
|
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '测试二维码',
|
||||||
|
dataIndex: 'isTest',
|
||||||
|
width: 110,
|
||||||
|
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '二维码类型',
|
||||||
|
dataIndex: 'qrcodeType',
|
||||||
|
width: 120,
|
||||||
|
render: (v: number) => {
|
||||||
|
if (v === 1) return <Tag color="blue">游客扫码</Tag>;
|
||||||
|
if (v === 2) return <Tag color="green">临时扫码</Tag>;
|
||||||
|
return <Tag color="#000000">自定义</Tag>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '仅显示一键成片',
|
||||||
|
dataIndex: 'showVideoEditOnly',
|
||||||
|
width: 130,
|
||||||
|
render: (v: number) => <Tag color={v === 1 ? 'green' : 'red'}>{v === 1 ? '是' : '否'}</Tag>,
|
||||||
|
},
|
||||||
|
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 160 },
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
width: 160,
|
||||||
|
fixed: 'right',
|
||||||
|
render: (_: any, record: QrcodeItem) => (
|
||||||
|
<Space>
|
||||||
|
<a
|
||||||
|
onClick={async () => {
|
||||||
|
try {
|
||||||
|
const plans = await ordersApi.getPackagePlanByCode(record.codeId as any);
|
||||||
|
const plan: any = Array.isArray(plans) && plans.length > 0 ? plans[0] : {};
|
||||||
|
const tourismFileIds = plan.tourismFileIds ? String(plan.tourismFileIds).split(',').filter(Boolean).map((x: any) => Number(x)) : [];
|
||||||
|
setCurrent({ ...record, vlogCount: plan.vlogCount, videoCount: plan.videoCount, photoCount: plan.photoCount, tourismFileIds });
|
||||||
|
} catch {
|
||||||
|
setCurrent(record);
|
||||||
|
}
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</a>
|
||||||
|
<Popconfirm
|
||||||
|
title={`确认删除二维码【${record.name}】?`}
|
||||||
|
onConfirm={async () => {
|
||||||
|
const hide = message.loading('正在删除...');
|
||||||
|
try {
|
||||||
|
await ordersApi.deleteQrcode(record.id!);
|
||||||
|
message.success('删除成功');
|
||||||
|
actionRef.current?.reload();
|
||||||
|
} catch (e) {
|
||||||
|
message.error('删除失败');
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<a style={{ color: '#1677ff' }}>删除</a>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Modal title={title} open={open} onCancel={() => onOpenChange(false)} footer={null} width={1600} destroyOnClose>
|
||||||
|
<div style={{ marginBottom: 12 }}>
|
||||||
|
<GradientButton size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>
|
||||||
|
新增
|
||||||
|
</GradientButton>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<ProTable<QrcodeItem>
|
||||||
|
rowKey="id"
|
||||||
|
actionRef={actionRef}
|
||||||
|
request={(p) => ordersApi.qrcodeListByTourism({ ...(p as any), tourismId })}
|
||||||
|
columns={columns}
|
||||||
|
search={false}
|
||||||
|
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||||
|
toolBarRender={false}
|
||||||
|
scroll={{ x: 1600 }}
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
|
{/* 新增/编辑表单:仅在打开时才挂载,避免列表页触发内部副作用 */}
|
||||||
|
{createOpen && (
|
||||||
|
<QrcodeTourismForm
|
||||||
|
title="新增二维码" open={createOpen}
|
||||||
|
onOpenChange={setCreateOpen}
|
||||||
|
onFinish={async (values) => {
|
||||||
|
const hide = message.loading('提交中...');
|
||||||
|
try {
|
||||||
|
const { vlogCount, videoCount, photoCount, tourismFileIds, ...qrRest } = values as any;
|
||||||
|
await ordersApi.saveOrUpdateQrcodePlan({
|
||||||
|
qrCode: { ...qrRest, tourismId },
|
||||||
|
vlogCount,
|
||||||
|
videoCount,
|
||||||
|
photoCount,
|
||||||
|
tourismFileIds,
|
||||||
|
});
|
||||||
|
message.success('修改成功');
|
||||||
|
actionRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
message.error('修改失败');
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
defaultTourismId={tourismId}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{editOpen && (
|
||||||
|
<QrcodeTourismForm
|
||||||
|
title="编辑二维码" open={editOpen}
|
||||||
|
onOpenChange={setEditOpen}
|
||||||
|
onFinish={async (values) => {
|
||||||
|
const hide = message.loading('提交中...');
|
||||||
|
try {
|
||||||
|
const merged: any = { ...(current as any), ...values };
|
||||||
|
const { vlogCount, videoCount, photoCount, tourismFileIds, ...qrRest } = merged;
|
||||||
|
await ordersApi.saveOrUpdateQrcodePlan({
|
||||||
|
qrCode: qrRest,
|
||||||
|
vlogCount,
|
||||||
|
videoCount,
|
||||||
|
photoCount,
|
||||||
|
tourismFileIds,
|
||||||
|
});
|
||||||
|
message.success('修改成功');
|
||||||
|
actionRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
message.error('修改失败');
|
||||||
|
return false;
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
defaultTourismId={tourismId}
|
||||||
|
initialValues={current}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 二维码预览 */}
|
||||||
|
<Modal title="二维码预览" open={previewOpen} onCancel={() => setPreviewOpen(false)} footer={null} width={600} centered destroyOnClose>
|
||||||
|
<div style={{ display: 'flex', justifyContent: 'center', padding: '20px 0' }}>
|
||||||
|
<img src={previewImage} alt="二维码预览" style={{ maxWidth: '100%', maxHeight: '70vh', objectFit: 'contain' }} />
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default QrcodeListModal;
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,347 @@
|
|||||||
|
import React, { useEffect, useState } from 'react';
|
||||||
|
import { ModalForm, ProForm, ProFormDigit, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||||
|
import { ordersApi } from '@/services/orders';
|
||||||
|
import { deviceApi } from '@/services/device';
|
||||||
|
import { miniAppApi } from '@/services/miniapp';
|
||||||
|
import type { QrcodeItem } from './QrcodeItem';
|
||||||
|
|
||||||
|
export interface QrcodeTourismFormProps {
|
||||||
|
open: boolean;
|
||||||
|
title: string;
|
||||||
|
initialValues?: Partial<QrcodeItem>;
|
||||||
|
onOpenChange: (v: boolean) => void;
|
||||||
|
onFinish: (values: QrcodeItem) => Promise<boolean>;
|
||||||
|
defaultTourismId?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QrcodeTourismForm: React.FC<QrcodeTourismFormProps> = ({ open, title, initialValues, onOpenChange, onFinish, defaultTourismId }) => {
|
||||||
|
// 统一默认值,解决新增/编辑缺省字段问题
|
||||||
|
const DEFAULTS: Partial<QrcodeItem> = {
|
||||||
|
status: 0, // 状态:0=启用1=禁用
|
||||||
|
enableVideoEdit: 0, // 是否开启一键成片:0=否 1=是
|
||||||
|
isTest: 0, // 是否测试二维码:0=否 1=是
|
||||||
|
qrcodeType: 1, // 二维码类型:1=游客扫码 2=临时扫码 3=自定义
|
||||||
|
showVideoEditOnly: 0, // 是否仅显示一键成片:0=否 1=是
|
||||||
|
materialCount: 1,
|
||||||
|
vlogCount: 0,
|
||||||
|
videoCount: 0,
|
||||||
|
photoCount: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// 过滤 initialValues 中的 undefined,避免覆盖默认值
|
||||||
|
const sanitizedInitial: Partial<QrcodeItem> = initialValues
|
||||||
|
? (Object.fromEntries(Object.entries(initialValues).filter(([, v]) => v !== undefined)) as any)
|
||||||
|
: {};
|
||||||
|
|
||||||
|
// 景区ID,用于素材查询
|
||||||
|
const tourismIdForFetch = (sanitizedInitial as any)?.tourismId ?? defaultTourismId;
|
||||||
|
|
||||||
|
// 景区素材
|
||||||
|
const [tourismFiles, setTourismFiles] = useState<any[]>([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// 仅在弹窗打开时才加载景区素材,避免在列表页无意义调用接口
|
||||||
|
if (!open) return;
|
||||||
|
if (!tourismIdForFetch) {
|
||||||
|
setTourismFiles([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let canceled = false;
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
const { data = [] } = await ordersApi.tourismFileByTourism(tourismIdForFetch as any);
|
||||||
|
if (!canceled) setTourismFiles(Array.isArray(data) ? data : []);
|
||||||
|
} catch {
|
||||||
|
if (!canceled) setTourismFiles([]);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
return () => {
|
||||||
|
canceled = true;
|
||||||
|
};
|
||||||
|
}, [open, tourismIdForFetch]);
|
||||||
|
|
||||||
|
// 景区素材类型字典(按业务提供)
|
||||||
|
const TYPE_LABEL: Record<number, string> = {
|
||||||
|
5: '视频',
|
||||||
|
6: '首页 Banner',
|
||||||
|
4: '展示图片',
|
||||||
|
3: '景区详情',
|
||||||
|
2: '景区小图展示',
|
||||||
|
1: '活动',
|
||||||
|
};
|
||||||
|
const typeName = (t: any) => TYPE_LABEL[Number(t)] || '其他';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ModalForm<QrcodeItem>
|
||||||
|
title={title}
|
||||||
|
visible={open}
|
||||||
|
onVisibleChange={onOpenChange}
|
||||||
|
onFinish={onFinish}
|
||||||
|
initialValues={(() => {
|
||||||
|
const init: any = {
|
||||||
|
...DEFAULTS,
|
||||||
|
...(sanitizedInitial as any),
|
||||||
|
tourismId: (sanitizedInitial as any)?.tourismId ?? defaultTourismId,
|
||||||
|
};
|
||||||
|
const toNum = (v: any) => (typeof v === 'string' ? Number(v) : v);
|
||||||
|
['status', 'enableVideoEdit', 'isTest', 'qrcodeType', 'showVideoEditOnly', 'materialCount', 'vlogCount', 'videoCount', 'photoCount'].forEach((k) => {
|
||||||
|
if (init[k] !== undefined) init[k] = toNum(init[k]);
|
||||||
|
});
|
||||||
|
if (init.templateId !== undefined && init.templateId !== null) {
|
||||||
|
init.templateId = String(init.templateId);
|
||||||
|
}
|
||||||
|
return init as any;
|
||||||
|
})()}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
grid
|
||||||
|
rowProps={{ gutter: [16, 8] }}
|
||||||
|
layout="horizontal"
|
||||||
|
labelCol={{ flex: '120px' }}
|
||||||
|
wrapperCol={{ flex: 'auto' }}
|
||||||
|
labelAlign="left"
|
||||||
|
labelWrap
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
>
|
||||||
|
{/* 小程序商户(仅显示支持支付的类型)*/}
|
||||||
|
<ProFormSelect
|
||||||
|
name="tenantId"
|
||||||
|
label="小程序商户"
|
||||||
|
showSearch
|
||||||
|
rules={[{ required: true, message: '请选择小程序商户' }]}
|
||||||
|
placeholder="请选择小程序商户"
|
||||||
|
request={async () => {
|
||||||
|
// 只取 type=PAY 的商户
|
||||||
|
const { data = [] } = await miniAppApi.list({ page: 1, limit: 1000 });
|
||||||
|
const filtered = (data || []).filter((m: any) => String(m?.type || '').toUpperCase() === 'PAY');
|
||||||
|
return filtered.map((m: any) => ({ label: m.subMchName || m.tenantId, value: m.tenantId }));
|
||||||
|
}}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 基本信息 */}
|
||||||
|
<ProFormText
|
||||||
|
name="name"
|
||||||
|
label="名称"
|
||||||
|
rules={[{ required: true, message: '请输入二维码名称' }]}
|
||||||
|
placeholder="请输入二维码名称"
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProFormSelect
|
||||||
|
name="waylineId"
|
||||||
|
label="航线"
|
||||||
|
showSearch
|
||||||
|
allowClear
|
||||||
|
rules={[{ required: true, message: '请选择航线' }]}
|
||||||
|
placeholder="请选择航线"
|
||||||
|
request={async () => {
|
||||||
|
const { data = [] } = await deviceApi.wayline({ current: 1, pageSize: 1000 });
|
||||||
|
return (data || []).map((w: any) => ({ label: w.name || w.waylineId, value: w.waylineId }));
|
||||||
|
}}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProFormSelect
|
||||||
|
name="deviceSn"
|
||||||
|
label="设备"
|
||||||
|
showSearch
|
||||||
|
allowClear
|
||||||
|
rules={[{ required: true, message: '请选择设备' }]}
|
||||||
|
placeholder="请选择设备"
|
||||||
|
request={async () => {
|
||||||
|
const { data = [] } = await deviceApi.deviceList({ page: 1, limit: 1000 });
|
||||||
|
return (data || []).map((d: any) => ({ label: d.deviceName || d.deviceSn, value: d.deviceSn }));
|
||||||
|
}}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProFormDigit
|
||||||
|
name="price"
|
||||||
|
label="价格(分)"
|
||||||
|
min={0}
|
||||||
|
rules={[{ required: true, message: '请输入价格' }]}
|
||||||
|
fieldProps={{ precision: 0 }}
|
||||||
|
placeholder="请输入价格"
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProFormSelect
|
||||||
|
name="status"
|
||||||
|
label="状态"
|
||||||
|
rules={[{ required: true, message: '请选择状态' }]}
|
||||||
|
options={[
|
||||||
|
{ label: '启用', value: 0 },
|
||||||
|
{ label: '禁用', value: 1 },
|
||||||
|
]}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 视频模板(可选) */}
|
||||||
|
<ProFormSelect
|
||||||
|
name="templateId"
|
||||||
|
label="视频模板"
|
||||||
|
showSearch
|
||||||
|
allowClear
|
||||||
|
placeholder="请选择视频模板"
|
||||||
|
request={async () => {
|
||||||
|
try {
|
||||||
|
const api: any = ordersApi as any;
|
||||||
|
const resp = api.getVideoTemplateList ? await api.getVideoTemplateList({ current: 1, pageSize: 1000 }) : { data: [] };
|
||||||
|
const { data = [] } = (resp || {}) as any;
|
||||||
|
return (data || []).map((t: any) => ({ label: t?.templateName || t?.name || String(t?.templateId ?? t?.id), value: String(t?.templateId ?? t?.id) }));
|
||||||
|
} catch {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 功能开关 */}
|
||||||
|
<ProFormSelect
|
||||||
|
name="enableVideoEdit"
|
||||||
|
label="一键成片"
|
||||||
|
options={[
|
||||||
|
{ label: '否', value: 0 },
|
||||||
|
{ label: '是', value: 1 },
|
||||||
|
]}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="isTest"
|
||||||
|
label="测试二维码"
|
||||||
|
options={[
|
||||||
|
{ label: '否', value: 0 },
|
||||||
|
{ label: '是', value: 1 },
|
||||||
|
]}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="qrcodeType"
|
||||||
|
label="二维码类型"
|
||||||
|
options={[
|
||||||
|
{ label: '游客扫码', value: 1 },
|
||||||
|
{ label: '临时扫码', value: 2 },
|
||||||
|
{ label: '自定义', value: 3 },
|
||||||
|
]}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="showVideoEditOnly"
|
||||||
|
label="仅显示一键成片"
|
||||||
|
options={[
|
||||||
|
{ label: '否', value: 0 },
|
||||||
|
{ label: '是', value: 1 },
|
||||||
|
]}
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 统计 */}
|
||||||
|
<ProFormDigit name="vlogCount" label="Vlog数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||||
|
<ProFormDigit name="videoCount" label="视频数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||||
|
<ProFormDigit name="photoCount" label="图片数量" min={0} fieldProps={{ precision: 0 }} colProps={{ span: 12 }} />
|
||||||
|
|
||||||
|
<ProFormDigit
|
||||||
|
name="materialCount"
|
||||||
|
label="素材数量"
|
||||||
|
min={1}
|
||||||
|
rules={[{ required: true, message: '请输入素材数量' }]}
|
||||||
|
fieldProps={{ precision: 0 }}
|
||||||
|
placeholder="请输入素材数量"
|
||||||
|
colProps={{ span: 12 }}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* 注册一个隐藏字段以提交素材ID数组 */}
|
||||||
|
<ProForm.Item name="tourismFileIds" hidden>
|
||||||
|
<div />
|
||||||
|
</ProForm.Item>
|
||||||
|
|
||||||
|
{/* 景区素材(移除查询条件;支持多选;无上限;保留“全部选择/取消选择”) */}
|
||||||
|
<ProForm.Item label="景区素材" shouldUpdate>
|
||||||
|
{({ getFieldValue, setFieldsValue }) => {
|
||||||
|
const selected: number[] = getFieldValue('tourismFileIds') || [];
|
||||||
|
if (!tourismIdForFetch) {
|
||||||
|
return <div style={{ color: '#999' }}>请选择景区后加载素材</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 不再提供筛选与上限;全量展示可选择
|
||||||
|
const list = tourismFiles || [];
|
||||||
|
|
||||||
|
const onToggle = (id: number) => {
|
||||||
|
const exists = selected.includes(id);
|
||||||
|
setFieldsValue?.({ tourismFileIds: exists ? selected.filter((x) => x !== id) : [...selected, id] });
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectAll = () => {
|
||||||
|
const ids = (list.map((f: any) => f?.id).filter(Boolean) as number[]);
|
||||||
|
const next = Array.from(new Set(ids));
|
||||||
|
setFieldsValue?.({ tourismFileIds: next });
|
||||||
|
};
|
||||||
|
|
||||||
|
const clearAll = () => setFieldsValue?.({ tourismFileIds: [] });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{/* 操作:全部选择 / 取消选择(左对齐,与“景区素材”同起点) */}
|
||||||
|
<div style={{ display: 'flex', gap: 12, alignItems: 'center', marginBottom: 8 }}>
|
||||||
|
<button type="button" onClick={selectAll} style={{ padding: '4px 10px', border: '1px solid #52c41a', background: '#52c41a', color: '#fff', borderRadius: 4, cursor: 'pointer' }}>全部选择</button>
|
||||||
|
<button type="button" onClick={clearAll} style={{ padding: '4px 10px', border: '1px solid #52c41a', background: '#fff', color: '#52c41a', borderRadius: 4, cursor: 'pointer' }}>取消选择</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 统计信息 */}
|
||||||
|
<div style={{ marginBottom: 8, fontSize: 12, color: '#666' }}>
|
||||||
|
已选{selected.length} 个;共{list.length} 个
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* 网格容器:自适应列 + 滚动 */}
|
||||||
|
<div style={{ maxHeight: 420, overflow: 'auto', padding: 8, background: '#fafafa', border: '1px solid #f0f0f0', borderRadius: 6 }}>
|
||||||
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(140px, 1fr))', gap: 12 }}>
|
||||||
|
{list.map((f: any) => {
|
||||||
|
const id = f?.id;
|
||||||
|
const url = f?.imageUrl || f?.linkUrl || f?.url;
|
||||||
|
const isSel = selected.includes(id);
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={id}
|
||||||
|
onClick={() => onToggle(id)}
|
||||||
|
style={{
|
||||||
|
borderWidth: 2,
|
||||||
|
borderStyle: 'solid',
|
||||||
|
borderColor: isSel ? '#52c41a' : '#f0f0f0',
|
||||||
|
borderRadius: 6,
|
||||||
|
cursor: 'pointer',
|
||||||
|
background: '#fff',
|
||||||
|
boxShadow: isSel ? '0 0 0 2px rgba(82,196,26,0.12) inset' : 'none',
|
||||||
|
overflow: 'hidden',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div style={{ position: 'relative', width: '100%', aspectRatio: '4 / 3', background: '#fafafa', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||||
|
{url ? (
|
||||||
|
<img src={url} alt={'素材-' + id} style={{ width: '100%', height: '100%', objectFit: 'cover' }} />
|
||||||
|
) : (
|
||||||
|
<div style={{ fontSize: 12, color: '#999' }}>无图片</div>
|
||||||
|
)}
|
||||||
|
{isSel ? (
|
||||||
|
<div style={{ position: 'absolute', top: 6, right: 6, width: 18, height: 18, borderRadius: '50%', background: '#52c41a' }} />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div style={{ padding: '6px 8px', fontSize: 12, color: '#555', display: 'flex', justifyContent: 'space-between' }}>
|
||||||
|
<span>ID:{id}</span>
|
||||||
|
<span style={{ color: '#888' }}>{typeName(f?.type)}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
</ProForm.Item>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default QrcodeTourismForm;
|
||||||
|
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import { PageContainer, ProFormText, ProTable } from '@ant-design/pro-components';
|
import { PageContainer, ProFormText, ProTable, type ActionType } from '@ant-design/pro-components';
|
||||||
import { Popconfirm, Space, Tag, message } from 'antd';
|
import { Popconfirm, Space, Tag, message } from 'antd';
|
||||||
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
import { ActionBar, GlassCard, GradientButton, SearchBarPlus } from '@/components/ui';
|
||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import { ordersApi } from '@/services/orders';
|
import { ordersApi } from '@/services/orders';
|
||||||
import TourismForm, { TourismItem } from './components/TourismForm';
|
import TourismForm, { TourismItem } from './components/TourismForm';
|
||||||
|
import QrcodeListModal from './components/QrcodeListModal';
|
||||||
import { tenantApi } from '@/services/tenant';
|
import { tenantApi } from '@/services/tenant';
|
||||||
|
|
||||||
const TourismPage: React.FC = () => {
|
const TourismPage: React.FC = () => {
|
||||||
@@ -12,6 +13,9 @@ const TourismPage: React.FC = () => {
|
|||||||
const [editOpen, setEditOpen] = useState(false);
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
const [current, setCurrent] = useState<TourismItem | undefined>(undefined);
|
const [current, setCurrent] = useState<TourismItem | undefined>(undefined);
|
||||||
const [params, setParams] = useState<Record<string, any>>({});
|
const [params, setParams] = useState<Record<string, any>>({});
|
||||||
|
const [qrcodeOpen, setQrcodeOpen] = useState(false);
|
||||||
|
const [qrcodeTourism, setQrcodeTourism] = useState<TourismItem | undefined>(undefined);
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
|
||||||
// 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据
|
// 首次进入时,默认按“当前租户 + 包含下级租户”查询,避免全量数据
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -33,7 +37,7 @@ const TourismPage: React.FC = () => {
|
|||||||
|
|
||||||
const columns: any[] = [
|
const columns: any[] = [
|
||||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
||||||
{ title: '旅游项目', dataIndex: 'tourismName' },
|
{ title: '景区名称', dataIndex: 'tourismName' },
|
||||||
{ title: '地址', dataIndex: 'tourismAddress' },
|
{ title: '地址', dataIndex: 'tourismAddress' },
|
||||||
{ title: '经度', dataIndex: 'longitude' },
|
{ title: '经度', dataIndex: 'longitude' },
|
||||||
{ title: '纬度', dataIndex: 'latitude' },
|
{ title: '纬度', dataIndex: 'latitude' },
|
||||||
@@ -54,6 +58,7 @@ const TourismPage: React.FC = () => {
|
|||||||
key: 'action',
|
key: 'action',
|
||||||
render: (_: any, record: TourismItem) => (
|
render: (_: any, record: TourismItem) => (
|
||||||
<Space>
|
<Space>
|
||||||
|
<a onClick={() => { setQrcodeTourism(record); setQrcodeOpen(true); }}>二维码</a>
|
||||||
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
<a onClick={() => { setCurrent(record); setEditOpen(true); }}>编辑</a>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={`确认删除项目[${record.tourismName}]?`}
|
title={`确认删除项目[${record.tourismName}]?`}
|
||||||
@@ -62,6 +67,7 @@ const TourismPage: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await ordersApi.deleteTourism(record.id!);
|
await ordersApi.deleteTourism(record.id!);
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
|
actionRef.current?.reload();
|
||||||
} catch {
|
} catch {
|
||||||
message.error('删除失败');
|
message.error('删除失败');
|
||||||
} finally { hide(); }
|
} finally { hide(); }
|
||||||
@@ -75,15 +81,22 @@ const TourismPage: React.FC = () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer header={{ title: '旅游项目' }}>
|
<PageContainer header={{ title: '景区列表' }}>
|
||||||
<SearchBarPlus
|
<SearchBarPlus
|
||||||
defaultCollapsed
|
defaultCollapsed
|
||||||
split
|
split
|
||||||
span={8}
|
span={8}
|
||||||
|
hideReset
|
||||||
onTenantChanged={(tenantId, includeChildren) => {
|
onTenantChanged={(tenantId, includeChildren) => {
|
||||||
setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren }));
|
setParams((prev) => ({ ...(prev || {}), tenantId, includeChildren }));
|
||||||
|
// 强制刷新表格
|
||||||
|
actionRef.current?.reload();
|
||||||
|
}}
|
||||||
|
onFinish={async (values) => {
|
||||||
|
setParams((prev) => ({ ...(prev || {}), ...values }));
|
||||||
|
// 即使查询条件未变化也再次请求
|
||||||
|
actionRef.current?.reload();
|
||||||
}}
|
}}
|
||||||
onFinish={async (values) => setParams((prev) => ({ ...(prev || {}), ...values }))}
|
|
||||||
>
|
>
|
||||||
<ProFormText name="tourismName" label="景区名称" placeholder="请输入景区名称" />
|
<ProFormText name="tourismName" label="景区名称" placeholder="请输入景区名称" />
|
||||||
</SearchBarPlus>
|
</SearchBarPlus>
|
||||||
@@ -100,6 +113,7 @@ const TourismPage: React.FC = () => {
|
|||||||
{params?.tenantId ? (
|
{params?.tenantId ? (
|
||||||
<ProTable<TourismItem>
|
<ProTable<TourismItem>
|
||||||
rowKey="id"
|
rowKey="id"
|
||||||
|
actionRef={actionRef}
|
||||||
params={params}
|
params={params}
|
||||||
request={(p) => ordersApi.tourism({ ...(p as any), ...params })}
|
request={(p) => ordersApi.tourism({ ...(p as any), ...params })}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -119,6 +133,8 @@ const TourismPage: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await ordersApi.saveOrUpdateTourism(values);
|
await ordersApi.saveOrUpdateTourism(values);
|
||||||
message.success('新增成功');
|
message.success('新增成功');
|
||||||
|
// 新增成功后刷新表格
|
||||||
|
actionRef.current?.reload();
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
message.error('新增失败');
|
message.error('新增失败');
|
||||||
@@ -137,6 +153,7 @@ const TourismPage: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
await ordersApi.saveOrUpdateTourism({ ...(current as any), ...values });
|
await ordersApi.saveOrUpdateTourism({ ...(current as any), ...values });
|
||||||
message.success('修改成功');
|
message.success('修改成功');
|
||||||
|
actionRef.current?.reload();
|
||||||
return true;
|
return true;
|
||||||
} catch {
|
} catch {
|
||||||
message.error('修改失败');
|
message.error('修改失败');
|
||||||
@@ -144,8 +161,18 @@ const TourismPage: React.FC = () => {
|
|||||||
} finally { hide(); }
|
} finally { hide(); }
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{qrcodeOpen && qrcodeTourism?.id ? (
|
||||||
|
<QrcodeListModal
|
||||||
|
open={qrcodeOpen}
|
||||||
|
onOpenChange={setQrcodeOpen}
|
||||||
|
tourismId={qrcodeTourism.id as number}
|
||||||
|
tourismName={qrcodeTourism.tourismName}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TourismPage;
|
export default TourismPage;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,151 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { ModalForm, ProForm, ProFormSelect, ProFormText } from '@ant-design/pro-components';
|
||||||
|
import { Button, Image, Upload, message, Row, Col } from 'antd';
|
||||||
|
import { UploadOutlined } from '@ant-design/icons';
|
||||||
|
|
||||||
|
export interface TourismFileItem {
|
||||||
|
id?: number;
|
||||||
|
tourismId?: number;
|
||||||
|
type?: number;
|
||||||
|
status?: number; // 0 启用,1 禁用
|
||||||
|
imageUrl?: string; // 保存时使用后端返回的 path
|
||||||
|
linkUrl?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TourismFileFormProps {
|
||||||
|
open: boolean;
|
||||||
|
title: string;
|
||||||
|
initialValues?: Partial<TourismFileItem>;
|
||||||
|
onOpenChange: (v: boolean) => void;
|
||||||
|
onFinish: (values: TourismFileItem) => Promise<boolean>;
|
||||||
|
tourismOptions: Array<{ label: string; value: number }>; // 项目下拉
|
||||||
|
}
|
||||||
|
|
||||||
|
const TYPE_OPTIONS = [
|
||||||
|
{ label: '视频', value: 5 },
|
||||||
|
{ label: '首页 Banner', value: 6 },
|
||||||
|
{ label: '展示图片', value: 4 },
|
||||||
|
{ label: '景区详情', value: 3 },
|
||||||
|
{ label: '景区小图展示', value: 2 },
|
||||||
|
{ label: '活动', value: 1 },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const STATUS_OPTIONS = [
|
||||||
|
{ label: '启用', value: 0 },
|
||||||
|
{ label: '禁用', value: 1 },
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
const TourismFileForm: React.FC<TourismFileFormProps> = ({ open, title, initialValues, onOpenChange, onFinish, tourismOptions }) => {
|
||||||
|
const [uploadPreviewUrl, setUploadPreviewUrl] = useState<string | undefined>();
|
||||||
|
const [uploadPath, setUploadPath] = useState<string | undefined>();
|
||||||
|
|
||||||
|
const doUpload = async (file: File) => {
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append('file', file);
|
||||||
|
const token = (typeof window !== 'undefined') ? sessionStorage.getItem('access_token') : undefined;
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
if (token) headers['Authorization'] = 'Bearer ' +token;
|
||||||
|
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData, headers });
|
||||||
|
const data = await resp.json();
|
||||||
|
if (!data || (!data.url && !data.path)) throw new Error('上传失败');
|
||||||
|
return data as { url: string; path: string };
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ModalForm<TourismFileItem>
|
||||||
|
title={title}
|
||||||
|
visible={open}
|
||||||
|
labelCol={{ span: 8 }}
|
||||||
|
wrapperCol={{ span: 16 }}
|
||||||
|
onVisibleChange={(v) => {
|
||||||
|
if (!v) {
|
||||||
|
setUploadPreviewUrl(undefined);
|
||||||
|
setUploadPath(undefined);
|
||||||
|
}
|
||||||
|
onOpenChange(v);
|
||||||
|
}}
|
||||||
|
onFinish={async (values) => {
|
||||||
|
const payload: TourismFileItem = { ...(initialValues || {}), ...values } as any;
|
||||||
|
if (uploadPath) payload.imageUrl = uploadPath;
|
||||||
|
if (!payload.imageUrl) {
|
||||||
|
message.warning('请先上传资源');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return onFinish(payload);
|
||||||
|
}}
|
||||||
|
initialValues={initialValues}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
>
|
||||||
|
<Row gutter={16}>
|
||||||
|
<Col span={12}>
|
||||||
|
<ProFormSelect
|
||||||
|
rules={[{ required: true, message: '请选择项目' }]}
|
||||||
|
name="tourismId"
|
||||||
|
label="项目"
|
||||||
|
options={tourismOptions}
|
||||||
|
showSearch
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
<Col span={12}>
|
||||||
|
<ProFormSelect
|
||||||
|
rules={[{ required: true, message: '请选择资源类型' }]}
|
||||||
|
name="type"
|
||||||
|
label="资源类型"
|
||||||
|
options={TYPE_OPTIONS as any}
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
<Col span={12}>
|
||||||
|
<ProFormSelect name="status" label="状态" options={STATUS_OPTIONS as any} initialValue={0} />
|
||||||
|
</Col>
|
||||||
|
<Col span={12}>
|
||||||
|
<ProFormText name="linkUrl" label="页面链接" placeholder="可为空" />
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
<Col span={24}>
|
||||||
|
<ProFormText
|
||||||
|
rules={[{ required: true, message: '请输入资源描述' }]}
|
||||||
|
name="description"
|
||||||
|
label="资源描述"
|
||||||
|
placeholder="请输入资源描述"
|
||||||
|
/>
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
<Col span={24}>
|
||||||
|
<ProForm.Item label="资源文件">
|
||||||
|
<Upload
|
||||||
|
maxCount={1}
|
||||||
|
showUploadList={false}
|
||||||
|
customRequest={async ({ file, onSuccess, onError }) => {
|
||||||
|
try {
|
||||||
|
if (file instanceof File) {
|
||||||
|
const r = await doUpload(file as File);
|
||||||
|
setUploadPreviewUrl(r.url);
|
||||||
|
setUploadPath(r.path);
|
||||||
|
onSuccess?.('ok');
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
onError?.(err as any);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
accept="image/*,video/*"
|
||||||
|
>
|
||||||
|
<Button icon={<UploadOutlined />}>上传图片/视频</Button>
|
||||||
|
</Upload>
|
||||||
|
</ProForm.Item>
|
||||||
|
</Col>
|
||||||
|
|
||||||
|
{(uploadPreviewUrl || initialValues?.imageUrl) && (
|
||||||
|
<Col span={24}>
|
||||||
|
<div style={{ marginTop: 12 }}>
|
||||||
|
<Image src={uploadPreviewUrl || initialValues?.imageUrl} width={200} />
|
||||||
|
</div>
|
||||||
|
</Col>
|
||||||
|
)}
|
||||||
|
</Row>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TourismFileForm;
|
||||||
@@ -1,24 +1,18 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useEffect, useRef, useState } from 'react';
|
||||||
import type { ActionType } from '@ant-design/pro-components';
|
|
||||||
import { ActionBar, GlassCard, SearchBarPlus } from '@/components/ui';
|
import { ActionBar, GlassCard, SearchBarPlus } from '@/components/ui';
|
||||||
import {
|
import { PageContainer, ProFormSelect } from '@ant-design/pro-components';
|
||||||
ModalForm,
|
import { Button, Image, Popconfirm, Space, Tag, message, Pagination } from 'antd';
|
||||||
PageContainer,
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
ProForm,
|
|
||||||
ProFormSelect,
|
|
||||||
ProFormText,
|
|
||||||
ProTable,
|
|
||||||
} from '@ant-design/pro-components';
|
|
||||||
import { Button, Image, Popconfirm, Space, Tag, Upload, message, Form } from 'antd';
|
|
||||||
import { PlusOutlined, UploadOutlined } from '@ant-design/icons';
|
|
||||||
import { ordersApi } from '@/services/orders';
|
import { ordersApi } from '@/services/orders';
|
||||||
|
import TourismFileForm, { TourismFileItem } from './components/TourismFileForm';
|
||||||
|
|
||||||
|
// 资源类型枚举(用于卡片展示的颜色)
|
||||||
const TYPE_OPTIONS = [
|
const TYPE_OPTIONS = [
|
||||||
{ label: '视频', value: 5, color: '#f5222d' },
|
{ label: '视频', value: 5, color: '#f5222d' },
|
||||||
{ label: '首页 Banner', value: 6, color: '#2f54eb' },
|
{ label: '首页 Banner', value: 6, color: '#2f54eb' },
|
||||||
{ label: '展示封面', value: 4, color: '#52c41a' },
|
{ label: '展示图片', value: 4, color: '#52c41a' },
|
||||||
{ label: '入口引导', value: 3, color: '#722ed1' },
|
{ label: '景区详情', value: 3, color: '#722ed1' },
|
||||||
{ label: '服务小结展示', value: 2, color: '#13c2c2' },
|
{ label: '景区小图展示', value: 2, color: '#13c2c2' },
|
||||||
{ label: '活动', value: 1, color: '#1890ff' },
|
{ label: '活动', value: 1, color: '#1890ff' },
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
@@ -28,218 +22,197 @@ const STATUS_OPTIONS = [
|
|||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
const TourismFilePage: React.FC = () => {
|
const TourismFilePage: React.FC = () => {
|
||||||
const actionRef = useRef<ActionType>();
|
|
||||||
const [query, setQuery] = useState<Record<string, any>>({});
|
const [query, setQuery] = useState<Record<string, any>>({});
|
||||||
const [tourismOptions, setTourismOptions] = useState<Array<{ label: string; value: number }>>([]);
|
const [tourismOptions, setTourismOptions] = useState<Array<{ label: string; value: number }>>([]);
|
||||||
|
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [editOpen, setEditOpen] = useState(false);
|
const [editOpen, setEditOpen] = useState(false);
|
||||||
const [current, setCurrent] = useState<any>();
|
const [current, setCurrent] = useState<any>();
|
||||||
const [uploadPreviewUrl, setUploadPreviewUrl] = useState<string | undefined>();
|
|
||||||
const [uploadPath, setUploadPath] = useState<string | undefined>();
|
|
||||||
const [editUploadPreviewUrl, setEditUploadPreviewUrl] = useState<string | undefined>();
|
|
||||||
const [editUploadPath, setEditUploadPath] = useState<string | undefined>();
|
|
||||||
|
|
||||||
|
// 分组数据(按项目分组)与分页
|
||||||
|
const [groups, setGroups] = useState<Array<{ tourismId: number; tourismName?: string; files: any[] }>>([]);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const fetchingRef = useRef(false);
|
||||||
|
const [pagination, setPagination] = useState<{ current: number; pageSize: number; total: number }>({ current: 1, pageSize: 10, total: 0 });
|
||||||
|
|
||||||
|
// 加载可选项目列表(用于筛选与表单下拉)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await ordersApi.tourism({ page: 1, limit: 1000 });
|
const res = await ordersApi.tourism({ page: 1, limit: 1000, tenantId: query?.tenantId, includeChildren: query?.includeChildren });
|
||||||
const list: Array<{ id: number; tourismName: string }> = (res as any).data || res?.data || [];
|
const list: Array<{ id: number; tourismName: string }> = (res as any)?.data || [];
|
||||||
setTourismOptions(list.map((it) => ({ label: (it as any).tourismName, value: (it as any).id })));
|
setTourismOptions(list.map((it: any) => ({ label: it.tourismName, value: it.id })));
|
||||||
} catch (e) {
|
} catch {}
|
||||||
// 忽略错误以不影响页面
|
|
||||||
}
|
|
||||||
})();
|
})();
|
||||||
}, []);
|
// 租户切换时刷新
|
||||||
|
}, [query?.tenantId, query?.includeChildren]);
|
||||||
|
|
||||||
const columns: any[] = [
|
// 加载查询结果(含分页)
|
||||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 48 },
|
const loadGroups = async (extra?: Record<string, any>) => {
|
||||||
{
|
const params = { ...(query || {}), ...(extra || {}), current: pagination.current, pageSize: pagination.pageSize };
|
||||||
title: '旅游项目',
|
if (fetchingRef.current) return; // 防抖去重
|
||||||
dataIndex: 'tourismId',
|
fetchingRef.current = true;
|
||||||
render: (_: any, record: any) => tourismOptions.find((o) => o.value === record.tourismId)?.label || record.tourismName || '-',
|
setLoading(true);
|
||||||
},
|
try {
|
||||||
{
|
const res = await ordersApi.tourismFilesGroupedByTenant(params as any);
|
||||||
title: '图片/预览',
|
setGroups(Array.isArray((res as any)?.data) ? (res as any).data : []);
|
||||||
dataIndex: 'imageUrl',
|
setPagination((p) => ({ ...p, total: Number((res as any)?.total || 0) }));
|
||||||
search: false,
|
} catch (e) {
|
||||||
width: 140,
|
setGroups([]);
|
||||||
render: (_: any, record: any) =>
|
setPagination((p) => ({ ...p, total: 0 }));
|
||||||
record.type === 5 ? (
|
} finally {
|
||||||
<video src={record.imageUrl} controls style={{ width: 120, height: 80, objectFit: 'cover' }} />
|
fetchingRef.current = false;
|
||||||
) : (
|
setLoading(false);
|
||||||
<Image src={record.imageUrl} width={120} height={80} style={{ objectFit: 'cover' }} />
|
}
|
||||||
),
|
|
||||||
},
|
|
||||||
{ title: '页面链接', dataIndex: 'linkUrl', ellipsis: true, copyable: true },
|
|
||||||
{ title: '描述', dataIndex: 'description', ellipsis: true },
|
|
||||||
{
|
|
||||||
title: '状态',
|
|
||||||
dataIndex: 'status',
|
|
||||||
width: 90,
|
|
||||||
render: (v: number) => <Tag color={v === 0 ? 'green' : 'default'}>{v === 0 ? '启用' : '禁用'}</Tag>,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '类型',
|
|
||||||
dataIndex: 'type',
|
|
||||||
width: 120,
|
|
||||||
render: (v: number) => {
|
|
||||||
const t = TYPE_OPTIONS.find((i) => i.value === Number(v));
|
|
||||||
return t ? <Tag color={t.color}>{t.label}</Tag> : '-';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', width: 180 },
|
|
||||||
{
|
|
||||||
title: '操作',
|
|
||||||
key: 'action',
|
|
||||||
width: 160,
|
|
||||||
render: (_: any, record: any) => (
|
|
||||||
<Space>
|
|
||||||
<a
|
|
||||||
onClick={() => {
|
|
||||||
setCurrent(record);
|
|
||||||
setEditOpen(true);
|
|
||||||
setEditUploadPreviewUrl(undefined);
|
|
||||||
setEditUploadPath(undefined);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
编辑
|
|
||||||
</a>
|
|
||||||
<Popconfirm
|
|
||||||
title={`确认删除资源[${record.id}]?`}
|
|
||||||
onConfirm={async () => {
|
|
||||||
const hide = message.loading('正在删除...');
|
|
||||||
try {
|
|
||||||
await ordersApi.deleteTourismFile(record.id);
|
|
||||||
message.success('删除成功');
|
|
||||||
actionRef.current?.reload();
|
|
||||||
} catch (e) {
|
|
||||||
message.error('删除失败');
|
|
||||||
} finally {
|
|
||||||
hide();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<a style={{ color: '#1677ff' }}>删除</a>
|
|
||||||
</Popconfirm>
|
|
||||||
</Space>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const doUpload = async (file: File) => {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('file', file);
|
|
||||||
const resp = await fetch('/api-file/files-anon', { method: 'POST', body: formData });
|
|
||||||
const data = await resp.json();
|
|
||||||
if (!data || (!data.url && !data.path)) throw new Error('上传失败');
|
|
||||||
return data as { url: string; path: string };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 首次与查询/分页变化时刷新
|
||||||
|
useEffect(() => {
|
||||||
|
loadGroups();
|
||||||
|
}, [query, pagination.current, pagination.pageSize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer header={{ title: '旅游资源管理' }}>
|
<PageContainer header={{ title: '景区素材管理' }}>
|
||||||
<SearchBarPlus defaultCollapsed split span={8} onTenantChanged={() => actionRef.current?.reload()} onFinish={async (values) => setQuery(values)}>
|
<SearchBarPlus
|
||||||
<ProFormText name="description" label="资源描述" placeholder="请输入关键字" />
|
defaultCollapsed
|
||||||
<ProFormSelect name="tourismId" label="项目" placeholder="请选择" options={tourismOptions} showSearch />
|
split
|
||||||
<ProFormSelect name="type" label="资源类型" placeholder="请选择" options={TYPE_OPTIONS as any} />
|
span={8 as any}
|
||||||
|
hideReset
|
||||||
|
onFinish={async (values) => {
|
||||||
|
// 查询提交后重置到第1页
|
||||||
|
setPagination((p) => ({ ...p, current: 1 }));
|
||||||
|
setQuery(values);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<ProFormSelect name="status" label="状态" placeholder="请选择" options={STATUS_OPTIONS as any} />
|
||||||
</SearchBarPlus>
|
</SearchBarPlus>
|
||||||
|
|
||||||
<ActionBar left={<Button size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</Button>} />
|
<ActionBar left={<Button size="middle" type="primary" icon={<PlusOutlined />} onClick={() => setCreateOpen(true)}>新增</Button>} />
|
||||||
|
|
||||||
<GlassCard>
|
<GlassCard>
|
||||||
<ProTable<any>
|
{loading ? (
|
||||||
rowKey="id"
|
<div style={{ padding: 24 }}>加载中...</div>
|
||||||
headerTitle="资源列表"
|
) : (
|
||||||
actionRef={actionRef}
|
<div>
|
||||||
request={(p) => ordersApi.tourismFile({ ...p, ...query })}
|
{groups && groups.length ? (
|
||||||
columns={columns}
|
groups.map((g) => (
|
||||||
search={false}
|
<div key={g.tourismId} style={{ marginBottom: 24 }}>
|
||||||
pagination={{ showSizeChanger: true, showQuickJumper: true, defaultPageSize: 10 }}
|
<h3 style={{ marginBottom: 12 }}>{g.tourismName || `项目#${g.tourismId}`}</h3>
|
||||||
/>
|
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, minmax(320px, 1fr))', gap: 16 }}>
|
||||||
|
{(g.files || []).map((record: any) => (
|
||||||
|
<div key={record.id} style={{ border: '1px solid #f0f0f0', borderRadius: 8, padding: 12 }}>
|
||||||
|
<div style={{ marginBottom: 8 }}>
|
||||||
|
{Number(record.type) === 5 ? (
|
||||||
|
<video src={record.imageUrl} controls style={{ width: '100%', height: 180, objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
) : (
|
||||||
|
<Image src={record.imageUrl} width={'100%'} height={180} style={{ objectFit: 'cover', borderRadius: 4 }} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 8 }}>
|
||||||
|
<Tag color={Number(record.status) === 0 ? 'green' : 'default'}>{Number(record.status) === 0 ? '启用' : '禁用'}</Tag>
|
||||||
|
<Tag color={(TYPE_OPTIONS.find((i) => i.value === Number(record.type)) || ({} as any)).color || 'default'}>
|
||||||
|
{(TYPE_OPTIONS.find((i) => i.value === Number(record.type)) || ({} as any)).label || '未知类型'}
|
||||||
|
</Tag>
|
||||||
|
</div>
|
||||||
|
<div style={{ fontSize: 12, color: '#666', marginBottom: 8 }}>{record.description || '-'}</div>
|
||||||
|
{record.linkUrl ? (
|
||||||
|
<div style={{ fontSize: 12, color: '#999' }}>
|
||||||
|
链接:
|
||||||
|
<a href={record.linkUrl} target="_blank" rel="noreferrer">
|
||||||
|
{record.linkUrl}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div style={{ marginTop: 8 }}>
|
||||||
|
<Space>
|
||||||
|
<a
|
||||||
|
style={{ color: '#1677ff' }}
|
||||||
|
onClick={() => {
|
||||||
|
setCurrent(record);
|
||||||
|
setEditOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
编辑
|
||||||
|
</a>
|
||||||
|
<Popconfirm
|
||||||
|
title={`确认删除资源[${record.id}]?`}
|
||||||
|
onConfirm={async () => {
|
||||||
|
const hide = message.loading('正在删除...');
|
||||||
|
try {
|
||||||
|
await ordersApi.deleteTourismFile(record.id);
|
||||||
|
message.success('删除成功');
|
||||||
|
loadGroups();
|
||||||
|
} catch (e) {
|
||||||
|
message.error('删除失败');
|
||||||
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<a style={{ color: '#ff4d4f' }}>删除</a>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
<div style={{ padding: 24, color: '#999' }}>暂无数据</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* 分页 */}
|
||||||
|
<div style={{ marginTop: 16, textAlign: 'right' }}>
|
||||||
|
<span style={{ marginRight: 12, color: '#999' }}>共 {pagination.total} 条</span>
|
||||||
|
<Pagination
|
||||||
|
current={pagination.current}
|
||||||
|
pageSize={pagination.pageSize}
|
||||||
|
total={pagination.total}
|
||||||
|
showSizeChanger
|
||||||
|
showQuickJumper
|
||||||
|
onChange={(cur, size) => {
|
||||||
|
setPagination({ current: cur, pageSize: (size as number) || pagination.pageSize, total: pagination.total });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</GlassCard>
|
</GlassCard>
|
||||||
|
|
||||||
{/* 新建 */}
|
<TourismFileForm
|
||||||
<ModalForm
|
|
||||||
title="新增资源"
|
title="新增资源"
|
||||||
open={createOpen}
|
open={createOpen}
|
||||||
onOpenChange={(v: boolean) => {
|
tourismOptions={tourismOptions}
|
||||||
if (!v) {
|
onOpenChange={setCreateOpen}
|
||||||
setUploadPreviewUrl(undefined);
|
onFinish={async (values: TourismFileItem) => {
|
||||||
setUploadPath(undefined);
|
|
||||||
}
|
|
||||||
setCreateOpen(v);
|
|
||||||
}}
|
|
||||||
onFinish={async (values) => {
|
|
||||||
if (!uploadPath) {
|
|
||||||
message.warning('请先上传资源');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const hide = message.loading('保存中...');
|
const hide = message.loading('保存中...');
|
||||||
try {
|
try {
|
||||||
await ordersApi.saveOrUpdateTourismFile({ ...values, imageUrl: uploadPath, status: values.status ?? 0 });
|
await ordersApi.saveOrUpdateTourismFile({ ...values, status: values.status ?? 0 });
|
||||||
message.success('新增成功');
|
message.success('新增成功');
|
||||||
actionRef.current?.reload();
|
loadGroups();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error('保存失败');
|
message.error('新增失败');
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
} finally {
|
||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<ProForm.Group>
|
|
||||||
<ProFormSelect rules={[{ required: true, message: '请选择项目' }]} width="md" name="tourismId" label="项目" options={tourismOptions} showSearch />
|
|
||||||
<ProFormSelect rules={[{ required: true, message: '请选择资源类型' }]} width="md" name="type" label="资源类型" options={TYPE_OPTIONS as any} />
|
|
||||||
<ProFormSelect width="md" name="status" label="状态" options={STATUS_OPTIONS as any} initialValue={0} />
|
|
||||||
<ProFormText width="md" name="linkUrl" label="页面链接" placeholder="可为空" />
|
|
||||||
<ProFormText rules={[{ required: true, message: '请输入资源描述' }]} width="md" name="description" label="资源描述" placeholder="请输入资源描述" />
|
|
||||||
</ProForm.Group>
|
|
||||||
<Upload
|
|
||||||
maxCount={1}
|
|
||||||
showUploadList={false}
|
|
||||||
customRequest={async ({ file, onSuccess, onError }) => {
|
|
||||||
try {
|
|
||||||
if (file instanceof File) {
|
|
||||||
const r = await doUpload(file as File);
|
|
||||||
setUploadPreviewUrl(r.url);
|
|
||||||
setUploadPath(r.path);
|
|
||||||
onSuccess?.('ok');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
onError?.(err as any);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
accept="image/*,video/*"
|
|
||||||
>
|
|
||||||
<Button icon={<UploadOutlined />}>上传图片/视频</Button>
|
|
||||||
</Upload>
|
|
||||||
{uploadPreviewUrl && (
|
|
||||||
<div style={{ marginTop: 12 }}>
|
|
||||||
{(ProForm as any) && <Image src={uploadPreviewUrl} width={200} />}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ModalForm>
|
|
||||||
|
|
||||||
{/* 编辑 */}
|
<TourismFileForm
|
||||||
<ModalForm
|
|
||||||
title="编辑资源"
|
title="编辑资源"
|
||||||
open={editOpen}
|
open={editOpen}
|
||||||
initialValues={current}
|
initialValues={current}
|
||||||
onOpenChange={(v: boolean) => {
|
tourismOptions={tourismOptions}
|
||||||
if (!v) {
|
onOpenChange={setEditOpen}
|
||||||
setEditUploadPreviewUrl(undefined);
|
onFinish={async (values: TourismFileItem) => {
|
||||||
setEditUploadPath(undefined);
|
|
||||||
}
|
|
||||||
setEditOpen(v);
|
|
||||||
}}
|
|
||||||
onFinish={async (values) => {
|
|
||||||
const payload = { ...(current || {}), ...values } as any;
|
|
||||||
if (editUploadPath) payload.imageUrl = editUploadPath;
|
|
||||||
const hide = message.loading('保存中...');
|
const hide = message.loading('保存中...');
|
||||||
try {
|
try {
|
||||||
await ordersApi.saveOrUpdateTourismFile(payload);
|
await ordersApi.saveOrUpdateTourismFile({ ...(current || {}), ...values });
|
||||||
message.success('修改成功');
|
message.success('修改成功');
|
||||||
actionRef.current?.reload();
|
loadGroups();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error('修改失败');
|
message.error('修改失败');
|
||||||
@@ -248,42 +221,9 @@ const TourismFilePage: React.FC = () => {
|
|||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
<ProForm.Group>
|
|
||||||
<ProFormSelect rules={[{ required: true, message: '请选择项目' }]} width="md" name="tourismId" label="项目" options={tourismOptions} showSearch />
|
|
||||||
<ProFormSelect rules={[{ required: true, message: '请选择资源类型' }]} width="md" name="type" label="资源类型" options={TYPE_OPTIONS as any} />
|
|
||||||
<ProFormSelect width="md" name="status" label="状态" options={STATUS_OPTIONS as any} />
|
|
||||||
<ProFormText width="md" name="linkUrl" label="页面链接" placeholder="可为空" />
|
|
||||||
<ProFormText rules={[{ required: true, message: '请输入资源描述' }]} width="md" name="description" label="资源描述" placeholder="请输入资源描述" />
|
|
||||||
</ProForm.Group>
|
|
||||||
<Upload
|
|
||||||
maxCount={1}
|
|
||||||
showUploadList={false}
|
|
||||||
customRequest={async ({ file, onSuccess, onError }) => {
|
|
||||||
try {
|
|
||||||
if (file instanceof File) {
|
|
||||||
const r = await doUpload(file as File);
|
|
||||||
setEditUploadPreviewUrl(r.url);
|
|
||||||
setEditUploadPath(r.path);
|
|
||||||
onSuccess?.('ok');
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
onError?.(err as any);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
accept="image/*,video/*"
|
|
||||||
>
|
|
||||||
<Button icon={<UploadOutlined />}>上传图片/视频</Button>
|
|
||||||
</Upload>
|
|
||||||
{(editUploadPreviewUrl || current?.imageUrl) && (
|
|
||||||
<div style={{ marginTop: 12 }}>
|
|
||||||
<Image src={editUploadPreviewUrl || current?.imageUrl} width={200} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ModalForm>
|
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default TourismFilePage;
|
export default TourismFilePage;
|
||||||
|
|
||||||
|
|||||||
@@ -1,30 +1,14 @@
|
|||||||
import React, { useEffect, useRef, useState } from 'react';
|
import React, { useRef } from 'react';
|
||||||
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
|
import { PageContainer, ProTable } from '@ant-design/pro-components';
|
||||||
import type { ActionType } from '@ant-design/pro-components';
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
import { Popconfirm, Form, message } from 'antd';
|
import { Popconfirm, message, Button } from 'antd';
|
||||||
import { roleApi } from '@/services/role';
|
|
||||||
import { tokenApi, TokenItem } from '@/services/token';
|
import { tokenApi, TokenItem } from '@/services/token';
|
||||||
import { GlassCard, SearchBarPlus } from '@/components/ui';
|
import { GlassCard } from '@/components/ui';
|
||||||
|
|
||||||
const TokenPage: React.FC = () => {
|
const TokenPage: React.FC = () => {
|
||||||
const [apps, setApps] = useState<any[]>([]);
|
|
||||||
const [params, setParams] = useState<{ tenantId?: string; username?: string }>({});
|
|
||||||
const [form] = Form.useForm();
|
|
||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
|
|
||||||
useEffect(() => {
|
const columns: ProColumns<TokenItem>[] = [
|
||||||
(async () => {
|
|
||||||
const appData = (await roleApi.apps()) || [];
|
|
||||||
setApps(appData);
|
|
||||||
if (appData.length > 0) {
|
|
||||||
const tenantId = appData[0].clientId;
|
|
||||||
setParams({ tenantId });
|
|
||||||
form.setFieldsValue({ tenantId });
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const columns = [
|
|
||||||
{ dataIndex: 'index', valueType: 'indexBorder' },
|
{ dataIndex: 'index', valueType: 'indexBorder' },
|
||||||
{ title: 'Token', dataIndex: 'tokenValue', width: 200 },
|
{ title: 'Token', dataIndex: 'tokenValue', width: 200 },
|
||||||
{ title: '过期时间', dataIndex: 'expiration', valueType: 'dateTime' },
|
{ title: '过期时间', dataIndex: 'expiration', valueType: 'dateTime' },
|
||||||
@@ -33,7 +17,8 @@ const TokenPage: React.FC = () => {
|
|||||||
{ title: '所属应用', dataIndex: 'clientId' },
|
{ title: '所属应用', dataIndex: 'clientId' },
|
||||||
{ title: '账号类型', dataIndex: 'accountType' },
|
{ title: '账号类型', dataIndex: 'accountType' },
|
||||||
{
|
{
|
||||||
title: '操作', key: 'action',
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
render: (_: any, entity: TokenItem) => (
|
render: (_: any, entity: TokenItem) => (
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
title={`确认删除 Token?`}
|
title={`确认删除 Token?`}
|
||||||
@@ -45,40 +30,31 @@ const TokenPage: React.FC = () => {
|
|||||||
actionRef.current?.reload();
|
actionRef.current?.reload();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.error('删除失败');
|
message.error('删除失败');
|
||||||
} finally { hide(); }
|
} finally {
|
||||||
|
hide();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<a>删除</a>
|
<a>删除</a>
|
||||||
</Popconfirm>
|
</Popconfirm>
|
||||||
)
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer header={{ title: 'Token 管理' }}>
|
<PageContainer header={{ title: 'Token 管理' }}>
|
||||||
<SearchBarPlus
|
|
||||||
defaultCollapsed
|
|
||||||
split
|
|
||||||
span={6}
|
|
||||||
onTenantChanged={() => actionRef.current?.reload?.()}
|
|
||||||
onFinish={async (values) => setParams(values)}
|
|
||||||
>
|
|
||||||
<ProFormSelect
|
|
||||||
name="tenantId"
|
|
||||||
label="所属应用"
|
|
||||||
fieldProps={{ allowClear: false }}
|
|
||||||
options={apps.map((item) => ({ label: item.clientId, value: item.clientId }))}
|
|
||||||
/>
|
|
||||||
<ProFormText name="username" label="搜索" placeholder="请输入用户名" />
|
|
||||||
</SearchBarPlus>
|
|
||||||
|
|
||||||
<GlassCard>
|
<GlassCard>
|
||||||
<ProTable<TokenItem>
|
<ProTable<TokenItem>
|
||||||
rowKey="tokenValue"
|
rowKey="tokenValue"
|
||||||
headerTitle="Token 列表"
|
headerTitle="Token 列表"
|
||||||
actionRef={actionRef}
|
actionRef={actionRef}
|
||||||
request={async (p) => tokenApi.page({ ...p, ...params } as any)}
|
request={async (p) => tokenApi.page({ ...p } as any)}
|
||||||
columns={columns as any}
|
columns={columns as any}
|
||||||
|
toolBarRender={() => [
|
||||||
|
<Button key="refresh" type="primary" onClick={() => actionRef.current?.reload?.()}>
|
||||||
|
查询
|
||||||
|
</Button>,
|
||||||
|
]}
|
||||||
search={false}
|
search={false}
|
||||||
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
pagination={{ showSizeChanger: true, showQuickJumper: true }}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ModalForm, ProFormText } from '@ant-design/pro-components';
|
||||||
|
import type { UserItem } from '@/services/system';
|
||||||
|
|
||||||
|
export interface ChangePasswordModalProps {
|
||||||
|
visible: boolean;
|
||||||
|
user?: UserItem;
|
||||||
|
onVisibleChange: (v: boolean) => void;
|
||||||
|
onFinish: (values: { newPassword: string; confirmPassword: string }) => Promise<boolean>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码弹窗(支持管理员为任意用户设置新密码)
|
||||||
|
*/
|
||||||
|
const ChangePasswordModal: React.FC<ChangePasswordModalProps> = ({ visible, user, onVisibleChange, onFinish }) => {
|
||||||
|
return (
|
||||||
|
<ModalForm<{ newPassword: string; confirmPassword: string }>
|
||||||
|
title={`修改密码${user?.username ? ` - ${user.username}` : ''}`}
|
||||||
|
visible={visible}
|
||||||
|
onVisibleChange={onVisibleChange}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
onFinish={onFinish}
|
||||||
|
>
|
||||||
|
<ProFormText
|
||||||
|
name="newPassword"
|
||||||
|
label="新密码"
|
||||||
|
fieldProps={{ type: 'password', autoComplete: 'new-password' }}
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请输入新密码' },
|
||||||
|
{ min: 6, message: '密码长度不能少于6位' },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="confirmPassword"
|
||||||
|
label="确认新密码"
|
||||||
|
fieldProps={{ type: 'password', autoComplete: 'new-password' }}
|
||||||
|
rules={[
|
||||||
|
{ required: true, message: '请再次输入新密码' },
|
||||||
|
({ getFieldValue }) => ({
|
||||||
|
validator(_, value) {
|
||||||
|
if (!value || getFieldValue('newPassword') === value) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error('两次输入的密码不一致'));
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ChangePasswordModal;
|
||||||
|
|
||||||
@@ -11,12 +11,13 @@ export interface UserTableRef {
|
|||||||
export interface UserTableProps {
|
export interface UserTableProps {
|
||||||
onEdit: (record: UserItem) => void;
|
onEdit: (record: UserItem) => void;
|
||||||
onResetPassword: (record: UserItem) => void;
|
onResetPassword: (record: UserItem) => void;
|
||||||
|
onChangePassword: (record: UserItem) => void;
|
||||||
onDelete: (record: UserItem) => void;
|
onDelete: (record: UserItem) => void;
|
||||||
// 额外查询参数(由外部查询条件统一注入)
|
// 额外查询参数(由外部查询条件统一注入)
|
||||||
extraParams?: Record<string, any>;
|
extraParams?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPassword, onDelete, extraParams }, ref) => {
|
const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPassword, onChangePassword, onDelete, extraParams }, ref) => {
|
||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
@@ -35,7 +36,7 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
|
|||||||
{ title: '用户名', dataIndex: 'username' },
|
{ title: '用户名', dataIndex: 'username' },
|
||||||
{ title: '用户昵称', dataIndex: 'nickname' },
|
{ title: '用户昵称', dataIndex: 'nickname' },
|
||||||
{ title: '手机号', dataIndex: 'mobile' },
|
{ title: '手机号', dataIndex: 'mobile' },
|
||||||
{ title: '性别', dataIndex: 'sex', valueType: 'select', valueEnum: { 0: { text: '男' }, 1: { text: '女' } }, width: 80 },
|
{ title: '性别', dataIndex: 'sex', valueType: 'select', valueEnum: { 0: { text: '女' }, 1: { text: '男' } }, width: 80 },
|
||||||
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', search: false },
|
{ title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', search: false },
|
||||||
{
|
{
|
||||||
title: '状态', dataIndex: 'enabled', search: false,
|
title: '状态', dataIndex: 'enabled', search: false,
|
||||||
@@ -44,10 +45,11 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作', valueType: 'option', width: 220,
|
title: '操作', valueType: 'option', width: 280,
|
||||||
render: (_, entity) => (
|
render: (_, entity) => (
|
||||||
<Space>
|
<Space>
|
||||||
<a onClick={() => onEdit(entity)}>编辑</a>
|
<a onClick={() => onEdit(entity)}>编辑</a>
|
||||||
|
<a onClick={() => onChangePassword(entity)}>修改密码</a>
|
||||||
<a onClick={() => onResetPassword(entity)}>重置密码</a>
|
<a onClick={() => onResetPassword(entity)}>重置密码</a>
|
||||||
<Popconfirm title={`确认删除用户[${entity.username}]?`} onConfirm={() => onDelete(entity)}>
|
<Popconfirm title={`确认删除用户[${entity.username}]?`} onConfirm={() => onDelete(entity)}>
|
||||||
<a style={{ color: '#1677ff' }}>删除</a>
|
<a style={{ color: '#1677ff' }}>删除</a>
|
||||||
@@ -71,7 +73,7 @@ const UserTable = forwardRef<UserTableRef, UserTableProps>(({ onEdit, onResetPas
|
|||||||
const { data, total } = await systemApi.users({ ...(safeP as any), ...(safeExtra as any) } as any);
|
const { data, total } = await systemApi.users({ ...(safeP as any), ...(safeExtra as any) } as any);
|
||||||
return { data, total, success: true };
|
return { data, total, success: true };
|
||||||
}}
|
}}
|
||||||
pagination={{ pageSize: 10 }}
|
pagination={{ pageSize: 20 }}
|
||||||
// 统一关闭 ProTable 自带搜索,由 SearchBarPlus 统一驱动
|
// 统一关闭 ProTable 自带搜索,由 SearchBarPlus 统一驱动
|
||||||
search={false}
|
search={false}
|
||||||
toolBarRender={false}
|
toolBarRender={false}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { systemApi, UserItem } from '@/services/system';
|
|||||||
import UserTable, { UserTableRef } from './components/UserTable';
|
import UserTable, { UserTableRef } from './components/UserTable';
|
||||||
import Toolbar from './components/Toolbar';
|
import Toolbar from './components/Toolbar';
|
||||||
import UserForm from './components/UserForm';
|
import UserForm from './components/UserForm';
|
||||||
|
import ChangePasswordModal from './components/ChangePasswordModal';
|
||||||
|
|
||||||
const UsersPage: React.FC = () => {
|
const UsersPage: React.FC = () => {
|
||||||
const tableRef = useRef<UserTableRef>(null);
|
const tableRef = useRef<UserTableRef>(null);
|
||||||
@@ -15,18 +16,27 @@ const UsersPage: React.FC = () => {
|
|||||||
const [createVisible, setCreateVisible] = useState(false);
|
const [createVisible, setCreateVisible] = useState(false);
|
||||||
const [editVisible, setEditVisible] = useState(false);
|
const [editVisible, setEditVisible] = useState(false);
|
||||||
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
|
const [currentRow, setCurrentRow] = useState<UserItem | undefined>(undefined);
|
||||||
|
const [pwdVisible, setPwdVisible] = useState(false);
|
||||||
|
const [pwdUser, setPwdUser] = useState<UserItem | undefined>(undefined);
|
||||||
|
|
||||||
const addUser = async (values: UserItem & { company?: string; type?: string }) => {
|
const addUser = async (values: UserItem & { company?: string; type?: string }) => {
|
||||||
const hide = message.loading('正在添加');
|
const hide = message.loading('正在添加');
|
||||||
try {
|
try {
|
||||||
await systemApi.saveOrUpdateUser({ ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any);
|
const res: any = await systemApi.saveOrUpdateUserRaw({
|
||||||
|
...(values as any),
|
||||||
|
roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId,
|
||||||
|
} as any);
|
||||||
|
const code = res?.resp_code ?? res?.code;
|
||||||
|
if (typeof code === 'number' && code !== 0) {
|
||||||
|
throw new Error(res?.resp_msg || res?.message || '添加用户失败');
|
||||||
|
}
|
||||||
hide();
|
hide();
|
||||||
message.success('添加用户成功');
|
message.success('添加用户成功');
|
||||||
tableRef.current?.reload();
|
tableRef.current?.reload();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
hide();
|
hide();
|
||||||
message.error('添加用户失败');
|
message.error(e?.message || '添加用户失败');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -34,14 +44,22 @@ const UsersPage: React.FC = () => {
|
|||||||
const editUser = async (values: UserItem & { company?: string; type?: string }) => {
|
const editUser = async (values: UserItem & { company?: string; type?: string }) => {
|
||||||
const hide = message.loading('正在更新');
|
const hide = message.loading('正在更新');
|
||||||
try {
|
try {
|
||||||
await systemApi.saveOrUpdateUser({ ...(currentRow as any), ...(values as any), roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId } as any);
|
const res: any = await systemApi.saveOrUpdateUserRaw({
|
||||||
|
...(currentRow as any),
|
||||||
|
...(values as any),
|
||||||
|
roleId: (values as any)?.roleIds ? (values as any).roleIds.join(',') : (values as any)?.roleId,
|
||||||
|
} as any);
|
||||||
|
const code = res?.resp_code ?? res?.code;
|
||||||
|
if (typeof code === 'number' && code !== 0) {
|
||||||
|
throw new Error(res?.resp_msg || res?.message || '修改用户失败');
|
||||||
|
}
|
||||||
hide();
|
hide();
|
||||||
message.success('修改用户成功');
|
message.success('修改用户成功');
|
||||||
tableRef.current?.reload();
|
tableRef.current?.reload();
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e: any) {
|
||||||
hide();
|
hide();
|
||||||
message.error('修改用户失败');
|
message.error(e?.message || '修改用户失败');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -58,6 +76,28 @@ const UsersPage: React.FC = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openChangePwd = (record: UserItem) => {
|
||||||
|
setPwdUser(record);
|
||||||
|
setPwdVisible(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const submitChangePwd = async (values: { newPassword: string; confirmPassword: string }) => {
|
||||||
|
const hide = message.loading('正在修改密码');
|
||||||
|
try {
|
||||||
|
await systemApi.changePassword(pwdUser!.id!, values.newPassword);
|
||||||
|
hide();
|
||||||
|
message.success('修改密码成功');
|
||||||
|
setPwdVisible(false);
|
||||||
|
setPwdUser(undefined);
|
||||||
|
tableRef.current?.reload();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
hide();
|
||||||
|
message.error('修改密码失败');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const delUser = async (record: UserItem) => {
|
const delUser = async (record: UserItem) => {
|
||||||
const hide = message.loading('正在删除');
|
const hide = message.loading('正在删除');
|
||||||
try {
|
try {
|
||||||
@@ -83,6 +123,7 @@ const UsersPage: React.FC = () => {
|
|||||||
defaultCollapsed={false}
|
defaultCollapsed={false}
|
||||||
split
|
split
|
||||||
span={6}
|
span={6}
|
||||||
|
hideReset
|
||||||
showTenant={!isAppType}
|
showTenant={!isAppType}
|
||||||
onTenantChanged={(tenantId, includeChildren) => {
|
onTenantChanged={(tenantId, includeChildren) => {
|
||||||
// 租户切换时,直接更新查询参数,ProTable 会因 params 变更自动请求
|
// 租户切换时,直接更新查询参数,ProTable 会因 params 变更自动请求
|
||||||
@@ -106,6 +147,7 @@ const UsersPage: React.FC = () => {
|
|||||||
<UserTable
|
<UserTable
|
||||||
ref={tableRef}
|
ref={tableRef}
|
||||||
onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }}
|
onEdit={(r) => { setCurrentRow(r); setEditVisible(true); }}
|
||||||
|
onChangePassword={(r) => openChangePwd(r)}
|
||||||
onResetPassword={(r) => resetPwd(r)}
|
onResetPassword={(r) => resetPwd(r)}
|
||||||
onDelete={(r) => delUser(r)}
|
onDelete={(r) => delUser(r)}
|
||||||
// 通过 __refresh 强制区分每次点击
|
// 通过 __refresh 强制区分每次点击
|
||||||
@@ -113,11 +155,14 @@ const UsersPage: React.FC = () => {
|
|||||||
/>
|
/>
|
||||||
</GlassCard>
|
</GlassCard>
|
||||||
|
|
||||||
{/* 新建(仅系统用户) */}
|
{/* 新建(仅系统用户)*/}
|
||||||
<UserForm title="新建用户" visible={createVisible} onVisibleChange={setCreateVisible} onFinish={addUser} showCompany={!isAppType ? true : false} />
|
<UserForm title="新建用户" visible={createVisible} onVisibleChange={setCreateVisible} onFinish={addUser} showCompany={!isAppType ? true : false} />
|
||||||
|
|
||||||
{/* 编辑 */}
|
{/* 编辑 */}
|
||||||
<UserForm title="修改用户" visible={editVisible} onVisibleChange={setEditVisible} onFinish={editUser} initialValues={currentRow} showCompany={!isAppType ? true : false} />
|
<UserForm title="修改用户" visible={editVisible} onVisibleChange={setEditVisible} onFinish={editUser} initialValues={currentRow} showCompany={!isAppType ? true : false} />
|
||||||
|
|
||||||
|
{/* 修改密码 */}
|
||||||
|
<ChangePasswordModal visible={pwdVisible} user={pwdUser} onVisibleChange={setPwdVisible} onFinish={submitChangePwd} />
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { request } from 'umi';
|
import { request } from 'umi';
|
||||||
|
|
||||||
export interface OrderItem {
|
export interface OrderItem {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -12,6 +12,15 @@ export interface OrderItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const ordersApi = {
|
export const ordersApi = {
|
||||||
|
// 按租户分组获取景区资源(新接口)
|
||||||
|
tourismFilesGroupedByTenant: async (params: { tenantId?: string; includeChildren?: boolean; type?: number; status?: number; description?: string; tourismId?: number; current?: number; pageSize?: number }) => {
|
||||||
|
const { current, pageSize, ...rest } = params || {};
|
||||||
|
const res = await request('/api-order/tourism/files/grouped/by-tenant', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||||
|
const list = (res as any)?.data ?? (res as any)?.data?.data ?? (res as any)?.rows ?? (res as any);
|
||||||
|
const total = (res as any)?.count ?? (res as any)?.data?.count ?? (Array.isArray(list) ? list.length : 0);
|
||||||
|
return { data: (Array.isArray(list) ? list : []), total } as { data: Array<{ tourismId: number; tourismName?: string; files: any[] }>; total: number };
|
||||||
|
},
|
||||||
|
|
||||||
// 订单列表
|
// 订单列表
|
||||||
order: async (params: { current?: number; pageSize?: number; orderNo?: string; orderStatus?: number; tourismId?: number; payType?: number }) => {
|
order: async (params: { current?: number; pageSize?: number; orderNo?: string; orderStatus?: number; tourismId?: number; payType?: number }) => {
|
||||||
const { current, pageSize, ...rest } = params || {};
|
const { current, pageSize, ...rest } = params || {};
|
||||||
@@ -43,11 +52,21 @@ export const ordersApi = {
|
|||||||
saveOrUpdateQrcode: async (data: any) => {
|
saveOrUpdateQrcode: async (data: any) => {
|
||||||
const res = await request('/api-order/qrcode', { method: 'POST', data });
|
const res = await request('/api-order/qrcode', { method: 'POST', data });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
saveOrUpdateQrcodePlan: async (payload: { qrCode: any; vlogCount?: number; videoCount?: number; photoCount?: number; tourismFileIds?: number[] }) => {
|
||||||
|
const res = await request('/api-order/qrcode/withPlan', { method: 'POST', data: payload });
|
||||||
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
deleteQrcode: async (id: number) => {
|
deleteQrcode: async (id: number) => {
|
||||||
const res = await request(`/api-order/qrcode/${id}`, { method: 'DELETE' });
|
const res = await request(`/api-order/qrcode/${id}`, { method: 'DELETE' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
// 按景区ID查询二维码列表
|
||||||
|
qrcodeListByTourism: async (params: { current?: number; pageSize?: number; tourismId: number; [k: string]: any }) => {
|
||||||
|
const { current, pageSize, ...rest } = params || {};
|
||||||
|
const res = await request('/api-order/qrcode', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||||
|
return { data: (res as any).data, total: (res as any).count };
|
||||||
|
},
|
||||||
|
|
||||||
// 旅游景区
|
// 旅游景区
|
||||||
tourism: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
tourism: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||||
@@ -60,7 +79,8 @@ export const ordersApi = {
|
|||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
deleteTourism: async (id: number) => {
|
deleteTourism: async (id: number) => {
|
||||||
const res = await request(`/api-order/tourism/${id}`, { method: 'DELETE' });
|
// 后端删除接口:DELETE /tourism(从请求体读取 id),不支持 path 变量
|
||||||
|
const res = await request('/api-order/tourism', { method: 'DELETE', data: { id } });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -92,6 +112,11 @@ export const ordersApi = {
|
|||||||
deleteTourismFile: async (id: number) => {
|
deleteTourismFile: async (id: number) => {
|
||||||
const res = await request(`/api-order/tourism/files/${id}`, { method: 'DELETE' });
|
const res = await request(`/api-order/tourism/files/${id}`, { method: 'DELETE' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
|
}, // 按景区ID获取资源列表(非分页)
|
||||||
|
tourismFileByTourism: async (tourismId: number) => {
|
||||||
|
const res = await request('/api-order/tourism/files/byTourism/' + tourismId, { method: 'GET' });
|
||||||
|
const list = (res as any)?.data ?? [];
|
||||||
|
return { data: Array.isArray(list) ? list : [], total: Array.isArray(list) ? list.length : 0 } as { data: any[]; total: number };
|
||||||
},
|
},
|
||||||
|
|
||||||
// 退款
|
// 退款
|
||||||
@@ -142,28 +167,39 @@ export const ordersApi = {
|
|||||||
return res as any;
|
return res as any;
|
||||||
},
|
},
|
||||||
|
|
||||||
// 视频模板
|
// 视频模板(注意后端路径前缀 /video/template)
|
||||||
getVideoTemplateList: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
getVideoTemplateList: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||||
const { current, pageSize, ...rest } = params || {};
|
const { current, pageSize, ...rest } = params || {};
|
||||||
const res = await request('/api-order/videoTemplate/list', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
const res = await request('/api-order/video/template/list', {
|
||||||
return { data: (res as any).data, total: (res as any).count };
|
method: 'GET',
|
||||||
|
params: { page: current, limit: pageSize, ...rest },
|
||||||
|
});
|
||||||
|
const list = (res as any)?.data?.data ?? (res as any)?.data ?? (res as any)?.rows ?? [];
|
||||||
|
const total = (res as any)?.data?.count ?? (res as any)?.count ?? (res as any)?.total ?? (Array.isArray(list) ? list.length : 0);
|
||||||
|
return { data: list, total };
|
||||||
},
|
},
|
||||||
saveVideoTemplate: async (data: any) => {
|
saveVideoTemplate: async (data: any) => {
|
||||||
const res = await request('/api-order/videoTemplate', { method: 'POST', data });
|
const res = await request('/api-order/video/template', { method: 'POST', data });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
updateVideoTemplate: async (data: any) => {
|
updateVideoTemplate: async (data: any) => {
|
||||||
const res = await request('/api-order/videoTemplate', { method: 'PUT', data });
|
const res = await request('/api-order/video/template', { method: 'PUT', data });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
deleteVideoTemplate: async (id: number) => {
|
deleteVideoTemplate: async (id: number) => {
|
||||||
const res = await request(`/api-order/videoTemplate/${id}`, { method: 'DELETE' });
|
const res = await request(`/api-order/video/template/${id}`, { method: 'DELETE' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
updateVideoTemplateStatus: async (id: number, status: number) => {
|
updateVideoTemplateStatus: async (id: number, status: number) => {
|
||||||
const res = await request(`/api-order/videoTemplate/${id}/status`, { method: 'PUT', params: { status } });
|
// 后端定义:/{id}/status/{status}
|
||||||
|
const res = await request(`/api-order/video/template/${id}/status/${status}`, { method: 'PUT' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
// 根据模板ID(templateId,字符串)查询模板信息(后端直查接口)
|
||||||
|
getVideoTemplateByTemplateId: async (templateId: string) => {
|
||||||
|
const res = await request(`/api-order/video/template/templateId/${templateId}`, { method: 'GET' });
|
||||||
|
return (res as any).data || res || null;
|
||||||
|
},
|
||||||
|
|
||||||
// 编辑任务
|
// 编辑任务
|
||||||
getEditTaskList: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
getEditTaskList: async (params: { current?: number; pageSize?: number; [k: string]: any }) => {
|
||||||
@@ -241,4 +277,11 @@ export const ordersApi = {
|
|||||||
const res = await request('/api-order/coupon/update-expired', { method: 'POST' });
|
const res = await request('/api-order/coupon/update-expired', { method: 'POST' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
getPackagePlanByCode: async (codeId: string) => {
|
||||||
|
const res = await request('/api-order/package/byCode/' + codeId, { method: 'GET' });
|
||||||
|
const list = ((res as any)?.data ?? (res as any)) as any[];
|
||||||
|
return Array.isArray(list) ? list : [];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ export const systemApi = {
|
|||||||
const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data });
|
const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
// 原样返回后端包装,便于上层拿到 resp_code/resp_msg 做精确提示
|
||||||
|
saveOrUpdateUserRaw: async (data: Partial<UserItem>) => {
|
||||||
|
const res = await request('/api-user/users/saveOrUpdate', { method: 'POST', data });
|
||||||
|
return res as any;
|
||||||
|
},
|
||||||
|
|
||||||
// 启用/禁用
|
// 启用/禁用
|
||||||
updateEnabled: async (id: number, enabled: boolean) => {
|
updateEnabled: async (id: number, enabled: boolean) => {
|
||||||
@@ -52,6 +57,15 @@ export const systemApi = {
|
|||||||
const res = await request(`/api-user/users/${id}/password`, { method: 'PUT' });
|
const res = await request(`/api-user/users/${id}/password`, { method: 'PUT' });
|
||||||
return (res as any).data || res;
|
return (res as any).data || res;
|
||||||
},
|
},
|
||||||
|
// 修改密码(支持管理员为指定用户设置自定义密码,或用户自助修改)
|
||||||
|
// 后端签名:PUT /users/password,Body: { id, oldPassword?, newPassword }
|
||||||
|
changePassword: async (id: number, newPassword: string, oldPassword?: string) => {
|
||||||
|
const res = await request('/api-user/users/password', {
|
||||||
|
method: 'PUT',
|
||||||
|
data: { id, newPassword, oldPassword },
|
||||||
|
});
|
||||||
|
return (res as any).data || res;
|
||||||
|
},
|
||||||
|
|
||||||
// 删除用户
|
// 删除用户
|
||||||
deleteUser: async (id: number) => {
|
deleteUser: async (id: number) => {
|
||||||
|
|||||||
@@ -10,9 +10,12 @@ export interface TokenItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const tokenApi = {
|
export const tokenApi = {
|
||||||
page: async (params: { current?: number; pageSize?: number; tenantId: string; username?: string }) => {
|
page: async (params: { current?: number; pageSize?: number; tenantId?: string; username?: string }) => {
|
||||||
if (!params?.tenantId) return { data: [], total: 0 };
|
const p2 = { tenantId: 'webApp', ...params };
|
||||||
const res = await request('/api-uaa/tokens', { method: 'GET', params: { page: params.current, limit: params.pageSize, ...params } });
|
const res = await request('/api-uaa/tokens', {
|
||||||
|
method: 'GET',
|
||||||
|
params: { page: p2.current, limit: p2.pageSize, ...p2 },
|
||||||
|
});
|
||||||
const data = (res as any).data;
|
const data = (res as any).data;
|
||||||
const total = (res as any).count ?? data?.length ?? 0;
|
const total = (res as any).count ?? data?.length ?? 0;
|
||||||
return { data, total } as { data: TokenItem[]; total: number };
|
return { data, total } as { data: TokenItem[]; total: number };
|
||||||
|
|||||||
@@ -1,202 +0,0 @@
|
|||||||
# 前端RSA加密使用指南
|
|
||||||
|
|
||||||
## 概述
|
|
||||||
|
|
||||||
本项目提供了与后端RSAUtil对应的前端RSA加密解决方案,确保敏感数据在传输过程中的安全性。
|
|
||||||
|
|
||||||
## 核心文件
|
|
||||||
|
|
||||||
- `rsaUtil.ts` - RSA加密核心工具类
|
|
||||||
- `securityUtil.ts` - 安全辅助工具类
|
|
||||||
- `useSecurity.ts` - React Hook,提供安全操作
|
|
||||||
- `SecureLoginForm` - 安全登录表单组件
|
|
||||||
|
|
||||||
## 基本使用
|
|
||||||
|
|
||||||
### 1. 密码加密
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import RSAUtil from '@/utils/rsaUtil';
|
|
||||||
|
|
||||||
// 加密密码
|
|
||||||
const encryptedPassword = RSAUtil.encryptPassword('user123456');
|
|
||||||
|
|
||||||
// 或使用便捷导入
|
|
||||||
import { encryptPassword } from '@/utils/rsaUtil';
|
|
||||||
const encrypted = encryptPassword('user123456');
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 登录表单处理
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import { useSecurity } from '@/hooks/useSecurity';
|
|
||||||
|
|
||||||
const LoginPage = () => {
|
|
||||||
const { secureLogin } = useSecurity();
|
|
||||||
|
|
||||||
const handleLogin = async (values) => {
|
|
||||||
const secureData = await secureLogin(values);
|
|
||||||
if (secureData) {
|
|
||||||
// 发送到后端
|
|
||||||
api.login(secureData);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 批量敏感字段加密
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import SecurityUtil from '@/utils/securityUtil';
|
|
||||||
|
|
||||||
const userForm = {
|
|
||||||
username: 'admin',
|
|
||||||
password: '123456',
|
|
||||||
email: 'admin@example.com'
|
|
||||||
};
|
|
||||||
|
|
||||||
// 只加密密码字段
|
|
||||||
const secureForm = SecurityUtil.processFormData(userForm, ['password']);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 使用安全登录组件
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
import SecureLoginForm from '@/components/SecureLoginForm';
|
|
||||||
|
|
||||||
const LoginPage = () => {
|
|
||||||
const handleLogin = async (loginData) => {
|
|
||||||
// loginData.password 已经被自动加密
|
|
||||||
const response = await api.login(loginData);
|
|
||||||
// 处理登录响应
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SecureLoginForm
|
|
||||||
onLogin={handleLogin}
|
|
||||||
showPasswordStrength={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
## 安全最佳实践
|
|
||||||
|
|
||||||
### 1. 加密时机
|
|
||||||
- ✅ 在发送请求前立即加密
|
|
||||||
- ✅ 在表单提交时加密
|
|
||||||
- ❌ 不要在组件状态中存储加密数据
|
|
||||||
- ❌ 不要过早加密(影响用户体验)
|
|
||||||
|
|
||||||
### 2. 错误处理
|
|
||||||
```typescript
|
|
||||||
const encryptedData = RSAUtil.encrypt(sensitiveData);
|
|
||||||
if (!encryptedData) {
|
|
||||||
// 处理加密失败
|
|
||||||
message.error('数据加密失败,请重试');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 加密前验证
|
|
||||||
```typescript
|
|
||||||
// 密码强度验证
|
|
||||||
const strength = SecurityUtil.validatePasswordStrength(password);
|
|
||||||
if (strength.level === 'weak') {
|
|
||||||
// 提示用户增强密码
|
|
||||||
}
|
|
||||||
|
|
||||||
// 输入安全过滤
|
|
||||||
const safeInput = SecurityUtil.sanitizeInput(userInput);
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 敏感数据脱敏
|
|
||||||
```typescript
|
|
||||||
// 显示时脱敏
|
|
||||||
const maskedPhone = SecurityUtil.maskSensitiveData('13812345678', 'phone');
|
|
||||||
// 结果: 138****5678
|
|
||||||
```
|
|
||||||
|
|
||||||
## 与后端对接
|
|
||||||
|
|
||||||
### 后端解密示例
|
|
||||||
你的后端使用 `RSAUtil.decryptOne()` 方法解密:
|
|
||||||
|
|
||||||
```java
|
|
||||||
// Java后端
|
|
||||||
String rawPassword = RSAUtil.decryptOne(req.getPassword());
|
|
||||||
```
|
|
||||||
|
|
||||||
### 前后端数据流程
|
|
||||||
1. 前端: 用户输入密码 `"123456"`
|
|
||||||
2. 前端: RSA加密 → `"LBS9qzlDcBQ..."`(Base64 + URL编码)
|
|
||||||
3. 后端: 接收加密数据
|
|
||||||
4. 后端: `RSAUtil.decryptOne()` 解密 → `"123456"`
|
|
||||||
|
|
||||||
## 安全注意事项
|
|
||||||
|
|
||||||
### 1. 公钥管理
|
|
||||||
- 公钥已硬编码在代码中(与后端保持一致)
|
|
||||||
- 生产环境建议通过API动态获取公钥
|
|
||||||
- 定期轮换密钥对
|
|
||||||
|
|
||||||
### 2. HTTPS传输
|
|
||||||
```typescript
|
|
||||||
// 确保API请求使用HTTPS
|
|
||||||
const API_BASE_URL = process.env.NODE_ENV === 'production'
|
|
||||||
? 'https://your-domain.com/api'
|
|
||||||
: 'http://localhost:9900';
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 内存安全
|
|
||||||
```typescript
|
|
||||||
// 避免在控制台输出敏感信息
|
|
||||||
if (process.env.NODE_ENV !== 'development') {
|
|
||||||
console.log = () => {};
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 输入验证
|
|
||||||
```typescript
|
|
||||||
// 在加密前验证输入
|
|
||||||
if (!password || password.trim() === '') {
|
|
||||||
throw new Error('密码不能为空');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password.length < 6) {
|
|
||||||
throw new Error('密码长度不能少于6位');
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 常见问题
|
|
||||||
|
|
||||||
### Q: 加密失败怎么办?
|
|
||||||
A: 检查输入数据是否为空,确认jsencrypt库已正确安装
|
|
||||||
|
|
||||||
### Q: 前后端加密解密不匹配?
|
|
||||||
A: 确认公钥私钥对是否一致,检查Base64编码格式
|
|
||||||
|
|
||||||
### Q: 性能优化建议?
|
|
||||||
A:
|
|
||||||
- RSA加密较慢,只加密敏感字段
|
|
||||||
- 考虑使用Web Worker处理大量数据加密
|
|
||||||
- 合理使用缓存
|
|
||||||
|
|
||||||
## 测试
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
// 简单测试
|
|
||||||
const testData = 'test123';
|
|
||||||
const encrypted = RSAUtil.encrypt(testData);
|
|
||||||
console.log('加密结果:', encrypted);
|
|
||||||
console.log('是否已加密:', RSAUtil.isEncrypted(encrypted));
|
|
||||||
```
|
|
||||||
|
|
||||||
## 升级指南
|
|
||||||
|
|
||||||
如需更新加密算法或密钥:
|
|
||||||
|
|
||||||
1. 与后端协调更新时间
|
|
||||||
2. 更新 `rsaUtil.ts` 中的公钥
|
|
||||||
3. 测试前后端对接
|
|
||||||
4. 发布更新
|
|
||||||
Reference in New Issue
Block a user