小程序模板網(wǎng)

日歷:公歷農(nóng)歷轉(zhuǎn)換,calendar-convert

發(fā)布時(shí)間:2018-05-17 08:51 所屬欄目:小程序開發(fā)教程
 
挺好  

示例代碼:
[AppleScript] 純文本查看 復(fù)制代碼
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//morningf@foxmail.com
 
var ccFile = require('../../utils/calendar-converter.js')
var calendarConverter = new ccFile.CalendarConverter();
 
//月份天數(shù)表
var DAY_OF_MONTH = [
    [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
    [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
];
 
//判斷當(dāng)前年是否閏年
var isLeapYear = function(year){
    if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
        return 1
    else
        return 0
};
 
//獲取當(dāng)月有多少天
var getDayCount = function(year, month){
    return DAY_OF_MONTH[isLeapYear(year)][month];
};
 
//獲取當(dāng)前索引下是幾號(hào)
var getDay = function(index) {
    return index - curDayOffset;
};
 
var pageData = {
    date: "",                //當(dāng)前日期字符串
 
    //arr數(shù)據(jù)是與索引對(duì)應(yīng)的數(shù)據(jù)信息
    arrIsShow: [],          //是否顯示此日期
    arrDays: [],            //關(guān)于幾號(hào)的信息
    arrInfoEx: [],          //農(nóng)歷節(jié)假日等擴(kuò)展信息
    arrInfoExShow: [],      //處理后用于顯示的擴(kuò)展信息
 
    //選擇一天時(shí)顯示的信息
    detailData: {
        curDay: "",         //detail中顯示的日信息
        curInfo1: "",
        curInfo2: "",
    }
    
}
 
//設(shè)置當(dāng)前詳細(xì)信息的索引,前臺(tái)的詳細(xì)信息會(huì)被更新
var setCurDetailIndex = function(index){
    var curEx = pageData.arrInfoEx[index];
    curDay = curEx.sDay - 1;
    pageData.detailData.curDay = curEx.sDay;
    pageData.detailData.curInfo1 = "農(nóng)歷" + curEx.lunarMonth + "月" + curEx.lunarDay;
    pageData.detailData.curInfo2 = curEx.cYear+curEx.lunarYear + "年 " + curEx.cMonth + "月 " + curEx.cDay + "日 " + curEx.lunarFestival;
}
 
//刷新全部數(shù)據(jù)
var refreshPageData = function(year, month, day){
    pageData.date = year+'年'+(month+1)+'月';
 
    var offset = new Date(year, month, 1).getDay();
 
    for (var i = 0; i < 42; ++i)
    {
        pageData.arrIsShow[i] = i < offset || i >= getDayCount(year, month) + offset ? false : true;
        pageData.arrDays[i] = i - offset + 1;
        var d = new Date(year, month, i - offset + 1);
        var dEx = calendarConverter.solar2lunar(d);
        pageData.arrInfoEx[i] = dEx;
        if ("" != dEx.lunarFestival)
        {
            pageData.arrInfoExShow[i] = dEx.lunarFestival;
        }
        else if ("初一" === dEx.lunarDay)
        {
            pageData.arrInfoExShow[i] = dEx.lunarMonth + "月";
        }
        else
        {
            pageData.arrInfoExShow[i] = dEx.lunarDay;
        }
    }
 
    setCurDetailIndex(offset + day);
};
 
var curDate = new Date();
var curMonth = curDate.getMonth();
var curYear = curDate.getFullYear();
var curDay = curDate.getDay();
refreshPageData(curYear, curMonth, curDay);
 
Page({
    data: pageData,
 
    onLoad: function(options){
        
    },
 
    goToday: function(e){
        curDate = new Date();
        curMonth = curDate.getMonth();
        curYear = curDate.getFullYear();
        curDay = curDate.getDay();
        refreshPageData(curYear, curMonth, curDay);
        this.setData(pageData);
    },
 
    goLastMonth: function(e){
        if (0 == curMonth)
        {
            curMonth = 11;
            --curYear
        }
        else
        {
            --curMonth;
        }
        refreshPageData(curYear, curMonth, 0);
        this.setData(pageData);
    },
 
    goNextMonth: function(e){
        if (11 == curMonth)
        {
            curMonth = 0;
            ++curYear
        }
        else
        {
            ++curMonth;
        }
        refreshPageData(curYear, curMonth, 0);
        this.setData(pageData);
    },
 
    selectDay: function(e){
        setCurDetailIndex(e.currentTarget.dataset.dayIndex);
        this.setData({
            detailData: pageData.detailData,
        })
    },
 
    bindDateChange: function(e){
        var arr = e.detail.value.split("-");
        refreshPageData(+arr[0], arr[1]-1, arr[2]-1);
        this.setData(pageData);
    },
});


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://22321a.com/wxmini/doc/course/24449.html 復(fù)制鏈接 如需定制請(qǐng)聯(lián)系易優(yōu)客服咨詢:800182392 點(diǎn)擊咨詢
QQ在線咨詢