@monoui/vuejs 1.1.12 → 1.1.16
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoui/vuejs",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.16",
|
|
4
4
|
"description": "This project will contain MonoFor UI Framework",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"repository": "git@gitlab.com:monoui/vuejs.git",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"vee-validate": "^3.0.11",
|
|
34
34
|
"vue": "^2.6.12",
|
|
35
35
|
"vue-cron-2": "^1.0.7",
|
|
36
|
+
"vue-js-toggle-button": "^1.3.3",
|
|
36
37
|
"vue-multiselect": "^2.1.6",
|
|
37
38
|
"vue-server-renderer": "^2.6.12",
|
|
38
39
|
"vue-sweetalert": "^0.1.18",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
</slot>
|
|
80
80
|
</tr>
|
|
81
81
|
<template v-if="filterable">
|
|
82
|
-
<tr
|
|
82
|
+
<tr>
|
|
83
83
|
<th
|
|
84
84
|
class="p-0 p-t-1 p-b-1"
|
|
85
85
|
:colspan="Object.keys(columns).length"
|
|
@@ -187,52 +187,66 @@
|
|
|
187
187
|
<slot name="pagination">
|
|
188
188
|
<div class="d-flex justify-content-between align-items-center mt-2">
|
|
189
189
|
<slot name="pagination-filters">
|
|
190
|
-
<div
|
|
191
|
-
<
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
<template v-for="perPage in filteredPerPageValues">
|
|
199
|
-
<b-dropdown-item
|
|
200
|
-
:key="'per-page-' + perPage"
|
|
201
|
-
@click="changeItemPerPage(perPage)"
|
|
202
|
-
>
|
|
203
|
-
{{ perPage }}
|
|
204
|
-
</b-dropdown-item>
|
|
205
|
-
</template>
|
|
206
|
-
<b-dropdown-divider
|
|
207
|
-
v-if="
|
|
208
|
-
filteredPerPageValues &&
|
|
209
|
-
filteredPerPageValues.length
|
|
210
|
-
"
|
|
211
|
-
></b-dropdown-divider>
|
|
212
|
-
<b-dropdown-item
|
|
213
|
-
@click="
|
|
214
|
-
changeItemPerPage(settings.totalItemCount)
|
|
215
|
-
"
|
|
190
|
+
<div>
|
|
191
|
+
<div v-show="!isDataEmpty">
|
|
192
|
+
<span>Show</span>
|
|
193
|
+
<b-dropdown
|
|
194
|
+
:text="itemPerPageText"
|
|
195
|
+
class="m-md-2"
|
|
196
|
+
size="sm"
|
|
197
|
+
variant="light"
|
|
216
198
|
>
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
199
|
+
<template
|
|
200
|
+
v-for="perPage in filteredPerPageValues"
|
|
201
|
+
>
|
|
202
|
+
<b-dropdown-item
|
|
203
|
+
:key="'per-page-' + perPage"
|
|
204
|
+
@click="changeItemPerPage(perPage)"
|
|
205
|
+
>
|
|
206
|
+
{{ perPage }}
|
|
207
|
+
</b-dropdown-item>
|
|
208
|
+
</template>
|
|
209
|
+
<b-dropdown-divider
|
|
210
|
+
v-if="
|
|
211
|
+
filteredPerPageValues &&
|
|
212
|
+
filteredPerPageValues.length &&
|
|
213
|
+
inLimit()
|
|
214
|
+
"
|
|
215
|
+
/>
|
|
216
|
+
<template>
|
|
217
|
+
<b-dropdown-item
|
|
218
|
+
v-if="inLimit()"
|
|
219
|
+
@click="
|
|
220
|
+
changeItemPerPage(
|
|
221
|
+
settings.totalItemCount
|
|
222
|
+
)
|
|
223
|
+
"
|
|
224
|
+
>
|
|
225
|
+
All ({{ settings.totalItemCount }})
|
|
226
|
+
</b-dropdown-item>
|
|
227
|
+
</template>
|
|
228
|
+
</b-dropdown>
|
|
229
|
+
</div>
|
|
220
230
|
</div>
|
|
221
231
|
</slot>
|
|
222
232
|
<slot name="pagination-center" v-bind="settings">
|
|
223
|
-
<
|
|
224
|
-
|
|
225
|
-
|
|
233
|
+
<div>
|
|
234
|
+
<span v-show="!isDataEmpty">
|
|
235
|
+
{{ settings.totalItemCount }} rows
|
|
236
|
+
</span>
|
|
237
|
+
</div>
|
|
226
238
|
</slot>
|
|
227
239
|
<slot name="pagination-buttons">
|
|
228
|
-
<
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
240
|
+
<div>
|
|
241
|
+
<b-pagination
|
|
242
|
+
v-if="settings.pageCount > 1"
|
|
243
|
+
v-model="settings.currentPage"
|
|
244
|
+
:total-rows="settings.totalItemCount"
|
|
245
|
+
:per-page="settings.itemPerPage"
|
|
246
|
+
@change="changePage"
|
|
247
|
+
v-bind="pagination"
|
|
248
|
+
/>
|
|
249
|
+
</div>
|
|
236
250
|
</slot>
|
|
237
251
|
</div>
|
|
238
252
|
</slot>
|
|
@@ -264,6 +278,23 @@ export default {
|
|
|
264
278
|
IconSortingArrows
|
|
265
279
|
},
|
|
266
280
|
props: {
|
|
281
|
+
history: {
|
|
282
|
+
type: Boolean,
|
|
283
|
+
required: false,
|
|
284
|
+
default: false
|
|
285
|
+
},
|
|
286
|
+
/// <summary>
|
|
287
|
+
/// Keep the table navigation history on options: 'query', 'cookie', 'session', 'local', 'hash'.
|
|
288
|
+
/// </summary>
|
|
289
|
+
historyStorage: {
|
|
290
|
+
type: String,
|
|
291
|
+
required: false,
|
|
292
|
+
default: "query"
|
|
293
|
+
},
|
|
294
|
+
historyName: {
|
|
295
|
+
type: String,
|
|
296
|
+
default: ""
|
|
297
|
+
},
|
|
267
298
|
columns: {
|
|
268
299
|
type: Object,
|
|
269
300
|
required: false
|
|
@@ -282,8 +313,9 @@ export default {
|
|
|
282
313
|
required: false
|
|
283
314
|
},
|
|
284
315
|
filterable: {
|
|
285
|
-
type:
|
|
286
|
-
required: false
|
|
316
|
+
type: Boolean,
|
|
317
|
+
required: false,
|
|
318
|
+
default: false
|
|
287
319
|
},
|
|
288
320
|
headerClass: {
|
|
289
321
|
type: String,
|
|
@@ -320,7 +352,7 @@ export default {
|
|
|
320
352
|
emptyMessage: {
|
|
321
353
|
type: String,
|
|
322
354
|
required: false,
|
|
323
|
-
default: "No data
|
|
355
|
+
default: "No data available in table"
|
|
324
356
|
},
|
|
325
357
|
autoLoad: {
|
|
326
358
|
type: Boolean,
|
|
@@ -361,6 +393,21 @@ export default {
|
|
|
361
393
|
type: String,
|
|
362
394
|
required: false,
|
|
363
395
|
default: "icon-arrow-down-long"
|
|
396
|
+
},
|
|
397
|
+
searchColumn: {
|
|
398
|
+
type: String,
|
|
399
|
+
required: false,
|
|
400
|
+
default: ""
|
|
401
|
+
},
|
|
402
|
+
searchWordMinLength: {
|
|
403
|
+
type: Number,
|
|
404
|
+
required: false,
|
|
405
|
+
default: 2
|
|
406
|
+
},
|
|
407
|
+
searchDebounce: {
|
|
408
|
+
type: Number,
|
|
409
|
+
required: false,
|
|
410
|
+
default: 300
|
|
364
411
|
}
|
|
365
412
|
},
|
|
366
413
|
watch: {
|
|
@@ -379,7 +426,9 @@ export default {
|
|
|
379
426
|
tableData: [],
|
|
380
427
|
searchWord: null,
|
|
381
428
|
isDataEmpty: false,
|
|
382
|
-
isLoading: false
|
|
429
|
+
isLoading: false,
|
|
430
|
+
limit: 250,
|
|
431
|
+
searchDebounceTimeout: null
|
|
383
432
|
};
|
|
384
433
|
},
|
|
385
434
|
computed: {
|
|
@@ -403,6 +452,22 @@ export default {
|
|
|
403
452
|
}
|
|
404
453
|
},
|
|
405
454
|
async mounted() {
|
|
455
|
+
this.settings.currentPage = this.getHistoryParameter(
|
|
456
|
+
"page",
|
|
457
|
+
this.settings.currentPage
|
|
458
|
+
);
|
|
459
|
+
this.settings.itemPerPage = this.getHistoryParameter(
|
|
460
|
+
"limit",
|
|
461
|
+
this.settings.itemPerPage
|
|
462
|
+
);
|
|
463
|
+
if (this.searchColumn) {
|
|
464
|
+
this.searchWord = this.getHistoryParameter(
|
|
465
|
+
`f-${this.searchColumn}`,
|
|
466
|
+
this.searchWord
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
this.loadHistoryFilters();
|
|
470
|
+
this.loadHistorySorting();
|
|
406
471
|
if (this.autoLoad) await this.getValues();
|
|
407
472
|
},
|
|
408
473
|
created() {},
|
|
@@ -428,9 +493,8 @@ export default {
|
|
|
428
493
|
return this.sorting.some(x => x.Column === column);
|
|
429
494
|
},
|
|
430
495
|
async toggleSort(column) {
|
|
431
|
-
if (!this.isSortable(column))
|
|
432
|
-
|
|
433
|
-
}
|
|
496
|
+
if (!this.isSortable(column)) return;
|
|
497
|
+
|
|
434
498
|
let currentSort = this.sorting.find(x => x.Column === column);
|
|
435
499
|
if (!currentSort) {
|
|
436
500
|
currentSort = { Column: column, Asc: true };
|
|
@@ -463,6 +527,16 @@ export default {
|
|
|
463
527
|
this.$emit("loading", this.isLoading);
|
|
464
528
|
const { currentPage, itemPerPage } = this.settings;
|
|
465
529
|
|
|
530
|
+
this.clearHistoryParameters("f-");
|
|
531
|
+
for (const filter of this.filters) {
|
|
532
|
+
this.addHistoryParameter(`f-${filter.Column}`, filter.Value);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
this.clearHistoryParameters("s-");
|
|
536
|
+
for (const sort of this.sorting) {
|
|
537
|
+
this.addHistoryParameter(`s-${sort.Column}`, sort.Asc ? 1 : 0);
|
|
538
|
+
}
|
|
539
|
+
|
|
466
540
|
let result = await this.requestFunction(
|
|
467
541
|
this.filters,
|
|
468
542
|
this.sorting,
|
|
@@ -505,16 +579,22 @@ export default {
|
|
|
505
579
|
) {
|
|
506
580
|
this.settings.pageCount = 1;
|
|
507
581
|
}
|
|
582
|
+
if (this.settings.currentPage > this.settings.pageCount) {
|
|
583
|
+
this.settings.currentPage = this.settings.pageCount;
|
|
584
|
+
this.changePage(this.settings.currentPage);
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
508
587
|
this.isLoading = false;
|
|
509
588
|
this.$emit("loading", this.isLoading);
|
|
510
589
|
},
|
|
511
590
|
changePage(page) {
|
|
512
591
|
this.settings.currentPage = page;
|
|
513
|
-
|
|
592
|
+
this.addHistoryParameter("page", page);
|
|
514
593
|
this.getValues();
|
|
515
594
|
},
|
|
516
595
|
changeItemPerPage(value) {
|
|
517
596
|
this.settings.itemPerPage = value;
|
|
597
|
+
this.addHistoryParameter("limit", value);
|
|
518
598
|
this.getValues();
|
|
519
599
|
},
|
|
520
600
|
isLessThanTotalItemCount(val) {
|
|
@@ -525,12 +605,359 @@ export default {
|
|
|
525
605
|
this.getValues();
|
|
526
606
|
},
|
|
527
607
|
addFilter(word) {
|
|
528
|
-
if (!
|
|
608
|
+
if (!this.searchColumn) return;
|
|
609
|
+
clearTimeout(this.searchDebounceTimeout);
|
|
610
|
+
this.searchDebounceTimeout = setTimeout(
|
|
611
|
+
() =>
|
|
612
|
+
this.searchColumnValue(
|
|
613
|
+
this.searchColumn,
|
|
614
|
+
word,
|
|
615
|
+
this.searchWordMinLength
|
|
616
|
+
),
|
|
617
|
+
this.searchDebounce
|
|
618
|
+
);
|
|
619
|
+
},
|
|
620
|
+
searchColumnValue(column, value, limit = -1) {
|
|
621
|
+
let filter = this.filters.find(x => x.Column === column);
|
|
622
|
+
|
|
623
|
+
if (filter && (!value || value.length < limit)) {
|
|
624
|
+
this.filters.splice(this.filters.indexOf(filter), 1);
|
|
529
625
|
this.getValues();
|
|
530
626
|
return;
|
|
531
627
|
}
|
|
532
628
|
|
|
629
|
+
if (filter) filter.Value = value;
|
|
630
|
+
else
|
|
631
|
+
this.filters.push({
|
|
632
|
+
Column: column,
|
|
633
|
+
Value: value
|
|
634
|
+
});
|
|
533
635
|
this.getValues();
|
|
636
|
+
},
|
|
637
|
+
inLimit() {
|
|
638
|
+
return this.settings.totalItemCount <= this.limit;
|
|
639
|
+
},
|
|
640
|
+
getHistoryName(name, seperator = "-") {
|
|
641
|
+
if (!name) name = "";
|
|
642
|
+
if (!this.historyName) return name;
|
|
643
|
+
return `${this.historyName}${seperator}${name}`;
|
|
644
|
+
},
|
|
645
|
+
clearHistoryParameters(
|
|
646
|
+
startsWith = null,
|
|
647
|
+
storage = this.historyStorage
|
|
648
|
+
) {
|
|
649
|
+
if (!startsWith || !storage) return;
|
|
650
|
+
|
|
651
|
+
try {
|
|
652
|
+
const startsWithName = this.getHistoryName(startsWith);
|
|
653
|
+
|
|
654
|
+
if (storage === "query") {
|
|
655
|
+
const url = new URL(window.location);
|
|
656
|
+
for (const searchParam of url.searchParams) {
|
|
657
|
+
if (searchParam[0].startsWith(startsWithName)) {
|
|
658
|
+
url.searchParams.delete(searchParam[0]);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
window.history.pushState({}, "", url);
|
|
662
|
+
return;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
if (storage === "local") {
|
|
666
|
+
const keys = Object.keys(localStorage);
|
|
667
|
+
for (const key of keys) {
|
|
668
|
+
if (!key.startsWith(startsWithName)) continue;
|
|
669
|
+
localStorage.removeItem(key);
|
|
670
|
+
}
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (storage === "session") {
|
|
675
|
+
const keys = Object.keys(sessionStorage);
|
|
676
|
+
for (const key of keys) {
|
|
677
|
+
if (!key.startsWith(startsWithName)) continue;
|
|
678
|
+
sessionStorage.removeItem(key);
|
|
679
|
+
}
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
if (storage === "cookie") {
|
|
684
|
+
var pairs = document.cookie.split(";");
|
|
685
|
+
var cookies = {};
|
|
686
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
687
|
+
var pair = pairs[i].split("=");
|
|
688
|
+
cookies[(pair[0] + "").trim()] = unescape(
|
|
689
|
+
pair.slice(1).join("=")
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
const keys = Object.keys(cookies);
|
|
693
|
+
for (const key of keys) {
|
|
694
|
+
if (!key.startsWith(startsWithName)) continue;
|
|
695
|
+
document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
|
|
696
|
+
}
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (storage === "hash") {
|
|
701
|
+
if (!window.location.hash) return;
|
|
702
|
+
const hash = window.location.hash.substr(1);
|
|
703
|
+
hash.split("&").reduce(function(_, item) {
|
|
704
|
+
var parts = item.split("=");
|
|
705
|
+
if (!parts[0].startsWith(startsWithName)) return;
|
|
706
|
+
window.location.hash = window.location.hash.replace(
|
|
707
|
+
`${item}`,
|
|
708
|
+
""
|
|
709
|
+
);
|
|
710
|
+
}, {});
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
} catch (error) {
|
|
714
|
+
console.error(error);
|
|
715
|
+
}
|
|
716
|
+
},
|
|
717
|
+
getHistoryParameters(startsWith = null, storage = this.historyStorage) {
|
|
718
|
+
if (!storage) return;
|
|
719
|
+
|
|
720
|
+
try {
|
|
721
|
+
const startsWithName = this.getHistoryName(startsWith);
|
|
722
|
+
let returnParameters = {};
|
|
723
|
+
|
|
724
|
+
if (storage === "query") {
|
|
725
|
+
const url = new URL(window.location);
|
|
726
|
+
for (const searchParam of url.searchParams) {
|
|
727
|
+
if (!searchParam[0].startsWith(startsWithName))
|
|
728
|
+
continue;
|
|
729
|
+
returnParameters[searchParam[0]] = searchParam[1];
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
if (storage === "local") {
|
|
734
|
+
const keys = Object.keys(localStorage);
|
|
735
|
+
for (const key of keys) {
|
|
736
|
+
if (!key.startsWith(startsWithName)) continue;
|
|
737
|
+
returnParameters[key] = localStorage.getItem(key);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (storage === "session") {
|
|
742
|
+
const keys = Object.keys(sessionStorage);
|
|
743
|
+
for (const key of keys) {
|
|
744
|
+
if (!key.startsWith(startsWithName)) continue;
|
|
745
|
+
returnParameters[key] = sessionStorage.getItem(key);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
if (storage === "cookie") {
|
|
750
|
+
var pairs = document.cookie.split(";");
|
|
751
|
+
var cookies = {};
|
|
752
|
+
for (var i = 0; i < pairs.length; i++) {
|
|
753
|
+
var pair = pairs[i].split("=");
|
|
754
|
+
cookies[(pair[0] + "").trim()] = unescape(
|
|
755
|
+
pair.slice(1).join("=")
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
const keys = Object.keys(cookies);
|
|
759
|
+
for (const key of keys) {
|
|
760
|
+
if (startsWithName && !key.startsWith(startsWithName))
|
|
761
|
+
continue;
|
|
762
|
+
returnParameters[key] = cookies[key];
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
if (storage === "hash") {
|
|
767
|
+
if (window.location.hash) {
|
|
768
|
+
const hash = window.location.hash.substr(1);
|
|
769
|
+
hash.split("&").reduce(function(_, item) {
|
|
770
|
+
var parts = item.split("=");
|
|
771
|
+
if (
|
|
772
|
+
startsWithName &&
|
|
773
|
+
!parts[0].startsWith(startsWithName)
|
|
774
|
+
)
|
|
775
|
+
return;
|
|
776
|
+
returnParameters[parts[0]] = parts[1];
|
|
777
|
+
}, {});
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
return returnParameters;
|
|
782
|
+
} catch (error) {
|
|
783
|
+
console.error(error);
|
|
784
|
+
}
|
|
785
|
+
},
|
|
786
|
+
loadHistoryFilters() {
|
|
787
|
+
const parameters = this.getHistoryParameters("f-");
|
|
788
|
+
const trimName = this.getHistoryName("f-");
|
|
789
|
+
const names = Object.keys(parameters);
|
|
790
|
+
for (const paramName of names) {
|
|
791
|
+
const value = parameters[paramName];
|
|
792
|
+
const column = paramName.replace(trimName, "");
|
|
793
|
+
|
|
794
|
+
let filter = this.filters.find(x => x.Column === column);
|
|
795
|
+
|
|
796
|
+
if (filter && !value) {
|
|
797
|
+
this.filters.splice(this.filters.indexOf(filter), 1);
|
|
798
|
+
} else if (filter) {
|
|
799
|
+
filter.Value = value;
|
|
800
|
+
} else {
|
|
801
|
+
this.filters.push({
|
|
802
|
+
Column: column,
|
|
803
|
+
Value: value
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
},
|
|
808
|
+
loadHistorySorting() {
|
|
809
|
+
const parameters = this.getHistoryParameters("s-");
|
|
810
|
+
const trimName = this.getHistoryName("s-");
|
|
811
|
+
const names = Object.keys(parameters);
|
|
812
|
+
for (const paramName of names) {
|
|
813
|
+
const value = parameters[paramName] ? true : false;
|
|
814
|
+
const column = paramName.replace(trimName, "");
|
|
815
|
+
|
|
816
|
+
let sort = this.sorting.find(x => x.Column === column);
|
|
817
|
+
|
|
818
|
+
if (sort) {
|
|
819
|
+
sort.Value = value;
|
|
820
|
+
} else {
|
|
821
|
+
this.sorting.push({ Column: column, Asc: value });
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
addHistoryParameter(name, value, storage = this.historyStorage) {
|
|
826
|
+
if (!this.history || !name || !storage) return;
|
|
827
|
+
|
|
828
|
+
try {
|
|
829
|
+
if (storage === "query") {
|
|
830
|
+
const url = new URL(window.location);
|
|
831
|
+
const historyName = this.getHistoryName(name);
|
|
832
|
+
url.searchParams.set(historyName, value);
|
|
833
|
+
window.history.pushState({}, "", url);
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
if (storage === "local") {
|
|
838
|
+
const historyName = this.getHistoryName(name);
|
|
839
|
+
localStorage.setItem(historyName, value);
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
if (storage === "session") {
|
|
844
|
+
const historyName = this.getHistoryName(name);
|
|
845
|
+
sessionStorage.setItem(historyName, value);
|
|
846
|
+
return;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
if (storage === "cookie") {
|
|
850
|
+
const historyName = this.getHistoryName(name);
|
|
851
|
+
document.cookie = `${historyName}=${value}`;
|
|
852
|
+
return;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
if (storage === "hash") {
|
|
856
|
+
const historyName = this.getHistoryName(name);
|
|
857
|
+
const curretParameters = this.getHistoryParameters();
|
|
858
|
+
const newParameters = {
|
|
859
|
+
...curretParameters,
|
|
860
|
+
[historyName]: value
|
|
861
|
+
};
|
|
862
|
+
const newHash = Object.keys(newParameters)
|
|
863
|
+
.map(key => `${key}=${newParameters[key]}`)
|
|
864
|
+
.join("&");
|
|
865
|
+
window.location.hash = newHash;
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
868
|
+
} catch (error) {
|
|
869
|
+
console.error(error);
|
|
870
|
+
}
|
|
871
|
+
},
|
|
872
|
+
getHistoryParameter(
|
|
873
|
+
name,
|
|
874
|
+
defaultValue = null,
|
|
875
|
+
storage = this.historyStorage
|
|
876
|
+
) {
|
|
877
|
+
if (!this.history || !name || !storage) return defaultValue;
|
|
878
|
+
|
|
879
|
+
try {
|
|
880
|
+
if (storage === "query") {
|
|
881
|
+
const url = new URL(window.location);
|
|
882
|
+
const historyName = this.getHistoryName(name);
|
|
883
|
+
return url.searchParams.get(historyName) || defaultValue;
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
if (storage === "local") {
|
|
887
|
+
const historyName = this.getHistoryName(name);
|
|
888
|
+
return localStorage.getItem(historyName) || defaultValue;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
if (storage === "session") {
|
|
892
|
+
const historyName = this.getHistoryName(name);
|
|
893
|
+
return sessionStorage.getItem(historyName) || defaultValue;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
if (storage === "cookie") {
|
|
897
|
+
const historyName = this.getHistoryName(name);
|
|
898
|
+
const cookie = document.cookie
|
|
899
|
+
.split(";")
|
|
900
|
+
.find(c => c.trim().startsWith(`${historyName}=`));
|
|
901
|
+
if (!cookie) return defaultValue;
|
|
902
|
+
return cookie.split("=")[1] || defaultValue;
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
if (storage === "hash") {
|
|
906
|
+
const historyName = this.getHistoryName(name);
|
|
907
|
+
const hash = window.location.hash
|
|
908
|
+
.split("#")
|
|
909
|
+
.find(c => c.trim().startsWith(`${historyName}=`));
|
|
910
|
+
if (!hash) return defaultValue;
|
|
911
|
+
return hash.split("=")[1] || defaultValue;
|
|
912
|
+
}
|
|
913
|
+
} catch (error) {
|
|
914
|
+
console.error(error);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
return defaultValue;
|
|
918
|
+
},
|
|
919
|
+
removeHistoryParameter(name, storage = this.historyStorage) {
|
|
920
|
+
if (!this.history || !name || !storage) return;
|
|
921
|
+
|
|
922
|
+
try {
|
|
923
|
+
const historyName = this.getHistoryName(name);
|
|
924
|
+
if (storage === "query") {
|
|
925
|
+
const url = new URL(window.location);
|
|
926
|
+
url.searchParams.delete(historyName);
|
|
927
|
+
window.history.pushState({}, "", url);
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
if (storage === "local") {
|
|
932
|
+
localStorage.removeItem(historyName);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
if (storage === "session") {
|
|
937
|
+
sessionStorage.removeItem(historyName);
|
|
938
|
+
return;
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
if (storage === "cookie") {
|
|
942
|
+
document.cookie = `${historyName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
if (storage === "hash") {
|
|
947
|
+
if (!window.location.hash) return;
|
|
948
|
+
const hash = window.location.hash.substr(1);
|
|
949
|
+
hash.split("&").reduce(function(_, item) {
|
|
950
|
+
var parts = item.split("=");
|
|
951
|
+
if (!parts[0].startsWith(historyName)) return;
|
|
952
|
+
window.location.hash = window.location.hash.replace(
|
|
953
|
+
`${item}`,
|
|
954
|
+
""
|
|
955
|
+
);
|
|
956
|
+
}, {});
|
|
957
|
+
}
|
|
958
|
+
} catch (error) {
|
|
959
|
+
console.error(error);
|
|
960
|
+
}
|
|
534
961
|
}
|
|
535
962
|
}
|
|
536
963
|
};
|