1 功能介绍
用来显示第三方链接进来的网站内容,当与第三方合作开发时,如有需要引入对应模块,可以通过iframe将其嵌入到项目中。 **# 2.基础用法展示
- 用法一,展示网页
该用法主要使用二开插件实现,通过setsrc方法来指定展示的网页资源的url
插件代码实现如下:
public class seturl extends AbstractFormPlugin implements Plugin {
@Override
public void afterBindData(EventObject e) {
IFrame iframe = this.getView().getControl("q5q6_iframeap");//通过控件的标识获取控件
iframe.setSrc("https://weathernew.pae.baidu.com/weathernew/pc?query=%E6%B1%9F%E8%A5%BF%E5%90%89%E5%AE%89%E5%A4%A9%E6%B0%94&srcid=4982&forecast=long_day_forecast");//设置展示网页的url
}
}
该用法还可以展示计算机上的资源如html文件等 示例插件代码:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String directoryName = simpleDateFormat.format(new Date());
StringBuffer sb = new StringBuffer();
for (int i = 1 ; i<=10; i++) {
int ascii = 48+(int)(Math.random()*9);
char ch = (char) ascii;
sb.append(ch);
}
File directoryGetQing = new File(System.getProperty("JETTY_WEBRES_PATH")+"/isv/html",directoryName);
if (!directoryGetQing.exists()) {
directoryGetQing.mkdirs();
}
File targetFile = new File(System.getProperty("JETTY_WEBRES_PATH")+"/isv/html/"+directoryName,sb+".html");
if (!targetFile.exists()) {
try {
targetFile.createNewFile();
} catch (IOException ex) {
ex.printStackTrace();
}
}
//写入文件
byte[] bytes =htmlString.getBytes();
try {
FileOutputStream fos=new FileOutputStream(targetFile);
fos.write(bytes);
} catch (IOException ex) {
ex.printStackTrace();
}
String htmlUrl = System.getProperty("domain.contextUrl")+"/isv/html/"+directoryName+"/"+sb+".html?"+"gaiIframeSize={"height":380,"width":1000}";
IFrame iframe = this.getView().getControl("q5q6_iframeap");// 设置url
iframe.setSrc(htmlUrl);
以上是一段使用iframe控件展示本地磁盘上的html的代码,通过将html代码写入本地磁盘,并以日期分包储存,再将静态资源的地址通过setsrc让iframe空间去展示
- 用法二,结合金蝶云苍穹gpt使用
通过获取gpt输出的文本信息来实现一些功能 可以通过获取gpt生成的html代码,在iframe控件上展示来实现一些特定的功能 如成绩分析, 具体gpt任务如下:
- 获取学生的成绩,示例:
public class GradeEvaluate implements IGPTAction {
@Override
public Map<String, String> invokeAction(String action, Map<String, String> params) {
Map<String , String> result = new HashMap<>();
if ("getgrade".equalsIgnoreCase(action)) {
//获取当前登录用户的id
long userID = UserServiceHelper.getCurrentUserId();
//获取考试信息
String test = params.get("testKind");
DynamicObject[] dys = BusinessDataServiceHelper.load("q5q6_gradeinput",
"q5q6_chinese," +
"q5q6_dance," +
"q5q6_math," +
"q5q6_english," +
"q5q6_lsmath," +
"q5q6_billiard",
(new QFilter("q5q6_testKind", QCP.equals, test).and(new QFilter("q5q6_user",QCP.equals,userID))).toArray());
//创建一个JsonArray
JSONArray jsonArray = new JSONArray();
for (DynamicObject dynamicObject : dys) {
//将每一个成绩信息加入JSONArray
JSONObject jsonObject = new JSONObject();
jsonObject.put("chinese", dynamicObject.getString("q5q6_chinese"));
jsonObject.put("english", dynamicObject.getString("q5q6_english"));
jsonObject.put("math", dynamicObject.getString("q5q6_math"));
jsonObject.put("lsmath", dynamicObject.getString("q5q6_lsmath"));
jsonObject.put("billiard", dynamicObject.getString("q5q6_billiard"));
jsonObject.put("dance", dynamicObject.getString("q5q6_dance"));
jsonArray.add(jsonObject);
}
System.out.println(jsonArray.toJSONString());
//加入resultDynamicObject参数,将JsonArray加入到这个参数当中,然后返回
result.put("resultDynamicObject", jsonArray.toJSONString());
}
return result;
}
}
- 交给gpt分析,示例:
- 获取gpt输出的文本并进行html截取,截取之后将html静态资源的地址交给iframe控件让iframe控件来展示该html资源,示例:
public class evaluate implements IGPTAction {
@Override
public Map<String, String> invokeAction(String action, Map<String, String> params) {
Map<String , String> result = new HashMap<>();
if ("gradeEvaluate".equalsIgnoreCase(action)) {
String htmlString = params.get("htmlResult");
//以防万一,在代码中我们再次截取一下字符串中的HTML片段
int indexBegin = htmlString.indexOf("<!DOCTYPE html>");
int indexEnd = htmlString.indexOf("</html>");
if (indexBegin != -1 && indexEnd != -1) {
try {
htmlString = htmlString.substring(indexBegin,indexEnd+7);
} catch (StringIndexOutOfBoundsException exception) {
htmlString = htmlString.substring(indexBegin);
}
}
//获取当前时间,我们可以在isv文件夹中根据时间来对相应的文件夹创建HTML文件
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String directoryName = simpleDateFormat.format(new Date());
//获取一个10位的随机文件名称
StringBuffer sb = new StringBuffer();
for (int i = 1 ; i<=10; i++) {
int ascii = 48+(int)(Math.random()*9);
char c = (char) ascii;
sb.append(c);
}
File directoryGetQing = new File(System.getProperty("JETTY_WEBRES_PATH")+"/isv/gptQing",directoryName);
//如果文件夹不存在就创建文件夹
if (!directoryGetQing.exists()) {
directoryGetQing.mkdirs();
}
File targetFile = new File(System.getProperty("JETTY_WEBRES_PATH")+"/isv/gptQing/"+directoryName,sb+".html");
if (!targetFile.exists()) {
try {
targetFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
//写入文件
byte[] bytes =htmlString.getBytes();
try {
FileOutputStream fos=new FileOutputStream(targetFile);
fos.write(bytes);
} catch (IOException e) {
e.printStackTrace();
}
//返回URL,其中gaiIframeSize={"height":380,"width":1000} 用于调整展示窗口宽高
result.put("htmlUrl" , System.getProperty("domain.contextUrl")+"/isv/gptQing/"+directoryName+"/"+sb+".html?"+"gaiIframeSize={"height":380,"width":1000}");
result.put("html", htmlString);
}
return result;
}
}
- 输出结果即可
以上就是结合gpt获取学生成绩分析图的具体步骤及实现 iframe结合gpt可以实现的功能有很多,具体的功能需要设计特定的gpt任务来实现