Colorpicker
组件类型:UxColorpickerComponentPublicInstance
支持单色、渐变色、透明度
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
value | String | 值(rgba(255,0,0,1)) | |
colors | Array | 预设颜色值 | |
title | String | 标题 | |
titleColor | String | $ux.Conf.titleColor | 标题颜色 |
size | Any | $ux.Conf.fontSize | 内容大小 |
color | String | $ux.Conf.fontColor | 内容颜色 |
darkColor | String | 深色none-不显示,auto-自动适配深色模式,其他-颜色 | |
confirm | String | 确定 | 确定文字 |
confirmColor | String | $ux.Conf.primaryColor | 确定文字颜色 |
btnSize | Any | $ux.Conf.fontSize | 按钮大小 |
btnType | String | normal | 按钮类型 |
btnPositon | String | bottom | 按钮位置 |
radius | Any | $ux.Conf.radius | 圆角 |
opacity | Number | $ux.Conf.maskAlpha | 遮罩透明度0-1 |
touchable | Boolean | false | 允许滑动关闭 |
maskClose | Boolean | true | 遮罩层关闭 |
disabled | Boolean | false | 是否禁用 |
darkColor
值 | 说明 |
---|---|
none不显示 | |
auto自动适配深色模式 | |
color其他颜色 |
btnType
值 | 说明 |
---|---|
normal正常 | |
bigger大按钮 |
btnPositon
值 | 说明 |
---|---|
top顶部按钮 | |
bottom底部按钮 |
touchable
值 | 说明 |
---|---|
true | |
false |
maskClose
值 | 说明 |
---|---|
true | |
false |
Events
事件名 | 说明 | 参数 |
---|---|---|
change | 确定选择时触发 | |
changing | 选择时触发 | |
close | 关闭时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="颜色选择器" :bold="true">
<ux-text text="支持单色快速选择"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单色" :bold="true">
<ux-colorpicker v-model="color" btnPositon="bottom" @changing="changing">
<view class="color" :style="{'background-color': color}"></view>
</ux-colorpicker>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :bold="true">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="颜色选择器" :bold="true">
<ux-text text="支持单色快速选择"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="单色" :bold="true">
<ux-colorpicker v-model="color" btnPositon="bottom" @changing="changing">
<view class="color" :style="{'background-color': color}"></view>
</ux-colorpicker>
</ux-card>
<ux-placeholder :height="200">
<ux-row justify="center" align="center" style="height: 100%;">
<ux-text prefix-icon="soapbubble-filled" text="真的没有了~"></ux-text>
</ux-row>
</ux-placeholder>
</ux-scroll>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const color = ref('#3c9cff')
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/colorpicker.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function changing(_color : string) {
color.value = _color
}
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const color = ref('#3c9cff')
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/colorpicker.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e) => {
title.value = e['title'] ?? ''
})
function changing(_color : string) {
color.value = _color
}
</script>
css
<style lang="scss">
.color {
/* #ifdef WEB */
cursor: pointer;
/* #endif */
width: 100%;
height: 40px;
border-radius: 10px;
background-color: #3c9cff;
}
</style>
<style lang="scss">
.color {
/* #ifdef WEB */
cursor: pointer;
/* #endif */
width: 100%;
height: 40px;
border-radius: 10px;
background-color: #3c9cff;
}
</style>