@iankibetsh/shframework 0.0.5 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/library.js CHANGED
@@ -1,10 +1,13 @@
1
1
  'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
3
5
  var Axios = require('axios');
4
6
  var NProgress = require('nprogress');
5
7
  var vue = require('vue');
6
8
  var moment = require('moment');
7
9
  var Swal = require('sweetalert2');
10
+ var pinia = require('pinia');
8
11
 
9
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
13
 
@@ -1649,7 +1652,6 @@ script$6.__file = "src/views/ShPhone.vue";
1649
1652
 
1650
1653
  var script$5 = {
1651
1654
  name: 'ShForm',
1652
- inject: ['global'],
1653
1655
  components: {
1654
1656
  ShPhone: script$6
1655
1657
  },
@@ -1665,7 +1667,7 @@ var script$5 = {
1665
1667
  selectData: {},
1666
1668
  users: [],
1667
1669
  allPlaceHolders: {},
1668
- user: this.global.state.user,
1670
+ user: null,
1669
1671
  allLabels: {}
1670
1672
  }
1671
1673
  },
@@ -3372,24 +3374,86 @@ script.render = render;
3372
3374
  script.__scopeId = "data-v-3628b6a6";
3373
3375
  script.__file = "src/views/ShTabs.vue";
3374
3376
 
3375
- var components = {
3376
- ShForm: script$5,
3377
- ShCanvas: script$4,
3378
- ShModal: script$3,
3379
- ShPhone: script$6,
3380
- ShTable: script$1,
3381
- ShTabs: script
3382
- };
3383
-
3384
- const plugin = {
3385
- install (Vue) {
3386
- for (const prop in components) {
3387
- if (components.hasOwnProperty(prop)) {
3388
- const component = components[prop];
3389
- Vue.component(component.name, component);
3377
+ const useUserStore = pinia.defineStore('user-store', {
3378
+ state: () => ({
3379
+ user: null,
3380
+ role: null,
3381
+ permissions: null,
3382
+ menus: [],
3383
+ loggedOut: false
3384
+ }),
3385
+ actions: {
3386
+ setUser (){
3387
+ const user = shstorage.getItem('user') ? JSON.parse(shstorage.getItem('user')) : null;
3388
+ if (user) {
3389
+ user.isAllowedTo = function (slug) {
3390
+ if (this.permissions) {
3391
+ let permissions = [];
3392
+ if (typeof this.permissions === 'string') {
3393
+ permissions = JSON.parse(this.permissions);
3394
+ } else {
3395
+ permissions = this.permissions;
3396
+ }
3397
+ return permissions.includes(slug)
3398
+ }
3399
+ return false
3400
+ };
3390
3401
  }
3402
+ this.user = user;
3403
+ apis.doGet('auth/user').then(res => {
3404
+ shstorage.setItem('user',res.data);
3405
+ const user = res.data;
3406
+ user.isAllowedTo = function (slug) {
3407
+ if (this.permissions) {
3408
+ let permissions = [];
3409
+ if (typeof this.permissions === 'string') {
3410
+ permissions = JSON.parse(this.permissions);
3411
+ } else {
3412
+ permissions = this.permissions;
3413
+ }
3414
+ return permissions.includes(slug)
3415
+ }
3416
+ return false
3417
+ };
3418
+ this.user = user;
3419
+ }).catch((reason) => {
3420
+ if (reason.response && reason.response.status) {
3421
+ this.loggedOut = true;
3422
+ }
3423
+ });
3424
+ if (this.user) {
3425
+ if (typeof this.user.permissions === 'string') {
3426
+ this.permissions = JSON.parse(this.user.permissions);
3427
+ } else {
3428
+ this.permissions = this.user.permissions;
3429
+ }
3430
+ }
3431
+ },
3432
+ signOut () {
3433
+ shstorage.setItem('user',null);
3434
+ shstorage.setItem('access_token',null);
3435
+ this.user = null;
3436
+ },
3437
+ logOut () {
3438
+ shstorage.setItem('user',null);
3439
+ shstorage.setItem('access_token',null);
3440
+ this.user = null;
3441
+ }
3442
+ },
3443
+ getters: {
3444
+ userId (state) {
3445
+ return state.user === null ? null:state.user.id
3391
3446
  }
3392
3447
  }
3393
- };
3448
+ });
3394
3449
 
3395
- module.exports = plugin;
3450
+ exports.ShCanvas = script$4;
3451
+ exports.ShForm = script$5;
3452
+ exports.ShModal = script$3;
3453
+ exports.ShPhone = script$6;
3454
+ exports.ShTable = script$1;
3455
+ exports.ShTabs = script;
3456
+ exports.apis = apis;
3457
+ exports.helpers = helpers;
3458
+ exports.shstorage = shstorage;
3459
+ exports.useUserStore = useUserStore;
package/dist/library.mjs CHANGED
@@ -3,6 +3,7 @@ import NProgress from 'nprogress';
3
3
  import { openBlock, createElementBlock, createElementVNode, createTextVNode, toDisplayString, createCommentVNode, withDirectives, Fragment, renderList, vModelSelect, vModelText, resolveComponent, normalizeClass, createBlock, renderSlot, createStaticVNode, withCtx, pushScopeId, popScopeId, createVNode } from 'vue';
4
4
  import moment from 'moment';
5
5
  import Swal from 'sweetalert2';
6
+ import { defineStore } from 'pinia';
6
7
 
7
8
  function setItem (key, value) {
8
9
  let toStore = value;
@@ -1640,7 +1641,6 @@ script$6.__file = "src/views/ShPhone.vue";
1640
1641
 
1641
1642
  var script$5 = {
1642
1643
  name: 'ShForm',
1643
- inject: ['global'],
1644
1644
  components: {
1645
1645
  ShPhone: script$6
1646
1646
  },
@@ -1656,7 +1656,7 @@ var script$5 = {
1656
1656
  selectData: {},
1657
1657
  users: [],
1658
1658
  allPlaceHolders: {},
1659
- user: this.global.state.user,
1659
+ user: null,
1660
1660
  allLabels: {}
1661
1661
  }
1662
1662
  },
@@ -3363,24 +3363,77 @@ script.render = render;
3363
3363
  script.__scopeId = "data-v-3628b6a6";
3364
3364
  script.__file = "src/views/ShTabs.vue";
3365
3365
 
3366
- var components = {
3367
- ShForm: script$5,
3368
- ShCanvas: script$4,
3369
- ShModal: script$3,
3370
- ShPhone: script$6,
3371
- ShTable: script$1,
3372
- ShTabs: script
3373
- };
3374
-
3375
- const plugin = {
3376
- install (Vue) {
3377
- for (const prop in components) {
3378
- if (components.hasOwnProperty(prop)) {
3379
- const component = components[prop];
3380
- Vue.component(component.name, component);
3366
+ const useUserStore = defineStore('user-store', {
3367
+ state: () => ({
3368
+ user: null,
3369
+ role: null,
3370
+ permissions: null,
3371
+ menus: [],
3372
+ loggedOut: false
3373
+ }),
3374
+ actions: {
3375
+ setUser (){
3376
+ const user = shstorage.getItem('user') ? JSON.parse(shstorage.getItem('user')) : null;
3377
+ if (user) {
3378
+ user.isAllowedTo = function (slug) {
3379
+ if (this.permissions) {
3380
+ let permissions = [];
3381
+ if (typeof this.permissions === 'string') {
3382
+ permissions = JSON.parse(this.permissions);
3383
+ } else {
3384
+ permissions = this.permissions;
3385
+ }
3386
+ return permissions.includes(slug)
3387
+ }
3388
+ return false
3389
+ };
3390
+ }
3391
+ this.user = user;
3392
+ apis.doGet('auth/user').then(res => {
3393
+ shstorage.setItem('user',res.data);
3394
+ const user = res.data;
3395
+ user.isAllowedTo = function (slug) {
3396
+ if (this.permissions) {
3397
+ let permissions = [];
3398
+ if (typeof this.permissions === 'string') {
3399
+ permissions = JSON.parse(this.permissions);
3400
+ } else {
3401
+ permissions = this.permissions;
3402
+ }
3403
+ return permissions.includes(slug)
3404
+ }
3405
+ return false
3406
+ };
3407
+ this.user = user;
3408
+ }).catch((reason) => {
3409
+ if (reason.response && reason.response.status) {
3410
+ this.loggedOut = true;
3411
+ }
3412
+ });
3413
+ if (this.user) {
3414
+ if (typeof this.user.permissions === 'string') {
3415
+ this.permissions = JSON.parse(this.user.permissions);
3416
+ } else {
3417
+ this.permissions = this.user.permissions;
3418
+ }
3381
3419
  }
3420
+ },
3421
+ signOut () {
3422
+ shstorage.setItem('user',null);
3423
+ shstorage.setItem('access_token',null);
3424
+ this.user = null;
3425
+ },
3426
+ logOut () {
3427
+ shstorage.setItem('user',null);
3428
+ shstorage.setItem('access_token',null);
3429
+ this.user = null;
3430
+ }
3431
+ },
3432
+ getters: {
3433
+ userId (state) {
3434
+ return state.user === null ? null:state.user.id
3382
3435
  }
3383
3436
  }
3384
- };
3437
+ });
3385
3438
 
3386
- export { plugin as default };
3439
+ export { script$4 as ShCanvas, script$5 as ShForm, script$3 as ShModal, script$6 as ShPhone, script$1 as ShTable, script as ShTabs, apis, helpers, shstorage, useUserStore };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iankibetsh/shframework",
3
- "version": "0.0.5",
3
+ "version": "0.1.0",
4
4
  "description": "Vue library for handling laravel backend",
5
5
  "main": "dist/library.js",
6
6
  "module": "dist/library.mjs",