EP21 Promise封装request请求

文件路径: E:/homework/uniappv3tswallpaper/utils/requset.js

utils 文件夹中创建一个新的 request 文件。

const BaseUrl = "https://tea.qingnian8.com/api/bizhi"

export function request(config = {}) {
	return new Promise((resolve, reject) => {
		let {
			url,
			header = {},
			method = "GET"
		} = config

		url = BaseUrl + url
		header['access-key'] = "guagua"

		uni.request({
			url,
			header,
			method,
			success: res => {
				if (res.data.errCode === 0) {
					resolve(res)
				} else if (res.data.errCode === 400) {
					uni.showModal({
						title: '错误信息',
						content: res.data.errMsg,
						showCancel: false
					})
					reject(res.data)
				} else {
					uni.showToast({
						title: res.data.errMsg,
						icon: "none"
					})
					reject(res.data)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}

文件路径: E:/homework/uniappv3tswallpaper/api/apis.js

创建一个新的 api 文件。

import {
	request
} from "@/utils/requset.js"

export function apiGetBanner() {
	return request({
		url: "/homeBanner"
	})
}
export function apiGetDayRandom() {
	return request({
		url: "/randomWall"
	})
}

文件路径: E:/homework/uniappv3tswallpaper/pages/index/index.vue

修改后的 index 文件。

<template>
	<view class="homeLayout pageBg">
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<view class="banner">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true"
				indicator-color="rgba(255,255,255,0.5)" indicator-active-color="rgba(255,255,255,1)">
				<swiper-item v-for="item in bannerList" :key="item._id">
					<image :src="item.picurl" mode="scaleToFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20"></uni-icons>
				<text class="text">公告</text>
			</view>
			<view class="center">
				<swiper :autoplay="true" :interval="3000" :duration="1000" circular vertical>
					<swiper-item v-for="item in noticeList" :key="item._id">
						<navigator url="/pages/notice/detail">
							{{item.title}}
						</navigator>
					</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="forward" size="16" color="#333"></uni-icons>
			</view>
		</view>
		<view class="select">
			<common-title>
				<template #name>
					每日推荐
				</template>
				<template #custom>
					<view class="date">
						<uni-icons type="calendar"></uni-icons>
						<view class="text">
							<uni-dateformat :date="Date.now()" format="dd号" />
						</view>
					</view>
				</template>
			</common-title>
			<view class="content">
				<scroll-view scroll-x="true">
					<view class="box" v-for="item in randomList" :key="item._id" @click="goPreview">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="theme">
			<common-title>
				<template #name>
					专题精选
				</template>
				<template #custom>
					<navigator url="">More+</navigator>
				</template>
			</common-title>
			<view class="content">
				<theme-item v-for="item in 8"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue';
	import {
		apiGetBanner,
		apiGetDayRandom
	} from "@/api/apis.js"

	const bannerList = ref([]);
	const randomList = ref([])
	const noticeList = ref([])

	const getBanner = async () => {
		let res = await apiGetBanner()
		bannerList.value = res.data.data
	};
	const getDayRandom = async () => {
		let res = await apiGetDayRandom()
		randomList.value = res.data.data
	};
	const getNotice = async () => {
		let res = await uni.request({
			url: "https://tea.qingnian8.com/api/bizhi/wallNewsList",
			header: {
				'access-key': "guagua"
			},
			data: {
				select: true
			}
		})
		if (res.data.errCode === 0) {
			noticeList.value = res.data.data
		}
	}

	// 点击跳转到壁纸预览页面
	const goPreview = () => {
		uni.navigateTo({
			url: '/pages/preview/preview'
		});
	};

	getBanner()
	getDayRandom()
	getNotice()
</script>

<style lang="scss">
	.homeLayout {
		.banner {
			width: 750rpx;
			padding: 30rpx 0;

			swiper {
				width: 100%;
				height: 340rpx;

				&-item {
					width: 100%;
					height: 100%;
					padding: 0 30rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}

		.notice {
			margin: 0 30rpx;
			display: flex;
			flex-direction: row;
			flex-wrap: nowrap;
			align-content: center;
			justify-content: center;
			align-items: center;
			background: gray;
			border-radius: 80rpx;
			height: 80rpx;
			line-height: 80rpx;


			.left {
				width: 140rpx;
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-content: center;
				justify-content: center;
				align-items: center;

				:deep() {
					.uni-icons {
						color: $brand-theme-color !important;
					}
				}

				.text {
					color: $brand-theme-color;
					font-weight: 600;
					font-size: 28rpx;
				}
			}

			.center {
				flex: 1;
				height: 100%;

				swiper {
					height: 100%;

					&-item {
						// 以下三条是实现 文字长度超过显示宽度时展示省略号 的关键操作
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
						// 以上三条

						height: 100%;
						color: $text-font-color-3;
						font-size: 30rpx;

						// flex布局与 text-overflow: ellipsis;属性 冲突
						// display: flex;
						// flex-direction: row;
						// flex-wrap: nowrap;
						// align-content: center;
						// align-items: center;
						// justify-content: flex-start;

						align-content: end;
						align-items: end;
					}
				}
			}

			.right {
				width: 70rpx;
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-content: center;
				align-items: center;
				justify-content: center;
			}
		}

		.select {
			padding: 50rpx 30rpx 0 30rpx;

			scroll-view {
				white-space: nowrap;

				.box {
					display: inline-block;
					width: 200rpx;
					height: 430rpx;
					margin-right: 15rpx;

					image {
						height: 100%;
						width: 100%;
					}
				}

				:last-child {
					margin-right: 0;
					border-radius: 10rpx;
				}
			}

			.date {
				display: flex;
				flex-direction: row;
				flex-wrap: nowrap;
				align-content: center;
				justify-content: center;
				align-items: center;
				color: $brand-theme-color;

				:deep() {
					.uni-icons {
						color: $brand-theme-color !important;
					}
				}
			}
		}

		.theme {
			padding: 50rpx 30rpx;

			.content {
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3, 1fr);
			}

		}
	}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/881449.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

SVN笔记-SVN安装

SVN笔记-SVN安装 1、在windows下安装 SVN 1、准备svn的安装文件 下载地址&#xff1a;https://sourceforge.net/projects/win32svn/ 2、下载完成后&#xff0c;在相应的盘符中会有一个Setup-Subversion-1.8.17.msi的文件&#xff0c;目前最新的版本是1.8.17&#xff0c; 这里…

UGit:腾讯自研的Git客户端新宠

UGit 是一款专门针对腾讯内部研发环境特点量身定制的 Git 客户端&#xff0c;其目标在于大幅提升开发效率以及确保团队协作的高度流畅性。UGit 能够良好地支持 macOS 10.11 及以上版本、Apple Silicon 以及 Win64 位系统。 可以下载体验一把。 https://ugit.qq.com/zh/index.…

【CSS Tricks】如何做一个粒子效果的logo

效果展示 代码展示 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta name"viewport" content"widthdevice-width, initial-scale1.0" /><title>粒子效果Logo</title>…

【图像匹配】基于Harris算法的图像匹配,matlab实现

博主简介&#xff1a;matlab图像代码项目合作&#xff08;扣扣&#xff1a;3249726188&#xff09; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 本次案例是基于基于Harris算法的图像匹配&#xff0c;用matlab实现。 一、案例背景和算法介绍 …

echarts 散点图tooltip显示一个点对应多个y值

tooltip&#xff1a;显示 tooltip: {trigger: "axis",extraCssText: max-width:50px; white-space:pre-wrap,formatter: function (params) {let arr []params.forEach(v > {arr.push(v.data[1])});return params[0].data[0]":<br>["arr.toStr…

Android 签名、空包签名 、jarsigner、apksigner

jarsigner是JDK提供的针对jar包签名的通用工具, 位于JDK/bin/jarsigner.exe apksigner是Google官方提供的针对Android apk签名及验证的专用工具, 位于Android SDK/build-tools/SDK版本/apksigner.bat jarsigner&#xff1a; jarsigner签名空包执行的命令&#xff1a; jar…

解决Hive乱码问题

在插入数据后&#xff0c;发现hive乱码 原因&#xff1a;Hive默认将存储表结构的元数据列编码设置为latin1&#xff0c;不支持中文 解决方法&#xff1a;在MySQL中修改对应Hive元数据列的编码 先查看mysql的所有字符集编码 1、先修改my.cnf 代码如下&#xff1a; vim /etc/…

weblogic CVE-2017-3506 靶场攻略

漏洞描述 Weblogic的WLS Security组件对外提供了webserver服务&#xff0c;其中使⽤了XMLDecoder来解析⽤户输⼊的XML数据&#xff0c;在解析过程中出现反序列化漏洞&#xff0c;可导致任意命令执⾏。 影响版本 受影响版本&#xff1a;WebLogic 10.3.6.0, 12.1.3.0, 12.2.1.…

YOLOv8改进 | 自定义数据集训练 | AirNet助力YOLOv8检测

目录 一、本文介绍 二、AirNet原理介绍 2.1 对比基降解编码器&#xff08;CBDE&#xff09; 2.2 降解引导修复网络&#xff08;DGRN&#xff09; 三、yolov8与AirNet结合修改教程 3.1 核心代码文件的创建与添加 3.1.1 AirNet.py文件添加 3.1.2 __init__.py文件添加 3…

AIGC时代!AI的“iPhone时刻”与投资机遇

AIGC时代&#xff01;AI的“iPhone时刻”与投资机遇 前言AI的“iPhone时刻”与投资机遇 前言 AIGC&#xff0c;也就是人工智能生成内容&#xff0c;它就像是一股汹涌的浪潮&#xff0c;席卷了整个科技世界。它的出现&#xff0c;让我们看到了人工智能的无限潜力&#xff0c;也…

微服务架构中的负载均衡与服务注册中心(Nacos)

1. 负载均衡&#xff1a;解决实际业务问题 1.1 业务场景思考 想象一个电子商务平台的微服务架构。我们有一个订单服务和多个用户服务实例。当订单服务需要调用用户服务时&#xff0c;它如何选择具体调用哪一台用户服务器&#xff1f;这就是负载均衡要解决的核心问题。 1.2 常…

HTML5好看的水果蔬菜在线商城网站源码系列模板2

文章目录 1.设计来源1.1 主界面1.2 商品列表界面1.3 商品详情界面1.4 其他界面效果 2.效果和源码2.1 动态效果2.2 源代码 源码下载 作者&#xff1a;xcLeigh 文章地址&#xff1a;https://blog.csdn.net/weixin_43151418/article/details/142059220 HTML5好看的水果蔬菜在线商城…

并查集LRU cache

并查集的定义 将n个不同的元素划分成一些不相交的集合。开始时&#xff0c;每个元素自成一个单元素集合&#xff0c;然后按一定的规律将归于同一组元素的集合合并。在此过程中要反复用到查询某一个元素归属于那个集合的运算。适合于描述这类问题的抽象数据类型称为并查集(unio…

2024华为杯研赛E题保姆级教程思路分析

E题题目&#xff1a;高速公路应急车道紧急启用模型 今年的E题设计到图像/视频处理&#xff0c;实际上&#xff0c;E题的难度相对来说较低&#xff0c;大家不用畏惧视频的处理&#xff0c;被这个吓到。实际上&#xff0c;这个不难&#xff0c;解决了视频的处理问题&#xff0c;…

Hazel 2024

不喜欢游戏的人也可以做引擎&#xff0c;比如 cherno 引擎的作用主要是有两点&#xff1a; 将数据可视化交互 当然有些引擎的功能也包含有制作数据文件&#xff0c;称之为资产 assets 不做窗口类的应用栈&#xff0c;可能要花一年才能做一个能实际使用的应用&#xff0c;只需…

笔记整理—内核!启动!—linux应用编程、网络编程部分(2)linux的文件管理策略

关于硬盘中的静态文件与inode&#xff1a;例如文件存储在扇区中&#xff0c;一个文件占用10个字节&#xff0c;一个扇区为512字节&#xff0c;这样的情况下一个扇区就只放了一个实际为10字节的文件&#xff0c;余下的502字节不可存放其他文件&#xff0c;因为扇区已经是可以访问…

机器学习 | Scikit Learn中的普通最小二乘法和岭回归

在统计建模中&#xff0c;普通最小二乘法&#xff08;OLS&#xff09;和岭回归是两种广泛使用的线性回归分析技术。OLS是一种传统的方法&#xff0c;它通过最小化预测值和实际值之间的平方误差之和来找到数据的最佳拟合线。然而&#xff0c;OLS可以遭受高方差和过拟合时&#x…

基于PHP的电脑线上销售系统

作者&#xff1a;计算机学姐 开发技术&#xff1a;SpringBoot、SSM、Vue、MySQL、JSP、ElementUI、Python、小程序等&#xff0c;“文末源码”。 专栏推荐&#xff1a;前后端分离项目源码、SpringBoot项目源码、SSM项目源码 系统展示 【2025最新】基于phpMySQL的电脑线上销售系…

【C语言】自定义类型——联合和枚举

目录 一、联合体&#xff08;共用体&#xff09; &#xff08;1&#xff09;联合体类型的声明 &#xff08;2&#xff09;联合体类型的特点 &#xff08;3&#xff09;联合体和结构体的比较 &#xff08;4&#xff09;联合体大小的计算 &#xff08;5&#xff09;联合体的…

RK3588/RK3588s运行yolov8达到27ms

前言 Hello&#xff0c;小伙伴们~~我最近做了一个比较有意思的东西&#xff0c;想起来也好久没有写博客了&#xff0c;就记录一下吧。希望和大家一起学习&#xff0c;一起进步&#xff01; 我简单介绍一下我最近做的这个东西的经过哈~上个月在B站上看到了一个博主发了一条视频关…