Skip to content

[Calendar] 设置自定义 format 函数时,初次加载不显示绑定的函数效果 切换后才会显示 #3836

@fewbadboy

Description

@fewbadboy

tdesign-miniprogram 版本

1.9.6

重现步骤

基础库版本

3.9.0

补充说明

// app.js
App({
  globalData: {
    year: new Date().getFullYear(),
    month: new Date().getMonth() + 1,
    // 初始值,好和请求数据对比区别
    dutyInfo: {
      2: ["test3", null],
      6: [null, "test3"],
    }
  },
  onLaunch() {
    (async() => await this.getDutyInfo(this.globalData.year, this.globalData.month))()
  },
  async getDutyInfo(year, month) {
    try {
      const { data }  = await request(`http://xxx/${year}/${month}`, 'get')
      this.globalData.dutyInfo = data
    } catch (error) {
      console.log(error)
    }
  }
})

返回值结果:

Image
// 部分代码
<t-tabs defaultValue="recommend">
    <t-tab-panel label="值班" value="recommend">
      <t-pull-down-refresh
        value="{{enable}}"
        loadingTexts="{{['下拉刷新', '松手刷新', '正在刷新', '刷新完成']}}"
        bind:refresh="onRefresh"
      >
        <t-calendar
          title="值班信息"
          switch-mode="month" 
          use-popup="{{false}}"
          min-date="{{minDate}}"
          max-date="{{maxDate}}"
          format="{{singleFormat}}"
          bind:select="handleSelect"
          bind:panel-change="handleChange"
        />
        </t-pull-down-refresh>
    </t-tab-panel>

// js
Page({
  data: {
    minDate: 0,
    maxDate: 0,
    singleFormat(params) {
        const app = getApp()
        const yearNow = app.globalData.year
        const monthNow = app.globalData.month
        const dutyInfo = app.globalData.dutyInfo
       

        const { date, day } = params;
        const year = date.getFullYear();
        const month = date.getMonth() + 1;
        
        if (year === yearNow && month === monthNow) {
          const key = String(day);
          const value = app.globalData.dutyInfo[key]

          // 只针对初始的 app.globalData.dutyInfo 生效了,请求后的数据没生效
          if (Array.isArray(value)) {
            const [first, second] = value
            params.prefix = first ? '🌝' : ''
            params.suffix = second ? '🌙' : ''
            params.className = 'on-dutying'
          }

          // 生效
          if ([27].includes(day)) {
            params.prefix = '值班'
            params.className = 'on-dutying'
          }
        }
        return params
      },
  }
})

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions