123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- var app = angular.module('app', [
- ]);
- app.controller("desktopMgn", ["$scope", "$http", "$interval", "$timeout", function ($scope, $http, $interval, $timeout) {
- var self = this;
- var s4 = new SM4Util();
- self.userId = $.cookie("GlWorkPlatform-userid");
- self.userName = $.cookie("GlWorkPlatform-username");
- self.userCName = $.cookie("GlWorkPlatform-chineseName");
- self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.userTypeEng = $.cookie("GlWorkPlatform-userTypeEng");
- var postCfg = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- };
- self.CrossPage = window.parent.CrossPage;
- self.loading = false;
- self.activeFrame = -1;
- self.frameArray = [];
- ////加载桌面数据
- self.getPluginData = function () {
- self.loading = true;
- var postData = {
- "isdefault": ""
- }
- //console.log(postData);
- //console.log(postData); s4.encryptData_CBC(JSON.stringify(postData))
- $http.post(apiurljs.login + "g2work/desktop/queryDataList", JSON.stringify(postData), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- //console.log(JSON.stringify(res));
- if (res.success) {
- self.loading = false;
- self.frameArray = res.data;
- angular.forEach(self.frameArray, function (item, index) {
- item.indexnum = index + 1;
- if (item.ISDEFAULT == "0") {
- item.ISDEFAULT_set = "非缺省桌面";
- } else {
- item.ISDEFAULT_set = "缺省桌面";
- }
- });
- self.activeFrame = 1;
- self.getPersonData(self.frameArray[0].CODE);
- } else {
- self.loading = false;
- self.frameArray = [];
- self.activeFrame = -1;
- }
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- if (textStatus != 200) {
- self.loading = false;
- }
- })
- };
- self.getPluginData();
- self.checkSelectItem = function (itemdata) {
- if (self.activeFrame != itemdata.indexnum) {
- self.loading = true;
- self.activeFrame = itemdata.indexnum;
- self.getPersonData(itemdata.CODE);
- }
- };
- self.info = {
- "code": "0",
- "cname": "",//名称
- "fileurl": "",
- "imagesmall": "",///图片
- "isdefault": "0"//是否缺省框架
- }
- ///新增---桌面
- self.btnAdd = function () {
- self.info = {
- "code": "0",
- "cname": "",//名称
- "fileurl": "",
- "imagesmall": "",///图片
- "isdefault": "0"//是否缺省框架
- }
- $("#btnfile").val(""); //文件
- $(".sp-upload-img").attr("src", "");
- self.pluginUpload_view = false;
- sp.layer("#layer_addplgn", 1);
- };
- ///编辑--桌面
- self.btnEditPlugin = function ($item) {
- self.info = {
- "code": $item.CODE,
- "cname": $item.CNAME,//名称
- "fileurl": $item.URL,
- "imagesmall": $item.IMAGESMALL,///缩略图
- "isdefault": $item.ISDEFAULT//是否缺省框架
- }
- $(".sp-upload-img").attr("src", $item.IMAGESMALL);
- sp.layer("#layer_addplgn", 1)
- };
- //图片文件转base64
- var imgBaseArr, fileSize;
- self.upload = function () {
- $("#btnfile").change(function (e) {
- //获取图片大小,字节
- var fileMsg = e.currentTarget.files;
- if (fileMsg[0].type.indexOf('image') !== -1) {
- //console.log(fileMsg[0].type);
- fileSize = fileMsg[0].size;//不能超过2668484,大约为2.6MB
- if (fileSize > 0.5 * 1024 * 1024) {
- alert("选择的图像文件不能超过500K,请重新选择!");
- $("#btnfile").val(""); //文件
- self.info.imagesmall = "";
- $(".sp-upload-img").attr("src", "");
- } else {
- var reader = new FileReader();
- reader.onload = function (e) {
- //console.log(e)
- var imgBase = reader.result; //这个就是base64的编码
- imgBaseArr = imgBase;
- //截取掉前面的内容“data:image/png;base64”,
- //if (imgBase.split(',')[0].indexOf('base64') >= 0) {
- // imgBaseArr = imgBase.split(',')[1];
- //}
- self.info.imagesmall = imgBaseArr;
- $(".sp-upload-img").attr("src", imgBaseArr);
- }
- reader.readAsDataURL(this.files[0]);
- }
- } else {
- alert("仅能上传图片");
- }
- })
- };
- self.upload();
- self.btnSubmitPlnDsabled = false;
- self.btnSubmitPln_text = "提 交";
- self.submit_plguin = function () {
- if (spngvld.submit("#layer_addplgn")) {
- //console.log(self.info.imagesmall);
- if (sp.isval(self.info.imagesmall)) {
- self.btnSubmitPlnDsabled = true;
- self.btnSubmitPln_text = "正在提交,请稍等..";
- var postData = {
- "code": self.info.code,
- "cname": self.info.cname,
- "url": self.info.fileurl,
- "imagesmall": self.info.imagesmall,
- "isdefault": self.info.isdefault
- }
- //console.log(postData);
- //console.log(postData); s4.encryptData_CBC(JSON.stringify(postData))
- $http.post(apiurljs.login + "g2work/desktop/saveData", JSON.stringify(postData), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- //console.log(JSON.stringify(res));
- if (res.success) {
- sp.closeCenter('.sp-layer');
- $timeout(function () {
- self.getPluginData();
- }, 210);
- } else {
- sp.closeCenter('.sp-layer');
- sp.dialog(res.message);
- }
- self.btnSubmitPlnDsabled = false;
- self.btnSubmitPln_text = "提 交";
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- if (textStatus != 200) {
- self.loading = false;
- }
- })
- } else {
- alert("您好,图片不能为空!");
- }
- }
- }
- self.cancel_plguin = function () {
- sp.closeCenter('.sp-layer');
- }
- //删除桌面
- self.removePlugin = function ($item) {
- var time1 = sp.getLocalDate1();
- //self.journalRecord(time1, sp.getLocalDate1(), "删除", "修改日志", window.location.pathname)
- var getDelID = $item.CODE;
- //console.log(getDelID);
- var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
- 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>";
- $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
- sp.openCenter(".sp-dialog");
- ///取消按钮
- $('.sp-closeDialog').click(function (event) {
- sp.closeCenter(".sp-dialog");
- event.preventDefault(); event.stopPropagation();
- });
- //post消息的id
- $("#delDataTrue").click(function () {
- var getid = $(this).attr("data-id");
- var data = {
- code: getid///角色编码
- };
- //console.log(data);
- $http.post(apiurljs.login + "g2work/desktop/deleteDataByCode", JSON.stringify(data), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- if (res.success) {
- self.getPluginData();
- sp.dialoghide();
- } else {
- sp.dialog(res.message);
- }
- });
- });
- }
- //上移一位--桌面
- self.moveUp_plugin = function (itemdata, indexnum) {
- var set_index = indexnum - 2;
- var postData = {
- "code2": self.frameArray[set_index].CODE,
- "code1": itemdata.CODE
- };
- //console.log(postData);
- $http.post(apiurljs.login + "g2work/desktop/swapSortidByCode", JSON.stringify(postData), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- if (res.success) {
- self.getPluginData();
- self.activeRole = -1;
- //self.getPluginData(self.unit, "0"); ///加载机构下方的人员
- } else {
- sp.dialog(res.message);
- }
- });
- }
- //下移一位--桌面
- self.moveDown_plugin = function (itemdata, indexnum) {
- var set_index = indexnum;
- var postData = {
- "code2": self.frameArray[set_index].CODE,
- "code1": itemdata.CODE
- };
- //console.log(postData);
- $http.post(apiurljs.login + "g2work/desktop/swapSortidByCode", JSON.stringify(postData), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- if (res.success) {
- self.getPluginData();
- } else {
- sp.dialog(res.message);
- }
- });
- }
- ////加载用户列表
- self.getPerson = [];///声明用户列表数组
- self.getPersonData = function (code) {
- var postData = {
- code: code
- }
- $http.post(apiurljs.login + "g2work/desktop/queryDataUserByCode", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- self.loading = false;
- ///console.log(JSON.stringify(res));
- if (res.success) {
- if (sp.isval(res.data)) {
- self.isSelectedAll = true;
- self.getPerson = res.data;
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (itm2) {
- if (itm2.AUTH == "1") {
- itm2.check = true;
- } else {
- itm2.check = false;
- self.isSelectedAll = false; //有一个未选中就是未全选
- }
- });
- });
- } else {
- self.getPerson = [];
- }
- } else {
- sp.dialog(res.message);
- }
- })
- .error(function (XMLHttpRequest, textStatus, errorThrown) {
- if (textStatus != 200) {
- self.loading = false;
- }
- })
- };
- ///点击用户checkbox选中事件
- self.isSelected = function () {
- self.isSelectedAll = true;
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- if (!item2.check) {
- return self.isSelectedAll = false;
- }
- })
- })
- }
- //全选
- self.isSelectedAll = false;
- self.selectAll = function () {
- if (self.isSelectedAll) {
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- item2.check = true;
- })
- })
- } else {
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- item2.check = false;
- })
- })
- }
- }
- //保存人员设置
- self.saveRole = function () {
- if (sp.isval(self.getPerson)) {
- var get_checkedUser = [];
- self.getPerson.forEach(function (itm) {
- itm.users.forEach(function (item2) {
- if (item2.check) {
- get_checkedUser.push({
- "code": self.frameArray[self.activeFrame - 1].CODE,
- "USERID": item2.USERID,
- "ISDEFAULT": self.frameArray[self.activeFrame - 1].ISDEFAULT
- })
- }
- });
- })
- //console.log(JSON.stringify(get_checkedUser));
- if (sp.isval(get_checkedUser)) {
- var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">您确认要提交吗?</div>";
- 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>";
- $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
- sp.openCenter(".sp-dialog");
- ///取消按钮
- $('.sp-closeDialog').click(function (event) {
- sp.closeCenter(".sp-dialog");
- event.preventDefault(); event.stopPropagation();
- });
- //post消息的id
- $("#delDataTrue").click(function () {
- var postData = {
- code: self.frameArray[self.activeFrame - 1].CODE,
- data: JSON.stringify(get_checkedUser)
- }
- //console.log(JSON.stringify(postData));
- $http.post(apiurljs.login + "g2work/desktop/updateDataUserByCode", JSON.stringify(postData), postCfg)
- .success(function (obj) {
- //var res = strToJson(s4.decryptData_CBC(obj.data));
- var res = obj;
- if (res.success) {
- //sp.dialog(res.message);
- self.getPersonData(self.frameArray[self.activeFrame - 1].CODE);
- sp.dialoghide();
- } else {
- sp.dialog(res.message);
- }
- });
- });
-
- } else {
- sp.dialog("人员不能为空!");
- }
- } else {
- sp.dialog("没有人员数据,不能提交!");
- }
- }
- }]);
|