1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| 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,
| }
| }
|
|