uni-app小程序优惠券镂空样式实现(完整代码!!!)

优惠券半圆镂空效果利用渐变实现,核心代码示例:

background: radial-gradient(circle at left top, transparent 6px, #ffd7d7 0) top left / 50% 100% no-repeat,
			radial-gradient(circle at right top, transparent 6px, #ffd7d7 0) top right / 50% 100% no-repeat;

效果图如下:
coupon

完整代码如下:

<template>
	<view class="content">
		<view class="tabHeads">
			<view class="tabLabel" @click="tabsClick(item)" v-for="(item,index) in tabsArray" :key="index">
				<view :class="[isNum === item.inx?'isTabActive':'default']">{{item.name}}</view>
			</view>
		</view>
		<view class="headWrap">
			<view class="labelDiv" :class="[isActive === item.id?'active':'']" v-for="(item,index) in labels"
				:key="index" @click.stop="toggle(item)">
				{{item.name}}
			</view>
		</view>
		<scroll-view :style="'height:'+wHeight+'px'" :scroll-top="scrollTop" scroll-y="true">
			<view class="couponMain">
				<view class="coupon" v-for="(item,index) in coupons" :key="index">
					<view class="couponTop"
						:class="[isNum ===1?item.type ===1?'bgColorTop1':item.type ===2?'bgColorTop2':'bgColorTop3':'bgColorTop4']">
						<view class="couponTopLeft">
							<view class="couponTypeDiv">
								<image v-if="isNum ===1  && item.type ===1" class="imgType"
									src="/static/coupon/money.png" mode="aspectFit"></image>
								<image v-if="isNum ===1  && item.type ===2" class="imgType"
									src="/static/coupon/discount.png" mode="aspectFit"></image>
								<image v-if="isNum ===1  && item.type ===3" class="imgType"
									src="/static/coupon/goods.png" mode="aspectFit"></image>
								<image v-if="isNum !==1" class="imgType" src="/static/coupon/expired.png"
									mode="aspectFit"></image>
								<view class="tpyeNameSty">{{item.type ===1?'现金券':item.type ===2?'折扣券':'兑物券'}}</view>
							</view>
							<view class="valueSty"
								:class="[isNum ===1?item.type ===1?'color1':item.type ===2?'color3':'color5':'color7']">
								<text v-if="item.type ===1" class="symbolMoney"></text>
								<text v-if="item.type ===1" class="moneyVal">{{item.money}}</text>
								<text v-if="item.type ===2" class="moneyVal">{{item.discount}}</text>
								<text v-if="item.type ===2" style="font-size: 14px;"></text>
								<text v-if="item.type ===3" class="moneyVal">{{item.num}}</text>
								<text v-if="item.type ===3" style="font-size: 14px;"></text>
							</view>
							<view v-if="item.limitCategory ===0 && item.limitStore ===0" class="useCondition"
								:class="[isNum ===1?item.type ===1?'borderColor1 color1':item.type ===2?'borderColor2 color3':'borderColor3 color5':'borderColor4 color7']">
								无门槛使用
							</view>
							<view v-else class="useCondition"
								:class="[isNum ===1?item.type ===1?'borderColor1 color1':item.type ===2?'borderColor2 color3':'borderColor3 color5':'borderColor4 color7']">
								<text>满{{item.condition}}元可</text>
								<text>{{item.type ===3?'兑':'用'}}</text>
							</view>
						</view>
						<view class="couponTopRight">
							<view class="ctr-left">
								<view class="couponName"
									:class="[isNum ===1?item.type ===1?'color1':item.type ===2?'color3':'color5':'color7']">
									{{item.name}}
								</view>
								<view class="couponStore"
									:class="[isNum ===1?item.type ===1?'color2':item.type ===2?'color4':'color6':'color8']">
									{{item.storeName}}
								</view>
								<view class="couponDate"
									:class="[isNum ===1?item.type ===1?'color2':item.type ===2?'color4':'color6':'color8']">
									{{item.startDate}}~{{item.endDate}}
								</view>
							</view>
							<view class="ctr-right">
								<text class="useBtn"
									:class="[isNum ===1?item.type ===1?'useBtnBgColor1':item.type ===2?'useBtnBgColor2':'useBtnBgColor3':'useBtnBgColor4']">{{isNum ===1?'去使用':isNum ===2?'已使用':'已过期'}}</text>
							</view>
						</view>
					</view>
					<view class="couponBottom"
						:class="[isNum ===1?item.type ===1?'bgColorTBottom1':item.type ===2?'bgColorTBottom2':'bgColorTBottom3':'bgColorTBottom4']">
						<view class="ruleLabel">
							<view class="ruleLabel-left">
								<text v-if="item.overlay ===1" class="overlay"
									:class="[isNum ===1?item.type ===1?'color1 bgColor1':item.type ===2?'color3 bgColor2':'color5 bgColor3':'color7 bgColor4']">
									{{item.overlay ===1?'可叠加':''}}
								</text>
								<text class="limit"
									:class="[isNum ===1?item.type ===1?'color1':item.type ===2?'color3':'color5':'color7']">
									{{item.limitCategory ===1?'限品类':'不限品类'}}
								</text>
								<text class="limit"
									:class="[isNum ===1?item.type ===1?'color1':item.type ===2?'color3':'color5':'color7']">/</text>
								<text class="limit"
									:class="[isNum ===1?item.type ===1?'color1':item.type ===2?'color3':'color5':'color7']">
									{{item.limitStore ===1?'限门店':'不限门店'}}
								</text>
							</view>
							<view class="ruleBtn"
								:class="[isNum ===1?item.type ===1?'color2':item.type ===2?'color4':'color6':'color8']"
								@click.stop="viewRules(item)">
								<text style="margin-right: 6px;">使用规则</text>
								<view class="arrowIcon"
									:class="[item.isViewRule?isNum ===1?item.type ===1?'rotate arrowIcon1':item.type ===2?'rotate arrowIcon2':'rotate arrowIcon3':'rotate arrowIcon4':isNum ===1?item.type ===1?'backRotate arrowIcon1':item.type ===2?'backRotate arrowIcon2':'backRotate arrowIcon3':'backRotate arrowIcon4']">
								</view>
							</view>
						</view>
						<view v-if="item.isViewRule" class="ruleDetail"
							:class="[isNum ===1?item.type ===1?'color2':item.type ===2?'color4':'color6':'color8']">
							<view class="ruleList">
								1.使用规则描述xxxxxxxx
							</view>
							<view class="ruleList">
								1.使用规则描述xxxxxxxx
							</view>
							<view class="ruleList">
								1.使用规则描述xxxxxxxx
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				wHeight: 0,
				scrollTop: 0,
				isNum: 1,
				tabsArray: [{
					inx: 1,
					name: '未使用'
				}, {
					inx: 2,
					name: '已使用'
				}, {
					inx: 3,
					name: '已过期'
				}],
				isActive: 1,
				labels: [{
					id: 1,
					name: '全部'
				}, {
					id: 2,
					name: '现金券'
				}, {
					id: 3,
					name: '折扣券'
				}, {
					id: 4,
					name: '兑物券'
				}],
				coupons: [{
					type: 1,
					money: 50,
					discount: 5,
					num: 1,
					condition: 20,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 1,
					limitCategory: 1,
					limitStore: 1,
					rules: '使用规则描述',
					isViewRule: false
				}, {
					type: 2,
					money: 50,
					discount: 5,
					num: 1,
					condition: 5,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 1,
					limitCategory: 0,
					limitStore: 0,
					rules: '使用规则描述',
					isViewRule: false
				}, {
					type: 3,
					money: 50,
					discount: 5,
					num: 1,
					condition: 20,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 1,
					limitCategory: 0,
					limitStore: 0,
					rules: '使用规则描述',
					isViewRule: false
				}, {
					type: 3,
					money: 50,
					discount: 5,
					num: 1,
					condition: 20,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 1,
					limitCategory: 1,
					limitStore: 0,
					rules: '使用规则描述',
					isViewRule: false
				}, {
					type: 3,
					money: 50,
					discount: 5,
					num: 1,
					condition: 20,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 1,
					limitCategory: 0,
					limitStore: 1,
					rules: '使用规则描述',
					isViewRule: false
				}, {
					type: 2,
					money: 50,
					discount: 5,
					num: 1,
					condition: 5,
					name: "仅可购买指定商品",
					storeName: '西安碑林钟楼店',
					startDate: '2021-05-01',
					endDate: '2021-08-01',
					overlay: 0,
					limitCategory: 0,
					limitStore: 0,
					rules: '使用规则描述',
					isViewRule: false
				}]
			}
		},
		onLoad() {
			uni.hideTabBar()

			const res = uni.getSystemInfoSync()
			this.wHeight = res.windowHeight - 86
		},
		onShow() {
			this.isActive = 1
		},
		methods: {
			tabsClick(item) {
				this.isNum = item.inx
			},
			toggle(item) {
				this.isActive = item.id
			},
			viewRules(item) {
				if (item.isViewRule) {
					item.isViewRule = false
				} else {
					item.isViewRule = true
				}
			}
		}
	}
</script>

<style scoped>
	.content {
		padding: 0;
		overflow: hidden;
	}

	.tabHeads {
		display: flex;
		background-color: #fff;
		margin-bottom: 1px;
	}

	.tabLabel {
		flex: 1;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 16px;
	}

	.default {
		color: #999999;
		padding: 10px 0;
		border-bottom: 1px solid #ffffff;
	}

	.isTabActive {
		color: #ff5555;
		padding: 10px 0;
		border-bottom: 1px solid #ff5555;
	}

	.headWrap {
		padding: 10px;
		background-color: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: nowrap;
	}

	.labelDiv {
		background-color: #eeeeee;
		padding: 4px 20px;
		border-radius: 4px;
		color: #999999;
		font-size: 12px;
	}

	.active {
		background-color: #ff5555;
		color: #fff;
	}

	.couponMain {
		padding: 10px;
		display: flex;
		flex-direction: column;
	}

	.coupon {
		margin-bottom: 10px;
	}

	.couponTop {
		display: flex;
		border-top-left-radius: 4px;
		border-top-right-radius: 4px;
	}

	.couponTopLeft {
		flex: 1.2;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		position: relative;
	}

	.couponTypeDiv {}

	.imgType {
		width: 46px;
		height: 40px;
		position: absolute;
		top: 0;
		left: 0;
	}

	.tpyeNameSty {
		font-size: 9px;
		transform: rotate(-40deg);
		position: absolute;
		top: 8px;
		left: 2px;
		color: #fff;
	}

	.valueSty {
		margin-bottom: 10px;
	}

	.symbolMoney {
		font-size: 16px;
	}

	.moneyVal {
		font-size: 24px;
	}

	.useCondition {
		font-size: 10px;
		padding: 4px 10px;
		border-radius: 12px;
	}

	.couponTopRight {
		flex: 3;
		display: flex;
		padding-bottom: 12px;
	}

	.ctr-left {
		flex: 1;
		display: flex;
		flex-direction: column;
	}

	.couponName {
		font-size: 16px;
		padding: 14px 0;
		text-shadow: 0px 4px 6px rgba(0, 0, 0, 0.04);
	}

	.couponStore {
		font-size: 12px;
		text-shadow: 0px 4px 6px rgba(0, 0, 0, 0.04);
		padding-bottom: 8px;
	}

	.couponDate {
		font-size: 12px;
		text-shadow: 0px 4px 6px rgba(0, 0, 0, 0.04);
	}

	.ctr-right {
		display: flex;
		align-items: flex-end;
		justify-content: center;
		padding: 0 10px;
	}

	.useBtn {
		color: #fff;
		font-size: 12px;
		padding: 6px 20px;
		border-radius: 18px;
	}

	.couponBottom {
		display: flex;
		flex-direction: column;
		padding: 10px;
		border-bottom-left-radius: 4px;
		border-bottom-right-radius: 4px;
	}

	.ruleLabel {
		display: flex;
		align-items: center;
	}

	.ruleLabel-left {
		flex: 1;
		display: flex;
		align-items: center;
	}

	.overlay {
		margin-right: 10px;
		padding: 4px 10px;
		font-size: 10px;
		border-radius: 11px;
	}

	.limit {
		font-size: 12px;
	}

	.ruleBtn {
		display: flex;
		align-items: center;
		font-size: 12px;
	}

	.arrowIcon {
		position: relative;
		width: 6px;
		height: 6px;
		transform: rotate(135deg);

	}

	.rotate {
		transform: rotate(-45deg);
		bottom: -2px;
	}

	.backRotate {
		transform: rotate(135deg);
		top: -2px;
	}

	.ruleDetail {
		display: flex;
		flex-direction: column;
	}

	.ruleList {
		padding-top: 10px;
		font-size: 12px;
	}

	/* 颜色配置 */
	.borderColor1 {
		border: 1px solid #5f98ff;
	}

	.borderColor2 {
		border: 1px solid #ff7979;
	}

	.borderColor3 {
		border: 1px solid #fc932c;
	}

	.borderColor4 {
		border: 1px solid #c3c3c3;
	}

	.arrowIcon1 {
		border-top: 1px solid #5f98ff;
		border-right: 1px solid #5f98ff;
	}

	.arrowIcon2 {
		border-top: 1px solid #ff7979;
		border-right: 1px solid #ff7979;
	}

	.arrowIcon3 {
		border-top: 1px solid #fc932c;
		border-right: 1px solid #fc932c;
	}

	.arrowIcon4 {
		border-top: 1px solid #c3c3c3;
		border-right: 1px solid #c3c3c3;
	}

	.useBtnBgColor1 {
		background-color: #2b6feb;
	}

	.useBtnBgColor2 {
		background-color: #ff5555;
	}

	.useBtnBgColor3 {
		background-color: #fa830e;
	}

	.useBtnBgColor4 {
		background-color: #bebebe;
	}

	.color1 {
		color: #2b6feb;
	}

	.color2 {
		color: #5f98ff;
	}

	.color3 {
		color: #ff5555;
	}

	.color4 {
		color: #ff7979;
	}

	.color5 {
		color: #fa830e;
	}

	.color6 {
		color: #fc932c;
	}

	.color7 {
		color: #bebebe;
	}

	.color8 {
		color: #c3c3c3;
	}

	.bgColor1 {
		background-color: #edf4ff;
	}

	.bgColor2 {
		background-color: #ffeeee;
	}

	.bgColor3 {
		background-color: #fff2e5;
	}

	.bgColor4 {
		background-color: #f3f3f3;
	}

	.bgColorTop1 {
		background: radial-gradient(circle at left bottom, transparent 6px, #edf4ff 0) bottom left / 50% 100% no-repeat,
			radial-gradient(circle at right bottom, transparent 6px, #edf4ff 0) bottom right / 50% 100% no-repeat;
	}

	.bgColorTBottom1 {
		background: radial-gradient(circle at left top, transparent 6px, #dae6ff 0) top left / 50% 100% no-repeat,
			radial-gradient(circle at right top, transparent 6px, #dae6ff 0) top right / 50% 100% no-repeat;
	}

	.bgColorTop2 {
		background: radial-gradient(circle at left bottom, transparent 6px, #ffeeee 0) bottom left / 50% 100% no-repeat,
			radial-gradient(circle at right bottom, transparent 6px, #ffeeee 0) bottom right / 50% 100% no-repeat;
	}

	.bgColorTBottom2 {
		background: radial-gradient(circle at left top, transparent 6px, #ffd7d7 0) top left / 50% 100% no-repeat,
			radial-gradient(circle at right top, transparent 6px, #ffd7d7 0) top right / 50% 100% no-repeat;
	}

	.bgColorTop3 {
		background: radial-gradient(circle at left bottom, transparent 6px, #fff2e5 0) bottom left / 50% 100% no-repeat,
			radial-gradient(circle at right bottom, transparent 6px, #fff2e5 0) bottom right / 50% 100% no-repeat;
	}

	.bgColorTBottom3 {
		background: radial-gradient(circle at left top, transparent 6px, #ffe0c1 0) top left / 50% 100% no-repeat,
			radial-gradient(circle at right top, transparent 6px, #ffe0c1 0) top right / 50% 100% no-repeat;
	}

	.bgColorTop4 {
		background: radial-gradient(circle at left bottom, transparent 6px, #f3f3f3 0) bottom left / 50% 100% no-repeat,
			radial-gradient(circle at right bottom, transparent 6px, #f3f3f3 0) bottom right / 50% 100% no-repeat;
	}

	.bgColorTBottom4 {
		background: radial-gradient(circle at left top, transparent 6px, #ededed 0) top left / 50% 100% no-repeat,
			radial-gradient(circle at right top, transparent 6px, #ededed 0) top right / 50% 100% no-repeat;
	}
</style>

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
### 回答1: Uni-app 是一款能够开发多个终端的跨平台框架,包括小程序、H5、App 等,可以在同一个代码库中开发出具有不同功能的应用。而 Uni-app 小程序源码就是使用 Uni-app 开发的小程序代码Uni-app 小程序源码具有以下优势: 1. 高效开发:借助 Uni-app 的跨平台开发框架,Uni-app 小程序源码可以快速开发出具有高质量和高性能的小程序。 2. 多平台统一:Uni-app 小程序源码可以快速发布到多个平台的小程序环境中,如微信小程序、支付宝小程序、百度小程序等。 3. 组件库完整Uni-app 小程序源码提供了完整的组件库和工具库,开发者可以快速开发出小程序。 4. 商业支持:Uni-app 小程序源码由腾讯公司开发,具有较强的商业支持,可以解决开发者在开发过程中的各种问题。 总的来说,Uni-app 小程序源码是一种高效、跨平台的小程序开发方式,可以大大节省开发者的时间和精力。同时,也为多个终端用户提供了更加方便和高效的小程序服务。 ### 回答2: Uni-app是一个跨平台开发框架,支持将一个代码库编译成多个平台的应用程序,其中包括iOS、Android、H5、微信小程序等。而Uni-app小程序源码是指使用Uni-app框架开发出来的小程序代码,通过该源码可以进行二次开发,解析出小程序的各个功能和页面,进行定制化开发,满足不同业务场景的需求。 使用Uni-app小程序源码可以快速实现小程序的开发,不仅减少了代码的编写量,同时也兼容了多个平台,方便用户在不同设备上使用该应用。同时,Uni-app小程序源码的可维护性也很高,因为只需要在一个代码库中进行修改和维护,而不需要针对每个平台单独编写代码。 在使用Uni-app小程序源码时,需要先进行环境搭建,安装相关的开发工具和依赖库,然后即可进行开发。源码中包含了小程序的各个功能和页面,开发者可以根据自己的需求进行修改和扩展,同时也可以使用Uni-app提供的组件和API完成自己的开发任务。 需要注意的是,在进行Uni-app小程序源码开发时,需要熟悉Vue.js框架的相关知识,因为Uni-app是基于Vue.js的框架进行开发的。同时,还需要了解小程序开发的相关知识,包括小程序的生命周期、路由、组件等。掌握这些知识后,才能够更好地利用Uni-app小程序源码进行开发,实现优秀的小程序应用。 ### 回答3: uni-app 小程序源码是指在 uni-app 开发框架下开发的小程序代码uni-app 是一个多端开发框架,可以让开发者使用一套代码同时开发出跨 iOS、Android、H5 等多个平台的应用程序。在这个框架下,我们可以通过 Vue.js 开发小程序,并且使用 uni-app 提供的开发工具来进行调试和编译。 uni-app 具有许多优点,如跨平台、快速开发、高效编译等,其提供了丰富的组件和插件,让开发者可以轻松地在小程序实现各种功能。开发者只需要按照 Vue.js 的组件开发方式去编写小程序代码,就可以实现复杂的应用逻辑。 uni-app 小程序源码的开发需要一定的技术积累和编程经验,同时还需要对互联网技术有一定的了解。一般来说,开发者需要掌握 Vue.js 基础、小程序开发技能等,才能开发出可靠、高效的 uni-app 小程序源码。 总之,uni-app 小程序源码是一个非常有价值的开发项目,可以帮助更多的开发者快速实现小程序应用功能,同时也可以提高开发效率,降低开发成本。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值