cardbuddy 0.6.0
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/README.md +211 -0
- package/dist/cli.js +76 -0
- package/dist/config.js +63 -0
- package/dist/core.js +2 -0
- package/dist/preview-editor/assets/apple-touch-icon-BQcES9QK.png +0 -0
- package/dist/preview-editor/assets/default-image-wzZYQ86K.png +0 -0
- package/dist/preview-editor/assets/favicon-16-Cg6Nrosk.png +0 -0
- package/dist/preview-editor/assets/favicon-32-B_1744sp.png +0 -0
- package/dist/preview-editor/assets/index-BYB0hngG.js +72 -0
- package/dist/preview-editor/assets/index-CpBZEQDy.css +1 -0
- package/dist/preview-editor/assets/site-icon-CFMif8z4.png +0 -0
- package/dist/preview-editor/assets/svg-symbols-B2exBrAr.svg +118 -0
- package/dist/preview-editor/index.html +17 -0
- package/dist/server-core/_vendor/finmall-env.mjs +96 -0
- package/dist/server-core/assetProxy.js +154 -0
- package/dist/server-core/bbox.js +153 -0
- package/dist/server-core/browser.js +108 -0
- package/dist/server-core/buildDataFromSchema.js +50 -0
- package/dist/server-core/cardFiles.js +188 -0
- package/dist/server-core/cardHistory.js +156 -0
- package/dist/server-core/cardImage.js +85 -0
- package/dist/server-core/cardImportMeta.js +139 -0
- package/dist/server-core/cardListCache.js +68 -0
- package/dist/server-core/cardOpenFolder.js +135 -0
- package/dist/server-core/cardSave.js +127 -0
- package/dist/server-core/cardSidecar.js +72 -0
- package/dist/server-core/cardSync.js +259 -0
- package/dist/server-core/cardValidate.js +134 -0
- package/dist/server-core/index.js +82 -0
- package/dist/server-core/logger.js +241 -0
- package/dist/server-core/nodeModels.js +52 -0
- package/dist/server-core/renderStatus.js +207 -0
- package/dist/server-core/screenshot.js +123 -0
- package/dist/server-core/sliceStatic.js +44 -0
- package/dist/standalone.js +447 -0
- package/dist/vendored/App.vue +2330 -0
- package/dist/vendored/api.js +142 -0
- package/dist/vendored/assets/apple-touch-icon.png +0 -0
- package/dist/vendored/assets/default-image.png +0 -0
- package/dist/vendored/assets/favicon-16.png +0 -0
- package/dist/vendored/assets/favicon-32.png +0 -0
- package/dist/vendored/assets/logo.png +0 -0
- package/dist/vendored/assets/site-icon.png +0 -0
- package/dist/vendored/assets/svg-symbols.svg +118 -0
- package/dist/vendored/assets/svgIcons/icons.svg +54 -0
- package/dist/vendored/assets/svgIcons/index.js +39 -0
- package/dist/vendored/components/AbsoluteLayout.vue +42 -0
- package/dist/vendored/components/AlertCardInstance.vue +58 -0
- package/dist/vendored/components/AlertCardLayer.vue +59 -0
- package/dist/vendored/components/ApiPayloadTree.vue +168 -0
- package/dist/vendored/components/AppToast.vue +37 -0
- package/dist/vendored/components/Button.vue +37 -0
- package/dist/vendored/components/Canvas.vue +65 -0
- package/dist/vendored/components/CardGallery.vue +243 -0
- package/dist/vendored/components/CardPreview.vue +72 -0
- package/dist/vendored/components/CardSelect.vue +200 -0
- package/dist/vendored/components/CheckGroup.vue +131 -0
- package/dist/vendored/components/Column.vue +25 -0
- package/dist/vendored/components/ComponentPalette.vue +294 -0
- package/dist/vendored/components/ConfirmDialog.vue +39 -0
- package/dist/vendored/components/CustomPlaceholder.vue +33 -0
- package/dist/vendored/components/DatePickerOverlay.vue +345 -0
- package/dist/vendored/components/DebugPanel.vue +806 -0
- package/dist/vendored/components/DeviceOverlay.vue +70 -0
- package/dist/vendored/components/Divider.vue +22 -0
- package/dist/vendored/components/Dropdown.vue +191 -0
- package/dist/vendored/components/EventEditor.vue +247 -0
- package/dist/vendored/components/GridLayout.vue +67 -0
- package/dist/vendored/components/HoverGuides.vue +122 -0
- package/dist/vendored/components/Icon.vue +34 -0
- package/dist/vendored/components/Image.vue +34 -0
- package/dist/vendored/components/Input.vue +90 -0
- package/dist/vendored/components/JsonTree.vue +516 -0
- package/dist/vendored/components/ListLayout.vue +68 -0
- package/dist/vendored/components/LogValue.vue +51 -0
- package/dist/vendored/components/Map.vue +110 -0
- package/dist/vendored/components/MultiColumn.vue +49 -0
- package/dist/vendored/components/MultiText.vue +58 -0
- package/dist/vendored/components/NodeInspector.vue +295 -0
- package/dist/vendored/components/PickerOverlay.vue +131 -0
- package/dist/vendored/components/ProgressSlider.vue +167 -0
- package/dist/vendored/components/PropControl.vue +241 -0
- package/dist/vendored/components/PropTree.vue +128 -0
- package/dist/vendored/components/RadioButton.vue +74 -0
- package/dist/vendored/components/RemotePreview.vue +171 -0
- package/dist/vendored/components/RenderTree.vue +437 -0
- package/dist/vendored/components/Root.vue +30 -0
- package/dist/vendored/components/Row.vue +25 -0
- package/dist/vendored/components/SelectionOverlay.vue +105 -0
- package/dist/vendored/components/StructureTree.vue +949 -0
- package/dist/vendored/components/SvgCode.vue +19 -0
- package/dist/vendored/components/SvgSymbols.vue +30 -0
- package/dist/vendored/components/Switch.vue +38 -0
- package/dist/vendored/components/Text.vue +32 -0
- package/dist/vendored/components/Video.vue +70 -0
- package/dist/vendored/components/ViewContainer.vue +52 -0
- package/dist/vendored/components/base.js +12 -0
- package/dist/vendored/components/icons.js +47 -0
- package/dist/vendored/components/index.js +58 -0
- package/dist/vendored/components/setters/SetBgPosition.vue +64 -0
- package/dist/vendored/components/setters/SetBgSize.vue +90 -0
- package/dist/vendored/components/setters/SetCode.vue +90 -0
- package/dist/vendored/components/setters/SetColor.vue +244 -0
- package/dist/vendored/components/setters/SetCustomSelect.vue +58 -0
- package/dist/vendored/components/setters/SetExpr.vue +107 -0
- package/dist/vendored/components/setters/SetGradient.vue +125 -0
- package/dist/vendored/components/setters/SetGrid9.vue +68 -0
- package/dist/vendored/components/setters/SetIconSelect.vue +67 -0
- package/dist/vendored/components/setters/SetIfForm.vue +61 -0
- package/dist/vendored/components/setters/SetImage.vue +43 -0
- package/dist/vendored/components/setters/SetList.vue +139 -0
- package/dist/vendored/components/setters/SetNumber.vue +118 -0
- package/dist/vendored/components/setters/SetNumberStyle.vue +113 -0
- package/dist/vendored/components/setters/SetPadding.vue +77 -0
- package/dist/vendored/components/setters/SetSegment.vue +160 -0
- package/dist/vendored/components/setters/SetSelect.vue +51 -0
- package/dist/vendored/components/setters/SetSwitch.vue +49 -0
- package/dist/vendored/components/setters/SetText.vue +52 -0
- package/dist/vendored/components/setters/props.js +23 -0
- package/dist/vendored/fidelity/baseline-messageOverview.json +87 -0
- package/dist/vendored/fidelity/calibration.json +29 -0
- package/dist/vendored/fidelity/fidelity-messageOverview-after.html +114 -0
- package/dist/vendored/fidelity/fidelity-messageOverview-after.json +272 -0
- package/dist/vendored/fidelity/fidelity-messageOverview.html +185 -0
- package/dist/vendored/fidelity/fidelity-messageOverview.json +336 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_v2.html +262 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_v2.json +502 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_v3.html +201 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_v3.json +417 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_visual.html +125 -0
- package/dist/vendored/fidelity/fidelity-messageOverview_visual.json +338 -0
- package/dist/vendored/index.html +16 -0
- package/dist/vendored/main.js +36 -0
- package/dist/vendored/meta/action-meta.json +141 -0
- package/dist/vendored/meta/component-meta.json +2714 -0
- package/dist/vendored/meta/directive-meta.json +40 -0
- package/dist/vendored/meta/style-meta.json +1086 -0
- package/dist/vendored/runtime/StyleParser.js +179 -0
- package/dist/vendored/runtime/adapter.js +166 -0
- package/dist/vendored/runtime/alert-card.js +125 -0
- package/dist/vendored/runtime/app-toast.js +33 -0
- package/dist/vendored/runtime/assets.js +16 -0
- package/dist/vendored/runtime/canvas-context.js +141 -0
- package/dist/vendored/runtime/card-runtime.js +289 -0
- package/dist/vendored/runtime/clipboard-node.js +83 -0
- package/dist/vendored/runtime/clipboard.js +29 -0
- package/dist/vendored/runtime/evaluate.js +152 -0
- package/dist/vendored/runtime/event-model.js +300 -0
- package/dist/vendored/runtime/hoverGuide.js +31 -0
- package/dist/vendored/runtime/jsapi-mock.js +256 -0
- package/dist/vendored/runtime/node-model.js +217 -0
- package/dist/vendored/runtime/property.js +364 -0
- package/dist/vendored/runtime/selectionOverlay.js +53 -0
- package/dist/vendored/runtime/toPreview.js +648 -0
- package/dist/vendored/standalone-main.js +36 -0
- package/dist/vendored/standalone.html +12 -0
- package/dist/vendored/styles/app.css +2565 -0
- package/dist/vendored/styles/card-gallery.css +234 -0
- package/dist/vendored/styles/card-select.css +281 -0
- package/dist/vendored/styles/components.css +383 -0
- package/dist/vendored/styles/dropdown.css +337 -0
- package/dist/vendored/styles/json-tree.css +308 -0
- package/dist/vendored/styles/node-inspector.css +1003 -0
- package/dist/vendored/styles/setters.css +962 -0
- package/dist/vendored/styles/standalone.css +27 -0
- package/dist/vendored/styles/structure-tree.css +320 -0
- package/package.json +42 -0
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
showDatePicker 模拟展现层:底部弹出日期选择器(Vant 风格滚轮)。
|
|
3
|
+
相对固定视口 phone-viewport 定位(absolute inset:0),层级同 DeviceOverlay(z-index 1100)。
|
|
4
|
+
对齐 docs/动态卡片方案详细说明.md「showDatePicker - 时间选择器」:
|
|
5
|
+
- type='year_month_day' 三列(年-月-日);type='year_month' 两列(年-月);type='month_day' 两列(月-日)。
|
|
6
|
+
- 列生成受 startDate/endDate 约束;year_month_day 下「月」切换联动「日」可选天数(2 月按闰年)。
|
|
7
|
+
- 点「确定」回传 { error:'0', currentDate, data:{ year, month, day, value } },点「取消」不回传。
|
|
8
|
+
- 交互:桌面端 mousedown 抓住任意一列拖动滚轮(mousemove/mouseup)并吸附到最近项;
|
|
9
|
+
支持鼠标滚轮滚动、点击某一项直接选中;移动端 touch 事件(同一套 pointerY 逻辑)。
|
|
10
|
+
- 实现采用 scrollTop(而非 transform),避免 Chrome 对大幅 translateY 的渲染裁剪问题,
|
|
11
|
+
同时保留 .pk-col__list 的原生 overflow-y:auto + padding 结构,使滚动更自然。
|
|
12
|
+
- 复用 showPicker 的 .pk-* 弹层样式,通过 .pk-cols--wheel 隐藏滚动条。
|
|
13
|
+
-->
|
|
14
|
+
<template>
|
|
15
|
+
<div class="device-ui">
|
|
16
|
+
<transition name="picker-fade">
|
|
17
|
+
<div v-if="datePicker" class="pk-mask" @click.self="onCancel">
|
|
18
|
+
<div class="pk-sheet">
|
|
19
|
+
<div class="pk-bar">
|
|
20
|
+
<button type="button" class="pk-bar__btn pk-bar__btn--cancel" @click="onCancel">取消</button>
|
|
21
|
+
<div v-if="datePicker.title" class="pk-bar__title">{{ datePicker.title }}</div>
|
|
22
|
+
<button type="button" class="pk-bar__btn pk-bar__btn--ok" @click="onConfirm">确定</button>
|
|
23
|
+
</div>
|
|
24
|
+
<div
|
|
25
|
+
ref="cols"
|
|
26
|
+
class="pk-cols pk-cols--wheel"
|
|
27
|
+
:class="['pk-cols--' + columns.length, { 'is-dragging': dragging }]"
|
|
28
|
+
>
|
|
29
|
+
<div
|
|
30
|
+
v-for="(col, ci) in columns"
|
|
31
|
+
:key="col.key"
|
|
32
|
+
class="pk-col"
|
|
33
|
+
@mousedown.prevent="onDragStart(ci, $event)"
|
|
34
|
+
@touchstart.prevent="onDragStart(ci, $event)"
|
|
35
|
+
@wheel="onWheel(ci, $event)"
|
|
36
|
+
>
|
|
37
|
+
<div class="pk-col__band"></div>
|
|
38
|
+
<div class="pk-col__list" @scroll="onScroll(ci, $event)">
|
|
39
|
+
<div
|
|
40
|
+
v-for="(item, ii) in col.items"
|
|
41
|
+
:key="col.key + '-' + item.text"
|
|
42
|
+
class="pk-item"
|
|
43
|
+
:class="{ 'pk-item--on': sel[ci] === ii }"
|
|
44
|
+
@click="onItemClick(ci, ii)"
|
|
45
|
+
>{{ item.text }}</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</transition>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
54
|
+
|
|
55
|
+
<script>
|
|
56
|
+
import { deviceUI, dismissDatePicker } from '@/runtime/jsapi-mock.js'
|
|
57
|
+
|
|
58
|
+
// 与 .pk-cols(230) / .pk-item(40) 的 CSS 尺寸一致:中间选中带落在容器中线。
|
|
59
|
+
// 上下各留 95px 空白,使首项/末项也能滚到中线。
|
|
60
|
+
const ITEM_H = 40
|
|
61
|
+
const PAD = (230 - ITEM_H) / 2 // 95
|
|
62
|
+
|
|
63
|
+
function pad(n) {
|
|
64
|
+
return String(n).padStart(2, '0')
|
|
65
|
+
}
|
|
66
|
+
function range(a, b) {
|
|
67
|
+
const out = []
|
|
68
|
+
for (let i = a; i <= b; i++) out.push(i)
|
|
69
|
+
return out
|
|
70
|
+
}
|
|
71
|
+
function daysInMonth(y, m) {
|
|
72
|
+
const leap = (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0
|
|
73
|
+
const dim = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
|
|
74
|
+
return dim[(m - 1 + 12) % 12]
|
|
75
|
+
}
|
|
76
|
+
// 容错解析日期:'1970-1-1' / '2026-05-16' / '05-16' 均可
|
|
77
|
+
function parseDate(s) {
|
|
78
|
+
if (!s) return null
|
|
79
|
+
const nums = String(s).split('-').map((x) => parseInt(x, 10))
|
|
80
|
+
if (nums.some((n) => Number.isNaN(n))) return null
|
|
81
|
+
if (nums.length === 3) return { y: nums[0], m: nums[1], d: nums[2] }
|
|
82
|
+
if (nums.length === 2) return { m: nums[0], d: nums[1] }
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default {
|
|
87
|
+
name: 'DatePickerOverlay',
|
|
88
|
+
data() {
|
|
89
|
+
return {
|
|
90
|
+
sel: [], // 各列选中索引(列数由 type 决定)
|
|
91
|
+
dragging: false,
|
|
92
|
+
drag: null, // { ci, startY, startScrollTop, moved }
|
|
93
|
+
suppressClick: false, // 拖动结束后抑制误触发的 click
|
|
94
|
+
scrollTimers: [], // 各列滚轮停止后吸附定时器
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
computed: {
|
|
98
|
+
datePicker() {
|
|
99
|
+
return deviceUI.datePicker
|
|
100
|
+
},
|
|
101
|
+
// 起止年份范围(供年列生成与选中值反算)
|
|
102
|
+
yearRange() {
|
|
103
|
+
const dp = this.datePicker
|
|
104
|
+
const lo = parseDate(dp && dp.startDate) || { y: 1970 }
|
|
105
|
+
const hi = parseDate(dp && dp.endDate) || { y: 2100 }
|
|
106
|
+
const minY = lo.y || 1970
|
|
107
|
+
const maxY = hi.y || 2100
|
|
108
|
+
return { minY, maxY }
|
|
109
|
+
},
|
|
110
|
+
columns() {
|
|
111
|
+
const dp = this.datePicker
|
|
112
|
+
if (!dp) return []
|
|
113
|
+
const { minY } = this.yearRange
|
|
114
|
+
if (dp.type === 'month_day') {
|
|
115
|
+
return [
|
|
116
|
+
{ key: 'month', items: range(1, 12).map((m) => ({ text: pad(m) })) },
|
|
117
|
+
{ key: 'day', items: range(1, 31).map((d) => ({ text: pad(d) })) },
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
if (dp.type === 'year_month') {
|
|
121
|
+
return [
|
|
122
|
+
{ key: 'year', items: range(minY, this.yearRange.maxY).map((y) => ({ text: String(y) })) },
|
|
123
|
+
{ key: 'month', items: range(1, 12).map((m) => ({ text: pad(m) })) },
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
// year_month_day:日列随选中年月联动天数
|
|
127
|
+
const y = minY + (this.sel[0] || 0)
|
|
128
|
+
const m = (this.sel[1] || 0) + 1
|
|
129
|
+
const dim = daysInMonth(y, m)
|
|
130
|
+
return [
|
|
131
|
+
{ key: 'year', items: range(minY, this.yearRange.maxY).map((yy) => ({ text: String(yy) })) },
|
|
132
|
+
{ key: 'month', items: range(1, 12).map((mm) => ({ text: pad(mm) })) },
|
|
133
|
+
{ key: 'day', items: range(1, dim).map((d) => ({ text: pad(d) })) },
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
watch: {
|
|
138
|
+
// datePicker 切换(含入参变化)时按 selectDate 初始化选中项
|
|
139
|
+
datePicker: {
|
|
140
|
+
immediate: true,
|
|
141
|
+
handler(dp) {
|
|
142
|
+
if (!dp) {
|
|
143
|
+
this.sel = []
|
|
144
|
+
this.scrollTimers = []
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
const parsed = parseDate(dp.selectDate) || this.todayConstrained(dp)
|
|
148
|
+
const { minY } = this.yearRange
|
|
149
|
+
if (dp.type === 'month_day') {
|
|
150
|
+
this.sel = [parsed.m - 1, parsed.d - 1]
|
|
151
|
+
} else if (dp.type === 'year_month') {
|
|
152
|
+
this.sel = [parsed.y - minY, parsed.m - 1]
|
|
153
|
+
} else {
|
|
154
|
+
const dim = daysInMonth(parsed.y, parsed.m)
|
|
155
|
+
this.sel = [parsed.y - minY, parsed.m - 1, Math.min(parsed.d, dim) - 1]
|
|
156
|
+
}
|
|
157
|
+
this.$nextTick(() => this.syncScrollTops())
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
// 年/月切换后联动「日」可选范围并刷新各列 scrollTop
|
|
161
|
+
sel: {
|
|
162
|
+
deep: true,
|
|
163
|
+
handler() {
|
|
164
|
+
const dp = this.datePicker
|
|
165
|
+
if (!dp) return
|
|
166
|
+
const s = this.sel.slice()
|
|
167
|
+
if (dp.type === 'year_month_day') {
|
|
168
|
+
const y = this.yearRange.minY + (s[0] || 0)
|
|
169
|
+
const m = (s[1] || 0) + 1
|
|
170
|
+
const dim = daysInMonth(y, m)
|
|
171
|
+
if (s[2] > dim - 1) {
|
|
172
|
+
s[2] = dim - 1
|
|
173
|
+
this.sel = s
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
this.$nextTick(() => this.syncScrollTops())
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
methods: {
|
|
182
|
+
getList(ci) {
|
|
183
|
+
const cols = this.$refs.cols
|
|
184
|
+
if (!cols) return null
|
|
185
|
+
return cols.querySelectorAll('.pk-col__list')[ci] || null
|
|
186
|
+
},
|
|
187
|
+
scrollForIndex(i) {
|
|
188
|
+
return (i || 0) * ITEM_H
|
|
189
|
+
},
|
|
190
|
+
// 用当前 sel 重建各列 scrollTop
|
|
191
|
+
syncScrollTops() {
|
|
192
|
+
const cols = this.columns
|
|
193
|
+
cols.forEach((_, ci) => {
|
|
194
|
+
const list = this.getList(ci)
|
|
195
|
+
if (!list) return
|
|
196
|
+
list.scrollTop = this.scrollForIndex(this.sel[ci] || 0)
|
|
197
|
+
})
|
|
198
|
+
},
|
|
199
|
+
pointerY(e) {
|
|
200
|
+
return e.touches && e.touches.length ? e.touches[0].clientY : e.clientY
|
|
201
|
+
},
|
|
202
|
+
onDragStart(ci, e) {
|
|
203
|
+
this.suppressClick = false
|
|
204
|
+
const list = this.getList(ci)
|
|
205
|
+
this.drag = {
|
|
206
|
+
ci,
|
|
207
|
+
startY: this.pointerY(e),
|
|
208
|
+
startScrollTop: list ? list.scrollTop : 0,
|
|
209
|
+
moved: false,
|
|
210
|
+
}
|
|
211
|
+
this.dragging = true
|
|
212
|
+
// 拖动中停止吸附
|
|
213
|
+
clearTimeout(this.scrollTimers[ci])
|
|
214
|
+
window.addEventListener('mousemove', this.onDragMove)
|
|
215
|
+
window.addEventListener('mouseup', this.onDragEnd)
|
|
216
|
+
window.addEventListener('touchmove', this.onDragMove, { passive: false })
|
|
217
|
+
window.addEventListener('touchend', this.onDragEnd)
|
|
218
|
+
},
|
|
219
|
+
onDragMove(e) {
|
|
220
|
+
if (!this.drag) return
|
|
221
|
+
if (e.cancelable) e.preventDefault()
|
|
222
|
+
const y = this.pointerY(e)
|
|
223
|
+
const delta = y - this.drag.startY
|
|
224
|
+
if (Math.abs(delta) > 3) this.drag.moved = true
|
|
225
|
+
const list = this.getList(this.drag.ci)
|
|
226
|
+
if (list) list.scrollTop = this.drag.startScrollTop - delta
|
|
227
|
+
},
|
|
228
|
+
onDragEnd() {
|
|
229
|
+
if (!this.drag) return
|
|
230
|
+
const ci = this.drag.ci
|
|
231
|
+
const list = this.getList(ci)
|
|
232
|
+
const wasMoved = this.drag.moved
|
|
233
|
+
this.drag = null
|
|
234
|
+
this.dragging = false
|
|
235
|
+
window.removeEventListener('mousemove', this.onDragMove)
|
|
236
|
+
window.removeEventListener('mouseup', this.onDragEnd)
|
|
237
|
+
window.removeEventListener('touchmove', this.onDragMove)
|
|
238
|
+
window.removeEventListener('touchend', this.onDragEnd)
|
|
239
|
+
if (list) {
|
|
240
|
+
const max = this.columns[ci].items.length - 1
|
|
241
|
+
let idx = Math.round(list.scrollTop / ITEM_H)
|
|
242
|
+
idx = Math.max(0, Math.min(max, idx))
|
|
243
|
+
// 先吸附再改 sel,避免 watch 冲突
|
|
244
|
+
list.scrollTop = this.scrollForIndex(idx)
|
|
245
|
+
if (this.sel[ci] !== idx) {
|
|
246
|
+
const next = this.sel.slice()
|
|
247
|
+
next[ci] = idx
|
|
248
|
+
this.sel = next
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (wasMoved) {
|
|
252
|
+
this.suppressClick = true
|
|
253
|
+
this.$nextTick(() => {
|
|
254
|
+
this.suppressClick = false
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
onWheel(ci, e) {
|
|
259
|
+
// 让原生滚轮滚动,停止后由 onScroll 吸附
|
|
260
|
+
clearTimeout(this.scrollTimers[ci])
|
|
261
|
+
this.scrollTimers[ci] = setTimeout(() => this.snapToNearest(ci), 120)
|
|
262
|
+
},
|
|
263
|
+
onScroll(ci, e) {
|
|
264
|
+
if (this.dragging) return
|
|
265
|
+
clearTimeout(this.scrollTimers[ci])
|
|
266
|
+
this.scrollTimers[ci] = setTimeout(() => this.snapToNearest(ci), 120)
|
|
267
|
+
},
|
|
268
|
+
snapToNearest(ci) {
|
|
269
|
+
const list = this.getList(ci)
|
|
270
|
+
if (!list) return
|
|
271
|
+
const max = (this.columns[ci] && this.columns[ci].items.length - 1) || 0
|
|
272
|
+
let idx = Math.round(list.scrollTop / ITEM_H)
|
|
273
|
+
idx = Math.max(0, Math.min(max, idx))
|
|
274
|
+
list.scrollTop = this.scrollForIndex(idx)
|
|
275
|
+
if (this.sel[ci] !== idx) {
|
|
276
|
+
const next = this.sel.slice()
|
|
277
|
+
next[ci] = idx
|
|
278
|
+
this.sel = next
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
onItemClick(ci, ii) {
|
|
282
|
+
if (this.suppressClick) return
|
|
283
|
+
const list = this.getList(ci)
|
|
284
|
+
if (list) list.scrollTop = this.scrollForIndex(ii)
|
|
285
|
+
const next = this.sel.slice()
|
|
286
|
+
next[ci] = ii
|
|
287
|
+
this.sel = next
|
|
288
|
+
},
|
|
289
|
+
todayConstrained(dp) {
|
|
290
|
+
const t = new Date()
|
|
291
|
+
const { minY, maxY } = this.yearRange
|
|
292
|
+
let y = t.getFullYear()
|
|
293
|
+
y = Math.max(minY, Math.min(maxY, y))
|
|
294
|
+
let m = t.getMonth() + 1
|
|
295
|
+
const dim = daysInMonth(y, m)
|
|
296
|
+
let d = Math.min(t.getDate(), dim)
|
|
297
|
+
return { y, m, d }
|
|
298
|
+
},
|
|
299
|
+
buildResult() {
|
|
300
|
+
const dp = this.datePicker
|
|
301
|
+
if (!dp) return null
|
|
302
|
+
const { minY } = this.yearRange
|
|
303
|
+
let y = ''
|
|
304
|
+
let m = 0
|
|
305
|
+
let d = 0
|
|
306
|
+
if (dp.type === 'month_day') {
|
|
307
|
+
m = (this.sel[0] || 0) + 1
|
|
308
|
+
d = (this.sel[1] || 0) + 1
|
|
309
|
+
} else if (dp.type === 'year_month') {
|
|
310
|
+
y = minY + (this.sel[0] || 0)
|
|
311
|
+
m = (this.sel[1] || 0) + 1
|
|
312
|
+
} else {
|
|
313
|
+
y = minY + (this.sel[0] || 0)
|
|
314
|
+
m = (this.sel[1] || 0) + 1
|
|
315
|
+
d = (this.sel[2] || 0) + 1
|
|
316
|
+
}
|
|
317
|
+
const mm = pad(m)
|
|
318
|
+
const dd = pad(d)
|
|
319
|
+
let value
|
|
320
|
+
if (dp.type === 'year_month_day') value = `${y}-${mm}-${dd}`
|
|
321
|
+
else if (dp.type === 'year_month') value = `${y}-${mm}`
|
|
322
|
+
else value = `${mm}-${dd}`
|
|
323
|
+
return {
|
|
324
|
+
year: dp.type === 'month_day' ? '' : String(y),
|
|
325
|
+
month: mm,
|
|
326
|
+
day: dp.type === 'year_month' ? '' : dd,
|
|
327
|
+
value,
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
onConfirm() {
|
|
331
|
+
dismissDatePicker(true, this.buildResult())
|
|
332
|
+
},
|
|
333
|
+
onCancel() {
|
|
334
|
+
dismissDatePicker(false)
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
beforeUnmount() {
|
|
338
|
+
window.removeEventListener('mousemove', this.onDragMove)
|
|
339
|
+
window.removeEventListener('mouseup', this.onDragEnd)
|
|
340
|
+
window.removeEventListener('touchmove', this.onDragMove)
|
|
341
|
+
window.removeEventListener('touchend', this.onDragEnd)
|
|
342
|
+
this.scrollTimers.forEach((t) => clearTimeout(t))
|
|
343
|
+
},
|
|
344
|
+
}
|
|
345
|
+
</script>
|