Skip to content
本页导读

Colorpicker

组件类型:UxColorpickerComponentPublicInstance

支持单色、渐变色、透明度

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
valueString值(rgba(255,0,0,1))
colorsArray预设颜色值
titleString标题
titleColorString$ux.Conf.titleColor标题颜色
sizeAny$ux.Conf.fontSize内容大小
colorString$ux.Conf.fontColor内容颜色
darkColorString深色none-不显示,auto-自动适配深色模式,其他-颜色
confirmString确定确定文字
confirmColorString$ux.Conf.primaryColor确定文字颜色
btnSizeAny$ux.Conf.fontSize按钮大小
btnTypeStringnormal按钮类型
btnPositonStringbottom按钮位置
radiusAny$ux.Conf.radius圆角
opacityNumber$ux.Conf.maskAlpha遮罩透明度0-1
touchableBooleanfalse允许滑动关闭
maskCloseBooleantrue遮罩层关闭
disabledBooleanfalse是否禁用

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>