Kaynağa Gözat

Merge branch 'fix/qywx_start_process_bug' into 'develop'

企业微信启动支持草稿模式

See merge request o2oa/o2oa!542
胡起 5 yıl önce
ebeveyn
işleme
7ad45732d3

+ 26 - 10
o2web/source/x_component_process_Xform/Form.js

@@ -279,8 +279,12 @@ MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
 
         if (this.json.mode === "Mobile") {
             var node = document.body.getElement(".o2_form_mobile_actions");
-            //if (node)
-            this._loadMobileActions(node, callback);
+            if (node) {
+                node.empty();
+                this._loadMobileActions(node, callback);
+            }else {
+                console.log("没有找到移动端底部操作栏!")
+            }
         } else {
             if (callback) callback();
         }
@@ -606,7 +610,7 @@ MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
             flag = flag && (!hideFlag);
         }
         if (tool.id == "action_processWork") {
-            if (!this.businessData.task) {
+            if (!this.businessData.task && this.businessData.work.startTime) {
                 flag = false;
             }
         }
@@ -1127,8 +1131,12 @@ MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
                 this.app.options.draftId = json.data.work.id;
                 this.app.options.desktopReload = true;
 
-                this.app.appId = "process.Work" + json.data.work.id,
+                this.app.appId = "process.Work" + json.data.work.id;
+                if(layout.desktop.apps) {
                     delete layout.desktop.apps[this.app.options.appId];
+                }else {
+                    layout.desktop.apps = {};
+                } 
                 layout.desktop.apps[this.app.appId] = this.app;
 
                 if (callback) callback();
@@ -1633,12 +1641,19 @@ MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
         this.saveFormData(function () {
             this.workAction.startDraft(this.businessData.work.id, function (json) {
                 this.app.options.workId = json.data[0].work;
-                var msg = {
-                    "subject": MWF.xApplication.process.Xform.LP.processStarted,
-                    "content": "<div>" + MWF.xApplication.process.Xform.LP.processStartedMessage + "“[" + json.data[0].processName + "]" + (this.businessData.data.title || this.businessData.data.subject) + "”</div>"
-                };
-                var tooltip = layout.desktop.message.addTooltip(msg);
-                var item = layout.desktop.message.addMessage(msg);
+                if (layout.mobile) {
+                    if(layout.notice) {
+                        layout.notice(MWF.xApplication.process.Xform.LP.processStartedMessage + "“[" + json.data[0].processName + "]" + (this.businessData.data.title || this.businessData.data.subject));
+                    }
+                }else {
+                    var msg = {
+                        "subject": MWF.xApplication.process.Xform.LP.processStarted,
+                        "content": "<div>" + MWF.xApplication.process.Xform.LP.processStartedMessage + "“[" + json.data[0].processName + "]" + (this.businessData.data.title || this.businessData.data.subject) + "”</div>"
+                    };
+                    var tooltip = layout.desktop.message.addTooltip(msg);
+                    var item = layout.desktop.message.addMessage(msg);
+                }
+                
 
                 this.app.reload();
 
@@ -1690,6 +1705,7 @@ MWF.xApplication.process.Xform.Form = MWF.APPForm = new Class({
 
     processWork: function () {
         var _self = this;
+        debugger;
         if (!this.businessData.work.startTime) {
             this.startDraftProcess();
         } else if( this.json.submitFormType === "select" ){

+ 4 - 0
o2web/source/x_desktop/js/base_simple.js

@@ -308,6 +308,10 @@ o2.addReady(function () {
             window.location = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
         } else if (options.workCompletedId) {
             window.location = "workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
+        }else if (options.draft){
+            window.location = "workmobilewithaction.html?draft=" + JSON.stringify(options.draft) + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
+        }else {
+            console.log("open work 错误,缺少参数!");
         }
     };
     var _openWork = function (options) {

+ 145 - 235
o2web/source/x_desktop/js/qywxStartProcess.js

@@ -1,259 +1,169 @@
-layout = window.layout || {};
-var locate = window.location;
-layout.protocol = locate.protocol;
-var href = locate.href;
-if (href.indexOf("debugger") != -1) layout.debugger = true;
-layout.desktop = layout;
-layout.session = layout.session || {};
-o2.xApplication = o2.xApplication || {};
 
-(function (layout) {
-    var _requireApp = function (appNames, callback, clazzName) {
-        var appPath = appNames.split(".");
-        var baseObject = o2.xApplication;
-        appPath.each(function (path, i) {
-            if (i < (appPath.length - 1)) {
-                baseObject[path] = baseObject[path] || {};
-            } else {
-                baseObject[path] = baseObject[path] || { "options": Object.clone(o2.xApplication.Common.options) };
-            }
-            baseObject = baseObject[path];
-        }.bind(this));
-        if (!baseObject.options) baseObject.options = Object.clone(o2.xApplication.Common.options);
 
-        var _lpLoaded = false;
-        o2.xDesktop.requireApp(appNames, "lp." + o2.language, {
-            "failure": function () {
-                o2.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
-            }.bind(this)
-        }, false);
-
-        o2.xDesktop.requireApp(appNames, clazzName, function () {
-            if (callback) callback(baseObject);
+layout.addReady(function(){
+    //重写 base_simple.js中的方法 这里是单点登录企业微信
+    layout.openLogin = function () {
+        console.log("开始login。。。。。。。。。。。。。");
+        var uri = locate.href.toURI();
+        var redirect = uri.getData("redirect");
+        var processId = uri.getData("processId");
+        var applicationId = uri.getData("appId");
+        MWF.require("MWF.xDesktop.Actions.RestActions", function () {
+            console.log("执行单点。。。。。。。。。。");
+            var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
+            action.getActions = function (actionCallback) {
+                this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
+                if (actionCallback) actionCallback();
+            };
+            action.invoke({
+                "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
+                    console.log("单点成功。");
+                    console.log(json);
+                    //基础数据。。。。
+                    layout.session.user = json.data;
+                    layout.content = $(document.body);
+                    layout.app = layout;
+
+                    //开始启动
+                    layout.startProcess(applicationId, processId, redirect);
+                }.bind(this), "failure": function (xhr, text, error) {
+                    var n = document.getElementById("loaddingArea");
+                    if (n) { n.destroy(); }
+                    document.id("layout").set("html", "<div>企业微信单点异常!</div>")
+                }.bind(this)
+            });
         });
     };
 
-    var _createNewApplication = function (e, appNamespace, appName, options, statusObj) {
-        var app = new appNamespace["Main"](layout, options);
-        app.desktop = layout;
-        app.inBrowser = true;
-        app.status = statusObj;
-
-        app.load(true);
+    layout.startProcess = function (appId, pId, redirect) {
+        console.log("开始startProcess。。。。。。。。");
+        console.log(appId);
+        console.log(pId);
+        MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(pId, appId, function (json) {
+
+            if (json.data) {
+                MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
+                    var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, layout.app, {
+                        "workData": {},
+                        "identity": null,
+                        "latest": false,
+                        "onStarted": function (data, title, processName) {
+                            console.log("进入 onStarted。。。。");
+                            debugger;
+                            if (data.work){
+                                layout.startProcessDraft(data, title, processName, redirect);
+                            }else{
+                                layout.startProcessInstance(data, title, processName, redirect);
+                            }
+                            
+                        }.bind(this)
 
-        var appId = appName;
-        if (options.appId) {
-            appId = options.appId;
-        } else {
-            if (appNamespace.options.multitask) appId = appId + "-" + (new o2.widget.UUID());
-        }
-        app.appId = appId;
-        layout.app = app;
-        layout.desktop.currentApp = app;
-
-        var mask = document.getElementById("appContentMask");
-        if (mask) mask.destroy();
-    };
-    var _openWorkHTML = function (options) {
-        var uri = new URI(window.location.href);
-        var redirectlink = uri.getData("redirectlink");
-        if (!redirectlink) {
-            redirectlink = encodeURIComponent(locate.pathname + locate.search);
-        } else {
-            redirectlink = encodeURIComponent(redirectlink);
-        }
-        if (options.workId) {
-            window.location = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
-        } else if (options.workCompletedId) {
-            window.location = "workmobilewithaction.html?workcompletedid=" + options.workCompletedId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirectlink;
-        }
+                    });
+                    var mask = document.getElementById("loaddingArea");
+                    if (mask) mask.destroy();
+                    starter.load();
+                }.bind(this));
+            }
+        }.bind(this));
     };
 
-    layout.openApplication = function (e, appNames, options, statusObj) {
-        if (layout.app) {
-            if (layout.mobile) {
-                _openWorkHTML(options, statusObj);
-            } else {
-                var par = "app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent((statusObj) ? JSON.encode(statusObj) : "") + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
+    layout.startProcessDraft = function(data, title, processName, redirect){
+        console.log("草稿模式。。。。");
+        console.log(data);
+        o2.require("o2.widget.UUID", function () {
+            var work = data.work;
+            var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
+            //先修改当前url为配置的门户地址
+            if (redirect) {
+                history.replaceState(null, "startProcess", redirect);
 
-                if (layout.app.$openWithSelf) {
-                    return window.location = "app.html?" + par + ((layout.debugger) ? "&debugger" : "");
-                } else {
-                    return window.open("app.html?" + par + ((layout.debugger) ? "&debugger" : ""), par);
-                }
+            } else {
+                history.replaceState(null, "startProcess", "/x_desktop/appMobile.html?app=process.TaskCenter");
+                
             }
-        } else {
-            var appPath = appNames.split(".");
-            var appName = appPath[appPath.length - 1];
             debugger;
-            _requireApp(appNames, function (appNamespace) {
-                _createNewApplication(e, appNamespace, appName, options, statusObj);
-            }.bind(this));
-        }
+            // layout.openApplication(null, "process.Work", options);
+            layout.openWorkIn(options);
+        });
+        
     };
-})(layout);
-
-o2.addReady(function () {
-    o2.load(["../o2_lib/mootools/plugin/mBox.Notice.js", "../o2_lib/mootools/plugin/mBox.Tooltip.js"], { "sequence": true }, function () {
-        MWF.loadLP("zh-cn");
-        MWF.require("MWF.widget.Common", null, false);
-        MWF.require("MWF.xDesktop.Common", null, false);
-        MWF.require("MWF.xAction.RestActions", null, false);
-        MWF.require("MWF.xDesktop.Authentication", null, false);
-        MWF.require("MWF.xDesktop.Layout", function () {
-
-            (function () {
-                layout.load = function () {
-                    var uri = href.toURI();
-                    var redirect = uri.getData("redirect");
-                    var processId = uri.getData("processId");
-                    var applicationId = uri.getData("appId");
-
-                    layout.isAuthentication(function () {
-                        //开始启动
-                        layout.startProcess(applicationId, processId, redirect);
-                    }, function(){
-                        MWF.require("MWF.xDesktop.Actions.RestActions", function () {
-                            var action = new MWF.xDesktop.Actions.RestActions("", "x_organization_assemble_authentication", "");
-                            action.getActions = function (actionCallback) {
-                                this.actions = { "sso": { "uri": "/jaxrs/qiyeweixin/code/{code}", "method": "GET" } };
-                                if (actionCallback) actionCallback();
-                            };
-                            action.invoke({
-                                "name": "sso", "async": true, "parameter": { "code": uri.getData("code") }, "success": function (json) {
-                                    //基础数据。。。。
-                                    layout.session.user = json.data;
-                                    layout.content = $(document.body);
-                                    layout.app = layout;
-
-                                    //开始启动
-                                    layout.startProcess(applicationId, processId, redirect);
-                                }.bind(this), "failure": function (xhr, text, error) {
-                                    var n = document.getElementById("loaddingArea");
-                                    if (n) { n.destroy(); }
-                                    document.id("layout").set("html", "<div>企业微信单点异常!</div>")
-                                }.bind(this)
-                            });
-                        });
-                    });
-                };
-
-                layout.startProcess = function (appId, pId, redirect) {
-                    MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(pId, appId, function (json) {
-
-                        if (json.data) {
-                            MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
-                                var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, layout.app, {
-                                    "workData": {},
-                                    "identity": null,
-                                    "latest": false,
-                                    "onStarted": function (data, title, processName) {
-
-                                        debugger;
-                                        var currentTask = [];
-                                        data.each(function (work) {
-                                            if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
-                                        }.bind(this));
-
-                                        if (currentTask.length == 1) {
-                                            var options = { "workId": currentTask[0], "appId": currentTask[0] };
+    layout.startProcessInstance = function(data, title, processName, redirect){
+        console.log("实例模式。。。。");
+        console.log(data);
+        var currentTask = [];
+        data.each(function (work) {
+            if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
+        }.bind(this));
 
-                                            //先修改当前url为配置的门户地址
-                                            if (redirect) {
-                                                history.replaceState(null, "startProcess", redirect);
-                                                // var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=" + redirect;
-                                                // workUrl.toURI().go();
+        if (currentTask.length == 1) {
+            var options = { "workId": currentTask[0], "appId": currentTask[0] };
 
-                                            } else {
-                                                history.replaceState(null, "startProcess", "/x_desktop/appMobile.html?app=process.TaskCenter");
-                                                // var workUrl = "workmobilewithaction.html?workid=" + options.workId + ((layout.debugger) ? "&debugger" : "") + "&redirectlink=appMobile.html%3Fapp%3Dprocess.TaskCenter";
-                                                // workUrl.toURI().go();
-                                            }
-                                            // layout.app = null;
-                                            layout.openApplication(null, "process.Work", options);
-                                        } else { }
+            //先修改当前url为配置的门户地址
+            if (redirect) {
+                history.replaceState(null, "startProcess", redirect);
 
-                                    }.bind(this)
+            } else {
+                history.replaceState(null, "startProcess", "/x_desktop/appMobile.html?app=process.TaskCenter");
+            }
 
-                                });
-                                var mask = document.getElementById("loaddingArea");
-                                if (mask) mask.destroy();
-                                starter.load();
-                            }.bind(this));
-                        }
-                    }.bind(this));
-                };
+            // layout.openApplication(null, "process.Work", options);
+            layout.openWorkIn(options);
 
-                layout.isAuthentication = function (callback, failure) {
-                    layout.authentication = new MWF.xDesktop.Authentication({
-                        "onLogin": layout.load.bind(layout)
-                    });
+        } else { }
+    };
+    layout.openWorkIn =  function(options){
+        o2.requireApp("Common", "", function() {
+            var uri = new URI(window.location.href);
+            var redirectlink = uri.getData("redirectlink");
+            if (!redirectlink) {
+                redirectlink = encodeURIComponent(locate.pathname + locate.search);
+            } else {
+                redirectlink = encodeURIComponent(redirectlink);
+            }
+            var appName="process.Work", m_status=null;
+            options.redirectlink = redirectlink; 
+            layout.app = null;//创建工作界面
+            layout.openApplication(null, appName, options, m_status);
+        }, true);
+    };
+    layout.notice = function (content, type, target, where, offset) {
+        if (!where) where = { "x": "right", "y": "top" };
+        if (!target) target = this.content;
+        if (!type) type = "ok";
+        var noticeTarget = target || $(document.body);
+        var off = offset;
+        if (!off) {
+            off = {
+                x: 10,
+                y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
+            };
+        }
 
-                    // var returnValue = true;
-                    this.authentication.isAuthenticated(function (json) {
-                        if (json.data.tokenType != "anonymous") {
-                            //基础数据。。。。
-                            layout.session.user = json.data;
-                            layout.content = $(document.body);
-                            layout.app = layout;
-                            if (callback) callback();
-                        } else {
-                            // returnValue = false;
-                            if (failure) failure();
-                        }
-                    }.bind(this), function () {
-                        // returnValue = false;
-                        if (failure) failure();
-                    }.bind(this));
-                    // console.log("back................."+returnValue);
-                    // return returnValue;
-                };
+        new mBox.Notice({
+            type: type,
+            position: where,
+            move: false,
+            target: noticeTarget,
+            delayClose: (type == "error") ? 10000 : 5000,
+            offset: off,
+            content: content
+        });
+    };
 
+    (function(layout){
+        console.log("开始执行。。。。。。。。");
+        var uri = locate.href.toURI();
+        var redirect = uri.getData("redirect");
+        var processId = uri.getData("processId");
+        var applicationId = uri.getData("appId");
+        console.log(uri);
+        layout.content = $(document.body);
+        layout.app = layout;
+        layout.startProcess(applicationId, processId, redirect);
+     })(layout);
+});
 
-                layout.notice = function (content, type, target, where, offset) {
-                    if (!where) where = { "x": "right", "y": "top" };
-                    if (!target) target = this.content;
-                    if (!type) type = "ok";
-                    var noticeTarget = target || $(document.body);
-                    var off = offset;
-                    if (!off) {
-                        off = {
-                            x: 10,
-                            y: where.y.toString().toLowerCase() == "bottom" ? 10 : 10
-                        };
-                    }
 
-                    new mBox.Notice({
-                        type: type,
-                        position: where,
-                        move: false,
-                        target: noticeTarget,
-                        delayClose: (type == "error") ? 10000 : 5000,
-                        offset: off,
-                        content: content
-                    });
-                };
 
-                MWF.getJSON("res/config/config.json", function (config) {
-                    layout.config = config;
-                    MWF.xDesktop.getServiceAddress(layout.config, function (service, center) {
-                        layout.serviceAddressList = service;
-                        layout.centerServer = center;
-                        layout.load();
-                    }.bind(this));
-                });
 
-                window.addEventListener('popstate', function (event) {
-                    debugger
-                    var ua = navigator.userAgent.toLowerCase()
-                    var isiOS = /(iPhone|iPad|iPod|iOS)/i.test(ua)
-                    if (isiOS) {
-                        console.log("is IOs");
-                        window.location.reload();
-                    }
-                }.bind(this));
-            })();
-        });
-    });
-});
 

+ 1 - 0
o2web/source/x_desktop/qywxstartprocess.html

@@ -10,6 +10,7 @@
     <script src="../o2_core/o2.min.js"></script>
     <script src="../o2_core/compatible.min.js"></script>
     <script src="../o2_lib/Decimal.js"></script>
+    <script src="js/base.min.js"></script>
     <script src="js/qywxStartProcess.min.js"></script>
     <script>layout.mobile = true;</script>