@zkwq/business 0.0.1
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/dist/index.css +1 -0
- package/dist/index.js +21861 -0
- package/dist/index.umd.cjs +46 -0
- package/package.json +27 -0
- package/src/components/base/ui/alert/Alert.vue +94 -0
- package/src/components/base/ui/autocomplete/autocomplete-suggestions.vue +77 -0
- package/src/components/base/ui/autocomplete/autocomplete.vue +305 -0
- package/src/components/base/ui/backtop/main.vue +112 -0
- package/src/components/base/ui/button/Button.vue +84 -0
- package/src/components/base/ui/button/ButtonGroup.vue +10 -0
- package/src/components/base/ui/carousel/Carousel.vue +304 -0
- package/src/components/base/ui/carousel/CarouselItem.vue +137 -0
- package/src/components/base/ui/cascader/cascader.vue +650 -0
- package/src/components/base/ui/cascader-panel/cascader-menu.vue +138 -0
- package/src/components/base/ui/cascader-panel/cascader-node.vue +246 -0
- package/src/components/base/ui/cascader-panel/cascader-panel.vue +382 -0
- package/src/components/base/ui/cascader-panel/node.js +166 -0
- package/src/components/base/ui/cascader-panel/store.js +62 -0
- package/src/components/base/ui/checkbox/checkbox-button.vue +199 -0
- package/src/components/base/ui/checkbox/checkbox-group.vue +48 -0
- package/src/components/base/ui/checkbox/checkbox.vue +222 -0
- package/src/components/base/ui/col/col.js +71 -0
- package/src/components/base/ui/collapse/collapse-item.vue +180 -0
- package/src/components/base/ui/collapse/collapse.vue +73 -0
- package/src/components/base/ui/color-picker/color.js +317 -0
- package/src/components/base/ui/color-picker/components/alpha-slider.vue +132 -0
- package/src/components/base/ui/color-picker/components/hue-slider.vue +123 -0
- package/src/components/base/ui/color-picker/components/picker-dropdown.vue +119 -0
- package/src/components/base/ui/color-picker/components/predefine.vue +61 -0
- package/src/components/base/ui/color-picker/components/sv-panel.vue +100 -0
- package/src/components/base/ui/color-picker/draggable.js +36 -0
- package/src/components/base/ui/color-picker/index.js +2 -0
- package/src/components/base/ui/color-picker/main.vue +188 -0
- package/src/components/base/ui/date-picker/basic/date-table.vue +441 -0
- package/src/components/base/ui/date-picker/basic/month-table.vue +254 -0
- package/src/components/base/ui/date-picker/basic/time-spinner.vue +304 -0
- package/src/components/base/ui/date-picker/basic/year-table.vue +101 -0
- package/src/components/base/ui/date-picker/panel/date-range.vue +680 -0
- package/src/components/base/ui/date-picker/panel/date.vue +597 -0
- package/src/components/base/ui/date-picker/panel/month-range.vue +289 -0
- package/src/components/base/ui/date-picker/panel/time-range.vue +248 -0
- package/src/components/base/ui/date-picker/panel/time-select.vue +178 -0
- package/src/components/base/ui/date-picker/panel/time.vue +186 -0
- package/src/components/base/ui/date-picker/picker/date-picker.js +43 -0
- package/src/components/base/ui/date-picker/picker/time-picker.js +39 -0
- package/src/components/base/ui/date-picker/picker/time-select.js +21 -0
- package/src/components/base/ui/date-picker/picker.vue +942 -0
- package/src/components/base/ui/dialog/Index.vue +212 -0
- package/src/components/base/ui/directive/repeat-click.js +24 -0
- package/src/components/base/ui/directive/ripple.js +303 -0
- package/src/components/base/ui/divider/Divider.vue +37 -0
- package/src/components/base/ui/drawer/Drawer.vue +202 -0
- package/src/components/base/ui/dropdown/dropdown-item.vue +39 -0
- package/src/components/base/ui/dropdown/dropdown-menu.vue +63 -0
- package/src/components/base/ui/dropdown/dropdown.vue +308 -0
- package/src/components/base/ui/form/Form.vue +167 -0
- package/src/components/base/ui/form/FormItem.vue +334 -0
- package/src/components/base/ui/form/LabelWrap.vue +69 -0
- package/src/components/base/ui/icon/icon.vue +13 -0
- package/src/components/base/ui/image/image-viewer.vue +302 -0
- package/src/components/base/ui/image/main.vue +248 -0
- package/src/components/base/ui/index.js +189 -0
- package/src/components/base/ui/input/Input.vue +438 -0
- package/src/components/base/ui/input/calcTextareaHeight.js +104 -0
- package/src/components/base/ui/input-number/input-number.vue +285 -0
- package/src/components/base/ui/locale/format.js +32 -0
- package/src/components/base/ui/locale/index.js +48 -0
- package/src/components/base/ui/locale/lang/zh-CN.js +120 -0
- package/src/components/base/ui/menu/menu-item-group.vue +45 -0
- package/src/components/base/ui/menu/menu-item.vue +112 -0
- package/src/components/base/ui/menu/menu-mixin.js +44 -0
- package/src/components/base/ui/menu/menu.vue +312 -0
- package/src/components/base/ui/menu/submenu.vue +408 -0
- package/src/components/base/ui/message/index.js +2 -0
- package/src/components/base/ui/message/main.js +87 -0
- package/src/components/base/ui/message/main.vue +110 -0
- package/src/components/base/ui/message-box/main.js +216 -0
- package/src/components/base/ui/message-box/main.vue +323 -0
- package/src/components/base/ui/mixin/emitter.js +31 -0
- package/src/components/base/ui/mixin/focus.js +9 -0
- package/src/components/base/ui/mixin/locale.js +9 -0
- package/src/components/base/ui/mixin/migrating.js +33 -0
- package/src/components/base/ui/pagination/pager.vue +163 -0
- package/src/components/base/ui/pagination/pagination.jsx +391 -0
- package/src/components/base/ui/popover/directive.js +20 -0
- package/src/components/base/ui/popover/index.js +14 -0
- package/src/components/base/ui/popover/main.vue +236 -0
- package/src/components/base/ui/progress/Progress.vue +227 -0
- package/src/components/base/ui/radio/radio-button.vue +114 -0
- package/src/components/base/ui/radio/radio-group.vue +111 -0
- package/src/components/base/ui/radio/radio.vue +134 -0
- package/src/components/base/ui/row/row.js +47 -0
- package/src/components/base/ui/scrollbar/bar.jsx +91 -0
- package/src/components/base/ui/scrollbar/index.jsx +203 -0
- package/src/components/base/ui/scrollbar/util.js +32 -0
- package/src/components/base/ui/select/Option.vue +168 -0
- package/src/components/base/ui/select/OptionGroup.vue +60 -0
- package/src/components/base/ui/select/Select.vue +920 -0
- package/src/components/base/ui/select/SelectDropdown.vue +74 -0
- package/src/components/base/ui/select/navigation-mixin.js +54 -0
- package/src/components/base/ui/skeleton/index.js +8 -0
- package/src/components/base/ui/skeleton/src/img-placeholder.vue +16 -0
- package/src/components/base/ui/skeleton/src/index.vue +80 -0
- package/src/components/base/ui/skeleton/src/item.vue +22 -0
- package/src/components/base/ui/skeleton-item/index.js +8 -0
- package/src/components/base/ui/slider/button.vue +238 -0
- package/src/components/base/ui/slider/main.vue +427 -0
- package/src/components/base/ui/slider/marker.js +18 -0
- package/src/components/base/ui/style/alert.scss +147 -0
- package/src/components/base/ui/style/animations.scss +65 -0
- package/src/components/base/ui/style/autocomplete.scss +81 -0
- package/src/components/base/ui/style/backtop.scss +20 -0
- package/src/components/base/ui/style/button-group.scss +0 -0
- package/src/components/base/ui/style/button.scss +380 -0
- package/src/components/base/ui/style/carousel-item.scss +50 -0
- package/src/components/base/ui/style/carousel.scss +161 -0
- package/src/components/base/ui/style/cascader-panel.scss +120 -0
- package/src/components/base/ui/style/cascader.scss +185 -0
- package/src/components/base/ui/style/checkbox-button.scss +0 -0
- package/src/components/base/ui/style/checkbox-group.scss +0 -0
- package/src/components/base/ui/style/checkbox.scss +360 -0
- package/src/components/base/ui/style/col.scss +156 -0
- package/src/components/base/ui/style/collapse-item.scss +0 -0
- package/src/components/base/ui/style/collapse.scss +114 -0
- package/src/components/base/ui/style/color-picker.scss +387 -0
- package/src/components/base/ui/style/config.scss +4 -0
- package/src/components/base/ui/style/date-picker/date-picker.scss +97 -0
- package/src/components/base/ui/style/date-picker/date-range-picker.scss +101 -0
- package/src/components/base/ui/style/date-picker/date-table.scss +151 -0
- package/src/components/base/ui/style/date-picker/month-table.scss +82 -0
- package/src/components/base/ui/style/date-picker/picker-panel.scss +117 -0
- package/src/components/base/ui/style/date-picker/picker.scss +197 -0
- package/src/components/base/ui/style/date-picker/time-picker.scss +85 -0
- package/src/components/base/ui/style/date-picker/time-range-picker.scss +31 -0
- package/src/components/base/ui/style/date-picker/time-spinner.scss +110 -0
- package/src/components/base/ui/style/date-picker/year-table.scss +51 -0
- package/src/components/base/ui/style/date-picker.scss +12 -0
- package/src/components/base/ui/style/dialog.scss +123 -0
- package/src/components/base/ui/style/divider.scss +47 -0
- package/src/components/base/ui/style/drawer.scss +218 -0
- package/src/components/base/ui/style/dropdown-item.scss +0 -0
- package/src/components/base/ui/style/dropdown-menu.scss +0 -0
- package/src/components/base/ui/style/dropdown.scss +185 -0
- package/src/components/base/ui/style/form-item.scss +0 -0
- package/src/components/base/ui/style/form.scss +203 -0
- package/src/components/base/ui/style/function.scss +43 -0
- package/src/components/base/ui/style/icon.scss +1167 -0
- package/src/components/base/ui/style/image.scss +184 -0
- package/src/components/base/ui/style/index.scss +57 -0
- package/src/components/base/ui/style/input-number.scss +187 -0
- package/src/components/base/ui/style/input.scss +477 -0
- package/src/components/base/ui/style/menu-item-group.scss +0 -0
- package/src/components/base/ui/style/menu-item.scss +0 -0
- package/src/components/base/ui/style/menu.scss +294 -0
- package/src/components/base/ui/style/message-box.scss +231 -0
- package/src/components/base/ui/style/message.scss +120 -0
- package/src/components/base/ui/style/mixins.scss +196 -0
- package/src/components/base/ui/style/option-group.scss +42 -0
- package/src/components/base/ui/style/option.scss +36 -0
- package/src/components/base/ui/style/pagination.scss +295 -0
- package/src/components/base/ui/style/popover.scss +40 -0
- package/src/components/base/ui/style/popper.scss +102 -0
- package/src/components/base/ui/style/popup.scss +42 -0
- package/src/components/base/ui/style/progress.scss +141 -0
- package/src/components/base/ui/style/radio-button.scss +113 -0
- package/src/components/base/ui/style/radio-group.scss +9 -0
- package/src/components/base/ui/style/radio.scss +203 -0
- package/src/components/base/ui/style/ripple.scss +35 -0
- package/src/components/base/ui/style/row.scss +39 -0
- package/src/components/base/ui/style/scrollbar.scss +75 -0
- package/src/components/base/ui/style/select-dropdown.scss +59 -0
- package/src/components/base/ui/style/select.scss +154 -0
- package/src/components/base/ui/style/skeleton-item.scss +84 -0
- package/src/components/base/ui/style/skeleton.scss +40 -0
- package/src/components/base/ui/style/slider.scss +250 -0
- package/src/components/base/ui/style/switch.scss +116 -0
- package/src/components/base/ui/style/tabs.scss +602 -0
- package/src/components/base/ui/style/tag.scss +174 -0
- package/src/components/base/ui/style/tooltip.scss +146 -0
- package/src/components/base/ui/style/transition.scss +138 -0
- package/src/components/base/ui/style/upload.scss +603 -0
- package/src/components/base/ui/style/utils.scss +39 -0
- package/src/components/base/ui/style/var.scss +1007 -0
- package/src/components/base/ui/switch/index.vue +174 -0
- package/src/components/base/ui/tabs/tab-bar.vue +57 -0
- package/src/components/base/ui/tabs/tab-nav.vue +294 -0
- package/src/components/base/ui/tabs/tab-pane.vue +56 -0
- package/src/components/base/ui/tabs/tabs.vue +191 -0
- package/src/components/base/ui/tag/Tag.vue +60 -0
- package/src/components/base/ui/tooltip/tooltip.jsx +234 -0
- package/src/components/base/ui/upload/Index.vue +340 -0
- package/src/components/base/ui/upload/Upload.vue +216 -0
- package/src/components/base/ui/upload/UploadDragger.vue +70 -0
- package/src/components/base/ui/upload/UploadList.vue +100 -0
- package/src/components/base/ui/upload/ajax.js +85 -0
- package/src/components/base/ui/util/aria-dialog.js +90 -0
- package/src/components/base/ui/util/aria-utils.js +122 -0
- package/src/components/base/ui/util/clickoutside.js +76 -0
- package/src/components/base/ui/util/date-util.js +292 -0
- package/src/components/base/ui/util/date.js +370 -0
- package/src/components/base/ui/util/debounce.js +21 -0
- package/src/components/base/ui/util/deepmerge.js +100 -0
- package/src/components/base/ui/util/dom.js +215 -0
- package/src/components/base/ui/util/index.js +262 -0
- package/src/components/base/ui/util/menu/aria-menubar.js +14 -0
- package/src/components/base/ui/util/menu/aria-menuitem.js +49 -0
- package/src/components/base/ui/util/menu/aria-submenu.js +59 -0
- package/src/components/base/ui/util/merge.js +14 -0
- package/src/components/base/ui/util/popper.js +1235 -0
- package/src/components/base/ui/util/popup/index.js +218 -0
- package/src/components/base/ui/util/popup/popup-manager.js +194 -0
- package/src/components/base/ui/util/resize-events.js +32 -0
- package/src/components/base/ui/util/scroll-into-view.js +27 -0
- package/src/components/base/ui/util/scrollbar-width.js +29 -0
- package/src/components/base/ui/util/shared.js +7 -0
- package/src/components/base/ui/util/throttle.js +91 -0
- package/src/components/base/ui/util/types.js +24 -0
- package/src/components/base/ui/util/vdom.js +5 -0
- package/src/components/base/ui/util/vue-popper.js +188 -0
- package/src/components/normal/AggsItemH.vue +139 -0
- package/src/index.js +10 -0
- package/src/static/base-icons.ttf +0 -0
- package/src/static/base-icons.woff +0 -0
- package/src/static/label_bg.png +0 -0
- package/src/static/term-label-bg.png +0 -0
- package/src/style/app-article.scss +698 -0
- package/src/style/app-comment.scss +259 -0
- package/src/style/app-recommend.scss +48 -0
- package/src/style/app-richtext.scss +176 -0
- package/src/style/index.scss +523 -0
- package/vite.config.js +38 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function getError(action, option, xhr) {
|
|
2
|
+
let msg
|
|
3
|
+
if (xhr.response) {
|
|
4
|
+
msg = `${xhr.response.error || xhr.response}`
|
|
5
|
+
} else if (xhr.responseText) {
|
|
6
|
+
msg = `${xhr.responseText}`
|
|
7
|
+
} else {
|
|
8
|
+
msg = `fail to post ${action} ${xhr.status}`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const err = new Error(msg)
|
|
12
|
+
err.status = xhr.status
|
|
13
|
+
err.method = 'post'
|
|
14
|
+
err.url = action
|
|
15
|
+
return err
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getBody(xhr) {
|
|
19
|
+
const text = xhr.responseText || xhr.response
|
|
20
|
+
if (!text) {
|
|
21
|
+
return text
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
return JSON.parse(text)
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return text
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default function upload(option) {
|
|
32
|
+
if (typeof XMLHttpRequest === 'undefined') {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const xhr = new XMLHttpRequest()
|
|
37
|
+
const action = option.action
|
|
38
|
+
|
|
39
|
+
if (xhr.upload) {
|
|
40
|
+
xhr.upload.onprogress = function progress(e) {
|
|
41
|
+
if (e.total > 0) {
|
|
42
|
+
e.percent = e.loaded / e.total * 100
|
|
43
|
+
}
|
|
44
|
+
option.onProgress(e)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const formData = new FormData()
|
|
49
|
+
|
|
50
|
+
if (option.data) {
|
|
51
|
+
Object.keys(option.data).forEach(key => {
|
|
52
|
+
formData.append(key, option.data[key])
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
formData.append(option.filename, option.file, option.file.name)
|
|
57
|
+
|
|
58
|
+
xhr.onerror = function error(e) {
|
|
59
|
+
option.onError(e)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
xhr.onload = function onload() {
|
|
63
|
+
if (xhr.status < 200 || xhr.status >= 300) {
|
|
64
|
+
return option.onError(getError(action, option, xhr))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
option.onSuccess(getBody(xhr))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
xhr.open('post', action, true)
|
|
71
|
+
|
|
72
|
+
if (option.withCredentials && 'withCredentials' in xhr) {
|
|
73
|
+
xhr.withCredentials = true
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const headers = option.headers || {}
|
|
77
|
+
|
|
78
|
+
for (let item in headers) {
|
|
79
|
+
if (headers.hasOwnProperty(item) && headers[item] !== null) {
|
|
80
|
+
xhr.setRequestHeader(item, headers[item])
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
xhr.send(formData)
|
|
84
|
+
return xhr
|
|
85
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Utils from './aria-utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @constructor
|
|
5
|
+
* @desc Dialog object providing modal focus management.
|
|
6
|
+
*
|
|
7
|
+
* Assumptions: The element serving as the dialog container is present in the
|
|
8
|
+
* DOM and hidden. The dialog container has role='dialog'.
|
|
9
|
+
*
|
|
10
|
+
* @param dialogId
|
|
11
|
+
* The ID of the element serving as the dialog container.
|
|
12
|
+
* @param focusAfterClosed
|
|
13
|
+
* Either the DOM node or the ID of the DOM node to focus when the
|
|
14
|
+
* dialog closes.
|
|
15
|
+
* @param focusFirst
|
|
16
|
+
* Optional parameter containing either the DOM node or the ID of the
|
|
17
|
+
* DOM node to focus when the dialog opens. If not specified, the
|
|
18
|
+
* first focusable element in the dialog will receive focus.
|
|
19
|
+
*/
|
|
20
|
+
var aria = aria || {};
|
|
21
|
+
var tabEvent;
|
|
22
|
+
|
|
23
|
+
aria.Dialog = function(dialog, focusAfterClosed, focusFirst) {
|
|
24
|
+
this.dialogNode = dialog;
|
|
25
|
+
if (this.dialogNode === null || this.dialogNode.getAttribute('role') !== 'dialog') {
|
|
26
|
+
throw new Error('Dialog() requires a DOM element with ARIA role of dialog.');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (typeof focusAfterClosed === 'string') {
|
|
30
|
+
this.focusAfterClosed = document.getElementById(focusAfterClosed);
|
|
31
|
+
} else if (typeof focusAfterClosed === 'object') {
|
|
32
|
+
this.focusAfterClosed = focusAfterClosed;
|
|
33
|
+
} else {
|
|
34
|
+
this.focusAfterClosed = null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof focusFirst === 'string') {
|
|
38
|
+
this.focusFirst = document.getElementById(focusFirst);
|
|
39
|
+
} else if (typeof focusFirst === 'object') {
|
|
40
|
+
this.focusFirst = focusFirst;
|
|
41
|
+
} else {
|
|
42
|
+
this.focusFirst = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (this.focusFirst) {
|
|
46
|
+
this.focusFirst.focus();
|
|
47
|
+
} else {
|
|
48
|
+
Utils.focusFirstDescendant(this.dialogNode);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
this.lastFocus = document.activeElement;
|
|
52
|
+
tabEvent = (e) => {
|
|
53
|
+
this.trapFocus(e);
|
|
54
|
+
};
|
|
55
|
+
this.addListeners();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
aria.Dialog.prototype.addListeners = function() {
|
|
59
|
+
document.addEventListener('focus', tabEvent, true);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
aria.Dialog.prototype.removeListeners = function() {
|
|
63
|
+
document.removeEventListener('focus', tabEvent, true);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
aria.Dialog.prototype.closeDialog = function() {
|
|
67
|
+
this.removeListeners();
|
|
68
|
+
if (this.focusAfterClosed) {
|
|
69
|
+
setTimeout(() => {
|
|
70
|
+
this.focusAfterClosed.focus();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
aria.Dialog.prototype.trapFocus = function(event) {
|
|
76
|
+
if (Utils.IgnoreUtilFocusChanges) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (this.dialogNode.contains(event.target)) {
|
|
80
|
+
this.lastFocus = event.target;
|
|
81
|
+
} else {
|
|
82
|
+
Utils.focusFirstDescendant(this.dialogNode);
|
|
83
|
+
if (this.lastFocus === document.activeElement) {
|
|
84
|
+
Utils.focusLastDescendant(this.dialogNode);
|
|
85
|
+
}
|
|
86
|
+
this.lastFocus = document.activeElement;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default aria.Dialog;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var aria = aria || {};
|
|
2
|
+
|
|
3
|
+
aria.Utils = aria.Utils || {};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @desc Set focus on descendant nodes until the first focusable element is
|
|
7
|
+
* found.
|
|
8
|
+
* @param element
|
|
9
|
+
* DOM node for which to find the first focusable descendant.
|
|
10
|
+
* @returns
|
|
11
|
+
* true if a focusable element is found and focus is set.
|
|
12
|
+
*/
|
|
13
|
+
aria.Utils.focusFirstDescendant = function(element) {
|
|
14
|
+
for (var i = 0; i < element.childNodes.length; i++) {
|
|
15
|
+
var child = element.childNodes[i];
|
|
16
|
+
if (aria.Utils.attemptFocus(child) || aria.Utils.focusFirstDescendant(child)) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @desc Find the last descendant node that is focusable.
|
|
25
|
+
* @param element
|
|
26
|
+
* DOM node for which to find the last focusable descendant.
|
|
27
|
+
* @returns
|
|
28
|
+
* true if a focusable element is found and focus is set.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
aria.Utils.focusLastDescendant = function(element) {
|
|
32
|
+
for (var i = element.childNodes.length - 1; i >= 0; i--) {
|
|
33
|
+
var child = element.childNodes[i];
|
|
34
|
+
if (aria.Utils.attemptFocus(child) || aria.Utils.focusLastDescendant(child)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @desc Set Attempt to set focus on the current node.
|
|
43
|
+
* @param element
|
|
44
|
+
* The node to attempt to focus on.
|
|
45
|
+
* @returns
|
|
46
|
+
* true if element is focused.
|
|
47
|
+
*/
|
|
48
|
+
aria.Utils.attemptFocus = function(element) {
|
|
49
|
+
if (!aria.Utils.isFocusable(element)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
aria.Utils.IgnoreUtilFocusChanges = true;
|
|
53
|
+
try {
|
|
54
|
+
element.focus();
|
|
55
|
+
} catch (e) {
|
|
56
|
+
}
|
|
57
|
+
aria.Utils.IgnoreUtilFocusChanges = false;
|
|
58
|
+
return (document.activeElement === element);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
aria.Utils.isFocusable = function(element) {
|
|
62
|
+
if (element.tabIndex > 0 || (element.tabIndex === 0 && element.getAttribute('tabIndex') !== null)) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (element.disabled) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
switch (element.nodeName) {
|
|
71
|
+
case 'A':
|
|
72
|
+
return !!element.href && element.rel !== 'ignore';
|
|
73
|
+
case 'INPUT':
|
|
74
|
+
return element.type !== 'hidden' && element.type !== 'file';
|
|
75
|
+
case 'BUTTON':
|
|
76
|
+
case 'SELECT':
|
|
77
|
+
case 'TEXTAREA':
|
|
78
|
+
return true;
|
|
79
|
+
default:
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* 触发一个事件
|
|
86
|
+
* mouseenter, mouseleave, mouseover, keyup, change, click 等
|
|
87
|
+
* @param {Element} elm
|
|
88
|
+
* @param {String} name
|
|
89
|
+
* @param {*} opts
|
|
90
|
+
*/
|
|
91
|
+
aria.Utils.triggerEvent = function(elm, name, ...opts) {
|
|
92
|
+
let eventName;
|
|
93
|
+
|
|
94
|
+
if (/^mouse|click/.test(name)) {
|
|
95
|
+
eventName = 'MouseEvents';
|
|
96
|
+
} else if (/^key/.test(name)) {
|
|
97
|
+
eventName = 'KeyboardEvent';
|
|
98
|
+
} else {
|
|
99
|
+
eventName = 'HTMLEvents';
|
|
100
|
+
}
|
|
101
|
+
const evt = document.createEvent(eventName);
|
|
102
|
+
|
|
103
|
+
evt.initEvent(name, ...opts);
|
|
104
|
+
elm.dispatchEvent
|
|
105
|
+
? elm.dispatchEvent(evt)
|
|
106
|
+
: elm.fireEvent('on' + name, evt);
|
|
107
|
+
|
|
108
|
+
return elm;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
aria.Utils.keys = {
|
|
112
|
+
tab: 9,
|
|
113
|
+
enter: 13,
|
|
114
|
+
space: 32,
|
|
115
|
+
left: 37,
|
|
116
|
+
up: 38,
|
|
117
|
+
right: 39,
|
|
118
|
+
down: 40,
|
|
119
|
+
esc: 27
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export default aria.Utils;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import Vue from 'vue'
|
|
2
|
+
import { on } from './dom'
|
|
3
|
+
|
|
4
|
+
const nodeList = []
|
|
5
|
+
const ctx = '@@clickoutsideContext'
|
|
6
|
+
|
|
7
|
+
let startClick
|
|
8
|
+
let seed = 0
|
|
9
|
+
|
|
10
|
+
!Vue.prototype.$isServer && on(document, 'mousedown', e => (startClick = e))
|
|
11
|
+
|
|
12
|
+
!Vue.prototype.$isServer && on(document, 'mouseup', e => {
|
|
13
|
+
nodeList.forEach(node => node[ctx].documentHandler(e, startClick))
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
function createDocumentHandler(el, binding, vnode) {
|
|
17
|
+
return function(mouseup = {}, mousedown = {}) {
|
|
18
|
+
if (!vnode ||
|
|
19
|
+
!vnode.context ||
|
|
20
|
+
!mouseup.target ||
|
|
21
|
+
!mousedown.target ||
|
|
22
|
+
el.contains(mouseup.target) ||
|
|
23
|
+
el.contains(mousedown.target) ||
|
|
24
|
+
el === mouseup.target ||
|
|
25
|
+
(vnode.context.popperElm &&
|
|
26
|
+
(vnode.context.popperElm.contains(mouseup.target) ||
|
|
27
|
+
vnode.context.popperElm.contains(mousedown.target)))) return
|
|
28
|
+
|
|
29
|
+
if (binding.expression &&
|
|
30
|
+
el[ctx].methodName &&
|
|
31
|
+
vnode.context[el[ctx].methodName]) {
|
|
32
|
+
vnode.context[el[ctx].methodName]()
|
|
33
|
+
} else {
|
|
34
|
+
el[ctx].bindingFn && el[ctx].bindingFn()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* v-clickoutside
|
|
41
|
+
* @desc 点击元素外面才会触发的事件
|
|
42
|
+
* @example
|
|
43
|
+
* ```vue
|
|
44
|
+
* <div v-element-clickoutside="handleClose">
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export default {
|
|
48
|
+
bind(el, binding, vnode) {
|
|
49
|
+
nodeList.push(el)
|
|
50
|
+
const id = seed++
|
|
51
|
+
el[ctx] = {
|
|
52
|
+
id,
|
|
53
|
+
documentHandler: createDocumentHandler(el, binding, vnode),
|
|
54
|
+
methodName: binding.expression,
|
|
55
|
+
bindingFn: binding.value
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
update(el, binding, vnode) {
|
|
60
|
+
el[ctx].documentHandler = createDocumentHandler(el, binding, vnode)
|
|
61
|
+
el[ctx].methodName = binding.expression
|
|
62
|
+
el[ctx].bindingFn = binding.value
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
unbind(el) {
|
|
66
|
+
let len = nodeList.length
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < len; i++) {
|
|
69
|
+
if (nodeList[i][ctx].id === el[ctx].id) {
|
|
70
|
+
nodeList.splice(i, 1)
|
|
71
|
+
break
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
delete el[ctx]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import fecha from './date';
|
|
2
|
+
import { t } from '../locale';
|
|
3
|
+
|
|
4
|
+
const weeks = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
|
|
5
|
+
const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
6
|
+
|
|
7
|
+
const newArray = function(start, end) {
|
|
8
|
+
let result = [];
|
|
9
|
+
for (let i = start; i <= end; i++) {
|
|
10
|
+
result.push(i);
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getI18nSettings = () => {
|
|
16
|
+
return {
|
|
17
|
+
dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
|
|
18
|
+
dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
|
|
19
|
+
monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)),
|
|
20
|
+
monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)),
|
|
21
|
+
amPm: ['am', 'pm']
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const toDate = function(date) {
|
|
26
|
+
return isDate(date) ? new Date(date) : null;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const isDate = function(date) {
|
|
30
|
+
if (date === null || date === undefined) return false;
|
|
31
|
+
if (isNaN(new Date(date).getTime())) return false;
|
|
32
|
+
if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
|
|
33
|
+
return true;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const isDateObject = function(val) {
|
|
37
|
+
return val instanceof Date;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const formatDate = function(date, format) {
|
|
41
|
+
date = toDate(date);
|
|
42
|
+
if (!date) return '';
|
|
43
|
+
return fecha.format(date, format || 'yyyy-MM-dd', getI18nSettings());
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const parseDate = function(string, format) {
|
|
47
|
+
return fecha.parse(string, format || 'yyyy-MM-dd', getI18nSettings());
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const getDayCountOfMonth = function(year, month) {
|
|
51
|
+
if (month === 3 || month === 5 || month === 8 || month === 10) {
|
|
52
|
+
return 30;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (month === 1) {
|
|
56
|
+
if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
|
|
57
|
+
return 29;
|
|
58
|
+
} else {
|
|
59
|
+
return 28;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return 31;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const getDayCountOfYear = function(year) {
|
|
67
|
+
const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
|
|
68
|
+
return isLeapYear ? 366 : 365;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const getFirstDayOfMonth = function(date) {
|
|
72
|
+
const temp = new Date(date.getTime());
|
|
73
|
+
temp.setDate(1);
|
|
74
|
+
return temp.getDay();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
|
|
78
|
+
// {prev, next} Date should work for Daylight Saving Time
|
|
79
|
+
// Adding 24 * 60 * 60 * 1000 does not work in the above scenario
|
|
80
|
+
export const prevDate = function(date, amount = 1) {
|
|
81
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export const nextDate = function(date, amount = 1) {
|
|
85
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export const getStartDateOfMonth = function(year, month) {
|
|
89
|
+
const result = new Date(year, month, 1);
|
|
90
|
+
const day = result.getDay();
|
|
91
|
+
|
|
92
|
+
if (day === 0) {
|
|
93
|
+
return prevDate(result, 7);
|
|
94
|
+
} else {
|
|
95
|
+
return prevDate(result, day);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const getWeekNumber = function(src) {
|
|
100
|
+
if (!isDate(src)) return null;
|
|
101
|
+
const date = new Date(src.getTime());
|
|
102
|
+
date.setHours(0, 0, 0, 0);
|
|
103
|
+
// Thursday in current week decides the year.
|
|
104
|
+
date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
|
|
105
|
+
// January 4 is always in week 1.
|
|
106
|
+
const week1 = new Date(date.getFullYear(), 0, 4);
|
|
107
|
+
// Adjust to Thursday in week 1 and count number of weeks from date to week 1.
|
|
108
|
+
// Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
|
|
109
|
+
return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const getRangeHours = function(ranges) {
|
|
113
|
+
const hours = [];
|
|
114
|
+
let disabledHours = [];
|
|
115
|
+
|
|
116
|
+
(ranges || []).forEach(range => {
|
|
117
|
+
const value = range.map(date => date.getHours());
|
|
118
|
+
|
|
119
|
+
disabledHours = disabledHours.concat(newArray(value[0], value[1]));
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
if (disabledHours.length) {
|
|
123
|
+
for (let i = 0; i < 24; i++) {
|
|
124
|
+
hours[i] = disabledHours.indexOf(i) === -1;
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
for (let i = 0; i < 24; i++) {
|
|
128
|
+
hours[i] = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return hours;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const getPrevMonthLastDays = (date, amount) => {
|
|
136
|
+
if (amount <= 0) return [];
|
|
137
|
+
const temp = new Date(date.getTime());
|
|
138
|
+
temp.setDate(0);
|
|
139
|
+
const lastDay = temp.getDate();
|
|
140
|
+
return range(amount).map((_, index) => lastDay - (amount - index - 1));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const getMonthDays = (date) => {
|
|
144
|
+
const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
145
|
+
const days = temp.getDate();
|
|
146
|
+
return range(days).map((_, index) => index + 1);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
function setRangeData(arr, start, end, value) {
|
|
150
|
+
for (let i = start; i < end; i++) {
|
|
151
|
+
arr[i] = value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const getRangeMinutes = function(ranges, hour) {
|
|
156
|
+
const minutes = new Array(60);
|
|
157
|
+
|
|
158
|
+
if (ranges.length > 0) {
|
|
159
|
+
ranges.forEach(range => {
|
|
160
|
+
const start = range[0];
|
|
161
|
+
const end = range[1];
|
|
162
|
+
const startHour = start.getHours();
|
|
163
|
+
const startMinute = start.getMinutes();
|
|
164
|
+
const endHour = end.getHours();
|
|
165
|
+
const endMinute = end.getMinutes();
|
|
166
|
+
if (startHour === hour && endHour !== hour) {
|
|
167
|
+
setRangeData(minutes, startMinute, 60, true);
|
|
168
|
+
} else if (startHour === hour && endHour === hour) {
|
|
169
|
+
setRangeData(minutes, startMinute, endMinute + 1, true);
|
|
170
|
+
} else if (startHour !== hour && endHour === hour) {
|
|
171
|
+
setRangeData(minutes, 0, endMinute + 1, true);
|
|
172
|
+
} else if (startHour < hour && endHour > hour) {
|
|
173
|
+
setRangeData(minutes, 0, 60, true);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
} else {
|
|
177
|
+
setRangeData(minutes, 0, 60, true);
|
|
178
|
+
}
|
|
179
|
+
return minutes;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const range = function(n) {
|
|
183
|
+
// see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
|
|
184
|
+
return Array.apply(null, {length: n}).map((_, n) => n);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
export const modifyDate = function(date, y, m, d) {
|
|
188
|
+
return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
export const modifyTime = function(date, h, m, s) {
|
|
192
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const modifyWithTimeString = (date, time) => {
|
|
196
|
+
if (date == null || !time) {
|
|
197
|
+
return date;
|
|
198
|
+
}
|
|
199
|
+
time = parseDate(time, 'HH:mm:ss');
|
|
200
|
+
return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export const clearTime = function(date) {
|
|
204
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export const clearMilliseconds = function(date) {
|
|
208
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
|
|
212
|
+
// TODO: refactory a more elegant solution
|
|
213
|
+
if (ranges.length === 0) return date;
|
|
214
|
+
const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
|
|
215
|
+
const ndate = normalizeDate(date);
|
|
216
|
+
const nranges = ranges.map(range => range.map(normalizeDate));
|
|
217
|
+
if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
|
|
218
|
+
|
|
219
|
+
let minDate = nranges[0][0];
|
|
220
|
+
let maxDate = nranges[0][0];
|
|
221
|
+
|
|
222
|
+
nranges.forEach(nrange => {
|
|
223
|
+
minDate = new Date(Math.min(nrange[0], minDate));
|
|
224
|
+
maxDate = new Date(Math.max(nrange[1], minDate));
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
const ret = ndate < minDate ? minDate : maxDate;
|
|
228
|
+
// preserve Year/Month/Date
|
|
229
|
+
return modifyDate(
|
|
230
|
+
ret,
|
|
231
|
+
date.getFullYear(),
|
|
232
|
+
date.getMonth(),
|
|
233
|
+
date.getDate()
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export const timeWithinRange = function(date, selectableRange, format) {
|
|
238
|
+
const limitedDate = limitTimeRange(date, selectableRange, format);
|
|
239
|
+
return limitedDate.getTime() === date.getTime();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export const changeYearMonthAndClampDate = function(date, year, month) {
|
|
243
|
+
// clamp date to the number of days in `year`, `month`
|
|
244
|
+
// eg: (2010-1-31, 2010, 2) => 2010-2-28
|
|
245
|
+
const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
|
|
246
|
+
return modifyDate(date, year, month, monthDate);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export const prevMonth = function(date) {
|
|
250
|
+
const year = date.getFullYear();
|
|
251
|
+
const month = date.getMonth();
|
|
252
|
+
return month === 0
|
|
253
|
+
? changeYearMonthAndClampDate(date, year - 1, 11)
|
|
254
|
+
: changeYearMonthAndClampDate(date, year, month - 1);
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const nextMonth = function(date) {
|
|
258
|
+
const year = date.getFullYear();
|
|
259
|
+
const month = date.getMonth();
|
|
260
|
+
return month === 11
|
|
261
|
+
? changeYearMonthAndClampDate(date, year + 1, 0)
|
|
262
|
+
: changeYearMonthAndClampDate(date, year, month + 1);
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
export const prevYear = function(date, amount = 1) {
|
|
266
|
+
const year = date.getFullYear();
|
|
267
|
+
const month = date.getMonth();
|
|
268
|
+
return changeYearMonthAndClampDate(date, year - amount, month);
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
export const nextYear = function(date, amount = 1) {
|
|
272
|
+
const year = date.getFullYear();
|
|
273
|
+
const month = date.getMonth();
|
|
274
|
+
return changeYearMonthAndClampDate(date, year + amount, month);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export const extractDateFormat = function(format) {
|
|
278
|
+
return format
|
|
279
|
+
.replace(/\W?m{1,2}|\W?ZZ/g, '')
|
|
280
|
+
.replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
|
|
281
|
+
.trim();
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
export const extractTimeFormat = function(format) {
|
|
285
|
+
return format
|
|
286
|
+
.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
|
|
287
|
+
.trim();
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
export const validateRangeInOneMonth = function(start, end) {
|
|
291
|
+
return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
|
|
292
|
+
};
|