@iankibetsh/shframework 1.1.9 → 1.2.1
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/library.js +49 -26
- package/dist/library.mjs +48 -27
- package/package.json +1 -1
package/dist/library.js
CHANGED
|
@@ -5,10 +5,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var Axios = require('axios');
|
|
6
6
|
var moment = require('moment');
|
|
7
7
|
var Swal = require('sweetalert2');
|
|
8
|
+
var shApis$1 = require('@/lib/repo/helpers/ShApis.js');
|
|
8
9
|
var vue = require('vue');
|
|
9
10
|
var NProgress = require('nprogress');
|
|
10
11
|
var Editor = require('@tinymce/tinymce-vue');
|
|
11
12
|
var pinia = require('pinia');
|
|
13
|
+
var shRepo$1 = require('@/lib/repo/helpers/ShRepo.js');
|
|
12
14
|
var vueRouter = require('vue-router');
|
|
13
15
|
|
|
14
16
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -16,8 +18,10 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
16
18
|
var Axios__default = /*#__PURE__*/_interopDefaultLegacy(Axios);
|
|
17
19
|
var moment__default = /*#__PURE__*/_interopDefaultLegacy(moment);
|
|
18
20
|
var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
|
|
21
|
+
var shApis__default = /*#__PURE__*/_interopDefaultLegacy(shApis$1);
|
|
19
22
|
var NProgress__default = /*#__PURE__*/_interopDefaultLegacy(NProgress);
|
|
20
23
|
var Editor__default = /*#__PURE__*/_interopDefaultLegacy(Editor);
|
|
24
|
+
var shRepo__default = /*#__PURE__*/_interopDefaultLegacy(shRepo$1);
|
|
21
25
|
|
|
22
26
|
function setItem (key, value) {
|
|
23
27
|
let toStore = value;
|
|
@@ -135,6 +139,23 @@ function getMenuCount (url) {
|
|
|
135
139
|
});
|
|
136
140
|
}
|
|
137
141
|
|
|
142
|
+
const signOutUser = ()=>{
|
|
143
|
+
const loginUrl = getShConfig('loginUrl','auth/login');
|
|
144
|
+
const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
|
|
145
|
+
console.log(loginUrl,logoutApiEndPoint);
|
|
146
|
+
shApis__default["default"].doPost(logoutApiEndPoint).then(res=>{
|
|
147
|
+
ShStorage.removeItem('access_token');
|
|
148
|
+
ShStorage.removeItem('user');
|
|
149
|
+
ShStorage.removeItem('last_activity');
|
|
150
|
+
window.location.href = loginUrl;
|
|
151
|
+
}).catch(ex=>{
|
|
152
|
+
ShStorage.removeItem('access_token');
|
|
153
|
+
ShStorage.removeItem('user');
|
|
154
|
+
ShStorage.removeItem('last_activity');
|
|
155
|
+
window.location.href = loginUrl;
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
138
159
|
|
|
139
160
|
const Toast = Swal__default["default"].mixin({
|
|
140
161
|
toast: true,
|
|
@@ -151,9 +172,11 @@ const Toast = Swal__default["default"].mixin({
|
|
|
151
172
|
toast.addEventListener('mouseleave', Swal__default["default"].resumeTimer);
|
|
152
173
|
}
|
|
153
174
|
});
|
|
154
|
-
function
|
|
175
|
+
function getShConfig(key = null,def = '') {
|
|
155
176
|
const config = ShStorage.getItem('ShConfig');
|
|
156
|
-
|
|
177
|
+
if(key) {
|
|
178
|
+
return config[key] ?? def
|
|
179
|
+
}
|
|
157
180
|
return config
|
|
158
181
|
}
|
|
159
182
|
function showToast (message, toastType, position) {
|
|
@@ -225,37 +248,32 @@ var shRepo = {
|
|
|
225
248
|
runPlainRequest,
|
|
226
249
|
getMenuCount,
|
|
227
250
|
setTabCounts,
|
|
228
|
-
|
|
251
|
+
getShConfig,
|
|
229
252
|
showToast,
|
|
230
253
|
runSilentRequest,
|
|
231
254
|
swalHttpError,
|
|
232
255
|
formatHttpCatchError,
|
|
233
256
|
formatDate,
|
|
234
257
|
numberFormat,
|
|
235
|
-
formatNumber
|
|
258
|
+
formatNumber,
|
|
259
|
+
signOutUser
|
|
236
260
|
};
|
|
237
261
|
|
|
238
262
|
startSession();
|
|
239
263
|
function logoutUser(){
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if(window.shInterval){
|
|
254
|
-
clearInterval(window.shInterval);
|
|
255
|
-
}
|
|
256
|
-
window.location.href = loginUrl;
|
|
257
|
-
});
|
|
258
|
-
ShStorage.getItem('user');
|
|
264
|
+
if(!sessionRestored()){
|
|
265
|
+
shRepo.signOutUser();
|
|
266
|
+
} else {
|
|
267
|
+
console.log('session has been restored in another tab');
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
function sessionRestored(){
|
|
271
|
+
const timeout = ShStorage.getItem('sessionTimeout') * 60;
|
|
272
|
+
const last_activity = ShStorage.getItem('last_activity');
|
|
273
|
+
const pastSeconds = moment__default["default"]().diff(last_activity, 'seconds');
|
|
274
|
+
if(!ShStorage.getItem('access_token'))
|
|
275
|
+
return false
|
|
276
|
+
return pastSeconds < timeout
|
|
259
277
|
}
|
|
260
278
|
const checkSession = function (isCheking) {
|
|
261
279
|
const timeout = ShStorage.getItem('sessionTimeout');
|
|
@@ -297,6 +315,10 @@ async function shSwalLogout (seconds = 30) {
|
|
|
297
315
|
showLoaderOnConfirm: true,
|
|
298
316
|
didOpen(popup) {
|
|
299
317
|
timerInterval = setInterval(() => {
|
|
318
|
+
// if(sessionRestored() && ShStorage.getItem('access_token')){
|
|
319
|
+
// console.log('swal closed by session restored')
|
|
320
|
+
// Swal.close()
|
|
321
|
+
// }
|
|
300
322
|
Swal__default["default"].getHtmlContainer().querySelector('strong')
|
|
301
323
|
.textContent = (Swal__default["default"].getTimerLeft() / 1000)
|
|
302
324
|
.toFixed(0);
|
|
@@ -4498,6 +4520,9 @@ const useUserStore = pinia.defineStore('user-store', {
|
|
|
4498
4520
|
user = res.data;
|
|
4499
4521
|
}
|
|
4500
4522
|
ShStorage.setItem('user',user);
|
|
4523
|
+
user.signOut = this.signOut;
|
|
4524
|
+
user.logout = this.signOut;
|
|
4525
|
+
user.logOut = this.signOut;
|
|
4501
4526
|
user.isAllowedTo = function (slug) {
|
|
4502
4527
|
if(!slug){
|
|
4503
4528
|
return true
|
|
@@ -4534,9 +4559,7 @@ const useUserStore = pinia.defineStore('user-store', {
|
|
|
4534
4559
|
ShStorage.setItem('session_start',timeNow);
|
|
4535
4560
|
},
|
|
4536
4561
|
signOut () {
|
|
4537
|
-
|
|
4538
|
-
ShStorage.setItem('access_token',null);
|
|
4539
|
-
this.user = null;
|
|
4562
|
+
shRepo__default["default"].signOutUser();
|
|
4540
4563
|
},
|
|
4541
4564
|
logOut () {
|
|
4542
4565
|
this.signOut();
|
package/dist/library.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Axios from 'axios';
|
|
2
2
|
import moment from 'moment';
|
|
3
3
|
import Swal from 'sweetalert2';
|
|
4
|
-
import
|
|
4
|
+
import shApis$1 from '@/lib/repo/helpers/ShApis.js';
|
|
5
|
+
import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, withModifiers, createVNode, ref, onMounted, unref, normalizeClass, createBlock, resolveDynamicComponent, renderSlot, normalizeProps, guardReactiveProps, withCtx, mergeProps, createStaticVNode, shallowRef, computed, isRef, vModelCheckbox, inject, watch, pushScopeId, popScopeId } from 'vue';
|
|
5
6
|
import NProgress from 'nprogress';
|
|
6
7
|
import Editor from '@tinymce/tinymce-vue';
|
|
7
8
|
import { defineStore, storeToRefs } from 'pinia';
|
|
9
|
+
import shRepo$1 from '@/lib/repo/helpers/ShRepo.js';
|
|
8
10
|
import { useRoute, useRouter } from 'vue-router';
|
|
9
11
|
|
|
10
12
|
function setItem (key, value) {
|
|
@@ -123,6 +125,23 @@ function getMenuCount (url) {
|
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
const signOutUser = ()=>{
|
|
129
|
+
const loginUrl = getShConfig('loginUrl','auth/login');
|
|
130
|
+
const logoutApiEndPoint = getShConfig('logoutApiEndpoint','auth/logout');
|
|
131
|
+
console.log(loginUrl,logoutApiEndPoint);
|
|
132
|
+
shApis$1.doPost(logoutApiEndPoint).then(res=>{
|
|
133
|
+
ShStorage.removeItem('access_token');
|
|
134
|
+
ShStorage.removeItem('user');
|
|
135
|
+
ShStorage.removeItem('last_activity');
|
|
136
|
+
window.location.href = loginUrl;
|
|
137
|
+
}).catch(ex=>{
|
|
138
|
+
ShStorage.removeItem('access_token');
|
|
139
|
+
ShStorage.removeItem('user');
|
|
140
|
+
ShStorage.removeItem('last_activity');
|
|
141
|
+
window.location.href = loginUrl;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
126
145
|
|
|
127
146
|
const Toast = Swal.mixin({
|
|
128
147
|
toast: true,
|
|
@@ -139,9 +158,11 @@ const Toast = Swal.mixin({
|
|
|
139
158
|
toast.addEventListener('mouseleave', Swal.resumeTimer);
|
|
140
159
|
}
|
|
141
160
|
});
|
|
142
|
-
function
|
|
161
|
+
function getShConfig(key = null,def = '') {
|
|
143
162
|
const config = ShStorage.getItem('ShConfig');
|
|
144
|
-
|
|
163
|
+
if(key) {
|
|
164
|
+
return config[key] ?? def
|
|
165
|
+
}
|
|
145
166
|
return config
|
|
146
167
|
}
|
|
147
168
|
function showToast (message, toastType, position) {
|
|
@@ -213,37 +234,32 @@ var shRepo = {
|
|
|
213
234
|
runPlainRequest,
|
|
214
235
|
getMenuCount,
|
|
215
236
|
setTabCounts,
|
|
216
|
-
|
|
237
|
+
getShConfig,
|
|
217
238
|
showToast,
|
|
218
239
|
runSilentRequest,
|
|
219
240
|
swalHttpError,
|
|
220
241
|
formatHttpCatchError,
|
|
221
242
|
formatDate,
|
|
222
243
|
numberFormat,
|
|
223
|
-
formatNumber
|
|
244
|
+
formatNumber,
|
|
245
|
+
signOutUser
|
|
224
246
|
};
|
|
225
247
|
|
|
226
248
|
startSession();
|
|
227
249
|
function logoutUser(){
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if(window.shInterval){
|
|
242
|
-
clearInterval(window.shInterval);
|
|
243
|
-
}
|
|
244
|
-
window.location.href = loginUrl;
|
|
245
|
-
});
|
|
246
|
-
ShStorage.getItem('user');
|
|
250
|
+
if(!sessionRestored()){
|
|
251
|
+
shRepo.signOutUser();
|
|
252
|
+
} else {
|
|
253
|
+
console.log('session has been restored in another tab');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function sessionRestored(){
|
|
257
|
+
const timeout = ShStorage.getItem('sessionTimeout') * 60;
|
|
258
|
+
const last_activity = ShStorage.getItem('last_activity');
|
|
259
|
+
const pastSeconds = moment().diff(last_activity, 'seconds');
|
|
260
|
+
if(!ShStorage.getItem('access_token'))
|
|
261
|
+
return false
|
|
262
|
+
return pastSeconds < timeout
|
|
247
263
|
}
|
|
248
264
|
const checkSession = function (isCheking) {
|
|
249
265
|
const timeout = ShStorage.getItem('sessionTimeout');
|
|
@@ -285,6 +301,10 @@ async function shSwalLogout (seconds = 30) {
|
|
|
285
301
|
showLoaderOnConfirm: true,
|
|
286
302
|
didOpen(popup) {
|
|
287
303
|
timerInterval = setInterval(() => {
|
|
304
|
+
// if(sessionRestored() && ShStorage.getItem('access_token')){
|
|
305
|
+
// console.log('swal closed by session restored')
|
|
306
|
+
// Swal.close()
|
|
307
|
+
// }
|
|
288
308
|
Swal.getHtmlContainer().querySelector('strong')
|
|
289
309
|
.textContent = (Swal.getTimerLeft() / 1000)
|
|
290
310
|
.toFixed(0);
|
|
@@ -4486,6 +4506,9 @@ const useUserStore = defineStore('user-store', {
|
|
|
4486
4506
|
user = res.data;
|
|
4487
4507
|
}
|
|
4488
4508
|
ShStorage.setItem('user',user);
|
|
4509
|
+
user.signOut = this.signOut;
|
|
4510
|
+
user.logout = this.signOut;
|
|
4511
|
+
user.logOut = this.signOut;
|
|
4489
4512
|
user.isAllowedTo = function (slug) {
|
|
4490
4513
|
if(!slug){
|
|
4491
4514
|
return true
|
|
@@ -4522,9 +4545,7 @@ const useUserStore = defineStore('user-store', {
|
|
|
4522
4545
|
ShStorage.setItem('session_start',timeNow);
|
|
4523
4546
|
},
|
|
4524
4547
|
signOut () {
|
|
4525
|
-
|
|
4526
|
-
ShStorage.setItem('access_token',null);
|
|
4527
|
-
this.user = null;
|
|
4548
|
+
shRepo$1.signOutUser();
|
|
4528
4549
|
},
|
|
4529
4550
|
logOut () {
|
|
4530
4551
|
this.signOut();
|