mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 01:25:28 +08:00
h5 动态表单,折腾中
This commit is contained in:
parent
6f08381705
commit
515b57d561
3
ruoyi-site/ruoyi-h5/doc/http/work.http
Normal file
3
ruoyi-site/ruoyi-h5/doc/http/work.http
Normal file
@ -0,0 +1,3 @@
|
||||
### 查询所有H5项目
|
||||
GET http://localhost:19200/h5/works/page?page=1&size=10
|
||||
Accept: application/json
|
||||
@ -1,11 +1,12 @@
|
||||
package com.luban.api.config;
|
||||
|
||||
import com.luban.api.s3.config.S3LoginUserInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
import org.springframework.web.servlet.config.annotation.*;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@ -31,4 +32,25 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
registry.addInterceptor(new S3LoginUserInterceptor()).addPathPatterns("/storage/**");
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
// 设置访问源地址
|
||||
config.addAllowedOriginPattern("*");
|
||||
// 设置访问源请求头
|
||||
config.addAllowedHeader("*");
|
||||
// 设置访问源请求方法
|
||||
config.addAllowedMethod("*");
|
||||
// 有效期 1800秒
|
||||
config.setMaxAge(1800L);
|
||||
// 添加映射路径,拦截一切请求
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
// 返回新的CorsFilter
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,19 +51,6 @@ public class WorkController {
|
||||
@Autowired
|
||||
private WorkService workService;
|
||||
|
||||
|
||||
@Operation(summary = "根据workId查询")
|
||||
@GetMapping("/has-forms")
|
||||
public List<WorkVO> hasForms() {
|
||||
return WorkConvert.toVO(workService.list());
|
||||
}
|
||||
|
||||
@Operation(summary = "根据workId查询")
|
||||
@GetMapping("/{id}")
|
||||
public WorkVO findWorkById(@PathVariable Long id) {
|
||||
return WorkConvert.toVO(workService.getById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询works")
|
||||
@GetMapping("/page")
|
||||
public IPage<H5Project> listWorks(@Valid H5ProjectQueryDTO dto) {
|
||||
@ -74,93 +61,5 @@ public class WorkController {
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "创建work")
|
||||
@PostMapping
|
||||
public WorkVO createWork(@RequestBody @Valid WorkCreateDTO dto) {
|
||||
WorkVO vo = new WorkVO();
|
||||
BeanUtils.copyProperties(dto, vo);
|
||||
Work work = WorkConvert.toEntity(vo);
|
||||
workService.save(work);
|
||||
return WorkConvert.toVO(work);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新work")
|
||||
@PutMapping("/{id}")
|
||||
public WorkVO updateWork(@PathVariable Long id, @RequestBody @Valid WorkUpdateDTO dto) {
|
||||
Work work = workService.getById(id);
|
||||
if (!StringUtils.isEmpty(dto.getTitle())) {
|
||||
work.setTitle(dto.getTitle());
|
||||
}
|
||||
if (!StringUtils.isEmpty(dto.getDescription())) {
|
||||
work.setDescription(dto.getDescription());
|
||||
}
|
||||
if (!StringUtils.isEmpty(dto.getCoverImageUrl())) {
|
||||
work.setCoverImageUrl(dto.getCoverImageUrl());
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(dto.getPages())) {
|
||||
work.setPages(JSONUtil.toJsonStr(dto.getPages()));
|
||||
}
|
||||
work.setIsTemplate(dto.isTemplate());
|
||||
work.setIsPublish(dto.isPublish());
|
||||
work.setWidth(dto.getWidth());
|
||||
work.setHeight(dto.getWidth());
|
||||
work.setPageMode(dto.getWidth());
|
||||
|
||||
work.setUpdateTime(LocalDateTime.now());
|
||||
workService.saveOrUpdate(work);
|
||||
return WorkConvert.toVO(work);
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "删除work")
|
||||
@DeleteMapping("/{id}")
|
||||
public void deleteWorkById(@PathVariable Long id) {
|
||||
workService.removeById(id);
|
||||
}
|
||||
|
||||
@Operation(summary = "设为模板")
|
||||
@PostMapping("/set-as-template/{id}")
|
||||
public WorkVO markWorkAsTemplate(@PathVariable Long id) {
|
||||
Work work = workService.getById(id);
|
||||
work.setIsTemplate(true);
|
||||
work.setUpdateTime(LocalDateTime.now());
|
||||
workService.updateById(work);
|
||||
return WorkConvert.toVO(work);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计作品总数")
|
||||
@GetMapping("/count")
|
||||
public long countWork() {
|
||||
return workService.count();
|
||||
}
|
||||
|
||||
@Operation(summary = "使用模板")
|
||||
@PostMapping("/use-template/{id}")
|
||||
public WorkVO useTemplate(@PathVariable Long id) {
|
||||
Work work = workService.getById(id);
|
||||
work.setId(null);
|
||||
work.setIsTemplate(false);
|
||||
work.setIsPublish(false);
|
||||
workService.save(work);
|
||||
return WorkConvert.toVO(work);
|
||||
}
|
||||
|
||||
@Operation(summary = "使用模板")
|
||||
@GetMapping("/preview/{id}")
|
||||
public ModelAndView useTemplate(@PathVariable Long id, @RequestParam(value = "view_mode", required = false) String viewMode) {
|
||||
Work work = workService.getById(id);
|
||||
|
||||
// 非预览模式, 查看不到内容
|
||||
boolean canRender = "preview".equals(viewMode) || work.getIsPublish();
|
||||
|
||||
if (!canRender) {
|
||||
work.setPages("[]");
|
||||
}
|
||||
ModelAndView mv = new ModelAndView("engine");
|
||||
//TODO 后端处理前端,这种方式不是很好,最后改成纯前端处理
|
||||
mv.addObject("workString", JSONUtil.toJsonStr(WorkConvert.toVO(work)));
|
||||
mv.addObject("work", work);
|
||||
return mv;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user