xs-common-plugins 1.1.2 → 1.1.6

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.
Files changed (139) hide show
  1. package/README.md +37 -0
  2. package/package.json +1 -1
  3. package/src/App.vue +11 -11
  4. package/src/common/common.js +143 -14
  5. package/src/common/createMenuId.js +7 -7
  6. package/src/common/uploadImgToBase64.js +12 -12
  7. package/src/common/utils.js +95 -95
  8. package/src/components/Breadcrumb/index.vue +81 -81
  9. package/src/components/Col_TableCell/data.js +4 -4
  10. package/src/components/Col_TableCell/index.scss +77 -77
  11. package/src/components/Col_TableCell/index.vue +43 -43
  12. package/src/components/Col_TableCell/methods.js +19 -19
  13. package/src/components/Hamburger/index.vue +44 -44
  14. package/src/components/ReportCmp/data.js +3 -3
  15. package/src/components/ReportCmp/index.scss +29 -29
  16. package/src/components/ReportCmp/index.vue +2 -2
  17. package/src/components/ReportCmp/methods.js +30 -30
  18. package/src/components/Search/cascader/data.js +3 -3
  19. package/src/components/Search/cascader/index.scss +17 -17
  20. package/src/components/Search/cascader/index.vue +96 -96
  21. package/src/components/Search/cascader/methods.js +41 -41
  22. package/src/components/Search/data.js +5 -5
  23. package/src/components/Search/hk_cascader/index.vue +104 -104
  24. package/src/components/Search/hk_cascader_qudao/index.vue +94 -94
  25. package/src/components/Search/methods.js +86 -86
  26. package/src/components/Search/product_option/data.js +3 -3
  27. package/src/components/Search/product_option/index.scss +68 -68
  28. package/src/components/Search/product_option/index.vue +419 -419
  29. package/src/components/Search/product_option/methods.js +46 -46
  30. package/src/components/Search/select/data.js +3 -3
  31. package/src/components/Search/select/index.scss +2 -2
  32. package/src/components/Search/select/index.vue +114 -114
  33. package/src/components/Search/select/methods.js +51 -51
  34. package/src/components/Search_filter/data.js +5 -5
  35. package/src/components/Search_filter/index.vue +88 -88
  36. package/src/components/Search_filter/methods.js +43 -43
  37. package/src/components/TableCmp/data.js +3 -3
  38. package/src/components/TableCmp/index.scss +22 -22
  39. package/src/components/TableCmp/index.vue +98 -98
  40. package/src/components/TableCmp/methods.js +35 -35
  41. package/src/components/home/BarChart.vue +118 -118
  42. package/src/components/home/LineChart.vue +146 -146
  43. package/src/components/home/Panel.vue +135 -135
  44. package/src/components/home/PanelGroup.vue +146 -146
  45. package/src/components/home/PieChart.vue +81 -81
  46. package/src/components/home/RaddarChart.vue +119 -119
  47. package/src/components/home/TabLayout.vue +88 -88
  48. package/src/components/home/TableList.vue +158 -158
  49. package/src/components/home/Teng.vue +248 -248
  50. package/src/components/home/TransactionTable.vue +49 -49
  51. package/src/components/home/mixins/resize.js +55 -55
  52. package/src/components/im/methods.js +25 -25
  53. package/src/components/image-singleUpload/data.js +3 -3
  54. package/src/components/image-singleUpload/index.scss +26 -26
  55. package/src/components/image-singleUpload/index.vue +56 -56
  56. package/src/components/image-singleUpload/methods.js +30 -30
  57. package/src/components/image-upload/data.js +7 -7
  58. package/src/components/image-upload/index.vue +41 -41
  59. package/src/components/image-upload/methods.js +80 -80
  60. package/src/components/multiple-image-upload/data.js +11 -11
  61. package/src/components/multiple-image-upload/index.scss +8 -8
  62. package/src/components/multiple-image-upload/index.vue +63 -63
  63. package/src/components/multiple-image-upload/methods.js +45 -45
  64. package/src/components/pro-upload/data.js +3 -3
  65. package/src/components/pro-upload/index.scss +4 -4
  66. package/src/components/pro-upload/index.vue +89 -89
  67. package/src/components/pro-upload/methods.js +86 -86
  68. package/src/components/report_set/index.scss +44 -44
  69. package/src/components/report_set/index.vue +153 -153
  70. package/src/components/search-page/src/index.scss +5 -5
  71. package/src/components/search-page/src/index.vue +76 -76
  72. package/src/components/search-page/src/methods.js +36 -36
  73. package/src/mixin/dialog.js +31 -31
  74. package/src/mixin/dlg.js +46 -46
  75. package/src/mixin/newDialog.js +19 -19
  76. package/src/mixin/report.js +82 -82
  77. package/src/mixin/table.js +93 -93
  78. package/src/mixin/tableCell/colTableCell_analysis.js +103 -103
  79. package/src/mixin/upload.js +22 -22
  80. package/src/mixin/vmodel.js +26 -26
  81. package/src/plugins/im/components/conversation-list/index.css +91 -91
  82. package/src/plugins/im/components/conversation-list/index.json +3 -3
  83. package/src/plugins/im/components/conversation-list/index.vue +89 -89
  84. package/src/plugins/im/components/loading/loading.css +69 -69
  85. package/src/plugins/im/components/loading/loading.json +3 -3
  86. package/src/plugins/im/components/loading/loading.vue +14 -14
  87. package/src/plugins/im/components/msg-image/index.json +3 -3
  88. package/src/plugins/im/components/msg-text/index.json +3 -3
  89. package/src/plugins/im/components/msg-text/index.vue +24 -24
  90. package/src/plugins/im/im-plug-in/Protobuf-2.3.7.min.js +1 -1
  91. package/src/plugins/im/im-plug-in/RongCallLib-3.1.5.min.js +74 -74
  92. package/src/plugins/im/im-plug-in/RongIMLib-4.1.0.js +17420 -17420
  93. package/src/plugins/im/im-plug-in/init.js +216 -216
  94. package/src/plugins/im/im-plug-in/qiniu.js +266 -266
  95. package/src/plugins/im/im-plug-in/send-data.js +431 -431
  96. package/src/plugins/im/im-plug-in/upload.js +232 -232
  97. package/src/plugins/im/lib/RongIMEmoji-2.2.6.js +332 -332
  98. package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.js +11635 -11635
  99. package/src/plugins/im/lib/RongIMLib-3.0.7.2-dev.min.js +6 -6
  100. package/src/plugins/im/utils/underscore-1.8.3.js +1531 -1531
  101. package/src/plugins/im/utils/utils.js +149 -149
  102. package/src/plugins/row-col-cmp/colCmp/data.js +3 -3
  103. package/src/plugins/row-col-cmp/colCmp/index.scss +50 -50
  104. package/src/plugins/row-col-cmp/colCmp/index.vue +53 -53
  105. package/src/plugins/row-col-cmp/colCmp/methods.js +25 -25
  106. package/src/plugins/row-col-cmp/rowCmp/data.js +3 -3
  107. package/src/plugins/row-col-cmp/rowCmp/index.scss +3 -3
  108. package/src/plugins/row-col-cmp/rowCmp/index.vue +43 -43
  109. package/src/plugins/row-col-cmp/rowCmp/methods.js +29 -29
  110. package/src/router/index.js +47 -43
  111. package/src/store/getters.js +13 -13
  112. package/src/store/index.js +58 -58
  113. package/src/store/modules/app.js +55 -55
  114. package/src/store/modules/dic.js +1 -1
  115. package/src/store/modules/settings.js +28 -28
  116. package/src/store/modules/user.js +94 -94
  117. package/src/store/modules/widgetdata.js +42 -42
  118. package/src/styles/element-ui.scss +49 -49
  119. package/src/styles/mixin.scss +28 -28
  120. package/src/styles/sidebar.scss +210 -210
  121. package/src/styles/transition.scss +48 -48
  122. package/src/styles/variables.scss +25 -25
  123. package/src/utils/get-page-title.js +10 -10
  124. package/src/utils/getMenu.js +2 -1
  125. package/src/utils/global-config.js +15 -15
  126. package/src/utils/index.js +332 -332
  127. package/src/utils/localStorage.js +21 -21
  128. package/src/utils/validate.js +20 -20
  129. package/src/views/layout/components/AllSearch/index.vue +44 -44
  130. package/src/views/layout/components/AppMain.vue +50 -50
  131. package/src/views/layout/components/Navbar.vue +43 -2
  132. package/src/views/layout/components/Sidebar/FixiOSBug.js +26 -26
  133. package/src/views/layout/components/Sidebar/Item.vue +28 -28
  134. package/src/views/layout/components/Sidebar/Link.vue +34 -34
  135. package/src/views/layout/components/Sidebar/Logo.vue +79 -79
  136. package/src/views/layout/components/Sidebar/SidebarItem.vue +67 -67
  137. package/src/views/layout/components/Sidebar/index.vue +114 -114
  138. package/src/views/layout/components/index.js +3 -3
  139. package/src/views/layout/index.vue +105 -105
@@ -1,30 +1,30 @@
1
- export default {
2
- // ------------------------------------------------------------------
3
- // pragma mark - inti(初始化行为)
4
- // ------------------------------------------------------------------
5
- createdInit() {
6
-
7
- },
8
- mountedInit() {
9
- },
10
-
11
- getdata() {
12
- return 11
13
- },
14
-
15
- // ------------------------------------------------------------------
16
- // pragma mark - Event Response(响应事件)
17
- // 命名规范: Name + EventHandler
18
- // ------------------------------------------------------------------
19
- Demo_handler() {
20
-
21
- },
22
-
23
- // ------------------------------------------------------------------
24
- // pragma mark - Private Methods(私有方法: )
25
- // 命名规范: 前缀 __ + name
26
- // ------------------------------------------------------------------
27
- __demoFunction() {
28
-
29
- }
1
+ export default {
2
+ // ------------------------------------------------------------------
3
+ // pragma mark - inti(初始化行为)
4
+ // ------------------------------------------------------------------
5
+ createdInit() {
6
+
7
+ },
8
+ mountedInit() {
9
+ },
10
+
11
+ getdata() {
12
+ return 11
13
+ },
14
+
15
+ // ------------------------------------------------------------------
16
+ // pragma mark - Event Response(响应事件)
17
+ // 命名规范: Name + EventHandler
18
+ // ------------------------------------------------------------------
19
+ Demo_handler() {
20
+
21
+ },
22
+
23
+ // ------------------------------------------------------------------
24
+ // pragma mark - Private Methods(私有方法: )
25
+ // 命名规范: 前缀 __ + name
26
+ // ------------------------------------------------------------------
27
+ __demoFunction() {
28
+
29
+ }
30
30
  }
@@ -1,43 +1,47 @@
1
- import Vue from 'vue'
2
- import VueRouter from 'vue-router'
3
- import autoRouter from '../automatically/router'
4
- Vue.use(VueRouter)
5
-
6
- const routes = [
7
- {
8
- path: '/',
9
- name: 'layout',
10
- component: () => import('../views/layout/index'),
11
- redirect: '/home', // 默认展示页面
12
- meta: { title: '首页', icon: 'example' },
13
- children: [autoRouter[0]]
14
- },
15
- {
16
- path: '/home',
17
- name: 'home',
18
- component: () => import('../views/layout/index'),
19
- meta: { title: '首页', icon: 'example' },
20
- children: [{
21
- path:'/',
22
- component: () => import('../views/home/index'),
23
- }],
24
- },
25
- {
26
- path: '/callback',
27
- name: 'callback',
28
- meta: { title: '认证' },
29
- component: ()=> import('../views/callback/index')
30
- },
31
- {
32
- path: '/slienceAuth',
33
- name: 'slienceAuth',
34
- meta: {title: '静默授权'},
35
- component: () => import("../views/slienceAuth/index")
36
- }
37
- ]
38
-
39
- const router = new VueRouter({
40
- routes
41
- })
42
-
43
- export default router
1
+ import Vue from 'vue'
2
+ import VueRouter from 'vue-router'
3
+ import autoRouter from '../automatically/router'
4
+ Vue.use(VueRouter)
5
+
6
+ const originalPush = VueRouter.prototype.push;
7
+ VueRouter.prototype.push = function push(location) {
8
+ return originalPush.call(this, location).catch(err => err)
9
+ }
10
+ const routes = [
11
+ {
12
+ path: '/',
13
+ name: 'layout',
14
+ component: () => import('../views/layout/index'),
15
+ redirect: '/home', // 默认展示页面
16
+ meta: { title: '首页', icon: 'example' },
17
+ children: [autoRouter[0]]
18
+ },
19
+ {
20
+ path: '/home',
21
+ name: 'home',
22
+ component: () => import('../views/layout/index'),
23
+ meta: { title: '首页', icon: 'example' },
24
+ children: [{
25
+ path:'/',
26
+ component: () => import('../views/home/index'),
27
+ }],
28
+ },
29
+ {
30
+ path: '/callback',
31
+ name: 'callback',
32
+ meta: { title: '认证' },
33
+ component: ()=> import('../views/callback/index')
34
+ },
35
+ {
36
+ path: '/slienceAuth',
37
+ name: 'slienceAuth',
38
+ meta: {title: '静默授权'},
39
+ component: () => import("../views/slienceAuth/index")
40
+ }
41
+ ]
42
+
43
+ const router = new VueRouter({
44
+ routes
45
+ })
46
+
47
+ export default router
@@ -1,13 +1,13 @@
1
- const getters = {
2
- sidebar: state => state.app.sidebar,
3
- device: state => state.app.device,
4
- token: state => state.user.token,
5
- avatar: state => state.user.avatar,
6
- name: state => state.user.name,
7
- widgetObj: state => state.widgetdata.widgetObj,
8
- widgetMeta: state => state.widgetdata.meta,
9
- menuList: state => state.app.menuList,
10
- ossCfg: state => state.oss.ossCfg,
11
- dic: state => state.dic.ask,
12
- }
13
- export default getters
1
+ const getters = {
2
+ sidebar: state => state.app.sidebar,
3
+ device: state => state.app.device,
4
+ token: state => state.user.token,
5
+ avatar: state => state.user.avatar,
6
+ name: state => state.user.name,
7
+ widgetObj: state => state.widgetdata.widgetObj,
8
+ widgetMeta: state => state.widgetdata.meta,
9
+ menuList: state => state.app.menuList,
10
+ ossCfg: state => state.oss.ossCfg,
11
+ dic: state => state.dic.ask,
12
+ }
13
+ export default getters
@@ -1,58 +1,58 @@
1
- import Vue from 'vue'
2
- import Vuex from 'vuex'
3
- import getters from './getters'
4
- import app from './modules/app'
5
- import user from './modules/user'
6
- import widgetdata from './modules/widgetdata'
7
- import dic from './modules/dic'
8
- import oss from './modules/oss'
9
-
10
- const globalCfg = require("../modules/module.config");
11
- const importModules = globalCfg.IMPORT_MODULES;
12
-
13
- import storeConfig from '../modules/storeCfg.js'
14
-
15
- Vue.use(Vuex)
16
-
17
- const modulesDB = storeConfig;
18
-
19
- let mod = {};
20
- if (importModules) {
21
- importModules.forEach(element => {
22
- if (modulesDB[`module_${element}`]) {
23
- mod[`module_${element}`] = Object.assign({}, {
24
- namespaced: true,
25
- }, modulesDB[`module_${element}`])
26
- }
27
- });
28
- }
29
-
30
- let storeCfg = {
31
- state: {
32
- search: null, // 全局搜索
33
- glo_loading: false
34
- },
35
- mutations: {
36
- setSearch(state, val) {
37
- state.search = val
38
- },
39
-
40
- setLoading(state, val) {
41
- state.glo_loading = val
42
- }
43
- },
44
-
45
- modules: {
46
- app,
47
- user,
48
- widgetdata,
49
- dic,
50
- oss,
51
- ...mod
52
- },
53
- getters
54
- }
55
-
56
- const store = new Vuex.Store(storeCfg)
57
-
58
- export default store
1
+ import Vue from 'vue'
2
+ import Vuex from 'vuex'
3
+ import getters from './getters'
4
+ import app from './modules/app'
5
+ import user from './modules/user'
6
+ import widgetdata from './modules/widgetdata'
7
+ import dic from './modules/dic'
8
+ import oss from './modules/oss'
9
+
10
+ const globalCfg = require("../modules/module.config");
11
+ const importModules = globalCfg.IMPORT_MODULES;
12
+
13
+ import storeConfig from '../modules/storeCfg.js'
14
+
15
+ Vue.use(Vuex)
16
+
17
+ const modulesDB = storeConfig;
18
+
19
+ let mod = {};
20
+ if (importModules) {
21
+ importModules.forEach(element => {
22
+ if (modulesDB[`module_${element}`]) {
23
+ mod[`module_${element}`] = Object.assign({}, {
24
+ namespaced: true,
25
+ }, modulesDB[`module_${element}`])
26
+ }
27
+ });
28
+ }
29
+
30
+ let storeCfg = {
31
+ state: {
32
+ search: null, // 全局搜索
33
+ glo_loading: false
34
+ },
35
+ mutations: {
36
+ setSearch(state, val) {
37
+ state.search = val
38
+ },
39
+
40
+ setLoading(state, val) {
41
+ state.glo_loading = val
42
+ }
43
+ },
44
+
45
+ modules: {
46
+ app,
47
+ user,
48
+ widgetdata,
49
+ dic,
50
+ oss,
51
+ ...mod
52
+ },
53
+ getters
54
+ }
55
+
56
+ const store = new Vuex.Store(storeCfg)
57
+
58
+ export default store
@@ -1,55 +1,55 @@
1
- import Cookies from 'js-cookie'
2
-
3
- const state = {
4
- sidebar: {
5
- opened: true, //侧边栏默认关闭
6
- withoutAnimation: false
7
- },
8
- menuList: [], // 侧边菜单
9
- device: 'desktop'
10
- }
11
-
12
- const mutations = {
13
- TOGGLE_SIDEBAR: state => {
14
- state.sidebar.opened = !state.sidebar.opened
15
- state.sidebar.withoutAnimation = false
16
- if (state.sidebar.opened) {
17
- Cookies.set('sidebarStatus', 1)
18
- } else {
19
- Cookies.set('sidebarStatus', 0)
20
- }
21
- },
22
- CLOSE_SIDEBAR: (state, withoutAnimation) => {
23
- Cookies.set('sidebarStatus', 0)
24
- state.sidebar.opened = false
25
- state.sidebar.withoutAnimation = withoutAnimation
26
- },
27
- TOGGLE_DEVICE: (state, device) => {
28
- state.device = device
29
- },
30
- SET_MENULIST: (state, list) => {
31
- state.menuList = list
32
- }
33
- }
34
-
35
- const actions = {
36
- toggleSideBar({ commit }) {
37
- commit('TOGGLE_SIDEBAR')
38
- },
39
- closeSideBar({ commit }, { withoutAnimation }) {
40
- commit('CLOSE_SIDEBAR', withoutAnimation)
41
- },
42
- toggleDevice({ commit }, device) {
43
- commit('TOGGLE_DEVICE', device)
44
- },
45
- getMenuList({ commit }, list) {
46
- commit('SET_MENULIST', list)
47
- }
48
- }
49
-
50
- export default {
51
- namespaced: true,
52
- state,
53
- mutations,
54
- actions
55
- }
1
+ import Cookies from 'js-cookie'
2
+
3
+ const state = {
4
+ sidebar: {
5
+ opened: true, //侧边栏默认关闭
6
+ withoutAnimation: false
7
+ },
8
+ menuList: [], // 侧边菜单
9
+ device: 'desktop'
10
+ }
11
+
12
+ const mutations = {
13
+ TOGGLE_SIDEBAR: state => {
14
+ state.sidebar.opened = !state.sidebar.opened
15
+ state.sidebar.withoutAnimation = false
16
+ if (state.sidebar.opened) {
17
+ Cookies.set('sidebarStatus', 1)
18
+ } else {
19
+ Cookies.set('sidebarStatus', 0)
20
+ }
21
+ },
22
+ CLOSE_SIDEBAR: (state, withoutAnimation) => {
23
+ Cookies.set('sidebarStatus', 0)
24
+ state.sidebar.opened = false
25
+ state.sidebar.withoutAnimation = withoutAnimation
26
+ },
27
+ TOGGLE_DEVICE: (state, device) => {
28
+ state.device = device
29
+ },
30
+ SET_MENULIST: (state, list) => {
31
+ state.menuList = list
32
+ }
33
+ }
34
+
35
+ const actions = {
36
+ toggleSideBar({ commit }) {
37
+ commit('TOGGLE_SIDEBAR')
38
+ },
39
+ closeSideBar({ commit }, { withoutAnimation }) {
40
+ commit('CLOSE_SIDEBAR', withoutAnimation)
41
+ },
42
+ toggleDevice({ commit }, device) {
43
+ commit('TOGGLE_DEVICE', device)
44
+ },
45
+ getMenuList({ commit }, list) {
46
+ commit('SET_MENULIST', list)
47
+ }
48
+ }
49
+
50
+ export default {
51
+ namespaced: true,
52
+ state,
53
+ mutations,
54
+ actions
55
+ }
@@ -22,7 +22,7 @@
22
22
  let dicing = [];
23
23
  const actions = {
24
24
  GET_ASK({ state, commit }, { props, value }) {
25
- if (!value) return;
25
+ if (!value || value == '0') return;
26
26
  let servers = props[0] || "";
27
27
  let tableName = props[1] || "";
28
28
  let key = servers + tableName;
@@ -1,28 +1,28 @@
1
-
2
- const state = {
3
- showSettings: false,
4
- fixedHeader: true,
5
- sidebarLogo: true
6
- }
7
-
8
- const mutations = {
9
- CHANGE_SETTING: (state, { key, value }) => {
10
- if (state.hasOwnProperty(key)) {
11
- state[key] = value
12
- }
13
- }
14
- }
15
-
16
- const actions = {
17
- changeSetting({ commit }, data) {
18
- commit('CHANGE_SETTING', data)
19
- }
20
- }
21
-
22
- export default {
23
- namespaced: true,
24
- state,
25
- mutations,
26
- actions
27
- }
28
-
1
+
2
+ const state = {
3
+ showSettings: false,
4
+ fixedHeader: true,
5
+ sidebarLogo: true
6
+ }
7
+
8
+ const mutations = {
9
+ CHANGE_SETTING: (state, { key, value }) => {
10
+ if (state.hasOwnProperty(key)) {
11
+ state[key] = value
12
+ }
13
+ }
14
+ }
15
+
16
+ const actions = {
17
+ changeSetting({ commit }, data) {
18
+ commit('CHANGE_SETTING', data)
19
+ }
20
+ }
21
+
22
+ export default {
23
+ namespaced: true,
24
+ state,
25
+ mutations,
26
+ actions
27
+ }
28
+
@@ -1,94 +1,94 @@
1
- import { getToken, setToken, removeToken } from '@/utils/auth'
2
-
3
- const getDefaultState = () => {
4
- return {
5
- token: getToken(),
6
- name: '',
7
- avatar: ''
8
- }
9
- }
10
-
11
- const state = getDefaultState()
12
-
13
- const mutations = {
14
- RESET_STATE: (state) => {
15
- Object.assign(state, getDefaultState())
16
- },
17
- SET_TOKEN: (state, token) => {
18
- state.token = token
19
- },
20
- SET_NAME: (state, name) => {
21
- state.name = name
22
- },
23
- SET_AVATAR: (state, avatar) => {
24
- state.avatar = avatar
25
- }
26
- }
27
-
28
- const actions = {
29
- // user login
30
- login({ commit }, userInfo) {
31
- const { username, password } = userInfo
32
- return new Promise((resolve, reject) => {
33
- login({ username: username.trim(), password: password }).then(response => {
34
- const { data } = response
35
- commit('SET_TOKEN', data.token)
36
- setToken(data.token)
37
- resolve()
38
- }).catch(error => {
39
- reject(error)
40
- })
41
- })
42
- },
43
-
44
- // get user info
45
- getInfo({ commit, state }) {
46
- return new Promise((resolve, reject) => {
47
- getInfo(state.token).then(response => {
48
- const { data } = response
49
-
50
- if (!data) {
51
- reject('Verification failed, please Login again.')
52
- }
53
-
54
- const { name, avatar } = data
55
-
56
- commit('SET_NAME', name)
57
- commit('SET_AVATAR', avatar)
58
- resolve(data)
59
- }).catch(error => {
60
- reject(error)
61
- })
62
- })
63
- },
64
-
65
- // user logout
66
- logout({ commit, state }) {
67
- return new Promise((resolve, reject) => {
68
- logout(state.token).then(() => {
69
- removeToken() // must remove token first
70
- commit('RESET_STATE')
71
- resolve();
72
- }).catch(error => {
73
- reject(error)
74
- })
75
- })
76
- },
77
-
78
- // remove token
79
- resetToken({ commit }) {
80
- return new Promise(resolve => {
81
- removeToken() // must remove token first
82
- commit('RESET_STATE')
83
- resolve()
84
- })
85
- }
86
- }
87
-
88
- export default {
89
- namespaced: true,
90
- state,
91
- mutations,
92
- actions
93
- }
94
-
1
+ import { getToken, setToken, removeToken } from '@/utils/auth'
2
+
3
+ const getDefaultState = () => {
4
+ return {
5
+ token: getToken(),
6
+ name: '',
7
+ avatar: ''
8
+ }
9
+ }
10
+
11
+ const state = getDefaultState()
12
+
13
+ const mutations = {
14
+ RESET_STATE: (state) => {
15
+ Object.assign(state, getDefaultState())
16
+ },
17
+ SET_TOKEN: (state, token) => {
18
+ state.token = token
19
+ },
20
+ SET_NAME: (state, name) => {
21
+ state.name = name
22
+ },
23
+ SET_AVATAR: (state, avatar) => {
24
+ state.avatar = avatar
25
+ }
26
+ }
27
+
28
+ const actions = {
29
+ // user login
30
+ login({ commit }, userInfo) {
31
+ const { username, password } = userInfo
32
+ return new Promise((resolve, reject) => {
33
+ login({ username: username.trim(), password: password }).then(response => {
34
+ const { data } = response
35
+ commit('SET_TOKEN', data.token)
36
+ setToken(data.token)
37
+ resolve()
38
+ }).catch(error => {
39
+ reject(error)
40
+ })
41
+ })
42
+ },
43
+
44
+ // get user info
45
+ getInfo({ commit, state }) {
46
+ return new Promise((resolve, reject) => {
47
+ getInfo(state.token).then(response => {
48
+ const { data } = response
49
+
50
+ if (!data) {
51
+ reject('Verification failed, please Login again.')
52
+ }
53
+
54
+ const { name, avatar } = data
55
+
56
+ commit('SET_NAME', name)
57
+ commit('SET_AVATAR', avatar)
58
+ resolve(data)
59
+ }).catch(error => {
60
+ reject(error)
61
+ })
62
+ })
63
+ },
64
+
65
+ // user logout
66
+ logout({ commit, state }) {
67
+ return new Promise((resolve, reject) => {
68
+ logout(state.token).then(() => {
69
+ removeToken() // must remove token first
70
+ commit('RESET_STATE')
71
+ resolve();
72
+ }).catch(error => {
73
+ reject(error)
74
+ })
75
+ })
76
+ },
77
+
78
+ // remove token
79
+ resetToken({ commit }) {
80
+ return new Promise(resolve => {
81
+ removeToken() // must remove token first
82
+ commit('RESET_STATE')
83
+ resolve()
84
+ })
85
+ }
86
+ }
87
+
88
+ export default {
89
+ namespaced: true,
90
+ state,
91
+ mutations,
92
+ actions
93
+ }
94
+