Flex请求后台页面错误:Error #2032: 流错误

本文探讨了Error#2032:流错误的原因及解决办法,特别关注设置URLRequest对象data属性的情况,并指出了在不同服务器环境下可能出现的问题。
错误类似:
IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2032: 流错误。

可能原因:
应该是设置了URLRequest对象的data属性.如果你调用的只是纯数据文件.你设置了这个属性的值就有可能出现这种错误.调用的后台程序页面应该不会出现这种情况的.

注:如果后台页面是部署在IIS上会出现这个问题,在tomcat下却没有。
<template> <view class="container"> <!-- 顶部信息展示 --> <view class="header"> <view class="title">{{ formData.dcWjTitle }}</view> <view class="info"> <text>被测评人员:{{ formData.dcName }}</text> <text style="margin-left: 20rpx;">部门:{{ formData.dcDept }}</text> </view> </view> <!-- 其他页面内容 --> </view> </template> <script> export default { data() { return { formData: { dcWjTitle: &#39;加载中...&#39;, dcName: &#39;加载中...&#39;, dcDept: &#39;加载中...&#39; }, token: &#39;&#39; } }, onLoad(options) { const wjId = options.id console.log(&#39;接收到的问卷ID:&#39;, wjId) this.getTokenAndLoadData(wjId) }, methods: { async getTokenAndLoadData(id) { try { this.token = uni.getStorageSync(&#39;token&#39;) if (!this.token) { throw new Error(&#39;未找到认证令牌,请重新登录&#39;) } await this.loadQuestionnaireData(id) } catch (error) { console.error(&#39;获取token失败:&#39;, error) uni.showToast({ title: error.message || &#39;请先登录&#39;, icon: &#39;none&#39;, duration: 3000 }) setTimeout(() => { uni.reLaunch({ url: &#39;/pages/login/login&#39; }) }, 1500) } }, async loadQuestionnaireData(id) { try { console.log(&#39;开始请求问卷数据,ID:&#39;, id) // 修复1: 使用正确的URL路径 const response = await uni.request({ url: `http://172.26.26.43/dev-api/wjdc/wj/${id}`, // 注意路径大小写 method: &#39;GET&#39;, header: { &#39;Authorization&#39;: `Bearer ${this.token}` }, timeout: 10000 // 添加超时设置 }) // 修复2: 正确处理uni.request返回结构 const [error, result] = response; if (error) { console.error(&#39;请求错误:&#39;, error) throw new Error(`网络请求失败: ${error.errMsg}`) } // 修复3: 检查状态码和业务码 if (result.statusCode !== 200) { throw new Error(`服务器返回错误状态: ${result.statusCode}`) } // 修复4: 根据接口格式获取数据 const responseData = result.data; if (responseData.code !== 200) { throw new Error(`接口错误: ${responseData.msg || &#39;未知错误&#39;}`) } // 修复5: 正确提取数据 const data = responseData.data console.log(&#39;接口返回数据:&#39;, data) // 更新表单数据 - 使用实际字段名 this.formData = { dcWjTitle: data.dcWjTitle || &#39;无标题&#39;, dcName: data.dcName || &#39;未知人员&#39;, dcDept: data.dcDept || &#39;未知部门&#39; } } catch (error) { console.error(&#39;请求失败:&#39;, error) // 显示错误信息 uni.showToast({ title: error.message || &#39;数据加载失败&#39;, icon: &#39;none&#39;, duration: 3000 }) // 更新为错误状态 this.formData = { dcWjTitle: &#39;数据加载失败&#39;, dcName: error.message || &#39;请检查网络&#39;, dcDept: &#39;或联系管理员&#39; } // 认证错误处理 if (error.message.includes(&#39;401&#39;) || error.message.includes(&#39;认证&#39;)) { uni.removeStorageSync(&#39;token&#39;) setTimeout(() => { uni.reLaunch({ url: &#39;/pages/login/login&#39; }) }, 1500) } } } } } </script> <style scoped> .container { padding: 20rpx; } .header { padding: 30rpx; background-color: #f8f8f8; border-radius: 12rpx; box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.1); margin-bottom: 30rpx; } .title { font-size: 36rpx; font-weight: bold; margin-bottom: 20rpx; color: #333; text-align: center; } .info { display: flex; justify-content: center; font-size: 28rpx; color: #666; } .info text { margin: 0 10rpx; padding: 5rpx 15rpx; background-color: #eef7ff; border-radius: 8rpx; } </style> 报错:17:26:02.824 请求失败:, TypeError: response is not iterable at pages/operation/operation.vue:103
07-24
// 核心类型定义 export type FormattedLocation = { lat: number; lng: number; spd: number; acc: number; alt: number; }; export type LocationSuccessResult = { latitude: number; longitude: number; speed: number; accuracy: number; altitude: number; verticalAccuracy: number; horizontalAccuracy: number; }; export type UniErrorData = { errMsg?: string; }; export interface LocationError { errMsg: string; } // 全局状态变量 let isLocating = false; let locationTimer: number | null = null; let currentPosition: LocationSuccessResult | null = null; let locationHistory: FormattedLocation[] = []; const RETRY_DELAY = 5000; const LOCATE_INTERVAL = 3000; type LocationCallback = (position: LocationSuccessResult) => void; let successCallback: LocationCallback | null = null; /** 开始持续定位 */ export function startContinuousLocation(callback: LocationCallback): void { if (isLocating) { console.log(‘定位已在进行中,无需重复启动’); return; } successCallback = callback; isLocating = true; console.log(‘开始持续定位…’); getLocation(); }/** 停止持续定位 */ export function stopContinuousLocation(): void { const timer = locationTimer; if (timer !== null) { clearTimeout(timer); } isLocating = false; successCallback = null; locationTimer = null; console.log(‘已停止持续定位’); }/** 获取当前定位信息 */ export function getCurrentPosition(): LocationSuccessResult | null { return currentPosition; }/** 获取累计轨迹数组 */ // 添加深拷贝函数 function deepCopyLocation(loc: FormattedLocation): FormattedLocation { return { lat: loc.lat, lng: loc.lng, spd: loc.spd, acc: loc.acc, alt: loc.alt }; }// 修改 getLocationHistory 函数 export function getLocationHistory(): FormattedLocation[] { const result: FormattedLocation[] = []; for (let i = 0; i < locationHistory.length; i++) { result.push(deepCopyLocation(locationHistory[i])); } return result; } /** 清空轨迹历史 */ export function clearLocationHistory(): void { locationHistory = []; console.log(‘轨迹历史已清空’); }/** 安全获取数值函数 - 修复类型转换问题 */ function getSafeNumber(value: any, defaultValue: number = 0): number { if (value == null) return defaultValue;// 使用更安全的类型转换方式 let numValue: number; if (typeof value === ‘number’) { numValue = value; } else if (typeof value === ‘string’) { numValue = parseFloat(value); } else { return defaultValue; } if (isNaN(numValue)) { return defaultValue; } return numValue; } /** 包装setTimeout调用 */ function scheduleNextLocation(): void { const timer = locationTimer; if (timer !== null) { clearTimeout(timer); } locationTimer = setTimeout(() => { getLocation(); }, LOCATE_INTERVAL); }/** 核心定位函数(已修复类型转换问题) */ function getLocation(): void { if (!isLocating) return;uni.getLocation({ type: ‘wgs84’, geocode: false, success: (res) => { // … (success 回调逻辑保持不变) const latitude = getSafeNumber(res.latitude); const longitude = getSafeNumber(res.longitude); const speed = getSafeNumber(res.speed); const accuracy = getSafeNumber(res.accuracy); const altitude = getSafeNumber(res.altitude); const verticalAccuracy = getSafeNumber(res.verticalAccuracy); const horizontalAccuracy = getSafeNumber(res.horizontalAccuracy); const locationRes: LocationSuccessResult = { latitude: latitude, longitude: longitude, speed: speed, accuracy: accuracy, altitude: altitude, verticalAccuracy: verticalAccuracy, horizontalAccuracy: horizontalAccuracy }; currentPosition = locationRes; const formattedLoc: FormattedLocation = { lat: locationRes.latitude, lng: locationRes.longitude, spd: locationRes.speed, acc: locationRes.accuracy, alt: locationRes.altitude }; locationHistory.push(formattedLoc); console.log(`定位成功:lat=${formattedLoc.lat.toFixed(6)}, lng=${formattedLoc.lng.toFixed(6)}, 精度=${formattedLoc.acc}m`); const callback = successCallback; if (callback !== null) { callback(locationRes); } scheduleNextLocation(); }, // --- 修改点 2:使用 API 提供的 IGetLocationFail 类型 --- fail: (err: IGetLocationFail) => { // 修改这里 console.error(&#39;定位失败:&#39;, err); // IGetLocationFail 类型已经明确包含了 errMsg 属性 const errMsg = err.errMsg ?? &#39;未知错误&#39;; console.error(&#39;定位失败:&#39;, errMsg); if (errMsg.includes(&#39;auth deny&#39;)) { uni.showToast({ title: &#39;请授予后台定位权限以继续巡查&#39;, icon: &#39;none&#39;, duration: 3000 }); stopContinuousLocation(); } else if (errMsg.includes(&#39;timeout&#39;)) { uni.showToast({ title: &#39;定位超时,5秒后重试&#39;, icon: &#39;none&#39;, duration: 2000 }); } else { uni.showToast({ title: `定位失败:${errMsg}`, icon: &#39;none&#39;, duration: 3000 }); } scheduleNextLocation(); } }); } {{ isPatrolling ? ‘巡查中’ : ‘已停止’ }} 已记录:{{ trackPoints.length }} 个点位 <view class="location-info"> <text>当前位置:</text> <text>{{ currentLat.toFixed(6) }}, {{ currentLng.toFixed(6) }}</text> </view> <!-- scroll-view 显示轨迹点位,高度 300rpx --> <view class="track-scroll-container"> <text class="track-title">轨迹点位记录:</text> <scroll-view class="track-scroll" scroll-y="true" :style="{ height: &#39;300rpx&#39; }"> <view class="track-list"> <!-- 无点位时显示提示 --> <view class="track-empty" v-if="trackPoints.length === 0"> 暂无轨迹点位,请开始巡查 </view> <!-- 遍历显示所有点位(无时间戳) --> <view class="track-item" v-for="(item, index) in trackPoints" :key="index"> <view class="track-item-index">{{ index + 1 }}</view> <view class="track-item-content"> <view class="track-item-row"> <text class="label">经纬度:</text> <text class="value">{{ item.lat.toFixed(6) }}, {{ item.lng.toFixed(6) }}</text> </view> <view class="track-item-row"> <text class="label">速度/精度:</text> <text class="value">{{ item.spd.toFixed(2) }}m/s / {{ item.acc.toFixed(1) }}m</text> </view> <view class="track-item-row"> <text class="label">高度:</text> <text class="value">{{ item.alt.toFixed(2) }}m</text> </view> </view> </view> </view> </scroll-view> </view> <button @click="startPatrol" :disabled="isPatrolling" class="start-btn"> 开始巡查 </button> <button @click="stopPatrol" :disabled="!isPatrolling" class="stop-btn"> 结束巡查 </button> <button @click="clearHistory" class="clear-btn"> 清空轨迹 </button> </view></template><script lang="uts"> import { startContinuousLocation, stopContinuousLocation, getLocationHistory, clearLocationHistory, type FormattedLocation, type LocationSuccessResult } from &#39;@/utils/location&#39;; export default { data() { return { isPatrolling: false, trackPoints: [] as FormattedLocation[], // 恢复为普通数组类型,无需 UTSArray currentLat: 0, currentLng: 0 }; }, methods: { startPatrol() { clearLocationHistory(); this.trackPoints = []; this.currentLat = 0; this.currentLng = 0; this.isPatrolling = true; startContinuousLocation((res: LocationSuccessResult) => { this.currentLat = res.latitude; this.currentLng = res.longitude; // 关键修改:直接赋值,无需 Array.from 或 UTSArray 转换 this.trackPoints = getLocationHistory(); }); }, stopPatrol() { stopContinuousLocation(); this.isPatrolling = false; // 直接获取,无需类型转换 const fullTrack = getLocationHistory(); console.log(&#39;巡查结束,轨迹点:&#39;, fullTrack); }, clearHistory() { clearLocationHistory(); this.trackPoints = []; this.currentLat = 0; this.currentLng = 0; uni.showToast({ title: &#39;轨迹已清空&#39;, icon: &#39;success&#39;, duration: 1500 }); } } }; </script><style scoped> /* 样式保持不变,无需修改 */ .patrol-container { padding: 20rpx; box-sizing: border-box; } .status { font-size: 32rpx; font-weight: bold; margin-bottom: 30rpx; color: #1989fa; display: flex; align-items: center; } .point-count { font-size: 24rpx; color: #666; margin-left: 20rpx; font-weight: normal; } .location-info { font-size: 28rpx; margin-bottom: 20rpx; color: #333; line-height: 40rpx; } /* 轨迹滚动容器样式 */ .track-scroll-container { margin: 20rpx 0; } .track-title { font-size: 26rpx; color: #333; margin-bottom: 10rpx; display: block; font-weight: 400; } .track-scroll { border: 1px solid #e5e5e5; border-radius: 12rpx; background-color: #fafafa; overflow: hidden; } .track-list { padding: 10rpx; } /* 无点位提示 */ .track-empty { font-size: 24rpx; color: #999; text-align: center; padding: 80rpx 0; } /* 点位项样式 */ .track-item { display: flex; padding: 12rpx 0; border-bottom: 1px solid #eee; } .track-item:last-child { border-bottom: none; } .track-item-index { width: 40rpx; height: 40rpx; background-color: #1989fa; color: white; border-radius: 50%; font-size: 22rpx; display: flex; align-items: center; justify-content: center; margin-right: 15rpx; flex-shrink: 0; } .track-item-content { flex: 1; } .track-item-row { font-size: 22rpx; color: #333; margin-bottom: 6rpx; display: flex; } .track-item-row:last-child { margin-bottom: 0; } .label { color: #666; width: 120rpx; flex-shrink: 0; } .value { flex: 1; word-break: break-all; } /* 按钮样式 */ button { margin-bottom: 20rpx; height: 80rpx; font-size: 28rpx; border-radius: 16rpx; } .start-btn { background-color: #1989fa; color: white; } .stop-btn { background-color: #ff4d4f; color: white; } .clear-btn { background-color: #f5f5f5; color: #333; border: 1px solid #eee; } </style>上方代码startContinuousLocation手机黑屏后不调用,打开页面又报错定位失败: ‍[⁠uts.sdk.modules.DCloudUniLocation.GetLocationFailImpl⁠]‍ {cause: null, data: null, errCode: 1505600, errMsg: "location fail: timeout", errSubject: "uni-location", ⁠...⁠} at utils/location.uts:189 14:02:29.777 定位失败: location fail: timeou,过一会重新调用,uniapp X开发引擎,uts语言
最新发布
11-25
vue左侧动态菜单栏实现<template> <div class="toubu"> <div class="header" v-if="this.caidanqiehuan == &#39;xian1&#39;"> <keep-alive> <Map class="dzMap" v-if="$route.meta.showMap"> <div class="header-left2"> <nav> <div v-for="item in caidanlan" :key="item.id" :class=" $route.name === item.name ? &#39;left-beijing&#39; : &#39;left-yanse&#39; " @click="handleTabClick(item.id)" > <router-link :to="{ name: item.name }" class="kk"> <img class="header-image" :src="item.image" alt="" /> <p>{{ item.name }}</p> </router-link> </div> </nav> </div> <div class="header-right1"> <div class="right-content"> <router-view></router-view> </div> </div> </Map> <div class="dzMap1" v-else> <div class="header-left3"> <nav> <div v-for="item in caidanlan" :key="item.id" :class="ck === item.id ? &#39;left-beijing&#39; : &#39;left-yanse&#39;" @click="handleTabClick(item.id)" > <router-link :to="{ name: item.name }" class="kk"> <img class="header-image" :src="item.image" alt="" /> <p>{{ item.name }}</p> </router-link> </div> </nav> </div> <div class="header-right2"> <div class="right-content"> <router-view></router-view> </div> </div> </div> </keep-alive> </div> </div> </template> <script> import router from "@/router"; import { RouterLink, RouterView } from "vue-router"; import Map from "@/views/qxjcfwpt/Map.vue"; import MapView from "@/views/qxjcfwpt/dysjrh/components/MapView.vue"; export default { name: "qxsjcxtj-page", components: { Map, MapView }, data() { return { caidanqiehuan: "xian1", tabPosition: "left", ck: 1, e: 1, routes: ["地灾预警"], activeIndex: "", isActive: "", caidanlan: [], //地图类数据 overViewLayer: [], Map: null, dataMapLayer: {}, //梦图矢量地图服务 // 1、监听当前视口的范围 CurMapExtent: [], //;墨卡托范围 MapServiceLayers: [], //复位数据 initCenter: "", defaultProps: { children: "children", label: "label", }, menuDataParsed: null, // 缓存解析后的菜单数据 }; }, mounted() { this.handleTabClick(this.e); this.caidan(); }, methods: { // 动态菜单 caidan() { if (!this.menuDataParsed) { const menuData = localStorage.getItem("menu"); if (menuData) { this.menuDataParsed = JSON.parse(menuData); } else { console.error("Menu data not found in localStorage"); return; } } const parsedData = this.menuDataParsed; let children1 = parsedData[0].children.find((item) => { return ( item.name === "实况信息" && Array.isArray(item.children) && item.children.length > 0 ); })?.children || []; this.caidanlan = children1.map((item) => ({ ...item, image: require(`@/assets/svg/${item.name}.png`), // 动态处理图片路径 })); if (!this.caidanlan.length) return; const first = this.caidanlan[0].name; this.routes = [first]; this.activeIndex = first; this.ck = this.caidanlan[0].id; console.log(first, "66"); /* 只在当前路由就是 /hy 时才重定向 */ if (this.$route.path === "/skxx" || this.$route.name === "实况信息") { this.$router.replace({ name: first }); } // } }, handleTabClick(e) { console.log(e, "77"); this.ck = e; // 获取当前路由 const currentRoute = this.$route; // 获取当前路由的名称 const currentRouteName = currentRoute.name; // 获取当前路由的完整路径 const currentRoutePath = currentRoute.path; }, }, watch: { $route(newRoute) { console.log(newRoute, "777"); // 检查数组中是否已经包含当前路由的名称 if (!this.routes.includes(newRoute.name)) { this.routes.push(newRoute.name); } this.activeIndex = newRoute.name; }, }, }; </script> <style lang="less" scoped> .header-left2::-webkit-scrollbar { display: none; /* 隐藏滚动条 */ } .header-left3::-webkit-scrollbar { display: none; /* 隐藏滚动条 */ } .header { width: 100vw; height: 91vh; display: flex; // border: 1px solid red; overflow: hidden; position: relative; .header-right { flex: 1; // border: 1px solid black; background-color: #eee; .right-botton { width: 100%; height: 2.5rem; display: flex; align-items: center; flex-direction: row; // border: 1px solid black; background-color: #b8daf6; .kkk { width: 7rem; height: 2rem; // border: 1px solid black; color: #297dd3; border: 1px solid #297dd3; font-size: 0.875rem; display: flex; align-items: center; justify-content: center; background-color: #e5f1ff; margin-left: 0.9375rem; border-radius: 0.3125rem; // font-weight: bold; font-family: "思源黑体"; .anniu { margin-left: 0.375rem; font-size: 0.75rem; } } .kkk1 { width: 7rem; height: 2rem; color: #297dd3; font-size: 0.875rem; display: flex; align-items: center; justify-content: center; background-color: #92c0ec; border: 1px solid #297dd3; margin-left: 0.9375rem; border-radius: 0.3125rem; // font-weight: bold; font-family: "思源黑体"; .anniu { margin-left: 0.375rem; font-size: 0.75rem; } } } .right-content { width: 100%; height: 95%; background-color: #eee; position: relative; // border: 1px solid black; } } .header-right1 { // border: 1px solid black; background-color: #eee; position: relative; pointer-events: auto; .right-content { width: 100%; height: 100%; background-color: #fff; // border: 1px solid black; } } .header-right2 { flex: 1; // border: 1px solid black; background-color: #eee; .right-content { width: 100%; height: 100%; background-color: #fff; // border: 1px solid black; } } .header-left { width: 15rem; height: 100%; // border: 1px solid black; display: flex; flex-direction: column; align-items: center; background-color: #1f75cd; .header-image { width: 1.25rem; margin-right: 0.75rem; margin-left: 2.25rem; margin-top: 0.125rem; } .left-yanse { width: 15rem; height: 3.75rem; display: flex; align-items: center; justify-content: center; } .kk { width: 15rem; height: 3.75rem; display: flex; align-items: center; p { font-size: 1rem; } } .left-yanse p { color: white; } .left-beijing { width: 15rem; height: 3.75rem; display: flex; align-items: center; justify-content: center; background: url(@/assets/image/15.png); background-size: 100% 100%; background-position: center; background-repeat: no-repeat; } .left-beijing p { color: white; } } .header-left1 { width: 4rem; height: 100%; // border: 1px solid black; display: flex; flex-direction: column; align-items: center; background-color: #1f75cd; .header-image { width: 1.25rem; } .left-yanse { width: 4rem; height: 3.75rem; // background-color: #2c72ad; display: flex; align-items: center; justify-content: center; } .kk { width: 4rem; height: 3.75rem; display: flex; align-items: center; justify-content: center; p { font-size: 1rem; } } .left-yanse p { color: white; } .left-beijing { width: 4rem; height: 3.75rem; display: flex; align-items: center; justify-content: center; background: url(@/assets/image/15.png); background-size: 100% 100%; background-position: center; background-repeat: no-repeat; } .left-beijing p { color: white; } } .header-left2 { width: 6rem; height: 100%; // border: 1px solid black; // background-color: #eee; display: flex; flex-direction: column; align-items: center; // padding-top: 0.625rem; // background-color:#eee; overflow: auto; pointer-events: auto; // position: absolute; // top:0; // left:-100rem; .header-image { width: 2rem; display: flex; align-items: center; justify-content: center; // border: 1px solid black; } .left-yanse { width: 5rem; height: 4rem; display: flex; align-items: center; justify-content: center; background-color: #1f75cd; // border: 1px solid black; margin-top: 0.375rem; border-radius: 0.375rem; } .left-yanse p { color: white; } .kk { width: 15rem; height: 3.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center; p { font-size: 0.8rem; } } .left-beijing { width: 5rem; height: 4rem; display: flex; align-items: center; justify-content: center; border-radius: 0.375rem; margin-top: 0.375rem; background-color: #f59a23; } .left-beijing p { color: white; } } .header-left3 { width: 6rem; height: 100%; // border: 1px solid black; // background-color: #eee; display: flex; flex-direction: column; align-items: center; // padding-top: 0.625rem; // background-color:#eee; overflow: auto; .header-image { width: 2rem; display: flex; align-items: center; justify-content: center; // border: 1px solid black; } .left-yanse { width: 5rem; height: 4rem; display: flex; align-items: center; justify-content: center; background-color: #1f75cd; // border: 1px solid black; margin-top: 0.375rem; border-radius: 0.375rem; } .left-yanse p { color: white; } .kk { width: 15rem; height: 3.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center; p { font-size: 0.8rem; } } .left-beijing { width: 5rem; height: 4rem; display: flex; align-items: center; justify-content: center; border-radius: 0.375rem; margin-top: 0.375rem; background-color: #f59a23; } .left-beijing p { color: white; } } .dzMap { width: 100%; height: 100%; // border: 1px solid red; display: flex; position: absolute; } .dzMap1 { width: 100%; height: 100%; // border: 1px solid red; position: absolute; display: flex; } } </style> 我的代码再点击左侧菜单时,右边的页面反应过慢,过了一会才跳转过来怎么优化这个问题
10-12
<template> <view class="page-wrap"> <view class="mod-nav-bar"> <view class="fixed-wrap"> <view class="status-bar"></view> <view class="title-bar"> <view class="arrow-wrap" v-if="showBack" @click.stop="navBack"> <uni-icons class="icon" type="left" size="28" :color="titleColor"></uni-icons> </view> <view class="text-wrap"> 百腾高盈官方商城 </view> <view class="menu-wrap"> </view> </view> </view> <view class="block-wrap"></view> </view> <mod-search @on-confirm="onSearch" v-model:keyword="searchVal"></mod-search> <view class="container1"> <scroll-view class="main" scroll-y :scroll-top="mainScrollTop" scroll-with-animation @scroll="onMainScroll"> <view class="group" v-for="(group,index) in categoryList" :key="group._id" :id="`module-${group._id}`"> <view class="name"> {{group.name}} </view> <view class="list"> <view class="item" v-for="(goods,index) in group.goods" :key="index"> <view class="active2"> <card-goods-info class="card" :info="goods" @select-buy="showSkuPop" :type="1"></card-goods-info> </view> </view> </view> </view> </scroll-view> </view> <view class="shop-bar"> <view class="content"> <view class="left"> <view class="icon-wrap" @click="openCartPop"> <view class="iconfont "> <image class="img2" src="/static/images/购物车灰.png" mode="s"></image> </view> <view class="tag" v-if="cartStore1.goodsTotal>0">{{cartStore1.goodsTotal}}</view> </view> <view class="price-wrap"> <text>合计:</text> <text class="num">¥{{formatprice(cartStore1.priceTotal)}}</text> </view> </view> <view class="right"> <button class="settle">去结算 </button> </view> </view> </view> <uni-popup ref="skuPopRef" type="bottom" :safe-area="false"> <view class="sku-pop-wrap"> <shop-sku class="active1" :info="currGoods" v-model:sku-id="currSkuId" @close="closeSkuPop"> </shop-sku> </view> </uni-popup> <uni-popup ref="cartPopRef" type="bottom" :safe-area="false"> <view class="cart-pop-wrap"> <shop-cart class="active3"></shop-cart> </view> </uni-popup> </view> </template> <script setup> /*该组件为页面组件,属于最高级的父组件*/ import { useNavBarStyle } from &#39;@/utils/system.js&#39;; import shopcartVue from &#39;@/components/shop-cart/shop-cart.vue&#39;; import cardGoodsInfoVue from "@/components/card-goods-info/card-goods-info.vue" import modNavBarVue from "@/components/mod-nav-bar/mod-nav-bar.vue" import { computed, unref, ref, nextTick } from "vue" import { navBarH } from "@/utils/system.js" import { SYSTEM_WINDOW_INFO } from "@/utils/confilg.js" import { useGoodsCategoryApi, useGoodsDetail } from "@/apis/goods.js" import { formatprice } from "@/utils/format.js" import { useCartStore } from "@/stores/carts.js" //它是 cart.js的父级,引入了其接受的函数值 import { routerTo } from "@/utils/common.js" defineOptions({ options: { styleIsolation: &#39;shared&#39; } }) const {statusBarHeight,titleBarHeight,headHeight} = useNavBarStyle(); const props = defineProps({ title:{ type:String, default:"" }, titleColor:{ type:String, default:&#39;#000&#39; } }) const showBack = getCurrentPages().length > 1 const cartStore1 = useCartStore(); //引入useCartStore函数,获取数值信息 const { data: categoryList = [] } = useGoodsCategoryApi(); const { data: goodsDetail = {} } = useGoodsDetail(); const currentClassId = ref(""); const mainScrollTop = ref(0) const skuPopRef = ref(null); const currSkuId = ref(goodsDetail?.sku?.[0]?._id || ""); const cartPopRef = ref(null); const currGoods = ref({}); const searchVal = ref(""); const containerHeight = computed(() => { let tabBarH = 0; // #ifdef H5 tabBarH = 50 // #endif return `${SYSTEM_WINDOW_INFO.windowHeight - unref(navBarH) - 45 - uni.rpx2px(100) - tabBarH }px ` }) const onClassTab = (item) => { currentClassId.value = item._id; mainScrollTop.value = item.top; } //每栏参数 const calcSize = () => { let h = 0; categoryList.forEach((item, index) => { const view = uni.createSelectorQuery().select(`#module-${item._id}`); //获取后台当前位置ID view.fields({ size: true }, data => { item.top = Math.floor(h) h += data.height }).exec(); }) } //定位专注栏,计算出所需位置 const onMainScroll = (e) => { let scrollTop = e.detail.scrollTop; let results = categoryList.filter(item => item.top <= scrollTop + 2).reverse() //获取数据结果,并且翻转 if (results.length > 0) currentClassId.value = results[0]._id; } //监听滑动的栏位 const showSkuPop = (e) => { //console.log(e._id) currGoods.value = goodsDetail; currSkuId.value = goodsDetail?.sku?.[0]?._id || " "; skuPopRef.value.open(); } const closeSkuPop = () => { skuPopRef.value.close(); } const openCartPop = () => { cartPopRef.value.open(); } const onSearch = () => { routerTo("/pages/shop/search/search?keyword=" + unref(searchVal)) } nextTick(() => { calcSize(); if (categoryList[0]) onClassTab(categoryList[0]) }) </script> <style lang="scss" > .page-wrap { .mod-nav-bar{ width: 750rpx; .fixed-wrap{ position: fixed; left:0; top:0; width: 100%; background: #fff; z-index:8000; .status-bar{ width: 100%; height: v-bind(statusBarHeight); } .title-bar{ display: flex; width: 100%; text-align: center; justify-content: space-between; align-items: center; height: v-bind(titleBarHeight); color:v-bind(titleColor); padding:0 32rpx; font-size: 32rpx; .arrow-wrap{ height: 100%; width:80rpx; flex-shrink: 0; display: flex; align-items: center; } .text-wrap{ flex:1; text-align: center; font-weight: bolder; } .menu-wrap{ height:100%; width: 80rpx; flex-shrink: 0; } } } .block-wrap{ width: 100%; height: v-bind(headHeight); } } .container1 { display: flex; justify-content: space-between; height: v-bind(containerHeight); .aside { width: 200rpx; height: 100%; background: #f9f9f9; flex-shrink: 0; .item { align-items: center; justify-content: center; width: 100%; height: 100rpx; font-size: 28rpx; color: #666; position: relative; &.active { color: $uni-color-primary; background: #fff; &::after { content: ""; display: block; position: absolute; left: 0; top: 50%; transform: translateY(-50%); width: 8rpx; height: 36rpx; background: #000; } } } } .main { flex:1; height: 100%; .group { gap: 30rpx; .name { gap: 24rpx; font-size: 26rpx; color: #333; padding: 10rpx 10rpx; position: sticky; top: 0; left: 0; background: #fff; font-weight: bold; } .list { padding: 10rpx; padding-top: 0; display: grid; gap: 10rpx; .item { /*.active2 { .card { .card-goods-item{ height: 180rpx; display: flex; justify-content: space-between; align-items: center; gap: 14rpx; border-bottom: 20px #999; .card-left { flex-shrink: 0; height: 100%; aspect-ratio: 1 / 1; border-radius: 6rpx; overflow: hidden; gap: 30rpx; .img { width: 100%; height: 100%; } } .card-right { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: space-between; .top-box { .title { font-size: 28rpx; color: #000; @include text-ellipsis(2); } .sku { display: flex; align-items: center; flex-wrap: wrap; margin-top: 10rpx; .tag { padding: 6rpx 10rpx; font-size: 20rpx; color: #333; background-color: #f0f0f0; border-radius: 4rpx; } } } .bottom-box { display: flex; align-items: flex-end; justify-content: space-between; .left { .price-wrap { font-size: 22rpx; .new { font-weight: bolder; color: $uni-color-error; .big { font-size: 28rpx; ; } } .old { font-size: 22rpx; color: #999; text-decoration: line-through; } } } .right { .buy { font-size: 24rpx; background: $uni-color-primary; border-radius: 40rpx; padding: 12rpx 24rpx; color: #fff; } } } } } } }*/ } } } }} .shop-bar { position: fixed; width: 100%; left: 0; //#ifdef H5 bottom: 50px; //#endif //#ifndef H5 bottom: 0; //#endif .content { position: relative; display: flex; justify-content: space-between; align-items: center; width: 100%; height: 100rpx; padding: 0 24rpx; box-sizing: border-box; background-color: #6a6a6a; .left { display: flex; align-items: center; height: 100%; .icon-wrap { display: flex; justify-content: center; align-items: center; width: 112rpx; height: 112rpx; border-radius: 50%; background-color: $uni-color-primary; position: absolute; top: -30rpx; left: 24rpx; .iconfont { justify-content: center; font-size: 30rpx; color: #fff; height: 100%; flex-shrink: 0; height: 100%; flex: auto; display: flex; flex-direction: column; justify-content: center; align-items: center; .img2 { justify-content: center; align-items: center; height: 50%; width: 50%; z-index: 8000; position: relative; } } .tag { position: absolute; right: 0; top: 0rpx; min-width: 40rpx; height: 40rpx; padding: 10rpx; font-size: 22rpx; color: #fff; display: flex; align-items: center; justify-content: center; background-color: $uni-color-error; border-radius: 40rpx; } } .price-wrap { display: flex; align-items: center; margin-left: 120rpx; color: #fff; font-size: 22rpx; .num { font-size: 36rpx; } } } .right { display: flex; justify-content: flex-end; align-items: center; height: 100%; .settle { padding: 0 32rpx; height: 66rpx; line-height: 66rpx; font-size: 32rpx; color: #fff; background-color: $uni-color-error; border-radius: 66rpx; } } } } .sku-pop-wrap{ background: #fff; min-height: 300rpx; padding: 32rpx; /* #ifdef H5 */ padding: 32rpx 32rpx 66px; /* #endif */ border-radius: 20rpx 20rpx 0; } .cart-pop-wrap { background: #fff; min-height: 300rpx; padding: 32rpx; /* #ifdef H5 */ padding: 32rpx 32rpx 66px; /* #endif */ border-radius: 20rpx 20rpx 0; } } </style> 分析在H端显示正常,但是在小程序端显示异常问题
09-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值