first commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"use strict";
|
||||
const uni_modules_wotDesignUni_components_common_props = require("../common/props.js");
|
||||
const datetimePickerViewProps = {
|
||||
...uni_modules_wotDesignUni_components_common_props.baseProps,
|
||||
/**
|
||||
* 选中项,当 type 为 time 时,类型为字符串,否则为 时间戳
|
||||
*/
|
||||
modelValue: uni_modules_wotDesignUni_components_common_props.makeRequiredProp([String, Number]),
|
||||
/**
|
||||
* 加载中
|
||||
*/
|
||||
loading: uni_modules_wotDesignUni_components_common_props.makeBooleanProp(false),
|
||||
/**
|
||||
* 加载的颜色,只能使用十六进制的色值写法,且不能使用缩写
|
||||
*/
|
||||
loadingColor: uni_modules_wotDesignUni_components_common_props.makeStringProp("#4D80F0"),
|
||||
/**
|
||||
* picker内部滚筒高
|
||||
*/
|
||||
columnsHeight: uni_modules_wotDesignUni_components_common_props.makeNumberProp(217),
|
||||
/**
|
||||
* picker item的高度
|
||||
*/
|
||||
itemHeight: uni_modules_wotDesignUni_components_common_props.makeNumberProp(35),
|
||||
/**
|
||||
* 选项的key
|
||||
*/
|
||||
valueKey: uni_modules_wotDesignUni_components_common_props.makeStringProp("value"),
|
||||
/**
|
||||
* 选项的label
|
||||
*/
|
||||
labelKey: uni_modules_wotDesignUni_components_common_props.makeStringProp("label"),
|
||||
/**
|
||||
* 选择器类型,可选值:date / year-month / time
|
||||
*/
|
||||
type: uni_modules_wotDesignUni_components_common_props.makeStringProp("datetime"),
|
||||
/**
|
||||
* 自定义过滤选项的函数,返回列的选项数组
|
||||
*/
|
||||
filter: Function,
|
||||
/**
|
||||
* 自定义弹出层选项文案的格式化函数,返回一个字符串
|
||||
*/
|
||||
formatter: Function,
|
||||
/**
|
||||
* 自定义列的格式化函数
|
||||
*/
|
||||
columnFormatter: Function,
|
||||
/**
|
||||
* 最小日期
|
||||
*/
|
||||
minDate: uni_modules_wotDesignUni_components_common_props.makeNumberProp(new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1).getTime()),
|
||||
/**
|
||||
* 最大日期
|
||||
*/
|
||||
maxDate: uni_modules_wotDesignUni_components_common_props.makeNumberProp(new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 11, 31).getTime()),
|
||||
/**
|
||||
* 最小小时,time类型时生效
|
||||
*/
|
||||
minHour: uni_modules_wotDesignUni_components_common_props.makeNumberProp(0),
|
||||
/**
|
||||
* 最大小时,time类型时生效
|
||||
*/
|
||||
maxHour: uni_modules_wotDesignUni_components_common_props.makeNumberProp(23),
|
||||
/**
|
||||
* 最小分钟,time类型时生效
|
||||
*/
|
||||
minMinute: uni_modules_wotDesignUni_components_common_props.makeNumberProp(0),
|
||||
/**
|
||||
* 最大分钟,time类型时生效
|
||||
*/
|
||||
maxMinute: uni_modules_wotDesignUni_components_common_props.makeNumberProp(59),
|
||||
/**
|
||||
* 是否显示秒选择,仅在 time 和 datetime 类型下生效
|
||||
*/
|
||||
useSecond: uni_modules_wotDesignUni_components_common_props.makeBooleanProp(false),
|
||||
/**
|
||||
* 最小秒数,仅在 time 和 datetime 类型下生效
|
||||
*/
|
||||
minSecond: uni_modules_wotDesignUni_components_common_props.makeNumberProp(0),
|
||||
/**
|
||||
* 最大秒数,仅在 time 和 datetime 类型下生效
|
||||
*/
|
||||
maxSecond: uni_modules_wotDesignUni_components_common_props.makeNumberProp(59),
|
||||
/**
|
||||
* 是否在手指松开时立即触发picker-view的 change 事件。若不开启则会在滚动动画结束后触发 change 事件,1.2.25版本起提供,仅微信小程序和支付宝小程序支持。
|
||||
*/
|
||||
immediateChange: uni_modules_wotDesignUni_components_common_props.makeBooleanProp(false)
|
||||
};
|
||||
exports.datetimePickerViewProps = datetimePickerViewProps;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/wot-design-uni/components/wd-datetime-picker-view/types.js.map
|
||||
@@ -0,0 +1,25 @@
|
||||
"use strict";
|
||||
function getPickerValue(value, type, useSecond = false) {
|
||||
const values = [];
|
||||
const date = new Date(value);
|
||||
if (type === "time") {
|
||||
const pair = String(value).split(":");
|
||||
values.push(parseInt(pair[0]), parseInt(pair[1]));
|
||||
if (useSecond && pair[2]) {
|
||||
values.push(parseInt(pair[2]));
|
||||
}
|
||||
} else {
|
||||
values.push(date.getFullYear(), date.getMonth() + 1);
|
||||
if (type === "date") {
|
||||
values.push(date.getDate());
|
||||
} else if (type === "datetime") {
|
||||
values.push(date.getDate(), date.getHours(), date.getMinutes());
|
||||
if (useSecond) {
|
||||
values.push(date.getSeconds());
|
||||
}
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
exports.getPickerValue = getPickerValue;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/wot-design-uni/components/wd-datetime-picker-view/util.js.map
|
||||
@@ -0,0 +1,394 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const uni_modules_wotDesignUni_components_common_util = require("../common/util.js");
|
||||
const uni_modules_wotDesignUni_components_wdDatetimePickerView_types = require("./types.js");
|
||||
const uni_modules_wotDesignUni_components_wdDatetimePickerView_util = require("./util.js");
|
||||
if (!Math) {
|
||||
wdPickerView();
|
||||
}
|
||||
const wdPickerView = () => "../wd-picker-view/wd-picker-view.js";
|
||||
const __default__ = {
|
||||
name: "wd-datetime-picker-view",
|
||||
virtualHost: true,
|
||||
addGlobalClass: true,
|
||||
styleIsolation: "shared"
|
||||
};
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
...__default__,
|
||||
props: uni_modules_wotDesignUni_components_wdDatetimePickerView_types.datetimePickerViewProps,
|
||||
emits: ["change", "pickstart", "pickend", "update:modelValue"],
|
||||
setup(__props, { expose: __expose, emit: __emit }) {
|
||||
const isValidDate = (date) => uni_modules_wotDesignUni_components_common_util.isDef(date) && !Number.isNaN(date);
|
||||
const times = (n, iteratee) => {
|
||||
let index = -1;
|
||||
const length = n < 0 ? 0 : n;
|
||||
const result = Array(length);
|
||||
while (++index < n) {
|
||||
result[index] = iteratee(index);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const getMonthEndDay = (year, month) => {
|
||||
return 32 - new Date(year, month - 1, 32).getDate();
|
||||
};
|
||||
const props = __props;
|
||||
const emit = __emit;
|
||||
const datePickerview = common_vendor.ref();
|
||||
const innerValue = common_vendor.ref(null);
|
||||
const columns = common_vendor.ref([]);
|
||||
const pickerValue = common_vendor.ref([]);
|
||||
const created = common_vendor.ref(false);
|
||||
const { proxy } = common_vendor.getCurrentInstance();
|
||||
const updateValue = uni_modules_wotDesignUni_components_common_util.debounce(() => {
|
||||
if (!created.value)
|
||||
return;
|
||||
const val = correctValue(props.modelValue);
|
||||
const isEqual = val === innerValue.value;
|
||||
if (!isEqual) {
|
||||
updateColumnValue(val);
|
||||
} else {
|
||||
columns.value = updateColumns();
|
||||
}
|
||||
}, 50);
|
||||
common_vendor.watch(
|
||||
() => props.modelValue,
|
||||
(val, oldVal) => {
|
||||
if (val === oldVal)
|
||||
return;
|
||||
const value = correctValue(val);
|
||||
updateColumnValue(value);
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
);
|
||||
common_vendor.watch(
|
||||
() => props.type,
|
||||
(target) => {
|
||||
const type = ["date", "year-month", "time", "datetime", "year"];
|
||||
if (type.indexOf(target) === -1) {
|
||||
common_vendor.index.__f__("error", "at uni_modules/wot-design-uni/components/wd-datetime-picker-view/wd-datetime-picker-view.vue:110", `type must be one of ${type}`);
|
||||
}
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
);
|
||||
common_vendor.watch(
|
||||
[
|
||||
() => props.type,
|
||||
() => props.filter,
|
||||
() => props.formatter,
|
||||
() => props.columnFormatter,
|
||||
() => props.minDate,
|
||||
() => props.maxDate,
|
||||
() => props.minHour,
|
||||
() => props.maxHour,
|
||||
() => props.minMinute,
|
||||
() => props.maxMinute,
|
||||
() => props.minSecond,
|
||||
() => props.maxSecond,
|
||||
() => props.useSecond
|
||||
],
|
||||
() => {
|
||||
updateValue();
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
common_vendor.onBeforeMount(() => {
|
||||
created.value = true;
|
||||
const innerValue2 = correctValue(props.modelValue);
|
||||
updateColumnValue(innerValue2);
|
||||
});
|
||||
function onChange({ value }) {
|
||||
pickerValue.value = value;
|
||||
const result = updateInnerValue();
|
||||
emit("update:modelValue", result);
|
||||
emit("change", {
|
||||
value: result,
|
||||
picker: proxy.$.exposed
|
||||
});
|
||||
}
|
||||
function updateColumns() {
|
||||
const { formatter, columnFormatter } = props;
|
||||
if (columnFormatter) {
|
||||
return columnFormatter(proxy.$.exposed);
|
||||
} else {
|
||||
return getOriginColumns().map((column) => {
|
||||
return column.values.map((value) => {
|
||||
return {
|
||||
label: formatter ? formatter(column.type, uni_modules_wotDesignUni_components_common_util.padZero(value)) : uni_modules_wotDesignUni_components_common_util.padZero(value),
|
||||
value
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
function setColumns(columnList) {
|
||||
columns.value = columnList;
|
||||
}
|
||||
function getOriginColumns() {
|
||||
const { filter } = props;
|
||||
return getRanges().map(({ type, range: range2 }) => {
|
||||
let values = times(range2[1] - range2[0] + 1, (index) => {
|
||||
return range2[0] + index;
|
||||
});
|
||||
if (filter) {
|
||||
values = filter(type, values);
|
||||
}
|
||||
return {
|
||||
type,
|
||||
values
|
||||
};
|
||||
});
|
||||
}
|
||||
function getRanges() {
|
||||
if (props.type === "time") {
|
||||
const result2 = [
|
||||
{
|
||||
type: "hour",
|
||||
range: [props.minHour, props.maxHour]
|
||||
},
|
||||
{
|
||||
type: "minute",
|
||||
range: [props.minMinute, props.maxMinute]
|
||||
}
|
||||
];
|
||||
if (props.useSecond) {
|
||||
result2.push({
|
||||
type: "second",
|
||||
range: [props.minSecond, props.maxSecond]
|
||||
});
|
||||
}
|
||||
return result2;
|
||||
}
|
||||
const { maxYear, maxDate, maxMonth, maxHour, maxMinute, maxSecond } = getBoundary("max", innerValue.value);
|
||||
const { minYear, minDate, minMonth, minHour, minMinute, minSecond } = getBoundary("min", innerValue.value);
|
||||
const result = [
|
||||
{
|
||||
type: "year",
|
||||
range: [minYear, maxYear]
|
||||
},
|
||||
{
|
||||
type: "month",
|
||||
range: [minMonth, maxMonth]
|
||||
},
|
||||
{
|
||||
type: "date",
|
||||
range: [minDate, maxDate]
|
||||
},
|
||||
{
|
||||
type: "hour",
|
||||
range: [minHour, maxHour]
|
||||
},
|
||||
{
|
||||
type: "minute",
|
||||
range: [minMinute, maxMinute]
|
||||
}
|
||||
];
|
||||
if (props.type === "datetime" && props.useSecond) {
|
||||
result.push({
|
||||
type: "second",
|
||||
range: [minSecond, maxSecond]
|
||||
});
|
||||
}
|
||||
if (props.type === "date")
|
||||
result.splice(3, 2);
|
||||
if (props.type === "year-month")
|
||||
result.splice(2, 3);
|
||||
if (props.type === "year")
|
||||
result.splice(1, 4);
|
||||
return result;
|
||||
}
|
||||
function correctValue(value) {
|
||||
const isDateType = props.type !== "time";
|
||||
if (isDateType && !isValidDate(value)) {
|
||||
value = props.minDate;
|
||||
} else if (!isDateType && !value) {
|
||||
value = props.useSecond ? `${uni_modules_wotDesignUni_components_common_util.padZero(props.minHour)}:00:00` : `${uni_modules_wotDesignUni_components_common_util.padZero(props.minHour)}:00`;
|
||||
}
|
||||
if (!isDateType) {
|
||||
let [hour, minute, second = "00"] = (uni_modules_wotDesignUni_components_common_util.isString(value) ? value : value.toString()).split(":");
|
||||
hour = uni_modules_wotDesignUni_components_common_util.padZero(uni_modules_wotDesignUni_components_common_util.range(Number(hour), props.minHour, props.maxHour));
|
||||
minute = uni_modules_wotDesignUni_components_common_util.padZero(uni_modules_wotDesignUni_components_common_util.range(Number(minute), props.minMinute, props.maxMinute));
|
||||
if (props.useSecond) {
|
||||
second = uni_modules_wotDesignUni_components_common_util.padZero(uni_modules_wotDesignUni_components_common_util.range(Number(second), props.minSecond, props.maxSecond));
|
||||
return `${hour}:${minute}:${second}`;
|
||||
}
|
||||
return `${hour}:${minute}`;
|
||||
}
|
||||
value = Math.min(Math.max(Number(value), props.minDate), props.maxDate);
|
||||
return value;
|
||||
}
|
||||
function getBoundary(type, innerValue2) {
|
||||
const value = new Date(innerValue2);
|
||||
const boundary = new Date(props[`${type}Date`]);
|
||||
const year = boundary.getFullYear();
|
||||
let month = 1;
|
||||
let date = 1;
|
||||
let hour = 0;
|
||||
let minute = 0;
|
||||
let second = 0;
|
||||
if (type === "max") {
|
||||
month = 12;
|
||||
date = getMonthEndDay(value.getFullYear(), value.getMonth() + 1);
|
||||
hour = 23;
|
||||
minute = 59;
|
||||
second = 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();
|
||||
if (value.getMinutes() === minute) {
|
||||
second = boundary.getSeconds();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
[`${type}Year`]: year,
|
||||
[`${type}Month`]: month,
|
||||
[`${type}Date`]: date,
|
||||
[`${type}Hour`]: hour,
|
||||
[`${type}Minute`]: minute,
|
||||
[`${type}Second`]: second
|
||||
};
|
||||
}
|
||||
function updateColumnValue(value) {
|
||||
const values = uni_modules_wotDesignUni_components_wdDatetimePickerView_util.getPickerValue(value, props.type, props.useSecond);
|
||||
if (props.modelValue !== value) {
|
||||
emit("update:modelValue", value);
|
||||
emit("change", {
|
||||
value,
|
||||
picker: proxy.$.exposed
|
||||
});
|
||||
}
|
||||
innerValue.value = value;
|
||||
columns.value = updateColumns();
|
||||
pickerValue.value = values;
|
||||
}
|
||||
function updateInnerValue() {
|
||||
var _a;
|
||||
const { type, useSecond } = props;
|
||||
let innerValue2 = "";
|
||||
const pickerVal = ((_a = datePickerview.value) == null ? void 0 : _a.getValues()) || [];
|
||||
const values = uni_modules_wotDesignUni_components_common_util.isArray(pickerVal) ? pickerVal : [pickerVal];
|
||||
if (type === "time") {
|
||||
if (useSecond) {
|
||||
innerValue2 = `${uni_modules_wotDesignUni_components_common_util.padZero(values[0])}:${uni_modules_wotDesignUni_components_common_util.padZero(values[1])}:${uni_modules_wotDesignUni_components_common_util.padZero(values[2])}`;
|
||||
} else {
|
||||
innerValue2 = `${uni_modules_wotDesignUni_components_common_util.padZero(values[0])}:${uni_modules_wotDesignUni_components_common_util.padZero(values[1])}`;
|
||||
}
|
||||
return innerValue2;
|
||||
}
|
||||
const year = values[0] && parseInt(values[0]);
|
||||
const month = type === "year" ? 1 : values[1] && parseInt(values[1]);
|
||||
const maxDate = getMonthEndDay(Number(year), Number(month));
|
||||
let date = 1;
|
||||
if (type !== "year-month" && type !== "year") {
|
||||
date = (Number(values[2]) && parseInt(String(values[2]))) > maxDate ? maxDate : values[2] && parseInt(String(values[2]));
|
||||
}
|
||||
let hour = 0;
|
||||
let minute = 0;
|
||||
let second = 0;
|
||||
if (type === "datetime") {
|
||||
hour = Number(values[3]) && parseInt(values[3]);
|
||||
minute = Number(values[4]) && parseInt(values[4]);
|
||||
if (useSecond) {
|
||||
second = Number(values[5]) && parseInt(values[5]);
|
||||
}
|
||||
}
|
||||
const value = new Date(Number(year), Number(month) - 1, Number(date), hour, minute, second).getTime();
|
||||
innerValue2 = correctValue(value);
|
||||
return innerValue2;
|
||||
}
|
||||
function columnChange(picker) {
|
||||
if (props.type === "time" || props.type === "year-month" || props.type === "year") {
|
||||
return;
|
||||
}
|
||||
const values = picker.getValues();
|
||||
const year = Number(values[0]);
|
||||
const month = Number(values[1]);
|
||||
const maxDate = getMonthEndDay(year, month);
|
||||
let date = Number(values[2]);
|
||||
date = date > maxDate ? maxDate : date;
|
||||
let hour = 0;
|
||||
let minute = 0;
|
||||
let second = 0;
|
||||
if (props.type === "datetime") {
|
||||
hour = Number(values[3]);
|
||||
minute = Number(values[4]);
|
||||
if (props.useSecond) {
|
||||
second = Number(values[5]);
|
||||
}
|
||||
}
|
||||
const value = new Date(year, month - 1, date, hour, minute, second).getTime();
|
||||
innerValue.value = correctValue(value);
|
||||
const newColumns = updateColumns();
|
||||
const selectedIndex = picker.getSelectedIndex().slice(0);
|
||||
newColumns.forEach((_columns, index) => {
|
||||
const nextColumnIndex = index + 1;
|
||||
const nextColumnData = newColumns[nextColumnIndex];
|
||||
if (nextColumnIndex > newColumns.length - 1)
|
||||
return;
|
||||
picker.setColumnData(
|
||||
nextColumnIndex,
|
||||
nextColumnData,
|
||||
selectedIndex[nextColumnIndex] <= nextColumnData.length - 1 ? selectedIndex[nextColumnIndex] : 0
|
||||
);
|
||||
});
|
||||
}
|
||||
function onPickStart() {
|
||||
emit("pickstart");
|
||||
}
|
||||
function onPickEnd() {
|
||||
emit("pickend");
|
||||
}
|
||||
function getSelects() {
|
||||
var _a;
|
||||
const pickerVal = (_a = datePickerview.value) == null ? void 0 : _a.getSelects();
|
||||
if (pickerVal == null)
|
||||
return void 0;
|
||||
if (uni_modules_wotDesignUni_components_common_util.isArray(pickerVal))
|
||||
return pickerVal;
|
||||
return [pickerVal];
|
||||
}
|
||||
__expose({
|
||||
updateColumns,
|
||||
setColumns,
|
||||
getSelects,
|
||||
correctValue,
|
||||
getOriginColumns
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return {
|
||||
a: common_vendor.sr(datePickerview, "a76d8a1e-0", {
|
||||
"k": "datePickerview"
|
||||
}),
|
||||
b: common_vendor.o(onChange),
|
||||
c: common_vendor.o(onPickStart),
|
||||
d: common_vendor.o(onPickEnd),
|
||||
e: common_vendor.o(($event) => pickerValue.value = $event),
|
||||
f: common_vendor.p({
|
||||
["custom-class"]: _ctx.customClass,
|
||||
["custom-style"]: _ctx.customStyle,
|
||||
["immediate-change"]: _ctx.immediateChange,
|
||||
columns: columns.value,
|
||||
["columns-height"]: _ctx.columnsHeight,
|
||||
["item-height"]: _ctx.itemHeight,
|
||||
columnChange,
|
||||
loading: _ctx.loading,
|
||||
["loading-color"]: _ctx.loadingColor,
|
||||
modelValue: pickerValue.value
|
||||
})
|
||||
};
|
||||
};
|
||||
}
|
||||
});
|
||||
wx.createComponent(_sfc_main);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/wot-design-uni/components/wd-datetime-picker-view/wd-datetime-picker-view.js.map
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {
|
||||
"wd-picker-view": "../wd-picker-view/wd-picker-view"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<wd-picker-view wx:if="{{f}}" class="r" u-r="datePickerview" bindchange="{{b}}" bindpickstart="{{c}}" bindpickend="{{d}}" u-i="a76d8a1e-0" bind:__l="__l" bindupdateModelValue="{{e}}" u-p="{{f}}"></wd-picker-view>
|
||||
Reference in New Issue
Block a user