Ben Lin
2025-03-05 b3305675a429cac20c2b73464badb64f999b615b
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!--
 * @Description: 通用组合页面,左边是树,右边是配置
 * @Author: Ben Lin
 * @version: 
 * @Date: 2024-06-18 23:30:30
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-10-21 23:03:27
-->
<template>
  <PageWrapper
    contentFullHeight
    contentClass="flex"
    :title="pageTitle"
    :content="pageContent"
    @back="goBack"
  >
    <Suspense class="w-1/4 xl:w-1/5">
      <LeftTree @select="NodeSelect" @deletenode="delCallback" />
    </Suspense>
    <Suspense>
      <div class="w-3/4 xl:w-4/5 p-5">
        <CarGridNav v-if="showNav" :configType="configType" :nodes="nodes">
          <template #[item] v-for="item in otherSlots" :key="item">
            <!-- 自定义内容 -->
            <div class="h-full" style="height: 400px">
              <FlowChartView :data="routeData" @init="init" />
            </div>
          </template>
        </CarGridNav>
        <Config
          v-if="showConfig"
          :configType="configType"
          :OtherTableName="OtherTableName"
          @success="configSuccess"
        />
      </div>
    </Suspense>
    <!-- <BasicTable class="w-3/4 xl:w-4/5" @register="registerTable">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate" preIcon="add_02|svg"> 新增 </a-button>
      </template>
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction :actions="createActions(record)" />
        </template>
      </template>
    </BasicTable> -->
    <!-- <normalDrawer @register="registerDrawer" @success="handleSuccess" /> -->
    <Suspense>
      <CustModal
        @register="registerCust"
        @success="custSuccess"
        :type="cType"
        :detailSlots="dtlSlots"
        :entityName="entityName"
      >
        <!-- 用插槽自定义多表单 -->
        <template #[item.name] v-for="item in dtlSlots" :key="item.name">
          <BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]">
            <!-- 用插槽自定义弹出选择框 -->
            <template #[name]="{ field }" v-for="name in item.slots" :key="name">
              <a-button
                class="mt-1 ml-1"
                size="small"
                @click="handleCustClick(field)"
                :preIcon="item.preIcons[name]"
              />
              <GeneralModal
                @register="useModalData[name][0]"
                @success="(d, u) => handleEntSuccess(d, u, item.name)"
              />
            </template>
          </BasicForm>
          <!-- 自定义内容 -->
        </template>
      </CustModal>
    </Suspense>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { PageWrapper } from '@/components/Page';
  import { useModal } from '@/components/Modal';
  import GeneralModal from '/@/views/components/GeneralModal.vue';
  import CarGridNav from './CarGridNav.vue';
  import Config from './Config.vue';
  import CustModal from '/@/views/components/CustModal.vue';
  import { OpenCustModal, initRoute } from '../data';
  import { Ref, VNode, defineAsyncComponent, onMounted, provide, ref, unref } from 'vue';
  import { FlowChartView } from '/@/components/FlowChart';
  import { useRoute } from 'vue-router';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { useTabs } from '/@/hooks/web/useTabs';
  import { isNullOrUnDef } from '/@/utils/is';
  import { useGo } from '/@/hooks/web/usePage';
  import { useMessage } from '/@/hooks/web/useMessage';
  import LogicFlow from '@logicflow/core';
 
  defineOptions({ name: '工单工艺绑定' });
 
  const LeftTree = defineAsyncComponent(() => import('./LeftTree.vue'));
  const { notification, createErrorModal } = useMessage();
  const go = useGo();
  const route = useRoute();
  const { setTitle, refreshPage } = useTabs();
  // const objParams = ref(JSON.parse(decodeURI(route.params?.id as string))); //ref(JSON.parse(history.state.obj))
  const routeParams = ref(JSON.parse(decodeURI(route.params?.id as string)));
  // 从sessionStorage中读取参数并转换回对象
  const savedParams = sessionStorage.getItem(`${routeParams.value.sName}_params`);
  const objParams = savedParams ? ref(JSON.parse(decodeURI(savedParams))) : ref({});
  const entityName = ref(routeParams.value.Name);
  const useModalData = ref({}); //表单中插槽渲染按钮打开模态框useModal方法
  const useFormData = ref({});
  const cType = ref('');
  const dtlSlots = ref([] as any[]);
  const otherSlots = ref<any[]>([]);
  const selectVals = ref({});
  const dense = isNullOrUnDef(objParams.value.dense) ? ref(false) : ref(objParams.value.dense);
  const pageTitle = ref(objParams.value.pageTitle);
  const pageContent = ref(objParams.value.pageContent);
  const colSlots = ref<any>(objParams.value.colSlots);
  const selectedNodes = ref([]);
  const isMounted = ref(false);
  const showNav = ref(false);
  const showConfig = ref(false);
  const showOtherTable = ref(false);
  const configType = ref('');
  const OtherTableName = ref('');
  const nodes = ref([]);
  const routeData = ref({
    nodes: [],
    edges: [],
  });
  const custImport = ref<any>(null);
  const [registerCust] = useModal();
  provide<Ref<any>>('objParams', objParams);
  provide<Ref<any>>('selectedNodes', nodes);
  setTitle(objParams.value.Title); //设置标签页标题
 
  /**
   * @description: 页面左侧点击返回链接时的操作
   * @return {*}
   */
  function goBack() {
    if (!isNullOrUnDef(custImport.value)) {
      const [{ GetHomeUrl }] = custImport.value['default']();
      // 本例的效果时点击返回始终跳转到账号列表页,实际应用时可返回上一页
      go(GetHomeUrl({ colSlots: colSlots.value, sName:objParams.value.firstSessionName  }));
    }
  }
 
  // function handleAdd(){
  //   console.log('handleAdd');
  // }
 
  onMounted(async () => {
    isMounted.value = false;
    /* 动态import实体名.ts的自定义方法 */
    try {
      custImport.value = await import(`../entityts/${entityName.value}.ts`);
      if (custImport.value['default']) {
        otherSlots.value = custImport.value['default']()[0]['GetSlots']();
      }
      isMounted.value = true;
    } catch (e) {
      console.log(e);
    }
  });
 
  const currlf = ref(null) as Ref<LogicFlow | null>;
  /**
   * @description: 工艺路线初始化,特殊页面自定义内容
   * @param {*} lf
   * @return {*}
   */
  async function init(lf, rotId) {
    initRoute(lf, rotId, routeData, currlf, objParams.value.rotType);
  }
 
  /**
   * @description: 选择节点时根据返回的事件参数显示隐藏相应组件
   * @param {*} e
   * @return {*}
   */
  function NodeSelect(e) {
    showConfig.value = e.showConfig;
    showOtherTable.value = e.showOtherTable;
    showNav.value = e.showNav;
    configType.value = e.type;
    OtherTableName.value = objParams.value.OtherTableName;
    nodes.value = e.nodes;
    routeData.value = {
      nodes: [],
      edges: [],
    };
    /* 自定义内容,只有显示工艺路线的组合页面会进来 */
    if (e.nodes[0].type == 'Route') {
      let _rotId = e.nodes[0].code;
      if (objParams.value.rotType == 'Wo') {
        _rotId = e.nodes[0].wo;
      }
      initRoute(currlf, _rotId, routeData, currlf, objParams.value.rotType);
    }
  }
 
  /**
   * @description: 删除节点后回调
   * @param {*} node
   * @return {*}
   */
  function delCallback(node) {
    refreshPage();
  }
 
  /**
   * @description: 保存配置成功返回方法
   * @return {*}
   */
  function configSuccess() {
    notification.success({ message: '成功保存行为配置数据' });
  }
 
  /**
   * @description: 弹出框确定返回
   * @param {*} d
   * @return {*}
   */
  function custSuccess(d) {
    // reload();
  }
 
  /**
   * @description: 各表单内弹出选择框选择成功后方法
   * @param {*} d
   * @param {*} u
   * @param {*} item
   * @return {*}
   */
  function handleEntSuccess(d, u, item) {
    /* 动态import实体名.ts的自定义方法 */
    try {
      import(`../entityts/${cType.value}.ts`).then((m) => {
        const [{ GetSelectSuccess }] = m.default();
        var values = GetSelectSuccess(d, u);
        selectVals.value = values; //保存弹出框选择的结果
        let _val = {};
        d.returnFieldName.map((x) => {
          _val[x] = values[x];
        });
        useFormData.value[item][1].setFieldsValue(_val);
      });
    } catch (e) {}
  }
 
  /**
   * @description: 打开自定义模态框
   * @param {*} item
   * @return {*}
   */
  function handleCustClick(item) {
    OpenCustModal(
      useModalData.value[item][1].openModal, //带入openModal方法
      cType.value,
      item,
      [],
      // selectVals.value['ROUTE_CODE'],
    ); //[openRvModal], selectVals.value['ID']这是自定义参数,按实际需求
  }
</script>
<style lang="less">
.vben-page-wrapper .vben-page-wrapper-content {
    margin: 1px;
}
</style>