fix(code): 修正代码错误及不严谨的地方

This commit is contained in:
2025-12-23 17:56:20 +08:00
parent 5588165f2c
commit d54a7e9f13
98 changed files with 5879 additions and 5879 deletions

View File

@@ -1360,7 +1360,7 @@ export default {
};
</script>
<style lang="scss">
<style>
.my-canvas {
display: flex;
position: fixed !important;

View File

@@ -108,7 +108,7 @@ export default {
};
</script>
<style lang="scss" scoped>
<style scoped>
@keyframes twinkling {
0% {
opacity: 0.2;

View File

@@ -187,7 +187,7 @@ export default {
};
</script>
<style lang="scss" scoped>
<style scoped>
@import './sx-rate/iconfont.css';
</style>

View File

@@ -1,186 +1,186 @@
<template>
<view
class="uni-calendar-item__weeks-box"
:class="{
'uni-calendar-item--disable': weeks.disable,
'uni-calendar-item--isDay': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple
}"
@click="choiceDate(weeks)"
>
<view class="uni-calendar-item__weeks-box-item">
<text v-if="selected && weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
<text class="uni-calendar-item__weeks-box-text"
:class="{
'uni-calendar-item--isDay-text': 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--before-checked': weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ weeks.date }}
</text>
<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': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple
}"
></text>
<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': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ 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="{
'uni-calendar-item--extra': weeks.extraInfo.info,
'uni-calendar-item--isDay-text': 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--before-checked': weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ weeks.extraInfo.info }}
</text>
</view>
</view>
</template>
<script>
export default {
props: {
weeks: {
type: Object,
default() {
return {};
}
},
calendar: {
type: Object,
default: () => {
return {};
}
},
selected: {
type: Array,
default: () => {
return [];
}
},
lunar: {
type: Boolean,
default: false
}
},
methods: {
choiceDate(weeks) {
this.$emit('change', weeks);
}
}
};
</script>
<style lang="scss" scoped>
.uni-calendar-item__weeks-box {
flex: 1;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
}
.uni-calendar-item__weeks-box-text {
font-size: 24rpx;
color: #fff;
}
.uni-calendar-item__weeks-lunar-text {
font-size: $uni-font-size-base;
color: $uni-text-color;
}
.uni-calendar-item__weeks-box-item {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
width: 100rpx;
height: 100rpx;
border-radius: 50%;
}
.uni-calendar-item__weeks-box-circle {
position: absolute;
top: 10rpx;
right: 10rpx;
width: 16rpx;
height: 16rpx;
border-radius: 16rpx;
background-color: $uni-color-error;
}
.uni-calendar-item--disable {
color: #feaa93;
}
.uni-calendar-item--isDay-text {
color: #fff;
}
.uni-calendar-item--isDay {
color: #000;
background-color: #fff;
border-radius: 50%;
}
.uni-calendar-item--extra {
// color: $uni-color-error;
// opacity: 0.8;
}
.uni-calendar-item--checked {
color: #fff;
background: rgba(255, 255, 255, 0.2);
border-radius: 50%;
}
.uni-calendar-item--multiple {
background-color: $uni-color-primary;
color: #fff;
opacity: 0.8;
}
.uni-calendar-item--before-checked {
background-color: #ff5a5f;
color: #fff;
}
.uni-calendar-item--after-checked {
background-color: #ff5a5f;
color: #fff;
}
</style>
<template>
<view
class="uni-calendar-item__weeks-box"
:class="{
'uni-calendar-item--disable': weeks.disable,
'uni-calendar-item--isDay': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple
}"
@click="choiceDate(weeks)"
>
<view class="uni-calendar-item__weeks-box-item">
<text v-if="selected && weeks.extraInfo" class="uni-calendar-item__weeks-box-circle"></text>
<text class="uni-calendar-item__weeks-box-text"
:class="{
'uni-calendar-item--isDay-text': 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--before-checked': weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ weeks.date }}
</text>
<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': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple
}"
></text>
<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': 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--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ 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="{
'uni-calendar-item--extra': weeks.extraInfo.info,
'uni-calendar-item--isDay-text': 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--before-checked': weeks.beforeMultiple,
'uni-calendar-item--multiple': weeks.multiple,
'uni-calendar-item--after-checked': weeks.afterMultiple,
'uni-calendar-item--disable': weeks.disable
}"
>
{{ weeks.extraInfo.info }}
</text>
</view>
</view>
</template>
<script>
export default {
props: {
weeks: {
type: Object,
default() {
return {};
}
},
calendar: {
type: Object,
default: () => {
return {};
}
},
selected: {
type: Array,
default: () => {
return [];
}
},
lunar: {
type: Boolean,
default: false
}
},
methods: {
choiceDate(weeks) {
this.$emit('change', weeks);
}
}
};
</script>
<style lang="scss" scoped>
.uni-calendar-item__weeks-box {
flex: 1;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
}
.uni-calendar-item__weeks-box-text {
font-size: 24rpx;
color: #fff;
}
.uni-calendar-item__weeks-lunar-text {
font-size: $uni-font-size-base;
color: $uni-text-color;
}
.uni-calendar-item__weeks-box-item {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
width: 100rpx;
height: 100rpx;
border-radius: 50%;
}
.uni-calendar-item__weeks-box-circle {
position: absolute;
top: 10rpx;
right: 10rpx;
width: 16rpx;
height: 16rpx;
border-radius: 16rpx;
background-color: $uni-color-error;
}
.uni-calendar-item--disable {
color: #feaa93;
}
.uni-calendar-item--isDay-text {
color: #fff;
}
.uni-calendar-item--isDay {
color: #000;
background-color: #fff;
border-radius: 50%;
}
.uni-calendar-item--extra {
// color: $uni-color-error;
// opacity: 0.8;
}
.uni-calendar-item--checked {
color: #fff;
background: rgba(255, 255, 255, 0.2);
border-radius: 50%;
}
.uni-calendar-item--multiple {
background-color: $uni-color-primary;
color: #fff;
opacity: 0.8;
}
.uni-calendar-item--before-checked {
background-color: #ff5a5f;
color: #fff;
}
.uni-calendar-item--after-checked {
background-color: #ff5a5f;
color: #fff;
}
</style>

View File

@@ -1,476 +1,476 @@
<template>
<view class="uni-calendar">
<view v-if="!insert && show" class="uni-calendar__mask" :class="{ 'uni-calendar--mask-show': aniMaskShow }" @click="clean"></view>
<view v-if="insert || show" class="uni-calendar__content" :class="{ 'uni-calendar--fixed': !insert, 'uni-calendar--ani-show': aniMaskShow }">
<view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top">
<view class="uni-calendar__header-btn-box" @click="close"><text class="uni-calendar__header-text uni-calendar--fixed-width">取消</text></view>
<view class="uni-calendar__header-btn-box" @click="confirm"><text class="uni-calendar__header-text uni-calendar--fixed-width">确定</text></view>
</view>
<view class="uni-calendar__header">
<view class="uni-calendar__header-btn-box" @click.stop="pre">
<!-- <view class="uni-calendar__header-btn uni-calendar--left"></view> -->
<text class="iconfont icon-back_light"></text>
</view>
<picker mode="date" :value="date" fields="month" @change="bindDateChange">
<text class="uni-calendar__header-text">{{ (nowDate.year || '') + '年' + (nowDate.month || '') + '月' }}</text>
</picker>
<view class="uni-calendar__header-btn-box" @click.stop="next">
<!-- <view class="uni-calendar__header-btn uni-calendar--right"></view> -->
<text class="iconfont icon-right"></text>
</view>
</view>
<view class="uni-calendar__box">
<view v-if="showMonth" class="uni-calendar__box-bg">
<text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
</view>
<view class="uni-calendar__weeks">
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
</view>
<view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
<view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
<uni-calendar-item :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></uni-calendar-item>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import Calendar from './util.js';
import uniCalendarItem from './uni-calendar-item.vue';
/**
* Calendar 日历
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
* @property {String} date 自定义当前时间,默认为今天
* @property {Boolean} lunar 显示农历
* @property {String} startDate 日期选择范围-开始日期
* @property {String} endDate 日期选择范围-结束日期
* @property {Boolean} range 范围选择
* @property {Boolean} insert = [true|false] 插入模式,默认为false
* @value true 弹窗模式
* @value false 插入模式
* @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
* @property {Boolean} showMonth 是否选择月份为背景
* @event {Function} change 日期改变,`insert :ture` 时生效
* @event {Function} confirm 确认选择`insert :false` 时生效
* @event {Function} monthSwitch 切换月份时触发
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
*/
export default {
components: {
uniCalendarItem
},
props: {
date: {
type: String,
default: ''
},
selected: {
type: Array,
default() {
return [];
}
},
lunar: {
type: Boolean,
default: false
},
startDate: {
type: String,
default: ''
},
endDate: {
type: String,
default: ''
},
range: {
type: Boolean,
default: false
},
insert: {
type: Boolean,
default: true
},
showMonth: {
type: Boolean,
default: true
},
clearDate: {
type: Boolean,
default: true
}
},
data() {
return {
show: false,
weeks: [],
calendar: {},
nowDate: '',
aniMaskShow: false
};
},
watch: {
date(newVal) {
this.cale.setDate(newVal);
this.init(this.cale.selectDate.fullDate);
},
startDate(val) {
this.cale.resetSatrtDate(val);
},
endDate(val) {
this.cale.resetEndDate(val);
},
selected(newVal) {
this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
this.weeks = this.cale.weeks;
}
},
created() {
// 获取日历方法实例
this.cale = new Calendar({
// date: new Date(),
selected: this.selected,
startDate: this.startDate,
endDate: this.endDate,
range: this.range
});
// 选中某一天
this.cale.setDate(this.date);
this.init(this.cale.selectDate.fullDate);
// this.setDay
},
methods: {
// 取消穿透
clean() {},
bindDateChange(e) {
const value = e.detail.value + '-1';
this.cale.setDate(value);
this.init(value);
},
/**
* 初始化日期显示
* @param {Object} date
*/
init(date) {
this.weeks = this.cale.weeks;
this.nowDate = this.calendar = this.cale.getInfo(date);
},
/**
* 打开日历弹窗
*/
open() {
// 弹窗模式并且清理数据
if (this.clearDate && !this.insert) {
this.cale.cleanMultipleStatus();
this.cale.setDate(this.date);
this.init(this.cale.selectDate.fullDate);
}
this.show = true;
this.$nextTick(() => {
setTimeout(() => {
this.aniMaskShow = true;
}, 50);
});
},
/**
* 关闭日历弹窗
*/
close() {
this.aniMaskShow = false;
this.$nextTick(() => {
setTimeout(() => {
this.show = false;
this.$emit('close');
}, 300);
});
},
/**
* 确认按钮
*/
confirm() {
this.setEmit('confirm');
this.close();
},
/**
* 变化触发
*/
change() {
if (!this.insert) return;
this.setEmit('change');
},
/**
* 选择月份触发
*/
monthSwitch() {
let { year, month } = this.nowDate;
this.$emit('monthSwitch', {
year,
month: Number(month)
});
},
/**
* 派发事件
* @param {Object} name
*/
setEmit(name) {
let { year, month, date, fullDate, lunar, extraInfo } = this.calendar;
this.$emit(name, {
range: this.cale.multipleStatus,
year,
month,
date,
fulldate: fullDate,
lunar,
extraInfo: extraInfo || {}
});
},
/**
* 选择天触发
* @param {Object} weeks
*/
choiceDate(weeks) {
if (weeks.disable) return;
this.calendar = weeks;
// 设置多选
this.cale.setMultiple(this.calendar.fullDate);
this.weeks = this.cale.weeks;
this.change();
},
/**
* 回到今天
*/
backtoday() {
let date = this.cale.getDate(new Date()).fullDate;
this.cale.setDate(date);
this.init(date);
this.change();
},
/**
* 上个月
*/
pre() {
const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate;
this.setDate(preDate);
this.monthSwitch();
},
/**
* 下个月
*/
next() {
const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate;
this.setDate(nextDate);
this.monthSwitch();
},
/**
* 设置日期
* @param {Object} date
*/
setDate(date) {
this.cale.setDate(date);
this.weeks = this.cale.weeks;
this.nowDate = this.cale.getInfo(date);
}
}
};
</script>
<style lang="scss" scoped>
.uni-calendar {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
}
.uni-calendar__mask {
position: fixed;
bottom: 0;
top: 0;
left: 0;
right: 0;
background-color: $uni-bg-color-mask;
transition-property: opacity;
transition-duration: 0.3s;
opacity: 0;
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-calendar--mask-show {
opacity: 1;
}
.uni-calendar--fixed {
position: fixed;
bottom: 0;
left: 0;
right: 0;
transition-property: transform;
transition-duration: 0.3s;
transform: translateY(460px);
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-calendar--ani-show {
transform: translateY(0);
}
.uni-calendar__content {
background: linear-gradient(180deg, rgba(247, 0, 66, 1), rgba(254, 147, 76, 1));
border-bottom-left-radius: 24rpx;
border-bottom-right-radius: 24rpx;
}
.uni-calendar__header {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 56rpx;
width: 657rpx;
margin: 0 auto;
background-color: #fa556a;
border-radius: 28px;
}
.uni-calendar--fixed-top {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: space-between;
border-top-color: $uni-border-color;
border-top-style: solid;
border-top-width: 1px;
}
.uni-calendar--fixed-width {
width: 50px;
// padding: 0 15px;
}
.uni-calendar__backtoday {
position: absolute;
right: 0;
top: 25rpx;
padding: 0 5px;
padding-left: 10px;
height: 25px;
line-height: 25px;
font-size: 12px;
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
color: $uni-text-color;
background-color: $uni-bg-color-hover;
}
.uni-calendar__header-text {
text-align: center;
width: 100px;
font-size: 26rpx;
color: #fff;
}
.uni-calendar__header-btn-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
color: #fff !important;
}
.uni-calendar__header-btn {
width: 10px;
height: 10px;
border-left-color: $uni-text-color-placeholder;
border-left-style: solid;
border-left-width: 2px;
border-top-color: $uni-color-subtitle;
border-top-style: solid;
border-top-width: 2px;
}
.uni-calendar--left {
transform: rotate(-45deg);
}
.uni-calendar--right {
transform: rotate(135deg);
}
.uni-calendar__weeks {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
}
.uni-calendar__weeks-item {
flex: 1;
}
.uni-calendar__weeks-day {
flex: 1;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
height: 45px;
color: #fff;
font-size: 24rpx;
}
.uni-calendar__weeks-day-text {
font-size: 14px;
}
.uni-calendar__box {
position: relative;
}
.uni-calendar__box-bg {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.uni-calendar__box-bg-text {
font-size: 200px;
font-weight: bold;
color: $uni-text-color-grey;
opacity: 0.1;
text-align: center;
/* #ifndef APP-NVUE */
line-height: 1;
/* #endif */
}
</style>
<template>
<view class="uni-calendar">
<view v-if="!insert && show" class="uni-calendar__mask" :class="{ 'uni-calendar--mask-show': aniMaskShow }" @click="clean"></view>
<view v-if="insert || show" class="uni-calendar__content" :class="{ 'uni-calendar--fixed': !insert, 'uni-calendar--ani-show': aniMaskShow }">
<view v-if="!insert" class="uni-calendar__header uni-calendar--fixed-top">
<view class="uni-calendar__header-btn-box" @click="close"><text class="uni-calendar__header-text uni-calendar--fixed-width">取消</text></view>
<view class="uni-calendar__header-btn-box" @click="confirm"><text class="uni-calendar__header-text uni-calendar--fixed-width">确定</text></view>
</view>
<view class="uni-calendar__header">
<view class="uni-calendar__header-btn-box" @click.stop="pre">
<!-- <view class="uni-calendar__header-btn uni-calendar--left"></view> -->
<text class="iconfont icon-back_light"></text>
</view>
<picker mode="date" :value="date" fields="month" @change="bindDateChange">
<text class="uni-calendar__header-text">{{ (nowDate.year || '') + '年' + (nowDate.month || '') + '月' }}</text>
</picker>
<view class="uni-calendar__header-btn-box" @click.stop="next">
<!-- <view class="uni-calendar__header-btn uni-calendar--right"></view> -->
<text class="iconfont icon-right"></text>
</view>
</view>
<view class="uni-calendar__box">
<view v-if="showMonth" class="uni-calendar__box-bg">
<text class="uni-calendar__box-bg-text">{{ nowDate.month }}</text>
</view>
<view class="uni-calendar__weeks">
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
<view class="uni-calendar__weeks-day"><text class="uni-calendar__weeks-day-text"></text></view>
</view>
<view class="uni-calendar__weeks" v-for="(item, weekIndex) in weeks" :key="weekIndex">
<view class="uni-calendar__weeks-item" v-for="(weeks, weeksIndex) in item" :key="weeksIndex">
<uni-calendar-item :weeks="weeks" :calendar="calendar" :selected="selected" :lunar="lunar" @change="choiceDate"></uni-calendar-item>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
import Calendar from './util.js';
import uniCalendarItem from './uni-calendar-item.vue';
/**
* Calendar 日历
* @description 日历组件可以查看日期,选择任意范围内的日期,打点操作。常用场景如:酒店日期预订、火车机票选择购买日期、上下班打卡等
* @tutorial https://ext.dcloud.net.cn/plugin?id=56
* @property {String} date 自定义当前时间,默认为今天
* @property {Boolean} lunar 显示农历
* @property {String} startDate 日期选择范围-开始日期
* @property {String} endDate 日期选择范围-结束日期
* @property {Boolean} range 范围选择
* @property {Boolean} insert = [true|false] 插入模式,默认为false
* @value true 弹窗模式
* @value false 插入模式
* @property {Boolean} clearDate = [true|false] 弹窗模式是否清空上次选择内容
* @property {Array} selected 打点,期待格式[{date: '2019-06-27', info: '签到', data: { custom: '自定义信息', name: '自定义消息头',xxx:xxx... }}]
* @property {Boolean} showMonth 是否选择月份为背景
* @event {Function} change 日期改变,`insert :ture` 时生效
* @event {Function} confirm 确认选择`insert :false` 时生效
* @event {Function} monthSwitch 切换月份时触发
* @example <uni-calendar :insert="true":lunar="true" :start-date="'2019-3-2'":end-date="'2019-5-20'"@change="change" />
*/
export default {
components: {
uniCalendarItem
},
props: {
date: {
type: String,
default: ''
},
selected: {
type: Array,
default() {
return [];
}
},
lunar: {
type: Boolean,
default: false
},
startDate: {
type: String,
default: ''
},
endDate: {
type: String,
default: ''
},
range: {
type: Boolean,
default: false
},
insert: {
type: Boolean,
default: true
},
showMonth: {
type: Boolean,
default: true
},
clearDate: {
type: Boolean,
default: true
}
},
data() {
return {
show: false,
weeks: [],
calendar: {},
nowDate: '',
aniMaskShow: false
};
},
watch: {
date(newVal) {
this.cale.setDate(newVal);
this.init(this.cale.selectDate.fullDate);
},
startDate(val) {
this.cale.resetSatrtDate(val);
},
endDate(val) {
this.cale.resetEndDate(val);
},
selected(newVal) {
this.cale.setSelectInfo(this.nowDate.fullDate, newVal);
this.weeks = this.cale.weeks;
}
},
created() {
// 获取日历方法实例
this.cale = new Calendar({
// date: new Date(),
selected: this.selected,
startDate: this.startDate,
endDate: this.endDate,
range: this.range
});
// 选中某一天
this.cale.setDate(this.date);
this.init(this.cale.selectDate.fullDate);
// this.setDay
},
methods: {
// 取消穿透
clean() {},
bindDateChange(e) {
const value = e.detail.value + '-1';
this.cale.setDate(value);
this.init(value);
},
/**
* 初始化日期显示
* @param {Object} date
*/
init(date) {
this.weeks = this.cale.weeks;
this.nowDate = this.calendar = this.cale.getInfo(date);
},
/**
* 打开日历弹窗
*/
open() {
// 弹窗模式并且清理数据
if (this.clearDate && !this.insert) {
this.cale.cleanMultipleStatus();
this.cale.setDate(this.date);
this.init(this.cale.selectDate.fullDate);
}
this.show = true;
this.$nextTick(() => {
setTimeout(() => {
this.aniMaskShow = true;
}, 50);
});
},
/**
* 关闭日历弹窗
*/
close() {
this.aniMaskShow = false;
this.$nextTick(() => {
setTimeout(() => {
this.show = false;
this.$emit('close');
}, 300);
});
},
/**
* 确认按钮
*/
confirm() {
this.setEmit('confirm');
this.close();
},
/**
* 变化触发
*/
change() {
if (!this.insert) return;
this.setEmit('change');
},
/**
* 选择月份触发
*/
monthSwitch() {
let { year, month } = this.nowDate;
this.$emit('monthSwitch', {
year,
month: Number(month)
});
},
/**
* 派发事件
* @param {Object} name
*/
setEmit(name) {
let { year, month, date, fullDate, lunar, extraInfo } = this.calendar;
this.$emit(name, {
range: this.cale.multipleStatus,
year,
month,
date,
fulldate: fullDate,
lunar,
extraInfo: extraInfo || {}
});
},
/**
* 选择天触发
* @param {Object} weeks
*/
choiceDate(weeks) {
if (weeks.disable) return;
this.calendar = weeks;
// 设置多选
this.cale.setMultiple(this.calendar.fullDate);
this.weeks = this.cale.weeks;
this.change();
},
/**
* 回到今天
*/
backtoday() {
let date = this.cale.getDate(new Date()).fullDate;
this.cale.setDate(date);
this.init(date);
this.change();
},
/**
* 上个月
*/
pre() {
const preDate = this.cale.getDate(this.nowDate.fullDate, -1, 'month').fullDate;
this.setDate(preDate);
this.monthSwitch();
},
/**
* 下个月
*/
next() {
const nextDate = this.cale.getDate(this.nowDate.fullDate, +1, 'month').fullDate;
this.setDate(nextDate);
this.monthSwitch();
},
/**
* 设置日期
* @param {Object} date
*/
setDate(date) {
this.cale.setDate(date);
this.weeks = this.cale.weeks;
this.nowDate = this.cale.getInfo(date);
}
}
};
</script>
<style lang="scss" scoped>
.uni-calendar {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
}
.uni-calendar__mask {
position: fixed;
bottom: 0;
top: 0;
left: 0;
right: 0;
background-color: $uni-bg-color-mask;
transition-property: opacity;
transition-duration: 0.3s;
opacity: 0;
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-calendar--mask-show {
opacity: 1;
}
.uni-calendar--fixed {
position: fixed;
bottom: 0;
left: 0;
right: 0;
transition-property: transform;
transition-duration: 0.3s;
transform: translateY(460px);
/* #ifndef APP-NVUE */
z-index: 99;
/* #endif */
}
.uni-calendar--ani-show {
transform: translateY(0);
}
.uni-calendar__content {
background: linear-gradient(180deg, rgba(247, 0, 66, 1), rgba(254, 147, 76, 1));
border-bottom-left-radius: 24rpx;
border-bottom-right-radius: 24rpx;
}
.uni-calendar__header {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: space-between;
align-items: center;
height: 56rpx;
width: 657rpx;
margin: 0 auto;
background-color: #fa556a;
border-radius: 28px;
}
.uni-calendar--fixed-top {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
justify-content: space-between;
border-top-color: $uni-border-color;
border-top-style: solid;
border-top-width: 1px;
}
.uni-calendar--fixed-width {
width: 50px;
// padding: 0 15px;
}
.uni-calendar__backtoday {
position: absolute;
right: 0;
top: 25rpx;
padding: 0 5px;
padding-left: 10px;
height: 25px;
line-height: 25px;
font-size: 12px;
border-top-left-radius: 25px;
border-bottom-left-radius: 25px;
color: $uni-text-color;
background-color: $uni-bg-color-hover;
}
.uni-calendar__header-text {
text-align: center;
width: 100px;
font-size: 26rpx;
color: #fff;
}
.uni-calendar__header-btn-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
color: #fff !important;
}
.uni-calendar__header-btn {
width: 10px;
height: 10px;
border-left-color: $uni-text-color-placeholder;
border-left-style: solid;
border-left-width: 2px;
border-top-color: $uni-color-subtitle;
border-top-style: solid;
border-top-width: 2px;
}
.uni-calendar--left {
transform: rotate(-45deg);
}
.uni-calendar--right {
transform: rotate(135deg);
}
.uni-calendar__weeks {
position: relative;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
}
.uni-calendar__weeks-item {
flex: 1;
}
.uni-calendar__weeks-day {
flex: 1;
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: column;
justify-content: center;
align-items: center;
height: 45px;
color: #fff;
font-size: 24rpx;
}
.uni-calendar__weeks-day-text {
font-size: 14px;
}
.uni-calendar__box {
position: relative;
}
.uni-calendar__box-bg {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.uni-calendar__box-bg-text {
font-size: 200px;
font-weight: bold;
color: $uni-text-color-grey;
opacity: 0.1;
text-align: center;
/* #ifndef APP-NVUE */
line-height: 1;
/* #endif */
}
</style>

View File

@@ -1,220 +1,220 @@
<template>
<view class="uni-navbar">
<view
:class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }"
:style="{ 'background-color': backgroundColor }"
class="uni-navbar__content">
<uni-status-bar v-if="statusBar" />
<view :style="{ color: color, backgroundColor: backgroundColor }" class="uni-navbar__header uni-navbar__content_view">
<view @tap="onClickLeft" class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
<view class="uni-navbar__content_view" v-if="leftIcon.length"><uni-icons :color="color" :type="leftIcon" size="24" /></view>
<view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view" v-if="leftText.length">
<text :style="{ color: color, fontSize: '14px' }">{{ leftText }}</text>
</view>
<slot name="left" />
</view>
<view class="uni-navbar__header-container uni-navbar__content_view">
<view class="uni-navbar__header-container-inner uni-navbar__content_view" v-if="title.length">
<text class="uni-nav-bar-text" :style="{ color: color }">{{ title }}</text>
</view>
<!-- 标题插槽 -->
<slot />
</view>
<view :class="title.length ? 'uni-navbar__header-btns-right' : ''" @tap="onClickRight" class="uni-navbar__header-btns uni-navbar__content_view">
<view class="uni-navbar__content_view" v-if="rightIcon.length"><uni-icons :color="color" :type="rightIcon" size="24" /></view>
<!-- 优先显示图标 -->
<view class="uni-navbar-btn-text uni-navbar__content_view" v-if="rightText.length && !rightIcon.length">
<text class="uni-nav-bar-right-text">{{ rightText }}</text>
</view>
<slot name="right" />
</view>
</view>
</view>
<view class="uni-navbar__placeholder" v-if="fixed">
<uni-status-bar v-if="statusBar" />
<view class="uni-navbar__placeholder-view" />
</view>
</view>
</template>
<script>
import uniStatusBar from '@/pages_tool/components/uni-status-bar/uni-status-bar.vue';
import uniIcons from '@/components/uni-icons/uni-icons.vue';
export default {
name: 'UniNavBar',
components: {
uniStatusBar,
uniIcons
},
props: {
title: {
type: String,
default: ''
},
leftText: {
type: String,
default: ''
},
rightText: {
type: String,
default: ''
},
leftIcon: {
type: String,
default: ''
},
rightIcon: {
type: String,
default: ''
},
fixed: {
type: [Boolean, String],
default: false
},
color: {
type: String,
default: '#000000'
},
backgroundColor: {
type: String,
default: '#FFFFFF'
},
statusBar: {
type: [Boolean, String],
default: false
},
shadow: {
type: [String, Boolean],
default: false
},
border: {
type: [String, Boolean],
default: true
}
},
mounted() {
if (uni.report && this.title !== '') {
uni.report('title', this.title);
}
},
methods: {
onClickLeft() {
this.$emit('clickLeft');
},
onClickRight() {
this.$emit('clickRight');
}
}
};
</script>
<style lang="scss" scoped>
$nav-height: 44px;
.uni-nav-bar-text {
/* #ifdef APP-PLUS */
font-size: 34rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: $uni-font-size-lg;
/* #endif */
}
.uni-nav-bar-right-text {
font-size: $uni-font-size-base;
}
.uni-navbar {
width: 750rpx;
}
.uni-navbar__content {
position: relative;
width: 750rpx;
background-color: $uni-bg-color;
overflow: hidden;
}
.uni-navbar__content_view {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
flex-direction: row;
// background-color: #FFFFFF;
}
.uni-navbar__header {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
width: 750rpx;
height: $nav-height;
line-height: $nav-height;
font-size: 16px;
// background-color: #ffffff;
}
.uni-navbar__header-btns {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-wrap: nowrap;
width: 120rpx;
padding: 0 6px;
justify-content: center;
align-items: center;
}
.uni-navbar__header-btns-left {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
width: 150rpx;
justify-content: flex-start;
}
.uni-navbar__header-btns-right {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
width: 150rpx;
padding-right: 30rpx;
justify-content: flex-end;
}
.uni-navbar__header-container {
flex: 1;
}
.uni-navbar__header-container-inner {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
align-items: center;
justify-content: center;
font-size: $uni-font-size-base;
}
.uni-navbar__placeholder-view {
height: $nav-height;
}
.uni-navbar--fixed {
position: fixed;
z-index: 998;
}
.uni-navbar--shadow {
/* #ifndef APP-NVUE */
box-shadow: 0 1px 6px #ccc;
/* #endif */
}
.uni-navbar--border {
border-bottom-width: 1rpx;
border-bottom-style: solid;
border-bottom-color: $uni-border-color;
}
</style>
<template>
<view class="uni-navbar">
<view
:class="{ 'uni-navbar--fixed': fixed, 'uni-navbar--shadow': shadow, 'uni-navbar--border': border }"
:style="{ 'background-color': backgroundColor }"
class="uni-navbar__content">
<uni-status-bar v-if="statusBar" />
<view :style="{ color: color, backgroundColor: backgroundColor }" class="uni-navbar__header uni-navbar__content_view">
<view @tap="onClickLeft" class="uni-navbar__header-btns uni-navbar__header-btns-left uni-navbar__content_view">
<view class="uni-navbar__content_view" v-if="leftIcon.length"><uni-icons :color="color" :type="leftIcon" size="24" /></view>
<view :class="{ 'uni-navbar-btn-icon-left': !leftIcon.length }" class="uni-navbar-btn-text uni-navbar__content_view" v-if="leftText.length">
<text :style="{ color: color, fontSize: '14px' }">{{ leftText }}</text>
</view>
<slot name="left" />
</view>
<view class="uni-navbar__header-container uni-navbar__content_view">
<view class="uni-navbar__header-container-inner uni-navbar__content_view" v-if="title.length">
<text class="uni-nav-bar-text" :style="{ color: color }">{{ title }}</text>
</view>
<!-- 标题插槽 -->
<slot />
</view>
<view :class="title.length ? 'uni-navbar__header-btns-right' : ''" @tap="onClickRight" class="uni-navbar__header-btns uni-navbar__content_view">
<view class="uni-navbar__content_view" v-if="rightIcon.length"><uni-icons :color="color" :type="rightIcon" size="24" /></view>
<!-- 优先显示图标 -->
<view class="uni-navbar-btn-text uni-navbar__content_view" v-if="rightText.length && !rightIcon.length">
<text class="uni-nav-bar-right-text">{{ rightText }}</text>
</view>
<slot name="right" />
</view>
</view>
</view>
<view class="uni-navbar__placeholder" v-if="fixed">
<uni-status-bar v-if="statusBar" />
<view class="uni-navbar__placeholder-view" />
</view>
</view>
</template>
<script>
import uniStatusBar from '@/pages_tool/components/uni-status-bar/uni-status-bar.vue';
import uniIcons from '@/components/uni-icons/uni-icons.vue';
export default {
name: 'UniNavBar',
components: {
uniStatusBar,
uniIcons
},
props: {
title: {
type: String,
default: ''
},
leftText: {
type: String,
default: ''
},
rightText: {
type: String,
default: ''
},
leftIcon: {
type: String,
default: ''
},
rightIcon: {
type: String,
default: ''
},
fixed: {
type: [Boolean, String],
default: false
},
color: {
type: String,
default: '#000000'
},
backgroundColor: {
type: String,
default: '#FFFFFF'
},
statusBar: {
type: [Boolean, String],
default: false
},
shadow: {
type: [String, Boolean],
default: false
},
border: {
type: [String, Boolean],
default: true
}
},
mounted() {
if (uni.report && this.title !== '') {
uni.report('title', this.title);
}
},
methods: {
onClickLeft() {
this.$emit('clickLeft');
},
onClickRight() {
this.$emit('clickRight');
}
}
};
</script>
<style lang="scss" scoped>
$nav-height: 44px;
.uni-nav-bar-text {
/* #ifdef APP-PLUS */
font-size: 34rpx;
/* #endif */
/* #ifndef APP-PLUS */
font-size: $uni-font-size-lg;
/* #endif */
}
.uni-nav-bar-right-text {
font-size: $uni-font-size-base;
}
.uni-navbar {
width: 750rpx;
}
.uni-navbar__content {
position: relative;
width: 750rpx;
background-color: $uni-bg-color;
overflow: hidden;
}
.uni-navbar__content_view {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
flex-direction: row;
// background-color: #FFFFFF;
}
.uni-navbar__header {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-direction: row;
width: 750rpx;
height: $nav-height;
line-height: $nav-height;
font-size: 16px;
// background-color: #ffffff;
}
.uni-navbar__header-btns {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex-wrap: nowrap;
width: 120rpx;
padding: 0 6px;
justify-content: center;
align-items: center;
}
.uni-navbar__header-btns-left {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
width: 150rpx;
justify-content: flex-start;
}
.uni-navbar__header-btns-right {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
width: 150rpx;
padding-right: 30rpx;
justify-content: flex-end;
}
.uni-navbar__header-container {
flex: 1;
}
.uni-navbar__header-container-inner {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
flex: 1;
align-items: center;
justify-content: center;
font-size: $uni-font-size-base;
}
.uni-navbar__placeholder-view {
height: $nav-height;
}
.uni-navbar--fixed {
position: fixed;
z-index: 998;
}
.uni-navbar--shadow {
/* #ifndef APP-NVUE */
box-shadow: 0 1px 6px #ccc;
/* #endif */
}
.uni-navbar--border {
border-bottom-width: 1rpx;
border-bottom-style: solid;
border-bottom-color: $uni-border-color;
}
</style>