| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- import { p as pickerSharedProps, P as Picker } from "./index-0f48f786.js";
- import { e as extend, o as makeArrayProp, q as padZero, s as clamp, c as createNamespace, v as isDate, x as isSameValue, y as pick, w as withInstall, t as truthProp, n as numericProp, m as makeNumericProp, z as makeStringProp, u as useChildren, A as useScrollParent, k as isDef, C as useClickAway, D as useEventListener, E as useRect, F as windowHeight, H as HAPTICS_FEEDBACK, a as useParent, G as unknownProp, g as getZIndexStyle, J as getContainingBlock, I as Icon, K as BORDER_BOTTOM } from "./index-487cde8c.js";
- import { u as useExpose } from "./use-scope-id-0b5b8615.js";
- import { d as defineComponent, r as ref, a as computed, w as watch, c as createVNode, m as mergeProps, n as reactive, T as Teleport, h as withDirectives, v as vShow } from "./index-5e4623ce.js";
- import { C as Cell } from "./index-8540448e.js";
- import { P as Popup } from "./index-eef3af38.js";
- import { u as useId } from "./index-41ec7e28.js";
- import { u as usePlaceholder } from "./use-placeholder-16d7c5d7.js";
- const sharedProps = extend({}, pickerSharedProps, {
- modelValue: makeArrayProp(),
- filter: Function,
- formatter: {
- type: Function,
- default: (type, option) => option
- }
- });
- const pickerInheritKeys = Object.keys(pickerSharedProps);
- function times(n, iteratee) {
- if (n < 0) {
- return [];
- }
- const result = Array(n);
- let index2 = -1;
- while (++index2 < n) {
- result[index2] = iteratee(index2);
- }
- return result;
- }
- const getMonthEndDay = (year, month) => 32 - new Date(year, month - 1, 32).getDate();
- const genOptions = (min, max, type, formatter, filter, values) => {
- const options = times(max - min + 1, (index2) => {
- const value = padZero(min + index2);
- return formatter(type, {
- text: value,
- value
- });
- });
- return filter ? filter(type, options, values) : options;
- };
- const formatValueRange = (values, columns) => values.map((value, index2) => {
- const column = columns[index2];
- if (column.length) {
- const minValue = +column[0].value;
- const maxValue = +column[column.length - 1].value;
- return padZero(clamp(+value, minValue, maxValue));
- }
- return value;
- });
- const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
- const [name$3] = createNamespace("date-picker");
- const datePickerProps = extend({}, sharedProps, {
- columnsType: {
- type: Array,
- default: () => ["year", "month", "day"]
- },
- minDate: {
- type: Date,
- default: () => new Date(currentYear - 10, 0, 1),
- validator: isDate
- },
- maxDate: {
- type: Date,
- default: () => new Date(currentYear + 10, 11, 31),
- validator: isDate
- }
- });
- var stdin_default$3 = defineComponent({
- name: name$3,
- props: datePickerProps,
- emits: ["confirm", "cancel", "change", "update:modelValue"],
- setup(props, {
- emit,
- slots
- }) {
- const currentValues = ref(props.modelValue);
- const updatedByExternalSources = ref(false);
- const pickerRef = ref();
- const genYearOptions = () => {
- const minYear = props.minDate.getFullYear();
- const maxYear = props.maxDate.getFullYear();
- return genOptions(minYear, maxYear, "year", props.formatter, props.filter);
- };
- const isMinYear = (year) => year === props.minDate.getFullYear();
- const isMaxYear = (year) => year === props.maxDate.getFullYear();
- const isMinMonth = (month) => month === props.minDate.getMonth() + 1;
- const isMaxMonth = (month) => month === props.maxDate.getMonth() + 1;
- const getValue = (type) => {
- const {
- minDate,
- columnsType
- } = props;
- const index2 = columnsType.indexOf(type);
- const value = updatedByExternalSources.value ? props.modelValue[index2] : currentValues.value[index2];
- if (value) {
- return +value;
- }
- switch (type) {
- case "year":
- return minDate.getFullYear();
- case "month":
- return minDate.getMonth() + 1;
- case "day":
- return minDate.getDate();
- }
- };
- const genMonthOptions = () => {
- const year = getValue("year");
- const minMonth = isMinYear(year) ? props.minDate.getMonth() + 1 : 1;
- const maxMonth = isMaxYear(year) ? props.maxDate.getMonth() + 1 : 12;
- return genOptions(minMonth, maxMonth, "month", props.formatter, props.filter);
- };
- const genDayOptions = () => {
- const year = getValue("year");
- const month = getValue("month");
- const minDate = isMinYear(year) && isMinMonth(month) ? props.minDate.getDate() : 1;
- const maxDate = isMaxYear(year) && isMaxMonth(month) ? props.maxDate.getDate() : getMonthEndDay(year, month);
- return genOptions(minDate, maxDate, "day", props.formatter, props.filter);
- };
- const confirm = () => {
- var _a;
- return (_a = pickerRef.value) == null ? void 0 : _a.confirm();
- };
- const getSelectedDate = () => currentValues.value;
- const columns = computed(() => props.columnsType.map((type) => {
- switch (type) {
- case "year":
- return genYearOptions();
- case "month":
- return genMonthOptions();
- case "day":
- return genDayOptions();
- default:
- return [];
- }
- }));
- watch(currentValues, (newValues) => {
- if (!isSameValue(newValues, props.modelValue)) {
- emit("update:modelValue", newValues);
- }
- });
- watch(() => props.modelValue, (newValues, oldValues) => {
- updatedByExternalSources.value = isSameValue(oldValues, currentValues.value);
- newValues = formatValueRange(newValues, columns.value);
- if (!isSameValue(newValues, currentValues.value)) {
- currentValues.value = newValues;
- }
- updatedByExternalSources.value = false;
- }, {
- immediate: true
- });
- const onChange = (...args) => emit("change", ...args);
- const onCancel = (...args) => emit("cancel", ...args);
- const onConfirm = (...args) => emit("confirm", ...args);
- useExpose({
- confirm,
- getSelectedDate
- });
- return () => createVNode(Picker, mergeProps({
- "ref": pickerRef,
- "modelValue": currentValues.value,
- "onUpdate:modelValue": ($event) => currentValues.value = $event,
- "columns": columns.value,
- "onChange": onChange,
- "onCancel": onCancel,
- "onConfirm": onConfirm
- }, pick(props, pickerInheritKeys)), slots);
- }
- });
- const DatePicker = withInstall(stdin_default$3);
- const [name$2, bem$2] = createNamespace("dropdown-menu");
- const dropdownMenuProps = {
- overlay: truthProp,
- zIndex: numericProp,
- duration: makeNumericProp(0.2),
- direction: makeStringProp("down"),
- activeColor: String,
- autoLocate: Boolean,
- closeOnClickOutside: truthProp,
- closeOnClickOverlay: truthProp,
- swipeThreshold: numericProp
- };
- const DROPDOWN_KEY = Symbol(name$2);
- var stdin_default$2 = defineComponent({
- name: name$2,
- props: dropdownMenuProps,
- setup(props, {
- slots
- }) {
- const id = useId();
- const root = ref();
- const barRef = ref();
- const offset = ref(0);
- const {
- children,
- linkChildren
- } = useChildren(DROPDOWN_KEY);
- const scrollParent = useScrollParent(root);
- const opened = computed(() => children.some((item) => item.state.showWrapper));
- const scrollable = computed(() => props.swipeThreshold && children.length > +props.swipeThreshold);
- const barStyle = computed(() => {
- if (opened.value && isDef(props.zIndex)) {
- return {
- zIndex: +props.zIndex + 1
- };
- }
- });
- const close = () => {
- children.forEach((item) => {
- item.toggle(false);
- });
- };
- const onClickAway = () => {
- if (props.closeOnClickOutside) {
- close();
- }
- };
- const updateOffset = () => {
- if (barRef.value) {
- const rect = useRect(barRef);
- if (props.direction === "down") {
- offset.value = rect.bottom;
- } else {
- offset.value = windowHeight.value - rect.top;
- }
- }
- };
- const onScroll = () => {
- if (opened.value) {
- updateOffset();
- }
- };
- const toggleItem = (active) => {
- children.forEach((item, index2) => {
- if (index2 === active) {
- item.toggle();
- } else if (item.state.showPopup) {
- item.toggle(false, {
- immediate: true
- });
- }
- });
- };
- const renderTitle = (item, index2) => {
- const {
- showPopup
- } = item.state;
- const {
- disabled,
- titleClass
- } = item;
- return createVNode("div", {
- "id": `${id}-${index2}`,
- "role": "button",
- "tabindex": disabled ? void 0 : 0,
- "class": [bem$2("item", {
- disabled,
- grow: scrollable.value
- }), {
- [HAPTICS_FEEDBACK]: !disabled
- }],
- "onClick": () => {
- if (!disabled) {
- toggleItem(index2);
- }
- }
- }, [createVNode("span", {
- "class": [bem$2("title", {
- down: showPopup === (props.direction === "down"),
- active: showPopup
- }), titleClass],
- "style": {
- color: showPopup ? props.activeColor : ""
- }
- }, [createVNode("div", {
- "class": "van-ellipsis"
- }, [item.renderTitle()])])]);
- };
- useExpose({
- close
- });
- linkChildren({
- id,
- props,
- offset,
- updateOffset
- });
- useClickAway(root, onClickAway);
- useEventListener("scroll", onScroll, {
- target: scrollParent,
- passive: true
- });
- return () => {
- var _a;
- return createVNode("div", {
- "ref": root,
- "class": bem$2()
- }, [createVNode("div", {
- "ref": barRef,
- "style": barStyle.value,
- "class": bem$2("bar", {
- opened: opened.value,
- scrollable: scrollable.value
- })
- }, [children.map(renderTitle)]), (_a = slots.default) == null ? void 0 : _a.call(slots)]);
- };
- }
- });
- const [name$1, bem$1] = createNamespace("dropdown-item");
- const dropdownItemProps = {
- title: String,
- options: makeArrayProp(),
- disabled: Boolean,
- teleport: [String, Object],
- lazyRender: truthProp,
- modelValue: unknownProp,
- titleClass: unknownProp
- };
- var stdin_default$1 = defineComponent({
- name: name$1,
- inheritAttrs: false,
- props: dropdownItemProps,
- emits: ["open", "opened", "close", "closed", "change", "update:modelValue"],
- setup(props, {
- emit,
- slots,
- attrs
- }) {
- const state = reactive({
- showPopup: false,
- transition: true,
- showWrapper: false
- });
- const wrapperRef = ref();
- const {
- parent,
- index: index2
- } = useParent(DROPDOWN_KEY);
- if (!parent) {
- return;
- }
- const getEmitter = (name2) => () => emit(name2);
- const onOpen = getEmitter("open");
- const onClose = getEmitter("close");
- const onOpened = getEmitter("opened");
- const onClosed = () => {
- state.showWrapper = false;
- emit("closed");
- };
- const onClickWrapper = (event) => {
- if (props.teleport) {
- event.stopPropagation();
- }
- };
- const toggle = (show = !state.showPopup, options = {}) => {
- if (show === state.showPopup) {
- return;
- }
- state.showPopup = show;
- state.transition = !options.immediate;
- if (show) {
- parent.updateOffset();
- state.showWrapper = true;
- }
- };
- const renderTitle = () => {
- if (slots.title) {
- return slots.title();
- }
- if (props.title) {
- return props.title;
- }
- const match = props.options.find((option) => option.value === props.modelValue);
- return match ? match.text : "";
- };
- const renderOption = (option) => {
- const {
- activeColor
- } = parent.props;
- const {
- disabled
- } = option;
- const active = option.value === props.modelValue;
- const onClick = () => {
- if (disabled) {
- return;
- }
- state.showPopup = false;
- if (option.value !== props.modelValue) {
- emit("update:modelValue", option.value);
- emit("change", option.value);
- }
- };
- const renderIcon = () => {
- if (active) {
- return createVNode(Icon, {
- "class": bem$1("icon"),
- "color": disabled ? void 0 : activeColor,
- "name": "success"
- }, null);
- }
- };
- return createVNode(Cell, {
- "role": "menuitem",
- "key": String(option.value),
- "icon": option.icon,
- "title": option.text,
- "class": bem$1("option", {
- active,
- disabled
- }),
- "style": {
- color: active ? activeColor : ""
- },
- "tabindex": active ? 0 : -1,
- "clickable": !disabled,
- "onClick": onClick
- }, {
- value: renderIcon
- });
- };
- const renderContent = () => {
- const {
- offset
- } = parent;
- const {
- autoLocate,
- zIndex,
- overlay,
- duration,
- direction,
- closeOnClickOverlay
- } = parent.props;
- const style = getZIndexStyle(zIndex);
- let offsetValue = offset.value;
- if (autoLocate && wrapperRef.value) {
- const offsetParent = getContainingBlock(wrapperRef.value);
- if (offsetParent) {
- offsetValue -= useRect(offsetParent).top;
- }
- }
- if (direction === "down") {
- style.top = `${offsetValue}px`;
- } else {
- style.bottom = `${offsetValue}px`;
- }
- return withDirectives(createVNode("div", mergeProps({
- "ref": wrapperRef,
- "style": style,
- "class": bem$1([direction]),
- "onClick": onClickWrapper
- }, attrs), [createVNode(Popup, {
- "show": state.showPopup,
- "onUpdate:show": ($event) => state.showPopup = $event,
- "role": "menu",
- "class": bem$1("content"),
- "overlay": overlay,
- "position": direction === "down" ? "top" : "bottom",
- "duration": state.transition ? duration : 0,
- "lazyRender": props.lazyRender,
- "overlayStyle": {
- position: "absolute"
- },
- "aria-labelledby": `${parent.id}-${index2.value}`,
- "closeOnClickOverlay": closeOnClickOverlay,
- "onOpen": onOpen,
- "onClose": onClose,
- "onOpened": onOpened,
- "onClosed": onClosed
- }, {
- default: () => {
- var _a;
- return [props.options.map(renderOption), (_a = slots.default) == null ? void 0 : _a.call(slots)];
- }
- })]), [[vShow, state.showWrapper]]);
- };
- useExpose({
- state,
- toggle,
- renderTitle
- });
- return () => {
- if (props.teleport) {
- return createVNode(Teleport, {
- "to": props.teleport
- }, {
- default: () => [renderContent()]
- });
- }
- return renderContent();
- };
- }
- });
- const DropdownItem = withInstall(stdin_default$1);
- const DropdownMenu = withInstall(stdin_default$2);
- const [name, bem] = createNamespace("nav-bar");
- const navBarProps = {
- title: String,
- fixed: Boolean,
- zIndex: numericProp,
- border: truthProp,
- leftText: String,
- rightText: String,
- leftDisabled: Boolean,
- rightDisabled: Boolean,
- leftArrow: Boolean,
- placeholder: Boolean,
- safeAreaInsetTop: Boolean,
- clickable: truthProp
- };
- var stdin_default = defineComponent({
- name,
- props: navBarProps,
- emits: ["clickLeft", "clickRight"],
- setup(props, {
- emit,
- slots
- }) {
- const navBarRef = ref();
- const renderPlaceholder = usePlaceholder(navBarRef, bem);
- const onClickLeft = (event) => {
- if (!props.leftDisabled) {
- emit("clickLeft", event);
- }
- };
- const onClickRight = (event) => {
- if (!props.rightDisabled) {
- emit("clickRight", event);
- }
- };
- const renderLeft = () => {
- if (slots.left) {
- return slots.left();
- }
- return [props.leftArrow && createVNode(Icon, {
- "class": bem("arrow"),
- "name": "arrow-left"
- }, null), props.leftText && createVNode("span", {
- "class": bem("text")
- }, [props.leftText])];
- };
- const renderRight = () => {
- if (slots.right) {
- return slots.right();
- }
- return createVNode("span", {
- "class": bem("text")
- }, [props.rightText]);
- };
- const renderNavBar = () => {
- const {
- title,
- fixed,
- border,
- zIndex
- } = props;
- const style = getZIndexStyle(zIndex);
- const hasLeft = props.leftArrow || props.leftText || slots.left;
- const hasRight = props.rightText || slots.right;
- return createVNode("div", {
- "ref": navBarRef,
- "style": style,
- "class": [bem({
- fixed
- }), {
- [BORDER_BOTTOM]: border,
- "van-safe-area-top": props.safeAreaInsetTop
- }]
- }, [createVNode("div", {
- "class": bem("content")
- }, [hasLeft && createVNode("div", {
- "class": [bem("left", {
- disabled: props.leftDisabled
- }), props.clickable && !props.leftDisabled ? HAPTICS_FEEDBACK : ""],
- "onClick": onClickLeft
- }, [renderLeft()]), createVNode("div", {
- "class": [bem("title"), "van-ellipsis"]
- }, [slots.title ? slots.title() : title]), hasRight && createVNode("div", {
- "class": [bem("right", {
- disabled: props.rightDisabled
- }), props.clickable && !props.rightDisabled ? HAPTICS_FEEDBACK : ""],
- "onClick": onClickRight
- }, [renderRight()])])]);
- };
- return () => {
- if (props.fixed && props.placeholder) {
- return renderPlaceholder(renderNavBar);
- }
- return renderNavBar();
- };
- }
- });
- const NavBar = withInstall(stdin_default);
- const index$2 = "";
- const index$1 = "";
- const index = "";
- const getDateTimeAgo = function(month_count) {
- const currentDate = /* @__PURE__ */ new Date();
- let currentYear2 = currentDate.getFullYear();
- let currentMonth = currentDate.getMonth();
- let currentDay = currentDate.getDate();
- let year = 0;
- let month = 0;
- let y = Math.trunc(month_count / 12);
- let m = month_count % 12;
- if (m < currentMonth) {
- year = currentYear2 - y;
- month = currentMonth - m;
- } else {
- year = currentYear2 - y - 1;
- month = currentMonth + 12 - m;
- }
- return new Date(year, month, currentDay);
- };
- export {
- DatePicker as D,
- NavBar as N,
- DropdownMenu as a,
- DropdownItem as b,
- getDateTimeAgo as g
- };
|