123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 |
- angular.module('push')
- .controller('resourceLibraryHomeCtrl', function ($scope, ResourceLibraryService, UtilService, $timeout, $ionicListDelegate, SqliteStorageService, UserService,
- HandleService, resourceLibraryTempData, SynchroService, ConfigService, ConstantService, $ionicScrollDelegate) {
- document.title = '资源库';
- if (UserService.defaultLan == 'English') {
- document.title = 'Database';
- }
- $scope.resourcelibrarylist = [];
- var uploadresliblist = [];
- var resourcelist = [];
- $scope.user = UserService.user.user;
- $scope.viplevel = UserService.viplevel;
- $scope.keyword = "";// 搜索关键词
- $scope.node = UserService.node;//节点号
- $scope.nodename = UserService.nodename;//节点号名称
- $scope.resinfocount = 0;//资源总数
- $scope.resexpertcount = 0;//专家总数
- $scope.resorgcount = 0;//企业总数
- $scope.resresearchfindingcount = 0;//成果总数
- $scope.techrequirementcount = 0;//需求总数
- $scope.defaultLan = UserService.defaultLan;
- $scope.comfromWeb = sessionStorage.comfrom == 'web';
- var updateHandleData = function (res) {
- if (res.insertList) {
- // console.log("-------------------res.insertList------------------------");
- // console.log(res.insertList);
- for (key in res.insertList) {
- SqliteStorageService.insertBatchData(key, res.insertList[key]).then(function () {
- // console.log("批量insert成功");
- }, function () {
- })
- }
- }
- if (res.updateList) {
- // console.log("-------------------res.updateList------------------------");
- // console.log(res.updateList);
- for (key in res.updateList) {
- SqliteStorageService.updateBatchData(key, res.updateList[key]).then(function () {
- // console.log("批量修改成功");
- }, function () {
- })
- }
- }
- if (res.deleteList) {
- // console.log("-------------------res.deleteList------------------------");
- // console.log(res.deleteList);
- for (key in res.deleteList) {
- SqliteStorageService.deleteBatchData(key, res.deleteList[key]).then(function () {
- // console.log("批量delete成功");
- }, function () {
- })
- }
- }
- $timeout(function () {
- UtilService.showMess("同步完成");
- ConfigService.ressynchroflg = false;
- initResourceLibraryList();
- $scope.hideLoadingToast();
- }, 300);
- };
- var handleResponseData = function (tempresponse) {
- //--第一次,本地没有数据,server数据全部返回处理
- if (tempresponse.responsetype == 1) {
- if (angular.isDefined(tempresponse.folderlist)) {
- HandleService.handleFirstServerResourceData(tempresponse.folderlist).then(function (res) {
- // console.log("处理返回数据,按表划分");
- // console.log(res);
- for (key in res) {
- SqliteStorageService.insertBatchData(key, res[key]).then(function (res) {
- // console.log("OK")
- }, function () {
- })
- }
- $timeout(function () {
- UtilService.showMess("同步完成");
- ConfigService.ressynchroflg = false;
- initResourceLibraryList();
- $scope.hideLoadingToast();
- }, 300);
- }, function () {
- });
- } else {
- $scope.hideLoadingToast();
- }
- }
- //--第二及之后,本地有数据,server数据部分返回处理
- if (tempresponse.responsetype == 2) {
- HandleService.handleSecondServerResourceData(tempresponse.folderReturnList, tempresponse.recordReturnList, uploadresliblist).then(function (res) {
- // console.log("按增删改处理同步返回的数据");
- // console.log(res);
- updateHandleData(res);
- }, function () {
- $scope.hideLoadingToast();
- });
- }
- };
- //资源同步
- var synchroResource = function () {
- uploadresliblist.sort(function (a, b) {
- return a.level - b.level;//置顶(level)升序
- });
- // console.log("------------------------------------");
- // console.log(uploadresliblist);
- // console.log(resourcelist);
- SynchroService.synchroResourceData(uploadresliblist, resourcelist).then(function (response) {
- // console.log("同步成功,返回的数据");
- // console.log(response);
- handleResponseData(response);
- }, function () {
- $scope.hideLoadingToast();
- })
- };
- //取本地资源
- var getResourceList = function () {
- var claidlist = "";
- angular.forEach(uploadresliblist, function (value) {
- var tempstr = "'" + value.localid + "'";
- claidlist = claidlist + tempstr + ",";
- });
- claidlist = claidlist.substring(0, claidlist.length - 1);
- var sql = "select * from resource where localclaid in (" + claidlist + ")";
- SqliteStorageService.queryData(sql).then(function (response) {
- // console.log(response);
- resourcelist = response;
- synchroResource();
- }, function () {
- })
- };
- //初始化资源库列表
- $scope.rescontactflg = 0;//0:本地/云资源库开始查询 2:查询结束
- var tempLocalResourceLibrarylist = [];
- var tempCloudResourceLibrarylist = [];
- $scope.resinfocount = 0;//资源总数
- var initResourceLibraryList = function () {
- // $scope.showLoadingToast();
- /*//--查询本地资源库
- tempLocalResourceLibrarylist = [];
- uploadresliblist = [];
- var sql = "select * from conninfofolder where userid = " + UserService.id + " and isCloud = 0 and type = 2 order by updatetime desc";
- SqliteStorageService.queryData(sql).then(function (response) {
- // console.log(response);
- angular.forEach(response, function (value, index) {
- if (value.localparentid == "0") {
- tempLocalResourceLibrarylist.push(value);
- }
- uploadresliblist.push(value);
- });
- $scope.rescontactflg++;
- //同步标志为true,去同步
- if (ConfigService.ressynchroflg) {
- if (uploadresliblist.length > 0) {
- getResourceList();
- } else {
- resourcelist = [];
- synchroResource();
- }
- }
- }, function () {
- tempLocalResourceLibrarylist = [];
- $scope.rescontactflg++;
- });*/
- //--查询云资源库;
- ResourceLibraryService.getResourceLibrary($scope.keyword, $scope.node).then(function (response) {
- if (UtilService.isDefined(response.data)) {
- console.log(response.data);
- // 配置图片
- tempCloudResourceLibrarylist = response.data;
- angular.forEach(tempCloudResourceLibrarylist, function (val) {
- val.logo = [];
- val.logo = val.name == '企业库' ? ['./img/2018/company1.png', './img/2018/company2.jpeg', './img/2018/company3.png']
- : val.name == '高校库' ? ['./img/2018/university1.png', './img/2018/university2.png', './img/2018/university3.png']
- : val.name == '人才库' || val.name == '技术经纪人库' ? ['./img/2018/person1.png', './img/2018/person2.png', './img/2018/person3.png']
- : val.name == '需求库' ? ['./img/2018/demand1.jpg', './img/2018/demand2.jpg']
- : val.name == '成果库' ? ['./img/2018/product1.jpg', './img/2018/product2.jpg', './img/2018/product3.jpg']
- : ['./img/2018/other1-1.jpg', './img/2018/other1-2.jpg', './img/2018/other1-3.jpg'];
- if ($scope.isLiyangApp && val.name == '企业库') {
- val.logo = ['./img/2018/liyang1.jpg', './img/2018/liyang2.jpg', './img/2018/liyang3.jpg'];
- }
- })
- } else {
- tempCloudResourceLibrarylist = [];
- }
- $scope.rescontactflg++;
- $scope.rescontactflg++;
- }, function () {
- tempCloudResourceLibrarylist = [];
- $scope.rescontactflg++;
- $scope.rescontactflg++;
- })
- };
- initResourceLibraryList();
- //拼接本地与云文件夹(按sort、updatetime排序)
- var connectLocalAndCloud = function () {
- HandleService.connectLocalAndCloud(tempLocalResourceLibrarylist, tempCloudResourceLibrarylist).then(function (response) {
- $scope.resourcelibrarylist = response;
- console.log(response);
- if ($scope.resourcelibrarylist.length == 0) {
- $scope.shownone = true;
- } else {
- $scope.shownone = false;
- $scope.resinfocount = 0;//资源总数
- // 节点资源总数
- angular.forEach($scope.resourcelibrarylist, function (value) {
- $scope.resinfocount += value.infocount;//资源总数
- if (value.moduleid == ConstantService.CATEGORY_MODULE_8) {
- $scope.resexpertcount = value.infocount;//专家总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_6) {
- $scope.resorgcount = value.infocount;//企业总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_2) {
- $scope.resresearchfindingcount = value.infocount;//成果总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_1) {
- $scope.techrequirementcount = value.infocount;//需求总数
- }
- });
- }
- resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist);
- $scope.hideLoadingToast();
- }, function () {
- $scope.hideLoadingToast();
- })
- };
- connectLocalAndCloud();
- //--监听本地与云文件夹查询是否结束
- $scope.$watch("rescontactflg", function (newValue) {
- if (newValue == 2) {
- //本地与云均无,显示缺省页
- if (tempCloudResourceLibrarylist.length == 0 && tempLocalResourceLibrarylist.length == 0) {
- $scope.shownone = true;
- $scope.resourcelibrarylist = [];
- $scope.hideLoadingToast();
- } else {
- //无云文件夹显示本地
- if (tempCloudResourceLibrarylist.length < 1) {
- $scope.resourcelibrarylist = tempLocalResourceLibrarylist;
- console.log($scope.resourcelibrarylist);
- $scope.hideLoadingToast();
- }
- //无本地文件夹显示云
- if (tempLocalResourceLibrarylist.length < 1) {
- $scope.resourcelibrarylist = tempCloudResourceLibrarylist;
- // 节点资源总数
- $scope.resinfocount = 0;
- angular.forEach($scope.resourcelibrarylist, function (value) {
- $scope.resinfocount += value.infocount;//资源总数
- if (value.moduleid == ConstantService.CATEGORY_MODULE_8) {
- $scope.resexpertcount = value.infocount;//专家总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_6) {
- $scope.resorgcount = value.infocount;//企业总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_2) {
- $scope.resresearchfindingcount = value.infocount;//成果总数
- }
- if (value.moduleid == ConstantService.CATEGORY_MODULE_1) {
- $scope.techrequirementcount = value.infocount;//需求总数
- }
- });
- $scope.hideLoadingToast();
- }
- //本地与云均有去拼接
- if (tempCloudResourceLibrarylist.length > 0 && tempLocalResourceLibrarylist.length > 0) {
- connectLocalAndCloud();
- }
- $scope.shownone = false;
- }
- $scope.rescontactflg = 0;
- resourceLibraryTempData.setResourceLibraryList($scope.resourcelibrarylist);
- // console.log($scope.resourcelibrarylist);
- }
- });
- $scope.$on("$ionicView.beforeEnter", function () {
- //TODO
- if ($scope.app) {
- $scope.setStatusBar(1);
- }
- $scope.node = UserService.node;//节点号
- $scope.nodename = UserService.nodename;//节点号名称
- $scope.resinfocount = 0;//资源总数
- $ionicScrollDelegate.$getByHandle('calenderContent').scrollTop();
- initResourceLibraryList();
- initResourceLibraryNodeBg();
- });
- //资源库搜索
- $scope.goResourceSearch = function () {
- $timeout(function () {
- $scope.go('resourceSearch');
- }, 350);
- };
- //获取定位
- $scope.getPosition = function () {
- // console.log("获取位置");
- };
- //进入资源库列表
- $scope.goResorceLibaryDetail = function (res) {
- resourceLibraryTempData.setCategoryIndex(0);
- resourceLibraryTempData.resetChecked();
- if (res.moduleid == false && UserService.node == '330122000') {
- window.open("http://app.zjumap.com:7736/#/index", "_blank");
- } else if (res.moduleid == 44) {
- $scope.go('wujingTeacher');
- } else if (res.moduleid == 43) {
- $scope.go('wujingTechnical');
- } else if (res.moduleid == 33) {
- //通知公告库
- $scope.go("notification");
- } else {
- //进入公共资源库列表
- if (res.fixtype == 1) {
- $scope.go('publicResource', {
- libtype: reclibc.moduleid,
- name: reclibc.name,
- reclibid: $scope.reclib.id,
- modlibid: reclibc.id
- });
- } else if (res.fixtype == 2) {
- //进入私人资源库列表
- $scope.go('privateResource', {
- res: angular.toJson(res),
- privateName: res.name,
- groupid: res.parentid,
- restype: res.moduleid,
- privateContent: res.content,
- authority: res.by5
- });
- }
- }
- };
- //进入设置资源库页面
- $scope.goResourceSet = function (reclib) {
- $timeout(function () {
- $ionicListDelegate.closeOptionButtons();
- }, 10);
- if (UtilService.isDefined(reclib.localid)) {
- $scope.go("authorityLocalSet", {authoritydata: angular.toJson(reclib), type: 1, goflg: 0});
- } else {
- $scope.go("authoritySet", {
- reclibid: reclib.id,
- authorityid: reclib.authorityid,
- authoritycomefrom: reclib.authoritycomefrom,
- name: reclib.name,
- content: reclib.content,
- sort: reclib.sort,
- type: 1,
- parentid: reclib.parentid
- });
- }
- };
- //网络异常时点击屏幕重新加载
- $scope.repeatLoad = function () {
- ConfigService.ressynchroflg = true;
- initResourceLibraryList();
- initResourceLibraryNodeBg();
- };
- //新建资源库
- $scope.createResLib = function () {
- $scope.go("authorityResourceCreate");
- };
- //下拉刷新数据
- $scope.refreshData = function () {
- $scope.repeatLoad();
- $scope.$broadcast('scroll.refreshComplete');
- var trHtml = "<div class='refresh_tip_div'>更新了" + $scope.resourcelibrarylist.length + "条内容</div>";
- $timeout(function () {
- $(".calendarList-content-ul .list").prepend(trHtml);
- $(".refresh_tip_div").animate({width: 100 + "%"}, 150);
- }, 800);
- $timeout(function () {
- $(".refresh_tip_div").slideUp();
- }, 1200);
- };
- // 首页搜索入口
- $scope.goIndexSearch = function () {
- $scope.go("indexSearchReasult");
- };
- $scope.goProvince = function () {
- ConfigService.cityflg = 1;
- $scope.go('chooseProvince');
- };
- // 跳转到选择节点
- $scope.goSelectNode = function () {
- $scope.go('chooseNodeIndex');
- };
- //进入资源库发布者列表
- $scope.goResourcePublisher = function (userlist) {
- $scope.go('resourcePublisherAccount', {userlist: userlist});
- };
- //节点背景图切换
- var initResourceLibraryNodeBg = function () {
- // $scope.showLoadingToast();
- var clienttype = 0;
- if ($scope.app) {
- clienttype = 1;
- } else {
- clienttype = 2;
- }
- ResourceLibraryService.getResourceLibraryNodeBg(clienttype).then(function (response) {
- $scope.urlBackGImage = response.data;
- 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)) {
- $scope.sourceBgName = $scope.urlBackGImage.adlist[0].sourceName
- } else {
- $scope.sourceBgName = 'group3/M00/0B/01/wKjILFuI0w2AcHjkAAAaToWtucA883.jpg';
- }
- }, function () {
- })
- };
- initResourceLibraryNodeBg();
- });
|