desktop_mgn.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. var app = angular.module('app', [
  2. ]);
  3. app.controller("desktopMgn", ["$scope", "$http", "$interval", "$timeout", function ($scope, $http, $interval, $timeout) {
  4. var self = this;
  5. var s4 = new SM4Util();
  6. self.userId = $.cookie("GlWorkPlatform-userid");
  7. self.userName = $.cookie("GlWorkPlatform-username");
  8. self.userCName = $.cookie("GlWorkPlatform-chineseName");
  9. self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
  10. self.userTypeEng = $.cookie("GlWorkPlatform-userTypeEng");
  11. var postCfg = {
  12. headers: {
  13. 'Content-Type': 'application/json',
  14. 'Authorization': "Bearer " + self.get_AccessToken
  15. }
  16. };
  17. self.CrossPage = window.parent.CrossPage;
  18. self.loading = false;
  19. self.activeFrame = -1;
  20. self.frameArray = [];
  21. ////加载桌面数据
  22. self.getPluginData = function () {
  23. self.loading = true;
  24. var postData = {
  25. "isdefault": ""
  26. }
  27. //console.log(postData);
  28. //console.log(postData); s4.encryptData_CBC(JSON.stringify(postData))
  29. $http.post(apiurljs.login + "g2work/desktop/queryDataList", JSON.stringify(postData), postCfg)
  30. .success(function (obj) {
  31. //var res = strToJson(s4.decryptData_CBC(obj.data));
  32. var res = obj;
  33. //console.log(JSON.stringify(res));
  34. if (res.success) {
  35. self.loading = false;
  36. self.frameArray = res.data;
  37. angular.forEach(self.frameArray, function (item, index) {
  38. item.indexnum = index + 1;
  39. if (item.ISDEFAULT == "0") {
  40. item.ISDEFAULT_set = "非缺省桌面";
  41. } else {
  42. item.ISDEFAULT_set = "缺省桌面";
  43. }
  44. });
  45. self.activeFrame = 1;
  46. self.getPersonData(self.frameArray[0].CODE);
  47. } else {
  48. self.loading = false;
  49. self.frameArray = [];
  50. self.activeFrame = -1;
  51. }
  52. })
  53. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  54. if (textStatus != 200) {
  55. self.loading = false;
  56. }
  57. })
  58. };
  59. self.getPluginData();
  60. self.checkSelectItem = function (itemdata) {
  61. if (self.activeFrame != itemdata.indexnum) {
  62. self.loading = true;
  63. self.activeFrame = itemdata.indexnum;
  64. self.getPersonData(itemdata.CODE);
  65. }
  66. };
  67. self.info = {
  68. "code": "0",
  69. "cname": "",//名称
  70. "fileurl": "",
  71. "imagesmall": "",///图片
  72. "isdefault": "0"//是否缺省框架
  73. }
  74. ///新增---桌面
  75. self.btnAdd = function () {
  76. self.info = {
  77. "code": "0",
  78. "cname": "",//名称
  79. "fileurl": "",
  80. "imagesmall": "",///图片
  81. "isdefault": "0"//是否缺省框架
  82. }
  83. $("#btnfile").val(""); //文件
  84. $(".sp-upload-img").attr("src", "");
  85. self.pluginUpload_view = false;
  86. sp.layer("#layer_addplgn", 1);
  87. };
  88. ///编辑--桌面
  89. self.btnEditPlugin = function ($item) {
  90. self.info = {
  91. "code": $item.CODE,
  92. "cname": $item.CNAME,//名称
  93. "fileurl": $item.URL,
  94. "imagesmall": $item.IMAGESMALL,///缩略图
  95. "isdefault": $item.ISDEFAULT//是否缺省框架
  96. }
  97. $(".sp-upload-img").attr("src", $item.IMAGESMALL);
  98. sp.layer("#layer_addplgn", 1)
  99. };
  100. //图片文件转base64
  101. var imgBaseArr, fileSize;
  102. self.upload = function () {
  103. $("#btnfile").change(function (e) {
  104. //获取图片大小,字节
  105. var fileMsg = e.currentTarget.files;
  106. if (fileMsg[0].type.indexOf('image') !== -1) {
  107. //console.log(fileMsg[0].type);
  108. fileSize = fileMsg[0].size;//不能超过2668484,大约为2.6MB
  109. if (fileSize > 0.5 * 1024 * 1024) {
  110. alert("选择的图像文件不能超过500K,请重新选择!");
  111. $("#btnfile").val(""); //文件
  112. self.info.imagesmall = "";
  113. $(".sp-upload-img").attr("src", "");
  114. } else {
  115. var reader = new FileReader();
  116. reader.onload = function (e) {
  117. //console.log(e)
  118. var imgBase = reader.result; //这个就是base64的编码
  119. imgBaseArr = imgBase;
  120. //截取掉前面的内容“data:image/png;base64”,
  121. //if (imgBase.split(',')[0].indexOf('base64') >= 0) {
  122. // imgBaseArr = imgBase.split(',')[1];
  123. //}
  124. self.info.imagesmall = imgBaseArr;
  125. $(".sp-upload-img").attr("src", imgBaseArr);
  126. }
  127. reader.readAsDataURL(this.files[0]);
  128. }
  129. } else {
  130. alert("仅能上传图片");
  131. }
  132. })
  133. };
  134. self.upload();
  135. self.btnSubmitPlnDsabled = false;
  136. self.btnSubmitPln_text = "提 交";
  137. self.submit_plguin = function () {
  138. if (spngvld.submit("#layer_addplgn")) {
  139. //console.log(self.info.imagesmall);
  140. if (sp.isval(self.info.imagesmall)) {
  141. self.btnSubmitPlnDsabled = true;
  142. self.btnSubmitPln_text = "正在提交,请稍等..";
  143. var postData = {
  144. "code": self.info.code,
  145. "cname": self.info.cname,
  146. "url": self.info.fileurl,
  147. "imagesmall": self.info.imagesmall,
  148. "isdefault": self.info.isdefault
  149. }
  150. //console.log(postData);
  151. //console.log(postData); s4.encryptData_CBC(JSON.stringify(postData))
  152. $http.post(apiurljs.login + "g2work/desktop/saveData", JSON.stringify(postData), postCfg)
  153. .success(function (obj) {
  154. //var res = strToJson(s4.decryptData_CBC(obj.data));
  155. var res = obj;
  156. //console.log(JSON.stringify(res));
  157. if (res.success) {
  158. sp.closeCenter('.sp-layer');
  159. $timeout(function () {
  160. self.getPluginData();
  161. }, 210);
  162. } else {
  163. sp.closeCenter('.sp-layer');
  164. sp.dialog(res.message);
  165. }
  166. self.btnSubmitPlnDsabled = false;
  167. self.btnSubmitPln_text = "提 交";
  168. })
  169. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  170. if (textStatus != 200) {
  171. self.loading = false;
  172. }
  173. })
  174. } else {
  175. alert("您好,图片不能为空!");
  176. }
  177. }
  178. }
  179. self.cancel_plguin = function () {
  180. sp.closeCenter('.sp-layer');
  181. }
  182. //删除桌面
  183. self.removePlugin = function ($item) {
  184. var time1 = sp.getLocalDate1();
  185. //self.journalRecord(time1, sp.getLocalDate1(), "删除", "修改日志", window.location.pathname)
  186. var getDelID = $item.CODE;
  187. //console.log(getDelID);
  188. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  189. var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
  190. var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  191. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  192. sp.openCenter(".sp-dialog");
  193. ///取消按钮
  194. $('.sp-closeDialog').click(function (event) {
  195. sp.closeCenter(".sp-dialog");
  196. event.preventDefault(); event.stopPropagation();
  197. });
  198. //post消息的id
  199. $("#delDataTrue").click(function () {
  200. var getid = $(this).attr("data-id");
  201. var data = {
  202. code: getid///角色编码
  203. };
  204. //console.log(data);
  205. $http.post(apiurljs.login + "g2work/desktop/deleteDataByCode", JSON.stringify(data), postCfg)
  206. .success(function (obj) {
  207. //var res = strToJson(s4.decryptData_CBC(obj.data));
  208. var res = obj;
  209. if (res.success) {
  210. self.getPluginData();
  211. sp.dialoghide();
  212. } else {
  213. sp.dialog(res.message);
  214. }
  215. });
  216. });
  217. }
  218. //上移一位--桌面
  219. self.moveUp_plugin = function (itemdata, indexnum) {
  220. var set_index = indexnum - 2;
  221. var postData = {
  222. "code2": self.frameArray[set_index].CODE,
  223. "code1": itemdata.CODE
  224. };
  225. //console.log(postData);
  226. $http.post(apiurljs.login + "g2work/desktop/swapSortidByCode", JSON.stringify(postData), postCfg)
  227. .success(function (obj) {
  228. //var res = strToJson(s4.decryptData_CBC(obj.data));
  229. var res = obj;
  230. if (res.success) {
  231. self.getPluginData();
  232. self.activeRole = -1;
  233. //self.getPluginData(self.unit, "0"); ///加载机构下方的人员
  234. } else {
  235. sp.dialog(res.message);
  236. }
  237. });
  238. }
  239. //下移一位--桌面
  240. self.moveDown_plugin = function (itemdata, indexnum) {
  241. var set_index = indexnum;
  242. var postData = {
  243. "code2": self.frameArray[set_index].CODE,
  244. "code1": itemdata.CODE
  245. };
  246. //console.log(postData);
  247. $http.post(apiurljs.login + "g2work/desktop/swapSortidByCode", JSON.stringify(postData), postCfg)
  248. .success(function (obj) {
  249. //var res = strToJson(s4.decryptData_CBC(obj.data));
  250. var res = obj;
  251. if (res.success) {
  252. self.getPluginData();
  253. } else {
  254. sp.dialog(res.message);
  255. }
  256. });
  257. }
  258. ////加载用户列表
  259. self.getPerson = [];///声明用户列表数组
  260. self.getPersonData = function (code) {
  261. var postData = {
  262. code: code
  263. }
  264. $http.post(apiurljs.login + "g2work/desktop/queryDataUserByCode", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
  265. .success(function (obj) {
  266. //var res = strToJson(s4.decryptData_CBC(obj.data));
  267. var res = obj;
  268. self.loading = false;
  269. ///console.log(JSON.stringify(res));
  270. if (res.success) {
  271. if (sp.isval(res.data)) {
  272. self.isSelectedAll = true;
  273. self.getPerson = res.data;
  274. self.getPerson.forEach(function (itm) {
  275. itm.users.forEach(function (itm2) {
  276. if (itm2.AUTH == "1") {
  277. itm2.check = true;
  278. } else {
  279. itm2.check = false;
  280. self.isSelectedAll = false; //有一个未选中就是未全选
  281. }
  282. });
  283. });
  284. } else {
  285. self.getPerson = [];
  286. }
  287. } else {
  288. sp.dialog(res.message);
  289. }
  290. })
  291. .error(function (XMLHttpRequest, textStatus, errorThrown) {
  292. if (textStatus != 200) {
  293. self.loading = false;
  294. }
  295. })
  296. };
  297. ///点击用户checkbox选中事件
  298. self.isSelected = function () {
  299. self.isSelectedAll = true;
  300. self.getPerson.forEach(function (itm) {
  301. itm.users.forEach(function (item2) {
  302. if (!item2.check) {
  303. return self.isSelectedAll = false;
  304. }
  305. })
  306. })
  307. }
  308. //全选
  309. self.isSelectedAll = false;
  310. self.selectAll = function () {
  311. if (self.isSelectedAll) {
  312. self.getPerson.forEach(function (itm) {
  313. itm.users.forEach(function (item2) {
  314. item2.check = true;
  315. })
  316. })
  317. } else {
  318. self.getPerson.forEach(function (itm) {
  319. itm.users.forEach(function (item2) {
  320. item2.check = false;
  321. })
  322. })
  323. }
  324. }
  325. //保存人员设置
  326. self.saveRole = function () {
  327. if (sp.isval(self.getPerson)) {
  328. var get_checkedUser = [];
  329. self.getPerson.forEach(function (itm) {
  330. itm.users.forEach(function (item2) {
  331. if (item2.check) {
  332. get_checkedUser.push({
  333. "code": self.frameArray[self.activeFrame - 1].CODE,
  334. "USERID": item2.USERID,
  335. "ISDEFAULT": self.frameArray[self.activeFrame - 1].ISDEFAULT
  336. })
  337. }
  338. });
  339. })
  340. //console.log(JSON.stringify(get_checkedUser));
  341. if (sp.isval(get_checkedUser)) {
  342. var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
  343. var dialogBody = "<div class=\"sp-dialog-body\">您确认要提交吗?</div>";
  344. var dialogFoot = "<div class=\"sp-dialog-foot\"><input id='delDataTrue' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
  345. $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
  346. sp.openCenter(".sp-dialog");
  347. ///取消按钮
  348. $('.sp-closeDialog').click(function (event) {
  349. sp.closeCenter(".sp-dialog");
  350. event.preventDefault(); event.stopPropagation();
  351. });
  352. //post消息的id
  353. $("#delDataTrue").click(function () {
  354. var postData = {
  355. code: self.frameArray[self.activeFrame - 1].CODE,
  356. data: JSON.stringify(get_checkedUser)
  357. }
  358. //console.log(JSON.stringify(postData));
  359. $http.post(apiurljs.login + "g2work/desktop/updateDataUserByCode", JSON.stringify(postData), postCfg)
  360. .success(function (obj) {
  361. //var res = strToJson(s4.decryptData_CBC(obj.data));
  362. var res = obj;
  363. if (res.success) {
  364. //sp.dialog(res.message);
  365. self.getPersonData(self.frameArray[self.activeFrame - 1].CODE);
  366. sp.dialoghide();
  367. } else {
  368. sp.dialog(res.message);
  369. }
  370. });
  371. });
  372. } else {
  373. sp.dialog("人员不能为空!");
  374. }
  375. } else {
  376. sp.dialog("没有人员数据,不能提交!");
  377. }
  378. }
  379. }]);