From 72cfeb5d6d747a10cb492ebec6e09934e46b04b1 Mon Sep 17 00:00:00 2001
From: zs <zhousong@weben-smart.com>
Date: 周三, 07 5月 2025 09:06:58 +0800
Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo
---
HIAWms/web/src/libs/Hook/Hook.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/HIAWms/web/src/libs/Hook/Hook.ts b/HIAWms/web/src/libs/Hook/Hook.ts
new file mode 100644
index 0000000..7d59138
--- /dev/null
+++ b/HIAWms/web/src/libs/Hook/Hook.ts
@@ -0,0 +1,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缁勪欢鐨刾rops鍙樺寲
+ * @param key 灞炴�ey
+ * @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缁勪欢鐨刾rops鍙樺寲
+ * @param key 灞炴�ey
+ * @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,
+ }
+}
--
Gitblit v1.9.3