vue2-client 1.10.32-alpha → 1.10.32-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue2-client",
3
- "version": "1.10.32-alpha",
3
+ "version": "1.10.32-alpha.1",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "serve": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve --no-eslint",
package/src/App.vue CHANGED
@@ -1,183 +1,196 @@
1
- <template>
2
- <a-config-provider :locale="locale" :get-popup-container="popContainer">
3
- <router-view/>
4
- </a-config-provider>
5
- </template>
6
-
7
- <script>
8
- import { enquireScreen } from '@vue2-client/utils/util'
9
- import { mapState, mapMutations } from 'vuex'
10
- import themeUtil from '@vue2-client/utils/themeUtil'
11
- import { getI18nKey } from '@vue2-client/utils/routerUtil'
12
- import { setSystemVersion } from '@vue2-client/utils/request'
13
- import waterMark from '@vue2-client/utils/waterMark'
14
-
15
- export default {
16
- name: 'App',
17
- data () {
18
- return {
19
- locale: {}
20
- }
21
- },
22
- created () {
23
- this.setHtmlTitle()
24
- this.setLanguage(this.lang)
25
- enquireScreen(isMobile => this.setDevice(isMobile))
26
- },
27
- mounted () {
28
- this.setWeekModeTheme(this.weekMode)
29
- const configStr = localStorage.getItem(process.env.VUE_APP_WEB_CONFIG_KEY)
30
- if (configStr) {
31
- const config = JSON.parse(configStr)
32
- if (config?.$globalProp?.environment === 'dev') {
33
- // 设置水印
34
- waterMark('开发环境')
35
- }
36
- }
37
- // 设置系统版本
38
- setSystemVersion(this.compatible)
39
- // 获取基座应用的信息进行初始化
40
- this.setMicroApp()
41
- },
42
- watch: {
43
- weekMode (val) {
44
- this.setWeekModeTheme(val)
45
- },
46
- lang (val) {
47
- this.setLanguage(val)
48
- this.setHtmlTitle()
49
- },
50
- $route () {
51
- this.setHtmlTitle()
52
- },
53
- 'theme.mode': {
54
- immediate: true,
55
- handler: function (val) {
56
- this.changeThemeMode(val)
57
- }
58
- },
59
- 'theme.color': {
60
- immediate: true,
61
- handler: function (val) {
62
- this.changeThemeColor(val)
63
- }
64
- },
65
- layout: function () {
66
- window.dispatchEvent(new Event('resize'))
67
- }
68
- },
69
- computed: {
70
- ...mapState('setting', ['layout', 'theme', 'weekMode', 'lang', 'compatible'])
71
- },
72
- methods: {
73
- ...mapMutations('setting', ['setDevice']),
74
- changeThemeColor (val) {
75
- if (process.env.NODE_ENV === 'production') {
76
- const closeMessage = this.$message.loading(`您选择了主题色 ${val}, 正在切换...`)
77
- themeUtil.changeThemeColor(val, this.theme.mode).then(closeMessage)
78
- } else {
79
- console.info('为保证构建性能,关闭开发环境下的主题色切换')
80
- }
81
- },
82
- changeThemeMode (val) {
83
- if (process.env.NODE_ENV === 'production') {
84
- const closeMessage = this.$message.loading(`您选择了主题模式 ${val}, 正在切换...`)
85
- themeUtil.changeThemeColor(this.theme.color, val).then(closeMessage)
86
- } else {
87
- console.info('为保证构建性能,关闭开发环境下的主题模式切换')
88
- }
89
- },
90
- setWeekModeTheme (weekMode) {
91
- if (weekMode) {
92
- document.body.classList.add('week-mode')
93
- } else {
94
- document.body.classList.remove('week-mode')
95
- }
96
- },
97
- setMicroApp () {
98
- const that = this
99
- if (window.__MICRO_APP_ENVIRONMENT__) {
100
- const data = window.microApp.getData()
101
- this.setMicroAppTheme(data.themeStore)
102
- window.microApp.addDataListener((_data) => {
103
- that.setMicroAppTheme(_data.themeStore)
104
- })
105
- }
106
- },
107
- setMicroAppTheme (themeStore) {
108
- try {
109
- let themeScheme = 'dark'
110
- if (themeStore && themeStore.themeColor && themeStore.themeScheme) {
111
- if (themeStore.themeScheme === 'dark') {
112
- themeScheme = 'night'
113
- }
114
- themeUtil.changeThemeColor(themeStore.themeColor, themeScheme)
115
- }
116
- } catch (e) {
117
- }
118
- },
119
- setLanguage (lang) {
120
- this.$i18n.locale = lang
121
- switch (lang) {
122
- case 'CN':
123
- this.locale = require('ant-design-vue/es/locale-provider/zh_CN').default
124
- break
125
- case 'HK':
126
- this.locale = require('ant-design-vue/es/locale-provider/zh_TW').default
127
- break
128
- case 'US':
129
- default:
130
- this.locale = require('ant-design-vue/es/locale-provider/en_US').default
131
- break
132
- }
133
- },
134
- setHtmlTitle () {
135
- // 微应用下不设置title
136
- if (window.__MICRO_APP_ENVIRONMENT__) {
137
- return
138
- }
139
- const route = this.$route
140
- const key = route.path === '/' ? 'home.name' : getI18nKey(route.matched[route.matched.length - 1].path)
141
- document.title = process.env.VUE_APP_NAME + ' | ' + this.$t(key)
142
- },
143
- popContainer () {
144
- return document.getElementById('popContainer')
145
- }
146
- }
147
- }
148
- </script>
149
-
150
- <style lang="less" scoped>
151
- #id {
152
- }
153
- </style>
154
- <style lang="less">
155
- @import "./font-style/font.css";
156
-
157
- body {
158
- font-family: 'PingFangSC-Regular-woff2', 'Microsoft YaHei UI', serif !important;
159
- }
160
-
161
- .water-mark-wrap {
162
- position: absolute;
163
- width: 100%;
164
- height: 100%;
165
- z-index: 9999;
166
- pointer-events: none;
167
- top: 0;
168
- left: 0;
169
- display: flex;
170
- overflow: hidden;
171
- flex-wrap: wrap;
172
- }
173
-
174
- .water-word {
175
- display: flex;
176
- align-items: center;
177
- justify-content: center;
178
- font-size: 18px;
179
- color: rgba(8, 8, 8, 0.1);
180
- transform: rotate(-45deg);
181
- user-select: none;
182
- }
183
- </style>
1
+ <template>
2
+ <a-config-provider :locale="locale" :get-popup-container="popContainer">
3
+ <router-view/>
4
+ </a-config-provider>
5
+ </template>
6
+
7
+ <script>
8
+ import { enquireScreen } from '@vue2-client/utils/util'
9
+ import { mapState, mapMutations } from 'vuex'
10
+ import themeUtil from '@vue2-client/utils/themeUtil'
11
+ import { getI18nKey } from '@vue2-client/utils/routerUtil'
12
+ import { setSystemVersion } from '@vue2-client/utils/request'
13
+ import waterMark from '@vue2-client/utils/waterMark'
14
+ import { isMicroAppEnv } from '@vue2-client/utils/microAppUtils'
15
+
16
+ export default {
17
+ name: 'App',
18
+ data () {
19
+ return {
20
+ locale: {}
21
+ }
22
+ },
23
+ created () {
24
+ this.setHtmlTitle()
25
+ this.setLanguage(this.lang)
26
+ enquireScreen(isMobile => this.setDevice(isMobile))
27
+ },
28
+ mounted () {
29
+ this.setWeekModeTheme(this.weekMode)
30
+ const configStr = localStorage.getItem(process.env.VUE_APP_WEB_CONFIG_KEY)
31
+ if (configStr) {
32
+ const config = JSON.parse(configStr)
33
+ if (config?.$globalProp?.environment === 'dev') {
34
+ // 设置水印
35
+ waterMark('开发环境')
36
+ }
37
+ }
38
+ // 设置系统版本
39
+ setSystemVersion(this.compatible)
40
+ // 获取基座应用的信息进行初始化
41
+ this.setMicroApp()
42
+ },
43
+ watch: {
44
+ weekMode (val) {
45
+ this.setWeekModeTheme(val)
46
+ },
47
+ lang (val) {
48
+ this.setLanguage(val)
49
+ this.setHtmlTitle()
50
+ },
51
+ $route () {
52
+ this.setHtmlTitle()
53
+ },
54
+ 'theme.mode': {
55
+ immediate: true,
56
+ handler: function (val) {
57
+ this.changeThemeMode(val)
58
+ }
59
+ },
60
+ 'theme.color': {
61
+ immediate: true,
62
+ handler: function (val) {
63
+ this.changeThemeColor(val)
64
+ }
65
+ },
66
+ layout: function () {
67
+ window.dispatchEvent(new Event('resize'))
68
+ }
69
+ },
70
+ computed: {
71
+ ...mapState('setting', ['layout', 'theme', 'weekMode', 'lang', 'compatible'])
72
+ },
73
+ methods: {
74
+ ...mapMutations('setting', ['setDevice']),
75
+ changeThemeColor (val) {
76
+ if (process.env.NODE_ENV === 'production') {
77
+ const closeMessage = this.$message.loading(`您选择了主题色 ${val}, 正在切换...`)
78
+ themeUtil.changeThemeColor(val, this.theme.mode).then(closeMessage)
79
+ } else {
80
+ console.info('为保证构建性能,关闭开发环境下的主题色切换')
81
+ }
82
+ },
83
+ changeThemeMode (val) {
84
+ if (process.env.NODE_ENV === 'production') {
85
+ const closeMessage = this.$message.loading(`您选择了主题模式 ${val}, 正在切换...`)
86
+ themeUtil.changeThemeColor(this.theme.color, val).then(closeMessage)
87
+ } else {
88
+ console.info('为保证构建性能,关闭开发环境下的主题模式切换')
89
+ }
90
+ },
91
+ setWeekModeTheme (weekMode) {
92
+ if (weekMode) {
93
+ document.body.classList.add('week-mode')
94
+ } else {
95
+ document.body.classList.remove('week-mode')
96
+ }
97
+ },
98
+ setMicroApp () {
99
+ let baseApp = '/login'
100
+ let queryData = {}
101
+ const that = this
102
+ if (isMicroAppEnv()) {
103
+ const data = window.microApp.getData() // 获取主应用下发的data数据
104
+ if (data.baseroute) {
105
+ baseApp = data.baseroute
106
+ } // 获取主应用下发的data数据
107
+ if (data.queryData) {
108
+ queryData = data.queryData
109
+ }
110
+ this.setMicroAppTheme(data.themeStore)
111
+ window.microApp.addDataListener((_data) => {
112
+ if (_data.baseroute) {
113
+ baseApp = _data.baseroute
114
+ }
115
+ that.setMicroAppTheme(_data.themeStore)
116
+ })
117
+ this.$router.replace({ path: baseApp, query: queryData })
118
+ }
119
+ },
120
+ setMicroAppTheme (themeStore) {
121
+ try {
122
+ let themeScheme = 'dark'
123
+ if (themeStore && themeStore.themeColor && themeStore.themeScheme) {
124
+ if (themeStore.themeScheme === 'dark') {
125
+ themeScheme = 'night'
126
+ }
127
+ themeUtil.changeThemeColor(themeStore.themeColor, themeScheme)
128
+ }
129
+ } catch (e) {
130
+ }
131
+ },
132
+ setLanguage (lang) {
133
+ this.$i18n.locale = lang
134
+ switch (lang) {
135
+ case 'CN':
136
+ this.locale = require('ant-design-vue/es/locale-provider/zh_CN').default
137
+ break
138
+ case 'HK':
139
+ this.locale = require('ant-design-vue/es/locale-provider/zh_TW').default
140
+ break
141
+ case 'US':
142
+ default:
143
+ this.locale = require('ant-design-vue/es/locale-provider/en_US').default
144
+ break
145
+ }
146
+ },
147
+ setHtmlTitle () {
148
+ // 微应用下不设置title
149
+ if (window.__MICRO_APP_ENVIRONMENT__) {
150
+ return
151
+ }
152
+ const route = this.$route
153
+ const key = route.path === '/' ? 'home.name' : getI18nKey(route.matched[route.matched.length - 1].path)
154
+ document.title = process.env.VUE_APP_NAME + ' | ' + this.$t(key)
155
+ },
156
+ popContainer () {
157
+ return document.getElementById('popContainer')
158
+ }
159
+ }
160
+ }
161
+ </script>
162
+
163
+ <style lang="less" scoped>
164
+ #id {
165
+ }
166
+ </style>
167
+ <style lang="less">
168
+ @import "./font-style/font.css";
169
+
170
+ body {
171
+ font-family: 'PingFangSC-Regular-woff2', 'Microsoft YaHei UI', serif !important;
172
+ }
173
+
174
+ .water-mark-wrap {
175
+ position: absolute;
176
+ width: 100%;
177
+ height: 100%;
178
+ z-index: 9999;
179
+ pointer-events: none;
180
+ top: 0;
181
+ left: 0;
182
+ display: flex;
183
+ overflow: hidden;
184
+ flex-wrap: wrap;
185
+ }
186
+
187
+ .water-word {
188
+ display: flex;
189
+ align-items: center;
190
+ justify-content: center;
191
+ font-size: 18px;
192
+ color: rgba(8, 8, 8, 0.1);
193
+ transform: rotate(-45deg);
194
+ user-select: none;
195
+ }
196
+ </style>
@@ -108,7 +108,7 @@ export default {
108
108
  methods: {
109
109
  getFlex (parentWidth, flex = defaultFlex) {
110
110
  if (parentWidth === 0) {
111
- return flex.xs
111
+ return flex.md
112
112
  }
113
113
  if (parentWidth < BREAKPOINTS.xs) return flex.xs
114
114
  if (parentWidth < BREAKPOINTS.sm) return flex.sm
@@ -1,172 +1,179 @@
1
- import { isDef, isRegExp, remove } from '@vue2-client/utils/util'
2
-
3
- const patternTypes = [String, RegExp, Array]
4
-
5
- function matches (pattern, name) {
6
- if (Array.isArray(pattern)) {
7
- if (pattern.indexOf(name) > -1) {
8
- return true
9
- } else {
10
- for (const item of pattern) {
11
- if (isRegExp(item) && item.test(name)) {
12
- return true
13
- }
14
- }
15
- return false
16
- }
17
- } else if (typeof pattern === 'string') {
18
- return pattern.split(',').indexOf(name) > -1
19
- } else if (isRegExp(pattern)) {
20
- return pattern.test(name)
21
- }
22
- /* istanbul ignore next */
23
- return false
24
- }
25
-
26
- function getComponentName (opts) {
27
- return opts && (opts.Ctor.options.name || opts.tag)
28
- }
29
-
30
- function getComponentKey (vnode) {
31
- const { componentOptions, key } = vnode
32
- return key == null
33
- ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
34
- : key + componentOptions.Ctor.cid
35
- }
36
-
37
- function getFirstComponentChild (children) {
38
- if (Array.isArray(children)) {
39
- for (let i = 0; i < children.length; i++) {
40
- const c = children[i]
41
- if (isDef(c) && (isDef(c.componentOptions) || c.isAsyncPlaceholder)) {
42
- return c
43
- }
44
- }
45
- }
46
- }
47
-
48
- function pruneCache (keepAliveInstance, filter) {
49
- const { cache, keys, _vnode } = keepAliveInstance
50
- for (const key in cache) {
51
- const cachedNode = cache[key]
52
- if (cachedNode) {
53
- const name = getComponentName(cachedNode.componentOptions)
54
- const componentKey = getComponentKey(cachedNode)
55
- if (name && !filter(name, componentKey)) {
56
- pruneCacheEntry(cache, key, keys, _vnode)
57
- }
58
- }
59
- }
60
- }
61
-
62
- function pruneCacheEntry2 (cache, key, keys) {
63
- const cached = cache[key]
64
- if (cached) {
65
- cached.componentInstance.$destroy()
66
- }
67
- cache[key] = null
68
- remove(keys, key)
69
- }
70
-
71
- function pruneCacheEntry (cache, key, keys, current) {
72
- const cached = cache[key]
73
- if (cached && (!current || cached.tag !== current.tag)) {
74
- cached.componentInstance.$destroy()
75
- }
76
- cache[key] = null
77
- remove(keys, key)
78
- }
79
-
80
- export default {
81
- name: 'AKeepAlive',
82
- abstract: true,
83
- model: {
84
- prop: 'clearCaches',
85
- event: 'clear'
86
- },
87
- props: {
88
- include: patternTypes,
89
- exclude: patternTypes,
90
- excludeKeys: patternTypes,
91
- max: [String, Number],
92
- clearCaches: Array
93
- },
94
- watch: {
95
- clearCaches: function (val) {
96
- if (val && val.length > 0) {
97
- const { cache, keys } = this
98
- val.forEach(key => {
99
- pruneCacheEntry2(cache, key, keys)
100
- })
101
- this.$emit('clear', [])
102
- }
103
- }
104
- },
105
-
106
- created () {
107
- this.cache = Object.create(null)
108
- this.keys = []
109
- },
110
-
111
- destroyed () {
112
- for (const key in this.cache) {
113
- pruneCacheEntry(this.cache, key, this.keys)
114
- }
115
- },
116
-
117
- mounted () {
118
- this.$watch('include', val => {
119
- pruneCache(this, (name) => matches(val, name))
120
- })
121
- this.$watch('exclude', val => {
122
- pruneCache(this, (name) => !matches(val, name))
123
- })
124
- this.$watch('excludeKeys', val => {
125
- pruneCache(this, (name, key) => !matches(val, key))
126
- })
127
- },
128
-
129
- render () {
130
- const slot = this.$slots.default
131
- const vnode = getFirstComponentChild(slot)
132
- const componentOptions = vnode && vnode.componentOptions
133
- if (componentOptions) {
134
- // check pattern
135
- const name = getComponentName(componentOptions)
136
- const componentKey = getComponentKey(vnode)
137
- const { include, exclude, excludeKeys } = this
138
- if (
139
- // not included
140
- (include && (!name || !matches(include, name))) ||
141
- // excluded
142
- (exclude && name && matches(exclude, name)) ||
143
- (excludeKeys && componentKey && matches(excludeKeys, componentKey))
144
- ) {
145
- return vnode
146
- }
147
-
148
- const { cache, keys } = this
149
- const key = vnode.key == null
150
- // same constructor may get registered as different local components
151
- // so cid alone is not enough (#3269)
152
- ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
153
- : vnode.key + componentOptions.Ctor.cid
154
- if (cache[key]) {
155
- vnode.componentInstance = cache[key].componentInstance
156
- // make current key freshest
157
- remove(keys, key)
158
- keys.push(key)
159
- } else {
160
- cache[key] = vnode
161
- keys.push(key)
162
- // prune oldest entry
163
- if (this.max && keys.length > parseInt(this.max)) {
164
- pruneCacheEntry(cache, keys[0], keys, this._vnode)
165
- }
166
- }
167
-
168
- vnode.data.keepAlive = true
169
- }
170
- return vnode || (slot && slot[0])
171
- }
172
- }
1
+ import { isDef, isRegExp, remove } from '@vue2-client/utils/util'
2
+
3
+ const patternTypes = [String, RegExp, Array]
4
+
5
+ function matches (pattern, name) {
6
+ if (Array.isArray(pattern)) {
7
+ if (pattern.indexOf(name) > -1) {
8
+ return true
9
+ } else {
10
+ for (const item of pattern) {
11
+ if (isRegExp(item) && item.test(name)) {
12
+ return true
13
+ }
14
+ }
15
+ return false
16
+ }
17
+ } else if (typeof pattern === 'string') {
18
+ return pattern.split(',').indexOf(name) > -1
19
+ } else if (isRegExp(pattern)) {
20
+ return pattern.test(name)
21
+ }
22
+ /* istanbul ignore next */
23
+ return false
24
+ }
25
+
26
+ function getComponentName (opts) {
27
+ return opts && (opts.Ctor.options.name || opts.tag)
28
+ }
29
+
30
+ function getComponentKey (vnode) {
31
+ const { componentOptions, key } = vnode
32
+ return key == null
33
+ ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
34
+ : key + `::${componentOptions.Ctor.cid}`
35
+ }
36
+
37
+ function getFirstComponentChild (children) {
38
+ if (Array.isArray(children)) {
39
+ for (let i = 0; i < children.length; i++) {
40
+ const c = children[i]
41
+ if (isDef(c) && (isDef(c.componentOptions) || c.isAsyncPlaceholder)) {
42
+ return c
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ function pruneCache (keepAliveInstance, filter) {
49
+ const { cache, keys, _vnode } = keepAliveInstance
50
+ for (const key in cache) {
51
+ const cachedNode = cache[key]
52
+ if (cachedNode) {
53
+ const name = getComponentName(cachedNode.componentOptions)
54
+ const componentKey = getComponentKey(cachedNode)
55
+ if (name && !filter(name, componentKey)) {
56
+ pruneCacheEntry(cache, key, keys, _vnode)
57
+ }
58
+ }
59
+ }
60
+ }
61
+
62
+ function pruneCacheEntry2 (cache, key, keys) {
63
+ const cached = cache[key]
64
+ if (cached) {
65
+ cached.componentInstance.$destroy()
66
+ }
67
+ cache[key] = null
68
+ remove(keys, key)
69
+ }
70
+
71
+ function pruneCacheEntry (cache, key, keys, current) {
72
+ const cached = cache[key]
73
+ if (cached && (!current || cached.tag !== current.tag)) {
74
+ cached.componentInstance.$destroy()
75
+ }
76
+ cache[key] = null
77
+ remove(keys, key)
78
+ }
79
+
80
+ export default {
81
+ name: 'AKeepAlive',
82
+ abstract: true,
83
+ model: {
84
+ prop: 'clearCaches',
85
+ event: 'clear'
86
+ },
87
+ props: {
88
+ include: patternTypes,
89
+ exclude: patternTypes,
90
+ excludeKeys: patternTypes,
91
+ max: [String, Number],
92
+ clearCaches: Array
93
+ },
94
+ watch: {
95
+ clearCaches: function (val) {
96
+ if (val && val.length > 0) {
97
+ const { cache, keys } = this
98
+ // 遍历所有缓存的 keys,找到以传入的 key 开头的项进行清除
99
+ keys.forEach(cacheKey => {
100
+ val.forEach(targetKey => {
101
+ // 检查缓存的 key 是否以目标 key 开头
102
+ console.warn('clearCaches:', cacheKey, targetKey, cacheKey.includes(`${targetKey}::`) || cacheKey.startsWith(targetKey))
103
+ if (cacheKey.includes(`${targetKey}::`) || cacheKey.startsWith(targetKey)) {
104
+ pruneCacheEntry2(cache, cacheKey, keys)
105
+ }
106
+ })
107
+ })
108
+ this.$emit('clear', [])
109
+ }
110
+ }
111
+ },
112
+
113
+ created () {
114
+ this.cache = Object.create(null)
115
+ this.keys = []
116
+ },
117
+
118
+ destroyed () {
119
+ for (const key in this.cache) {
120
+ pruneCacheEntry(this.cache, key, this.keys)
121
+ }
122
+ },
123
+
124
+ mounted () {
125
+ this.$watch('include', val => {
126
+ pruneCache(this, (name) => matches(val, name))
127
+ })
128
+ this.$watch('exclude', val => {
129
+ pruneCache(this, (name) => !matches(val, name))
130
+ })
131
+ this.$watch('excludeKeys', val => {
132
+ pruneCache(this, (name, key) => !matches(val, key))
133
+ })
134
+ },
135
+
136
+ render () {
137
+ const slot = this.$slots.default
138
+ const vnode = getFirstComponentChild(slot)
139
+ const componentOptions = vnode && vnode.componentOptions
140
+ if (componentOptions) {
141
+ // check pattern
142
+ const name = getComponentName(componentOptions)
143
+ const componentKey = getComponentKey(vnode)
144
+ const { include, exclude, excludeKeys } = this
145
+ if (
146
+ // not included
147
+ (include && (!name || !matches(include, name))) ||
148
+ // excluded
149
+ (exclude && name && matches(exclude, name)) ||
150
+ (excludeKeys && componentKey && matches(excludeKeys, componentKey))
151
+ ) {
152
+ return vnode
153
+ }
154
+
155
+ const { cache, keys } = this
156
+ const key = vnode.key == null
157
+ // same constructor may get registered as different local components
158
+ // so cid alone is not enough (#3269)
159
+ ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
160
+ : vnode.key + `::${componentOptions.Ctor.cid}`
161
+ if (cache[key]) {
162
+ vnode.componentInstance = cache[key].componentInstance
163
+ // make current key freshest
164
+ remove(keys, key)
165
+ keys.push(key)
166
+ } else {
167
+ cache[key] = vnode
168
+ keys.push(key)
169
+ // prune oldest entry
170
+ if (this.max && keys.length > parseInt(this.max)) {
171
+ pruneCacheEntry(cache, keys[0], keys, this._vnode)
172
+ }
173
+ }
174
+
175
+ vnode.data.keepAlive = true
176
+ }
177
+ return vnode || (slot && slot[0])
178
+ }
179
+ }
@@ -1,78 +1,78 @@
1
- <template>
2
- <page-toggle-transition :disabled="animate.disabled" :animate="animate.name" :direction="animate.direction">
3
- <a-keep-alive :exclude-keys="excludeKeys" v-if="cachePage" v-model="clearCaches">
4
- <router-view v-if="!refreshing" :key="$route.fullPath" />
5
- </a-keep-alive>
6
- <router-view v-else-if="!refreshing" />
7
- </page-toggle-transition>
8
- </template>
9
-
10
- <script>
11
- import PageToggleTransition from '../components/transition/PageToggleTransition'
12
- import { mapState } from 'vuex'
13
- import AKeepAlive from '@vue2-client/components/cache/AKeepAlive'
14
-
15
- export default {
16
- name: 'BlankView',
17
- components: { PageToggleTransition, AKeepAlive },
18
- data () {
19
- return {
20
- clearCaches: [],
21
- excludeKeys: [],
22
- refreshing: false
23
- }
24
- },
25
- computed: {
26
- ...mapState('setting', ['cachePage', 'animate'])
27
- },
28
- created () {
29
- this.loadCacheConfig(this.$router?.options?.routes)
30
- },
31
- mounted () {
32
- if (window.__MICRO_APP_ENVIRONMENT__) {
33
- window.microApp.addDataListener((data) => {
34
- if (data.type === 'refresh') {
35
- this.refresh()
36
- } else if (data.type === 'clearCache') {
37
- this.clearCache(data.key)
38
- }
39
- })
40
- }
41
- },
42
- methods: {
43
- // 加载需要排除缓存的路由配置
44
- loadCacheConfig (routes, pCache = true) {
45
- routes.forEach(item => {
46
- const cacheAble = item.meta?.page?.cacheAble ?? pCache ?? true
47
- if (!cacheAble) {
48
- this.excludeKeys.push(new RegExp(`${item.path.replace(/:[^/]*/g, '[^/]*')}(\\?.*)?\\d*$`))
49
- }
50
- if (item.children) {
51
- this.loadCacheConfig(item.children, cacheAble)
52
- }
53
- })
54
- },
55
- // 刷新页面方法
56
- refresh () {
57
- this.refreshing = true
58
- setTimeout(() => {
59
- this.refreshing = false
60
- }, 200)
61
- },
62
- // 清除特定页面的缓存
63
- clearCache (key) {
64
- this.clearCaches = [key]
65
- }
66
- },
67
- watch: {
68
- '$router.options.routes': function (val) {
69
- this.excludeKeys = []
70
- this.loadCacheConfig(val)
71
- }
72
- }
73
- }
74
- </script>
75
-
76
- <style scoped>
77
-
78
- </style>
1
+ <template>
2
+ <page-toggle-transition :disabled="animate.disabled" :animate="animate.name" :direction="animate.direction">
3
+ <a-keep-alive :exclude-keys="excludeKeys" v-if="cachePage" v-model="clearCaches">
4
+ <router-view v-if="!refreshing" :key="$route.path" />
5
+ </a-keep-alive>
6
+ <router-view v-else-if="!refreshing" />
7
+ </page-toggle-transition>
8
+ </template>
9
+
10
+ <script>
11
+ import PageToggleTransition from '../components/transition/PageToggleTransition'
12
+ import { mapState } from 'vuex'
13
+ import AKeepAlive from '@vue2-client/components/cache/AKeepAlive'
14
+
15
+ export default {
16
+ name: 'BlankView',
17
+ components: { PageToggleTransition, AKeepAlive },
18
+ data () {
19
+ return {
20
+ clearCaches: [],
21
+ excludeKeys: [],
22
+ refreshing: false
23
+ }
24
+ },
25
+ computed: {
26
+ ...mapState('setting', ['cachePage', 'animate'])
27
+ },
28
+ created () {
29
+ this.loadCacheConfig(this.$router?.options?.routes)
30
+ },
31
+ mounted () {
32
+ if (window.__MICRO_APP_ENVIRONMENT__) {
33
+ window.microApp.addDataListener((data) => {
34
+ if (data.type === 'refresh') {
35
+ this.refresh()
36
+ } else if (data.type === 'clearCache' && data.key) {
37
+ this.clearCache(data.key)
38
+ }
39
+ })
40
+ }
41
+ },
42
+ methods: {
43
+ // 加载需要排除缓存的路由配置
44
+ loadCacheConfig (routes, pCache = true) {
45
+ routes.forEach(item => {
46
+ const cacheAble = item.meta?.page?.cacheAble ?? pCache ?? true
47
+ if (!cacheAble) {
48
+ this.excludeKeys.push(new RegExp(`${item.path.replace(/:[^/]*/g, '[^/]*')}(\\?.*)?\\d*$`))
49
+ }
50
+ if (item.children) {
51
+ this.loadCacheConfig(item.children, cacheAble)
52
+ }
53
+ })
54
+ },
55
+ // 刷新页面方法
56
+ refresh () {
57
+ this.refreshing = true
58
+ setTimeout(() => {
59
+ this.refreshing = false
60
+ }, 200)
61
+ },
62
+ // 清除特定页面的缓存
63
+ clearCache (resultKeys) {
64
+ this.clearCaches = resultKeys
65
+ }
66
+ },
67
+ watch: {
68
+ '$router.options.routes': function (val) {
69
+ this.excludeKeys = []
70
+ this.loadCacheConfig(val)
71
+ }
72
+ }
73
+ }
74
+ </script>
75
+
76
+ <style scoped>
77
+
78
+ </style>
@@ -20,7 +20,7 @@ NProgress.configure({ showSpinner: false })
20
20
  * @param form
21
21
  * @param next
22
22
  */
23
- const progressStart = (to, from, next) => {
23
+ const progressStart = (to, form, next) => {
24
24
  // start progress bar
25
25
  if (!NProgress.isStarted()) {
26
26
  NProgress.start()
@@ -35,7 +35,10 @@ const progressStart = (to, from, next) => {
35
35
  * @param next
36
36
  * @param options
37
37
  */
38
- const loginGuard = (to, from, next, options) => {
38
+ const loginGuard = (to, form, next, options) => {
39
+ if (window.__MICRO_APP_ENVIRONMENT__) {
40
+ window.microApp.dispatch({ type: '子应用发送给主应用的数据', to: to.path })
41
+ }
39
42
  const urlParams = new URLSearchParams(window.location.search)
40
43
  const LoginTicket = urlParams.get('LoginTicket')
41
44
  // 如果是需要我们自己登陆的项目
@@ -169,12 +172,6 @@ const loginGuard = (to, from, next, options) => {
169
172
  if (!Vue.$store.state?.setting?.menuData || Vue.$store.state?.setting?.menuData?.length === 0) {
170
173
  loadRoutes(funcToRouter(v4LoginData.functions))
171
174
  }
172
-
173
- if (window.__MICRO_APP_ENVIRONMENT__) {
174
- window.microApp.forceDispatch({ type: 'microMounted', appName: window.__MICRO_APP_NAME__ })
175
- }
176
-
177
- console.warn(to.fullPath, from.fullPath)
178
175
  next()
179
176
  } else {
180
177
  const { store, message } = options
@@ -205,7 +202,7 @@ const loginGuard = (to, from, next, options) => {
205
202
  * @param next
206
203
  * @param options
207
204
  */
208
- const authorityGuard = (to, from, next, options) => {
205
+ const authorityGuard = (to, form, next, options) => {
209
206
  const { store, message } = options
210
207
  const permissions = store.getters['account/permissions']
211
208
  const roles = store.getters['account/roles']
@@ -251,9 +248,6 @@ const redirectGuard = (to, from, next, options) => {
251
248
 
252
249
  /**
253
250
  * 进度条结束
254
- * @param to
255
- * @param form
256
- * @param options
257
251
  */
258
252
  const progressDone = () => {
259
253
  // finish progress bar
@@ -6,6 +6,15 @@ export function getWindow () {
6
6
  return window
7
7
  }
8
8
 
9
+ /**
10
+ * 获取当前子应用的 name
11
+ * @returns {string} 子应用的 name
12
+ */
13
+ export function getMicroAppName () {
14
+ // 如果在微前端环境中运行,返回应用名称,否则返回 undefined
15
+ return window.__MICRO_APP_ENVIRONMENT__ ? window.__MICRO_APP_NAME__ : undefined
16
+ }
17
+
9
18
  /**
10
19
  * 判断是否处于 microApp 环境
11
20
  * @returns {boolean} 如果在 microApp 环境下返回 true,否则返回 false