@ptcwebops/ptcw-design 5.6.1 → 5.6.2
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/dist/cjs/ptc-mobile-select.cjs.entry.js +436 -436
- package/dist/collection/components/ptc-mobile-select/mobile-select/dist/mobile-select.es.js +441 -0
- package/dist/collection/components/ptc-mobile-select/mobile-select/dist/mobile-select.iife.js +661 -0
- package/dist/collection/components/ptc-mobile-select/mobile-select/dist/mobile-select.iife.min.js +7 -0
- package/dist/collection/components/ptc-mobile-select/mobile-select/dist/mobile-select.umd.js +22 -0
- package/dist/collection/components/ptc-mobile-select/ptc-mobile-select.css +164 -164
- package/dist/collection/components/ptc-mobile-select/ptc-mobile-select.js +1 -1
- package/dist/custom-elements/index.js +436 -436
- package/dist/esm/ptc-mobile-select.entry.js +436 -436
- package/dist/types/components/ptc-mobile-select/mobile-select/dist/mobile-select.d.ts +209 -0
- package/dist/types/components/ptc-mobile-select/ptc-mobile-select.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +1 -1
|
@@ -4,442 +4,442 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
const index = require('./index-63ddc79c.js');
|
|
6
6
|
|
|
7
|
-
/*
|
|
8
|
-
* mobile-select v1.4.0
|
|
9
|
-
* Homepage: https://github.com/onlyhom/mobile-select
|
|
10
|
-
* Released under the MIT License.
|
|
11
|
-
* (c) 2017-present
|
|
12
|
-
*/
|
|
13
|
-
var S = Object.defineProperty;
|
|
14
|
-
var D = (g, t, e) => t in g ? S(g, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : g[t] = e;
|
|
15
|
-
var h = (g, t, e) => (D(g, typeof t != "symbol" ? t + "" : t, e), e);
|
|
16
|
-
function w() {
|
|
17
|
-
return !navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/);
|
|
18
|
-
}
|
|
19
|
-
const l = class {
|
|
20
|
-
constructor(t) {
|
|
21
|
-
h(this, "mobileSelect");
|
|
22
|
-
h(this, "trigger");
|
|
23
|
-
h(this, "wheelList");
|
|
24
|
-
h(this, "sliderList");
|
|
25
|
-
h(this, "wheelsContain");
|
|
26
|
-
h(this, "panel");
|
|
27
|
-
h(this, "ensureBtn");
|
|
28
|
-
h(this, "cancelBtn");
|
|
29
|
-
h(this, "grayLayer");
|
|
30
|
-
h(this, "popUp");
|
|
31
|
-
h(this, "initPosition");
|
|
32
|
-
h(this, "initColWidth");
|
|
33
|
-
h(this, "wheelsData");
|
|
34
|
-
h(this, "displayJson");
|
|
35
|
-
h(this, "curValue");
|
|
36
|
-
h(this, "curIndexArr");
|
|
37
|
-
h(this, "isCascade");
|
|
38
|
-
h(this, "isJsonType");
|
|
39
|
-
h(this, "startY");
|
|
40
|
-
h(this, "moveEndY");
|
|
41
|
-
h(this, "moveY");
|
|
42
|
-
h(this, "preMoveY");
|
|
43
|
-
h(this, "offsetY");
|
|
44
|
-
h(this, "offsetSum");
|
|
45
|
-
h(this, "oversizeBorder");
|
|
46
|
-
h(this, "enableClickStatus");
|
|
47
|
-
h(this, "optionHeight");
|
|
48
|
-
h(this, "curDistance");
|
|
49
|
-
h(this, "cascadeJsonData");
|
|
50
|
-
h(this, "eventHandleMap");
|
|
51
|
-
h(this, "initDeepCount");
|
|
52
|
-
h(this, "config");
|
|
53
|
-
!l.checkRequiredConfig(t) || (this.config = Object.assign({}, l.defaultConfig, t), this.wheelsData = t.wheels, this.isJsonType = !1, this.cascadeJsonData = [], this.displayJson = [], this.curValue = [], this.curIndexArr = [], this.isCascade = !1, this.offsetY = 0, this.offsetSum = 0, this.curDistance = [], this.enableClickStatus = !1, this.optionHeight = 0, this.initPosition = t.position || [], this.initColWidth = t.colWidth || [], this.init());
|
|
54
|
-
}
|
|
55
|
-
init() {
|
|
56
|
-
if (!this.checkTriggerAvailable())
|
|
57
|
-
return;
|
|
58
|
-
const { config: t } = this;
|
|
59
|
-
if (this.isJsonType = l.checkDataType(this.wheelsData), this.renderComponent(this.wheelsData), this.wheelList = this.mobileSelect.getElementsByClassName("ms-wheel"), this.sliderList = this.mobileSelect.getElementsByClassName("ms-select-container"), this.panel = this.mobileSelect.querySelector(".ms-panel"), this.wheelsContain = this.mobileSelect.querySelector(".ms-wheels"), this.ensureBtn = this.mobileSelect.querySelector(".ms-ensure"), this.cancelBtn = this.mobileSelect.querySelector(".ms-cancel"), this.grayLayer = this.mobileSelect.querySelector(".ms-gray-layer"), this.popUp = this.mobileSelect.querySelector(".ms-content"), this.optionHeight = this.mobileSelect.querySelector("li").offsetHeight, t.initValue && this.setTriggerInnerText(t.initValue), this.setStyle(t), this.isCascade = this.checkCascade(), this.isCascade && this.initCascade(), t.initValue && (this.initPosition = this.getPositionByInitValue()), this.initPosition.length < this.sliderList.length) {
|
|
60
|
-
const e = this.sliderList.length - this.initPosition.length;
|
|
61
|
-
for (let i = 0; i < e; i++)
|
|
62
|
-
this.initPosition.push(0);
|
|
63
|
-
}
|
|
64
|
-
this.isCascade ? this.initPosition.forEach((e, i) => {
|
|
65
|
-
this.checkRange(i, this.initPosition);
|
|
66
|
-
}) : this.setCurDistance(this.initPosition), this.eventHandleMap = {
|
|
67
|
-
cancelBtn: {
|
|
68
|
-
event: "click",
|
|
69
|
-
fn: () => {
|
|
70
|
-
var e, i, s, n;
|
|
71
|
-
this.hide(), (i = (e = this.config).cancel) == null || i.call(e, this.curIndexArr, this.curValue, this), (n = (s = this.config).onCancel) == null || n.call(s, this.curValue, this.curIndexArr, this);
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
ensureBtn: {
|
|
75
|
-
event: "click",
|
|
76
|
-
fn: () => {
|
|
77
|
-
var e, i, s, n;
|
|
78
|
-
this.hide(), this.optionHeight || (this.optionHeight = this.mobileSelect.querySelector("li").offsetHeight), this.setTriggerInnerText(this.getConnectedString()), this.curIndexArr = this.getIndexArr(), this.curValue = this.getCurValue(), (i = (e = this.config).callback) == null || i.call(e, this.curIndexArr, this.curValue, this), (n = (s = this.config).onChange) == null || n.call(s, this.curValue, this.curIndexArr, this);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
trigger: {
|
|
82
|
-
event: "click",
|
|
83
|
-
fn: () => {
|
|
84
|
-
this.show();
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
grayLayer: {
|
|
88
|
-
event: "click",
|
|
89
|
-
fn: () => this.hide()
|
|
90
|
-
},
|
|
91
|
-
popUp: {
|
|
92
|
-
event: "click",
|
|
93
|
-
fn: (e) => e.stopPropagation()
|
|
94
|
-
},
|
|
95
|
-
panel: {
|
|
96
|
-
event: ["touchstart", "touchend", "touchmove"],
|
|
97
|
-
fn: (e) => this.touch(e)
|
|
98
|
-
}
|
|
99
|
-
}, w() && (this.eventHandleMap.panel.event = ["mousedown", "mousemove", "mouseup"]), this.registerEvents("add"), this.fixRowStyle(), t.autoFocus && this.show();
|
|
100
|
-
}
|
|
101
|
-
static checkDataType(t) {
|
|
102
|
-
var e, i;
|
|
103
|
-
return typeof ((i = (e = t[0]) == null ? void 0 : e.data) == null ? void 0 : i[0]) == "object";
|
|
104
|
-
}
|
|
105
|
-
static checkRequiredConfig(t) {
|
|
106
|
-
const e = l.REQUIRED_PARAMS;
|
|
107
|
-
if (!t) {
|
|
108
|
-
const i = e.map((s) => `'${s}'`);
|
|
109
|
-
return l.log("error", `missing required param ${i.join(" and ")}.`), !1;
|
|
110
|
-
}
|
|
111
|
-
for (let i = 0; i < e.length; i++) {
|
|
112
|
-
const s = e[i];
|
|
113
|
-
if (!t[s])
|
|
114
|
-
return l.log("error", `missing required param '${s}'.`), !1;
|
|
115
|
-
}
|
|
116
|
-
return !0;
|
|
117
|
-
}
|
|
118
|
-
static log(t, e) {
|
|
119
|
-
var i;
|
|
120
|
-
(i = console[t]) == null || i.call(console, `[mobile-select]: ${e}`);
|
|
121
|
-
}
|
|
122
|
-
checkTriggerAvailable() {
|
|
123
|
-
const { config: t } = this;
|
|
124
|
-
return this.trigger = t.trigger instanceof HTMLElement ? t.trigger : document.querySelector(t.trigger), this.trigger ? !0 : (l.log("error", "trigger HTMLElement does not found on your document."), !1);
|
|
125
|
-
}
|
|
126
|
-
getPositionByInitValue() {
|
|
127
|
-
var n;
|
|
128
|
-
const { keyMap: t, connector: e, initValue: i } = this.config, s = (i == null ? void 0 : i.split(e)) || [];
|
|
129
|
-
if (this.isJsonType) {
|
|
130
|
-
let o = (n = this.wheelsData[0]) == null ? void 0 : n.data;
|
|
131
|
-
return s.reduce((r, c) => {
|
|
132
|
-
var u;
|
|
133
|
-
const a = o == null ? void 0 : o.findIndex((d) => d[t.value] == c);
|
|
134
|
-
return r.push(a < 0 ? 0 : a), o = (u = o[a]) == null ? void 0 : u[t.childs], r;
|
|
135
|
-
}, []);
|
|
136
|
-
}
|
|
137
|
-
return s.reduce((o, r, c) => {
|
|
138
|
-
var u, d;
|
|
139
|
-
const a = (d = (u = this.wheelsData[c]) == null ? void 0 : u.data) == null ? void 0 : d.findIndex((f) => f == r);
|
|
140
|
-
return o.push(a < 0 ? 0 : a), o;
|
|
141
|
-
}, []);
|
|
142
|
-
}
|
|
143
|
-
getConnectedString() {
|
|
144
|
-
let t = "";
|
|
145
|
-
for (let e = 0; e < this.wheelList.length; e++)
|
|
146
|
-
e == this.wheelList.length - 1 ? t += this.getInnerText(e) : t += this.getInnerText(e) + this.config.connector;
|
|
147
|
-
return t;
|
|
148
|
-
}
|
|
149
|
-
setTriggerInnerText(t) {
|
|
150
|
-
this.config.triggerDisplayValue && (this.trigger.textContent = t);
|
|
151
|
-
}
|
|
152
|
-
setValue(t) {
|
|
153
|
-
if (!t || !t.length)
|
|
154
|
-
return;
|
|
155
|
-
if (this.isJsonType && typeof t[0] != "object" || !this.isJsonType && typeof t[0] == "object") {
|
|
156
|
-
l.log("error", `The setValue() input format should be same with getValue(), like: ${JSON.stringify(this.getValue())}`);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
const { keyMap: e } = this.config;
|
|
160
|
-
t.forEach((i, s) => {
|
|
161
|
-
var r;
|
|
162
|
-
const n = this.isCascade ? this.displayJson[s] : (r = this.wheelsData[s]) == null ? void 0 : r.data, o = n == null ? void 0 : n.findIndex((c) => this.isJsonType ? i[e.id] == c[e.id] || i[e.value] == c[e.value] : i == c);
|
|
163
|
-
this.locatePosition(s, o);
|
|
164
|
-
}), this.setTriggerInnerText(this.getConnectedString());
|
|
165
|
-
}
|
|
166
|
-
setTitle(t) {
|
|
167
|
-
this.mobileSelect.querySelector(".ms-title").innerHTML = t;
|
|
168
|
-
}
|
|
169
|
-
setStyle(t) {
|
|
170
|
-
if (t.ensureBtnColor && (this.ensureBtn.style.color = t.ensureBtnColor), t.cancelBtnColor && (this.cancelBtn.style.color = t.cancelBtnColor), t.titleColor) {
|
|
171
|
-
const e = this.mobileSelect.querySelector(".ms-title");
|
|
172
|
-
e.style.color = t.titleColor;
|
|
173
|
-
}
|
|
174
|
-
if (t.textColor && (this.panel = this.mobileSelect.querySelector(".ms-panel"), this.panel.style.color = t.textColor), t.titleBgColor) {
|
|
175
|
-
const e = this.mobileSelect.querySelector(".ms-btn-bar");
|
|
176
|
-
e.style.backgroundColor = t.titleBgColor;
|
|
177
|
-
}
|
|
178
|
-
if (t.bgColor) {
|
|
179
|
-
this.panel = this.mobileSelect.querySelector(".ms-panel");
|
|
180
|
-
const e = this.mobileSelect.querySelector(".ms-shadow-mask");
|
|
181
|
-
this.panel.style.backgroundColor = t.bgColor, e.style.background = "linear-gradient(to bottom, " + t.bgColor + ", rgba(255, 255, 255, 0), " + t.bgColor + ")";
|
|
182
|
-
}
|
|
183
|
-
if (typeof t.maskOpacity == "number") {
|
|
184
|
-
const e = this.mobileSelect.querySelector(".ms-gray-layer");
|
|
185
|
-
e.style.background = "rgba(0, 0, 0, " + t.maskOpacity + ")";
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
show() {
|
|
189
|
-
var t, e, i;
|
|
190
|
-
this.mobileSelect.classList.add("ms-show"), (t = document.querySelector("body")) == null || t.classList.add("ms-show"), typeof this.config.onShow == "function" && ((i = (e = this.config).onShow) == null || i.call(e, this.curValue, this.curIndexArr, this));
|
|
191
|
-
}
|
|
192
|
-
hide() {
|
|
193
|
-
var t, e, i;
|
|
194
|
-
this.mobileSelect.classList.remove("ms-show"), (t = document.querySelector("body")) == null || t.classList.remove("ms-show"), typeof this.config.onHide == "function" && ((i = (e = this.config).onHide) == null || i.call(e, this.curValue, this.curIndexArr, this));
|
|
195
|
-
}
|
|
196
|
-
registerEvents(t) {
|
|
197
|
-
for (const [e, i] of Object.entries(this.eventHandleMap))
|
|
198
|
-
typeof i.event == "string" ? this[e][`${t}EventListener`](i.event, i.fn, { passive: !1 }) : i.event.forEach((s) => {
|
|
199
|
-
this[e][`${t}EventListener`](s, i.fn, { passive: !1 });
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
destroy() {
|
|
203
|
-
var t, e;
|
|
204
|
-
this.registerEvents("remove"), (e = (t = this.mobileSelect) == null ? void 0 : t.parentNode) == null || e.removeChild(this.mobileSelect);
|
|
205
|
-
}
|
|
206
|
-
getOptionsHtmlStr(t) {
|
|
207
|
-
const { keyMap: e } = this.config;
|
|
208
|
-
let i = "";
|
|
209
|
-
if (this.isJsonType)
|
|
210
|
-
for (let s = 0; s < t.length; s++) {
|
|
211
|
-
const n = t[s][e.id], o = t[s][e.value];
|
|
212
|
-
i += `<li data-id="${n}">${o}</li>`;
|
|
213
|
-
}
|
|
214
|
-
else
|
|
215
|
-
for (let s = 0; s < t.length; s++)
|
|
216
|
-
i += "<li>" + t[s] + "</li>";
|
|
217
|
-
return i;
|
|
218
|
-
}
|
|
219
|
-
renderComponent(t) {
|
|
220
|
-
this.mobileSelect = document.createElement("div"), this.mobileSelect.className = "ms-mobile-select", this.mobileSelect.innerHTML = `<div class="ms-gray-layer"></div>
|
|
221
|
-
<div class="ms-content">
|
|
222
|
-
<div class="ms-btn-bar">
|
|
223
|
-
<div class="ms-fix-width">
|
|
224
|
-
<div class="ms-cancel">${this.config.cancelBtnText}</div>
|
|
225
|
-
<div class="ms-title">${this.config.title || ""}</div>
|
|
226
|
-
<div class="ms-ensure">${this.config.ensureBtnText}</div>
|
|
227
|
-
</div>
|
|
228
|
-
</div>
|
|
229
|
-
<div class="ms-panel">
|
|
230
|
-
<div class="ms-fix-width">
|
|
231
|
-
<div class="ms-wheels"></div>
|
|
232
|
-
<div class="ms-select-line"></div>
|
|
233
|
-
<div class="ms-shadow-mask"></div>
|
|
234
|
-
</div>
|
|
235
|
-
</div>`, document.body.appendChild(this.mobileSelect);
|
|
236
|
-
let e = "";
|
|
237
|
-
for (let i = 0; i < t.length; i++)
|
|
238
|
-
e += `<div class="ms-wheel" data-index="${i}"><ul class="ms-select-container">`, e += this.getOptionsHtmlStr(t[i].data), e += "</ul></div>";
|
|
239
|
-
this.mobileSelect.querySelector(".ms-wheels").innerHTML = e;
|
|
240
|
-
}
|
|
241
|
-
reRenderWheels() {
|
|
242
|
-
const t = this.wheelList.length - this.displayJson.length;
|
|
243
|
-
if (t > 0)
|
|
244
|
-
for (let e = 0; e < t; e++)
|
|
245
|
-
this.wheelsContain.removeChild(this.wheelList[this.wheelList.length - 1]);
|
|
246
|
-
for (let e = 0; e < this.displayJson.length; e++)
|
|
247
|
-
if (this.wheelList[e])
|
|
248
|
-
this.sliderList[e].innerHTML = this.getOptionsHtmlStr(this.displayJson[e]);
|
|
249
|
-
else {
|
|
250
|
-
const i = document.createElement("div");
|
|
251
|
-
i.className = "ms-wheel", i.innerHTML = `<ul class="ms-select-container">${this.getOptionsHtmlStr(this.displayJson[e])}</ul>`, i.setAttribute("data-index", e.toString()), this.wheelsContain.appendChild(i);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
checkCascade() {
|
|
255
|
-
var e;
|
|
256
|
-
const { keyMap: t } = this.config;
|
|
257
|
-
if (this.isJsonType) {
|
|
258
|
-
const i = this.wheelsData[0].data;
|
|
259
|
-
for (let s = 0; s < i.length; s++)
|
|
260
|
-
if (t.childs in i[s] && ((e = i[s][t.childs]) == null ? void 0 : e.length) > 0)
|
|
261
|
-
return this.cascadeJsonData = this.wheelsData[0].data, !0;
|
|
262
|
-
}
|
|
263
|
-
return !1;
|
|
264
|
-
}
|
|
265
|
-
initCascade() {
|
|
266
|
-
this.displayJson.push(this.cascadeJsonData), this.initPosition.length > 0 ? (this.initDeepCount = 0, this.initCheckArrDeep(this.cascadeJsonData[this.initPosition[0]])) : this.checkArrDeep(this.cascadeJsonData[0]), this.reRenderWheels();
|
|
267
|
-
}
|
|
268
|
-
initCheckArrDeep(t) {
|
|
269
|
-
if (t) {
|
|
270
|
-
const { keyMap: e } = this.config;
|
|
271
|
-
if (e.childs in t && t[e.childs].length > 0) {
|
|
272
|
-
this.displayJson.push(t[e.childs]), this.initDeepCount++;
|
|
273
|
-
const i = t[e.childs][this.initPosition[this.initDeepCount]];
|
|
274
|
-
i ? this.initCheckArrDeep(i) : this.checkArrDeep(t[e.childs][0]);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
checkArrDeep(t) {
|
|
279
|
-
if (!t)
|
|
280
|
-
return;
|
|
281
|
-
const { keyMap: e } = this.config;
|
|
282
|
-
e.childs in t && t[e.childs].length > 0 && (this.displayJson.push(t[e.childs]), this.checkArrDeep(t[e.childs][0]));
|
|
283
|
-
}
|
|
284
|
-
checkRange(t, e) {
|
|
285
|
-
var o;
|
|
286
|
-
const i = this.displayJson.length - 1 - t, { keyMap: s } = this.config;
|
|
287
|
-
for (let r = 0; r < i; r++)
|
|
288
|
-
this.displayJson.pop();
|
|
289
|
-
let n;
|
|
290
|
-
for (let r = 0; r <= t; r++)
|
|
291
|
-
n = r == 0 ? this.cascadeJsonData[e[0]] : (o = n == null ? void 0 : n[s.childs]) == null ? void 0 : o[e[r]];
|
|
292
|
-
this.checkArrDeep(n), this.reRenderWheels(), this.fixRowStyle(), this.setCurDistance(this.resetPosition(t, e));
|
|
293
|
-
}
|
|
294
|
-
resetPosition(t, e) {
|
|
295
|
-
const i = [...e];
|
|
296
|
-
let s;
|
|
297
|
-
if (this.sliderList.length > e.length) {
|
|
298
|
-
s = this.sliderList.length - e.length;
|
|
299
|
-
for (let n = 0; n < s; n++)
|
|
300
|
-
i.push(0);
|
|
301
|
-
} else if (this.sliderList.length < e.length) {
|
|
302
|
-
s = e.length - this.sliderList.length;
|
|
303
|
-
for (let n = 0; n < s; n++)
|
|
304
|
-
i.pop();
|
|
305
|
-
}
|
|
306
|
-
for (let n = t + 1; n < i.length; n++)
|
|
307
|
-
i[n] = 0;
|
|
308
|
-
return i;
|
|
309
|
-
}
|
|
310
|
-
updateWheels(t) {
|
|
311
|
-
if (this.isCascade) {
|
|
312
|
-
if (this.cascadeJsonData = t, this.displayJson = [], this.initCascade(), this.initPosition.length < this.sliderList.length) {
|
|
313
|
-
const e = this.sliderList.length - this.initPosition.length;
|
|
314
|
-
for (let i = 0; i < e; i++)
|
|
315
|
-
this.initPosition.push(0);
|
|
316
|
-
}
|
|
317
|
-
this.setCurDistance(this.initPosition), this.fixRowStyle();
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
updateWheel(t, e) {
|
|
321
|
-
if (this.isCascade) {
|
|
322
|
-
l.log("error", "'updateWheel()' not support cascade json data, please use 'updateWheels()' instead to update the whole data source");
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
let i = "";
|
|
326
|
-
i += this.getOptionsHtmlStr(e), this.wheelsData[t] = this.isJsonType ? { data: e } : e, this.sliderList[t].innerHTML = i;
|
|
327
|
-
}
|
|
328
|
-
fixRowStyle() {
|
|
329
|
-
if (this.initColWidth.length && this.initColWidth.length === this.wheelList.length) {
|
|
330
|
-
const e = this.initColWidth.reduce((i, s) => i + s, 0);
|
|
331
|
-
this.initColWidth.forEach((i, s) => {
|
|
332
|
-
this.wheelList[s].style.width = (i / e * 100).toFixed(2) + "%";
|
|
333
|
-
});
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
const t = (100 / this.wheelList.length).toFixed(2);
|
|
337
|
-
for (let e = 0; e < this.wheelList.length; e++)
|
|
338
|
-
this.wheelList[e].style.width = t + "%";
|
|
339
|
-
}
|
|
340
|
-
getIndex(t) {
|
|
341
|
-
return Math.round((2 * this.optionHeight - t) / this.optionHeight);
|
|
342
|
-
}
|
|
343
|
-
getIndexArr() {
|
|
344
|
-
const t = [];
|
|
345
|
-
for (let e = 0; e < this.curDistance.length; e++)
|
|
346
|
-
t.push(this.getIndex(this.curDistance[e]));
|
|
347
|
-
return t;
|
|
348
|
-
}
|
|
349
|
-
getCurValue() {
|
|
350
|
-
const t = [], e = this.getIndexArr(), { keyMap: i } = this.config;
|
|
351
|
-
if (this.isCascade)
|
|
352
|
-
for (let s = 0; s < this.wheelList.length; s++) {
|
|
353
|
-
const n = this.displayJson[s][e[s]];
|
|
354
|
-
n && t.push({
|
|
355
|
-
[i.id]: n[i.id],
|
|
356
|
-
[i.value]: n[i.value]
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
else if (this.isJsonType)
|
|
360
|
-
for (let s = 0; s < this.curDistance.length; s++)
|
|
361
|
-
t.push(this.wheelsData[s].data[this.getIndex(this.curDistance[s])]);
|
|
362
|
-
else
|
|
363
|
-
for (let s = 0; s < this.curDistance.length; s++)
|
|
364
|
-
t.push(this.getInnerText(s));
|
|
365
|
-
return t;
|
|
366
|
-
}
|
|
367
|
-
getValue() {
|
|
368
|
-
return this.getCurValue();
|
|
369
|
-
}
|
|
370
|
-
calcDistance(t) {
|
|
371
|
-
return 2 * this.optionHeight - t * this.optionHeight;
|
|
372
|
-
}
|
|
373
|
-
setCurDistance(t) {
|
|
374
|
-
const e = [];
|
|
375
|
-
for (let i = 0; i < this.sliderList.length; i++)
|
|
376
|
-
e.push(this.calcDistance(t[i])), this.movePosition(this.sliderList[i], e[i]);
|
|
377
|
-
this.curDistance = e;
|
|
378
|
-
}
|
|
379
|
-
fixPosition(t) {
|
|
380
|
-
return -(this.getIndex(t) - 2) * this.optionHeight;
|
|
381
|
-
}
|
|
382
|
-
movePosition(t, e) {
|
|
383
|
-
t.style.transform = "translate3d(0," + e + "px, 0)";
|
|
384
|
-
}
|
|
385
|
-
locatePosition(t, e) {
|
|
386
|
-
t === void 0 || e === void 0 || e < 0 || (this.curDistance[t] = this.calcDistance(e), this.movePosition(this.sliderList[t], this.curDistance[t]), this.isCascade && this.checkRange(t, this.getIndexArr()));
|
|
387
|
-
}
|
|
388
|
-
updateCurDistance(t, e) {
|
|
389
|
-
this.curDistance[e] = parseInt(t.style.transform.split(",")[1]);
|
|
390
|
-
}
|
|
391
|
-
getInnerText(t) {
|
|
392
|
-
var s;
|
|
393
|
-
const e = this.sliderList[t].getElementsByTagName("li").length;
|
|
394
|
-
let i = this.getIndex(this.curDistance[t]);
|
|
395
|
-
return i >= e ? i = e - 1 : i < 0 && (i = 0), ((s = this.sliderList[t].getElementsByTagName("li")[i]) == null ? void 0 : s.textContent) || "";
|
|
396
|
-
}
|
|
397
|
-
touch(t) {
|
|
398
|
-
var o, r, c, a, u, d, f, v;
|
|
399
|
-
const i = (t.composedPath && t.composedPath()).find((m) => {
|
|
400
|
-
var p;
|
|
401
|
-
return (p = m.classList) == null ? void 0 : p.contains("ms-wheel");
|
|
402
|
-
});
|
|
403
|
-
if (!i)
|
|
404
|
-
return;
|
|
405
|
-
const s = i.firstChild, n = parseInt(i.getAttribute("data-index") || "0");
|
|
406
|
-
switch (t.type) {
|
|
407
|
-
case "touchstart":
|
|
408
|
-
case "mousedown":
|
|
409
|
-
s.style.transition = "none 0s ease-out", this.startY = Math.floor(t instanceof TouchEvent ? t.touches[0].clientY : t.clientY), this.preMoveY = this.startY, t.type === "mousedown" && (this.enableClickStatus = !0);
|
|
410
|
-
break;
|
|
411
|
-
case "touchmove":
|
|
412
|
-
case "mousemove":
|
|
413
|
-
if (t.preventDefault(), t.type === "mousemove" && !this.enableClickStatus)
|
|
414
|
-
break;
|
|
415
|
-
this.moveY = Math.floor(t instanceof TouchEvent ? t.touches[0].clientY : t.clientY), this.offsetY = (this.moveY - this.preMoveY) * this.config.scrollSpeed, this.updateCurDistance(s, n), this.curDistance[n] = this.curDistance[n] + this.offsetY, this.movePosition(s, this.curDistance[n]), this.preMoveY = this.moveY;
|
|
416
|
-
break;
|
|
417
|
-
case "touchend":
|
|
418
|
-
case "mouseup":
|
|
419
|
-
if (s.style.transition = "transform 0.18s ease-out", this.moveEndY = Math.floor(t instanceof TouchEvent ? t.changedTouches[0].clientY : t.clientY), this.offsetSum = this.moveEndY - this.startY, this.oversizeBorder = -(s.getElementsByTagName("li").length - 3) * this.optionHeight, this.offsetSum == 0) {
|
|
420
|
-
const m = Math.floor((window.innerHeight - this.moveEndY) / 40);
|
|
421
|
-
if (m != 2) {
|
|
422
|
-
const p = m - 2, C = this.curDistance[n] + p * this.optionHeight;
|
|
423
|
-
C <= 2 * this.optionHeight && C >= this.oversizeBorder && (this.curDistance[n] = C, this.movePosition(s, this.curDistance[n]), (r = (o = this.config).transitionEnd) == null || r.call(o, this.getIndexArr(), this.getCurValue(), this), (a = (c = this.config).onTransitionEnd) == null || a.call(c, this.getCurValue(), this.getIndexArr(), this));
|
|
424
|
-
}
|
|
425
|
-
} else
|
|
426
|
-
this.updateCurDistance(s, n), this.curDistance[n] = this.fixPosition(this.curDistance[n]), this.curDistance[n] > 2 * this.optionHeight ? this.curDistance[n] = 2 * this.optionHeight : this.curDistance[n] < this.oversizeBorder && (this.curDistance[n] = this.oversizeBorder), this.movePosition(s, this.curDistance[n]), (d = (u = this.config).transitionEnd) == null || d.call(u, this.getIndexArr(), this.getCurValue(), this), (v = (f = this.config).onTransitionEnd) == null || v.call(f, this.getCurValue(), this.getIndexArr(), this);
|
|
427
|
-
t.type === "mouseup" && (this.enableClickStatus = !1), this.isCascade && this.checkRange(n, this.getIndexArr());
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
let y = l;
|
|
433
|
-
h(y, "defaultConfig", {
|
|
434
|
-
keyMap: { id: "id", value: "value", childs: "childs" },
|
|
435
|
-
position: [],
|
|
436
|
-
colWidth: [],
|
|
437
|
-
title: "",
|
|
438
|
-
connector: " ",
|
|
439
|
-
ensureBtnText: "\u786E\u8BA4",
|
|
440
|
-
cancelBtnText: "\u53D6\u6D88",
|
|
441
|
-
triggerDisplayValue: !0,
|
|
442
|
-
scrollSpeed: 1
|
|
7
|
+
/*
|
|
8
|
+
* mobile-select v1.4.0
|
|
9
|
+
* Homepage: https://github.com/onlyhom/mobile-select
|
|
10
|
+
* Released under the MIT License.
|
|
11
|
+
* (c) 2017-present
|
|
12
|
+
*/
|
|
13
|
+
var S = Object.defineProperty;
|
|
14
|
+
var D = (g, t, e) => t in g ? S(g, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : g[t] = e;
|
|
15
|
+
var h = (g, t, e) => (D(g, typeof t != "symbol" ? t + "" : t, e), e);
|
|
16
|
+
function w() {
|
|
17
|
+
return !navigator.userAgent.toLowerCase().match(/ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/);
|
|
18
|
+
}
|
|
19
|
+
const l = class {
|
|
20
|
+
constructor(t) {
|
|
21
|
+
h(this, "mobileSelect");
|
|
22
|
+
h(this, "trigger");
|
|
23
|
+
h(this, "wheelList");
|
|
24
|
+
h(this, "sliderList");
|
|
25
|
+
h(this, "wheelsContain");
|
|
26
|
+
h(this, "panel");
|
|
27
|
+
h(this, "ensureBtn");
|
|
28
|
+
h(this, "cancelBtn");
|
|
29
|
+
h(this, "grayLayer");
|
|
30
|
+
h(this, "popUp");
|
|
31
|
+
h(this, "initPosition");
|
|
32
|
+
h(this, "initColWidth");
|
|
33
|
+
h(this, "wheelsData");
|
|
34
|
+
h(this, "displayJson");
|
|
35
|
+
h(this, "curValue");
|
|
36
|
+
h(this, "curIndexArr");
|
|
37
|
+
h(this, "isCascade");
|
|
38
|
+
h(this, "isJsonType");
|
|
39
|
+
h(this, "startY");
|
|
40
|
+
h(this, "moveEndY");
|
|
41
|
+
h(this, "moveY");
|
|
42
|
+
h(this, "preMoveY");
|
|
43
|
+
h(this, "offsetY");
|
|
44
|
+
h(this, "offsetSum");
|
|
45
|
+
h(this, "oversizeBorder");
|
|
46
|
+
h(this, "enableClickStatus");
|
|
47
|
+
h(this, "optionHeight");
|
|
48
|
+
h(this, "curDistance");
|
|
49
|
+
h(this, "cascadeJsonData");
|
|
50
|
+
h(this, "eventHandleMap");
|
|
51
|
+
h(this, "initDeepCount");
|
|
52
|
+
h(this, "config");
|
|
53
|
+
!l.checkRequiredConfig(t) || (this.config = Object.assign({}, l.defaultConfig, t), this.wheelsData = t.wheels, this.isJsonType = !1, this.cascadeJsonData = [], this.displayJson = [], this.curValue = [], this.curIndexArr = [], this.isCascade = !1, this.offsetY = 0, this.offsetSum = 0, this.curDistance = [], this.enableClickStatus = !1, this.optionHeight = 0, this.initPosition = t.position || [], this.initColWidth = t.colWidth || [], this.init());
|
|
54
|
+
}
|
|
55
|
+
init() {
|
|
56
|
+
if (!this.checkTriggerAvailable())
|
|
57
|
+
return;
|
|
58
|
+
const { config: t } = this;
|
|
59
|
+
if (this.isJsonType = l.checkDataType(this.wheelsData), this.renderComponent(this.wheelsData), this.wheelList = this.mobileSelect.getElementsByClassName("ms-wheel"), this.sliderList = this.mobileSelect.getElementsByClassName("ms-select-container"), this.panel = this.mobileSelect.querySelector(".ms-panel"), this.wheelsContain = this.mobileSelect.querySelector(".ms-wheels"), this.ensureBtn = this.mobileSelect.querySelector(".ms-ensure"), this.cancelBtn = this.mobileSelect.querySelector(".ms-cancel"), this.grayLayer = this.mobileSelect.querySelector(".ms-gray-layer"), this.popUp = this.mobileSelect.querySelector(".ms-content"), this.optionHeight = this.mobileSelect.querySelector("li").offsetHeight, t.initValue && this.setTriggerInnerText(t.initValue), this.setStyle(t), this.isCascade = this.checkCascade(), this.isCascade && this.initCascade(), t.initValue && (this.initPosition = this.getPositionByInitValue()), this.initPosition.length < this.sliderList.length) {
|
|
60
|
+
const e = this.sliderList.length - this.initPosition.length;
|
|
61
|
+
for (let i = 0; i < e; i++)
|
|
62
|
+
this.initPosition.push(0);
|
|
63
|
+
}
|
|
64
|
+
this.isCascade ? this.initPosition.forEach((e, i) => {
|
|
65
|
+
this.checkRange(i, this.initPosition);
|
|
66
|
+
}) : this.setCurDistance(this.initPosition), this.eventHandleMap = {
|
|
67
|
+
cancelBtn: {
|
|
68
|
+
event: "click",
|
|
69
|
+
fn: () => {
|
|
70
|
+
var e, i, s, n;
|
|
71
|
+
this.hide(), (i = (e = this.config).cancel) == null || i.call(e, this.curIndexArr, this.curValue, this), (n = (s = this.config).onCancel) == null || n.call(s, this.curValue, this.curIndexArr, this);
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
ensureBtn: {
|
|
75
|
+
event: "click",
|
|
76
|
+
fn: () => {
|
|
77
|
+
var e, i, s, n;
|
|
78
|
+
this.hide(), this.optionHeight || (this.optionHeight = this.mobileSelect.querySelector("li").offsetHeight), this.setTriggerInnerText(this.getConnectedString()), this.curIndexArr = this.getIndexArr(), this.curValue = this.getCurValue(), (i = (e = this.config).callback) == null || i.call(e, this.curIndexArr, this.curValue, this), (n = (s = this.config).onChange) == null || n.call(s, this.curValue, this.curIndexArr, this);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
trigger: {
|
|
82
|
+
event: "click",
|
|
83
|
+
fn: () => {
|
|
84
|
+
this.show();
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
grayLayer: {
|
|
88
|
+
event: "click",
|
|
89
|
+
fn: () => this.hide()
|
|
90
|
+
},
|
|
91
|
+
popUp: {
|
|
92
|
+
event: "click",
|
|
93
|
+
fn: (e) => e.stopPropagation()
|
|
94
|
+
},
|
|
95
|
+
panel: {
|
|
96
|
+
event: ["touchstart", "touchend", "touchmove"],
|
|
97
|
+
fn: (e) => this.touch(e)
|
|
98
|
+
}
|
|
99
|
+
}, w() && (this.eventHandleMap.panel.event = ["mousedown", "mousemove", "mouseup"]), this.registerEvents("add"), this.fixRowStyle(), t.autoFocus && this.show();
|
|
100
|
+
}
|
|
101
|
+
static checkDataType(t) {
|
|
102
|
+
var e, i;
|
|
103
|
+
return typeof ((i = (e = t[0]) == null ? void 0 : e.data) == null ? void 0 : i[0]) == "object";
|
|
104
|
+
}
|
|
105
|
+
static checkRequiredConfig(t) {
|
|
106
|
+
const e = l.REQUIRED_PARAMS;
|
|
107
|
+
if (!t) {
|
|
108
|
+
const i = e.map((s) => `'${s}'`);
|
|
109
|
+
return l.log("error", `missing required param ${i.join(" and ")}.`), !1;
|
|
110
|
+
}
|
|
111
|
+
for (let i = 0; i < e.length; i++) {
|
|
112
|
+
const s = e[i];
|
|
113
|
+
if (!t[s])
|
|
114
|
+
return l.log("error", `missing required param '${s}'.`), !1;
|
|
115
|
+
}
|
|
116
|
+
return !0;
|
|
117
|
+
}
|
|
118
|
+
static log(t, e) {
|
|
119
|
+
var i;
|
|
120
|
+
(i = console[t]) == null || i.call(console, `[mobile-select]: ${e}`);
|
|
121
|
+
}
|
|
122
|
+
checkTriggerAvailable() {
|
|
123
|
+
const { config: t } = this;
|
|
124
|
+
return this.trigger = t.trigger instanceof HTMLElement ? t.trigger : document.querySelector(t.trigger), this.trigger ? !0 : (l.log("error", "trigger HTMLElement does not found on your document."), !1);
|
|
125
|
+
}
|
|
126
|
+
getPositionByInitValue() {
|
|
127
|
+
var n;
|
|
128
|
+
const { keyMap: t, connector: e, initValue: i } = this.config, s = (i == null ? void 0 : i.split(e)) || [];
|
|
129
|
+
if (this.isJsonType) {
|
|
130
|
+
let o = (n = this.wheelsData[0]) == null ? void 0 : n.data;
|
|
131
|
+
return s.reduce((r, c) => {
|
|
132
|
+
var u;
|
|
133
|
+
const a = o == null ? void 0 : o.findIndex((d) => d[t.value] == c);
|
|
134
|
+
return r.push(a < 0 ? 0 : a), o = (u = o[a]) == null ? void 0 : u[t.childs], r;
|
|
135
|
+
}, []);
|
|
136
|
+
}
|
|
137
|
+
return s.reduce((o, r, c) => {
|
|
138
|
+
var u, d;
|
|
139
|
+
const a = (d = (u = this.wheelsData[c]) == null ? void 0 : u.data) == null ? void 0 : d.findIndex((f) => f == r);
|
|
140
|
+
return o.push(a < 0 ? 0 : a), o;
|
|
141
|
+
}, []);
|
|
142
|
+
}
|
|
143
|
+
getConnectedString() {
|
|
144
|
+
let t = "";
|
|
145
|
+
for (let e = 0; e < this.wheelList.length; e++)
|
|
146
|
+
e == this.wheelList.length - 1 ? t += this.getInnerText(e) : t += this.getInnerText(e) + this.config.connector;
|
|
147
|
+
return t;
|
|
148
|
+
}
|
|
149
|
+
setTriggerInnerText(t) {
|
|
150
|
+
this.config.triggerDisplayValue && (this.trigger.textContent = t);
|
|
151
|
+
}
|
|
152
|
+
setValue(t) {
|
|
153
|
+
if (!t || !t.length)
|
|
154
|
+
return;
|
|
155
|
+
if (this.isJsonType && typeof t[0] != "object" || !this.isJsonType && typeof t[0] == "object") {
|
|
156
|
+
l.log("error", `The setValue() input format should be same with getValue(), like: ${JSON.stringify(this.getValue())}`);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
const { keyMap: e } = this.config;
|
|
160
|
+
t.forEach((i, s) => {
|
|
161
|
+
var r;
|
|
162
|
+
const n = this.isCascade ? this.displayJson[s] : (r = this.wheelsData[s]) == null ? void 0 : r.data, o = n == null ? void 0 : n.findIndex((c) => this.isJsonType ? i[e.id] == c[e.id] || i[e.value] == c[e.value] : i == c);
|
|
163
|
+
this.locatePosition(s, o);
|
|
164
|
+
}), this.setTriggerInnerText(this.getConnectedString());
|
|
165
|
+
}
|
|
166
|
+
setTitle(t) {
|
|
167
|
+
this.mobileSelect.querySelector(".ms-title").innerHTML = t;
|
|
168
|
+
}
|
|
169
|
+
setStyle(t) {
|
|
170
|
+
if (t.ensureBtnColor && (this.ensureBtn.style.color = t.ensureBtnColor), t.cancelBtnColor && (this.cancelBtn.style.color = t.cancelBtnColor), t.titleColor) {
|
|
171
|
+
const e = this.mobileSelect.querySelector(".ms-title");
|
|
172
|
+
e.style.color = t.titleColor;
|
|
173
|
+
}
|
|
174
|
+
if (t.textColor && (this.panel = this.mobileSelect.querySelector(".ms-panel"), this.panel.style.color = t.textColor), t.titleBgColor) {
|
|
175
|
+
const e = this.mobileSelect.querySelector(".ms-btn-bar");
|
|
176
|
+
e.style.backgroundColor = t.titleBgColor;
|
|
177
|
+
}
|
|
178
|
+
if (t.bgColor) {
|
|
179
|
+
this.panel = this.mobileSelect.querySelector(".ms-panel");
|
|
180
|
+
const e = this.mobileSelect.querySelector(".ms-shadow-mask");
|
|
181
|
+
this.panel.style.backgroundColor = t.bgColor, e.style.background = "linear-gradient(to bottom, " + t.bgColor + ", rgba(255, 255, 255, 0), " + t.bgColor + ")";
|
|
182
|
+
}
|
|
183
|
+
if (typeof t.maskOpacity == "number") {
|
|
184
|
+
const e = this.mobileSelect.querySelector(".ms-gray-layer");
|
|
185
|
+
e.style.background = "rgba(0, 0, 0, " + t.maskOpacity + ")";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
show() {
|
|
189
|
+
var t, e, i;
|
|
190
|
+
this.mobileSelect.classList.add("ms-show"), (t = document.querySelector("body")) == null || t.classList.add("ms-show"), typeof this.config.onShow == "function" && ((i = (e = this.config).onShow) == null || i.call(e, this.curValue, this.curIndexArr, this));
|
|
191
|
+
}
|
|
192
|
+
hide() {
|
|
193
|
+
var t, e, i;
|
|
194
|
+
this.mobileSelect.classList.remove("ms-show"), (t = document.querySelector("body")) == null || t.classList.remove("ms-show"), typeof this.config.onHide == "function" && ((i = (e = this.config).onHide) == null || i.call(e, this.curValue, this.curIndexArr, this));
|
|
195
|
+
}
|
|
196
|
+
registerEvents(t) {
|
|
197
|
+
for (const [e, i] of Object.entries(this.eventHandleMap))
|
|
198
|
+
typeof i.event == "string" ? this[e][`${t}EventListener`](i.event, i.fn, { passive: !1 }) : i.event.forEach((s) => {
|
|
199
|
+
this[e][`${t}EventListener`](s, i.fn, { passive: !1 });
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
destroy() {
|
|
203
|
+
var t, e;
|
|
204
|
+
this.registerEvents("remove"), (e = (t = this.mobileSelect) == null ? void 0 : t.parentNode) == null || e.removeChild(this.mobileSelect);
|
|
205
|
+
}
|
|
206
|
+
getOptionsHtmlStr(t) {
|
|
207
|
+
const { keyMap: e } = this.config;
|
|
208
|
+
let i = "";
|
|
209
|
+
if (this.isJsonType)
|
|
210
|
+
for (let s = 0; s < t.length; s++) {
|
|
211
|
+
const n = t[s][e.id], o = t[s][e.value];
|
|
212
|
+
i += `<li data-id="${n}">${o}</li>`;
|
|
213
|
+
}
|
|
214
|
+
else
|
|
215
|
+
for (let s = 0; s < t.length; s++)
|
|
216
|
+
i += "<li>" + t[s] + "</li>";
|
|
217
|
+
return i;
|
|
218
|
+
}
|
|
219
|
+
renderComponent(t) {
|
|
220
|
+
this.mobileSelect = document.createElement("div"), this.mobileSelect.className = "ms-mobile-select", this.mobileSelect.innerHTML = `<div class="ms-gray-layer"></div>
|
|
221
|
+
<div class="ms-content">
|
|
222
|
+
<div class="ms-btn-bar">
|
|
223
|
+
<div class="ms-fix-width">
|
|
224
|
+
<div class="ms-cancel">${this.config.cancelBtnText}</div>
|
|
225
|
+
<div class="ms-title">${this.config.title || ""}</div>
|
|
226
|
+
<div class="ms-ensure">${this.config.ensureBtnText}</div>
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
<div class="ms-panel">
|
|
230
|
+
<div class="ms-fix-width">
|
|
231
|
+
<div class="ms-wheels"></div>
|
|
232
|
+
<div class="ms-select-line"></div>
|
|
233
|
+
<div class="ms-shadow-mask"></div>
|
|
234
|
+
</div>
|
|
235
|
+
</div>`, document.body.appendChild(this.mobileSelect);
|
|
236
|
+
let e = "";
|
|
237
|
+
for (let i = 0; i < t.length; i++)
|
|
238
|
+
e += `<div class="ms-wheel" data-index="${i}"><ul class="ms-select-container">`, e += this.getOptionsHtmlStr(t[i].data), e += "</ul></div>";
|
|
239
|
+
this.mobileSelect.querySelector(".ms-wheels").innerHTML = e;
|
|
240
|
+
}
|
|
241
|
+
reRenderWheels() {
|
|
242
|
+
const t = this.wheelList.length - this.displayJson.length;
|
|
243
|
+
if (t > 0)
|
|
244
|
+
for (let e = 0; e < t; e++)
|
|
245
|
+
this.wheelsContain.removeChild(this.wheelList[this.wheelList.length - 1]);
|
|
246
|
+
for (let e = 0; e < this.displayJson.length; e++)
|
|
247
|
+
if (this.wheelList[e])
|
|
248
|
+
this.sliderList[e].innerHTML = this.getOptionsHtmlStr(this.displayJson[e]);
|
|
249
|
+
else {
|
|
250
|
+
const i = document.createElement("div");
|
|
251
|
+
i.className = "ms-wheel", i.innerHTML = `<ul class="ms-select-container">${this.getOptionsHtmlStr(this.displayJson[e])}</ul>`, i.setAttribute("data-index", e.toString()), this.wheelsContain.appendChild(i);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
checkCascade() {
|
|
255
|
+
var e;
|
|
256
|
+
const { keyMap: t } = this.config;
|
|
257
|
+
if (this.isJsonType) {
|
|
258
|
+
const i = this.wheelsData[0].data;
|
|
259
|
+
for (let s = 0; s < i.length; s++)
|
|
260
|
+
if (t.childs in i[s] && ((e = i[s][t.childs]) == null ? void 0 : e.length) > 0)
|
|
261
|
+
return this.cascadeJsonData = this.wheelsData[0].data, !0;
|
|
262
|
+
}
|
|
263
|
+
return !1;
|
|
264
|
+
}
|
|
265
|
+
initCascade() {
|
|
266
|
+
this.displayJson.push(this.cascadeJsonData), this.initPosition.length > 0 ? (this.initDeepCount = 0, this.initCheckArrDeep(this.cascadeJsonData[this.initPosition[0]])) : this.checkArrDeep(this.cascadeJsonData[0]), this.reRenderWheels();
|
|
267
|
+
}
|
|
268
|
+
initCheckArrDeep(t) {
|
|
269
|
+
if (t) {
|
|
270
|
+
const { keyMap: e } = this.config;
|
|
271
|
+
if (e.childs in t && t[e.childs].length > 0) {
|
|
272
|
+
this.displayJson.push(t[e.childs]), this.initDeepCount++;
|
|
273
|
+
const i = t[e.childs][this.initPosition[this.initDeepCount]];
|
|
274
|
+
i ? this.initCheckArrDeep(i) : this.checkArrDeep(t[e.childs][0]);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
checkArrDeep(t) {
|
|
279
|
+
if (!t)
|
|
280
|
+
return;
|
|
281
|
+
const { keyMap: e } = this.config;
|
|
282
|
+
e.childs in t && t[e.childs].length > 0 && (this.displayJson.push(t[e.childs]), this.checkArrDeep(t[e.childs][0]));
|
|
283
|
+
}
|
|
284
|
+
checkRange(t, e) {
|
|
285
|
+
var o;
|
|
286
|
+
const i = this.displayJson.length - 1 - t, { keyMap: s } = this.config;
|
|
287
|
+
for (let r = 0; r < i; r++)
|
|
288
|
+
this.displayJson.pop();
|
|
289
|
+
let n;
|
|
290
|
+
for (let r = 0; r <= t; r++)
|
|
291
|
+
n = r == 0 ? this.cascadeJsonData[e[0]] : (o = n == null ? void 0 : n[s.childs]) == null ? void 0 : o[e[r]];
|
|
292
|
+
this.checkArrDeep(n), this.reRenderWheels(), this.fixRowStyle(), this.setCurDistance(this.resetPosition(t, e));
|
|
293
|
+
}
|
|
294
|
+
resetPosition(t, e) {
|
|
295
|
+
const i = [...e];
|
|
296
|
+
let s;
|
|
297
|
+
if (this.sliderList.length > e.length) {
|
|
298
|
+
s = this.sliderList.length - e.length;
|
|
299
|
+
for (let n = 0; n < s; n++)
|
|
300
|
+
i.push(0);
|
|
301
|
+
} else if (this.sliderList.length < e.length) {
|
|
302
|
+
s = e.length - this.sliderList.length;
|
|
303
|
+
for (let n = 0; n < s; n++)
|
|
304
|
+
i.pop();
|
|
305
|
+
}
|
|
306
|
+
for (let n = t + 1; n < i.length; n++)
|
|
307
|
+
i[n] = 0;
|
|
308
|
+
return i;
|
|
309
|
+
}
|
|
310
|
+
updateWheels(t) {
|
|
311
|
+
if (this.isCascade) {
|
|
312
|
+
if (this.cascadeJsonData = t, this.displayJson = [], this.initCascade(), this.initPosition.length < this.sliderList.length) {
|
|
313
|
+
const e = this.sliderList.length - this.initPosition.length;
|
|
314
|
+
for (let i = 0; i < e; i++)
|
|
315
|
+
this.initPosition.push(0);
|
|
316
|
+
}
|
|
317
|
+
this.setCurDistance(this.initPosition), this.fixRowStyle();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
updateWheel(t, e) {
|
|
321
|
+
if (this.isCascade) {
|
|
322
|
+
l.log("error", "'updateWheel()' not support cascade json data, please use 'updateWheels()' instead to update the whole data source");
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
let i = "";
|
|
326
|
+
i += this.getOptionsHtmlStr(e), this.wheelsData[t] = this.isJsonType ? { data: e } : e, this.sliderList[t].innerHTML = i;
|
|
327
|
+
}
|
|
328
|
+
fixRowStyle() {
|
|
329
|
+
if (this.initColWidth.length && this.initColWidth.length === this.wheelList.length) {
|
|
330
|
+
const e = this.initColWidth.reduce((i, s) => i + s, 0);
|
|
331
|
+
this.initColWidth.forEach((i, s) => {
|
|
332
|
+
this.wheelList[s].style.width = (i / e * 100).toFixed(2) + "%";
|
|
333
|
+
});
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const t = (100 / this.wheelList.length).toFixed(2);
|
|
337
|
+
for (let e = 0; e < this.wheelList.length; e++)
|
|
338
|
+
this.wheelList[e].style.width = t + "%";
|
|
339
|
+
}
|
|
340
|
+
getIndex(t) {
|
|
341
|
+
return Math.round((2 * this.optionHeight - t) / this.optionHeight);
|
|
342
|
+
}
|
|
343
|
+
getIndexArr() {
|
|
344
|
+
const t = [];
|
|
345
|
+
for (let e = 0; e < this.curDistance.length; e++)
|
|
346
|
+
t.push(this.getIndex(this.curDistance[e]));
|
|
347
|
+
return t;
|
|
348
|
+
}
|
|
349
|
+
getCurValue() {
|
|
350
|
+
const t = [], e = this.getIndexArr(), { keyMap: i } = this.config;
|
|
351
|
+
if (this.isCascade)
|
|
352
|
+
for (let s = 0; s < this.wheelList.length; s++) {
|
|
353
|
+
const n = this.displayJson[s][e[s]];
|
|
354
|
+
n && t.push({
|
|
355
|
+
[i.id]: n[i.id],
|
|
356
|
+
[i.value]: n[i.value]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
else if (this.isJsonType)
|
|
360
|
+
for (let s = 0; s < this.curDistance.length; s++)
|
|
361
|
+
t.push(this.wheelsData[s].data[this.getIndex(this.curDistance[s])]);
|
|
362
|
+
else
|
|
363
|
+
for (let s = 0; s < this.curDistance.length; s++)
|
|
364
|
+
t.push(this.getInnerText(s));
|
|
365
|
+
return t;
|
|
366
|
+
}
|
|
367
|
+
getValue() {
|
|
368
|
+
return this.getCurValue();
|
|
369
|
+
}
|
|
370
|
+
calcDistance(t) {
|
|
371
|
+
return 2 * this.optionHeight - t * this.optionHeight;
|
|
372
|
+
}
|
|
373
|
+
setCurDistance(t) {
|
|
374
|
+
const e = [];
|
|
375
|
+
for (let i = 0; i < this.sliderList.length; i++)
|
|
376
|
+
e.push(this.calcDistance(t[i])), this.movePosition(this.sliderList[i], e[i]);
|
|
377
|
+
this.curDistance = e;
|
|
378
|
+
}
|
|
379
|
+
fixPosition(t) {
|
|
380
|
+
return -(this.getIndex(t) - 2) * this.optionHeight;
|
|
381
|
+
}
|
|
382
|
+
movePosition(t, e) {
|
|
383
|
+
t.style.transform = "translate3d(0," + e + "px, 0)";
|
|
384
|
+
}
|
|
385
|
+
locatePosition(t, e) {
|
|
386
|
+
t === void 0 || e === void 0 || e < 0 || (this.curDistance[t] = this.calcDistance(e), this.movePosition(this.sliderList[t], this.curDistance[t]), this.isCascade && this.checkRange(t, this.getIndexArr()));
|
|
387
|
+
}
|
|
388
|
+
updateCurDistance(t, e) {
|
|
389
|
+
this.curDistance[e] = parseInt(t.style.transform.split(",")[1]);
|
|
390
|
+
}
|
|
391
|
+
getInnerText(t) {
|
|
392
|
+
var s;
|
|
393
|
+
const e = this.sliderList[t].getElementsByTagName("li").length;
|
|
394
|
+
let i = this.getIndex(this.curDistance[t]);
|
|
395
|
+
return i >= e ? i = e - 1 : i < 0 && (i = 0), ((s = this.sliderList[t].getElementsByTagName("li")[i]) == null ? void 0 : s.textContent) || "";
|
|
396
|
+
}
|
|
397
|
+
touch(t) {
|
|
398
|
+
var o, r, c, a, u, d, f, v;
|
|
399
|
+
const i = (t.composedPath && t.composedPath()).find((m) => {
|
|
400
|
+
var p;
|
|
401
|
+
return (p = m.classList) == null ? void 0 : p.contains("ms-wheel");
|
|
402
|
+
});
|
|
403
|
+
if (!i)
|
|
404
|
+
return;
|
|
405
|
+
const s = i.firstChild, n = parseInt(i.getAttribute("data-index") || "0");
|
|
406
|
+
switch (t.type) {
|
|
407
|
+
case "touchstart":
|
|
408
|
+
case "mousedown":
|
|
409
|
+
s.style.transition = "none 0s ease-out", this.startY = Math.floor(t instanceof TouchEvent ? t.touches[0].clientY : t.clientY), this.preMoveY = this.startY, t.type === "mousedown" && (this.enableClickStatus = !0);
|
|
410
|
+
break;
|
|
411
|
+
case "touchmove":
|
|
412
|
+
case "mousemove":
|
|
413
|
+
if (t.preventDefault(), t.type === "mousemove" && !this.enableClickStatus)
|
|
414
|
+
break;
|
|
415
|
+
this.moveY = Math.floor(t instanceof TouchEvent ? t.touches[0].clientY : t.clientY), this.offsetY = (this.moveY - this.preMoveY) * this.config.scrollSpeed, this.updateCurDistance(s, n), this.curDistance[n] = this.curDistance[n] + this.offsetY, this.movePosition(s, this.curDistance[n]), this.preMoveY = this.moveY;
|
|
416
|
+
break;
|
|
417
|
+
case "touchend":
|
|
418
|
+
case "mouseup":
|
|
419
|
+
if (s.style.transition = "transform 0.18s ease-out", this.moveEndY = Math.floor(t instanceof TouchEvent ? t.changedTouches[0].clientY : t.clientY), this.offsetSum = this.moveEndY - this.startY, this.oversizeBorder = -(s.getElementsByTagName("li").length - 3) * this.optionHeight, this.offsetSum == 0) {
|
|
420
|
+
const m = Math.floor((window.innerHeight - this.moveEndY) / 40);
|
|
421
|
+
if (m != 2) {
|
|
422
|
+
const p = m - 2, C = this.curDistance[n] + p * this.optionHeight;
|
|
423
|
+
C <= 2 * this.optionHeight && C >= this.oversizeBorder && (this.curDistance[n] = C, this.movePosition(s, this.curDistance[n]), (r = (o = this.config).transitionEnd) == null || r.call(o, this.getIndexArr(), this.getCurValue(), this), (a = (c = this.config).onTransitionEnd) == null || a.call(c, this.getCurValue(), this.getIndexArr(), this));
|
|
424
|
+
}
|
|
425
|
+
} else
|
|
426
|
+
this.updateCurDistance(s, n), this.curDistance[n] = this.fixPosition(this.curDistance[n]), this.curDistance[n] > 2 * this.optionHeight ? this.curDistance[n] = 2 * this.optionHeight : this.curDistance[n] < this.oversizeBorder && (this.curDistance[n] = this.oversizeBorder), this.movePosition(s, this.curDistance[n]), (d = (u = this.config).transitionEnd) == null || d.call(u, this.getIndexArr(), this.getCurValue(), this), (v = (f = this.config).onTransitionEnd) == null || v.call(f, this.getCurValue(), this.getIndexArr(), this);
|
|
427
|
+
t.type === "mouseup" && (this.enableClickStatus = !1), this.isCascade && this.checkRange(n, this.getIndexArr());
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
let y = l;
|
|
433
|
+
h(y, "defaultConfig", {
|
|
434
|
+
keyMap: { id: "id", value: "value", childs: "childs" },
|
|
435
|
+
position: [],
|
|
436
|
+
colWidth: [],
|
|
437
|
+
title: "",
|
|
438
|
+
connector: " ",
|
|
439
|
+
ensureBtnText: "\u786E\u8BA4",
|
|
440
|
+
cancelBtnText: "\u53D6\u6D88",
|
|
441
|
+
triggerDisplayValue: !0,
|
|
442
|
+
scrollSpeed: 1
|
|
443
443
|
}), h(y, "REQUIRED_PARAMS", ["trigger", "wheels"]);
|
|
444
444
|
|
|
445
445
|
const ptcMobileSelectCss = ".ms-mobile-select{position:absolute;top:0;right:0;bottom:0;left:0;z-index:0;opacity:0;visibility:hidden;-webkit-transition:opacity 0.4s, z-index 0.4s;transition:opacity 0.4s, z-index 0.4s;transform:translate(0, 0)}.ms-mobile-select *{margin:0;padding:0;-webkit-box-sizing:border-box;box-sizing:border-box}.ms-mobile-select .ms-gray-layer{position:fixed;top:0;left:0;bottom:0;right:0;background:rgba(0, 0, 0, 0.7);z-index:888;display:block}.ms-mobile-select .ms-content{width:100%;display:block;position:fixed;z-index:889;color:black;-webkit-transition:all 0.4s;transition:all 0.4s;bottom:-350px;left:0;background:white}.ms-mobile-select .ms-fix-width{width:90%;margin:0 auto;position:relative}.ms-mobile-select .ms-fix-width:after{content:\".\";display:block;height:0;clear:both;visibility:hidden}.ms-mobile-select .ms-btn-bar{border-bottom:1px solid #dcdcdc;font-size:15px;height:45px;position:relative;text-align:center;line-height:45px}.ms-mobile-select .ms-cancel,.ms-mobile-select .ms-ensure{height:45px;width:55px;cursor:pointer;position:absolute;top:0;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.ms-mobile-select .ms-cancel{left:0;color:#666}.ms-mobile-select .ms-ensure{right:0;color:#1e83d3}.ms-mobile-select .ms-title{font-size:15px;padding:0 15%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.ms-mobile-select .ms-panel:after{content:\".\";display:block;height:0;clear:both;visibility:hidden}.ms-mobile-select .ms-wheels{width:100%;height:200px;overflow:hidden}.ms-mobile-select .ms-wheel{position:relative;z-index:0;float:left;width:50%;height:200px;overflow:hidden;-webkit-transition:width 0.3s ease;transition:width 0.3s ease}.ms-mobile-select .ms-select-container{display:block;text-align:center}.ms-mobile-select .ms-select-container li{font-size:15px;display:block;height:40px;line-height:40px;cursor:pointer;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.ms-mobile-select .ms-select-line{height:40px;width:100%;position:absolute;top:80px;pointer-events:none;-webkit-box-sizing:border-box;box-sizing:border-box;border-top:1px solid #dcdcdc;border-bottom:1px solid #dcdcdc}.ms-mobile-select .ms-shadow-mask{position:absolute;top:0;width:100%;height:200px;background:linear-gradient(to bottom, #fffffff5, #ffffffcc 25%, #ffffff00 49%, #ffffff00 51%, #ffffffcc 75%, #fffffff5);opacity:0.9;pointer-events:none}.ms-mobile-select.ms-show{opacity:1;z-index:10000;visibility:visible}.ms-mobile-select.ms-show .ms-content{bottom:0}.ms-default-trigger{min-height:1em;color:#888}body.ms-show{overflow-y:hidden}h1,h2,h3,h4,h5,h6,p,ul,li,ptc-subnav,ptc-tab-list,ptc-link,ptc-square-card,.hyphenate-text,ptc-footer{word-break:break-word;hyphens:manual;-webkit-hyphens:manual;-moz-hyphens:manual;-ms-hyphens:manual}@supports (hyphenate-limit-chars: 12 3 3){h1,h2,h3,h4,h5,h6,p,ul,li,ptc-subnav,ptc-tab-list,ptc-link,ptc-square-card,.hyphenate-text,ptc-footer{hyphens:auto;-webkit-hyphenate-limit-before:3;-webkit-hyphenate-limit-after:3;hyphenate-limit-chars:12 3 3;hyphenate-limit-lines:2;hyphenate-limit-last:always;hyphenate-limit-zone:6%;-webkit-hyphens:auto;-webkit-hyphenate-limit-before:3;-webkit-hyphenate-limit-after:3;-webkit-hyphenate-limit-chars:12 3 3;-webkit-hyphenate-limit-lines:2;-moz-hyphens:auto;-moz-hyphenate-limit-chars:12 3 3;-moz-hyphenate-limit-lines:2;-ms-hyphens:auto;-ms-hyphenate-limit-chars:12 3 3;-ms-hyphenate-limit-lines:2}}.mobile-select-wrapper{display:block}.mobile-select-wrapper div{display:inline;margin-right:var(--ptc-element-spacing-03);width:100%;font-family:var(--ptc-font-latin);font-weight:var(--ptc-font-weight-bold);font-size:var(--ptc-font-size-x-small);line-height:var(--ptc-line-height-densest);color:var(--color-white);height:18px}.mobileSelect .content{top:auto}.mobileSelect .content .btnBar{border-color:var(--color-gray-10)}.mobileSelect .content .btnBar .cancel,.mobileSelect .content .btnBar .ensure,.mobileSelect .content .btnBar .title{font-family:var(--ptc-font-latin);font-weight:var(--ptc-font-weight-semibold);font-size:var(--ptc-font-size-x-small);line-height:var(--ptc-line-height-densest)}.mobileSelect .content .btnBar .ensure,.mobileSelect .content .btnBar .cancel{transform:translateY(12.5px);width:125px}.mobileSelect .content .panel .wheel .selectContainer li{font-family:var(--ptc-font-latin);font-weight:var(--ptc-font-weight-semibold);font-size:var(--ptc-font-size-x-small);line-height:var(--ptc-line-height-densest);height:45px}ptc-responsive-wrapper.xsmall .mobile-select-wrapper,ptc-responsive-wrapper.small .mobile-select-wrapper{display:block}ptc-responsive-wrapper.medium .mobile-select-wrapper,ptc-responsive-wrapper.large .mobile-select-wrapper,ptc-responsive-wrapper.xlarge .mobile-select-wrapper,ptc-responsive-wrapper.xxlarge .mobile-select-wrapper,ptc-responsive-wrapper.large2k .mobile-select-wrapper,ptc-responsive-wrapper.large4k .mobile-select-wrapper{display:none}.ms-mobile-select.ms-show .ms-cancel,.ms-mobile-select.ms-show .ms-ensure{width:auto}";
|