提交 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.0.39(2021-07-19)
1. 强制登陆配置,新增白名单模式 1. 强制登陆配置,新增白名单模式
2. 强制登陆配置,支持正则表达式 2. 强制登陆配置,支持正则表达式
......
...@@ -337,9 +337,9 @@ export default async function() { ...@@ -337,9 +337,9 @@ export default async function() {
let pass = true let pass = true
//pattern //pattern
if (needLogin) { if (needLogin) {
pass = needLogin.every((item) => { pass = needLogin.every((item) => {
if (item.slice(0, 8) == 'pattern:') { if(typeof(item) == 'object' && item.pattern){
return !eval(item.slice(8, item.length)).test(url) return !item.pattern.test(url)
} }
return url != item return url != item
}) })
...@@ -347,8 +347,8 @@ export default async function() { ...@@ -347,8 +347,8 @@ export default async function() {
} }
if (visitor&&!inLoginPage) { if (visitor&&!inLoginPage) {
pass = visitor.some((item) => { pass = visitor.some((item) => {
if (item.slice(0, 8) == 'pattern:') { if(typeof(item) == 'object' && item.pattern){
return eval(item.slice(8, item.length)).test(url) return item.pattern.test(url)
} }
return url == item return url == item
}) })
......
{ {
"id": "uni-starter", "id": "uni-starter",
"displayName": "uni-starter", "displayName": "uni-starter",
"version": "1.0.39", "version": "1.0.40",
"description": "云端一体应用快速开发基本项目模版", "description": "云端一体应用快速开发基本项目模版",
"keywords": [ "keywords": [
"uni-starter",
"login", "login",
"登录模版", "登录",
"uniCloud", "搜索",
"搜索" "uni-id例子"
], ],
"repository": "https://codechina.csdn.net/dcloud/uni-starter.git", "repository": "https://codechina.csdn.net/dcloud/uni-starter.git",
"engines": { "engines": {
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<uni-grid :column="3" :highlight="true" @change="change"> <uni-grid :column="3" :highlight="true" @change="change">
<template v-for="(item,i) in gridList"> <template v-for="(item,i) in gridList">
<uni-grid-item :index="i" :key="i" <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;"> <view class="grid-item-box" style="background-color: #fff;">
<image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" /> <image :src="'/static/grid/c'+(i+1)+'.png'" class="image" mode="aspectFill" />
...@@ -31,7 +31,6 @@ ...@@ -31,7 +31,6 @@
</view> </view>
</uni-grid-item> </uni-grid-item>
</template> </template>
</uni-grid> </uni-grid>
</view> </view>
</view> </view>
......
<template> <template>
<view class="center"> <view class="center">
<uni-sign-in ref="signIn"></uni-sign-in>
<view class="userInfo" @click.capture="toUserInfo"> <view class="userInfo" @click.capture="toUserInfo">
<uni-file-picker v-if="userInfo.avatar_file" v-model="userInfo.avatar_file" <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 fileMediatype="image" :del-icon="false" return-type="object" :image-styles="listStyles" disablePreview
...@@ -59,7 +60,12 @@ ...@@ -59,7 +60,12 @@
} }
], ],
ucenterList: [ ucenterList: [
[ [
{
"title": '签到有奖',
"event": 'signIn',
"icon": "compose"
},
// #ifdef APP-PLUS // #ifdef APP-PLUS
{ {
"title": '去评分', "title": '去评分',
...@@ -148,6 +154,9 @@ ...@@ -148,6 +154,9 @@
uni.navigateTo({ uni.navigateTo({
url: "/pages/ucenter/settings/settings" url: "/pages/ucenter/settings/settings"
}) })
},
signIn(){ //签到
this.$refs.signIn.open()
}, },
/** /**
* 个人中心项目列表点击事件 * 个人中心项目列表点击事件
...@@ -211,17 +220,16 @@ ...@@ -211,17 +220,16 @@
uni.showLoading({ uni.showLoading({
mask: true 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); console.log(res);
const data = res.result.data[0]; const data = res.result.data[0];
let msg = ''; let msg = '';
msg = data ? ('当前积分为' + data.balance) : '当前无积分'; msg = data ? ('当前积分为' + data.score) : '当前无积分';
uni.showToast({ uni.showToast({
title: msg, title: msg,
icon: 'none' icon: 'none'
}); });
}).finally(() => {
uni.hideLoading()
}) })
}, },
async share() { async share() {
......
...@@ -29,13 +29,13 @@ module.exports = { ...@@ -29,13 +29,13 @@ module.exports = {
* 注意:黑名单与白名单模式二选一 * 注意:黑名单与白名单模式二选一
*/ */
// "needLogin" : [ // "needLogin" : [
// "pattern:/^\\/pages\\/userinfo.*/", //支持正则表达式 // {pattern:/^\/pages\/list.*/}", //支持正则表达式
// "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list", // "/uni_modules/uni-news-favorite/pages/uni-news-favorite/list",
// "/uni_modules/uni-feedback/pages/uni-feedback/add" // "/uni_modules/uni-feedback/pages/uni-feedback/add"
// ], // ],
"visitor" : [ "visitor" : [
"/",//注意入口页必须直接写 "/" "/",//注意入口页必须直接写 "/"
"pattern:/^\\/pages\\/list.*/", //支持正则表达式 {"pattern":/^\/pages\/list.*/}, //支持正则表达式
"/pages/grid/grid", "/pages/grid/grid",
"/pages/ucenter/ucenter", "/pages/ucenter/ucenter",
"/pages/ucenter/about/about", "/pages/ucenter/about/about",
......
## 1.3.15(2021-02-04) ## 1.3.16(2021-05-12)
- 调整为uni_modules目录规范 - 新增 组件示例地址
## 1.3.15(2021-02-04)
- 调整为uni_modules目录规范
<template> <template>
<view class="uni-calendar-item__weeks-box" :class="{ <view class="uni-calendar-item__weeks-box" :class="{
'uni-calendar-item--disable':weeks.disable, 'uni-calendar-item--disable':weeks.disable,
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay, 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
'uni-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) , 'uni-calendar-item--checked':(calendar.fullDate === weeks.fullDate && !weeks.isDay) ,
'uni-calendar-item--before-checked':weeks.beforeMultiple, 'uni-calendar-item--before-checked':weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple, 'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked':weeks.afterMultiple, 'uni-calendar-item--after-checked':weeks.afterMultiple,
}" }"
@click="choiceDate(weeks)"> @click="choiceDate(weeks)">
<view class="uni-calendar-item__weeks-box-item"> <view class="uni-calendar-item__weeks-box-item">
<text v-if="selected&&weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text> <text v-if="selected&&weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
<text class="uni-calendar-item__weeks-box-text" :class="{ <text class="uni-calendar-item__weeks-box-text" :class="{
'uni-calendar-item--isDay-text': weeks.isDay, 'uni-calendar-item--isDay-text': weeks.isDay,
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay, 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay, 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
'uni-calendar-item--before-checked':weeks.beforeMultiple, 'uni-calendar-item--before-checked':weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple, 'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked':weeks.afterMultiple, 'uni-calendar-item--after-checked':weeks.afterMultiple,
'uni-calendar-item--disable':weeks.disable, 'uni-calendar-item--disable':weeks.disable,
}">{{weeks.date}}</text> }">{{weeks.date}}</text>
<text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uni-calendar-item__weeks-lunar-text" :class="{ <text v-if="!lunar&&!weeks.extraInfo && weeks.isDay" class="uni-calendar-item__weeks-lunar-text" :class="{
'uni-calendar-item--isDay-text':weeks.isDay, 'uni-calendar-item--isDay-text':weeks.isDay,
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay, 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay, 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
'uni-calendar-item--before-checked':weeks.beforeMultiple, 'uni-calendar-item--before-checked':weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple, 'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked':weeks.afterMultiple, 'uni-calendar-item--after-checked':weeks.afterMultiple,
}">今天</text> }">今天</text>
<text v-if="lunar&&!weeks.extraInfo" class="uni-calendar-item__weeks-lunar-text" :class="{ <text v-if="lunar&&!weeks.extraInfo" class="uni-calendar-item__weeks-lunar-text" :class="{
'uni-calendar-item--isDay-text':weeks.isDay, 'uni-calendar-item--isDay-text':weeks.isDay,
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay, 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay, 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
'uni-calendar-item--before-checked':weeks.beforeMultiple, 'uni-calendar-item--before-checked':weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple, 'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked':weeks.afterMultiple, 'uni-calendar-item--after-checked':weeks.afterMultiple,
'uni-calendar-item--disable':weeks.disable, 'uni-calendar-item--disable':weeks.disable,
}">{{weeks.isDay?'今天': (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text> }">{{weeks.isDay?'今天': (weeks.lunar.IDayCn === '初一'?weeks.lunar.IMonthCn:weeks.lunar.IDayCn)}}</text>
<text v-if="weeks.extraInfo&&weeks.extraInfo.info" class="uni-calendar-item__weeks-lunar-text" :class="{ <text v-if="weeks.extraInfo&&weeks.extraInfo.info" class="uni-calendar-item__weeks-lunar-text" :class="{
'uni-calendar-item--extra':weeks.extraInfo.info, 'uni-calendar-item--extra':weeks.extraInfo.info,
'uni-calendar-item--isDay-text':weeks.isDay, 'uni-calendar-item--isDay-text':weeks.isDay,
'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay, 'uni-calendar-item--isDay':calendar.fullDate === weeks.fullDate && weeks.isDay,
'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay, 'uni-calendar-item--checked':calendar.fullDate === weeks.fullDate && !weeks.isDay,
'uni-calendar-item--before-checked':weeks.beforeMultiple, 'uni-calendar-item--before-checked':weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple, 'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked':weeks.afterMultiple, 'uni-calendar-item--after-checked':weeks.afterMultiple,
'uni-calendar-item--disable':weeks.disable, 'uni-calendar-item--disable':weeks.disable,
}">{{weeks.extraInfo.info}}</text> }">{{weeks.extraInfo.info}}</text>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
props: { props: {
weeks: { weeks: {
type: Object, type: Object,
default () { default () {
return {} return {}
} }
}, },
calendar: { calendar: {
type: Object, type: Object,
default: () => { default: () => {
return {} return {}
} }
}, },
selected: { selected: {
type: Array, type: Array,
default: () => { default: () => {
return [] return []
} }
}, },
lunar: { lunar: {
type: Boolean, type: Boolean,
default: false default: false
} }
}, },
methods: { methods: {
choiceDate(weeks) { choiceDate(weeks) {
this.$emit('change', weeks) this.$emit('change', weeks)
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.uni-calendar-item__weeks-box { .uni-calendar-item__weeks-box {
flex: 1; flex: 1;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
.uni-calendar-item__weeks-box-text { .uni-calendar-item__weeks-box-text {
font-size: $uni-font-size-base; font-size: $uni-font-size-base;
color: $uni-text-color; color: $uni-text-color;
} }
.uni-calendar-item__weeks-lunar-text { .uni-calendar-item__weeks-lunar-text {
font-size: $uni-font-size-sm; font-size: $uni-font-size-sm;
color: $uni-text-color; color: $uni-text-color;
} }
.uni-calendar-item__weeks-box-item { .uni-calendar-item__weeks-box-item {
position: relative; position: relative;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
/* #endif */ /* #endif */
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
width: 100rpx; width: 100rpx;
height: 100rpx; height: 100rpx;
} }
.uni-calendar-item__weeks-box-circle { .uni-calendar-item__weeks-box-circle {
position: absolute; position: absolute;
top: 5px; top: 5px;
right: 5px; right: 5px;
width: 8px; width: 8px;
height: 8px; height: 8px;
border-radius: 8px; border-radius: 8px;
background-color: $uni-color-error; background-color: $uni-color-error;
} }
.uni-calendar-item--disable { .uni-calendar-item--disable {
background-color: rgba(249, 249, 249, $uni-opacity-disabled); background-color: rgba(249, 249, 249, $uni-opacity-disabled);
color: $uni-text-color-disable; color: $uni-text-color-disable;
} }
.uni-calendar-item--isDay-text { .uni-calendar-item--isDay-text {
color: $uni-color-primary; color: $uni-color-primary;
} }
.uni-calendar-item--isDay { .uni-calendar-item--isDay {
background-color: $uni-color-primary; background-color: $uni-color-primary;
opacity: 0.8; opacity: 0.8;
color: #fff; color: #fff;
} }
.uni-calendar-item--extra { .uni-calendar-item--extra {
color: $uni-color-error; color: $uni-color-error;
opacity: 0.8; opacity: 0.8;
} }
.uni-calendar-item--checked { .uni-calendar-item--checked {
background-color: $uni-color-primary; background-color: $uni-color-primary;
color: #fff; color: #fff;
opacity: 0.8; opacity: 0.8;
} }
.uni-calendar-item--multiple { .uni-calendar-item--multiple {
background-color: $uni-color-primary; background-color: $uni-color-primary;
color: #fff; color: #fff;
opacity: 0.8; opacity: 0.8;
} }
.uni-calendar-item--before-checked { .uni-calendar-item--before-checked {
background-color: #ff5a5f; background-color: #ff5a5f;
...@@ -166,5 +166,5 @@ ...@@ -166,5 +166,5 @@
.uni-calendar-item--after-checked { .uni-calendar-item--after-checked {
background-color: #ff5a5f; background-color: #ff5a5f;
color: #fff; color: #fff;
} }
</style> </style>
import CALENDAR from './calendar.js' import CALENDAR from './calendar.js'
class Calendar { class Calendar {
constructor({ constructor({
date, date,
selected, selected,
startDate, startDate,
endDate, endDate,
range range
} = {}) { } = {}) {
// 当前日期 // 当前日期
this.date = this.getDate(new Date()) // 当前初入日期 this.date = this.getDate(new Date()) // 当前初入日期
// 打点信息 // 打点信息
this.selected = selected || []; this.selected = selected || [];
// 范围开始 // 范围开始
this.startDate = startDate this.startDate = startDate
// 范围结束 // 范围结束
this.endDate = endDate this.endDate = endDate
this.range = range this.range = range
// 多选状态 // 多选状态
this.cleanMultipleStatus() this.cleanMultipleStatus()
// 每周日期 // 每周日期
this.weeks = {} this.weeks = {}
// this._getWeek(this.date.fullDate) // this._getWeek(this.date.fullDate)
} }
/** /**
* 设置日期 * 设置日期
* @param {Object} date * @param {Object} date
*/ */
setDate(date) { setDate(date) {
this.selectDate = this.getDate(date) this.selectDate = this.getDate(date)
this._getWeek(this.selectDate.fullDate) this._getWeek(this.selectDate.fullDate)
} }
/** /**
* 清理多选状态 * 清理多选状态
*/ */
cleanMultipleStatus() { cleanMultipleStatus() {
this.multipleStatus = { this.multipleStatus = {
before: '', before: '',
after: '', after: '',
data: [] data: []
} }
} }
/** /**
* 重置开始日期 * 重置开始日期
*/ */
resetSatrtDate(startDate) { resetSatrtDate(startDate) {
// 范围开始 // 范围开始
this.startDate = startDate this.startDate = startDate
} }
/** /**
* 重置结束日期 * 重置结束日期
*/ */
resetEndDate(endDate) { resetEndDate(endDate) {
// 范围结束 // 范围结束
this.endDate = endDate this.endDate = endDate
} }
/** /**
* 获取任意时间 * 获取任意时间
*/ */
getDate(date, AddDayCount = 0, str = 'day') { getDate(date, AddDayCount = 0, str = 'day') {
if (!date) { if (!date) {
date = new Date() date = new Date()
} }
if (typeof date !== 'object') { if (typeof date !== 'object') {
date = date.replace(/-/g, '/') date = date.replace(/-/g, '/')
} }
const dd = new Date(date) const dd = new Date(date)
switch (str) { switch (str) {
case 'day': case 'day':
dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期 dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
break break
case 'month': case 'month':
if (dd.getDate() === 31) { if (dd.getDate() === 31) {
dd.setDate(dd.getDate() + AddDayCount) dd.setDate(dd.getDate() + AddDayCount)
} else { } else {
dd.setMonth(dd.getMonth() + AddDayCount) // 获取AddDayCount天后的日期 dd.setMonth(dd.getMonth() + AddDayCount) // 获取AddDayCount天后的日期
} }
break break
case 'year': case 'year':
dd.setFullYear(dd.getFullYear() + AddDayCount) // 获取AddDayCount天后的日期 dd.setFullYear(dd.getFullYear() + AddDayCount) // 获取AddDayCount天后的日期
break break
} }
const y = dd.getFullYear() const y = dd.getFullYear()
const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0 const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0 const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
return { return {
fullDate: y + '-' + m + '-' + d, fullDate: y + '-' + m + '-' + d,
year: y, year: y,
month: m, month: m,
date: d, date: d,
day: dd.getDay() day: dd.getDay()
} }
} }
/** /**
* 获取上月剩余天数 * 获取上月剩余天数
*/ */
_getLastMonthDays(firstDay, full) { _getLastMonthDays(firstDay, full) {
let dateArr = [] let dateArr = []
for (let i = firstDay; i > 0; i--) { for (let i = firstDay; i > 0; i--) {
const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate() const beforeDate = new Date(full.year, full.month - 1, -i + 1).getDate()
dateArr.push({ dateArr.push({
date: beforeDate, date: beforeDate,
month: full.month - 1, month: full.month - 1,
lunar: this.getlunar(full.year, full.month - 1, beforeDate), lunar: this.getlunar(full.year, full.month - 1, beforeDate),
disable: true disable: true
}) })
} }
return dateArr return dateArr
} }
/** /**
* 获取本月天数 * 获取本月天数
*/ */
_currentMonthDys(dateData, full) { _currentMonthDys(dateData, full) {
let dateArr = [] let dateArr = []
let fullDate = this.date.fullDate let fullDate = this.date.fullDate
for (let i = 1; i <= dateData; i++) { for (let i = 1; i <= dateData; i++) {
let isinfo = false let isinfo = false
let nowDate = full.year + '-' + (full.month < 10 ? let nowDate = full.year + '-' + (full.month < 10 ?
full.month : full.month) + '-' + (i < 10 ? full.month : full.month) + '-' + (i < 10 ?
'0' + i : i) '0' + i : i)
// 是否今天 // 是否今天
let isDay = fullDate === nowDate let isDay = fullDate === nowDate
// 获取打点信息 // 获取打点信息
let info = this.selected && this.selected.find((item) => { let info = this.selected && this.selected.find((item) => {
if (this.dateEqual(nowDate, item.date)) { if (this.dateEqual(nowDate, item.date)) {
return item return item
} }
}) })
// 日期禁用 // 日期禁用
let disableBefore = true let disableBefore = true
let disableAfter = true let disableAfter = true
if (this.startDate) { if (this.startDate) {
let dateCompBefore = this.dateCompare(this.startDate, fullDate) let dateCompBefore = this.dateCompare(this.startDate, fullDate)
disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate) disableBefore = this.dateCompare(dateCompBefore ? this.startDate : fullDate, nowDate)
}
if (this.endDate) {
let dateCompAfter = this.dateCompare(fullDate, this.endDate)
disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate)
} }
let multiples = this.multipleStatus.data
if (this.endDate) { let checked = false
let dateCompAfter = this.dateCompare(fullDate, this.endDate) let multiplesStatus = -1
disableAfter = this.dateCompare(nowDate, dateCompAfter ? this.endDate : fullDate) if (this.range) {
if (multiples) {
multiplesStatus = multiples.findIndex((item) => {
return this.dateEqual(item, nowDate)
})
}
if (multiplesStatus !== -1) {
checked = true
}
}
let data = {
fullDate: nowDate,
year: full.year,
date: i,
multiple: this.range ? checked : false,
beforeMultiple: this.dateEqual(this.multipleStatus.before, nowDate),
afterMultiple: this.dateEqual(this.multipleStatus.after, nowDate),
month: full.month,
lunar: this.getlunar(full.year, full.month, i),
disable: !disableBefore || !disableAfter,
isDay
} }
let multiples = this.multipleStatus.data if (info) {
let checked = false data.extraInfo = info
let multiplesStatus = -1 }
if (this.range) {
if (multiples) { dateArr.push(data)
multiplesStatus = multiples.findIndex((item) => { }
return this.dateEqual(item, nowDate) return dateArr
}) }
} /**
if (multiplesStatus !== -1) { * 获取下月天数
checked = true */
} _getNextMonthDays(surplus, full) {
} let dateArr = []
let data = { for (let i = 1; i < surplus + 1; i++) {
fullDate: nowDate, dateArr.push({
year: full.year, date: i,
date: i, month: Number(full.month) + 1,
multiple: this.range ? checked : false, lunar: this.getlunar(full.year, Number(full.month) + 1, i),
beforeMultiple: this.dateEqual(this.multipleStatus.before, nowDate), disable: true
afterMultiple: this.dateEqual(this.multipleStatus.after, nowDate), })
month: full.month, }
lunar: this.getlunar(full.year, full.month, i), return dateArr
disable: !disableBefore || !disableAfter, }
isDay
} /**
if (info) { * 获取当前日期详情
data.extraInfo = info * @param {Object} date
} */
getInfo(date) {
dateArr.push(data) if (!date) {
} date = new Date()
return dateArr }
} const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate)
/** return dateInfo
* 获取下月天数 }
*/
_getNextMonthDays(surplus, full) { /**
let dateArr = [] * 比较时间大小
for (let i = 1; i < surplus + 1; i++) { */
dateArr.push({ dateCompare(startDate, endDate) {
date: i, // 计算截止时间
month: Number(full.month) + 1, startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
lunar: this.getlunar(full.year, Number(full.month) + 1, i), // 计算详细项的截止时间
disable: true endDate = new Date(endDate.replace('-', '/').replace('-', '/'))
}) if (startDate <= endDate) {
} return true
return dateArr } else {
} return false
}
/** }
* 获取当前日期详情
* @param {Object} date /**
*/ * 比较时间是否相等
getInfo(date) { */
if (!date) { dateEqual(before, after) {
date = new Date() // 计算截止时间
} before = new Date(before.replace('-', '/').replace('-', '/'))
const dateInfo = this.canlender.find(item => item.fullDate === this.getDate(date).fullDate) // 计算详细项的截止时间
return dateInfo after = new Date(after.replace('-', '/').replace('-', '/'))
} if (before.getTime() - after.getTime() === 0) {
return true
/** } else {
* 比较时间大小 return false
*/ }
dateCompare(startDate, endDate) { }
// 计算截止时间
startDate = new Date(startDate.replace('-', '/').replace('-', '/'))
// 计算详细项的截止时间 /**
endDate = new Date(endDate.replace('-', '/').replace('-', '/')) * 获取日期范围内所有日期
if (startDate <= endDate) { * @param {Object} begin
return true * @param {Object} end
} else { */
return false geDateAll(begin, end) {
} var arr = []
} var ab = begin.split('-')
var ae = end.split('-')
/** var db = new Date()
* 比较时间是否相等 db.setFullYear(ab[0], ab[1] - 1, ab[2])
*/ var de = new Date()
dateEqual(before, after) { de.setFullYear(ae[0], ae[1] - 1, ae[2])
// 计算截止时间 var unixDb = db.getTime() - 24 * 60 * 60 * 1000
before = new Date(before.replace('-', '/').replace('-', '/')) var unixDe = de.getTime() - 24 * 60 * 60 * 1000
// 计算详细项的截止时间 for (var k = unixDb; k <= unixDe;) {
after = new Date(after.replace('-', '/').replace('-', '/')) k = k + 24 * 60 * 60 * 1000
if (before.getTime() - after.getTime() === 0) { arr.push(this.getDate(new Date(parseInt(k))).fullDate)
return true }
} else { return arr
return false }
} /**
} * 计算阴历日期显示
*/
getlunar(year, month, date) {
/** return CALENDAR.solar2lunar(year, month, date)
* 获取日期范围内所有日期 }
* @param {Object} begin /**
* @param {Object} end * 设置打点
*/ */
geDateAll(begin, end) { setSelectInfo(data, value) {
var arr = [] this.selected = value
var ab = begin.split('-') this._getWeek(data)
var ae = end.split('-') }
var db = new Date()
db.setFullYear(ab[0], ab[1] - 1, ab[2]) /**
var de = new Date() * 获取多选状态
de.setFullYear(ae[0], ae[1] - 1, ae[2]) */
var unixDb = db.getTime() - 24 * 60 * 60 * 1000 setMultiple(fullDate) {
var unixDe = de.getTime() - 24 * 60 * 60 * 1000 let {
for (var k = unixDb; k <= unixDe;) { before,
k = k + 24 * 60 * 60 * 1000 after
arr.push(this.getDate(new Date(parseInt(k))).fullDate)
}
return arr
}
/**
* 计算阴历日期显示
*/
getlunar(year, month, date) {
return CALENDAR.solar2lunar(year, month, date)
}
/**
* 设置打点
*/
setSelectInfo(data, value) {
this.selected = value
this._getWeek(data)
}
/**
* 获取多选状态
*/
setMultiple(fullDate) {
let {
before,
after
} = this.multipleStatus } = this.multipleStatus
if (!this.range) return if (!this.range) return
if (before && after) { if (before && after) {
this.multipleStatus.before = '' this.multipleStatus.before = ''
this.multipleStatus.after = '' this.multipleStatus.after = ''
this.multipleStatus.data = [] this.multipleStatus.data = []
} else { } else {
if (!before) { if (!before) {
this.multipleStatus.before = fullDate this.multipleStatus.before = fullDate
} else { } else {
this.multipleStatus.after = fullDate this.multipleStatus.after = fullDate
if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) { if (this.dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after); this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
} else { } else {
this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before); this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
} }
} }
}
this._getWeek(fullDate)
}
/**
* 获取每周数据
* @param {Object} dateData
*/
_getWeek(dateData) {
const {
fullDate,
year,
month,
date,
day
} = this.getDate(dateData)
let firstDay = new Date(year, month - 1, 1).getDay()
let currentDay = new Date(year, month, 0).getDate()
let dates = {
lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 上个月末尾几天
currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 本月天数
nextMonthDays: [], // 下个月开始几天
weeks: []
}
let canlender = []
const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
let weeks = {}
// 拼接数组 上个月开始几天 + 本月天数+ 下个月开始几天
for (let i = 0; i < canlender.length; i++) {
if (i % 7 === 0) {
weeks[parseInt(i / 7)] = new Array(7)
}
weeks[parseInt(i / 7)][i % 7] = canlender[i]
} }
this.canlender = canlender this._getWeek(fullDate)
this.weeks = weeks }
}
/**
//静态方法 * 获取每周数据
// static init(date) { * @param {Object} dateData
// if (!this.instance) { */
// this.instance = new Calendar(date); _getWeek(dateData) {
// } const {
// return this.instance; fullDate,
// } year,
} month,
date,
day
} = this.getDate(dateData)
let firstDay = new Date(year, month - 1, 1).getDay()
let currentDay = new Date(year, month, 0).getDate()
let dates = {
lastMonthDays: this._getLastMonthDays(firstDay, this.getDate(dateData)), // 上个月末尾几天
currentMonthDys: this._currentMonthDys(currentDay, this.getDate(dateData)), // 本月天数
nextMonthDays: [], // 下个月开始几天
weeks: []
}
let canlender = []
const surplus = 42 - (dates.lastMonthDays.length + dates.currentMonthDys.length)
dates.nextMonthDays = this._getNextMonthDays(surplus, this.getDate(dateData))
canlender = canlender.concat(dates.lastMonthDays, dates.currentMonthDys, dates.nextMonthDays)
let weeks = {}
// 拼接数组 上个月开始几天 + 本月天数+ 下个月开始几天
for (let i = 0; i < canlender.length; i++) {
if (i % 7 === 0) {
weeks[parseInt(i / 7)] = new Array(7)
}
weeks[parseInt(i / 7)][i % 7] = canlender[i]
}
this.canlender = canlender
this.weeks = weeks
}
//静态方法
// static init(date) {
// if (!this.instance) {
// this.instance = new Calendar(date);
// }
// return this.instance;
// }
}
export default Calendar export default Calendar
{ {
"id": "uni-calendar", "id": "uni-calendar",
"displayName": "Calendar 日历", "displayName": "uni-calendar 日历",
"version": "1.3.15", "version": "1.3.16",
"description": "日历组件", "description": "日历组件",
"keywords": [ "keywords": [
"日历", "uni-ui",
"打卡", "uniui",
"日历选择" "日历",
], "",
"repository": "https://github.com/dcloudio/uni-ui", "打卡",
"engines": { "日历选择"
"HBuilderX": "" ],
}, "repository": "https://github.com/dcloudio/uni-ui",
"directories": { "engines": {
"example": "../../temps/example_temps" "HBuilderX": ""
}, },
"dcloudext": { "directories": {
"category": [ "example": "../../temps/example_temps"
"前端组件", },
"通用组件" "dcloudext": {
], "category": [
"sale": { "前端组件",
"regular": { "通用组件"
"price": "0.00" ],
}, "sale": {
"sourcecode": { "regular": {
"price": "0.00" "price": "0.00"
} },
}, "sourcecode": {
"contact": { "price": "0.00"
"qq": "" }
}, },
"declaration": { "contact": {
"ads": "无", "qq": ""
"data": "无", },
"permissions": "无" "declaration": {
}, "ads": "无",
"npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui" "data": "无",
}, "permissions": "无"
"uni_modules": { },
"dependencies": [], "npmurl": "https://www.npmjs.com/package/@dcloudio/uni-ui"
"encrypt": [], },
"platforms": { "uni_modules": {
"cloud": { "dependencies": [],
"tcb": "y", "encrypt": [],
"aliyun": "y" "platforms": {
}, "cloud": {
"client": { "tcb": "y",
"App": { "aliyun": "y"
"app-vue": "y", },
"app-nvue": "y" "client": {
}, "App": {
"H5-mobile": { "app-vue": "y",
"Safari": "y", "app-nvue": "y"
"Android Browser": "y", },
"微信浏览器(Android)": "y", "H5-mobile": {
"QQ浏览器(Android)": "y" "Safari": "y",
}, "Android Browser": "y",
"H5-pc": { "微信浏览器(Android)": "y",
"Chrome": "y", "QQ浏览器(Android)": "y"
"IE": "y", },
"Edge": "y", "H5-pc": {
"Firefox": "y", "Chrome": "y",
"Safari": "y" "IE": "y",
}, "Edge": "y",
"小程序": { "Firefox": "y",
"微信": "y", "Safari": "y"
"阿里": "y", },
"百度": "y", "小程序": {
"字节跳动": "y", "微信": "y",
"QQ": "y" "阿里": "y",
}, "百度": "y",
"快应用": { "字节跳动": "y",
"华为": "u", "QQ": "y"
"联盟": "u" },
} "快应用": {
} "华为": "u",
} "联盟": "u"
} }
}
}
}
} }
\ No newline at end of file
## Calendar 日历 ## Calendar 日历
> **组件名:uni-calendar**
> 代码块: `uCalendar` > 代码块: `uCalendar`
日历组件 日历组件
> **注意事项**
> 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。 > 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
> - 本组件农历转换使用的js是 [@1900-2100区间内的公历、农历互转](https://github.com/jjonline/calendar.js) > - 本组件农历转换使用的js是 [@1900-2100区间内的公历、农历互转](https://github.com/jjonline/calendar.js)
> - 仅支持自定义组件模式 > - 仅支持自定义组件模式
...@@ -94,3 +96,8 @@ export default { ...@@ -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.
先完成此消息的编辑!
想要评论请 注册