zenglf
2023-08-17 7442a435d058bd17d6fc679e1b7956bf3a5d32ae
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
<template>
  <a-card :bordered="false">
    <a-col :span="18">
      <a-spin
        tip="Loading..."
        :spinning="spinning"
      >
        <div>
          <a-row>
            <!-- 预览区域 -->
            <a-col :span="24">
              <template>
                <!-- <div style="float: left;width:104px;height:104px;margin-right: 10px;margin: 0 8px 8px 0;">
                  <div style="width: 100%;height: 100%;position: relative;padding: 8px;border: 1px solid #d9d9d9;border-radius: 4px;"> -->
                <img
                  style="width: 100%;"
                  :src="src"
                  :preview="preview"
                >
                <!-- :src="dataSource[0].upload.src"
                      :preview="dataSource[0].id" -->
                <!-- </div>
                </div> -->
              </template>
            </a-col>
          </a-row>
        </div>
      </a-spin>
      <p></p>
    </a-col>
  </a-card>
</template>
 
<script>
 
import ARow from 'ant-design-vue/es/grid/Row'
import { getAction } from '@/api/manage'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import Vue from 'vue'
import { getFileAccessHttpUrl } from '@/api/manage';
 
export default {
  name: 'PhotoPreview',
  components: {
    ARow
  },
  props: {
    specialtyInspectionPlanId: {
      type: String,
      default: '',
      required: false
    }
  },
  watch: {
    specialtyInspectionPlanId: {
      immediate: true,
      handler(val) {
        if (!this.specialtyInspectionPlanId) {
          this.clearList()
        } else {
          getAction(this.url.list, { pageNo: 1, pageSize: 10, id: val, delFlag: 0 }).then((res) => {
            if (res.success) {
              for (let i = 0; i < res.result.records.length; i++) {
                let r = res.result.records[i].upload;
                r.src = this.getSrc(res.result.records[i].upload);
              }
              this.dataSource = res.result.records || res.result;
              this.src = res.result.records[0].upload.src
              this.preview = res.result.records[0].id
            } else {
              this.$message.warning(res.message)
            }
          }).finally(() => {
            this.loading = false
          })
        }
      }
    }
  },
  data() {
    return {
      description: '图片预览页面',
      spinning: false,
      dataSource: [],
      src: "",
      preview: "",
      url: {
        list: "/eam/specialtyInspectionPlan/getSpecialtyInspectionPlanList",
      },
    }
  },
  created() {
  },
  methods: {
    clearList() {
      this.dataSource = [],
        this.src = "",
        this.preview = ""
    },
 
    getSrc(record) {
 
      if (!record.path) {
        return '';
      }
      //本地:local\Minio:minio\阿里云:alioss
      if (record.uploadType == 'local') {
 
        let ssoLoginFlag = Vue.ls.get("ssoLoginFlag");
        let deployMode = Vue.ls.get("deployMode");
 
        if (ssoLoginFlag && deployMode == "container") {
          var baseProject = Vue.ls.get("baseProject");
          console.log("baseProject==>" + baseProject)
 
          var hostname = window.location.protocol + "//" + window.location.host;
          var url = hostname + '/' + baseProject + '/sys/common/static';
          return getFileAccessHttpUrl(record.path + record.encodeName, url, window._CONFIG['hyperTextTransfer'])
        } else {
          //根据发布状态修改https 或 http
          return getFileAccessHttpUrl(record.path + record.encodeName, this.url.urlDownload, window._CONFIG['hyperTextTransfer'])
        }
 
      } else if (record.uploadType == 'alioss') {
 
        const OSS = require('ali-oss')
        const client = new OSS({
          // region以杭州为例(oss-cn-hangzhou),其他region按实际情况填写。
          region: window._CONFIG['region'],
          // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号。
          accessKeyId: window._CONFIG['accessKeyId'],
          accessKeySecret: window._CONFIG['accessKeySecret'],
          bucket: window._CONFIG['bucket'],
        })
        // object-key表示从OSS下载文件时需要指定包含文件后缀在内的完整路径,例如abc/efg/123.jpg。
        return client.signatureUrl(record.path)
      }
    },
  }
}
</script>
<style scoped>
.table-operator {
  margin-bottom: 10px;
}
 
.clName .ant-tree li span.ant-tree-switcher,
.ant-tree li span.ant-tree-iconEle {
  width: 10px !important;
}
 
.clName .ant-tree li .ant-tree-node-content-wrapper.ant-tree-node-selected {
  background-color: #1890ff !important;
}
</style>