index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <el-drawer
  3. v-model="drawerVisible"
  4. :close-on-click-modal="false"
  5. destroy-on-close
  6. direction="rtl"
  7. size="990px"
  8. >
  9. <template #header>
  10. <div class="drawerTitle">图纸资料</div>
  11. </template>
  12. <el-scrollbar>
  13. <!-- <div class="grid-container">
  14. <div v-for="(box, index) in drawingData" :key="index" class="suit-box">
  15. <div class="pdf-box" @click="toShowPDF(box)">
  16. <el-image class="pdf-box" :src="baseUrl + box.pdfPath + '.jpg'">
  17. <template #error>
  18. <el-image class="pdf-box" :src="DefaultPDF" fit="cover" />
  19. </template>
  20. </el-image>
  21. </div>
  22. <div class="suit-title">{{ box?.drawingTitle }}</div>
  23. <div class="suit-desc">{{ box?.created }}</div>
  24. <el-button
  25. class="download-btn"
  26. type="primary"
  27. @click="download(box)"
  28. :key="box.drawingPath"
  29. >下载</el-button
  30. >
  31. </div>
  32. </div> -->
  33. <avue-crud
  34. ref="crudRef"
  35. v-model:search="search"
  36. v-model="form"
  37. :data="data"
  38. :option="option"
  39. v-model:page="page"
  40. @row-save="createRow"
  41. @row-update="updateRow"
  42. @row-del="deleteRow"
  43. @search-change="searchChange"
  44. @search-reset="resetChange"
  45. @size-change="dataList"
  46. @current-change="dataList"
  47. @selection-change="selectionChange"
  48. >
  49. <template #img="{ row }">
  50. <el-image class="pdf-box" :src="baseUrl + row.drawingPath">
  51. <template #error>
  52. <el-image class="pdf-box" :src="DefaultPDF" fit="cover" />
  53. </template>
  54. </el-image>
  55. </template>
  56. <template #menu="{ row, index, type }">
  57. <el-button @click="toShowPDF(row)" link type="primary" size="small"
  58. >查看</el-button
  59. >
  60. <el-button
  61. class="download-btn"
  62. row
  63. link
  64. type="info"
  65. @click="download(row)"
  66. :key="row.drawingPath"
  67. >下载</el-button
  68. >
  69. </template>
  70. </avue-crud>
  71. </el-scrollbar>
  72. <PDFDrawerView ref="PDFDrawerViewRef"></PDFDrawerView>
  73. </el-drawer>
  74. </template>
  75. <script lang="ts" setup>
  76. import { drawingList } from "@/api/process/reportBreak";
  77. import { useProcessStore } from "@/store/modules/processView";
  78. import { useCrud } from "@/hooks/userCrud";
  79. import PDFView from "@/components/PDFView/index.vue";
  80. import DefaultPDF from "@/assets/images/default-pdf.png";
  81. const processStore = useProcessStore();
  82. const drawingData = ref<any>([]);
  83. const baseUrl = import.meta.env.VITE_APP_UPLOAD_URL;
  84. const { form, data, option, search, page, toDeleteIds, Methords, Utils } =
  85. useCrud({
  86. src: "/api/v1/base/drawing",
  87. });
  88. const { dataList, createRow, updateRow, deleteRow, searchChange, resetChange } =
  89. Methords; //增删改查
  90. const { selectionChange, multipleDelete } = Methords; //选中和批量删除事件
  91. const { checkBtnPerm, downloadTemplate, exportData } = Utils;
  92. option.value = Object.assign(option.value, {
  93. selection: false,
  94. addBtn: false,
  95. delBtn: false,
  96. editBtn: false,
  97. viewBtn: false,
  98. indexWidth: 80,
  99. grid: true,
  100. gridSpan: 8,
  101. gridBackground: (row, index) => {
  102. if (index === 1) {
  103. return "linear-gradient(to right, rgba(255,255,255,255.2), rgba(255,0,0,0.2))";
  104. } else {
  105. return "linear-gradient(to right, rgba(255,255,255,255.2), rgba(0,255,0,0.2))";
  106. }
  107. },
  108. column: [
  109. {
  110. label: "编号",
  111. prop: "drawingCode",
  112. search: true,
  113. gridRow: true,
  114. },
  115. {
  116. label: "标题",
  117. prop: "drawingTitle",
  118. gridRow: true,
  119. },
  120. {
  121. label: "文件名",
  122. prop: "fileName",
  123. gridRow: true,
  124. },
  125. {
  126. label: "图片",
  127. className: "imgbox",
  128. prop: "img",
  129. align: "center",
  130. },
  131. ],
  132. });
  133. const getListData = () => {
  134. search.value.materialCode = processStore.scanInfo.materialCode;
  135. dataList();
  136. };
  137. onMounted(() => {
  138. // drawingList({ materialCode: processStore.scanInfo.materialCode }).then(
  139. // (res) => {
  140. // console.log("res", res);
  141. // drawingData.value = res.data;
  142. // }
  143. // );
  144. });
  145. const drawerVisible = ref<boolean>(false);
  146. const openDrawer = () => {
  147. getListData();
  148. drawerVisible.value = true;
  149. };
  150. const downloadBtnLoading = ref(false);
  151. const download = async (row: any) => {
  152. downloadBtnLoading.value = true;
  153. let url = import.meta.env.VITE_APP_UPLOAD_URL + row.drawingPath;
  154. // 1. 获取资源并转为Blob
  155. const response = await fetch(url);
  156. const blob = await response.blob();
  157. // 2. 创建临时对象URL
  158. const tempUrl = URL.createObjectURL(blob);
  159. // 3. 创建隐藏a标签触发下载
  160. const link = document.createElement("a");
  161. link.href = tempUrl;
  162. link.download = row.fileName;
  163. link.style.display = "none";
  164. document.body.appendChild(link);
  165. link.click();
  166. // 4. 清理内存
  167. URL.revokeObjectURL(tempUrl);
  168. document.body.removeChild(link);
  169. downloadBtnLoading.value = false;
  170. };
  171. const PDFDrawerViewRef = ref(null);
  172. const toShowPDF = (row) => {
  173. let url = import.meta.env.VITE_APP_UPLOAD_URL + row.pdfPath;
  174. PDFDrawerViewRef.value && PDFDrawerViewRef.value.showPdf(url);
  175. };
  176. defineExpose({
  177. openDrawer,
  178. });
  179. </script>
  180. <style lang="scss" scoped>
  181. .grid-container {
  182. display: grid;
  183. /*行间距*/
  184. grid-row-gap: 24px;
  185. /*列间距*/
  186. grid-column-gap: 24px;
  187. overflow-y: auto;
  188. padding: 24px;
  189. width: calc(100% - 48px);
  190. grid-template-columns: 1fr 1fr 1fr;
  191. height: calc(100vh - 100px);
  192. .suit-box {
  193. height: 343px;
  194. background-color: white;
  195. border-radius: 16px 16px 16px 16px;
  196. display: flex;
  197. flex-direction: column;
  198. align-items: start;
  199. justify-content: center;
  200. position: relative;
  201. .pdf-box {
  202. height: 263px;
  203. width: 100%;
  204. overflow: hidden;
  205. }
  206. .suit-title {
  207. font-weight: 500;
  208. font-size: 20px;
  209. color: rgba(0, 0, 0, 0.9);
  210. text-align: left;
  211. margin-left: 24px;
  212. }
  213. .suit-desc {
  214. font-size: 20px;
  215. color: rgba(0, 0, 0, 0.6);
  216. text-align: left;
  217. margin-left: 24px;
  218. }
  219. .download-btn {
  220. position: absolute;
  221. right: 20px;
  222. top: 20px;
  223. }
  224. }
  225. }
  226. </style>