zhou zhou
10 小时以前 7c2bffa1a495cc4a3a263f654c08c231009c5c4e
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
<template>
  <ElDialog
    :model-value="visible"
    width="80%"
    top="6vh"
    destroy-on-close
    :title="t('pages.task.flowStepDialog.title')"
    @update:model-value="emit('update:visible', $event)"
  >
    <div class="flex flex-col gap-4">
      <div class="rounded-xl border border-[var(--el-border-color-lighter)] bg-[var(--el-fill-color-blank)] px-4 py-3">
        <div class="text-sm text-[var(--art-gray-500)]">{{ t('pages.task.flowStepDialog.currentTask') }}</div>
        <div class="mt-1 flex flex-wrap items-center gap-x-6 gap-y-2 text-sm text-[var(--art-gray-900)]">
          <span>{{ t('pages.task.detail.taskCode') }}:{{ taskRow?.taskCode || '--' }}</span>
          <span>{{ t('pages.task.detail.taskStatus') }}:{{ taskRow?.taskStatusLabel || '--' }}</span>
          <span>{{ t('pages.task.detail.taskType') }}:{{ taskRow?.taskTypeLabel || '--' }}</span>
        </div>
      </div>
 
      <ArtTable
        :loading="loading"
        :data="rows"
        :columns="columns"
        :pagination="pagination"
        @pagination:size-change="handleSizeChange"
        @pagination:current-change="handleCurrentChange"
      />
    </div>
  </ElDialog>
</template>
 
<script setup>
  import { computed, reactive, ref, watch } from 'vue'
  import { useI18n } from 'vue-i18n'
  import { guardRequestWithMessage } from '@/utils/sys/requestGuard'
  import { fetchFlowStepInstancePage } from '@/api/flow-step-instance'
  import { normalizeFlowStepInstanceRow } from '@/views/system/flow-step-instance/flowStepInstancePage.helpers'
 
  const props = defineProps({
    visible: {
      type: Boolean,
      default: false
    },
    taskRow: {
      type: Object,
      default: () => ({})
    }
  })
 
  const emit = defineEmits(['update:visible'])
  const { t } = useI18n()
 
  const loading = ref(false)
  const rows = ref([])
  const pagination = reactive({
    current: 1,
    size: 20,
    total: 0
  })
 
  const columns = computed(() => [
    {
      type: 'globalIndex',
      label: t('table.index'),
      width: 72,
      align: 'center'
    },
    {
      prop: 'flowInstanceNo',
      label: t('pages.task.flowStepDialog.flowInstanceNo'),
      minWidth: 160,
      showOverflowTooltip: true
    },
    {
      prop: 'stepCode',
      label: t('pages.task.flowStepDialog.stepCode'),
      minWidth: 140,
      showOverflowTooltip: true
    },
    {
      prop: 'stepName',
      label: t('pages.task.flowStepDialog.stepName'),
      minWidth: 180,
      showOverflowTooltip: true
    },
    {
      prop: 'stepType',
      label: t('pages.task.flowStepDialog.stepType'),
      minWidth: 140,
      showOverflowTooltip: true
    },
    {
      prop: 'executeResult',
      label: t('pages.task.flowStepDialog.executeResult'),
      minWidth: 140,
      showOverflowTooltip: true
    },
    {
      prop: 'statusText',
      label: t('table.status'),
      width: 120,
      showOverflowTooltip: true
    },
    {
      prop: 'startTimeText',
      label: t('pages.task.flowStepDialog.startTime'),
      minWidth: 180,
      showOverflowTooltip: true
    },
    {
      prop: 'endTimeText',
      label: t('pages.task.flowStepDialog.endTime'),
      minWidth: 180,
      showOverflowTooltip: true
    }
  ])
 
  function updatePaginationState(response) {
    pagination.total = Number(response?.total || 0)
    pagination.current = Number(response?.current || pagination.current || 1)
    pagination.size = Number(response?.size || pagination.size || 20)
  }
 
  async function loadRows() {
    if (!props.visible || !props.taskRow?.taskCode) {
      return
    }
 
    loading.value = true
    try {
      const response = await guardRequestWithMessage(
        fetchFlowStepInstancePage({
          taskNo: props.taskRow.taskCode,
          current: pagination.current,
          pageSize: pagination.size
        }),
        {
          records: [],
          total: 0,
          current: pagination.current,
          size: pagination.size
        },
        { timeoutMessage: t('pages.task.flowStepDialog.timeout') }
      )
      rows.value = Array.isArray(response?.records)
        ? response.records.map((record) => normalizeFlowStepInstanceRow(record))
        : []
      updatePaginationState(response)
    } finally {
      loading.value = false
    }
  }
 
  function handleSizeChange(size) {
    pagination.size = size
    pagination.current = 1
    void loadRows()
  }
 
  function handleCurrentChange(current) {
    pagination.current = current
    void loadRows()
  }
 
  watch(
    () => [props.visible, props.taskRow?.taskCode],
    ([visible]) => {
      if (!visible) {
        rows.value = []
        pagination.current = 1
        return
      }
      pagination.current = 1
      void loadRows()
    }
  )
</script>