Commit 1ab32e11 by houweibin

1,API缓存 (品牌商品列表页面,分类页面,首页,博客列表,所有品牌)

2,Moncler商品详情显示 contact us 按钮
3,去掉商品详情页面图片的自动滚动
4,其他
parent 2e8141bf
......@@ -242,6 +242,8 @@
C066650C1D75A2E500F02EF4 /* Mine.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C06665081D75A2E500F02EF4 /* Mine.storyboard */; };
C066650F1D7675FC00F02EF4 /* KWMAboutUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */; };
C06665121D767A0A00F02EF4 /* KWMContactUsVC.m in Sources */ = {isa = PBXBuildFile; fileRef = C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */; };
C06F5D811FBA9381005BC5AF /* CacheKeyConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */; };
C06F5D841FBAA5D0005BC5AF /* KWMPPCacheUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */; };
C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */; };
C07267851F1616E500C5A869 /* KWMColor.m in Sources */ = {isa = PBXBuildFile; fileRef = C07267841F1616E500C5A869 /* KWMColor.m */; };
C077966F1EEAA2BE00CD6859 /* KWMFilterUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = C077966E1EEAA2BE00CD6859 /* KWMFilterUtil.m */; };
......@@ -797,6 +799,10 @@
C066650E1D7675FC00F02EF4 /* KWMAboutUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMAboutUsVC.m; sourceTree = "<group>"; };
C06665101D767A0A00F02EF4 /* KWMContactUsVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMContactUsVC.h; sourceTree = "<group>"; };
C06665111D767A0A00F02EF4 /* KWMContactUsVC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KWMContactUsVC.m; sourceTree = "<group>"; };
C06F5D7F1FBA9381005BC5AF /* CacheKeyConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CacheKeyConstants.h; sourceTree = "<group>"; };
C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CacheKeyConstants.m; sourceTree = "<group>"; };
C06F5D821FBAA5D0005BC5AF /* KWMPPCacheUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KWMPPCacheUtil.h; sourceTree = "<group>"; };
C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KWMPPCacheUtil.m; sourceTree = "<group>"; };
C07267801F15D62400C5A869 /* NSLayoutConstraint+Multiplier.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSLayoutConstraint+Multiplier.h"; sourceTree = "<group>"; };
C07267811F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSLayoutConstraint+Multiplier.m"; sourceTree = "<group>"; };
C07267831F1616E500C5A869 /* KWMColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KWMColor.h; sourceTree = "<group>"; };
......@@ -1295,6 +1301,8 @@
C034E68E1D6AEB12006EE129 /* main.m */,
C034E6E91D6AF0A0006EE129 /* Header-Prefix.h */,
C034E6EA1D6AF0A0006EE129 /* Localizable.strings */,
C06F5D7F1FBA9381005BC5AF /* CacheKeyConstants.h */,
C06F5D801FBA9381005BC5AF /* CacheKeyConstants.m */,
);
name = "Supporting Files";
sourceTree = "<group>";
......@@ -1489,6 +1497,8 @@
9B8298E21EF22BE200743438 /* KWMCurrencyUtil.m */,
C03120AE1EF2B26B00E49EFA /* KWMPayUtil.h */,
C03120AF1EF2B26B00E49EFA /* KWMPayUtil.m */,
C06F5D821FBAA5D0005BC5AF /* KWMPPCacheUtil.h */,
C06F5D831FBAA5D0005BC5AF /* KWMPPCacheUtil.m */,
);
path = Util;
sourceTree = "<group>";
......@@ -2516,7 +2526,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
F84386F9A53E1205C21D5570 /* [CP] Copy Pods Resources */ = {
......@@ -2585,6 +2595,7 @@
C0028EC51F0DD19C00744C14 /* KWMAdditionalResult.m in Sources */,
C03943C01DD1FCE900141475 /* KWMProductType.m in Sources */,
C0CC140C1D7829FC007B5986 /* KWMSelectSizeVC.m in Sources */,
C06F5D841FBAA5D0005BC5AF /* KWMPPCacheUtil.m in Sources */,
C00D40971F187CAB00DEA685 /* KWMCategoryTitleView.m in Sources */,
C034E7B31D6AFC3B006EE129 /* KWMMainVC.m in Sources */,
C08FDA2A1D9B583400EBDB0D /* KWMGiftCardVC.m in Sources */,
......@@ -2776,6 +2787,7 @@
C034E7C21D6B0B62006EE129 /* KWMMineVC.m in Sources */,
DA8D64121F31C67F00B8F4A6 /* DeepLinkURLProtocol.m in Sources */,
C08FDA271D9A5F3400EBDB0D /* KWMAddGiftCardVC.m in Sources */,
C06F5D811FBA9381005BC5AF /* CacheKeyConstants.m in Sources */,
C07267821F15D62400C5A869 /* NSLayoutConstraint+Multiplier.m in Sources */,
C02C7D9E1E643323008DC29C /* KWMShareVC.m in Sources */,
C034E68F1D6AEB12006EE129 /* main.m in Sources */,
......
//
// CacheKeyConstants.h
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
/** 此文件存放缓存时用到的key **/
extern NSString *const CACHE_KEY_FAIL_HINT;
extern NSString *const CACHE_KEY_SDK_getProductsPage;
extern NSString *const CACHE_KEY_getHomeDataWithSuccess;
extern NSString *const CACHE_KEY_SDK_getCollectionByHandle;
extern NSString *const CACHE_KEY_SDK_getCollectionByHandle_getProductsPage;
//
// CacheKeyConstants.m
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
NSString *const CACHE_KEY_FAIL_HINT = @"网络已断开,请重新连接";
NSString *const CACHE_KEY_SDK_getCollectionByHandle = @"MobileSDK-getCollectionByHandle";
NSString *const CACHE_KEY_SDK_getCollectionByHandle_getProductsPage = @"MobileSDK-getCollectionByHandle_getProductsPage";
NSString *const CACHE_KEY_SDK_getProductsPage = @"MobileSDK-getProductsPage";
NSString *const CACHE_KEY_getHomeDataWithSuccess = @"getHomeDataWithSuccess";
......@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import "AFNetworking.h"
#import <PPNetworkHelper/PPNetworkHelper.h>
#import "KWMRequestListResult.h"
#import "KWMRequestResult.h"
#import "KWMCemaroseResult.h"
......@@ -145,6 +146,7 @@
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) getAllBrand:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBrandsResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBrandsResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
......@@ -162,6 +164,7 @@
* @return NSURLSessionDataTask
*/
- (NSURLSessionDataTask *) getAllBlog:(NSDictionary *)parameters
cacheCallback:(void(^)(KWMBlogResult *result))cacheCallback
success:(void(^)(NSURLSessionDataTask *task,KWMBlogResult *result))success
failure:(void(^)(NSURLSessionDataTask *task,NSError *error))failure;
- (NSURLSessionDataTask *) getAllPage:(NSDictionary *)parameters
......
......@@ -128,17 +128,25 @@
<constraint firstAttribute="height" constant="30" id="HK4-OE-vEa"/>
</constraints>
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kkz-NK-BGC">
<rect key="frame" x="0.0" y="0.0" width="375" height="64"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="bottom" secondItem="IcS-3H-XUB" secondAttribute="bottom" id="0j4-ln-dzu"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="zpX-41-Ngk" secondAttribute="top" constant="64" id="1ku-fw-1rl"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="6iQ-dc-23W" secondAttribute="bottom" constant="44" id="5UQ-kj-JaO"/>
<constraint firstAttribute="trailing" secondItem="kkz-NK-BGC" secondAttribute="trailing" id="5Z1-ce-Sci"/>
<constraint firstAttribute="trailing" secondItem="evT-5t-rty" secondAttribute="trailing" id="67h-A6-5jJ"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="top" secondItem="kkz-NK-BGC" secondAttribute="bottom" id="7mJ-4u-nZA"/>
<constraint firstItem="kkz-NK-BGC" firstAttribute="top" secondItem="zpX-41-Ngk" secondAttribute="top" id="9Hm-Pk-FQC"/>
<constraint firstItem="IcS-3H-XUB" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="CIl-uD-o0w"/>
<constraint firstAttribute="trailing" secondItem="IcS-3H-XUB" secondAttribute="trailing" id="Cv2-YS-e4D"/>
<constraint firstItem="hDa-nl-Tlr" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="NhL-d5-aXA"/>
<constraint firstItem="kkz-NK-BGC" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="OXr-gn-pes"/>
<constraint firstItem="evT-5t-rty" firstAttribute="leading" secondItem="zpX-41-Ngk" secondAttribute="leading" id="Og9-68-h35"/>
<constraint firstItem="HuL-FJ-3YQ" firstAttribute="top" secondItem="Cy8-TS-7aW" secondAttribute="bottom" id="PIf-9Z-uEf"/>
<constraint firstAttribute="bottom" secondItem="Cy8-TS-7aW" secondAttribute="bottom" id="Svy-Uy-Rgg"/>
<constraint firstItem="IcS-3H-XUB" firstAttribute="top" secondItem="hDa-nl-Tlr" secondAttribute="bottom" id="VMa-R5-OFW"/>
<constraint firstAttribute="bottom" secondItem="evT-5t-rty" secondAttribute="bottom" id="XDr-SL-NMM"/>
<constraint firstAttribute="trailing" secondItem="hDa-nl-Tlr" secondAttribute="trailing" id="a3q-U2-mJY"/>
......
......@@ -21,6 +21,7 @@
#import "KWMFilterVC.h"
#import "KWMShoppingCart.h"
#import "KWMSearchFeedbackVC.h"
#import "KWMPPCacheUtil.h"
@interface KWMBrandCaramelVC ()<UITableViewDelegate,UITableViewDataSource,KWMBrandCaramelCellDelegate>
@property (nonatomic) KWMBarandSelectView *barandSelectView;
......@@ -65,29 +66,8 @@
[self initView];
[self getCollection:_handle];
if(self.goodModel){
[self initCacheData];
}
}
-(void)initCacheData{
if(self.goodModel){
NSArray *products = [self.userDao getCollectionCache:self.goodModel.id tags:_isSale?[NSArray arrayWithObjects:@"sale", nil]:nil];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
}else if(self.collection!=nil && self.collection.identifier!=nil){
NSArray *products = [self.userDao getCollectionCache:self.collection.identifier tags:_isSale?[NSArray arrayWithObjects:@"sale", nil]:nil];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
}
}
- (void)setBackColor{
colorArr = [NSArray arrayWithObjects:@"#D8A88D",@"#A4C8C6",@"#E6C995",@"#718473",@"#D7B48B", nil];
int num = arc4random_uniform(10);
......@@ -303,7 +283,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 244;
}
......@@ -314,13 +293,18 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}else if([KWMStringUtil isEmpty:collectionHandle]){
return;
}
NSDictionary *parameters = @{@"handle":handle};
BOOL canUseCacheCollection = [self canUseCacheCollection:parameters];
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
if(!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle collection:collection];
}
if(collection && !error){
self.collection = collection;
[self setBrandData];
//如果已经拿到缓存中collection,getProduct则已经调用过了。
if(!canUseCacheCollection){
[self getProcduct:collection.identifier];
if(!self.goodModel){
[self initCacheData];
}
}else if(error != nil){
[self showError:error];
......@@ -362,7 +346,14 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[self.tbvBrandCaramel.mj_footer resetNoMoreData];
}
NSInteger tagetPage = self.currentPage.integerValue + 1;
NSDictionary *parameters = [KWMPPCacheUtil getProductPageCacheKey:tagetPage pageSize:self.client.pageSize sortOrder:collectionSort tags:tags inCollection:collectionId];
if([self isUseCacheProduct:parameters page:tagetPage]){
return;
};
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
if (!error){
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
}
if (error) {
[self showError:error];
NSLog(@"Error fetching products: %@", error);
......@@ -371,17 +362,14 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[weakSelf.dataList removeAllObjects];
[self.tbvBrandCaramel reloadData];
}else if (error == nil && products) {
//
if(tagetPage == 1 && (tags.count == 0 || (tags.count == 1 && weakSelf.isSale)) ){
[weakSelf.userDao saveCollectionCache:products collectionId:collectionId tags:tags];
if(tagetPage == 1){
[weakSelf.dataList removeAllObjects];
}
//
weakSelf.hasNextPage = !reachedEnd;
[weakSelf appendDataList:products setPage:page];
weakSelf.vNoneGoods.hidden = YES;
[self.tbvBrandCaramel reloadData];
// [weakSelf.dataList addObjectsFromArray:products];
// [weakSelf.tbvBrandCaramel.mj_header endRefreshing];
// [weakSelf.tbvBrandCaramel.mj_footer endRefreshing];
......@@ -391,4 +379,40 @@ static NSString *idStr = @"KWMBrandCaramelCell";
}];
}
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCacheProduct:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page{
if(!kIsNetwork || page==1){
NSArray *cacheProducts = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getProductsPage];
if(cacheProducts && cacheProducts.count > 0){
self.vNoneGoods.hidden = YES;
if(page == 1){
[self.dataList removeAllObjects];
}
self.hasNextPage = YES;
[self appendDataList:cacheProducts setPage:page];
[self.tbvBrandCaramel reloadData];
}else if(!kIsNetwork){
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
//缓存规则:默认拿缓存数据,api依旧照常执行,不过执行过的getProduct api不会重新执行
-(BOOL)canUseCacheCollection:(NSDictionary *)cacheKeyDictionary{
BUYCollection *collection = [KWMPPCacheUtil getCollectionByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle];
if(collection){
self.collection = collection;
[self setBrandData];
[self getProcduct:collection.identifier];
return true;
}else{
return false;
}
}
@end
......@@ -18,7 +18,7 @@
@interface KWMSearchBrandVC ()<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate,KWMSearchBrandViewDelegate>
@property (nonatomic,strong) NSMutableArray *dataArray;
@property (nonatomic)KWMSearchBrandView *searchBrandView;
@property (nonatomic,weak)KWMSearchBrandView *searchBrandView;
@end
@implementation KWMSearchBrandVC {
......@@ -32,20 +32,16 @@
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[_searchBrandView removeFromSuperview];
searchArr = nil;
searchTitle = nil;
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
[self initHeaderView];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self initHeaderView];
// Do any additional setup after loading the view.
self.automaticallyAdjustsScrollViewInsets = NO;
self.title = @"所有品牌";
......@@ -67,8 +63,9 @@
}
- (void)initHeaderView{
self.searchBrandView = [[KWMSearchBrandView alloc] init];
[self.view addSubview:_searchBrandView];
KWMSearchBrandView *searchBrandView = [[KWMSearchBrandView alloc] init];
[self.view addSubview:searchBrandView];
self.searchBrandView = searchBrandView;
self.searchBrandView.delegate = self;
[self initCustomTitleBarConstarints:self.searchBrandView];
}
......@@ -313,13 +310,26 @@ static NSString *identify = @"KWMSearchBrandsCell";
return ;
}
// NSArray *indexArray= [result.brands arrayWithPinYinFirstLetterFormat];
if(self.dataArray){ //如果已经从缓存拿到数据了。
return;
}
NSArray *indexArray= [[result.brands rx_filterWithBlock:^BOOL(id each) {
return each && each != [NSNull null];
}] arrayWithPinYinFirstLetterFormat];
_dataArray =[NSMutableArray arrayWithArray:indexArray];
[weakSelf.tbvSearchBrand reloadData];
};
void(^cacheCallback)(KWMBrandsResult *) = ^(KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){
return ;
}
NSArray *indexArray= [[result.brands rx_filterWithBlock:^BOOL(id each) {
return each && each != [NSNull null];
}] arrayWithPinYinFirstLetterFormat];
_dataArray =[NSMutableArray arrayWithArray:indexArray];
[weakSelf.tbvSearchBrand reloadData];
};
[self.api getAllBrand:nil success:success failure:failure];
[self.api getAllBrand:nil cacheCallback:cacheCallback success:success failure:failure];
// [self showLoading];
}
......
......@@ -18,6 +18,8 @@
#import "KWMFilterUtil.h"
#import "MJRefresh.h"
#import "KWMShoppingCart.h"
#import "CacheKeyConstants.h"
#import "KWMPPCacheUtil.h"
......@@ -284,15 +286,26 @@
-(void)requestAllBrandsApi{
__weak KWMCategoryVC *weakSelf = self;
void(^failure)(NSURLSessionDataTask *,NSError *) = ^(NSURLSessionDataTask *task,NSError *error){
//如果从缓存拿到了数据,不需要提示网络错误,反之提示
if(!self.allBrands || self.allBrands.count == 0){
[weakSelf showError:error];
}
};
void(^success)(NSURLSessionDataTask *,KWMBrandsResult *) = ^(NSURLSessionDataTask *task,KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){
return ;
}
if(!self.allBrands){
self.allBrands = result.brands;
}
};
void(^cacheCallback)(KWMBrandsResult *) = ^(KWMBrandsResult *result){
if([weakSelf hasCemaroseError:result]){
return ;
}
self.allBrands = result.brands;
};
[self.api getAllBrand:nil success:success failure:failure];
[self.api getAllBrand:nil cacheCallback:cacheCallback success:success failure:failure];
}
#pragma mark - API BUYClient+Storefront.h
......@@ -305,6 +318,11 @@
if(cmodel.brand){
[tags addObject:cmodel.brand];
}
NSDictionary *parameters = [KWMPPCacheUtil getProductPageCacheKey:cpage pageSize:self.client.pageSize sortOrder:cmodel.sort tags:tags inCollection:cmodel.collection_id];
//从缓存中拿数据
if([self isUseCache:parameters page:cpage cmodel:cmodel]){
return;
}
[self.client getProductsPage:cpage inCollection:cmodel.collection_id withTags:tags sortOrder:cmodel.sort completion:^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
weakSelf.cvRightProduct.mj_footer.hidden = false;
if (cmodel == self.selectedCategory) {
......@@ -325,6 +343,8 @@
[weakSelf showError:error];
}
else{
//保存缓存
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getProductsPage products:products];
// weakSelf.refreshUtil.page = page;
cmodel.page = page;
// weakSelf.refreshUtil.hasNextPage = !reachedEnd;
......@@ -368,4 +388,30 @@
// [self.cvRightProduct reloadData];
}
#pragma mark -cache
//缓存规则:第一页数据默认先从缓存拿,然后再更新,后面的根据网络判断从缓存拿数据还是从api拿数据
- (BOOL)isUseCache:(NSDictionary *)cacheKeyDictionary page:(NSUInteger)page cmodel:(KWMCategoryModel *)cmodel{
if(!kIsNetwork || page == 1){
NSArray *cacheProducts = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getProductsPage];
if(cacheProducts && cacheProducts.count > 0){
if ([self.cvRightProduct.mj_header isRefreshing]) {
[self.cvRightProduct.mj_header endRefreshing];
}
if ([self.cvRightProduct.mj_footer isRefreshing]) {
[self.cvRightProduct.mj_footer endRefreshing];
}
cmodel.page = page;
if (page == 1) {
[cmodel.products removeAllObjects];
}
[cmodel.products addObjectsFromArray:cacheProducts];
[self.cvRightProduct reloadData];
self.filterTab.userInteractionEnabled = true;
}else if(!kIsNetwork){
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
@end
......@@ -32,6 +32,15 @@
- (void) requestData {
[self showLoading];
void(^cacheCallback)(id) = ^(id result) {
[self hideLoading];
if (self.type == KWMContentTypePage) {
self.article = [[result pages] firstObject];
}else{
self.article = [[result blogs] firstObject];
}
[self initData];
};
void(^success)(NSURLSessionDataTask *,id) = ^(NSURLSessionDataTask *task, id result) {
[self hideLoading];
if (self.type == KWMContentTypePage) {
......@@ -52,7 +61,7 @@
if (self.type == KWMContentTypePage) {
[self.api getAllPage:param success:success failure:failure];
}else{
[self.api getAllBlog:param success:success failure:failure];
[self.api getAllBlog:param cacheCallback:nil success:success failure:failure];
}
}
......
......@@ -96,14 +96,21 @@
//请求api
- (void)requestBlogAPI{
__weak KWMHomeVC *weakSelf = self;
[self.api getAllBlog:nil success:^(NSURLSessionDataTask *task, KWMBlogResult *result) {
[self.api getAllBlog:nil cacheCallback:^(KWMBlogResult *result) {
if (result != nil) {
_dataArr = [[result.blogs reverseObjectEnumerator] allObjects];
[self.tbvBlog reloadData];
}
} success:^(NSURLSessionDataTask *task, KWMBlogResult *result) {
[weakSelf hideLoading];
if (result != nil) {
_dataArr = [[result.blogs reverseObjectEnumerator] allObjects];
[self.tbvBlog reloadData];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if(self.dataArr==nil || self.dataArr.count == 0){
[self showError:error];
}
NSLog(@"error:%@",error);
}];
}
......
......@@ -15,6 +15,7 @@
#import <SDWebImage/UIImageView+WebCache.h>
#import "MZFormSheetPresentationViewController.h"
#import "Buy/Buy.h"
#import <PPNetworkHelper/PPNetworkCache.h>
@class AppDelegate;
......
......@@ -326,6 +326,12 @@
//显示错误信息
- (void)showError:(NSError *)error{
if (!error){
return;
}
if ([error.domain isEqualToString:@"缓存错误"]){
return;
}
if ([error.domain isEqualToString:NSURLErrorDomain]) {
[self showToast:@"网络已断开,请重新连接"];
return;
......
......@@ -5,7 +5,7 @@
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13174"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
......@@ -206,6 +206,7 @@
<constraints>
<constraint firstItem="u9U-m1-VeK" firstAttribute="centerY" secondItem="0c8-k5-y3n" secondAttribute="centerY" id="25t-Oi-zog"/>
<constraint firstItem="rId-0e-u0H" firstAttribute="trailing" secondItem="0c8-k5-y3n" secondAttribute="trailing" id="75j-Nn-dmV"/>
<constraint firstItem="asr-TI-lDQ" firstAttribute="top" secondItem="aEK-K4-3qL" secondAttribute="bottom" constant="11" id="7nW-oq-nDP"/>
<constraint firstItem="Djf-FZ-FEl" firstAttribute="top" secondItem="HiY-gY-I4h" secondAttribute="bottom" constant="78" id="9tF-dE-M4M"/>
<constraint firstAttribute="trailing" secondItem="HiY-gY-I4h" secondAttribute="trailing" constant="44" id="Aaw-WU-fjk"/>
<constraint firstItem="cZA-Am-Uhr" firstAttribute="top" secondItem="aob-ud-437" secondAttribute="bottom" constant="51" id="DAS-0A-mel"/>
......@@ -215,7 +216,6 @@
<constraint firstItem="aob-ud-437" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="KU0-IE-DgX"/>
<constraint firstItem="0c8-k5-y3n" firstAttribute="centerX" secondItem="ely-f5-Lwm" secondAttribute="centerX" id="Ka8-Ji-nhM"/>
<constraint firstItem="aob-ud-437" firstAttribute="top" secondItem="rId-0e-u0H" secondAttribute="bottom" constant="49" id="NQa-TC-6pa"/>
<constraint firstItem="asr-TI-lDQ" firstAttribute="top" secondItem="ely-f5-Lwm" secondAttribute="top" constant="31" id="OH6-Xy-NVa"/>
<constraint firstItem="rId-0e-u0H" firstAttribute="top" secondItem="0c8-k5-y3n" secondAttribute="bottom" id="Pbi-2f-q1U"/>
<constraint firstItem="Mtf-5x-f0v" firstAttribute="top" secondItem="7U8-AN-1tB" secondAttribute="bottom" constant="22" id="QW2-mK-nvw"/>
<constraint firstItem="0c8-k5-y3n" firstAttribute="top" secondItem="ely-f5-Lwm" secondAttribute="top" constant="282" id="UTS-0F-XzY"/>
......
......@@ -187,9 +187,6 @@
self.client.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"token"]];
[self.client getOrdersForCustomerCallback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
for (int i = 0; i<orders.count; i++) {
NSLog(@"langArray[%d]=%@", i,orders[i].JSONDictionary);
}
[weakSelf hideLoading];
if (error == nil && orders != nil ) {
[weakSelf.orderList removeAllObjects];
......
......@@ -19,6 +19,8 @@
#import "KWMWishListVC.h"
#import <MJRefresh.h>
#import "KWMStringUtil.h"
#import "KWMPPCacheUtil.h"
#import "CacheKeyConstants.h"
typedef enum{
......@@ -349,12 +351,16 @@ typedef enum{
[self showLoading];
BOOL isHome = [handle isEqualToString:@"products-list-app-homepage"];
NSInteger cpage = isHome ? self.page : 1;
NSDictionary *parameters = [self getProductCacheKeyDictionary:cpage tags:tags handle:handle];
if([self isUseProductDataCache:parameters valueKeyPath:valueKeyPath page:cpage isHome:isHome]){
return;
}
[self.client getCollectionByHandle:handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
[self hideLoading];
if (!error) {
[self.client getProductsPage:cpage inCollection:collection.identifier withTags:tags sortOrder:BUYCollectionSortCollectionDefault completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
[self hideLoading];
if (!error) {
[KWMPPCacheUtil saveDataToCache:parameters urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage products:products];
[self setValue:products forKeyPath:valueKeyPath];
[self.cvHome reloadData];
}else{
......@@ -366,7 +372,6 @@ typedef enum{
}
}];
}else{
[self hideLoading];
[self showError:error];
}
}];
......@@ -392,7 +397,11 @@ typedef enum{
- (void) loadHomeData {
[self requestProductWithHandle:@"hot-sell-app" tags:nil valueKeyPath:@"recommendHeader.productArray"];
if([self isUseHomeDataCache]){
return;
}
[self.api getHomeDataWithSuccess:^(NSURLSessionDataTask *task, KWMHomeDataResult *result) {
[KWMPPCacheUtil saveDataToCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess homeData:result.data];
self.homeData = result.data;
[self.cvHome reloadData];
} failure:^(NSURLSessionDataTask *task, NSError *error) {
......@@ -442,4 +451,57 @@ typedef enum{
}
#pragma mark -cache
/** 因为homedata api的url是动态的,url上的时间戳随时间的改变,所以需要手动保存,和获取 **/
-(BOOL)isUseHomeDataCache{
if(!kIsNetwork){
KWMHomeData *homeData = [KWMPPCacheUtil getHomeDataByCache:nil urlKey:CACHE_KEY_getHomeDataWithSuccess];
if(homeData){
self.homeData = homeData;
[self.cvHome reloadData];
}else{
[self showToast:CACHE_KEY_FAIL_HINT];
}
}
return !kIsNetwork;
}
//初始化缓存parameters key
- (NSDictionary *)getProductCacheKeyDictionary:(NSUInteger)page
tags:(nullable NSArray <NSString *> *)tags
handle:(nullable NSString *)handle{
NSMutableDictionary *params = @{
@"limit" : @(self.client.pageSize),
@"page" : @(page)
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (handle) {
params[@"handle"] = handle;
}
return params;
}
-(BOOL)isUseProductDataCache:(NSDictionary *)cacheKeyDictionary valueKeyPath:(NSString *)valueKeyPath page:(NSUInteger)page isHome:(BOOL)isHome{
if(!kIsNetwork){
[self hideLoading];
NSArray *products = [KWMPPCacheUtil getProductDataByCache:cacheKeyDictionary urlKey:CACHE_KEY_SDK_getCollectionByHandle_getProductsPage];
if(products && products.count > 0){
[self setValue:products forKeyPath:valueKeyPath];
[self.cvHome reloadData];
if (isHome) {
self.page = self.page + 1;
products.count ? [self.cvHome.mj_footer endRefreshing] : [self.cvHome.mj_footer endRefreshingWithNoMoreData];
}
}else{
[self showToast:CACHE_KEY_FAIL_HINT];
if (isHome) {
[self.cvHome.mj_footer endRefreshing];
}
}
}
return !kIsNetwork;
}
@end
......@@ -61,12 +61,12 @@
@implementation KWMFirstDetailView
- (id)init{
if (self=[super init]){
[self addView];
}
return self;
}
//- (id)init{
// if (self=[super init]){
// [self addView];
// }
// return self;
//}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
......@@ -94,7 +94,7 @@
NSLog(@"KWMProductDetailView%f%f",self.frame.size.width,self.frame.size.height);
self.vView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
[self addSubview:self.vView];
self.imageScrollView.autoScroll = false;
self.imageScrollView.pageDotImage = [UIImage imageNamed:@"ic_page_1"];
self.imageScrollView.currentPageDotImage = [UIImage imageNamed:@"ic_page_2"];
self.imageScrollView.delegate = self;
......
......@@ -9,6 +9,7 @@
#import "KWMNewProductVC.h"
#import "KWMLoginVC.h"
#import "KWMBeforePayVC.h"
#import "KWMContactUsVC.h"
#import "KWMBrandCaramelVC.h"
#import "KWMShareVC.h"
#import "KWMWishListVC.h"
......@@ -32,6 +33,10 @@
@property (weak, nonatomic) IBOutlet UIButton *btnShopCart;
@property (weak, nonatomic) IBOutlet UIButton *btnContactUs;
@property (weak, nonatomic) IBOutlet UIView *vBottomBar;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIButton *btnLike;
......@@ -102,7 +107,9 @@
self.detailView1.delegate = self;
self.detailView2.delegate = self;
self.midDetailView.delegate = self;
[self initBottomViewHidden];
if(self.product){
[self.detailView1 setSizeGuideHidden:!self.typeTag];
self.midDetailView.product = self.product;
[self.detailView1 setData:self.product];
[self requestBrandProducts:1];
......@@ -119,6 +126,18 @@
}
-(void)initBottomViewHidden{
if(self.product){
NSString *productVendor = self.product.vendor;
NSString *targetVendor = @"Moncler";
BOOL isShowContactUs = [productVendor isEqualToString:targetVendor];
self.vBottomBar.hidden = isShowContactUs;
self.btnContactUs.hidden = !isShowContactUs;
self.vBottomBar.hidden = NO;
}
}
- (void)initShopCartCount{
......@@ -187,6 +206,11 @@
[self.navigationController pushViewController:shopCartVC animated:YES];
}
-(IBAction)onClickContactUs:(id)sender{
KWMContactUsVC *contactVC = (KWMContactUsVC *)[KWMBaseVC findControllerBy:[KWMContactUsVC kwmTag] fromStoryboard:@"Mine"];
[self.navigationController pushViewController:contactVC animated:YES];
}
-(IBAction)onClickShare:(id)sender{
if(self.product){
KWMShareVC *shareVC = (KWMShareVC *)[KWMBaseVC findControllerBy:[KWMShareVC kwmTag] fromStoryboard:@"New"];
......@@ -493,15 +517,16 @@
}else if(product){
weakSelf.product = product;
weakSelf.productId = product.identifier;
[weakSelf initBottomViewHidden];
// [weakSelf initMidViewHight];
weakSelf.midDetailView.product = product;
[weakSelf.detailView1 setData:product];
[self requestBrandProducts:1];
[self requestCategoryProducts:1];
if(self.handle){
[self requestAdminProduct];
[self requestColorMetafield];
[weakSelf requestBrandProducts:1];
[weakSelf requestCategoryProducts:1];
//handle初始化的商品页面还没有请求admin api(获取库存),以及颜色 api;
if(weakSelf.handle){
[weakSelf requestAdminProduct];
[weakSelf requestColorMetafield];
}
}
};
......@@ -741,7 +766,6 @@
break;
}
}
[self.detailView1 setSizeGuideHidden:!self.typeTag];
}
......
......@@ -130,6 +130,20 @@
<constraint firstItem="2KH-pA-K5l" firstAttribute="height" secondItem="T6J-Gp-5iu" secondAttribute="width" constant="250" id="pFo-pT-vgh"/>
</constraints>
</scrollView>
<button opaque="NO" tag="999" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="344-t8-DPO">
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
<color key="backgroundColor" red="0.14117647059999999" green="0.14117647059999999" blue="0.14117647059999999" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="50" id="EXc-qM-375"/>
</constraints>
<fontDescription key="fontDescription" name="PingFangSC-Regular" family="PingFang SC" pointSize="15"/>
<state key="normal" title="CONTACT US">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="onClickContactUs:" destination="Vzq-D6-e57" eventType="touchUpInside" id="0G8-We-IP4"/>
</connections>
</button>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aqB-2y-BKU" userLabel="底部">
<rect key="frame" x="0.0" y="617" width="375" height="50"/>
<subviews>
......@@ -223,17 +237,21 @@
<constraints>
<constraint firstAttribute="trailing" secondItem="aqB-2y-BKU" secondAttribute="trailing" id="2B4-2I-dss"/>
<constraint firstItem="kgb-zB-eBa" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" id="3J0-tF-Mna"/>
<constraint firstAttribute="trailing" secondItem="344-t8-DPO" secondAttribute="trailing" id="4Nw-O8-AnE"/>
<constraint firstItem="aqB-2y-BKU" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="6I6-ul-bGF"/>
<constraint firstAttribute="trailing" secondItem="T6J-Gp-5iu" secondAttribute="trailing" id="B5K-Fj-FOR"/>
<constraint firstItem="T6J-Gp-5iu" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="DZE-DY-3SX"/>
<constraint firstItem="5rs-FM-Imo" firstAttribute="top" secondItem="aqB-2y-BKU" secondAttribute="bottom" id="Dag-cY-cd9"/>
<constraint firstAttribute="trailing" secondItem="kgb-zB-eBa" secondAttribute="trailing" id="FyY-BZ-73X"/>
<constraint firstItem="kgb-zB-eBa" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="KfD-qL-WSj"/>
<constraint firstItem="344-t8-DPO" firstAttribute="leading" secondItem="IxM-8o-F8K" secondAttribute="leading" id="Vt4-dE-ATW"/>
<constraint firstItem="aqB-2y-BKU" firstAttribute="top" secondItem="T6J-Gp-5iu" secondAttribute="bottom" id="kEG-am-iPo"/>
<constraint firstItem="5rs-FM-Imo" firstAttribute="top" secondItem="344-t8-DPO" secondAttribute="bottom" id="m3x-3k-Osi"/>
<constraint firstItem="T6J-Gp-5iu" firstAttribute="top" secondItem="Pjy-Ny-sa9" secondAttribute="bottom" constant="44" id="nNS-e6-C1V"/>
</constraints>
</view>
<connections>
<outlet property="btnContactUs" destination="344-t8-DPO" id="Se8-h5-pev"/>
<outlet property="btnLike" destination="jLv-Vv-7Vi" id="sep-kb-Y2L"/>
<outlet property="btnShopCart" destination="gbx-rg-A8B" id="vel-Ab-0rI"/>
<outlet property="detailView1" destination="2KH-pA-K5l" id="ynO-by-UfZ"/>
......@@ -242,6 +260,7 @@
<outlet property="heightMidView" destination="Pwf-vg-Z3k" id="h8Z-Kr-bXi"/>
<outlet property="midDetailView" destination="t55-gT-VGG" id="BRI-de-9Jz"/>
<outlet property="scrollView" destination="T6J-Gp-5iu" id="ZLc-Xh-Pyk"/>
<outlet property="vBottomBar" destination="aqB-2y-BKU" id="S6H-fL-0uE"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="uHF-Hi-PUR" userLabel="First Responder" sceneMemberID="firstResponder"/>
......
......@@ -41,7 +41,8 @@
*/
@property (strong, nonatomic) NSArray<NSString *>*ctags;
@property (nonatomic) KWMProductType *productType;
/** 该属性相关页面已经废弃,相关逻辑也已删除 **/
@property (nonatomic) KWMProductType *productType DEPRECATED_ATTRIBUTE;
@property (nonatomic) BUYCollectionSort collectionSort;
......
......@@ -14,6 +14,7 @@
#import "KWMFilterUtil.h"
#import "KWMStringUtil.h"
#import "KWMImageBlurUtil.h"
#import "KWMPPCacheUtil.h"
@interface KWMSelectedGoodsVC ()
@end
......@@ -55,22 +56,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
self.collectionSort = BUYCollectionSortCreatedDescending;
if (self.handle && !self.title) {
self.title = self.handle.capitalizedString;
}else if(self.productType != nil){
//初始化双行标题栏
NSString *mTitle;
if(self.tagType == 0){
mTitle = @"婴儿";
}else if(self.tagType == 1){
mTitle = @"女孩";
}else if(self.tagType == 2){
mTitle = @"男孩";
}else if(self.tagType == 3){
mTitle = @"鞋子";
}
KWMDoubleTitleView *doubleTitleView = [[KWMDoubleTitleView alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
doubleTitleView.lbTitle.text = mTitle;
doubleTitleView.lbSecondTitle.text = self.productType.value;
self.navigationItem.titleView=doubleTitleView;
}
openPosition = -1;
self.automaticallyAdjustsScrollViewInsets = NO;
......@@ -83,32 +68,10 @@ static NSString *idStr = @"KWMBrandCaramelCell";
self.filterView.delegate = self;
self.filterTab.delegate = self;
[self initCacheData];
[self fixFilterError];
}
-(void)initCacheData{
NSNumber *collectionId;
NSArray *tags;
if(self.collection!=nil){
collectionId = self.collection.identifier;
}
if(self.productType!=nil){
if(![KWMStringUtil isEmpty:self.productType.collectionId]){
NSInteger num = [self.productType.collectionId integerValue];
collectionId = @(num);
}
NSString *tag;
if(self.tagType == 0){
tag = @"baby";
}else if(self.tagType == 1){
tag = @"girls";
}else if(self.tagType == 2){
tag = @"boys";
}else if(self.tagType == 3){
tag = @"shoes";
}
tags = [NSArray arrayWithObjects:tag, nil];
}
-(void)fixFilterError{
NSMutableDictionary *sf = [NSMutableDictionary new];
for (NSString *tag in self.ctags) {
......@@ -139,12 +102,6 @@ static NSString *idStr = @"KWMBrandCaramelCell";
return r;
}] mutableCopy]];
}
NSArray *products = [self.userDao getCollectionCache:collectionId tags:tags];
if(products && products.count>0){
[self appendDataList:products setPage:1];
self.currentPage = 0;
}
}
-(UITableView *)targetTableView{
......@@ -274,20 +231,51 @@ static NSString *idStr = @"KWMBrandCaramelCell";
- (void)requestProductList{
__weak KWMSelectedGoodsVC *weakSelf = self;
if (self.handle) {
[self.client getCollectionByHandle:self.handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
NSArray * tags = [KWMFilterUtil getTagsByFilterArray:weakSelf.filterView.selectedTags];
if ([tags count] <= 0) {
tags = weakSelf.ctags;
}
if(error){
[weakSelf showError:error];
}
if(collection){
[weakSelf requestProductListApi:collection.identifier tags:tags];
}
}];
return;
}else{
if(!self.collection){
return;
}
NSNumber *collectionId = self.collection.identifier;
//初始化tag
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if(collectionId == nil){
return;
}
[self requestProductListApi:collectionId tags:tags];
}
}
- (void)requestProductListApi:(NSNumber *)collectionId tags:(NSArray *)tags{
self.isLoading = YES;
__weak KWMSelectedGoodsVC *weakSelf = self;
NSInteger tagetPage = self.currentPage.integerValue + 1;
void(^completion)(NSArray<BUYProduct *> *,NSUInteger,BOOL,NSError*) = ^(NSArray *products,NSUInteger page, BOOL reachedEnd, NSError *error){
BUYCollectionSort collectionSort = self.filterView.selectedSort;
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:^(NSArray<BUYProduct *> * _Nullable products, NSUInteger page, BOOL reachedEnd, NSError * _Nullable error) {
[weakSelf hideLoading];
weakSelf.isLoading = NO;
if(tagetPage == 1){
if(!products || products.count == 0){
self.vNoData.hidden = NO;
[weakSelf.dataList removeAllObjects];
if(!products || products.count == 0){
weakSelf.vNoData.hidden = NO;
[weakSelf.tbvSelectedGoods reloadData];
return;
}
}
weakSelf.isLoading = NO;
if (error == nil && products) {
self.vNoData.hidden = YES;
weakSelf.hasNextPage = !reachedEnd;
......@@ -297,51 +285,7 @@ static NSString *idStr = @"KWMBrandCaramelCell";
[self showError:error];
NSLog(@"Error fetching products: %@", error);
}
};
if (self.handle) {
[self.client getCollectionByHandle:self.handle completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
NSArray * tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if ([tags count] <= 0) {
tags = self.ctags;
}
[self.client getProductsPage:tagetPage inCollection:collection.identifier withTags:tags sortOrder:self.filterView.selectedSort completion:completion];
}];
// [self.client getProductsPage:tagetPage inCollection:nil withTags:self.ctags sortOrder:self.filterView.selectedSort completion:completion];
return;
}
NSNumber *collectionId;
if(self.collection!=nil){
collectionId = self.collection.identifier;
}
//初始化排序及筛选tag
BUYCollectionSort collectionSort = self.filterView.selectedSort;
NSMutableArray *tags = [KWMFilterUtil getTagsByFilterArray:self.filterView.selectedTags];
if(self.productType!=nil){
if(![KWMStringUtil isEmpty:self.productType.collectionId]){
NSInteger num = [self.productType.collectionId integerValue];
collectionId = @(num);
}
if(self.tagType == 0){
[tags addObject:@"baby"];
}else if(self.tagType == 1){
[tags addObject:@"girls"];
}else if(self.tagType == 2){
[tags addObject:@"boys"];
}else if(self.tagType == 3){
[tags addObject:@"shoes"];
}
}
if(collectionId == nil){
return;
}
self.isLoading = YES;
[self.client getProductsPage:tagetPage inCollection:collectionId withTags:tags sortOrder:collectionSort completion:completion];
}
@end
......@@ -147,7 +147,7 @@
-(MJRefreshHeader *)createHeader{
__weak KWMCollectionRefreshUtil *weakSelf = self;
KWMLoadingHeader *header = [KWMLoadingHeader headerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf reLoadData];
});
}];
......@@ -159,7 +159,7 @@
__weak KWMCollectionRefreshUtil *weakSelf = self;
MJRefreshAutoNormalFooter *footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[weakSelf loadData];
});
}];
......
//
// KWMPPCacheUtil.h
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "KWMHomeData.h"
#import <Buy/Buy.h>
#import "CacheKeyConstants.h"
@interface KWMPPCacheUtil : NSObject
//这个key用的地方比较多,所以抽在这里了
+ (NSDictionary *)getProductPageCacheKey:(NSUInteger)page
pageSize:(NSUInteger)pageSize
sortOrder:(BUYCollectionSort)sortOrder
tags:(nullable NSArray <NSString *> *)tags
inCollection:(nullable NSNumber *)collectionId;
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products;
+ (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey homeData:(KWMHomeData *)homeData;
+(KWMHomeData *)getHomeDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey collection:(BUYCollection *)collection;
+(BUYCollection *)getCollectionByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey;
@end
//
// KWMPPCacheUtil.m
// iCemarose
//
// Created by HouWeiBin on 2017/11/14.
// Copyright © 2017年 kollway. All rights reserved.
//
#import "KWMPPCacheUtil.h"
@implementation KWMPPCacheUtil
#pragma mark -cache
//这个key用的地方比较多,所以抽在这里了
+ (NSDictionary *)getProductPageCacheKey:(NSUInteger)page
pageSize:(NSUInteger)pageSize
sortOrder:(BUYCollectionSort)sortOrder
tags:(nullable NSArray <NSString *> *)tags
inCollection:(nullable NSNumber *)collectionId{
NSMutableDictionary *params = @{
@"limit" : @(pageSize),
@"page" : @(page),
@"sort_by" : [BUYCollection sortOrderParameterForCollectionSort:sortOrder]
}.mutableCopy;
if (tags) {
params[@"tag"] = [tags componentsJoinedByString:@","];
}
if (collectionId) {
params[@"collection_id"] = collectionId;
}
return params;
}
+ (void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey products:(NSArray *)products{
NSMutableArray *dictArray = [NSMutableArray array];
if(products){
for(BUYProduct *product in products){
NSDictionary *productDict = product.JSONDictionary;
if(productDict){
[dictArray addObject:productDict];
}
}
}
NSDictionary *saveDict = [[NSDictionary alloc] initWithObjectsAndKeys:dictArray, @"array",nil];
[PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
}
+ (NSArray *)getProductDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
NSMutableArray *products = [NSMutableArray array];
if(cacheDictionary && [cacheDictionary objectForKey:@"array"]){
NSArray *dictArray = [cacheDictionary objectForKey:@"array"];
for(NSDictionary *dict in dictArray){
if(dict){
BUYProduct *product = (BUYProduct *)[[BUYModelManager modelManager] buy_objectWithEntityName:[BUYProduct entityName] JSONDictionary:dict];
[products addObject:product];
}
}
}
return products;
}
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey homeData:(KWMHomeData *)homeData{
NSDictionary *saveDict = [[NSDictionary alloc]initWithObjectsAndKeys:homeData,@"homeData", nil];
[PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
}
+(KWMHomeData *)getHomeDataByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
if(cacheDictionary && [cacheDictionary objectForKey:@"homeData"]){
KWMHomeData *homeData = (KWMHomeData *)[cacheDictionary objectForKey:@"homeData"];
return homeData;
}else{
return nil;
}
}
+(void)saveDataToCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey collection:(BUYCollection *)collection{
// if(collection && collection.JSONDictionary){
//这里会崩溃,因为collection的image(BuyImageLink里又有一个Collection,获取其dictionary会出现无限递归的问题)
// NSDictionary *saveDict = collection.JSONDictionary;
// [PPNetworkCache setHttpCache:saveDict URL:urlKey parameters:cacheKeyDictionary];
// }
if(collection){
NSString *imageString = collection.image.sourceURL.absoluteString;
NSDictionary *collectionData = @{@"image":imageString,
@"identifier":collection.identifier.stringValue,
@"description":collection.htmlDescription,
};
[PPNetworkCache setHttpCache:collectionData URL:urlKey parameters:cacheKeyDictionary];
}
}
+(BUYCollection *)getCollectionByCache:(NSDictionary *)cacheKeyDictionary urlKey:(NSString *)urlKey{
NSDictionary *cacheDictionary = [PPNetworkCache httpCacheForURL:urlKey parameters:cacheKeyDictionary];
if(cacheDictionary){
// BUYCollection *collection = (BUYCollection *)[[BUYModelManager modelManager] buy_objectWithEntityName:[BUYCollection entityName] JSONDictionary:cacheDictionary];
// return collection;
BUYCollection *collection = [[BUYCollection alloc]init];
collection.image = [[BUYImageLink alloc]init];
NSString *imageString = cacheDictionary[@"image"];
collection.image.sourceURL = [[NSURL alloc]initWithString:imageString];
collection.htmlDescription = cacheDictionary[@"description"];
NSString *idString = cacheDictionary[@"identifier"];
collection.identifier = @([idString integerValue]);
return collection;
}else{
return nil;
}
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment