resourceLibraryHomeCtrl.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. angular.module('push')
  2. .controller('resourceLibraryHomeCtrl', function ($scope, ResourceLibraryService, UtilService, $timeout, $ionicListDelegate, SqliteStorageService, UserService,
  3. HandleService, resourceLibraryTempData, SynchroService, ConfigService, ConstantService, $ionicScrollDelegate) {
  4. document.title = '资源库';
  5. if (UserService.defaultLan == 'English') {
  6. document.title = 'Database';
  7. }
  8. $scope.resourcelibrarylist = [];
  9. var uploadresliblist = [];
  10. var resourcelist = [];
  11. $scope.user = UserService.user.user;
  12. $scope.viplevel = UserService.viplevel;
  13. $scope.keyword = "";// 搜索关键词
  14. $scope.node = UserService.node;//节点号
  15. $scope.nodename = UserService.nodename;//节点号名称
  16. $scope.resinfocount = 0;//资源总数
  17. $scope.resexpertcount = 0;//专家总数
  18. $scope.resorgcount = 0;//企业总数
  19. $scope.resresearchfindingcount = 0;//成果总数
  20. $scope.techrequirementcount = 0;//需求总数
  21. $scope.defaultLan = UserService.defaultLan;
  22. $scope.comfromWeb = sessionStorage.comfrom == 'web';
  23. var updateHandleData = function (res) {
  24. if (res.insertList) {
  25. // console.log("-------------------res.insertList------------------------");
  26. // console.log(res.insertList);
  27. for (key in res.insertList) {
  28. SqliteStorageService.insertBatchData(key, res.insertList[key]).then(function () {
  29. // console.log("批量insert成功");
  30. }, function () {
  31. })
  32. }
  33. }
  34. if (res.updateList) {
  35. // console.log("-------------------res.updateList------------------------");
  36. // console.log(res.updateList);
  37. for (key in res.updateList) {
  38. SqliteStorageService.updateBatchData(key, res.updateList[key]).then(function () {
  39. // console.log("批量修改成功");
  40. }, function () {
  41. })
  42. }
  43. }
  44. if (res.deleteList) {
  45. // console.log("-------------------res.deleteList------------------------");
  46. // console.log(res.deleteList);
  47. for (key in res.deleteList) {
  48. SqliteStorageService.deleteBatchData(key, res.deleteList[key]).then(function () {
  49. // console.log("批量delete成功");
  50. }, function () {
  51. })
  52. }
  53. }
  54. $timeout(function () {
  55. UtilService.showMess("同步完成");
  56. ConfigService.ressynchroflg = false;
  57. initResourceLibraryList();
  58. $scope.hideLoadingToast();
  59. }, 300);
  60. };
  61. var handleResponseData = function (tempresponse) {
  62. //--第一次,本地没有数据,server数据全部返回处理
  63. if (tempresponse.responsetype == 1) {
  64. if (angular.isDefined(tempresponse.folderlist)) {
  65. HandleService.handleFirstServerResourceData(tempresponse.folderlist).then(function (res) {
  66. // console.log("处理返回数据,按表划分");
  67. // console.log(res);
  68. for (key in res) {
  69. SqliteStorageService.insertBatchData(key, res[key]).then(function (res) {
  70. // console.log("OK")
  71. }, function () {
  72. })
  73. }
  74. $timeout(function () {
  75. UtilService.showMess("同步完成");
  76. ConfigService.ressynchroflg = false;
  77. initResourceLibraryList();
  78. $scope.hideLoadingToast();
  79. }, 300);
  80. }, function () {
  81. });
  82. } else {
  83. $scope.hideLoadingToast();
  84. }
  85. }
  86. //--第二及之后,本地有数据,server数据部分返回处理
  87. if (tempresponse.responsetype == 2) {
  88. HandleService.handleSecondServerResourceData(tempresponse.folderReturnList, tempresponse.recordReturnList, uploadresliblist).then(function (res) {
  89. // console.log("按增删改处理同步返回的数据");
  90. // console.log(res);
  91. updateHandleData(res);
  92. }, function () {
  93. $scope.hideLoadingToast();
  94. });
  95. }
  96. };
  97. //资源同步
  98. var synchroResource = function () {
  99. uploadresliblist.sort(function (a, b) {
  100. return a.level - b.level;//置顶(level)升序
  101. });
  102. // console.log("------------------------------------");
  103. // console.log(uploadresliblist);
  104. // console.log(resourcelist);
  105. SynchroService.synchroResourceData(uploadresliblist, resourcelist).then(function (response) {
  106. // console.log("同步成功,返回的数据");
  107. // console.log(response);
  108. handleResponseData(response);
  109. }, function () {
  110. $scope.hideLoadingToast();
  111. })
  112. };
  113. //取本地资源
  114. var getResourceList = function () {
  115. var claidlist = "";
  116. angular.forEach(uploadresliblist, function (value) {
  117. var tempstr = "'" + value.localid + "'";
  118. claidlist = claidlist + tempstr + ",";
  119. });
  120. claidlist = claidlist.substring(0, claidlist.length - 1);
  121. var sql = "select * from resource where localclaid in (" + claidlist + ")";
  122. SqliteStorageService.queryData(sql).then(function (response) {
  123. // console.log(response);
  124. resourcelist = response;
  125. synchroResource();
  126. }, function () {
  127. })
  128. };
  129. //初始化资源库列表
  130. $scope.rescontactflg = 0;//0:本地/云资源库开始查询 2:查询结束
  131. var tempLocalResourceLibrarylist = [];
  132. var tempCloudResourceLibrarylist = [];
  133. $scope.resinfocount = 0;//资源总数
  134. var initResourceLibraryList = function () {
  135. // $scope.showLoadingToast();
  136. /*//--查询本地资源库
  137. tempLocalResourceLibrarylist = [];
  138. uploadresliblist = [];
  139. var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0 and type = 2 order by updatetime desc";
  140. SqliteStorageService.queryData(sql).then(function (response) {
  141. // console.log(response);
  142. angular.forEach(response, function (value, index) {
  143. if (value.localparentid == "0") {
  144. tempLocalResourceLibrarylist.push(value);
  145. }
  146. uploadresliblist.push(value);
  147. });
  148. $scope.rescontactflg++;
  149. //同步标志为true,去同步
  150. if (ConfigService.ressynchroflg) {
  151. if (uploadresliblist.length > 0) {
  152. getResourceList();
  153. } else {
  154. resourcelist = [];
  155. synchroResource();
  156. }
  157. }
  158. }, function () {
  159. tempLocalResourceLibrarylist = [];
  160. $scope.rescontactflg++;
  161. });*/
  162. //--查询云资源库;
  163. ResourceLibraryService.getResourceLibrary($scope.keyword, $scope.node).then(function (response) {
  164. if (UtilService.isDefined(response.data)) {
  165. console.log(response.data);
  166. // 配置图片
  167. tempCloudResourceLibrarylist = response.data;
  168. angular.forEach(tempCloudResourceLibrarylist, function (val) {
  169. val.logo = [];
  170. val.logo = val.name == '企业库' ? ['./img/2018/company1.png', './img/2018/company2.jpeg', './img/2018/company3.png']
  171. : val.name == '高校库' ? ['./img/2018/university1.png', './img/2018/university2.png', './img/2018/university3.png']
  172. : val.name == '人才库' || val.name == '技术经纪人库' ? ['./img/2018/person1.png', './img/2018/person2.png', './img/2018/person3.png']
  173. : val.name == '需求库' ? ['./img/2018/demand1.jpg', './img/2018/demand2.jpg']
  174. : val.name == '成果库' ? ['./img/2018/product1.jpg', './img/2018/product2.jpg', './img/2018/product3.jpg']
  175. : ['./img/2018/other1-1.jpg', './img/2018/other1-2.jpg', './img/2018/other1-3.jpg'];
  176. if ($scope.isLiyangApp && val.name == '企业库') {
  177. val.logo = ['./img/2018/liyang1.jpg', './img/2018/liyang2.jpg', './img/2018/liyang3.jpg'];
  178. }
  179. })
  180. } else {
  181. tempCloudResourceLibrarylist = [];
  182. }
  183. $scope.rescontactflg++;
  184. $scope.rescontactflg++;
  185. }, function () {
  186. tempCloudResourceLibrarylist = [];
  187. $scope.rescontactflg++;
  188. $scope.rescontactflg++;
  189. })
  190. };
  191. initResourceLibraryList();
  192. //拼接本地与云文件夹(按sort、updatetime排序)
  193. var connectLocalAndCloud = function () {
  194. HandleService.connectLocalAndCloud(tempLocalResourceLibrarylist, tempCloudResourceLibrarylist).then(function (response) {
  195. $scope.resourcelibrarylist = response;
  196. console.log(response);
  197. if ($scope.resourcelibrarylist.length == 0) {
  198. $scope.shownone = true;
  199. } else {
  200. $scope.shownone = false;
  201. $scope.resinfocount = 0;//资源总数
  202. // 节点资源总数
  203. angular.forEach($scope.resourcelibrarylist, function (value) {
  204. $scope.resinfocount += value.infocount;//资源总数
  205. if (value.moduleid == ConstantService.CATEGORY_MODULE_8) {
  206. $scope.resexpertcount = value.infocount;//专家总数
  207. }
  208. if (value.moduleid == ConstantService.CATEGORY_MODULE_6) {
  209. $scope.resorgcount = value.infocount;//企业总数
  210. }
  211. if (value.moduleid == ConstantService.CATEGORY_MODULE_2) {
  212. $scope.resresearchfindingcount = value.infocount;//成果总数
  213. }
  214. if (value.moduleid == ConstantService.CATEGORY_MODULE_1) {
  215. $scope.techrequirementcount = value.infocount;//需求总数
  216. }
  217. });
  218. }
  219. resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist);
  220. $scope.hideLoadingToast();
  221. }, function () {
  222. $scope.hideLoadingToast();
  223. })
  224. };
  225. connectLocalAndCloud();
  226. //--监听本地与云文件夹查询是否结束
  227. $scope.$watch("rescontactflg", function (newValue) {
  228. if (newValue == 2) {
  229. //本地与云均无,显示缺省页
  230. if (tempCloudResourceLibrarylist.length == 0 && tempLocalResourceLibrarylist.length == 0) {
  231. $scope.shownone = true;
  232. $scope.resourcelibrarylist = [];
  233. $scope.hideLoadingToast();
  234. } else {
  235. //无云文件夹显示本地
  236. if (tempCloudResourceLibrarylist.length < 1) {
  237. $scope.resourcelibrarylist = tempLocalResourceLibrarylist;
  238. console.log($scope.resourcelibrarylist);
  239. $scope.hideLoadingToast();
  240. }
  241. //无本地文件夹显示云
  242. if (tempLocalResourceLibrarylist.length < 1) {
  243. $scope.resourcelibrarylist = tempCloudResourceLibrarylist;
  244. // 节点资源总数
  245. $scope.resinfocount = 0;
  246. angular.forEach($scope.resourcelibrarylist, function (value) {
  247. $scope.resinfocount += value.infocount;//资源总数
  248. if (value.moduleid == ConstantService.CATEGORY_MODULE_8) {
  249. $scope.resexpertcount = value.infocount;//专家总数
  250. }
  251. if (value.moduleid == ConstantService.CATEGORY_MODULE_6) {
  252. $scope.resorgcount = value.infocount;//企业总数
  253. }
  254. if (value.moduleid == ConstantService.CATEGORY_MODULE_2) {
  255. $scope.resresearchfindingcount = value.infocount;//成果总数
  256. }
  257. if (value.moduleid == ConstantService.CATEGORY_MODULE_1) {
  258. $scope.techrequirementcount = value.infocount;//需求总数
  259. }
  260. });
  261. $scope.hideLoadingToast();
  262. }
  263. //本地与云均有去拼接
  264. if (tempCloudResourceLibrarylist.length > 0 && tempLocalResourceLibrarylist.length > 0) {
  265. connectLocalAndCloud();
  266. }
  267. $scope.shownone = false;
  268. }
  269. $scope.rescontactflg = 0;
  270. resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist);
  271. // console.log($scope.resourcelibrarylist);
  272. }
  273. });
  274. $scope.$on("$ionicView.beforeEnter", function () {
  275. //TODO
  276. if ($scope.app) {
  277. $scope.setStatusBar(1);
  278. }
  279. $scope.node = UserService.node;//节点号
  280. $scope.nodename = UserService.nodename;//节点号名称
  281. $scope.resinfocount = 0;//资源总数
  282. $ionicScrollDelegate.$getByHandle('calenderContent').scrollTop();
  283. initResourceLibraryList();
  284. initResourceLibraryNodeBg();
  285. });
  286. //资源库搜索
  287. $scope.goResourceSearch = function () {
  288. $timeout(function () {
  289. $scope.go('resourceSearch');
  290. }, 350);
  291. };
  292. //获取定位
  293. $scope.getPosition = function () {
  294. // console.log("获取位置");
  295. };
  296. //进入资源库列表
  297. $scope.goResorceLibaryDetail = function (res) {
  298. resourceLibraryTempData.setCategoryIndex(0);
  299. resourceLibraryTempData.resetChecked();
  300. if (res.moduleid == false && UserService.node == '330122000') {
  301. window.open("http://app.zjumap.com:7736/#/index", "_blank");
  302. } else if (res.moduleid == 44) {
  303. $scope.go('wujingTeacher');
  304. } else if (res.moduleid == 43) {
  305. $scope.go('wujingTechnical');
  306. } else if (res.moduleid == 33) {
  307. //通知公告库
  308. $scope.go("notification");
  309. } else {
  310. //进入公共资源库列表
  311. if (res.fixtype == 1) {
  312. $scope.go('publicResource', {
  313. libtype: reclibc.moduleid,
  314. name: reclibc.name,
  315. reclibid: $scope.reclib.id,
  316. modlibid: reclibc.id
  317. });
  318. } else if (res.fixtype == 2) {
  319. //进入私人资源库列表
  320. $scope.go('privateResource', {
  321. res: angular.toJson(res),
  322. privateName: res.name,
  323. groupid: res.parentid,
  324. restype: res.moduleid,
  325. privateContent: res.content,
  326. authority: res.by5
  327. });
  328. }
  329. }
  330. };
  331. //进入设置资源库页面
  332. $scope.goResourceSet = function (reclib) {
  333. $timeout(function () {
  334. $ionicListDelegate.closeOptionButtons();
  335. }, 10);
  336. if (UtilService.isDefined(reclib.localid)) {
  337. $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 1, goflg: 0});
  338. } else {
  339. $scope.go("authoritySet", {
  340. reclibid: reclib.id,
  341. authorityid: reclib.authorityid,
  342. authoritycomefrom: reclib.authoritycomefrom,
  343. name: reclib.name,
  344. content: reclib.content,
  345. sort: reclib.sort,
  346. type: 1,
  347. parentid: reclib.parentid
  348. });
  349. }
  350. };
  351. //网络异常时点击屏幕重新加载
  352. $scope.repeatLoad = function () {
  353. ConfigService.ressynchroflg = true;
  354. initResourceLibraryList();
  355. initResourceLibraryNodeBg();
  356. };
  357. //新建资源库
  358. $scope.createResLib = function () {
  359. $scope.go("authorityResourceCreate");
  360. };
  361. //下拉刷新数据
  362. $scope.refreshData = function () {
  363. $scope.repeatLoad();
  364. $scope.$broadcast('scroll.refreshComplete');
  365. var trHtml = "<div class='refresh_tip_div'>更新了" + $scope.resourcelibrarylist.length + "条内容</div>";
  366. $timeout(function () {
  367. $(".calendarList-content-ul .list").prepend(trHtml);
  368. $(".refresh_tip_div").animate({width: 100 + "%"}, 150);
  369. }, 800);
  370. $timeout(function () {
  371. $(".refresh_tip_div").slideUp();
  372. }, 1200);
  373. };
  374. // 首页搜索入口
  375. $scope.goIndexSearch = function () {
  376. $scope.go("indexSearchReasult");
  377. };
  378. $scope.goProvince = function () {
  379. ConfigService.cityflg = 1;
  380. $scope.go('chooseProvince');
  381. };
  382. // 跳转到选择节点
  383. $scope.goSelectNode = function () {
  384. $scope.go('chooseNodeIndex');
  385. };
  386. //进入资源库发布者列表
  387. $scope.goResourcePublisher = function (userlist) {
  388. $scope.go('resourcePublisherAccount', {userlist: userlist});
  389. };
  390. //节点背景图切换
  391. var initResourceLibraryNodeBg = function () {
  392. // $scope.showLoadingToast();
  393. var clienttype = 0;
  394. if ($scope.app) {
  395. clienttype = 1;
  396. } else {
  397. clienttype = 2;
  398. }
  399. ResourceLibraryService.getResourceLibraryNodeBg(clienttype).then(function (response) {
  400. $scope.urlBackGImage = response.data;
  401. if (($scope.urlBackGImage && $scope.urlBackGImage.adlist.length > 0 && $scope.urlBackGImage.adlist[0].sourceName != undefined) || ($scope.urlBackGImage.adlist.length > 0 && $scope.urlBackGImage.adlist[0].sourceName.length > 0)) {
  402. $scope.sourceBgName = $scope.urlBackGImage.adlist[0].sourceName
  403. } else {
  404. $scope.sourceBgName = 'group3/M00/0B/01/wKjILFuI0w2AcHjkAAAaToWtucA883.jpg';
  405. }
  406. }, function () {
  407. })
  408. };
  409. initResourceLibraryNodeBg();
  410. });