提交 f9ef3751 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1. 调整使用正则表达式配置强制登陆功能的写法,解决在小程序端的兼容问题。 2. 新增签到功能(培养用户习惯,提升用户粘性)。支持:每日签到奖励、周期性连续7日签到,奖励翻倍。

上级 710a0132
## 1.0.40(2021-07-22)
1. 调整使用正则表达式配置强制登陆功能的写法,解决在小程序端的兼容问题。
2. 新增签到功能(培养用户习惯,提升用户粘性)。支持:每日签到奖励、周期性连续7日签到,奖励翻倍。
## 1.0.39(2021-07-19)
1. 强制登陆配置,新增白名单模式
2. 强制登陆配置,支持正则表达式
......
......@@ -338,8 +338,8 @@ export default async function() {
//pattern
if (needLogin) {
pass = needLogin.every((item) => {
if (item.slice(0, 8) == 'pattern:') {
return !eval(item.slice(8, item.length)).test(url)
if(typeof(item) == 'object' && item.pattern){
return !item.pattern.test(url)
}
return url != item
})
......@@ -347,8 +347,8 @@ export default async function() {
}
if (visitor&&!inLoginPage) {
pass = visitor.some((item) => {
if (item.slice(0, 8) == 'pattern:') {
return eval(item.slice(8, item.length)).test(url)
if(typeof(item) == 'object' && item.pattern){
return item.pattern.test(url)
}
return url == item
})
......
{
"id": "uni-starter",
"displayName": "uni-starter",
"version": "1.0.39",
"version": "1.0.40",
"description": "云端一体应用快速开发基本项目模版",
"keywords": [
"uni-starter",
"login",
"登录模版",
"uniCloud",
"搜索"
"登录",
"搜索",
"uni-id例子"
],
"repository": "https://codechina.csdn.net/dcloud/uni-starter.git",
"engines": {
......
......@@ -23,7 +23,7 @@
<uni-grid :column="3" :highlight="true" @change="change">
<template v-for="(item,i) in gridList">
<uni-grid-item :index="i" :key="i"
v-if="i<3 || i>3&&i<7&&hasLogin || i>7&&uniIDHasRole('admin')"
v-if="i<3 || i>2&&i<6&&hasLogin || i>5&&uniIDHasRole('admin')"
>
<view class="grid-item-box" style="background-color: #fff;">
<image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" />
......@@ -31,7 +31,6 @@
</view>
</uni-grid-item>
</template>
</uni-grid>
</view>
</view>
......
<template>
<view class="center">
<uni-sign-in ref="signIn"></uni-sign-in>
<view class="userInfo" @click.capture="toUserInfo">
<uni-file-picker v-if="userInfo.avatar_file" v-model="userInfo.avatar_file"
fileMediatype="image" :del-icon="false" return-type="object" :image-styles="listStyles" disablePreview
......@@ -60,6 +61,11 @@
],
ucenterList: [
[
{
"title": '签到有奖',
"event": 'signIn',
"icon": "compose"
},
// #ifdef APP-PLUS
{
"title": '去评分',
......@@ -149,6 +155,9 @@
url: "/pages/ucenter/settings/settings"
})
},
signIn(){ //签到
this.$refs.signIn.open()
},
/**
* 个人中心项目列表点击事件
*/
......@@ -211,17 +220,16 @@
uni.showLoading({
mask: true
})
db.collection("uni-id-scores").where('user_id == $env.uid').field('score,balance').get().then((res) => {
db.collection("uni-id-scores").where('"user_id" == $env.uid').field('score,balance').get().then((res) => {
uni.hideLoading()
console.log(res);
const data = res.result.data[0];
let msg = '';
msg = data ? ('当前积分为' + data.balance) : '当前无积分';
msg = data ? ('当前积分为' + data.score) : '当前无积分';
uni.showToast({
title: msg,
icon: 'none'
});
}).finally(() => {
uni.hideLoading()
})
},
async share() {
......
......@@ -29,13 +29,13 @@ module.exports = {
* 注意:黑名单与白名单模式二选一
*/
// "needLogin" : [
// "pattern:/^\\/pages\\/userinfo.*/", //支持正则表达式
// {pattern:/^\/pages\/list.*/}", //支持正则表达式
// "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
// "/uni_modules/uni-feedback/pages/uni-feedback/add"
// ],
"visitor" : [
"/",//注意入口页必须直接写 "/"
"pattern:/^\\/pages\\/list.*/", //支持正则表达式
{"pattern":/^\/pages\/list.*/}, //支持正则表达式
"/pages/grid/grid",
"/pages/ucenter/ucenter",
"/pages/ucenter/about/about",
......
## 1.3.16(2021-05-12)
- 新增 组件示例地址
## 1.3.15(2021-02-04)
- 调整为uni_modules目录规范
{
"id": "uni-calendar",
"displayName": "Calendar 日历",
"version": "1.3.15",
"displayName": "uni-calendar 日历",
"version": "1.3.16",
"description": "日历组件",
"keywords": [
"uni-ui",
"uniui",
"日历",
"",
"打卡",
"日历选择"
],
......
## Calendar 日历
> **组件名:uni-calendar**
> 代码块: `uCalendar`
日历组件
> **注意事项**
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
> - 本组件农历转换使用的js是 [@1900-2100区间内的公历、农历互转](https://github.com/jjonline/calendar.js)
> - 仅支持自定义组件模式
......@@ -94,3 +96,8 @@ export default {
## 组件示例
点击查看:[https://hellouniapp.dcloud.net.cn/pages/extUI/calendar/calendar](https://hellouniapp.dcloud.net.cn/pages/extUI/calendar/calendar)
\ No newline at end of file
<template>
<view>
<uni-popup ref="popup" type="center">
<image class="background-img" src="@/static/uni-sign-in/background.png" mode="width">
</image>
<view class="content">
<view class="main">
<text class="title">今日签到成功</text>
<text class="total">本轮已签到{{signInRes.days.length}}</text>
<text class="scores">当前积分:{{signInRes.score}}</text>
</view>
<view>
<view class="days-box">
<view class="days" v-for="(item,index) in weekdays" :key="index">
<uni-icons v-if="signInRes.days.includes(item-1)" class="icon active" color="#FFFFFF"
type="checkmarkempty"></uni-icons>
<template v-else>
<uni-icons v-if="item<signInRes.n" class="icon active" color="#FFFFFF"
type="closeempty"></uni-icons>
<uni-icons v-else class="icon" type="checkmarkempty" color="#FFFFFF"></uni-icons>
</template>
<template v-if="signInRes.days.includes(item-1)||item>signInRes.n">
<text class="day" :class="{grey:item>signInRes.n}">第{{item}}</text>
</template>
<text v-else class="day">缺卡</text>
</view>
</view>
<view class="tip-box">
<text class="tip">签到一次得10积分</text>
<view class="row">
<text class="tip">连续签到7天可多得</text>
<text class="red">50</text>
<text class="tip">积分</text>
</view>
</view>
</view>
<uni-icons @click="closeMe" class="close-icon" type="closeempty" size="20" color="#AAAAAA"></uni-icons>
</view>
</uni-popup>
</view>
</template>
<script>
const db = uniCloud.database();
const signInTable = db.collection('opendb-sign-in')
export default {
name: "uni-signIn",
data() {
return {
total: 0,
scores: 0,
weekdays: [1, 2, 3, 4, 5, 6, 7],
signInRes: {
days: [],
n: 0
}
}
},
mounted() {},
methods: {
closeMe(e) {
this.$refs.popup.close()
},
async open() {
uni.showLoading({
mask: true
});
const date = new Date(new Date().toLocaleDateString()).getTime()
let res = await signInTable
.action('signIn')
.where(`'user_id' == $env.uid && 'date' == ${date} && 'isDelete' == false`)
.get()
this.signInRes = res.result
console.log(res);
if (res.result.data.length) {
uni.hideLoading()
uni.showToast({
title: '今日已签过',
duration:3000,
icon: 'none'
});
} else {
let res = await signInTable.action('signIn').add({});
console.log(res);
uni.hideLoading()
this.signInRes = res.result
if(this.signInRes.days.length==7){
uni.showToast({
title:"你已完成7日连续签到,获得60积分!",
icon:"none",
duration:5000
})
}else{
uni.showToast({
title:"签到成功,获得10积分!",
icon:"none",
duration:5000
})
}
}
this.$refs.popup.open()
}
}
}
</script>
<style lang="scss">
.background-img {
width: 600rpx;
height: 600rpx;
}
.content {
position: absolute;
width: 600rpx;
height: 600rpx;
justify-content: space-around;
align-items: center;
border-radius: 10px;
z-index: 5;
}
.background-img,
.content {
top: 0;
}
.main {
align-items: center;
}
.title {
font-size: 44rpx;
color: #FFFFFF;
font-weight: 600;
}
.total {
background-color: #FFFFFF;
color: #ed5200;
text-align: center;
border-radius: 100px;
font-size: 30rpx;
margin: 16rpx 0;
width: 230rpx;
}
.scores {
text-align: center;
color: #FFFFFF;
}
.days-box {
flex-direction: row;
}
.days {
margin: 12rpx;
font-size: 19rpx;
justify-content: center;
align-items: center;
color: #f8692c;
}
.grey{
color: #C0C0C0;
}
.days-box .icon {
background-color: #feefeb;
border-radius: 100px;
height: 50rpx;
line-height: 50rpx;
justify-content: center;
width: 50rpx;
margin-bottom: 6rpx;
}
.days-box .icon.active {
background-image: linear-gradient(to top, #FF9002, #FF5100);
background-color: #ffff7f;
}
.content,
.days-box {
padding: 26rpx;
}
.tip-box {
justify-content: center;
}
.tip-box .row {
flex-direction: row;
justify-content: center;
}
.tip,
.red {
text-align: center;
font-size: 24rpx;
color: #999999;
height: 30rpx;
line-height: 30rpx;
}
.red {
color: #ff0000;
}
.close-icon {
margin-bottom: -180rpx;
background-color: #FFFFFF;
border-radius: 100px;
text-align: center;
height: 46rpx;
line-height: 46rpx;
width: 46rpx;
}
</style>
{
"id": "uni-sign-in",
"displayName": "uni-sign-in",
"version": "1.0.0",
"description": "uni-sign-in",
"keywords": [
"uni-sign-in"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"category": [
"uniCloud",
"云端一体页面模板"
],
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"App": {
"app-vue": "u",
"app-nvue": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uni-sign-in
\ No newline at end of file
// 开发文档:https://uniapp.dcloud.io/uniCloud/clientdb?id=action
const db = uniCloud.database();
const dbCmd = db.command
const signInTable = db.collection('opendb-sign-in');
const scoresTable = db.collection('uni-id-scores');
module.exports = {
before: async (state, event) => {
// console.log({state});
if(state.type == 'create'){
let date = new Date(new Date().toLocaleDateString()).getTime()
let {total} = await signInTable.where({
user_id:state.auth.uid,
date,
isDelete:false
}).count()
console.log(total);
if(total){
throw new Error("今天已经签到")
}
state.newData.date = date
state.newData.isDelete = false
}
},
after: async (state, event, error, result) => {
if (error) {
throw error
}
let date = new Date(new Date().toLocaleDateString()).getTime()
//查最近7天的签到情况
let {data:signInData} = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.gte(date-3600*24*6*1000),
isDelete:false
}).get()
let allDate = signInData.map(item=>item.date)
//今天是本轮签到的第几天
const n = ( date - Math.min(...allDate) )/3600/24/1000+1;
//换成数字--第几天
let days = signInData.map(item=>{
return (n*10000 - (date - item.date)/3600/24/1000*10000)/10000 -1
})
if(state.type == 'create'){
if(n == 7){ //如果已经满一轮就软删除之前的内容
let setIsDeleteRes = await signInTable.where({
user_id:state.auth.uid,
date:dbCmd.neq(date)
}).update({isDelete:true})
console.log({setIsDeleteRes});
}
//给加积分
let addScores = await scoresTable.where({user_id:state.auth.uid}).update({
user_id:state.auth.uid,
score:dbCmd.inc(n==7?60:10) //如果是第七天就多加50分,也就是60分
})
console.log({addScores});
}
//查出来有多少积分
let {data:[{score}]} = await scoresTable.where({user_id:state.auth.uid}).get()
return {...result,score,signInData,n,days}
}
}
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": "auth.uid == doc.user_id",
"create": "auth.uid != null && 'signIn' in action",
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id":{
"forceDefaultValue":{
"$env":"uid"
}
},
"date":{
"bsonType":"timestamp",
"description":"签到的日期时间戳",
"permission":{
"write":false
}
},
"create_time":{
"bsonType":"timestamp",
"description":"签到的时间戳",
"forceDefaultValue":{
"$env":"now"
}
},
"ip":{
"bsonType":"string",
"forceDefaultValue":{
"$env":"clientIP"
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册