活动介绍

.main-text { padding: 12rpx; font-size: 15px; height: 70rpx; overflow: hidden; text-overflow: ellipsis; -webkit-line-clamp: 2; } 不显示省略号

时间: 2024-04-08 10:28:37 浏览: 170
要让省略号显示出来,你可以添加以下的 CSS 样式: ```css .main-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } ``` 这样设置后,如果文本内容超出了容器的宽度,就会显示省略号。
相关问题

详细解读.bg{ width: 100%; height: 30rpx; background-color: #edecf2; } .horizon{ display: flex; flex-direction: row; } .vertical{ display: flex; flex-direction: column; } .firstrow{ width: 100%; height: 100rpx; align-items: center; } .left{ margin-left: 40rpx; } .right{ margin-right: 20rpx; } .top{ margin-top: 30rpx; } .icon{ width: 40rpx; height: 40rpx; } .input{ margin-left: 30rpx; font-size: 32rpx; color: gray; flex-grow: 1; } .line{ width: 100%; height: 3rpx; background-color: #edecf2; } .picker{ margin-left: 30rpx; width: 100rpx; height: 100%; font-size: 32rpx; color: #222; } .arrow{ width: 10rpx; height: 10rpx; border: 4rpx solid #333; border-bottom: none; border-left: none; transform: rotate(135deg); } .icon-ValidCode{ width: 180rpx; height: 80rpx; margin-right: 20rpx; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; } .declare{ font-size: 30rpx; color: #666666; } /* 获取验证码 倒计时 按钮 如果设置宽高不生效的话,删除app.js里面的 "style": "v2",*/ .button{ width: 200rpx; height: 65rpx; color: #449f45; border: 3rpx solid #449f45; border-radius: 80rpx; font-size: 24rpx; margin-right: 20rpx; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; text-align: center; } /* 确定按钮 */ .sureBtn{ margin-top: 70rpx; margin-left: 40rpx; margin-right: 40rpx; }

这是一段CSS代码,用于设置网页界面的样式。其中包括了一些类名,如horizon、vertical、left、right、top、input等,用于控制元素的布局和样式。具体来说,horizon和vertical这两个类名用于设置元素的水平或垂直方向的排列方式,left和right用于设置元素的左侧或右侧的外边距,top用于设置元素的顶部外边距,input用于设置输入框的样式,包括字体大小、颜色和弹性增长等。此外,还有一些其他的类名,如icon、line、picker、arrow等,用于设置图标、分割线、选择器和箭头的样式。最后还有一些针对特定元素的类名,如icon-ValidCode和button,用于设置验证码图标和按钮的样式。总之,这段CSS代码的作用是为网页界面提供一定的美观和可读性。

<template> <view class="page-container"> <!-- 打开弹框的按钮 --> <!-- 遮罩层 --> <view class="mask" v-if="localShow" @click="hideDialog"></view> <!-- 弹框 --> <view class="dialog" :class="{ 'dialog-show': localShow }"> <view class="dialog-content"> <view class="dialog-header"> <text class="dialog-title">提示</text> <text class="close-icon" @click="hideDialog">×</text> </view> <!-- 内容区 --> <view > <text>申请提前结束考核,您的入职考核结束时间=申请审批通过的时间。考核结束后的已缴费订单将都不再计入考核结果,是否确认提前结束考核?</text> </view> <view class="sec"> <view class="inComeList" v-if="filteredActions"> <inComeItem v-for="(item, index) in filteredActions" :key="item.settleMonth" :lastDom="index == filteredActions.length - 1" :data="item" /> </view> <view class="button-group"> <button class="dialog-button" >取消</button> <button class="dialog-button">确认</button> </view> </view> </view> </view> </view> </template> <script> import inComeItem from "../inComeItem/index.vue"; export default { components: { inComeItem, }, props: { showDialog: { type: Boolean, default: false, }, showModel: { type: Boolean, default: false, }, }, watch: { showModel(newVal) { // 监听父组件数据变化 this.localShow = newVal; }, }, data() { return { localShow: this.showDialog, // 本地副本 // 返回假数据 filteredActions: [] }; }, created() { console.log("============onload===========", this.showDialog) }, onload() { console.log("============onload===========", this.showDialog) this.getConfirmApply(); }, methods: { async getConfirmApply(){ const { data } = await uni.$u.http.get("/app/staffAssess/getConfirmApply"); console.log("APP-查询提前结束审批信息",data) }, // 隐藏弹框 hideDialog() { this.localShow = false; this.$emit("update:show-model", false); // 通知父组件更新 }, }, }; </script> <style lang="scss" scoped> .page-container { padding: 20rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; background: #f3f5f8; } .mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 998; } .dialog { position: fixed; bottom: -100%; left: 0; width: 100%; height: calc(100% * 2 / 3); transition: bottom 0.3s ease; z-index: 999; display: flex; justify-content: center; align-items: flex-end; // bottom: 0; } .dialog-show { bottom: 0; } .dialog-content { background-color: #fff; width: 100%; height: 100%; border-top-left-radius: 10rpx; border-top-right-radius: 10rpx; padding: 30rpx; box-sizing: border-box; } .dialog-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20rpx; border-bottom: 1rpx solid #ccc; } .dialog-title { font-size: 32rpx; font-weight: normal; text-align: center; flex: 1; } .close-icon { font-size: 36rpx; cursor: pointer; } .radio-group { margin-top: 60rpx; } .radio-item { display: flex; align-items: center; margin-bottom: 10rpx; font-size: 28rpx; } .radio-item radio { transform: scale(0.6); } .audit-status { display: flex; justify-content: space-between; align-items: center; margin-top: 25rpx; padding: 15rpx; padding-top: 30rpx; background-color: rgba(245, 246, 249, 1); border-radius: 15rpx; } .status-label { font-size: 28rpx; } .status-value { display: flex; font-size: 28rpx; } .audit-text { color: #d01212; } .audit-date { color: #666; margin-top: 10rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; } .dialog-footer { padding-top: 20rpx; text-align: center; margin-top: 25rpx !important; } /deep/.next-button { width: 80%; padding: 10rpx; background-color: rgba(12, 195, 199, 1) !important; border: none !important; color: #fff !important; border-radius: 15rpx; font-size: 30rpx; } .titleName { margin-top: 40rpx; } .radioName { margin-top: 40rpx; } /* 添加按钮组样式 */ .button-group { display: flex; /* 使用 Flex 布局 */ justify-content: space-between; /* 按钮之间平均分配空间 */ margin-top: 40rpx; /* 顶部间距 */ gap: 20rpx; /* 按钮之间的间隙 */ } /* 按钮样式 */ .dialog-button { flex: 1; /* 每个按钮平分可用空间 */ height: 80rpx; line-height: 80rpx; background-color: rgba(12, 195, 199, 1); color: white; border-radius: 15rpx; font-size: 30rpx; border: none; } </style> <template> <view class="page-container"> <!-- 打开弹框的按钮 --> <!-- 遮罩层 --> <view class="mask" v-if="localShow" @click="hideDialog"></view> <!-- 弹框 --> <view class="dialog" :class="{ 'dialog-show': localShow }"> <view class="dialog-content"> <view class="dialog-header"> <text class="dialog-title">提示</text> <text class="close-icon" @click="hideDialog">×</text> </view> <!-- 内容区 --> <view > <text>申请提前结束考核,您的入职考核结束时间=申请审批通过的时间。考核结束后的已缴费订单将都不再计入考核结果,是否确认提前结束考核?</text> </view> <view class="sec"> <view class="inComeList" v-if="filteredActions"> <inComeItem v-for="(item, index) in filteredActions" :key="item.settleMonth" :lastDom="index == filteredActions.length - 1" :data="item" /> </view> <view class="button-group"> <button class="dialog-button" >取消</button> <button class="dialog-button">确认</button> </view> </view> </view> </view> </view> </template> <script> import inComeItem from "../inComeItem/index.vue"; export default { components: { inComeItem, }, props: { showDialog: { type: Boolean, default: false, }, showModel: { type: Boolean, default: false, }, }, watch: { showModel(newVal) { // 监听父组件数据变化 this.localShow = newVal; }, }, data() { return { localShow: this.showDialog, // 本地副本 // 返回假数据 filteredActions: [] }; }, created() { console.log("============onload===========", this.showDialog) }, onload() { console.log("============onload===========", this.showDialog) this.getConfirmApply(); }, methods: { async getConfirmApply(){ const { data } = await uni.$u.http.get("/app/staffAssess/getConfirmApply"); console.log("APP-查询提前结束审批信息",data) }, // 隐藏弹框 hideDialog() { this.localShow = false; this.$emit("update:show-model", false); // 通知父组件更新 }, }, }; </script> <style lang="scss" scoped> .page-container { padding: 20rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; background: #f3f5f8; } .mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 998; } .dialog { position: fixed; bottom: -100%; left: 0; width: 100%; height: calc(100% * 2 / 3); transition: bottom 0.3s ease; z-index: 999; display: flex; justify-content: center; align-items: flex-end; // bottom: 0; } .dialog-show { bottom: 0; } .dialog-content { background-color: #fff; width: 100%; height: 100%; border-top-left-radius: 10rpx; border-top-right-radius: 10rpx; padding: 30rpx; box-sizing: border-box; } .dialog-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20rpx; border-bottom: 1rpx solid #ccc; } .dialog-title { font-size: 32rpx; font-weight: normal; text-align: center; flex: 1; } .close-icon { font-size: 36rpx; cursor: pointer; } .radio-group { margin-top: 60rpx; } .radio-item { display: flex; align-items: center; margin-bottom: 10rpx; font-size: 28rpx; } .radio-item radio { transform: scale(0.6); } .audit-status { display: flex; justify-content: space-between; align-items: center; margin-top: 25rpx; padding: 15rpx; padding-top: 30rpx; background-color: rgba(245, 246, 249, 1); border-radius: 15rpx; } .status-label { font-size: 28rpx; } .status-value { display: flex; font-size: 28rpx; } .audit-text { color: #d01212; } .audit-date { color: #666; margin-top: 10rpx; font-family: "PingFangSC-Regular", "PingFang SC", sans-serif; font-weight: 400; font-style: normal; color: #0d0d0d; } .dialog-footer { padding-top: 20rpx; text-align: center; margin-top: 25rpx !important; } /deep/.next-button { width: 80%; padding: 10rpx; background-color: rgba(12, 195, 199, 1) !important; border: none !important; color: #fff !important; border-radius: 15rpx; font-size: 30rpx; } .titleName { margin-top: 40rpx; } .radioName { margin-top: 40rpx; } /* 添加按钮组样式 */ .button-group { display: flex; /* 使用 Flex 布局 */ justify-content: space-between; /* 按钮之间平均分配空间 */ margin-top: 40rpx; /* 顶部间距 */ gap: 20rpx; /* 按钮之间的间隙 */ } /* 按钮样式 */ .dialog-button { flex: 1; /* 每个按钮平分可用空间 */ height: 80rpx; line-height: 80rpx; background-color: rgba(12, 195, 199, 1); color: white; border-radius: 15rpx; font-size: 30rpx; border: none; } </style> onload为啥不执行

<think>我们正在讨论Vue组件中onLoad生命周期钩子未执行的问题。根据提供的引用,我们可以总结如下: 引用[1]提到:在自定义组件中,使用onLoad、onShow生命周期可能会失效。解决方案有两种: 1. 使用Vue的生命周期函数如created()或mounted()替换,但需要注意mounted可能存在延迟(需要切换组件再切换回来才能更新)。 2. 在子组件上添加ref,父组件在相应生命周期中通过ref调用子组件的方法(子组件将onLoad和onShow中的代码放到一个方法中,比如onLoadMethod,父组件在需要时调用这个方法)。 引用[2]展示了在main.js中通过Vue.mixin全局混入onLoad和onShow方法,这样每个组件都可以使用这些生命周期钩子。但这里需要注意的是,这通常是在uni-app等跨平台框架中的做法,因为标准的Vue.js并没有onLoad和onShow这样的生命周期钩子。 引用[3]和[4]则介绍了父子组件之间通信的方法,比如子组件通过$emit触发父组件的事件,或者通过全局事件总线进行通信。 现在,用户的问题是:为什么Vue组件中定义的onLoad方法没有被调用? 关键点: - 标准的Vue.js(包括Vue2和Vue3)并没有`onLoad`这个生命周期钩子。`onLoad`通常是在uni-app或微信小程序等框架中使用的生命周期钩子,表示页面加载时触发。 - 如果用户是在Vue.js项目中(非uni-app等框架)使用了`onLoad`,那么它不会被Vue识别,因此不会执行。 解决方案: 1. 确认项目环境:如果是标准的Vue项目(如使用vue-cli创建),则应该使用Vue自身的生命周期钩子(如created、mounted)。如果是uni-app项目,则可以使用onLoad,但需要注意组件的使用方式(如引用[1]所述,自定义组件中onLoad可能不会触发,需要使用其他方法)。 2. 如果是在uni-app中,自定义组件默认不会触发页面生命周期(如onLoad、onShow等)。因此,需要采用其他方法: - 方法一:使用Vue的生命周期钩子(created或mounted)代替,但注意在uni-app中,组件的created和mounted在页面onLoad之后才会触发,且页面跳转返回时不会再次触发(而onShow会触发)。 - 方法二:通过父组件(页面)调用子组件的方法(使用ref),在页面的onLoad中调用子组件的初始化方法(如引用[1]的第二种方案)。 - 方法三:使用uni-app的页面生命周期监听机制,例如在自定义组件内使用`uni.$on`监听事件,然后在页面的onLoad中触发事件,但这样需要组件和页面之间建立事件通信。 因此,用户的问题很可能是因为在自定义组件中使用了页面生命周期钩子,而自定义组件并不支持这些钩子(在uni-app中)或者是在标准Vue中使用了不存在的钩子。 具体回答步骤: 1. 指出问题:Vue组件中未调用onLoad方法的原因是因为Vue本身没有这个钩子(标准Vue项目)或者自定义组件不支持页面生命周期(uni-app项目)。 2. 根据项目环境给出解决方案: - 标准Vue项目:使用created或mounted代替。 - uni-app项目:按照引用[1]的解决方案,使用Vue的生命周期钩子或者通过父组件调用子组件方法。 3. 提供代码示例。 注意:根据用户的问题,我们无法确定是标准Vue项目还是uni-app项目,但引用中提到了uni-app,所以可以假设可能是uni-app环境。 下面组织回答:</think>### Vue 组件中 `onLoad` 生命周期钩子未调用的原因及解决方案 在 Vue 组件中,`onLoad` 生命周期钩子未被调用通常是由于 **环境兼容性问题** 或 **组件层级限制** 导致的。以下是具体原因和解决方案: --- ### 一、核心原因分析 1. **`onLoad` 不是 Vue 原生生命周期钩子** - `onLoad` 是 **uni-app/小程序框架** 特有的页面级生命周期钩子(如页面加载时触发),**不是 Vue 标准 API**。 - 在标准 Vue 组件中定义 `onLoad` 方法,Vue 不会自动识别和调用它[^1]。 2. **自定义组件不支持页面级钩子** - 在 uni-app 等跨平台框架中,`onLoad` 仅在**页面组件**中有效,**自定义子组件默认不会触发**该钩子[^1]。 3. **钩子注册方式错误** - 未通过全局混入(`Vue.mixin`)或框架规范注册钩子,导致 Vue 无法识别[^2]。 --- ### 二、解决方案 #### ✅ 方案 1:使用 Vue 原生钩子替代(推荐) 在自定义组件中,用 Vue 标准生命周期钩子替换 `onLoad`: ```javascript // 自定义子组件 export default { created() { // 替代 onLoad console.log("组件初始化完成,可访问数据"); this.loadData(); // 初始化数据 }, mounted() { // 替代 onShow console.log("DOM 已挂载,可操作元素"); }, methods: { loadData() { // 数据加载逻辑 } } } ``` **注意**: - `created` 在数据初始化后触发(类似 `onLoad`) - `mounted` 在 DOM 挂载后触发(类似页面显示) - 此方案在标准 Vue 和 uni-app 中均适用[^1][^4]。 --- #### ✅ 方案 2:父组件通过 `ref` 手动触发(uni-app 专用) 当子组件需要响应页面生命周期时: ```javascript // 子组件:定义初始化方法 export default { methods: { initOnLoad() { // 替代 onLoad 的逻辑 console.log("模拟 onLoad 执行"); this.loadData(); } } } // 父组件(页面级组件) <template> <child-component ref="childRef" /> </template> <script> export default { onLoad() { // 页面 onLoad 触发时调用子组件方法 this.$refs.childRef.initOnLoad(); } } </script> ``` **优势**: - 精确控制子组件初始化时机 - 兼容 uni-app 的页面生命周期[^1][^3]。 --- #### ✅ 方案 3:全局混入生命周期(uni-app 专用) 在 `main.js` 中扩展自定义组件的生命周期支持: ```javascript // main.js Vue.mixin({ onLoad() { // 全局逻辑(如路由解析) this._route = parseRoute(this.$root.$mp); // 若为自定义组件,调用其初始化方法 if (this.$options.methods?.initOnLoad) { this.initOnLoad(); } } }); // 子组件 export default { methods: { initOnLoad() { // 会被全局混入调用 console.log("全局混入触发 onLoad"); } } } ``` **适用场景**: - 需要统一管理多个组件的初始化逻辑[^2]。 --- ### 三、关键选择建议 | **场景** | **推荐方案** | **原因** | |--------------------------|-------------------|-----------------------------| | 标准 Vue 项目 | 方案 1(created) | 使用 Vue 原生 API,无兼容问题 | | uni-app 页面组件 | 直接使用 onLoad | 框架原生支持 | | uni-app 自定义子组件 | 方案 2(ref 调用)| 精准控制初始化时机 | | 多组件共享初始化逻辑 | 方案 3(全局混入)| 统一维护,减少重复代码 | > **避坑指南**: > - 避免在自定义组件中直接使用 `onLoad`,除非通过全局混入显式支持[^2]。 > - 在 `created` 中发起异步请求时,需配合 `v-if` 处理加载状态,防止操作未渲染的 DOM。 --- ### 总结 `onLoad` 未被调用的根本原因是**环境与组件层级的限制**。在标准 Vue 项目中应使用 `created/mounted` 替代;在 uni-app 自定义组件中,需通过 **父组件触发** 或 **全局混入** 实现类似功能。优先推荐使用 Vue 原生生命周期钩子,可最大程度保证代码兼容性和可维护性[^1][^2][^4]。
阅读全文

相关推荐

<template> <view :class="{ inComeItemWrap: true, lastDomWrap: lastDom }"> <view :class="{ dot: true, activeC: data.approveState == 1 }" /> <view class="time-status-container"> <view class="time-text">{{ formatDate(data.checkDate) }}</view> <view :class="['status-badge', status-${data.approveState}]"> {{ getStatusText(data.approveState) }} </view> </view> <view class="con"> <view class="conItem1"> <text class="label">失败原因</text> <text class="value">{{ data.remark }}</text> </view> </view> </view> </template> <script> export default { name: "inComeItem", props: { data: { type: Object, default: () => { return {}; }, }, lastDom: { type: Boolean, default: false, }, }, data() { return {}; }, methods: { formatMoney(amount) { return amount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") }, formatDate(dateStr) { return dateStr // 实际项目中可添加日期格式化逻辑 }, getStatusText(state) { const statusMap = { 0: '未提交', 1: '审批中', 2: '审批通过', 3: '审批失败' } return statusMap[state] || '' } } }; </script> <style lang="scss" scoped> .inComeItemWrap { position: relative; // margin-left: 20rpx; padding-top: 40rpx; padding-bottom: 36rpx; padding-left: 20rpx; border-left: 4rpx solid #05c4c8;; } .lastDomWrap { border-left: 1px dashed #f3f5f8; } .dot { position: absolute; left: -13rpx; top: 0; width: 20rpx; height: 20rpx; border-radius: 20rpx; background: #05c4c8; // 改为绿色背景 border-color: #05c4c8; // 改为绿色边框 } .time { position: absolute; left: 16rpx; top: -12rpx; font-size: 28rpx; color: #000; font-weight: bold; } .activeC { background: #05c4c8; } .con { padding-left: 30rpx; display: flex; .conItem1 { flex: 1; } .conItem2 { width: 60%; } .conItemT { margin-bottom: 4rpx; white-space: nowrap; color: #7c7c7c; font-size: 24rpx; } .conItemV { color: #000; font-weight: bold; font-size: 30rpx; } } .status1 { display: flex; align-content: center; align-items: center; font-weight: normal; font-size: 24rpx; padding: 0 8rpx; margin-left: 8rpx; color: #fff; background: #caa658; border-radius: 40rpx; } .status2 { display: flex; align-items: center; align-content: center; justify-content: center; font-weight: normal; padding: 0 12rpx; margin-left: 8rpx; background: #05c4c8; color: #fff; border-radius: 40upx; font-size: 24rpx; } .status3 { font-weight: normal; margin-left: 8rpx; position: relative; width: 204upx; /* 按钮宽度 */ height: 40upx; /* 按钮高度 */ border-radius: 40upx; /* 圆角 */ overflow: hidden; /* 隐藏超出边界的部分 */ } .status3::before, .status3::after { content: ""; position: absolute; width: 100%; height: 100%; } .statusText { display: flex; justify-content: center; align-items: center; position: absolute; left: 0; right: 0; top: 0; bottom: 0; text-align: center; font-size: 24rpx; z-index: 1; } /* 左侧颜色部分 */ .status3::before { background-color: #00d3d6; /* 青色 */ clip-path: polygon(0 0, 54% 0, 46% 100%, 0 100%); } /* 右侧颜色部分 */ .status3::after { background-color: #ffe6e6; /* 粉色 */ clip-path: polygon(54% 0, 100% 0, 100% 100%, 46% 100%); } .time-status-container { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24rpx; width: 100%; .time-text { font-size: 32rpx; color: #333;; font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .status-badge { font-size: 26rpx; height: 44rpx; line-height: 44rpx; border-radius: 44rpx; padding: 0 24rpx; margin-left: 20rpx; box-shadow: 0 4rpx 8rpx rgba(0,0,0,0.05); color: white; text-align: center; min-width: 120rpx; flex-shrink: 0; &.status-0 { background: linear-gradient(135deg, #caa658, darken(#caa658, 10%)); } &.status-1, &.status-2, &.status-3 { background: linear-gradient(135deg, #05c4c8, darken(#05c4c8, 10%)); } } } </style> 步骤条居中线正常链接

在原有的页面上添加 ,底部 已加载完毕 分割线 避免被购物车挡住 原有页面如下 : <template> <view class="shop-container"> <view class="fixed-header"> <view class="search-bar"> <uni-search-bar placeholder="搜索菜品" radius="100" @confirm="searchDish" @input="searchInput" cancelButton="none" /> </view> <scroll-view class="category-scroll" scroll-x="true"> <view v-for="(category, index) in categories" :key="index" class="category-item" :class="{ active: currentCategory === index }" @click="changeCategory(index)" > {{ category.name }} </view> </scroll-view> </view> <scroll-view class="dish-list" scroll-y="true"> <view v-for="(dish, index) in filteredDishes" :key="dish.id" class="dish-item"> <image class="dish-image" :src="dish.image" mode="aspectFill" /> <view class="dish-info"> <text class="dish-name">{{ dish.name }}</text> <text class="dish-price">¥{{ dish.price.toFixed(2) }}</text> <text class="dish-stock" :class="{ 'low-stock': dish.stock < 5 }"> 剩余: {{ dish.stock }}份 </text> </view> <view class="quantity-selector" v-if="cartItemQuantity(dish.id) > 0"> <button class="quantity-btn" @click="decreaseQuantity(dish)"> <uni-icons type="minus" size="16" color="#ff6b6b"></uni-icons> </button> <text class="quantity-text">{{ cartItemQuantity(dish.id) }}</text> <button class="quantity-btn" :disabled="cartItemQuantity(dish.id) >= dish.stock" @click="increaseQuantity(dish)" > <uni-icons type="plus" size="16" color="#ff6b6b"></uni-icons> </button> </view> <view class="add-btn-container" v-else> <button v-if="dish.stock > 0" class="add-btn" :disabled="dish.stock <= 0" @click="addToCart(dish)"> <uni-icons type="plusempty" size="20" color="#fff"></uni-icons> </button> <text v-if="dish.stock <= 0" class="sold-out-text">已售罄</text> </view> </view> </scroll-view> <view class="cart-bar" @click="showCartDetail"> <view class="cart-icon-container"> <uni-icons type="cart-filled" size="30" color="#fff"></uni-icons> <view v-if="cartItemCount > 0" class="cart-badge">{{ cartItemCount }}</view> </view> <text class="total-price">¥{{ totalPrice.toFixed(2) }}</text> <button class="checkout-btn" :disabled="cartItemCount === 0">去结算</button> </view> <uni-popup ref="cartPopup" type="bottom" :maskClick="false"> <view class="cart-detail"> <view class="cart-header"> <text class="cart-title">已选菜品</text> <uni-icons type="close" size="24" color="#999" @click="closeCartDetail"></uni-icons> </view> <scroll-view class="cart-list" scroll-y="true"> <view v-for="(item, index) in cart" :key="item.id" class="cart-item"> <image class="cart-item-image" :src="item.image" mode="aspectFill" /> <view class="cart-item-info"> <text class="cart-item-name">{{ item.name }}</text> <text class="cart-item-price">¥{{ item.price.toFixed(2) }}</text> </view> <view class="cart-item-quantity"> <button class="cart-quantity-btn" @click="decreaseCartQuantity(item)"> <uni-icons type="minus" size="16" color="#ff6b6b"></uni-icons> </button> <text class="cart-quantity-text">{{ item.quantity }}</text> <button class="cart-quantity-btn" :disabled="item.quantity >= item.stock" @click="increaseCartQuantity(item)" > <uni-icons type="plus" size="16" color="#ff6b6b"></uni-icons> </button> </view> </view> </scroll-view> <view class="cart-footer"> <text class="cart-total">总计: ¥{{ totalPrice.toFixed(2) }}</text> <button class="cart-checkout-btn" @click="checkout">去结算</button> </view> </view> </uni-popup> </view> </template> <script> export default { data() { return { currentCategory: 0, // 当前选中的分类索引 searchKeyword: '', // 搜索关键词 cart: [], // 购物车 // 菜品分类 categories: [ { id: 0, name: '全部' }, { id: 1, name: '热销' }, { id: 2, name: '主食' }, { id: 3, name: '汤类' }, { id: 4, name: '小吃' }, { id: 5, name: '饮品' } ], // 菜品数据 dishes: [ { id: 1, name: '鱼香肉丝', price: 38, stock: 15, image: '/static/images/dishes/1.jpeg', category: 1 }, { id: 2, name: '宫保鸡丁', price: 42, stock: 8, image: '/static/images/dishes/2.jpeg', category: 1 }, { id: 3, name: '麻婆豆腐', price: 28, stock: 0, image: '/static/images/dishes/3.jpg', category: 1 }, { id: 4, name: '扬州炒饭', price: 25, stock: 12, image: '/static/images/dishes/4.jpeg', category: 2 }, { id: 5, name: '番茄鸡蛋面', price: 22, stock: 20, image: '/static/images/dishes/4.jpeg', category: 2 }, { id: 6, name: '酸辣汤', price: 18, stock: 5, image: '/static/images/dishes/4.jpeg', category: 3 }, { id: 7, name: '春卷', price: 15, stock: 3, image: '/static/images/dishes/4.jpeg', category: 4 }, { id: 8, name: '冰镇酸梅汤', price: 12, stock: 25, image: '/static/images/dishes/dish08.jpg', category: 5 } ] } }, computed: { // 过滤后的菜品列表 filteredDishes() { let result = [...this.dishes]; // 按分类过滤 if (this.currentCategory > 0) { result = result.filter(dish => dish.category === this.currentCategory); } // 按关键词搜索 if (this.searchKeyword) { const keyword = this.searchKeyword.toLowerCase(); result = result.filter(dish => dish.name.toLowerCase().includes(keyword) ); } return result; }, // 购物车商品数量 cartItemCount() { return this.cart.reduce((total, item) => total + item.quantity, 0); }, // 总金额 totalPrice() { return this.cart.reduce((total, item) => total + (item.price * item.quantity), 0); } }, methods: { // 切换分类 changeCategory(index) { this.currentCategory = index; }, // 搜索输入 searchInput(e) { this.searchKeyword = e.value; }, // 搜索确认 searchDish(e) { this.searchKeyword = e.value; }, // 获取菜品在购物车中的数量 cartItemQuantity(dishId) { const item = this.cart.find(item => item.id === dishId); return item ? item.quantity : 0; }, // 添加到购物车 addToCart(dish) { if (dish.stock <= 0) return; // 检查是否已在购物车 const existingItem = this.cart.find(item => item.id === dish.id); if (existingItem) { // 如果已在购物车,增加数量 this.increaseQuantity(dish); } else { // 添加到购物车 this.cart.push({ ...dish, quantity: 1 }); } }, // 增加菜品数量 increaseQuantity(dish) { const item = this.cart.find(item => item.id === dish.id); if (item && item.quantity < dish.stock) { item.quantity++; } }, // 减少菜品数量 decreaseQuantity(dish) { const item = this.cart.find(item => item.id === dish.id); if (item) { if (item.quantity > 1) { item.quantity--; } else { // 数量为1时减少则移除 this.cart = this.cart.filter(cartItem => cartItem.id !== dish.id); } } }, // 增加购物车中菜品数量 increaseCartQuantity(item) { const dish = this.dishes.find(d => d.id === item.id); if (dish && item.quantity < dish.stock) { item.quantity++; } }, // 减少购物车中菜品数量 decreaseCartQuantity(item) { if (item.quantity > 1) { item.quantity--; } else { // 数量为1时减少则移除 this.cart = this.cart.filter(cartItem => cartItem.id !== item.id); } }, // 显示购物车详情 showCartDetail() { if (this.cartItemCount > 0) { this.$refs.cartPopup.open(); } }, // 关闭购物车详情 closeCartDetail() { this.$refs.cartPopup.close(); }, // 结算 checkout() { uni.showToast({ title: '结算成功', icon: 'success' }); // 实际开发中这里会有支付流程 this.closeCartDetail(); } } } </script> <style lang="scss" scoped> .shop-container { display: flex; flex-direction: column; height: 100vh; background-color: #f5f5f5; padding-bottom: 100rpx; } /* 新增顶部固定容器 */ .fixed-header { position: sticky; top: 0; z-index: 1000; /* 确保在顶部 */ background: white; /* 背景色,避免滚动时内容透出 */ box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1); /* 添加阴影增强层次感 */ } .search-bar { padding: 20rpx; background-color: #fff; } .category-scroll { white-space: nowrap; background-color: #fff; padding: 20rpx 0; border-bottom: 1rpx solid #eee; } .category-item { display: inline-block; padding: 10rpx 30rpx; margin: 0 10rpx; border-radius: 30rpx; background-color: #f5f5f5; font-size: 28rpx; &.active { background-color: #ff6b6b; color: #fff; } } .dish-list { flex: 1; padding: 20rpx; /* 添加顶部内边距,避免内容被固定栏遮挡 */ // padding-top: 0; } .dish-item { display: flex; align-items: center; background-color: #fff; border-radius: 16rpx; margin-bottom: 15rpx; padding: 20rpx; box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05); } .dish-image { width: 180rpx; height: 180rpx; border-radius: 8rpx; margin-right: 20rpx; } .dish-info { flex: 1; display: flex; flex-direction: column; justify-content: space-between; } .dish-name { font-size: 28rpx; font-weight: bold; color: #333; } .dish-price { font-size: 30rpx; color: #ff6b6b; margin-top: 10rpx; } .dish-stock { font-size: 24rpx; color: #999; margin-top: 10rpx; &.low-stock { color: #ff6b6b; } } .add-btn-container { display: flex; align-items: center; } .add-btn { width: 70rpx; height: 70rpx; border-radius: 50%; background-color: #ff6b6b; display: flex; justify-content: center; align-items: center; color: #fff; font-size: 24rpx; padding: 0; margin: 0; &.disabled { background-color: #ccc; } } .sold-out-text { font-size: 28rpx; color: #999; padding: 10rpx 20rpx; background-color: #f5f5f5; border-radius: 8rpx; } .quantity-selector { display: flex; align-items: center; background-color: #fff; border-radius: 40rpx; padding: 6rpx; box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1); } .quantity-btn { width: 50rpx; height: 50rpx; border-radius: 50%; display: flex; justify-content: center; align-items: center; padding: 0; margin: 0; background-color: #fff; border: 1rpx solid #eee; } .quantity-text { font-size: 28rpx; min-width: 60rpx; text-align: center; font-weight: bold; } .cart-bar { position: fixed; bottom: 0; left: 0; right: 0; height: 100rpx; background-color: #333; display: flex; align-items: center; padding: 0 30rpx; color: #fff; z-index: 999; } .cart-icon-container { position: relative; margin-right: 20rpx; } .cart-badge { position: absolute; top: -10rpx; right: -10rpx; background-color: #ff6b6b; color: #fff; border-radius: 50%; width: 40rpx; height: 40rpx; display: flex; justify-content: center; align-items: center; font-size: 24rpx; } .total-price { flex: 1; font-size: 36rpx; font-weight: bold; } .checkout-btn { background-color: #ff6b6b; color: #fff; border-radius: 50rpx; padding: 0 40rpx; height: 70rpx; line-height: 70rpx; font-size: 30rpx; &[disabled] { background-color: #999; opacity: 0.6; } } /* 购物车详情弹窗样式 */ .cart-detail { background-color: #fff; border-top-left-radius: 20rpx; border-top-right-radius: 20rpx; padding: 30rpx; max-height: 80vh; display: flex; flex-direction: column; } .cart-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20rpx; border-bottom: 1rpx solid #eee; margin-bottom: 20rpx; } .cart-title { font-size: 36rpx; font-weight: bold; color: #333; } .cart-list { flex: 1; max-height: 60vh; } .cart-item { display: flex; align-items: center; padding: 20rpx 0; border-bottom: 1rpx solid #f5f5f5; } .cart-item-image { width: 120rpx; height: 120rpx; border-radius: 8rpx; margin-right: 20rpx; } .cart-item-info { flex: 1; } .cart-item-name { font-size: 30rpx; color: #333; margin-bottom: 10rpx; } .cart-item-price { font-size: 28rpx; color: #ff6b6b; } .cart-item-quantity { display: flex; align-items: center; } .cart-quantity-btn { width: 50rpx; height: 50rpx; border-radius: 50%; display: flex; justify-content: center; align-items: center; padding: 0; margin: 0 10rpx; background-color: #fff; border: 1rpx solid #eee; } .cart-quantity-text { font-size: 28rpx; min-width: 60rpx; text-align: center; font-weight: bold; } .cart-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 20rpx; padding-top: 20rpx; border-top: 1rpx solid #eee; } .cart-total { font-size: 36rpx; font-weight: bold; color: #ff6b6b; } .cart-checkout-btn { background-color: #ff6b6b; color: #fff; border-radius: 50rpx; padding: 0 40rpx; height: 80rpx; line-height: 80rpx; font-size: 32rpx; } </style>

/*! * weui.js v1.1.0 (https://github.com/weui/weui-wxss) * Copyright 2016, wechat ui team * MIT license */ page { line-height: 1.6; font-family: -apple-system-font, "Helvetica Neue", sans-serif; } icon { vertical-align: middle; } .weui-cells { position: relative; margin-top: 1.17647059em; background-color: #FFFFFF; line-height: 1.41176471; font-size: 17px; } .weui-cells:before { content: " "; position: absolute; left: 0; top: 0; right: 0; height: 1px; border-top: 1rpx solid #D9D9D9; color: #D9D9D9; } .weui-cells:after { content: " "; position: absolute; left: 0; bottom: 0; right: 0; height: 1px; border-bottom: 1rpx solid #D9D9D9; color: #D9D9D9; } .weui-cells__title { margin-top: .77em; margin-bottom: .3em; padding-left: 15px; padding-right: 15px; color: #999999; font-size: 14px; } .weui-cells_after-title { margin-top: 0; } .weui-cells__tips { margin-top: .3em; color: #999999; padding-left: 15px; padding-right: 15px; font-size: 14px; } .weui-cell { padding: 10px 15px; position: relative; display: -webkit-box; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; align-items: center; } .weui-cell:before { content: " "; position: absolute; left: 0; top: 0; right: 0; height: 1px; border-top: 1rpx solid #D9D9D9; color: #D9D9D9; left: 15px; } .weui-cell:first-child:before { display: none; } .weui-cell_active { background-color: #ECECEC; } .weui-cell_primary { -webkit-box-align: start; -webkit-align-items: flex-start; align-items: flex-start; } .weui-cell__bd { -webkit-box-flex: 1; -webkit-flex: 1; flex: 1; } .weui-cell__ft { text-align: right; color: #999999; } .weui-cell_access { color: inherit; } .weui-cell__ft_in-access { padding-right: 13px; position: relative; } .weui-cell__ft_in-access:after { content: " "; display: inline-block; height: 6px; width: 6px; bord

<template> <view class="container"> <view class="filter-box"> <view class="date-picker">开始日期:{{ startDate || '请选择' }}</view> <view class="date-picker">结束日期:{{ endDate || '请选择' }}</view> <button @tap="filterData" class="filter-btn">筛选</button> </view> <view class="progress-card"> <text class="title">个人考核进度</text> <text class="progress-text">{{ progress }}%(当前阶段:{{ currentStage }})</text> </view> <view class="tabs"> <text :class="['tab-item', activeTab === 0 ? 'active' : '']" @tap="switchTab(0)">订单记录</text> <text :class="['tab-item', activeTab === 1 ? 'active' : '']" @tap="switchTab(1)">消费记录</text> </view> <scroll-view scroll-y class="list-container" @scrolltolower="loadMore"> <view v-if="activeTab === 0" class="list"> <view v-for="(item, index) in filteredOrders" :key="index" class="list-item"> <text class="order-no">订单号:{{ item.orderNo }}</text> <text class="order-date">{{ item.date }}</text> <text class="order-amount">金额:¥{{ item.amount }}</text> </view> <view v-if="!filteredOrders.length" class="empty-tip">暂无订单记录</view> </view> <view v-if="activeTab === 1" class="list"> <view v-for="(item, index) in filteredConsumptions" :key="index" class="list-item"> <text class="consume-type">{{ item.type }}</text> <text class="consume-date">{{ item.date }}</text> <text class="consume-amount">¥{{ item.amount }}</text> </view> <view v-if="!filteredConsumptions.length" class="empty-tip">暂无消费记录</view> </view> <view v-if="loading" class="loading">加载中...</view> </scroll-view> </view> </template> <style lang="scss"> .container { padding: 20rpx; } .filter-box { display: flex; align-items: center; margin-bottom: 20rpx; .date-picker { flex: 1; padding: 15rpx; border: 1rpx solid #eee; margin-right: 10rpx; border-radius: 8rpx; } .filter-btn { width: 150rpx; height: 70rpx; line-height: 70rpx; } } .progress-card { background: #fff; padding: 30rpx; border-radius: 16rpx; margin-bottom: 30rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.1); .title { display: block; font-size: 34rpx; margin-bottom: 20rpx; } .progress-text { display: block; margin-top: 15rpx; color: #666; } } .tabs { display: flex; border-bottom: 1rpx solid #eee; .tab-item { flex: 1; text-align: center; padding: 25rpx; color: #666; &.active { color: #007AFF; border-bottom: 4rpx solid #007AFF; } } } .list-container { height: calc(100vh - 400rpx); .list-item { padding: 30rpx; background: #fff; margin-bottom: 20rpx; border-radius: 12rpx; display: flex; justify-content: space-between; box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.05); .order-amount, .consume-amount { color: #e64340; font-weight: bold; } } .empty-tip { text-align: center; color: #999; padding: 50rpx; } .loading { text-align: center; padding: 30rpx; color: #999; } } </style>我需要消费记录样式和订单记录样式帮我在我这个代码写一下

<template> <view :class="{ inComeItemWrap: true, lastDomWrap: lastDom }"> <view :class="{ dot: true, activeC: data.assessState == 1 }" /> <view class="time flex"> {{ data.checkDate}} <view v-if="data.approveState == 0" class="status status1">未提交</view> <view v-if="data.approveState == 1" class="status status2">1审批中</view> <view v-if="data.approveState == 2" class="status status2">2审批通过</view> <view v-if="data.approveState == 3" class="status status2">3审批失败</view> </view> <view class="con"> <view class="conItem1"> <view class="conItemT">失败原因</view> <view class="conItemV">{{ incomeAmountStr }}</view> </view> </view> </view> </template> <script> import dayjs from "@/uni_modules/uview-ui/libs/util/dayjs.js"; export default { name: "inComeItem", props: { data: { type: Object, default: () => { return {}; }, }, lastDom: { type: Boolean, default: false, }, }, data() { return {}; }, computed: { incomeAmountStr() { let { data } = this return this.formatMoney(Math.floor(data.incomeAmount/100 || 0)).replace(/\d/g, '*'); } }, methods: { dayjs, }, }; </script> <style lang="scss" scoped> .inComeItemWrap { position: relative; // margin-left: 20rpx; padding-top: 40rpx; padding-bottom: 36rpx; border-left: 1px dashed #ccc; padding-left: 20rpx; } .lastDomWrap { border-left: 1px dashed #f3f5f8; } .dot { position: absolute; left: -13rpx; top: 0; width: 20rpx; height: 20rpx; border-radius: 20rpx; background: #05c4c8; } .time { position: absolute; left: 16rpx; top: -12rpx; font-size: 28rpx; color: #000; font-weight: bold; } .activeC { background: #05c4c8; } .con { padding-left: 30rpx; display: flex; .conItem1 { flex: 1; } .conItem2 { width: 60%; } .conItemT { margin-bottom: 4rpx; white-space: nowrap; color: #7c7c7c; font-size: 24rpx; } .conItemV { color: #000; font-weight: bold; font-size: 30rpx; } } .status1 { display: flex; align-content: center; align-items: center; font-weight: normal; font-size: 24rpx; padding: 0 8rpx; margin-left: 8rpx; color: #fff; background: #caa658; border-radius: 40rpx; } .status2 { display: flex; align-items: center; align-content: center; justify-content: center; font-weight: normal; padding: 0 12rpx; margin-left: 8rpx; background: #05c4c8; color: #fff; border-radius: 40upx; font-size: 24rpx; } .status3 { font-weight: normal; margin-left: 8rpx; position: relative; width: 204upx; /* 按钮宽度 */ height: 40upx; /* 按钮高度 */ border-radius: 40upx; /* 圆角 */ overflow: hidden; /* 隐藏超出边界的部分 */ } .status3::before, .status3::after { content: ""; position: absolute; width: 100%; height: 100%; } .statusText { display: flex; justify-content: center; align-items: center; position: absolute; left: 0; right: 0; top: 0; bottom: 0; text-align: center; font-size: 24rpx; z-index: 1; } /* 左侧颜色部分 */ .status3::before { background-color: #00d3d6; /* 青色 */ clip-path: polygon(0 0, 54% 0, 46% 100%, 0 100%); } /* 右侧颜色部分 */ .status3::after { background-color: #ffe6e6; /* 粉色 */ clip-path: polygon(54% 0, 100% 0, 100% 100%, 46% 100%); } </style> 优化一下样式

<template> <view class="mask" v-if="visible" @click="handleMaskClick"></view> <view class="dialog-box" v-if="visible"> <view class="dialog-header"> <text class="title">提示</text> <text class="close-btn" @click="close">×</text> </view> <view class="dialog-content"> <text>申请提前结束考核将无法继续答题,是否确认提前结束考核?</text> </view> <view class="dialog-footer"> <button class="btn cancel" @click="cancel">取消</button> <button class="btn confirm" @click="confirm">确认</button> </view> </view> </template> <script> export default { props: { visible: { type: Boolean, default: false } }, methods: { close() { this.$emit('close') }, cancel() { this.$emit('cancel') }, confirm() { this.$emit('confirm') }, handleMaskClick() { // 点击遮罩层不关闭弹窗 // this.close() } } } </script> <style scoped> .mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 999; } .dialog-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 80%; max-width: 600rpx; background-color: #fff; border-radius: 16rpx; z-index: 1000; box-shadow: 0 4rpx 24rpx rgba(0, 0, 0, 0.12); } .dialog-header { display: flex; justify-content: space-between; align-items: center; padding: 32rpx; border-bottom: 1rpx solid #eee; } .title { font-size: 36rpx; font-weight: bold; } .close-btn { font-size: 40rpx; color: #999; } .dialog-content { padding: 48rpx 32rpx; font-size: 32rpx; line-height: 1.5; color: #333; } .dialog-footer { display: flex; border-top: 1rpx solid #eee; } .btn { flex: 1; height: 96rpx; line-height: 96rpx; font-size: 32rpx; background: none; border-radius: 0; } .btn::after { border: none; } .cancel { color: #666; border-right: 1rpx solid #eee; } .confirm { color: #007aff; font-weight: bold; } </style> 优化一下

<template> 用户登录 <input v-model="username" placeholder="用户名"> <input v-model="password" type="password" placeholder="密码"> <button @click="handleLogin">登录</button> </template> <script setup> import { ref } from 'vue' import { useRouter } from 'vue-router' import axios from 'axios' import { ElMessage } from 'element-plus' const router = useRouter() const username = ref('') const password = ref('') const handleLogin = async () => { try { // 发送POST请求到登录接口 const response = await axios.post('http://172.26.26.43/dev-api/login', { username: username.value, password: password.value }) const { code, message, token } = response.data // 根据状态码判断登录是否成功 if (code === 200) { // 存储token到localStorage localStorage.setItem('token', token) ElMessage.success({ message:'登录成功!', customClass:'mobile-message', duration: 1000 }) setTimeout(() => { // 登录成功后跳转到详情页 router.push({ name: 'Detail' , params: { id: 123 } }) }, 1000) } else { alert(登录失败: ${message}) } } catch (error) { // 处理请求错误 console.error('登录请求出错:', error) alert('登录请求失败,请检查网络或联系管理员') } } </script> <style scoped> /* 添加移动端适配的样式 */ .login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; /* 使容器至少和视口一样高 */ background-color: #f5f5f5; /* 背景色 */ padding: 16px; /* 内边距 */ } .login-form { width: 100%; max-width: 400px; /* 最大宽度,避免在大屏幕上过宽 */ padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); } .login-form h2 { text-align: center; margin-bottom: 20px; color: #333; } .login-form input { width: 100%; padding: 12px; margin-bottom: 12px; border: 1px solid #ddd; border-radius: 4px; font-size: 16px; box-sizing: border-box; /* 确保宽度包含内边距和边框 */ } .login-form button { width: 100%; padding: 12px; background-color: #007bff; color: white; border: none; border-radius: 4px; font-size: 16px; cursor: pointer; } /* 按钮的点击区域已经足够大(高度44px左右) */ .login-form button:active { background-color: #0056b3; } .login-form a { display: block; text-align: center; margin-top: 12px; color: #007bff; text-decoration: none; } </style> 我什么我这个项目的登录界面可以正常登录,但是修改后:<template> <view class="login-container"> <view class="login-form"> <text class="login-title">用户登录</text> <input v-model="username" placeholder="用户名" class="login-input" placeholder-class="input-placeholder" /> <input v-model="password" type="password" placeholder="密码" class="login-input" placeholder-class="input-placeholder" /> <button class="login-button" :loading="loading" @click="handleLogin" >登录</button> </view> </view> </template> <script> import { ref } from 'vue' export default { setup() { const username = ref('') const password = ref('') const loading = ref(false) const handleLogin = async () => { // 验证输入 if (!username.value.trim()) { uni.showToast({ title: '请输入用户名', icon: 'none', duration: 2000 }) return } if (!password.value) { uni.showToast({ title: '请输入密码', icon: 'none', duration: 2000 }) return } loading.value = true try { // 正确使用 uni.request 并处理返回值 const [error, response] = await uni.request({ url: 'http://172.26.26.43/dev-api/login', method: 'POST', data: { username: username.value, password: password.value }, header: { 'Content-Type': 'application/json' }, timeout: 10000 // 10秒超时 }) // 处理请求错误 if (error) { throw new Error(请求失败: ${error.errMsg}) } // 检查响应状态 if (response.statusCode !== 200) { throw new Error(服务器错误: ${response.statusCode}) } // 解析响应数据 const { data } = response const { code, message, token } = data if (code === 200) { // 存储token uni.setStorageSync('token', token) uni.showToast({ title: '登录成功!', icon: 'success', duration: 1000 }) // 登录成功后跳转 setTimeout(() => { uni.redirectTo({ url: '/pages/index/index' }) }, 1000) } else { throw new Error(登录失败: ${message || '未知错误'}) } } catch (error) { console.error('登录请求出错:', error) uni.showToast({ title: error.message || '登录失败,请重试', icon: 'none', duration: 2000 }) } finally { loading.value = false } } return { username, password, loading, handleLogin } } } </script> <style scoped> /* 保持之前的样式不变 */ .login-container { display: flex; justify-content: center; align-items: center; min-height: 100vh; padding: 32rpx; background-color: #f5f5f5; } .login-form { width: 100%; max-width: 600rpx; padding: 60rpx; background: #fff; border-radius: 16rpx; box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1); } .login-title { display: block; text-align: center; margin-bottom: 60rpx; font-size: 40rpx; font-weight: bold; color: #333; } .login-input { width: 100%; height: 88rpx; padding: 0 24rpx; margin-bottom: 40rpx; border: 2rpx solid #ddd; border-radius: 12rpx; font-size: 32rpx; box-sizing: border-box; } .input-placeholder { color: #999; font-size: 32rpx; } .login-button { width: 100%; height: 88rpx; line-height: 88rpx; background-color: #007aff; color: white; font-size: 32rpx; border-radius: 12rpx; margin-top: 20rpx; } .login-button:active { background-color: #0062cc; opacity: 0.9; } </style> 用到uniapp里就登录不了

<template> <view class="box"> <view style="text-align: center;padding: 10rpx;"> <image class="image" src="../../static/images/icons/male.png" mode="scaleToFill" /> <view style="font-size: 24rpx;color: #a6a8ac;">男生</view> </view> <view class="mid"> <view class="flex" style="justify-content: space-between;"> <view class="males">{{ malePercent }}%</view> <view class="females">{{ femalePercent }}%</view> </view> <view class="progress-bar"> <view class="male" :style="{ width: malePercent + '%' }"></view> <view class="progress"> <view class="progress-bar-inner" :style="{ width: percent + '%' }"></view> </view> <view class="female" :style="{ width: femalePercent + '%' }"></view> </view> </view> <view style="text-align: center;padding: 10rpx;"> <image class="image" src="../../static/images/icons/female.png" mode="scaleToFill" /> <view style="font-size: 24rpx;color: #a6a8ac;">女生</view> </view> </view> </template> <script setup> import { computed } from 'vue' const props = defineProps({ male: { type: Number, requirde: true }, female: { type: Number, requirde: true }, }) // 总比例 const percent = computed(() => { return props.male / (props.male + props.female) * 100 }) // 男生比例 const malePercent = computed(() => { return Math.round(props.male / (props.male + props.female) * 100) }) // 女生比例 const femalePercent = computed(() => { return Math.round(props.female / (props.male + props.female) * 100) }) </script> <style lang="scss" scoped> .progress-bar { display: flex; align-items: center; height: 30rpx; width: 100%; border: 1px solid #ccc; border-radius: 30rpx; overflow: hidden; } .progress-bar .male, .progress-bar .female { display: flex; justify-content: center; align-items: center; height: 100%; color: #fff; font-size: 14px; font-weight: bold; } .progress-bar .male { flex: 0 0 auto; background-color: #007bff; } .progress-bar .progress { flex: 1 1 auto; height: 100%; position: relative; } .progress-bar .progress .progress-bar-inner { height: 100%; background-color: #28a745; position: absolute; top: 0; left: 0; } .progress-bar .female { flex: 0 0 auto; background-color: #dc3545; } .content { justify-content: space-between; } .males { color: #007bff; font-size: 24rpx; } .females { color: #dc3545; font-size: 24rpx; } .box { display: flex; justify-content: space-around; align-items: center; margin-top: 50rpx; margin-bottom: 50rpx; .mid { width: 70%; } } .image { height: 60rpx; width: 60rpx; } </style> 帮我把上述代码改成只传male一个值就可以显示出male和female两个的比例出来

最新推荐

recommend-type

【税会实务】Excel文字输入技巧.doc

【税会实务】Excel文字输入技巧.doc
recommend-type

中职计算机教学大纲(1).docx

中职计算机教学大纲(1).docx
recommend-type

VC图像编程全面资料及程序汇总

【标题】:"精通VC图像编程资料全览" 【知识点】: VC即Visual C++,是微软公司推出的一个集成开发环境(IDE),专门用于C++语言的开发。VC图像编程涉及到如何在VC++开发环境中处理和操作图像。在VC图像编程中,开发者通常会使用到Windows API中的GDI(图形设备接口)或GDI+来进行图形绘制,以及DirectX中的Direct2D或DirectDraw进行更高级的图形处理。 1. GDI(图形设备接口): - GDI是Windows操作系统提供的一套应用程序接口,它允许应用程序通过设备无关的方式绘制图形。 - 在VC图像编程中,主要使用CDC类(设备上下文类)来调用GDI函数进行绘制,比如绘制线条、填充颜色、显示文本等。 - CDC类提供了很多函数,比如`MoveTo`、`LineTo`、`Rectangle`、`Ellipse`、`Polygon`等,用于绘制基本的图形。 - 对于图像处理,可以使用`StretchBlt`、`BitBlt`、`TransparentBlt`等函数进行图像的位块传输。 2. GDI+: - GDI+是GDI的后继技术,提供了更丰富的图形处理功能。 - GDI+通过使用`Graphics`类来提供图像的绘制、文本的渲染、图像的处理和颜色管理等功能。 - GDI+引入了对矢量图形、渐变色、复杂的文本格式和坐标空间等更高级的图形处理功能。 - `Image`类是GDI+中用于图像操作的基础类,通过它可以进行图像的加载、保存、旋转、缩放等操作。 3. DirectX: - DirectX是微软推出的一系列API集合,用于在Windows平台上进行高性能多媒体编程。 - DirectX中的Direct2D是用于硬件加速的二维图形API,专门用于UI元素和简单的图形渲染。 - DirectDraw主要用于硬件加速的位图操作,比如全屏游戏开发中的画面渲染。 4. 位图操作: - 在VC图像编程中,位图操作是一个重要的部分。需要了解如何加载、保存和处理位图(BMP)文件。 - 可以使用位图文件格式的解析,来访问位图的像素数据,进行像素级别的图像处理和修改。 5. 高级图像处理技术: - 包括图像滤镜、图像转换、图像压缩和解压缩技术。 - 需要掌握一些图像处理算法,比如卷积、FFT(快速傅里叶变换)、DCT(离散余弦变换)等。 - 了解图像的色彩空间转换,比如RGB到YUV的转换,这在视频处理中非常重要。 6. 图像库的使用: - 除了直接使用API进行图像处理之外,还可以使用开源的图像处理库,如OpenCV。 - OpenCV是一个跨平台的计算机视觉和机器学习软件库,它提供了很多高级的图像处理功能。 【压缩包子文件的文件名称列表】: VC++ 文件名称列表显示为"VC++",这表明文件包中可能包含了Visual C++的项目、源代码文件、动态链接库(DLLs)、编译器设置、链接器设置等。如果要使用这些文件进行VC图像编程,需要确保Visual C++开发环境已经安装并且配置好,同时需要安装好所有依赖的库和工具。 要开始VC图像编程,开发者需要具备C++编程基础,熟悉Windows编程概念,并且对图形学有一定的了解。掌握VC图像编程技巧,对于进行桌面应用程序开发、图像处理软件开发以及游戏开发等都是至关重要的。
recommend-type

Pokemmo响应速度翻倍:多线程处理的高级技巧

# 摘要 多线程处理是提高软件并发性能和响应速度的关键技术,本文从基础概念与优势出发,深入探讨了多线程的实现机制,包括线程模型、调度算法、编程关键技术、线程安全性最佳实践、死锁预防与处理等方面。通
recommend-type

人名列表滚动抽奖

<think>嗯,用户想实现一个滚动抽奖功能,需要前端动画效果和随机选择逻辑。首先,我得考虑前端怎么实现滚动效果。可能用CSS动画或者JavaScript的requestAnimationFrame?比如,使用CSS的@keyframes来控制位移,或者用JS动态更新样式。然后,随机选择算法,可能需要确保公平性,比如用Fisher-Yates洗牌算法,或者用Math.random()来生成随机索引。然后,用户可能需要平滑的滚动动画,比如先快速滚动,然后逐渐减速,最后停在选中的人名上。这可能需要设置定时器,逐步改变位置,或者使用CSS过渡效果。另外,还要考虑性能,避免页面卡顿,可能需要使用硬件加
recommend-type

一站式JSF开发环境:即解压即用JAR包

标题:“jsf开发完整JAR包”所指的知识点: 1. JSF全称JavaServer Faces,是Java EE(现EE4J)规范之一,用于简化Java Web应用中基于组件的用户界面构建。JSF提供了一种模型-视图-控制器(MVC)架构的实现,使得开发者可以将业务逻辑与页面表示分离。 2. “开发完整包”意味着这个JAR包包含了JSF开发所需的所有类库和资源文件。通常来说,一个完整的JSF包会包含核心的JSF库,以及一些可选的扩展库,例如PrimeFaces、RichFaces等,这些扩展库提供了额外的用户界面组件。 3. 在一个项目中使用JSF,开发者无需单独添加每个必要的JAR文件到项目的构建路径中。因为打包成一个完整的JAR包后,所有这些依赖都被整合在一起,极大地方便了开发者的部署工作。 4. “解压之后就可以直接导入工程中使用”表明这个JAR包是一个可执行的归档文件,可能是一个EAR包或者一个可直接部署的Java应用包。解压后,开发者只需将其内容导入到他们的IDE(如Eclipse或IntelliJ IDEA)中,或者将其放置在Web应用服务器的正确目录下,就可以立即进行开发。 描述中所指的知识点: 1. “解压之后就可以直接导入工程中使用”说明这个JAR包是预先配置好的,它可能包含了所有必要的配置文件,例如web.xml、faces-config.xml等,这些文件是JSF项目运行所必需的。 2. 直接使用意味着减少了开发者配置环境和处理依赖的时间,有助于提高开发效率。 标签“jsf jar包”所指的知识点: 1. 标签指明了JAR包的内容是专门针对JSF框架的。因此,这个JAR包包含了JSF规范所定义的API以及可能包含的具体实现,比如Mojarra或MyFaces。 2. “jar包”是一种Java平台的归档文件格式,用于聚合多个文件到一个文件中。在JSF开发中,JAR文件经常被用来打包和分发库或应用程序。 文件名称列表“jsf”所指的知识点: 1. “jsf”文件名可能意味着这是JSF开发的核心库,它应该包含了所有核心的JavaServer Faces类文件以及资源文件。 2. 如果是使用特定版本的JSF,例如“jsf-2.2.jar”,则表明文件内包含了对应版本的JSF实现。这种情况下,开发者必须确认他们所使用的Web服务器或应用程序服务器支持该版本的JSF。 3. 文件名称也可能是“jsf-components.jar”、“jsf-impl.jar”等,表明这个JAR包是JSF的一个子模块或特定功能组件。例如,“jsf-components.jar”可能包含了一系列用于在JSF应用中使用的自定义组件。 4. 对于开发者而言,了解文件名称中所蕴含的信息非常重要,因为这将决定他们需要下载哪些JAR包来满足特定项目的需求。 综合以上信息,开发者在使用JSF进行Java Web应用开发时,会通过一个预先配置好的JAR包来快速地搭建和启动项目。这样做不仅简化了项目初始化的过程,也使得开发者能够更加聚焦于业务逻辑的实现和界面设计,而不必深究底层框架配置的细节。
recommend-type

Pokemmo内存优化揭秘:专家教你如何降低50%资源消耗

# 摘要 本文综述了Pokemmo游戏的内存优化方法,从内存管理基础出发,探讨内存使用效率的影响因素,并介绍了性能监控与分析工具。在内存优化实践技巧章节中,详细讨论了代码层面的优化、数据结构和算法选择对内存效率的影响,并通过案例分析展示了实际的优化过程。针对Pokemmo游戏特点,分析了内存消耗特性并提出了特定优化技术。最后,本文展望了未来内存管理技术的发展方向,以及游戏开发中面临的新挑战,为Pokemmo及类似游戏提供了优化建议。 # 关键字 内存优化;内存管理;性能监控;数据结构;算法效率;游戏开发 参考资源链接:[Pokemmo必备资源包:四种ROM与汉化补丁](https://we
recommend-type

直接访问子路由是吧

<think>我们正在使用Vue2,因此需要参考VueRouterv3的文档(因为Vue2对应VueRouterv3,Vue3对应VueRouterv4)。用户的问题是:如何配置路由以支持直接访问子路由?即,在Vue2中,我们希望直接通过URL访问嵌套的子路由(例如:/parent/child),而不仅仅是先访问父路由再导航到子路由。根据之前的回答和引用,我们已经知道:1.在父路由的配置中,使用`children`数组来定义子路由。2.子路由的`path`不能以斜杠开头(例如:'child'而不是'/child'),这样它就会基于父路由的路径进行拼接。3.在父组件的模板中放置`<router-
recommend-type

C++函数库查询辞典使用指南与功能介绍

标题中提到的“C++函数库查询辞典”指的是一个参考工具书或者是一个软件应用,专门用来查询C++编程语言中提供的标准库中的函数。C++是一种静态类型、编译式、通用编程语言,它支持多种编程范式,包括过程化、面向对象和泛型编程。C++标准库是一组包含函数、类、迭代器和模板的库,它为C++程序员提供标准算法和数据结构。 描述中提供的内容并没有给出实际的知识点,只是重复了标题的内容,并且有一串无关的字符“sdfsdfsdffffffffffffffffff”,因此这部分内容无法提供有价值的信息。 标签“C++ 函数库 查询辞典”强调了该工具的用途,即帮助开发者查询C++的标准库函数。它可能包含每个函数的详细说明、语法、使用方法、参数说明以及示例代码等,是学习和开发过程中不可或缺的参考资源。 文件名称“c++函数库查询辞典.exe”表明这是一个可执行程序。在Windows操作系统中,以“.exe”结尾的文件通常是可执行程序。这意味着用户可以通过双击或者命令行工具来运行这个程序,进而使用其中的查询功能查找C++标准库中各类函数的详细信息。 详细知识点如下: 1. C++标准库的组成: C++标准库由多个组件构成,包括输入输出流(iostream)、算法(algorithm)、容器(container)、迭代器(iterator)、字符串处理(string)、数值计算(numeric)、本地化(locale)等。 2. 输入输出流(iostream)库: 提供输入输出操作的基本功能。使用诸如iostream、fstream、sstream等头文件中的类和对象(如cin, cout, cerr等)来实现基本的输入输出操作。 3. 算法(algorithm)库: 包含对容器进行操作的大量模板函数,如排序(sort)、查找(find)、拷贝(copy)等。 4. 容器(container)库: 提供各种数据结构,如向量(vector)、列表(list)、队列(queue)、映射(map)等。 5. 迭代器(iterator): 迭代器提供了一种方法来访问容器中的元素,同时隐藏了容器的内部结构。 6. 字符串处理(string)库: C++标准库中的字符串类提供了丰富的功能用于处理字符串。 7. 数值计算(numeric)库: 提供数值计算所需的函数和类,比如对复数的支持和数值算法。 8. 本地化(locale)库: 提供本地化相关的功能,比如日期、时间的格式化显示以及字符的本地化比较。 9. 错误处理和异常: C++通过throw、try、catch关键字和标准异常类提供了一套异常处理机制。 10. 智能指针: C++11及其后续版本提供了智能指针(如unique_ptr、shared_ptr、weak_ptr)来自动管理动态分配的内存。 11. lambda表达式: 在C++11中引入,允许临时创建匿名函数对象。 12. C++11新特性: 包括范围for循环、移动语义、类内初始化器、auto类型推导等。 使用C++函数库查询辞典的用户可能需要对C++的基础知识有一定的掌握,例如变量、数据类型、控制结构、函数以及面向对象的概念等。了解C++标准库的结构和内容能够帮助程序员有效地利用库函数进行软件开发,提高编程效率并减少重复造轮子的工作。 总结来说,一个C++函数库查询辞典工具对于C++程序员来说是一个非常有用的资源,它能够提供快速查找标准库函数的能力,帮助程序员更高效地解决问题和进行学习。同时,随着C++标准的不断更新,例如C++11、C++14、C++17和C++20,函数库查询辞典也会不断地更新以包含新的特性,这对于紧跟技术发展的开发者来说尤为重要。
recommend-type

【bat脚本安全最佳实践】:保护你的系统与脚本安全的黄金法则

# 摘要 本文旨在全面阐述BAT脚本的基础知识、安全编写原则、审查与优化方法以及在企业环境中的安全应用。通过深入分析脚本安全基础、常见安全陷阱及脚本的权限管理,文章提出了安全编写的具体实践和预防措施。本文详细介绍了脚本安全审查流程、代码优化、错误处理和安全更新维护策略。在企业应用方面,探讨了企业安全政策制定、脚本审计和版本控制以及外部威胁的防范措施。通过案例分析,总结了脚本