This commit is contained in:
2025-12-17 17:01:49 +08:00
parent dde8716262
commit 1e04e7c39a
21 changed files with 180 additions and 18 deletions

View File

@@ -12,6 +12,7 @@
@optional
- (void)functionView:(KBFunctionView *_Nullable)functionView didTapToolActionAtIndex:(NSInteger)index;
- (void)functionView:(KBFunctionView *_Nullable)functionView didRightTapToolActionAtIndex:(NSInteger)index;
- (void)functionViewDidRequestSubscription:(KBFunctionView *_Nullable)functionView;
@end

View File

@@ -24,6 +24,7 @@
#import "WJXEventSource.h"
#import "KBTagItemModel.h"
#import <MJExtension/MJExtension.h>
#import "KBBizCode.h"
@interface KBFunctionView () <KBFunctionBarViewDelegate, KBStreamOverlayViewDelegate, KBFunctionTagListViewDelegate>
// UI
@@ -347,6 +348,7 @@
NSError *error = nil;
NSDictionary *payload = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
if (error || ![payload isKindOfClass:[NSDictionary class]]) { return; }
if ([self kb_handleBizErrorIfNeeded:payload]) { return; }
NSString *type = payload[@"type"];
if (![type isKindOfClass:[NSString class]]) { return; }
@@ -395,6 +397,32 @@
self.eventSourceDidReceiveDone = NO;
}
- (BOOL)kb_handleBizErrorIfNeeded:(NSDictionary *)payload {
NSInteger code = KBBizCodeFromJSONObject(payload);
if (code == NSNotFound || code == KBBizCodeSuccess) {
return NO;
}
BOOL needSubscriptionGuide = (code == KBBizCodeQuotaExhausted);
NSString *msg = KBBizMessageFromJSONObject(payload);
if (msg.length == 0) {
msg = KBLocalized(@"拉取失败");
}
NSError *bizError = [NSError errorWithDomain:@"KBStreamBizError"
code:code
userInfo:@{NSLocalizedDescriptionKey: msg}];
[self kb_finishEventSourceWithError:bizError];
if (needSubscriptionGuide) {
[self kb_requestSubscriptionGuide];
}
return YES;
}
- (void)kb_requestSubscriptionGuide {
if ([self.delegate respondsToSelector:@selector(functionViewDidRequestSubscription:)]) {
[self.delegate functionViewDidRequestSubscription:self];
}
}
#pragma mark - Event Parsing
- (NSString *)kb_normalizedLLMChunkString:(id)dataValue {

View File

@@ -17,7 +17,7 @@ static NSString * const kKBKeyboardSubscriptionCellId = @"kKBKeyboardSubscriptio
@end
@interface KBKeyboardSubscriptionView () <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UIView *cardView;
@property (nonatomic, strong) UIImageView *cardView;
@property (nonatomic, strong) UIButton *closeButton;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIScrollView *featureScrollView;
@@ -35,7 +35,6 @@ static NSString * const kKBKeyboardSubscriptionCellId = @"kKBKeyboardSubscriptio
@property (nonatomic, assign, getter=isLoading) BOOL loading;
@property (nonatomic, strong) CADisplayLink *featureDisplayLink;
@property (nonatomic, assign) CGFloat featureLoopWidth;
@property (nonatomic, strong) CAGradientLayer *cardGradientLayer;
@end
@implementation KBKeyboardSubscriptionView
@@ -56,7 +55,6 @@ static NSString * const kKBKeyboardSubscriptionCellId = @"kKBKeyboardSubscriptio
- (void)layoutSubviews {
[super layoutSubviews];
self.cardGradientLayer.frame = self.cardView.bounds;
self.featureLoopWidth = self.featureScrollView.contentSize.width * 0.5f;
[self startFeatureTickerIfNeeded];
}
@@ -98,10 +96,10 @@ static NSString * const kKBKeyboardSubscriptionCellId = @"kKBKeyboardSubscriptio
- (void)setupCardView {
[self addSubview:self.cardView];
[self.cardView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.mas_left).offset(6);
make.right.equalTo(self.mas_right).offset(-6);
make.top.equalTo(self.mas_top).offset(4);
make.bottom.equalTo(self.mas_bottom).offset(-4);
make.left.equalTo(self.mas_left).offset(0);
make.right.equalTo(self.mas_right).offset(0);
make.top.equalTo(self.mas_top).offset(0);
make.bottom.equalTo(self.mas_bottom).offset(0);
}];
[self.cardView addSubview:self.closeButton];
@@ -422,17 +420,13 @@ static NSString * const kKBKeyboardSubscriptionCellId = @"kKBKeyboardSubscriptio
#pragma mark - Lazy
- (UIView *)cardView {
- (UIImageView *)cardView {
if (!_cardView) {
_cardView = [[UIView alloc] init];
_cardView.layer.cornerRadius = 20;
_cardView.layer.masksToBounds = YES;
_cardGradientLayer = [CAGradientLayer layer];
_cardGradientLayer.colors = @[ (id)[UIColor colorWithRed:0.80 green:0.96 blue:0.91 alpha:1].CGColor,
(id)[UIColor colorWithRed:0.72 green:0.89 blue:0.98 alpha:1].CGColor ];
_cardGradientLayer.startPoint = CGPointMake(0, 0);
_cardGradientLayer.endPoint = CGPointMake(1, 1);
[_cardView.layer insertSublayer:_cardGradientLayer atIndex:0];
_cardView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"keybord_bg_icon"]];
// _cardView.layer.cornerRadius = 20;
// _cardView.layer.masksToBounds = YES;
_cardView.contentMode = UIViewContentModeScaleAspectFill;
_cardView.clipsToBounds = true;
}
return _cardView;
}