From d2d52c3089309ab1a7cec26d5e2f8c44e9733635 Mon Sep 17 00:00:00 2001 From: wx-jincw Date: Sun, 6 Apr 2025 15:28:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=BF=AE=E6=94=B9=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bs-ui/src/components/MyImageViewer/index.vue | 7 +- bs-ui/src/main.js | 2 + bs-ui/src/mixins/table-mixin.js | 1 + bs-ui/src/plugins/print.js | 123 ++++++++++++++++++ .../gallery/list/components/ImageItem.vue | 14 +- bs-ui/src/views/gallery/list/index.vue | 52 ++++++-- 6 files changed, 177 insertions(+), 22 deletions(-) create mode 100644 bs-ui/src/plugins/print.js diff --git a/bs-ui/src/components/MyImageViewer/index.vue b/bs-ui/src/components/MyImageViewer/index.vue index b63ce30..b100002 100644 --- a/bs-ui/src/components/MyImageViewer/index.vue +++ b/bs-ui/src/components/MyImageViewer/index.vue @@ -42,7 +42,12 @@ export default { srcList() { console.log("this.files"); console.log(this.files); - return this.files.map(val => process.env.VUE_APP_BASE_API + val.attachFileurl); + return this.files.map(val => { + if (val.attachFileurl.indexOf("http") === 0) { + return val.attachFileurl; + } + return process.env.VUE_APP_BASE_API + val.attachFileurl; + }); } }, methods: { diff --git a/bs-ui/src/main.js b/bs-ui/src/main.js index 4b78186..c16e679 100644 --- a/bs-ui/src/main.js +++ b/bs-ui/src/main.js @@ -12,6 +12,7 @@ import store from './store' import router from './router' import directive from './directive' // directive import plugins from './plugins' // plugins +import Print from './plugins/print'; import { download } from '@/utils/request' import './assets/icons' // icon @@ -67,6 +68,7 @@ Vue.mixin(CommonMixin); Vue.use(directive) Vue.use(plugins) +Vue.use(Print) Vue.use(VueMeta) DictData.install() diff --git a/bs-ui/src/mixins/table-mixin.js b/bs-ui/src/mixins/table-mixin.js index 9b9bea2..7c7e7d3 100644 --- a/bs-ui/src/mixins/table-mixin.js +++ b/bs-ui/src/mixins/table-mixin.js @@ -23,6 +23,7 @@ export default { query: { ...this.MXPageInfo().defaultQuery }, tableSort: {}, // 表格相关参数end + showSearch: true, }; }, created() { diff --git a/bs-ui/src/plugins/print.js b/bs-ui/src/plugins/print.js new file mode 100644 index 0000000..1e1c861 --- /dev/null +++ b/bs-ui/src/plugins/print.js @@ -0,0 +1,123 @@ +const Print = function (dom, options) { + if (!(this instanceof Print)) return new Print(dom, options); + + this.options = this.extend({ + noPrint: '.no-print', + onStart: function () {}, + onEnd: function () {} + }, options); + + if ((typeof dom) === "string") { + this.dom = document.querySelector(dom); + } else { + this.dom = dom; + } + + this.init(); +}; +Print.prototype = { + init: function () { + let content = this.getStyle() + this.getHtml(); + this.writeIframe(content); + }, + extend: function (obj, obj2) { + for (let k in obj2) { + obj[k] = obj2[k]; + } + return obj; + }, + + getStyle: function () { + let str = ""; + let styles = document.querySelectorAll('style,link'); + for (let i = 0; i < styles.length; i++) { + str += styles[i].outerHTML; + } + str += ""; + + return str; + }, + + getHtml: function () { + let inputs = document.querySelectorAll('input'); + let textareas = document.querySelectorAll('textarea'); + let selects = document.querySelectorAll('select'); + + for (let k in inputs) { + if (inputs[k].type === "checkbox" || inputs[k].type === "radio") { + if (inputs[k].checked === true) { + inputs[k].setAttribute('checked', "checked"); + } else { + inputs[k].removeAttribute('checked'); + } + } else if (inputs[k].type === "text") { + inputs[k].setAttribute('value', inputs[k].value); + } + } + + for (let k2 in textareas) { + if (textareas[k2].type === 'textarea') { + textareas[k2].innerHTML = textareas[k2].value; + } + } + + for (let k3 in selects) { + if (selects[k3].type === 'select-one') { + let child = selects[k3].children; + for (let i in child) { + if (child[i].tagName === 'OPTION') { + if (child[i].selected === true) { + child[i].setAttribute('selected', "selected"); + } else { + child[i].removeAttribute('selected'); + } + } + } + } + } + return this.dom.outerHTML; + }, + + writeIframe: function (content) { + let w; + let doc; + let iframe = document.createElement('iframe'); + let f = document.body.appendChild(iframe); + iframe.id = "myIframe"; + iframe.style = "position:absolute;width:0;height:0;top:-10px;left:-10px;"; + w = f.contentWindow || f.contentDocument; + doc = f.contentDocument || f.contentWindow.document; + doc.open(); + doc.write(content); + doc.close(); + this.toPrint(w, function () { + document.body.removeChild(iframe); + }); + }, + + toPrint: function (w, cb) { + let _this = this; + w.onload = function () { + try { + setTimeout(function () { + w.focus(); + typeof _this.options.onStart === 'function' && _this.options.onStart(); + if (!w.document.execCommand('print', false, null)) { + w.print(); + } + typeof _this.options.onEnd === 'function' && _this.options.onEnd(); + w.close(); + cb && cb(); + }); + } catch (err) { + console.log('err', err); + } + }; + } +}; +const MyPlugin = {}; +MyPlugin.install = function (Vue, options) { + // 4. 添加实例方法 + Vue.prototype.$print = Print; +}; +export default MyPlugin; diff --git a/bs-ui/src/views/gallery/list/components/ImageItem.vue b/bs-ui/src/views/gallery/list/components/ImageItem.vue index 9adf853..3153192 100644 --- a/bs-ui/src/views/gallery/list/components/ImageItem.vue +++ b/bs-ui/src/views/gallery/list/components/ImageItem.vue @@ -1,16 +1,14 @@ diff --git a/bs-ui/src/views/gallery/list/index.vue b/bs-ui/src/views/gallery/list/index.vue index 2b23e44..9ae1205 100644 --- a/bs-ui/src/views/gallery/list/index.vue +++ b/bs-ui/src/views/gallery/list/index.vue @@ -1,17 +1,17 @@ @@ -55,5 +76,10 @@ export default { .image-list { display: flex; flex-wrap: wrap; + + .image-item { + width: 300px; + margin: 0 15px 15px 0; + } } \ No newline at end of file