首页 > 其他分享 >直播软件app开发,vant 时间选择控件修订为只显示年份

直播软件app开发,vant 时间选择控件修订为只显示年份

时间:2022-12-15 14:23:10浏览次数:43  
标签:function 控件 vant app value month year var type

直播软件app开发,vant 时间选择控件修订为只显示年份

 

import _extends from "@babel/runtime/helpers/esm/extends";
import { createNamespace } from '../utils';
import { isDate } from '../utils/validate/date';
import { padZero } from '../utils/format/string';
import { getTrueValue, getMonthEndDay } from './utils';
import { sharedProps, TimePickerMixin } from './shared';
var currentYear = new Date().getFullYear();
var _createNamespace = createNamespace('date-picker'),
    createComponent = _createNamespace[0];
export default createComponent({
  mixins: [TimePickerMixin],
  props: _extends({}, sharedProps, {
    type: {
      type: String,
      default: 'datetime'
    },
    minDate: {
      type: Date,
      default: function _default() {
        return new Date(currentYear - 10, 0, 1);
      },
      validator: isDate
    },
    maxDate: {
      type: Date,
      default: function _default() {
        return new Date(currentYear + 10, 11, 31);
      },
      validator: isDate
    }
  }),
  watch: {
    filter: 'updateInnerValue',
    minDate: 'updateInnerValue',
    maxDate: 'updateInnerValue',
    value: function value(val) {
      val = this.formatValue(val);
      if (val.valueOf() !== this.innerValue.valueOf()) {
        this.innerValue = val;
      }
    }
  },
  computed: {
    ranges: function ranges() {
      var _this$getBoundary = this.getBoundary('max', this.innerValue),
          maxYear = _this$getBoundary.maxYear,
          maxDate = _this$getBoundary.maxDate,
          maxMonth = _this$getBoundary.maxMonth,
          maxHour = _this$getBoundary.maxHour,
          maxMinute = _this$getBoundary.maxMinute;
      var _this$getBoundary2 = this.getBoundary('min', this.innerValue),
          minYear = _this$getBoundary2.minYear,
          minDate = _this$getBoundary2.minDate,
          minMonth = _this$getBoundary2.minMonth,
          minHour = _this$getBoundary2.minHour,
          minMinute = _this$getBoundary2.minMinute;
      var result = [{
        type: 'year',
        range: [minYear, maxYear]
      }, {
        type: 'month',
        range: [minMonth, maxMonth]
      }, {
        type: 'day',
        range: [minDate, maxDate]
      }, {
        type: 'hour',
        range: [minHour, maxHour]
      }, {
        type: 'minute',
        range: [minMinute, maxMinute]
      }];
      switch (this.type) {
        case 'date':
          result = result.slice(0, 3);
          break;
        case 'year-month':
          result = result.slice(0, 2);
          break;
        case 'month-day':
          result = result.slice(1, 3);
          break;
        case 'datehour':
          result = result.slice(0, 4);
          break;
//修订这里
        case 'year':
          result = result.slice(0,1);
          break;
      }
      if (this.columnsOrder) {
        var columnsOrder = this.columnsOrder.concat(result.map(function (column) {
          return column.type;
        }));
        result.sort(function (a, b) {
          return columnsOrder.indexOf(a.type) - columnsOrder.indexOf(b.type);
        });
      }
      return result;
    }
  },
  methods: {
    formatValue: function formatValue(value) {
      if (!isDate(value)) {
        value = this.minDate;
      }
      value = Math.max(value, this.minDate.getTime());
      value = Math.min(value, this.maxDate.getTime());
      return new Date(value);
    },
    getBoundary: function getBoundary(type, value) {
      var _ref;
      var boundary = this[type + "Date"];
      var year = boundary.getFullYear();
      var month = 1;
      var date = 1;
      var hour = 0;
      var minute = 0;
      if (type === 'max') {
        month = 12;
        date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
        hour = 23;
        minute = 59;
      }
      if (value.getFullYear() === year) {
        month = boundary.getMonth() + 1;
        if (value.getMonth() + 1 === month) {
          date = boundary.getDate();
          if (value.getDate() === date) {
            hour = boundary.getHours();
            if (value.getHours() === hour) {
              minute = boundary.getMinutes();
            }
          }
        }
      }
      return _ref = {}, _ref[type + "Year"] = year, _ref[type + "Month"] = month, _ref[type + "Date"] = date, _ref[type + "Hour"] = hour, _ref[type + "Minute"] = minute, _ref;
    },
    updateInnerValue: function updateInnerValue() {
      var _this = this;
      var type = this.type;
      var indexes = this.getPicker().getIndexes();
      var getValue = function getValue(type) {
        var index = 0;
        _this.originColumns.forEach(function (column, columnIndex) {
          if (type === column.type) {
            index = columnIndex;
          }
        });
        var values = _this.originColumns[index].values;
        return getTrueValue(values[indexes[index]]);
      };
      var year;
      var month;
      var day;
      if (type === 'month-day') {
        year = this.innerValue.getFullYear();
        month = getValue('month');
        day = getValue('day');
      } else {
      //修订这里
        year = getValue('year');
        // month = getValue('month');
        month = type === 'year' ? 1 : getValue('month');
        day = type === 'year' ? 1 : getValue('day');
      }
      var maxDay = getMonthEndDay(year, month);
      day = day > maxDay ? maxDay : day;
      var hour = 0;
      var minute = 0;
      if (type === 'datehour') {
        hour = getValue('hour');
      }
      if (type === 'datetime') {
        hour = getValue('hour');
        minute = getValue('minute');
      }
      var value = new Date(year, month - 1, day, hour, minute);
      this.innerValue = this.formatValue(value);
    },
    onChange: function onChange(picker) {
      var _this2 = this;
      this.updateInnerValue();
      this.$nextTick(function () {
        _this2.$nextTick(function () {
          _this2.$emit('change', picker);
        });
      });
    },
    updateColumnValue: function updateColumnValue() {
      var _this3 = this;
      var value = this.innerValue;
      var formatter = this.formatter;
      var values = this.originColumns.map(function (column) {
        switch (column.type) {
          case 'year':
            return formatter('year', "" + value.getFullYear());
          case 'month':
            return formatter('month', padZero(value.getMonth() + 1));
          case 'day':
            return formatter('day', padZero(value.getDate()));
          case 'hour':
            return formatter('hour', padZero(value.getHours()));
          case 'minute':
            return formatter('minute', padZero(value.getMinutes()));
          default:
            // no default
            return null;
        }
      });
      this.$nextTick(function () {
        _this3.getPicker().setValues(values);
      });
    }
  }
});

以上就是直播软件app开发,vant 时间选择控件修订为只显示年份, 更多内容欢迎关注之后的文章

 

标签:function,控件,vant,app,value,month,year,var,type
From: https://www.cnblogs.com/yunbaomengnan/p/16984900.html

相关文章

  • 再论Mac OS下如何将shell可执行文件转换成直接运行的APP?
    今天看见一个更加直接的转换方法,转载到这里来备份下,后续有需要可以实践一下,不过看其方法是比较完整和实用的。fan'yi是否曾经想到过让应用程序直接运行而不是多个shell命令?......
  • 开发者的福音——APP热更新技术
    首先,热更新技术作为一种App软件开发者常用的更新方式,简而言之就是用户在下载安装APP之后,会有APP的即时更新。自从2017年苹果AppStore针对热更新的下架事件发生之后,诸多开发......
  • uniapp vue3下的代理转发不生效问题,亲测有效解决
    以前配置过vuevite的代理转发,没想到在uniapp的代理转发下翻车了,其实是一个很小的问题。调试过程中,尝试了webpack、vite等写法在根目录下创建了vite.config.jsvue.co......
  • uniapp 浏览器调试配置代理
    "h5":{"sdkConfigs":{"maps":{"qqmap":{"key":"SB5BZ-***********************-KVBUC"......
  • uniapp打包配置注意事项
    1.使用原生安卓api要在app权限配置中勾选对应功能  2.打包前要在app模块配置中勾选对应模块 ......
  • Chapter 13 Pygame flappybird
    importpygameimportsysimportrandomclassBird(object):"""定义一个鸟类"""def__init__(self):"""定义初始化方法"""self.birdRect=......
  • App 实现的两类网络请求
    1.JavaHttpUrl 的实现如下:1.1Get请求{//显示进度finalProgressDialogprogressDialog=newProgressDialog(this);progressDialog.setTitle(......
  • 31-WebAPP服务器TomCat及优化
    Tomcat基础功能Tomcat服务器是一个免费的开放源代码的Web应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,Tomcat具有处理HTML静态......
  • DailyRollingFileAppender 支持设置最大日志数量
    Log4j现在已经被大家熟知了,所有细节都可以在网上查到,Log4j支持Appender,其中DailyRollingFileAppender是被经常用到的Appender之一。最常用的Appender——RollingFileAppende......
  • 记录--uniapp 应用APP跳转微信小程序
    这里给大家分享我在网上总结出来的一些知识,希望对大家有所帮助最近APP项目开发完成,在评审会上老板提了一个需求,想在开发的APP上添加一个链接,可以跳转公司的小程序商城。......