Skip to content

xtf-picker

组件说明

xtf-picker 是滚轮选择器,适用于日期、时段和级联地区选择。支持弹窗、常驻、静态多列、级联、循环滚动与 pickerManager 服务模式。


基础用法

1. 单列弹窗

vue
<template>
  <xtf-picker v-model="value" label="优先级" :columns="columns" @confirm="confirm" />
</template>
<script>
export default {
  data() {
    return {
      value: 'normal',
      columns: [
        { label: '普通', value: 'normal' },
        { label: '紧急', value: 'urgent' }
      ]
    }
  },
  methods: {
    confirm(p) {
      console.log(p.value)
    }
  }
}
</script>

2. 多列常驻

vue
<template>
  <xtf-picker
    v-model="date"
    mode="inline"
    :columns="columns"
    :column-titles="['年', '月']"
    @change="changed"
  />
</template>
<script>
export default {
  data() {
    return {
      date: [2026, 8],
      columns: [
        [{ label: '2026年', value: 2026 }],
        [
          { label: '8月', value: 8 },
          { label: '9月', value: 9 }
        ]
      ]
    }
  },
  methods: {
    changed(v) {
      console.log(v)
    }
  }
}
</script>

3. 级联与循环

vue
<template>
  <xtf-picker
    v-model="area"
    mode="inline"
    :columns="areas"
    :column-titles="['区域', '城市']"
    loop
    theme-preset="aurora"
  />
</template>
<script>
export default {
  data() {
    return {
      area: ['east', 'sh'],
      areas: [{ label: '华东', value: 'east', children: [{ label: '上海', value: 'sh' }] }]
    }
  }
}
</script>

全部属性

属性类型默认值作用描述适用范围
serviceBooleanfalse作为 pickerManager 服务宿主页面挂载一个
valueString | Number | Boolean | Array''当前值v-model
modeString'popup'popup/inline展示模式
label / placeholder / titleString''字段、占位、面板标题文案
displayMode / themePresetString'flat'/'default'flat/layered/spread/spotlight/carousel/ticker、主题预设视觉
columnsArray[]单列、多列或级联数据见下表
valueKey / labelKey / childrenKeyString'value'/'label'/'children'数据字段映射自定义数据
columnTitles / columnWidths / columnGapArray/Array | String/String | Number[]/[]/16列标题、宽度与列间距;间距数字按 rpx 处理多列
columnHeight / wheelItemHeight / overscanCount / wheelPerspective / wheelCurveString | Number400/88/6/1000/1滚轮尺寸、缓冲、透视和曲率滚轮效果
motionActiveScale / motionScaleMin / motionOpacityMin / motionOpacityStep / motionOffsetStep / motionBlurStep / motionTransitionDurationString | Number1/0.985/0.38/0.22/0/0/90选项动效参数视觉微调
snapDuration / momentumThreshold / cascadeDelayString | Number180/1.1/34吸附、惯性、级联延迟手感
loop / showPreviewPath / validateOnInitBooleanfalse/true/true循环、预览、初始校验行为
separator / previewLabelString' / '/'当前选择'路径分隔和标签预览
displayFormatterFunctionnull({labels,value,path,options})=>String自定义回显
size / disabled / required / messageString/Boolean/Boolean/String''/false/false/''字段状态表单
confirmText / cancelText / confirmHint / emptyTextString''面板文案文案
popupLayoutString'default'弹窗布局:default 标准标题与操作,system 居中标题、关闭图标及底部双操作滚轮弹窗
popupCustomClass / wheelCustomClass / columnCustomClass / frameCustomClass / optionCustomClass / activeOptionCustomClassString''局部类名样式
popupCustomStyle / wheelCustomStyle / columnCustomStyle / columnHeadStyle / frameCustomStyle / optionCustomStyle / activeOptionCustomStyle / optionTextStyle / activeOptionTextStyle / maskTopStyle / maskBottomStyle / customStyleString | Object''局部样式样式
customClassString''根字段类名样式

columns 节点字段

字段类型默认值说明
value / labelAny/String-值和显示文本
childrenArray[]级联子节点
disabledBooleanfalse禁止选择

事件

事件名称触发时机回调参数参数说明
input / change选择值提交或 inline 改变(value)单值或路径数组
confirm弹窗确认({ value,path,labels,options })完整选择结果
cancel取消或遮罩关闭({ source,value,path,labels,options })取消结果
update:selectedinline 滚轮更新({ source,value,path,labels,options })当前选择详情
update:validated初始/数据变更后校正值({ source,value })校正结果

事件使用示例

vue
<template>
  <xtf-picker v-model="value" :columns="columns" @confirm="confirm" @cancel="cancel" />
</template>
<script>
export default {
  data() {
    return { value: 'a', columns: [{ label: 'A', value: 'a' }] }
  },
  methods: {
    confirm(p) {
      console.log(p.labels)
    },
    cancel(p) {
      console.log(p.source)
    }
  }
}
</script>

方法

1. open(options) / close() - 控制实例弹窗

非服务模式下,open(options) 会忽略 options 并打开当前实例;服务模式下会将 options 交给 pickerManager

js
this.$refs.picker.open()
this.$refs.picker.close()

2. pickerManager.popup(options) - 服务模式弹出

需在页面放置 <xtf-picker service />

js
import { pickerManager } from '@/uni_modules/xtf-linkui'
pickerManager
  .popup({ title: '选择时段', columns: [{ label: '上午', value: 'am' }] })
  .then((payload) => console.log(payload.value))

插槽

组件源码未声明插槽;弹窗、滚轮列、选项和遮罩的定制均通过对应 *CustomClass*CustomStyle 属性完成。


主题说明

  • 字段使用 --xtf-input-bg--xtf-input-border--xtf-input-placeholder
  • 文本继承 --xtf-color-text,必填标记使用 --xtf-color-danger
  • default/slate/aurora/sunrise 为组件内置滚轮主题预设。

如需全局调整主题,请在 xtf-config-provider 或主题配置中覆盖相关变量。

MIT Licensed