bri-components 1.5.21 → 1.6.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/README.md +83 -83
- package/lib/styles/bundle.css +12 -12
- package/lib/styles/font/fontello.svg +31 -31
- package/package.json +125 -125
- package/src/components/Error/Error403.vue +42 -42
- package/src/components/Error/Error404.vue +40 -40
- package/src/components/Error/Error500.vue +51 -51
- package/src/components/Error/error.less +162 -162
- package/src/components/Error/errorBack.vue +40 -40
- package/src/components/controls/DshControlInput.vue +195 -195
- package/src/components/controls/base/BriUpload/BriUpload.vue +434 -434
- package/src/components/controls/base/BriUpload/BriUploadImage.vue +377 -377
- package/src/components/controls/base/BriUpload/uploadList.vue +727 -727
- package/src/components/controls/base/BriUpload/uploadMixin.js +446 -446
- package/src/components/controls/base/DshCascader/DshCascader.vue +215 -215
- package/src/components/controls/base/DshCascader/components/cascaderModal.vue +366 -366
- package/src/components/controls/base/DshCascader/components/cascaderPicker.vue +416 -416
- package/src/components/controls/base/DshCascader/components/cascaderSimple.vue +141 -141
- package/src/components/controls/base/DshCascader/components/cascaderTree.vue +151 -151
- package/src/components/controls/base/DshCoordinates.vue +585 -577
- package/src/components/controls/base/DshDate/DshDate.vue +191 -191
- package/src/components/controls/base/DshDate/DshDaterange.vue +186 -186
- package/src/components/controls/base/DshDivider.vue +201 -201
- package/src/components/controls/base/DshEditor.vue +274 -274
- package/src/components/controls/base/DshInput/BriInputs.vue +166 -166
- package/src/components/controls/base/DshInput/DshInput.vue +260 -260
- package/src/components/controls/base/DshNumber/BriInputNumber/BriInputNumber.vue +435 -435
- package/src/components/controls/base/DshNumber/BriInputNumber/mixins/emitter.js +34 -34
- package/src/components/controls/base/DshNumber/BriInputNumber/mixins/form.js +14 -14
- package/src/components/controls/base/DshNumber/BriInputNumber/utils/assist.js +322 -322
- package/src/components/controls/base/DshNumber/DshNumber.vue +143 -143
- package/src/components/controls/base/DshNumber/DshNumberange.vue +109 -109
- package/src/components/controls/base/DshSelect/DshCheckbox.vue +168 -168
- package/src/components/controls/base/DshSelect/DshSelect.vue +180 -180
- package/src/components/controls/base/DshSelect/DshSelectAll.vue +269 -269
- package/src/components/controls/base/DshSwitch/DshSwitch.vue +115 -115
- package/src/components/controls/control.less +324 -324
- package/src/components/controls/controlMap.js +117 -117
- package/src/components/controls/extra/DshColor.vue +81 -81
- package/src/components/controls/extra/DshThemeColor.vue +100 -100
- package/src/components/controls/extra/DshThemeIcon.vue +122 -122
- package/src/components/controls/mixins/cascaderMixin.js +325 -325
- package/src/components/controls/mixins/cascaderPickerMixin.js +227 -227
- package/src/components/controls/mixins/cascaderTableMixin.js +130 -130
- package/src/components/controls/mixins/controlMixin.js +393 -393
- package/src/components/controls/mixins/dateMixin.js +149 -149
- package/src/components/controls/mixins/flatTableMixin.js +111 -111
- package/src/components/controls/mixins/numberMixin.js +112 -112
- package/src/components/controls/mixins/selectMixin.js +233 -233
- package/src/components/controls/mixins/switchMixin.js +87 -87
- package/src/components/controls/mixins/userAndDepartMixin.js +260 -260
- package/src/components/controls/senior/DshLabels.vue +333 -333
- package/src/components/controls/senior/DshPackage.vue +57 -57
- package/src/components/controls/senior/cascaderTable.vue +213 -213
- package/src/components/controls/senior/correlation.vue +135 -135
- package/src/components/controls/senior/flatTable.vue +138 -138
- package/src/components/controls/senior/selectDepartments.vue +399 -399
- package/src/components/controls/senior/selectUsers/departMenu.vue +293 -293
- package/src/components/controls/senior/selectUsers/selectUsers.vue +712 -712
- package/src/components/controls/special/DshBack.vue +42 -42
- package/src/components/controls/special/DshUndeveloped.vue +41 -41
- package/src/components/form/DshAdvSearch.vue +510 -510
- package/src/components/form/DshDefaultSearch.vue +260 -260
- package/src/components/form/DshForm.vue +494 -494
- package/src/components/form/searchMixin.js +376 -376
- package/src/components/list/BriCard.vue +95 -95
- package/src/components/list/BriTable.vue +205 -205
- package/src/components/list/BriTree.vue +529 -529
- package/src/components/list/BriTreeItem.vue +163 -163
- package/src/components/list/DshBox/DshBox.vue +219 -219
- package/src/components/list/DshBox/DshCard.vue +446 -446
- package/src/components/list/DshBox/DshCrossTable.vue +827 -827
- package/src/components/list/DshBox/DshList.vue +404 -404
- package/src/components/list/DshBox/DshPanel.vue +669 -669
- package/src/components/list/DshBox/DshSingleData.vue +119 -119
- package/src/components/list/DshBox/DshTable.vue +239 -239
- package/src/components/list/DshCascaderTable.vue +115 -115
- package/src/components/list/DshFlatTable.vue +337 -337
- package/src/components/list/DshPage.vue +194 -194
- package/src/components/list/DshTreeTable.vue +113 -113
- package/src/components/list/common/importModal.vue +243 -243
- package/src/components/list/common/quoteListModal.vue +206 -206
- package/src/components/list/mixins/DshCascaderTableMixin.js +278 -278
- package/src/components/list/mixins/DshFlatTableMixin.js +509 -509
- package/src/components/list/mixins/DshTreeTableMixin.js +286 -286
- package/src/components/list/mixins/tableBaseMixin.js +1653 -1653
- package/src/components/list/mixins/treeTableBaseMixin.js +145 -145
- package/src/components/other/BriAvatar.vue +166 -166
- package/src/components/other/BriCode.vue +125 -125
- package/src/components/other/BriCollapseTree.vue +207 -207
- package/src/components/other/BriGantt.vue +1087 -1087
- package/src/components/other/BriIframe.vue +116 -116
- package/src/components/other/BriLoading.vue +171 -171
- package/src/components/other/BriSvg.vue +27 -27
- package/src/components/other/DshColorPanel.vue +128 -128
- package/src/components/other/DshMenuNav.vue +188 -188
- package/src/components/small/BriButton.vue +71 -71
- package/src/components/small/BriDrawer.vue +169 -169
- package/src/components/small/BriTooltip.vue +87 -87
- package/src/components/small/DshBtnModal.vue +68 -68
- package/src/components/small/DshButtons.vue +324 -324
- package/src/components/small/DshDropdown.vue +225 -225
- package/src/components/small/DshIcons.vue +59 -59
- package/src/components/small/DshListRender.js +21 -21
- package/src/components/small/DshModal.vue +160 -160
- package/src/components/small/DshSteps.vue +141 -141
- package/src/components/small/DshTabs.vue +598 -598
- package/src/components/small/DshTabsSet.vue +309 -309
- package/src/components/small/DshTags.vue +251 -251
- package/src/components/small/DshTitle.vue +50 -50
- package/src/components/small/render.js +20 -20
- package/src/components/unit/DshFormUnit.vue +398 -398
- package/src/components/unit/DshListUnit.vue +115 -115
- package/src/components/unit/unitMixin.js +86 -86
- package/src/data/index.js +4 -4
- package/src/index.js +285 -285
- package/src/styles/bundle.css +12 -12
- package/src/styles/components/BriButton.less +307 -307
- package/src/styles/components/BriTable.less +344 -344
- package/src/styles/components/DshModal.less +257 -257
- package/src/styles/components/index.less +3 -3
- package/src/styles/global/animate.less +11 -11
- package/src/styles/global/base.less +45 -45
- package/src/styles/global/box.less +186 -186
- package/src/styles/global/control.less +122 -122
- package/src/styles/global/flex.less +282 -282
- package/src/styles/global/global.less +8 -8
- package/src/styles/global/text.less +59 -59
- package/src/styles/global/variables.less +85 -85
- package/src/styles/iconfont/iconfont.css +254 -254
- package/src/styles/iconfont/iconfont.json +422 -422
- package/src/styles/iconfont/iconfont.svg +137 -137
- package/src/styles/index.less +26 -26
- package/src/styles/reset-easytable.less +21 -21
- package/src/styles/reset-iview-controls.less +145 -145
- package/src/styles/reset-iview-other.less +49 -49
- package/src/styles/reset-iview-variables.less +43 -43
- package/src/styles/reset.less +45 -45
- package/src/utils/index.js +3 -5
- package/lib/0.bri-components.min.js +0 -1
- package/lib/1.bri-components.min.js +0 -1
- package/lib/10.bri-components.min.js +0 -1
- package/lib/11.bri-components.min.js +0 -1
- package/lib/2.bri-components.min.js +0 -1
- package/lib/3.bri-components.min.js +0 -1
- package/lib/4.bri-components.min.js +0 -1
- package/lib/5.bri-components.min.js +0 -1
- package/lib/6.bri-components.min.js +0 -1
- package/lib/7.bri-components.min.js +0 -1
- package/lib/8.bri-components.min.js +0 -1
- package/lib/9.bri-components.min.js +0 -1
- package/lib/bri-components.min.js +0 -18
- package/src/utils/table.js +0 -175
|
@@ -1,322 +1,322 @@
|
|
|
1
|
-
import Vue from "vue";
|
|
2
|
-
const isServer = Vue.prototype.$isServer;
|
|
3
|
-
|
|
4
|
-
export function camelcaseToHyphen (str) {
|
|
5
|
-
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// For Modal scrollBar hidden
|
|
9
|
-
let cached;
|
|
10
|
-
export function getScrollBarSize (fresh) {
|
|
11
|
-
if (isServer) return 0;
|
|
12
|
-
if (fresh || cached === undefined) {
|
|
13
|
-
const inner = document.createElement("div");
|
|
14
|
-
inner.style.width = "100%";
|
|
15
|
-
inner.style.height = "200px";
|
|
16
|
-
|
|
17
|
-
const outer = document.createElement("div");
|
|
18
|
-
const outerStyle = outer.style;
|
|
19
|
-
|
|
20
|
-
outerStyle.position = "absolute";
|
|
21
|
-
outerStyle.top = 0;
|
|
22
|
-
outerStyle.left = 0;
|
|
23
|
-
outerStyle.pointerEvents = "none";
|
|
24
|
-
outerStyle.visibility = "hidden";
|
|
25
|
-
outerStyle.width = "200px";
|
|
26
|
-
outerStyle.height = "150px";
|
|
27
|
-
outerStyle.overflow = "hidden";
|
|
28
|
-
|
|
29
|
-
outer.appendChild(inner);
|
|
30
|
-
|
|
31
|
-
document.body.appendChild(outer);
|
|
32
|
-
|
|
33
|
-
const widthContained = inner.offsetWidth;
|
|
34
|
-
outer.style.overflow = "scroll";
|
|
35
|
-
let widthScroll = inner.offsetWidth;
|
|
36
|
-
|
|
37
|
-
if (widthContained === widthScroll) {
|
|
38
|
-
widthScroll = outer.clientWidth;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
document.body.removeChild(outer);
|
|
42
|
-
|
|
43
|
-
cached = widthContained - widthScroll;
|
|
44
|
-
}
|
|
45
|
-
return cached;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// watch DOM change
|
|
49
|
-
export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
|
|
50
|
-
|
|
51
|
-
const SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
|
|
52
|
-
// const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g; // eslint认为\为无用的转义符(:和_不需要转义)
|
|
53
|
-
const MOZ_HACK_REGEXP = /^moz([A-Z])/;
|
|
54
|
-
|
|
55
|
-
function camelCase (name) {
|
|
56
|
-
return name.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
57
|
-
return offset ? letter.toUpperCase() : letter;
|
|
58
|
-
}).replace(MOZ_HACK_REGEXP, "Moz$1");
|
|
59
|
-
}
|
|
60
|
-
// getStyle
|
|
61
|
-
export function getStyle (element, styleName) {
|
|
62
|
-
if (!element || !styleName) return null;
|
|
63
|
-
styleName = camelCase(styleName);
|
|
64
|
-
if (styleName === "float") {
|
|
65
|
-
styleName = "cssFloat";
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const computed = document.defaultView.getComputedStyle(element, "");
|
|
69
|
-
return element.style[styleName] || computed ? computed[styleName] : null;
|
|
70
|
-
} catch (e) {
|
|
71
|
-
return element.style[styleName];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// firstUpperCase
|
|
76
|
-
function firstUpperCase (str) {
|
|
77
|
-
return str.toString()[0].toUpperCase() + str.toString().slice(1);
|
|
78
|
-
}
|
|
79
|
-
export {firstUpperCase};
|
|
80
|
-
|
|
81
|
-
// Warn
|
|
82
|
-
export function warnProp (component, prop, correctType, wrongType) {
|
|
83
|
-
correctType = firstUpperCase(correctType);
|
|
84
|
-
wrongType = firstUpperCase(wrongType);
|
|
85
|
-
console.error(`[iView warn]: Invalid prop: type check failed for prop ${prop}. Expected ${correctType}, got ${wrongType}. (found in component: ${component})`); // eslint-disable-line
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function typeOf (obj) {
|
|
89
|
-
const toString = Object.prototype.toString;
|
|
90
|
-
const map = {
|
|
91
|
-
"[object Boolean]": "boolean",
|
|
92
|
-
"[object Number]": "number",
|
|
93
|
-
"[object String]": "string",
|
|
94
|
-
"[object Function]": "function",
|
|
95
|
-
"[object Array]": "array",
|
|
96
|
-
"[object Date]": "date",
|
|
97
|
-
"[object RegExp]": "regExp",
|
|
98
|
-
"[object Undefined]": "undefined",
|
|
99
|
-
"[object Null]": "null",
|
|
100
|
-
"[object Object]": "object"
|
|
101
|
-
};
|
|
102
|
-
return map[toString.call(obj)];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// deepCopy
|
|
106
|
-
function deepCopy (data) {
|
|
107
|
-
const t = typeOf(data);
|
|
108
|
-
let o;
|
|
109
|
-
|
|
110
|
-
if (t === "array") {
|
|
111
|
-
o = [];
|
|
112
|
-
} else if (t === "object") {
|
|
113
|
-
o = {};
|
|
114
|
-
} else {
|
|
115
|
-
return data;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (t === "array") {
|
|
119
|
-
for (let i = 0; i < data.length; i++) {
|
|
120
|
-
o.push(deepCopy(data[i]));
|
|
121
|
-
}
|
|
122
|
-
} else if (t === "object") {
|
|
123
|
-
for (let i in data) {
|
|
124
|
-
o[i] = deepCopy(data[i]);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return o;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export {deepCopy};
|
|
131
|
-
|
|
132
|
-
// scrollTop animation
|
|
133
|
-
export function scrollTop (el, from = 0, to, duration = 500, endCallback) {
|
|
134
|
-
if (!window.requestAnimationFrame) {
|
|
135
|
-
window.requestAnimationFrame = (
|
|
136
|
-
window.webkitRequestAnimationFrame ||
|
|
137
|
-
window.mozRequestAnimationFrame ||
|
|
138
|
-
window.msRequestAnimationFrame ||
|
|
139
|
-
function (callback) {
|
|
140
|
-
return window.setTimeout(callback, 1000 / 60);
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
const difference = Math.abs(from - to);
|
|
145
|
-
const step = Math.ceil(difference / duration * 50);
|
|
146
|
-
|
|
147
|
-
function scroll (start, end, step) {
|
|
148
|
-
if (start === end) {
|
|
149
|
-
endCallback && endCallback();
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
let d = (start + step > end) ? end : start + step;
|
|
154
|
-
if (start > end) {
|
|
155
|
-
d = (start - step < end) ? end : start - step;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (el === window) {
|
|
159
|
-
window.scrollTo(d, d);
|
|
160
|
-
} else {
|
|
161
|
-
el.scrollTop = d;
|
|
162
|
-
}
|
|
163
|
-
window.requestAnimationFrame(() => scroll(d, end, step));
|
|
164
|
-
}
|
|
165
|
-
scroll(from, to, step);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Find components upward
|
|
169
|
-
function findComponentUpward (context, componentName, componentNames) {
|
|
170
|
-
if (typeof componentName === "string") {
|
|
171
|
-
componentNames = [componentName];
|
|
172
|
-
} else {
|
|
173
|
-
componentNames = componentName;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
let parent = context.$parent;
|
|
177
|
-
let name = parent.$options.name;
|
|
178
|
-
while (parent && (!name || componentNames.indexOf(name) < 0)) {
|
|
179
|
-
parent = parent.$parent;
|
|
180
|
-
if (parent) name = parent.$options.name;
|
|
181
|
-
}
|
|
182
|
-
return parent;
|
|
183
|
-
}
|
|
184
|
-
export {findComponentUpward};
|
|
185
|
-
|
|
186
|
-
// Find component downward
|
|
187
|
-
export function findComponentDownward (context, componentName) {
|
|
188
|
-
const childrens = context.$children;
|
|
189
|
-
let children = null;
|
|
190
|
-
|
|
191
|
-
if (childrens.length) {
|
|
192
|
-
for (const child of childrens) {
|
|
193
|
-
const name = child.$options.name;
|
|
194
|
-
if (name === componentName) {
|
|
195
|
-
children = child;
|
|
196
|
-
break;
|
|
197
|
-
} else {
|
|
198
|
-
children = findComponentDownward(child, componentName);
|
|
199
|
-
if (children) break;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return children;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Find components downward
|
|
207
|
-
export function findComponentsDownward (context, componentName) {
|
|
208
|
-
return context.$children.reduce((components, child) => {
|
|
209
|
-
if (child.$options.name === componentName) components.push(child);
|
|
210
|
-
const foundChilds = findComponentsDownward(child, componentName);
|
|
211
|
-
return components.concat(foundChilds);
|
|
212
|
-
}, []);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// Find components upward
|
|
216
|
-
export function findComponentsUpward (context, componentName) {
|
|
217
|
-
let parents = [];
|
|
218
|
-
const parent = context.$parent;
|
|
219
|
-
if (parent) {
|
|
220
|
-
if (parent.$options.name === componentName) parents.push(parent);
|
|
221
|
-
return parents.concat(findComponentsUpward(parent, componentName));
|
|
222
|
-
} else {
|
|
223
|
-
return [];
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Find brothers components
|
|
228
|
-
export function findBrothersComponents (context, componentName, exceptMe = true) {
|
|
229
|
-
let res = context.$parent.$children.filter(item => {
|
|
230
|
-
return item.$options.name === componentName;
|
|
231
|
-
});
|
|
232
|
-
let index = res.findIndex(item => item._uid === context._uid);
|
|
233
|
-
if (exceptMe) res.splice(index, 1);
|
|
234
|
-
return res;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/* istanbul ignore next */
|
|
238
|
-
const trim = function (string) {
|
|
239
|
-
return (string || "").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, "");
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
/* istanbul ignore next */
|
|
243
|
-
export function hasClass (el, cls) {
|
|
244
|
-
if (!el || !cls) return false;
|
|
245
|
-
if (cls.indexOf(" ") !== -1) throw new Error("className should not contain space.");
|
|
246
|
-
if (el.classList) {
|
|
247
|
-
return el.classList.contains(cls);
|
|
248
|
-
} else {
|
|
249
|
-
return (" " + el.className + " ").indexOf(" " + cls + " ") > -1;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/* istanbul ignore next */
|
|
254
|
-
export function addClass (el, cls) {
|
|
255
|
-
if (!el) return;
|
|
256
|
-
let curClass = el.className;
|
|
257
|
-
const classes = (cls || "").split(" ");
|
|
258
|
-
|
|
259
|
-
for (let i = 0, j = classes.length; i < j; i++) {
|
|
260
|
-
const clsName = classes[i];
|
|
261
|
-
if (!clsName) continue;
|
|
262
|
-
|
|
263
|
-
if (el.classList) {
|
|
264
|
-
el.classList.add(clsName);
|
|
265
|
-
} else {
|
|
266
|
-
if (!hasClass(el, clsName)) {
|
|
267
|
-
curClass += " " + clsName;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (!el.classList) {
|
|
272
|
-
el.className = curClass;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/* istanbul ignore next */
|
|
277
|
-
export function removeClass (el, cls) {
|
|
278
|
-
if (!el || !cls) return;
|
|
279
|
-
const classes = cls.split(" ");
|
|
280
|
-
let curClass = " " + el.className + " ";
|
|
281
|
-
|
|
282
|
-
for (let i = 0, j = classes.length; i < j; i++) {
|
|
283
|
-
const clsName = classes[i];
|
|
284
|
-
if (!clsName) continue;
|
|
285
|
-
|
|
286
|
-
if (el.classList) {
|
|
287
|
-
el.classList.remove(clsName);
|
|
288
|
-
} else {
|
|
289
|
-
if (hasClass(el, clsName)) {
|
|
290
|
-
curClass = curClass.replace(" " + clsName + " ", " ");
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (!el.classList) {
|
|
295
|
-
el.className = trim(curClass);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export const dimensionMap = {
|
|
300
|
-
xs: "480px",
|
|
301
|
-
sm: "576px",
|
|
302
|
-
md: "768px",
|
|
303
|
-
lg: "992px",
|
|
304
|
-
xl: "1200px",
|
|
305
|
-
xxl: "1600px"
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
export function setMatchMedia () {
|
|
309
|
-
if (typeof window !== "undefined") {
|
|
310
|
-
const matchMediaPolyfill = mediaQuery => {
|
|
311
|
-
return {
|
|
312
|
-
media: mediaQuery,
|
|
313
|
-
matches: false,
|
|
314
|
-
on () {},
|
|
315
|
-
off () {}
|
|
316
|
-
};
|
|
317
|
-
};
|
|
318
|
-
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
export const sharpMatcherRegx = /#([^#]+)$/;
|
|
1
|
+
import Vue from "vue";
|
|
2
|
+
const isServer = Vue.prototype.$isServer;
|
|
3
|
+
|
|
4
|
+
export function camelcaseToHyphen (str) {
|
|
5
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// For Modal scrollBar hidden
|
|
9
|
+
let cached;
|
|
10
|
+
export function getScrollBarSize (fresh) {
|
|
11
|
+
if (isServer) return 0;
|
|
12
|
+
if (fresh || cached === undefined) {
|
|
13
|
+
const inner = document.createElement("div");
|
|
14
|
+
inner.style.width = "100%";
|
|
15
|
+
inner.style.height = "200px";
|
|
16
|
+
|
|
17
|
+
const outer = document.createElement("div");
|
|
18
|
+
const outerStyle = outer.style;
|
|
19
|
+
|
|
20
|
+
outerStyle.position = "absolute";
|
|
21
|
+
outerStyle.top = 0;
|
|
22
|
+
outerStyle.left = 0;
|
|
23
|
+
outerStyle.pointerEvents = "none";
|
|
24
|
+
outerStyle.visibility = "hidden";
|
|
25
|
+
outerStyle.width = "200px";
|
|
26
|
+
outerStyle.height = "150px";
|
|
27
|
+
outerStyle.overflow = "hidden";
|
|
28
|
+
|
|
29
|
+
outer.appendChild(inner);
|
|
30
|
+
|
|
31
|
+
document.body.appendChild(outer);
|
|
32
|
+
|
|
33
|
+
const widthContained = inner.offsetWidth;
|
|
34
|
+
outer.style.overflow = "scroll";
|
|
35
|
+
let widthScroll = inner.offsetWidth;
|
|
36
|
+
|
|
37
|
+
if (widthContained === widthScroll) {
|
|
38
|
+
widthScroll = outer.clientWidth;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
document.body.removeChild(outer);
|
|
42
|
+
|
|
43
|
+
cached = widthContained - widthScroll;
|
|
44
|
+
}
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// watch DOM change
|
|
49
|
+
export const MutationObserver = isServer ? false : window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || false;
|
|
50
|
+
|
|
51
|
+
const SPECIAL_CHARS_REGEXP = /([:\-_]+(.))/g;
|
|
52
|
+
// const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g; // eslint认为\为无用的转义符(:和_不需要转义)
|
|
53
|
+
const MOZ_HACK_REGEXP = /^moz([A-Z])/;
|
|
54
|
+
|
|
55
|
+
function camelCase (name) {
|
|
56
|
+
return name.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
57
|
+
return offset ? letter.toUpperCase() : letter;
|
|
58
|
+
}).replace(MOZ_HACK_REGEXP, "Moz$1");
|
|
59
|
+
}
|
|
60
|
+
// getStyle
|
|
61
|
+
export function getStyle (element, styleName) {
|
|
62
|
+
if (!element || !styleName) return null;
|
|
63
|
+
styleName = camelCase(styleName);
|
|
64
|
+
if (styleName === "float") {
|
|
65
|
+
styleName = "cssFloat";
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
const computed = document.defaultView.getComputedStyle(element, "");
|
|
69
|
+
return element.style[styleName] || computed ? computed[styleName] : null;
|
|
70
|
+
} catch (e) {
|
|
71
|
+
return element.style[styleName];
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// firstUpperCase
|
|
76
|
+
function firstUpperCase (str) {
|
|
77
|
+
return str.toString()[0].toUpperCase() + str.toString().slice(1);
|
|
78
|
+
}
|
|
79
|
+
export {firstUpperCase};
|
|
80
|
+
|
|
81
|
+
// Warn
|
|
82
|
+
export function warnProp (component, prop, correctType, wrongType) {
|
|
83
|
+
correctType = firstUpperCase(correctType);
|
|
84
|
+
wrongType = firstUpperCase(wrongType);
|
|
85
|
+
console.error(`[iView warn]: Invalid prop: type check failed for prop ${prop}. Expected ${correctType}, got ${wrongType}. (found in component: ${component})`); // eslint-disable-line
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function typeOf (obj) {
|
|
89
|
+
const toString = Object.prototype.toString;
|
|
90
|
+
const map = {
|
|
91
|
+
"[object Boolean]": "boolean",
|
|
92
|
+
"[object Number]": "number",
|
|
93
|
+
"[object String]": "string",
|
|
94
|
+
"[object Function]": "function",
|
|
95
|
+
"[object Array]": "array",
|
|
96
|
+
"[object Date]": "date",
|
|
97
|
+
"[object RegExp]": "regExp",
|
|
98
|
+
"[object Undefined]": "undefined",
|
|
99
|
+
"[object Null]": "null",
|
|
100
|
+
"[object Object]": "object"
|
|
101
|
+
};
|
|
102
|
+
return map[toString.call(obj)];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// deepCopy
|
|
106
|
+
function deepCopy (data) {
|
|
107
|
+
const t = typeOf(data);
|
|
108
|
+
let o;
|
|
109
|
+
|
|
110
|
+
if (t === "array") {
|
|
111
|
+
o = [];
|
|
112
|
+
} else if (t === "object") {
|
|
113
|
+
o = {};
|
|
114
|
+
} else {
|
|
115
|
+
return data;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (t === "array") {
|
|
119
|
+
for (let i = 0; i < data.length; i++) {
|
|
120
|
+
o.push(deepCopy(data[i]));
|
|
121
|
+
}
|
|
122
|
+
} else if (t === "object") {
|
|
123
|
+
for (let i in data) {
|
|
124
|
+
o[i] = deepCopy(data[i]);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return o;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export {deepCopy};
|
|
131
|
+
|
|
132
|
+
// scrollTop animation
|
|
133
|
+
export function scrollTop (el, from = 0, to, duration = 500, endCallback) {
|
|
134
|
+
if (!window.requestAnimationFrame) {
|
|
135
|
+
window.requestAnimationFrame = (
|
|
136
|
+
window.webkitRequestAnimationFrame ||
|
|
137
|
+
window.mozRequestAnimationFrame ||
|
|
138
|
+
window.msRequestAnimationFrame ||
|
|
139
|
+
function (callback) {
|
|
140
|
+
return window.setTimeout(callback, 1000 / 60);
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
const difference = Math.abs(from - to);
|
|
145
|
+
const step = Math.ceil(difference / duration * 50);
|
|
146
|
+
|
|
147
|
+
function scroll (start, end, step) {
|
|
148
|
+
if (start === end) {
|
|
149
|
+
endCallback && endCallback();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let d = (start + step > end) ? end : start + step;
|
|
154
|
+
if (start > end) {
|
|
155
|
+
d = (start - step < end) ? end : start - step;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (el === window) {
|
|
159
|
+
window.scrollTo(d, d);
|
|
160
|
+
} else {
|
|
161
|
+
el.scrollTop = d;
|
|
162
|
+
}
|
|
163
|
+
window.requestAnimationFrame(() => scroll(d, end, step));
|
|
164
|
+
}
|
|
165
|
+
scroll(from, to, step);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Find components upward
|
|
169
|
+
function findComponentUpward (context, componentName, componentNames) {
|
|
170
|
+
if (typeof componentName === "string") {
|
|
171
|
+
componentNames = [componentName];
|
|
172
|
+
} else {
|
|
173
|
+
componentNames = componentName;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let parent = context.$parent;
|
|
177
|
+
let name = parent.$options.name;
|
|
178
|
+
while (parent && (!name || componentNames.indexOf(name) < 0)) {
|
|
179
|
+
parent = parent.$parent;
|
|
180
|
+
if (parent) name = parent.$options.name;
|
|
181
|
+
}
|
|
182
|
+
return parent;
|
|
183
|
+
}
|
|
184
|
+
export {findComponentUpward};
|
|
185
|
+
|
|
186
|
+
// Find component downward
|
|
187
|
+
export function findComponentDownward (context, componentName) {
|
|
188
|
+
const childrens = context.$children;
|
|
189
|
+
let children = null;
|
|
190
|
+
|
|
191
|
+
if (childrens.length) {
|
|
192
|
+
for (const child of childrens) {
|
|
193
|
+
const name = child.$options.name;
|
|
194
|
+
if (name === componentName) {
|
|
195
|
+
children = child;
|
|
196
|
+
break;
|
|
197
|
+
} else {
|
|
198
|
+
children = findComponentDownward(child, componentName);
|
|
199
|
+
if (children) break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return children;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Find components downward
|
|
207
|
+
export function findComponentsDownward (context, componentName) {
|
|
208
|
+
return context.$children.reduce((components, child) => {
|
|
209
|
+
if (child.$options.name === componentName) components.push(child);
|
|
210
|
+
const foundChilds = findComponentsDownward(child, componentName);
|
|
211
|
+
return components.concat(foundChilds);
|
|
212
|
+
}, []);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Find components upward
|
|
216
|
+
export function findComponentsUpward (context, componentName) {
|
|
217
|
+
let parents = [];
|
|
218
|
+
const parent = context.$parent;
|
|
219
|
+
if (parent) {
|
|
220
|
+
if (parent.$options.name === componentName) parents.push(parent);
|
|
221
|
+
return parents.concat(findComponentsUpward(parent, componentName));
|
|
222
|
+
} else {
|
|
223
|
+
return [];
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Find brothers components
|
|
228
|
+
export function findBrothersComponents (context, componentName, exceptMe = true) {
|
|
229
|
+
let res = context.$parent.$children.filter(item => {
|
|
230
|
+
return item.$options.name === componentName;
|
|
231
|
+
});
|
|
232
|
+
let index = res.findIndex(item => item._uid === context._uid);
|
|
233
|
+
if (exceptMe) res.splice(index, 1);
|
|
234
|
+
return res;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/* istanbul ignore next */
|
|
238
|
+
const trim = function (string) {
|
|
239
|
+
return (string || "").replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, "");
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
/* istanbul ignore next */
|
|
243
|
+
export function hasClass (el, cls) {
|
|
244
|
+
if (!el || !cls) return false;
|
|
245
|
+
if (cls.indexOf(" ") !== -1) throw new Error("className should not contain space.");
|
|
246
|
+
if (el.classList) {
|
|
247
|
+
return el.classList.contains(cls);
|
|
248
|
+
} else {
|
|
249
|
+
return (" " + el.className + " ").indexOf(" " + cls + " ") > -1;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/* istanbul ignore next */
|
|
254
|
+
export function addClass (el, cls) {
|
|
255
|
+
if (!el) return;
|
|
256
|
+
let curClass = el.className;
|
|
257
|
+
const classes = (cls || "").split(" ");
|
|
258
|
+
|
|
259
|
+
for (let i = 0, j = classes.length; i < j; i++) {
|
|
260
|
+
const clsName = classes[i];
|
|
261
|
+
if (!clsName) continue;
|
|
262
|
+
|
|
263
|
+
if (el.classList) {
|
|
264
|
+
el.classList.add(clsName);
|
|
265
|
+
} else {
|
|
266
|
+
if (!hasClass(el, clsName)) {
|
|
267
|
+
curClass += " " + clsName;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (!el.classList) {
|
|
272
|
+
el.className = curClass;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/* istanbul ignore next */
|
|
277
|
+
export function removeClass (el, cls) {
|
|
278
|
+
if (!el || !cls) return;
|
|
279
|
+
const classes = cls.split(" ");
|
|
280
|
+
let curClass = " " + el.className + " ";
|
|
281
|
+
|
|
282
|
+
for (let i = 0, j = classes.length; i < j; i++) {
|
|
283
|
+
const clsName = classes[i];
|
|
284
|
+
if (!clsName) continue;
|
|
285
|
+
|
|
286
|
+
if (el.classList) {
|
|
287
|
+
el.classList.remove(clsName);
|
|
288
|
+
} else {
|
|
289
|
+
if (hasClass(el, clsName)) {
|
|
290
|
+
curClass = curClass.replace(" " + clsName + " ", " ");
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (!el.classList) {
|
|
295
|
+
el.className = trim(curClass);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export const dimensionMap = {
|
|
300
|
+
xs: "480px",
|
|
301
|
+
sm: "576px",
|
|
302
|
+
md: "768px",
|
|
303
|
+
lg: "992px",
|
|
304
|
+
xl: "1200px",
|
|
305
|
+
xxl: "1600px"
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export function setMatchMedia () {
|
|
309
|
+
if (typeof window !== "undefined") {
|
|
310
|
+
const matchMediaPolyfill = mediaQuery => {
|
|
311
|
+
return {
|
|
312
|
+
media: mediaQuery,
|
|
313
|
+
matches: false,
|
|
314
|
+
on () {},
|
|
315
|
+
off () {}
|
|
316
|
+
};
|
|
317
|
+
};
|
|
318
|
+
window.matchMedia = window.matchMedia || matchMediaPolyfill;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export const sharpMatcherRegx = /#([^#]+)$/;
|