增加换肤功能

This commit is contained in:
启星
2025-08-14 10:07:49 +08:00
parent f6964c1e89
commit 4f9318d98e
8789 changed files with 978530 additions and 2 deletions

View File

@@ -0,0 +1,61 @@
//
// TUICustomerServicePluginDataProvider+CalculateSize.h
// TUICustomerServicePlugin
//
// Created by xia on 2023/6/13.
//
#import "TUICustomerServicePluginDataProvider.h"
NS_ASSUME_NONNULL_BEGIN
#define TUICustomerServicePluginBranchCellWidth (0.65 * Screen_Width)
#define TUICustomerServicePluginBranchCellMargin 12
#define TUICustomerServicePluginBranchCellInnerMargin 8
#define TUICustomerServicePluginInputCellWidth (0.69 * Screen_Width)
#define TUICustomerServicePluginEvaluationBubbleWidth (0.67 * Screen_Width)
#define TUICustomerServicePluginCardBubbleWidth (0.65 * Screen_Width)
#define TUIBotBranchCellWidth (0.65 * Screen_Width)
#define TUIBotBranchCellMargin 12
#define TUIBotBranchCellInnerMargin 8
@interface TUICustomerServicePluginDataProvider (CalculateSize)
+ (CGSize)calcBranchCellSize:(NSString *)header items:(NSArray *)items;
+ (CGSize)calcBranchCellSizeOfHeader:(NSString *)header;
+ (CGSize)calcBranchCellSizeOfTableView:(NSArray *)items;
+ (CGFloat)calcBranchCellHeightOfTableView:(NSArray *)items row:(NSInteger)row;
+ (CGFloat)calcBranchCellHeightOfContent:(NSString *)content;
+ (CGSize)calcCollectionCellSize:(NSString *)header items:(NSArray *)items;
+ (CGSize)calcCollectionCellSizeOfHeader:(NSString *)header;
+ (CGSize)calcCollectionCellSizeOfTableView:(NSArray *)items;
+ (CGFloat)calcCollectionCellHeightOfTableView:(NSArray *)items row:(NSInteger)row;
+ (CGFloat)calcCollectionCellHeightOfContent:(NSString *)content;
+ (CGSize)calcCollectionInputCellSize:(NSString *)header;
+ (CGSize)calcCollectionInputCellSizeOfHeader:(NSString *)header;
+ (CGSize)calcEvaluationCellSize:(NSString *)header
tail:(NSString *)tail
score:(NSInteger)score
selected:(BOOL)selected;
+ (CGSize)calcEvaluationBubbleSize:(NSString *)header score:(NSInteger)score;
+ (CGSize)calcEvaluationBubbleHeaderSize:(NSString *)header;
+ (CGSize)calcEvaluationBubbleScoreSize:(NSInteger)score;
+ (CGSize)calcEvaluationBubbleTailSize:(NSString *)tail;
+ (CGSize)calcCardHeaderSize:(NSString *)header;
+ (CGSize)calcMenuCellSize:(NSString *)title;
+ (CGSize)calcMenuCellButtonSize:(NSString *)title;
+ (CGSize)calcBotBranchCellSize:(NSString *)header items:(NSArray *)items;
+ (CGSize)calcBotBranchCellSizeOfHeader:(NSString *)header;
+ (CGSize)calcBotBranchCellSizeOfTableView:(NSArray *)items;
+ (CGFloat)calcBotBranchCellHeightOfTableView:(NSArray *)items row:(NSInteger)row;
+ (CGFloat)calcBotBranchCellHeightOfContent:(NSString *)content;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,232 @@
//
// TUICustomerServicePluginDataProvider+CalculateSize.m
// TUICustomerServicePlugin
//
// Created by xia on 2023/6/13.
//
#import "TUICustomerServicePluginDataProvider+CalculateSize.h"
#import <TUICore/TUIDefine.h>
@implementation TUICustomerServicePluginDataProvider (CalculateSize)
#pragma mark - Branch Cell
+ (CGSize)calcBranchCellSize:(NSString *)header items:(NSArray *)items {
float topBottomMargin = TUICustomerServicePluginBranchCellMargin;
float marginBetweenHeaderAndTableView = TUICustomerServicePluginBranchCellInnerMargin;
float headerHeight = [TUICustomerServicePluginDataProvider calcBranchCellSizeOfHeader:header].height;
float tableViewHeight = [TUICustomerServicePluginDataProvider calcBranchCellSizeOfTableView:items].height;
return CGSizeMake(TUICustomerServicePluginBranchCellWidth,
headerHeight + tableViewHeight + topBottomMargin * 2 + marginBetweenHeaderAndTableView);
}
+ (CGSize)calcBranchCellSizeOfHeader:(NSString *)header {
float leftRightMargin = TUICustomerServicePluginBranchCellMargin;
CGRect rect = [header boundingRectWithSize:CGSizeMake(TUICustomerServicePluginBranchCellWidth - leftRightMargin * 2, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return CGSizeMake(ceilf(rect.size.width), ceilf(rect.size.height));
}
+ (CGSize)calcBranchCellSizeOfTableView:(NSArray *)items {
CGFloat height = 0;
for (int i = 0; i < items.count; i++) {
height += [self calcBranchCellHeightOfTableView:items row:i];
}
return CGSizeMake(TUICustomerServicePluginBranchCellWidth, height);
}
+ (CGFloat)calcBranchCellHeightOfTableView:(NSArray *)items row:(NSInteger)row {
if (row < 0 || row >= items.count) {
return 0;
}
NSString *content = items[row];
return [self calcBranchCellHeightOfContent:content];
}
+ (CGFloat)calcBranchCellHeightOfContent:(NSString *)content {
float width = TUICustomerServicePluginBranchCellWidth - TUICustomerServicePluginBranchCellMargin * 2 - 5 - 6;
CGRect rect = [content boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return MAX(rect.size.height + 16, 36);
}
#pragma mark - Collection Cell
+ (CGSize)calcCollectionCellSize:(NSString *)header items:(NSArray *)items {
float topBottomMargin = TUICustomerServicePluginBranchCellMargin;
float marginBetweenHeaderAndTableView = TUICustomerServicePluginBranchCellInnerMargin;
float headerHeight = [TUICustomerServicePluginDataProvider calcCollectionCellSizeOfHeader:header].height;
float tableViewHeight = [TUICustomerServicePluginDataProvider calcCollectionCellSizeOfTableView:items].height;
return CGSizeMake(TUICustomerServicePluginBranchCellWidth,
headerHeight + tableViewHeight + topBottomMargin * 2 + marginBetweenHeaderAndTableView);
}
+ (CGSize)calcCollectionCellSizeOfHeader:(NSString *)header {
float leftRightMargin = TUICustomerServicePluginBranchCellMargin;
float width = TUICustomerServicePluginBranchCellWidth - leftRightMargin * 2;
CGRect rect = [header boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return CGSizeMake(width, rect.size.height);
}
+ (CGSize)calcCollectionCellSizeOfTableView:(NSArray *)items {
CGFloat height = 0;
for (int i = 0; i < items.count; i++) {
height += [self calcCollectionCellHeightOfTableView:items row:i];
}
return CGSizeMake(TUICustomerServicePluginBranchCellWidth, height);
}
+ (CGFloat)calcCollectionCellHeightOfTableView:(NSArray *)items row:(NSInteger)row {
if (row < 0 || row >= items.count) {
return 0;
}
NSString *content = items[row];
return [self calcBranchCellHeightOfContent:content];
}
+ (CGFloat)calcCollectionCellHeightOfContent:(NSString *)content {
float width = TUICustomerServicePluginBranchCellWidth - TUICustomerServicePluginBranchCellMargin * 2;
CGRect rect = [content boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return MAX(rect.size.height + 16, 36);
}
#pragma mark - Collection input cell
+ (CGSize)calcCollectionInputCellSize:(NSString *)header {
CGFloat headerHeight = [self calcCollectionInputCellSizeOfHeader:header].height;
return CGSizeMake(TUICustomerServicePluginInputCellWidth, headerHeight + 20 + 6 + 36);
}
+ (CGSize)calcCollectionInputCellSizeOfHeader:(NSString *)header {
float width = TUICustomerServicePluginInputCellWidth - TUICustomerServicePluginBranchCellMargin * 2;
CGRect rect = [header boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return CGSizeMake(width, MAX(rect.size.height, 22));
}
#pragma mark - Evaluation cell
+ (CGSize)calcEvaluationCellSize:(NSString *)header
tail:(NSString *)tail
score:(NSInteger)score
selected:(BOOL)selected {
float topLabelHeight = 20 + 20;
float bubbleHeight = [self calcEvaluationBubbleSize:header score:score].height;
float bottomHeight = 20;
if (selected) {
float height = [self calcEvaluationBubbleTailSize:tail].height;
bottomHeight += height;
}
return CGSizeMake(Screen_Width, topLabelHeight + bubbleHeight + bottomHeight);
}
+ (CGSize)calcEvaluationBubbleSize:(NSString *)header score:(NSInteger)score {
float width = TUICustomerServicePluginEvaluationBubbleWidth - TUICustomerServicePluginBranchCellMargin * 2;
float headerHeight = [self calcEvaluationBubbleHeaderSize:header].height;
float scoreHeight = [self calcEvaluationBubbleScoreSize:score].height;
return CGSizeMake(width, 20 + headerHeight + 12 + scoreHeight + 12 + 30 + 20);
}
+ (CGSize)calcEvaluationBubbleHeaderSize:(NSString *)header {
float width = TUICustomerServicePluginEvaluationBubbleWidth - TUICustomerServicePluginBranchCellMargin * 2;
CGRect rect = [header boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:12] }
context:nil];
return rect.size;
}
+ (CGSize)calcEvaluationBubbleScoreSize:(NSInteger)score {
float width = TUICustomerServicePluginEvaluationBubbleWidth - TUICustomerServicePluginBranchCellMargin * 2;
return CGSizeMake(width, score <= 5 ? 24 : 24 * 2 + 15);
}
+ (CGSize)calcEvaluationBubbleTailSize:(NSString *)tail {
float width = Screen_Width - 52 * 2;
CGRect rect = [tail boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:12] }
context:nil];
return CGSizeMake(width, rect.size.height + 20);
}
#pragma mark - Card cell
+ (CGSize)calcCardHeaderSize:(NSString *)header {
float width = TUICustomerServicePluginCardBubbleWidth - 120;
CGRect rect = [header boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:12] }
context:nil];
return CGSizeMake(width, rect.size.height);
}
#pragma mark - Menu button
+ (CGSize)calcMenuCellSize:(NSString *)title {
CGSize size = [self calcMenuCellButtonSize:title];
return CGSizeMake(size.width + 12, size.height + 8 + 6);
}
+ (CGSize)calcMenuCellButtonSize:(NSString *)title {
CGFloat margin = 28;
CGRect rect = [title boundingRectWithSize:CGSizeMake(MAXFLOAT, 32)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:14] }
context:nil];
return CGSizeMake(rect.size.width + margin, 32);
}
#pragma mark -Bot
+ (CGSize)calcBotBranchCellSize:(NSString *)header items:(NSArray *)items {
float topBottomMargin = TUIBotBranchCellMargin;
float marginBetweenHeaderAndTableView = TUIBotBranchCellInnerMargin;
float headerHeight = [TUICustomerServicePluginDataProvider calcBranchCellSizeOfHeader:header].height;
float tableViewHeight = [TUICustomerServicePluginDataProvider calcBranchCellSizeOfTableView:items].height;
return CGSizeMake(TUIBotBranchCellWidth,
headerHeight + tableViewHeight + topBottomMargin * 2 + marginBetweenHeaderAndTableView);
}
+ (CGSize)calcBotBranchCellSizeOfHeader:(NSString *)header {
float leftRightMargin = TUIBotBranchCellMargin;
CGRect rect = [header boundingRectWithSize:CGSizeMake(TUIBotBranchCellWidth - leftRightMargin * 2, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return CGSizeMake(TUIBotBranchCellWidth, rect.size.height);
}
+ (CGSize)calcBotBranchCellSizeOfTableView:(NSArray *)items {
CGFloat height = 0;
for (int i = 0; i < items.count; i++) {
height += [self calcBranchCellHeightOfTableView:items row:i];
}
return CGSizeMake(TUIBotBranchCellWidth, height);
}
+ (CGFloat)calcBotBranchCellHeightOfTableView:(NSArray *)items row:(NSInteger)row {
if (row < 0 || row >= items.count) {
return 0;
}
NSString *content = items[row];
return [self calcBranchCellHeightOfContent:content];
}
+ (CGFloat)calcBotBranchCellHeightOfContent:(NSString *)content {
float width = TUIBotBranchCellWidth - TUIBotBranchCellMargin * 2 - 5 - 6;
CGRect rect = [content boundingRectWithSize:CGSizeMake(width, MAXFLOAT)
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:16] }
context:nil];
return MAX(rect.size.height + 16, 36);
}
@end

View File

@@ -0,0 +1,21 @@
//
// TUICustomerServicePluginDataProvider.h
// Masonry
//
// Created by xia on 2023/6/12.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface TUICustomerServicePluginDataProvider : NSObject
+ (void)sendTextMessage:(NSString *)text;
+ (void)sendCustomMessage:(NSData *)data;
+ (void)sendCustomMessageWithoutUpdateUI:(NSData *)data;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,58 @@
//
// TUICustomerServicePluginDataProvider.m
// Masonry
//
// Created by xia on 2023/6/12.
//
#import "TUICustomerServicePluginDataProvider.h"
#import <TUICore/TUICore.h>
#import <TUICore/TUIDefine.h>
#import <ImSDK_Plus/ImSDK_Plus.h>
@implementation TUICustomerServicePluginDataProvider
+ (void)sendTextMessage:(NSString *)text {
V2TIMMessage *message = [[V2TIMManager sharedInstance] createTextMessage:text];
if (message == nil) {
return;
}
NSDictionary *param = @{TUICore_TUIChatService_SendMessageMethod_MsgKey: message};
[TUICore callService:TUICore_TUIChatService
method:TUICore_TUIChatService_SendMessageMethod
param:param];
}
+ (void)sendCustomMessage:(NSData *)data {
V2TIMMessage *message = [[V2TIMManager sharedInstance] createCustomMessage:[self supplyCustomerServiceID:data]];
if (message == nil) {
return;
}
NSDictionary *param = @{TUICore_TUIChatService_SendMessageMethod_MsgKey: message};
[TUICore callService:TUICore_TUIChatService
method:TUICore_TUIChatService_SendMessageMethod
param:param];
}
+ (void)sendCustomMessageWithoutUpdateUI:(NSData *)data {
V2TIMMessage *message = [[V2TIMManager sharedInstance] createCustomMessage:[self supplyCustomerServiceID:data]];
if (message == nil) {
return;
}
NSDictionary *param = @{TUICore_TUIChatService_SendMessageMethodWithoutUpdateUI_MsgKey: message};
[TUICore callService:TUICore_TUIChatService
method:TUICore_TUIChatService_SendMessageMethodWithoutUpdateUI
param:param];
}
+ (NSData *)supplyCustomerServiceID:(NSData *)data {
NSDictionary *dic = [TUITool jsonData2Dictionary:data];
if (!dic || 0 == dic.allKeys.count || [dic objectForKey:BussinessID_CustomerService]) {
return data;
}
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:dic];
[param setObject:@(0) forKey:BussinessID_CustomerService];
return [TUITool dictionary2JsonData:param];
}
@end