目的:从消息进审批详情页面,审批完成后关闭webview窗口,回到消息界面的jsapi。
作用原理:
a、审批的详情链接中有source=message参数,此参数是用来标记是从消息进入,当点击审批同意之后会调用closeWindow ,方法,需要开发者在此方法实现关闭窗口或者回到详情的功能
b、不要用js中的跳转功能,因为跳转之后,在app上点击返回,会又回到移动审批的页面,移动审批的页面层级比较深,有的页面回退会导致报错
c、从审批列表中进入审批详情的时候没有source=message参数,移动审批已经实现了审批完回到审批列表的功能!
配置界面:
模板实例:
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() { tplData = tplData || {}; tplData.appbridge = tplData.appbridge || {}; tplData.appbridge.closeWindow = function() { setTimeout(function(){ //TODO 写入关闭窗口的jsapi },2000); }; });
------------------------------------------------------------------------------------------------------------------------------------
示例代码:
审批完,等两秒钟回到审批详情或回到列表方案:
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() { tplData = tplData || {}; tplData.appbridge = tplData.appbridge || {}; tplData.appbridge.closeWindow = function() { setTimeout(function(){ $.goBackToDetail();//回到详情 //$.goBackToList();//回到列表 },2000); }; });
------------------------------------------------------------------------------------------------------------------------------------
调用钉钉的关闭页面:
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() {
tplData = tplData || {};
tplData.appbridge = tplData.appbridge || {};
$script4 = $("<script />", {src: "https://g.alicdn.com/dingding/dingtalk-jsapi/2.6.41/dingtalk.open.js"});
$script4.appendTo($("body"));
$script4.on("load", function() {
try{
dd.ready(function() {
tplData.appbridge.closeWindow = function() {
setTimeout("loadzjlcClosing()", 100);
setTimeout(function(){
dd.biz.navigation.close();
},3000);
};
});
}catch(e){
alert("初始化钉钉失败");
}
});
})
function loadzjlcClosing() {
$.loading({text:"流程处理完成,等待同步..."});
}
$(window).on("load",function(e){
setTimeout(function(){
if(location.href.indexOf("process-list/index")>-1 && location.href.indexOf("#list=1") > -1){
window.history.back();
}
},15);
});
------------------------------------------------------------------------------------------------------------------------------------
蓝凌关闭回到会话页面
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() {
tplData = tplData || {};
tplData.appbridge = tplData.appbridge || {};
tplData.appbridge.closeWindow = function() {
if(document.referrer.indexOf("&_mobile=")!=-1){ //从web列表进入,会带_mobile参数,这种情况,不能关闭webview,直接调用返回
$.goBackToList && $.goBackToList();
}else{
Was.exec('app', 'exitApp', {});
}
};
});
------------------------------------------------------------------------------------------------------------------------------------
云之家关闭回到会话页面
------------------------------------------------------------------------------------------------------------------------------------
(function(){if(window.XuntongJSBridge){return};var _CUSTOM_PROTOCOL_SCHEME='xuntong',callbacksCount=1,callbacks={};function _handleMessageFromXT(callbackId,message){try{var callback=callbacks[callbackId];if(!callback)return;callback.apply(null,[message])}catch(e){alert(e)}}function _call(functionName,message,callback){var hasCallback=callback&&typeof callback=="function";var callbackId=hasCallback?callbacksCount++:0;if(hasCallback)callbacks[callbackId]=callback;var iframe=document.createElement("IFRAME");iframe.setAttribute("src",_CUSTOM_PROTOCOL_SCHEME+":"+functionName+":"+callbackId+":"+encodeURIComponent(JSON.stringify(message)));iframe.setAttribute("height","1px");iframe.setAttribute("width","1px");document.documentElement.appendChild(iframe);iframe.parentNode.removeChild(iframe);iframe=null}var __XuntongJSBridge={invoke:_call,call:_call,handleMessageFromXT:_handleMessageFromXT};window.XuntongJSBridge=__XuntongJSBridge})(); mysoft.prepare(function() { tplData = tplData || {}; tplData.appbridge = tplData.appbridge || {}; tplData.appbridge.closeWindow = function() { XuntongJSBridge.call('close'); }; })
------------------------------------------------------------------------------------------------------------------------------------
消息关闭窗口,列表回到固定的第三方OA待办列表
------------------------------------------------------------------------------------------------------------------------------------
//在详情页面记录来源 var locationHref = location.href; if (locationHref.indexOf("process-detail/index") > -1) { var refrrer = document.referrer; var source = ''; if (refrrer !== '') { //来源是H5列表 source = 'list'; } else { //来源是消息 source = 'message'; } localStorage.setItem("mysoft_source", source); } mysoft.prepare(function() { tplData = tplData || {}; tplData.appbridge =tplData.appbridge|| {}; tplData.appbridge.closeWindow = function() { setTimeout( function() { $.loading.close(); //审批结束后根据来源进行跳转 var mysoft_source = localStorage.getItem("mysoft_source"); if (mysoft_source == 'list') { //返回到列表,调用工作流的返回列表接口 $.goBackToList(); } if (mysoft_source == 'message') { //返回到详情,调用工作流的返回详情接口 //此处实现关闭方法; } }, 1500 ); }; });
------------------------------------------------------------------------------------------------------------------------------------
钉钉APP专用,使用的第三方待办中心消息关闭窗口,列表回到固定的第三方OA待办列表
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() { tplData = tplData || {}; tplData.appbridge = tplData.appbridge || {}; $script4 = $("<script/>", {src: "https://g.alicdn.com/dingding/dingtalk-jsapi/2.6.41/dingtalk.open.js"}); $script4.appendTo($("body")); $script4.on("load", function() { try{ dd.ready(function() { tplData.appbridge.closeWindow = function() { setTimeout("loadzjlcClosing()", 100); setTimeout(function(){ if(window.dd && !window.dd.pc){ dd.biz.navigation.replace({ url: '跳转地址',// 新的页面链接 onSuccess : function(result) {}, onFail : function(err) {} }); }else{ //解决pc不能跳转的问题 dd.biz.navigation.setTitle({title:'地址标题'}); location.href='跳转地址'; } },3000); }; }); }catch(e){ alert("初始化钉钉失败"); } }); }) function loadzjlcClosing() { $.loading({text:"流程处理完成,等待同步..."}); } $(window).on("load",function(e){ setTimeout(function(){ if(location.href.indexOf("process-list/index")>-1 && location.href.indexOf("#list=1") > -1){ window.history.back(); } },15); });
------------------------------------------------------------------------------------------------------------------------------------
致远APP专用,使用的第三方待办中心消息关闭窗口
------------------------------------------------------------------------------------------------------------------------------------
mysoft.prepare(function() { var cmpshell = navigator.userAgent.indexOf('seeyonCordova') > -1;//CMP壳 var cordovaUrl= "https://cmp/v/js/cordova/__CMPSHELL_PLATFORM__/cordova.js"; var cordovaPluginUrl = "https://cmp/v/js/cordova/cordova-plugins.js"; var m3CMP = "https://cmp/v/js/cmp.js"; //M3的CMP var i18nJS = "https://cmp/v/js/cmp-i18n.js"; //CMP的国际化文件 var web="https://cmp/v/js/cmp-webviewListener.js"; appenScript(i18nJS,function onload(e){ //CMP壳加载cordova appenScript(cordovaUrl,function onload(e){ appenScript(cordovaPluginUrl,function onload(e){ appenScript(m3CMP,function onload(e){ appenScript(web,function onload(e){ init(); },function onerror(e){ alert(JSON.stringify(e)) }); },function onerror(e){ alert(JSON.stringify(e)) }); },function onerror(e){ alert(JSON.stringify(e)) }); },function onerror(e){ alert(JSON.stringify(e)) }); },function onerror(e){ alert(JSON.stringify(e)) }); function appenScript(url,onload,onerror){ var script = document.createElement("script"); script.src = url; script.onload=onload; script.onerror=onerror; document.head.appendChild(script); } function init(){ //使用CMP方法 try { tplData = tplData || {}; tplData.appbridge = tplData.appbridge || {}; cmp.navigation.setCloseButtonDisplay = function(){ return true; } tplData.appbridge.closeWindow = function() { cmp.ready(function(){ //触发删除缓存 cmp.event.trigger("deletesessioncache", document); if(cmp.platform.CMPShell){ //触发平台事件,用于刷新列表数据 cmp.webViewListener.fire({ type: "com.seeyon.m3.ListRefresh", data: {type: 'update'} }); cmp.webViewListener.fire({ type: "coll.ListRefresh", data: {refreshList: 'true'} }); //触发cap4列表刷新监听 cmp.href.notify('cap4.todoListRefresh', {refreshList: 'true'}); }//调用刷新列表 //处理提交的逻辑 cmp.href.closePage();//==================================>调用关闭webview的函数 }); }; } catch (e) { alert(e); } }; })
注意点:
1、我们是https站点,不能引用http的js,请把js放在配置里面
2、测试链接:http://{环境的域名}/{租户的tenant_id}/demo/clx/html?__from={erpapijc},把变量替换成真实的信息后,可以把此链接当做消息发送给第三方,从第三方打开后可以在页面中看到“审批提交按钮”,点击此按钮就是模拟审批中“同意“的事件,用来调试跳转 问题
作者: 初良祥 日期: 2020-11-30