3
This commit is contained in:
@@ -40,6 +40,8 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
|
||||
// 网络流式(封装)
|
||||
@property (nonatomic, strong, nullable) KBStreamFetcher *streamFetcher;
|
||||
@property (nonatomic, assign) BOOL streamHasOutput; // 是否已输出过正文(首段去首个 \t 用)
|
||||
@property (nonatomic, strong, nullable) NSNumber *loadingTagIndex; // 当前显示loading的标签index
|
||||
@property (nonatomic, copy, nullable) NSString *loadingTagTitle;
|
||||
|
||||
// Data
|
||||
@property (nonatomic, strong) NSArray<NSString *> *itemsInternal;
|
||||
@@ -212,8 +214,7 @@ static NSString * const kKBFunctionTagCellId = @"KBFunctionTagCellId";
|
||||
}];
|
||||
self.streamOverlay = overlay;
|
||||
|
||||
// 优先拉取后端测试数据(GET);失败则回落到本地演示
|
||||
[self kb_startNetworkStreamingWithSeed:title];
|
||||
// 只创建 UI;网络在点击 cell 时启动,避免重复 start 导致首包重复
|
||||
}
|
||||
|
||||
- (void)kb_onTapStreamDelete {
|
||||
@@ -258,8 +259,13 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
};
|
||||
fetcher.onFinish = ^(NSError * _Nullable error) {
|
||||
__strong typeof(weakSelf) self = weakSelf; if (!self) return;
|
||||
// 若还未出现任何数据且仍在 loading,则取消小菊花
|
||||
if (!self.streamHasOutput && self.loadingTagIndex) {
|
||||
[self.tagListView setLoading:NO atIndex:self.loadingTagIndex.integerValue];
|
||||
self.loadingTagIndex = nil; self.loadingTagTitle = nil;
|
||||
}
|
||||
if (error) { [KBHUD showInfo:@"拉取失败"]; }
|
||||
[self.streamOverlay finish];
|
||||
if (self.streamOverlay) { [self.streamOverlay finish]; }
|
||||
};
|
||||
self.streamFetcher = fetcher;
|
||||
[self.streamFetcher start];
|
||||
@@ -277,7 +283,16 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
/// - 目前网络层(KBStreamFetcher)已做 “/t->\t、首段去一个 \t、段间去一个空格”
|
||||
/// - 这里仅负责附加到视图与标记首段状态,避免 UI 抖动
|
||||
- (void)kb_appendChunkToStreamView:(NSString *)chunk {
|
||||
if (chunk.length == 0 || !self.streamOverlay) return;
|
||||
if (chunk.length == 0) return;
|
||||
// 第一次有数据才创建 overlay,并取消 cell 上的小菊花
|
||||
if (!self.streamOverlay) {
|
||||
[self kb_showStreamTextViewIfNeededWithTitle:self.loadingTagTitle ?: @""];
|
||||
if (self.loadingTagIndex) {
|
||||
[self.tagListView setLoading:NO atIndex:self.loadingTagIndex.integerValue];
|
||||
self.loadingTagIndex = nil; self.loadingTagTitle = nil;
|
||||
}
|
||||
}
|
||||
if (!self.streamOverlay) return;
|
||||
[self.streamOverlay appendChunk:chunk];
|
||||
self.streamHasOutput = YES;
|
||||
}
|
||||
@@ -287,10 +302,14 @@ static NSString * const kKBStreamDemoURL = @"http://192.168.1.144:7529/api/demo/
|
||||
- (void)tagListView:(KBFunctionTagListView *)view didSelectIndex:(NSInteger)index title:(NSString *)title {
|
||||
// 权限全部打开(键盘已启用 + 完全访问)。在扩展进程中仅需判断“完全访问”。
|
||||
if ([[KBFullAccessManager shared] hasFullAccess]) {
|
||||
[self kb_showStreamTextViewIfNeededWithTitle:title ?: @""];
|
||||
// 先在 cell 上显示小菊花,等有数据回来再弹出 overlay
|
||||
[self.tagListView setLoading:YES atIndex:index];
|
||||
self.loadingTagIndex = @(index);
|
||||
self.loadingTagTitle = title ?: @"";
|
||||
[self kb_startNetworkStreamingWithSeed:self.loadingTagTitle];
|
||||
return;
|
||||
}
|
||||
// 保留原有拉起主 App 的逻辑(若需要)
|
||||
// 未开启完全访问:保持原有引导路径
|
||||
[KBHUD showInfo:@"处理中…"];
|
||||
UIInputViewController *ivc = KBFindInputViewController(self);
|
||||
if (!ivc) return;
|
||||
|
||||
Reference in New Issue
Block a user