刚来公司不久写的,希望能给大家带来帮助!
cocosCreator日历插件
/*

  • @Author: mikey.ni

  • @Date: 2018-5-14 10:24:46

  • @Last Modified by: mikey.ni

  • @Last Modified time: 2019-01-14 10:41:20

  • @mailbox [email protected]
    */
    import { LayerManager } from “…/…/common/manager/LayerManager”;
    import { UtilTime } from “…/…/common/util/UtilTime”;
    const { ccclass } = cc._decorator;
    @ccclass
    export class CalendarView extends cc.Component {
    private contenArr: Array<cc.Node> = []
    private lblYear: cc.Node = null; //年月日显示
    private conten: cc.Node = null
    private layblue: cc.Node = null;
    private lblLastMonth: cc.Label = null; //上个月
    private lblNextMonth: cc.Label = null; //下个月
    private currentMonth: number = 0; // 当前余额
    private newYear: number = 0;
    private newMonth: number = 0;
    private defauleDayTag: number = null
    public lblCurrentTime: cc.Label = null; //当前选择时间文本
    public nodeDayTime: cc.Node = null //今天时间

    public init() {
    this.conten = this.node.getChildByName(“conten”);
    this.lblYear = this.node.getChildByName(“lblYear”);

     this.layblue = this.node.getChildByName("layblue");
     this.nodeDayTime = this.node.getChildByName("lblDayTime");
    
     let lblLastMonthNode: cc.Node = this.node.getChildByName("lblLasttMonth");
     let lblNextMonthNode: cc.Node = this.node.getChildByName("lblNextMonth");
    
     this.lblLastMonth = lblLastMonthNode.getComponent(cc.Label);
     this.lblNextMonth = lblNextMonthNode.getComponent(cc.Label);
     this.contenArr = this.conten.children;
     let lbl: cc.Label = null;
     for (let i = 0; i < this.contenArr.length; i++) {
         lbl = this.contenArr[i].getComponent(cc.Label);
         if (lbl) {
             lbl.overflow = cc.Label.Overflow.CLAMP;
             lbl.node.setContentSize(40, 40);
         }
     }
    

    }
    onLoad() {
    this.init();
    }
    onEnable() {
    this.addEventNodeFun();
    this.initViewFun();
    }
    onDisable() {
    this.removeEventNodeFun();
    }

    private addEventNodeFun() { //添加监听事件
    let self = this
    this.contenArr = this.conten.children;
    for (let i = 0; i < this.contenArr.length; i++) {
    this.contenArr[i].on(cc.Node.EventType.TOUCH_START, this.upEventReceiveFun, this);
    this.contenArr[i].on(cc.Node.EventType.TOUCH_END, this.upLayblueFun, this);
    }
    this.node.getChildByName(“sprBg”).on(cc.Node.EventType.TOUCH_START, function (event) {
    event.stopPropagation();
    }, this);
    this.node.getChildByName(“eventBg”).on(cc.Node.EventType.TOUCH_START, function (event) {
    event.stopPropagation();
    self.node.active = false;
    }, this);
    this.nodeDayTime.on(cc.Node.EventType.TOUCH_END, this.onUpdateDayTime.bind(this));
    }
    private removeEventNodeFun() {
    this.contenArr = this.conten.children;
    if (!this.node.isValid) return;
    for (let i = 0; i < this.contenArr.length; i++) {
    this.contenArr[i].off(cc.Node.EventType.TOUCH_START, this.upEventReceiveFun, this)
    this.contenArr[i].off(cc.Node.EventType.TOUCH_START, this.upLayblueFun, this)
    }
    this.nodeDayTime.off(cc.Node.EventType.TOUCH_END, this.onUpdateDayTime.bind(this));
    }

    private onUpdateDayTime() {

     this.initViewFun();
    

    }

    private initViewCalendar(start: number, end: number, dcurrent: number = -1) { //列表初始化

     let startS: number = (start == 7) ? 0 : start;//星期
     let k: number = 0;//当月天数;
     let upObj: any = this.getUpMonthMaxDay();
     let upDay: number = upObj.end - startS;//上个月补位天数
     let downDay: number = 0; //下个月补位天数
     for (let i: number = 0; i < this.contenArr.length; i++) {
         this.contenArr[i].getChildByName("lblYinli").getComponent(cc.Label).string = ""
         if (startS <= i && end + startS > i) {
             ++k;
             this.contenArr[i].tag = k;
             if (k == dcurrent) {
                 this.defauleDayTag = i;
             }
             this.contenArr[i].getComponent(cc.Label).string = k.toString();
             //this.contenArr[i].getChildByName("lblYinli").getComponent(cc.Label).string = LunarDate.GetLunarDay(this.newYear, this.newMonth, k)
             this.contenArr[i].color = cc.hexToColor("#FFFFFF")
         } else {
             if (i < startS) {       //上个月的补空位
                 ++upDay;
                 this.contenArr[i].tag = 100 + upDay;
                 this.contenArr[i].getComponent(cc.Label).string = upDay.toString();
    
             } else if (i >= end + startS) {  //下个月补空位
                 ++downDay;
                 this.contenArr[i].getComponent(cc.Label).string = downDay.toString();
                 this.contenArr[i].tag = 200 + downDay;
             }
             this.contenArr[i].color = cc.hexToColor("#999999");
         }
     }
    

    }
    private initViewFun() { //初始化

     let date: Date = new Date()
     let severTime: string = UtilTime.formatYMD1(date);// "";TimeUti.formatYMD1(TimeUtil.getSeverDate())
     this.currentMonth = date.getMonth() + 1;
     cc.log(this.currentMonth)
     this.updateMonth();
     this.lblYear.getComponent(cc.Label).string = severTime;
     let str = severTime.split("/")
     this.newYear = Number(str[0]);
     this.newMonth = Number(str[1]);
     let minAndMax: any = this.getTimeDataFun(this.newYear, this.newMonth)
     this.initViewCalendar(minAndMax.start, minAndMax.end, Number(str[2]));
     let nodeWordPos = this.conten.convertToWorldSpaceAR(this.contenArr[this.defauleDayTag].getPosition());
     let myParentSpacePosition = this.node.convertToNodeSpaceAR(nodeWordPos);
     this.layblue.setPosition(myParentSpacePosition);
     this.layblue.active = true;
    
     this.lblYear.getComponent(cc.Label).string = UtilTime.formatYMD2(date);
     if (this.lblCurrentTime) {
         this.lblCurrentTime.string = UtilTime.formatYMD2(date);;
     }
    

    }

    private updateFun() { //更新
    this.lblYear.getComponent(cc.Label).string = this.newYear + “/” + this.newMonth;
    let minAndMax: any = this.getTimeDataFun(this.newYear, this.newMonth)
    this.initViewCalendar(minAndMax.start, minAndMax.end)
    }

    private upLayblueFun(event) {

     let nodeWordPos = this.conten.convertToWorldSpaceAR(event.target.getPosition());
     let myParentSpacePosition = this.node.convertToNodeSpaceAR(nodeWordPos);
     this.layblue.setPosition(myParentSpacePosition);
     this.layblue.active = true;
    

    }

    private upEventReceiveFun(event) { //点击事件触发
    let yearMonth: any = { yaer: 0, month: 0 };
    let day: number = 0;
    let Tag: number = event.target._tag;
    let YearMD: string = “”;
    if (Tag > 200) {
    day = Math.abs(Tag - 200);
    yearMonth = this.downYaerMonthWayFun();
    } else if (Tag > 100) {
    day = Math.abs(Tag - 100);
    yearMonth = this.upYaerMonthWayFun();
    } else {
    day = Tag;
    yearMonth.yaer = this.newYear;
    yearMonth.month = this.newMonth;
    }
    let monthStr: string = (yearMonth.month < 10 ?“0” : “”)+yearMonth.month;
    let dayStr: string = (day < 10 ? “0”: “”)+day;
    YearMD = yearMonth.yaer + “-” + monthStr + “-” + dayStr;
    this.lblYear.getComponent(cc.Label).string = YearMD;
    cc.log(“事件=================”, yearMonth.yaer + “-” + yearMonth.month + “-” + day);
    if (this.lblCurrentTime) {
    this.lblCurrentTime.string = YearMD;
    }
    }
    private leftBtnFun() {
    if (this.reduceDateFun()) {
    this.layblue.active = false
    this.updateFun()
    } else {
    LayerManager.instance.viewMessagewindow(“超出日期范围”);
    }
    }
    private rigthBtnFun() {
    this.layblue.active = false
    this.addDateFun();
    this.updateFun();
    }
    private reduceDateFun(): boolean {
    if (this.newMonth - 1 > 0) {
    this.newMonth -= 1;
    this.currentMonth = this.newMonth;
    this.updateMonth();
    return true
    } else {
    if (this.newYear - 1 > 1980) {
    this.newYear -= 1;
    this.newMonth = 12;
    this.currentMonth = this.newMonth;
    this.updateMonth();
    return true
    } else {
    return false
    }
    }
    }

    private addDateFun() {

     if (this.newMonth + 1 < 13) {
         this.newMonth += 1;
         this.currentMonth = this.newMonth;
         this.updateMonth();
     } else {
         this.newYear += 1;
         this.newMonth = 1
         this.currentMonth = this.newMonth;
         this.updateMonth();
         // if( this.newYear + 1 < 2020){
         //     this.newYear+=1;
         //     this.newMonth = 1
         // }else{
         //  //cc.log("addDateFun=====提示==", this.newYear)
         // }
     }
    

    }

    private updateMonth() {
    if (this.currentMonth == 12) {

         this.lblNextMonth.string = 1 + "月";
    
         this.lblLastMonth.string = (this.currentMonth - 1) + "月";
    
     } else if (this.currentMonth == 1) {
    
         this.lblNextMonth.string = (this.currentMonth + 1) + "月";
    
         this.lblLastMonth.string = 12 + "月";
     } else {
    
         this.lblNextMonth.string = (this.currentMonth + 1) + "月";
    
         this.lblLastMonth.string = (this.currentMonth - 1) + "月";
     }
    

    }

    private getTimeDataFun(yaer: number, month: number): any {
    let temp: Date = new Date(yaer, month, 0);
    let max: number = temp.getDate()
    temp.setDate(1)
    let min: number = temp.getDay()
    let bol: boolean = (yaer % 4 == 0 && yaer % 100 != 0) || yaer % 400 == 0;
    if (bol) {
    if (month == 2) {
    max = 29;
    }
    } else {
    if (month == 2) {
    max = 28;
    }
    }
    return { start: min, end: max }
    }

    private getUpMonthMaxDay(): any {
    let upYearMonth: any = {};
    upYearMonth = this.upYaerMonthWayFun()
    return this.getTimeDataFun(upYearMonth.yaer, upYearMonth.month)
    }

    private upYaerMonthWayFun(): object {
    let upYear: number = 0;
    let upMonth: number = 0
    if (this.newMonth == 1) {
    upYear = this.newYear - 1
    upMonth = 12;
    } else {
    upYear = this.newYear;
    upMonth = this.newMonth - 1;
    }
    return { yaer: upYear, month: upMonth }
    }
    private downYaerMonthWayFun(): object {

     let downYear: number = 0;
     let downMonth: number = 0
     if (this.newMonth == 12) {
         downYear = this.newYear + 1;
         downMonth = 1;
     } else {
         downYear = this.newYear;
         downMonth = this.newMonth + 1;
     }
     return { yaer: downYear, month: downMonth }
    

    }
    public show() {
    if (!this.node.active) {
    this.node.active = true;
    }
    }
    public hide() {
    if (this.node.active) {
    this.node.active = false;
    }
    }
    }
    // let LunarDate = {
    // madd: new Array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334),
    // HsString: ‘甲乙丙丁戊己庚辛壬癸’,
    // EbString: ‘子丑寅卯辰巳午未申酉戌亥’,
    // NumString: “一二三四五六七八九十”,
    // MonString: “正二三四五六七八九十冬腊”,
    // CalendarData: new Array(0xA4B, 0x5164B, 0x6A5, 0x6D4, 0x415B5, 0x2B6,
    // 0x957, 0x2092F, 0x497, 0x60C96, 0xD4A, 0xEA5, 0x50DA9, 0x5AD, 0x2B6,
    // 0x3126E, 0x92E, 0x7192D, 0xC95, 0xD4A, 0x61B4A, 0xB55, 0x56A, 0x4155B,
    // 0x25D, 0x92D, 0x2192B, 0xA95, 0x71695, 0x6CA, 0xB55, 0x50AB5, 0x4DA,
    // 0xA5B, 0x30A57, 0x52B, 0x8152A, 0xE95, 0x6AA, 0x615AA, 0xAB5, 0x4B6,
    // 0x414AE, 0xA57, 0x526, 0x31D26, 0xD95, 0x70B55, 0x56A, 0x96D, 0x5095D,
    // 0x4AD, 0xA4D, 0x41A4D, 0xD25, 0x81AA5, 0xB54, 0xB6A, 0x612DA, 0x95B, 0x49B,
    // 0x41497, 0xA4B, 0xA164B, 0x6A5, 0x6D4, 0x615B4, 0xAB6, 0x957, 0x5092F, 0x497,
    // 0x64B, 0x30D4A, 0xEA5, 0x80D65, 0x5AC, 0xAB6, 0x5126D, 0x92E, 0xC96, 0x41A95, 0xD4A,
    // 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5,
    // 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95),
    // Year: null,
    // Month: null,
    // Day: null,
    // TheDate: null,
    // GetBit: function (m, n) {
    // return (m >> n) & 1;
    // },
    // e2c: function () {
    // this.TheDate = (arguments.length != 3) ? new Date() : new Date(arguments[0], arguments1, arguments2);
    // var total, m, n, k;
    // var isEnd = false;
    // var tmp = this.TheDate.getFullYear();
    // total = (tmp - 1921) * 365 + Math.floor((tmp - 1921) / 4) + this.madd[this.TheDate.getMonth()] + this.TheDate.getDate() - 38;
    // if (this.TheDate.getYear() % 4 == 0 && this.TheDate.getMonth() > 1) {
    // total++;
    // }
    // for (m = 0; ; m++) {
    // k = (this.CalendarData[m] < 0xfff) ? 11 : 12;
    // for (n = k; n >= 0; n–) {
    // if (total <= 29 + this.GetBit(this.CalendarData[m], n)) {
    // isEnd = true;
    // break;
    // }
    // total = total - 29 - this.GetBit(this.CalendarData[m], n);
    // }
    // if (isEnd)
    // break;
    // }
    // this.Year = 1921 + m;
    // this.Month = k - n + 1;
    // this.Day = total;
    // if (k == 12) {
    // if (this.Month == Math.floor(this.CalendarData[m] / 0x10000) + 1) {
    // this.Month = 1 - this.Month;
    // }
    // if (this.Month > Math.floor(this.CalendarData[m] / 0x10000) + 1) {
    // this.Month–;
    // }
    // }
    // },
    // GetcDateString: function () {
    // var tmp = “”;
    // // tmp += this.HsString.charAt((this.Year - 4) % 10);
    // // tmp += this.EbString.charAt((this.Year - 4) % 12);
    // // tmp += “年 “;
    // let sd =””
    // let monthStr = “”
    // let haoStr = “”

// if (this.Month < 1) {
// // tmp += “(闰)”;
// monthStr = this.MonString.charAt(-this.Month - 1);
// } else {
// monthStr = this.MonString.charAt(this.Month - 1);
// }

// // tmp += “月”;
// haoStr = (this.Day < 11) ? “初” : ((this.Day < 20) ? “十” : ((this.Day < 30) ? “廿” : “三十”));
// if (this.Day % 10 != 0 || this.Day == 10) {
// //tmp += this.NumString.charAt((this.Day - 1) % 10);
// // cc.log(“this.Day==”,this.Day)
// sd = this.NumString.charAt((this.Day - 1) % 10);
// haoStr+=sd
// }
// if(haoStr===“初一”){
// tmp += (monthStr+“月”)
// }else{
// tmp += haoStr
// }
// return tmp;
// },
// GetLunarDay: function (solarYear, solarMonth, solarDay) {
// if (solarYear < 1921|| solarYear > 2020 ) {//
// return “”;
// } else {
// solarMonth = (parseInt(solarMonth) > 0) ? (solarMonth - 1) : 11;
// this.e2c(solarYear, solarMonth, solarDay);
// return this.GetcDateString();
// }
// }
// };

你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。

新的改变

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

  1. 全新的界面设计 ,将会带来全新的写作体验;
  2. 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;
  3. 增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;
  4. 全新的 KaTeX数学公式 语法;
  5. 增加了支持甘特图的mermaid语法1 功能;
  6. 增加了 多屏幕编辑 Markdown文章功能;
  7. 增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;
  8. 增加了 检查列表 功能。

功能快捷键

撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G

合理的创建标题,有助于目录的生成

直接输入1次#,并按下space后,将生成1级标题。
输入2次#,并按下space后,将生成2级标题。
以此类推,我们支持6级标题。有助于使用TOC语法后生成一个完美的目录。

如何改变文本的样式

强调文本 强调文本

加粗文本 加粗文本

标记文本

删除文本

引用文本

H2O is是液体。

210 运算结果是 1024.

插入链接与图片

链接: link.

图片: cocosCreator日历插件

带尺寸的图片: cocosCreator日历插件

居中的图片: cocosCreator日历插件

居中并且带尺寸的图片: cocosCreator日历插件

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

如何插入一段漂亮的代码片

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block
var foo = 'bar';

生成一个适合你的列表

  • 项目
    • 项目
      • 项目
  1. 项目1
  2. 项目2
  3. 项目3
  • 计划任务
  • 完成任务

创建一个表格

一个简单的表格是这么创建的:

项目 Value
电脑 $1600
手机 $12
导管 $1

设定内容居中、居左、居右

使用:---------:居中
使用:----------居左
使用----------:居右

第一列 第二列 第三列
第一列文本居中 第二列文本居右 第三列文本居左

SmartyPants

SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

TYPE ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

创建一个自定义列表

Markdown
Text-to-HTML conversion tool
Authors
John
Luke

如何创建一个注脚

一个具有注脚的文本。2

注释也是必不可少的

Markdown将文本转换为 HTML

KaTeX数学公式

您可以使用渲染LaTeX数学表达式 KaTeX:

Gamma公式展示 Γ(n)=(n1)!nN\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N 是通过欧拉积分

Γ(z)=0tz1etdt&ThinSpace;. \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,.

你可以找到更多关于的信息 LaTeX 数学表达式here.

新的甘特图功能,丰富你的文章

Mon 06Mon 13Mon 20已完成 进行中 计划一 计划二 现有任务Adding GANTT diagram functionality to mermaid
  • 关于 甘特图 语法,参考 这儿,

UML 图表

可以使用UML图表进行渲染。 Mermaid. 例如下面产生的一个序列图::

张三李四王五你好!李四, 最近怎么样?你最近怎么样,王五?我很好,谢谢!我很好,谢谢!李四想了很长时间,文字太长了不适合放在一行.打量着王五...很好... 王五, 你怎么样?张三李四王五

这将产生一个流程图。:

链接
长方形
圆角长方形
菱形
  • 关于 Mermaid 语法,参考 这儿,

FLowchart流程图

我们依旧会支持flowchart的流程图:

Created with Raphaël 2.2.0开始我的操作确认?结束yesno
  • 关于 Flowchart流程图 语法,参考 这儿.

导出与导入

导出

如果你想尝试使用此编辑器, 你可以在此篇文章任意编辑。当你完成了一篇文章的写作, 在上方工具栏找到 文章导出 ,生成一个.md文件或者.html文件进行本地保存。

导入

如果你想加载一篇你写过的.md文件或者.html文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入,
继续你的创作。


  1. mermaid语法说明 ↩︎

  2. 注脚的解释 ↩︎

相关文章: