@radiantabyss/vue 3.0.7
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/babel.config.js +5 -0
- package/package.json +28 -0
- package/src/Alert.js +35 -0
- package/src/Bootstrap.js +42 -0
- package/src/Components.js +44 -0
- package/src/Confirm.js +8 -0
- package/src/Directives.js +20 -0
- package/src/Mixins.js +16 -0
- package/src/Modals.js +19 -0
- package/src/Request.js +210 -0
- package/src/Routing/Actions.js +47 -0
- package/src/Routing/Middleware.js +41 -0
- package/src/Routing/Route.js +75 -0
- package/src/Routing/RouteCrud.js +15 -0
- package/src/Routing/RouteFiles.js +1 -0
- package/src/Routing/Router.js +83 -0
- package/src/Store.js +54 -0
- package/src/Support/Cookie.js +28 -0
- package/src/Support/Gate.js +47 -0
- package/src/Support/Helpers.js +36 -0
- package/src/Support/Item.js +63 -0
- package/src/Support/Items.js +363 -0
- package/src/Support/ReactiveStorage.js +30 -0
- package/src/Support/Str.js +209 -0
- package/src/Validation/Response.js +16 -0
- package/src/Validation/Validator.js +27 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createRouter, createWebHistory } from 'vue-router';
|
|
2
|
+
import Str from './../Support/Str';
|
|
3
|
+
import Actions from './Actions';
|
|
4
|
+
import Middleware from './Middleware';
|
|
5
|
+
import RouteFiles from './RouteFiles';
|
|
6
|
+
import Route from './Route';
|
|
7
|
+
import RouteCrud from './RouteCrud';
|
|
8
|
+
|
|
9
|
+
window.RouteFiles = RouteFiles;
|
|
10
|
+
window.Route = Route;
|
|
11
|
+
window.RouteCrud = RouteCrud;
|
|
12
|
+
|
|
13
|
+
//load route files
|
|
14
|
+
let context = import.meta.glob('/src/Routes/**/*.js');
|
|
15
|
+
|
|
16
|
+
const loadModules = async () => {
|
|
17
|
+
window.Actions = await Actions();
|
|
18
|
+
const files = Object.keys(context);
|
|
19
|
+
|
|
20
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
21
|
+
let file = files[i].replace('/src/Routes/', '').replace(/\.js$/, '');
|
|
22
|
+
window.__route_file = file;
|
|
23
|
+
|
|
24
|
+
if ( !RouteFiles[__route_file] ) {
|
|
25
|
+
RouteFiles[__route_file] = [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
await context[files[i]]();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default async () => {
|
|
33
|
+
let runMiddleware = await Middleware();
|
|
34
|
+
|
|
35
|
+
await loadModules();
|
|
36
|
+
|
|
37
|
+
//create router
|
|
38
|
+
const Router = createRouter({
|
|
39
|
+
history: createWebHistory(),
|
|
40
|
+
routes: [],
|
|
41
|
+
duplicateNavigationPolicy: 'reload',
|
|
42
|
+
scrollBehavior(to, from, scroll) {
|
|
43
|
+
if ( (to.meta.settings && to.meta.settings.disable_scroll)
|
|
44
|
+
|| (from.name == to.name && (!to.meta.settings || !to.meta.settings.force_scroll)) ) {
|
|
45
|
+
return scroll;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
//run middleware
|
|
56
|
+
Router.beforeEach(async (to, from, next) => {
|
|
57
|
+
try {
|
|
58
|
+
await runMiddleware(to, from);
|
|
59
|
+
next();
|
|
60
|
+
}
|
|
61
|
+
catch(redirect) {
|
|
62
|
+
if ( redirect === false || to.path == redirect ) {
|
|
63
|
+
return next();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
next({path: redirect});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
Router.afterEach((to, from) => {
|
|
71
|
+
//save previous route
|
|
72
|
+
localStorage.setItem('_previous_route', from.fullPath != '/' ? from.fullPath : '');
|
|
73
|
+
|
|
74
|
+
//change document title
|
|
75
|
+
let title = to.name.replace(/\//g, ' / ').replace(/Action$/, '');
|
|
76
|
+
if ( to.meta.settings.title ) {
|
|
77
|
+
title = to.meta.settings.title;
|
|
78
|
+
}
|
|
79
|
+
document.title = `${title} :: ${import.meta.env.VITE_NAME}`;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return { Router, RouteFiles };
|
|
83
|
+
};
|
package/src/Store.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createStore } from 'vuex';
|
|
2
|
+
|
|
3
|
+
const Modules = {};
|
|
4
|
+
let context = import.meta.glob('/src/Store/**/*.js');
|
|
5
|
+
|
|
6
|
+
const loadModules = async () => {
|
|
7
|
+
const files = Object.keys(context);
|
|
8
|
+
|
|
9
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
10
|
+
let split = files[i].split('/');
|
|
11
|
+
split.shift();
|
|
12
|
+
split.shift();
|
|
13
|
+
split.shift();
|
|
14
|
+
|
|
15
|
+
let name = split[split.length - 1].replace('.js', '');
|
|
16
|
+
split.pop();
|
|
17
|
+
|
|
18
|
+
let module = await context[files[i]]();
|
|
19
|
+
setNamespace(Modules, name, split, module);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function setNamespace(Modules, name, namespace, module) {
|
|
24
|
+
if ( !namespace.length ) {
|
|
25
|
+
Modules[name] = module.default;
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let first = namespace[0].replace(/-/g, ' ').replace(/_/g, ' ').replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,function(s) {
|
|
30
|
+
return s.toUpperCase();
|
|
31
|
+
}).replace(/ /g, '');
|
|
32
|
+
|
|
33
|
+
namespace.shift();
|
|
34
|
+
|
|
35
|
+
if ( !Modules[first] ) {
|
|
36
|
+
Modules[first] = {
|
|
37
|
+
namespaced: true,
|
|
38
|
+
modules: {},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setNamespace(Modules[first].modules, name, namespace, module);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default async (app) => {
|
|
46
|
+
await loadModules();
|
|
47
|
+
|
|
48
|
+
const Store = createStore({
|
|
49
|
+
modules: Modules,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
window.Store = Store;
|
|
53
|
+
app.use(Store);
|
|
54
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
get(key) {
|
|
3
|
+
key = key + "=";
|
|
4
|
+
var ca = document.cookie.split(';');
|
|
5
|
+
for(var i=0;i < ca.length;i++) {
|
|
6
|
+
var c = ca[i];
|
|
7
|
+
while (c.charAt(0)==' ') c = c.substring(1,c.length);
|
|
8
|
+
if (c.indexOf(key) == 0) return c.substring(key.length,c.length);
|
|
9
|
+
}
|
|
10
|
+
return null;
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
set(key, value, duration = 1) {
|
|
14
|
+
var expires = "";
|
|
15
|
+
if ( duration ) {
|
|
16
|
+
var date = new Date();
|
|
17
|
+
date.setTime(date.getTime() + (duration*24*60*60*1000));
|
|
18
|
+
expires = "; expires=" + date.toUTCString();
|
|
19
|
+
}
|
|
20
|
+
document.cookie = key + "=" + (value || "") + expires + "; path=/;domain="+window.location.host.replace(':8080', '');
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
delete(key) {
|
|
24
|
+
self.set(key, null, -1);
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default self;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
gates: {},
|
|
3
|
+
|
|
4
|
+
allows(gate, param = null) {
|
|
5
|
+
self.check(gate);
|
|
6
|
+
return self.gates[gate](param);
|
|
7
|
+
},
|
|
8
|
+
|
|
9
|
+
denies(gate, param = null) {
|
|
10
|
+
self.check(gate);
|
|
11
|
+
return !self.gates[gate](param);
|
|
12
|
+
},
|
|
13
|
+
|
|
14
|
+
any(gates, param = null) {
|
|
15
|
+
for ( let gate of gates ) {
|
|
16
|
+
self.check(gate);
|
|
17
|
+
if ( self.gates[gate](param) ) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return false;
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
none(gates, param = null) {
|
|
26
|
+
for ( let gate of gates ) {
|
|
27
|
+
self.check(gate);
|
|
28
|
+
if ( self.gates[gate](param) ) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return true;
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
define(name, gate) {
|
|
37
|
+
self.gates[name] = gate;
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
check(gate) {
|
|
41
|
+
if ( typeof self.gates[gate] !== 'function' ) {
|
|
42
|
+
throw `Gate ${gate} does not exist.`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default self;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
dmp(text) {
|
|
3
|
+
// eslint-disable-next-line
|
|
4
|
+
console.log(text);
|
|
5
|
+
},
|
|
6
|
+
|
|
7
|
+
handleEmpty(items) {
|
|
8
|
+
if ( items === false ) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if ( items === null ) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if ( Array.isArray(items) && !items.length ) {
|
|
17
|
+
return [];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if ( !Array.isArray(items) && !Object.keys(items).length ) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
array_unique(arr) {
|
|
28
|
+
return [...new Set(arr)];
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for ( let helper in self ) {
|
|
33
|
+
window[helper] = self[helper];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default self;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
let self = {
|
|
2
|
+
patch(item, data) {
|
|
3
|
+
return self.setKeys(item, Object.keys(data), Object.values(data));
|
|
4
|
+
},
|
|
5
|
+
|
|
6
|
+
setKey(item, key, value) {
|
|
7
|
+
return self.setKeys(item, key, value);
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
setKeys(item, keys, values) {
|
|
11
|
+
let not_empty = window.handleEmpty(item);
|
|
12
|
+
if ( not_empty !== true ) {
|
|
13
|
+
item = {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
17
|
+
let array_values = [];
|
|
18
|
+
for ( let key of keys ) {
|
|
19
|
+
array_values.push(values);
|
|
20
|
+
}
|
|
21
|
+
values = array_values;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if ( !Array.isArray(keys) ) {
|
|
25
|
+
keys = [keys];
|
|
26
|
+
values = [values];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for ( let i = 0; i < keys.length; i++ ) {
|
|
30
|
+
item[keys[i]] = values[i];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {...item};
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
removeEmptyKeys(item) {
|
|
37
|
+
let new_item = Array.isArray(item) ? [] : {};
|
|
38
|
+
let count = Array.isArray(item) ? item.length : Object.keys(item).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(item) ? i : Object.keys(item)[i];
|
|
41
|
+
|
|
42
|
+
if ( item[index] !== '' ) {
|
|
43
|
+
new_item[index] = item[index];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return new_item;
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
deleteKeys(item, keys) {
|
|
51
|
+
for ( let key of keys ) {
|
|
52
|
+
delete item[key];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {...item};
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
deleteKey(item, key) {
|
|
59
|
+
return self.deleteKeys(item, [key]);
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default self;
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
const self = {
|
|
2
|
+
pluck(items, key = 'id') {
|
|
3
|
+
let plucked = [];
|
|
4
|
+
for (let i = 0; i < items.length; i++) {
|
|
5
|
+
plucked.push(items[i][key]);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return plucked;
|
|
9
|
+
},
|
|
10
|
+
|
|
11
|
+
spread(items) {
|
|
12
|
+
return JSON.parse(JSON.stringify(items));
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
keyBy(items, key = 'id') {
|
|
16
|
+
let not_empty = window.handleEmpty(items);
|
|
17
|
+
if ( not_empty !== true ) {
|
|
18
|
+
return not_empty;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let new_items = {};
|
|
22
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
23
|
+
for ( let i = 0; i < count; i++ ) {
|
|
24
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
25
|
+
new_items[items[index][key]] = items[index];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return new_items;
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
groupBy(items, key = 'id') {
|
|
32
|
+
let not_empty = window.handleEmpty(items);
|
|
33
|
+
if ( not_empty !== true ) {
|
|
34
|
+
return not_empty;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
38
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
39
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
41
|
+
|
|
42
|
+
if (typeof new_items[items[index][key]] === 'undefined') {
|
|
43
|
+
new_items[items[index][key]] = [];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
new_items[items[index][key]].push(items[index]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new_items;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
find(items, ids) {
|
|
53
|
+
let not_empty = window.handleEmpty(items);
|
|
54
|
+
if ( not_empty !== true ) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let single = false;
|
|
59
|
+
if ( !Array.isArray(ids) ) {
|
|
60
|
+
if ( typeof ids === 'string' ) {
|
|
61
|
+
ids = parseInt(ids);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
ids = [ids];
|
|
65
|
+
single = true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
69
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
70
|
+
for ( let i = 0; i < count; i++ ) {
|
|
71
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
72
|
+
|
|
73
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
74
|
+
if ( Array.isArray(items) ) {
|
|
75
|
+
new_items.push(items[index]);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
new_items[index] = items[index];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if ( single ) {
|
|
84
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
85
|
+
return new_items[0];
|
|
86
|
+
}
|
|
87
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
88
|
+
return new_items[Object.keys(new_items)[0]];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new_items;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
findByKey(items, key, value = true, single = false) {
|
|
98
|
+
let not_empty = window.handleEmpty(items);
|
|
99
|
+
if ( not_empty !== true ) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
104
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
105
|
+
for ( let i = 0; i < count; i++ ) {
|
|
106
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
107
|
+
|
|
108
|
+
if ( items[index][key] == value ) {
|
|
109
|
+
if ( Array.isArray(items) ) {
|
|
110
|
+
new_items.push(items[index]);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
new_items[index] = items[index];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if ( single ) {
|
|
119
|
+
if ( Array.isArray(new_items) && new_items.length ) {
|
|
120
|
+
return new_items[0];
|
|
121
|
+
}
|
|
122
|
+
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
123
|
+
return new_items[Object.keys(new_items)[0]];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return new_items;
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
add(items, item, at_first_position = false) {
|
|
133
|
+
let not_empty = window.handleEmpty(items);
|
|
134
|
+
if ( not_empty !== true ) {
|
|
135
|
+
items = [];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if ( at_first_position ) {
|
|
139
|
+
items.unshift(item);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
items.push(item);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return items;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
addMany(items, added, at_first_position = false) {
|
|
149
|
+
let not_empty = window.handleEmpty(items);
|
|
150
|
+
if ( not_empty !== true ) {
|
|
151
|
+
items = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if ( at_first_position ) {
|
|
155
|
+
return added.concat(items);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
return items.concat(added);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
patch(items, data) {
|
|
163
|
+
if ( !data.id ) {
|
|
164
|
+
throw 'ID is required.';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
let id = data.id;
|
|
168
|
+
delete data.id;
|
|
169
|
+
|
|
170
|
+
return self.setKeys(items, id, Object.keys(data), Object.values(data));
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
replace(items, item) {
|
|
174
|
+
let not_empty = window.handleEmpty(items);
|
|
175
|
+
if ( not_empty !== true ) {
|
|
176
|
+
return not_empty;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
180
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
181
|
+
for ( let i = 0; i < count; i++ ) {
|
|
182
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
183
|
+
|
|
184
|
+
if ( items[index].id == item.id ) {
|
|
185
|
+
new_items[index] = item;
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
new_items[index] = items[index];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return new_items;
|
|
193
|
+
},
|
|
194
|
+
|
|
195
|
+
delete(items, ids) {
|
|
196
|
+
let not_empty = window.handleEmpty(items);
|
|
197
|
+
if ( not_empty !== true ) {
|
|
198
|
+
return not_empty;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if ( !Array.isArray(ids) ) {
|
|
202
|
+
if ( typeof ids === 'string' ) {
|
|
203
|
+
ids = parseInt(ids);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
ids = [ids];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
210
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
211
|
+
for ( let i = 0; i < count; i++ ) {
|
|
212
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
213
|
+
|
|
214
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if ( Array.isArray(items) ) {
|
|
219
|
+
new_items.push(items[index]);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
new_items[index] = items[index];
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return new_items;
|
|
227
|
+
},
|
|
228
|
+
|
|
229
|
+
deleteByKey(items, key, value) {
|
|
230
|
+
let not_empty = window.handleEmpty(items);
|
|
231
|
+
if ( not_empty !== true ) {
|
|
232
|
+
return not_empty;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
let new_items = Array.isArray(items) ? [] : {};
|
|
236
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
237
|
+
for ( let i = 0; i < count; i++ ) {
|
|
238
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
239
|
+
|
|
240
|
+
if ( items[index][key] != value ) {
|
|
241
|
+
new_items[index] = items[index];
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return new_items;
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
setKey(items, id, key, value) {
|
|
249
|
+
return self.setKeys(items, id, key, value);
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
setKeys(items, ids, keys, values) {
|
|
253
|
+
let not_empty = window.handleEmpty(items);
|
|
254
|
+
if ( not_empty !== true ) {
|
|
255
|
+
return not_empty;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if ( !Array.isArray(ids) ) {
|
|
259
|
+
if ( typeof ids === 'string' ) {
|
|
260
|
+
ids = parseInt(ids);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
ids = [ids];
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
267
|
+
let array_values = [];
|
|
268
|
+
for ( let key of keys ) {
|
|
269
|
+
array_values.push(values);
|
|
270
|
+
}
|
|
271
|
+
values = array_values;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if ( !Array.isArray(keys) ) {
|
|
275
|
+
keys = [keys];
|
|
276
|
+
values = [values];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
280
|
+
for ( let i = 0; i < count; i++ ) {
|
|
281
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
282
|
+
|
|
283
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
284
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
285
|
+
items[i][keys[j]] = values[j];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return items;
|
|
291
|
+
},
|
|
292
|
+
|
|
293
|
+
toggleKey(items, id, key) {
|
|
294
|
+
return self.toggleKeys(items, id, key);
|
|
295
|
+
},
|
|
296
|
+
|
|
297
|
+
toggleKeys(items, ids, keys) {
|
|
298
|
+
let not_empty = window.handleEmpty(items);
|
|
299
|
+
if ( not_empty !== true ) {
|
|
300
|
+
return not_empty;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ( !Array.isArray(ids) ) {
|
|
304
|
+
if ( typeof ids === 'string' ) {
|
|
305
|
+
ids = parseInt(ids);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
ids = [ids];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if ( !Array.isArray(keys) ) {
|
|
312
|
+
keys = [keys];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
316
|
+
for ( let i = 0; i < count; i++ ) {
|
|
317
|
+
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
318
|
+
|
|
319
|
+
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
320
|
+
for ( let j = 0; j < keys.length; j++ ) {
|
|
321
|
+
items[index][keys[j]] = !items[index][keys[j]];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return items;
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
sort(items, from, to) {
|
|
330
|
+
const copy = [...items];
|
|
331
|
+
const valueToMove = copy.splice(from, 1)[0];
|
|
332
|
+
copy.splice(to, 0, valueToMove);
|
|
333
|
+
|
|
334
|
+
return copy;
|
|
335
|
+
},
|
|
336
|
+
|
|
337
|
+
next(items, current, key = 'id') {
|
|
338
|
+
for ( let i = 0; i < items.length; i++ ) {
|
|
339
|
+
if ( items[i][key] == current[key] && i < items.length - 1 ) {
|
|
340
|
+
return items[i + 1];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return false;
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
prev(items, current, key = 'id') {
|
|
348
|
+
for ( let i = items.length - 1; i >= 0; i-- ) {
|
|
349
|
+
if ( items[i][key] == current[key] && i > 0 ) {
|
|
350
|
+
return items[i - 1];
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return false;
|
|
355
|
+
},
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
window.pluck = self.pluck;
|
|
359
|
+
window.spread = self.spread;
|
|
360
|
+
window.keyBy = self.keyBy;
|
|
361
|
+
window.groupBy = self.groupBy;
|
|
362
|
+
|
|
363
|
+
export default self;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { reactive } from 'vue';
|
|
2
|
+
|
|
3
|
+
const self = {
|
|
4
|
+
state: reactive({
|
|
5
|
+
data: {}
|
|
6
|
+
}),
|
|
7
|
+
|
|
8
|
+
setItem(key, value) {
|
|
9
|
+
localStorage.setItem(key, value);
|
|
10
|
+
self.state.data[key] = value;
|
|
11
|
+
},
|
|
12
|
+
|
|
13
|
+
getItem(key) {
|
|
14
|
+
if (!self.state.data[key]) {
|
|
15
|
+
const value = localStorage.getItem(key);
|
|
16
|
+
if (value) {
|
|
17
|
+
self.state.data[key] = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return self.state.data[key];
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
removeItem(key) {
|
|
25
|
+
localStorage.removeItem(key);
|
|
26
|
+
delete self.state.data[key];
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default self;
|