天天看點

uni-app 21公共搜尋頁開發

不廢話,直接上圖
uni-app 21公共搜尋頁開發
下圖是代碼

search.nvue

<template>
	<view class="page">
		<!-- 導航欄 -->
		<free-nav-bar title="我的收藏" showBack :showRight="false">
			<input type="text" value="" placeholder="請輸入關鍵字" style="width: 650rpx;" class="font-md" />
		</free-nav-bar>
		
		<view class="py-3 flex align-center justify-center">
			<text class="font text-light-muted">搜尋指定内容</text>
		</view>
		
		<view class="px-4 flex flex-wrap">
			<view class="flex align-center justify-center mb-3" style="width: 223rpx;" v-for="(item,index) in typeList" :key="index">
				<text class="font text-hover-primary">{{item.name}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
	export default {
		components:{
			freeNavBar
		},
		data() {
			return {
				typeList:[{
					name:'聊天記錄',
					key:'history'
				},
				{
					name:'使用者',
					key:'user'
				},
				{
					name:'群聊',
					key:'group'
				}]
			}
		},
		methods: {
			
		}
	}
</script>

<style>

</style>

           
使用的插件
// free-nav-bar.vue
<template>
	<view>
		<view :class="getClass">
			<!-- 狀态欄 -->
			<view :style="'height:'+statusBarHeight+'px;'"></view>
			<!-- 導航 -->
			<view class="w-100 flex align-center justify-between" style="height: 90rpx;">
				<!-- 左邊 -->
				<view class="flex align-center">
					<!-- 傳回按鈕 -->
					<free-icon-button v-if="showBack" @click="back"><text class="iconfont font-md">&#xe60d;</text></free-icon-button>
					<!-- 标題 -->
					<slot>
					<text v-if="title" class="font-md ml-3" >{{getTitle}}</text>
					</slot>
				</view>
				<!-- 右邊 -->
				<view class="flex align-center" v-if="showRight">
					<slot name="right">
						<free-icon-button @click="search"><text class="iconfont font-md">&#xe6e3;</text></free-icon-button>
						<free-icon-button @click="openExtend"><text class="iconfont font-md">&#xe682;</text></free-icon-button>
					</slot>
				</view>
				<!--\ue6e3 \ue682 -->
			</view>
		</view>

		<!-- 站位 -->
		<view v-if="fixed" :style="fixedStyle"></view>
		
		<!-- 擴充菜單  -->
		<free-popup v-if="showRight" ref="extend" maskColor bottom :bodyWidth="320" :bodyHeight="525" bodyBgColor="bg-dark" transformOrigin="right top">
			<view class="flex flex-column" style="width:320rpx;height: 525rpx;">
					<view v-for="(item,index) in menus" :key="index" class="flex-1 flex align-center" hover-class="bg-hover-dark" @click="clickEvent(item.event)">
						<text class="pl-3 pr-2 iconfont font-md text-white">{{item.icon}}</text>
						<text class="font-md text-white">{{item.name}}</text>
					</view>
			</view>
		</free-popup>
	</view>
</template>

<script>
	import freeIconButton from './free-icon-button.vue';
	import freePopup from './free-popup.vue';
	export default {
		components: {
			freeIconButton,
			freePopup
		},
		props: {
			showBack:{
				type:Boolean,
				default:false
			},
			title: {
				type: String,
				default: ''
			},
			fixed:{
				type:Boolean,
				default:false
			},
			noreadnum:{
				type:Number,
				default:0
			},
			bgColor:{
				type:String,
				default:"bg-light"
			},
			showRight:{
				type:Boolean,
				default:true
			}
		},
		data() {
			return {
				statusBarHeight: 0,
				navBarHeight: 0,
				menus:[
					{
						name:'發起群聊',
						event:"",
						icon:"\ue633"
					},
					{
						name:'添加好友',
						event:"",
						icon:"\ue65d"
					},
					{
						name:'掃一掃',
						event:"",
						icon:"\ue614"
					},
					{
						name:'收付款',
						event:"",
						icon:"\ue66c"
					},
					{
						name:'幫助與回報',
						event:"",
						icon:"\ue61c"
					}
				],
			}
		},
		mounted() {
			// 擷取工作列高度
			// #ifdef APP-PLUS-NVUE
			this.statusBarHeight = plus.navigator.getStatusbarHeight()
			// #endif
			this.navBarHeight = this.statusBarHeight + uni.upx2px(90)
		},
		computed: {
			fixedStyle() {
				return `height:${this.navBarHeight}px`;
			},
			getTitle(){
				let noreadnum = this.noreadnum>0 ? '('+this.noreadnum+')' : '';
				return this.title + noreadnum;
			},
			getClass(){
				let fixed = this.fixed?"fixed-top":"";
				return `${fixed} ${this.bgColor}`;
			}
		},
		methods:{
			openExtend(){
				this.$refs.extend.show(uni.upx2px(415),uni.upx2px(150));
			},
			// 傳回
			back(){
				uni.navigateBack({
					delta:1
				})
			},
			search(){
				uni.navigateTo({
					url:'/pages/common/search/search'
				})
			}
		}
	}
</script>

<style>

</style>

           

感謝大家觀看,我們下期見

繼續閱讀