eoss-ui 0.6.54 → 0.6.55

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