H5ViewController.m 23 KB

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