From ff6c4f006c5c4194fb730df73dfc766f77c800e6 Mon Sep 17 00:00:00 2001 From: Juzi Date: Mon, 21 Dec 2020 11:20:29 +0800 Subject: [PATCH] build: Travis CI automatic compilation --- examples/dist/calendar/calendar.wxml | 29 ++ .../dist/calendar/components/day/index.js | 16 + .../dist/calendar/components/day/index.json | 3 + .../dist/calendar/components/day/index.wxml | 8 + .../dist/calendar/components/day/index.wxs | 27 ++ .../dist/calendar/components/day/index.wxss | 1 + .../dist/calendar/components/header/index.js | 15 + .../calendar/components/header/index.json | 3 + .../calendar/components/header/index.wxml | 20 + .../calendar/components/header/index.wxss | 1 + .../dist/calendar/components/mounth/index.js | 194 ++++++++++ .../calendar/components/mounth/index.json | 6 + .../calendar/components/mounth/index.wxml | 24 ++ .../dist/calendar/components/mounth/index.wxs | 12 + .../calendar/components/mounth/index.wxss | 1 + examples/dist/calendar/config.js | 3 + examples/dist/calendar/dete.js | 29 ++ examples/dist/calendar/index.js | 342 ++++++++++++++++++ examples/dist/calendar/index.json | 10 + examples/dist/calendar/index.wxml | 10 + examples/dist/calendar/index.wxs | 37 ++ examples/dist/calendar/index.wxss | 1 + examples/dist/calendar/util.js | 113 ++++++ examples/dist/calendar/utils.wxs | 24 ++ 24 files changed, 929 insertions(+) create mode 100644 examples/dist/calendar/calendar.wxml create mode 100644 examples/dist/calendar/components/day/index.js create mode 100644 examples/dist/calendar/components/day/index.json create mode 100644 examples/dist/calendar/components/day/index.wxml create mode 100644 examples/dist/calendar/components/day/index.wxs create mode 100644 examples/dist/calendar/components/day/index.wxss create mode 100644 examples/dist/calendar/components/header/index.js create mode 100644 examples/dist/calendar/components/header/index.json create mode 100644 examples/dist/calendar/components/header/index.wxml create mode 100644 examples/dist/calendar/components/header/index.wxss create mode 100644 examples/dist/calendar/components/mounth/index.js create mode 100644 examples/dist/calendar/components/mounth/index.json create mode 100644 examples/dist/calendar/components/mounth/index.wxml create mode 100644 examples/dist/calendar/components/mounth/index.wxs create mode 100644 examples/dist/calendar/components/mounth/index.wxss create mode 100644 examples/dist/calendar/config.js create mode 100644 examples/dist/calendar/dete.js create mode 100644 examples/dist/calendar/index.js create mode 100644 examples/dist/calendar/index.json create mode 100644 examples/dist/calendar/index.wxml create mode 100644 examples/dist/calendar/index.wxs create mode 100644 examples/dist/calendar/index.wxss create mode 100644 examples/dist/calendar/util.js create mode 100644 examples/dist/calendar/utils.wxs diff --git a/examples/dist/calendar/calendar.wxml b/examples/dist/calendar/calendar.wxml new file mode 100644 index 00000000..d5f49620 --- /dev/null +++ b/examples/dist/calendar/calendar.wxml @@ -0,0 +1,29 @@ + + + diff --git a/examples/dist/calendar/components/day/index.js b/examples/dist/calendar/components/day/index.js new file mode 100644 index 00000000..885993dd --- /dev/null +++ b/examples/dist/calendar/components/day/index.js @@ -0,0 +1,16 @@ +Component({ + data: {}, + properties: { + text: null, + topInfo: null, + bottomInfo: null, + type: null, + color: { + type: String, + value: '' + } + }, + methods: { + + } +}); \ No newline at end of file diff --git a/examples/dist/calendar/components/day/index.json b/examples/dist/calendar/components/day/index.json new file mode 100644 index 00000000..32640e0d --- /dev/null +++ b/examples/dist/calendar/components/day/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} \ No newline at end of file diff --git a/examples/dist/calendar/components/day/index.wxml b/examples/dist/calendar/components/day/index.wxml new file mode 100644 index 00000000..b352152c --- /dev/null +++ b/examples/dist/calendar/components/day/index.wxml @@ -0,0 +1,8 @@ + + + {{ topInfo }} + {{ text }} + {{ bottomInfo }} + \ No newline at end of file diff --git a/examples/dist/calendar/components/day/index.wxs b/examples/dist/calendar/components/day/index.wxs new file mode 100644 index 00000000..b81bd182 --- /dev/null +++ b/examples/dist/calendar/components/day/index.wxs @@ -0,0 +1,27 @@ +function getDayStyle(type, color) { + var style = []; + + if (color) { + if ( + type === 'start' || + type === 'end' || + type === 'selected' + ) { + style.push(['background', color]); + } else if (type === 'middle') { + style.push(['color', color]); + // style.push(['background', color]); + // style.push(['opacity', '0.1']); + } + } + + return style + .map(function(item) { + return item.join(':'); + }) + .join(';'); +} + +module.exports = { + getDayStyle: getDayStyle, +}; \ No newline at end of file diff --git a/examples/dist/calendar/components/day/index.wxss b/examples/dist/calendar/components/day/index.wxss new file mode 100644 index 00000000..e9a84857 --- /dev/null +++ b/examples/dist/calendar/components/day/index.wxss @@ -0,0 +1 @@ +.calendar-day-container{display:flex;flex-direction:column;height:100%;align-items:center;position:relative;color:#666}.calendar-day-container.selected{background-color:#3963bc;color:#fff;border-radius:8rpx}.calendar-day-container.start{background-color:#3963bc;color:#fff;border-radius:8rpx}.calendar-day-container.end{background-color:#3963bc;color:#fff;border-radius:8rpx}.calendar-day-container.disabled{color:#c8c9cc;cursor:default;background:#fff}.calendar-day-container.middle{color:#3963bc}.calendar-day-container.middle::after{position:absolute;top:0;right:0;bottom:0;left:0;background-color:currentColor;opacity:.1;content:''}.calendar-day-container .top{height:24rpx;line-height:24rpx;font-size:16rpx}.calendar-day-container .text{flex:1;font-size:32rpx}.calendar-day-container .bottom{height:24rpx;line-height:24rpx;font-size:16rpx} \ No newline at end of file diff --git a/examples/dist/calendar/components/header/index.js b/examples/dist/calendar/components/header/index.js new file mode 100644 index 00000000..29aa51a8 --- /dev/null +++ b/examples/dist/calendar/components/header/index.js @@ -0,0 +1,15 @@ +Component({ + data: { + weekdays: ['日', '一', '二', '三', '四', '五', '六'] + }, + properties: { + title: { + type: String, + value: '日期选择' + }, + subTitle: String, + showTitle: Boolean, + showSubtitle: Boolean + }, + methods: {} +}); \ No newline at end of file diff --git a/examples/dist/calendar/components/header/index.json b/examples/dist/calendar/components/header/index.json new file mode 100644 index 00000000..32640e0d --- /dev/null +++ b/examples/dist/calendar/components/header/index.json @@ -0,0 +1,3 @@ +{ + "component": true +} \ No newline at end of file diff --git a/examples/dist/calendar/components/header/index.wxml b/examples/dist/calendar/components/header/index.wxml new file mode 100644 index 00000000..3dfeb5e4 --- /dev/null +++ b/examples/dist/calendar/components/header/index.wxml @@ -0,0 +1,20 @@ + + + + + {{ title }} + + + + + {{ subTitle }} + + + + + {{ item }} + + + \ No newline at end of file diff --git a/examples/dist/calendar/components/header/index.wxss b/examples/dist/calendar/components/header/index.wxss new file mode 100644 index 00000000..b9566429 --- /dev/null +++ b/examples/dist/calendar/components/header/index.wxss @@ -0,0 +1 @@ +.calendar-header-container .calendar-header-container_title{text-align:center;padding:20rpx 0;font-size:36rpx;line-height:44rpx}.calendar-header-container .calendar-header-container_subtitle{text-align:center;font-size:36rpx;line-height:44rpx;margin-bottom:30rpx}.calendar-header-container .calendar-header__weekdays{display:flex;justify-content:center;align-items:center;margin:0 20rpx;padding:10rpx 0;border-bottom:1rpx solid #f3f3f3}.calendar-header-container .calendar-header__weekdays .calendar-header__weekday{width:14.285%;text-align:center} \ No newline at end of file diff --git a/examples/dist/calendar/components/mounth/index.js b/examples/dist/calendar/components/mounth/index.js new file mode 100644 index 00000000..5633ac2d --- /dev/null +++ b/examples/dist/calendar/components/mounth/index.js @@ -0,0 +1,194 @@ +import { compareDay, getMonthEndDay } from '../../util'; +import * as config from '../../config'; +Component({ + data: { + days: [] + }, + properties: { + minDate: { + type: [Date,String,null], + // observer: 'setDays' + }, + maxDate: { + type: [Date,String,null], + // observer: 'setDays' + }, + formatter: { + type: null, + observer: 'setDays' + }, + date: { + type: null, + observer: 'setDays' + }, + currentDate: { + type: [null, Array], + observer() { + this.setDays(); + } + }, + type: { + type: String, + observer: 'setDays' + }, + showMonthTitle: Boolean, + color: { + type: String, + value: '' + } + }, + methods: { + + /** + * 某一天的点击事件 + */ + onClick(event) { + const { item } = event.currentTarget.dataset; + if (item.type !== 'disabled' && item.type !== 'empty') { + this.triggerEvent('clickDay', item); + } + }, + debounce(fn) { + let timer; + return () => { + let that = this; + let args = arguments; + if(timer) clearTimeout(timer); + timer = setTimeout(function() { + fn.apply(that, args); + }, 300); + }; + }, + setDays() { + this.debounce(this.setDay)(); + }, + /** + * 设置某月分的天数 + */ + setDay() { + let days = []; + const startDate = new Date(this.data.date); + const year = startDate.getFullYear(); + const month = startDate.getMonth(); + const day = new Date(year, month, 1).getDay(); + + const totalDay = getMonthEndDay(year, month + 1); + + for (let day = 1; day <= totalDay; day++) { + const date = new Date(year, month, day).getTime(); + const type = this.getDayType(date); + + + let config = { + date, + type, + text: day, + bottomInfo: this.getBottomInfo(type), + topInfo: '' + }; + + if (this.data.formatter) { + config = this.data.formatter(config); + } + days.push(config); + } + + for(let i = 0; i < day; i++) { + days.unshift({ + type: 'empty' + }); + } + + this.setData({ + days + }); + }, + + isDateInCurrent(date) { + const { currentDate } = this.data; + return currentDate.some(item => { + return compareDay(item, date) === 0; + }); + }, + + getMultipleDayType(date) { + const { currentDate } = this.data; + + if (!Array.isArray(currentDate)) { + return ''; + } + + if (this.isDateInCurrent(date)) { + return 'selected'; + } + + return ''; + }, + + getRangeDayType(day) { + const { currentDate } = this.data; + if (!Array.isArray(currentDate)) { + return; + } + + const [startDay, endDay] = currentDate; + + if (!startDay) { + return; + } + const compareToStart = compareDay(day, startDay); + + if (!endDay) { + return compareToStart === 0 ? 'start' : ''; + } + + const compareToEnd = compareDay(day, endDay); + + if (compareToStart === 0) { + return 'start'; + } + + if (compareToEnd === 0) { + return 'end'; + } + + if (compareToStart > 0 && compareToEnd < 0) { + return 'middle'; + } + }, + + // date 循环的某一天 + getDayType(date) { + const { type, minDate, maxDate, currentDate } = this.data; + + if (compareDay(date, minDate) < 0 || compareDay(date, maxDate) > 0) { + return 'disabled'; + } + + if (type === config.TYPE_SINGLE) { + return compareDay(date, currentDate) === 0 ? 'selected' : ''; + } + + if (type === config.TYPE_MULTIPLE) { + return this.getMultipleDayType(date); + } + + if (type === config.TYPE_RANGE) { + return this.getRangeDayType(date); + } + }, + + getBottomInfo(type) { + if (this.data.type === config.TYPE_RANGE) { + if (type === 'start') { + return '开始'; + } + if (type === 'end') { + return '结束'; + } + return ''; + } + return ''; + } + } +}); \ No newline at end of file diff --git a/examples/dist/calendar/components/mounth/index.json b/examples/dist/calendar/components/mounth/index.json new file mode 100644 index 00000000..d03ef78a --- /dev/null +++ b/examples/dist/calendar/components/mounth/index.json @@ -0,0 +1,6 @@ +{ + "component": true, + "usingComponents": { + "day":"../day/index" + } +} diff --git a/examples/dist/calendar/components/mounth/index.wxml b/examples/dist/calendar/components/mounth/index.wxml new file mode 100644 index 00000000..50f6332b --- /dev/null +++ b/examples/dist/calendar/components/mounth/index.wxml @@ -0,0 +1,24 @@ + + + + + {{ computed.formatMonthTitle(date) }} + + + + + + + \ No newline at end of file diff --git a/examples/dist/calendar/components/mounth/index.wxs b/examples/dist/calendar/components/mounth/index.wxs new file mode 100644 index 00000000..3e860b4e --- /dev/null +++ b/examples/dist/calendar/components/mounth/index.wxs @@ -0,0 +1,12 @@ +/* eslint-disable */ + +function formatMonthTitle(date) { + date = getDate(date); + return date.getFullYear() + '年' + (date.getMonth() + 1) + '月'; +} + + + +module.exports = { + formatMonthTitle: formatMonthTitle +}; diff --git a/examples/dist/calendar/components/mounth/index.wxss b/examples/dist/calendar/components/mounth/index.wxss new file mode 100644 index 00000000..3259ccb7 --- /dev/null +++ b/examples/dist/calendar/components/mounth/index.wxss @@ -0,0 +1 @@ +.calendar-mounth-container{color:#333;display:flex;flex-direction:column}.calendar-mounth-container .title{text-align:center;font-weight:800}.calendar-mounth-container .calendar-day-container{display:flex;flex-wrap:wrap}.calendar-mounth-container .calendar-day-container .calendar-day-wrap{width:14.285%} \ No newline at end of file diff --git a/examples/dist/calendar/config.js b/examples/dist/calendar/config.js new file mode 100644 index 00000000..a6dfbfda --- /dev/null +++ b/examples/dist/calendar/config.js @@ -0,0 +1,3 @@ +export const TYPE_SINGLE = 'single'; +export const TYPE_RANGE = 'range'; +export const TYPE_MULTIPLE = 'multiple'; \ No newline at end of file diff --git a/examples/dist/calendar/dete.js b/examples/dist/calendar/dete.js new file mode 100644 index 00000000..ad2ffea4 --- /dev/null +++ b/examples/dist/calendar/dete.js @@ -0,0 +1,29 @@ +const formatFlags = { + format: function(format, date) { + date = new Date(date); + let ret; + const opt = { + 'y+': date.getFullYear().toString(), // 年 + 'M+': (date.getMonth() + 1).toString(), // 月 + 'd+': date.getDate().toString(), // 日 + }; + for (let k in opt) { + ret = new RegExp('(' + k + ')').exec(format); + if (ret) { + format = format.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0'))); + } + } + return format; + } +}; + +formatFlags.format('yyyy/MM/dd', new Date()); +formatFlags.format('yyyy-MM-dd', new Date()); +formatFlags.format('yyyy-M-dd', new Date()); +formatFlags.format('yyyy-M-d', new Date()); +// formatFlags.format('yy-M-dd', new Date()) +formatFlags.format('M-dd', new Date()); +formatFlags.format('MM-dd', new Date()); + + +export default formatFlags; \ No newline at end of file diff --git a/examples/dist/calendar/index.js b/examples/dist/calendar/index.js new file mode 100644 index 00000000..ef1df782 --- /dev/null +++ b/examples/dist/calendar/index.js @@ -0,0 +1,342 @@ +import eventBus from '../core/utils/event-bus.js'; +import validator from '../behaviors/validator'; +import rules from '../behaviors/rules'; +import * as config from './config'; +import formatFlags from './dete'; + +import { getDayByOffset, getDate, compareDay, calcDateNum, copyDates, getTime, formatMonthTitle, compareMonth, getMonths } from './util'; + +Component({ + externalClasses: [ + 'l-class' + ], + behaviors: ['wx://form-field', validator, rules], + properties: { + show: { + type: Boolean, + value: false, + observer(val) { + if (val) { + this.initRect(); + this.scrollIntoView(); + } + } + }, + type: { + type: String, + value: config.TYPE_SINGLE, + options: [config.TYPE_SINGLE, config.TYPE_MULTIPLE, config.TYPE_RANGE], + observer() { + this.setData({ currentDate: this.initCurrentDate() }); + } + }, + color: { + type: String, + value: '' + }, + defaultDate: { + type: [String, Number, Date, Array], + value: '', + observer() { + this.setData({ currentDate: this.initCurrentDate() }); + } + }, + format: { + type: String, + value: 'timestamp' + // value: 'yyyy-MM-dd', + }, + formatter: { + type: [Function, null], + value: null + }, + minDate: { + type: [String, Number, null], + value: Date.now() + }, + maxDate: { + type: [String, Number, null], + value: new Date( + new Date().getFullYear(), + new Date().getMonth() + 6, + new Date().getDate() + ).getTime() + }, + minSelect: { + type: [Number, null], + value: null + }, + maxSelect: { + type: [Number, null], + value: null + }, + allowSameDay: Boolean, + showConfirm: { + type: Boolean, + value: true + }, + confirmText: { + type: String, + value: '确认' + }, + maxLimitMessage: { + type: String + }, + minLimitMessage: { + type: String + }, + showTitle: { + type: Boolean, + value: true + }, + showSubtitle: { + type: Boolean, + value: true + }, + title: { + type: String, + value: '日期选择' + } + + }, + lifetimes: { + attached() { + this.setData({ + currentDate: this.initCurrentDate() + }); + }, + ready() { + if (this.data.show) { + this.initRect(); + this.scrollIntoView(); + } + } + }, + data: { + currentDate: null, + types: config, + subTitle: '', + scrollIntoViewIndex: '' + }, + methods: { + clickDay(event) { + const { type, currentDate, maxLimitMessage, maxSelect, allowSameDay } = this.data; + const { date } = event.detail; + if(type === config.TYPE_SINGLE) { + this.setData({ + currentDate: getTime(date) + }); + this.triggerEvent('linclickday', copyDates(date)); + this.triggerEvent('linselect', copyDates(date)); + } + if(type === config.TYPE_MULTIPLE) { + let _index = null; + const isSelected = currentDate.some((item, index) => { + const res = compareDay(item, date) === 0; + if(res) { + _index = index; + } + return res; + }); + + if(isSelected) { + // 取消选择 + currentDate.splice(_index, 1); + this.setData({ + currentDate: getTime(currentDate) + }); + this.triggerEvent('linunselect', copyDates(currentDate)); + } else { + if(maxSelect && currentDate.length >= maxSelect) { + wx.lin.showToast({ + title: maxLimitMessage || `选择天数不能超过 ${ maxSelect } 天` + }); + this.triggerEvent('linclickday', copyDates(date)); + return; + } + // 添加 + this.setData({ + currentDate: getTime([...currentDate, date]) + }); + this.triggerEvent('linselect', copyDates([...currentDate, date])); + } + this.triggerEvent('linclickday', copyDates(date)); + } + + if(type === config.TYPE_RANGE) { + const [startDay, endDay] = currentDate; + if (startDay && !endDay) { + const compareToStart = compareDay(date, startDay); + if (compareToStart === 1) { + if(this.checkSelectRange([startDay, date])) { + this.setData({ + currentDate: getTime([startDay, date]) + }); + this.triggerEvent('linselect', copyDates([startDay, date])); + } + } + else if (compareToStart === -1) { + // 选择结束日期在开始日期之前 重新开始选择 + this.setData({ + currentDate: getTime([date, null]) + }); + } else if(allowSameDay){ + this.setData({ + currentDate: getTime([date, date]) + }); + } + } + else { + // 重新开始选择 + this.setData({ + currentDate: getTime([date, null]) + }); + } + } + }, + + checkSelectRange(date) { + const { maxSelect, maxLimitMessage, minSelect, minLimitMessage } = this.data; + if (maxSelect && calcDateNum(date) > maxSelect) { + + wx.lin.showToast({ + title: maxLimitMessage || `选择天数不能超过 ${ maxSelect } 天` + }); + return false; + } + + if (minSelect && calcDateNum(date) < minSelect) { + wx.lin.showToast({ + title: minLimitMessage || `选择天数不能少于 ${ minSelect } 天` + }); + return false; + } + + return true; + }, + + initCurrentDate() { + + const { type, minDate, defaultDate, maxDate } = this.data; + const defaultDateIsArr = Array.isArray(defaultDate); + + if (type === config.TYPE_SINGLE) { + if(!defaultDate) { + return minDate; + } + if(defaultDateIsArr) { + return minDate; + } + if(compareDay(defaultDate, minDate) === -1) { + return minDate; + } + if(compareDay(defaultDate, maxDate) === 1) { + return maxDate; + } + return defaultDate; + } + + if(type === config.TYPE_MULTIPLE) { + if(!defaultDate) { + return []; + } + if(defaultDateIsArr) { + return defaultDate.filter(item => { + return compareDay(item, minDate) === 1 && compareDay(item, maxDate) === -1; + }); + } + if(compareDay(defaultDate, minDate) === -1) { + return [minDate]; + } + if(compareDay(defaultDate, maxDate) === 1) { + return [maxDate]; + } + return [minDate]; + } + + if(type === config.TYPE_RANGE) { + if(defaultDateIsArr) { + let [startDay = minDate, endDay] = defaultDate; + if(compareDay(startDay, minDate) === -1 || compareDay(startDay, maxDate) !== -1) { + startDay = minDate; + } + if(!endDay) { + endDay = getDayByOffset(getDate(startDay), 1).getTime(); + } + if(compareDay(endDay, maxDate) === 1 || compareDay(endDay, minDate) === -1) { + endDay = getDayByOffset(getDate(startDay), 1).getTime(); + } + return [ + startDay, + endDay + ]; + } + return [ + minDate, + getDayByOffset(getDate(minDate), 1).getTime() + ]; + } + }, + initRect() { + if (!this.contentObserver !== null && this.contentObserver !== undefined) { + this.contentObserver.disconnect(); + } + const contentObserver = this.createIntersectionObserver({ + thresholds: [0, 0.1, 0.9, 1], + observeAll: true + }); + this.contentObserver = contentObserver; + contentObserver.relativeTo('.calendar-body-wrap'); + contentObserver.observe('.month', res => { + if (res.boundingClientRect.top <= res.relativeRect.top) { + // @ts-ignore + this.setData({ subTitle: formatMonthTitle(res.dataset.date) }); + } + }); + }, + scrollIntoView() { + setTimeout(() => { + const { currentDate, type, show, minDate, maxDate } = this.data; + const targetDate = type === 'single' ? currentDate : currentDate[0]; + const displayed = show; + if (!targetDate || !displayed) { + return; + } + const months = getMonths(minDate, maxDate); + months.some((month, index) => { + if (compareMonth(month, targetDate) === 0) { + this.setData({ scrollIntoViewIndex: `month${index}` }); + return true; + } + return false; + }); + }, 100); + }, + closePicker() { + this.setData({ + show: false + }); + }, + onClickConfirm() { + const {format, type, currentDate} = this.data; + eventBus.emit(`lin-form-blur-${this.id}`, this.id); + let value = null; + if(type === 'single') { + value = format !== 'timestamp' ? formatFlags.format('yyyy-MM-dd', currentDate) : currentDate; + } else { + value = currentDate.map(item => { + return format !== 'timestamp' ? formatFlags.format('yyyy-MM-dd', item) : item; + }); + } + this.triggerEvent('linconfirm', value); + }, + getValues() { + return this.data.currentDate; + }, + reset() { + this.setData({ + currentDate: null + }); + } + } +}); diff --git a/examples/dist/calendar/index.json b/examples/dist/calendar/index.json new file mode 100644 index 00000000..2dc44d1d --- /dev/null +++ b/examples/dist/calendar/index.json @@ -0,0 +1,10 @@ +{ + "component": true, + "usingComponents": { + "header":"./components/header/index", + "mounth":"./components/mounth/index", + "l-toast": "/dist/toast/index", + "l-popup": "/dist/popup/index", + "l-button": "/dist/button/index" + } +} diff --git a/examples/dist/calendar/index.wxml b/examples/dist/calendar/index.wxml new file mode 100644 index 00000000..9fc43c45 --- /dev/null +++ b/examples/dist/calendar/index.wxml @@ -0,0 +1,10 @@ + + + +