ry-vue-map 0.0.1 → 0.0.2

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.
@@ -1,544 +0,0 @@
1
- /**
2
- * 主题状态管理
3
- */
4
- import { changeColor } from 'ele-admin/packages/style/util';
5
- import { TAB_KEEP_ALIVE, THEME_STORE_NAME } from '@/config/setting';
6
- // state默认值
7
- const DEFAULT_STATE = {
8
- // 侧边栏风格: light(亮色), dark(暗色)
9
- sideStyle: 'dark',
10
- // 顶栏风格: light(亮色), dark(暗色), primary(主色)
11
- headStyle: 'light',
12
- // 标签页风格: default(默认), dot(圆点), card(卡片)
13
- tabStyle: 'default',
14
- // 布局风格: side(默认), top(顶栏菜单), mix(混合菜单)
15
- layoutStyle: 'side',
16
- // 侧边栏菜单风格: default(默认), mix(双排菜单)
17
- sideMenuStyle: 'default',
18
- // 是否固定侧栏
19
- fixedSidebar: true,
20
- // 是否固定顶栏
21
- fixedHeader: false,
22
- // 是否固定主体
23
- fixedBody: true,
24
- // 内容区域宽度铺满
25
- bodyFull: true,
26
- // 是否开启多标签
27
- showTabs: true,
28
- // logo是否自适应宽度
29
- logoAutoSize: false,
30
- // 侧栏是否多彩图标
31
- colorfulIcon: false,
32
- // 侧边栏是否只保持一个子菜单展开
33
- sideUniqueOpen: true,
34
- // 是否开启页脚
35
- showFooter: true,
36
- // 是否是色弱模式
37
- weakMode: false,
38
- // 是否是暗黑模式
39
- darkMode: false,
40
- // 主题色
41
- color: null,
42
- // 是否折叠侧边栏
43
- collapse: false,
44
- // 当前打开的选项卡
45
- tabs: [],
46
- // 主页的组件
47
- homeComponents: [],
48
- // 需要keep-alive的组件
49
- keepAliveInclude: [],
50
- // 不需要keep-alive的组件
51
- keepAliveExclude: [],
52
- // 屏幕宽度
53
- screenWidth:
54
- document.documentElement.clientWidth || document.body.clientWidth,
55
- // 屏幕高度
56
- screenHeight:
57
- document.documentElement.clientHeight || document.body.clientHeight,
58
- // 内容区域宽度
59
- contentWidth: document.querySelector('.ele-admin-content-view')?.clientWidth
60
- };
61
- // 不需要本地缓存的state
62
- const NO_CACHE_STATE = [
63
- 'collapse',
64
- 'tabs',
65
- 'homeComponents',
66
- 'keepAliveInclude',
67
- 'keepAliveExclude',
68
- 'screenWidth',
69
- 'screenHeight',
70
- 'contentWidth'
71
- ];
72
- // 改变时禁用过渡效果的state
73
- const DISABLED_TRANSITIONS = [
74
- 'layoutStyle',
75
- 'sideMenuStyle',
76
- 'fixedSidebar',
77
- 'fixedHeader',
78
- 'fixedBody',
79
- 'logoAutoSize'
80
- ];
81
- //
82
- let updateSizeTimer = null;
83
-
84
- /**
85
- * 读取缓存的配置
86
- * @param keyName 缓存的键名
87
- * @returns {Object}
88
- */
89
- function getCacheSetting(keyName) {
90
- let cache = {};
91
- try {
92
- const value = localStorage.getItem(keyName);
93
- if (value) {
94
- const temp = JSON.parse(value);
95
- if (typeof temp === 'object') {
96
- cache = temp;
97
- }
98
- }
99
- } catch (e) {
100
- }
101
- return cache;
102
- }
103
-
104
- /**
105
- * 缓存配置
106
- * @param keyName 缓存的键名
107
- * @param key 缓存的配置名
108
- * @param value 缓存的配置名对应的值
109
- */
110
- function cacheSetting(keyName, key, value) {
111
- if (NO_CACHE_STATE.includes(key)) {
112
- return;
113
- }
114
- const cache = getCacheSetting(keyName);
115
- if (cache[key] !== value) {
116
- cache[key] = value;
117
- localStorage.setItem(keyName, JSON.stringify(cache));
118
- }
119
- }
120
-
121
- /**
122
- * 检查state值以兼容旧版本
123
- * @param key
124
- * @param value
125
- * @returns
126
- */
127
- function checkStateValue(key, value) {
128
- if (typeof value === 'number') {
129
- if (key === 'sideStyle') {
130
- return ['light', 'dark'][value < 2 ? value : 1];
131
- }
132
- if (key === 'headStyle') {
133
- return ['light', 'dark', 'primary'][value < 3 ? value : 2];
134
- }
135
- if (key === 'tabStyle') {
136
- return ['default', 'dot', 'card'][value < 3 ? value : 2];
137
- }
138
- if (key === 'layoutStyle') {
139
- return ['side', 'top', 'mix'][value < 3 ? value : 2];
140
- }
141
- }
142
- return value;
143
- }
144
-
145
- /**
146
- * 获取state
147
- * @returns {Object}
148
- */
149
- function getState() {
150
- const state = { ...DEFAULT_STATE };
151
- // 读取缓存的配置及默认配置
152
- for (let key in state) {
153
- if (!Object.prototype.hasOwnProperty.call(state, key)) {
154
- continue;
155
- }
156
- const cache = getCacheSetting(THEME_STORE_NAME);
157
- if (cache[key] !== undefined) {
158
- state[key] = checkStateValue(key, cache[key]);
159
- }
160
- }
161
-
162
- // 恢复色弱模式
163
- if (state.weakMode) {
164
- changeWeakMode(true);
165
- }
166
-
167
- // 恢复上次主题色
168
- if (state.color || state.darkMode) {
169
- window.addEventListener('load', () => {
170
- doChangeTheme(state.color, state.darkMode).catch((e) => {
171
- console.error(e);
172
- });
173
- });
174
- }
175
- return state;
176
- }
177
-
178
- /**
179
- * 切换主题
180
- * @param value 主题
181
- * @param dark 是否是暗黑模式
182
- * @returns {Promise<>}
183
- */
184
- function doChangeTheme(value, dark) {
185
- return new Promise((resolve, reject) => {
186
- try {
187
- changeColor(value, dark);
188
- resolve();
189
- } catch (e) {
190
- reject(e);
191
- }
192
- });
193
- }
194
-
195
- /**
196
- * 开关色弱模式
197
- * @param weakMode 是否开启色弱模式
198
- */
199
- function changeWeakMode(weakMode) {
200
- const weakClass = 'ele-admin-weak';
201
- if (weakMode) {
202
- document.body.classList.add(weakClass);
203
- } else {
204
- document.body.classList.remove(weakClass);
205
- }
206
- }
207
-
208
- /**
209
- * 获取需要keep-alive的组件
210
- * @param tabs 页签数据
211
- * @param homeComponents 主页组件
212
- * @returns {any[]}
213
- */
214
- function getKeepAliveInclude(tabs, homeComponents) {
215
- const components = new Set();
216
- if (tabs) {
217
- tabs.forEach((t) => {
218
- if (t?.components?.length) {
219
- t.components.forEach((c) => {
220
- if (typeof c === 'string' && c) {
221
- components.add(c);
222
- }
223
- });
224
- }
225
- });
226
- }
227
- if (homeComponents) {
228
- homeComponents.forEach((c) => {
229
- components.add(c);
230
- });
231
- }
232
- return Array.from(components);
233
- }
234
-
235
- export default {
236
- namespaced: true,
237
- state: getState(),
238
- mutations: {
239
- // 修改state值
240
- SET: function(state, obj) {
241
- if (DISABLED_TRANSITIONS.includes(obj.key)) {
242
- document.body.classList.add('ele-transition-disabled');
243
- setTimeout(() => {
244
- document.body.classList.remove('ele-transition-disabled');
245
- }, 100);
246
- }
247
- state[obj.key] = obj.value;
248
- // 缓存修改的配置
249
- cacheSetting(THEME_STORE_NAME, obj.key, obj.value);
250
- },
251
- // 更新屏幕尺寸
252
- UPDATE_SCREEN(state) {
253
- const w =
254
- document.documentElement.clientWidth || document.body.clientWidth;
255
- const h =
256
- document.documentElement.clientHeight || document.body.clientHeight;
257
- state.screenWidth = w;
258
- state.screenHeight = h;
259
- },
260
- // 更新内容区域宽度
261
- UPDATE_CONTENT_WIDTH(state) {
262
- state.contentWidth =
263
- document.querySelector('.ele-admin-content-view')?.clientWidth || 0;
264
- },
265
- // 更新keepAliveInclude
266
- UPDATE_KEEP_ALIVE_INCLUDE: function(state) {
267
- if (state.showTabs && TAB_KEEP_ALIVE) {
268
- state.keepAliveInclude = getKeepAliveInclude(
269
- state.tabs,
270
- state.homeComponents
271
- );
272
- } else {
273
- state.keepAliveInclude = [];
274
- }
275
- }
276
- },
277
- actions: {
278
- /**
279
- * 修改配置
280
- * @param {commit}
281
- * @param obj
282
- */
283
- set({ commit }, obj) {
284
- commit('SET', obj);
285
- if (obj.key === 'showTabs') {
286
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
287
- }
288
- updateSizeTimer && clearTimeout(updateSizeTimer);
289
- updateSizeTimer = setTimeout(
290
- function() {
291
- commit('UPDATE_CONTENT_WIDTH');
292
- },
293
- obj.key === 'collapse' ? 360 : 100
294
- );
295
- },
296
- /**
297
- * 切换配置(boolean类型的配置)
298
- * @param {commit, state}
299
- * @param key 配置名称
300
- */
301
- toggle({ commit, state }, key) {
302
- commit('SET', { key: key, value: !state[key] });
303
- updateSizeTimer && clearTimeout(updateSizeTimer);
304
- updateSizeTimer = setTimeout(
305
- function() {
306
- commit('UPDATE_CONTENT_WIDTH');
307
- },
308
- key === 'collapse' ? 360 : 100
309
- );
310
- },
311
- /**
312
- * 切换主题色
313
- * @param {commit, state}
314
- * @param value 颜色值
315
- * @returns {Promise<>}
316
- */
317
- setColor({ commit, state }, value) {
318
- return new Promise((resolve, reject) => {
319
- doChangeTheme(value, state.darkMode)
320
- .then(() => {
321
- commit('SET', { key: 'color', value: value });
322
- return resolve();
323
- })
324
- .catch((e) => {
325
- reject(e);
326
- });
327
- });
328
- },
329
- /**
330
- * 切换暗黑模式
331
- * @param {commit, state}
332
- * @param value 是否开启暗黑模式
333
- * @returns {Promise<>}
334
- */
335
- setDarkMode({ commit, state }, value) {
336
- return new Promise((resolve, reject) => {
337
- doChangeTheme(state.color, value)
338
- .then(() => {
339
- commit('SET', { key: 'darkMode', value: value });
340
- return resolve();
341
- })
342
- .catch((e) => {
343
- reject(e);
344
- });
345
- });
346
- },
347
- /**
348
- * 切换色弱模式
349
- * @param {commit}
350
- * @param value 是否开启色弱模式
351
- * @returns {Promise<>}
352
- */
353
- setWeakMode({ commit }, value) {
354
- return new Promise((resolve) => {
355
- changeWeakMode(value);
356
- commit('SET', { key: 'weakMode', value: value });
357
- resolve();
358
- });
359
- },
360
- /**
361
- * 更新屏幕尺寸
362
- * @param {commit, state}
363
- */
364
- updateScreen({ commit }) {
365
- commit('UPDATE_SCREEN');
366
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
367
- commit('UPDATE_CONTENT_WIDTH');
368
- },
369
- /**
370
- * 重置设置
371
- */
372
- resetSetting({ commit }) {
373
- const excludes = [
374
- 'weakMode',
375
- 'darkMode',
376
- 'color',
377
- 'collapse',
378
- 'tabs',
379
- 'homeComponents',
380
- 'keepAliveInclude',
381
- 'keepAliveExclude',
382
- 'screenWidth',
383
- 'screenHeight',
384
- 'contentWidth'
385
- ];
386
- Object.keys(DEFAULT_STATE).forEach((key) => {
387
- if (!excludes.includes(key)) {
388
- commit('SET', { key: key, value: DEFAULT_STATE[key] });
389
- updateSizeTimer && clearTimeout(updateSizeTimer);
390
- updateSizeTimer = setTimeout(function() {
391
- commit('UPDATE_CONTENT_WIDTH');
392
- }, 100);
393
- }
394
- });
395
- },
396
- /**
397
- * 添加tab
398
- * @param {commit, state}
399
- * @param obj {Object}
400
- */
401
- tabAdd({ commit, state }, obj) {
402
- if (!obj.key) {
403
- obj.key = obj.fullPath || obj.path;
404
- }
405
- const i = state.tabs.findIndex((d) => d.key === obj.key);
406
- if (i === -1) {
407
- commit('SET', { key: 'tabs', value: state.tabs.concat([obj]) });
408
- } else if (obj.fullPath !== state.tabs[i].fullPath) {
409
- const tabs = state.tabs
410
- .slice(0, i)
411
- .concat([obj])
412
- .concat(state.tabs.slice(i + 1));
413
- commit('SET', { key: 'tabs', value: tabs });
414
- }
415
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
416
- },
417
- /**
418
- * 移除指定tab
419
- * @param commit
420
- * @param state
421
- * @param key {String}
422
- * @returns {Promise<Object>}
423
- */
424
- tabRemove({ commit, state }, key) {
425
- return new Promise((resolve) => {
426
- let index = -1,
427
- lastIndex = -1,
428
- lastPath,
429
- last;
430
- for (let i = 0; i < state.tabs.length; i++) {
431
- if (state.tabs[i].key === key || state.tabs[i].fullPath === key) {
432
- index = i;
433
- break;
434
- }
435
- lastIndex = i;
436
- last = state.tabs[i];
437
- lastPath = last.fullPath;
438
- }
439
- commit('SET', {
440
- key: 'tabs',
441
- value: state.tabs.filter((d, i) => i !== index)
442
- });
443
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
444
- resolve({ lastIndex: lastIndex, lastPath: lastPath, last: last });
445
- });
446
- },
447
- /**
448
- * 移除所有tab
449
- * @param commit
450
- */
451
- tabRemoveAll({ commit }) {
452
- commit('SET', { key: 'tabs', value: [] });
453
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
454
- },
455
- /**
456
- * 移除左侧tab
457
- * @param commit
458
- * @param state
459
- * @param key {String}
460
- */
461
- tabRemoveLeft({ commit, state }, key) {
462
- for (let i = 0; i < state.tabs.length; i++) {
463
- if (state.tabs[i].key === key) {
464
- commit('SET', { key: 'tabs', value: state.tabs.slice(i) });
465
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
466
- break;
467
- }
468
- }
469
- },
470
- /**
471
- * 移除右侧tab
472
- * @param commit
473
- * @param state
474
- * @param key {String}
475
- */
476
- tabRemoveRight({ commit, state }, key) {
477
- for (let i = 0; i < state.tabs.length; i++) {
478
- if (state.tabs[i].key === key) {
479
- commit('SET', { key: 'tabs', value: state.tabs.slice(0, i + 1) });
480
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
481
- break;
482
- }
483
- }
484
- },
485
- /**
486
- * 移除其他tab
487
- * @param commit
488
- * @param state
489
- * @param key {String}
490
- */
491
- tabRemoveOther({ commit, state }, key) {
492
- commit('SET', {
493
- key: 'tabs',
494
- value: state.tabs.filter((d) => d.key === key)
495
- });
496
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
497
- },
498
- /**
499
- * 修改指定tab
500
- * @param commit
501
- * @param state
502
- * @param obj {Object}
503
- */
504
- tabSetTitle({ commit, state }, obj) {
505
- let i = -1;
506
- if (obj.fullPath) {
507
- i = state.tabs.findIndex((d) => d.fullPath === obj.fullPath);
508
- } else if (obj.path) {
509
- i = state.tabs.findIndex((d) => d.path === obj.path);
510
- }
511
- if (i !== -1) {
512
- const data = Object.assign({}, state.tabs[i]);
513
- if (typeof obj.title === 'string' && obj.title) {
514
- data.title = obj.title;
515
- }
516
- if (typeof obj.closable === 'boolean') {
517
- data.closable = obj.closable;
518
- }
519
- const tabs = state.tabs
520
- .slice(0, i)
521
- .concat([data])
522
- .concat(state.tabs.slice(i + 1));
523
- commit('SET', { key: 'tabs', value: tabs });
524
- }
525
- },
526
- /**
527
- * 设置主页的组件名称
528
- * @param {commit, state}
529
- * @param components {Array}
530
- */
531
- setHomeComponents({ commit }, components) {
532
- commit('SET', { key: 'homeComponents', value: components });
533
- commit('UPDATE_KEEP_ALIVE_INCLUDE');
534
- },
535
- /**
536
- * 设置不需要keep-alive的组件
537
- * @param commit
538
- * @param value {Array}
539
- */
540
- setKeepAliveExclude({ commit }, value) {
541
- commit('SET', { key: 'keepAliveExclude', value: value });
542
- }
543
- }
544
- };
@@ -1,74 +0,0 @@
1
- /**
2
- * 登录状态管理
3
- */
4
- import { formatMenus, toTreeData } from 'ele-admin';
5
- import { USER_MENUS } from '@/config/setting';
6
-
7
- export default {
8
- namespaced: true,
9
- state: {
10
- // 当前登录用户信息
11
- info: null,
12
- // 当前登录用户的菜单
13
- menus: null,
14
- // 当前登录用户的权限
15
- authorities: [],
16
- // 当前登录用户的角色
17
- roles: []
18
- },
19
- mutations: {
20
- // 设置登录用户的信息
21
- setUserInfo(state, info) {
22
- state.info = info;
23
- },
24
- // 设置登录用户的菜单
25
- setMenus(state, menus) {
26
- state.menus = menus;
27
- },
28
- // 设置登录用户的权限
29
- setAuthorities(state, authorities) {
30
- state.authorities = authorities;
31
- },
32
- // 设置登录用户的角色
33
- setRoles(state, roles) {
34
- state.roles = roles;
35
- }
36
- },
37
- actions: {
38
- /**
39
- * 请求用户信息、权限、角色、菜单
40
- * @param commit
41
- * @returns {Promise}
42
- */
43
- fetchUserInfo() {
44
- // return new Promise((resolve, reject) => {
45
- // getUserInfo()
46
- // .then((result) => {
47
- // // 用户信息
48
- // commit('setUserInfo', result);
49
- // // 用户权限
50
- // const authorities = result.authorities
51
- // ?.filter((d) => !!d.authority)
52
- // ?.map((d) => d.authority);
53
- // commit('setAuthorities', authorities);
54
- // // 用户角色
55
- // const roles = result.roles?.map((d) => d.roleCode);
56
- // commit('setRoles', roles);
57
- // // 用户菜单
58
- // const menuData = toTreeData({
59
- // data: result.authorities?.filter((d) => d.menuType === 0), // 过滤掉按钮类型的菜单
60
- // idField: 'menuId',
61
- // parentIdField: 'parentId'
62
- // });
63
- // // 处理菜单数据格式
64
- // const { menus, homePath } = formatMenus(USER_MENUS ?? menuData);
65
- // commit('setMenus', menus);
66
- // resolve({ menus, homePath });
67
- // })
68
- // .catch((e) => {
69
- // reject(e);
70
- // });
71
- // });
72
- }
73
- }
74
- };
@@ -1,4 +0,0 @@
1
- import { required, formType, column } from './decorators/index.js';
2
- import columnFactory from './column/index.js';
3
-
4
- export { required, formType, column, columnFactory };