From aee78fab7a97ae72a3782aa419bb7c99c4199a22 Mon Sep 17 00:00:00 2001 From: mangogan <1261639871@qq.com> Date: Mon, 29 Jul 2019 16:40:11 +0800 Subject: [PATCH 1/9] feature: the most basic of tab --- demo/components/tabDemo.vue | 111 +++++++++++++++++++++++++++ demo/demo.vue | 4 + demo/index.js | 2 + index.js | 2 + packages/common/Tab/index.js | 9 +++ packages/common/Tab/src/TabPanel.vue | 50 ++++++++++++ packages/common/Tab/src/main.vue | 89 +++++++++++++++++++++ styles/Tab.scss | 22 ++++++ styles/index.scss | 1 + 9 files changed, 290 insertions(+) create mode 100644 demo/components/tabDemo.vue create mode 100644 packages/common/Tab/index.js create mode 100644 packages/common/Tab/src/TabPanel.vue create mode 100644 packages/common/Tab/src/main.vue create mode 100644 styles/Tab.scss diff --git a/demo/components/tabDemo.vue b/demo/components/tabDemo.vue new file mode 100644 index 000000000..8a43149f6 --- /dev/null +++ b/demo/components/tabDemo.vue @@ -0,0 +1,111 @@ + + diff --git a/demo/demo.vue b/demo/demo.vue index 18a121569..97b7c1498 100644 --- a/demo/demo.vue +++ b/demo/demo.vue @@ -134,6 +134,10 @@ export default { { name: 'Form', path: '/n-form' + }, + { + name: 'Tab', + path: '/n-tab' } ] }, diff --git a/demo/index.js b/demo/index.js index 042ca2e5f..1b34372dc 100644 --- a/demo/index.js +++ b/demo/index.js @@ -27,6 +27,7 @@ import inputNumberDemo from './components/inputNumberDemo' import nimbusIconDemo from './components/nimbusIconDemo' import radioDemo from './components/radioDemo' import formDemo from './components/formDemo' +import tabDemo from './components/tabDemo' import timePickerDemo from './components/timePickerDemo' import notificationDemo from './components/notificationDemo' @@ -82,6 +83,7 @@ const routes = [ { path: '/n-nimbus-icon', component: nimbusIconDemo }, { path: '/n-radio', component: radioDemo }, { path: '/n-form', component: formDemo }, + { path: '/n-tab', component: tabDemo }, { path: '/n-time-picker', component: timePickerDemo }, { path: '/n-router-debug', component: routerDebug } ] diff --git a/index.js b/index.js index 994833cec..7d897ed1d 100644 --- a/index.js +++ b/index.js @@ -24,6 +24,7 @@ import DatePicker from './packages/common/DatePicker' import InputNumber from './packages/common/InputNumber' import Radio from './packages/common/Radio' import Form from './packages/common/Form' +import Tab from './packages/common/Tab' import TimePicker from './packages/common/TimePicker' import ServiceCard from './packages/nimbus/ServiceCard' import HomeLayout from './packages/nimbus/HomeLayout' @@ -67,6 +68,7 @@ function install (Vue) { NimbusIcon.install(Vue) Radio.install(Vue) Form.install(Vue) + Tab.install(Vue) TimePicker.install(Vue) } diff --git a/packages/common/Tab/index.js b/packages/common/Tab/index.js new file mode 100644 index 000000000..413ed1516 --- /dev/null +++ b/packages/common/Tab/index.js @@ -0,0 +1,9 @@ +import Tab from './src/main.vue' +import NTabPanel from './src/TabPanel.vue' + +Tab.install = function (Vue) { + Vue.component(Tab.name, Tab) + Vue.component(NTabPanel.name, NTabPanel) +} + +export default Tab diff --git a/packages/common/Tab/src/TabPanel.vue b/packages/common/Tab/src/TabPanel.vue new file mode 100644 index 000000000..4eb0d4336 --- /dev/null +++ b/packages/common/Tab/src/TabPanel.vue @@ -0,0 +1,50 @@ + + diff --git a/packages/common/Tab/src/main.vue b/packages/common/Tab/src/main.vue new file mode 100644 index 000000000..51333d872 --- /dev/null +++ b/packages/common/Tab/src/main.vue @@ -0,0 +1,89 @@ + + diff --git a/styles/Tab.scss b/styles/Tab.scss new file mode 100644 index 000000000..aeb93364e --- /dev/null +++ b/styles/Tab.scss @@ -0,0 +1,22 @@ +@import './mixins/mixins.scss'; +@import './theme/default.scss'; + +@include b(tab) { + display: block; + width: 100%; + height: 100%; + .n-tab--label { + display: flex; + align-items: center; + justify-items: flex-start; + background-color: bisque; + padding-bottom: 10px; + .n-tab--label-item { + padding: 2px 5px; + border-right: 1px solid #cccccc; + } + .n-tab--label-item_active { + color: aquamarine; + } + } +} \ No newline at end of file diff --git a/styles/index.scss b/styles/index.scss index 250f79c05..2f3f7bee9 100644 --- a/styles/index.scss +++ b/styles/index.scss @@ -23,6 +23,7 @@ @import './Radio.scss'; @import './Form.scss'; @import './TimePicker.scss'; +@import './Tab.scss'; @import "./NimbusServiceLayout.scss"; @import "./Popover.scss"; From 01ab476f8908addfbdc7bab0d56fd3cd060267e5 Mon Sep 17 00:00:00 2001 From: mangogan <1261639871@qq.com> Date: Tue, 30 Jul 2019 10:59:21 +0800 Subject: [PATCH 2/9] store --- demo/components/formDemo.vue | 5 +++- demo/components/tabDemo.vue | 8 ++++++- packages/common/Form/src/form-item.vue | 4 +++- packages/common/Tab/src/TabPanel.vue | 33 ++++++++++++++++++++------ packages/common/Tab/src/main.vue | 15 +++++++----- styles/Form.scss | 6 ++++- styles/Tab.scss | 20 +++++++++++++++- 7 files changed, 73 insertions(+), 18 deletions(-) diff --git a/demo/components/formDemo.vue b/demo/components/formDemo.vue index d3ecf469d..de99732a4 100644 --- a/demo/components/formDemo.vue +++ b/demo/components/formDemo.vue @@ -182,7 +182,10 @@ :label-width="200" label-position="top" > - + diff --git a/demo/components/tabDemo.vue b/demo/components/tabDemo.vue index 8a43149f6..f57cddb72 100644 --- a/demo/components/tabDemo.vue +++ b/demo/components/tabDemo.vue @@ -31,7 +31,10 @@ - + + + haha: +
diff --git a/packages/common/Form/src/form-item.vue b/packages/common/Form/src/form-item.vue index 1e55a1e0e..0dbdb069c 100644 --- a/packages/common/Form/src/form-item.vue +++ b/packages/common/Form/src/form-item.vue @@ -7,7 +7,9 @@ :class="`${prefix}__label`" :style="style" > - {{ label }} + + {{ label }} +
-
-
- -
+
+
diff --git a/packages/common/Form/src/main.vue b/packages/common/Form/src/main.vue index d248738a8..727f068ae 100644 --- a/packages/common/Form/src/main.vue +++ b/packages/common/Form/src/main.vue @@ -10,7 +10,6 @@ + +
+
+ +
+
+ Basic Usage / name attribute +
+
+ + + I am a input + + + I am an active button hahaha +
Two mode supported now: normal and card. + closable only can use in card mode. +
+ Configure addable and add-panel attributes to dynamically add panels. +
+ before-leave attribute: callback before tab-panel changed +
+ tab-remove attribute: callback after tab removed, param is the instance of the panel. +
+
+ + I am a button hahaha + + + {{ i.content }} + +
+
+
+
-
@@ -81,65 +290,30 @@ import docCodeEditorMixin from './docCodeEditorMixin' export default { mixins: [docCodeEditorMixin], data () { - let d = new Array(20).fill(0) - d = d.map((item, idx) => { - return { - name: 'xiaobai' + idx, - age: Math.ceil((Math.random() * 20)) - } - }) return { panels: [], - data: d, - columns0: [ - { - title: 'Name', - key: 'name', - width: 300 - }, - { - title: '#', - render: (h, params) => { - return ( - this.handleClick(params)} - > - delete - - ) - } - }, - { - title: 'Age', - key: 'age', - render: (h, params) => { - return {params.row.age} - } - }, - { - title: '#', - render: (h, params) => { - return ( - this.handleClick(params)} - > - delete - - ) - } - }] + toggleName: 'b' } }, methods: { - addPanel () { + addPanelItem () { this.panels.push({ label: this.panels.length, content: 'i am number' + this.panels.length }) + }, + tabRemove (i) { + console.log('callback tab-remove', i) + }, + updateName () { + this.toggleName = this.toggleName === 'a' ? 'b' : 'a' + }, + beforeLeave (n, o) { + return new Promise((resolve, reject) => { + setTimeout(() => { + resolve('e') + }, 500) + }) } } } diff --git a/packages/common/Tab/src/TabPanel.vue b/packages/common/Tab/src/TabPanel.vue index f787801d7..292ddc4ea 100644 --- a/packages/common/Tab/src/TabPanel.vue +++ b/packages/common/Tab/src/TabPanel.vue @@ -66,23 +66,19 @@ export default { this.$on('display-none', this.setDisplayNone) }, beforeDestroy () { - console.log('before destory call') this.$off('display-none', this.setDisplayNone) }, methods: { updateIsShow (flag) { this.isShow = flag this.$forceUpdate() - // window.getComputedStyle(this.NTab.refs['slot'], null).getPropertyValue('width') - // this.$refs['panel'].classList.toggle('n-tab-panel_active') - // 这里应该是根据切换的方向(左右) 来设置 }, setTransfer (per) { + // 这里可以优化, 直接在上层div做整体移动, 不需要对子元素移动 this.style.transform = 'translateX(' + per + ')' }, setDisplayNone (i) { if (i === this._NaiveTabOrder) { - // this.$set(this.style, 'display', 'none') this.unDelete = false } } diff --git a/packages/common/Tab/src/main.vue b/packages/common/Tab/src/main.vue index 17a4b20b9..ea12f751b 100644 --- a/packages/common/Tab/src/main.vue +++ b/packages/common/Tab/src/main.vue @@ -1,27 +1,32 @@