开始做登录
This commit is contained in:
1
miniprogram_npm/@vant/weapp/calendar/components/header/index.d.ts
vendored
Normal file
1
miniprogram_npm/@vant/weapp/calendar/components/header/index.d.ts
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
@@ -0,0 +1,45 @@
|
||||
"use strict";
|
||||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
||||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
||||
if (ar || !(i in from)) {
|
||||
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
||||
ar[i] = from[i];
|
||||
}
|
||||
}
|
||||
return to.concat(ar || Array.prototype.slice.call(from));
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var component_1 = require("../../../common/component");
|
||||
(0, component_1.VantComponent)({
|
||||
props: {
|
||||
title: {
|
||||
type: String,
|
||||
value: '日期选择',
|
||||
},
|
||||
subtitle: String,
|
||||
showTitle: Boolean,
|
||||
showSubtitle: Boolean,
|
||||
firstDayOfWeek: {
|
||||
type: Number,
|
||||
observer: 'initWeekDay',
|
||||
},
|
||||
},
|
||||
data: {
|
||||
weekdays: [],
|
||||
},
|
||||
created: function () {
|
||||
this.initWeekDay();
|
||||
},
|
||||
methods: {
|
||||
initWeekDay: function () {
|
||||
var defaultWeeks = ['日', '一', '二', '三', '四', '五', '六'];
|
||||
var firstDayOfWeek = this.data.firstDayOfWeek || 0;
|
||||
this.setData({
|
||||
weekdays: __spreadArray(__spreadArray([], defaultWeeks.slice(firstDayOfWeek, 7), true), defaultWeeks.slice(0, firstDayOfWeek), true),
|
||||
});
|
||||
},
|
||||
onClickSubtitle: function (event) {
|
||||
this.$emit('click-subtitle', event);
|
||||
},
|
||||
},
|
||||
});
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"component": true
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<view class="van-calendar__header">
|
||||
<block wx:if="{{ showTitle }}">
|
||||
<view class="van-calendar__header-title"><slot name="title"></slot></view>
|
||||
<view class="van-calendar__header-title">{{ title }}</view>
|
||||
</block>
|
||||
|
||||
<view wx:if="{{ showSubtitle }}" class="van-calendar__header-subtitle" bind:tap="onClickSubtitle">
|
||||
{{ subtitle }}
|
||||
</view>
|
||||
|
||||
<view class="van-calendar__weekdays">
|
||||
<view wx:for="{{ weekdays }}" wx:key="index" class="van-calendar__weekday">
|
||||
{{ item }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
@@ -0,0 +1 @@
|
||||
@import '../../../common/index.wxss';.van-calendar__header{box-shadow:var(--calendar-header-box-shadow,0 2px 10px hsla(220,1%,50%,.16));flex-shrink:0}.van-calendar__header-subtitle,.van-calendar__header-title{font-weight:var(--font-weight-bold,500);height:var(--calendar-header-title-height,44px);line-height:var(--calendar-header-title-height,44px);text-align:center}.van-calendar__header-title+.van-calendar__header-title,.van-calendar__header-title:empty{display:none}.van-calendar__header-title:empty+.van-calendar__header-title{display:block!important}.van-calendar__weekdays{display:flex}.van-calendar__weekday{flex:1;font-size:var(--calendar-weekdays-font-size,12px);line-height:var(--calendar-weekdays-height,30px);text-align:center}
|
6
miniprogram_npm/@vant/weapp/calendar/components/month/index.d.ts
vendored
Normal file
6
miniprogram_npm/@vant/weapp/calendar/components/month/index.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface Day {
|
||||
date: Date;
|
||||
type: string;
|
||||
text: number;
|
||||
bottomInfo?: string;
|
||||
}
|
158
miniprogram_npm/@vant/weapp/calendar/components/month/index.js
Normal file
158
miniprogram_npm/@vant/weapp/calendar/components/month/index.js
Normal file
@@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var component_1 = require("../../../common/component");
|
||||
var utils_1 = require("../../utils");
|
||||
(0, component_1.VantComponent)({
|
||||
props: {
|
||||
date: {
|
||||
type: null,
|
||||
observer: 'setDays',
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
observer: 'setDays',
|
||||
},
|
||||
color: String,
|
||||
minDate: {
|
||||
type: null,
|
||||
observer: 'setDays',
|
||||
},
|
||||
maxDate: {
|
||||
type: null,
|
||||
observer: 'setDays',
|
||||
},
|
||||
showMark: Boolean,
|
||||
rowHeight: null,
|
||||
formatter: {
|
||||
type: null,
|
||||
observer: 'setDays',
|
||||
},
|
||||
currentDate: {
|
||||
type: null,
|
||||
observer: 'setDays',
|
||||
},
|
||||
firstDayOfWeek: {
|
||||
type: Number,
|
||||
observer: 'setDays',
|
||||
},
|
||||
allowSameDay: Boolean,
|
||||
showSubtitle: Boolean,
|
||||
showMonthTitle: Boolean,
|
||||
},
|
||||
data: {
|
||||
visible: true,
|
||||
days: [],
|
||||
},
|
||||
methods: {
|
||||
onClick: function (event) {
|
||||
var index = event.currentTarget.dataset.index;
|
||||
var item = this.data.days[index];
|
||||
if (item.type !== 'disabled') {
|
||||
this.$emit('click', item);
|
||||
}
|
||||
},
|
||||
setDays: function () {
|
||||
var days = [];
|
||||
var startDate = new Date(this.data.date);
|
||||
var year = startDate.getFullYear();
|
||||
var month = startDate.getMonth();
|
||||
var totalDay = (0, utils_1.getMonthEndDay)(startDate.getFullYear(), startDate.getMonth() + 1);
|
||||
for (var day = 1; day <= totalDay; day++) {
|
||||
var date = new Date(year, month, day);
|
||||
var type = this.getDayType(date);
|
||||
var config = {
|
||||
date: date,
|
||||
type: type,
|
||||
text: day,
|
||||
bottomInfo: this.getBottomInfo(type),
|
||||
};
|
||||
if (this.data.formatter) {
|
||||
config = this.data.formatter(config);
|
||||
}
|
||||
days.push(config);
|
||||
}
|
||||
this.setData({ days: days });
|
||||
},
|
||||
getMultipleDayType: function (day) {
|
||||
var currentDate = this.data.currentDate;
|
||||
if (!Array.isArray(currentDate)) {
|
||||
return '';
|
||||
}
|
||||
var isSelected = function (date) {
|
||||
return currentDate.some(function (item) { return (0, utils_1.compareDay)(item, date) === 0; });
|
||||
};
|
||||
if (isSelected(day)) {
|
||||
var prevDay = (0, utils_1.getPrevDay)(day);
|
||||
var nextDay = (0, utils_1.getNextDay)(day);
|
||||
var prevSelected = isSelected(prevDay);
|
||||
var nextSelected = isSelected(nextDay);
|
||||
if (prevSelected && nextSelected) {
|
||||
return 'multiple-middle';
|
||||
}
|
||||
if (prevSelected) {
|
||||
return 'end';
|
||||
}
|
||||
return nextSelected ? 'start' : 'multiple-selected';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
getRangeDayType: function (day) {
|
||||
var _a = this.data, currentDate = _a.currentDate, allowSameDay = _a.allowSameDay;
|
||||
if (!Array.isArray(currentDate)) {
|
||||
return '';
|
||||
}
|
||||
var startDay = currentDate[0], endDay = currentDate[1];
|
||||
if (!startDay) {
|
||||
return '';
|
||||
}
|
||||
var compareToStart = (0, utils_1.compareDay)(day, startDay);
|
||||
if (!endDay) {
|
||||
return compareToStart === 0 ? 'start' : '';
|
||||
}
|
||||
var compareToEnd = (0, utils_1.compareDay)(day, endDay);
|
||||
if (compareToStart === 0 && compareToEnd === 0 && allowSameDay) {
|
||||
return 'start-end';
|
||||
}
|
||||
if (compareToStart === 0) {
|
||||
return 'start';
|
||||
}
|
||||
if (compareToEnd === 0) {
|
||||
return 'end';
|
||||
}
|
||||
if (compareToStart > 0 && compareToEnd < 0) {
|
||||
return 'middle';
|
||||
}
|
||||
return '';
|
||||
},
|
||||
getDayType: function (day) {
|
||||
var _a = this.data, type = _a.type, minDate = _a.minDate, maxDate = _a.maxDate, currentDate = _a.currentDate;
|
||||
if ((0, utils_1.compareDay)(day, minDate) < 0 || (0, utils_1.compareDay)(day, maxDate) > 0) {
|
||||
return 'disabled';
|
||||
}
|
||||
if (type === 'single') {
|
||||
return (0, utils_1.compareDay)(day, currentDate) === 0 ? 'selected' : '';
|
||||
}
|
||||
if (type === 'multiple') {
|
||||
return this.getMultipleDayType(day);
|
||||
}
|
||||
/* istanbul ignore else */
|
||||
if (type === 'range') {
|
||||
return this.getRangeDayType(day);
|
||||
}
|
||||
return '';
|
||||
},
|
||||
getBottomInfo: function (type) {
|
||||
if (this.data.type === 'range') {
|
||||
if (type === 'start') {
|
||||
return '开始';
|
||||
}
|
||||
if (type === 'end') {
|
||||
return '结束';
|
||||
}
|
||||
if (type === 'start-end') {
|
||||
return '开始/结束';
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
});
|
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"component": true
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
<wxs src="./index.wxs" module="computed"></wxs>
|
||||
<wxs src="../../../wxs/utils.wxs" module="utils" />
|
||||
|
||||
<view class="van-calendar__month" style="{{ computed.getMonthStyle(visible, date, rowHeight) }}">
|
||||
<view wx:if="{{ showMonthTitle }}" class="van-calendar__month-title">
|
||||
{{ computed.formatMonthTitle(date) }}
|
||||
</view>
|
||||
|
||||
<view wx:if="{{ visible }}" class="van-calendar__days">
|
||||
<view wx:if="{{ showMark }}" class="van-calendar__month-mark">
|
||||
{{ computed.getMark(date) }}
|
||||
</view>
|
||||
|
||||
<view
|
||||
wx:for="{{ days }}"
|
||||
wx:key="index"
|
||||
style="{{ computed.getDayStyle(item.type, index, date, rowHeight, color, firstDayOfWeek) }}"
|
||||
class="{{ utils.bem('calendar__day', [item.type]) }} {{ item.className }}"
|
||||
data-index="{{ index }}"
|
||||
bindtap="onClick"
|
||||
>
|
||||
<view wx:if="{{ item.type === 'selected' }}" class="van-calendar__selected-day" style="width: {{ rowHeight }}px; height: {{ rowHeight }}px; background: {{ color }}">
|
||||
<view wx:if="{{ item.topInfo }}" class="van-calendar__top-info">{{ item.topInfo }}</view>
|
||||
{{ item.text }}
|
||||
<view wx:if="{{ item.bottomInfo }}" class="van-calendar__bottom-info">
|
||||
{{ item.bottomInfo }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:else>
|
||||
<view wx:if="{{ item.topInfo }}" class="van-calendar__top-info">{{ item.topInfo }}</view>
|
||||
{{ item.text }}
|
||||
<view wx:if="{{ item.bottomInfo }}" class="van-calendar__bottom-info">
|
||||
{{ item.bottomInfo }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
@@ -0,0 +1,71 @@
|
||||
/* eslint-disable */
|
||||
var utils = require('../../utils.wxs');
|
||||
|
||||
function getMark(date) {
|
||||
return getDate(date).getMonth() + 1;
|
||||
}
|
||||
|
||||
var ROW_HEIGHT = 64;
|
||||
|
||||
function getDayStyle(type, index, date, rowHeight, color, firstDayOfWeek) {
|
||||
var style = [];
|
||||
var current = getDate(date).getDay() || 7;
|
||||
var offset = current < firstDayOfWeek ? (7 - firstDayOfWeek + current) :
|
||||
current === 7 && firstDayOfWeek === 0 ? 0 :
|
||||
(current - firstDayOfWeek);
|
||||
|
||||
if (index === 0) {
|
||||
style.push(['margin-left', (100 * offset) / 7 + '%']);
|
||||
}
|
||||
|
||||
if (rowHeight !== ROW_HEIGHT) {
|
||||
style.push(['height', rowHeight + 'px']);
|
||||
}
|
||||
|
||||
if (color) {
|
||||
if (
|
||||
type === 'start' ||
|
||||
type === 'end' ||
|
||||
type === 'start-end' ||
|
||||
type === 'multiple-selected' ||
|
||||
type === 'multiple-middle'
|
||||
) {
|
||||
style.push(['background', color]);
|
||||
} else if (type === 'middle') {
|
||||
style.push(['color', color]);
|
||||
}
|
||||
}
|
||||
|
||||
return style
|
||||
.map(function(item) {
|
||||
return item.join(':');
|
||||
})
|
||||
.join(';');
|
||||
}
|
||||
|
||||
function formatMonthTitle(date) {
|
||||
date = getDate(date);
|
||||
return date.getFullYear() + '年' + (date.getMonth() + 1) + '月';
|
||||
}
|
||||
|
||||
function getMonthStyle(visible, date, rowHeight) {
|
||||
if (!visible) {
|
||||
date = getDate(date);
|
||||
|
||||
var totalDay = utils.getMonthEndDay(
|
||||
date.getFullYear(),
|
||||
date.getMonth() + 1
|
||||
);
|
||||
var offset = getDate(date).getDay();
|
||||
var padding = Math.ceil((totalDay + offset) / 7) * rowHeight;
|
||||
|
||||
return 'padding-bottom:' + padding + 'px';
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getMark: getMark,
|
||||
getDayStyle: getDayStyle,
|
||||
formatMonthTitle: formatMonthTitle,
|
||||
getMonthStyle: getMonthStyle
|
||||
};
|
@@ -0,0 +1 @@
|
||||
@import '../../../common/index.wxss';.van-calendar{background-color:var(--calendar-background-color,#fff);display:flex;flex-direction:column;height:100%}.van-calendar__month-title{font-size:var(--calendar-month-title-font-size,14px);font-weight:var(--font-weight-bold,500);height:var(--calendar-header-title-height,44px);line-height:var(--calendar-header-title-height,44px);text-align:center}.van-calendar__days{display:flex;flex-wrap:wrap;position:relative;-webkit-user-select:none;user-select:none}.van-calendar__month-mark{color:var(--calendar-month-mark-color,rgba(242,243,245,.8));font-size:var(--calendar-month-mark-font-size,160px);left:50%;pointer-events:none;position:absolute;top:50%;transform:translate(-50%,-50%);z-index:0}.van-calendar__day,.van-calendar__selected-day{align-items:center;display:flex;justify-content:center;text-align:center}.van-calendar__day{font-size:var(--calendar-day-font-size,16px);height:var(--calendar-day-height,64px);position:relative;width:14.285%}.van-calendar__day--end,.van-calendar__day--multiple-middle,.van-calendar__day--multiple-selected,.van-calendar__day--start,.van-calendar__day--start-end{background-color:var(--calendar-range-edge-background-color,#ee0a24);color:var(--calendar-range-edge-color,#fff)}.van-calendar__day--start{border-radius:4px 0 0 4px}.van-calendar__day--end{border-radius:0 4px 4px 0}.van-calendar__day--multiple-selected,.van-calendar__day--start-end{border-radius:4px}.van-calendar__day--middle{color:var(--calendar-range-middle-color,#ee0a24)}.van-calendar__day--middle:after{background-color:currentColor;bottom:0;content:"";left:0;opacity:var(--calendar-range-middle-background-opacity,.1);position:absolute;right:0;top:0}.van-calendar__day--disabled{color:var(--calendar-day-disabled-color,#c8c9cc);cursor:default}.van-calendar__bottom-info,.van-calendar__top-info{font-size:var(--calendar-info-font-size,10px);left:0;line-height:var(--calendar-info-line-height,14px);position:absolute;right:0}@media (max-width:350px){.van-calendar__bottom-info,.van-calendar__top-info{font-size:9px}}.van-calendar__top-info{top:6px}.van-calendar__bottom-info{bottom:6px}.van-calendar__selected-day{background-color:var(--calendar-selected-day-background-color,#ee0a24);border-radius:4px;color:var(--calendar-selected-day-color,#fff);height:var(--calendar-selected-day-size,54px);width:var(--calendar-selected-day-size,54px)}
|
Reference in New Issue
Block a user