Commit 316f67ab81432e24b0412fd1629a2353aca5f068

Authored by 潘钊
2 parents a9cc5402 4a5801f4

Merge branch 'minhang' into qingpu

# Conflicts:
#	src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
#	src/main/java/com/bsth/data/gpsdata/GpsRealData.java
#	src/main/resources/application-dev.properties

Too many changes to show.

To preserve performance only 17 of 36 files are displayed.

src/main/java/com/bsth/controller/realcontrol/BasicDataController.java
... ... @@ -47,6 +47,15 @@ public class BasicDataController {
47 47 return rs;
48 48 }
49 49  
  50 + @RequestMapping("/all_personnel")
  51 + public Map<String, String> all_personnel(){
  52 + //Map<String, Object> rs = new HashMap<>();
  53 + //PersonnelFieldFilter filter=new PersonnelFieldFilter();
  54 +
  55 + //rs.put("list", JSON.parse(JSON.toJSONString(BasicData.jsyMap.values(), filter)));
  56 + return BasicData.allPerson;
  57 + }
  58 +
50 59  
51 60 public class PersonnelFieldFilter implements PropertyFilter{
52 61  
... ...
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
... ... @@ -144,4 +144,4 @@ public class ArrivalData_GPS implements CommandLineRunner{
144 144 carIndexMap.put(nbbm, size);
145 145 return rs;
146 146 }
147   -}
  147 +}
148 148 \ No newline at end of file
... ...
src/main/java/com/bsth/oplog/db/DBHelper.java
... ... @@ -37,7 +37,7 @@ public class DBHelper implements CommandLineRunner{
37 37  
38 38 @Override
39 39 public void run() {
40   - persistence.batchSave(buffer);
  40 + //persistence.batchSave(buffer);
41 41 }
42 42 }
43 43  
... ...
src/main/resources/application-dev.properties
... ... @@ -8,9 +8,9 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
8 8 spring.jpa.database= MYSQL
9 9 spring.jpa.show-sql= true
10 10 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
11   -spring.datasource.url= jdbc:mysql://127.0.0.1:3306/qp_control
  11 +spring.datasource.url= jdbc:mysql://192.168.168.201:3306/qp_control
12 12 spring.datasource.username= root
13   -spring.datasource.password= panzhao
  13 +spring.datasource.password= 123456
14 14 #DATASOURCE
15 15 spring.datasource.max-active=100
16 16 spring.datasource.max-idle=8
... ...
src/main/resources/datatools/config-prod.properties
... ... @@ -4,11 +4,11 @@
4 4 datatools.kettle_properties=/datatools/kettle.properties
5 5 # 2、ktr文件通用配置变量(数据库连接,根据不同的环境需要修正)
6 6 #数据库ip地址
7   -datatools.kvars_dbip=192.168.40.82
  7 +datatools.kvars_dbip=192.168.40.100
8 8 #数据库用户名
9 9 datatools.kvars_dbuname=root
10 10 #数据库密码
11   -datatools.kvars_dbpwd=123456
  11 +datatools.kvars_dbpwd=root@JSP2jsp
12 12 #数据库库名
13 13 datatools.kvars_dbdname=qp_control
14 14  
... ...
src/main/resources/static/assets/img/bg_9b9dcb65ff.png

17.4 KB | W: | H:

5.9 KB | W: | H:

  • 2-up
  • Swipe
  • Onion skin
src/main/resources/static/pages/scheduleApp/module/common/dts1/checkbox/saCheckboxgroup.js
1   -
2   -
3   -/**
4   - * saCheckboxgroup指令
5   - * 属性如下:
6   - * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
7   - * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
8   - * dcname(必须):绑定的model字段名,如:dcname=xl.id
9   - * name(必须):控件的名字
10   - * required(可选):是否要用required验证
11   - * disabled(可选):标示框是否可选
12   - *
13   - */
14   -angular.module('ScheduleApp').directive('saCheckboxgroup', [
15   - function() {
16   - return {
17   - restrict: 'E',
18   - templateUrl: '/pages/scheduleApp/module/common/dts1/checkbox/saCheckboxgroupTemplate.html',
19   - scope: {
20   - model: "=" // 独立作用域,关联外部的模型object
21   - },
22   - controllerAs: "$saCheckboxgroupCtrl",
23   - bindToController: true,
24   - controller: function($scope) {
25   - var self = this;
26   - self.$$data = []; // 内部的数据
27   -
28   - // TODO:数据写死,周一至周日选择数据,以后有别的数据再议
29   - self.$$data = [
30   - {name: "星期一", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
31   - {name: "星期二", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
32   - {name: "星期三", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
33   - {name: "星期四", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
34   - {name: "星期五", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
35   - {name: "星期六", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
36   - {name: "星期日", checkedvalue: "1", uncheckedvalue: "0", ischecked: false}
37   - ];
38   - },
39   -
40   - /**
41   - * 此阶段可以改dom结构,此时angular还没扫描指令,
42   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
43   - * @param tElem
44   - * @param tAttrs
45   - * @returns {{pre: Function, post: Function}}
46   - */
47   - compile: function(tElem, tAttrs) {
48   - // 获取所有的属性
49   - var $name_attr = tAttrs["name"]; // 控件的名字
50   - var $required_attr = tAttrs["required"]; // 是否需要required验证
51   - var $disabled_attr = tAttrs["disabled"]; // 是否禁用
52   - var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
53   -
54   - // controlAs名字
55   - var ctrlAs = '$saCheckboxgroupCtrl';
56   -
57   - // 如果有required属性,添加angularjs required验证
58   - if ($required_attr != undefined) {
59   - //console.log(tElem.html());
60   - tElem.find("div").attr("required", "");
61   - }
62   - // 如果有disabled属性,添加禁用标志
63   - if ($disabled_attr != undefined) {
64   - tElem.find("input").attr("ng-disabled", "true");
65   - }
66   -
67   - return {
68   - pre: function(scope, element, attr) {
69   - // TODO:
70   - },
71   - /**
72   - * 相当于link函数。
73   - * @param scope
74   - * @param element
75   - * @param attr
76   - */
77   - post: function(scope, element, attr) {
78   - // name属性
79   - if ($name_attr) {
80   - scope[ctrlAs]["$name_attr"] = $name_attr;
81   - }
82   -
83   - /**
84   - * checkbox选择事件处理函数。
85   - * @param $d 数据对象,$$data中的元素对象
86   - */
87   - scope[ctrlAs].$$internal_updateCheck_fn = function($d) {
88   - $d.ischecked = !$d.ischecked;
89   - console.log($d);
90   - };
91   -
92   - // 测试使用watch监控$$data的变化
93   - scope.$watch(
94   - function() {
95   - return scope[ctrlAs]["$$data"];
96   - },
97   - function(newValue, oldValue) {
98   - // 根据$$data生成对应的数据
99   - var rule_days_arr = [];
100   - var i;
101   - for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
102   - if (scope[ctrlAs]["$$data"][i].ischecked)
103   - rule_days_arr.push(scope[ctrlAs]["$$data"][i].checkedvalue);
104   - else
105   - rule_days_arr.push(scope[ctrlAs]["$$data"][i].uncheckedvalue);
106   - }
107   - scope[ctrlAs].$$internalmodel = rule_days_arr.join(",");
108   - //scope[ctrlAs].$$internalmodel = undefined;
109   - console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);
110   -
111   - // 更新model
112   - if ($dcname_attr) {
113   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = rule_days_arr.join(',');");
114   - }
115   -
116   -
117   - },
118   - true
119   - );
120   -
121   - // TODO:
122   -
123   - // 监控dcvalue model值变换
124   - attr.$observe("dcvalue", function(value) {
125   - console.log("saCheckboxgroup 监控dc1 model值变换:" + value);
126   - if (value) {
127   - // 根据value值,修改$$data里的值
128   - var data_array = value.split(",");
129   - var i;
130   - if (data_array.length > scope[ctrlAs]["$$data"].length) {
131   - for (i = 0; i < scope[ctrlAs]["$$data"].length; i ++) {
132   - if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
133   - scope[ctrlAs]["$$data"][i].ischecked = true;
134   - } else {
135   - scope[ctrlAs]["$$data"][i].ischecked = false;
136   - }
137   - }
138   - } else {
139   - for (i = 0; i < data_array.length; i ++) {
140   - if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
141   - scope[ctrlAs]["$$data"][i].ischecked = true;
142   - } else {
143   - scope[ctrlAs]["$$data"][i].ischecked = false;
144   - }
145   - }
146   - }
147   -
148   - }
149   - });
150   - }
151   -
152   - };
153   -
154   -
155   - }
156   -
157   - };
158   - }
159   -]);
160   -
  1 +
  2 +
  3 +/**
  4 + * saCheckboxgroup指令
  5 + * 属性如下:
  6 + * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
  7 + * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
  8 + * dcname(必须):绑定的model字段名,如:dcname=xl.id
  9 + * name(必须):控件的名字
  10 + * required(可选):是否要用required验证
  11 + * disabled(可选):标示框是否可选
  12 + *
  13 + */
  14 +angular.module('ScheduleApp').directive('saCheckboxgroup', [
  15 + function() {
  16 + return {
  17 + restrict: 'E',
  18 + templateUrl: '/pages/scheduleApp/module/common/dts1/checkbox/saCheckboxgroupTemplate.html',
  19 + scope: {
  20 + model: "=" // 独立作用域,关联外部的模型object
  21 + },
  22 + controllerAs: "$saCheckboxgroupCtrl",
  23 + bindToController: true,
  24 + controller: function($scope) {
  25 + var self = this;
  26 + self.$$data = []; // 内部的数据
  27 +
  28 + // TODO:数据写死,周一至周日选择数据,以后有别的数据再议
  29 + self.$$data = [
  30 + {name: "星期一", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  31 + {name: "星期二", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  32 + {name: "星期三", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  33 + {name: "星期四", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  34 + {name: "星期五", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  35 + {name: "星期六", checkedvalue: "1", uncheckedvalue: "0", ischecked: false},
  36 + {name: "星期日", checkedvalue: "1", uncheckedvalue: "0", ischecked: false}
  37 + ];
  38 + },
  39 +
  40 + /**
  41 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  42 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  43 + * @param tElem
  44 + * @param tAttrs
  45 + * @returns {{pre: Function, post: Function}}
  46 + */
  47 + compile: function(tElem, tAttrs) {
  48 + // 获取所有的属性
  49 + var $name_attr = tAttrs["name"]; // 控件的名字
  50 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  51 + var $disabled_attr = tAttrs["disabled"]; // 是否禁用
  52 + var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
  53 +
  54 + // controlAs名字
  55 + var ctrlAs = '$saCheckboxgroupCtrl';
  56 +
  57 + // 如果有required属性,添加angularjs required验证
  58 + if ($required_attr != undefined) {
  59 + //console.log(tElem.html());
  60 + tElem.find("div").attr("required", "");
  61 + }
  62 + // 如果有disabled属性,添加禁用标志
  63 + if ($disabled_attr != undefined) {
  64 + tElem.find("input").attr("ng-disabled", "true");
  65 + }
  66 +
  67 + return {
  68 + pre: function(scope, element, attr) {
  69 + // TODO:
  70 + },
  71 + /**
  72 + * 相当于link函数。
  73 + * @param scope
  74 + * @param element
  75 + * @param attr
  76 + */
  77 + post: function(scope, element, attr) {
  78 + // name属性
  79 + if ($name_attr) {
  80 + scope[ctrlAs]["$name_attr"] = $name_attr;
  81 + }
  82 +
  83 + /**
  84 + * checkbox选择事件处理函数。
  85 + * @param $d 数据对象,$$data中的元素对象
  86 + */
  87 + scope[ctrlAs].$$internal_updateCheck_fn = function($d) {
  88 + $d.ischecked = !$d.ischecked;
  89 + console.log($d);
  90 + };
  91 +
  92 + // 测试使用watch监控$$data的变化
  93 + scope.$watch(
  94 + function() {
  95 + return scope[ctrlAs]["$$data"];
  96 + },
  97 + function(newValue, oldValue) {
  98 + // 根据$$data生成对应的数据
  99 + var rule_days_arr = [];
  100 + var i;
  101 + for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
  102 + if (scope[ctrlAs]["$$data"][i].ischecked)
  103 + rule_days_arr.push(scope[ctrlAs]["$$data"][i].checkedvalue);
  104 + else
  105 + rule_days_arr.push(scope[ctrlAs]["$$data"][i].uncheckedvalue);
  106 + }
  107 + scope[ctrlAs].$$internalmodel = rule_days_arr.join(",");
  108 + //scope[ctrlAs].$$internalmodel = undefined;
  109 + console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);
  110 +
  111 + // 更新model
  112 + if ($dcname_attr) {
  113 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = rule_days_arr.join(',');");
  114 + }
  115 +
  116 +
  117 + },
  118 + true
  119 + );
  120 +
  121 + // TODO:
  122 +
  123 + // 监控dcvalue model值变换
  124 + attr.$observe("dcvalue", function(value) {
  125 + console.log("saCheckboxgroup 监控dc1 model值变换:" + value);
  126 + if (value) {
  127 + // 根据value值,修改$$data里的值
  128 + var data_array = value.split(",");
  129 + var i;
  130 + if (data_array.length > scope[ctrlAs]["$$data"].length) {
  131 + for (i = 0; i < scope[ctrlAs]["$$data"].length; i ++) {
  132 + if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
  133 + scope[ctrlAs]["$$data"][i].ischecked = true;
  134 + } else {
  135 + scope[ctrlAs]["$$data"][i].ischecked = false;
  136 + }
  137 + }
  138 + } else {
  139 + for (i = 0; i < data_array.length; i ++) {
  140 + if (data_array[i] == scope[ctrlAs]["$$data"][i].checkedvalue) {
  141 + scope[ctrlAs]["$$data"][i].ischecked = true;
  142 + } else {
  143 + scope[ctrlAs]["$$data"][i].ischecked = false;
  144 + }
  145 + }
  146 + }
  147 +
  148 + }
  149 + });
  150 + }
  151 +
  152 + };
  153 +
  154 +
  155 + }
  156 +
  157 + };
  158 + }
  159 +]);
  160 +
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/load/loadingWidget.js
1   -
2   -/**
3   - * loading载入中指令。
4   - */
5   -angular.module('ScheduleApp').directive('loadingWidget', ['requestNotificationChannel', function(requestNotificationChannel) {
6   - return {
7   - restrict: 'A',
8   - link: function(scope, element) {
9   - // 初始隐藏loading界面
10   - element.hide();
11   -
12   - // 开始请求通知处理
13   - requestNotificationChannel.onRequestStarted(scope, function() {
14   - element.show();
15   - });
16   - // 请求结束通知处理
17   - requestNotificationChannel.onRequestEnded(scope, function() {
18   - element.hide();
19   - });
20   - }
21   - };
  1 +
  2 +/**
  3 + * loading载入中指令。
  4 + */
  5 +angular.module('ScheduleApp').directive('loadingWidget', ['requestNotificationChannel', function(requestNotificationChannel) {
  6 + return {
  7 + restrict: 'A',
  8 + link: function(scope, element) {
  9 + // 初始隐藏loading界面
  10 + element.hide();
  11 +
  12 + // 开始请求通知处理
  13 + requestNotificationChannel.onRequestStarted(scope, function() {
  14 + element.show();
  15 + });
  16 + // 请求结束通知处理
  17 + requestNotificationChannel.onRequestEnded(scope, function() {
  18 + element.hide();
  19 + });
  20 + }
  21 + };
22 22 }]);
23 23 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/radioButton/saRadiogroup.js
1   -
2   -/**
3   - * saRadiogroup指令
4   - * 属性如下:
5   - * model(必须):独立作用域,外部绑定的一个值,如:ctrl.timeTableManageForForm.isEnableDisTemplate
6   - * dicgroup(必须):关联的字典数据type(TODO:以后增加其他数据源)
7   - * name(必须):控件的名字
8   - * required(可选):是否要用required验证
9   - * disabled(可选):标示单选框是否可选
10   - *
11   - */
12   -angular.module('ScheduleApp').directive("saRadiogroup", [function() {
13   - /**
14   - * 使用字典数据的单选按钮组的指令。
15   - * 指令名称:truefalse-Dic
16   - */
17   - return {
18   - restrict: 'E',
19   - templateUrl: '/pages/scheduleApp/module/common/dts1/radioButton/saRadiogroupTemplate.html',
20   - scope: {
21   - model: "="
22   - },
23   - controllerAs: "$saRadiogroupCtrl",
24   - bindToController: true,
25   - controller: function($scope) {
26   - //$scope["model"] = {selectedOption: null};
27   - //console.log("controller");
28   - //console.log("controller:" + $scope["model"]);
29   -
30   - var self = this;
31   - self.$$data = null; // 内部数据
32   - },
33   -
34   - /**
35   - * 此阶段可以改dom结构,此时angular还没扫描指令,
36   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
37   - * @param tElem
38   - * @param tAttrs
39   - * @returns {{pre: Function, post: Function}}
40   - */
41   - compile: function(tElem, tAttrs) {
42   - // 获取属性
43   - var $dicgroup_attr = tAttrs["dicgroup"]; // 关联的字典数据type
44   - var $name_attr = tAttrs["name"]; // 控件的名字
45   - var $required_attr = tAttrs["required"]; // 是否要用required验证
46   - var $disabled_attr = tAttrs["disabled"]; // 标示单选框是否可选
47   -
48   - // controlAs名字
49   - var ctrlAs = "$saRadiogroupCtrl";
50   -
51   - // 如果有required属性,添加angularjs required验证
52   - if ($required_attr != undefined) {
53   - tElem.find("input").attr("required", "");
54   - }
55   -
56   - return {
57   - pre: function(scope, element, attr) {
58   -
59   - },
60   -
61   - /**
62   - * 相当于link函数。
63   - * @param scope
64   - * @param element
65   - * @param attr
66   - */
67   - post: function(scope, element, attr) {
68   - //console.log("link");
69   - //console.log("link:" + scope.model);
70   - //scope["model"] = {selectedOption: null};
71   -
72   - if ($name_attr) {
73   - scope[ctrlAs].nv = $name_attr;
74   - }
75   -
76   - if ($disabled_attr) {
77   - scope[ctrlAs].disabled = true;
78   - }
79   - if ($dicgroup_attr) {
80   - var obj = dictionaryUtils.getByGroup($dicgroup_attr);
81   - scope[ctrlAs].$$data = obj;
82   - // 处理 scope["dic"] key值
83   - scope[ctrlAs].dicvalueCalcu = function(value) {
84   - if (value == "true") {
85   - //console.log(value);
86   - return true;
87   - } else if (value == "false") {
88   - //console.log(value);
89   - return false;
90   - } else {
91   - return value;
92   - }
93   - };
94   - }
95   - }
96   - };
97   - }
98   - };
99   -}]);
  1 +
  2 +/**
  3 + * saRadiogroup指令
  4 + * 属性如下:
  5 + * model(必须):独立作用域,外部绑定的一个值,如:ctrl.timeTableManageForForm.isEnableDisTemplate
  6 + * dicgroup(必须):关联的字典数据type(TODO:以后增加其他数据源)
  7 + * name(必须):控件的名字
  8 + * required(可选):是否要用required验证
  9 + * disabled(可选):标示单选框是否可选
  10 + *
  11 + */
  12 +angular.module('ScheduleApp').directive("saRadiogroup", [function() {
  13 + /**
  14 + * 使用字典数据的单选按钮组的指令。
  15 + * 指令名称:truefalse-Dic
  16 + */
  17 + return {
  18 + restrict: 'E',
  19 + templateUrl: '/pages/scheduleApp/module/common/dts1/radioButton/saRadiogroupTemplate.html',
  20 + scope: {
  21 + model: "="
  22 + },
  23 + controllerAs: "$saRadiogroupCtrl",
  24 + bindToController: true,
  25 + controller: function($scope) {
  26 + //$scope["model"] = {selectedOption: null};
  27 + //console.log("controller");
  28 + //console.log("controller:" + $scope["model"]);
  29 +
  30 + var self = this;
  31 + self.$$data = null; // 内部数据
  32 + },
  33 +
  34 + /**
  35 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  36 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  37 + * @param tElem
  38 + * @param tAttrs
  39 + * @returns {{pre: Function, post: Function}}
  40 + */
  41 + compile: function(tElem, tAttrs) {
  42 + // 获取属性
  43 + var $dicgroup_attr = tAttrs["dicgroup"]; // 关联的字典数据type
  44 + var $name_attr = tAttrs["name"]; // 控件的名字
  45 + var $required_attr = tAttrs["required"]; // 是否要用required验证
  46 + var $disabled_attr = tAttrs["disabled"]; // 标示单选框是否可选
  47 +
  48 + // controlAs名字
  49 + var ctrlAs = "$saRadiogroupCtrl";
  50 +
  51 + // 如果有required属性,添加angularjs required验证
  52 + if ($required_attr != undefined) {
  53 + tElem.find("input").attr("required", "");
  54 + }
  55 +
  56 + return {
  57 + pre: function(scope, element, attr) {
  58 +
  59 + },
  60 +
  61 + /**
  62 + * 相当于link函数。
  63 + * @param scope
  64 + * @param element
  65 + * @param attr
  66 + */
  67 + post: function(scope, element, attr) {
  68 + //console.log("link");
  69 + //console.log("link:" + scope.model);
  70 + //scope["model"] = {selectedOption: null};
  71 +
  72 + if ($name_attr) {
  73 + scope[ctrlAs].nv = $name_attr;
  74 + }
  75 +
  76 + if ($disabled_attr) {
  77 + scope[ctrlAs].disabled = true;
  78 + }
  79 + if ($dicgroup_attr) {
  80 + var obj = dictionaryUtils.getByGroup($dicgroup_attr);
  81 + scope[ctrlAs].$$data = obj;
  82 + // 处理 scope["dic"] key值
  83 + scope[ctrlAs].dicvalueCalcu = function(value) {
  84 + if (value == "true") {
  85 + //console.log(value);
  86 + return true;
  87 + } else if (value == "false") {
  88 + //console.log(value);
  89 + return false;
  90 + } else {
  91 + return value;
  92 + }
  93 + };
  94 + }
  95 + }
  96 + };
  97 + }
  98 + };
  99 +}]);
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/select/saSelect.js
1   -
2   -angular.module('ScheduleApp').directive("saSelect", ['$timeout', function($timeout) {
3   - return {
4   - restrict: 'E',
5   - templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelectTemplate.html',
6   - scope: {
7   - model: "="
8   - },
9   - controllerAs: "$saSelectCtrl",
10   - bindToController: true,
11   - controller: function() {
12   - var self = this;
13   - self.datas = []; // 关联的字典数据,内部格式 {code:{值},name:{名字}}
14   - },
15   - /**
16   - * 此阶段可以改dom结构,此时angular还没扫描指令,
17   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
18   - * @param tElem
19   - * @param tAttrs
20   - * @returns {{pre: Function, post: Function}}
21   - */
22   - compile: function(tElem, tAttrs) {
23   - // 确定是否使用angularjs required验证
24   - // 属性 required
25   - // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
26   - var required_attr = tAttrs["required"];
27   - if (required_attr) {
28   - if (required_attr == "true") {
29   - // 添加required属性指令
30   - tElem.find("ui-select").attr("required", "");
31   - } else {
32   - // 不等于true,不添加required属性指令
33   - }
34   - } else {
35   - // 不添加required属性指令
36   - }
37   -
38   - //console.log("saSelect" + ":compile = >" + tElem.html());
39   -
40   - return {
41   - pre: function(scope, element, attr) {
42   - // TODO:
43   - },
44   - /**
45   - * 相当于link函数。
46   - *
47   - * 重要属性如下:
48   - * model 是绑定外部值。
49   - * dicgroup 字典组的类型
50   - * name input name属性值
51   - */
52   - post: function(scope, element, attr) {
53   - // 1、获取属性
54   - var dicgroup_attr = attr['dicgroup']; // 字典组的类型
55   - var name_attr = attr['name']; // input name属性值
56   - var dicname_attr = attr['dicname']; // model关联的字典名字段
57   - var codename_attr = attr['codename']; // model关联的字典值字段
58   - var placeholder_attr = attr['placeholder']; // select placeholder提示
59   -
60   - // 系统的字典对象,使用dictionaryUtils类获取
61   - var origin_dicgroup;
62   - var dic_key; // 字典key
63   -
64   - if (dicgroup_attr) { // 赋值指定的字典数据
65   - origin_dicgroup = dictionaryUtils.getByGroup(dicgroup_attr);
66   - for (dic_key in origin_dicgroup) {
67   - var data = {}; // 重新组合的字典元素对象
68   - if (dic_key == "true")
69   - data.code = true;
70   - else
71   - data.code = dic_key;
72   - data.name = origin_dicgroup[dic_key];
73   - scope["$saSelectCtrl"].datas.push(data);
74   - }
75   - }
76   -
77   - if (name_attr) {
78   - scope["$saSelectCtrl"].nv = name_attr;
79   - }
80   - if (placeholder_attr) {
81   - scope["$saSelectCtrl"].ph = placeholder_attr;
82   - }
83   -
84   - scope["$saSelectCtrl"].select = function($item) {
85   - if (codename_attr) {
86   - scope["$saSelectCtrl"].model[codename_attr] = $item.code;
87   - }
88   - if (dicname_attr) {
89   - scope["$saSelectCtrl"].model[dicname_attr] = $item.name;
90   - }
91   - };
92   -
93   - scope["$saSelectCtrl"].remove = function() {
94   - if (codename_attr) {
95   - scope["$saSelectCtrl"].model[codename_attr] = null;
96   - }
97   - if (dicname_attr) {
98   - scope["$saSelectCtrl"].model[dicname_attr] = null;
99   - }
100   - scope["$saSelectCtrl"].cmodel = null;
101   - };
102   -
103   - $timeout(function() {
104   - // 创建内部使用的绑定对象
105   - var model_code = scope["$saSelectCtrl"].model[codename_attr];
106   - scope["$saSelectCtrl"].cmodel = model_code;
107   - }, 0);
108   - }
109   - }
110   - }
111   - };
112   -}]);
  1 +
  2 +angular.module('ScheduleApp').directive("saSelect", ['$timeout', function($timeout) {
  3 + return {
  4 + restrict: 'E',
  5 + templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelectTemplate.html',
  6 + scope: {
  7 + model: "="
  8 + },
  9 + controllerAs: "$saSelectCtrl",
  10 + bindToController: true,
  11 + controller: function() {
  12 + var self = this;
  13 + self.datas = []; // 关联的字典数据,内部格式 {code:{值},name:{名字}}
  14 + },
  15 + /**
  16 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  17 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  18 + * @param tElem
  19 + * @param tAttrs
  20 + * @returns {{pre: Function, post: Function}}
  21 + */
  22 + compile: function(tElem, tAttrs) {
  23 + // 确定是否使用angularjs required验证
  24 + // 属性 required
  25 + // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
  26 + var required_attr = tAttrs["required"];
  27 + if (required_attr) {
  28 + if (required_attr == "true") {
  29 + // 添加required属性指令
  30 + tElem.find("ui-select").attr("required", "");
  31 + } else {
  32 + // 不等于true,不添加required属性指令
  33 + }
  34 + } else {
  35 + // 不添加required属性指令
  36 + }
  37 +
  38 + //console.log("saSelect" + ":compile = >" + tElem.html());
  39 +
  40 + return {
  41 + pre: function(scope, element, attr) {
  42 + // TODO:
  43 + },
  44 + /**
  45 + * 相当于link函数。
  46 + *
  47 + * 重要属性如下:
  48 + * model 是绑定外部值。
  49 + * dicgroup 字典组的类型
  50 + * name input name属性值
  51 + */
  52 + post: function(scope, element, attr) {
  53 + // 1、获取属性
  54 + var dicgroup_attr = attr['dicgroup']; // 字典组的类型
  55 + var name_attr = attr['name']; // input name属性值
  56 + var dicname_attr = attr['dicname']; // model关联的字典名字段
  57 + var codename_attr = attr['codename']; // model关联的字典值字段
  58 + var placeholder_attr = attr['placeholder']; // select placeholder提示
  59 +
  60 + // 系统的字典对象,使用dictionaryUtils类获取
  61 + var origin_dicgroup;
  62 + var dic_key; // 字典key
  63 +
  64 + if (dicgroup_attr) { // 赋值指定的字典数据
  65 + origin_dicgroup = dictionaryUtils.getByGroup(dicgroup_attr);
  66 + for (dic_key in origin_dicgroup) {
  67 + var data = {}; // 重新组合的字典元素对象
  68 + if (dic_key == "true")
  69 + data.code = true;
  70 + else
  71 + data.code = dic_key;
  72 + data.name = origin_dicgroup[dic_key];
  73 + scope["$saSelectCtrl"].datas.push(data);
  74 + }
  75 + }
  76 +
  77 + if (name_attr) {
  78 + scope["$saSelectCtrl"].nv = name_attr;
  79 + }
  80 + if (placeholder_attr) {
  81 + scope["$saSelectCtrl"].ph = placeholder_attr;
  82 + }
  83 +
  84 + scope["$saSelectCtrl"].select = function($item) {
  85 + if (codename_attr) {
  86 + scope["$saSelectCtrl"].model[codename_attr] = $item.code;
  87 + }
  88 + if (dicname_attr) {
  89 + scope["$saSelectCtrl"].model[dicname_attr] = $item.name;
  90 + }
  91 + };
  92 +
  93 + scope["$saSelectCtrl"].remove = function() {
  94 + if (codename_attr) {
  95 + scope["$saSelectCtrl"].model[codename_attr] = null;
  96 + }
  97 + if (dicname_attr) {
  98 + scope["$saSelectCtrl"].model[dicname_attr] = null;
  99 + }
  100 + scope["$saSelectCtrl"].cmodel = null;
  101 + };
  102 +
  103 + $timeout(function() {
  104 + // 创建内部使用的绑定对象
  105 + var model_code = scope["$saSelectCtrl"].model[codename_attr];
  106 + scope["$saSelectCtrl"].cmodel = model_code;
  107 + }, 0);
  108 + }
  109 + }
  110 + }
  111 + };
  112 +}]);
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/select/saSelect2.js
1   -
2   -
3   -angular.module('ScheduleApp').directive("saSelect2", [
4   - '$timeout', '$$SearchInfoService_g',
5   - function($timeout, $$searchInfoService_g) {
6   - return {
7   - restrict: 'E',
8   - templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect2Template.html',
9   - scope: {
10   - model: "=" // 独立作用域,关联外部的模型对象
11   - },
12   - controllerAs: "$saSelectCtrl",
13   - bindToController: true,
14   - controller: function($scope) {
15   - var self = this;
16   - self.$$data = []; // 内部关联的数据
17   - },
18   - /**
19   - * 此阶段可以改dom结构,此时angular还没扫描指令,
20   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
21   - * @param tElem
22   - * @param tAttrs
23   - * @returns {{pre: Function, post: Function}}
24   - */
25   - compile: function(tElem, tAttrs) {
26   - // 1、获取此阶段使用的属性
27   - var $required_attr = tAttrs["required"]; // 用于和表单验证连接,指定成required="true"才有效。
28   -
29   - // 2、处理属性
30   -
31   - // 确定是否使用angularjs required验证
32   - // 属性 required
33   - // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
34   - if ($required_attr) {
35   - if ($required_attr == "true") {
36   - // 添加required属性指令
37   - tElem.find("ui-select").attr("required", "");
38   - } else {
39   - // 不等于true,不添加required属性指令
40   - }
41   - } else {
42   - // 不添加required属性指令
43   - }
44   -
45   - //console.log("saSelect" + ":compile = >" + tElem.html());
46   -
47   - return {
48   - pre: function(scope, element, attr) {
49   - // TODO:
50   - },
51   - /**
52   - * 相当于link函数。
53   - *
54   - * 重要属性如下:
55   - * model 是绑定外部值。
56   - * dicgroup 字典组的类型
57   - * name input name属性值
58   - */
59   - post: function(scope, element, attr) {
60   - // 1、获取此阶段使用的属性
61   - var $name_attr = attr["name"]; // 表单验证时需要的名字
62   - var $type_attr = attr["type"]; // 关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
63   - var $modelcolname1_attr = attr["modelcolname1"]; // 关联的模型字段名字1(一般应该是编码字段)
64   - var $modelcolname2_attr = attr["modelcolname2"]; // 关联的模型字段名字2(一般应该是名字字段)
65   - var $datacolname1_attr = attr["datacolname1"]; // 内部数据对应的字段名字1(与模型字段1对应)
66   - var $datacolname2_attr = attr["datacolname2"]; // 内部数据对应的字段名字2(与模型字段2对应)
67   - var $showcolname_attr = attr["showcolname"]; // 下拉框显示的内部数据字段名
68   - var $placeholder_attr = attr["placeholder"]; // select placeholder字符串描述
69   -
70   - // 2、处理属性、转换成$saSelectCtrl内部使用的属性
71   - if ($name_attr) {
72   - scope["$saSelectCtrl"].$name_attr = $name_attr;
73   - }
74   - if ($placeholder_attr) {
75   - scope["$saSelectCtrl"].$placeholder_attr = $placeholder_attr;
76   - }
77   - if ($showcolname_attr) {
78   - scope["$saSelectCtrl"].$showcolname_attr = $showcolname_attr;
79   - }
80   -
81   - // 2-1、添加内部方法,根据type值,改变$$data的值
82   - scope["$saSelectCtrl"].$$internal_data_change_fn = function() {
83   - // 根据type属性动态载入数据
84   - if ($type_attr) {
85   - $$searchInfoService_g[$type_attr].list(
86   - {type: "all"},
87   - function(result) {
88   - scope["$saSelectCtrl"].$$data = [];
89   - for (var i = 0; i < result.length; i ++) {
90   - var data = {}; // data是result的一部分属性集合,根据配置来确定
91   - if ($datacolname1_attr) {
92   - data[$datacolname1_attr] = result[i][$datacolname1_attr];
93   - }
94   - if ($datacolname2_attr) {
95   - data[$datacolname2_attr] = result[i][$datacolname2_attr];
96   - }
97   - if ($showcolname_attr) {
98   - // 动态添加基于名字的拼音
99   - data[$showcolname_attr] = result[i][$showcolname_attr];
100   - if (data[$showcolname_attr]) {
101   - data["fullChars"] = pinyin.getFullChars(result[i][$showcolname_attr]).toUpperCase(); // 全拼
102   - data["camelChars"] = pinyin.getCamelChars(result[i][$showcolname_attr]); // 简拼
103   - }
104   - }
105   - if (data["fullChars"])
106   - scope["$saSelectCtrl"].$$data.push(data);
107   - }
108   - },
109   - function(result) {
110   -
111   - }
112   - );
113   - }
114   - };
115   -
116   - // 3、选择、删除事件映射模型和内部数据对应的字段
117   - scope["$saSelectCtrl"].$select_fn_attr = function($item) {
118   - if ($modelcolname1_attr && $datacolname1_attr) {
119   - scope["$saSelectCtrl"].model[$modelcolname1_attr] = $item[$datacolname1_attr];
120   - }
121   - if ($modelcolname2_attr && $datacolname2_attr) {
122   - scope["$saSelectCtrl"].model[$modelcolname2_attr] = $item[$datacolname2_attr];
123   - }
124   - };
125   - scope["$saSelectCtrl"].$remove_fn_attr = function() {
126   - if ($modelcolname1_attr) {
127   - scope["$saSelectCtrl"].model[$modelcolname1_attr] = null;
128   - }
129   - if ($modelcolname2_attr) {
130   - scope["$saSelectCtrl"].model[$modelcolname2_attr] = null;
131   - }
132   - scope["$saSelectCtrl"].$$cmodel = null; // 内部模型清空
133   -
134   - scope["$saSelectCtrl"].$$internal_data_change_fn();
135   - };
136   -
137   - // 4、搜索事件
138   - scope["$saSelectCtrl"].$refreshdata_fn_attr = function($search) {
139   - //var fullChars = pinyin.getFullChars($search).toUpperCase();
140   - //var camelChars = pinyin.getCamelChars($search);
141   - //
142   - //console.log(fullChars + " " + camelChars);
143   - // TODO:事件暂时没用,放着以后再说
144   - };
145   -
146   - // 5、全部载入后,输入的
147   - $timeout(function() {
148   - // 创建内部使用的绑定对象,用于确认选中那个值
149   - scope["$saSelectCtrl"].$$cmodel = scope["$saSelectCtrl"].model[$modelcolname1_attr];
150   -
151   - scope["$saSelectCtrl"].$$internal_data_change_fn();
152   - }, 0);
153   - }
154   - }
155   - }
156   - };
157   - }
158   -]);
159   -
  1 +
  2 +
  3 +angular.module('ScheduleApp').directive("saSelect2", [
  4 + '$timeout', '$$SearchInfoService_g',
  5 + function($timeout, $$searchInfoService_g) {
  6 + return {
  7 + restrict: 'E',
  8 + templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect2Template.html',
  9 + scope: {
  10 + model: "=" // 独立作用域,关联外部的模型对象
  11 + },
  12 + controllerAs: "$saSelectCtrl",
  13 + bindToController: true,
  14 + controller: function($scope) {
  15 + var self = this;
  16 + self.$$data = []; // 内部关联的数据
  17 + },
  18 + /**
  19 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  20 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  21 + * @param tElem
  22 + * @param tAttrs
  23 + * @returns {{pre: Function, post: Function}}
  24 + */
  25 + compile: function(tElem, tAttrs) {
  26 + // 1、获取此阶段使用的属性
  27 + var $required_attr = tAttrs["required"]; // 用于和表单验证连接,指定成required="true"才有效。
  28 +
  29 + // 2、处理属性
  30 +
  31 + // 确定是否使用angularjs required验证
  32 + // 属性 required
  33 + // 如果没有填写,内部不添加验证,如果填写了,并且等于true添加验证,否则不添加
  34 + if ($required_attr) {
  35 + if ($required_attr == "true") {
  36 + // 添加required属性指令
  37 + tElem.find("ui-select").attr("required", "");
  38 + } else {
  39 + // 不等于true,不添加required属性指令
  40 + }
  41 + } else {
  42 + // 不添加required属性指令
  43 + }
  44 +
  45 + //console.log("saSelect" + ":compile = >" + tElem.html());
  46 +
  47 + return {
  48 + pre: function(scope, element, attr) {
  49 + // TODO:
  50 + },
  51 + /**
  52 + * 相当于link函数。
  53 + *
  54 + * 重要属性如下:
  55 + * model 是绑定外部值。
  56 + * dicgroup 字典组的类型
  57 + * name input name属性值
  58 + */
  59 + post: function(scope, element, attr) {
  60 + // 1、获取此阶段使用的属性
  61 + var $name_attr = attr["name"]; // 表单验证时需要的名字
  62 + var $type_attr = attr["type"]; // 关联的那种数据值(xl/cl/ry)-> 对应线路信息/车辆信息/人员信息,后面有的继续加
  63 + var $modelcolname1_attr = attr["modelcolname1"]; // 关联的模型字段名字1(一般应该是编码字段)
  64 + var $modelcolname2_attr = attr["modelcolname2"]; // 关联的模型字段名字2(一般应该是名字字段)
  65 + var $datacolname1_attr = attr["datacolname1"]; // 内部数据对应的字段名字1(与模型字段1对应)
  66 + var $datacolname2_attr = attr["datacolname2"]; // 内部数据对应的字段名字2(与模型字段2对应)
  67 + var $showcolname_attr = attr["showcolname"]; // 下拉框显示的内部数据字段名
  68 + var $placeholder_attr = attr["placeholder"]; // select placeholder字符串描述
  69 +
  70 + // 2、处理属性、转换成$saSelectCtrl内部使用的属性
  71 + if ($name_attr) {
  72 + scope["$saSelectCtrl"].$name_attr = $name_attr;
  73 + }
  74 + if ($placeholder_attr) {
  75 + scope["$saSelectCtrl"].$placeholder_attr = $placeholder_attr;
  76 + }
  77 + if ($showcolname_attr) {
  78 + scope["$saSelectCtrl"].$showcolname_attr = $showcolname_attr;
  79 + }
  80 +
  81 + // 2-1、添加内部方法,根据type值,改变$$data的值
  82 + scope["$saSelectCtrl"].$$internal_data_change_fn = function() {
  83 + // 根据type属性动态载入数据
  84 + if ($type_attr) {
  85 + $$searchInfoService_g[$type_attr].list(
  86 + {type: "all"},
  87 + function(result) {
  88 + scope["$saSelectCtrl"].$$data = [];
  89 + for (var i = 0; i < result.length; i ++) {
  90 + var data = {}; // data是result的一部分属性集合,根据配置来确定
  91 + if ($datacolname1_attr) {
  92 + data[$datacolname1_attr] = result[i][$datacolname1_attr];
  93 + }
  94 + if ($datacolname2_attr) {
  95 + data[$datacolname2_attr] = result[i][$datacolname2_attr];
  96 + }
  97 + if ($showcolname_attr) {
  98 + // 动态添加基于名字的拼音
  99 + data[$showcolname_attr] = result[i][$showcolname_attr];
  100 + if (data[$showcolname_attr]) {
  101 + data["fullChars"] = pinyin.getFullChars(result[i][$showcolname_attr]).toUpperCase(); // 全拼
  102 + data["camelChars"] = pinyin.getCamelChars(result[i][$showcolname_attr]); // 简拼
  103 + }
  104 + }
  105 + if (data["fullChars"])
  106 + scope["$saSelectCtrl"].$$data.push(data);
  107 + }
  108 + },
  109 + function(result) {
  110 +
  111 + }
  112 + );
  113 + }
  114 + };
  115 +
  116 + // 3、选择、删除事件映射模型和内部数据对应的字段
  117 + scope["$saSelectCtrl"].$select_fn_attr = function($item) {
  118 + if ($modelcolname1_attr && $datacolname1_attr) {
  119 + scope["$saSelectCtrl"].model[$modelcolname1_attr] = $item[$datacolname1_attr];
  120 + }
  121 + if ($modelcolname2_attr && $datacolname2_attr) {
  122 + scope["$saSelectCtrl"].model[$modelcolname2_attr] = $item[$datacolname2_attr];
  123 + }
  124 + };
  125 + scope["$saSelectCtrl"].$remove_fn_attr = function() {
  126 + if ($modelcolname1_attr) {
  127 + scope["$saSelectCtrl"].model[$modelcolname1_attr] = null;
  128 + }
  129 + if ($modelcolname2_attr) {
  130 + scope["$saSelectCtrl"].model[$modelcolname2_attr] = null;
  131 + }
  132 + scope["$saSelectCtrl"].$$cmodel = null; // 内部模型清空
  133 +
  134 + scope["$saSelectCtrl"].$$internal_data_change_fn();
  135 + };
  136 +
  137 + // 4、搜索事件
  138 + scope["$saSelectCtrl"].$refreshdata_fn_attr = function($search) {
  139 + //var fullChars = pinyin.getFullChars($search).toUpperCase();
  140 + //var camelChars = pinyin.getCamelChars($search);
  141 + //
  142 + //console.log(fullChars + " " + camelChars);
  143 + // TODO:事件暂时没用,放着以后再说
  144 + };
  145 +
  146 + // 5、全部载入后,输入的
  147 + $timeout(function() {
  148 + // 创建内部使用的绑定对象,用于确认选中那个值
  149 + scope["$saSelectCtrl"].$$cmodel = scope["$saSelectCtrl"].model[$modelcolname1_attr];
  150 +
  151 + scope["$saSelectCtrl"].$$internal_data_change_fn();
  152 + }, 0);
  153 + }
  154 + }
  155 + }
  156 + };
  157 + }
  158 +]);
  159 +
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/select/saSelect3.js
1   -
2   -
3   -
4   -/**
5   - * saSelect3指令
6   - * 属性如下:
7   - * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
8   - * name(必须):控件的名字
9   - * placeholder(可选):占位符字符串
10   - * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
11   - * dcname(必须):绑定的model字段名,如:dcname=xl.id
12   - * icname(必须):内部与之对应的字段名,如:icname=code
13   - * dcname2(可选):其他需要赋值的model字段名2,如:dcname2=xl.name
14   - * icname2(可选):内部与之对应的字段名2,如:icname2=name
15   - * dcname3(可选):其他需要赋值的model字段名3,如:dcname2=xl.name
16   - * icname3(可选):内部与之对应的字段名3,如:icname2=name
17   - * icnames(必须):用于用于显示,以及简评处理的内部数据字段,如:icnames=name
18   - * required(可选):是否要用required验证
19   - * datatype(必须):业务数据类型,有字典类型,动态数据类型,暂时写的死点
20   - * mlp(可选):是否多级属性(这里假设外部model如果多级,内部model也是多级)
21   - *
22   - * 高级属性:
23   - * dataassociate(可选):数据源是否关联属性(内部数据随外部指定的参数变化而变化)
24   - * dataparam(可选):数据源关联的外部参数对象
25   - *
26   - */
27   -angular.module('ScheduleApp').directive("saSelect3", [
28   - '$timeout',
29   - '$$SearchInfoService_g',
30   - function($timeout, $$searchInfoService_g) {
31   - return {
32   - restrict: 'E',
33   - templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect3Template.html',
34   - scope: {
35   - model: "=" // 独立作用域,关联外部的模型object
36   - },
37   - controllerAs: "$saSelectCtrl",
38   - bindToController: true,
39   - controller: function($scope) {
40   - var self = this;
41   - self.$$data = []; // ui-select显示用的数据源
42   - self.$$data_real= []; // 内部真实的数据源
43   - },
44   -
45   - /**
46   - * 此阶段可以改dom结构,此时angular还没扫描指令,
47   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
48   - * @param tElem
49   - * @param tAttrs
50   - * @returns {{pre: Function, post: Function}}
51   - */
52   - compile: function(tElem, tAttrs) {
53   - // 获取所有的属性
54   - var $name_attr = tAttrs["name"]; // 控件的名字
55   - var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字
56   - var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
57   - var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
58   - var $dcname2_attr = tAttrs["dcname2"]; // 其他需要赋值的model字段名2
59   - var $icname2_attr = tAttrs["icname2"]; // 内部与之对应的字段名2
60   - var $dcname3_attr = tAttrs["dcname3"]; // 其他需要赋值的model字段名3
61   - var $icname3_attr = tAttrs["icname3"]; // 内部与之对应的字段名3
62   -
63   - var $icname_s_attr = tAttrs["icnames"]; // 用于用于显示,以及简评处理的内部数据字段
64   - var $datatype_attr = tAttrs["datatype"]; // 内部业务数据类型
65   - var $required_attr = tAttrs["required"]; // 是否需要required验证
66   - var $mlp_attr = tAttrs["mlp"]; // 是否多级属性
67   - var $dataassociate_attr = tAttrs["dataassociate"]; // 数据源是否关联属性
68   -
69   - // controlAs名字
70   - var ctrlAs = "$saSelectCtrl";
71   -
72   - // 数据源初始化标志
73   - var $$data_init = false;
74   - // 如果有required属性,添加angularjs required验证
75   - if ($required_attr != undefined) {
76   - tElem.find("ui-select").attr("required", "");
77   - }
78   -
79   - // 由于有的属性是多级的如xl.name,所以要在compile阶段重写属性绑定属性定义
80   - // 原来的设置:{{$select.selected[$saSelectCtrl.$icname_s]}}
81   - tElem.find("ui-select-match").html("{{$select.selected" + "." + $icname_s_attr + "}}");
82   - // 原来的设置:item[$saSelectCtrl.$icname] as item in $saSelectCtrl.$$data
83   - tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
84   - // 原来的设置:item[$saSelectCtrl.$icname_s]
85   - tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $icname_s_attr);
86   - // 原来的设置:{{$saSelectCtrl.$name}}
87   - tElem.find("ui-select").attr("name", $name_attr);
88   - // 原来的设置:{{$saSelectCtrl.$placeholder}}
89   - tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);
90   -
91   - return {
92   - pre: function(scope, element, attr) {
93   - // TODO:
94   - },
95   - /**
96   - * 相当于link函数。
97   - * @param scope
98   - * @param element
99   - * @param attr
100   - */
101   - post: function(scope, element, attr) {
102   - // 添加选中事件处理函数
103   - scope[ctrlAs].$$internal_select_fn = function($item) {
104   - if ($dcname_attr && $icname_attr) {
105   - if ($mlp_attr) {
106   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
107   - } else {
108   - scope[ctrlAs].model[$dcname_attr] = $item[$icname_attr];
109   - }
110   - }
111   - if ($dcname2_attr && $icname2_attr) {
112   - if ($mlp_attr) {
113   - eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = $item" + "." + $icname2_attr + ";");
114   - } else {
115   - scope[ctrlAs].model[$dcname2_attr] = $item[$icname2_attr];
116   - }
117   - }
118   - if ($dcname3_attr && $icname3_attr) {
119   - if ($mlp_attr) {
120   - eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = $item" + "." + $icname3_attr + ";");
121   - } else {
122   - scope[ctrlAs].model[$dcname3_attr] = $item[$icname3_attr];
123   - }
124   - }
125   - };
126   -
127   - // 删除选中事件处理函数
128   - scope[ctrlAs].$$internal_remove_fn = function() {
129   - scope[ctrlAs].$$internalmodel = undefined;
130   - if ($mlp_attr) {
131   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
132   - } else {
133   - scope[ctrlAs].model[$dcname_attr] = undefined;
134   - }
135   -
136   - if ($dcname2_attr) {
137   - if ($mlp_attr) {
138   - eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = undefined;");
139   - } else {
140   - scope[ctrlAs].model[$dcname2_attr] = undefined;
141   - }
142   - }
143   - if ($dcname3_attr) {
144   - if ($mlp_attr) {
145   - eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = undefined;");
146   - } else {
147   - scope[ctrlAs].model[$dcname3_attr] = undefined;
148   - }
149   - }
150   - };
151   -
152   - /**
153   - * 内部方法,读取字典数据作为数据源。
154   - * @param dicgroup 字典类型,如:gsType
155   - * @param ccol 代码字段名
156   - * @param ncol 名字字段名
157   - */
158   - scope[ctrlAs].$$internal_dic_data = function(dicgroup, ccol, ncol) {
159   - var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
160   - var dic_key; // 字典key
161   - // 清空内部数据
162   - scope[ctrlAs].$$data_real = [];
163   - for (dic_key in origin_dicgroup) {
164   - var data = {}; // 重新组合的字典元素对象
165   - if (dic_key == "true")
166   - data[ccol] = true;
167   - else
168   - data[ccol] = dic_key;
169   - data[ncol] = origin_dicgroup[dic_key];
170   - scope[ctrlAs].$$data_real.push(data);
171   - }
172   - // 这里直接将$$data_real数据深拷贝到$$data
173   - angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);
174   -
175   - console.log(scope[ctrlAs].$$data);
176   - };
177   -
178   - /**
179   - * TODO:这个方法有性能问题,result一多就会卡一卡,之后再解决把
180   - * 内部方法,读取字典数据作为数据源。
181   - * @param result 原始数据
182   - * @param dcvalue 传入的关联数据
183   - */
184   - scope[ctrlAs].$$internal_other_data = function(result, dcvalue) {
185   - console.log("start=" + dcvalue);
186   - // 清空内部数据
187   - scope[ctrlAs].$$data_real = [];
188   - scope[ctrlAs].$$data = [];
189   - for (var i = 0; i < result.length; i ++) {
190   - if ($icname_s_attr) {
191   - if ($mlp_attr) {
192   - if (eval("result[i]" + "." + $icname_s_attr)) {
193   - // 全拼
194   - result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $icname_s_attr)).toUpperCase();
195   - // 简拼
196   - result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $icname_s_attr));
197   - }
198   - } else {
199   - if (result[i][$icname_s_attr]) {
200   - // 全拼
201   - result[i]["fullChars"] = pinyin.getFullChars(result[i][$icname_s_attr]).toUpperCase();
202   - // 简拼
203   - result[i]["camelChars"] = pinyin.getCamelChars(result[i][$icname_s_attr]);
204   - }
205   - }
206   - }
207   -
208   - if (result[i]["fullChars"]) { // 有拼音的加入数据源
209   - scope[ctrlAs].$$data_real.push(result[i]);
210   - }
211   -
212   - }
213   - //console.log("start2");
214   -
215   - // 数量太大取前10条记录作为显示
216   - if (angular.isArray(scope[ctrlAs].$$data_real)) {
217   - // 先迭代循环查找已经传过来的值
218   - if (scope[ctrlAs].$$data_real.length > 0) {
219   - if (dcvalue) {
220   - for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
221   - if (scope[ctrlAs].$$data_real[j][$icname_attr] == dcvalue) {
222   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[j]));
223   - break;
224   - }
225   - }
226   - }
227   - }
228   - // 在插入剩余的数据
229   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
230   - if (scope[ctrlAs].$$data.length < 10) {
231   - if ($mlp_attr) {
232   - if (eval("scope[ctrlAs].$$data_real[k]" + "." + $icname_attr + " != dcvalue")) {
233   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
234   - }
235   - } else {
236   - if (scope[ctrlAs].$$data_real[k][$icname_attr] != dcvalue) {
237   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
238   - }
239   - }
240   - } else {
241   - break;
242   - }
243   - }
244   - }
245   -
246   - //console.log("end");
247   - };
248   -
249   - /**
250   - * 判定一个对象是否为空对象。
251   - * @param Obj
252   - */
253   - scope[ctrlAs].$$internal_isEmpty_obj = function(obj) {
254   - console.log(typeof obj);
255   -
256   - if (typeof obj === "object" && !(obj instanceof Array)) {
257   - for (var prop in obj) {
258   - if (obj.hasOwnProperty(prop)) {
259   - return false;
260   - }
261   - }
262   - return true;
263   - } else {
264   - throw "必须是对象";
265   - }
266   - };
267   -
268   - // 刷新数据
269   - scope[ctrlAs].$$internal_refresh_fn = function(search) {
270   - // 绑定的model字段值,此属性是绑定属性,只能在link阶段获取
271   - var $dcvalue_attr = attr["dcvalue"];
272   -
273   - console.log("刷新数据:" + $dcvalue_attr);
274   -
275   - if (!$$data_init) { // 只初始化$$data_real一次,重新载入页面才能重新初始化
276   - if (dictionaryUtils.getByGroup($datatype_attr)) { // 判定是否字典类型数据源
277   - scope[ctrlAs].$$internal_dic_data(
278   - $datatype_attr, $icname_attr, $icname_s_attr);
279   - if ($dcvalue_attr) {
280   - scope[ctrlAs].$$internalmodel = $dcvalue_attr;
281   - }
282   - } else { // 非字典类型数据源
283   - if (!$dataassociate_attr) {
284   - $$searchInfoService_g[$datatype_attr].list(
285   - {type: "all"},
286   - function(result) {
287   - //console.log("ok:" + $datatype_attr);
288   - scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
289   - //console.log("ok2:" + $datatype_attr);
290   - if ($dcvalue_attr) {
291   - scope[ctrlAs].$$internalmodel = $dcvalue_attr;
292   - }
293   -
294   - $$data_init = true;
295   - },
296   - function(result) {
297   -
298   - }
299   - );
300   - }
301   - }
302   - }
303   -
304   - if ($$data_init) {
305   - if (search && search != "") { // 有search值
306   - if (!dictionaryUtils.getByGroup($datatype_attr)) { // 其他数据源
307   - // 处理search
308   - console.log("search:" + search);
309   -
310   - scope[ctrlAs].$$data = [];
311   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
312   - var upTerm = search.toUpperCase();
313   - if (scope[ctrlAs].$$data.length < 10) {
314   - if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
315   - || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
316   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
317   - }
318   - } else {
319   - break;
320   - }
321   - }
322   - }
323   - }
324   -
325   - }
326   -
327   - };
328   -
329   -
330   -
331   -
332   -
333   -
334   -
335   -
336   -
337   -
338   - // TODO:
339   -
340   - // dom全部载入后调用
341   - $timeout(function() {
342   - console.log("dom全部载入后调用");
343   - }, 0);
344   - // 监控dcvalue model值变换
345   - attr.$observe("dcvalue", function(value) {
346   - console.log("监控dc1 model值变换:" + value);
347   - scope[ctrlAs].$$internalmodel = value;
348   - }
349   - );
350   - // 监控获取数据参数变换
351   - attr.$observe("dataparam", function(value) {
352   - // 判定是否空对象
353   - console.log(value);
354   - var obj = JSON.parse(value);
355   - var $dcvalue_attr = attr["dcvalue"];
356   - if (!scope[ctrlAs].$$internal_isEmpty_obj(obj)) {
357   - console.log("dataparam:" + obj);
358   -
359   - //
360   -
361   - obj["type"] = "all";
362   -
363   - $$data_init = false;
364   - $$searchInfoService_g[$datatype_attr].list(
365   - obj,
366   - function(result) {
367   - //console.log("ok:" + $datatype_attr);
368   - scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
369   - //console.log("ok2:" + $datatype_attr);
370   - if ($dcvalue_attr) {
371   - scope[ctrlAs].$$internalmodel = $dcvalue_attr;
372   - }
373   -
374   - $$data_init = true;
375   - },
376   - function(result) {
377   -
378   - }
379   - );
380   - }
381   - }
382   - );
383   - }
384   - };
385   - }
386   - };
387   -
388   - }
389   -]);
390   -
  1 +
  2 +
  3 +
  4 +/**
  5 + * saSelect3指令
  6 + * 属性如下:
  7 + * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
  8 + * name(必须):控件的名字
  9 + * placeholder(可选):占位符字符串
  10 + * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
  11 + * dcname(必须):绑定的model字段名,如:dcname=xl.id
  12 + * icname(必须):内部与之对应的字段名,如:icname=code
  13 + * dcname2(可选):其他需要赋值的model字段名2,如:dcname2=xl.name
  14 + * icname2(可选):内部与之对应的字段名2,如:icname2=name
  15 + * dcname3(可选):其他需要赋值的model字段名3,如:dcname2=xl.name
  16 + * icname3(可选):内部与之对应的字段名3,如:icname2=name
  17 + * icnames(必须):用于用于显示,以及简评处理的内部数据字段,如:icnames=name
  18 + * required(可选):是否要用required验证
  19 + * datatype(必须):业务数据类型,有字典类型,动态数据类型,暂时写的死点
  20 + * mlp(可选):是否多级属性(这里假设外部model如果多级,内部model也是多级)
  21 + *
  22 + * 高级属性:
  23 + * dataassociate(可选):数据源是否关联属性(内部数据随外部指定的参数变化而变化)
  24 + * dataparam(可选):数据源关联的外部参数对象
  25 + *
  26 + */
  27 +angular.module('ScheduleApp').directive("saSelect3", [
  28 + '$timeout',
  29 + '$$SearchInfoService_g',
  30 + function($timeout, $$searchInfoService_g) {
  31 + return {
  32 + restrict: 'E',
  33 + templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect3Template.html',
  34 + scope: {
  35 + model: "=" // 独立作用域,关联外部的模型object
  36 + },
  37 + controllerAs: "$saSelectCtrl",
  38 + bindToController: true,
  39 + controller: function($scope) {
  40 + var self = this;
  41 + self.$$data = []; // ui-select显示用的数据源
  42 + self.$$data_real= []; // 内部真实的数据源
  43 + },
  44 +
  45 + /**
  46 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  47 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  48 + * @param tElem
  49 + * @param tAttrs
  50 + * @returns {{pre: Function, post: Function}}
  51 + */
  52 + compile: function(tElem, tAttrs) {
  53 + // 获取所有的属性
  54 + var $name_attr = tAttrs["name"]; // 控件的名字
  55 + var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字
  56 + var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
  57 + var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
  58 + var $dcname2_attr = tAttrs["dcname2"]; // 其他需要赋值的model字段名2
  59 + var $icname2_attr = tAttrs["icname2"]; // 内部与之对应的字段名2
  60 + var $dcname3_attr = tAttrs["dcname3"]; // 其他需要赋值的model字段名3
  61 + var $icname3_attr = tAttrs["icname3"]; // 内部与之对应的字段名3
  62 +
  63 + var $icname_s_attr = tAttrs["icnames"]; // 用于用于显示,以及简评处理的内部数据字段
  64 + var $datatype_attr = tAttrs["datatype"]; // 内部业务数据类型
  65 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  66 + var $mlp_attr = tAttrs["mlp"]; // 是否多级属性
  67 + var $dataassociate_attr = tAttrs["dataassociate"]; // 数据源是否关联属性
  68 +
  69 + // controlAs名字
  70 + var ctrlAs = "$saSelectCtrl";
  71 +
  72 + // 数据源初始化标志
  73 + var $$data_init = false;
  74 + // 如果有required属性,添加angularjs required验证
  75 + if ($required_attr != undefined) {
  76 + tElem.find("ui-select").attr("required", "");
  77 + }
  78 +
  79 + // 由于有的属性是多级的如xl.name,所以要在compile阶段重写属性绑定属性定义
  80 + // 原来的设置:{{$select.selected[$saSelectCtrl.$icname_s]}}
  81 + tElem.find("ui-select-match").html("{{$select.selected" + "." + $icname_s_attr + "}}");
  82 + // 原来的设置:item[$saSelectCtrl.$icname] as item in $saSelectCtrl.$$data
  83 + tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
  84 + // 原来的设置:item[$saSelectCtrl.$icname_s]
  85 + tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $icname_s_attr);
  86 + // 原来的设置:{{$saSelectCtrl.$name}}
  87 + tElem.find("ui-select").attr("name", $name_attr);
  88 + // 原来的设置:{{$saSelectCtrl.$placeholder}}
  89 + tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);
  90 +
  91 + return {
  92 + pre: function(scope, element, attr) {
  93 + // TODO:
  94 + },
  95 + /**
  96 + * 相当于link函数。
  97 + * @param scope
  98 + * @param element
  99 + * @param attr
  100 + */
  101 + post: function(scope, element, attr) {
  102 + // 添加选中事件处理函数
  103 + scope[ctrlAs].$$internal_select_fn = function($item) {
  104 + if ($dcname_attr && $icname_attr) {
  105 + if ($mlp_attr) {
  106 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
  107 + } else {
  108 + scope[ctrlAs].model[$dcname_attr] = $item[$icname_attr];
  109 + }
  110 + }
  111 + if ($dcname2_attr && $icname2_attr) {
  112 + if ($mlp_attr) {
  113 + eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = $item" + "." + $icname2_attr + ";");
  114 + } else {
  115 + scope[ctrlAs].model[$dcname2_attr] = $item[$icname2_attr];
  116 + }
  117 + }
  118 + if ($dcname3_attr && $icname3_attr) {
  119 + if ($mlp_attr) {
  120 + eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = $item" + "." + $icname3_attr + ";");
  121 + } else {
  122 + scope[ctrlAs].model[$dcname3_attr] = $item[$icname3_attr];
  123 + }
  124 + }
  125 + };
  126 +
  127 + // 删除选中事件处理函数
  128 + scope[ctrlAs].$$internal_remove_fn = function() {
  129 + scope[ctrlAs].$$internalmodel = undefined;
  130 + if ($mlp_attr) {
  131 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
  132 + } else {
  133 + scope[ctrlAs].model[$dcname_attr] = undefined;
  134 + }
  135 +
  136 + if ($dcname2_attr) {
  137 + if ($mlp_attr) {
  138 + eval("scope[ctrlAs].model" + "." + $dcname2_attr + " = undefined;");
  139 + } else {
  140 + scope[ctrlAs].model[$dcname2_attr] = undefined;
  141 + }
  142 + }
  143 + if ($dcname3_attr) {
  144 + if ($mlp_attr) {
  145 + eval("scope[ctrlAs].model" + "." + $dcname3_attr + " = undefined;");
  146 + } else {
  147 + scope[ctrlAs].model[$dcname3_attr] = undefined;
  148 + }
  149 + }
  150 + };
  151 +
  152 + /**
  153 + * 内部方法,读取字典数据作为数据源。
  154 + * @param dicgroup 字典类型,如:gsType
  155 + * @param ccol 代码字段名
  156 + * @param ncol 名字字段名
  157 + */
  158 + scope[ctrlAs].$$internal_dic_data = function(dicgroup, ccol, ncol) {
  159 + var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
  160 + var dic_key; // 字典key
  161 + // 清空内部数据
  162 + scope[ctrlAs].$$data_real = [];
  163 + for (dic_key in origin_dicgroup) {
  164 + var data = {}; // 重新组合的字典元素对象
  165 + if (dic_key == "true")
  166 + data[ccol] = true;
  167 + else
  168 + data[ccol] = dic_key;
  169 + data[ncol] = origin_dicgroup[dic_key];
  170 + scope[ctrlAs].$$data_real.push(data);
  171 + }
  172 + // 这里直接将$$data_real数据深拷贝到$$data
  173 + angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);
  174 +
  175 + console.log(scope[ctrlAs].$$data);
  176 + };
  177 +
  178 + /**
  179 + * TODO:这个方法有性能问题,result一多就会卡一卡,之后再解决把
  180 + * 内部方法,读取字典数据作为数据源。
  181 + * @param result 原始数据
  182 + * @param dcvalue 传入的关联数据
  183 + */
  184 + scope[ctrlAs].$$internal_other_data = function(result, dcvalue) {
  185 + console.log("start=" + dcvalue);
  186 + // 清空内部数据
  187 + scope[ctrlAs].$$data_real = [];
  188 + scope[ctrlAs].$$data = [];
  189 + for (var i = 0; i < result.length; i ++) {
  190 + if ($icname_s_attr) {
  191 + if ($mlp_attr) {
  192 + if (eval("result[i]" + "." + $icname_s_attr)) {
  193 + // 全拼
  194 + result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $icname_s_attr)).toUpperCase();
  195 + // 简拼
  196 + result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $icname_s_attr));
  197 + }
  198 + } else {
  199 + if (result[i][$icname_s_attr]) {
  200 + // 全拼
  201 + result[i]["fullChars"] = pinyin.getFullChars(result[i][$icname_s_attr]).toUpperCase();
  202 + // 简拼
  203 + result[i]["camelChars"] = pinyin.getCamelChars(result[i][$icname_s_attr]);
  204 + }
  205 + }
  206 + }
  207 +
  208 + if (result[i]["fullChars"]) { // 有拼音的加入数据源
  209 + scope[ctrlAs].$$data_real.push(result[i]);
  210 + }
  211 +
  212 + }
  213 + //console.log("start2");
  214 +
  215 + // 数量太大取前10条记录作为显示
  216 + if (angular.isArray(scope[ctrlAs].$$data_real)) {
  217 + // 先迭代循环查找已经传过来的值
  218 + if (scope[ctrlAs].$$data_real.length > 0) {
  219 + if (dcvalue) {
  220 + for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
  221 + if (scope[ctrlAs].$$data_real[j][$icname_attr] == dcvalue) {
  222 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[j]));
  223 + break;
  224 + }
  225 + }
  226 + }
  227 + }
  228 + // 在插入剩余的数据
  229 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  230 + if (scope[ctrlAs].$$data.length < 10) {
  231 + if ($mlp_attr) {
  232 + if (eval("scope[ctrlAs].$$data_real[k]" + "." + $icname_attr + " != dcvalue")) {
  233 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  234 + }
  235 + } else {
  236 + if (scope[ctrlAs].$$data_real[k][$icname_attr] != dcvalue) {
  237 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  238 + }
  239 + }
  240 + } else {
  241 + break;
  242 + }
  243 + }
  244 + }
  245 +
  246 + //console.log("end");
  247 + };
  248 +
  249 + /**
  250 + * 判定一个对象是否为空对象。
  251 + * @param Obj
  252 + */
  253 + scope[ctrlAs].$$internal_isEmpty_obj = function(obj) {
  254 + console.log(typeof obj);
  255 +
  256 + if (typeof obj === "object" && !(obj instanceof Array)) {
  257 + for (var prop in obj) {
  258 + if (obj.hasOwnProperty(prop)) {
  259 + return false;
  260 + }
  261 + }
  262 + return true;
  263 + } else {
  264 + throw "必须是对象";
  265 + }
  266 + };
  267 +
  268 + // 刷新数据
  269 + scope[ctrlAs].$$internal_refresh_fn = function(search) {
  270 + // 绑定的model字段值,此属性是绑定属性,只能在link阶段获取
  271 + var $dcvalue_attr = attr["dcvalue"];
  272 +
  273 + console.log("刷新数据:" + $dcvalue_attr);
  274 +
  275 + if (!$$data_init) { // 只初始化$$data_real一次,重新载入页面才能重新初始化
  276 + if (dictionaryUtils.getByGroup($datatype_attr)) { // 判定是否字典类型数据源
  277 + scope[ctrlAs].$$internal_dic_data(
  278 + $datatype_attr, $icname_attr, $icname_s_attr);
  279 + if ($dcvalue_attr) {
  280 + scope[ctrlAs].$$internalmodel = $dcvalue_attr;
  281 + }
  282 + } else { // 非字典类型数据源
  283 + if (!$dataassociate_attr) {
  284 + $$searchInfoService_g[$datatype_attr].list(
  285 + {type: "all"},
  286 + function(result) {
  287 + //console.log("ok:" + $datatype_attr);
  288 + scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
  289 + //console.log("ok2:" + $datatype_attr);
  290 + if ($dcvalue_attr) {
  291 + scope[ctrlAs].$$internalmodel = $dcvalue_attr;
  292 + }
  293 +
  294 + $$data_init = true;
  295 + },
  296 + function(result) {
  297 +
  298 + }
  299 + );
  300 + }
  301 + }
  302 + }
  303 +
  304 + if ($$data_init) {
  305 + if (search && search != "") { // 有search值
  306 + if (!dictionaryUtils.getByGroup($datatype_attr)) { // 其他数据源
  307 + // 处理search
  308 + console.log("search:" + search);
  309 +
  310 + scope[ctrlAs].$$data = [];
  311 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  312 + var upTerm = search.toUpperCase();
  313 + if (scope[ctrlAs].$$data.length < 10) {
  314 + if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
  315 + || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
  316 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  317 + }
  318 + } else {
  319 + break;
  320 + }
  321 + }
  322 + }
  323 + }
  324 +
  325 + }
  326 +
  327 + };
  328 +
  329 +
  330 +
  331 +
  332 +
  333 +
  334 +
  335 +
  336 +
  337 +
  338 + // TODO:
  339 +
  340 + // dom全部载入后调用
  341 + $timeout(function() {
  342 + console.log("dom全部载入后调用");
  343 + }, 0);
  344 + // 监控dcvalue model值变换
  345 + attr.$observe("dcvalue", function(value) {
  346 + console.log("监控dc1 model值变换:" + value);
  347 + scope[ctrlAs].$$internalmodel = value;
  348 + }
  349 + );
  350 + // 监控获取数据参数变换
  351 + attr.$observe("dataparam", function(value) {
  352 + // 判定是否空对象
  353 + console.log(value);
  354 + var obj = JSON.parse(value);
  355 + var $dcvalue_attr = attr["dcvalue"];
  356 + if (!scope[ctrlAs].$$internal_isEmpty_obj(obj)) {
  357 + console.log("dataparam:" + obj);
  358 +
  359 + //
  360 +
  361 + obj["type"] = "all";
  362 +
  363 + $$data_init = false;
  364 + $$searchInfoService_g[$datatype_attr].list(
  365 + obj,
  366 + function(result) {
  367 + //console.log("ok:" + $datatype_attr);
  368 + scope[ctrlAs].$$internal_other_data(result, $dcvalue_attr);
  369 + //console.log("ok2:" + $datatype_attr);
  370 + if ($dcvalue_attr) {
  371 + scope[ctrlAs].$$internalmodel = $dcvalue_attr;
  372 + }
  373 +
  374 + $$data_init = true;
  375 + },
  376 + function(result) {
  377 +
  378 + }
  379 + );
  380 + }
  381 + }
  382 + );
  383 + }
  384 + };
  385 + }
  386 + };
  387 +
  388 + }
  389 +]);
  390 +
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/select/saSelect4.js
1   -/**
2   - * saSelect4指令,封装angular-ui-select控件,并添加相应的业务。
3   - * name(必须):控件的名字
4   - * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
5   - * placeholder(可选):输入框占位符字符串
6   - *
7   - * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
8   - * dcname(必须):绑定的model字段名,如:dcname=xl.id
9   - * icname(必须):内部与之对应的字段名,如:icname=code
10   - *
11   - * cmaps(可选):model其他字段和内部数据字段名映射,如:{{ {'xl.id' : 'id', 'xl.name' : 'name'} | json}}
12   - * dsparams(必须):内部数据源查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
13   - * dscol(必须):内部显示的信息(暂时用内部字段),如:dscol=name
14   - * required(可选):是否要用required验证
15   - */
16   -angular.module('ScheduleApp').directive('saSelect4', [
17   - '$timeout',
18   - '$$SearchInfoService_g',
19   - function($timeout, $$searchInfoService_g) {
20   - return {
21   - restrict: 'E',
22   - templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect4Template.html',
23   - scope: {
24   - model: "=" // 独立作用域,关联外部的模型object
25   - },
26   - controllerAs: "$saSelectCtrl",
27   - bindToController: true,
28   - controller: function($scope) {
29   - var self = this;
30   - self.$$data = []; // ui-select显示用的数据
31   - self.$$data_real = []; // 内部真实的数据
32   -
33   - // saSelect4组件的ng-model,用于外部绑定验证等操作
34   - self.$$internalmodel = undefined;
35   -
36   - self.$$internal_select_value = undefined; // 选中的值
37   - },
38   -
39   - /**
40   - * 此阶段可以改dom结构,此时angular还没扫描指令,
41   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
42   - * @param tElem
43   - * @param tAttrs
44   - * @returns {{pre: Function, post: Function}}
45   - */
46   - compile: function(tElem, tAttrs) {
47   - // 获取属性
48   - var $name_attr = tAttrs["name"]; // 控件的名字
49   - var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字
50   -
51   - var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
52   - var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
53   -
54   - var $cmaps_attr = tAttrs["cmaps"]; // model其他字段和内部数据字段名映射
55   - var $dscol_attr = tAttrs["dscol"]; // 内部显示的信息
56   - var $required_attr = tAttrs["required"]; // 是否需要required验证
57   -
58   - // controlAs名字
59   - var ctrlAs = "$saSelectCtrl";
60   -
61   - // 验证属性
62   - if (!$name_attr) {
63   - throw new error("name属性必须填写");
64   - }
65   - if (!$dcname_attr) {
66   - throw new error("dcname属性必须填写");
67   - }
68   - if (!$icname_attr) {
69   - throw new error("icname属性必须填写");
70   - }
71   - if (!$dscol_attr) {
72   - throw new error("dscol属性必须填写");
73   - }
74   -
75   - // 动态设置dom
76   - // dom required 属性
77   - if ($required_attr != undefined) {
78   - tElem.find("div").attr("required", "");
79   - }
80   - // dom placeholder 属性
81   - tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);
82   - // dom dscol 属性
83   - tElem.find("ui-select-match").html("{{$select.selected" + "." + $dscol_attr + "}}");
84   - tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $dscol_attr);
85   - // dom icname 属性
86   - tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
87   - // dom name 属性
88   - tElem.find("div").attr("name", $name_attr);
89   -
90   - return {
91   - pre: function(scope, element, attr) {
92   - // TODO:
93   - },
94   -
95   - /**
96   - * 相当于link函数。
97   - * @param scope
98   - * @param element
99   - * @param attr
100   - */
101   - post: function(scope, element, attr) {
102   -
103   - // 添加选中事件处理函数
104   - scope[ctrlAs].$$internal_select_fn = function($item) {
105   - if ($dcname_attr && $icname_attr) {
106   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
107   - }
108   -
109   - if ($cmaps_attr) {
110   - for (var mc in $cmaps_attr) { // model的字段名:内部数据源对应字段名
111   - var ic = $cmaps_attr[mc]; // 内部数据源对应字段
112   - eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
113   - }
114   - }
115   - };
116   -
117   - // 删除选中事件处理函数
118   - scope[ctrlAs].$$internal_remove_fn = function() {
119   - scope[ctrlAs].$$internal_select_value = undefined;
120   - if ($dcname_attr) {
121   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
122   - }
123   -
124   - if ($cmaps_attr) {
125   - var mc; // model的字段名
126   - for (mc in $cmaps_attr) {
127   - eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
128   - }
129   - }
130   - scope[ctrlAs].$$internal_validate_model();
131   - };
132   -
133   - // 刷新数据
134   - scope[ctrlAs].$$internal_refresh_fn = function(search) {
135   - if (search && search != "") { // 有search值
136   - // 处理search
137   - console.log("search:" + search);
138   -
139   - scope[ctrlAs].$$data = [];
140   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
141   - var upTerm = search.toUpperCase();
142   - if (scope[ctrlAs].$$data.length < 10) {
143   - if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
144   - || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
145   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
146   - }
147   - } else {
148   - break;
149   - }
150   - }
151   - }
152   - };
153   -
154   - /**
155   - * 验证内部数据,更新外部model
156   - */
157   - scope[ctrlAs].$$internal_validate_model = function() {
158   - if (scope[ctrlAs].$$internal_select_value) {
159   - var select_value_temp = scope[ctrlAs].$$internal_select_value;
160   - if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
161   - var obj;
162   - for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
163   - if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
164   - obj = angular.copy(scope[ctrlAs].$$data_real[j]);
165   - break;
166   - }
167   - }
168   - if (obj) { // 在data中判定有没有
169   - for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
170   - if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
171   - obj = undefined;
172   - break;
173   - }
174   - }
175   - if (obj) {
176   - scope[ctrlAs].$$data.push(obj);
177   - }
178   - // 更新内部model,用于外部验证
179   - // 内部model的值暂时随意,以后再改
180   - scope[ctrlAs].$$internalmodel = {desc: "ok"};
181   - } else {
182   - scope[ctrlAs].$$internalmodel = undefined;
183   - }
184   -
185   - } else {
186   - scope[ctrlAs].$$internalmodel = undefined;
187   - }
188   -
189   - } else {
190   - scope[ctrlAs].$$internalmodel = undefined;
191   - }
192   - };
193   -
194   - /**
195   - * 内部方法,读取字典数据作为数据源。
196   - * @param atype ajax查询类型
197   - * @param ajaxparamobj 查询参数对象
198   - */
199   - scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
200   - ajaxparamobj.type = 'all';
201   - $$searchInfoService_g[atype].list(
202   - ajaxparamobj,
203   - function(result) {
204   - console.log("$$internal_ajax_data result");
205   -
206   - // 清空内部数据
207   - scope[ctrlAs].$$data_real = [];
208   - scope[ctrlAs].$$data = [];
209   -
210   - // result中添加拼音数据,注意:这里要求result返回对象数组
211   - for (var i = 0; i < result.length; i ++) {
212   - if ($dscol_attr) {
213   - if (eval("result[i]" + "." + $dscol_attr)) {
214   - // 全拼
215   - result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $dscol_attr)).toUpperCase();
216   - // 简拼
217   - result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $dscol_attr));
218   - }
219   - }
220   -
221   - if (result[i]["fullChars"]) { // 有拼音的加入数据源
222   - scope[ctrlAs].$$data_real.push(result[i]);
223   - }
224   -
225   - }
226   -
227   - // 数据量太大,取10条记录显示
228   - if (angular.isArray(scope[ctrlAs].$$data_real)) {
229   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
230   - if (scope[ctrlAs].$$data.length < 10) {
231   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
232   - } else {
233   - break;
234   - }
235   - }
236   - }
237   -
238   - scope[ctrlAs].$$internal_validate_model();
239   - },
240   - function(result) {
241   -
242   - }
243   - );
244   - };
245   -
246   - /**
247   - * 内部方法,读取字典数据作为数据源。
248   - * @param dictype 字典类型,如:gsType
249   - */
250   - scope[ctrlAs].$$internal_dic_data = function(dictype) {
251   - if (!dictionaryUtils.getByGroup(dictype)) {
252   - throw new error("字典数据不窜在=" + dictype);
253   - }
254   -
255   - // 清空内部数据
256   - scope[ctrlAs].$$data_real = [];
257   - scope[ctrlAs].$$data = [];
258   -
259   - var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
260   - var dic_key; // 字典key
261   -
262   - for (dic_key in origin_dicgroup) {
263   - var data = {}; // 重新组合的字典元素对象
264   - if (dic_key == "true")
265   - data[$icname_attr] = true;
266   - else
267   - data[$icname_attr] = dic_key;
268   - data[$dscol_attr] = origin_dicgroup[dic_key];
269   - scope[ctrlAs].$$data_real.push(data);
270   - }
271   - // 这里直接将$$data_real数据深拷贝到$$data
272   - angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);
273   - scope[ctrlAs].$$internal_validate_model();
274   - };
275   -
276   - attr.$observe("dsparams", function(value) {
277   - if (value && value != "") {
278   - var obj = JSON.parse(value);
279   - console.log("observe 监控 dsparams=" + obj);
280   -
281   - // dsparams格式如下:
282   - // {type: 'dic/ajax', param: 'dic名字'/'ajax查询参数对象', atype: 'ajax查询类型'}
283   -
284   - if (obj.type == 'dic') {
285   - scope[ctrlAs].$$internal_dic_data(obj.param);
286   -
287   - } else if (obj.type == 'ajax') {
288   - scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
289   - } else {
290   - throw new Error("dsparams参数格式异常=" + obj);
291   - }
292   -
293   - }
294   -
295   - });
296   -
297   - // 监控model绑定的dcvalue值变化
298   - attr.$observe("dcvalue", function(value) {
299   - if (value && value != "") {
300   - console.log("observe 监控 dcvalue=" + value);
301   - scope[ctrlAs].$$internal_select_value = value;
302   - scope[ctrlAs].$$internal_validate_model();
303   - }
304   -
305   - // 闭包测试
306   - var obj = {'a':1,'b':2};
307   - var tfx = scope[ctrlAs].$$test.bind(obj);
308   - console.log("闭包测试=" + tfx());
309   - });
310   -
311   - scope[ctrlAs].$$test = function() {
312   - var exp = "this.a + '(' + this.b + ')'";
313   - console.log("exp=" + exp);
314   - return eval(exp);
315   - };
316   - }
317   - };
318   -
319   - }
320   -
321   - };
322   - }
  1 +/**
  2 + * saSelect4指令,封装angular-ui-select控件,并添加相应的业务。
  3 + * name(必须):控件的名字
  4 + * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
  5 + * placeholder(可选):输入框占位符字符串
  6 + *
  7 + * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
  8 + * dcname(必须):绑定的model字段名,如:dcname=xl.id
  9 + * icname(必须):内部与之对应的字段名,如:icname=code
  10 + *
  11 + * cmaps(可选):model其他字段和内部数据字段名映射,如:{{ {'xl.id' : 'id', 'xl.name' : 'name'} | json}}
  12 + * dsparams(必须):内部数据源查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
  13 + * dscol(必须):内部显示的信息(暂时用内部字段),如:dscol=name
  14 + * required(可选):是否要用required验证
  15 + */
  16 +angular.module('ScheduleApp').directive('saSelect4', [
  17 + '$timeout',
  18 + '$$SearchInfoService_g',
  19 + function($timeout, $$searchInfoService_g) {
  20 + return {
  21 + restrict: 'E',
  22 + templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect4Template.html',
  23 + scope: {
  24 + model: "=" // 独立作用域,关联外部的模型object
  25 + },
  26 + controllerAs: "$saSelectCtrl",
  27 + bindToController: true,
  28 + controller: function($scope) {
  29 + var self = this;
  30 + self.$$data = []; // ui-select显示用的数据
  31 + self.$$data_real = []; // 内部真实的数据
  32 +
  33 + // saSelect4组件的ng-model,用于外部绑定验证等操作
  34 + self.$$internalmodel = undefined;
  35 +
  36 + self.$$internal_select_value = undefined; // 选中的值
  37 + },
  38 +
  39 + /**
  40 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  41 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  42 + * @param tElem
  43 + * @param tAttrs
  44 + * @returns {{pre: Function, post: Function}}
  45 + */
  46 + compile: function(tElem, tAttrs) {
  47 + // 获取属性
  48 + var $name_attr = tAttrs["name"]; // 控件的名字
  49 + var $placeholder_attr = tAttrs["placeholder"]; // 占位符的名字
  50 +
  51 + var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
  52 + var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
  53 +
  54 + var $cmaps_attr = tAttrs["cmaps"]; // model其他字段和内部数据字段名映射
  55 + var $dscol_attr = tAttrs["dscol"]; // 内部显示的信息
  56 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  57 +
  58 + // controlAs名字
  59 + var ctrlAs = "$saSelectCtrl";
  60 +
  61 + // 验证属性
  62 + if (!$name_attr) {
  63 + throw new error("name属性必须填写");
  64 + }
  65 + if (!$dcname_attr) {
  66 + throw new error("dcname属性必须填写");
  67 + }
  68 + if (!$icname_attr) {
  69 + throw new error("icname属性必须填写");
  70 + }
  71 + if (!$dscol_attr) {
  72 + throw new error("dscol属性必须填写");
  73 + }
  74 +
  75 + // 动态设置dom
  76 + // dom required 属性
  77 + if ($required_attr != undefined) {
  78 + tElem.find("div").attr("required", "");
  79 + }
  80 + // dom placeholder 属性
  81 + tElem.find("ui-select-match").attr("placeholder", $placeholder_attr);
  82 + // dom dscol 属性
  83 + tElem.find("ui-select-match").html("{{$select.selected" + "." + $dscol_attr + "}}");
  84 + tElem.find("ui-select-choices span").attr("ng-bind", "item" + "." + $dscol_attr);
  85 + // dom icname 属性
  86 + tElem.find("ui-select-choices").attr("repeat", "item" + "." + $icname_attr + " as item in $saSelectCtrl.$$data");
  87 + // dom name 属性
  88 + tElem.find("div").attr("name", $name_attr);
  89 +
  90 + return {
  91 + pre: function(scope, element, attr) {
  92 + // TODO:
  93 + },
  94 +
  95 + /**
  96 + * 相当于link函数。
  97 + * @param scope
  98 + * @param element
  99 + * @param attr
  100 + */
  101 + post: function(scope, element, attr) {
  102 +
  103 + // 添加选中事件处理函数
  104 + scope[ctrlAs].$$internal_select_fn = function($item) {
  105 + if ($dcname_attr && $icname_attr) {
  106 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
  107 + }
  108 +
  109 + if ($cmaps_attr) {
  110 + for (var mc in $cmaps_attr) { // model的字段名:内部数据源对应字段名
  111 + var ic = $cmaps_attr[mc]; // 内部数据源对应字段
  112 + eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
  113 + }
  114 + }
  115 + };
  116 +
  117 + // 删除选中事件处理函数
  118 + scope[ctrlAs].$$internal_remove_fn = function() {
  119 + scope[ctrlAs].$$internal_select_value = undefined;
  120 + if ($dcname_attr) {
  121 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
  122 + }
  123 +
  124 + if ($cmaps_attr) {
  125 + var mc; // model的字段名
  126 + for (mc in $cmaps_attr) {
  127 + eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
  128 + }
  129 + }
  130 + scope[ctrlAs].$$internal_validate_model();
  131 + };
  132 +
  133 + // 刷新数据
  134 + scope[ctrlAs].$$internal_refresh_fn = function(search) {
  135 + if (search && search != "") { // 有search值
  136 + // 处理search
  137 + console.log("search:" + search);
  138 +
  139 + scope[ctrlAs].$$data = [];
  140 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  141 + var upTerm = search.toUpperCase();
  142 + if (scope[ctrlAs].$$data.length < 10) {
  143 + if (scope[ctrlAs].$$data_real[k].fullChars.indexOf(upTerm) != -1
  144 + || scope[ctrlAs].$$data_real[k].camelChars.indexOf(upTerm) != -1) {
  145 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  146 + }
  147 + } else {
  148 + break;
  149 + }
  150 + }
  151 + }
  152 + };
  153 +
  154 + /**
  155 + * 验证内部数据,更新外部model
  156 + */
  157 + scope[ctrlAs].$$internal_validate_model = function() {
  158 + if (scope[ctrlAs].$$internal_select_value) {
  159 + var select_value_temp = scope[ctrlAs].$$internal_select_value;
  160 + if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
  161 + var obj;
  162 + for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
  163 + if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
  164 + obj = angular.copy(scope[ctrlAs].$$data_real[j]);
  165 + break;
  166 + }
  167 + }
  168 + if (obj) { // 在data中判定有没有
  169 + for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
  170 + if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
  171 + obj = undefined;
  172 + break;
  173 + }
  174 + }
  175 + if (obj) {
  176 + scope[ctrlAs].$$data.push(obj);
  177 + }
  178 + // 更新内部model,用于外部验证
  179 + // 内部model的值暂时随意,以后再改
  180 + scope[ctrlAs].$$internalmodel = {desc: "ok"};
  181 + } else {
  182 + scope[ctrlAs].$$internalmodel = undefined;
  183 + }
  184 +
  185 + } else {
  186 + scope[ctrlAs].$$internalmodel = undefined;
  187 + }
  188 +
  189 + } else {
  190 + scope[ctrlAs].$$internalmodel = undefined;
  191 + }
  192 + };
  193 +
  194 + /**
  195 + * 内部方法,读取字典数据作为数据源。
  196 + * @param atype ajax查询类型
  197 + * @param ajaxparamobj 查询参数对象
  198 + */
  199 + scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
  200 + ajaxparamobj.type = 'all';
  201 + $$searchInfoService_g[atype].list(
  202 + ajaxparamobj,
  203 + function(result) {
  204 + console.log("$$internal_ajax_data result");
  205 +
  206 + // 清空内部数据
  207 + scope[ctrlAs].$$data_real = [];
  208 + scope[ctrlAs].$$data = [];
  209 +
  210 + // result中添加拼音数据,注意:这里要求result返回对象数组
  211 + for (var i = 0; i < result.length; i ++) {
  212 + if ($dscol_attr) {
  213 + if (eval("result[i]" + "." + $dscol_attr)) {
  214 + // 全拼
  215 + result[i]["fullChars"] = pinyin.getFullChars(eval("result[i]" + "." + $dscol_attr)).toUpperCase();
  216 + // 简拼
  217 + result[i]["camelChars"] = pinyin.getCamelChars(eval("result[i]" + "." + $dscol_attr));
  218 + }
  219 + }
  220 +
  221 + if (result[i]["fullChars"]) { // 有拼音的加入数据源
  222 + scope[ctrlAs].$$data_real.push(result[i]);
  223 + }
  224 +
  225 + }
  226 +
  227 + // 数据量太大,取10条记录显示
  228 + if (angular.isArray(scope[ctrlAs].$$data_real)) {
  229 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  230 + if (scope[ctrlAs].$$data.length < 10) {
  231 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  232 + } else {
  233 + break;
  234 + }
  235 + }
  236 + }
  237 +
  238 + scope[ctrlAs].$$internal_validate_model();
  239 + },
  240 + function(result) {
  241 +
  242 + }
  243 + );
  244 + };
  245 +
  246 + /**
  247 + * 内部方法,读取字典数据作为数据源。
  248 + * @param dictype 字典类型,如:gsType
  249 + */
  250 + scope[ctrlAs].$$internal_dic_data = function(dictype) {
  251 + if (!dictionaryUtils.getByGroup(dictype)) {
  252 + throw new error("字典数据不窜在=" + dictype);
  253 + }
  254 +
  255 + // 清空内部数据
  256 + scope[ctrlAs].$$data_real = [];
  257 + scope[ctrlAs].$$data = [];
  258 +
  259 + var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
  260 + var dic_key; // 字典key
  261 +
  262 + for (dic_key in origin_dicgroup) {
  263 + var data = {}; // 重新组合的字典元素对象
  264 + if (dic_key == "true")
  265 + data[$icname_attr] = true;
  266 + else
  267 + data[$icname_attr] = dic_key;
  268 + data[$dscol_attr] = origin_dicgroup[dic_key];
  269 + scope[ctrlAs].$$data_real.push(data);
  270 + }
  271 + // 这里直接将$$data_real数据深拷贝到$$data
  272 + angular.copy(scope[ctrlAs].$$data_real, scope[ctrlAs].$$data);
  273 + scope[ctrlAs].$$internal_validate_model();
  274 + };
  275 +
  276 + attr.$observe("dsparams", function(value) {
  277 + if (value && value != "") {
  278 + var obj = JSON.parse(value);
  279 + console.log("observe 监控 dsparams=" + obj);
  280 +
  281 + // dsparams格式如下:
  282 + // {type: 'dic/ajax', param: 'dic名字'/'ajax查询参数对象', atype: 'ajax查询类型'}
  283 +
  284 + if (obj.type == 'dic') {
  285 + scope[ctrlAs].$$internal_dic_data(obj.param);
  286 +
  287 + } else if (obj.type == 'ajax') {
  288 + scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
  289 + } else {
  290 + throw new Error("dsparams参数格式异常=" + obj);
  291 + }
  292 +
  293 + }
  294 +
  295 + });
  296 +
  297 + // 监控model绑定的dcvalue值变化
  298 + attr.$observe("dcvalue", function(value) {
  299 + if (value && value != "") {
  300 + console.log("observe 监控 dcvalue=" + value);
  301 + scope[ctrlAs].$$internal_select_value = value;
  302 + scope[ctrlAs].$$internal_validate_model();
  303 + }
  304 +
  305 + // 闭包测试
  306 + var obj = {'a':1,'b':2};
  307 + var tfx = scope[ctrlAs].$$test.bind(obj);
  308 + console.log("闭包测试=" + tfx());
  309 + });
  310 +
  311 + scope[ctrlAs].$$test = function() {
  312 + var exp = "this.a + '(' + this.b + ')'";
  313 + console.log("exp=" + exp);
  314 + return eval(exp);
  315 + };
  316 + }
  317 + };
  318 +
  319 + }
  320 +
  321 + };
  322 + }
323 323 ]);
324 324 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/select/saSelect5.js
1   -/**
2   - * saSelect5指令,基于简拼查询的select,内部封装angular-ui-select控件,并嵌入相应的业务逻辑。
3   - * name(必须):控件的名字
4   - * model(必须):独立作用域,指定一个外部对象模型双向绑定,如:model=ctrl.employeeInfoForSave
5   - * cmaps(必须):外部对象与指令内部数据对象字段名映射对象字符串,如:{'xl.id' : 'id', 'xl.name' : 'name'}
6   - * dcname(必须):绑定的model字段名,如:dcname=xl.id
7   - * icname(必须):内部与之对应的字段名,如:icname=id
8   - *
9   - * dsparams(必须):内部数据源查询参数对象,如:{{ {'ttid_eq': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
10   - * dsparamsextra(可选):内部数据源查询附加参数对象字符串,如:{'type':'all'}
11   - * iterobjname(必须):内部数据源迭代的数据变量名,如:iterobjname=item
12   - * iterobjexp(必须):内部显示用的表达式
13   - * searchph(必须):查询输入占位符字符串,如:searchph=请输入...
14   - * searchexp(必须):查询基于的内部数据源的表达式,如:searchexp=this.name+'('+this.code+')'
15   - *
16   - * required(可选):是否需要form的required验证
17   - *
18   - */
19   -angular.module('ScheduleApp').directive('saSelect5', [
20   - '$timeout',
21   - '$$SearchInfoService_g',
22   - function($timeout, $$searchInfoService_g) {
23   - return {
24   - restrict: 'E',
25   - templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect5Template.html',
26   - scope: { // 独立作用域
27   - model: "=" // 绑定外部对象
28   - },
29   - controllerAs: "$saSelectCtrl",
30   - bindToController: true,
31   - controller: function($scope) {
32   - var self = this;
33   - self.$$data = []; // 内部ui-select显示用数据
34   - self.$$data_real = []; // 内部保存的实际数据
35   -
36   - // myselect组件的ng-model,用于外部绑定验证等操作
37   - self.$$internalmodel = undefined;
38   -
39   - self.$$internal_select_value = undefined; // 选中的值
40   -
41   - },
42   -
43   - /**
44   - * 此阶段可以改dom结构,此时angular还没扫描指令,
45   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
46   - * @param tElem
47   - * @param tAttrs
48   - * @returns {{pre: Function, post: Function}}
49   - */
50   - compile: function(tElem, tAttrs) {
51   - // 获取属性,并验证必须按属性
52   - var $name_attr = tAttrs["name"]; // 控件的名字
53   - var $cmaps_attr = tAttrs["cmaps"]; // 外部对象与指令内部数据对象字段名映射对象
54   - var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
55   - var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
56   -
57   - var $dsparams_attr = tAttrs["dsparams"]; // 内部数据源查询参数对象
58   - var $dsparamsextra_attr = tAttrs["dsparamsextra"]; // 内部数据源查询附加参数对象字符串
59   - var $iterobjname_attr = tAttrs["iterobjname"]; // 内部数据源迭代的数据变量名
60   - var $iterobjexp_attr = tAttrs["iterobjexp"]; // 内部显示用的表达式
61   - var $searchph_attr = tAttrs["searchph"]; // 查询输入占位符字符串
62   - var $searchexp_attr = tAttrs["searchexp"]; // 查询基于的内部数据源的表达式
63   -
64   - var $required_attr = tAttrs["required"]; // 是否需要required验证
65   -
66   - if (!$name_attr) {
67   - throw new Error("name属性必须填写");
68   - }
69   - if (!$cmaps_attr) {
70   - throw new Error("cmaps属性必须填写")
71   - }
72   - if (!$dcname_attr || !$icname_attr) {
73   - throw new Error("dcname、icname属性必须填写");
74   - }
75   - if (!$dsparams_attr) {
76   - throw new Error("dsparams属性必须填写");
77   - }
78   - if (!$iterobjname_attr) {
79   - throw new Error("iterobjname属性必须填写");
80   - }
81   - if (!$iterobjexp_attr) {
82   - throw new Error("iterobjexp属性必须填写");
83   - }
84   - if (!$searchph_attr) {
85   - throw new Error("searchph属性必须填写");
86   - }
87   - if (!$searchexp_attr) {
88   - throw new Error("searchexp属性必须填写");
89   - }
90   -
91   - // 内部controlAs名字
92   - var ctrlAs = "$saSelectCtrl";
93   -
94   - // 动态设置dom
95   - // dom,最外层name属性设置
96   - tElem.find("div:first").attr("name", $name_attr);
97   - // dom,最外层divrequired属性设置
98   - if ($required_attr != undefined) {
99   - tElem.find("div[name=\'" + $name_attr + "\']").attr("required", "");
100   - }
101   - // dom,ui-select-match的placeholder属性设定
102   - tElem.find("ui-select-match").attr("placeholder", $searchph_attr);
103   - // dom,ui-select-match的内容设定
104   - var uiSelectMatchHtml = "{{" + ctrlAs + ".$$internal_match_str($select.selected)}}";
105   - tElem.find("ui-select-match").html(uiSelectMatchHtml);
106   - // dom,ui-select-choices的repeat属性设定
107   - var uiSelectChoices_repeatAttr = $iterobjname_attr + "." + $icname_attr + " as " + $iterobjname_attr + " in " + ctrlAs + ".$$data";
108   - tElem.find("ui-select-choices").attr("repeat", uiSelectChoices_repeatAttr);
109   - // dom,span ng-bind属性设置,TODO:暂时无法用transclude设置,先用属性设置
110   - tElem.find("ui-select-choices").html("{{" + $iterobjexp_attr + "}}");
111   -
112   - return {
113   - pre: function (scope, element, attr) {
114   - // TODO:
115   - },
116   -
117   - /**
118   - * 相当于link函数。
119   - * @param scope
120   - * @param element
121   - * @param attr
122   - */
123   - post: function (scope, element, attr) {
124   -
125   - // 添加选中事件处理函数
126   - scope[ctrlAs].$$internal_select_fn = function($item) {
127   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
128   -
129   - eval("var obj=" + $cmaps_attr);
130   - for (var mc in obj) { // model的字段名:内部数据源对应字段名
131   - var ic = obj[mc]; // 内部数据源对应字段
132   - eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
133   - }
134   - };
135   -
136   - // 删除选中事件处理函数
137   - scope[ctrlAs].$$internal_remove_fn = function() {
138   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
139   -
140   - eval("var obj=" + $cmaps_attr);
141   - var mc; // model的字段名
142   - for (mc in obj) {
143   - eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
144   - }
145   - };
146   -
147   - // 刷新数据
148   - scope[ctrlAs].$$internal_refresh_fn = function(search) {
149   - if (search && search != "") { // 有search值
150   - // 处理search
151   - console.log("search:" + search);
152   -
153   - scope[ctrlAs].$$data = [];
154   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
155   - var upTerm = search.toUpperCase();
156   - if (scope[ctrlAs].$$data.length < 10) {
157   - if (scope[ctrlAs].$$data_real[k].$fullChars.indexOf(upTerm) != -1
158   - || scope[ctrlAs].$$data_real[k].$camelChars.indexOf(upTerm) != -1
159   - || scope[ctrlAs].$$data_real[k].$calcu_str.indexOf(upTerm) != -1) {
160   - scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
161   - }
162   - } else {
163   - break;
164   - }
165   - }
166   - }
167   - };
168   -
169   - /**
170   - * 验证内部数据,更新外部model
171   - */
172   - scope[ctrlAs].$$internal_validate_model = function() {
173   - if (scope[ctrlAs].$$internal_select_value) {
174   - var select_value_temp = scope[ctrlAs].$$internal_select_value;
175   - if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
176   - var obj;
177   - for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
178   - if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
179   - obj = angular.copy(scope[ctrlAs].$$data_real[j]);
180   - break;
181   - }
182   - }
183   - if (obj) { // 在data中判定有没有
184   - for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
185   - if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
186   - obj = undefined;
187   - break;
188   - }
189   - }
190   - if (obj) {
191   - scope[ctrlAs].$$data.push(obj);
192   - }
193   - // 更新内部model,用于外部验证
194   - // 内部model的值暂时随意,以后再改
195   - scope[ctrlAs].$$internalmodel = {desc: "ok"};
196   - } else {
197   - scope[ctrlAs].$$internalmodel = undefined;
198   - }
199   -
200   - } else {
201   - scope[ctrlAs].$$internalmodel = undefined;
202   - }
203   -
204   - } else {
205   - scope[ctrlAs].$$internalmodel = undefined;
206   - }
207   - };
208   -
209   - /**
210   - * 内部match表达式转换函数,需要外部绑定此函数的上下文。
211   - * @param context function上下文
212   - */
213   - scope[ctrlAs].$$internal_match_str = function (context) {
214   - var fx = function() {
215   - try {
216   - return eval($searchexp_attr);
217   - } catch (err) {
218   - //console.log(err);
219   - return undefined;
220   - }
221   -
222   - };
223   -
224   - var str = fx.bind(context)();
225   - if (str && str != "")
226   - return str;
227   - else
228   - return undefined;
229   - };
230   -
231   - /**
232   - * 内部方法,读取字典数据作为数据源。
233   - * @param atype ajax查询类型
234   - * @param ajaxparamobj 查询参数对象
235   - */
236   - scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
237   - // 如果ajaxparamobj为空对象,则表示清空内部选项
238   - var isEmptyObj = true;
239   - for (var name in ajaxparamobj) {
240   - isEmptyObj = false;
241   - }
242   - if (isEmptyObj) {
243   - // 重新创建内部保存的数据
244   - scope[ctrlAs].$$data_real = [];
245   - // 重新创建内部ui-select显示用数据,默认取10条记录显示
246   - scope[ctrlAs].$$data = [];
247   -
248   - scope[ctrlAs].$$internal_remove_fn();
249   - scope[ctrlAs].$$internal_validate_model();
250   -
251   - return;
252   - }
253   -
254   - if ($dsparamsextra_attr) { // 合并附加参数
255   - eval("var extra = " + $dsparamsextra_attr);
256   - for (var extrakey in extra) {
257   - ajaxparamobj[extrakey] = extra[extrakey];
258   - }
259   - }
260   -
261   - $$searchInfoService_g[atype].list(
262   - ajaxparamobj,
263   - function(result) {
264   - console.log("$$internal_ajax_data result");
265   -
266   - // 重新创建内部保存的数据
267   - scope[ctrlAs].$$data_real = [];
268   - // result中添加拼音数据,注意:这里要求result返回对象数组
269   - for (var i = 0; i < result.length; i++) {
270   - // 闭包绑定返回最终查询的值
271   - var calcu_str = scope[ctrlAs].$$internal_match_str(result[i]);
272   - if (calcu_str) {
273   - // 全拼
274   - result[i]["$fullChars"] = pinyin.getFullChars(calcu_str);
275   - // 简拼
276   - result[i]["$camelChars"] = pinyin.getCamelChars(calcu_str);
277   - // 原值
278   - result[i]["$calcu_str"] = calcu_str;
279   -
280   - scope[ctrlAs].$$data_real.push(result[i]);
281   - }
282   - }
283   -
284   - // 重新创建内部ui-select显示用数据,默认取10条记录显示
285   - scope[ctrlAs].$$data = [];
286   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
287   - if (scope[ctrlAs].$$data.length < 10) {
288   - scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
289   - } else {
290   - break;
291   - }
292   - }
293   -
294   - scope[ctrlAs].$$internal_validate_model();
295   - },
296   - function(result) {
297   - throw new Error("ajax查询出错");
298   - }
299   - );
300   - };
301   -
302   - /**
303   - * 内部方法,读取字典数据作为数据源。
304   - * @param dictype 字典类型,如:gsType
305   - */
306   - scope[ctrlAs].$$internal_dic_data = function(dictype) {
307   - if (!dictionaryUtils.getByGroup(dictype)) {
308   - throw new error("字典数据不窜在=" + dictype);
309   - }
310   -
311   - // 重新创建内部保存的数据
312   - scope[ctrlAs].$$data_real = [];
313   - var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
314   - var dic_key; // 字典key
315   -
316   - for (dic_key in origin_dicgroup) {
317   - var data = {}; // 重新组合的字典元素对象
318   - if (dic_key == "true")
319   - data[$icname_attr] = true;
320   - else
321   - data[$icname_attr] = dic_key;
322   - data[$dscol_attr] = origin_dicgroup[dic_key];
323   - scope[ctrlAs].$$data_real.push(data);
324   - }
325   -
326   - // 重新创建内部ui-select显示用数据,直接复制所有的字典数据
327   - scope[ctrlAs].$$data = [];
328   - for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
329   - scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
330   - }
331   -
332   - scope[ctrlAs].$$internal_validate_model();
333   - };
334   -
335   - /**
336   - * 监控dsparams属性变化
337   - */
338   - attr.$observe("dsparams", function(value) {
339   - if (value && value != "") {
340   - var obj = JSON.parse(value);
341   - console.log("saSelect5 监控到dsparams属性变化,old=" + $dsparams_attr + ",new=" + value);
342   -
343   - // dsparams格式如下:
344   - // {type: 'dic/ajax', param: 'dic名字'/'ajax查询参数对象', atype: 'ajax查询类型'}
345   -
346   - if (obj.type == 'dic') {
347   - scope[ctrlAs].$$internal_dic_data(obj.param);
348   -
349   - } else if (obj.type == 'ajax') {
350   - scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
351   - } else {
352   - throw new Error("dsparams参数格式异常=" + obj);
353   - }
354   -
355   - }
356   - });
357   -
358   - /**
359   - * 监控外部模型dcname的值的变化。
360   - */
361   - scope.$watch(
362   - function() {
363   - return eval("scope." + ctrlAs + ".model" + "." + $dcname_attr);
364   - },
365   - function(newValue, oldValue) {
366   - if (newValue === undefined && oldValue === undefined) {
367   - // 两侧都是undefined,不处理
368   -
369   - } else {
370   - console.log("saSelect5 监控到外部模型" + $dcname_attr + "属性值变化,old=" + oldValue + ",new=" + newValue);
371   - scope[ctrlAs].$$internal_select_value = newValue;
372   - scope[ctrlAs].$$internal_validate_model();
373   - }
374   - },
375   - true
376   - );
377   - }
378   - };
379   - }
380   - };
381   - }
  1 +/**
  2 + * saSelect5指令,基于简拼查询的select,内部封装angular-ui-select控件,并嵌入相应的业务逻辑。
  3 + * name(必须):控件的名字
  4 + * model(必须):独立作用域,指定一个外部对象模型双向绑定,如:model=ctrl.employeeInfoForSave
  5 + * cmaps(必须):外部对象与指令内部数据对象字段名映射对象字符串,如:{'xl.id' : 'id', 'xl.name' : 'name'}
  6 + * dcname(必须):绑定的model字段名,如:dcname=xl.id
  7 + * icname(必须):内部与之对应的字段名,如:icname=id
  8 + *
  9 + * dsparams(必须):内部数据源查询参数对象,如:{{ {'ttid_eq': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
  10 + * dsparamsextra(可选):内部数据源查询附加参数对象字符串,如:{'type':'all'}
  11 + * iterobjname(必须):内部数据源迭代的数据变量名,如:iterobjname=item
  12 + * iterobjexp(必须):内部显示用的表达式
  13 + * searchph(必须):查询输入占位符字符串,如:searchph=请输入...
  14 + * searchexp(必须):查询基于的内部数据源的表达式,如:searchexp=this.name+'('+this.code+')'
  15 + *
  16 + * required(可选):是否需要form的required验证
  17 + *
  18 + */
  19 +angular.module('ScheduleApp').directive('saSelect5', [
  20 + '$timeout',
  21 + '$$SearchInfoService_g',
  22 + function($timeout, $$searchInfoService_g) {
  23 + return {
  24 + restrict: 'E',
  25 + templateUrl: '/pages/scheduleApp/module/common/dts1/select/saSelect5Template.html',
  26 + scope: { // 独立作用域
  27 + model: "=" // 绑定外部对象
  28 + },
  29 + controllerAs: "$saSelectCtrl",
  30 + bindToController: true,
  31 + controller: function($scope) {
  32 + var self = this;
  33 + self.$$data = []; // 内部ui-select显示用数据
  34 + self.$$data_real = []; // 内部保存的实际数据
  35 +
  36 + // myselect组件的ng-model,用于外部绑定验证等操作
  37 + self.$$internalmodel = undefined;
  38 +
  39 + self.$$internal_select_value = undefined; // 选中的值
  40 +
  41 + },
  42 +
  43 + /**
  44 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  45 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  46 + * @param tElem
  47 + * @param tAttrs
  48 + * @returns {{pre: Function, post: Function}}
  49 + */
  50 + compile: function(tElem, tAttrs) {
  51 + // 获取属性,并验证必须按属性
  52 + var $name_attr = tAttrs["name"]; // 控件的名字
  53 + var $cmaps_attr = tAttrs["cmaps"]; // 外部对象与指令内部数据对象字段名映射对象
  54 + var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
  55 + var $icname_attr = tAttrs["icname"]; // 内部与之对应的字段名
  56 +
  57 + var $dsparams_attr = tAttrs["dsparams"]; // 内部数据源查询参数对象
  58 + var $dsparamsextra_attr = tAttrs["dsparamsextra"]; // 内部数据源查询附加参数对象字符串
  59 + var $iterobjname_attr = tAttrs["iterobjname"]; // 内部数据源迭代的数据变量名
  60 + var $iterobjexp_attr = tAttrs["iterobjexp"]; // 内部显示用的表达式
  61 + var $searchph_attr = tAttrs["searchph"]; // 查询输入占位符字符串
  62 + var $searchexp_attr = tAttrs["searchexp"]; // 查询基于的内部数据源的表达式
  63 +
  64 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  65 +
  66 + if (!$name_attr) {
  67 + throw new Error("name属性必须填写");
  68 + }
  69 + if (!$cmaps_attr) {
  70 + throw new Error("cmaps属性必须填写")
  71 + }
  72 + if (!$dcname_attr || !$icname_attr) {
  73 + throw new Error("dcname、icname属性必须填写");
  74 + }
  75 + if (!$dsparams_attr) {
  76 + throw new Error("dsparams属性必须填写");
  77 + }
  78 + if (!$iterobjname_attr) {
  79 + throw new Error("iterobjname属性必须填写");
  80 + }
  81 + if (!$iterobjexp_attr) {
  82 + throw new Error("iterobjexp属性必须填写");
  83 + }
  84 + if (!$searchph_attr) {
  85 + throw new Error("searchph属性必须填写");
  86 + }
  87 + if (!$searchexp_attr) {
  88 + throw new Error("searchexp属性必须填写");
  89 + }
  90 +
  91 + // 内部controlAs名字
  92 + var ctrlAs = "$saSelectCtrl";
  93 +
  94 + // 动态设置dom
  95 + // dom,最外层name属性设置
  96 + tElem.find("div:first").attr("name", $name_attr);
  97 + // dom,最外层divrequired属性设置
  98 + if ($required_attr != undefined) {
  99 + tElem.find("div[name=\'" + $name_attr + "\']").attr("required", "");
  100 + }
  101 + // dom,ui-select-match的placeholder属性设定
  102 + tElem.find("ui-select-match").attr("placeholder", $searchph_attr);
  103 + // dom,ui-select-match的内容设定
  104 + var uiSelectMatchHtml = "{{" + ctrlAs + ".$$internal_match_str($select.selected)}}";
  105 + tElem.find("ui-select-match").html(uiSelectMatchHtml);
  106 + // dom,ui-select-choices的repeat属性设定
  107 + var uiSelectChoices_repeatAttr = $iterobjname_attr + "." + $icname_attr + " as " + $iterobjname_attr + " in " + ctrlAs + ".$$data";
  108 + tElem.find("ui-select-choices").attr("repeat", uiSelectChoices_repeatAttr);
  109 + // dom,span ng-bind属性设置,TODO:暂时无法用transclude设置,先用属性设置
  110 + tElem.find("ui-select-choices").html("{{" + $iterobjexp_attr + "}}");
  111 +
  112 + return {
  113 + pre: function (scope, element, attr) {
  114 + // TODO:
  115 + },
  116 +
  117 + /**
  118 + * 相当于link函数。
  119 + * @param scope
  120 + * @param element
  121 + * @param attr
  122 + */
  123 + post: function (scope, element, attr) {
  124 +
  125 + // 添加选中事件处理函数
  126 + scope[ctrlAs].$$internal_select_fn = function($item) {
  127 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = $item" + "." + $icname_attr + ";");
  128 +
  129 + eval("var obj=" + $cmaps_attr);
  130 + for (var mc in obj) { // model的字段名:内部数据源对应字段名
  131 + var ic = obj[mc]; // 内部数据源对应字段
  132 + eval("scope[ctrlAs].model" + "." + mc + " = $item" + "." + ic + ";");
  133 + }
  134 + };
  135 +
  136 + // 删除选中事件处理函数
  137 + scope[ctrlAs].$$internal_remove_fn = function() {
  138 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = undefined;");
  139 +
  140 + eval("var obj=" + $cmaps_attr);
  141 + var mc; // model的字段名
  142 + for (mc in obj) {
  143 + eval("scope[ctrlAs].model" + "." + mc + " = undefined;");
  144 + }
  145 + };
  146 +
  147 + // 刷新数据
  148 + scope[ctrlAs].$$internal_refresh_fn = function(search) {
  149 + if (search && search != "") { // 有search值
  150 + // 处理search
  151 + console.log("search:" + search);
  152 +
  153 + scope[ctrlAs].$$data = [];
  154 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  155 + var upTerm = search.toUpperCase();
  156 + if (scope[ctrlAs].$$data.length < 10) {
  157 + if (scope[ctrlAs].$$data_real[k].$fullChars.indexOf(upTerm) != -1
  158 + || scope[ctrlAs].$$data_real[k].$camelChars.indexOf(upTerm) != -1
  159 + || scope[ctrlAs].$$data_real[k].$calcu_str.indexOf(upTerm) != -1) {
  160 + scope[ctrlAs].$$data.push(angular.copy(scope[ctrlAs].$$data_real[k]));
  161 + }
  162 + } else {
  163 + break;
  164 + }
  165 + }
  166 + }
  167 + };
  168 +
  169 + /**
  170 + * 验证内部数据,更新外部model
  171 + */
  172 + scope[ctrlAs].$$internal_validate_model = function() {
  173 + if (scope[ctrlAs].$$internal_select_value) {
  174 + var select_value_temp = scope[ctrlAs].$$internal_select_value;
  175 + if (scope[ctrlAs].$$data_real && scope[ctrlAs].$$data_real.length > 0) {
  176 + var obj;
  177 + for (var j = 0; j < scope[ctrlAs].$$data_real.length; j++) {
  178 + if (eval("scope[ctrlAs].$$data_real[j]" + "." + $icname_attr + " == select_value_temp")) {
  179 + obj = angular.copy(scope[ctrlAs].$$data_real[j]);
  180 + break;
  181 + }
  182 + }
  183 + if (obj) { // 在data中判定有没有
  184 + for (var k = 0; k < scope[ctrlAs].$$data.length; k++) {
  185 + if (eval("scope[ctrlAs].$$data[k]" + "." + $icname_attr + " == obj." + $icname_attr)) {
  186 + obj = undefined;
  187 + break;
  188 + }
  189 + }
  190 + if (obj) {
  191 + scope[ctrlAs].$$data.push(obj);
  192 + }
  193 + // 更新内部model,用于外部验证
  194 + // 内部model的值暂时随意,以后再改
  195 + scope[ctrlAs].$$internalmodel = {desc: "ok"};
  196 + } else {
  197 + scope[ctrlAs].$$internalmodel = undefined;
  198 + }
  199 +
  200 + } else {
  201 + scope[ctrlAs].$$internalmodel = undefined;
  202 + }
  203 +
  204 + } else {
  205 + scope[ctrlAs].$$internalmodel = undefined;
  206 + }
  207 + };
  208 +
  209 + /**
  210 + * 内部match表达式转换函数,需要外部绑定此函数的上下文。
  211 + * @param context function上下文
  212 + */
  213 + scope[ctrlAs].$$internal_match_str = function (context) {
  214 + var fx = function() {
  215 + try {
  216 + return eval($searchexp_attr);
  217 + } catch (err) {
  218 + //console.log(err);
  219 + return undefined;
  220 + }
  221 +
  222 + };
  223 +
  224 + var str = fx.bind(context)();
  225 + if (str && str != "")
  226 + return str;
  227 + else
  228 + return undefined;
  229 + };
  230 +
  231 + /**
  232 + * 内部方法,读取字典数据作为数据源。
  233 + * @param atype ajax查询类型
  234 + * @param ajaxparamobj 查询参数对象
  235 + */
  236 + scope[ctrlAs].$$internal_ajax_data = function(atype, ajaxparamobj) {
  237 + // 如果ajaxparamobj为空对象,则表示清空内部选项
  238 + var isEmptyObj = true;
  239 + for (var name in ajaxparamobj) {
  240 + isEmptyObj = false;
  241 + }
  242 + if (isEmptyObj) {
  243 + // 重新创建内部保存的数据
  244 + scope[ctrlAs].$$data_real = [];
  245 + // 重新创建内部ui-select显示用数据,默认取10条记录显示
  246 + scope[ctrlAs].$$data = [];
  247 +
  248 + scope[ctrlAs].$$internal_remove_fn();
  249 + scope[ctrlAs].$$internal_validate_model();
  250 +
  251 + return;
  252 + }
  253 +
  254 + if ($dsparamsextra_attr) { // 合并附加参数
  255 + eval("var extra = " + $dsparamsextra_attr);
  256 + for (var extrakey in extra) {
  257 + ajaxparamobj[extrakey] = extra[extrakey];
  258 + }
  259 + }
  260 +
  261 + $$searchInfoService_g[atype].list(
  262 + ajaxparamobj,
  263 + function(result) {
  264 + console.log("$$internal_ajax_data result");
  265 +
  266 + // 重新创建内部保存的数据
  267 + scope[ctrlAs].$$data_real = [];
  268 + // result中添加拼音数据,注意:这里要求result返回对象数组
  269 + for (var i = 0; i < result.length; i++) {
  270 + // 闭包绑定返回最终查询的值
  271 + var calcu_str = scope[ctrlAs].$$internal_match_str(result[i]);
  272 + if (calcu_str) {
  273 + // 全拼
  274 + result[i]["$fullChars"] = pinyin.getFullChars(calcu_str);
  275 + // 简拼
  276 + result[i]["$camelChars"] = pinyin.getCamelChars(calcu_str);
  277 + // 原值
  278 + result[i]["$calcu_str"] = calcu_str;
  279 +
  280 + scope[ctrlAs].$$data_real.push(result[i]);
  281 + }
  282 + }
  283 +
  284 + // 重新创建内部ui-select显示用数据,默认取10条记录显示
  285 + scope[ctrlAs].$$data = [];
  286 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  287 + if (scope[ctrlAs].$$data.length < 10) {
  288 + scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
  289 + } else {
  290 + break;
  291 + }
  292 + }
  293 +
  294 + scope[ctrlAs].$$internal_validate_model();
  295 + },
  296 + function(result) {
  297 + throw new Error("ajax查询出错");
  298 + }
  299 + );
  300 + };
  301 +
  302 + /**
  303 + * 内部方法,读取字典数据作为数据源。
  304 + * @param dictype 字典类型,如:gsType
  305 + */
  306 + scope[ctrlAs].$$internal_dic_data = function(dictype) {
  307 + if (!dictionaryUtils.getByGroup(dictype)) {
  308 + throw new error("字典数据不窜在=" + dictype);
  309 + }
  310 +
  311 + // 重新创建内部保存的数据
  312 + scope[ctrlAs].$$data_real = [];
  313 + var origin_dicgroup = dictionaryUtils.getByGroup(dicgroup);
  314 + var dic_key; // 字典key
  315 +
  316 + for (dic_key in origin_dicgroup) {
  317 + var data = {}; // 重新组合的字典元素对象
  318 + if (dic_key == "true")
  319 + data[$icname_attr] = true;
  320 + else
  321 + data[$icname_attr] = dic_key;
  322 + data[$dscol_attr] = origin_dicgroup[dic_key];
  323 + scope[ctrlAs].$$data_real.push(data);
  324 + }
  325 +
  326 + // 重新创建内部ui-select显示用数据,直接复制所有的字典数据
  327 + scope[ctrlAs].$$data = [];
  328 + for (var k = 0; k < scope[ctrlAs].$$data_real.length; k++) {
  329 + scope[ctrlAs].$$data.push(scope[ctrlAs].$$data_real[k]);
  330 + }
  331 +
  332 + scope[ctrlAs].$$internal_validate_model();
  333 + };
  334 +
  335 + /**
  336 + * 监控dsparams属性变化
  337 + */
  338 + attr.$observe("dsparams", function(value) {
  339 + if (value && value != "") {
  340 + var obj = JSON.parse(value);
  341 + console.log("saSelect5 监控到dsparams属性变化,old=" + $dsparams_attr + ",new=" + value);
  342 +
  343 + // dsparams格式如下:
  344 + // {type: 'dic/ajax', param: 'dic名字'/'ajax查询参数对象', atype: 'ajax查询类型'}
  345 +
  346 + if (obj.type == 'dic') {
  347 + scope[ctrlAs].$$internal_dic_data(obj.param);
  348 +
  349 + } else if (obj.type == 'ajax') {
  350 + scope[ctrlAs].$$internal_ajax_data(obj.atype, obj.param);
  351 + } else {
  352 + throw new Error("dsparams参数格式异常=" + obj);
  353 + }
  354 +
  355 + }
  356 + });
  357 +
  358 + /**
  359 + * 监控外部模型dcname的值的变化。
  360 + */
  361 + scope.$watch(
  362 + function() {
  363 + return eval("scope." + ctrlAs + ".model" + "." + $dcname_attr);
  364 + },
  365 + function(newValue, oldValue) {
  366 + if (newValue === undefined && oldValue === undefined) {
  367 + // 两侧都是undefined,不处理
  368 +
  369 + } else {
  370 + console.log("saSelect5 监控到外部模型" + $dcname_attr + "属性值变化,old=" + oldValue + ",new=" + newValue);
  371 + scope[ctrlAs].$$internal_select_value = newValue;
  372 + scope[ctrlAs].$$internal_validate_model();
  373 + }
  374 + },
  375 + true
  376 + );
  377 + }
  378 + };
  379 + }
  380 + };
  381 + }
382 382 ]);
383 383 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts1/validation/remoteValidaton.js
1   -angular.module('ScheduleApp').directive("remoteValidaton", [
2   - 'BusInfoManageService_g',
3   - 'EmployeeInfoManageService_g',
4   - 'TimeTableManageService_g',
5   - function(
6   - busInfoManageService_g,
7   - employeeInfoManageService_g,
8   - timeTableManageService_g
9   - ) {
10   - /**
11   - * 远端验证指令,依赖于ngModel
12   - * 指令名称 remote-Validation
13   - * 需要属性 rvtype 表示验证类型
14   - */
15   - return {
16   - restrict: "A",
17   - require: "^ngModel",
18   - link: function(scope, element, attr, ngModelCtrl) {
19   - element.bind("keyup", function() {
20   - var modelValue = ngModelCtrl.$modelValue;
21   - var rv1_attr = attr["rv1"];
22   - if (attr["rvtype"]) {
23   -
24   - // 根据rvtype的值,确定使用那个远端验证的url,
25   - // rv1, rv2, rv3是关联比较值,暂时使用rv1
26   - // 这个貌似没法通用,根据业务变换
27   - // TODO:暂时有点乱以后改
28   - if (attr["rvtype"] == "insideCode") {
29   - busInfoManageService_g.validate.insideCode(
30   - {"insideCode_eq": modelValue, type: "equale"},
31   - function(result) {
32   - //console.log(result);
33   - if (result.status == "SUCCESS") {
34   - ngModelCtrl.$setValidity('remote', true);
35   - } else {
36   - ngModelCtrl.$setValidity('remote', false);
37   - }
38   - },
39   - function(result) {
40   - //console.log(result);
41   - ngModelCtrl.$setValidity('remote', true);
42   - }
43   - );
44   - } else if (attr["rvtype"] == "jobCode") {
45   - if (!rv1_attr) {
46   - ngModelCtrl.$setValidity('remote', false);
47   - return;
48   - }
49   -
50   - employeeInfoManageService_g.validate.jobCode(
51   - {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
52   - function(result) {
53   - //console.log(result);
54   - if (result.status == "SUCCESS") {
55   - ngModelCtrl.$setValidity('remote', true);
56   - } else {
57   - ngModelCtrl.$setValidity('remote', false);
58   - }
59   - },
60   - function(result) {
61   - //console.log(result);
62   - ngModelCtrl.$setValidity('remote', true);
63   - }
64   - );
65   - } else if (attr["rvtype"] == "ttinfoname") {
66   - if (!rv1_attr) {
67   - ngModelCtrl.$setValidity('remote', false);
68   - return;
69   - }
70   -
71   - timeTableManageService_g.validate.ttinfoname(
72   - {"name_eq": modelValue, "xl.id_eq": rv1_attr, type: "equale"},
73   - function(result) {
74   - //console.log(result);
75   - if (result.status == "SUCCESS") {
76   - ngModelCtrl.$setValidity('remote', true);
77   - } else {
78   - ngModelCtrl.$setValidity('remote', false);
79   - }
80   - },
81   - function(result) {
82   - //console.log(result);
83   - ngModelCtrl.$setValidity('remote', true);
84   - }
85   - );
86   -
87   - }
88   - } else {
89   - // 没有rvtype,就不用远端验证了
90   - ngModelCtrl.$setValidity('remote', true);
91   - }
92   -
93   - attr.$observe("rv1", function(value) {
94   - if (attr["rvtype"] == "jobCode") {
95   - if (!value) {
96   - ngModelCtrl.$setValidity('remote', false);
97   - return;
98   - }
99   -
100   - employeeInfoManageService_g.validate.jobCode(
101   - {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
102   - function(result) {
103   - //console.log(result);
104   - if (result.status == "SUCCESS") {
105   - ngModelCtrl.$setValidity('remote', true);
106   - } else {
107   - ngModelCtrl.$setValidity('remote', false);
108   - }
109   - },
110   - function(result) {
111   - //console.log(result);
112   - ngModelCtrl.$setValidity('remote', true);
113   - }
114   - );
115   - } else if (attr["rvtype"] == "ttinfoname") {
116   - if (!value) {
117   - ngModelCtrl.$setValidity('remote', false);
118   - return;
119   - }
120   -
121   - console.log("rv1:" + value);
122   -
123   - timeTableManageService_g.validate.ttinfoname(
124   - {"name_eq": modelValue, "xl.id_eq": value, type: "equale"},
125   - function(result) {
126   - //console.log(result);
127   - if (result.status == "SUCCESS") {
128   - ngModelCtrl.$setValidity('remote', true);
129   - } else {
130   - ngModelCtrl.$setValidity('remote', false);
131   - }
132   - },
133   - function(result) {
134   - //console.log(result);
135   - ngModelCtrl.$setValidity('remote', true);
136   - }
137   - );
138   - }
139   -
140   - });
141   - });
142   - }
143   - };
144   - }
145   - ]
  1 +angular.module('ScheduleApp').directive("remoteValidaton", [
  2 + 'BusInfoManageService_g',
  3 + 'EmployeeInfoManageService_g',
  4 + 'TimeTableManageService_g',
  5 + function(
  6 + busInfoManageService_g,
  7 + employeeInfoManageService_g,
  8 + timeTableManageService_g
  9 + ) {
  10 + /**
  11 + * 远端验证指令,依赖于ngModel
  12 + * 指令名称 remote-Validation
  13 + * 需要属性 rvtype 表示验证类型
  14 + */
  15 + return {
  16 + restrict: "A",
  17 + require: "^ngModel",
  18 + link: function(scope, element, attr, ngModelCtrl) {
  19 + element.bind("keyup", function() {
  20 + var modelValue = ngModelCtrl.$modelValue;
  21 + var rv1_attr = attr["rv1"];
  22 + if (attr["rvtype"]) {
  23 +
  24 + // 根据rvtype的值,确定使用那个远端验证的url,
  25 + // rv1, rv2, rv3是关联比较值,暂时使用rv1
  26 + // 这个貌似没法通用,根据业务变换
  27 + // TODO:暂时有点乱以后改
  28 + if (attr["rvtype"] == "insideCode") {
  29 + busInfoManageService_g.validate.insideCode(
  30 + {"insideCode_eq": modelValue, type: "equale"},
  31 + function(result) {
  32 + //console.log(result);
  33 + if (result.status == "SUCCESS") {
  34 + ngModelCtrl.$setValidity('remote', true);
  35 + } else {
  36 + ngModelCtrl.$setValidity('remote', false);
  37 + }
  38 + },
  39 + function(result) {
  40 + //console.log(result);
  41 + ngModelCtrl.$setValidity('remote', true);
  42 + }
  43 + );
  44 + } else if (attr["rvtype"] == "jobCode") {
  45 + if (!rv1_attr) {
  46 + ngModelCtrl.$setValidity('remote', false);
  47 + return;
  48 + }
  49 +
  50 + employeeInfoManageService_g.validate.jobCode(
  51 + {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
  52 + function(result) {
  53 + //console.log(result);
  54 + if (result.status == "SUCCESS") {
  55 + ngModelCtrl.$setValidity('remote', true);
  56 + } else {
  57 + ngModelCtrl.$setValidity('remote', false);
  58 + }
  59 + },
  60 + function(result) {
  61 + //console.log(result);
  62 + ngModelCtrl.$setValidity('remote', true);
  63 + }
  64 + );
  65 + } else if (attr["rvtype"] == "ttinfoname") {
  66 + if (!rv1_attr) {
  67 + ngModelCtrl.$setValidity('remote', false);
  68 + return;
  69 + }
  70 +
  71 + timeTableManageService_g.validate.ttinfoname(
  72 + {"name_eq": modelValue, "xl.id_eq": rv1_attr, type: "equale"},
  73 + function(result) {
  74 + //console.log(result);
  75 + if (result.status == "SUCCESS") {
  76 + ngModelCtrl.$setValidity('remote', true);
  77 + } else {
  78 + ngModelCtrl.$setValidity('remote', false);
  79 + }
  80 + },
  81 + function(result) {
  82 + //console.log(result);
  83 + ngModelCtrl.$setValidity('remote', true);
  84 + }
  85 + );
  86 +
  87 + }
  88 + } else {
  89 + // 没有rvtype,就不用远端验证了
  90 + ngModelCtrl.$setValidity('remote', true);
  91 + }
  92 +
  93 + attr.$observe("rv1", function(value) {
  94 + if (attr["rvtype"] == "jobCode") {
  95 + if (!value) {
  96 + ngModelCtrl.$setValidity('remote', false);
  97 + return;
  98 + }
  99 +
  100 + employeeInfoManageService_g.validate.jobCode(
  101 + {"jobCode_eq": modelValue, "companyCode_eq": rv1_attr, type: "equale"},
  102 + function(result) {
  103 + //console.log(result);
  104 + if (result.status == "SUCCESS") {
  105 + ngModelCtrl.$setValidity('remote', true);
  106 + } else {
  107 + ngModelCtrl.$setValidity('remote', false);
  108 + }
  109 + },
  110 + function(result) {
  111 + //console.log(result);
  112 + ngModelCtrl.$setValidity('remote', true);
  113 + }
  114 + );
  115 + } else if (attr["rvtype"] == "ttinfoname") {
  116 + if (!value) {
  117 + ngModelCtrl.$setValidity('remote', false);
  118 + return;
  119 + }
  120 +
  121 + console.log("rv1:" + value);
  122 +
  123 + timeTableManageService_g.validate.ttinfoname(
  124 + {"name_eq": modelValue, "xl.id_eq": value, type: "equale"},
  125 + function(result) {
  126 + //console.log(result);
  127 + if (result.status == "SUCCESS") {
  128 + ngModelCtrl.$setValidity('remote', true);
  129 + } else {
  130 + ngModelCtrl.$setValidity('remote', false);
  131 + }
  132 + },
  133 + function(result) {
  134 + //console.log(result);
  135 + ngModelCtrl.$setValidity('remote', true);
  136 + }
  137 + );
  138 + }
  139 +
  140 + });
  141 + });
  142 + }
  143 + };
  144 + }
  145 + ]
146 146 );
147 147 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts2/bcGroup/saBcgroup.js
1   -/**
2   - * saBcgroup指令,用于套跑界面中,从指定线路,指定时刻表,指定路牌的班次列表中选择套跑班次。
3   - * 属性如下:
4   - * name(必须):控件的名字
5   - * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
6   - * bcttinfoidsvalue(必须):绑定的model班次ids字段值,如:bcttinfoidsvalue={{ctrl.employeeInfoForSave.lprange}}
7   - * bcttinfoidsname(必须):bind的model班次ids字段名,如:bcttinfoidsname=lprange
8   - * dataparams (必须):内部数据关联的查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
9   - * required(可选):是否要用required验证
10   - *
11   - */
12   -angular.module('ScheduleApp').directive('saBcgroup', [
13   - 'TimeTableDetailManageService_g',
14   - function(timeTableDetailManageService_g) {
15   - return {
16   - restrict: 'E',
17   - templateUrl: '/pages/scheduleApp/module/common/dts2/bcGroup/saBcgroupTemplate.html',
18   - scope: {
19   - model: "=" // 独立作用域,关联外部的模型object
20   - },
21   - controllerAs: '$saBcgroupCtrl',
22   - bindToController: true,
23   - controller: function($scope) {
24   - var self = this;
25   - self.$$data = []; // 选择线路,时刻表,路牌后的班次列表
26   -
27   - // 测试数据
28   - //self.$$data = [
29   - // {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
30   - // {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
31   - // {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
32   - //];
33   -
34   -
35   - self.$$dataSelected = []; // 套跑选中的班次列表
36   -
37   - //self.$$dataSelected = [
38   - // {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
39   - // {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
40   - // {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
41   - //];
42   -
43   - // saBcgroup组件的ng-model,用于外部绑定等操作
44   - self.$$internalmodel = undefined;
45   -
46   - self.$$data_bcdata_first_init = false; // 班次数据首次初始化标志
47   - self.$$data_bcttinfoids_first_init = false; // 班次ids数据首次初始化标志
48   - self.$$data_bcttinfoids_first_data = undefined; // 班次ids数据首次初始化数据
49   -
50   - },
51   -
52   - /**
53   - * 此阶段可以改dom结构,此时angular还没扫描指令,
54   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
55   - * @param tElem
56   - * @param tAttrs
57   - * @returns {{pre: Function, post: Function}}
58   - */
59   - compile: function(tElem, tAttrs) {
60   - // TODO:获取所有的属性
61   - var $name_attr = tAttrs["name"]; // 控件的名字
62   - var $required_attr = tAttrs["required"]; // 是否需要required验证
63   - var $bcttinfoidsname_attr = tAttrs["bcttinfoidsname"]; // bind的model班次ids字段名
64   -
65   - // controlAs名字
66   - var ctrlAs = '$saBcgroupCtrl';
67   -
68   - // 如果有required属性,添加angularjs required验证
69   - if ($required_attr != undefined) {
70   - //console.log(tElem.html());
71   - tElem.find("div").attr("required", "");
72   - }
73   -
74   - return {
75   - pre: function(scope, element, attr) {
76   - // TODO:
77   - },
78   -
79   - /**
80   - * 相当于link函数。
81   - * @param scope
82   - * @param element
83   - * @param attr
84   - */
85   - post: function(scope, element, attr) {
86   - // name属性
87   - if ($name_attr) {
88   - scope[ctrlAs]["$name_attr"] = $name_attr;
89   - }
90   -
91   - // TODO:
92   -
93   -
94   - /**
95   - * 班次列表点击(班次列表中选中班次)
96   - * @param $index
97   - */
98   - scope[ctrlAs].$$internal_bclist_click = function($index) {
99   - var data_temp = scope[ctrlAs].$$data;
100   - var data_temp2 = scope[ctrlAs].$$dataSelected;
101   - var i = 0;
102   - var isunique = true; // 是否已经选择过
103   - if (data_temp && data_temp.length > $index) {
104   - for (i = 0; i < data_temp2.length; i++) {
105   - if (data_temp2[i].bcttinfoid == data_temp[$index].bcttinfoid) {
106   - isunique = false;
107   - break;
108   - }
109   - }
110   - if (isunique) {
111   - data_temp2.push({
112   - bcttinfoid: data_temp[$index].bcttinfoid,
113   - bcfcsj: data_temp[$index].bcfcsj,
114   - bctype: data_temp[$index].bctype
115   - });
116   - }
117   -
118   - }
119   - };
120   - /**
121   - * 选中的班次双击(删除选中的班次)
122   - * @param $index
123   - */
124   - scope[ctrlAs].$$internal_selbclist_dbclick = function($index) {
125   - var data_temp = scope[ctrlAs].$$dataSelected;
126   - if (data_temp && data_temp.length > $index) {
127   - data_temp.splice($index, 1);
128   - }
129   - };
130   -
131   -
132   - /**
133   - * 验证内部数据,更新外部model
134   - */
135   - scope[ctrlAs].$$internal_validate_model = function() {
136   - var data_temp = scope[ctrlAs].$$dataSelected;
137   - var bcttinfoIds = [];
138   - var i = 0;
139   -
140   - if (data_temp &&
141   - data_temp.length > 0) {
142   -
143   - for (i = 0; i < data_temp.length; i++) {
144   - bcttinfoIds.push(data_temp[i].bcttinfoid);
145   - }
146   -
147   - // 更新外部model字段
148   - if ($bcttinfoidsname_attr) {
149   - console.log("bcttinfoidsname=" + bcttinfoIds.join(','));
150   - eval("scope[ctrlAs].model" + "." + $bcttinfoidsname_attr + " = bcttinfoIds.join(',');");
151   - }
152   -
153   - // 更新内部model,用于外部验证
154   - // 内部model的值暂时随意,以后再改
155   - scope[ctrlAs].$$internalmodel = {desc: "ok"};
156   -
157   - scope[ctrlAs].$$data_bcdata_first_init = true;
158   - scope[ctrlAs].$$data_bcttinfoids_first_init = true;
159   -
160   - } else {
161   - scope[ctrlAs].$$internalmodel = undefined;
162   - }
163   -
164   - };
165   -
166   - // 监控内部数据,$$data_selected 变化
167   - scope.$watch(
168   - function() {
169   - console.log("长度:" + scope[ctrlAs].$$dataSelected.length);
170   - return scope[ctrlAs].$$dataSelected;
171   - },
172   - function(newValue, oldValue) {
173   - scope[ctrlAs].$$internal_validate_model();
174   - },
175   - true
176   - );
177   -
178   - /**
179   - * 验证数据是否初始化完成,
180   - * 所谓的初始化就是内部所有的数据被有效设定过一次。
181   - */
182   - scope[ctrlAs].$$internal_validate_init = function() {
183   - var self = scope[ctrlAs];
184   -
185   - var data_temp = self.$$data;
186   - var dataSelect_temp = self.$$dataSelected;
187   - var bcttinfoids = null;
188   -
189   - var i = 0;
190   - var j = 0;
191   -
192   - if (self.$$data_bcdata_first_init &&
193   - self.$$data_bcttinfoids_first_init) {
194   - console.log("开始初始化数据");
195   -
196   - bcttinfoids = self.$$data_bcttinfoids_first_data ? self.$$data_bcttinfoids_first_data.split(",") : [];
197   -
198   - for (i = 0; i < bcttinfoids.length; i++) {
199   - dataSelect_temp.push({
200   - bcttinfoid: bcttinfoids[i]
201   - });
202   - for (j = 0; j < data_temp.length; j++) {
203   - if (dataSelect_temp[i].bcttinfoid == data_temp[j].bcttinfoid) {
204   - dataSelect_temp[i].bcfcsj = data_temp[j].bcfcsj;
205   - dataSelect_temp[i].bctype = data_temp[j].bctype;
206   - break;
207   - }
208   - }
209   - }
210   -
211   - console.log("数据初始化完毕!");
212   - }
213   -
214   - };
215   -
216   - // 监控初始化标志
217   - scope.$watch(
218   - function() {
219   - return scope[ctrlAs].$$data_bcdata_first_init;
220   - },
221   - function(newValue, oldValue) {
222   - scope[ctrlAs].$$internal_validate_init();
223   - }
224   - );
225   - scope.$watch(
226   - function() {
227   - return scope[ctrlAs].$$data_bcttinfoids_first_init;
228   - },
229   - function(newValue, oldValue) {
230   - scope[ctrlAs].$$internal_validate_init();
231   - }
232   - );
233   -
234   - // 监控内部数据的变化
235   - attr.$observe("dataparams", function(value) {
236   - if (value && value != "") {
237   - if (value == '{}') {
238   - return;
239   - }
240   -
241   - console.log("bcgroup observe 监控 dataparams=" + value);
242   -
243   - timeTableDetailManageService_g.bcdetails.list(
244   - JSON.parse(value),
245   - function(result) {
246   - // 获取值了
247   - console.log("内部班次数据获取了");
248   -
249   - scope[ctrlAs].$$data = [];
250   - for (var i = 0; i < result.length; i++) {
251   - scope[ctrlAs].$$data.push({
252   - bcttinfoid: result[i].id,
253   - bcfcsj: result[i].fcsj,
254   - bctype: result[i].bcType
255   - });
256   - }
257   - if (scope[ctrlAs].$$data_bcdata_first_init &&
258   - scope[ctrlAs].$$data_bcttinfoids_first_init) {
259   -
260   - scope[ctrlAs].$$dataSelected = [];
261   - scope[ctrlAs].$$internalmodel = undefined;
262   - }
263   - scope[ctrlAs].$$data_bcdata_first_init = true;
264   - },
265   - function(result) {
266   -
267   - }
268   - );
269   - }
270   - });
271   - // 监控班次ids数据的变化
272   - attr.$observe("bcttinfoidsvalue", function(value) {
273   - if (value && value != "") {
274   - console.log("observe 监控 bcttinfoidsvalue=" + value);
275   - scope[ctrlAs].$$data_bcttinfoids_first_init = true;
276   - scope[ctrlAs].$$data_bcttinfoids_first_data = value;
277   - }
278   - });
279   -
280   - }
281   - }
282   -
283   - }
284   - }
285   - }
  1 +/**
  2 + * saBcgroup指令,用于套跑界面中,从指定线路,指定时刻表,指定路牌的班次列表中选择套跑班次。
  3 + * 属性如下:
  4 + * name(必须):控件的名字
  5 + * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
  6 + * bcttinfoidsvalue(必须):绑定的model班次ids字段值,如:bcttinfoidsvalue={{ctrl.employeeInfoForSave.lprange}}
  7 + * bcttinfoidsname(必须):bind的model班次ids字段名,如:bcttinfoidsname=lprange
  8 + * dataparams (必须):内部数据关联的查询参数,如:{{ {'ttid': ctrl.rerunManageForSave.rerunTtinfo.id} | json }}
  9 + * required(可选):是否要用required验证
  10 + *
  11 + */
  12 +angular.module('ScheduleApp').directive('saBcgroup', [
  13 + 'TimeTableDetailManageService_g',
  14 + function(timeTableDetailManageService_g) {
  15 + return {
  16 + restrict: 'E',
  17 + templateUrl: '/pages/scheduleApp/module/common/dts2/bcGroup/saBcgroupTemplate.html',
  18 + scope: {
  19 + model: "=" // 独立作用域,关联外部的模型object
  20 + },
  21 + controllerAs: '$saBcgroupCtrl',
  22 + bindToController: true,
  23 + controller: function($scope) {
  24 + var self = this;
  25 + self.$$data = []; // 选择线路,时刻表,路牌后的班次列表
  26 +
  27 + // 测试数据
  28 + //self.$$data = [
  29 + // {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
  30 + // {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
  31 + // {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
  32 + //];
  33 +
  34 +
  35 + self.$$dataSelected = []; // 套跑选中的班次列表
  36 +
  37 + //self.$$dataSelected = [
  38 + // {bcttinfoid: 1, bcfcsj: '7:30', bctype: 'out'},
  39 + // {bcttinfoid: 2, bcfcsj: '8:30', bctype: 'normal'},
  40 + // {bcttinfoid: 3, bcfcsj: '9:30', bctype: 'in'}
  41 + //];
  42 +
  43 + // saBcgroup组件的ng-model,用于外部绑定等操作
  44 + self.$$internalmodel = undefined;
  45 +
  46 + self.$$data_bcdata_first_init = false; // 班次数据首次初始化标志
  47 + self.$$data_bcttinfoids_first_init = false; // 班次ids数据首次初始化标志
  48 + self.$$data_bcttinfoids_first_data = undefined; // 班次ids数据首次初始化数据
  49 +
  50 + },
  51 +
  52 + /**
  53 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  54 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  55 + * @param tElem
  56 + * @param tAttrs
  57 + * @returns {{pre: Function, post: Function}}
  58 + */
  59 + compile: function(tElem, tAttrs) {
  60 + // TODO:获取所有的属性
  61 + var $name_attr = tAttrs["name"]; // 控件的名字
  62 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  63 + var $bcttinfoidsname_attr = tAttrs["bcttinfoidsname"]; // bind的model班次ids字段名
  64 +
  65 + // controlAs名字
  66 + var ctrlAs = '$saBcgroupCtrl';
  67 +
  68 + // 如果有required属性,添加angularjs required验证
  69 + if ($required_attr != undefined) {
  70 + //console.log(tElem.html());
  71 + tElem.find("div").attr("required", "");
  72 + }
  73 +
  74 + return {
  75 + pre: function(scope, element, attr) {
  76 + // TODO:
  77 + },
  78 +
  79 + /**
  80 + * 相当于link函数。
  81 + * @param scope
  82 + * @param element
  83 + * @param attr
  84 + */
  85 + post: function(scope, element, attr) {
  86 + // name属性
  87 + if ($name_attr) {
  88 + scope[ctrlAs]["$name_attr"] = $name_attr;
  89 + }
  90 +
  91 + // TODO:
  92 +
  93 +
  94 + /**
  95 + * 班次列表点击(班次列表中选中班次)
  96 + * @param $index
  97 + */
  98 + scope[ctrlAs].$$internal_bclist_click = function($index) {
  99 + var data_temp = scope[ctrlAs].$$data;
  100 + var data_temp2 = scope[ctrlAs].$$dataSelected;
  101 + var i = 0;
  102 + var isunique = true; // 是否已经选择过
  103 + if (data_temp && data_temp.length > $index) {
  104 + for (i = 0; i < data_temp2.length; i++) {
  105 + if (data_temp2[i].bcttinfoid == data_temp[$index].bcttinfoid) {
  106 + isunique = false;
  107 + break;
  108 + }
  109 + }
  110 + if (isunique) {
  111 + data_temp2.push({
  112 + bcttinfoid: data_temp[$index].bcttinfoid,
  113 + bcfcsj: data_temp[$index].bcfcsj,
  114 + bctype: data_temp[$index].bctype
  115 + });
  116 + }
  117 +
  118 + }
  119 + };
  120 + /**
  121 + * 选中的班次双击(删除选中的班次)
  122 + * @param $index
  123 + */
  124 + scope[ctrlAs].$$internal_selbclist_dbclick = function($index) {
  125 + var data_temp = scope[ctrlAs].$$dataSelected;
  126 + if (data_temp && data_temp.length > $index) {
  127 + data_temp.splice($index, 1);
  128 + }
  129 + };
  130 +
  131 +
  132 + /**
  133 + * 验证内部数据,更新外部model
  134 + */
  135 + scope[ctrlAs].$$internal_validate_model = function() {
  136 + var data_temp = scope[ctrlAs].$$dataSelected;
  137 + var bcttinfoIds = [];
  138 + var i = 0;
  139 +
  140 + if (data_temp &&
  141 + data_temp.length > 0) {
  142 +
  143 + for (i = 0; i < data_temp.length; i++) {
  144 + bcttinfoIds.push(data_temp[i].bcttinfoid);
  145 + }
  146 +
  147 + // 更新外部model字段
  148 + if ($bcttinfoidsname_attr) {
  149 + console.log("bcttinfoidsname=" + bcttinfoIds.join(','));
  150 + eval("scope[ctrlAs].model" + "." + $bcttinfoidsname_attr + " = bcttinfoIds.join(',');");
  151 + }
  152 +
  153 + // 更新内部model,用于外部验证
  154 + // 内部model的值暂时随意,以后再改
  155 + scope[ctrlAs].$$internalmodel = {desc: "ok"};
  156 +
  157 + scope[ctrlAs].$$data_bcdata_first_init = true;
  158 + scope[ctrlAs].$$data_bcttinfoids_first_init = true;
  159 +
  160 + } else {
  161 + scope[ctrlAs].$$internalmodel = undefined;
  162 + }
  163 +
  164 + };
  165 +
  166 + // 监控内部数据,$$data_selected 变化
  167 + scope.$watch(
  168 + function() {
  169 + console.log("长度:" + scope[ctrlAs].$$dataSelected.length);
  170 + return scope[ctrlAs].$$dataSelected;
  171 + },
  172 + function(newValue, oldValue) {
  173 + scope[ctrlAs].$$internal_validate_model();
  174 + },
  175 + true
  176 + );
  177 +
  178 + /**
  179 + * 验证数据是否初始化完成,
  180 + * 所谓的初始化就是内部所有的数据被有效设定过一次。
  181 + */
  182 + scope[ctrlAs].$$internal_validate_init = function() {
  183 + var self = scope[ctrlAs];
  184 +
  185 + var data_temp = self.$$data;
  186 + var dataSelect_temp = self.$$dataSelected;
  187 + var bcttinfoids = null;
  188 +
  189 + var i = 0;
  190 + var j = 0;
  191 +
  192 + if (self.$$data_bcdata_first_init &&
  193 + self.$$data_bcttinfoids_first_init) {
  194 + console.log("开始初始化数据");
  195 +
  196 + bcttinfoids = self.$$data_bcttinfoids_first_data ? self.$$data_bcttinfoids_first_data.split(",") : [];
  197 +
  198 + for (i = 0; i < bcttinfoids.length; i++) {
  199 + dataSelect_temp.push({
  200 + bcttinfoid: bcttinfoids[i]
  201 + });
  202 + for (j = 0; j < data_temp.length; j++) {
  203 + if (dataSelect_temp[i].bcttinfoid == data_temp[j].bcttinfoid) {
  204 + dataSelect_temp[i].bcfcsj = data_temp[j].bcfcsj;
  205 + dataSelect_temp[i].bctype = data_temp[j].bctype;
  206 + break;
  207 + }
  208 + }
  209 + }
  210 +
  211 + console.log("数据初始化完毕!");
  212 + }
  213 +
  214 + };
  215 +
  216 + // 监控初始化标志
  217 + scope.$watch(
  218 + function() {
  219 + return scope[ctrlAs].$$data_bcdata_first_init;
  220 + },
  221 + function(newValue, oldValue) {
  222 + scope[ctrlAs].$$internal_validate_init();
  223 + }
  224 + );
  225 + scope.$watch(
  226 + function() {
  227 + return scope[ctrlAs].$$data_bcttinfoids_first_init;
  228 + },
  229 + function(newValue, oldValue) {
  230 + scope[ctrlAs].$$internal_validate_init();
  231 + }
  232 + );
  233 +
  234 + // 监控内部数据的变化
  235 + attr.$observe("dataparams", function(value) {
  236 + if (value && value != "") {
  237 + if (value == '{}') {
  238 + return;
  239 + }
  240 +
  241 + console.log("bcgroup observe 监控 dataparams=" + value);
  242 +
  243 + timeTableDetailManageService_g.bcdetails.list(
  244 + JSON.parse(value),
  245 + function(result) {
  246 + // 获取值了
  247 + console.log("内部班次数据获取了");
  248 +
  249 + scope[ctrlAs].$$data = [];
  250 + for (var i = 0; i < result.length; i++) {
  251 + scope[ctrlAs].$$data.push({
  252 + bcttinfoid: result[i].id,
  253 + bcfcsj: result[i].fcsj,
  254 + bctype: result[i].bcType
  255 + });
  256 + }
  257 + if (scope[ctrlAs].$$data_bcdata_first_init &&
  258 + scope[ctrlAs].$$data_bcttinfoids_first_init) {
  259 +
  260 + scope[ctrlAs].$$dataSelected = [];
  261 + scope[ctrlAs].$$internalmodel = undefined;
  262 + }
  263 + scope[ctrlAs].$$data_bcdata_first_init = true;
  264 + },
  265 + function(result) {
  266 +
  267 + }
  268 + );
  269 + }
  270 + });
  271 + // 监控班次ids数据的变化
  272 + attr.$observe("bcttinfoidsvalue", function(value) {
  273 + if (value && value != "") {
  274 + console.log("observe 监控 bcttinfoidsvalue=" + value);
  275 + scope[ctrlAs].$$data_bcttinfoids_first_init = true;
  276 + scope[ctrlAs].$$data_bcttinfoids_first_data = value;
  277 + }
  278 + });
  279 +
  280 + }
  281 + }
  282 +
  283 + }
  284 + }
  285 + }
286 286 ]);
287 287 \ No newline at end of file
... ...
src/main/resources/static/pages/scheduleApp/module/common/dts2/dateGroup/saDategroup.js
1   -
2   -
3   -/**
4   - * saDategroup指令
5   - * 属性如下:
6   - * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
7   - * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
8   - * dcname(必须):绑定的model字段名,如:dcname=xl.id
9   - * name(必须):控件的名字
10   - * required(可选):是否要用required验证
11   - * disabled(可选):标示框是否可选
12   - *
13   - */
14   -angular.module('ScheduleApp').directive('saDategroup', [
15   - '$filter',
16   - function($filter) {
17   - return {
18   - restrict: 'E',
19   - templateUrl: '/pages/scheduleApp/module/common/dts2/dateGroup/saDategroupTemplate.html',
20   - scope: {
21   - model: "=" // 独立作用域,关联外部的模型object
22   - },
23   - controllerAs: "$saDategroupCtrl",
24   - bindToController: true,
25   - controller: function($scope) {
26   - var self = this;
27   - self.$$data = []; // 内部的数据
28   - self.$$date_select; // 内部选中的日期
29   -
30   - //// 测试数据
31   - //self.$$data = [
32   - // {datestr: '2011-01-01', ischecked: true},
33   - // {datestr: '2011-01-01', ischecked: true},
34   - // {datestr: '2011-01-01', ischecked: true}
35   - //];
36   - },
37   -
38   - /**
39   - * 此阶段可以改dom结构,此时angular还没扫描指令,
40   - * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
41   - * @param tElem
42   - * @param tAttrs
43   - * @returns {{pre: Function, post: Function}}
44   - */
45   - compile: function(tElem, tAttrs) {
46   - // 获取所有的属性
47   - var $name_attr = tAttrs["name"]; // 控件的名字
48   - var $required_attr = tAttrs["required"]; // 是否需要required验证
49   - var $disabled_attr = tAttrs["disabled"]; // 是否禁用
50   - var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
51   -
52   - // controlAs名字
53   - var ctrlAs = '$saDategroupCtrl';
54   -
55   - // 如果有required属性,添加angularjs required验证
56   - if ($required_attr != undefined) {
57   - //console.log(tElem.html());
58   - tElem.find("div").attr("required", "");
59   - }
60   - // 如果有disabled属性,添加禁用标志
61   - if ($disabled_attr != undefined) {
62   - tElem.find("input").attr("ng-disabled", "true");
63   - tElem.find("div").attr("ng-disabled", "true");
64   - }
65   -
66   - return {
67   - pre: function (scope, element, attr) {
68   - // TODO:
69   - },
70   - /**
71   - * 相当于link函数。
72   - * @param scope
73   - * @param element
74   - * @param attr
75   - */
76   - post: function (scope, element, attr) {
77   - // name属性
78   - if ($name_attr) {
79   - scope[ctrlAs]["$name_attr"] = $name_attr;
80   - }
81   -
82   -
83   - // 日期open属性,及方法
84   - scope[ctrlAs].$$specialDateOpen = false;
85   - scope[ctrlAs].$$specialDate_open = function() {
86   - scope[ctrlAs].$$specialDateOpen = true;
87   - };
88   -
89   - // 监控选择的日期
90   - scope.$watch(
91   - function() {
92   - return scope[ctrlAs]['$$date_select'];
93   - },
94   - function(newValue, oldValue) {
95   - if (newValue) {
96   - //console.log("saDategroup--->selectdate:" + newValue);
97   - // 调用内置filter,转换日期到yyyy-MM-dd格式
98   - var text = $filter('date')(newValue, 'yyyy-MM-dd');
99   - var i;
100   - var isexist = false; // 日期是否已经选择标识
101   - for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
102   - if (scope[ctrlAs]["$$data"][i].datestr == text) {
103   - isexist = true;
104   - break;
105   - }
106   - }
107   - if (!isexist) {
108   - scope[ctrlAs]["$$data"].push(
109   - {
110   - datestr: text,
111   - ischecked: true
112   - }
113   - );
114   - }
115   -
116   - }
117   -
118   - }
119   - );
120   -
121   - /**
122   - * 日期点击事件处理函数。
123   - * @param $index 索引
124   - */
125   - scope[ctrlAs].$$internal_datestr_click = function($index) {
126   - scope[ctrlAs].$$data.splice($index, 1);
127   - };
128   -
129   - // 测试使用watch监控$$data的变化
130   - scope.$watch(
131   - function() {
132   - return scope[ctrlAs]['$$data'];
133   - },
134   - function(newValue, oldValue) {
135   - // 根据$$data生成对应的数据
136   - var special_days_arr = [];
137   - var i;
138   - for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
139   - special_days_arr.push(scope[ctrlAs]["$$data"][i].datestr);
140   - }
141   -
142   - scope[ctrlAs].$$internalmodel = special_days_arr.join(",");
143   - console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);
144   -
145   - // 更新model
146   - if ($dcname_attr) {
147   - eval("scope[ctrlAs].model" + "." + $dcname_attr + " = special_days_arr.join(',');");
148   - }
149   - },
150   - true
151   - );
152   -
153   - // 监控dcvalue model值变换
154   - attr.$observe("dcvalue", function(value) {
155   - console.log("saDategroup 监控dc1 model值变换:" + value);
156   - if (value) {
157   - // 根据value值,修改$$data里的值
158   - var date_array = value.split(",");
159   - var i;
160   - scope[ctrlAs]["$$data"] = [];
161   - for (i = 0; i < date_array.length; i++) {
162   - scope[ctrlAs]["$$data"].push(
163   - {
164   - datestr: date_array[i],
165   - ischecked: true
166   - }
167   - );
168   - }
169   -
170   -
171   -
172   -
173   -
174   -
175   -
176   -
177   -
178   - }
179   - });
180   -
181   - }
182   -
183   - };
184   - }
185   - }
186   - }
187   -]);
188   -
  1 +
  2 +
  3 +/**
  4 + * saDategroup指令
  5 + * 属性如下:
  6 + * model(必须):指定一个外部object,独立作用域,如:model=ctrl.employeeInfoForSave
  7 + * dcvalue(必须):绑定的model字段值,如:dcvalue={{ctrl.employeeInfoForSave.xl.id}}
  8 + * dcname(必须):绑定的model字段名,如:dcname=xl.id
  9 + * name(必须):控件的名字
  10 + * required(可选):是否要用required验证
  11 + * disabled(可选):标示框是否可选
  12 + *
  13 + */
  14 +angular.module('ScheduleApp').directive('saDategroup', [
  15 + '$filter',
  16 + function($filter) {
  17 + return {
  18 + restrict: 'E',
  19 + templateUrl: '/pages/scheduleApp/module/common/dts2/dateGroup/saDategroupTemplate.html',
  20 + scope: {
  21 + model: "=" // 独立作用域,关联外部的模型object
  22 + },
  23 + controllerAs: "$saDategroupCtrl",
  24 + bindToController: true,
  25 + controller: function($scope) {
  26 + var self = this;
  27 + self.$$data = []; // 内部的数据
  28 + self.$$date_select; // 内部选中的日期
  29 +
  30 + //// 测试数据
  31 + //self.$$data = [
  32 + // {datestr: '2011-01-01', ischecked: true},
  33 + // {datestr: '2011-01-01', ischecked: true},
  34 + // {datestr: '2011-01-01', ischecked: true}
  35 + //];
  36 + },
  37 +
  38 + /**
  39 + * 此阶段可以改dom结构,此时angular还没扫描指令,
  40 + * 这里就可以动态添加其他angularjs的指令字符串,如required指令字符串。
  41 + * @param tElem
  42 + * @param tAttrs
  43 + * @returns {{pre: Function, post: Function}}
  44 + */
  45 + compile: function(tElem, tAttrs) {
  46 + // 获取所有的属性
  47 + var $name_attr = tAttrs["name"]; // 控件的名字
  48 + var $required_attr = tAttrs["required"]; // 是否需要required验证
  49 + var $disabled_attr = tAttrs["disabled"]; // 是否禁用
  50 + var $dcname_attr = tAttrs["dcname"]; // 绑定的model字段名
  51 +
  52 + // controlAs名字
  53 + var ctrlAs = '$saDategroupCtrl';
  54 +
  55 + // 如果有required属性,添加angularjs required验证
  56 + if ($required_attr != undefined) {
  57 + //console.log(tElem.html());
  58 + tElem.find("div").attr("required", "");
  59 + }
  60 + // 如果有disabled属性,添加禁用标志
  61 + if ($disabled_attr != undefined) {
  62 + tElem.find("input").attr("ng-disabled", "true");
  63 + tElem.find("div").attr("ng-disabled", "true");
  64 + }
  65 +
  66 + return {
  67 + pre: function (scope, element, attr) {
  68 + // TODO:
  69 + },
  70 + /**
  71 + * 相当于link函数。
  72 + * @param scope
  73 + * @param element
  74 + * @param attr
  75 + */
  76 + post: function (scope, element, attr) {
  77 + // name属性
  78 + if ($name_attr) {
  79 + scope[ctrlAs]["$name_attr"] = $name_attr;
  80 + }
  81 +
  82 +
  83 + // 日期open属性,及方法
  84 + scope[ctrlAs].$$specialDateOpen = false;
  85 + scope[ctrlAs].$$specialDate_open = function() {
  86 + scope[ctrlAs].$$specialDateOpen = true;
  87 + };
  88 +
  89 + // 监控选择的日期
  90 + scope.$watch(
  91 + function() {
  92 + return scope[ctrlAs]['$$date_select'];
  93 + },
  94 + function(newValue, oldValue) {
  95 + if (newValue) {
  96 + //console.log("saDategroup--->selectdate:" + newValue);
  97 + // 调用内置filter,转换日期到yyyy-MM-dd格式
  98 + var text = $filter('date')(newValue, 'yyyy-MM-dd');
  99 + var i;
  100 + var isexist = false; // 日期是否已经选择标识
  101 + for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
  102 + if (scope[ctrlAs]["$$data"][i].datestr == text) {
  103 + isexist = true;
  104 + break;
  105 + }
  106 + }
  107 + if (!isexist) {
  108 + scope[ctrlAs]["$$data"].push(
  109 + {
  110 + datestr: text,
  111 + ischecked: true
  112 + }
  113 + );
  114 + }
  115 +
  116 + }
  117 +
  118 + }
  119 + );
  120 +
  121 + /**
  122 + * 日期点击事件处理函数。
  123 + * @param $index 索引
  124 + */
  125 + scope[ctrlAs].$$internal_datestr_click = function($index) {
  126 + scope[ctrlAs].$$data.splice($index, 1);
  127 + };
  128 +
  129 + // 测试使用watch监控$$data的变化
  130 + scope.$watch(
  131 + function() {
  132 + return scope[ctrlAs]['$$data'];
  133 + },
  134 + function(newValue, oldValue) {
  135 + // 根据$$data生成对应的数据
  136 + var special_days_arr = [];
  137 + var i;
  138 + for (i = 0; i < scope[ctrlAs]["$$data"].length; i++) {
  139 + special_days_arr.push(scope[ctrlAs]["$$data"][i].datestr);
  140 + }
  141 +
  142 + scope[ctrlAs].$$internalmodel = special_days_arr.join(",");
  143 + console.log("bbbbbbbb--->" + scope[ctrlAs].$$internalmodel);
  144 +
  145 + // 更新model
  146 + if ($dcname_attr) {
  147 + eval("scope[ctrlAs].model" + "." + $dcname_attr + " = special_days_arr.join(',');");
  148 + }
  149 + },
  150 + true
  151 + );
  152 +
  153 + // 监控dcvalue model值变换
  154 + attr.$observe("dcvalue", function(value) {
  155 + console.log("saDategroup 监控dc1 model值变换:" + value);
  156 + if (value) {
  157 + // 根据value值,修改$$data里的值
  158 + var date_array = value.split(",");
  159 + var i;
  160 + scope[ctrlAs]["$$data"] = [];
  161 + for (i = 0; i < date_array.length; i++) {
  162 + scope[ctrlAs]["$$data"].push(
  163 + {
  164 + datestr: date_array[i],
  165 + ischecked: true
  166 + }
  167 + );
  168 + }
  169 +
  170 +
  171 +
  172 +
  173 +
  174 +
  175 +
  176 +
  177 +
  178 + }
  179 + });
  180 +
  181 + }
  182 +
  183 + };
  184 + }
  185 + }
  186 + }
  187 +]);
  188 +
... ...