wupengfei
8 天以前 f37c78b6412db783615f8b38f0487c57136c4ed8
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
<template>
  <PortraitTable v-bind="portraitTableProps" :label-width="labelWidth"> </PortraitTable>
  <div class="enclosure-list-title">附件列表</div>
  <ProTableV2
    :table-data="annexList"
    :columns="CommonAnnexTableColumns"
    :operation-btns="operationListBtns"
    :show-pagination="false"
    :show-no-data="false"
    :auto-height="false"
    :show-table-column-setting="false"
    :table-props="{ maxHeight: '400px' }"
    :column-render-map="columnsRenderProps"
  >
  </ProTableV2>
</template>
 
<script setup lang="ts" generic="TAnnexItem">
import { downloadFileByUrl } from '@bole-core/core';
import { CommonAnnexTableColumns } from '@/constants';
import { ProTableV2, ProTableV2Props } from '@bole-core/components';
 
defineOptions({
  name: 'PortraitTableWithAttachment',
});
 
type Props = {
  annexList: TAnnexItem[];
  customDownLoad?: (row: TAnnexItem) => Promise<any>;
  labelWidth?: string;
  portraitTableProps: any;
  columnsRenderProps?: ProTableV2Props['columnRenderMap'];
  downloadFileKey?: keyof TAnnexItem;
};
 
const props = withDefaults(defineProps<Props>(), {
  labelWidth: '180px',
  columnsRenderProps: () => ({}),
  downloadFileKey: 'url' as any,
});
 
const operationListBtns = [
  {
    data: {
      enCode: 'downloadBtn',
      name: '下载',
    },
    emits: {
      onClick: (row) => handleDownload(row),
    },
  },
];
 
function handleDownload(row: TAnnexItem) {
  if (props.customDownLoad) {
    props.customDownLoad(row);
  } else {
    downloadFileByUrl(row[props.downloadFileKey] as any);
  }
}
</script>
 
<style lang="scss" scoped>
@use '@/style/common.scss' as *;
 
.enclosure-list-title {
  padding: 16px 0;
  font-size: 14px;
  color: getCssVar('text-color', 'primary');
  line-height: 19px;
}
</style>