Element 时间控件限制时间范围

172 阅读1分钟

image.png

pickerOptions: {
            onPick: ({ maxDate, minDate }: any) => {
              // minDate 开始时间 maxDate 结束时间
              this.curDate = minDate && minDate.getTime();
              if (maxDate) {
                this.curDate = '';
              }
              if (maxDate && minDate) {
                // 计算出 minDate  (this.disabled_Day: number) xx天后的时间
                let maxTime = dateAdd(this.disabled_Day, 'd', minDate);
                let newEndTime = parseTime(maxTime, '{y}-{m}-{d} 23:59:59');
                this.$set(this.searchParams.afterTime, 1, newEndTime);
              }
            },
            disabledDate: (time: any) => {
              if (this.curDate) {
                const one = this.disabled_Day * 24 * 3600 * 1000;
                const minTime = this.curDate - one;
                const maxTime = this.curDate + one;
                return time.getTime() < minTime || time.getTime() > maxTime;
              }
            }
          },