diff --git a/package.json b/package.json index 768ba63..afd19f0 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "vue": "2.6.12", "vue-count-to": "1.0.13", "vue-cropper": "0.5.5", + "vue-print-nb": "^1.7.5", "vue-router": "3.4.9", "vuedraggable": "2.24.3", "vuex": "3.6.0" diff --git a/src/assets/images/cases/logo.jpg b/src/assets/images/cases/logo.jpg new file mode 100644 index 0000000..79eccbc Binary files /dev/null and b/src/assets/images/cases/logo.jpg differ diff --git a/src/main.js b/src/main.js index b7fc26d..f43260e 100644 --- a/src/main.js +++ b/src/main.js @@ -2,8 +2,8 @@ import Vue from 'vue' import Cookies from 'js-cookie' import dayjs from 'dayjs' - import Element from 'element-ui' +import Print from 'vue-print-nb' import './assets/styles/element-variables.scss' // 安全防护 import { initSecurity, setupErrorHandler } from '@/utils/security' @@ -14,6 +14,7 @@ import App from './App' import store from './store' import router from './router' import directive from './directive' // directive +import print from './utils/print' // print utils import plugins from './plugins' // plugins import { download } from '@/utils/request' @@ -39,6 +40,7 @@ import DictTag from '@/components/DictTag' // 字典数据组件 import DictData from '@/components/DictData' + // 全局方法挂载 Vue.prototype.getDicts = getDicts Vue.prototype.getConfigKey = getConfigKey @@ -63,6 +65,7 @@ Vue.component('ImagePreview', ImagePreview) Vue.use(directive) Vue.use(plugins) +Vue.use(Print); //注册 DictData.install() /** diff --git a/src/utils/print.js b/src/utils/print.js new file mode 100644 index 0000000..9661de5 --- /dev/null +++ b/src/utils/print.js @@ -0,0 +1,76 @@ +export default function print(html) { + let style = getStyle(); + let container = getContainer(html); + + document.body.appendChild(style); + document.body.appendChild(container); + + getLoadPromise(container).then(() => { + window.print(); + document.body.removeChild(style); + document.body.removeChild(container); + }); +} + +// 设置打印样式 +function getStyle() { + let styleContent = `#print-container { + display: none; + } + @media print { + body > :not(.print-container) { + display: none; + } + html, + body { + display: block !important; + } + #print-container { + display: block; + } + }`; + let style = document.createElement("style"); + style.innerHTML = styleContent; + return style; +} + +// 清空打印内容 +function cleanPrint() { + let div = document.getElementById('print-container') + if (!!div) { + document.querySelector('body').removeChild(div) + } +} + +// 新建DOM,将需要打印的内容填充到DOM +function getContainer(html) { + cleanPrint() + let container = document.createElement("div"); + container.setAttribute("id", "print-container"); + container.innerHTML = html; + return container; +} + +// 图片完全加载后再调用打印方法 +function getLoadPromise(dom) { + let imgs = dom.querySelectorAll("img"); + imgs = [].slice.call(imgs); + + if (imgs.length === 0) { + return Promise.resolve(); + } + + let finishedCount = 0; + return new Promise(resolve => { + function check() { + finishedCount++; + if (finishedCount === imgs.length) { + resolve(); + } + } + imgs.forEach(img => { + img.addEventListener("load", check); + img.addEventListener("error", check); + }) + }); +} diff --git a/src/views/cases/components/UltrasoundReportPrint.vue b/src/views/cases/components/UltrasoundReportPrint.vue index f5b9aa3..a9efa1c 100644 --- a/src/views/cases/components/UltrasoundReportPrint.vue +++ b/src/views/cases/components/UltrasoundReportPrint.vue @@ -1,277 +1,250 @@ - - - \ No newline at end of file + diff --git a/src/views/cases/detail.vue b/src/views/cases/detail.vue index 556d181..4acdc87 100644 --- a/src/views/cases/detail.vue +++ b/src/views/cases/detail.vue @@ -10,7 +10,7 @@ type="text" icon="el-icon-plus" @click="handleOpenFile" - v-if="form.status == 1 || form.status == 5" + :disabled="form.status != 1 && form.status != 5" > 新增 @@ -18,7 +18,7 @@ @@ -641,7 +633,10 @@ import { postReportPhraseDelete, postReportPhraseCount, postReportTemplateTree, + postReportPrint, } from "@/api/cases/index.js"; +import { postMessagePushToUser } from "@/api/knowledge"; +import { mapGetters } from "vuex"; // 导入打印组件 import UltrasoundReportPrint from "./components/UltrasoundReportPrint.vue"; import CreateGroupDialog from "@/views/message/components/CreateGroupDialog"; @@ -651,13 +646,13 @@ export default { UltrasoundReportPrint, CreateGroupDialog, }, + computed: { + ...mapGetters(["userInfo"]), + }, data() { return { - // 新增:控制打印弹窗显隐 - printDialogVisible: false, // ================== 分享相关 ================== shareDialogVisible: false, // 分享弹窗 - shareItem: null, // 当前分享的病例 // 主报告表单 form: { attachment: [], @@ -938,28 +933,71 @@ export default { }, // 打印 handlePrint() { - this.printDialogVisible = true; // 打开打印预览弹窗 + this.$refs.UltrasoundReportPrintRef.print(this.form); }, handleClose() { this.$router.back(); }, handleShare() { - this.shareItem = { - patientName: this.form.patientName, - medicalNo: this.form.medicalNo, - text_comment: this.form.text_comment, - conclusion: this.form.conclusion, - }; - this.shareDialogVisible = true; + this.$refs.createGroupDialogRef.show(); }, handleShareToContacts(selectedMembers) { + // form if (selectedMembers && selectedMembers.length > 0) { - const shareTarget = selectedMembers[0]; - this.$message.success(`已分享给 ${shareTarget.name}`); - console.log("分享病例:", this.shareItem, "给:", shareTarget); + postMessagePushToUser({ + client_id: "utalk-client-689", + message: { + at_users: [], + message_id: 0, + payload: { + content: JSON.stringify({ + age: this.form.patient_age || 0, + agetype: this.form.patient_age_type + ? patientAgeTypeList.find( + (i) => i.value == this.form.patient_age_type + ).label || "" + : "", + body: this.form.positions.length + ? this.form.positions + .map((item) => item.level2.name) + .join("|") + + (this.form.position_text + ? "|" + this.form.position_text + : "") + : this.form.position_text, + name: this.form.patient_name || "", + report_id: this.form.id, + sex: this.form.patient_sex + ? patientSexList.find((i) => i.value == this.form.patient_sex) + .label || "" + : "", + status: + this.form.submit_type || 0 + ? this.statusList.find( + (i) => i.value == this.form.submit_type + ).label || "" + : "", + }), + file_duration: 0, + file_ico: "", + file_name: "", + file_path: "", + file_size: 0, + file_type: "", + }, + scene: 1, + source_id: this.userInfo.id, + target_id: selectedMembers[0].id, + timestamp: 0, + type: "report_share", + }, + target_id: selectedMembers[0].id, + topic: "/user/¯", + }).then((res) => { + this.$modal.msgSuccess(`已分享给 ${selectedMembers[0].name}`); + }); + this.shareDialogVisible = false; } - this.shareDialogVisible = false; - this.shareItem = null; }, // 部位模板列表 loadTemplateList() { @@ -1129,7 +1167,7 @@ export default {