-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add CascadePicker component #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #45 +/- ##
==========================================
- Coverage 88.94% 88.66% -0.28%
==========================================
Files 45 49 +4
Lines 841 891 +50
Branches 113 121 +8
==========================================
+ Hits 748 790 +42
- Misses 49 52 +3
- Partials 44 49 +5
Continue to review full report at Codecov.
|
dolymood
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
example/pages/linkage-picker.vue
Outdated
| createAPI(Vue, DatePicker, ['select', 'cancel'], false) | ||
| const linkageData = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
数据放 data/ 中把
example/pages/picker.vue
Outdated
| return [provinces, cities, areas] | ||
| } | ||
| return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有 data 的话 整个 data() 可以删除了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍get~
| <cube-picker | ||
| ref="picker" | ||
| :title="title" | ||
| :data="pickerData" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pickerData 初始放在 data 中
| return { | ||
| linkageData: this.data.slice(), | ||
| pickerSelectedIndex: this.selectedIndex.slice(), | ||
| tempIndex: [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果变量不需要 watch 或者 computed 或者当做 prop 的话,可以直接写在 this 上,可以在 created 中初始化,没必要放在 data 中,data 中之存放 observe 数据。这里的 tempIndex 和 changeI 都可以移除
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍get~
| } | ||
| }, | ||
| computed: { | ||
| depth() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depth 可以不需要,看下边的 updatePickerData 那里
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍get~
| updatePickerData(init) { | ||
| const pickerData = [] | ||
| let data = this.linkageData | ||
| for (let i = 0; i < this.depth; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这种树状结构的数据重新梳理的话,使用递归即可,也可以直接使用循环,但是判断条件是判断 data 还有没有children。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
另,这个对数据结构的梳理可以重新加一个函数梳理
| if (!init) { | ||
| this.$refs.picker.setData(this.pickerData, this.tempIndex) | ||
| this.$refs.picker.refresh() | ||
| for (let j = this.changeI + 1; j < this.depth; j++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分不需要吧循环不需要吧,已经setData了,应该不需要重新调用picker 的 scrollTo了吧;如果不是的话,那可以考虑进一步修改 picker 的逻辑,使其适应性更强?
还有一个问题是 如果是没show的情况下调用refresh 会有问题吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
现在在show的时候,如果不scrollTo是没有滚动相应tempIndex的~嗯,明天看一下picker的逻辑~~如果是没show的情况下调用refresh 会有问题,所以我在init的时候不会执行这段
|
Need unit tests. |
f8b74a7 to
382228d
Compare
* CascadePicker init * add tests
Please make sure these boxes are checked before submitting your PR, thank you!
devbranch.