FineReport的决策平台提供了toast样式的自定义接口,方便进行多样化的定制开发,但是对于优秀toast样式的传播方式却没有提供好的方案。
依托于应用商店,FineReport V8.0(2016-04-29日之后的版本),提供了toast样式自定义插件的支持,这样就可以像开发插件一样开发toast样式了,同时可以在应用中心直接发布自己的toast样式插件。
前端:
为了能够使用自定义的toast样式,我们需要重写FR.Msg.toast方法。
(function ($) {
$.extend(FR.Msg, {
toast: function(message){
/*需要重写的toast方法*/
}
});
})(jQuery);
后台:
由于toast样式已经在内部生成了加载的逻辑,只要按照下方“插件内容”中的做法,不需要其他额外的后台接口就可以成功加载样式,所以后台不需要调用其它关键接口。
插件配置:
/*除了上述的style.js等文件,不需要实现其他接口*/
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.fr.fs.plugin.customstyle.toast.[(defined toast name)]</id>
<name><![CDATA[(plugin name)]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>8.0</env-version>
<jartime>2015-01-07</jartime>
<vendor>[(author name)]]</vendor>
<description><![CDATA[(plugin description)]]></description>
<change-notes><![CDATA[无]]></change-notes>
</plugin>
插件包定义:
plugin.xml内容:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.fs.plugin.customstyle.toast.[plugintest]</id>
<name><![CDATA[plugintest]]></name>
<active>yes</active>
<version>1.0</version>
<env-version>8.0</env-version>
<jartime>2015-01-07</jartime>
<vendor>[author name]]</vendor>
<description><![CDATA[plugin description]]></description>
<change-notes><![CDATA[无]]></change-notes>
</plugin>
ps: "[ ]"中内容都是可以自定义的
样式内容:
在这个包下新增style.css, style.js, cover.png, cover@2x.png这四个文件,内容的开发见自定义样式之toast示例
可以看到只要实现了接口的toast方法,并按照上述包名打包插件,就可以开发出来一个自定义样式toast插件了。开发好的插件可以上传到应用中心方便共享给所有的用户。
效果图
安装插件后,插件管理中心可以看到该插件
之后决策平台的管理员可以在平台的外观配置->信息提示中选择该toast样式,之后toast提示的样式就像下图这样了
源码
如果你希望查看完整的示例源码,可以看这里:http://cloud.finedevelop.com:2015/projects/PB/repos/plugin-toast_popup_right_r