NewTopicVC.m 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. //
  2. // NewTopicVC.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/14.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "NewTopicVC.h"
  9. #import "LYLPhotoTailoringTool.h"
  10. #import "FWZFileGetTool.h"
  11. #import "FWZGetNoteBookTool.h"
  12. #import "RichTextEditViewController.h"
  13. #import "AddLookUpUserSecondVC.h"
  14. @interface NewTopicVC ()<WKUIDelegate,WKNavigationDelegate,UIScrollViewDelegate,WKScriptMessageHandler>
  15. @property (weak, nonatomic) IBOutlet UIView *NavBarV;
  16. @property (weak, nonatomic) IBOutlet UIButton *DoneBtn;
  17. @property (nonatomic,strong) WKWebView *webView;
  18. @property (nonatomic,assign) CGFloat keyBoardH;
  19. @property (nonatomic,assign) BOOL isShoujianren;
  20. @property (nonatomic,assign) BOOL isChaosongren;
  21. @property (nonatomic,strong) NSMutableArray <SelectModel *> *chaoShongArray;
  22. @property (nonatomic,strong) NSMutableArray <SelectModel *> *shouJianArray;
  23. @end
  24. @implementation NewTopicVC
  25. + (NewTopicVC *)initNewTopicVC{
  26. NewTopicVC *controller = [StoryboardManager.shared.TDGroupInfo instantiateViewControllerWithIdentifier:@"NewTopicVC"];
  27. return controller;
  28. }
  29. - (void)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. [[IQKeyboardManager sharedManager] setEnable:YES];
  33. }
  34. - (void)viewDidLoad {
  35. [super viewDidLoad];
  36. self.fd_prefersNavigationBarHidden = YES;
  37. WS(weakSelf);
  38. [self.DoneBtn setAction:^{
  39. [weakSelf submit];
  40. }];
  41. NSURL *pathUrl = [NSURL URLWithString:@"http://192.168.0.118:8080/#/mobile/editor"];
  42. // NSURL *pathUrl = [NSURL URLWithString:@"http://192.168.0.119:8080/#/mobile/topicDetails"];
  43. NSURLRequest *request = [NSURLRequest requestWithURL:pathUrl];
  44. [self.webView loadRequest:request];
  45. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
  46. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
  47. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recviveChaoSongRen:) name:NOTIFI_ChaoSongRen object:nil];
  48. }
  49. - (void)upDateAction:(NSString *)action
  50. {
  51. [self.webView evaluateJavaScript:action completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  52. NSLog(@"上传成功");
  53. }];
  54. }
  55. #pragma mark - layload
  56. - (WKWebView *)webView
  57. {
  58. if (!_webView) {
  59. WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
  60. // 实例化对象
  61. WKUserContentController* userContent = [[WKUserContentController alloc] init];
  62. [userContent addScriptMessageHandler:self name:@"chosePic"];
  63. [userContent addScriptMessageHandler:self name:@"toPZ"];
  64. [userContent addScriptMessageHandler:self name:@"toBJ"];
  65. [userContent addScriptMessageHandler:self name:@"toSC"];
  66. [userContent addScriptMessageHandler:self name:@"toWJ"];
  67. [userContent addScriptMessageHandler:self name:@"keyBoard"];
  68. [userContent addScriptMessageHandler:self name:@"approverCheckUsers"];
  69. [userContent addScriptMessageHandler:self name:@"carbonCopyUsers"];
  70. [userContent addScriptMessageHandler:self name:@"getType"];
  71. configuration.userContentController = userContent;
  72. WKPreferences *preferences = [WKPreferences new];
  73. preferences.javaScriptCanOpenWindowsAutomatically = YES;
  74. preferences.minimumFontSize = 40.0;
  75. configuration.preferences = preferences;
  76. // 初始化WKWebView
  77. _webView = [[WKWebView alloc]initWithFrame:CGRectZero configuration:configuration];
  78. // UI代理
  79. _webView.UIDelegate = self;
  80. // 导航代理
  81. _webView.navigationDelegate = self;
  82. _webView.scrollView.delegate = self;
  83. }
  84. return _webView;
  85. }
  86. -(NSMutableArray<SelectModel *> *)shouJianArray{
  87. if(!_shouJianArray){
  88. _shouJianArray = [[NSMutableArray alloc] init];
  89. }
  90. return _shouJianArray;
  91. }
  92. -(NSMutableArray<SelectModel *> *)chaoShongArray{
  93. if(!_chaoShongArray){
  94. _chaoShongArray = [[NSMutableArray alloc] init];
  95. }
  96. return _chaoShongArray;
  97. }
  98. #pragma mark - KeyBoard
  99. - (void)keyBoardWillShow:(NSNotification *)note
  100. {
  101. // 获取用户信息
  102. NSDictionary *userInfo = [NSDictionary dictionaryWithDictionary:note.userInfo];
  103. // 获取键盘高度
  104. CGRect keyBoardBounds = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
  105. self.keyBoardH = keyBoardBounds.size.height;
  106. [self.webView evaluateJavaScript:@"textFocus()" completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  107. NSLog(@"keyShow");
  108. }];
  109. }
  110. - (void)keyBoardWillHide:(NSNotification *)note
  111. {
  112. self.keyBoardH = 0.f;
  113. [self.webView evaluateJavaScript:@"blur()" completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  114. NSLog(@"keyHidden");
  115. }];
  116. }
  117. #pragma mark - WKScriptMessageHandler
  118. - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
  119. WS(weakSelf);
  120. NSLog(@"messageName:%@",message.name);
  121. if ([message.name isEqualToString:@"chosePic"]) {
  122. [self chatBarDidPhotoAction];
  123. }
  124. if ([message.name isEqualToString:@"toPZ"]) {
  125. [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
  126. } choosImgBlock:^(UIImage *image) {
  127. [weakSelf didSelectImage:@[image]];
  128. }];
  129. }
  130. if ([message.name isEqualToString:@"toBJ"]) {
  131. [[FWZGetNoteBookTool sharedTool] openNoteBookListChooseNoteBookBlock:^(NSMutableArray<MyNoteBookSubModel *> * _Nonnull noteArr) {
  132. NSLog(@"SmartBarNotes %@",noteArr);
  133. [weakSelf disSelectNoteBook:noteArr];
  134. }];
  135. }
  136. if ([message.name isEqualToString:@"toSC"]) {
  137. [[FWZGetNoteBookTool sharedTool] openCollectListChooseCollectBlock:^(NSMutableArray<MyFavoriteSubModel *> * _Nonnull collectArr) {
  138. NSLog(@"SmartBarCollection %@",collectArr);
  139. [weakSelf disSelectCollect:collectArr];
  140. }];
  141. }
  142. if ([message.name isEqualToString:@"toWJ"]) {
  143. [[FWZFileGetTool sharedTool] openFileWithCrop:YES showImgBlock:^(NSString * _Nonnull fileUrlStr) {
  144. } choosFileBlock:^(NSData * _Nonnull fileData, NSString * _Nonnull fileName) {
  145. SHOWLOADING
  146. [[HttpManager sharedHttpManager] HeaderUploadFileUrl:Host(Modify_UserImages_Post) parameters:@{} fileData:fileData fileKey:@"file" fileName:fileName mimeType:@"multipart/form-data" success:^(id _Nonnull responseObject) {
  147. REMOVESHOW
  148. NSLog(@"上传成功的文件%@",responseObject);
  149. NSString *jsonString = [NSString stringWithFormat:@"getAndroidImg('%@','%@','%ld')",responseObject[@"AbsolutePath"],responseObject[@"FileName"],(long)CollectDataType_File];
  150. [weakSelf upDateAction:jsonString];
  151. } failure:^(NSError * _Nonnull error) {
  152. REMOVESHOW
  153. }];
  154. }];
  155. }
  156. if ([message.name isEqualToString:@"keyBoard"]) {
  157. NSString *jsonString = [NSString stringWithFormat:@"getIosKeyBorad('%f')",self.keyBoardH];
  158. [self.webView evaluateJavaScript:jsonString completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  159. }];
  160. }
  161. if ([message.name isEqualToString:@"approverCheckUsers"]) {
  162. self.isShoujianren = YES;
  163. self.isChaosongren = NO;
  164. [self selectPeopleWithType:1];
  165. }
  166. if ([message.name isEqualToString:@"carbonCopyUsers"]) {
  167. self.isShoujianren = NO;
  168. self.isChaosongren = YES;
  169. [self selectPeopleWithType:2];
  170. }
  171. if ([message.name isEqualToString:@"getType"]) {
  172. NSString *jsonString = [NSString stringWithFormat:@"getType('%d','%d','%d','%@')",1,1,622,USERDEFAULTSGET(@"LOGINTOKEN")];
  173. [self.webView evaluateJavaScript:jsonString completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  174. NSLog(@"data:%@",data);
  175. NSLog(@"error:%@",error);
  176. }];
  177. }
  178. }
  179. - (void)selectPeopleWithType:(NSInteger)type {
  180. AddLookUpUserSecondVC *vc = [[AddLookUpUserSecondVC alloc] init];
  181. vc.isAllSelected = YES;
  182. Department *defaltGroupSetion = [[Department alloc]init];
  183. defaltGroupSetion.Name = @"单位通讯录";
  184. defaltGroupSetion.Id = 0;
  185. defaltGroupSetion.SourceId = 0;
  186. defaltGroupSetion.SourceType = 1;
  187. defaltGroupSetion.SourceName = @"单位通讯录";
  188. defaltGroupSetion.MiddleType = type;
  189. Department *myGroupSetion = [[Department alloc]init];
  190. myGroupSetion.Name = @"自建通讯录";
  191. myGroupSetion.Id = 0;
  192. myGroupSetion.MiddleType = type;
  193. myGroupSetion.SourceType = 3;
  194. myGroupSetion.SourceId = 0;
  195. myGroupSetion.SourceName = @"自建通讯录";
  196. vc.departSourceDataArray = @[defaltGroupSetion,myGroupSetion].mutableCopy;
  197. vc.isDefalutPage = 1;
  198. vc.titleStr = @"选人";
  199. [self.navigationController pushViewController:vc animated:YES];
  200. }
  201. - (void)recviveChaoSongRen:(NSNotification *)notification{
  202. if (self.isShoujianren) {
  203. NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
  204. if (array.count > 0) {
  205. NSLog(@"shouJianArray结果数据组%@",array);
  206. NSString *jsonString = [NSString stringWithFormat:@"getApproverCheckUsersList('%@')",[self arrayToJSONModel:array]];
  207. [self.webView evaluateJavaScript:jsonString completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  208. NSLog(@"data:%@",data);
  209. NSLog(@"error:%@",error);
  210. }];
  211. }
  212. }
  213. if (self.isChaosongren) {
  214. NSMutableArray <SelectModel *>* array = notification.userInfo[@"selectPeople"];
  215. if (array.count > 0) {
  216. NSLog(@"chaoShongArray结果数据组%@",array);
  217. NSString *jsonString = [NSString stringWithFormat:@"getCarbonCopyUsersList('%@')",[self arrayToJSONModel:array]];
  218. [self.webView evaluateJavaScript:jsonString completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  219. NSLog(@"data:%@",data);
  220. NSLog(@"error:%@",error);
  221. }];
  222. }
  223. }
  224. }
  225. #pragma mark - 选择图片
  226. - (void)chatBarDidPhotoAction
  227. {
  228. WS(weakSelf);
  229. [self.view endEditing:YES];
  230. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:nil];
  231. [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
  232. leftButton.hidden = YES;
  233. }];
  234. imagePickerVc.showSelectBtn = NO;
  235. imagePickerVc.allowCrop = YES;
  236. imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
  237. imagePickerVc.allowTakePicture = NO;
  238. imagePickerVc.allowTakeVideo = NO;
  239. imagePickerVc.allowPickingOriginalPhoto = NO;
  240. imagePickerVc.allowPickingGif = NO;
  241. [imagePickerVc setIsStatusBarDefault:YES];
  242. [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
  243. [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
  244. [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
  245. PHAsset *asset = assets.firstObject;
  246. switch (asset.mediaType) {
  247. case PHAssetMediaTypeVideo: {
  248. } break;
  249. case PHAssetMediaTypeImage: {
  250. [weakSelf didSelectImage:photos];
  251. } break;
  252. case PHAssetMediaTypeAudio:
  253. break;
  254. case PHAssetMediaTypeUnknown:
  255. break;
  256. default: break;
  257. }
  258. }];
  259. [self presentViewController:imagePickerVc animated:YES completion:nil];
  260. }
  261. - (void)didSelectImage:(NSArray *)images
  262. {
  263. NSMutableArray * array = [NSMutableArray array];
  264. for (UIImage * image in images) {
  265. NSData *data = UIImageJPEGRepresentation(image, 1);
  266. [array addObject:data];
  267. }
  268. WS(weakSelf);
  269. NSString *urlString = [[NSString alloc] initWithFormat:@"%@%@",BaseUrl,Modify_UserImages_Post];
  270. [[HttpManager sharedHttpManager] HeaderUploadUrl:urlString parameters:@{} pictureArray:array pictureKey:@"file" success:^(id _Nonnull responseObject) {
  271. NSLog(@"%@",responseObject);
  272. for (NSDictionary * dict in responseObject) {
  273. NSString *jsonString = [NSString stringWithFormat:@"getAndroidImg('%@','%@','%ld')",dict[@"AbsolutePath"],dict[@"FileName"],(long)CollectDataType_IMG];
  274. [weakSelf upDateAction:jsonString];
  275. }
  276. } failure:^(NSError * _Nonnull error) {
  277. }];
  278. }
  279. #pragma mark - 选择笔记
  280. - (void)disSelectNoteBook:(NSMutableArray<MyNoteBookSubModel *>*_Nonnull )noteArr{
  281. for (MyNoteBookSubModel *dataModel in noteArr ) {
  282. if (dataModel.AttributeValue == 1) {
  283. NSString *jsonString = [NSString stringWithFormat:@"getAndroidNoteCollection('%ld','%@','%ld','%@')",(long)CollectDataType_Note,dataModel.Title,(long)dataModel.MiddleId,dataModel.Name];
  284. [self upDateAction:jsonString];
  285. }else{
  286. NSString *jsonString = [NSString stringWithFormat:@"getAndroidNoteCollection('%ld','%@','%ld','%@')",(long)CollectDataType_NoteFile,dataModel.FolderName,(long)dataModel.Id,[AppUserModel sharedAppUserModel].Name];
  287. [self upDateAction:jsonString];
  288. }
  289. }
  290. }
  291. #pragma mark - 选择收藏
  292. - (void)disSelectCollect:(NSMutableArray<MyFavoriteSubModel *> * _Nonnull) collectArr{
  293. for (MyFavoriteSubModel *dataModel in collectArr ) {
  294. if(dataModel.AttributeValue == 1)
  295. {
  296. NSString *jsonString = [NSString stringWithFormat:@"getAndroidNoteCollection('%ld','%@','%ld','%@')",(long)[ZYCTool returnDataType:dataModel.CollectionType],dataModel.Title,(long)dataModel.CollectionDataId,dataModel.Data.Author];
  297. [self upDateAction:jsonString];
  298. }else{
  299. NSString *jsonString = [NSString stringWithFormat:@"getAndroidNoteCollection('%ld','%@','%ld','%@')",(long)CollectDataType_CollectFile,dataModel.FolderName,(long)dataModel.Id,[AppUserModel sharedAppUserModel].Name];
  300. [self upDateAction:jsonString];
  301. }
  302. }
  303. }
  304. #pragma mark - WKScriptMessageHandler
  305. -(NSString *)convertToJson:(NSDictionary *)dict
  306. {
  307. NSError *error;
  308. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
  309. NSString *jsonString;
  310. if (!jsonData) {
  311. NSLog(@"%@",error);
  312. }else{
  313. jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
  314. }
  315. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  316. NSRange range = {0,jsonString.length};
  317. //去掉字符串中的空格
  318. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  319. NSRange range2 = {0,mutStr.length};
  320. //去掉字符串中的换行符
  321. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  322. return mutStr;
  323. }
  324. #pragma mark - WKUIDelegete
  325. - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(nonnull NSString *)message initiatedByFrame:(nonnull WKFrameInfo *)frame completionHandler:(nonnull void (^)(void))completionHandler
  326. {
  327. NSLog(@"%@",message);
  328. completionHandler();
  329. }
  330. - (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(nonnull NSString *)message initiatedByFrame:(nonnull WKFrameInfo *)frame completionHandler:(nonnull void (^)(BOOL))completionHandler
  331. {
  332. NSLog(@"223123");
  333. completionHandler(YES);
  334. }
  335. - (void)webView:(WKWebView *)webView runJavaScriptTextInputPanelWithPrompt:(nonnull NSString *)prompt defaultText:(nullable NSString *)defaultText initiatedByFrame:(nonnull WKFrameInfo *)frame completionHandler:(nonnull void (^)(NSString * _Nullable))completionHandler
  336. {
  337. NSLog(@"323123");
  338. completionHandler(@"111");
  339. }
  340. #pragma mark - 提交富文本
  341. - (void)submit
  342. {
  343. NSString *jsonString = [NSString stringWithFormat:@"getEditorText()"];
  344. [self.webView evaluateJavaScript:jsonString completionHandler:^(id _Nullable data, NSError * _Nullable error) {
  345. NSLog(@"submit:%@",data);
  346. NSDictionary * dict = (NSDictionary *)data;
  347. switch (self.type) {
  348. case CreateNoticeType:
  349. {
  350. [self submitNotice:dict];
  351. }
  352. break;
  353. case CreateTopicType:
  354. {
  355. [self submitTopic:dict];
  356. }
  357. break;
  358. default:
  359. break;
  360. }
  361. }];
  362. }
  363. #pragma mark - 提交通知
  364. - (void)submitNotice:(NSDictionary *)dict
  365. {
  366. NSString * html = dict[@"html"];
  367. NSArray * jsonArray = dict[@"json"];
  368. NSMutableDictionary * paraDict = [NSMutableDictionary dictionary];
  369. [paraDict setObject:dict[@"Title"] forKey:@"Title"];
  370. [paraDict setObject:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  371. [paraDict setValue:self.isDraft ? @(2) : @(1) forKey:@"NoticeType"];
  372. if (self.isFolder) {
  373. [paraDict setValue:@(self.FolderId) forKey:@"FolderId"];
  374. }
  375. [paraDict setObject:html forKey:@"HtmlContent"];
  376. [paraDict setObject:dict[@"AddresseeUserMiddles"] forKey:@"AddresseeUserMiddles"];
  377. [paraDict setObject:dict[@"CcUserMiddles"] forKey:@"CcUserMiddles"];
  378. [paraDict setObject:[self arrayToJSONString:jsonArray] forKey:@"Content"];
  379. if (self.isEdit) {
  380. [paraDict setObject:@(self.Id) forKey:@"id"];
  381. [self sentChangeNotice:paraDict withNoticeType:self.isDraft ? 2 : 1];
  382. }else{
  383. [self sentNoticeRequeast:paraDict withNoticeType:self.isDraft ? 2 : 1];
  384. }
  385. }
  386. - (void)sentChangeNotice:(NSMutableDictionary *)dic withNoticeType:(NSInteger)NoticeType{
  387. WS(weakSelf);
  388. [[HttpManager sharedHttpManager] POSTUrl:Host(API_NOTICE_EDIT) parameters:dic responseStyle:DATA success:^(id _Nonnull responseObject) {
  389. REMOVESHOW
  390. if(NoticeType == 1){
  391. SHOWSUCCESS(@"通知已经发送");
  392. }else{
  393. SHOWSUCCESS(@"通知已经存放草稿箱");
  394. }
  395. [weakSelf.navigationController popViewControllerAnimated:YES];
  396. } failure:^(NSError * _Nonnull error) {
  397. SHOWERROR([ZYCTool handerResultData:error]);
  398. }];
  399. }
  400. - (void)sentNoticeRequeast:(NSMutableDictionary *)dic withNoticeType:(NSInteger)NoticeType{
  401. WS(weakSelf);
  402. [[HttpManager sharedHttpManager] PUTUrl:Host(API_NOTICE_ADD) parameters:dic success:^(id _Nonnull responseObject) {
  403. REMOVESHOW
  404. if(NoticeType == 1){
  405. SHOWSUCCESS(@"通知已经发送");
  406. }else{
  407. SHOWSUCCESS(@"通知已经存放草稿箱");
  408. }
  409. [weakSelf.navigationController popViewControllerAnimated:YES];
  410. } failure:^(NSError * _Nonnull error) {
  411. SHOWERROR([ZYCTool handerResultData:error]);
  412. }];
  413. }
  414. #pragma mark - 提交话题
  415. - (void)submitTopic:(NSDictionary *)dict
  416. {
  417. NSString * html = dict[@"html"];
  418. NSArray * jsonArray = dict[@"json"];
  419. NSMutableDictionary * paraDict = [NSMutableDictionary dictionary];
  420. [paraDict setObject:dict[@"Title"] forKey:@"Title"];
  421. [paraDict setObject:@([AppUserModel sharedAppUserModel].Id) forKey:@"UserId"];
  422. [paraDict setObject:@(0) forKey:@"FolderId"];
  423. [paraDict setObject:@[] forKey:@"TopicAddresseeUserIds"];
  424. [paraDict setObject:html forKey:@"HtmlContent"];
  425. [paraDict setObject:[self arrayToJSONString:jsonArray] forKey:@"Content"];
  426. SHOWLOADING
  427. [[HttpManager sharedHttpManager] POSTUrl:Host(APP_Topic_Add) parameters:paraDict responseStyle:DATA success:^(id _Nonnull responseObject) {
  428. NSLog(@"%@",responseObject);
  429. REMOVESHOW
  430. SHOWSUCCESS(@"创建成功");
  431. } failure:^(NSError * _Nonnull error) {
  432. REMOVESHOW
  433. SHOWERROR([ZYCTool handerResultData:error])
  434. }];
  435. }
  436. - (NSString *)arrayToJSONModel:(NSArray *)array
  437. {
  438. NSMutableArray * mArray = [NSMutableArray array];
  439. for (SelectModel * model in array) {
  440. NSDictionary * dict = [model modelToJSONObject];
  441. [mArray addObject:@{@"SourceType":dict[@"SourceType"],@"SourceId":dict[@"SourceId"],@"SourceName":dict[@"SourceName"],@"MiddleType":@(self.type)}];
  442. }
  443. return [self arrayToJSONString:mArray];
  444. }
  445. - (NSString *)arrayToJSONString:(NSArray *)array
  446. {
  447. NSError *error = nil;
  448. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:array options:NSJSONWritingPrettyPrinted error:&error];
  449. NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  450. NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
  451. NSRange range = {0,jsonString.length};
  452. //去掉字符串中的空格
  453. [mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
  454. NSRange range2 = {0,mutStr.length};
  455. //去掉字符串中的换行符
  456. [mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
  457. return mutStr;
  458. }
  459. - (void)dealloc {
  460. WKUserContentController *userCC = self.webView.configuration.userContentController;
  461. [userCC removeScriptMessageHandlerForName:@"chosePic"];
  462. [userCC removeScriptMessageHandlerForName:@"toPZ"];
  463. [userCC removeScriptMessageHandlerForName:@"toBJ"];
  464. [userCC removeScriptMessageHandlerForName:@"toSC"];
  465. [userCC removeScriptMessageHandlerForName:@"toWJ"];
  466. [userCC removeScriptMessageHandlerForName:@"keyBoard"];
  467. [userCC removeScriptMessageHandlerForName:@"getType"];
  468. [userCC removeScriptMessageHandlerForName:@"approverCheckUsers"];
  469. [userCC removeScriptMessageHandlerForName:@"carbonCopyUsers"];
  470. [[NSNotificationCenter defaultCenter] removeObserver:self];
  471. [self.webView stopLoading];
  472. self.webView.UIDelegate = nil;
  473. self.webView.navigationDelegate = nil;
  474. self.webView.scrollView.delegate = nil;
  475. [self.webView removeFromSuperview];
  476. }
  477. - (void)viewWillDisappear:(BOOL)animated
  478. {
  479. [super viewWillDisappear:animated];
  480. WKWebsiteDataStore *dateStore = [WKWebsiteDataStore defaultDataStore];
  481. [dateStore fetchDataRecordsOfTypes:[WKWebsiteDataStore allWebsiteDataTypes]
  482. completionHandler:^(NSArray * __nonnull records) {
  483. for (WKWebsiteDataRecord *record in records)
  484. {
  485. [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:record.dataTypes
  486. forDataRecords:@[record]
  487. completionHandler:^{
  488. NSLog(@"Cookies for %@ deleted successfully",record.displayName);
  489. }];
  490. }
  491. }];
  492. }
  493. @end