diff --git a/packages/canvas/render/src/application-function/global-state.ts b/packages/canvas/render/src/application-function/global-state.ts index 9e8f84ae82..3e1623967b 100644 --- a/packages/canvas/render/src/application-function/global-state.ts +++ b/packages/canvas/render/src/application-function/global-state.ts @@ -13,14 +13,43 @@ export function useGlobalState() { watchEffect(() => { reset(stores) globalState.value.forEach(({ id, state = {}, getters = {} }) => { - const computedGetters = Object.keys(getters).reduce( - (acc, key) => ({ - ...acc, - [key]: new Func('return ' + getters[key])().call(acc, state) // parseData(getters[key], null, acc)?.call?.(acc, state) //理论上不应该走parseData, unibuy代码遗留 - }), - {} - ) - stores[id] = { ...state, ...computedGetters } + const hasGetters = Object.keys(getters).length > 0 + + if (Array.isArray(state)) { + if (!hasGetters) { + stores[id] = [...state] + } else { + const computedGetters = {} + Object.keys(getters).forEach((key) => { + try { + computedGetters[key] = new Func('return ' + getters[key])().call(computedGetters, state) + } catch (error) { + computedGetters[key] = undefined + } + }) + + const arrayWithGetters = [...state] + Object.assign(arrayWithGetters, computedGetters) + stores[id] = arrayWithGetters + } + } else if (typeof state !== 'object' || state === null) { + stores[id] = state + } else { + if (!hasGetters) { + stores[id] = { ...state } + } else { + const computedGetters = {} + Object.keys(getters).forEach((key) => { + try { + computedGetters[key] = new Func('return ' + getters[key])().call(computedGetters, state) + } catch (error) { + computedGetters[key] = undefined + } + }) + + stores[id] = Object.assign({}, state, computedGetters) + } + } }) }) return { diff --git a/packages/configurator/src/variable-configurator/VariableConfigurator.vue b/packages/configurator/src/variable-configurator/VariableConfigurator.vue index f15df65798..46700b05ab 100644 --- a/packages/configurator/src/variable-configurator/VariableConfigurator.vue +++ b/packages/configurator/src/variable-configurator/VariableConfigurator.vue @@ -503,14 +503,8 @@ export default { state.variables = {} const stores = useResource().appSchemaState.globalState - stores.forEach(({ id, state: storeState = {}, getters = {} }) => { - const loadProp = (prop) => { - const propBinding = `${id}.${prop}` - state.variables[propBinding] = propBinding - } - - Object.keys(storeState).forEach(loadProp) - Object.keys(getters).forEach(loadProp) + stores.forEach(({ id, state: _storeState = {}, _getters = {} }) => { + state.variables[id] = id }) } else if (item.id === 'loop') { state.bindPrefix = '' diff --git a/packages/plugins/materials/src/composable/useResource.js b/packages/plugins/materials/src/composable/useResource.js index 10577ebd3f..9cfab9a4a4 100644 --- a/packages/plugins/materials/src/composable/useResource.js +++ b/packages/plugins/materials/src/composable/useResource.js @@ -143,8 +143,8 @@ const fetchAppState = async () => { appSchemaState.bridge = appData.bridge appSchemaState.utils = appData.utils - appSchemaState.isDemo = appData.meta?.is_demo - appSchemaState.globalState = appData?.meta.global_state + appSchemaState.isDemo = appData.meta?.isDemo || appData.meta?.is_demo + appSchemaState.globalState = appData?.meta.globalState || appData?.meta.global_state // 词条语言为空时使用默认的语言 const defaultLocales = [ diff --git a/packages/vue-generator/src/templates/vue-template/templateFiles/src/lowcodeConfig/store.js b/packages/vue-generator/src/templates/vue-template/templateFiles/src/lowcodeConfig/store.js index f7f39c7a84..d1de82c190 100644 --- a/packages/vue-generator/src/templates/vue-template/templateFiles/src/lowcodeConfig/store.js +++ b/packages/vue-generator/src/templates/vue-template/templateFiles/src/lowcodeConfig/store.js @@ -4,7 +4,7 @@ const useStores = () => { const stores = {} Object.values({ ...useDefinedStores }).forEach((store) => { - stores[store.$id] = store() + stores[store.$id] = store().$state }) return stores