@mdsfe/mds-ui 0.2.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/CHANGELOG.md +778 -0
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/dist/_locale/index.js +18 -0
- package/dist/_locale/zh-CN.js +123 -0
- package/dist/_mixin/emitter.js +35 -0
- package/dist/_mixin/focus.js +13 -0
- package/dist/_mixin/locale.js +17 -0
- package/dist/_mixin/popper.js +192 -0
- package/dist/_mixin/tooltip.js +218 -0
- package/dist/_util/__test__/switchcase.test.js +43 -0
- package/dist/_util/autoprefixer.js +249 -0
- package/dist/_util/clickoutside.js +79 -0
- package/dist/_util/date.js +368 -0
- package/dist/_util/dateUtil.js +311 -0
- package/dist/_util/dom.js +240 -0
- package/dist/_util/getRequestAnimationFrame.js +50 -0
- package/dist/_util/getScroll.js +21 -0
- package/dist/_util/loaders/loaders.css.js +52 -0
- package/dist/_util/loaders/loading.js +53 -0
- package/dist/_util/merge.js +18 -0
- package/dist/_util/popper.js +1261 -0
- package/dist/_util/popup/index.js +232 -0
- package/dist/_util/popup/popup-manager.js +205 -0
- package/dist/_util/proptype.js +12 -0
- package/dist/_util/repeatClick.js +30 -0
- package/dist/_util/resize.js +61 -0
- package/dist/_util/resizeEvent.js +59 -0
- package/dist/_util/scrollIntoView.js +38 -0
- package/dist/_util/scrollbar-width.js +37 -0
- package/dist/_util/soda.js +54 -0
- package/dist/_util/switchcase.js +22 -0
- package/dist/_util/throttleByAnimationFrame.js +70 -0
- package/dist/_util/tree/node.js +412 -0
- package/dist/_util/tree/tree.js +410 -0
- package/dist/_util/util.js +166 -0
- package/dist/_util/vue-popper.js +213 -0
- package/dist/affix.js +509 -0
- package/dist/anchor.js +522 -0
- package/dist/avatar.js +437 -0
- package/dist/backtop.js +469 -0
- package/dist/badge.js +439 -0
- package/dist/bordershadow.js +310 -0
- package/dist/breadcrumb.js +434 -0
- package/dist/button.js +579 -0
- package/dist/card.js +514 -0
- package/dist/carousel.js +1326 -0
- package/dist/cascaderpanel.js +2320 -0
- package/dist/checkbox.js +681 -0
- package/dist/col.js +546 -0
- package/dist/collapse.js +671 -0
- package/dist/color.js +306 -0
- package/dist/datepicker.js +8089 -0
- package/dist/divider.js +346 -0
- package/dist/drawer.js +652 -0
- package/dist/dropdown.js +687 -0
- package/dist/empty.js +416 -0
- package/dist/font.js +306 -0
- package/dist/form.js +878 -0
- package/dist/icon.js +401 -0
- package/dist/index.js +1 -0
- package/dist/input.js +1251 -0
- package/dist/inputnumber.js +689 -0
- package/dist/layout.js +786 -0
- package/dist/list.js +789 -0
- package/dist/loading.js +430 -0
- package/dist/mds-ui.min.css +7 -0
- package/dist/mds-ui.min.js +64911 -0
- package/dist/menu.js +1131 -0
- package/dist/message.js +1016 -0
- package/dist/modal.js +895 -0
- package/dist/notification.js +818 -0
- package/dist/pagination.js +1213 -0
- package/dist/popconfirm.js +336 -0
- package/dist/popover.js +206 -0
- package/dist/progress.js +1023 -0
- package/dist/radio.js +760 -0
- package/dist/rate.js +765 -0
- package/dist/row.js +546 -0
- package/dist/select.js +4950 -0
- package/dist/slider.js +1411 -0
- package/dist/slottable.js +1414 -0
- package/dist/steps.js +546 -0
- package/dist/style/affix.css +5524 -0
- package/dist/style/anchor.css +5572 -0
- package/dist/style/avatar.css +5587 -0
- package/dist/style/backtop.css +34 -0
- package/dist/style/badge.css +5655 -0
- package/dist/style/bordershadow.css +5601 -0
- package/dist/style/breadcrumb.css +5551 -0
- package/dist/style/button.css +7679 -0
- package/dist/style/card.css +5670 -0
- package/dist/style/carousel.css +5731 -0
- package/dist/style/cascaderpanel.css +125 -0
- package/dist/style/checkbox.css +5700 -0
- package/dist/style/col.css +8121 -0
- package/dist/style/collapse.css +5593 -0
- package/dist/style/color.css +6136 -0
- package/dist/style/datepicker.css +5977 -0
- package/dist/style/divider.css +5558 -0
- package/dist/style/drawer.css +7979 -0
- package/dist/style/dropdown.css +7950 -0
- package/dist/style/empty.css +5563 -0
- package/dist/style/font.css +5559 -0
- package/dist/style/form.css +5662 -0
- package/dist/style/icon.css +5538 -0
- package/dist/style/input.css +6256 -0
- package/dist/style/inputnumber.css +5828 -0
- package/dist/style/layout.css +5572 -0
- package/dist/style/list.css +5655 -0
- package/dist/style/loading.css +5540 -0
- package/dist/style/menu.css +6183 -0
- package/dist/style/message.css +194 -0
- package/dist/style/modal.css +5637 -0
- package/dist/style/notification.css +5706 -0
- package/dist/style/pagination.css +6683 -0
- package/dist/style/popconfirm.css +7951 -0
- package/dist/style/popover.css +5727 -0
- package/dist/style/progress.css +5714 -0
- package/dist/style/radio.css +5769 -0
- package/dist/style/rate.css +5616 -0
- package/dist/style/row.css +8121 -0
- package/dist/style/select.css +5729 -0
- package/dist/style/slider.css +5594 -0
- package/dist/style/slottable.css +5831 -0
- package/dist/style/steps.css +6100 -0
- package/dist/style/switch.css +5624 -0
- package/dist/style/table.css +8392 -0
- package/dist/style/tabs.css +6047 -0
- package/dist/style/tag.css +5935 -0
- package/dist/style/text.css +5636 -0
- package/dist/style/timeline.css +5602 -0
- package/dist/style/timepicker.css +5904 -0
- package/dist/style/tooltip.css +5686 -0
- package/dist/style/transfer.css +101 -0
- package/dist/style/transition.css +1417 -0
- package/dist/style/tree.css +5598 -0
- package/dist/style/typography.css +5640 -0
- package/dist/style/upload.css +5834 -0
- package/dist/switch.js +448 -0
- package/dist/table.js +3809 -0
- package/dist/tabs.js +1273 -0
- package/dist/tag.js +478 -0
- package/dist/text.js +1100 -0
- package/dist/timeline.js +495 -0
- package/dist/timepicker.js +1567 -0
- package/dist/tooltip.js +179 -0
- package/dist/transfer.js +981 -0
- package/dist/transition.js +246 -0
- package/dist/tree.js +1866 -0
- package/dist/typography.js +469 -0
- package/dist/upload.js +1990 -0
- package/package.json +144 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (C) 2005-present, 58.com. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<p style="background:#000;text-align:center;padding: 20px 0">
|
|
2
|
+
<a href="https://matrix.58.com/)">
|
|
3
|
+
<img style="width: 46px;
|
|
4
|
+
height: 46px;display: inline-block;
|
|
5
|
+
vertical-align: middle;" src="https://matrix.58.com/home/dist/img/logo.gif"/>
|
|
6
|
+
<i style="font-size: 32px;
|
|
7
|
+
color: #fff;
|
|
8
|
+
display: inline-block;
|
|
9
|
+
vertical-align: middle;">MATRIX</i>
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
[![Build Status][travis-image]][travis-url] [![license][license-image]][license-url] [![javascript style guide][standard-image]][standard-url] [![version][version-image]][version-url]
|
|
14
|
+
|
|
15
|
+
[travis-url]: https://www.travis-ci.org
|
|
16
|
+
[travis-image]: https://img.shields.io/badge/build-passing-brightgreen.svg
|
|
17
|
+
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
|
|
18
|
+
[standard-url]: https://standardjs.com
|
|
19
|
+
[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
|
|
20
|
+
[license-url]: demo/miniprogram-demo/LICENSE
|
|
21
|
+
[version-image]: https://img.shields.io/badge/version-v0.0.9-blue.svg
|
|
22
|
+
[version-url]: README.md
|
|
23
|
+
|
|
24
|
+
> Better enable enterprise project in the background
|
|
25
|
+
|
|
26
|
+
## Intro
|
|
27
|
+
|
|
28
|
+
这是基于 [Vue](https://vuejs.org/) 的组件化实现,开发和服务于企业级产品,意旨在帮助开发者快速搭建属于自己的业务应用。
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
#### npm 安装
|
|
35
|
+
> 推荐使用npm的方式安装,能更好的和`webpack`等打包工具配合使用
|
|
36
|
+
``` bash
|
|
37
|
+
npm install @bic-fe/mds-ui -S
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
#### CDN 引用
|
|
41
|
+
> 支持在页面上引入`Js`和`Css`文件既可以开始使用
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
<!-- 引入样式 -->
|
|
45
|
+
<link rel="stylesheet" href="https://unpkg.com/@bic-fe/mds-ui/dist/mds-ui.min.css">
|
|
46
|
+
<!-- 引入组件库 -->
|
|
47
|
+
<script src="https://unpkg.com/@bic-fe/mds-ui/dist/mds-ui.min.js"></script>
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
`注意`:使用`CDN`引入`mds-ui`组件库需要在链接地址上锁定版本,避免组件库升级的时候带来兼容性的影响。锁定版本的方法为在连接后面增加版本号
|
|
51
|
+
|
|
52
|
+
目前可以通过 [unpkg.com/mds-ui](https://unpkg.com/browse/@bic-fe/mds-ui/) 获取到最新版本的资源,支持在页面上引入Js和Css文件既可以开始使用
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
#### 完整引入
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
import Vue from 'vue'; // 引入Vue
|
|
60
|
+
import '@bic-fe/mds-ui/dist/mds-ui.min.css'; // 引入组件的样式
|
|
61
|
+
import MdsUi from '@bic-fe/mds-ui'; // 引入组件
|
|
62
|
+
|
|
63
|
+
Vue.use(MdsUi); // 使用组件
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### 按需引入
|
|
68
|
+
|
|
69
|
+
方法一:
|
|
70
|
+
|
|
71
|
+
可以通过下面的写法来按需加载组件
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
import Button from '@bic-fe/mds-ui/dist/button';
|
|
75
|
+
```
|
|
76
|
+
方法二:
|
|
77
|
+
|
|
78
|
+
也可以使用 babel-plugin-import 来进行按需加载
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
import { Button } from '@bic-fe/mds-ui';
|
|
82
|
+
```
|
|
83
|
+
`.babelrc`修改
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
{
|
|
87
|
+
"plugins": [
|
|
88
|
+
[
|
|
89
|
+
"import", {
|
|
90
|
+
"libraryName": "@bic-fe/mds-ui",
|
|
91
|
+
"libraryDirectory": "dist",
|
|
92
|
+
"styleLibraryDirectory": "dist/style",
|
|
93
|
+
"style":true
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
## Browser Support
|
|
101
|
+
|
|
102
|
+
Modern browsers and Internet Explorer 10+.
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
[MIT](http://opensource.org/licenses/MIT)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.tfn = undefined;
|
|
5
|
+
|
|
6
|
+
var _zhCN = require('./zh-CN.js');
|
|
7
|
+
|
|
8
|
+
var _zhCN2 = _interopRequireDefault(_zhCN);
|
|
9
|
+
|
|
10
|
+
var _util = require('../_util/util.js');
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
var tfn = exports.tfn = function tfn(path) {
|
|
15
|
+
return (0, _util.getValueByPath)(_zhCN2.default, path, '');
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
exports.default = { tfn: tfn };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = {
|
|
5
|
+
mds: {
|
|
6
|
+
colorpicker: {
|
|
7
|
+
confirm: '确定',
|
|
8
|
+
clear: '清空'
|
|
9
|
+
},
|
|
10
|
+
datepicker: {
|
|
11
|
+
now: '此刻',
|
|
12
|
+
today: '今天',
|
|
13
|
+
cancel: '取消',
|
|
14
|
+
clear: '清空',
|
|
15
|
+
confirm: '确定',
|
|
16
|
+
selectDate: '选择日期',
|
|
17
|
+
selectTime: '选择时间',
|
|
18
|
+
startDate: '开始日期',
|
|
19
|
+
startTime: '开始时间',
|
|
20
|
+
endDate: '结束日期',
|
|
21
|
+
endTime: '结束时间',
|
|
22
|
+
prevYear: '前一年',
|
|
23
|
+
nextYear: '后一年',
|
|
24
|
+
prevMonth: '上个月',
|
|
25
|
+
nextMonth: '下个月',
|
|
26
|
+
year: '年',
|
|
27
|
+
month1: '1 月',
|
|
28
|
+
month2: '2 月',
|
|
29
|
+
month3: '3 月',
|
|
30
|
+
month4: '4 月',
|
|
31
|
+
month5: '5 月',
|
|
32
|
+
month6: '6 月',
|
|
33
|
+
month7: '7 月',
|
|
34
|
+
month8: '8 月',
|
|
35
|
+
month9: '9 月',
|
|
36
|
+
month10: '10 月',
|
|
37
|
+
month11: '11 月',
|
|
38
|
+
month12: '12 月',
|
|
39
|
+
week: '周次',
|
|
40
|
+
weeks: {
|
|
41
|
+
sun: '日',
|
|
42
|
+
mon: '一',
|
|
43
|
+
tue: '二',
|
|
44
|
+
wed: '三',
|
|
45
|
+
thu: '四',
|
|
46
|
+
fri: '五',
|
|
47
|
+
sat: '六'
|
|
48
|
+
},
|
|
49
|
+
months: {
|
|
50
|
+
jan: '一月',
|
|
51
|
+
feb: '二月',
|
|
52
|
+
mar: '三月',
|
|
53
|
+
apr: '四月',
|
|
54
|
+
may: '五月',
|
|
55
|
+
jun: '六月',
|
|
56
|
+
jul: '七月',
|
|
57
|
+
aug: '八月',
|
|
58
|
+
sep: '九月',
|
|
59
|
+
oct: '十月',
|
|
60
|
+
nov: '十一月',
|
|
61
|
+
dec: '十二月'
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
select: {
|
|
65
|
+
loading: '加载中',
|
|
66
|
+
noMatch: '无匹配数据',
|
|
67
|
+
noData: '无数据',
|
|
68
|
+
placeholder: '请选择'
|
|
69
|
+
},
|
|
70
|
+
cascader: {
|
|
71
|
+
noMatch: '无匹配数据',
|
|
72
|
+
loading: '加载中',
|
|
73
|
+
placeholder: '请选择',
|
|
74
|
+
noData: '暂无数据'
|
|
75
|
+
},
|
|
76
|
+
pagination: {
|
|
77
|
+
goto: '前往',
|
|
78
|
+
pagesize: '条/页',
|
|
79
|
+
total: '共 {total} 条',
|
|
80
|
+
pageClassifier: '页'
|
|
81
|
+
},
|
|
82
|
+
messagebox: {
|
|
83
|
+
title: '提示',
|
|
84
|
+
confirm: '确定',
|
|
85
|
+
cancel: '取消',
|
|
86
|
+
error: '输入的数据不合法!'
|
|
87
|
+
},
|
|
88
|
+
upload: {
|
|
89
|
+
deleteTip: '按 delete 键可删除',
|
|
90
|
+
delete: '删除',
|
|
91
|
+
preview: '查看图片',
|
|
92
|
+
continue: '继续上传'
|
|
93
|
+
},
|
|
94
|
+
table: {
|
|
95
|
+
emptyText: '暂无数据',
|
|
96
|
+
confirmFilter: '筛选',
|
|
97
|
+
resetFilter: '重置',
|
|
98
|
+
clearFilter: '全部',
|
|
99
|
+
sumText: '合计'
|
|
100
|
+
},
|
|
101
|
+
tree: {
|
|
102
|
+
emptyText: '暂无数据'
|
|
103
|
+
},
|
|
104
|
+
transfer: {
|
|
105
|
+
noMatch: '无匹配数据',
|
|
106
|
+
noData: '无数据',
|
|
107
|
+
titles: ['列表 1', '列表 2'],
|
|
108
|
+
filterPlaceholder: '请输入搜索内容',
|
|
109
|
+
noCheckedFormat: '共 {total} 项',
|
|
110
|
+
hasCheckedFormat: '已选 {checked}/{total} 项'
|
|
111
|
+
},
|
|
112
|
+
image: {
|
|
113
|
+
error: '加载失败'
|
|
114
|
+
},
|
|
115
|
+
pageHeader: {
|
|
116
|
+
title: '返回'
|
|
117
|
+
},
|
|
118
|
+
popconfirm: {
|
|
119
|
+
confirmButtonText: '确定',
|
|
120
|
+
cancelButtonText: '取消'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
function _broadcast(componentName, eventName, params) {
|
|
5
|
+
this.$children.forEach(function (child) {
|
|
6
|
+
var name = child.$options.componentName;
|
|
7
|
+
if (name === componentName) {
|
|
8
|
+
child.$emit.apply(child, [eventName].concat(params));
|
|
9
|
+
} else {
|
|
10
|
+
_broadcast.apply(child, [componentName, eventName].concat([params]));
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
exports.default = {
|
|
15
|
+
methods: {
|
|
16
|
+
dispatch: function dispatch(componentName, eventName, params) {
|
|
17
|
+
var parent = this.$parent || this.$root;
|
|
18
|
+
var name = parent.$options.componentName;
|
|
19
|
+
|
|
20
|
+
while (parent && (!name || name !== componentName)) {
|
|
21
|
+
parent = parent.$parent;
|
|
22
|
+
|
|
23
|
+
if (parent) {
|
|
24
|
+
name = parent.$options.componentName;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (parent) {
|
|
28
|
+
parent.$emit.apply(parent, [eventName].concat(params));
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
broadcast: function broadcast(componentName, eventName, params) {
|
|
32
|
+
_broadcast.call(this, componentName, eventName, params);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
|
|
5
|
+
var _index = require('../_locale/index.js');
|
|
6
|
+
|
|
7
|
+
exports.default = {
|
|
8
|
+
methods: {
|
|
9
|
+
t: function t() {
|
|
10
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
11
|
+
args[_key] = arguments[_key];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return _index.tfn.apply(this, args);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
|
|
5
|
+
var _extends2 = require('babel-runtime/helpers/extends');
|
|
6
|
+
|
|
7
|
+
var _extends3 = _interopRequireDefault(_extends2);
|
|
8
|
+
|
|
9
|
+
var _assign = require('babel-runtime/core-js/object/assign');
|
|
10
|
+
|
|
11
|
+
var _assign2 = _interopRequireDefault(_assign);
|
|
12
|
+
|
|
13
|
+
var _create = require('babel-runtime/core-js/object/create');
|
|
14
|
+
|
|
15
|
+
var _create2 = _interopRequireDefault(_create);
|
|
16
|
+
|
|
17
|
+
var _keys = require('babel-runtime/core-js/object/keys');
|
|
18
|
+
|
|
19
|
+
var _keys2 = _interopRequireDefault(_keys);
|
|
20
|
+
|
|
21
|
+
var _popper = require('popper.js');
|
|
22
|
+
|
|
23
|
+
var _popper2 = _interopRequireDefault(_popper);
|
|
24
|
+
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 实际使用的位置和popper.js的位置映射表
|
|
29
|
+
*/
|
|
30
|
+
var placementMap = {
|
|
31
|
+
top: 'top',
|
|
32
|
+
left: 'left',
|
|
33
|
+
right: 'right',
|
|
34
|
+
bottom: 'bottom',
|
|
35
|
+
topLeft: 'top-start',
|
|
36
|
+
topRight: 'top-end',
|
|
37
|
+
bottomLeft: 'bottom-start',
|
|
38
|
+
bottomRight: 'bottom-end',
|
|
39
|
+
leftTop: 'left-start',
|
|
40
|
+
leftBottom: 'left-end',
|
|
41
|
+
rightTop: 'right-start',
|
|
42
|
+
rightBottom: 'right-end'
|
|
43
|
+
};
|
|
44
|
+
var popperMap = {
|
|
45
|
+
'top': 'top',
|
|
46
|
+
'left': 'left',
|
|
47
|
+
'right': 'right',
|
|
48
|
+
'bottom': 'bottom',
|
|
49
|
+
'top-start': 'topLeft',
|
|
50
|
+
'top-end': 'topRight',
|
|
51
|
+
'bottom-start': 'bottomLeft',
|
|
52
|
+
'bottom-end': 'bottomRight',
|
|
53
|
+
'left-start': 'leftTop',
|
|
54
|
+
'left-end': 'leftBottom',
|
|
55
|
+
'right-start': 'rightTop',
|
|
56
|
+
'right-end': 'rightBottom'
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.default = {
|
|
60
|
+
props: {
|
|
61
|
+
placement: {
|
|
62
|
+
type: String,
|
|
63
|
+
default: 'bottom'
|
|
64
|
+
},
|
|
65
|
+
popperOptions: {
|
|
66
|
+
type: Object,
|
|
67
|
+
default: function _default() {}
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
data: function data() {
|
|
71
|
+
return {
|
|
72
|
+
placementMap: placementMap,
|
|
73
|
+
popperMap: popperMap,
|
|
74
|
+
popper: null,
|
|
75
|
+
reference: null,
|
|
76
|
+
visible: false,
|
|
77
|
+
visibleArrow: false,
|
|
78
|
+
currentPalcement: '',
|
|
79
|
+
popperModifiers: {}
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
watch: {
|
|
84
|
+
visible: function visible(val) {
|
|
85
|
+
var _this = this;
|
|
86
|
+
|
|
87
|
+
if (val) {
|
|
88
|
+
this.$nextTick(function () {
|
|
89
|
+
_this.updatePopper();
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
this.destroyPopper();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
computed: {
|
|
97
|
+
placementCls: function placementCls() {
|
|
98
|
+
return [this.prefixCls + '-placement-' + this.popperMap[this.currentPalcement]];
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
created: function created() {
|
|
102
|
+
this.currentPalcement = this.placementMap[this.placement];
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
methods: {
|
|
106
|
+
createPopper: function createPopper() {
|
|
107
|
+
var _this2 = this;
|
|
108
|
+
|
|
109
|
+
if ((0, _keys2.default)(this.placementMap).indexOf(this.placement) === -1) return;
|
|
110
|
+
this.popper = this.popper || this.$refs.popper;
|
|
111
|
+
if (this.popperVM && this.popperVM.$el) {
|
|
112
|
+
this.popper = this.popperVM.$el;
|
|
113
|
+
}
|
|
114
|
+
var options = (0, _create2.default)(null);
|
|
115
|
+
if (!this.popper || !this.reference) return;
|
|
116
|
+
if (this.visibleArrow) this.appendArrow(this.popper);
|
|
117
|
+
document.body.appendChild(this.popper);
|
|
118
|
+
if (this.popperJS && this.popperJS.destroy) {
|
|
119
|
+
this.popperJS.destroy();
|
|
120
|
+
}
|
|
121
|
+
options.placement = this.currentPalcement;
|
|
122
|
+
var defaultModifiers = {
|
|
123
|
+
computeStyle: {
|
|
124
|
+
gpuAcceleration: false
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
options.modifiers = (0, _assign2.default)({}, defaultModifiers, this.popperModifiers);
|
|
128
|
+
options.onCreate = function () {
|
|
129
|
+
_this2.currentPalcement = _this2.popper.getAttribute('x-placement');
|
|
130
|
+
_this2.resetTransformOrigin();
|
|
131
|
+
_this2.$nextTick(_this2.updatePopper);
|
|
132
|
+
};
|
|
133
|
+
options.onUpdate = function () {
|
|
134
|
+
_this2.currentPalcement = _this2.popper.getAttribute('x-placement');
|
|
135
|
+
};
|
|
136
|
+
this.popperJS = new _popper2.default(this.reference, this.popper, (0, _extends3.default)({}, options, this.popperOptions));
|
|
137
|
+
},
|
|
138
|
+
updatePopper: function updatePopper() {
|
|
139
|
+
if (this.popperJS) {
|
|
140
|
+
this.popperJS.update();
|
|
141
|
+
} else {
|
|
142
|
+
this.createPopper();
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
doDestroy: function doDestroy() {
|
|
146
|
+
if (this.visible || !this.popperJS) return;
|
|
147
|
+
this.popperJS.destroy();
|
|
148
|
+
this.popperJS = null;
|
|
149
|
+
},
|
|
150
|
+
destroyPopper: function destroyPopper() {
|
|
151
|
+
if (this.popperJS) {
|
|
152
|
+
this.resetTransformOrigin();
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
resetTransformOrigin: function resetTransformOrigin() {
|
|
156
|
+
var tfPlacementMap = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' };
|
|
157
|
+
var placement = this.currentPalcement.split('-')[0];
|
|
158
|
+
var origin = tfPlacementMap[placement];
|
|
159
|
+
this.popper.style.transformOrigin = ['top', 'bottom'].indexOf(placement) > -1 ? 'center ' + origin : origin + ' center';
|
|
160
|
+
},
|
|
161
|
+
appendArrow: function appendArrow(element) {
|
|
162
|
+
var hash = void 0;
|
|
163
|
+
if (this.appended) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this.appended = true;
|
|
168
|
+
|
|
169
|
+
(0, _keys2.default)(element.attributes).some(function (item) {
|
|
170
|
+
if (/^_v-/.test(element.attributes[item].name)) {
|
|
171
|
+
hash = element.attributes[item].name;
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
return false;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
var arrow = document.createElement('div');
|
|
178
|
+
|
|
179
|
+
if (hash) {
|
|
180
|
+
arrow.setAttribute(hash, '');
|
|
181
|
+
}
|
|
182
|
+
arrow.className = this.prefixCls + '-arrow';
|
|
183
|
+
element.querySelector('.' + this.prefixCls + '-content').appendChild(arrow);
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
beforeDestroy: function beforeDestroy() {
|
|
187
|
+
this.doDestroy();
|
|
188
|
+
if (this.popper && this.popper.parentNode === document.body) {
|
|
189
|
+
document.body.removeChild(this.popper);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
};
|