# magic-api-plugin-freemarker
**Repository Path**: linlw/magic-api-plugin-freemarker
## Basic Information
- **Project Name**: magic-api-plugin-freemarker
- **Description**: 用于magic-api 的freemarker插件
支持在线编辑freemarker文件
可让接口返回渲染后的Html文件
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: linlw/v1115
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 8
- **Created**: 2022-11-15
- **Last Updated**: 2022-11-15
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# magic-api-plugin-freemarker
# 介绍
- 用于[magic-api](https://gitee.com/ssssssss-team/magic-api) 的freemarker插件
- 支持在线编辑freemarker文件
- 可让接口返回渲染后的Html文件
# 部署步骤
## maven编译
```cmd
mvn clean install
```
## pom引入
```xml
cn.luow
magic-api-plugin-freemarker
2.0.2
```
# 使用说明
## 例一:
### 创建一个模板,引入其他模板使用<#include "@/xxx/xx">

### css和js文件还是要写在标签里

### 代码中使用response.ftl(params,url)返回前端页面

## 例二:
### 引入外部js css

### 将数据组装到模板里,生成前端页面

# 注意
### 如果加了插件之后页面没有模板模块,可能是springboot限制了静态文件大小,请尝试增加限制
```yaml
spring:
servlet:
multipart:
enabled: true
max-file-size: 10485760 #10mb
max-request-size: 10485760 #10mb
```
##Demo Code
```html
模板: /common/sdk_amis
amis
函数: /common/sub_page
import response;
// Usage: 公共模块:多页面
// import '@/v1daily/sub_page' as sub_page;
// return sub_page('config',{},{},{},{})
import '@/common/sub_config' as sub_config; //匹配配置 sub_config
var nav0 = {
"type": "nav",
"stacked": false,
// "stacked": true,
// "className": "w-md",
"itemBadge": {
"mode": "ribbon",
"size": 10,
"text": "${customText}",
"position": "top-left",
"visibleOn": "this.customText",
"level": "${customLevel}"
},
"links": [
{
"label": "导数任务1",
"to": "/prod-api/v2/jdpt/config/apiget?act=g00_auto",
"icon": "fa fa-database",
"customText": "AUTO",
"customLevel": "success"
},
{
"label": "文档中心2",
"to": "/prod-api/v2/jdpt/config/apiget?act=g01_page",
"icon": "fa fa-database",
"customText": "DOC",
"customLevel": "warning"
},
{
"label": "上传解压ZIP",
"to": "/prod-api/v2/jdpt/config/apiget?act=g02_zip",
"icon": "fa fa-database",
"customText": "STEP1",
"customLevel": "info"
},
{
"label": "导入明细EXCEL",
"to": "/prod-api/v2/jdpt/config/apiget?act=g03_excel",
"icon": "fa fa-database",
"customText": "STEP2",
"customLevel": "debug"
},
{
"label": "队列任务",
"to": "/prod-api/v2/jdpt/config/apiget?act=g04_import",
"icon": "fa fa-database",
"customText": "STEP3",
"customLevel": "success"
},
{
"label": "执行任务",
"to": "/prod-api/v2/jdpt/config/apiget?act=g05_task",
"icon": "fa fa-database",
"customText": "STEP4",
"customLevel": "warning"
},
{
"label": "生成指标",
"to": "/prod-api/v2/jdpt/config/apiget?act=g06_zbk",
"icon": "fa fa-database",
"customText": "STEP5",
"customLevel": "warning"
},
{
"label": "同步数据",
"to": "/prod-api/v2/jdpt/config/apiget?act=g07_sync",
"icon": "fa fa-database",
"customText": "STEP6",
"customLevel": "success"
},
{
"label": "月报生成",
"to": "/prod-api/v2/jdpt/config/apiget?act=g08_amis",
"icon": "fa fa-database",
"customText": "REPORT",
"customLevel": "info"
},
{
"label": "上线测试",
"to": "/prod-api/v2/jdpt/config/apiget?act=g09_test",
"icon": "fa fa-database",
"customText": "TEST",
"customLevel": "danger"
},
{
"label": "科室指标",
"to": "/prod-api/v2/jdpt/v1daily/amis_crud_office?act=crud01_page",
"icon": "fa fa-database",
"customText": "科室",
"customLevel": "success"
}
]
}
var navBlank = {
"type": "tpl",
"tpl": "
"
}
// return response.json({
// status : 0,
// msg : 'ok',
// data: {
// ret: ret.cnt
// msg: "select * from zb_sys_data where zbk_type = '" + sheetName +"' and zbk_yydate = '" + yydate + "'",
// }
// });
var nav99 =
{
"type": "form",
"name": "otherForm",
"data":{
"show": "0"
},
"title": "处理结果",
"actions": [],
"body": [
{
"type": "static",
"name": "show",
"label": "返回状态",
// "hiddenOn": "this.show == 0",
"visibleOn": "this.show == 1",
},
{
"type": "static",
"name": "ret",
"label": "数据统计"
},
{
"type": "static",
"name": "msg",
"label": "提示信息"
}
]
}
// var navAmisDemo = config['amis-demo']::json
alljson = {
"type": "page",
"data": {
"breadcrumb": [
{
"label": "首页",
"href": "/prod-api/v2/jdpt/config/apiget?act=g00_auto"
},
{
"label": "上级页面",
"href": "/prod-api/v2/jdpt/config/apiget?act=g01_page"
},
{
"label": "当前页面"
}
]
},
"body": [
nav0,
navBlank,
nav1,
navBlank,
nav2,
navBlank,
nav3,
navBlank,
nav4
]
}
let data = {data: alljson::stringify};
//直接通过 freemarker plugin ftl返回模板
return response.ftl(data, "/common/sdk_amis")//接口和模板路径,省路路经
接口: /新建接口放这里v2/日志分页列表LOGAMIS(/v2/logamis)
import response;
alljson = {
"type": "page",
"body": {
"type": "crud",
"api": "post:/prod-api/v2/jdpt/v2/logpage",
"syncLocation": false,
"pageField": "page",
"perPageField": "limit",
"autoFillHeight": true,
"defaultParams": {
"limit": 10
},
"columns": [
{
"name": "id",
"label": "ID",
"sortable": true
},
{
"name": "logType",
"label": "日志类型",
"searchable": true
},
// {
// "name": "createUserCode",
// "label": "用户代码",
// "searchable": true
// },
// {
// "name": "createUserName",
// "label": "用户名称",
// "searchable": true
// },
{
"name": "createDate",
"label": "操作日期",
"searchable": true
},
{
"name": "requestUri",
"label": "请求路径",
"searchable": true
},
{
"name": "requestMethod",
"label": "请求方法",
"searchable": true
},
{
"name": "requestParams",
"label": "请求参数",
"searchable": true
},
{
"name": "requestIp",
"label": "请示地址",
"searchable": true
},
{
"name": "serverAddress",
"label": "服务器",
"searchable": true
},
{
"name": "isException",
"label": "是否异常",
"searchable": true
},
{
"name": "exceptionInfo",
"label": "返回或异常",
"searchable": true
},
{
"name": "startTime",
"label": "开始时间",
"searchable": true
},
{
"name": "endTime",
"label": "结束时间",
"searchable": true
},
{
"name": "executeTime",
"label": "执行时间",
"sortable": true
},
{
"name": "userAgent",
"label": "代理标识",
"searchable": true
},
{
"name": "deviceName",
"label": "设备",
"searchable": true
},
{
"name": "browserName",
"label": "浏览器",
"searchable": true
}
]
}
}
let data = {data: alljson::stringify};
//直接通过 freemarker plugin ftl返回模板
return response.ftl(data, "/common/sdk_amis")//接口和模板路径,省路路经
接口: /新建接口放这里v2/日志分页接口LOGPAGE(/v2/logpage)
import response;
import '@/test/uncamel' as uncamel;
// return uncamel('userId');
// 检查无显式赋值时, 使用默认值
var myLimit = body?.limit? body?.limit : 10
var myPage = body?.page? body?.page : 1
var myOrderBy = body?.orderBy? uncamel(body?.orderBy) : "id"
var myOrderDir = body?.orderDir? body?.orderDir : "asc"
var myUser = body?.user? body?.user : 0
// {
// "limit": 10, -- 每页显示条数: myLimit,
// "page": 1, -- 计算该页起始: (myPage-1)*myLimit
// "orderBy": "id", -- 需要反驼峰命名还原字段名, uncamel(body?.orderBy) 再用 ${myOrderBy} 占位符用于SQL order by
// "orderDir": "asc" -- 用 ${myOrderDir} 占位符用于SQL order by
// "user": 0 -- 若传入1为平台操作日志, 对应SQL为 create_user_code` not like ''
// }
var sql = """
SELECT id,
log_type,
create_user_code,
create_user_name,
create_date,
request_uri,
request_method,
request_params,
request_ip,
server_address,
is_exception,
exception_info,
start_time,
end_time,
execute_time,
user_agent,
device_name,
browser_name
FROM audit_sys_log
where 1=1
?{body?.id != null, and id = #{body.id}}
?{body?.logType != null, and `log_type` like concat('%',#{body?.logType},'%')}
?{body?.createUserCode != null, and `create_user_code` like concat('%',#{body?.createUserCode},'%')}
?{body?.createUserName != null, and `create_user_name` like concat('%',#{body?.createUserName},'%')}
?{body?.createDate != null, and `create_date` like concat('%',#{body?.createDate},'%')}
?{body?.requestUri != null, and `request_uri` like concat('%',#{body?.requestUri},'%')}
?{body?.requestMethod != null, and `request_method` like concat('%',#{body?.requestMethod},'%')}
?{body?.requestParams != null, and `request_params` like concat('%',#{body?.requestParams},'%')}
?{body?.requestIp != null, and `request_ip` like concat('%',#{body?.requestIp},'%')}
?{body?.serverAddress != null, and `server_address` like concat('%',#{body?.serverAddress},'%')}
?{body?.isException != null, and `is_exception` like concat('%',#{body?.isException},'%')}
?{body?.startTime != null, and `start_time` like concat('%',#{body?.startTime},'%')}
?{body?.endTime != null, and `end_time` like concat('%',#{body?.endTime},'%')}
?{body?.executeTime != null, and `execute_time` like concat('%',#{body?.executeTime},'%')}
?{body?.userAgent != null, and `user_agent` like concat('%',#{body?.userAgent},'%')}
?{body?.deviceName != null, and `device_name` like concat('%',#{body?.deviceName},'%')}
?{body?.browserName != null, and `browser_name` like concat('%',#{body?.browserName},'%')}
?{myUser == 0, and `create_user_code` like ''}
?{myUser == 1, and `create_user_code` not like ''}
order by ${myOrderBy} ${myOrderDir}
"""
var rows = db.jdpt.page(sql, myLimit, (myPage-1)*myLimit )
return response.json({
status : 0,
msg : 'ok',
data: rows
})
// var me = {
// "date": date_format(now(),'yyyy-MM-dd'),
// "now": now().format("yyyy-MM-dd HH:mm:ss")
// }
// me['rows']['columns'] = me['cols']
// return response.json({
// status : 0,
// msg : 'ok',
// data: me.rows
// })
```