原创

springboot+springcloud+activiti6.0-modeler在线绘制遇到的问题

在现实项目中由于使用了springcloud中的zuul网关进行服务与服务直接的连接,通常在使用activiti-modeler在线绘制的时候一般都是这样写的,代码如下:
@GetMapping("/editor/{modelId}")
public void editor(HttpServletResponse response ,@PathVariable("modelId") String modelId) throws Exception
{
response.sendRedirect("/editor?modelId="+modelId);
}
@GetMapping("/editor")
public String editor()
{
return "modeler";
}
这样写如果用到网关后肯定是跳转不到这个页面的,因为重定向网之后,前面地址会变成网关的地址,比如网关地址是:http://localhost:8087 ,activiti的地址为:http://localhost:8080,如果请求在线绘制页面时请求地址为:http://loaclhost:8080/process/editor/xxxxxxxx 重定向后的地址为:http://localhost:8087/process/editor?modelId=xxxxxxxxx
所以获取不到对应的请求页面。

为了出现上述问题我们进行代码更改:
@GetMapping("/editor/{modelId}")
public String editor(@PathVariable("modelId") String modelId)
{
return "modeler";
}
并更改editor-app下的app.js
源代码如下:
$rootScope.$on('$includeContentLoaded', function (event) {
if (!$rootScope.editorInitialized) {

                ORYX._loadPlugins();

                var modelId = EDITOR.UTIL.getParameterByName('modelId');

                fetchModel(modelId);

                $rootScope.window = {};
                var updateWindowSize = function() {
                    $rootScope.window.width = $window.innerWidth;
                    $rootScope.window.height  = $window.innerHeight;
                };

                // Window resize hook
                angular.element($window).bind('resize', function() {
                    $rootScope.safeApply(updateWindowSize());
                });

他这种获取方法就是重定向后对应的参数是请求url中?modelId=之后的数据我们进行更改
var modelId = document.URL.toString().substring(document.URL.toString().lastIndexOf("/") + 1);
意思是从请求的URL中获取最后一个/后面的全部数据,这个得根据个人的程序来定。代码如下:
$rootScope.$on('$includeContentLoaded', function (event) {
if (!$rootScope.editorInitialized) {

                ORYX._loadPlugins();

                // var modelId = EDITOR.UTIL.getParameterByName('modelId');
                var modelId = document.URL.toString().substring(document.URL.toString().lastIndexOf("/") + 1);
                fetchModel(modelId);

                $rootScope.window = {};
                var updateWindowSize = function() {
                    $rootScope.window.width = $window.innerWidth;
                    $rootScope.window.height  = $window.innerHeight;
                };

                // Window resize hook
                angular.element($window).bind('resize', function() {
                    $rootScope.safeApply(updateWindowSize());
                });

                $rootScope.$watch('window.forceRefresh', function(newValue) {
                    if(newValue) {
                        $timeout(function() {
                            updateWindowSize();
                            $rootScope.window.forceRefresh = false;
                        });
                    }
                });

这样在去请求就OK了。

正文到此结束
本文目录