¶Ô±ÈÐÂÎļþ |
| | |
| | | import { get, isNil } from 'lodash' |
| | | import { defineEmits, PropType, computed, Ref } from 'vue' |
| | | import sdk from 'sdk' |
| | | |
| | | export const useHook = (props: any, emit: any) => { |
| | | /** |
| | | * å建计ç®å±æ§ï¼çå¬cmsç»ä»¶çpropsåå |
| | | * @param key 屿§Key |
| | | * @returns |
| | | */ |
| | | const createComputed = <T>(key: string, defaultValue?: any): Ref<T> => { |
| | | return computed({ |
| | | get() { |
| | | const v = isNil(props[key]) ? defaultValue : props[key] |
| | | return v |
| | | }, |
| | | set(v) { |
| | | emit('update', { [key]: v }) |
| | | }, |
| | | }) |
| | | } |
| | | /** |
| | | * è·å计ç®å±æ§ï¼çå¬cmsç»ä»¶çpropsåå |
| | | * @param key 屿§Key |
| | | * @returns |
| | | */ |
| | | const getComputedProp = <T>(key: string, defaultValue?: any): Ref<T> => { |
| | | return computed(() => { |
| | | return get( |
| | | props, |
| | | `node.props.${key}`, |
| | | !isNil(defaultValue) ? defaultValue : '' |
| | | ) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * è·åç»ä»¶list |
| | | */ |
| | | const widgetList = computed<any[]>(() => { |
| | | return get(window.app, 'current.project.current.page.body.children', []) |
| | | }) |
| | | |
| | | const getVariable = () => get(sdk, 'models.Variable') |
| | | |
| | | const Variable = getVariable() |
| | | |
| | | const VariableStore = Variable.store |
| | | |
| | | return { |
| | | widgetList, |
| | | Variable, |
| | | VariableStore, |
| | | getVariable, |
| | | createComputed, |
| | | getComputedProp, |
| | | } |
| | | } |