refactor: 修改语言切换处理方式

This commit is contained in:
liujuping.liujupin 2021-09-23 14:28:07 +08:00
parent f0cb1cd8ea
commit a11585a543
2 changed files with 9 additions and 22 deletions

View File

@ -96,7 +96,6 @@ export function leafWrapper(Comp: types.IBaseRenderer, {
this.initOnPropsChangeEvent();
this.initOnChildrenChangeEvent();
this.initOnVisibleChangeEvent();
this.initLangChangeEvent();
this.state = {
nodeChildren: null,
childrenInState: false,
@ -189,26 +188,6 @@ export function leafWrapper(Comp: types.IBaseRenderer, {
dispose && this.disposeFunctions.push(dispose);
}
/**
*
*/
initLangChangeEvent() {
if (this.leaf?.componentName !== 'Page') {
return;
}
const dispose = (window as any).VisualEngine.Env.onEnvChange(() => {
this.beforeRender(RerenderType.LangChanged);
const nextProps = getProps(this.leaf?.export?.(TransformStage.Render) as types.ISchema, Comp, this.componentInfo);
const nextChildren = getChildren(this.leaf?.export?.(TransformStage.Render) as types.ISchema, Comp);
this.setState({
nodeChildren: nextChildren,
nodeProps: nextProps,
});
});
dispose && this.disposeFunctions.push(dispose);
}
componentWillUnmount() {
this.disposeFunctions.forEach(fn => fn());
}

View File

@ -1,7 +1,8 @@
import logger from '@ali/vu-logger';
import { EventEmitter } from 'events';
import { editor } from '@ali/lowcode-engine';
import { editor, designer } from '@ali/lowcode-engine';
import { GlobalEvent, isJSExpression } from '@ali/lowcode-types';
import env from './env';
/**
* Bus class as an EventEmitter
@ -77,6 +78,13 @@ editor?.on('history.forward', (data) => {
bus.emit('ve.history.forward', data);
});
env.onEnvChange((_envs, name, value) => {
if (name !== 'locale') {
return;
}
designer.project.simulator?.set(name, value.replace('_', '-'));
});
function triggerUseVariableChange(data: any) {
const { node, prop, oldValue, newValue } = data;
const propConfig = node.componentMeta.prototype?.options.configure.find((o: any) => o.name === prop.getKey());