Browse Source

lean 4

master
onlyxx 4 years ago
commit
1459cf0340
  1. 13
      encrypt.xml
  2. BIN
      lib/gson-2.3.1.jar
  3. 0
      lib/report/.gitkeep
  4. 19
      plugin.xml
  5. 50
      src/main/java/com/fr/plugin/LeanFileDef.java
  6. 42
      src/main/java/com/fr/plugin/LeanHttpHandler.java
  7. 13
      src/main/java/com/fr/plugin/LeanHttpProvider.java
  8. 20
      src/main/java/com/fr/plugin/LeanJSCSSBridge.java
  9. 6
      src/main/java/com/fr/plugin/MyFunctionConstants.java
  10. 16
      src/main/java/com/fr/plugin/MyURLAliasProvider.java
  11. 1
      src/main/resources/com/fr/plugin/demo.properties
  12. 1
      src/main/resources/com/fr/plugin/demo_zh_CN.properties
  13. 0
      src/main/resources/com/fr/plugin/web/lean.css
  14. 138
      src/main/resources/com/fr/plugin/web/lean.html
  15. 1
      src/main/resources/com/fr/plugin/web/lean.js

13
encrypt.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<target name="compile_encrypt_javas" depends="copyFiles">
<echo message="加密文件"/>
<echo message="${projectDir}"/>
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask">
<classpath refid="compile.classpath"/>
</taskdef>
<pretreatment baseDir="${projectDir}"/>
</target>
<target name="compile_plain_javas" depends="copyFiles">
</target>
</project>

BIN
lib/gson-2.3.1.jar

Binary file not shown.

0
lib/report/.gitkeep

19
plugin.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.fineui.lean</id>
<name><![CDATA[学习fineUI]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>author</vendor>
<description><![CDATA[学习fineUI]]></description>
<change-notes><![CDATA[
[2018-08-01]修改一点问题。<br/>
[2018-07-31]初始化插件。<br/>
]]></change-notes>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.LeanHttpProvider" />
<URLAliasProvider class="com.fr.plugin.MyURLAliasProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.MyURLAliasProvider"/>
</plugin>

50
src/main/java/com/fr/plugin/LeanFileDef.java

@ -0,0 +1,50 @@
package com.fr.plugin;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
@FunctionRecorder
public class LeanFileDef extends Component {
public static final LeanFileDef KEY = new LeanFileDef();
private LeanFileDef(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
public ScriptPath script( RequestClient client ) {
//如果不需要就直接返回 ScriptPath.EMPTY
return ScriptPath.build("com/fr/plugin/web/lean.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
public StylePath style( RequestClient client ) {
//如果不需要就直接返回 StylePath.EMPTY;
return StylePath.build("com/fr/plugin/web/lean.css");
}
/**
* 通过给定的资源过滤器控制是否加载这个资源
* @return 资源过滤器
*/
@ExecuteFunctionRecord
public Filter filter() {
return new Filter(){
@Override
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

42
src/main/java/com/fr/plugin/LeanHttpHandler.java

@ -0,0 +1,42 @@
package com.fr.plugin;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.decision.web.LoginComponent;
import com.fr.decision.webservice.utils.WebServiceUtils;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.Browser;
import com.fr.web.struct.AtomBuilder;
import com.fr.web.struct.PathGroup;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
//
public class LeanHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
//如果返回null表示 支持任意类型
//return RequestMethod.GET
//return RequestMethod.POST
return null;
}
@Override
public String getPath() {
return "/leanFineUI";
}
@Override
public boolean isPublic() {
//这里要和注册短url那儿一致
return true;
}
@Override
public void handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
String html = WebServiceUtils.parseWebPageResourceSafe("com/fr/plugin/web/lean.html",new HashMap<>());
WebUtils.printAsString(response, html);
}
}

13
src/main/java/com/fr/plugin/LeanHttpProvider.java

@ -0,0 +1,13 @@
package com.fr.plugin;
import com.fr.decision.fun.HttpHandler;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
public class LeanHttpProvider extends AbstractHttpHandlerProvider {
@Override
public HttpHandler[] registerHandlers() {
return new HttpHandler[]{
new LeanHttpHandler()
};
}
}

20
src/main/java/com/fr/plugin/LeanJSCSSBridge.java

@ -0,0 +1,20 @@
package com.fr.plugin;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.web.struct.Atom;
public class LeanJSCSSBridge extends AbstractWebResourceProvider {
@Override
public Atom attach() {
//在平台主组件加载时添加我们自己的组件
return MainComponent.KEY;
}
@Override
public Atom client() {
//我们自己要引入的组件
return LeanFileDef.KEY;
}
}

6
src/main/java/com/fr/plugin/MyFunctionConstants.java

@ -0,0 +1,6 @@
package com.fr.plugin;
public class MyFunctionConstants {
public static final String PLUGIN_ID = "com.fr.plugin.fineui.lean";
}

16
src/main/java/com/fr/plugin/MyURLAliasProvider.java

@ -0,0 +1,16 @@
package com.fr.plugin;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
import com.fr.plugin.transform.FunctionRecorder;
@FunctionRecorder
public class MyURLAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/leanFineUI123","/leanFineUI",true)
};
}
}

1
src/main/resources/com/fr/plugin/demo.properties

@ -0,0 +1 @@
Plugin-Test_Function_Abs=Test ABS

1
src/main/resources/com/fr/plugin/demo_zh_CN.properties

@ -0,0 +1 @@
Plugin-Test_Function_Abs=测试ABS函数

0
src/main/resources/com/fr/plugin/web/lean.css

138
src/main/resources/com/fr/plugin/web/lean.html

@ -0,0 +1,138 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>学习FINE UI工具页</title>
<!--引入官方 css文件-->
<link rel="stylesheet" type="text/css"
href="/webroot/decision/file?path=/com/fr/web/ui/fineui.min.css&type=plain&parser=plain"/>
<link rel="stylesheet" type="text/css"
href="https://fanruan.design/markdown/lib/codemirror/codemirror.min.css"/>
<style>
.CodeMirror {
height: 100%;
}
#lean {
width: 49%;
height: 100%;
border: 1px solid;
position: absolute;
left: 0
}
#editAre {
width: 49%;
height: 100%;
border: 1px solid;
position: absolute;
right: 0
}
#editor {
width: 100%;
height: 100%
}
</style>
</head>
<body>
<div id="lean">
</div>
${somea}
<div id="editAre">
<textarea id="editor">
BI.createWidget({
type: "bi.label",
text: "测试文本"
})
</textarea>
</div>
</body>
<!-- 引入官方的js-->
<script type="text/javascript"
src="/webroot/decision/file?path=/com/fr/web/ui/fineui.min.js&type=plain&parser=plain"></script>
<script type="text/javascript"
src="https://fanruan.design/markdown/lib/codemirror/codemirror.min.js"></script>
<script id="markdown-lib-codemirror-modes-min" type="text/javascript"
src="https://fanruan.design/markdown/lib/codemirror/modes.min.js"></script>
<script id="markdown-lib-prettify-min" type="text/javascript"
src="https://fanruan.design/markdown/lib/prettify.min.js"></script>
<!-- 写自己的js-->
<script>
var editor = document.getElementById("editor");
var lean = document.getElementById("lean");
var codeEditor = null;
init();
function _runCode(code) {
code = code.replace(/^BI.createWidget|[^=]\sBI.createWidget/, "return BI.createWidget");
code = "function(){" + code + "}()";
try {
var widget = new Function("return " + code)(); // eslint-disable-line
return widget;
} catch (e) {
return false;
}
return false;
}
function change() {
var val = codeEditor.getValue();
var widget = _runCode(val);
if (widget) {
removeAllChild()
lean.append(widget.element[0]);
widget._isRoot = true;
widget._mount();
}
}
function init() {
codeEditor = CodeMirror.fromTextArea(editor, {
mode: "javascript",
value: editor.value,
// lineNumbers: true,
lineWrapping: true,
tabSize: 4,
dragDrop: false,
// autofocus: true,
autoCloseTags: true,
readOnly: false,
indentUnit: 4,
foldGutter: false,
// gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
matchBrackets: true,
indentWithTabs: true,
// styleActiveLine: true,
// styleSelectedText: true,
autoCloseBrackets: true
// showTrailingSpace: true
// highlightSelectionMatches: { showToken: /\w/ }
});
var timer;
codeEditor.on("change", function (_cm, changeObj) {
timer = setTimeout(function () {
clearTimeout(timer);
change();
timer = null;
}, 300);
});
change()
}
function removeAllChild() {
var div = document.getElementById("lean");
while (div.hasChildNodes()) //当div下还存在子节点时 循环继续
{
div.removeChild(div.firstChild);
}
}
</script>
</html>

1
src/main/resources/com/fr/plugin/web/lean.js

@ -0,0 +1 @@
alert("this is my first alert");
Loading…
Cancel
Save