From b1ce70777fb52ba986b6a8cf1b00cce93c2e84be Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 14 十一月 2025 17:46:47 +0800
Subject: [PATCH] 1. 修改巡查单据的下载功能(待完成)
---
src/views/fysp/scene/SceneInspectFile.vue | 173 +++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 118 insertions(+), 55 deletions(-)
diff --git a/src/views/fysp/scene/SceneInspectFile.vue b/src/views/fysp/scene/SceneInspectFile.vue
index 2f0e860..ddeaeb4 100644
--- a/src/views/fysp/scene/SceneInspectFile.vue
+++ b/src/views/fysp/scene/SceneInspectFile.vue
@@ -28,21 +28,26 @@
'鍦板潃锛�' + item.scense.location
}}</el-text>
</div>
- <el-space class="m-t-4">
- <el-tag>
- {{
- item.scense.cityname +
- item.scense.districtname +
- item.scense.townname
- }}
- <!-- {{ item.scense.districtname }}
- {{ item.scense.townname }} -->
- </el-tag>
- <el-tag>{{ item.scense.type }}</el-tag>
-
- <!-- {{ item.scense.contacts }}
- {{ item.scense.contactst }} -->
- </el-space>
+ <el-row justify="space-between">
+ <el-space class="m-t-4">
+ <el-tag>
+ {{
+ item.scense.cityname +
+ item.scense.districtname +
+ item.scense.townname
+ }}
+ </el-tag>
+ <el-tag>{{ item.scense.type }}</el-tag>
+ </el-space>
+ <el-button
+ type="default"
+ size="small"
+ class="m-t-4"
+ @click="handlePreview(item)"
+ >
+ 棰勮
+ </el-button>
+ </el-row>
</el-checkbox>
</el-space>
</el-checkbox-group>
@@ -53,11 +58,28 @@
<el-button type="primary" :loading="docLoading" @click="handelDownload">
涓嬭浇
</el-button>
- <!-- <el-button type="default" :loading="docLoading" @click="handelPrint">
+ <el-button type="default" :loading="docLoading" @click="handelPrint">
鎵撳嵃
- </el-button> -->
+ </el-button>
</div>
</template>
+ </el-dialog>
+ <el-dialog v-model="previewVisible" :show-close="false" fullscreen>
+ <template #header="{ close, titleId, titleClass }">
+ <el-row justify="end">
+ <el-button type="danger" @click="close" icon="CircleCloseFilled">
+ 鍏抽棴
+ </el-button>
+ <el-button
+ type="primary"
+ @click="handelPrint(refWord)"
+ icon="PrintFilled"
+ >
+ 鎵撳嵃
+ </el-button>
+ </el-row>
+ </template>
+ <div ref="refWord"></div>
</el-dialog>
</template>
<script setup>
@@ -65,23 +87,36 @@
* 鍦烘櫙宸℃煡鍗曟嵁鑷姩涓嬭浇
*/
import { ref, watch } from 'vue';
-import { exportDocx } from '@/utils/doc';
+import {
+ exportDocx,
+ prepareDocxBlob,
+ preparePdf,
+ previewDocx,
+ downloadDocx,
+ print
+} from '@/utils/doc';
import sceneApi from '@/api/fysp/sceneApi';
const props = defineProps({
// 瀵硅瘽妗嗗紑鍏�
modelValue: Boolean,
// 鍦烘櫙鍩虹淇℃伅鏁扮粍
- value: Array
+ value: Array,
+ previewElement: String
});
const emits = defineEmits(['update:modelValue']);
+
+const refWord = ref(null);
const loading = ref(false);
const scrollbarRef = ref();
const sceneInfoList = ref([]);
const checkList = ref([]);
const docLoading = ref(false);
+
+// 棰勮瀵硅瘽妗嗗紑鍏�
+const previewVisible = ref(false);
watch(
() => [props.modelValue, props.value],
@@ -139,10 +174,12 @@
}
// 鏍煎紡鍖栧満鏅俊鎭紝鐢熸垚鍙傛暟缁撴瀯
-function parseParam() {
- const selected = sceneInfoList.value.filter((v, i) => {
- return checkList.value.indexOf(i) != -1;
- });
+function parseParam(item) {
+ const selected = item
+ ? [item]
+ : sceneInfoList.value.filter((v, i) => {
+ return checkList.value.indexOf(i) != -1;
+ });
const param = selected.map((v) => {
switch (v.scense.typeid) {
// 宸ュ湴
@@ -187,22 +224,12 @@
}
});
- // param.forEach((p) => {
- // for (const key in p.params) {
- // let value = p.params[key];
- // if (value == undefined) {
- // // 鑻ュ睘鎬х己澶憋紝鍒欐敼涓�20涓┖鏍肩锛屽搴攚ord涓�10涓腑鏂囧瓧绗︾殑闀垮害
- // p.params[key] = ' ';
- // }
- // }
- // });
-
return param;
}
// 鏍规嵁鍦烘櫙绫诲瀷锛岀敓鎴愬搴旂殑word鏂囨。
-function generateDoc(param) {
- param.forEach((p) => {
+function generateDoc(param, callback) {
+ param.map((p) => {
let template, _param;
switch (p.type) {
// 宸ュ湴
@@ -218,39 +245,72 @@
default:
break;
}
-
- exportDocx(template, _param, `${_param.name}宸℃煡鍗曟嵁.docx`).finally(
- () => (docLoading.value = false)
- );
+ prepareDocxBlob(template, _param).then((blob) => {
+ callback(blob, `${_param.name}宸℃煡鍗曟嵁.docx`);
+ });
});
}
-// 涓嬭浇word鏂囨。
-function download(file) {}
+function generatePdf(param, callback) {
+ param.map((p) => {
+ let template, _param;
+ switch (p.type) {
+ // 宸ュ湴
+ case 1:
+ template = '/宸ュ湴宸℃煡鍗曟嵁妯℃澘.docx';
+ _param = p.params;
+ break;
+ // 椁愰ギ
+ case 5:
+ template = '/椁愰ギ宸℃煡鍗曟嵁妯℃澘.docx';
+ _param = p.params;
+ break;
+ default:
+ break;
+ }
+ preparePdf(template, _param).then((blob) => {
+ callback(blob, `${_param.name}宸℃煡鍗曟嵁.pdf`);
+ });
+ });
+}
-// 鎵撳嵃word鏂囨。
-function print(file) {}
-
-function filePrepare() {
+function filePrepare(callback) {
const param = parseParam();
if (param) {
- return generateDoc(param);
+ return generateDoc(param, callback);
}
}
-// 鐐瑰嚮涓嬭浇鎸夐挳鎿嶄綔
+// 鐐瑰嚮涓嬭浇鎸夐挳鎿嶄綔, 涓嬭浇word鏂囨。
function handelDownload() {
- const file = filePrepare();
- if (file) {
- download(file);
- }
+ filePrepare((blob, name) => {
+ downloadDocx(blob, name);
+ });
}
// 鐐瑰嚮鎵撳嵃鎸夐挳鎿嶄綔
-function handelPrint() {
- const file = filePrepare();
- if (file) {
- print(file);
+function handelPrint(ref) {
+ if (ref) {
+ print(ref);
+ }
+ // const file = filePrepare();
+ // if (file) {
+ // previewDocx(file.blob, refWord.value);
+ // }
+}
+
+function handlePreview(item) {
+ const param = parseParam(item);
+ if (param) {
+ generatePdf(param, (blob, name) => {
+ blob.getBuffer((buffer) => {
+ previewDocx(buffer, refWord.value);
+ });
+ previewVisible.value = true;
+ // setTimeout(() => {
+ // previewDocx(blob, refWord.value);
+ // }, 200);
+ });
}
}
@@ -271,4 +331,7 @@
:deep(.el-checkbox) {
height: auto;
}
+:deep(.el-checkbox__label) {
+ width: 100%;
+}
</style>
--
Gitblit v1.9.3