apiCloud如何打开新页面的同时,关掉当前页-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

apiCloud如何打开新页面的同时,关掉当前页

简介:

方法很多,只要不同时open、close都可行。给你一个简单的方式:

     api.addEventListener({
         name:'viewdisappear'
     },function(){
         api.closeWin({
              name:api.winName
         });
     });

谢谢官方提供的方案,棒棒的!

使用场景,选择好友加入群组!
群生成之后,关闭选择页面!

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>title</title>
    <link rel="stylesheet" type="text/css" href="api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css"/>
    <style>
        body{

        }
    </style>
</head>
<body style="background: #eae6e6;">
<header class="aui-bar aui-bar-nav aui-margin-b-15" id="aui-header">
    <a class="aui-pull-left aui-btn" tapmode onclick="closeWin()">
        <span class="aui-iconfont aui-icon-left"></span>取消
    </a>
    <div class="aui-title">选择朋友</div>
    <a class="aui-pull-right aui-btn">
        <span class="aui-iconfont" style="color:#3F8A2C;" onclick="confirmChooseEvent();">确定</span>
    </a>
</header>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/message_common.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript">
    apiready = function () {
        fix_status_bar();
        var header_height = $api.dom("header").offsetHeight;

        api.openFrame({
            name: 'message_choose_friends_frm',
            url: 'message_choose_friends_frm.html',
            rect: {
                x: 0,
                y: header_height,
                w:'auto',           //宽度,若传'auto',页面从x位置开始自动充满父页面宽度
                h:api.winHeight - header_height            //高度,若传'auto',页面从y位置开始自动充满父页面高度
            },
            bgColor:'rgba(0,0,0,0)',
            bounces:false,
            vScrollBarEnabled:false,
            hScrollBarEnabled:false
        });

        // 监听页面消失的时候,关掉页面就可以了
        api.addEventListener({
            name:'viewdisappear'
        },function(){
            api.closeWin();
        });

    }
    
    function confirmChooseEvent() {
        api.sendEvent({
            name: 'confirmChooseEvent',
            extra: {
            }
        });
    }

</script>
</html>

frm页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
    <title>选择朋友</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css"/>
    <link rel="stylesheet" href="../css/message_style.css">
    <style>
        .s_mapul {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            max-height: 350px;
            overflow: scroll;
            background: #fff;
            overflow-y: auto;
        }

        .s_mapul li {
            border-bottom: 1px solid #ededed;
            padding: 0.3rem 5%;
            position: relative;
        }

        .s_mapul li h2 {
            font-size: 0.8rem;
        }

        .s_mapul li h2 img {
            position: absolute;
            right: 5%;
            height: 1rem;
        }

        .s_mapul li p {
            font-size: 0.6rem;
            color: #b0b0b0;
            margin-top: 0.2rem;
        }
    </style>
</head>
<body>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/message_common.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/convertPinyin.js"></script>
<script>
    var user;
    var UIListCheck;
    apiready = function () {
        fix_status_bar();
        user = $api.getStorage('user');

        // 监听页面关闭
        api.addEventListener({
            name: 'confirmChooseEvent'
        }, function (ret, err) {
            getSelectedSync();
        });

        api.ajax({
            url: BASE_URL_ACTION+'/RongCloud/GetFriends',
            method: 'post',
            data: {
                values: {
                    customerId: user.person_id,
                }
            }
        }, function (json, err) {
            if (json.result) {
                dealFriendsData(json.info,function(contacts) {
                    UIListCheck = api.require('UIListCheck');
                    UIListCheck.open({
                        rect: {
                            x: 0,
                            y: 22,
                            w: api.frameWidth,
                            h: api.frameHeight - 22
                        },
                        contacts: contacts,
                        fixedOn: 'message_choose_friends_frm'
                    }, function (ret) {
                        if (ret) {
                        }
                    });
                });
            } else {
                toast('获取好友数据失败');
            }
        });



    }

    function dealFriendsData(data,callback) {
        var contacts = [];
        for (var i=0;i<data.length;i++) {
            var item = {};
            item.employee_id = data[i].Id;
            item.remark = data[i].NickName;
            item.position = "";
            item.phonetic = convertPinyin(data[i].NickName);
            contacts[i] = item;
        }
        if (typeof callback == 'function') {
            callback(contacts);
        }
    }

    function getSelectedSync() {
        var ret = UIListCheck.getSelectedSync();
        var contacts = ret.contacts;
        if (contacts.length == 0) {
            toast('请选择好友');
            return;
        }

        var values = {
            systemName : 'yunlutong',
            customerId : user.person_id
        }

        for(var i = 0;i<contacts.length;i++) {
            var key='contactIds['+i+']';
            values[key]= contacts[i].employee_id;
        }
        
        api.ajax({
            url : BASE_URL_ACTION+'/RongCloud/AddGroup',
            method : 'post',
            data : {
                values : values
            }
        }, function(json, err) {
            if (json.result) {
                toast('创建成功');

                setTimeout(openChatPage('',json.groupid,0,'群聊','GROUP','index',''),500);

                // 本来想在这里处理的,发现不管用
            } else {
                toast('创建失败');
            }

        });


    }




</script>

</body>

</html>
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/7212227.html,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章