Skip to content

搜索栏 xSearch


在线预览
在线模拟尺寸:

介绍

可定制化强

平台兼容

H5andriodIOS小程序UTSUNIAPP-X SDKversion
☑️☑️☑️☑️4.44+1.1.9

文件路径

ts

@/uni_modules/tmx-ui/components/x-search/x-search.uvue

使用

ts

<x-search></x-search>

Props 属性

名称说明类型默认值
round输入框圆角string"8"
showClear是否显示清除图标booleantrue
modelValue双向绑定的输入值string""
placeholder输入框提示语string""
iconColor搜索图标和清除图标的颜色string"#bfbfbf"
color搜索条背景string"#ffffff"
cancelFontColor取消的文本色string"#000000"
darkColor暗黑模式下的搜索条背景,空值取:sheetDarkColorstring""
inputBgColor输入框的背景string"#f5f5f5"
fontColor输入框的字体颜色string"#333333"
border边框style请输入规范的css<br>格式:1px,solid,red<br>默认空值,表示不设置边string[]() : string[] => [] as string[]
darkBorderColor边框style请输入规范的css<br>如:red,暗黑变换时,如果你设定了border,但没有设定本值,将会自动取全局的边线颜色。<br>默认空值,表示不设置边string""
placeholderStyle输入框的提示样式string""

Events 事件

名称参数说明
cancel-取消时触发
clear-清空时触发
rightClick**** : string点击右侧文本时触发,如果你使用了插槽替换了,此事件不会触发
confirm**** : string输入法点了确认搜索按钮时触发
input**** : string输入时触发
update:modelValue-等同v-model

Slots 插槽

名称说明数据
left左插槽-
inputLeft--
inputRight--
cacel--
right--

Ref 方法

名称参数返回值说明

示例文件路径

json

/pages/index/search

示例源码

uvue
vue
<template>
	<!-- #ifdef MP-WEIXIN -->
	<page-meta :page-style="`background-color:${xThemeConfigBgColor}`">
		<navigation-bar :background-color="xThemeConfigNavBgColor"
			:front-color="xThemeConfigNavFontColor"></navigation-bar>
	</page-meta>
	<!-- #endif -->
	<view style="flex:1;display: flex;flex-direction: column;">

		<x-input class="mx-14 mb-14" @input="searchWordList" v-model="word" color="white" left-icon="search-2-line" placeholder="输入关联组件名或者英文名"></x-input>
		
		<!-- #ifdef MP -->
		<view style="flex:1;display: flex;flex-direction: column;position: relative;margin:0 16px;">
		<!-- #endif -->
		<list-view class="flex-1"
		<!-- #ifdef MP -->
		style="position: absolute;height: 100%;width:100%"
		<!-- #endif -->
		<!-- #ifndef MP -->
		style="margin:0 16px;"
		<!-- #endif -->
		>
			<list-item v-for="(item,index) in list" :key="index">
				<navigator :url="item.url" class="lsitCell flex flex-row flex-row-center-between" :style="{backgroundColor: listBgcColor}">
					<text :style="{color:textcColor}">{{item.title}}</text>
				</navigator>
			</list-item>
			
			<list-item>
				<x-empty title="没组件,换个词" :showBtn="false" :empty="true" :loading="false" :error="false" v-if="list.length==0"></x-empty>
			</list-item>
		</list-view>
		<!-- #ifdef MP -->
		</view>
		<!-- #endif -->

	</view>

</template>

<script setup lang="uts">
	import { listdata, type INDEXITEMINFO_AR,INDEXITEMINFO } from "./index.uts"
	import { xStore, xDate } from "@/uni_modules/tmx-ui/index.uts"
	const word = ref('')
	const list = ref<INDEXITEMINFO[]>([])
	let tid = 2232
	const listBgcColor = computed(():string=>{
		return xStore.xConfig.dark == 'dark'?xStore.xConfig.sheetDarkColor:'#ffffff'
	})
	const textcColor = computed(():string=>{
		return xStore.xConfig.dark == 'dark'?'#fff':'#333'
	})
	
	const searchWordList = (value:string)=>{
		if(value.trim()==''){
			list.value = [] as INDEXITEMINFO[]
			return
		}
		clearTimeout(tid)
		let temvalue = value.toLowerCase()
		tid = setTimeout(function() {
			let listtem = [] as INDEXITEMINFO[];
			for(let i=0;i<listdata.length;i++){
				let children = listdata[i].children;
				for(let j=0;j<children.length;j++){
					let item = children[j];
					let title = item.title.toLowerCase();
					let pagename = item.url.split('/').pop()!.toLowerCase()
					if(title.indexOf(temvalue)>-1||pagename.indexOf(temvalue)>-1){
						listtem.push(item)
					}
				}
			}
			list.value = [...listtem]
		}, 350);
	}
	onLoad((obj:OnLoadOptions)=>{
		let tempWord = obj['word'] ?? ""
		searchWordList(tempWord)
		word.value = tempWord
	})
	onBeforeUnmount(()=>{
		clearTimeout(tid)
	})
</script>

<style >
	/* #ifdef MP */
	page,body{
		height:100vh;
		display: flex;
		flex-direction: column;
	}
	/* #endif */
	.lsitCell{
		height: 50px;
		padding: 0 16px;
		margin-bottom: 1px;
		/* #ifndef APP */
		box-szing:border-box;
		/* #endif */
	}
</style>
最近更新