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

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误类似:
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
<script setup> import { ref, onMounted } from &#39;vue&#39;; import { onShow } from &#39;@dcloudio/uni-app&#39;; // 响应式数据 const surveyList = ref([]); const total = ref(0); const loading = ref(false); // 获取问卷数据 const fetchSurveyData = async () => { try { loading.value = true; // 使用uni.request发送请求 const [error, res] = await uni.request({ url: &#39;http://172.26.26.43/dev-api/wjdc/wj/listTx&#39;, method: &#39;GET&#39;, data: { pageNum: 1, pageSize: 10, dcWjTitle: &#39;&#39;, dcId: &#39;&#39;, dcDept: &#39;&#39; } }); if (error) throw error; // 处理响应数据 const response = res.data; if (response.code === 200) { surveyList.value = response.rows; total.value = response.total; } else { throw new Error(response.msg || &#39;请求失败&#39;); } } catch (error) { uni.showToast({ title: error.message || &#39;加载失败&#39;, icon: &#39;none&#39;, duration: 2000 }); } finally { loading.value = false; } }; // 使用onShow替代onMounted确保每次进入页面都刷新 onShow(() => { fetchSurveyData(); }); </script> <template> <view class="container"> <!-- 自定义加载状态 --> <view v-if="loading" class="loading-container"> <view class="loading-spinner"></view> <text class="loading-text">加载中...</text> </view> <!-- 数据展示 --> <template v-else> <text class="total">共 {{ total }} 条记录</text> <view v-for="(item, index) in surveyList" :key="index" class="card"> <view class="title">{{ item.dcWjTitle }}</view> <view class="info"> <text>部门: {{ item.dcDept }}</text> <text>创建人: {{ item.createBy }}</text> </view> <view class="meta"> <text>创建时间: {{ item.createTime }}</text> <text class="score">得分: {{ item.score }}</text> </view> </view> <!-- 空数据提示 --> <view v-if="surveyList.length === 0" class="empty"> <text>暂无数据</text> </view> </template> </view> </template> <style scoped> .container { padding: 20rpx; background-color: #f5f5f5; min-height: 100vh; } /* 自定义加载状态样式 */ .loading-container { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40rpx 0; } .loading-spinner { width: 60rpx; height: 60rpx; border: 6rpx solid #f3f3f3; border-top: 6rpx solid #3498db; border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 20rpx; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .loading-text { color: #666; font-size: 28rpx; } /* 数据样式 */ .total { display: block; margin: 20rpx 0; padding: 0 20rpx; color: #888; font-size: 28rpx; } .card { padding: 30rpx; margin-bottom: 30rpx; border-radius: 16rpx; background-color: #fff; box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.05); } .title { font-size: 34rpx; font-weight: bold; margin-bottom: 20rpx; color: #333; } .info { display: flex; justify-content: space-between; color: #666; font-size: 28rpx; margin-bottom: 15rpx; } .meta { display: flex; justify-content: space-between; color: #999; font-size: 26rpx; margin-top: 15rpx; } .score { color: #e74c3c; font-weight: bold; } .empty { text-align: center; padding: 100rpx 0; color: #999; font-size: 32rpx; } </style> 我的数据加载板块参照代码:<template> <div class="detail-container"> <!-- 索引板块卡片 --> <el-card class="index-card"> <!-- 表单区域 --> <el-form :model="formData" label-position="top" ref="indexForm" class="mobile-form" > <!-- 问卷标题 --> <el-form-item label="问卷标题:" prop="dcWjTitle"> <el-input v-model="formData.dcWjTitle" placeholder="请输入问卷标题" clearable :prefix-icon="Document" /> </el-form-item> <div class="form-row"> <!-- 被测评人 --> <el-form-item label="被测评人:" prop="dcId" class="inline-form-item"> <el-select v-model="formData.dcId" multiple filterable remote reserve-keyword clearable placeholder="请选择被测评人" :remote-method="searchBdr" :loading="bdrLoading" @focus="handleBdrFocus" > <el-option v-for="item in bdrOptions" :key="item.dcId" :label="item.dcName" :value="item.dcId" /> </el-select> </el-form-item> <!-- 人员部门 --> <el-form-item label="人员部门:" prop="dcDept" class="inline-form-item"> <el-input v-model="formData.dcDept" placeholder="请输入人员部门" clearable :prefix-icon="OfficeBuilding" /> </el-form-item> </div> <!-- 提交状态 --> <el-form-item label="提交状态:" prop="state"> <el-select v-model="formData.state" placeholder="请选择提交状态" clearable class="mobile-select" > <el-option label="已提交" :value="1" /> <el-option label="未提交" :value="0" /> </el-select> </el-form-item> <!-- 新增:按钮区域 --> <el-form-item class="button-group"> <el-button type="primary" @click="handleSearch" class="action-button" :icon="Search" > 搜索 </el-button> <el-button @click="handleReset" class="action-button" :icon="Refresh" > 重置 </el-button> </el-form-item> </el-form> </el-card> <!-- 数据显示板块 --> <el-card class="data-card"> <template #header> <div class="card-header"> <el-button type="primary" size="small" :icon="Refresh" @click="fetchData" > 刷新数据 </el-button> </div> </template> <!-- 数据加载 --> <div v-loading="loading" class="card-container"> <div v-for="(item, index) in tableData" :key="item.dcWjId" class="data-card-item" > <!-- 顶部:序号和问卷标题 --> <div class="card-header-section"> <!-- <div class="card-id">序号{{ item.dcWjId }}</div> --> <div class="card-title">{{ item.dcWjTitle }}</div> </div> <!-- 中间:其他数据 --> <div class="card-body-section"> <div class="card-row"> <span class="card-label">被测评人:</span> <span class="card-value">{{ item.dcName }}</span> </div> <div class="card-row"> <span class="card-label">部门:</span> <span class="card-value">{{ item.dcDept }}</span> </div> <div class="card-row"> <span class="card-label">创建时间:</span> <span class="card-value">{{ item.createTime }}</span> </div> <div class="card-row"> <span class="card-label">提交时间:</span> <span class="card-value">{{ item.updateTime || &#39;-&#39; }}</span> </div> </div> <!-- 底部:状态、得分和操作按钮 --> <div class="card-footer-section"> <div class="status-container"> <el-tag :type="item.state === &#39;1&#39; ? &#39;success&#39; : &#39;info&#39;"> {{ item.state === &#39;1&#39; ? &#39;已提交&#39; : &#39;未提交&#39; }} </el-tag> <div class="score">总分: {{ item.score || &#39;0&#39; }}</div> </div> <el-button size="small" type="primary" @click="handleView(item)" class="action-btn" > 编辑/查看 </el-button> </div> </div> <!-- 空数据提示 --> <el-empty v-if="tableData.length === 0" description="暂无数据" /> </div> <!-- 分页控件 --> <div class="pagination-container"> <el-pagination v-model:current-page="pagination.current" v-model:page-size="pagination.size" :page-sizes="[5, 10, 20, 50]" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total" @size-change="handleSizeChange" @current-change="handlePageChange" /> </div> </el-card> </div> </template> <script setup> // 确保正确导入所有 Vue 函数 import { ref, reactive, onMounted, onUnmounted } from &#39;vue&#39;; import axios from &#39;axios&#39;; import { Document, User, OfficeBuilding, Search, Refresh } from &#39;@element-plus/icons-vue&#39;; import { ElMessage } from &#39;element-plus&#39;; import { useRouter } from &#39;vue-router&#39;; const router = useRouter(); // 环境变量管理API地址 const API_BASE = import.meta.env.VITE_API_BASE || &#39;http://172.26.26.43/dev-api&#39;; const API_URL = `${API_BASE}/wjdc/wj/listTx`; const BDR_API_URL = `${API_BASE}/wjdc/wj/getBdrList`; // 被测评人相关数据 const bdrOptions = ref([]); // 被测评人选项列表 const bdrLoading = ref(false); // 加载状态 const bdrCache = ref([]); // 缓存所有被测评人数据 // 表单数据 const formData = reactive({ dcWjTitle: &#39;&#39;, dcId: [], dcDept: &#39;&#39;, state: null }); // 表格数据 const tableData = ref([]); const loading = ref(false); // 分页配置 const pagination = reactive({ current: 1, size: 10, total: 0 }); // 表单引用 const indexForm = ref(null); // 请求取消令牌 let cancelTokenSource = axios.CancelToken.source(); // 处理被测评人输入框获取焦点 const handleBdrFocus = () => { if (bdrCache.value.length === 0) { fetchBdrList(&#39;&#39;); } }; // 获取被测评人列表 const fetchBdrList = async (keyword = &#39;&#39;) => { const token = getAuthToken(); if (!token) return; bdrLoading.value = true; try { const response = await axios.get(BDR_API_URL, { headers: { &#39;Authorization&#39;: `Bearer ${token}` } }); // 判断返回的数据是否是数组 if (Array.isArray(response.data)) { // 缓存所有数据 bdrCache.value = response.data; // 根据关键字过滤 if (keyword) { const searchTerm = keyword.toLowerCase(); bdrOptions.value = bdrCache.value.filter(item => item.dcName && item.dcName.toLowerCase().includes(searchTerm) ).slice(0, 10); // 最多显示10条 } else { // 未输入关键字时显示前10条 bdrOptions.value = bdrCache.value.slice(0, 10); } } else { // 如果不是数组,则按照原有格式处理(假设有code和data) if (response.data && response.data.code === 200) { bdrCache.value = response.data.data || []; // 同样的过滤逻辑 if (keyword) { const searchTerm = keyword.toLowerCase(); bdrOptions.value = bdrCache.value.filter(item => item.dcName.toLowerCase().includes(searchTerm) ).slice(0, 10); } else { bdrOptions.value = bdrCache.value.slice(0, 10); } } else { const msg = response.data?.msg || &#39;返回数据格式不正确&#39;; ElMessage.error(&#39;获取被测评人列表失败: &#39; + msg); } } } catch (error) { console.error(&#39;获取被测评人列表失败:&#39;, error); ElMessage.error(&#39;获取被测评人列表失败&#39;); } finally { bdrLoading.value = false; } }; // 搜索被测评人(防抖) let searchBdrTimer = null; const searchBdr = (query) => { if (searchBdrTimer) clearTimeout(searchBdrTimer); searchBdrTimer = setTimeout(() => { if (bdrCache.value.length === 0) { fetchBdrList(query); } else { // 本地过滤 if (query) { const searchTerm = query.toLowerCase(); bdrOptions.value = bdrCache.value.filter(item => item.dcName.toLowerCase().includes(searchTerm) ).slice(0, 10); } else { bdrOptions.value = bdrCache.value.slice(0, 10); } } }, 300); }; // 获取认证令牌 const getAuthToken = () => { const token = localStorage.getItem(&#39;token&#39;); if (!token) { ElMessage.warning(&#39;请先登录&#39;); router.push(&#39;/login&#39;); return null; } return token; }; // 搜索按钮处理函数 - 防抖 let searchTimer = null; const handleSearch = () => { // 检查被测评人选择数量 if (formData.dcId.length > 1) { ElMessage.warning({ message: &#39;当前只能搜索一个被测人员&#39;, duration: 3000 }); return; } if (searchTimer) clearTimeout(searchTimer); searchTimer = setTimeout(() => { pagination.current = 1; fetchData(); }, 300); }; // 重置按钮处理函数 const handleReset = () => { if (indexForm.value) { indexForm.value.resetFields(); // 确保重置后 dcId 是空数组 formData.dcId = []; } handleSearch(); }; // 编辑/查看 const handleView = (row) => { router.push({ name: &#39;Operation&#39;, // 路由名称 params: { id: row.dcWjId // 传递问卷ID作为参数 } }); }; // 分页大小改变 const handleSizeChange = (size) => { pagination.size = size; fetchData(); }; // 页码改变 const handlePageChange = (page) => { pagination.current = page; fetchData(); }; // 获取数据 const fetchData = async () => { // 获取认证令牌 const token = getAuthToken(); if (!token) return; // 取消之前的请求 if (cancelTokenSource) { cancelTokenSource.cancel(&#39;请求被取消&#39;); } cancelTokenSource = axios.CancelToken.source(); loading.value = true; try { // 构造请求参数 const params = { pageNum: pagination.current, pageSize: pagination.size, ...formData, // 安全处理:确保 dcId 是数组再 join dcId: Array.isArray(formData.dcId) ? formData.dcId.join(&#39;,&#39;) : &#39;&#39; // 将数组转换为逗号分隔的字符串 }; // 调用API - 添加认证头 const response = await axios.get(API_URL, { params, cancelToken: cancelTokenSource.token, headers: { &#39;Content-Type&#39;: &#39;application/json&#39;, &#39;Authorization&#39;: `Bearer ${token}` } }); // 处理响应数据 const { data } = response; if (data && data.code === 200) { // 修改点:直接使用 data.rows 和 data.total tableData.value = data.rows || []; pagination.total = data.total || 0; // 空数据提示 if (tableData.value.length === 0) { ElMessage.info(&#39;没有找到匹配的数据&#39;); } } else { const errorMsg = data?.msg || &#39;未知错误&#39;; console.error(&#39;API返回错误:&#39;, errorMsg); ElMessage.error(`请求失败: ${errorMsg}`); tableData.value = []; pagination.total = 0; } } catch (error) { // 处理认证失败 if (error.response && error.response.status === 401) { ElMessage.error(&#39;认证过期,请重新登录&#39;); localStorage.removeItem(&#39;token&#39;); router.push(&#39;/login&#39;); return; } // 忽略取消请求错误 if (!axios.isCancel(error)) { console.error(&#39;获取数据失败:&#39;, error); const errorMsg = error.response?.data?.message || &#39;网络请求失败&#39;; ElMessage.error(`请求失败: ${errorMsg}`); tableData.value = []; pagination.total = 0; } } finally { loading.value = false; } }; // 页面加载时获取初始数据 onMounted(() => { fetchData(); }); // 组件卸载时取消所有请求 onUnmounted(() => { if (cancelTokenSource) { cancelTokenSource.cancel(&#39;组件卸载,取消请求&#39;); } }); </script> <style scoped> .form-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 16px; } .inline-form-item { flex: 1; min-width: 250px; } .inline-form-item :deep(.el-form-item__label) { float: left; width: auto; padding-right: 12px; line-height: 32px; } .inline-form-item :deep(.el-form-item__content) { display: flex; flex: 1; } /* 移动端响应式 */ @media (max-width: 768px) { .form-row { flex-direction: column; gap: 16px; } .inline-form-item { min-width: 100%; } .inline-form-item :deep(.el-form-item__label) { float: none; width: 100%; padding-right: 0; padding-bottom: 8px; } } /* 卡片容器样式 */ .card-container { display: grid; grid-template-columns: repeat(auto-fill, minmax(500px, 1fr)); gap: 16px; } /* 单个卡片样式 */ .data-card-item { background: #fff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); padding: 16px; display: flex; flex-direction: column; transition: all 0.3s ease; border: 1px solid #ebeef5; } .data-card-item:hover { transform: translateY(-4px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12); } /* 卡片头部(序号+标题) */ .card-header-section { padding-bottom: 12px; border-bottom: 1px solid #f0f2f5; margin-bottom: 12px; } .card-id { font-size: 14px; color: #909399; margin-bottom: 4px; } .card-title { font-size: 16px; font-weight: 600; color: #303133; line-height: 1.4; word-break: break-word; } /* 卡片主体(其他信息) */ .card-body-section { flex: 1; margin-bottom: 12px; } .card-row { display: flex; margin-bottom: 8px; font-size: 14px; } .card-label { color: #606266; min-width: 70px; text-align: right; } .card-value { color: #303133; flex: 1; word-break: break-word; } /* 卡片底部(状态+按钮) */ .card-footer-section { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; border-top: 1px solid #f0f2f5; } .status-container { display: flex; align-items: center; gap: 8px; } .score { font-size: 14px; color: #e6a23c; font-weight: 500; } .action-btn { flex-shrink: 0; } /* 移动端响应式 */ @media (max-width: 768px) { .card-container { grid-template-columns: 1fr; } .card-row { flex-direction: column; margin-bottom: 12px; } .card-label { text-align: left; margin-bottom: 4px; font-weight: 500; } .card-footer-section { flex-direction: column; align-items: stretch; gap: 12px; } .status-container { justify-content: space-between; } } /* 添加选择器样式 */ :deep(.el-select) .el-input__inner { height: auto !important; min-height: 44px; padding: 5px 15px; } /* 标签样式 */ :deep(.el-tag) { margin: 2px 6px 2px 0; } /* 下拉菜单样式 */ :deep(.el-select-dropdown) { max-height: 300px; overflow-y: auto; } .index-card { border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); } .card-header { font-size: 18px; font-weight: 600; color: #1a1a1a; } .mobile-form { :deep(.el-form-item__label) { font-weight: 500; margin-bottom: 6px; } :deep(.el-input__inner) { height: 44px; border-radius: 8px; } } .mobile-select { width: 100%; :deep(.el-input__inner) { height: 44px; } } /* 按钮区域样式 */ .button-group { display: flex; gap: 12px; margin-top: 16px; } .action-button { flex: 1; height: 46px; font-size: 16px; border-radius: 8px; } /* 移动端响应式调整 */ @media (max-width: 480px) { .button-group { flex-direction: column; gap: 10px; } .action-button { width: 100%; } } </style>
07-24
<template> <view class="bg-content"> <z-paging ref="paging1" v-model="dataList" @query="queryList"> <view slot="top"> <view class="tablesChange"> <view class="tables"> <u-tabs :list="tabsList4" @click="clickTabFn" :scrollable="true" lineColor="#FF6400" :activeStyle="{color: &#39;#303133&#39;,fontWeight: 600,transform: &#39;scale(1.05)&#39;,fontSize: &#39;31rpx&#39;}" :inactiveStyle="{color: &#39;#606266&#39;,fontWeight:500,transform: &#39;scale(1)&#39;,fontSize: &#39;31rpx&#39;}" itemStyle="padding-left: 30rpx; padding-right: 30rpx; height: 80rpx;"> </u-tabs> </view> </view> </view> <!-- <view class="my-evaluate f-jcsb f-a-i" @click="navMyevaluateFn" v-if="actTab==3"> <view class="f-a-i"> <u-icon type="eye" size="20" color="#fff"></u-icon> <u-icon name="chat" color="#999" size="18"></u-icon> 我的评价 </view> <view> <u-icon name="arrow-right" color="#999" size="18"></u-icon> </view> </view> --> <view> <view @click="jump()" class="list-cont" v-for="(item,index) in dataList" :key="index" > <canvas style="width:220rpx;height:86rpx;" canvas-id="colorCanvas"></canvas> <view class="top-flex"> <text class="grayfont">2025-7-10 11:29:15</text> <text style="font-weight: 500;">待支付</text> </view> <view class="main"> <image src="/static/images/tabbar/showroom_active.png" mode=""></image> <view class="main-msg"> <text class="font">东风风行E702022款500超享版</text> <view class="car-money"> <text class="blue-font">¥<text style="padding-right: 10rpx;">210000</text>元</text> </view> <view class="profit-estimate"> <text class="profit-label">预估可赚</text> <text class="profit-value">30000元</text> </view> </view> </view> <view class="main-bto"> <text>车辆年限:1年内</text> <text>公里数:1.78万公里</text> <text>使用性质:非营运</text> </view> </view> </view> </z-paging> </view> </template> <script> import { tabsList4 } from "@/data/tabsData2.js" export default { data() { return { tabsList4, actTab: -1, dataList: [], buttStyle: { width: &#39;160rpx&#39;, height: &#39;56rpx&#39;, marginLeft: &#39;16rpx&#39; }, imageUrl: &#39;https://cbl.diyouzhijia.com/static/images/ygctzmp/home/backgroundHeader.png&#39;, dominantColor: &#39;&#39;, topUpTypeShow: false, topUpType: &#39;ye&#39;, payPrice: 0, payData: { from: "", orderNo: "", payChannel: "yue", payType: "yue", scene: 0 } }; }, onLoad(){ this.getImageColor() }, methods: { // 加载图片时获取背景? async getImageColor() { try { // 1. 确保使用正确的Canvas上下文 const canvasId = &#39;colorCanvas&#39;; const ctx = uni.createCanvasContext(canvasId, this); // 2. 等待图片加载完成 await new Promise((resolve, reject) => { const img = new Image(); img.onload = () => resolve(img); img.onerror = reject; img.src = this.imageUrl; }); // 3. 绘制图片(使用明确尺寸) ctx.drawImage(this.imageUrl, 0, 0, 100, 100); // 4. 必须使用 draw(true) 同步绘制 await new Promise(resolve => ctx.draw(true, resolve)); // 5. 获取像素数据 const res = await new Promise((resolve, reject) => { uni.canvasGetImageData({ canvasId, x: 0, y: 0, width: 1, height: 1, success: resolve, fail: reject }); }); // 6. 提取颜色(注意微信小程序返回的data是Uint8ClampedArray) const pixelData = res.data || []; const [r, g, b] = pixelData.slice(0, 3); this.dominantColor = `rgb(${r}, ${g}, ${b})`; console.log(&#39;成功获取主色调:&#39;, this.dominantColor); } catch (err) { console.error(&#39;颜色分析失败:&#39;, err); this.dominantColor = &#39;rgb(255,255,255)&#39;; // 默认白色 } }, jump(){ uni.navigateTo({ url:&#39;/pagesB/home/publish&#39; }) }, topUpTypeClose() { this.topUpTypeShow = false }, // 去支付 //详情 navParticularFn(item) { uni.navigateTo({ url:&#39;/pagesA/showroom/newPayOrder/detalorder?orderId=&#39;+item.id }) }, clickTabFn(tab) { this.actTab = tab.value this.$refs.paging1.refresh(); }, //订单列表 queryList(pageNo, pageSize) { // 此处请求仅为演示,请替换为自己项目中的请求 let obj = { page: pageNo, limit: pageSize, type: this.actTab } let arr=[ { name:&#39;1&#39;, value:&#39;2&#39; }, { name:&#39;2&#39;, value:&#39;3&#39; } ] this.$refs.paging1.complete(arr); // getInformationOrderList(obj).then(res => { // this.$refs.paging.complete(res.data.list); // }) }, }, onShow() { if (this.$refs.paging1) { this.$refs.paging1.refresh(); } } } </script> <style lang="scss" scoped> .bg-content { min-height: 100vh; background: #F6F7FB; } .order-list-butt { width: 100%; padding: 0 24rpx; .order-list-butt-go { width: 120rpx; font-size: 24rpx; font-weight: 400; color: #999999; image { width: 48rpx; height: 48rpx; } } .order-list-butt-refund { padding: 16rpx 24rpx; font-size: 24rpx; font-weight: 400; color: #111111; background: #F5F5F5; margin-top: 16rpx; } } .user-data { padding: 24rpx 24rpx 0 24rpx; .user-data-image { width: 48rpx; height: 48rpx; border-radius: 50%; background: #f5f5f5; image { width: 100%; height: 100%; } } .user-data-name { font-size: 28rpx; font-weight: 400; color: #000000; margin-left: 16rpx; } .user-data-state { font-size: 24rpx; font-weight: bold; color: #FF6400; } } .car-rental { width: calc(100% - 48rpx); margin: 24rpx 24rpx 0 24rpx; padding-bottom: 24rpx; border-bottom: 1rpx solid #eee; .car-rental-cont { height: 150rpx; width: calc(100% - 218rpx); margin-left: 16rpx; display: flex; flex-direction: column; justify-content: space-around; .car-rental-cont-name { font-size: 32rpx; font-weight: 400; color: #111111; } .car-rental-cont-price { font-size: 32rpx; font-weight: bold; color: #111111; } .car-rental-cont-total-payment { font-size: 24rpx; font-weight: 400; color: #666666; } } image { width: 202rpx; height: 150rpx; } } .list-cont { // width: calc(100% - 30rpx); margin: 24rpx; background: #fff; border-radius: 8rpx; padding-bottom: 24rpx; // border: 1px solid red; padding: 30rpx; .top-flex{ display: flex; width: 100%; padding-bottom: 26rpx; justify-content: space-between; align-items: center; border-bottom: 1px solid #DBDBDB; text{ font-size: 28rpx; color: #2F74FA; font-weight: 500; } .grayfont{ color: #666666; font-size: 28rpx; } } .main-bto{ display: flex; width: 100%; align-items: center; justify-content: space-between; color: #666666; font-size: 24rpx; text{ padding-top: 30rpx; } } .main{ display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #DBDBDB; padding-bottom: 30rpx; margin-top: 30rpx; image{ width: 259rpx; height: 180rpx; border-radius: 10rpx; } .main-msg{ flex: 1; height: 100%; margin-left: 30rpx; display: flex; flex-direction: column; justify-content: space-between; .car-money{ margin-top: 10rpx; .blue-font{ color: #FF6400; font-size: 24rpx; text{ font-size: 36rpx; } } } // .bg-money{ // width: 100%; // height: 44rpx; // margin-top: 10rpx; // font-size: 24rpx; // font-weight: 500; // color: white; // line-height: 44rpx; // // border: 1px solid #3E80F5; // background: url(&#39;https://cbl.diyouzhijia.com/static/images/ygcmp/home/yugu.png&#39;) no-repeat; // background-size: 100% 100%; // } .profit-estimate { display: flex; align-items: center; width: 100%; height: 48rpx; margin-top: 10rpx; // margin-bottom: 30rpx; color: white; background: url(&#39;https://cbl.diyouzhijia.com/static/images/ygcmp/home/yugu.png&#39;) no-repeat; background-size: 100% 100%; .profit-label { color: #ffffff; font-weight: 700; font-size: 24rpx; margin: 0 31rpx 0 13rpx; } .profit-value { flex: 1; text-align: center; font-weight: 700; color: #2f74fa; font-size: 32rpx; } } .font{ color: #333333; font-size: 28rpx; // margin-top: 10rpx; font-weight: 500; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; /* 限制显示的行数 */ overflow: hidden; text-overflow: ellipsis; } } } } .tab-list { background: #fff; overflow: auto; view { width: 88rpx; padding-bottom: 12rpx; border-bottom: 6rpx solid transparent; font-size: 29rpx; font-weight: bold; display: inline-block; color: #555555; text-align: center; } .act-tab { border-bottom: 6rpx solid #000; font-size: 29rpx; font-weight: bold; color: #222222; } } .act-flaf { width: calc(100% - 56rpx); margin-left: 24rpx; } .circle { width: 30rpx; height: 30rpx; border-radius: 50%; border: 2rpx solid #D7D7D7; } .my-evaluate { background: #fff; padding: 16rpx 24rpx; width: calc(100% - 48rpx); margin: 24rpx; border-radius: 8rpx; } .tablesChange{ // padding: 0px 30rpx; .tables{ background-color: white; // border-radius: ; border-radius: 20rpx 20rpx 0px 0px; padding: 30rpx 20rpx; padding-bottom: 0px; } } </style>上面代码中颜色分析失败: ReferenceError: Image is not defined报错;帮我写出完整可以用的getImageColor函数里的方法
07-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值