学习:uniapp全栈微信小程序vue3后台(26) - 指南
126.将服务协议和隐私政策内容展示到页面中
是否开启广告
声明
热门搜索
用户协议隐私政策
/pages/agreement/agreement
import { onLoad } from "@dcloudio/uni-app"
import { ref } from "vue";
const dbJQL = uniCloud.databaseForJQL();
const detail = ref("")
let type;
onLoad((e) => {
type = e.type
uni.setNavigationBarTitle({
title: e.title
})
})
const getData = async () => {
let { data = {} } = await dbJQL.collection("wallpaper-system-config").orderBy("_id asc").limit(1)
.field(type)
.get({ getOne: true });
detail.value = data[type]
}
{{detail}}
.detail {
padding: 30rpx;
line-height: 1.7em;
text-indent: 2em;
}
127.创建硬币积分系统schema表及领取硬币逻辑
新建DB Schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": "true",
"create": "true",
"update": "true",
"delete": "true"
},
"properties": {
"_id": {
"description": "存储文档 ID(用户 ID),系统自动生成"
},
"user_id": {
"bsonType": "string",
"description": "用户ID, 参考`uni-id-users` 表",
"foreignKey": "uni-id-users._id",
"defaultValue": {
"$env": "uid"
}
},
"total": {
"bsonType": "int",
"description": "积分总数",
"defaultValue": 0
},
"dayGet": {
"bsonType": "bool",
"description": "是否领取每日硬币",
"defaultValue": false
},
"record": {
"bsonType": "array",
"description": "操作记录",
"defaultValue": [],
"properties": {
"time": {
"bsonType": "timestamp",
"description": "操作时间",
"defaultValue": {
"$env": "now"
}
},
"score": {
"bsonType": "int",
"description": "积分流动数"
},
"desc": {
"bsonType": "string",
"description": "当前操作描述"
}
}
},
"ip": {
"bsonType": "string",
"description": "评论发表时 IP 地址",
"forceDefaultValue": {
"$env": "clientIP"
}
},
"createTime": {
"bsonType": "timestamp",
"description": "创建时间",
"defaultValue": {
"$env": "now"
}
}
},
"version": "0.0.1"
}
/uniCloud-alipay/cloudfunctions/client-user-action/index.obj.js
//每日获取硬币
async giveDayCoin() {
const dbJQL = uniCloud.databaseForJQL({
clientInfo: this.getClientInfo()
})
let res = await dbJQL.collection("wallpaper-activity-coin")
.where(`user_id == $cloudEnv_uid `)
.limit(1)
.get({ getOne: true });
return res;
}
/pages/user/user
//每日领币
const dayCoin = async () => {
console.log("每日领币");
if (!gotoLogin()) return;
try {
let { errCode } = await actionCloudObj.giveDayCoin();
if (errCode !== 0) return showToast({ title: "请重试" })
showToast({ title: "领取成功" });
} catch (err) {
showToast({ title: err.errMsg })
}
}
128.通过dayjs判断每日领币条件及实时更新硬币数量
npm i dayjs
/uniCloud-alipay/cloudfunctions/client-user-action/index.obj.js
新建js文件
import { defineStore } from 'pinia';
import { ref } from "vue";
const actionCloudObj = uniCloud.importObject("client-user-action", { customUI: true });
export const useCoinStore = defineStore('coin', () => {
const total = ref(0);
const getCoinCount = async () => {
total.value = await actionCloudObj.getCoinCount();
console.log(total.value);
}
return { total, getCoinCount };
});
/uniCloud-alipay/cloudfunctions/client-user-action/index.obj.js
async getCoinCount() {
let start = dayjs().startOf("day").valueOf()
let end = dayjs().endOf("day").valueOf()
const dbJQL = uniCloud.databaseForJQL({
clientInfo: this.getClientInfo()
})
let { data: { total = 0 } = {} } = await dbJQL.collection("wallpaper-activity-coin")
.where(`user_id == $cloudEnv_uid && createTime >= ${start} && createTime <= ${end}`)
.limit(1)
.field("total")
.get({ getOne: true });
return total;
},
/pages/user/user
129.看广告获取硬币的实现逻辑
不支持浏览器
/pages/user/user
//看广告获得硬币
const adCoin = () => {
if (!gotoLogin()) return;
if (uni.getSystemInfoSync().uniPlatform !== 'mp-weixin') return showToast({ title: "只支持微信小程序" })
console.log("看广告获得硬币");
}
看广告获取硬币
/uniCloud-alipay/cloudfunctions/client-user-action/index.obj.js
//看广告获取硬币
async giveAdCoin() {
let start = dayjs().startOf("day").valueOf()
let end = dayjs().endOf("day").valueOf()
const dbJQL = uniCloud.databaseForJQL({
clientInfo: this.getClientInfo()
})
let p1 = dbJQL.collection("wallpaper-activity-coin")
.where(`user_id == $cloudEnv_uid && createTime >= ${start} && createTime = ${start} && createTime <= ${end}`)
.update(params);
} else {
//新增
return await dbJQL.collection("wallpaper-activity-coin")
.add({
total: config.adCoin,
record: [recordItem]
})
}
},
/pages/user/user
const getAdcoin = async () => {
try {
uni.showLoading();
let { errCode } = await actionCloudObj.giveAdCoin();
if (errCode !== 0) return showToast({ title: "获取硬币失败,请重试" });
showToast({ title: `获取${config.value.adCoin}硬币` })
getCoin();
} catch (err) {
showToast({ title: err.errMsg })
}
}
130.微信小程序激励视频广告位的使用
/pages/user/user
{{userInfo.nickname|| '未登录'}}
硬币:{{coinStore.total}}
每日领币
+{{config.dayCoin}} / 日
看广告得币
+{{config.adCoin}}/ 次
硬币规则
说明
我的下载
{{record.downloadSize}}
我的评分
{{record.scoreSize}}
联系客服
订阅更新
常见问题
退出登录
退出当前账号
硬币规则说明
{{config.ruleCoin}}
确认
import pagesJson from '@/pages.json'
import { getNavBarHeight } from "@/utils/system.js"
import { apiUserInfo } from "@/api/apis.js"
import { computed, ref } from "vue";
import { onLoad } from "@dcloudio/uni-app"
import { getPageAndParams, gotoLogin, routerTo, showModal, showToast } from "@/utils/common.js"
import { store, mutations } from '@/uni_modules/uni-id-pages/common/store.js'
import { useSystemStore } from "@/stores/system.js"
import { useCoinStore } from "@/stores/coin.js"
import { watch } from "vue";
const coinStore = useCoinStore();
const systemStore = useSystemStore();
const config = computed(() => systemStore.config)
const actionCloudObj = uniCloud.importObject("client-user-action", { customUI: true });
const userInfo = computed(() => store.userInfo);
const record = ref({ downloadSize: 0, scoreSize: 0 });
const rulePopRef = ref(null);
const hasLogin = computed(() => store.hasLogin);
let videoAd = null;
onLoad(() => {})
watch(() => config.value.rewardedVideo, (nv) => {
if (!config.value.rewardedVideo) return;
if (wx.createRewardedVideoAd) {
videoAd = wx.createRewardedVideoAd({
adUnitId: config.value.rewardedVideo
})
videoAd.onLoad(() => {})
videoAd.onError((err) => {
console.error('激励视频光告加载失败', err)
showToast({ title: "请稍后重试" })
})
videoAd.onClose((res) => {
if (res.isEnded) {
coinStore.getAdCoin();
} else {
showToast({ title: "广告未完播,无法获得奖励" })
}
})
}
}, { immediate: true })
const clickContact = () => {
uni.makePhoneCall({
phoneNumber: "114"
})
}
const getCoin = () => {
if (!hasLogin.value) return;
coinStore.getCoinCount();
}
const getRecord = async () => {
if (!hasLogin.value) return;
let res = await actionCloudObj.userHistoryCount();
record.value = res
}
//每日领币
const dayCoin = async () => {
console.log("每日领币");
if (!gotoLogin()) return;
try {
let { errCode } = await actionCloudObj.giveDayCoin();
if (errCode !== 0) return showToast({ title: "请重试" })
showToast({ title: "领取成功" });
} catch (err) {
showToast({ title: err.errMsg })
}
}
//看广告获得硬币
const adCoin = () => {
if (!gotoLogin()) return;
if (uni.getSystemInfoSync().uniPlatform !== 'mp-weixin') return showToast({ title: "只支持微信小程序" })
console.log("看广告获得硬币");
if (videoAd) {
videoAd.show().catch(() => {
// 失败重试
videoAd.load()
.then(() => videoAd.show())
.catch(err => {
console.error('激励视频 广告显示失败', err)
showToast({ title: "加载失败,请刷新重试" })
})
})
}
}
const getAdcoin = async () => {
try {
uni.showLoading();
let { errCode } = await actionCloudObj.giveAdCoin();
if (errCode !== 0) return showToast({ title: "获取硬币失败,请重试" });
showToast({ title: `获取${config.value.adCoin}硬币` })
getCoin();
} catch (err) {
showToast({ title: err.errMsg })
}
}
//硬币规则说明
const ruleCoin = () => {
rulePopRef.value.open();
}
//关闭硬币规则
const ruleClose = () => {
rulePopRef.value.close();
}
//退出登录
const logout = async () => {
let feedback = await showModal({ content: "是否确认退出登录" })
if (feedback == 'confirm') mutations.logout();
init();
}
//登录或者个人中心
const handleUserInfo = () => {
// 检查用户是否已登录(hasLogin.value)
if (hasLogin.value) {
// 如果已登录,跳转到用户信息页面
routerTo(`/uni_modules/uni-id-pages/pages/userinfo/userinfo`)
} else {
// 如果未登录,跳转到登录页面,并携带当前页面的路径和参数作为重定向 URL
routerTo(`/${pagesJson.uniIdRouter.loginPage}?uniIdRedirectUrl=${getPageAndParams()}`)
}
}
const downloadPage = () => {
if (!gotoLogin()) return;
routerTo('/pages/classlist/classlist?name=我的下载&type=download')
}
const scorePage = () => {
if (!gotoLogin()) return;
routerTo('/pages/classlist/classlist?name=我的评分&type=score')
}
const init = () => {
record.value = { downloadSize: 0, scoreSize: 0 };
coinStore.total = 0
}
//监听登录成功
uni.$on('uni-id-pages-login-success', () => {
getRecord();
getCoin();
})
getRecord();
getCoin();
.userLayout {
.userInfo {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
margin: 50rpx 0;
.box {
display: flex;
flex-direction: column;
align-items: center;
}
.avatar {
width: 160rpx;
height: 160rpx;
border-radius: 50%;
overflow: hidden;
image {
width: 100%;
height: 100%;
}
}
.name {
font-size: 44rpx;
color: #333;
padding: 20rpx 0 5rpx;
}
.other {
font-size: 26rpx;
color: #aaa;
}
}
.section {
width: 690rpx;
margin: 50rpx auto;
border: 1px solid #eee;
border-radius: 10rpx;
box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.05);
.list {
.row {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 30rpx;
height: 100rpx;
border-bottom: 1px solid #eee;
position: relative;
background: #fff;
&:last-child {
border-bottom: 0
}
.left {
display: flex;
align-items: center;
:deep() {
.uni-icons {
color: $brand-theme-color !important;
}
}
.text {
padding-left: 20rpx;
color: #666
}
}
.right {
display: flex;
align-items: center;
.text {
font-size: 28rpx;
color: #aaa;
}
}
button {
position: absolute;
top: 0;
left: 0;
height: 100rpx;
width: 100%;
opacity: 0;
}
}
.hoverRow {
transform: scale(0.99);
}
}
}
.grid {
display: grid;
justify-content: space-between;
grid-template-columns: repeat(3, 1fr);
min-height: 160rpx;
margin-top: 0;
.item {
border-right: 1px solid #eee;
background: #fff;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
&:last-child {
border-right: none
}
:deep() {
.uni-icons {
color: $brand-theme-color !important;
}
}
.title {
font-size: 26rpx;
padding: 8rpx 0 2rpx;
color: #666;
}
.des {
font-size: 22rpx;
color: #aaa;
}
}
.hoverItem {
transform: scale(0.96);
}
}
}
.rulePop {
background: #fff;
width: 80vw;
min-height: 200rpx;
border-radius: 20rpx;
padding-top: 50rpx;
.title {
font-size: 38rpx;
color: #333;
text-align: center;
}
.desc {
font-size: 30rpx;
color: #999;
line-height: 1.7em;
padding: 50rpx;
display: block;
}
.confirm {
border-top: 1px solid #eee;
line-height: 3.4em;
display: flex;
align-items: center;
justify-content: center;
color: $brand-theme-color;
font-size: 34rpx;
}
}
小程序累计用户数没满500人 T T
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/918416.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!相关文章
HTML5介绍(HTML5特性、HTML5功能) - 指南
HTML5介绍(HTML5特性、HTML5功能) - 指南2025-09-26 14:50
tlnshuju
阅读(0)
评论(0) 收藏
举报pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: blo…
Experiment1
Experiment 1
实验任务1
1.1
#include <stdio.h>
int main() {printf(" O \n");printf("<H>\n");printf("I I\n");printf(" O \n");printf("<H>\n&qu…
读书笔记:Oracle 自动索引:让数据库自己管索引?
我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。本文为个人学…
海安县建设局网站先备案还是先做网站
分类目录:《系统学习Python》总目录 文章《系统学习Python——装饰器:“私有“和“公有“属性案例-[实现私有属性]》中的代码有点复杂,并且你最好自己跟踪运行它,看看它是如何工作的。然而为了帮助你理解,这里给出一些…
1_2025.9.26_1
题目:[https://codeforces.com/problemset/problem/2140/E1]
ac代码:[https://codeforces.com/contest/2140/submission/340570458]
思路:状压dp,因m<=2,n<=20,所以将状态压缩遍历,再根据题解给的式子写即…
故障处理:Oracle RAC集群CTSS时钟同步故障案例分析与解决
我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。本案例来自一…
Linux系统提权-web/普通用户-docker逃逸提权shell交互
Linux系统提权-web/普通用户-docker逃逸&提权&shell交互
docker提权分几种情况
1、权限在docker里面逃逸 提权(宿主机)
2、权限不在docker里面借助docker应用去提权(用户归属是docker组 拉镜像 提权)参考链接h…
网站开发z亿玛酷1负责网页设计与制作策划书
目录
1.加载镜像并进入容器
2.安装依赖
3.在docker外部git-clone lcm
4.将get-clone的lcm复制到容器中
5.编译库
6.将可执行文件复制到容器中
7.进入可执行文件
8.编译可执行文件
9.再开一个终端运行程序
10.将以上容器打成镜像并导出 1.加载镜像并进入容器
sudo do…
PostgreSQL技术大讲堂 - 第106讲:分区表索引优化
PostgreSQL从入门到精通系列课程,100+节PG技术讲解,让你从小白一步步成长为独当一面的PG专业人员,点击这里查看章节内容,持续更新,欢迎加入。
第106讲:重讲分区表索引优化主要内容:1、全局索引与本地分区索引的…
AI智能体:从认知到实践
人工智能时代:时代的机遇和挑战。潮起AI Agent智能体到底是什么,为什么大家都在卷AI智能体1、什么是AI Agent智能体? 规划感知,决策,行动 ===》记忆 =》》大语言模型理解智能体,人工智能的本质是仿生技术,我们…
Kinect屏幕边缘检测不灵敏的解决方案
在做体感项目时,在边缘部分的抓取动作识别非常差于是我做出了优化,不采用原本的映射关系:假设原本人物站在中间,保持位置不动,右手臂向右伸直,终点为屏幕的极限位置此时我们并不将手臂伸直的位置映射到屏幕的极限…
网站建设话术关键词wordpress 仿豆瓣标注
1、目的
使公司的图纸得到有效的控制,确保生产所用的图纸为最新有效版本,避免因图纸管理不当造成的损失。
2、定义
本制度所述的图纸包括产品总装图、装配图、零件图、工装图纸、检具图纸、包装图纸、工艺流程
3、范围
客户提供的图纸,技…
国内做交互网站WordPress 如何去域名授权
对于关系型数据库而言,针对表的检索,一般来说,建立合适的索引就可以达到很好的检索效果。(这里不包含表设计的合理与否)比如像状态列这样可选择性非常低的值,该如何检索? 其实这个已经不是关系…
暴力拓客游戏小程序:助力商家高效引流与裂变的智能解决方案
在数字化营销时代,流量获取与用户裂变成为商家经营的核心需求。暴力拓客游戏小程序(以热门口红游戏为核心载体)应运而生,依托微信生态,通过 “游戏 + 裂变” 模式,为运营商和实体商户提供从流量获取、用户转化到…
vue3小坑之-为什么把ref定义的数组赋值给数组对象后取值为空数组?
天呢,居然两年没有上博客园看过了,呜呜呜,日渐废柴
这次总结一个码代码的时候遇到的问题,为什么把数据赋值给数组对象的某个字段,打印出来的是个空数组?
错误写法一:// 动态获取list值,前端可以增删改查
const …
扫码签到赢大奖小程序:助力多场景获客的智能营销工具
在数字化营销浪潮下,线下场景的流量激活与用户留存成为商家核心需求。由厦门掌界网络开发的 “扫码签到赢大奖” 小程序,依托微信生态,以 “签到 + 抽奖” 为核心模式,为门店、景区、展会等场景提供低成本、高效率…
seo基础入门汉中网站seo
公司里绝大多数主机已经禁止外网访问,仅保留一台主机设置socks作为代理服务器。如下为对socks这一概念的学习整理
什么是socks
是一种OSI模型下会话层的协议,位于表示层与传输层之间,作用是: exchanges network packets between…
贵阳建站推广公司蜘蛛搜索引擎
字符编码的问题看似很小,经常被技术人员忽视,但是很容易导致一些莫名其妙的问题。这里总结了一下字符编码的一些普及性的知识,希望对大家有所帮助。
还是得从ASCII码说起
说到字符编码,不得不说ASCII码的简史。计算机一开始发明…
庐江魅力网做网站号码成都网站开发
物理建模是四旋翼无人机控制系统建模的基础,主要涉及到无人机的物理特性和运动学特性。物理建模的目的是将无人机的运动与输入信号(如控制电压)之间的关系进行数学描述。
四旋翼无人直升机是具有四个输入力和六个坐标输出的欠驱动动力学旋翼…