gpc-ui 0.1.7

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.
@@ -0,0 +1,159 @@
1
+ <template>
2
+ <div class="tabs">
3
+ <div class="tabs-bar">
4
+ <div :class="tabCls(item)"
5
+ v-for="(item, index) in navList"
6
+ @click="handleChange(index)"
7
+ :key="item.name">
8
+ {{ item.label }}
9
+ </div>
10
+ <div class="tabs-tab-underline"
11
+ :style="{ left: underlineLeft, width: underlineWidth }"
12
+ :class="{ 'tabs-tab-underline-active': currentValue !== null }"></div>
13
+ </div>
14
+ <div class="tabs-content">
15
+ <slot></slot>
16
+ </div>
17
+ </div>
18
+ </template>
19
+
20
+ <script>
21
+ export default {
22
+ props: {
23
+ curTab: [String, Number]
24
+ },
25
+ data() {
26
+ return {
27
+ currentValue: this.curTab,
28
+ navList: []
29
+ }
30
+ },
31
+ computed: {
32
+ underlineLeft() {
33
+ if (this.currentValue === null) return '0';
34
+ const index = this.navList.findIndex(tab => tab.name === this.currentValue);
35
+ if (index === -1) return '0';
36
+ const tabElement = this.$el.querySelectorAll('.tabs-tab')[index];
37
+ if (!tabElement) return '0';
38
+ return `${tabElement.offsetLeft}px`;
39
+ },
40
+ underlineWidth() {
41
+ if (this.currentValue === null) return '0';
42
+ const index = this.navList.findIndex(tab => tab.name === this.currentValue);
43
+ if (index === -1) return '0';
44
+ const tabElement = this.$el.querySelectorAll('.tabs-tab')[index];
45
+ if (!tabElement) return '0';
46
+ return `${tabElement.offsetWidth}px`;
47
+ }
48
+ },
49
+ methods: {
50
+ tabCls(item) {
51
+ return [
52
+ 'tabs-tab',
53
+ {
54
+ 'tabs-tab-active': item.name === this.currentValue
55
+ }
56
+ ]
57
+ },
58
+ getTabs() {
59
+ return this.$children.filter(function (item) {
60
+ return item.$options.name === 'TabPane'
61
+ })
62
+ },
63
+ updateNav() {
64
+ this.navList = []
65
+ let _this = this
66
+ this.getTabs().forEach(function (pane, index) {
67
+ _this.navList.push({
68
+ label: pane.label,
69
+ name: pane.name || index
70
+ })
71
+ if (!pane.name) pane.name = index
72
+ if (index === 0) {
73
+ if (!_this.currentValue) {
74
+ _this.currentValue = pane.name || index
75
+ }
76
+ }
77
+ })
78
+ this.updateStatus()
79
+ },
80
+ updateStatus() {
81
+ let tabs = this.getTabs()
82
+ let _this = this
83
+ tabs.forEach(function (tab) {
84
+ let b = tab.name === _this.currentValue
85
+ tab.show = b
86
+ return tab.show
87
+ })
88
+ },
89
+ handleChange(index) {
90
+ let nav = this.navList[index]
91
+ let name = nav.name
92
+ this.currentValue = name
93
+ this.$emit('input', name)
94
+ this.$emit('on-click', name)
95
+ }
96
+ },
97
+ watch: {
98
+ curTab: function (val) {
99
+ this.currentValue = val
100
+ },
101
+ currentValue() {
102
+ this.updateStatus()
103
+ }
104
+ },
105
+ mounted() {
106
+ this.updateNav()
107
+ }
108
+ }
109
+ </script>
110
+
111
+ <style scoped>
112
+ [v-cloak] {
113
+ display: none;
114
+ }
115
+
116
+ .tabs {
117
+ font-size: 20px;
118
+ color: #d3d3d3;
119
+ }
120
+
121
+ .tabs-bar {
122
+ position: relative;
123
+ }
124
+
125
+ .tabs-bar:after {
126
+ content: '';
127
+ display: block;
128
+ width: 100%;
129
+ height: 1px;
130
+ background: #d7dde4;
131
+ }
132
+
133
+ .tabs-tab {
134
+ display: inline-block;
135
+ padding: 4px 16px;
136
+ margin-right: 6px;
137
+ background: #fff;
138
+ cursor: pointer;
139
+ position: relative;
140
+ }
141
+
142
+ .tabs-tab-active {
143
+ color: #018a46;
144
+ }
145
+
146
+ .tabs-tab-underline {
147
+ position: absolute;
148
+ bottom: 0;
149
+ left: 0;
150
+ width: 0;
151
+ height: 2px;
152
+ background: #018a46;
153
+ transition: width 0.3s ease, left 0.3s ease;
154
+ }
155
+
156
+ .tabs-tab-underline-active {
157
+ width: 100%;
158
+ }
159
+ </style>
@@ -0,0 +1,20 @@
1
+ import gpcLogin from "./gpc-login/index.vue"
2
+ import gpcTabs from "./gpc-tabs/Tabs.vue"
3
+
4
+ const components = {
5
+ gpcLogin,
6
+ gpcTabs
7
+ };
8
+
9
+ function install(Vue) {
10
+ const keys = Object.keys(components);
11
+ keys.forEach((name) => {
12
+ const component = components[name];
13
+ Vue.component(component.name || name, component);
14
+ });
15
+ }
16
+
17
+ export default {
18
+ install,
19
+ ...components,
20
+ };