方法很多,只要不同时open、close都可行。给你一个简单的方式:
api.addEventListener({
name:'viewdisappear'
},function(){
api.closeWin({
name:api.winName
});
});
谢谢官方提供的方案,棒棒的!
使用场景,选择好友加入群组!
群生成之后,关闭选择页面!
titlebody{
}
取消
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: {
}
});
}
frm页面
content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0">
选择朋友.s_mapul {
position: absolute;
top: 0;
left: 0;
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;
}
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
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
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('创建失败');
}
});
}