@ql-web/view-report 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/view-report.css +223 -1
- package/view-report.es.js +335 -223
- package/view-report.umd.js +474 -1
package/view-report.es.js
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
function
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
options
|
|
1
|
+
import { defineComponent, ref, computed, watch, onMounted, onUnmounted, isVue2 } from "vue-demi";
|
|
2
|
+
function normalizeComponent(scriptExports, render3, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, shadowMode) {
|
|
3
|
+
var options = typeof scriptExports === "function" ? scriptExports.options : scriptExports;
|
|
4
|
+
if (render3) {
|
|
5
|
+
options.render = render3;
|
|
6
|
+
options.staticRenderFns = staticRenderFns;
|
|
7
|
+
options._compiled = true;
|
|
8
|
+
}
|
|
9
|
+
if (scopeId) {
|
|
10
|
+
options._scopeId = "data-v-" + scopeId;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
exports: scriptExports,
|
|
14
|
+
options
|
|
7
15
|
};
|
|
8
16
|
}
|
|
9
|
-
const
|
|
17
|
+
const _sfc_main$1 = defineComponent({
|
|
10
18
|
name: "MyButton",
|
|
11
19
|
// 必须声明 name,用于全局注册
|
|
12
20
|
props: {
|
|
@@ -19,126 +27,138 @@ const G = M({
|
|
|
19
27
|
default: "#409eff"
|
|
20
28
|
}
|
|
21
29
|
},
|
|
22
|
-
setup(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
30
|
+
setup(props, { emit }) {
|
|
31
|
+
const handleClick = () => {
|
|
32
|
+
emit("click", "按钮被点击");
|
|
33
|
+
};
|
|
34
|
+
return { handleClick };
|
|
26
35
|
}
|
|
27
36
|
});
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
var _sfc_render$1 = function render() {
|
|
38
|
+
var _vm = this, _c = _vm._self._c;
|
|
39
|
+
_vm._self._setupProxy;
|
|
40
|
+
return _c("button", { staticClass: "my-button", style: { background: _vm.color }, on: { "click": _vm.handleClick } }, [_vm._t("default", function() {
|
|
41
|
+
return [_vm._v(_vm._s(_vm.text))];
|
|
32
42
|
})], 2);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
43
|
+
};
|
|
44
|
+
var _sfc_staticRenderFns$1 = [];
|
|
45
|
+
var __component__$1 = /* @__PURE__ */ normalizeComponent(
|
|
46
|
+
_sfc_main$1,
|
|
47
|
+
_sfc_render$1,
|
|
48
|
+
_sfc_staticRenderFns$1,
|
|
49
|
+
false,
|
|
38
50
|
null,
|
|
39
51
|
"d19bd5c3"
|
|
40
52
|
);
|
|
41
|
-
const
|
|
42
|
-
class
|
|
53
|
+
const MyButton = __component__$1.exports;
|
|
54
|
+
class DateUtils {
|
|
43
55
|
/**
|
|
44
56
|
* 格式化日期为 YYYY-MM-DD 格式
|
|
45
57
|
* @param {Date} date 日期对象
|
|
46
58
|
* @returns {string} 格式化后的日期字符串
|
|
47
59
|
*/
|
|
48
|
-
static formatDate(
|
|
49
|
-
if (!
|
|
50
|
-
const
|
|
51
|
-
|
|
60
|
+
static formatDate(date) {
|
|
61
|
+
if (!date || !(date instanceof Date) || isNaN(date.getTime())) return "";
|
|
62
|
+
const year = date.getFullYear();
|
|
63
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
64
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
65
|
+
return `${year}-${month}-${day}`;
|
|
52
66
|
}
|
|
53
67
|
/**
|
|
54
68
|
* 获取指定日期所在月份的第一天
|
|
55
69
|
* @param {Date} date 基准日期
|
|
56
70
|
* @returns {Date} 月份第一天
|
|
57
71
|
*/
|
|
58
|
-
static getFirstDayOfMonth(
|
|
59
|
-
return new Date(
|
|
72
|
+
static getFirstDayOfMonth(date) {
|
|
73
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
60
74
|
}
|
|
61
75
|
/**
|
|
62
76
|
* 获取指定日期所在月份的最后一天
|
|
63
77
|
* @param {Date} date 基准日期
|
|
64
78
|
* @returns {Date} 月份最后一天
|
|
65
79
|
*/
|
|
66
|
-
static getLastDayOfMonth(
|
|
67
|
-
return new Date(
|
|
80
|
+
static getLastDayOfMonth(date) {
|
|
81
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
68
82
|
}
|
|
69
83
|
/**
|
|
70
84
|
* 获取日期对应的星期数(周日=0,周六=6)
|
|
71
85
|
* @returns {number} 星期数
|
|
72
86
|
*/
|
|
73
|
-
static getDayOfWeek(
|
|
74
|
-
return
|
|
87
|
+
static getDayOfWeek(date) {
|
|
88
|
+
return date.getDay();
|
|
75
89
|
}
|
|
76
90
|
/**
|
|
77
91
|
* 上一个月(支持跨年,如2026-01 → 2025-12)
|
|
78
92
|
* @returns {Date} 上月日期
|
|
79
93
|
*/
|
|
80
|
-
static getPrevMonth(
|
|
81
|
-
const
|
|
82
|
-
|
|
94
|
+
static getPrevMonth(date) {
|
|
95
|
+
const year = date.getMonth() === 0 ? date.getFullYear() - 1 : date.getFullYear();
|
|
96
|
+
const month = date.getMonth() === 0 ? 11 : date.getMonth() - 1;
|
|
97
|
+
return new Date(year, month, 1);
|
|
83
98
|
}
|
|
84
99
|
/**
|
|
85
100
|
* 下一个月(支持跨年,如2025-12 → 2026-01)
|
|
86
101
|
* @returns {Date} 下月日期
|
|
87
102
|
*/
|
|
88
|
-
static getNextMonth(
|
|
89
|
-
const
|
|
90
|
-
|
|
103
|
+
static getNextMonth(date) {
|
|
104
|
+
const year = date.getMonth() === 11 ? date.getFullYear() + 1 : date.getFullYear();
|
|
105
|
+
const month = date.getMonth() === 11 ? 0 : date.getMonth() + 1;
|
|
106
|
+
return new Date(year, month, 1);
|
|
91
107
|
}
|
|
92
108
|
/**
|
|
93
109
|
* 上一年(直接切换年份,如2026 → 2025)
|
|
94
110
|
* @returns {Date} 上年同月日期
|
|
95
111
|
*/
|
|
96
|
-
static getPrevYear(
|
|
97
|
-
return new Date(
|
|
112
|
+
static getPrevYear(date) {
|
|
113
|
+
return new Date(date.getFullYear() - 1, date.getMonth(), 1);
|
|
98
114
|
}
|
|
99
115
|
/**
|
|
100
116
|
* 下一年(直接切换年份,如2025 → 2026)
|
|
101
117
|
* @returns {Date} 下年同月日期
|
|
102
118
|
*/
|
|
103
|
-
static getNextYear(
|
|
104
|
-
return new Date(
|
|
119
|
+
static getNextYear(date) {
|
|
120
|
+
return new Date(date.getFullYear() + 1, date.getMonth(), 1);
|
|
105
121
|
}
|
|
106
122
|
/**
|
|
107
123
|
* 生成6行7列的日期面板数据(42个,自动补充跨月/跨年日期)
|
|
108
124
|
* @returns {Array} 42个日期对象的数组(6*7)
|
|
109
125
|
*/
|
|
110
|
-
static generateMonthPanel(
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
static generateMonthPanel(currentDate, selectedDate = "") {
|
|
127
|
+
const panel = [];
|
|
128
|
+
const firstDay = this.getFirstDayOfMonth(currentDate);
|
|
129
|
+
const lastDay = this.getLastDayOfMonth(currentDate);
|
|
130
|
+
const firstDayWeek = this.getDayOfWeek(firstDay);
|
|
131
|
+
const prevMonthDaysCount = firstDayWeek;
|
|
132
|
+
for (let i = prevMonthDaysCount; i > 0; i--) {
|
|
133
|
+
const prevDay = new Date(firstDay.getTime() - i * 24 * 60 * 60 * 1e3);
|
|
134
|
+
panel.push({
|
|
135
|
+
date: prevDay,
|
|
136
|
+
formatDate: this.formatDate(prevDay),
|
|
137
|
+
isCurrentMonth: false,
|
|
138
|
+
isSelected: this.formatDate(prevDay) === selectedDate
|
|
119
139
|
});
|
|
120
140
|
}
|
|
121
|
-
const
|
|
122
|
-
for (let
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
date:
|
|
126
|
-
formatDate: this.formatDate(
|
|
127
|
-
isCurrentMonth:
|
|
128
|
-
isSelected: this.formatDate(
|
|
141
|
+
const currentMonthDays = lastDay.getDate();
|
|
142
|
+
for (let i = 1; i <= currentMonthDays; i++) {
|
|
143
|
+
const currentDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), i);
|
|
144
|
+
panel.push({
|
|
145
|
+
date: currentDay,
|
|
146
|
+
formatDate: this.formatDate(currentDay),
|
|
147
|
+
isCurrentMonth: true,
|
|
148
|
+
isSelected: this.formatDate(currentDay) === selectedDate
|
|
129
149
|
});
|
|
130
150
|
}
|
|
131
|
-
const
|
|
132
|
-
for (let
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
date:
|
|
136
|
-
formatDate: this.formatDate(
|
|
137
|
-
isCurrentMonth:
|
|
138
|
-
isSelected: this.formatDate(
|
|
151
|
+
const needNextDays = 42 - panel.length;
|
|
152
|
+
for (let i = 1; i <= needNextDays; i++) {
|
|
153
|
+
const nextDay = new Date(lastDay.getTime() + i * 24 * 60 * 60 * 1e3);
|
|
154
|
+
panel.push({
|
|
155
|
+
date: nextDay,
|
|
156
|
+
formatDate: this.formatDate(nextDay),
|
|
157
|
+
isCurrentMonth: false,
|
|
158
|
+
isSelected: this.formatDate(nextDay) === selectedDate
|
|
139
159
|
});
|
|
140
160
|
}
|
|
141
|
-
return
|
|
161
|
+
return panel;
|
|
142
162
|
}
|
|
143
163
|
// ========== 新增十年跨度相关方法(不改动原有逻辑) ==========
|
|
144
164
|
/**
|
|
@@ -146,214 +166,306 @@ class v {
|
|
|
146
166
|
* @param {Date} date 基准日期
|
|
147
167
|
* @returns {number} 十年起始年份(如2026 → 2020)
|
|
148
168
|
*/
|
|
149
|
-
static getDecadeStart(
|
|
150
|
-
const
|
|
151
|
-
return Math.floor(
|
|
169
|
+
static getDecadeStart(date) {
|
|
170
|
+
const year = date.getFullYear();
|
|
171
|
+
return Math.floor(year / 10) * 10;
|
|
152
172
|
}
|
|
153
173
|
/**
|
|
154
174
|
* 获取下一个十年区间起始年份
|
|
155
175
|
* @param {number} decadeStart 当前十年起始年份
|
|
156
176
|
* @returns {number} 下一个十年起始年份(如2020 → 2030)
|
|
157
177
|
*/
|
|
158
|
-
static getNextDecade(
|
|
159
|
-
return
|
|
178
|
+
static getNextDecade(decadeStart) {
|
|
179
|
+
return decadeStart + 10;
|
|
160
180
|
}
|
|
161
181
|
/**
|
|
162
182
|
* 获取上一个十年区间起始年份
|
|
163
183
|
* @param {number} decadeStart 当前十年起始年份
|
|
164
184
|
* @returns {number} 上一个十年起始年份(如2020 → 2010)
|
|
165
185
|
*/
|
|
166
|
-
static getPrevDecade(
|
|
167
|
-
return
|
|
186
|
+
static getPrevDecade(decadeStart) {
|
|
187
|
+
return decadeStart - 10;
|
|
168
188
|
}
|
|
169
189
|
/**
|
|
170
190
|
* 生成十年跨度的年份数组(如2020-2029)
|
|
171
191
|
* @param {number} decadeStart 十年起始年份
|
|
172
192
|
* @returns {Array} 十年年份数组
|
|
173
193
|
*/
|
|
174
|
-
static generateDecadeYears(
|
|
175
|
-
return Array.from({ length: 10 }, (
|
|
194
|
+
static generateDecadeYears(decadeStart) {
|
|
195
|
+
return Array.from({ length: 10 }, (_, i) => decadeStart + i);
|
|
176
196
|
}
|
|
177
197
|
}
|
|
178
|
-
const
|
|
198
|
+
const _sfc_main = defineComponent({
|
|
179
199
|
name: "ViewDatePicker",
|
|
180
200
|
// Vue2兼容:props定义(vue-demi已适配)
|
|
181
201
|
props: {
|
|
182
202
|
value: {
|
|
183
203
|
// Vue2的v-model绑定值(兼容Vue3的modelValue)
|
|
184
204
|
type: String,
|
|
185
|
-
default: () =>
|
|
205
|
+
default: () => DateUtils.formatDate(/* @__PURE__ */ new Date())
|
|
186
206
|
},
|
|
187
207
|
modelValue: {
|
|
188
208
|
// Vue3的v-model绑定值
|
|
189
209
|
type: String,
|
|
190
|
-
default: () =>
|
|
210
|
+
default: () => DateUtils.formatDate(/* @__PURE__ */ new Date())
|
|
191
211
|
}
|
|
192
212
|
},
|
|
193
213
|
// Vue2/Vue3兼容:emits定义
|
|
194
214
|
emits: ["input", "update:modelValue", "change"],
|
|
195
|
-
setup(
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
215
|
+
setup(props, { emit }) {
|
|
216
|
+
const pickerWrapper = ref(null);
|
|
217
|
+
const dateInput = ref(null);
|
|
218
|
+
const datePanel = ref(null);
|
|
219
|
+
const panelVisible = ref(false);
|
|
220
|
+
const panelStyle = ref({});
|
|
221
|
+
const currentYear = ref((/* @__PURE__ */ new Date()).getFullYear());
|
|
222
|
+
const currentMonth = ref((/* @__PURE__ */ new Date()).getMonth() + 1);
|
|
223
|
+
const hoverDate = ref("");
|
|
224
|
+
const displayDate = ref("");
|
|
225
|
+
const panelType = ref("date");
|
|
226
|
+
const decadeStart = ref(DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1)));
|
|
227
|
+
const decadeYears = computed(() => {
|
|
228
|
+
const years = DateUtils.generateDecadeYears(decadeStart.value);
|
|
229
|
+
return Array.isArray(years) ? years : [];
|
|
230
|
+
});
|
|
231
|
+
const getDecadeStartAndEnd = computed(() => {
|
|
232
|
+
const start = decadeStart.value;
|
|
233
|
+
const end = start + 9;
|
|
234
|
+
return `${start}年-${end}年`;
|
|
235
|
+
});
|
|
236
|
+
const panelDates = computed(() => {
|
|
237
|
+
const currentDateTemp = new Date(currentYear.value, currentMonth.value - 1, 1);
|
|
238
|
+
const dates = DateUtils.generateMonthPanel(currentDateTemp, displayDate.value);
|
|
239
|
+
return Array.isArray(dates) ? dates : [];
|
|
240
|
+
});
|
|
241
|
+
const initDisplayDate = () => {
|
|
242
|
+
const initValue = isVue2 ? props.value : props.modelValue;
|
|
243
|
+
if (initValue) {
|
|
244
|
+
displayDate.value = initValue;
|
|
245
|
+
const date = new Date(initValue);
|
|
246
|
+
if (!isNaN(date.getTime())) {
|
|
247
|
+
currentYear.value = date.getFullYear();
|
|
248
|
+
currentMonth.value = date.getMonth() + 1;
|
|
249
|
+
decadeStart.value = DateUtils.getDecadeStart(date);
|
|
250
|
+
}
|
|
211
251
|
} else {
|
|
212
|
-
const
|
|
213
|
-
|
|
252
|
+
const now = /* @__PURE__ */ new Date();
|
|
253
|
+
displayDate.value = DateUtils.formatDate(now);
|
|
254
|
+
currentYear.value = now.getFullYear();
|
|
255
|
+
currentMonth.value = now.getMonth() + 1;
|
|
256
|
+
decadeStart.value = DateUtils.getDecadeStart(now);
|
|
214
257
|
}
|
|
215
258
|
};
|
|
216
|
-
|
|
217
|
-
() => [
|
|
259
|
+
watch(
|
|
260
|
+
() => [props.value, props.modelValue],
|
|
218
261
|
() => {
|
|
219
|
-
|
|
262
|
+
initDisplayDate();
|
|
220
263
|
},
|
|
221
|
-
{ immediate:
|
|
264
|
+
{ immediate: true, deep: true }
|
|
222
265
|
);
|
|
223
|
-
const
|
|
224
|
-
if (!
|
|
225
|
-
const
|
|
226
|
-
|
|
266
|
+
const calcPanelPosition = () => {
|
|
267
|
+
if (!dateInput.value || !datePanel.value) return;
|
|
268
|
+
const inputRect = dateInput.value.getBoundingClientRect();
|
|
269
|
+
const wrapperRect = pickerWrapper.value.getBoundingClientRect();
|
|
270
|
+
panelStyle.value = {
|
|
227
271
|
position: "absolute",
|
|
228
|
-
top: `${
|
|
229
|
-
left: `${
|
|
272
|
+
top: `${inputRect.bottom - wrapperRect.top + 4}px`,
|
|
273
|
+
left: `${inputRect.left - wrapperRect.left}px`,
|
|
230
274
|
zIndex: 9999,
|
|
231
|
-
width:
|
|
275
|
+
width: `322px`
|
|
232
276
|
};
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (l.contains(n) || n.classList.contains("year-item") || n.classList.contains("month-item")) return !0;
|
|
265
|
-
let f = n;
|
|
266
|
-
for (; f.parentElement; ) {
|
|
267
|
-
if (f = f.parentElement, f === l)
|
|
268
|
-
return !0;
|
|
269
|
-
if (f.tagName === "BODY") break;
|
|
277
|
+
};
|
|
278
|
+
const togglePanel = () => {
|
|
279
|
+
panelVisible.value = !panelVisible.value;
|
|
280
|
+
if (panelVisible.value) {
|
|
281
|
+
setTimeout(() => calcPanelPosition(), 0);
|
|
282
|
+
panelType.value = "date";
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
const openYearPanel = () => {
|
|
286
|
+
decadeStart.value = DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1));
|
|
287
|
+
panelType.value = "year";
|
|
288
|
+
};
|
|
289
|
+
const openMonthPanel = () => {
|
|
290
|
+
panelType.value = "month";
|
|
291
|
+
};
|
|
292
|
+
const selectDecadeYear = (year) => {
|
|
293
|
+
currentYear.value = year;
|
|
294
|
+
panelType.value = "month";
|
|
295
|
+
};
|
|
296
|
+
const selectTargetMonth = (month) => {
|
|
297
|
+
currentMonth.value = month;
|
|
298
|
+
panelType.value = "date";
|
|
299
|
+
};
|
|
300
|
+
const selectDate = (item) => {
|
|
301
|
+
displayDate.value = item.formatDate;
|
|
302
|
+
currentYear.value = item.date.getFullYear();
|
|
303
|
+
currentMonth.value = item.date.getMonth() + 1;
|
|
304
|
+
if (isVue2) {
|
|
305
|
+
emit("input", displayDate.value);
|
|
306
|
+
} else {
|
|
307
|
+
emit("update:modelValue", displayDate.value);
|
|
270
308
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
309
|
+
emit("change", {
|
|
310
|
+
date: item.date,
|
|
311
|
+
formatDate: displayDate.value
|
|
312
|
+
});
|
|
313
|
+
panelVisible.value = false;
|
|
314
|
+
};
|
|
315
|
+
const switchToPrevYear = () => {
|
|
316
|
+
currentYear.value -= 1;
|
|
317
|
+
decadeStart.value = DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1));
|
|
277
318
|
};
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
319
|
+
const switchToPrevMonth = () => {
|
|
320
|
+
if (currentMonth.value === 1) {
|
|
321
|
+
currentMonth.value = 12;
|
|
322
|
+
currentYear.value -= 1;
|
|
323
|
+
} else {
|
|
324
|
+
currentMonth.value -= 1;
|
|
325
|
+
}
|
|
326
|
+
decadeStart.value = DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1));
|
|
327
|
+
};
|
|
328
|
+
const switchToNextMonth = () => {
|
|
329
|
+
if (currentMonth.value === 12) {
|
|
330
|
+
currentMonth.value = 1;
|
|
331
|
+
currentYear.value += 1;
|
|
332
|
+
} else {
|
|
333
|
+
currentMonth.value += 1;
|
|
334
|
+
}
|
|
335
|
+
decadeStart.value = DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1));
|
|
336
|
+
};
|
|
337
|
+
const switchToNextYear = () => {
|
|
338
|
+
currentYear.value += 1;
|
|
339
|
+
decadeStart.value = DateUtils.getDecadeStart(new Date(currentYear.value, currentMonth.value - 1));
|
|
340
|
+
};
|
|
341
|
+
const switchToNextTenYears = () => {
|
|
342
|
+
decadeStart.value = DateUtils.getNextDecade(decadeStart.value);
|
|
343
|
+
};
|
|
344
|
+
const switchToPrevTenYears = () => {
|
|
345
|
+
decadeStart.value = DateUtils.getPrevDecade(decadeStart.value);
|
|
346
|
+
};
|
|
347
|
+
const handleInput = (e) => {
|
|
348
|
+
displayDate.value = e.target.value;
|
|
349
|
+
};
|
|
350
|
+
const isElementInContainer = (el, container) => {
|
|
351
|
+
if (!el || !container) return false;
|
|
352
|
+
if (container.contains(el)) return true;
|
|
353
|
+
if (el.classList.contains("year-item")) return true;
|
|
354
|
+
if (el.classList.contains("month-item")) return true;
|
|
355
|
+
let currentEl = el;
|
|
356
|
+
while (currentEl.parentElement) {
|
|
357
|
+
currentEl = currentEl.parentElement;
|
|
358
|
+
if (currentEl === container) {
|
|
359
|
+
return true;
|
|
360
|
+
}
|
|
361
|
+
if (currentEl.tagName === "BODY") break;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
};
|
|
365
|
+
const handleViewReportClickOutside = (e) => {
|
|
366
|
+
const isInWrapper = isElementInContainer(e.target, pickerWrapper.value);
|
|
367
|
+
if (panelVisible.value && pickerWrapper.value && !isInWrapper) {
|
|
368
|
+
panelVisible.value = false;
|
|
369
|
+
panelType.value = "date";
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
const handleViewReportResizes = () => {
|
|
373
|
+
if (panelVisible.value) calcPanelPosition();
|
|
374
|
+
};
|
|
375
|
+
onMounted(() => {
|
|
376
|
+
initDisplayDate();
|
|
377
|
+
document.addEventListener("click", handleViewReportClickOutside);
|
|
378
|
+
window.addEventListener("scroll", handleViewReportResizes, true);
|
|
379
|
+
window.addEventListener("resize", handleViewReportResizes);
|
|
380
|
+
});
|
|
381
|
+
onUnmounted(() => {
|
|
382
|
+
document.removeEventListener("click", handleViewReportClickOutside);
|
|
383
|
+
window.removeEventListener("scroll", handleViewReportResizes, true);
|
|
384
|
+
window.removeEventListener("resize", handleViewReportResizes);
|
|
385
|
+
});
|
|
386
|
+
return {
|
|
387
|
+
pickerWrapper,
|
|
388
|
+
dateInput,
|
|
389
|
+
datePanel,
|
|
390
|
+
panelVisible,
|
|
391
|
+
panelStyle,
|
|
392
|
+
currentYear,
|
|
289
393
|
// 仅暴露currentYear/currentMonth
|
|
290
|
-
currentMonth
|
|
291
|
-
hoverDate
|
|
292
|
-
displayDate
|
|
293
|
-
panelType
|
|
294
|
-
decadeYears
|
|
295
|
-
panelDates
|
|
296
|
-
togglePanel
|
|
297
|
-
openYearPanel
|
|
298
|
-
openMonthPanel
|
|
299
|
-
selectDecadeYear
|
|
300
|
-
selectTargetMonth
|
|
301
|
-
selectDate
|
|
302
|
-
switchToPrevYear
|
|
303
|
-
switchToPrevMonth
|
|
304
|
-
switchToNextMonth
|
|
305
|
-
switchToNextYear
|
|
306
|
-
handleInput
|
|
307
|
-
getDecadeStartAndEnd
|
|
308
|
-
switchToPrevTenYears
|
|
309
|
-
switchToNextTenYears
|
|
394
|
+
currentMonth,
|
|
395
|
+
hoverDate,
|
|
396
|
+
displayDate,
|
|
397
|
+
panelType,
|
|
398
|
+
decadeYears,
|
|
399
|
+
panelDates,
|
|
400
|
+
togglePanel,
|
|
401
|
+
openYearPanel,
|
|
402
|
+
openMonthPanel,
|
|
403
|
+
selectDecadeYear,
|
|
404
|
+
selectTargetMonth,
|
|
405
|
+
selectDate,
|
|
406
|
+
switchToPrevYear,
|
|
407
|
+
switchToPrevMonth,
|
|
408
|
+
switchToNextMonth,
|
|
409
|
+
switchToNextYear,
|
|
410
|
+
handleInput,
|
|
411
|
+
getDecadeStartAndEnd,
|
|
412
|
+
switchToPrevTenYears,
|
|
413
|
+
switchToNextTenYears
|
|
310
414
|
};
|
|
311
415
|
}
|
|
312
416
|
});
|
|
313
|
-
var
|
|
314
|
-
var
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
},
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
417
|
+
var _sfc_render = function render2() {
|
|
418
|
+
var _vm = this, _c = _vm._self._c;
|
|
419
|
+
_vm._self._setupProxy;
|
|
420
|
+
return _c("div", { ref: "pickerWrapper", staticClass: "view-date-picker-wrapper" }, [_c("div", { staticClass: "native-input-wrapper" }, [_c("input", { ref: "dateInput", staticClass: "native-input", attrs: { "type": "text", "placeholder": "请选择日期", "readonly": "" }, domProps: { "value": _vm.displayDate }, on: { "input": _vm.handleInput, "click": _vm.togglePanel } }), _c("span", { staticClass: "date-icon", on: { "click": _vm.togglePanel } }, [_vm._v("📅")])]), _c("div", { directives: [{ name: "show", rawName: "v-show", value: _vm.panelVisible, expression: "panelVisible" }], ref: "datePanel", staticClass: "date-picker-dropdown", style: _vm.panelStyle }, [_c("div", { staticClass: "date-picker-panel" }, [_c("div", { directives: [{ name: "show", rawName: "v-show", value: _vm.panelType == "date", expression: "panelType == 'date'" }], staticClass: "picker-header" }, [_c("button", { staticClass: "toggle-btn year-btn prev-year", on: { "click": _vm.switchToPrevYear } }, [_vm._v("«")]), _c("button", { staticClass: "toggle-btn month-btn prev-month", on: { "click": _vm.switchToPrevMonth } }, [_vm._v(" < ")]), _c("div", { staticClass: "current-month" }, [_c("span", { staticClass: "clickable-year", on: { "click": _vm.openYearPanel } }, [_vm._v(_vm._s(_vm.currentYear) + "年")]), _c("span", { staticClass: "clickable-month", on: { "click": _vm.openMonthPanel } }, [_vm._v(_vm._s(_vm.currentMonth) + "月")])]), _c("button", { staticClass: "toggle-btn month-btn next-month", on: { "click": _vm.switchToNextMonth } }, [_vm._v(">")]), _c("button", { staticClass: "toggle-btn year-btn next-year", on: { "click": _vm.switchToNextYear } }, [_vm._v("»")])]), _c("div", { directives: [{ name: "show", rawName: "v-show", value: _vm.panelType == "year", expression: "panelType == 'year'" }], staticClass: "picker-header" }, [_c("button", { staticClass: "toggle-btn month-btn prev-month", on: { "click": _vm.switchToPrevTenYears } }, [_vm._v(" < ")]), _c("div", { staticClass: "current-month" }, [_c("span", { staticClass: "clickable-year" }, [_vm._v(_vm._s(_vm.getDecadeStartAndEnd) + "年")])]), _c("button", { staticClass: "toggle-btn month-btn next-month", on: { "click": _vm.switchToNextTenYears } }, [_vm._v(">")])]), _c("div", { directives: [{ name: "show", rawName: "v-show", value: _vm.panelType == "month", expression: "panelType == 'month'" }], staticClass: "picker-header" }, [_c("button", { staticClass: "toggle-btn month-btn prev-month", on: { "click": _vm.switchToPrevYear } }, [_vm._v(" < ")]), _c("div", { staticClass: "current-month" }, [_c("span", { staticClass: "clickable-year" }, [_vm._v(_vm._s(_vm.currentYear) + "年")])]), _c("button", { staticClass: "toggle-btn month-btn next-month", on: { "click": _vm.switchToNextYear } }, [_vm._v(">")])]), _vm.panelType === "date" ? _c("div", { staticClass: "bod-mb" }, [_vm._m(0), _c("div", { staticClass: "picker-panel" }, _vm._l(_vm.panelDates, function(item, index2) {
|
|
421
|
+
return _c("div", { key: index2, staticClass: "date-item", class: {
|
|
422
|
+
"not-current-month": !item.isCurrentMonth,
|
|
423
|
+
"selected": item.formatDate === _vm.displayDate,
|
|
424
|
+
"hover": _vm.hoverDate === item.formatDate && item.formatDate !== _vm.displayDate
|
|
425
|
+
}, on: { "click": function($event) {
|
|
426
|
+
return _vm.selectDate(item);
|
|
427
|
+
}, "mouseenter": function($event) {
|
|
428
|
+
_vm.hoverDate = item.formatDate;
|
|
429
|
+
}, "mouseleave": function($event) {
|
|
430
|
+
_vm.hoverDate = "";
|
|
431
|
+
} } }, [_vm._v(" " + _vm._s(item.date.getDate()) + " ")]);
|
|
432
|
+
}), 0)]) : _vm.panelType === "year" ? _c("div", { staticClass: "bod-mb" }, _vm._l(_vm.decadeYears, function(year) {
|
|
433
|
+
return _c("div", { key: year, staticClass: "year-item", class: { "selected": year === _vm.currentYear }, on: { "click": function($event) {
|
|
434
|
+
return _vm.selectDecadeYear(year);
|
|
435
|
+
} } }, [_vm._v(" " + _vm._s(year) + "年 ")]);
|
|
436
|
+
}), 0) : _vm.panelType === "month" ? _c("div", { staticClass: "bod-mb" }, _vm._l(12, function(month) {
|
|
437
|
+
return _c("div", { key: month, staticClass: "month-item", class: { "selected": month === _vm.currentMonth }, on: { "click": function($event) {
|
|
438
|
+
return _vm.selectTargetMonth(month);
|
|
439
|
+
} } }, [_vm._v(" " + _vm._s(month) + "月 ")]);
|
|
440
|
+
}), 0) : _vm._e()])])]);
|
|
441
|
+
};
|
|
442
|
+
var _sfc_staticRenderFns = [function() {
|
|
443
|
+
var _vm = this, _c = _vm._self._c;
|
|
444
|
+
_vm._self._setupProxy;
|
|
445
|
+
return _c("div", { staticClass: "picker-week-header" }, [_c("div", { staticClass: "week-item" }, [_vm._v("日")]), _c("div", { staticClass: "week-item" }, [_vm._v("一")]), _c("div", { staticClass: "week-item" }, [_vm._v("二")]), _c("div", { staticClass: "week-item" }, [_vm._v("三")]), _c("div", { staticClass: "week-item" }, [_vm._v("四")]), _c("div", { staticClass: "week-item" }, [_vm._v("五")]), _c("div", { staticClass: "week-item" }, [_vm._v("六")])]);
|
|
446
|
+
}];
|
|
447
|
+
var __component__ = /* @__PURE__ */ normalizeComponent(
|
|
448
|
+
_sfc_main,
|
|
449
|
+
_sfc_render,
|
|
450
|
+
_sfc_staticRenderFns,
|
|
451
|
+
false,
|
|
344
452
|
null,
|
|
345
453
|
"e6885493"
|
|
346
454
|
);
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
455
|
+
const ViewDatePicker = __component__.exports;
|
|
456
|
+
const components = [MyButton, ViewDatePicker];
|
|
457
|
+
const install = (app) => {
|
|
458
|
+
components.forEach((component) => {
|
|
459
|
+
app.component(component.name, component);
|
|
350
460
|
});
|
|
351
461
|
};
|
|
352
|
-
typeof window
|
|
353
|
-
|
|
462
|
+
if (typeof window !== "undefined" && window.Vue) {
|
|
463
|
+
install(window.Vue);
|
|
464
|
+
}
|
|
465
|
+
const index = { install };
|
|
354
466
|
export {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
467
|
+
MyButton,
|
|
468
|
+
ViewDatePicker,
|
|
469
|
+
index as default,
|
|
470
|
+
install
|
|
359
471
|
};
|