Flex:Label手型光标

本文介绍如何在Flex中为Label元素设置手型光标效果,通过三步操作即可实现:设置useHandCursor属性为true,mouseChildren属性为false,buttonMode属性为true。

在flex中,要让一个label应用手型光标如下:

 

label.useHandCursor = true;

label.mouseChildren = false;

label.buttonMode = true;

帮我添加注释<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>调查表单</title> <script src="js/vue.js"></script> <style> #user-from{ max-width: 600px; margin: 20px auto; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); border-radius: 8px; } .from-group{ margin-bottom: 15px; } label{ display: block; margin-bottom: 5px; font-weight: 500; } .form-control{ width: 100%; padding: 8px 12px; border: 1px solid #ddd; } .radio-group, .checkbox-group{ display: flex; gap: 15px; } .radio-group label, .checkbox-group label{ display: flex; align-items: center; gap:5px; } .submit-btn{ background-color: #42b983; color: white; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 16px; } .submit-btn:disabled{ background-color: #cccccc; cursor: not-allowed; } .data-preview{ margin-top: 20px; padding: 15px; background-color: #f5f5f5; border-radius: 4px; } pre{ white-space: pre-wrap; word-wrap: break-word; } </style> </head> <body> <div id="user-from"> <h2>用户信息调查</h2> <form @submit.prevent="handleSubmit"> <div class="from-group"> <label>姓名:</label> <input type="text" v-model="userInfo.name" placeholder="请输入姓名" class="form-control"> </div> <div class="from-group"> <label>个人简介:</label> <textarea v-model="userInfo.bio" placeholder="请输入个人简介" class="form-control" rows="3"></textarea> </div> <div class="from-group"> <label>性别</label> <div class="radio-group"> <label> <input type="radio" value="male" v-model="userInfo.gender"> 男 </label> <label> <input type="radio" value="female" v-model="userInfo.gender"> 女 </label> </div> </div> <div class="from-group"> <label> <input type="checkbox" v-model="userInfo.agreeTerms" > 我已阅读并同意用户协议 </label> </div> <div class="from-group"> <label>兴趣爱好:</label> <div class="checkbox-group"> <label> <input type="checkbox" value="reading" v-model="userInfo.hobbies"/>阅读 </label><label for=""> <input type="checkbox" value="sports" v-model="userInfo.hobbies"/>运动 </label><label for=""> <input type="checkbox" value="coding" v-model="userInfo.hobbies"/>编程 </label><label for=""> <input type="checkbox" value="music" v-model="userInfo.hobbies"/>音乐 </label> </div> </div> <div class="from-group"> <label>职业:</label> <select v-model="userInfo.occupation" class="form-control"> <option value="">请选择职业</option> <option value="student">学生</option> <option value="teacher">教师</option> <option value="engineer">工程师</option> <option value="doctor">医生</option> <option value="other">其他</option> </select> </div> <button type="submit" class="submit-btn" :disabled= "!userInfo.agreeTerms">提交</button> </form> <div class="data-preview"> <h3>当前表单数据:</h3> <pre>{{userInfo}}</pre> </div> </div> <script> const app=new Vue({ el:"#user-from", data:{ userInfo:{ name:'', bio:'', gender:'male', agreeTerms: false, hobbies:[], occupation:'' } }, methods:{ handleSubmit(){ alert('表单提交成功 \n ' +JSON.stringify(this.userInfo,null,2)); } } }) </script> </body> </html>
09-27
<template> <view class="container"> <!-- 登录区域 --> <view v-if="!isLoggedIn" class="login-box"> <view class="login-title">投诉后台管理登录</view> <input v-model="loginForm.username" placeholder="请输入账号" class="login-input" /> <input v-model="loginForm.password" placeholder="请输入密码" type="password" class="login-input" /> <button @click="login" class="login-button">登录</button> <button @click="goToHome" class="home-button">返回首页</button> <text v-if="loginError" class="login-error">{{ loginError }}</text> </view> <!-- 投诉列表区域 --> <view v-else class="complaint-container"> <view class="back-home" @click="goToHome"> <text class="icon">←</text> <text>返回首页</text> </view> <view class="search-bar"> <input v-model="searchForm.category" placeholder="请输入投诉类别" /> <input v-model="searchForm.keyword" placeholder="请输入关键词" /> <view class="dropdown"> <picker mode="selector" :range="statusOptions" range-key="label" :value="searchForm.statusIndex" @change="handleStatusPickerChange"> <view class="dropdown-trigger"> <text>{{ statusOptions[searchForm.statusIndex].label }}</text> <text class="arrow">▼</text> </view> </picker> </view> <button @click="searchComplaints">搜索</button> </view> <view class="complaint-list"> <view class="complaint-item" v-for="item in complaints" :key="item.id"> <view class="title">{{ item.title }}</view> <view class="category">类别:{{ item.category }}</view> <view class="status-container"> <text class="status-label">状态:</text> <picker mode="selector" :range="statusOptions" range-key="label" :value="item.statusIndex" @change="changeStatus($event, item)"> <view :class="['picker-button', getStatusClass(item.statusLabel)]"> <text>{{ item.statusLabel }}</text> </view> </picker> </view> </view> </view> </view> </view> </template> <script setup> import { ref, onMounted } from 'vue'; // 登录相关 const isLoggedIn = ref(false); const loginForm = ref({ username: '', password: '' }); const loginError = ref(''); // 页面加载时检查缓存 onMounted(() => { const cachedLogin = uni.getStorageSync('loginInfo'); if (cachedLogin) { isLoggedIn.value = true; loginForm.value.username = cachedLogin.username; loginForm.value.password = cachedLogin.password; fetchComplaints(); } }); // 返回首页 const goToHome = () => { try { const pages = getCurrentPages(); if (pages.length > 1) { uni.navigateBack(); } else { uni.reLaunch({ url: '/pages/index/index' }); } } catch (error) { uni.reLaunch({ url: '/pages/index/index' }); } }; // 搜索相关 const searchForm = ref({ category: '', keyword: '', statusIndex: 0 // 默认选中“待处理” }); // 投诉列表 const complaints = ref([]); // 状态选择器事件 const handleStatusPickerChange = (event) => { const index = event.detail.value; searchForm.value.statusIndex = index; }; // 状态选项 const statusOptions = ref([ { label: '待处理', value: 0 }, { label: '处理中', value: 1 }, { label: '已完成', value: 2 } ]); //状态颜色 const getStatusClass = (statusLabel) => { if (statusLabel === '待处理') return 'status-pending'; if (statusLabel === '处理中') return 'status-processing'; if (statusLabel === '已完成') return 'status-completed'; return ''; }; // 模拟登录接口 const login = async () => { uni.showLoading({ title: '登录中' }); // 模拟请求接口 setTimeout(() => { if (loginForm.value.username === '' && loginForm.value.password === '') { // 缓存登录信息 uni.setStorageSync('loginInfo', { username: loginForm.value.username, password: loginForm.value.password }); isLoggedIn.value = true; loginError.value = ''; fetchComplaints(); // 登录成功后加载投诉列表 } else { loginError.value = '账号或密码错误'; } uni.hideLoading(); }, 500); }; // 获取投诉列表(模拟) const fetchComplaints = async () => { uni.showLoading({ title: '加载中' }); // 模拟从后台获取数据 setTimeout(() => { complaints.value = [ { id: 1, title: '关于食堂卫生问题的投诉', category: '后勤管理', content: '食堂卫生不达标,影响员工健康', status: 0, statusLabel: '待处理', statusIndex: 0 }, { id: 2, title: '关于办公室空调噪音大', category: '设备问题', content: '空调运行噪音大,影响办公', status: 1, statusLabel: '处理中', statusIndex: 1 } ]; uni.hideLoading(); }, 500); }; // 搜索投诉 const searchComplaints = async () => { uni.showLoading({ title: '搜索中' }); setTimeout(() => { let filtered = complaints.value; // 按类别过滤 if (searchForm.value.category) { filtered = filtered.filter(item => item.category.includes(searchForm.value.category)); } // 按关键词过滤 if (searchForm.value.keyword) { filtered = filtered.filter(item => item.content.includes(searchForm.value.keyword)); } // 按状态过滤 const selectedStatusValue = statusOptions.value[searchForm.value.statusIndex].value; if (selectedStatusValue !== '') { filtered = filtered.filter(item => item.status === selectedStatusValue); } complaints.value = filtered; uni.hideLoading(); }, 300); }; // 状态变更 const changeStatus = async (event, item) => { const index = event.detail.value; const newStatus = statusOptions.value[index].value; item.status = newStatus; item.statusLabel = statusOptions.value[index].label; item.statusIndex = index; // 模拟提交到后台 await updateStatusToServer(item); uni.showToast({ title: '状态已更新' }); }; // 模拟提交到后台 const updateStatusToServer = async (item) => { return new Promise(resolve => { setTimeout(() => { resolve(); }, 300); }); }; </script> <style scoped> .container { padding: 30rpx; background-color: #f9f9f9; } .home-button { background-color: #f0f0f0; color: #333; margin-top: 20rpx; } .back-home { display: flex; align-items: center; font-size: 30rpx; color: #007AFF; padding: 10rpx 20rpx; border-radius: 8rpx; background-color: #f5f5f5; width: fit-content; /* 根据内容自适应宽度 */ cursor: pointer; /* PC端显示光标 */ margin-bottom: 20rpx; /* 增加底部间距 */ } .back-home .icon { margin-right: 10rpx; font-weight: bold; } .login-box { background-color: #fff; padding: 40rpx; border-radius: 16rpx; box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1); } .login-title { font-size: 36rpx; font-weight: bold; text-align: center; margin-bottom: 40rpx; color: #333; } .login-input { border: 1rpx solid #ccc; padding: 20rpx; margin-bottom: 30rpx; border-radius: 8rpx; width: 100%; } .login-button { background-color: #007AFF; color: white; } .login-error { color: red; font-size: 24rpx; margin-top: 10rpx; display: block; } .search-bar input { border: 1rpx solid #ccc; padding: 20rpx; margin-bottom: 20rpx; border-radius: 8rpx; } .complaint-list { margin-top: 30rpx; } .complaint-item { background-color: #fff; padding: 30rpx; margin-bottom: 30rpx; border-radius: 12rpx; box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.1); } .title { font-size: 32rpx; font-weight: bold; color: #333; margin-bottom: 20rpx; } .category { font-size: 28rpx; color: #666; margin-bottom: 20rpx; } .status { font-size: 28rpx; color: #999; } .status-container { display: flex; align-items: center; } .status-label { font-size: 28rpx; color: #999; } .picker-button { padding: 10rpx 20rpx; border-radius: 8rpx; font-size: 28rpx; color: white; } .status-pending { background-color: #ff9900; /* 橙色 */ } .status-processing { background-color: #007AFF; /* 蓝色 */ } .status-completed { background-color: #00cc66; /* 绿色 */ } /* 下拉选择器样式 */ .dropdown { position: relative; width: 100%; margin-bottom: 20rpx; } .dropdown-trigger { background-color: #f0f0f0; padding: 20rpx; border-radius: 8rpx; display: flex; justify-content: space-between; align-items: center; font-size: 28rpx; color: #333; } .dropdown-trigger .arrow { font-size: 24rpx; color: #999; } </style> 我想要去掉登录缓存功能
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值