tanghaolin
2025-03-07 d9e68c8234a79ecaa9fb3304caadbc99607715c9
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
<template>
  <!-- 实物图 -->
  <div style="position: relative; height: 100%" v-loading="state.m_loadingCheck">
    <div style="font-size: 13px; float: left; font-weight: bold">
      <a v-if="state.CAD_Path !== null" class="diagram btn-export default blue-stripe pos_style" @click="exportCAD">
        <el-icon size="12">
          <PictureFilled />
        </el-icon>
        <span style="margin-left: 1px">
          {{ t("selectPage.export.TR") }}CAD
        </span>
      </a>
 
    </div>
    <viewer :images="state.currentimageList" :options="state.OptionssalseImg" class="imgBox">
      <img :onerror="useDefaultImage" v-for="src in state.currentimageList" :key="src" :src="src"
        style="max-width: 100%; max-height: 100%; height: auto; width: auto" />
    </viewer>
    <span v-if="state.isDebug" class="debug_span">{{ state.currentimageList[0] }}</span>
  </div>
</template>
 
<script setup name="realPictureCtrl">
import { reactive, watch, toRefs, onMounted } from 'vue';
import UtilsHelper from '@/utils/utils.js'
import defaultImgUrl from '@/assets/img_fail.png'
import { ElMessage } from 'element-plus';
import { useI18n } from 'vue-i18n';
import { CheckDownAssemFile } from "@/api/detail.ts"
const { t } = useI18n()
const props = defineProps({
  tag: {
    type: String,
    default: "normal"
  },
  pid: Number,
  sid: Number,
  width: Number,
  height: Number,
  path: String,
  cad: String
})
const { tag, pid, sid, path, cad } = toRefs(props)
const state = reactive({
  currentimageList: [],
  isDebug: false, //是否显示图片路径
  isVisibleWaterMark: true, //是否显示水印
  OptionssalseImg: {
    "title": false,
  },
  CAD_Path: null,
  m_PID: 0,
  m_SID: 0,
  m_loadingCheck:false
})
watch(path, (newVal, oldVal) => {
  state.currentimageList = [];
  if (newVal == null || newVal == "") return;
  state.currentimageList.push(newVal);
 
})
watch(cad, (newVal, oldVal) => {
  if (newVal == null || newVal == "") return;
  state.CAD_Path = newVal.replace('.png', '.dwg');
})
watch(pid, (newVal, oldVal) => {
  if (!newVal || newVal == "") return;
  state.m_PID = newVal
})
watch(sid, (newVal, oldVal) => {
  if (!newVal || newVal == "") return;
  state.m_SID = newVal
})
onMounted(() => {
  state.isDebug = window.globalConfig.IsDebug;
  state.isVisibleWaterMark = window.globalConfig.IsVisibleWaterMark;
})
const useDefaultImage = (event) => {
  event.target.src = defaultImgUrl;
}
const exportCAD = async () => {
  extractCadByAuth()
}
// 校验cad下载权限
const extractCadByAuth = () => {
  const FileSuffix = {
    'PDF':0,
    'CAD':3,
    'PNG':4
  }
  let requestData = {
    SeriesID: state.m_SID,
    ProductID : state.m_PID,
    FilePath: state.CAD_Path,
    FileSuffixType:FileSuffix.CAD
  }
  state.m_loadingCheck = true;
  CheckDownAssemFile(requestData).then(async (res) => {
    state.m_loadingCheck = false;
    let result = res.data;
    if (result.Code !== 0) {
      ElMessage.error(result.Message);
      return;
    }
    let isExistFile = await UtilsHelper.isExistImgPath(state.CAD_Path)
    if (!isExistFile) {
      ElMessage.error("暂未上传对应的CAD文件")
      return
    }
    UtilsHelper.downloadFile(state.CAD_Path, UtilsHelper.extractFileExtension(state.CAD_Path))
  }).catch(err => {
    state.m_loadingCheck = false;
    console.log(err, '异常错误');
  })
}
</script>
<style lang="scss">
.tabBackground {
  border: 1px solid #eae8e8;
  background-color: white;
  margin-top: -1px;
}
 
.imgBox {
  width: 100%;
  height: 100% !important;
  display: flex;
  justify-content: center;
  align-items: center;
}
 
.diagram {
  cursor: pointer;
  font-size: 12px;
  margin-top: 0;
  margin-bottom: 3px;
  padding-top: 5px;
  height: 27px;
 
  &>span {
    font-size: 12px;
    font-family: "SourceHanSans-Bold";
  }
}
 
.pos_style {
  position: absolute;
  height: 15px;
  line-height: 15px;
  left: 10px;
  top: 5px;
}
 
.debug_span {
  z-index: 1000;
  position: absolute;
  bottom: 2px;
  left:0px;
  opacity: 0.4;
}
 
.btn-export {
  width: unset;
  height: unset;
  border-radius: unset;
  border-width: 0;
  padding: 7px 14px;
  font-size: 12px;
  outline: none !important;
  background-image: none !important;
  border-radius: unset !important;
  filter: none;
  border-radius: 0;
  box-shadow: none;
  text-shadow: none;
 
  &.default {
    color: #333333;
    background-color: #e5e5e5 !important;
 
    &:hover {
      background-color: #aaaaaa;
    }
  }
 
  &.blue-stripe {
    border-left: 3px solid #4b8df8;
  }
}
</style>