项目管理生成二维码添加打印功能

This commit is contained in:
lc 2024-04-17 09:08:56 +08:00
parent bf689c0a75
commit 38b6eb62d4
2 changed files with 62 additions and 7 deletions

View File

@ -37,7 +37,7 @@ import DictTag from '@/components/DictTag'
import VueMeta from 'vue-meta' import VueMeta from 'vue-meta'
// 字典数据组件 // 字典数据组件
import DictData from '@/components/DictData' import DictData from '@/components/DictData'
import Print from 'vue-print-nb'
// 全局方法挂载 // 全局方法挂载
Vue.prototype.getDicts = getDicts Vue.prototype.getDicts = getDicts
Vue.prototype.getConfigKey = getConfigKey Vue.prototype.getConfigKey = getConfigKey
@ -61,6 +61,7 @@ Vue.component('ImagePreview', ImagePreview)
Vue.use(directive) Vue.use(directive)
Vue.use(plugins) Vue.use(plugins)
Vue.use(VueMeta) Vue.use(VueMeta)
Vue.use(Print);
DictData.install() DictData.install()
/** /**

View File

@ -76,14 +76,17 @@
</el-dialog> </el-dialog>
<!-- 二维码 --> <!-- 二维码 -->
<el-dialog :visible.sync="codeOpen" width="250px" append-to-body> <el-dialog :visible.sync="codeOpen" width="250px" append-to-body>
<div id="printdata">
<div>项目名称<span>{{ this.titles }}</span></div> <div>项目名称<span>{{ this.titles }}</span></div>
<div> <div>
<vue-qr ref="qrCode" :text="texturl" :logoSrc="logoSrc" :color-dark="randomColor"></vue-qr> <vue-qr ref="qrCode" :text="texturl" :logoSrc="logoSrc" :color-dark="randomColor"></vue-qr>
</div> </div>
</div>
<div slot="footer"> <div slot="footer">
<el-button type="primary" @click="() => { <el-button type="primary" @click="() => { codeOpen = false }">确定</el-button>
codeOpen = false <el-button type="text" @click="handlePrint" v-print="'#printdata'" >下载二维码</el-button>
}">确定</el-button>
</div> </div>
</el-dialog> </el-dialog>
</div> </div>
@ -91,6 +94,7 @@
<script> <script>
import { listProject, getProject, delProject, addProject, updateProject } from "@/api/abuwx/project"; import { listProject, getProject, delProject, addProject, updateProject } from "@/api/abuwx/project";
import upload from '@/components/FileUpload/index.vue' import upload from '@/components/FileUpload/index.vue'
import VueQr from 'vue-qr' import VueQr from 'vue-qr'
// import { Base64 } from "js-base64"; // import { Base64 } from "js-base64";
@ -103,6 +107,35 @@ export default {
}, },
data() { data() {
return { return {
printContent: {
id: "printdata", //
preview: false, //
previewTitle: "", //
popTitle: "", //
// extraCss: "", //css
previewBeforeOpenCallback(vue) {
console.log("正在加载预览窗口");
},
previewOpenCallback(vue) {
console.log("已经加载完预览窗口");
},
clickMounted: (vue) => {
console.log("触发点击打印回调");
vue.isShowPrint = true; //
},
beforeOpenCallback(vue) {
console.log("打开之前", vue.barcodeNum);
},
openCallback(vue) {
console.log(vue);
vue.isShowPrint = false; //
console.log("执行了打印", vue.barcodeNum);
},
},
fontSizeText: "16px",
lineHeightText: "16px",
downLoadUrl :process.env.VUE_APP_BASE_API, downLoadUrl :process.env.VUE_APP_BASE_API,
// //
loading: true, loading: true,
@ -251,7 +284,28 @@ export default {
this.download('abuwx/project/export', { this.download('abuwx/project/export', {
...this.queryParams ...this.queryParams
}, `project_${new Date().getTime()}.xlsx`) }, `project_${new Date().getTime()}.xlsx`)
} },
handlePrint(qrCode,name) {
// refName ref name
const iconUrl = this.$refs[qrCode].$el.src //currentSrc
console.log(this.$refs[qrCode],'=====================')
const a = document.createElement('a')
const event = new MouseEvent('click')
a.download = name
a.href = iconUrl
a.dispatchEvent(event)
},
} }
}; };
</script> </script>
<style scoped lang="scss">
#printdata {
text-align: center;
font-weight: 700;
font-size: 20px;
.text {
margin-bottom: 20px;
}
}
</style>