TabPicker 多级联动选择器

Scan me!

底部级联选择、非级联选择的tab切换面板

引入

  1. import { TabPicker } from 'mand-mobile'
  2. Vue.component(TabPicker.name, TabPicker)

使用指南

tab切换的title支持自定义渲染(通过slot-scope)

  1. <!-- props 为每个tab标签的数据 -->
  2. <div
  3. slot="titles"
  4. slot-scope="props"
  5. class="title-item">
  6. 标签dom
  7. {{ props.label }}
  8. </div>

异步级联面板支持传入slot

  1. <!--异步获取数据loading slot-->
  2. <div slot="loading">loading内容</div>
  3. <!--异步获取数据异常 slot -->
  4. <div slot="error">数据异常</div>

代码演示

普通多频道

  1. <template>
  2. <div class="md-example-child md-example-child-tab-picker md-example-child-tab-picker-0">
  3. <md-button @click="showTabPicker">普通多频道</md-button>
  4. <md-tab-picker
  5. v-model="isTabPickerShow"
  6. :title="title"
  7. :data="pickerData"
  8. ok-text="确认"
  9. cancel-text="取消"
  10. @confirm="onTabPickerConfirm"
  11. @change="onTabPickerChange"
  12. ></md-tab-picker>
  13. </div>
  14. </template>
  15. <script>
  16. import {Button, TabPicker} from 'mand-mobile'
  17. import pickerData from 'mand-mobile/components/tab-picker/demo/data/no-cascade'
  18. export default {
  19. name: 'tab-picker-demo',
  20. components: {
  21. [TabPicker.name]: TabPicker,
  22. [Button.name]: Button,
  23. },
  24. data() {
  25. return {
  26. isTabPickerShow: false,
  27. title: '选择title',
  28. pickerData,
  29. }
  30. },
  31. methods: {
  32. showTabPicker() {
  33. this.isTabPickerShow = true
  34. },
  35. onTabPickerConfirm(selected) {
  36. if (selected) {
  37. console.log(`[Mand Mobile] TabPicker 确认选择项: ${JSON.stringify(selected)}`)
  38. } else {
  39. console.warn('[Mand Mobile] TabPicker 点击确认按钮时未选择到任何确定项')
  40. }
  41. },
  42. onTabPickerChange(select) {
  43. console.log(
  44. `[Mand Mobile] TabPicker ${select.selectTab}列, ${select.selectIndex}项: label: ${select.selectItem
  45. .label}, value: ${select.selectItem.value}`,
  46. )
  47. },
  48. },
  49. }
  50. </script>
  51.  

异步级联多频道

  1. <template>
  2. <div class="md-example-child md-example-child-tab-picker md-example-child-tab-picker-2">
  3. <md-button @click="showTabPicker">异步级联多频道</md-button>
  4. <md-tab-picker
  5. v-model="isTabPickerShow"
  6. data-struct="async"
  7. :title="title"
  8. :async-func="asyncFunc"
  9. :option-render="optionRenders"
  10. ok-text="确认"
  11. cancel-text="取消"
  12. @confirm="onTabPickerConfirm"
  13. @change="onTabPickerChange"
  14. ></md-tab-picker>
  15. </div>
  16. </template>
  17. <script>
  18. import {Button, TabPicker} from 'mand-mobile'
  19. const NOOP = () => {}
  20. export default {
  21. name: 'tab-picker-demo',
  22. components: {
  23. [TabPicker.name]: TabPicker,
  24. [Button.name]: Button,
  25. },
  26. data() {
  27. return {
  28. isTabPickerShow: false,
  29. title: '选择title',
  30. optionRenders: [NOOP, NOOP, this.optionRender],
  31. }
  32. },
  33. methods: {
  34. asyncFunc: (value, callback) => {
  35. console.log('loading')
  36. setTimeout(() => {
  37. callback(null, {
  38. options: [
  39. {
  40. label: '一级选项一',
  41. value: '0271',
  42. },
  43. {
  44. label: '一级选项二',
  45. value: '0272',
  46. },
  47. ],
  48. asyncFunc: (value, callback) => {
  49. console.log('第一级选择项', value)
  50. callback(null, {
  51. options: [
  52. {
  53. label: '二级选项一',
  54. value: '0271',
  55. },
  56. {
  57. label: '二级选项二',
  58. value: '0272',
  59. },
  60. ],
  61. asyncFunc: (value, callback) => {
  62. console.log('第二级选择项', value)
  63. callback(null, {
  64. options: [
  65. {
  66. label: '三级选项一',
  67. value: '0271',
  68. },
  69. {
  70. label: '三级选项二',
  71. value: '0272',
  72. },
  73. ],
  74. })
  75. },
  76. })
  77. },
  78. })
  79. }, 1000)
  80. },
  81. optionRender(item) {
  82. return `<div class="md-field-item-custom-title">${item.label}</div><div class="md-field-item-custom-brief">十年前你说生如夏花般灿烂,十年后你说平凡才是唯一的答案</div>`
  83. },
  84. showTabPicker() {
  85. this.isTabPickerShow = true
  86. },
  87. onTabPickerConfirm(selected) {
  88. if (selected) {
  89. console.log(`[Mand Mobile] TabPicker 确认选择项: ${JSON.stringify(selected)}`)
  90. } else {
  91. console.warn('[Mand Mobile] TabPicker 点击确认按钮时未选择到任何确定项')
  92. }
  93. },
  94. onTabPickerChange(select) {
  95. console.log(
  96. `[Mand Mobile] TabPicker ${select.selectTab}列, ${select.selectIndex}项: label: ${select.selectItem
  97. .label}, value: ${select.selectItem.value}`,
  98. )
  99. },
  100. },
  101. }
  102. </script>
  103.  

级联多频道

  1. <template>
  2. <div class="md-example-child md-example-child-tab-picker md-example-child-tab-picker-1">
  3. <md-button @click="showTabPicker">级联多频道</md-button>
  4. <md-tab-picker
  5. v-model="isTabPickerShow"
  6. :title="title"
  7. :data="pickerData"
  8. data-struct="cascade"
  9. ok-text="确认"
  10. cancel-text="取消"
  11. :option-render="optionRenders"
  12. @confirm="onTabPickerConfirm"
  13. @change="onTabPickerChange"
  14. ></md-tab-picker>
  15. </div>
  16. </template>
  17. <script>
  18. import {Button, TabPicker} from 'mand-mobile'
  19. import pickerData from 'mand-mobile/components/tab-picker/demo/data/cascade'
  20. const NOOP = () => {}
  21. export default {
  22. name: 'tab-picker-demo',
  23. components: {
  24. [TabPicker.name]: TabPicker,
  25. [Button.name]: Button,
  26. },
  27. data() {
  28. return {
  29. isTabPickerShow: false,
  30. title: '选择title',
  31. optionRenders: [NOOP, NOOP, this.optionRender],
  32. pickerData,
  33. }
  34. },
  35. methods: {
  36. optionRender(item) {
  37. return `<div class="md-field-item-custom-title">${item.label}</div><div class="md-field-item-custom-brief">十年前你说生如夏花般灿烂,十年后你说平凡才是唯一的答案</div>`
  38. },
  39. showTabPicker() {
  40. this.isTabPickerShow = true
  41. },
  42. onTabPickerConfirm(selected) {
  43. if (selected) {
  44. console.log(`[Mand Mobile] TabPicker 确认选择项: ${JSON.stringify(selected)}`)
  45. } else {
  46. console.warn('[Mand Mobile] TabPicker 点击确认按钮时未选择到任何确定项')
  47. }
  48. },
  49. onTabPickerChange(select) {
  50. console.log(
  51. `[Mand Mobile] TabPicker ${select.selectTab}列, ${select.selectIndex}项: label: ${select.selectItem
  52. .label}, value: ${select.selectItem.value}`,
  53. )
  54. },
  55. },
  56. }
  57. </script>
  58.  

API

TabPicker Props

属性说明类型默认值备注
v-model控制显示或隐藏Booleanfalse-
data数据源Array[]数据格式参考附录
data-struct数据级联类型StringnoCascadenormal, cascade, async
default-index初始选中项索引Array[]-
option-render返回各选项渲染内容Array<Function({text, disabled, …}):String>[]vue 2.1.0+可使用slot-scope,见附录
async-func异步获取数据函数Function(value, callBack)--
title弹窗标题String--
ok-text确认按钮文案String确认-
cancel-text取消按钮文案String取消-
placeholder1.6.3+待选择提示文案String请选择-
errorLabel1.6.3+数据源错误文案String数据异常-
loadingLabel1.6.3+异步加载文案String加载中-
mask-closable1.3.0+点击蒙层是否可关闭弹出层Booleantrue-

TabPicker Methods

getSelectedItem()

获取所有列选中项的值

返回

属性说明类型
columnsValue所有列选中项的值Array<{value, lable, …}>

TabPicker Events

@change(select)

底部弹窗选中事件

属性说明类型
select各列选中项值Object: {value,lable}

@confirm(selected)

底部弹窗确认选择事件

属性说明类型
selected各列选中项值Array<{value,lable}>

@cancel()

底部弹窗取消选择事件

@show()

底部弹窗弹层展示事件

@hide()

底部弹窗弹层隐藏事件

附录

  • 非级联数据源数据格式
  1. [
  2. {
  3. // 选项展示文案
  4. "label": "",
  5. // 以下自定义字段
  6. "value": "",
  7. //该选项下的列表
  8. "children": [
  9. {
  10. "label": "",
  11. "value": ""
  12. },
  13. // ...
  14. ]
  15. },
  16. // ...
  17. // ...
  18. ]
  • 级联数据源数据格式
  1. [
  2. {
  3. // 选项展示文案
  4. "label": "",
  5. // 选项值
  6. "value": "",
  7. // 第二列对应数据
  8. "children": [
  9. {
  10. "label": "",
  11. "value": "",
  12. "children": [
  13. //...
  14. ]
  15. }
  16. ]
  17. },
  18. //...
  19. ]
  • 异步级联数据源数据格式
  1. {
  2. "options": [
  3. {
  4. // 选项展示文案
  5. "label": "",
  6. // 选项值
  7. "value": ""
  8. },
  9. //...
  10. ]
  11. "asyncFunc": (value, callback) => {
  12. callback(null, {
  13. "options": [
  14. {
  15. "label": '',
  16. "value": ''
  17. },
  18. //...
  19. ],
  20. "asyncFunc": (value, callback) => {
  21. //...
  22. }
  23. })
  24. }
  25. }
  • 自定义渲染option
  1. <template>
  2. <md-tab-picker
  3. :data="data"
  4. >
  5. <!-- option 为每个选项的数据 -->
  6. <li
  7. slot="option"
  8. slot-scope="props"
  9. class="option-item">
  10. 公共dom样式
  11. <div v-if="props.index === 0" >
  12. 第{{ props.index }}列dom样式 {{ props.option.label }}
  13. </div>
  14. <div v-else-if="props.index === 1">
  15. 第{{ props.index }}列dom样式 {{ props.option.label }}
  16. </div>
  17. <div v-else>
  18. 第{{ props.index }}列dom样式 {{ props.option.label }}
  19. </div>
  20. </li>
  21. </md-tab-picker>
  22. </template>