html页面按钮里面写上: on-tap=“myCollection()”
controller:
controller:注入:$scope, $rootScope, GSSGlobal, $ionicPopup, $ionicHistory, $stateParams, guideDetailServices, $ionicLoading, $ionicActionSheet
// 接收参数
$scope.BSZNID =
s
t
a
t
e
P
a
r
a
m
s
.
B
S
Z
N
I
D
;
c
o
n
s
o
l
e
.
l
o
g
(
stateParams.BSZNID; console.log(
stateParams.BSZNID;console.log(stateParams)
var id = $scope.BSZNID;
$ionicLoading.show();
guideDetailServices.guideDetail(id).then(function (info) {
$ionicLoading.hide();
s
c
o
p
e
.
g
u
i
d
e
D
e
t
a
i
l
=
i
n
f
o
.
D
a
t
a
.
d
a
t
a
;
/
/
当
登
录
后
,
里
面
有
值
,
跳
转
函
数
i
f
(
scope.guideDetail = info.Data.data; //当登录后,里面有值,跳转函数 if (
scope.guideDetail=info.Data.data;//当登录后,里面有值,跳转函数if(stateParams.isCollect) {
addCollect();
}
});
//收藏
$scope.myCollection = function() {
$ionicActionSheet.show({
buttons:[
{text:‘收藏’}
],
cancelText:‘取消’,
buttonClicked:function(index) {
switch(index) {
case 0:
//判断是否是登录状态
if(!GSSGlobal.userInfo.id) {
//确认对话框
var confirmPopup = $ionicPopup.confirm({
title:‘提示信息’,
template:‘您还未登录,继续收藏请按确认进行登录’,
cancelText: “取消”,
okText: “确认”
});
//进行登录操作
confirmPopup.then(function(res) {
if(res) {
//登录后页面跳转的url,在state里面的url后面加上/:isCollect
GSSGlobal.loginSucJump = location.hash + “1”;
//登录
GSSGlobal.login();
}else {
}
});
} else {
addCollect()
}
break;
}
//return 为true时,上拉菜单关闭
return true;
}
})
};
function addCollect() {
//收藏页面的标题
var name =
s
c
o
p
e
.
m
a
n
y
R
u
l
e
A
n
d
O
n
e
D
e
t
a
i
l
.
I
T
E
M
N
A
M
E
;
/
/
页
面
地
址
v
a
r
u
r
l
=
l
o
c
a
t
i
o
n
.
h
a
s
h
;
i
f
(
scope.manyRuleAndOneDetail.ITEMNAME; //页面地址 var url = location.hash; if(
scope.manyRuleAndOneDetail.ITEMNAME;//页面地址varurl=location.hash;if(stateParams.isCollect) {
url = url.substr(0,url.length - 1);
}
//加载动作
GSSGlobal.showLoading();
debugger;
//往service传值,
guideMoreRuleAndOneServices.addCollection(name, url, GSSGlobal.userInfo.id).then(function(info) {
GSSGlobal.hideLoading();
//传值成功对返回值进行判断,true便成功
if(info.Data && info.Data.collectionId) {
$rootScope.ShowAlert(‘收藏成功’);
}
}, function(err) {
GSSGlobal.hideLoading();
})
}
services:按照接口的参数和controller传值对应,userId:id,不能写死
//新增个人收藏
addMyCollection: function (name, url, id) {
return $LibExcuteProc.ExcuteProc(“GSSPersonalCollectionApi/PersonalCollectionReg”, {
collectionName: name,
url: url,
type: 0,
userId: id
}, “POST”);
},