ionic简单收藏功能

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”);
},

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值