feat: add virtual resource payments and optimize images

This commit is contained in:
王鹏
2026-07-28 13:35:23 +08:00
parent ab281be02a
commit d14f005d34
35 changed files with 462 additions and 2125 deletions

View File

@@ -11,7 +11,7 @@
</cover-view>
<!-- 顶部图片 -->
<view class="top-img">
<image class="ui-img" :src="blogInfo.showImg" mode="aspectFill"></image>
<image class="ui-img" :src="$image.original(blogInfo.showImg)" mode="aspectFill"></image>
<text v-if="share == 0" @click="back()" class="cuIcon-back backbut"></text>
<text v-else @click="home()" class="cuIcon-home backbut"></text>
</view>
@@ -53,7 +53,7 @@
<view v-if="blogInfo.picList && blogInfo.picList.length > 0" class="screenshot-view">
<view class="screenshot-list">
<view v-for="(item, index) in blogInfo.picList" :key="index" class="screenshot-item" @click="previewImage(index)">
<image class="screenshot-img" :src="item" mode="aspectFill"></image>
<image class="screenshot-img" :src="$image.original(item)" lazy-load mode="aspectFill"></image>
</view>
</view>
</view>
@@ -69,7 +69,7 @@
<block>
<view class="list-li" v-for="(item ,index) in blogList" :key="index" @click="to(item.id)">
<view class="list-img">
<image class="ui-img" :src="item.showImg"></image>
<image class="ui-img" :src="$image.articleThumbnail(item)" lazy-load mode="aspectFill"></image>
</view>
<view class="list-li-left">
<view class="list-li-left-h">
@@ -85,7 +85,7 @@
</view>
<view v-else class="margin">
<!-- <view style="width: 100%;height: 300rpx;">
<image class="blog-showimg" :src="blogInfo.showImg"></image>
<image class="blog-showimg" :src="$image.original(blogInfo.showImg)" lazy-load mode="aspectFill"></image>
</view> -->
<view v-if="blogInfo.remark" class="shuoming">说明:{{blogInfo.remark}}</view>
<view v-else class="shuoming">说明请先点击下方按钮即可获取文章详情由于存储与服务器成本很高不得已部分内容需您观看激励视频广告</view>
@@ -111,7 +111,7 @@
<view class="cover-list-font">点赞</view>
</view>
<view v-if="blogInfo.appResourceId" @click="download(blogInfo.appResourceId)">
<view v-if="blogInfo.appResourceId" @click="download()">
<view class="cover-list-icon">
<image class="ui-img" src="https://img.yidaima.cn/feast/xiazai.svg"
mode="aspectFit">
@@ -370,8 +370,16 @@
})
})
},
download(id) {
this.$tab.navigateTo('/pages/blog/resource?id=' + id + "&type=1")
download() {
const id = this.blogInfo && this.blogInfo.appResourceId
if (!id) {
uni.showToast({
title: '资源信息不存在',
icon: 'none'
})
return
}
this.$tab.navigateTo('/pages/blog/resource?id=' + encodeURIComponent(id) + "&type=1")
},
back(val) {
const pages = getCurrentPages();
@@ -778,4 +786,4 @@
z-index: 1025;
background-color: #fff;
}
</style>
</style>

View File

@@ -3,7 +3,7 @@
<!-- 顶部图片 -->
<view class="top-img">
<image class="ui-img" :src="resourceInfo.showImg" mode="aspectFill"></image>
<image class="ui-img" :src="$image.original(resourceInfo.showImg)" mode="aspectFill"></image>
<text @click="back()" class="cuIcon-back backbut"></text>
</view>
<view class="resource-box">
@@ -45,7 +45,8 @@
</view>
<view v-if="isLookAd == 0" class="shuoming2">复制下方链接打开手机浏览器进行下载</view>
<view v-else class="shuoming2">请先点击下方按钮即可获取资源下载列表</view>
<view v-if="isLookAd == 0" v-for="(item,index) in resourceInfo.appResourceListList" :key="index" class="file-list">
<template v-if="isLookAd == 0">
<view v-for="(item,index) in resourceInfo.appResourceListList" :key="index" class="file-list">
<view class="resource-view">
<view class="resource-img3">
<image class="ui-img" src="https://img.yidaima.cn/feast/files.svg" mode="aspectFit"></image>
@@ -56,6 +57,7 @@
</view>
<view class="file-url-box"><text class="file-url">{{item.listUrl}}</text><text @click="copy(item.listUrl)" class="file-copy">复制</text></view>
</view>
</template>
<view v-if="adUnitId" style="width: 100%; margin-top: 50rpx;">
<ad-custom :unit-id="adUnitId" ad-intervals="30" ></ad-custom>
@@ -65,13 +67,16 @@
</view>
</view>
<view v-if="isLookAd ==1 || isLookAd == 2" style="height: 140rpx; width: 100%;"></view>
<view v-if="isLookAd ==1 || isLookAd == 2 || isLookAd == 3" style="height: 140rpx; width: 100%;"></view>
<view v-if="isLookAd ==1" @click="lookAd()" class="resource-ad">
广告查看
</view>
<view v-if="isLookAd ==2" @click="jfAd()" class="resource-ad">
积分获取 {{resourceInfo.adNumber}} 积分
</view>
<view v-if="isLookAd ==3" @click="payResource()" class="resource-ad">
{{paying ? '支付结果确认中...' : '付费获取 ¥' + formatPrice(resourceInfo.priceFen) + ' '}}
</view>
<u-toast ref="uToast"></u-toast>
</view>
@@ -79,7 +84,8 @@
<script>
import {
getResource,getResourceByUserId,resourceDownLoad,appGetUserById,exchangeResource
getResource,getResourceByUserId,resourceDownLoad,appGetUserById,exchangeResource,
createVirtualResourceOrder,getVirtualResourceOrder
} from "@/api/app/index.js"
import config from '@/config'
let videoAd = null;
@@ -90,8 +96,13 @@
adUnitId:"",
adUnitId2:"",
id:null,
resourceInfo:{},
resourceInfo:{
resourceTitle: '',
showImg: '',
appResourceListList: []
},
isLookAd:null,
paying: false,
tag_style: {
h1: 'line-height: 50px;font-size:16px;',
h2: 'line-height: 50px;font-size:16px',
@@ -125,10 +136,20 @@
}
},
onLoad(option) {
this.adUnitId = uni.getStorageSync("sysSet").zyinfoAd
this.adUnitId2 = uni.getStorageSync("sysSet").downVideoAd
this.userId = uni.getStorageSync("userInfo").userId
this.id = option.id
const sysSet = uni.getStorageSync("sysSet") || {}
const userInfo = uni.getStorageSync("userInfo") || {}
this.adUnitId = sysSet.zyinfoAd || ""
this.adUnitId2 = sysSet.downVideoAd || ""
this.userId = userInfo.userId || null
const id = option && option.id
if (!/^\d+$/.test(String(id || ''))) {
uni.showToast({
title: '资源参数错误,请重新进入',
icon: 'none'
})
return
}
this.id = id
if(option.type){
this.type = option.type
}
@@ -212,7 +233,7 @@
message: "兑换成功",
icon: false
})
that.isLookAd = 0
that.getInfo()
})
}
@@ -237,26 +258,33 @@
},
getInfo(){
var that = this;
getResourceByUserId(this.id, this.userId).then(response => {
console.log(response.data)
getResourceByUserId(this.id).then(response => {
if (!response || !response.data) {
uni.showToast({
title: '资源信息不存在',
icon: 'none'
})
return
}
if(response.data.isAd == 0){
this.isLookAd = 0
resourceDownLoad({id: this.id}).then(response => {})
}else if(response.data.isAd == 1){
this.isLookAd = 1
//resourceDownLoad({id: this.id}).then(response => {})
}else{
}else if(response.data.isAd == 2){
this.isLookAd = 2
}else if(response.data.isAd == 3){
this.isLookAd = 3
}
that.resourceInfo = response.data
var str = that.resourceInfo.explain
var str = that.resourceInfo.explain || ''
if (str.includes("/dev-api")) {
that.resourceInfo.explain = str.replace("/dev-api", that.baseUrl)
} else {
that.resourceInfo.explain = str.replace("/prod-api", that.baseUrl)
}
that.contentDate = response.data.explain
that.contentDate = that.resourceInfo.explain
.replace(/<h1([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<h1')
.replace(/<h1([\s\w"=\/\.:;]+)((?:(class="[^"]+")))/ig, '<h1')
.replace(/<h1>/ig, '<h1 class="h1">')
@@ -296,6 +324,122 @@
}
});
},
payResource(){
var that = this;
if (this.paying) {
return;
}
if (!this.userId) {
uni.showToast({
title: '请先登录后购买',
icon: 'none'
});
return;
}
if (!this.resourceInfo.priceFen || this.resourceInfo.priceFen <= 0) {
uni.showToast({
title: '价格信息错误',
icon: 'none'
});
return;
}
if (typeof wx === 'undefined' || typeof wx.requestVirtualPayment !== 'function') {
uni.showToast({
title: '当前微信版本不支持虚拟支付,请升级微信',
icon: 'none'
});
return;
}
this.paying = true;
uni.login({
provider: 'weixin',
success: loginRes => {
createVirtualResourceOrder({
resourceId: that.id,
code: loginRes.code
}).then(response => {
var payParams = response.data;
wx.requestVirtualPayment({
signData: payParams.signData,
paySig: payParams.paySig,
signature: payParams.signature,
mode: payParams.mode,
success: () => {
that.confirmVirtualOrder(payParams.orderNo, 0);
},
fail: err => {
that.paying = false;
var cancelled = err && err.errCode === -2;
uni.showToast({
title: cancelled ? '已取消支付' : '支付未完成,请重试',
icon: 'none'
});
}
});
}).catch(() => {
that.paying = false;
});
},
fail: () => {
that.paying = false;
uni.showToast({
title: '获取微信登录凭证失败',
icon: 'none'
});
}
});
},
confirmVirtualOrder(orderNo, attempt){
var that = this;
var shouldSync = attempt === 1 || attempt === 6;
getVirtualResourceOrder(orderNo, shouldSync).then(response => {
var order = response.data;
if (order.unlocked) {
that.paying = false;
that.$refs.uToast.show({
type: 'success',
title: '',
message: '购买成功',
icon: false
});
that.getInfo();
return;
}
if (order.status === 2 || order.status === 3) {
that.paying = false;
uni.showToast({
title: order.status === 2 ? '订单已退款' : '订单已关闭',
icon: 'none'
});
return;
}
if (attempt < 10) {
setTimeout(function() {
that.confirmVirtualOrder(orderNo, attempt + 1);
}, 1200);
} else {
that.paying = false;
uni.showToast({
title: '支付结果确认中,请稍后重新进入页面',
icon: 'none',
duration: 3000
});
}
}).catch(() => {
if (attempt < 10) {
setTimeout(function() {
that.confirmVirtualOrder(orderNo, attempt + 1);
}, 1200);
} else {
that.paying = false;
}
});
},
formatPrice(priceFen){
var value = Number(priceFen || 0) / 100;
return value.toFixed(2);
},
back(val) {
const pages = getCurrentPages();
if (pages.length > 1) {
@@ -451,4 +595,4 @@
top: 100rpx;
font-size: 50rpx;
}
</style>
</style>