var DataRightsApp = angular.module('DataRightsApp', [ 'baseServices' ]); DataRightsApp.service('dataRightsService', ['$http','$jsonToFormData','BaseService', function($http,$jsonToFormData,BaseService) { var service = { init:function($scope){ /** * 控件类型。 16是隐藏域 4 用户单选,8,用户多选, 17,角色单选,5,角色多选, 18,组织单选,6,组织多选 19,岗位单选,7,岗位多选 */ this.scope = $scope; $scope.controlList = [{key : '1',value : '单行文本框'}, {key : '15',value : '日期控件'}, {key : '3',value : '数据字典'}, {key : '11',value : '下拉选项'}, {key : '4',value : '人员选择器(单选)'}, {key : '17',value : '角色选择器(单选)'}, {key : '18',value : '组织选择器(单选)'}, {key : '19',value : '岗位选择器(单选)'}]; $scope.bpmFormTable = []; $scope.displayFields = []; $scope.conditionFields = []; $scope.sortFields = []; $scope.filterFields = []; $scope.manageFields = []; $scope.exportFileds = []; $scope.dataRightsJson = DataRightsJson; $scope.sqlButtons = parseToJson($scope.dataRightsJson.sqlButtons); this.initDataRightsJson(DataRightsJson); switch($scope.type){ case "sysQueryView": this.initSysQueryViewData(bpmFormTableJSON); break; default : $scope.bpmFormTable = bpmFormTableJSON; break; } console.info($scope.dataRightsJson.displayField); if($scope.dataRightsJson.displayField) $scope.displayFields = parseToJson($scope.dataRightsJson.displayField); if($scope.dataRightsJson.conditionField) $scope.conditionFields = parseToJson($scope.dataRightsJson.conditionField); else if($scope.dataRightsJson.conditions) $scope.conditionFields = parseToJson($scope.dataRightsJson.conditions); if($scope.dataRightsJson.sortField) $scope.sortFields = parseToJson($scope.dataRightsJson.sortField); if($scope.dataRightsJson.filterField) $scope.filterFields = parseToJson($scope.dataRightsJson.filterField); if($scope.dataRightsJson.manageField) $scope.manageFields = parseToJson($scope.dataRightsJson.manageField); else if($scope.dataRightsJson.buttons) $scope.manageFields = parseToJson($scope.dataRightsJson.buttons); if($scope.dataRightsJson.exportField) $scope.exportFileds = parseToJson($scope.dataRightsJson.exportField); $scope.ctlOptions = [ {k : "1",v : "单行文本框"},{k : "15",v : "日期控件"} ,{k : "3",v : "数据字典"} ,{k : "11",v : "下拉选项"} ,{k : "4",v : "人员选择器(单选)"},{k : "17",v : "角色选择器(单选)"},{k : "18",v : "组织选择器(单选)"},{k : "19",v : "岗位选择器(单选)"} ]; $scope.managerButtons = [{k:"add",v:"新增"},{k:"edit",v:"编辑"},{k:"del",v:"删除"},{k:"detail",v:"明细"},{k:"export",v:"导出"},{k:"import",v:"导入"},{k:"start",v:"启动流程"},{k:"reStart",v:"重启流程"}] $scope.getOptions = function(ty){ var ops = []; switch (ty) { case 'varchar' : ops = [{k : "1",v : "="},{k : "2",v : "!="},{k : "3",v : "like"}]; break; case 'number' : case 'int' : ops = [{k : "1",v : "="},{k : "2",v : ">"},{k : "3",v : "<"},{k : "4",v : ">="},{k : "5",v : "<="}]; break; case 'date' : ops = [{k : "1",v : "="},{k : "2",v : ">"},{k : "3",v : "<"},{k : "4",v : ">="},{k : "5",v : "<="},{k : "6",v : "日期范围"}]; break; default : ops = [{k : "1",v : "="},{k : "2",v : ">"},{k : "3",v : "<"},{k : "4",v : ">="},{k : "5",v : "<="}]; break; } return ops; } }, getOperateOptions : function(type){ var ops = []; switch (type) { case 'varchar' : ops = [{k : "1",v : "等于"},{k : "2",v : "不等于"},{k : "4",v : "like"},{k : "5",v : "like_l"},{k : "6",v : "like_r"},{k:"7",v:"in"}]; break; case 'number' : case 'int' : ops = [{k : "1",v : "等于"},{k : "2",v : "不等于"},{k : "3",v : "大于"},{k : "4",v : "大于等于"},{k : "5",v : "小于"},{k : "6",v : "小于等于"},{k:"7",v:"in"},{k : "8",v : "between"},{k:"9",v:"not in"}]; break; case 'date' : ops = [{k : "1",v : "等于"},{k : "2",v : "不等于"},{k : "3",v : "大于"},{k : "4",v : "大于等于"},{k : "5",v : "小于"},{k : "6",v : "小于等于"},{k : "7",v : "between"}]; break; default : ops = [{k : "1",v : "等于"},{k : "2",v : "不等于"},{k : "3",v : "大于"},{k : "4",v : "大于等于"},{k : "5",v : "小于"},{k : "6",v : "小于等于"}]; break; } return ops; }, initSysQueryViewData:function(bpmFormTableJSON){ var scope = this.scope, fieldList = [], displayList = []; for(var i = 0 ; i < bpmFormTableJSON.length ; i++){ if(bpmFormTableJSON[i].isSearch) fieldList.push(bpmFormTableJSON[i]); if(bpmFormTableJSON[i].isShow){ delete bpmFormTableJSON[i].alarmSetting; delete bpmFormTableJSON[i].controlContent; delete bpmFormTableJSON[i].resultFrom; bpmFormTableJSON[i].sortAble = 0; bpmFormTableJSON[i].defaultSort = 0; bpmFormTableJSON[i].frozen = 0; bpmFormTableJSON[i].sortSeq = "asc"; bpmFormTableJSON[i].align = "left"; displayList.push(bpmFormTableJSON[i]); } } scope.bpmFormTable = { fieldList : fieldList } var tempDiaplayFields = ""; if(displayFields&&displayFields.length>0){ for(var i = 0 ; i < displayFields.length ; i++){ var df = displayFields[i]; if(!df) continue; var hasShowRights = false; for(var j = 0 ; j < displayList.length ; j++) { if(df.fieldName == displayList[j].name) { df.name = displayList[j].name; df.fieldDesc = displayList[j].fieldDesc; df.isVirtual = displayList[j].isVirtual; hasShowRights = true; break; } } if(hasShowRights){ tempDiaplayFields = tempDiaplayFields ||[]; tempDiaplayFields.push(df); } } } scope.filterFields = { type:DataRightsJson.filterType||2, sql:(DataRightsJson.filterType==2||DataRightsJson.filterType==3)?DataRightsJson.filter:"", conditions:DataRightsJson.filterType==1?parseToJson(DataRightsJson.filter):"" } if(DataRightsJson.supportGroup == 1){ var groupingView = parseToJson(DataRightsJson.groupSetting), groupSummary = groupingView.groupSummary, groupField = groupingView.groupField, groupColumnShow = groupingView.groupColumnShow, groupText = groupingView.groupText, groupOrder = groupingView.groupOrder; scope.groupingView = []; for(var i = 0 ; i < groupField.length ; i++){ var isInDisplayFields = false; for(var j = 0 ; j < displayFields.length ; j++){ if(displayFields[j].fieldName == groupField[i]){ displayFields[j].gchecked = true; isInDisplayFields = true; break; } } if(isInDisplayFields) scope.groupingView.push({ groupField:groupField[i], groupColumnShow:groupColumnShow[i]?1:0, groupSummary:groupSummary[i]?1:0, groupText:groupText[i], groupOrder:groupOrder[i] }) } } scope.displayFields = tempDiaplayFields||displayList; scope.allDisplayFields = displayList; scope.sysQueryMetaFields = bpmFormTableJSON; }, isCheckboxNull : function(data){ return data!= 0 && data!= 1; }, initDataRightsJson : function(dataRightsJson){ if(!dataRightsJson.pageSize) dataRightsJson.pageSize = 20; if(this.isCheckboxNull(dataRightsJson.isQuery)) dataRightsJson.isQuery = 0; if(this.isCheckboxNull(dataRightsJson.initQuery)) dataRightsJson.initQuery = 0; if(this.isCheckboxNull(dataRightsJson.showRowsNum)) dataRightsJson.showRowsNum = 0; }, manageFieldValid : function(list){ if(!list) return false; var name =new Array(); for(var i = 0 ; i < list.length ; i++){ name.push(list[i].name); } return this.isRepeat(name); }, isRepeat : function (arr) { var hash = {}; for(var i in arr) { if(hash[arr[i]]) { return true; } hash[arr[i]] = true; } return false; }, selectCondition : function(type) { var _self = this.scope, list = _self.bpmFormTable.fieldList, service = _self.service; if(!_self.conditionFields) _self.conditionFields=[]; switch(type){ case 'sysQueryView': for(var f in list){ if(list[f].checked&&!this.hasInList(list[f].fieldName||list[f].name,_self.conditionFields,'name')){ var condition = { name : list[f].fieldName|| list[f].name, type : list[f].fieldType|| list[f].type||list[f].dataType, operate : "1", valueFrom : "1" }; if(condition.type == "date"){ condition.format = list[f].dateFormat||"yyyy-MM-dd" } _self.conditionFields.push(condition); } } break; default: for(var f in list){ if(list[f].checked&&!this.hasInList(list[f].fieldName||list[f].name,_self.conditionFields,'na')){ var condition = { na : list[f].fieldName|| list[f].name, ty : list[f].fieldType|| list[f].type, op : 1, cm : list[f].fieldDesc, va : "", vf : 1, ct : list[f].controlType, qt : this.getQueryType(list[f].fieldType|| list[f].type,1) }; _self.conditionFields.push(condition); } } break; } }, hasInList:function(na,list,tag){ for(var i in list){ if(list[i][tag]==na) return true; } return false; }, /** * 选择排序的字段 */ selectSort : function(listKey,nameKey,descKey) { var _self = this.scope, list = _self.bpmFormTable.fieldList, service = _self.service; if(listKey) list = _self.bpmFormTable[listKey]; nameKey = nameKey||"fieldName"; descKey = descKey||"fieldDesc"; if(!_self.sortFields) _self.sortFields = []; for(var f in list){ if(list[f].checked&&!this.hasInList(list[f][nameKey],_self.sortFields,'name')){ var condition = { name : list[f][nameKey], desc : list[f][descKey] }; _self.sortFields.push(condition); } } }, addManage : function() { this.scope.manageFields = this.scope.manageFields||[]; var list = this.scope.manageFields; var mf = {desc:"新增",name:"新增"} if(!this.noRights) mf.right = [{type:"none"}]; list.push(mf); }, /** * 增加过滤条件 */ addFilter : function() { var _self = this,bt = this.scope.dataRightsJson; var right = {type : 'none',id : '',name : '',script : ''}; this.filterDialog({ key : bt.tableId||bt.tableName, source : bt.source, callback : function(rtn) { if (rtn) { var filter = {},type= rtn.type,condition = (type==2?rtn.condition:JSON2.stringify(rtn.condition)); filter.name = rtn.name; filter.key = rtn.key; filter.type = type; filter.condition = condition; filter.right = [right]; if(!_self.scope.filterFields) _self.scope.filterFields = []; _self.scope.filterFields.push(filter); _self.scope.$digest(); } } }); }, /** * 过滤的窗口 */ filterDialog : function(conf) { var dialogWidth = 750; var dialogHeight = 500; conf = $.extend({}, {dialogWidth : dialogWidth,dialogHeight : dialogHeight,help : 0,status : 0,scroll : 0,center : 1}, conf); var url = this.scope.filterUrl + conf.key; url = url.getNewUrl(); var that =this; DialogUtil.open({ height:conf.dialogHeight, width: conf.dialogWidth, title : '过滤的窗口', url: url, isResize: true, //自定义参数 conf: conf, sucCall:function(rtn){ if (rtn && conf.callback) { conf.callback.call(that, rtn); } } }); }, /** * 编辑过滤条件窗口 */ editFilterDialog : function(list,idx) { var _self = this,bt = this.scope.dataRightsJson; this.filterDialog({ key : bt.tableId||bt.tableName, source : bt.source, filter : list[idx], callback : function(rtn) { if (rtn) { var condition = (rtn.type==2?rtn.condition:JSON2.stringify(rtn.condition)); list[idx].name = rtn.name; list[idx].key = rtn.key; list[idx].type = rtn.type; list[idx].condition = rtn.condition; this.scope.$digest(); } } }); }, delTr : function(list,idx) { list.splice(idx,1); }, moveTr : function(list,idx,isUp) { idx = parseInt(idx); if((isUp&&idx==0)||(!isUp&&idx==list.length-1)) return; if (isUp) { var t=list[idx-1]; list[idx-1]=list[idx]; list[idx]=t; } else { var t=list[idx+1]; list[idx+1]=list[idx]; list[idx]=t; } }, getQueryType : function(type, op) { var qt = "S"; switch (type) { case 'varchar' : if (op) { switch (op) { case 1 : case 2 : qt = 'S'; break case 3 : qt = 'SL'; break case 4 : qt = 'SLL'; break case 5 : qt = 'SLR'; break default : qt = 'S'; break } } break; case 'number' : qt = 'L'; break; case 'int' : qt = 'N'; break; case 'date' : if (op == 6) qt = 'DR'; else qt = 'DL'; break; default : qt = 'S'; break; } return qt; }, setSysQueryViewJson:function(json){ if(this.scope.type == 'sysQueryView'){ var obj = this.scope.dataRightsJson; json.conditions = json.conditionField; json.buttons = json.manageField; json.initQuery = obj.initQuery; json.showRowsNum = obj.showRowsNum; json.filterType = this.scope.filterFields.type; //过滤条件 if(json.filterType == 2|| json.filterType == 3){ editor.save(); json.filter = $('#sql').val(); }else json.filter = JSON.stringify($("#ruleDiv").linkdiv("getData")); //分组数据 json.supportGroup = obj.supportGroup; if(obj.supportGroup == 1){ var scope = this.scope, list = scope.groupingView; var groupField = []; var groupColumnShow = []; var groupText = []; var groupOrder = []; var groupSummary=[]; for(var i = 0 ; i < list.length ; i++) { groupField.push(list[i].groupField); groupColumnShow.push(list[i].groupColumnShow==1); groupSummary.push(list[i].groupSummary==1); groupText.push(list[i].groupText); groupOrder.push(list[i].groupOrder); } json.groupSetting = { groupField:groupField, groupColumnShow:groupColumnShow, groupText:groupText, groupOrder:groupOrder, groupSummary:groupSummary } json.groupSetting = JSON.stringify(json.groupSetting); } json.filterField = this.scope.dataRightsJson.showRowsNum; } }, customFormSubmit : function (showResponse){ var dr = this.scope.dataRightsJson; var json={ id:dr.id, tableId:dr.tableId, sqlId:dr.sqlId, name:dr.name, formKey:dr.formKey, source:dr.source, defId:dr.defId, alias:dr.alias, templateAlias:dr.templateAlias, sqlAlias:dr.sqlAlias, isQuery:dr.isQuery, isFilter:dr.isFilter, needPage:dr.needPage, pageSize:dr.pageSize, displayField:this.listToString(this.scope.displayFields), conditionField:this.listToString(this.scope.conditionFields), sortField:this.listToString(this.scope.sortFields), filterField:this.listToString(this.scope.filterFields), manageField:this.listToString(this.scope.manageFields), exportField:this.listToString(this.scope.exportFileds), templateAlias:dr.templateAlias }; //业务数据模板上的是否初始化模板 if(dr.resetTemp){ json.resetTemp=dr.resetTemp; } this.setSysQueryViewJson(json); var form = $('
'); var input = $(""); var jsonStr=JSON2.stringify(json); input.val(jsonStr); form.append(input); form.ajaxForm({success:showResponse}); form.submit(); }, listToString: function(list){ for(var i = 0 ; i < list.length ; i++){ if(list[i].hasOwnProperty("$$hashKey")) delete list[i].$$hashKey; } return JSON.stringify(list); }, setPingyin : function(sco,from,target){ var input = getValByScope("",from,sco); Share.getPingyin({ input:input, postCallback:function(data){ setValToScope(null,data.output,null,target,sco); } }); } }; return service; }]) .directive('rightSelect', function($compile) { return { restrict : 'E', replace : true, scope:{ list:"=" }, template : '', link : function(scope, elm, attrs) { scope.setPermision = function(list) { if(scope.r=="") return; for(var i = 0 ; i < list.length ; i++){ if(list[i].fields&&list[i].fields.length>0){ scope.setPermision(list[i].fields); }else{ if(list[i].right[0].hasOwnProperty("v")) list[i].right[0] = {"v":scope.r}; else list[i].right[0] = {"type":scope.r}; } } } } }; }) .directive('toolButtons', ['dataRightsService',function(dataRightsService) { return { restrict : 'E', replace : true, scope:{type:"@",list:"=",index:"@"}, template : '
'+ ''+ ''+ ''+ ''+ '
', link : function(scope, elm, attrs) { scope.service = dataRightsService; } }; }]) //显示字段,显示列字段 .directive('displaySetting', function() { return { restrict : 'E', replace : true, template : '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
序号列名注释'+ '显示权限'+ ''+ '排序
{{$index}}{{f.name}}'+ ''+ ''+ '
'+ '
'+ ''+ '
'+ '
' }; }) //显示字段,显示列字段 for SYS_QUERY_FIELDSETTING .directive('fieldSetting', function() { return { restrict : 'E', replace : true, template : '
'+ '重置列表'+ '    '+ '重置所有列表'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ /*''+*/ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ /*''+*/ ''+ ''+ '
序号顺序列名注释支持排序排序方向默认排序是否冻结是否隐藏对齐方式统计类型宽度(%)统计模板'+ ''+ ''+ '显示权限'+ ''+ '排序
{{$index+1}}'+ ''+ '{{f.name}}{{f.fieldDesc}} '+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
'+ '
'+ ''+ '
'+ '
', link:function(scope,element,attrs){ scope.changeDefaultSort = function(idx){ for ( var i = 0; i < scope.displayFields.length; i++) { if(i!=idx) scope.displayFields[i].defaultSort = 0; } } for(var i = 0 ;i .directive('manageSetting', function() { return { restrict : 'E', replace : true, template : '
'+ '
'+ '
'+ '
'+ '添加'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
选择名称类型'+ '权限'+ ''+ '管理
'+ ''+ ''+ ''+ ''+ '
'+ '
'+ ''+ '
'+ '
' }; }) //功能按钮 .directive('manageSettingView', function() { return { restrict : 'E', replace : true, template : '
'+ '重置按钮'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
名称类型URL路径管理
'+ '{{f.name}}'+ ''+ '{{f.inRow==1?"行内":"页头"}}'+ ''+ '{{f.urlPath}}'+ ''+ ''+ '
'+ '
', link:function(scope,el,attrs){ scope.oldManageFields = $.extend(true,[],scope.manageFields); scope.resetFields = function(){ scope.manageFields = $.extend(true,[],scope.sqlButtons); } } }; }) //导出字段 .directive('exportSetting', function() { return { restrict : 'E', replace : true, template : '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
序号列名注释'+ '导出权限'+ ''+ '
{{table.tableDesc}}({{table.tableName}})
{{$index}}{{f.name}}'+ ''+ '
'+ '
{{$index}}{{f.name}}'+ ''+ '
'+ '
'+ '
', link:function(scope,el,attrs){ console.info("scope.table.fields"); } }; }) //查询条件字段 .directive('conditionSetting', function() { return { restrict : 'E', replace : true, template : '
'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
列名注释类型
{{field.fieldName||field.name}}{{field.fieldDesc}}{{field.fieldType||field.type||field.dataType}}
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ ''+ '==>'+ ''+ '
'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
列名显示名控件类型条件值来源管理
{{cd.na}}'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ ''+ '==>'+ ''+ '
'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
列名数据类型操作符值来源格式化管理
{{cd.name}}{{cd.type}}'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
'+ '
'+ '
'+ '
'+ '
'+ '
', link:function(scope,el,attrs){ } }; }) //过滤条件 .directive('filterSetting', function() { return { restrict : 'E', replace : true, template : '
'+ '
'+ '
'+ '
'+ '添加'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
选择名称Key类型'+ '权限'+ ''+ '管理
'+ '{{f.name}}{{f.key}}{{f.type==2?"SQL":"条件脚本"}}'+ '
'+ '
'+ ''+ '
'+ '
' }; }) //排序字段 .directive('sortSetting', function() { return { restrict : 'E', replace : true, scope:true, template : '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
选择列名注释
'+ ''+ '{{field.name||field.fieldName}}{{field.desc||field.fieldDesc}}
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ ''+ '==>'+ ''+ '
'+ '
'+ '
'+ '
'+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ ''+ '
列名注释排序管理
{{sd.name}}{{sd.desc}}'+ ''+ ''+ ''+ '
'+ '
'+ '
'+ '
'+ '
'+ '
'+ '', link:function(scope,element,attrs){ scope['listkey'] = attrs['listkey']; scope['namekey'] = attrs['namekey']; scope['desckey'] = attrs['desckey']; } }; })