@opentiny/vue-renderless 3.1.0-alpha.0 → 3.5.0
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.
- package/action-menu/index.js +10 -0
- package/action-menu/vue.js +26 -0
- package/amount/index.js +334 -0
- package/amount/vue.js +206 -0
- package/area/index.js +162 -0
- package/area/vue.js +68 -0
- package/autonavi-map/index.js +28 -0
- package/avatar/index.js +5 -1
- package/avatar/vue.js +2 -1
- package/baidu-map/index.js +28 -0
- package/breadcrumb/index.js +9 -0
- package/breadcrumb/vue.js +25 -3
- package/breadcrumb-item/index.js +26 -0
- package/breadcrumb-item/vue.js +20 -11
- package/bulletin-board/index.js +4 -1
- package/button-group/vue.js +1 -1
- package/calendar/index.js +14 -14
- package/card-template/index.js +1 -1
- package/cascader/index.js +21 -7
- package/cascader/vue.js +1 -2
- package/cascader-node/index.js +3 -1
- package/cascader-panel/index.js +12 -4
- package/cascader-panel/vue.js +1 -2
- package/chart-bar/index.js +533 -0
- package/chart-boxplot/index.js +270 -0
- package/chart-candle/index.js +428 -0
- package/chart-core/deps/constants.js +65 -0
- package/chart-core/deps/numerify.js +286 -0
- package/chart-core/deps/utils.js +205 -0
- package/chart-core/index.js +541 -0
- package/chart-core/modules/animation.js +10 -0
- package/chart-core/modules/extend.js +36 -0
- package/chart-core/modules/mark.js +7 -0
- package/chart-core/vue.js +128 -0
- package/chart-funnel/index.js +155 -0
- package/chart-gauge/index.js +153 -0
- package/chart-graph/index.js +38 -0
- package/chart-heatmap/index.js +407 -0
- package/chart-line/index.js +358 -0
- package/chart-liquidfill/index.js +119 -0
- package/chart-map/index.js +261 -0
- package/chart-pie/index.js +327 -0
- package/chart-radar/index.js +181 -0
- package/chart-sankey/index.js +166 -0
- package/chart-scatter/index.js +360 -0
- package/chart-sunburst/index.js +36 -0
- package/chart-tree/index.js +107 -0
- package/chart-waterfall/index.js +231 -0
- package/chart-wordcloud/index.js +109 -0
- package/checkbox/index.js +4 -4
- package/checkbox-button/index.js +3 -1
- package/common/bigInt.js +5 -2
- package/common/date.js +17 -17
- package/common/deps/date-util.js +15 -5
- package/common/deps/date.js +6 -6
- package/common/deps/dom.js +18 -6
- package/common/deps/eSpaceCtrl.js +286 -0
- package/common/deps/fullscreen/apis.js +22 -22
- package/common/deps/memorize.js +3 -3
- package/common/deps/modal-queue.js +2 -0
- package/common/deps/popper.js +12 -10
- package/common/deps/popup-manager.js +16 -5
- package/common/deps/resize-event.js +6 -2
- package/common/deps/scrollbar-width.js +6 -2
- package/common/deps/tree-model/node.js +30 -10
- package/common/deps/tree-model/tree-store.js +33 -21
- package/common/deps/tree-model/util.js +6 -2
- package/common/deps/upload-ajax.js +7 -1
- package/common/deps/vue-popper.js +2 -2
- package/common/string.js +1 -1
- package/company/index.js +56 -0
- package/company/vue.js +35 -0
- package/country/index.js +54 -0
- package/country/vue.js +35 -0
- package/credit-card-form/index.js +1 -0
- package/currency/index.js +78 -0
- package/currency/vue.js +39 -0
- package/date-panel/index.js +16 -6
- package/date-picker/index.js +9 -5
- package/date-range/index.js +28 -9
- package/date-table/index.js +3 -1
- package/dept/index.js +318 -0
- package/dept/vue.js +163 -0
- package/detail-page/index.js +4 -1
- package/dialog-box/index.js +14 -4
- package/dialog-box/vue.js +7 -3
- package/drop-roles/index.js +73 -0
- package/drop-roles/vue.js +38 -0
- package/dropdown/index.js +5 -4
- package/dropdown/vue.js +5 -3
- package/dropdown-item/index.js +15 -0
- package/dropdown-item/vue.js +27 -13
- package/espace/index.js +129 -0
- package/espace/vue.js +52 -0
- package/exception/index.js +1 -1
- package/file-upload/index.js +336 -291
- package/form/index.js +3 -1
- package/form/vue.js +15 -0
- package/form-item/index.js +15 -5
- package/fullscreen/index.js +4 -4
- package/fullscreen/vue.js +3 -3
- package/grid/core/interceptor.js +4 -7
- package/grid/plugins/export.js +2 -2
- package/grid/plugins/exportExcel.js +28 -10
- package/grid/static/array/findTree.js +1 -1
- package/grid/static/base/helperCreateGetObjects.js +1 -1
- package/grid/static/base/helperEqualCompare.js +2 -2
- package/grid/static/base/helperGetHGSKeys.js +1 -1
- package/grid/static/base/uniqueId.js +1 -1
- package/grid/static/object/assign.js +3 -3
- package/grid/static/string/toString.js +3 -3
- package/hrapprover/index.js +118 -0
- package/hrapprover/vue.js +102 -0
- package/locales/index.js +116 -0
- package/locales/vue.js +46 -0
- package/logon-user/index.js +23 -0
- package/logon-user/vue.js +22 -0
- package/logout/index.js +118 -0
- package/logout/vue.js +22 -0
- package/milestone/index.js +2 -1
- package/mini-picker/index.js +1 -1
- package/mini-picker/vue.js +1 -1
- package/modal/index.js +4 -2
- package/month-table/index.js +2 -2
- package/nav-menu/index.js +2 -2
- package/numeric/index.js +5 -2
- package/package.json +33 -136
- package/pager-item/vue.js +6 -2
- package/picker/index.js +43 -17
- package/picker/timezone.js +2 -2
- package/picker-column/index.js +7 -3
- package/pop-upload/index.js +5 -3
- package/popeditor/index.js +15 -7
- package/popover/index.js +87 -54
- package/popover/vue.js +13 -9
- package/rate/index.js +2 -2
- package/rich-text/clipboard.js +77 -0
- package/rich-text/index.js +176 -0
- package/rich-text/module/file-upload.js +118 -0
- package/rich-text/module/image-drop.js +54 -0
- package/rich-text/module/image-upload.js +84 -0
- package/rich-text/options.js +187 -0
- package/rich-text/table-module.js +557 -0
- package/rich-text/vue.js +149 -0
- package/roles/index.js +87 -0
- package/roles/vue.js +39 -0
- package/search/index.js +32 -27
- package/search/vue.js +7 -2
- package/select/index.js +328 -304
- package/select/vue.js +19 -9
- package/select-dropdown/index.js +1 -1
- package/slider/index.js +9 -11
- package/slider/vue.js +3 -3
- package/split/vue.js +1 -1
- package/tab-nav/index.js +0 -6
- package/tab-nav/vue.js +0 -14
- package/table/index.js +1 -1
- package/text-popup/index.js +6 -4
- package/time/index.js +3 -1
- package/time-range/index.js +6 -2
- package/time-spinner/index.js +15 -5
- package/toggle-menu/index.js +11 -0
- package/toggle-menu/vue.js +2 -1
- package/tooltip/index.js +46 -35
- package/tooltip/vue.js +5 -1
- package/tree/index.js +57 -21
- package/tree-menu/index.js +3 -1
- package/tree-node/index.js +7 -3
- package/upload/index.js +14 -5
- package/user/index.js +634 -0
- package/user/vue.js +113 -0
- package/user-account/index.js +23 -0
- package/user-account/vue.js +25 -0
- package/user-contact/index.js +1 -4
- package/user-head/index.js +33 -11
- package/user-head/vue.js +10 -7
- package/user-link/index.js +43 -0
- package/user-link/vue.js +60 -0
package/user/index.js
ADDED
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import debounce from '@opentiny/vue-renderless/common/deps/debounce';
|
|
4
|
+
import { toDateStr } from '@opentiny/vue-renderless/common/date';
|
|
5
|
+
import { toJsonStr } from '@opentiny/vue-renderless/common/object';
|
|
6
|
+
import { toJson } from '@opentiny/vue-renderless/common/string';
|
|
7
|
+
import { log } from '@opentiny/vue-renderless/common';
|
|
8
|
+
var request = {
|
|
9
|
+
timmer: null,
|
|
10
|
+
group: {},
|
|
11
|
+
requests: [],
|
|
12
|
+
cache: {},
|
|
13
|
+
batch: 0,
|
|
14
|
+
addRequest: function addRequest(_ref) {
|
|
15
|
+
var _this = this;
|
|
16
|
+
var param = _ref.param,
|
|
17
|
+
cb = _ref.cb;
|
|
18
|
+
this.requests.push({
|
|
19
|
+
param: param,
|
|
20
|
+
cb: cb,
|
|
21
|
+
result: []
|
|
22
|
+
});
|
|
23
|
+
var valueField = param.valueField,
|
|
24
|
+
queryIds = param.queryIds;
|
|
25
|
+
if (!this.group[valueField]) {
|
|
26
|
+
this.group[valueField] = [];
|
|
27
|
+
}
|
|
28
|
+
queryIds.forEach(function (id) {
|
|
29
|
+
if (!~_this.group[valueField].indexOf(id)) {
|
|
30
|
+
!_this.group[valueField].push(id);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
removeRequest: function removeRequest(item) {
|
|
35
|
+
var idx = this.requests.indexOf(item);
|
|
36
|
+
this.requests.splice(idx, 1);
|
|
37
|
+
},
|
|
38
|
+
clearRequest: function clearRequest() {
|
|
39
|
+
this.timmer = null;
|
|
40
|
+
this.group = {};
|
|
41
|
+
this.requests = [];
|
|
42
|
+
this.cache = {};
|
|
43
|
+
this.batch = 0;
|
|
44
|
+
},
|
|
45
|
+
getParams: function getParams() {
|
|
46
|
+
var _this2 = this;
|
|
47
|
+
var args = [];
|
|
48
|
+
var _loop = function _loop(key) {
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(_this2.group, key)) {
|
|
50
|
+
var all = _this2.group[key];
|
|
51
|
+
var items = _this2.splitArr(all, _this2.batch);
|
|
52
|
+
if (key === 'userId') {
|
|
53
|
+
args.push.apply(args, _toConsumableArray(items.map(function (item) {
|
|
54
|
+
return item.join(',');
|
|
55
|
+
})));
|
|
56
|
+
} else {
|
|
57
|
+
args.push.apply(args, _toConsumableArray(items.map(function (item) {
|
|
58
|
+
return _defineProperty({
|
|
59
|
+
valueField: key,
|
|
60
|
+
valueSplit: item.valueSplit
|
|
61
|
+
}, key, item.join(','));
|
|
62
|
+
})));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
for (var key in this.group) {
|
|
67
|
+
_loop(key);
|
|
68
|
+
}
|
|
69
|
+
return args;
|
|
70
|
+
},
|
|
71
|
+
setCache: function setCache(data, valueField) {
|
|
72
|
+
var _this3 = this;
|
|
73
|
+
var me = this;
|
|
74
|
+
if (valueField && !this.group[valueField]) {
|
|
75
|
+
this.group[valueField] = [];
|
|
76
|
+
}
|
|
77
|
+
data.forEach(function (item) {
|
|
78
|
+
for (var key in _this3.group) {
|
|
79
|
+
if (Object.prototype.hasOwnProperty.call(_this3.group, key)) {
|
|
80
|
+
if (!me.cache[key]) {
|
|
81
|
+
me.cache[key] = {};
|
|
82
|
+
}
|
|
83
|
+
me.cache[key][item[key]] = item;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
singleRequest: function singleRequest(param, api, cb) {
|
|
89
|
+
var queryIds = param.queryIds,
|
|
90
|
+
valueField = param.valueField,
|
|
91
|
+
valueSplit = param.valueSplit;
|
|
92
|
+
var queryStr = queryIds.join(',');
|
|
93
|
+
var params = valueField === 'userId' ? queryStr : _defineProperty({
|
|
94
|
+
valueField: valueField,
|
|
95
|
+
valueSplit: valueSplit
|
|
96
|
+
}, valueField, queryStr);
|
|
97
|
+
api.fetchW3Accounts(params).then(function (data) {
|
|
98
|
+
cb(data);
|
|
99
|
+
})["catch"](function (e) {
|
|
100
|
+
cb({
|
|
101
|
+
error: e
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
batchRequest: function batchRequest(api) {
|
|
106
|
+
var _this4 = this;
|
|
107
|
+
var me = this;
|
|
108
|
+
var reqParamsSeq = me.getParams();
|
|
109
|
+
var reqLen = reqParamsSeq.length;
|
|
110
|
+
reqParamsSeq.forEach(function (params) {
|
|
111
|
+
api.fetchW3Accounts(params).then(function (data) {
|
|
112
|
+
me.setCache(data);
|
|
113
|
+
me.requests.slice().forEach(function (reqItem) {
|
|
114
|
+
var param = reqItem.param,
|
|
115
|
+
cb = reqItem.cb;
|
|
116
|
+
var queryIds = param.queryIds,
|
|
117
|
+
valueField = param.valueField;
|
|
118
|
+
queryIds.forEach(function (id) {
|
|
119
|
+
var user = me.cache[valueField] && me.cache[valueField][id];
|
|
120
|
+
user && reqItem.result.indexOf(user) === -1 && reqItem.result.push(user);
|
|
121
|
+
});
|
|
122
|
+
if (reqItem.result.length === queryIds.length) {
|
|
123
|
+
me.removeRequest(reqItem);
|
|
124
|
+
cb(reqItem.result);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
})["finally"](function () {
|
|
128
|
+
reqLen--;
|
|
129
|
+
var errors = [];
|
|
130
|
+
if (!reqLen) {
|
|
131
|
+
_this4.requests.forEach(function (_ref4) {
|
|
132
|
+
var cb = _ref4.cb,
|
|
133
|
+
result = _ref4.result,
|
|
134
|
+
param = _ref4.param;
|
|
135
|
+
var queryIds = param.queryIds,
|
|
136
|
+
valueField = param.valueField;
|
|
137
|
+
cb(result);
|
|
138
|
+
queryIds.forEach(function (id) {
|
|
139
|
+
if (!_this4.cache[valueField] || !_this4.cache[valueField][id]) {
|
|
140
|
+
errors.push(id);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
errors.length && log("user [".concat(errors.join(','), "] not found"), 'warn');
|
|
145
|
+
_this4.clearRequest();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
setBatch: function setBatch(batch) {
|
|
151
|
+
if (typeof batch !== 'number' || batch <= 0) {
|
|
152
|
+
batch = 50;
|
|
153
|
+
}
|
|
154
|
+
if (batch <= 500 && this.batch < batch) {
|
|
155
|
+
this.batch = batch;
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
getusers: function getusers(_ref5) {
|
|
159
|
+
var _this5 = this;
|
|
160
|
+
var param = _ref5.param,
|
|
161
|
+
api = _ref5.api,
|
|
162
|
+
batch = _ref5.batch,
|
|
163
|
+
cb = _ref5.cb;
|
|
164
|
+
if (batch !== false) {
|
|
165
|
+
this.setBatch(batch);
|
|
166
|
+
clearTimeout(this.timmer);
|
|
167
|
+
this.addRequest({
|
|
168
|
+
param: param,
|
|
169
|
+
cb: cb
|
|
170
|
+
});
|
|
171
|
+
this.timmer = setTimeout(function () {
|
|
172
|
+
return _this5.batchRequest(api);
|
|
173
|
+
}, 100);
|
|
174
|
+
} else {
|
|
175
|
+
this.singleRequest(param, api, cb);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
splitArr: function splitArr(arr, num) {
|
|
179
|
+
var result = [];
|
|
180
|
+
if (arr.length && num > 0) {
|
|
181
|
+
var just = arr.length % num === 0;
|
|
182
|
+
var part = Math.floor(arr.length / num);
|
|
183
|
+
var len = just ? part : part + 1;
|
|
184
|
+
for (var i = 0; i < len; i++) {
|
|
185
|
+
result.push(arr.slice(i * num, (i + 1) * num));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
export var suggestUser = function suggestUser(api) {
|
|
192
|
+
return function (query) {
|
|
193
|
+
return new Promise(function (resolve, reject) {
|
|
194
|
+
api.fetchSuggestUser(query).then(function (users) {
|
|
195
|
+
if (users.length) {
|
|
196
|
+
resolve(users);
|
|
197
|
+
} else {
|
|
198
|
+
resolve({
|
|
199
|
+
invalid: query
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
})["catch"](reject);
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
export var updateOptions = function updateOptions(_ref6) {
|
|
207
|
+
var props = _ref6.props,
|
|
208
|
+
state = _ref6.state,
|
|
209
|
+
nextTick = _ref6.nextTick;
|
|
210
|
+
return function (usersList) {
|
|
211
|
+
var valueField = props.valueField,
|
|
212
|
+
textField = props.textField,
|
|
213
|
+
noDataText = props.noDataText;
|
|
214
|
+
var values = [].concat(state.user || []);
|
|
215
|
+
var options = [].concat(state.selected);
|
|
216
|
+
var hides = [];
|
|
217
|
+
var count = 0;
|
|
218
|
+
usersList.forEach(function (users) {
|
|
219
|
+
users.forEach(function (user) {
|
|
220
|
+
var u = user[valueField];
|
|
221
|
+
user._show = true;
|
|
222
|
+
count++;
|
|
223
|
+
if (!~values.indexOf(u)) {
|
|
224
|
+
values.push(u);
|
|
225
|
+
options.push(user);
|
|
226
|
+
} else {
|
|
227
|
+
hides.push(u);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
state.selected.forEach(function (us) {
|
|
232
|
+
us._show = !!~hides.indexOf(us[valueField]);
|
|
233
|
+
});
|
|
234
|
+
!count && !noDataText && (state.visible = false);
|
|
235
|
+
if (!props.sortByFetchData) {
|
|
236
|
+
options.sort(function (a, b) {
|
|
237
|
+
return a[textField] > b[textField] ? 1 : -1;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
state.options = options;
|
|
241
|
+
return nextTick();
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
export var autoSelect = function autoSelect(_ref7) {
|
|
245
|
+
var props = _ref7.props,
|
|
246
|
+
state = _ref7.state,
|
|
247
|
+
nextTick = _ref7.nextTick;
|
|
248
|
+
return function (usersList) {
|
|
249
|
+
if (!usersList.length) {
|
|
250
|
+
return nextTick();
|
|
251
|
+
}
|
|
252
|
+
var values = props.multiple ? [].concat(state.user) : [];
|
|
253
|
+
usersList.forEach(function (list) {
|
|
254
|
+
if (list.length === 1) {
|
|
255
|
+
var value = list[0][props.valueField];
|
|
256
|
+
!~values.indexOf(value) && values.push(value);
|
|
257
|
+
if (props.autoClose) {
|
|
258
|
+
state.visible = false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
if (!values.length) {
|
|
263
|
+
return nextTick();
|
|
264
|
+
}
|
|
265
|
+
if (props.multiple) {
|
|
266
|
+
state.user.length !== values.length && (state.user = values);
|
|
267
|
+
} else {
|
|
268
|
+
state.user = values[0];
|
|
269
|
+
}
|
|
270
|
+
return nextTick();
|
|
271
|
+
};
|
|
272
|
+
};
|
|
273
|
+
export var searchMethod = function searchMethod(_ref8) {
|
|
274
|
+
var api = _ref8.api,
|
|
275
|
+
props = _ref8.props,
|
|
276
|
+
state = _ref8.state,
|
|
277
|
+
emit = _ref8.emit;
|
|
278
|
+
return debounce(props.delay, function (query) {
|
|
279
|
+
if (query && query.length >= props.suggestLength) {
|
|
280
|
+
state.loading = true;
|
|
281
|
+
state.visible = true;
|
|
282
|
+
var multiple = props.multiple;
|
|
283
|
+
var suggests;
|
|
284
|
+
if (multiple) {
|
|
285
|
+
suggests = query.split(new RegExp("[".concat(props.textSplit.split('').join('\\'), "]"))).filter(function (q) {
|
|
286
|
+
return q && q.length >= props.suggestLength;
|
|
287
|
+
}).map(function (q) {
|
|
288
|
+
return api.suggestUser(q.trim());
|
|
289
|
+
});
|
|
290
|
+
} else {
|
|
291
|
+
suggests = [api.suggestUser(query.trim())];
|
|
292
|
+
}
|
|
293
|
+
Promise.all(suggests).then(function (users) {
|
|
294
|
+
var failList = [];
|
|
295
|
+
var usersList = [];
|
|
296
|
+
users.forEach(function (item) {
|
|
297
|
+
if (item.invalid) {
|
|
298
|
+
failList.push(item.invalid);
|
|
299
|
+
} else {
|
|
300
|
+
usersList.push(item);
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
if (failList.length) {
|
|
304
|
+
emit('error', failList);
|
|
305
|
+
}
|
|
306
|
+
api.updateOptions(usersList).then(function () {
|
|
307
|
+
api.autoSelect(usersList).then(function () {
|
|
308
|
+
api.userChange(state.user);
|
|
309
|
+
state.loading = false;
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
};
|
|
316
|
+
export var setSelected = function setSelected(_ref9) {
|
|
317
|
+
var api = _ref9.api,
|
|
318
|
+
props = _ref9.props,
|
|
319
|
+
state = _ref9.state;
|
|
320
|
+
return function (value) {
|
|
321
|
+
var values = Array.isArray(value) ? value.map(function (v) {
|
|
322
|
+
return String(v).toLocaleLowerCase();
|
|
323
|
+
}) : String(value).toLocaleLowerCase().split(props.valueSplit);
|
|
324
|
+
state.selected = state.options.filter(function (user) {
|
|
325
|
+
return ~values.indexOf(String(user[props.valueField]).toLocaleLowerCase());
|
|
326
|
+
});
|
|
327
|
+
props.cache && api.cacheUser(state.selected);
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
export var userChange = function userChange(_ref10) {
|
|
331
|
+
var api = _ref10.api,
|
|
332
|
+
emit = _ref10.emit,
|
|
333
|
+
props = _ref10.props,
|
|
334
|
+
state = _ref10.state;
|
|
335
|
+
return function (value) {
|
|
336
|
+
var multiple = props.multiple;
|
|
337
|
+
var newVal = multiple && Array.isArray(value) ? value.join(props.valueSplit) : String(value || '');
|
|
338
|
+
api.setSelected(newVal);
|
|
339
|
+
if (typeof state.lastValue === 'string' && state.lastValue !== null && state.lastValue.toLocaleLowerCase() !== newVal.toLocaleLowerCase()) {
|
|
340
|
+
emit('update:modelValue', newVal);
|
|
341
|
+
emit('change', newVal, state.selected);
|
|
342
|
+
}
|
|
343
|
+
state.lastValue = newVal;
|
|
344
|
+
};
|
|
345
|
+
};
|
|
346
|
+
var syncCacheIds = function syncCacheIds(ids, props, queryIds, cacheData) {
|
|
347
|
+
var valueField = props.valueField,
|
|
348
|
+
cacheFields = props.cacheFields,
|
|
349
|
+
cacheKey = props.cacheKey;
|
|
350
|
+
var cacheUsers = toJson(window.localStorage.getItem(cacheKey)) || {};
|
|
351
|
+
ids.forEach(function (id) {
|
|
352
|
+
if (cacheUsers[id]) {
|
|
353
|
+
var _cacheUser = cacheUsers[id];
|
|
354
|
+
var textField = props.textField === 'userCN' || props.textField === 'userId' || props.textField === 'dept' ? '' : props.textField;
|
|
355
|
+
if (textField !== '' && !_cacheUser.a) {
|
|
356
|
+
window.localStorage.removeItem(cacheKey);
|
|
357
|
+
queryIds.push(id);
|
|
358
|
+
}
|
|
359
|
+
var user = _defineProperty({
|
|
360
|
+
userId: _cacheUser.i,
|
|
361
|
+
userCN: _cacheUser.u,
|
|
362
|
+
dept: _cacheUser.d,
|
|
363
|
+
employeeNumber: _cacheUser.e
|
|
364
|
+
}, textField, _cacheUser.a);
|
|
365
|
+
cacheFields.forEach(function (field) {
|
|
366
|
+
user[field] = _cacheUser[field];
|
|
367
|
+
});
|
|
368
|
+
cacheData.push(Object.assign(user, _defineProperty({}, valueField, cacheUsers[id].p || cacheUsers[id].i)));
|
|
369
|
+
} else {
|
|
370
|
+
queryIds.push(id);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
export var getUsers = function getUsers(_ref11) {
|
|
375
|
+
var api = _ref11.api,
|
|
376
|
+
props = _ref11.props,
|
|
377
|
+
state = _ref11.state;
|
|
378
|
+
return function (value) {
|
|
379
|
+
var valueField = props.valueField,
|
|
380
|
+
cache = props.cache;
|
|
381
|
+
var ids = Array.isArray(value) ? value : value.split(props.valueSplit);
|
|
382
|
+
var cacheData = [];
|
|
383
|
+
var queryIds = cache ? [] : ids;
|
|
384
|
+
if (cache) {
|
|
385
|
+
syncCacheIds(ids, props, queryIds, cacheData);
|
|
386
|
+
request.setCache(cacheData, valueField);
|
|
387
|
+
if (!queryIds.length) {
|
|
388
|
+
return Promise.resolve(cacheData);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
var param = {
|
|
392
|
+
valueSplit: props.valueSplit,
|
|
393
|
+
valueField: valueField,
|
|
394
|
+
queryIds: queryIds
|
|
395
|
+
};
|
|
396
|
+
return new Promise(function (resolve, reject) {
|
|
397
|
+
var cb = function cb(data) {
|
|
398
|
+
if (data.error) {
|
|
399
|
+
reject(data.error);
|
|
400
|
+
} else {
|
|
401
|
+
resolve(data.concat(cacheData));
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
request.getusers({
|
|
405
|
+
param: param,
|
|
406
|
+
api: api,
|
|
407
|
+
batch: state.batch,
|
|
408
|
+
cb: cb
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
};
|
|
412
|
+
};
|
|
413
|
+
export var updateCache = function updateCache(_ref12) {
|
|
414
|
+
var props = _ref12.props,
|
|
415
|
+
state = _ref12.state;
|
|
416
|
+
return function () {
|
|
417
|
+
var users = toJson(window.localStorage.getItem(props.cacheKey)) || {};
|
|
418
|
+
var currDate = toDateStr(new Date(), 'yyyyMMdd');
|
|
419
|
+
if (currDate !== users.t) {
|
|
420
|
+
users.t = currDate;
|
|
421
|
+
for (var u in users) {
|
|
422
|
+
if (u !== 't') {
|
|
423
|
+
var user = users[u];
|
|
424
|
+
if (user.r > 0) {
|
|
425
|
+
user.r = 0;
|
|
426
|
+
} else {
|
|
427
|
+
user.r--;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
state.cache = users;
|
|
433
|
+
};
|
|
434
|
+
};
|
|
435
|
+
export var saveCache = function saveCache(_ref13) {
|
|
436
|
+
var props = _ref13.props;
|
|
437
|
+
return function (cache) {
|
|
438
|
+
window.localStorage.setItem(props.cacheKey, toJsonStr(cache));
|
|
439
|
+
};
|
|
440
|
+
};
|
|
441
|
+
export var cacheUser = function cacheUser(_ref14) {
|
|
442
|
+
var api = _ref14.api,
|
|
443
|
+
props = _ref14.props,
|
|
444
|
+
service = _ref14.service;
|
|
445
|
+
return function (users) {
|
|
446
|
+
var valueField = props.valueField,
|
|
447
|
+
cacheKey = props.cacheKey;
|
|
448
|
+
var cacheUser = toJson(window.localStorage.getItem(cacheKey)) || {};
|
|
449
|
+
var cacheFields = service.userCache;
|
|
450
|
+
var user;
|
|
451
|
+
var _loop2 = function _loop2() {
|
|
452
|
+
var u = users[i];
|
|
453
|
+
var key = u[valueField];
|
|
454
|
+
user = cacheUser[key];
|
|
455
|
+
if (user) {
|
|
456
|
+
user.r++;
|
|
457
|
+
} else {
|
|
458
|
+
var us = {
|
|
459
|
+
p: u[valueField],
|
|
460
|
+
i: u[cacheFields.userId],
|
|
461
|
+
u: u[cacheFields.userCN],
|
|
462
|
+
d: u[cacheFields.dept],
|
|
463
|
+
e: u[cacheFields.eno],
|
|
464
|
+
a: ~['userCN', 'userId', 'dept'].indexOf(props.textField) ? null : u[props.textField],
|
|
465
|
+
r: 0
|
|
466
|
+
};
|
|
467
|
+
props.cacheFields.forEach(function (field) {
|
|
468
|
+
us[field] = u[field];
|
|
469
|
+
});
|
|
470
|
+
cacheUser[key] = us;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
for (var i = 0; i < users.length; i++) {
|
|
474
|
+
_loop2();
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
api.saveCache(cacheUser);
|
|
478
|
+
} catch (e) {
|
|
479
|
+
var sortUsers = Object.keys(cacheUser).sort(function (a, b) {
|
|
480
|
+
return cacheUser[a].r < cacheUser[b].r ? 1 : -1;
|
|
481
|
+
});
|
|
482
|
+
var cutUser = sortUsers.splice(0, sortUsers.length / 2);
|
|
483
|
+
var newCache = {};
|
|
484
|
+
for (var _i in cutUser) {
|
|
485
|
+
if (Object.prototype.hasOwnProperty.call(cutUser, _i)) {
|
|
486
|
+
newCache[cutUser[_i]] = cacheUser[cutUser[_i]];
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
api.saveCache(newCache);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
export var useSortable = function useSortable(_ref15) {
|
|
494
|
+
var api = _ref15.api,
|
|
495
|
+
props = _ref15.props,
|
|
496
|
+
state = _ref15.state,
|
|
497
|
+
refs = _ref15.refs;
|
|
498
|
+
return function () {
|
|
499
|
+
var selectDom = refs.select.$el;
|
|
500
|
+
if (props.sortable && props.multiple && !state.sortable) {
|
|
501
|
+
var tagsDom = selectDom.querySelector('.aui-select__tags>span');
|
|
502
|
+
state.sortable = props.sortable.create(tagsDom, {
|
|
503
|
+
handle: '.aui-tag',
|
|
504
|
+
ghostClass: 'aui-user__ghost',
|
|
505
|
+
onEnd: function onEnd(_ref16) {
|
|
506
|
+
var newIndex = _ref16.newIndex,
|
|
507
|
+
oldIndex = _ref16.oldIndex;
|
|
508
|
+
var currUser = state.user.splice(oldIndex, 1)[0];
|
|
509
|
+
state.user.splice(newIndex, 0, currUser);
|
|
510
|
+
api.userChange(state.user);
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
};
|
|
516
|
+
export var visibleChange = function visibleChange(_ref17) {
|
|
517
|
+
var state = _ref17.state,
|
|
518
|
+
emit = _ref17.emit;
|
|
519
|
+
return function (show) {
|
|
520
|
+
if (!show) {
|
|
521
|
+
state.visible = show;
|
|
522
|
+
state.options = state.selected.map(function (user) {
|
|
523
|
+
return Object.assign(user, {
|
|
524
|
+
_show: true
|
|
525
|
+
});
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
emit('visible-change', show);
|
|
529
|
+
};
|
|
530
|
+
};
|
|
531
|
+
export var initUser = function initUser(_ref18) {
|
|
532
|
+
var api = _ref18.api,
|
|
533
|
+
props = _ref18.props,
|
|
534
|
+
state = _ref18.state;
|
|
535
|
+
return function (value) {
|
|
536
|
+
if (value === state.lastValue) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
state.user = !props.multiple ? '' : [];
|
|
540
|
+
if (typeof value === 'number') {
|
|
541
|
+
value = String(value);
|
|
542
|
+
}
|
|
543
|
+
if (!value) {
|
|
544
|
+
state.options = [];
|
|
545
|
+
state.selected = [];
|
|
546
|
+
api.userChange(value);
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
value && api.getUsers(value).then(function (info) {
|
|
550
|
+
info.sort(function (a, b) {
|
|
551
|
+
return value.indexOf(String(a[props.valueField])) > value.indexOf(String(b[props.valueField])) ? 1 : -1;
|
|
552
|
+
});
|
|
553
|
+
var list = info.map(function (user) {
|
|
554
|
+
user._show = true;
|
|
555
|
+
return user[props.valueField];
|
|
556
|
+
});
|
|
557
|
+
state.options = info;
|
|
558
|
+
state.user = props.multiple ? list : list[0];
|
|
559
|
+
api.userChange(value);
|
|
560
|
+
});
|
|
561
|
+
};
|
|
562
|
+
};
|
|
563
|
+
export var handleBlur = function handleBlur(_ref19) {
|
|
564
|
+
var constants = _ref19.constants,
|
|
565
|
+
dispatch = _ref19.dispatch,
|
|
566
|
+
state = _ref19.state;
|
|
567
|
+
return function () {
|
|
568
|
+
dispatch(constants.COMPONENT_NAME.FormItem, constants.EVENT_NAME.FormBlur, state.user);
|
|
569
|
+
};
|
|
570
|
+
};
|
|
571
|
+
export var initService = function initService(_ref20) {
|
|
572
|
+
var props = _ref20.props,
|
|
573
|
+
service = _ref20.service;
|
|
574
|
+
var noopFnCreator = function noopFnCreator(propName) {
|
|
575
|
+
return function () {
|
|
576
|
+
if (propName) {
|
|
577
|
+
return Promise.reject(new Error("[TINY Error][User]] Prop ".concat(propName, " is not configured")));
|
|
578
|
+
} else {
|
|
579
|
+
return Promise.reject(new Error('[TINY Error][User]] This component depends on @opentiny/vue-service'));
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
};
|
|
583
|
+
var $service = service || {};
|
|
584
|
+
var _$service$common = $service.common,
|
|
585
|
+
common = _$service$common === void 0 ? {} : _$service$common,
|
|
586
|
+
_$service$setting = $service.setting,
|
|
587
|
+
setting = _$service$setting === void 0 ? {} : _$service$setting,
|
|
588
|
+
_$service$base = $service.base,
|
|
589
|
+
base = _$service$base === void 0 ? {} : _$service$base;
|
|
590
|
+
var fetchUser = $service.fetchUser,
|
|
591
|
+
fetchW3Accounts = $service.fetchW3Accounts,
|
|
592
|
+
fetchSuggestUser = $service.fetchSuggestUser,
|
|
593
|
+
fetchUserByUserId = $service.fetchUserByUserId;
|
|
594
|
+
var _setting$options = setting.options,
|
|
595
|
+
options = _setting$options === void 0 ? {} : _setting$options;
|
|
596
|
+
var _options$UserCache = options.UserCache,
|
|
597
|
+
UserCache = _options$UserCache === void 0 ? {
|
|
598
|
+
uuid: 'uuid',
|
|
599
|
+
userId: 'userId',
|
|
600
|
+
userCN: 'userCN',
|
|
601
|
+
dept: 'dept',
|
|
602
|
+
eno: 'employeeNumber'
|
|
603
|
+
} : _options$UserCache,
|
|
604
|
+
_options$User = options.User,
|
|
605
|
+
User = _options$User === void 0 ? {
|
|
606
|
+
batch: 50
|
|
607
|
+
} : _options$User;
|
|
608
|
+
return {
|
|
609
|
+
fetchUser: props.fetchUser || fetchUser || noopFnCreator('fetchUser'),
|
|
610
|
+
fetchW3Accounts: props.fetchW3Accounts || fetchW3Accounts || noopFnCreator('fetchW3Accounts'),
|
|
611
|
+
fetchSuggestUser: props.fetchSuggestUser || fetchSuggestUser || noopFnCreator('fetchSuggestUser'),
|
|
612
|
+
fetchUserByUserId: props.fetchUserByUserId || fetchUserByUserId || noopFnCreator('fetchUserByUserId'),
|
|
613
|
+
getUserImageUrl: props.getUserImageUrl || common.getUserImageUrl || noopFnCreator('getUserImageUrl'),
|
|
614
|
+
getLangData: props.getLangData || base.getLangData || noopFnCreator('getLangData'),
|
|
615
|
+
getUserInfo: props.getUserInfo || base.getUserInfo || noopFnCreator('getUserInfo'),
|
|
616
|
+
userCache: props.UserCache || UserCache,
|
|
617
|
+
batch: User.batch
|
|
618
|
+
};
|
|
619
|
+
};
|
|
620
|
+
export var filter = function filter(_ref21) {
|
|
621
|
+
var props = _ref21.props,
|
|
622
|
+
state = _ref21.state;
|
|
623
|
+
return function () {
|
|
624
|
+
if (props.multiple && props.hideSelected) {
|
|
625
|
+
var selectedUsers = state.user.map(function (value) {
|
|
626
|
+
return typeof value === 'string' ? value.toLocaleLowerCase() : value;
|
|
627
|
+
});
|
|
628
|
+
return state.options.filter(function (user) {
|
|
629
|
+
return !~selectedUsers.indexOf(typeof user[props.valueField] === 'string' ? user[props.valueField].toLocaleLowerCase() : user[props.valueField]);
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
return state.options;
|
|
633
|
+
};
|
|
634
|
+
};
|