web-component-gallery 2.1.19 → 2.1.20
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/extensions/UpdateTheme.js +1 -1
- package/package.json +1 -1
- package/extensions/Theme.js +0 -93
|
@@ -3,7 +3,7 @@ const less = require('less')
|
|
|
3
3
|
|
|
4
4
|
// CSS变量搭桥文件名
|
|
5
5
|
const cssFileName = 'vars.module'
|
|
6
|
-
const colorPalette = require('
|
|
6
|
+
const colorPalette = require('../utils/ColorPalette')
|
|
7
7
|
|
|
8
8
|
// 获取并解析LESS文件
|
|
9
9
|
async function fetchAndParseLessFile(fileName, isParseVariables) {
|
package/package.json
CHANGED
package/extensions/Theme.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import message from 'ant-design-vue/es/message'
|
|
2
|
-
|
|
3
|
-
const watchTheme = {
|
|
4
|
-
created() {
|
|
5
|
-
/** 全局添加标志变量来控制是否已经添加过监听器 */
|
|
6
|
-
if (!window._storageListenerAdded) {
|
|
7
|
-
/** 监听storage变化 */
|
|
8
|
-
window.addEventListener('storage', this.handleStorageChange)
|
|
9
|
-
window._storageListenerAdded = true
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
methods: {
|
|
13
|
-
handleStorageChange(event) {
|
|
14
|
-
// console.log('Storage changed:', event.newValue)
|
|
15
|
-
/** 判断是否为主题key更改并执行资源切换 */
|
|
16
|
-
event.key === 'projectTheme' && this.$setTheme(event.newValue)
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
beforeDestroy() {
|
|
20
|
-
/** 销毁标志变量及监听器 */
|
|
21
|
-
if (window._storageListenerAdded) {
|
|
22
|
-
window.removeEventListener('storage', this.handleStorageChange)
|
|
23
|
-
window._storageListenerAdded = false
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default {
|
|
29
|
-
install(Vue) {
|
|
30
|
-
/** 判断是否属于内嵌项目 */
|
|
31
|
-
const isHas = window.parent !== window
|
|
32
|
-
|
|
33
|
-
Vue.prototype.$setTheme = function(theme) {
|
|
34
|
-
/** 子项目则只需切换主题资源 */
|
|
35
|
-
if(isHas) {
|
|
36
|
-
return ToggleThemeSource(theme)
|
|
37
|
-
}
|
|
38
|
-
ToggleTheme(theme)
|
|
39
|
-
}
|
|
40
|
-
/** 子项目需挂载监听主题变化自动执行切换 */
|
|
41
|
-
isHas && Vue.mixin(watchTheme)
|
|
42
|
-
|
|
43
|
-
/** 切换当前主题 */
|
|
44
|
-
function ToggleTheme(scopeName) {
|
|
45
|
-
/** 切换主题loading */
|
|
46
|
-
const hideMessage = message.loading('正在切换主题!', 0)
|
|
47
|
-
|
|
48
|
-
ToggleThemeSource(scopeName)
|
|
49
|
-
|
|
50
|
-
const loadingTimer=setTimeout(() => {
|
|
51
|
-
hideMessage()
|
|
52
|
-
clearTimeout(loadingTimer)
|
|
53
|
-
}, 10)
|
|
54
|
-
|
|
55
|
-
Vue.prototype.$store.commit('SET_THEME',scopeName)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** 切换主题资源 */
|
|
59
|
-
function ToggleThemeSource(scopeName) {
|
|
60
|
-
try {
|
|
61
|
-
const { toggleTheme } = require('@zougt/theme-css-extract-webpack-plugin/dist/toggleTheme')
|
|
62
|
-
/** 获取初始配置项 */
|
|
63
|
-
// env.themeConfig 来源 vue.config.js define (webpack的DefinePlugin)
|
|
64
|
-
const themeConfig = env.themeConfig || {}
|
|
65
|
-
/** 主题配置
|
|
66
|
-
* @scopeName 名称
|
|
67
|
-
* @multipleScopeVars 主题项
|
|
68
|
-
* @extract 是否提取
|
|
69
|
-
* @publicPath 资源输出路径
|
|
70
|
-
* @outputDir 提取的 css 文件存放目录
|
|
71
|
-
*/
|
|
72
|
-
toggleTheme({
|
|
73
|
-
scopeName: `theme-${scopeName}`,
|
|
74
|
-
multipleScopeVars: themeConfig.multipleScopeVars,
|
|
75
|
-
extract: themeConfig.extract,
|
|
76
|
-
publicPath: themeConfig.publicPath,
|
|
77
|
-
outputDir: themeConfig.extractCssOutputDir
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
/** 加载主题对应样式文件 */
|
|
81
|
-
// const requireLess = require.context('@/theme/styles', false, /\.less$/)
|
|
82
|
-
// requireLess(`./${scopeName}.less`)
|
|
83
|
-
let themeLink = document.getElementById('theme-stylesheet')
|
|
84
|
-
themeLink.href = `${process.env.BASE_URL}static/style/${scopeName}.css`
|
|
85
|
-
} catch(err) {
|
|
86
|
-
// message.error('主题资源加载失败')
|
|
87
|
-
console.error('换肤控件错误:', err)
|
|
88
|
-
throw err
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
}
|