干燥机配套车间生产管理系统/云平台前端
baoshiwei
2023-03-10 1fb197352b6a263646e4ccd3ed1c7854ede031dd
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
<template>
  <div>
    <template v-if="hasFile" v-for="(file, fileKey) of [innerFile || {}]" :key="fileKey">
      <div class="j-vxe-image-list">
        <template v-if="!file || !(file['url'] || file['path'] || file['message'])">
          <a-tooltip :title="'请稍后: ' + JSON.stringify(file) + (file['url'] || file['path'] || file['message'])">
            <LoadingOutlined />
          </a-tooltip>
        </template>
        <template v-else-if="file['path']">
          <template v-for="src of imgList">
            <img class="j-vxe-image" :src="src" alt="图片错误" @click="handleMoreOperation" />
          </template>
        </template>
        <a-tooltip v-else :title="file.message || '上传失败'" @click="handleClickShowImageError">
          <Icon icon="ant-design:exclamation-circle" style="color: red" />
        </a-tooltip>
      </div>
    </template>
    <div class="j-vxe-image-upload">
      <a-upload
        name="file"
        :data="{ isup: 1 }"
        :multiple="false"
        :action="uploadAction"
        :headers="uploadHeaders"
        :showUploadList="false"
        v-bind="cellProps"
        @change="handleChangeUpload"
      >
        <a-button v-if="!hasFile" preIcon="ant-design:upload">{{ originColumn.btnText || '上传图片' }}</a-button>
        <div v-if="hasFile && imgList.length < maxCount" class="j-vxe-plus" @click="">
          <Icon icon="ant-design:plus" />
        </div>
      </a-upload>
    </div>
    <JUploadModal :value="modalValue" @register="registerModel" @change="onModalChange" />
  </div>
</template>
<script lang="ts">
  import { computed, defineComponent } from 'vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { JVxeComponent } from '/@/components/jeecg/JVxeTable/types';
  import { useJVxeCompProps } from '/@/components/jeecg/JVxeTable/hooks';
  import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';
  import { getFileAccessHttpUrl } from '/@/utils/common/compUtils';
  import { components, enhanced, useFileCell } from '../hooks/useFileCell';
 
  export default defineComponent({
    name: 'JVxeImageCell',
    components: components,
    props: useJVxeCompProps(),
    setup(props: JVxeComponent.Props) {
      const { createErrorModal } = useMessage();
      const setup = useFileCell(props, UploadTypeEnum.image, { multiple: true });
      const { innerFile, maxCount } = setup;
 
      const imgList = computed(() => {
        if (innerFile.value) {
          if (innerFile.value['url']) {
            return [innerFile.value['url']];
          } else if (innerFile.value['path']) {
            let paths = innerFile.value['path'].split(',');
            return paths.map((p) => getFileAccessHttpUrl(p));
          }
        }
        return [];
      });
 
      // 弹出上传出错详细信息
      function handleClickShowImageError() {
        let file = innerFile.value || null;
        if (file && file['message']) {
          createErrorModal({
            title: '上传出错',
            content: '错误信息:' + file['message'],
            maskClosable: true,
          });
        }
      }
 
      return {
        ...setup,
        imgList,
        maxCount,
        handleClickShowImageError,
      };
    },
    // 【组件增强】注释详见:JVxeComponent.Enhanced
    enhanced: enhanced,
  });
</script>
 
<style scoped lang="less">
  .j-vxe-image {
    height: 32px;
    max-width: 100px !important;
    cursor: pointer;
    display: inline-block;
    margin-right: 4px;
    vertical-align: top;
 
    &:hover {
      opacity: 0.8;
    }
 
    &:active {
      opacity: 0.6;
    }
  }
 
  .j-vxe-plus {
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    background-color: #fafafa;
    border: 1px dashed #d9d9d9;
    border-radius: 2px;
    cursor: pointer;
  }
 
  .j-vxe-image-list,
  .j-vxe-image-upload {
    display: inline-block;
    vertical-align: top;
  }
</style>