eoss-ui 0.6.52 → 0.6.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/lib/button-group.js +58 -55
  2. package/lib/button.js +58 -55
  3. package/lib/checkbox-group.js +61 -58
  4. package/lib/data-table-form.js +58 -55
  5. package/lib/data-table.js +65 -62
  6. package/lib/date-picker.js +58 -55
  7. package/lib/dialog.js +58 -55
  8. package/lib/eoss-ui.common.js +912 -845
  9. package/lib/flow-group.js +58 -55
  10. package/lib/flow-list.js +153 -147
  11. package/lib/flow.js +467 -424
  12. package/lib/form.js +62 -59
  13. package/lib/handle-user.js +58 -55
  14. package/lib/handler.js +58 -55
  15. package/lib/icon.js +58 -55
  16. package/lib/index.js +1 -1
  17. package/lib/input-number.js +58 -55
  18. package/lib/input.js +59 -56
  19. package/lib/login.js +61 -58
  20. package/lib/main.js +258 -235
  21. package/lib/menu.js +1 -1
  22. package/lib/nav.js +61 -58
  23. package/lib/page.js +58 -55
  24. package/lib/pagination.js +58 -55
  25. package/lib/player.js +58 -55
  26. package/lib/qr-code.js +71 -68
  27. package/lib/radio-group.js +61 -58
  28. package/lib/retrial-auth.js +58 -55
  29. package/lib/select-ganged.js +59 -56
  30. package/lib/select.js +61 -57
  31. package/lib/selector-panel.js +61 -58
  32. package/lib/selector.js +58 -55
  33. package/lib/sizer.js +58 -55
  34. package/lib/steps.js +61 -58
  35. package/lib/switch.js +58 -55
  36. package/lib/table-form.js +58 -55
  37. package/lib/tabs.js +58 -55
  38. package/lib/theme-chalk/flow.css +1 -1
  39. package/lib/theme-chalk/index.css +1 -1
  40. package/lib/theme-chalk/upload.css +1 -1
  41. package/lib/tips.js +61 -58
  42. package/lib/tree-group.js +58 -55
  43. package/lib/tree.js +61 -58
  44. package/lib/upload.js +71 -68
  45. package/lib/utils/util.js +54 -51
  46. package/lib/wujie.js +58 -55
  47. package/lib/wxlogin.js +58 -55
  48. package/package.json +159 -159
  49. package/packages/button/index.js +5 -5
  50. package/packages/button/src/main.vue +418 -418
  51. package/packages/button-group/index.js +5 -5
  52. package/packages/button-group/src/main.vue +298 -298
  53. package/packages/calendar/index.js +5 -5
  54. package/packages/card/index.js +5 -5
  55. package/packages/card/src/main.vue +156 -156
  56. package/packages/cascader/index.js +5 -5
  57. package/packages/cascader/src/main.vue +168 -168
  58. package/packages/checkbox-group/index.js +5 -5
  59. package/packages/checkbox-group/src/main.vue +333 -333
  60. package/packages/clients/index.js +5 -5
  61. package/packages/clients/src/main.vue +144 -144
  62. package/packages/data-table/index.js +5 -5
  63. package/packages/data-table/src/children.vue +39 -39
  64. package/packages/data-table/src/column.vue +989 -989
  65. package/packages/data-table/src/main.vue +1822 -1822
  66. package/packages/data-table/src/sizer.vue +195 -195
  67. package/packages/data-table-form/index.js +5 -5
  68. package/packages/data-table-form/src/checkbox.vue +101 -101
  69. package/packages/data-table-form/src/colgroup.vue +17 -17
  70. package/packages/data-table-form/src/main.vue +181 -181
  71. package/packages/data-table-form/src/radio.vue +65 -65
  72. package/packages/data-table-form/src/table.vue +233 -233
  73. package/packages/data-table-form/src/tbody.vue +336 -336
  74. package/packages/data-table-form/src/thead.vue +68 -68
  75. package/packages/date-picker/index.js +5 -5
  76. package/packages/date-picker/src/main.vue +236 -236
  77. package/packages/dialog/index.js +5 -5
  78. package/packages/enable-drag/index.js +5 -5
  79. package/packages/enterprise/index.js +5 -5
  80. package/packages/enterprise/src/main.vue +66 -66
  81. package/packages/error-page/index.js +5 -5
  82. package/packages/error-page/src/main.vue +44 -44
  83. package/packages/flow/index.js +5 -5
  84. package/packages/flow/src/component/CommonOpinions.vue +345 -345
  85. package/packages/flow/src/component/CustomPreset.vue +322 -322
  86. package/packages/flow/src/component/FileList.vue +99 -99
  87. package/packages/flow/src/component/Preset.vue +255 -255
  88. package/packages/flow/src/component/SendMsg.vue +229 -229
  89. package/packages/flow/src/component/TimeLimit.vue +190 -190
  90. package/packages/flow/src/component/taskUnionExamine.vue +611 -611
  91. package/packages/flow/src/form.vue +121 -121
  92. package/packages/flow/src/freeStartFlow.vue +2843 -2843
  93. package/packages/flow/src/main.vue +3131 -3131
  94. package/packages/flow/src/processForm.vue +1031 -1031
  95. package/packages/flow/src/processReject.vue +293 -293
  96. package/packages/flow/src/reset.vue +900 -902
  97. package/packages/flow/src/startTaskRead.vue +641 -597
  98. package/packages/flow/src/supervise.vue +138 -138
  99. package/packages/flow/src/table.vue +58 -58
  100. package/packages/flow-group/index.js +5 -5
  101. package/packages/flow-group/src/main.vue +688 -688
  102. package/packages/flow-list/index.js +5 -5
  103. package/packages/flow-list/src/main.vue +1437 -1434
  104. package/packages/form/index.js +5 -5
  105. package/packages/form/src/main.vue +3583 -3583
  106. package/packages/form/src/table.vue +1426 -1426
  107. package/packages/handle-user/index.js +5 -5
  108. package/packages/handle-user/src/main.vue +138 -138
  109. package/packages/handler/index.js +5 -5
  110. package/packages/handler/src/main.vue +493 -493
  111. package/packages/icon/index.js +5 -5
  112. package/packages/icon/src/main.vue +101 -101
  113. package/packages/icons/index.js +5 -5
  114. package/packages/icons/src/main.vue +81 -81
  115. package/packages/input/index.js +5 -5
  116. package/packages/input/src/main.vue +356 -356
  117. package/packages/input-number/index.js +5 -5
  118. package/packages/input-number/src/main.vue +106 -106
  119. package/packages/label/index.js +5 -5
  120. package/packages/label/src/main.vue +457 -457
  121. package/packages/layout/index.js +5 -5
  122. package/packages/layout/src/item.vue +152 -152
  123. package/packages/layout/src/main.vue +31 -31
  124. package/packages/login/index.js +5 -5
  125. package/packages/login/src/main.vue +1935 -1935
  126. package/packages/login/src/resetPassword.vue +562 -562
  127. package/packages/main/index.js +5 -5
  128. package/packages/main/src/default/index.vue +7 -1
  129. package/packages/main/src/default/message.vue +249 -249
  130. package/packages/main/src/default/notice.vue +157 -157
  131. package/packages/main/src/default/userinfo.vue +503 -503
  132. package/packages/main/src/main.vue +4 -1
  133. package/packages/main/src/public/online.vue +89 -89
  134. package/packages/main/src/public/search.vue +466 -461
  135. package/packages/main/src/public/settings.vue +221 -221
  136. package/packages/main/src/simplicity/apps.vue +388 -388
  137. package/packages/main/src/simplicity/avatar.vue +82 -82
  138. package/packages/main/src/simplicity/handler.vue +259 -259
  139. package/packages/main/src/simplicity/index.vue +2064 -2064
  140. package/packages/main/src/simplicity/lists.vue +84 -84
  141. package/packages/main/src/simplicity/menu-list.vue +128 -128
  142. package/packages/main/src/simplicity/message.vue +259 -259
  143. package/packages/main/src/simplicity/notice.vue +190 -190
  144. package/packages/main/src/simplicity/router-page.vue +45 -45
  145. package/packages/main/src/simplicity/sub-menu.vue +241 -241
  146. package/packages/main/src/simplicity/user.vue +257 -257
  147. package/packages/main/src/simplicity/userinfo.vue +312 -312
  148. package/packages/menu/index.js +5 -5
  149. package/packages/menu/src/main.vue +536 -536
  150. package/packages/nav/index.js +5 -5
  151. package/packages/nav/src/main.vue +351 -351
  152. package/packages/notify/index.js +5 -5
  153. package/packages/notify/src/main.vue +538 -538
  154. package/packages/page/index.js +5 -5
  155. package/packages/page/src/main.vue +167 -167
  156. package/packages/pagination/index.js +5 -5
  157. package/packages/pagination/src/main.vue +96 -96
  158. package/packages/player/index.js +5 -5
  159. package/packages/player/src/main.vue +194 -194
  160. package/packages/qr-code/index.js +5 -5
  161. package/packages/qr-code/src/main.vue +170 -170
  162. package/packages/radio-group/index.js +6 -6
  163. package/packages/radio-group/src/main.vue +319 -319
  164. package/packages/retrial-auth/index.js +5 -5
  165. package/packages/retrial-auth/src/main.vue +280 -280
  166. package/packages/select/index.js +5 -5
  167. package/packages/select/src/main.vue +776 -775
  168. package/packages/select-ganged/index.js +5 -5
  169. package/packages/select-ganged/src/main.vue +724 -724
  170. package/packages/selector/index.js +5 -5
  171. package/packages/selector/src/main.vue +687 -687
  172. package/packages/selector-panel/index.js +5 -5
  173. package/packages/selector-panel/src/main.vue +1027 -1027
  174. package/packages/selector-panel/src/selection.vue +177 -177
  175. package/packages/selector-panel/src/tree.vue +129 -129
  176. package/packages/sizer/index.js +5 -5
  177. package/packages/sizer/src/main.vue +254 -254
  178. package/packages/steps/index.js +5 -5
  179. package/packages/steps/src/main.vue +181 -181
  180. package/packages/switch/index.js +5 -5
  181. package/packages/switch/src/main.vue +154 -154
  182. package/packages/table-form/index.js +5 -5
  183. package/packages/tabs/index.js +5 -5
  184. package/packages/tabs/src/main.vue +788 -788
  185. package/packages/tabs-panel/index.js +5 -5
  186. package/packages/tabs-panel/src/main.vue +29 -29
  187. package/packages/theme-chalk/lib/flow.css +1 -1
  188. package/packages/theme-chalk/lib/index.css +1 -1
  189. package/packages/theme-chalk/lib/upload.css +1 -1
  190. package/packages/theme-chalk/src/base.scss +260 -260
  191. package/packages/theme-chalk/src/button-group.scss +175 -175
  192. package/packages/theme-chalk/src/button.scss +24 -24
  193. package/packages/theme-chalk/src/calendar.scss +113 -113
  194. package/packages/theme-chalk/src/card.scss +99 -99
  195. package/packages/theme-chalk/src/checkbox-group.scss +8 -8
  196. package/packages/theme-chalk/src/clients.scss +87 -87
  197. package/packages/theme-chalk/src/data-table-form.scss +67 -67
  198. package/packages/theme-chalk/src/data-table.scss +293 -293
  199. package/packages/theme-chalk/src/date-picker.scss +7 -7
  200. package/packages/theme-chalk/src/dialog.scss +77 -77
  201. package/packages/theme-chalk/src/enable-drag.scss +181 -181
  202. package/packages/theme-chalk/src/enterprise.scss +5 -5
  203. package/packages/theme-chalk/src/error-page.scss +18 -18
  204. package/packages/theme-chalk/src/flow-group.scss +110 -110
  205. package/packages/theme-chalk/src/flow-list.scss +36 -36
  206. package/packages/theme-chalk/src/flow.scss +336 -335
  207. package/packages/theme-chalk/src/form.scss +496 -496
  208. package/packages/theme-chalk/src/handle-user.scss +40 -40
  209. package/packages/theme-chalk/src/handler.scss +143 -143
  210. package/packages/theme-chalk/src/icon.scss +1789 -1789
  211. package/packages/theme-chalk/src/icons.scss +99 -99
  212. package/packages/theme-chalk/src/input.scss +9 -9
  213. package/packages/theme-chalk/src/label.scss +24 -24
  214. package/packages/theme-chalk/src/layout.scss +46 -46
  215. package/packages/theme-chalk/src/login.scss +969 -969
  216. package/packages/theme-chalk/src/main.scss +663 -663
  217. package/packages/theme-chalk/src/menu.scss +222 -222
  218. package/packages/theme-chalk/src/mixins/color.scss +117 -117
  219. package/packages/theme-chalk/src/nav.scss +111 -111
  220. package/packages/theme-chalk/src/page.scss +3 -3
  221. package/packages/theme-chalk/src/pagination.scss +29 -29
  222. package/packages/theme-chalk/src/player.scss +9 -9
  223. package/packages/theme-chalk/src/qr-code.scss +17 -17
  224. package/packages/theme-chalk/src/radio-group.scss +9 -9
  225. package/packages/theme-chalk/src/retrial-auth.scss +38 -38
  226. package/packages/theme-chalk/src/select-ganged.scss +8 -8
  227. package/packages/theme-chalk/src/select.scss +8 -8
  228. package/packages/theme-chalk/src/selector-panel.scss +204 -204
  229. package/packages/theme-chalk/src/selector.scss +91 -91
  230. package/packages/theme-chalk/src/simplicity.scss +1265 -1265
  231. package/packages/theme-chalk/src/sizer.scss +36 -36
  232. package/packages/theme-chalk/src/steps.scss +88 -88
  233. package/packages/theme-chalk/src/switch.scss +3 -3
  234. package/packages/theme-chalk/src/table-form.scss +1 -1
  235. package/packages/theme-chalk/src/tabs.scss +87 -87
  236. package/packages/theme-chalk/src/tips.scss +7 -7
  237. package/packages/theme-chalk/src/toolbar.scss +179 -179
  238. package/packages/theme-chalk/src/tree-group.scss +72 -72
  239. package/packages/theme-chalk/src/tree.scss +165 -165
  240. package/packages/theme-chalk/src/upload.scss +168 -167
  241. package/packages/theme-chalk/src/wxlogin.scss +3 -3
  242. package/packages/tips/index.js +5 -5
  243. package/packages/tips/src/main.vue +141 -141
  244. package/packages/toolbar/index.js +5 -5
  245. package/packages/toolbar/src/main.vue +430 -430
  246. package/packages/tree/index.js +5 -5
  247. package/packages/tree/src/main.vue +2 -2
  248. package/packages/tree-group/index.js +5 -5
  249. package/packages/upload/index.js +5 -5
  250. package/packages/upload/src/main.vue +1343 -1339
  251. package/packages/upload/src/picture.js +15 -15
  252. package/packages/wujie/index.js +5 -5
  253. package/packages/wujie/src/main.vue +145 -145
  254. package/packages/wxlogin/index.js +5 -5
  255. package/packages/wxlogin/src/main.vue +128 -128
  256. package/src/config/api.js +281 -281
  257. package/src/config/image.js +2 -2
  258. package/src/index.js +1 -1
  259. package/src/utils/bus.js +3 -3
  260. package/src/utils/date-util.js +312 -312
  261. package/src/utils/http.js +50 -50
  262. package/src/utils/rules.js +18 -18
  263. package/src/utils/store.js +21 -21
  264. package/src/utils/util.js +15 -12
  265. package/src/utils/webSocket.js +107 -107
@@ -1,775 +1,776 @@
1
- <script>
2
- import { findSysCode, getDictList } from 'eoss-ui/src/config/api.js';
3
- import { debounce } from 'throttle-debounce';
4
- import store from 'eoss-ui/src/utils/store';
5
- import util from 'eoss-ui/src/utils/util';
6
- export default {
7
- name: 'EsSelect',
8
- componentName: 'EsSelect',
9
- inheritAttrs: false,
10
- provide() {
11
- return {
12
- esSelect: this
13
- };
14
- },
15
- inject: {
16
- esForm: {
17
- default: ''
18
- }
19
- },
20
- props: {
21
- service: String,
22
- value: [String, Array, Object, Number],
23
- method: {
24
- type: String,
25
- default: 'get'
26
- },
27
- param: {
28
- type: Object,
29
- default() {
30
- return {};
31
- }
32
- },
33
- // 显示隐藏组件
34
- display: {
35
- type: Boolean,
36
- default: true
37
- },
38
- // 是否不渲染组件
39
- hide: {
40
- type: Boolean,
41
- default: false
42
- },
43
- valueType: {
44
- type: String,
45
- default: 'string',
46
- validator: function (value) {
47
- return ['string', 'object'].includes(value);
48
- }
49
- },
50
- // 选择项的值字段
51
- valueKey: {
52
- type: String,
53
- default: 'value'
54
- },
55
- // 指定选择项显示值的键名,data元素是对象类型时必填
56
- labelKey: {
57
- type: String,
58
- default: 'name'
59
- },
60
- data: {
61
- type: Array,
62
- default() {
63
- return [];
64
- }
65
- },
66
- // 远程搜索
67
- remote: Boolean,
68
- remoteKey: {
69
- type: String,
70
- default: 'searchKey'
71
- },
72
- remoteMethod: Function,
73
- // 选择项远程地址
74
- url: String,
75
- // 选择项获取代码表数据(优先级大于url)
76
- sysCode: String,
77
- filtrate: [String, Object, Array],
78
- filtrateKey: {
79
- type: String,
80
- default: 'pid'
81
- },
82
- readonly: Boolean,
83
- separator: {
84
- type: String,
85
- default: '-'
86
- },
87
- symbol: {
88
- type: String,
89
- default: ','
90
- },
91
- plain: Boolean,
92
- where: Object,
93
- parseData: Function,
94
- disabled: Boolean,
95
- // 是否下拉树选择
96
- tree: {
97
- type: [Boolean, Object],
98
- default: false
99
- },
100
- // 父级是否可选
101
- parentCheck: {
102
- type: Boolean,
103
- default: true
104
- },
105
- // 父级可选时父级是否作为单独的值
106
- parentAsValue: {
107
- type: Boolean,
108
- default: true
109
- },
110
- group: Boolean,
111
- multiple: Boolean,
112
- defaultValue: Boolean,
113
- onExpand: Function,
114
- onLoadsub: Function,
115
- subParamKey: Object,
116
- lazy: Boolean,
117
- //是否请求代码表
118
- ajax: {
119
- type: Boolean,
120
- default: true
121
- },
122
- isNoParamRequest: {
123
- type: Boolean,
124
- default: true
125
- },
126
- dataKey: String
127
- },
128
- data() {
129
- return {
130
- loading: false,
131
- options: '',
132
- valKey: this.valueKey,
133
- label: this.labelKey,
134
- hidden: false,
135
- canceled: false
136
- };
137
- },
138
- computed: {
139
- isObject() {
140
- if (this.valueType === 'object') {
141
- return true;
142
- }
143
- if (
144
- util.isObject(this.value) ||
145
- (this.value && this.value[0] && util.isObject(this.value[0]))
146
- ) {
147
- return true;
148
- }
149
- return false;
150
- },
151
- isRemote() {
152
- return new Boolean(this.remote);
153
- },
154
- results() {
155
- if (this.options.length) {
156
- return this.options;
157
- }
158
- if (this.filtrate) {
159
- if (Array.isArray(this.filtrate) && this.filtrate.length) {
160
- let ary = [];
161
- this.filtrate.forEach((items) => {
162
- let val = typeof items === 'string' ? items : items[this.valKey];
163
- ary = ary.concat(
164
- this.data.filter((item) => {
165
- return item[this.filtrateKey] == val;
166
- })
167
- );
168
- });
169
- return ary;
170
- } else {
171
- let val =
172
- typeof this.filtrate === 'string'
173
- ? this.filtrate
174
- : this.filtrate[this.valKey];
175
- return this.data.filter((item) => {
176
- return item[this.filtrateKey] == val;
177
- });
178
- }
179
- }
180
- return this.data;
181
- },
182
- models: {
183
- get() {
184
- return this.value;
185
- },
186
- set(val) {
187
- return val;
188
- }
189
- },
190
- findCode() {
191
- if (this.service) {
192
- return `/${this.service}${getDictList}`;
193
- }
194
- return findSysCode;
195
- }
196
- },
197
- watch: {
198
- sysCode: {
199
- immediate: true,
200
- handler(val, old) {
201
- if (val && val !== old) {
202
- this.label = this.service ? 'label' : 'shortName';
203
- this.valKey = this.service ? 'value' : 'cciValue';
204
- const options = store.get(val);
205
- if (options) {
206
- this.options = JSON.parse(JSON.stringify(options));
207
- } else {
208
- this.getData(val);
209
- }
210
- }
211
- }
212
- },
213
- url: {
214
- immediate: true,
215
- handler(val, old) {
216
- if (val && old !== val && !this.sysCode) {
217
- this.getData(this.sysCode);
218
- }
219
- }
220
- },
221
- param: {
222
- deep: true,
223
- handler(val, old) {
224
- if (this.url && JSON.stringify(val) !== JSON.stringify(old)) {
225
- this.options = [];
226
- this.getData(this.sysCode);
227
- }
228
- }
229
- }
230
- },
231
- beforeCreate() {
232
- this.getData = debounce(500, (sysCode, param, reload) => {
233
- this.getDatas(sysCode, param, reload);
234
- });
235
- },
236
- created() {
237
- this.bindEventBus();
238
- },
239
- mounted() {},
240
- methods: {
241
- createOption({ filtrate, data, readonly = false, h }) {
242
- let filte =
243
- filtrate && util.isObject(filtrate) ? filtrate[this.valKey] : filtrate;
244
- let eles = [];
245
- data.forEach((item) => {
246
- if (this.models === undefined && item.selected) {
247
- this.$emit(
248
- 'input',
249
- this.valueType === 'object' ? item : item[this.valKey]
250
- );
251
- }
252
- if (
253
- (Object.prototype.hasOwnProperty.call(item, 'children') ||
254
- Object.prototype.hasOwnProperty.call(item, 'options')) &&
255
- (item.children || item.options)
256
- ) {
257
- const children = item.children || item.options;
258
- if (readonly) {
259
- eles.push(
260
- this.createOption({ filtrate, data: children, readonly, h })
261
- );
262
- } else {
263
- eles.push(
264
- h(
265
- 'el-option-group',
266
- { attrs: { label: item[this.label] || item.label } },
267
- this.createOption({ filtrate, data: children, readonly, h })
268
- )
269
- );
270
- }
271
- } else {
272
- if (readonly) {
273
- if (item[this.valKey] === filte) {
274
- eles.push(item[this.label] || item.label);
275
- }
276
- } else {
277
- if (
278
- filte === null ||
279
- filte === undefined ||
280
- filte === '' ||
281
- filte === item[this.filtrateKey]
282
- ) {
283
- if (typeof item === 'string') {
284
- eles.push(
285
- h('el-option', {
286
- attrs: {
287
- label: item,
288
- value: item
289
- }
290
- })
291
- );
292
- } else {
293
- let content = [];
294
- const labelContent = item[this.label] || item.label;
295
- //判断它是否是html字符串
296
- if (
297
- typeof labelContent === 'string' &&
298
- /<[^>]+>/.test(labelContent)
299
- ) {
300
- // 如果是 HTML 字符串,创建对应的 VNode
301
- content = [
302
- h('div', { domProps: { innerHTML: labelContent } })
303
- ];
304
- } else {
305
- content = [labelContent];
306
- }
307
- if (item.render) {
308
- content = [item.render(h, item)];
309
- }
310
- if (item.tips) {
311
- let attrs =
312
- typeof item.tips == 'string'
313
- ? { content: item.tips }
314
- : item.tips;
315
- content.push(
316
- h('es-tips', {
317
- attrs: attrs
318
- })
319
- );
320
- }
321
-
322
- eles.push(
323
- h(
324
- 'el-option',
325
- {
326
- attrs: {
327
- label: item[this.label] || item.label,
328
- value: this.isObject ? item : item[this.valKey],
329
- disabled: item.disabled
330
- }
331
- },
332
- content
333
- )
334
- );
335
- }
336
- }
337
- }
338
- }
339
- });
340
- return eles;
341
- },
342
- getDatas(sysCode, param, reload) {
343
- if (
344
- !reload &&
345
- (!this.ajax ||
346
- (!this.isNoParamRequest && Object.keys(this.param).length == 0))
347
- ) {
348
- return false;
349
- }
350
- let params = {};
351
- if (this.results.length === 0 || reload) {
352
- params = util.extend(
353
- {},
354
- this.param,
355
- sysCode ? { sysAppCode: sysCode, code: sysCode } : {},
356
- param ? param : {}
357
- );
358
- } else {
359
- return false;
360
- }
361
- if (!sysCode && !this.url) {
362
- return false;
363
- }
364
- this.loading = true;
365
- util
366
- .ajax({
367
- url: sysCode ? this.findCode : this.url,
368
- method: this.method,
369
- params: params,
370
- data: params
371
- })
372
- .then((res) => {
373
- this.loading = false;
374
- this.canceled = false;
375
- if (res.rCode === 0) {
376
- if (this.parseData) {
377
- this.options = this.parseData(
378
- JSON.parse(JSON.stringify(res.results))
379
- );
380
- } else {
381
- this.options = JSON.parse(JSON.stringify(res.results));
382
- }
383
- if (sysCode || this.dataKey) {
384
- const bus = this.bus || this.$root.Bus;
385
- bus &&
386
- bus.$emit(
387
- sysCode || this.dataKey,
388
- JSON.parse(JSON.stringify(this.options))
389
- );
390
- store.set(sysCode, JSON.parse(JSON.stringify(this.options)));
391
- }
392
- } else {
393
- this.$message.error(res.msg);
394
- }
395
- })
396
- .catch((err) => {
397
- this.loading = false;
398
- if (err.message) {
399
- if (err.message !== 'canceled') {
400
- this.$message.error(err.message);
401
- }
402
- if (err.message === 'canceled' && sysCode) {
403
- this.canceled = true;
404
- }
405
- }
406
- });
407
- },
408
- search(query) {
409
- if (query && query !== '') {
410
- if (this.url && this.url !== '') {
411
- this.loading = true;
412
- let params = {};
413
- params[this.remoteKey] = query;
414
- params = util.extend({}, this.param, params);
415
- util
416
- .ajax({
417
- url: this.url,
418
- method: this.method,
419
- params: params,
420
- data: params
421
- })
422
- .then((res) => {
423
- this.loading = false;
424
- if (res.rCode === 0) {
425
- this.options = JSON.parse(JSON.stringify(res.results));
426
- }
427
- })
428
- .catch((err) => {
429
- this.loading = false;
430
- if (err.message && err.message !== 'canceled') {
431
- this.$message.error(err.message);
432
- }
433
- });
434
- } else {
435
- this.options = [];
436
- }
437
- } else {
438
- this.options = this.data;
439
- }
440
- },
441
- renderd(doms, h, type) {
442
- if (typeof this.$attrs[type] === 'boolean') {
443
- if (this.$attrs.render) {
444
- if (typeof this.$attrs.render == 'string') {
445
- try {
446
- doms.push(
447
- h(
448
- 'template',
449
- { slot: type },
450
- util.toFunction(this.$attrs.render)(h, this)
451
- )
452
- );
453
- } catch (error) {
454
- throw error;
455
- }
456
- } else {
457
- doms.push(
458
- h('template', { slot: type }, this.$attrs.render(h, this))
459
- );
460
- }
461
- }
462
- } else if (typeof this.$attrs[type] === 'object') {
463
- doms.push(
464
- h(
465
- 'es-button',
466
- {
467
- slot: type,
468
- class: ['el-primeval', this.$attrs[type].class],
469
- props: {
470
- ...this.$attrs[type].props,
471
- size: this.$attrs[type].size
472
- ? this.$attrs[type].size
473
- : type === 'prefix' || type === 'suffix'
474
- ? 'small'
475
- : '',
476
- type: 'primary'
477
- },
478
- domProps: this.$attrs[type].icon
479
- ? { innerHTML: this.$attrs[type].icon }
480
- : {},
481
- on: {
482
- click: (e) => {
483
- this.$attrs[type].click &&
484
- this.$attrs[type].click(this, this.model);
485
- this.$attrs[type].event &&
486
- this.$attrs[type].event(this, this.model);
487
- }
488
- },
489
- ref: 'selectBtn'
490
- },
491
- [this.$attrs[type].text]
492
- )
493
- );
494
- } else {
495
- doms.push(h('template', { slot: type }, [this.$attrs[type]]));
496
- }
497
- },
498
- getLabel(value, data) {
499
- if ((value || value === 0) && data) {
500
- if (util.isObject(data)) {
501
- if (value === data[this.valKey]) {
502
- return data[this.label];
503
- } else if (value === data[this.label]) {
504
- return value;
505
- } else if (
506
- Object.prototype.hasOwnProperty.call(data, 'children') &&
507
- data.children &&
508
- data.children.length
509
- ) {
510
- let val = this.getLabel(value, data.children);
511
- if (val) {
512
- return val;
513
- }
514
- }
515
- } else {
516
- if (
517
- typeof data === 'string' ||
518
- (!data.length && !this.sysCode && !this.url)
519
- ) {
520
- return value;
521
- }
522
- if (Array.isArray(data) && data.length) {
523
- for (let i = 0; i < data.length; i++) {
524
- let val = this.getLabel(value, data[i]);
525
- if (val) {
526
- return val;
527
- }
528
- }
529
- }
530
- }
531
- }
532
- return '';
533
- },
534
- reload() {
535
- this.getData(...arguments);
536
- },
537
- handleExpand(data, node) {
538
- if (this.onExpand) {
539
- this.onExpand(data, node);
540
- } else {
541
- if (this.lazy) {
542
- this.loadsub(data, node);
543
- }
544
- this.$emit('node-expand', data, node);
545
- }
546
- },
547
- //请求子节点数据
548
- loadsub(data, node) {
549
- if (data.state !== '' && (!data.children || data.children.length === 0)) {
550
- let param = {};
551
- if (this.subParamKey) {
552
- for (let i in this.subParamKey) {
553
- param[i] = data[this.subParamKey[i]];
554
- }
555
- } else {
556
- param[this.valKey] = data[this.valKey];
557
- }
558
- let params = util.extend({}, this.param, this.where, param);
559
- if (this.parseParams) {
560
- params = this.parseParams({ data, params, node });
561
- }
562
- if (this.onLoadsub) {
563
- this.onLoadsub({ data, params, node })
564
- .then((res) => {
565
- this.loading = false;
566
- this.$set(data, 'children', JSON.parse(JSON.stringify(res)));
567
- if (this.dataKey && this.esForm) {
568
- this.esForm.setSysCodes(
569
- this.dataKey,
570
- JSON.parse(JSON.stringify(this.options))
571
- );
572
- }
573
- })
574
- .catch((e) => {
575
- this.loading = false;
576
- });
577
- } else {
578
- util
579
- .ajax({
580
- method: this.method,
581
- url: this.url,
582
- data: params,
583
- params: params
584
- })
585
- .then((res) => {
586
- if (res.rCode === 0) {
587
- this.loading = false;
588
- let results = JSON.parse(JSON.stringify(res.results));
589
- if (Array.isArray(results)) {
590
- if (data.id === results[0].id) {
591
- this.$set(data, 'children', results[0].children);
592
- } else {
593
- this.$set(data, 'children', results);
594
- }
595
- } else if (data.id === results.id) {
596
- this.$set(data, 'children', results.children);
597
- } else {
598
- console.error('tree数据格式错误');
599
- }
600
- if (this.dataKey && this.esForm) {
601
- this.esForm.setSysCodes(
602
- this.dataKey,
603
- JSON.parse(JSON.stringify(this.options))
604
- );
605
- }
606
- }
607
- })
608
- .catch((err) => {
609
- this.loading = false;
610
- if (err.message && err.message !== 'canceled') {
611
- this.$message.error(err.message);
612
- }
613
- });
614
- }
615
- }
616
- },
617
- toggleMenu() {
618
- this.$refs.elSelect.toggleMenu();
619
- },
620
- setOptions(val) {
621
- this.options = val;
622
- },
623
- bindEventBus() {
624
- const bus = this.bus || this.$root.Bus;
625
- bus && bus.$on(this.sysCode || this.dataKey, this.setOptions);
626
- },
627
- unbindEventBus() {
628
- const bus = this.bus || this.$root.Bus;
629
- bus && bus.$off(this.sysCode || this.dataKey, this.setOptions);
630
- }
631
- },
632
- beforeDestroy() {
633
- this.unbindEventBus();
634
- },
635
- render(h) {
636
- if (!this.hide) {
637
- if (this.readonly) {
638
- let dom = [];
639
- if (Array.isArray(this.models)) {
640
- dom = this.models.map((item) => {
641
- if (util.isObject(item)) {
642
- if (!item[this.label] && !item.label) {
643
- return this.getLabel(value[this.valKey], data);
644
- }
645
- return item[this.label] || item.label;
646
- }
647
- return this.getLabel(item, this.results);
648
- });
649
- } else if (util.isObject(this.models)) {
650
- if (!this.models[this.label] && !this.models.label) {
651
- dom = [this.getLabel(this.models[this.valKey], this.results)];
652
- } else {
653
- dom = [this.models[this.label] || this.models.label];
654
- }
655
- } else {
656
- dom = [this.getLabel(this.models, this.results)];
657
- }
658
- return h(
659
- 'div',
660
- {
661
- class: [
662
- {
663
- 'es-plain': this.plain,
664
- 'es-textarea__inner el-textarea__inner': this.multiple,
665
- 'el-input__inner es-input__inner': !this.multiple
666
- }
667
- ]
668
- },
669
- [dom.join(this.symbol)]
670
- );
671
- }
672
- let doms = [];
673
- let cls = [];
674
- if (this.results.length && !this.tree) {
675
- if (this.filtrate && Array.isArray(this.filtrate)) {
676
- doms = this.filtrate.map((item) => {
677
- return h(
678
- 'el-option-group',
679
- {
680
- attrs: {
681
- label: item[this.label] || item.label,
682
- key: item[this.valKey]
683
- }
684
- },
685
- this.createOption({ filtrate: item, data: this.results, h })
686
- );
687
- });
688
- } else {
689
- doms = this.createOption({
690
- filtrate: this.filtrate,
691
- data: this.results,
692
- h
693
- });
694
- }
695
- }
696
- let { prefix, suffix, prepend, append, ...attrs } = this.$attrs;
697
- if (this.$slots.prefix) {
698
- doms.push(h('template', { slot: 'prefix' }, this.$slots.prefix));
699
- } else if (prefix) {
700
- this.renderd(doms, h, 'prefix');
701
- cls.push('es-select-button-prefix');
702
- }
703
- if (this.$slots.suffix) {
704
- doms.push(h('template', { slot: 'suffix' }, this.$slots.suffix));
705
- } else if (suffix) {
706
- this.renderd(doms, h, 'suffix');
707
- cls.push('es-select-button-suffix');
708
- }
709
- if (this.$slots.prepend) {
710
- doms.push(h('template', { slot: 'prepend' }, this.$slots.prepend));
711
- } else if (prepend) {
712
- this.renderd(doms, h, 'prepend');
713
- }
714
- if (this.$slots.append) {
715
- doms.push(h('template', { slot: 'append' }, this.$slots.append));
716
- } else if (append) {
717
- this.renderd(doms, h, 'append');
718
- }
719
- if (!this.models && this.results.length && this.defaultValue) {
720
- if (this.valueType === 'object') {
721
- this.models = this.results[0];
722
- //this.$emit('input', this.results[0]);
723
- } else {
724
- this.models = this.results[0][this.valKey];
725
- //this.$emit('input', this.results[0][this.valKey]);
726
- }
727
- this.$emit('change', this.results[0], 0);
728
- }
729
- return h(
730
- 'el-select',
731
- {
732
- class: cls,
733
- ref: 'elSelect',
734
- directives: [
735
- {
736
- name: 'show',
737
- value: this.display
738
- }
739
- ],
740
- props: {
741
- ...attrs,
742
- multiple: this.multiple,
743
- valueType: this.valueType,
744
- valueKey: this.valKey,
745
- labelKey: this.label,
746
- loading: this.loading,
747
- disabled: this.disabled,
748
- tree:
749
- typeof this.tree === 'boolean'
750
- ? this.tree
751
- : { ...this.tree, lazy: this.label },
752
- data: this.results,
753
- // 父级是否可选
754
- parentCheck: this.parentCheck,
755
- // 父级可选时父级是否作为单独的值
756
- parentAsValue: this.parentAsValue,
757
- value: this.models
758
- },
759
- attrs: {
760
- remoteMethod: !this.remoteMethod ? this.search : this.remoteMethod,
761
- remote: this.remote
762
- },
763
- on: {
764
- ...this.$listeners,
765
- 'node-expand': this.handleExpand
766
- }
767
- },
768
- this.$slots.default ? this.$slots.default : doms
769
- );
770
- } else {
771
- return '';
772
- }
773
- }
774
- };
775
- </script>
1
+ <script>
2
+ import { findSysCode, getDictList } from 'eoss-ui/src/config/api.js';
3
+ import { throttle } from 'throttle-debounce';
4
+ import store from 'eoss-ui/src/utils/store';
5
+ import util from 'eoss-ui/src/utils/util';
6
+ export default {
7
+ name: 'EsSelect',
8
+ componentName: 'EsSelect',
9
+ inheritAttrs: false,
10
+ provide() {
11
+ return {
12
+ esSelect: this
13
+ };
14
+ },
15
+ inject: {
16
+ esForm: {
17
+ default: ''
18
+ }
19
+ },
20
+ props: {
21
+ service: String,
22
+ value: [String, Array, Object, Number],
23
+ method: {
24
+ type: String,
25
+ default: 'get'
26
+ },
27
+ param: {
28
+ type: Object,
29
+ default() {
30
+ return {};
31
+ }
32
+ },
33
+ // 显示隐藏组件
34
+ display: {
35
+ type: Boolean,
36
+ default: true
37
+ },
38
+ // 是否不渲染组件
39
+ hide: {
40
+ type: Boolean,
41
+ default: false
42
+ },
43
+ valueType: {
44
+ type: String,
45
+ default: 'string',
46
+ validator: function (value) {
47
+ return ['string', 'object'].includes(value);
48
+ }
49
+ },
50
+ // 选择项的值字段
51
+ valueKey: {
52
+ type: String,
53
+ default: 'value'
54
+ },
55
+ // 指定选择项显示值的键名,data元素是对象类型时必填
56
+ labelKey: {
57
+ type: String,
58
+ default: 'name'
59
+ },
60
+ data: {
61
+ type: Array,
62
+ default() {
63
+ return [];
64
+ }
65
+ },
66
+ // 远程搜索
67
+ remote: Boolean,
68
+ remoteKey: {
69
+ type: String,
70
+ default: 'searchKey'
71
+ },
72
+ remoteMethod: Function,
73
+ // 选择项远程地址
74
+ url: String,
75
+ // 选择项获取代码表数据(优先级大于url)
76
+ sysCode: String,
77
+ filtrate: [String, Object, Array],
78
+ filtrateKey: {
79
+ type: String,
80
+ default: 'pid'
81
+ },
82
+ readonly: Boolean,
83
+ separator: {
84
+ type: String,
85
+ default: '-'
86
+ },
87
+ symbol: {
88
+ type: String,
89
+ default: ','
90
+ },
91
+ plain: Boolean,
92
+ where: Object,
93
+ parseData: Function,
94
+ disabled: Boolean,
95
+ // 是否下拉树选择
96
+ tree: {
97
+ type: [Boolean, Object],
98
+ default: false
99
+ },
100
+ // 父级是否可选
101
+ parentCheck: {
102
+ type: Boolean,
103
+ default: true
104
+ },
105
+ // 父级可选时父级是否作为单独的值
106
+ parentAsValue: {
107
+ type: Boolean,
108
+ default: true
109
+ },
110
+ group: Boolean,
111
+ multiple: Boolean,
112
+ defaultValue: Boolean,
113
+ onExpand: Function,
114
+ onLoadsub: Function,
115
+ subParamKey: Object,
116
+ lazy: Boolean,
117
+ //是否请求代码表
118
+ ajax: {
119
+ type: Boolean,
120
+ default: true
121
+ },
122
+ isNoParamRequest: {
123
+ type: Boolean,
124
+ default: true
125
+ },
126
+ dataKey: String
127
+ },
128
+ data() {
129
+ return {
130
+ loading: false,
131
+ options: '',
132
+ valKey: this.valueKey,
133
+ label: this.labelKey,
134
+ hidden: false,
135
+ canceled: false
136
+ };
137
+ },
138
+ computed: {
139
+ isObject() {
140
+ if (this.valueType === 'object') {
141
+ return true;
142
+ }
143
+ if (
144
+ util.isObject(this.value) ||
145
+ (this.value && this.value[0] && util.isObject(this.value[0]))
146
+ ) {
147
+ return true;
148
+ }
149
+ return false;
150
+ },
151
+ isRemote() {
152
+ return new Boolean(this.remote);
153
+ },
154
+ results() {
155
+ if (this.options.length) {
156
+ return this.options;
157
+ }
158
+ if (this.filtrate) {
159
+ if (Array.isArray(this.filtrate) && this.filtrate.length) {
160
+ let ary = [];
161
+ this.filtrate.forEach((items) => {
162
+ let val = typeof items === 'string' ? items : items[this.valKey];
163
+ ary = ary.concat(
164
+ this.data.filter((item) => {
165
+ return item[this.filtrateKey] == val;
166
+ })
167
+ );
168
+ });
169
+ return ary;
170
+ } else {
171
+ let val =
172
+ typeof this.filtrate === 'string'
173
+ ? this.filtrate
174
+ : this.filtrate[this.valKey];
175
+ return this.data.filter((item) => {
176
+ return item[this.filtrateKey] == val;
177
+ });
178
+ }
179
+ }
180
+ return this.data;
181
+ },
182
+ models: {
183
+ get() {
184
+ return this.value;
185
+ },
186
+ set(val) {
187
+ return val;
188
+ }
189
+ },
190
+ findCode() {
191
+ if (this.service) {
192
+ return `/${this.service}${getDictList}`;
193
+ }
194
+ return findSysCode;
195
+ }
196
+ },
197
+ watch: {
198
+ sysCode: {
199
+ immediate: true,
200
+ handler(val, old) {
201
+ if (val && val !== old) {
202
+ this.label = this.service ? 'label' : 'shortName';
203
+ this.valKey = this.service ? 'value' : 'cciValue';
204
+ const options = store.get(val);
205
+ if (options) {
206
+ this.options = JSON.parse(JSON.stringify(options));
207
+ } else {
208
+ this.getData(val);
209
+ }
210
+ }
211
+ }
212
+ },
213
+ url: {
214
+ immediate: true,
215
+ handler(val, old) {
216
+ if (val && old !== val && !this.sysCode) {
217
+ this.getData(this.sysCode);
218
+ }
219
+ }
220
+ },
221
+ param: {
222
+ deep: true,
223
+ handler(val, old) {
224
+ if (this.url && JSON.stringify(val) !== JSON.stringify(old)) {
225
+ this.options = [];
226
+ this.getData(this.sysCode);
227
+ }
228
+ }
229
+ }
230
+ },
231
+ beforeCreate() {
232
+ this.getData = throttle(500, (sysCode, param, reload) => {
233
+ this.getDatas(sysCode, param, reload);
234
+ });
235
+ },
236
+ created() {
237
+ this.bindEventBus();
238
+ },
239
+ mounted() {},
240
+ methods: {
241
+ createOption({ filtrate, data, readonly = false, h }) {
242
+ let filte =
243
+ filtrate && util.isObject(filtrate) ? filtrate[this.valKey] : filtrate;
244
+ let eles = [];
245
+ data.forEach((item) => {
246
+ if (this.models === undefined && item.selected) {
247
+ this.$emit(
248
+ 'input',
249
+ this.valueType === 'object' ? item : item[this.valKey]
250
+ );
251
+ }
252
+ if (
253
+ (Object.prototype.hasOwnProperty.call(item, 'children') ||
254
+ Object.prototype.hasOwnProperty.call(item, 'options')) &&
255
+ (item.children || item.options)
256
+ ) {
257
+ const children = item.children || item.options;
258
+ if (readonly) {
259
+ eles.push(
260
+ this.createOption({ filtrate, data: children, readonly, h })
261
+ );
262
+ } else {
263
+ eles.push(
264
+ h(
265
+ 'el-option-group',
266
+ { attrs: { label: item[this.label] || item.label } },
267
+ this.createOption({ filtrate, data: children, readonly, h })
268
+ )
269
+ );
270
+ }
271
+ } else {
272
+ if (readonly) {
273
+ if (item[this.valKey] === filte) {
274
+ eles.push(item[this.label] || item.label);
275
+ }
276
+ } else {
277
+ if (
278
+ filte === null ||
279
+ filte === undefined ||
280
+ filte === '' ||
281
+ filte === item[this.filtrateKey]
282
+ ) {
283
+ if (typeof item === 'string') {
284
+ eles.push(
285
+ h('el-option', {
286
+ attrs: {
287
+ label: item,
288
+ value: item
289
+ }
290
+ })
291
+ );
292
+ } else {
293
+ let content = [];
294
+ const labelContent = item[this.label] || item.label;
295
+ //判断它是否是html字符串
296
+ if (
297
+ typeof labelContent === 'string' &&
298
+ /<[^>]+>/.test(labelContent)
299
+ ) {
300
+ // 如果是 HTML 字符串,创建对应的 VNode
301
+ content = [
302
+ h('div', { domProps: { innerHTML: labelContent } })
303
+ ];
304
+ } else {
305
+ content = [labelContent];
306
+ }
307
+ if (item.render) {
308
+ content = [item.render(h, item)];
309
+ }
310
+ if (item.tips) {
311
+ let attrs =
312
+ typeof item.tips == 'string'
313
+ ? { content: item.tips }
314
+ : item.tips;
315
+ content.push(
316
+ h('es-tips', {
317
+ attrs: attrs
318
+ })
319
+ );
320
+ }
321
+
322
+ eles.push(
323
+ h(
324
+ 'el-option',
325
+ {
326
+ attrs: {
327
+ label: item[this.label] || item.label,
328
+ value: this.isObject ? item : item[this.valKey],
329
+ disabled: item.disabled
330
+ },
331
+ style: item.style
332
+ },
333
+ content
334
+ )
335
+ );
336
+ }
337
+ }
338
+ }
339
+ }
340
+ });
341
+ return eles;
342
+ },
343
+ getDatas(sysCode, param, reload) {
344
+ if (
345
+ !reload &&
346
+ (!this.ajax ||
347
+ (!this.isNoParamRequest && Object.keys(this.param).length == 0))
348
+ ) {
349
+ return false;
350
+ }
351
+ let params = {};
352
+ if (this.results.length === 0 || reload) {
353
+ params = util.extend(
354
+ {},
355
+ this.param,
356
+ sysCode ? { sysAppCode: sysCode, code: sysCode } : {},
357
+ param ? param : {}
358
+ );
359
+ } else {
360
+ return false;
361
+ }
362
+ if (!sysCode && !this.url) {
363
+ return false;
364
+ }
365
+ this.loading = true;
366
+ util
367
+ .ajax({
368
+ url: sysCode ? this.findCode : this.url,
369
+ method: this.method,
370
+ params: params,
371
+ data: params
372
+ })
373
+ .then((res) => {
374
+ this.loading = false;
375
+ this.canceled = false;
376
+ if (res.rCode === 0) {
377
+ if (this.parseData) {
378
+ this.options = this.parseData(
379
+ JSON.parse(JSON.stringify(res.results))
380
+ );
381
+ } else {
382
+ this.options = JSON.parse(JSON.stringify(res.results));
383
+ }
384
+ if (sysCode || this.dataKey) {
385
+ const bus = this.bus || this.$root.Bus;
386
+ bus &&
387
+ bus.$emit(
388
+ sysCode || this.dataKey,
389
+ JSON.parse(JSON.stringify(this.options))
390
+ );
391
+ store.set(sysCode, JSON.parse(JSON.stringify(this.options)));
392
+ }
393
+ } else {
394
+ this.$message.error(res.msg);
395
+ }
396
+ })
397
+ .catch((err) => {
398
+ this.loading = false;
399
+ if (err.message) {
400
+ if (err.message !== 'canceled') {
401
+ this.$message.error(err.message);
402
+ }
403
+ if (err.message === 'canceled' && sysCode) {
404
+ this.canceled = true;
405
+ }
406
+ }
407
+ });
408
+ },
409
+ search(query) {
410
+ if (query && query !== '') {
411
+ if (this.url && this.url !== '') {
412
+ this.loading = true;
413
+ let params = {};
414
+ params[this.remoteKey] = query;
415
+ params = util.extend({}, this.param, params);
416
+ util
417
+ .ajax({
418
+ url: this.url,
419
+ method: this.method,
420
+ params: params,
421
+ data: params
422
+ })
423
+ .then((res) => {
424
+ this.loading = false;
425
+ if (res.rCode === 0) {
426
+ this.options = JSON.parse(JSON.stringify(res.results));
427
+ }
428
+ })
429
+ .catch((err) => {
430
+ this.loading = false;
431
+ if (err.message && err.message !== 'canceled') {
432
+ this.$message.error(err.message);
433
+ }
434
+ });
435
+ } else {
436
+ this.options = [];
437
+ }
438
+ } else {
439
+ this.options = this.data;
440
+ }
441
+ },
442
+ renderd(doms, h, type) {
443
+ if (typeof this.$attrs[type] === 'boolean') {
444
+ if (this.$attrs.render) {
445
+ if (typeof this.$attrs.render == 'string') {
446
+ try {
447
+ doms.push(
448
+ h(
449
+ 'template',
450
+ { slot: type },
451
+ util.toFunction(this.$attrs.render)(h, this)
452
+ )
453
+ );
454
+ } catch (error) {
455
+ throw error;
456
+ }
457
+ } else {
458
+ doms.push(
459
+ h('template', { slot: type }, this.$attrs.render(h, this))
460
+ );
461
+ }
462
+ }
463
+ } else if (typeof this.$attrs[type] === 'object') {
464
+ doms.push(
465
+ h(
466
+ 'es-button',
467
+ {
468
+ slot: type,
469
+ class: ['el-primeval', this.$attrs[type].class],
470
+ props: {
471
+ ...this.$attrs[type].props,
472
+ size: this.$attrs[type].size
473
+ ? this.$attrs[type].size
474
+ : type === 'prefix' || type === 'suffix'
475
+ ? 'small'
476
+ : '',
477
+ type: 'primary'
478
+ },
479
+ domProps: this.$attrs[type].icon
480
+ ? { innerHTML: this.$attrs[type].icon }
481
+ : {},
482
+ on: {
483
+ click: (e) => {
484
+ this.$attrs[type].click &&
485
+ this.$attrs[type].click(this, this.model);
486
+ this.$attrs[type].event &&
487
+ this.$attrs[type].event(this, this.model);
488
+ }
489
+ },
490
+ ref: 'selectBtn'
491
+ },
492
+ [this.$attrs[type].text]
493
+ )
494
+ );
495
+ } else {
496
+ doms.push(h('template', { slot: type }, [this.$attrs[type]]));
497
+ }
498
+ },
499
+ getLabel(value, data) {
500
+ if ((value || value === 0) && data) {
501
+ if (util.isObject(data)) {
502
+ if (value === data[this.valKey]) {
503
+ return data[this.label];
504
+ } else if (value === data[this.label]) {
505
+ return value;
506
+ } else if (
507
+ Object.prototype.hasOwnProperty.call(data, 'children') &&
508
+ data.children &&
509
+ data.children.length
510
+ ) {
511
+ let val = this.getLabel(value, data.children);
512
+ if (val) {
513
+ return val;
514
+ }
515
+ }
516
+ } else {
517
+ if (
518
+ typeof data === 'string' ||
519
+ (!data.length && !this.sysCode && !this.url)
520
+ ) {
521
+ return value;
522
+ }
523
+ if (Array.isArray(data) && data.length) {
524
+ for (let i = 0; i < data.length; i++) {
525
+ let val = this.getLabel(value, data[i]);
526
+ if (val) {
527
+ return val;
528
+ }
529
+ }
530
+ }
531
+ }
532
+ }
533
+ return '';
534
+ },
535
+ reload() {
536
+ this.getData(...arguments);
537
+ },
538
+ handleExpand(data, node) {
539
+ if (this.onExpand) {
540
+ this.onExpand(data, node);
541
+ } else {
542
+ if (this.lazy) {
543
+ this.loadsub(data, node);
544
+ }
545
+ this.$emit('node-expand', data, node);
546
+ }
547
+ },
548
+ //请求子节点数据
549
+ loadsub(data, node) {
550
+ if (data.state !== '' && (!data.children || data.children.length === 0)) {
551
+ let param = {};
552
+ if (this.subParamKey) {
553
+ for (let i in this.subParamKey) {
554
+ param[i] = data[this.subParamKey[i]];
555
+ }
556
+ } else {
557
+ param[this.valKey] = data[this.valKey];
558
+ }
559
+ let params = util.extend({}, this.param, this.where, param);
560
+ if (this.parseParams) {
561
+ params = this.parseParams({ data, params, node });
562
+ }
563
+ if (this.onLoadsub) {
564
+ this.onLoadsub({ data, params, node })
565
+ .then((res) => {
566
+ this.loading = false;
567
+ this.$set(data, 'children', JSON.parse(JSON.stringify(res)));
568
+ if (this.dataKey && this.esForm) {
569
+ this.esForm.setSysCodes(
570
+ this.dataKey,
571
+ JSON.parse(JSON.stringify(this.options))
572
+ );
573
+ }
574
+ })
575
+ .catch((e) => {
576
+ this.loading = false;
577
+ });
578
+ } else {
579
+ util
580
+ .ajax({
581
+ method: this.method,
582
+ url: this.url,
583
+ data: params,
584
+ params: params
585
+ })
586
+ .then((res) => {
587
+ if (res.rCode === 0) {
588
+ this.loading = false;
589
+ let results = JSON.parse(JSON.stringify(res.results));
590
+ if (Array.isArray(results)) {
591
+ if (data.id === results[0].id) {
592
+ this.$set(data, 'children', results[0].children);
593
+ } else {
594
+ this.$set(data, 'children', results);
595
+ }
596
+ } else if (data.id === results.id) {
597
+ this.$set(data, 'children', results.children);
598
+ } else {
599
+ console.error('tree数据格式错误');
600
+ }
601
+ if (this.dataKey && this.esForm) {
602
+ this.esForm.setSysCodes(
603
+ this.dataKey,
604
+ JSON.parse(JSON.stringify(this.options))
605
+ );
606
+ }
607
+ }
608
+ })
609
+ .catch((err) => {
610
+ this.loading = false;
611
+ if (err.message && err.message !== 'canceled') {
612
+ this.$message.error(err.message);
613
+ }
614
+ });
615
+ }
616
+ }
617
+ },
618
+ toggleMenu() {
619
+ this.$refs.elSelect.toggleMenu();
620
+ },
621
+ setOptions(val) {
622
+ this.options = val;
623
+ },
624
+ bindEventBus() {
625
+ const bus = this.bus || this.$root.Bus;
626
+ bus && bus.$on(this.sysCode || this.dataKey, this.setOptions);
627
+ },
628
+ unbindEventBus() {
629
+ const bus = this.bus || this.$root.Bus;
630
+ bus && bus.$off(this.sysCode || this.dataKey, this.setOptions);
631
+ }
632
+ },
633
+ beforeDestroy() {
634
+ this.unbindEventBus();
635
+ },
636
+ render(h) {
637
+ if (!this.hide) {
638
+ if (this.readonly) {
639
+ let dom = [];
640
+ if (Array.isArray(this.models)) {
641
+ dom = this.models.map((item) => {
642
+ if (util.isObject(item)) {
643
+ if (!item[this.label] && !item.label) {
644
+ return this.getLabel(value[this.valKey], data);
645
+ }
646
+ return item[this.label] || item.label;
647
+ }
648
+ return this.getLabel(item, this.results);
649
+ });
650
+ } else if (util.isObject(this.models)) {
651
+ if (!this.models[this.label] && !this.models.label) {
652
+ dom = [this.getLabel(this.models[this.valKey], this.results)];
653
+ } else {
654
+ dom = [this.models[this.label] || this.models.label];
655
+ }
656
+ } else {
657
+ dom = [this.getLabel(this.models, this.results)];
658
+ }
659
+ return h(
660
+ 'div',
661
+ {
662
+ class: [
663
+ {
664
+ 'es-plain': this.plain,
665
+ 'es-textarea__inner el-textarea__inner': this.multiple,
666
+ 'el-input__inner es-input__inner': !this.multiple
667
+ }
668
+ ]
669
+ },
670
+ [dom.join(this.symbol)]
671
+ );
672
+ }
673
+ let doms = [];
674
+ let cls = [];
675
+ if (this.results.length && !this.tree) {
676
+ if (this.filtrate && Array.isArray(this.filtrate)) {
677
+ doms = this.filtrate.map((item) => {
678
+ return h(
679
+ 'el-option-group',
680
+ {
681
+ attrs: {
682
+ label: item[this.label] || item.label,
683
+ key: item[this.valKey]
684
+ }
685
+ },
686
+ this.createOption({ filtrate: item, data: this.results, h })
687
+ );
688
+ });
689
+ } else {
690
+ doms = this.createOption({
691
+ filtrate: this.filtrate,
692
+ data: this.results,
693
+ h
694
+ });
695
+ }
696
+ }
697
+ let { prefix, suffix, prepend, append, ...attrs } = this.$attrs;
698
+ if (this.$slots.prefix) {
699
+ doms.push(h('template', { slot: 'prefix' }, this.$slots.prefix));
700
+ } else if (prefix) {
701
+ this.renderd(doms, h, 'prefix');
702
+ cls.push('es-select-button-prefix');
703
+ }
704
+ if (this.$slots.suffix) {
705
+ doms.push(h('template', { slot: 'suffix' }, this.$slots.suffix));
706
+ } else if (suffix) {
707
+ this.renderd(doms, h, 'suffix');
708
+ cls.push('es-select-button-suffix');
709
+ }
710
+ if (this.$slots.prepend) {
711
+ doms.push(h('template', { slot: 'prepend' }, this.$slots.prepend));
712
+ } else if (prepend) {
713
+ this.renderd(doms, h, 'prepend');
714
+ }
715
+ if (this.$slots.append) {
716
+ doms.push(h('template', { slot: 'append' }, this.$slots.append));
717
+ } else if (append) {
718
+ this.renderd(doms, h, 'append');
719
+ }
720
+ if (!this.models && this.results.length && this.defaultValue) {
721
+ if (this.valueType === 'object') {
722
+ this.models = this.results[0];
723
+ //this.$emit('input', this.results[0]);
724
+ } else {
725
+ this.models = this.results[0][this.valKey];
726
+ //this.$emit('input', this.results[0][this.valKey]);
727
+ }
728
+ this.$emit('change', this.results[0], 0);
729
+ }
730
+ return h(
731
+ 'el-select',
732
+ {
733
+ class: cls,
734
+ ref: 'elSelect',
735
+ directives: [
736
+ {
737
+ name: 'show',
738
+ value: this.display
739
+ }
740
+ ],
741
+ props: {
742
+ ...attrs,
743
+ multiple: this.multiple,
744
+ valueType: this.valueType,
745
+ valueKey: this.valKey,
746
+ labelKey: this.label,
747
+ loading: this.loading,
748
+ disabled: this.disabled,
749
+ tree:
750
+ typeof this.tree === 'boolean'
751
+ ? this.tree
752
+ : { ...this.tree, lazy: this.label },
753
+ data: this.results,
754
+ // 父级是否可选
755
+ parentCheck: this.parentCheck,
756
+ // 父级可选时父级是否作为单独的值
757
+ parentAsValue: this.parentAsValue,
758
+ value: this.models
759
+ },
760
+ attrs: {
761
+ remoteMethod: !this.remoteMethod ? this.search : this.remoteMethod,
762
+ remote: this.remote
763
+ },
764
+ on: {
765
+ ...this.$listeners,
766
+ 'node-expand': this.handleExpand
767
+ }
768
+ },
769
+ this.$slots.default ? this.$slots.default : doms
770
+ );
771
+ } else {
772
+ return '';
773
+ }
774
+ }
775
+ };
776
+ </script>