From 3aedad63dd01f1fc5154cb520af32edab967d6e0 Mon Sep 17 00:00:00 2001
From: schangxiang@126.com <schangxiang@126.com>
Date: 周一, 12 5月 2025 09:15:26 +0800
Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo

---
 PipeLineLems/pipelinelems_web/src/widgets/MyPluginName/Controllers/MyEntityNameDrawer.ts |  143 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 143 insertions(+), 0 deletions(-)

diff --git a/PipeLineLems/pipelinelems_web/src/widgets/MyPluginName/Controllers/MyEntityNameDrawer.ts b/PipeLineLems/pipelinelems_web/src/widgets/MyPluginName/Controllers/MyEntityNameDrawer.ts
new file mode 100644
index 0000000..8a95db5
--- /dev/null
+++ b/PipeLineLems/pipelinelems_web/src/widgets/MyPluginName/Controllers/MyEntityNameDrawer.ts
@@ -0,0 +1,143 @@
+import { ref, onMounted, reactive, computed, Ref, watch } from 'vue'
+import { injectModel } from '@/libs/Provider/Provider'
+import { MyEntityNameDrawer } from '../Models/MyEntityNameDrawer'
+import { ElMessage } from 'element-plus'
+import isEqual from 'lodash/isEqual'
+import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
+import { cloneDeep } from 'lodash'
+
+export const useMyEntityNameDrawer = (props: any, ctx?: any) => {
+  const myEntityNameDrawer =
+    injectModel<MyEntityNameDrawer>('myEntityNameDrawer')
+  /**
+   * 鐢ㄦ潵瀵规瘮鐨勫垵濮嬪寲鏁版嵁
+   */
+  const initiateData: Ref<Record<string, any>> = ref({})
+  const formData = ref<Record<string, any>>({})
+  // ref
+  const formRef = ref()
+
+  const current = computed(() => {
+    return props.row || null
+  })
+  const visible = computed({
+    get() {
+      return props.modelValue
+    },
+    set(val) {
+      ctx.emit('update:modelValue', val)
+    },
+  })
+  /**
+   * 娣诲姞鐨刦orm瀛楁
+   */
+  const formItems = reactive([
+    {
+      label: '鍚嶇О',
+      prop: 'name',
+      el: 'input',
+      placeholder: '璇疯緭鍏ュ悕绉�',
+      rules: [{ required: true, message: '鍚嶇О', trigger: 'blur' }],
+    },
+    {
+      label: '缂栧彿',
+      prop: 'code',
+      el: 'input',
+      placeholder: '璇疯緭鍏ョ紪鍙�',
+      rules: [{ required: true, message: '缂栧彿', trigger: 'blur' }],
+    },
+    {
+      label: '澶囨敞',
+      prop: 'remark',
+      el: 'input',
+      placeholder: '璇疯緭鍏ュ娉�',
+    },
+  ])
+  /**
+   * 鏍¢獙鏄惁鏈夋暟鎹彉鍖�
+   */
+  const checkIsEqualObject = () => {
+    const data = {
+      formData: formData.value,
+    }
+    const check = isEqual(initiateData.value, data)
+    return check
+  }
+
+  const onClose = (done: () => void) => {
+    if (visible.value) {
+      if (checkIsEqualObject()) {
+        visible.value = false
+        done && done()
+      } else {
+        ConfirmBox('鏄惁淇濆瓨璁剧疆锛�')
+          .then(() => {
+            onConfirm()
+          })
+          .catch(() => {
+            visible.value = false
+            done && done()
+          })
+      }
+    }
+  }
+  /**
+   * 淇濆瓨
+   */
+  const onConfirm = async () => {
+    await formRef.value?.validate()
+    const data = {
+      name: formData.value.name,
+      code: formData.value.code,
+      remark: formData.value.remark,
+      sort: props.sort,
+    }
+    if (!current.value) {
+      await myEntityNameDrawer.addMyEntityName(data)
+    } else {
+      const id = current.value.id
+      await myEntityNameDrawer.updateMyEntityName(id, data)
+    }
+    ElMessage.success('淇濆瓨鎴愬姛')
+    ctx.emit('confirm')
+  }
+
+  const updateCheckData = () => {
+    initiateData.value = {
+      formData: {
+        ...formData.value,
+      },
+    }
+  }
+  /**
+   * 寮圭獥鎵撳紑鑾峰彇璇︽儏
+   */
+  const onOpen = async () => {
+    if (current.value) {
+      const res = await myEntityNameDrawer.getMyEntityNameDetail(current.value)
+
+      formData.value = {
+        name: res.name,
+        code: res.code,
+        remark: res.remark,
+        id: res.id,
+      }
+      updateCheckData()
+    } else {
+      formData.value = {}
+      updateCheckData()
+    }
+  }
+
+  watch(() => current.value, onOpen)
+
+  return {
+    formItems,
+    formData,
+    visible,
+    formRef,
+    onOpen,
+    onClose,
+    onConfirm,
+  }
+}

--
Gitblit v1.9.3