Skip to content

Commit

Permalink
fix: 修复 v2 ,变量更新时,更新错误
Browse files Browse the repository at this point in the history
  • Loading branch information
aisen60 committed May 22, 2024
1 parent dbd311e commit 7ad9729
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/mobile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ const listenToSyncLocale = () => {
const listenToSyncGetVar = () => {
window.addEventListener('message', (event) => {
if (event.data.type === IframeSyncEnum.GET_VAR) {
const component = JSON.parse(event.data.value);
const componentVar = JSON.parse(event.data.value);

const vars = transformVarsType(component, _mobileVersion);
const vars = transformVarsType(componentVar, _mobileVersion);

syncVarToParent(vars);
}
Expand All @@ -147,8 +147,8 @@ const listenToSyncSetVar = () => {
const styleTag = document.querySelector(`#${STYLE_TAG_ID}`);
if (styleTag) {
styleTag.innerHTML = `
.van-theme-light ${lightCss}
.van-theme-dark ${darkCss}
html.van-theme-light ${lightCss}
html.van-theme-dark ${darkCss}
`;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ export const getCssVariable = (name: string): string => {
export const transformVarsType = (componentVar: ProjectVarObject, version: ProjectVersion) => {
const vars: Record<string, WComponentVarType> = {};

const component = componentVar;
const newComponentVar = componentVar;

Object.keys(component).forEach((key) => {
Object.keys(newComponentVar).forEach((key) => {
const isVar =
version === ProjectEnum.VERSION_2
? component[key].startsWith('@')
: component[key].includes('var(--');
? newComponentVar[key].startsWith('@')
: newComponentVar[key].includes('var(--');

const varLabel = isVar ? component[key] : '';
const varLabel = isVar ? newComponentVar[key] : '';

const name = version === ProjectEnum.VERSION_2 ? key.replace('@', '--van-') : key;

Expand Down

0 comments on commit 7ad9729

Please sign in to comment.