ol-base-components 2.9.4 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/public/index.html +1 -0
- package/public/print-lock.css +352 -0
- package/src/App.vue +276 -33
- package/src/assets/css/iconfont.css +342 -0
- package/src/main.js +4 -5
- package/src/package/index.js +4 -3
- package/src/package/print/index.js +78 -0
- package/src/package/print/src/components/PaperSelector.vue +123 -0
- package/src/package/print/src/index.vue +625 -0
- package/src/package/print/src/provide/aaa.json +110 -0
- package/src/package/print/src/provide/provider1.js +215 -0
- package/src/package/table/src/index.vue +16 -11
package/src/package/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import OlSearch from "./formSearch";
|
|
|
3
3
|
import Dialog from "./dialog";
|
|
4
4
|
import OlForm from "./form";
|
|
5
5
|
import OlNumberRange from "./numberRange";
|
|
6
|
+
import OlPrint, { Hiprint } from "./print";
|
|
6
7
|
|
|
7
8
|
import SwaggerClient from "swagger-client";
|
|
8
9
|
|
|
@@ -204,7 +205,7 @@ function hideLoading() {
|
|
|
204
205
|
}
|
|
205
206
|
}
|
|
206
207
|
|
|
207
|
-
const components = [OlTable, OlSearch, Dialog, OlForm, OlNumberRange];
|
|
208
|
+
const components = [OlTable, OlSearch, Dialog, OlForm, OlNumberRange, OlPrint];
|
|
208
209
|
const install = async function (Vue) {
|
|
209
210
|
// 设置全局数据
|
|
210
211
|
components.map(item => {
|
|
@@ -214,5 +215,5 @@ const install = async function (Vue) {
|
|
|
214
215
|
};
|
|
215
216
|
|
|
216
217
|
export default install;
|
|
217
|
-
export { OlTable, OlSearch, Dialog, OlForm, OlNumberRange };
|
|
218
|
-
export { swaggerInstall, swaggerUnload };
|
|
218
|
+
export { OlTable, OlSearch, Dialog, OlForm, OlNumberRange, OlPrint };
|
|
219
|
+
export { swaggerInstall, swaggerUnload, Hiprint };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import OlPrint from "./src/index.vue";
|
|
2
|
+
|
|
3
|
+
// 方式1:组件方式注册
|
|
4
|
+
OlPrint.install = function (Vue) {
|
|
5
|
+
Vue.component("ol-print", OlPrint);
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// 方式2:插件方式注册(全局方法)
|
|
9
|
+
let printInstance = null;
|
|
10
|
+
let container = null;
|
|
11
|
+
|
|
12
|
+
const Hiprint = {
|
|
13
|
+
install(Vue) {
|
|
14
|
+
const hiprint = function (options) {
|
|
15
|
+
const { printData, onPrintData, defaultTemplate, onTemplate, onSubmit } = options;
|
|
16
|
+
// 销毁旧实例
|
|
17
|
+
if (printInstance) {
|
|
18
|
+
printInstance.$destroy();
|
|
19
|
+
if (container && container.parentNode) {
|
|
20
|
+
container.parentNode.removeChild(container);
|
|
21
|
+
}
|
|
22
|
+
printInstance = null;
|
|
23
|
+
container = null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 创建新实例
|
|
27
|
+
container = document.createElement("div");
|
|
28
|
+
document.body.appendChild(container);
|
|
29
|
+
|
|
30
|
+
const PrintComponent = Vue.extend(OlPrint);
|
|
31
|
+
const propsData = {};
|
|
32
|
+
if (printData) {
|
|
33
|
+
propsData.printData = printData;
|
|
34
|
+
}
|
|
35
|
+
if (onPrintData) {
|
|
36
|
+
propsData.onPrintData = onPrintData;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (onTemplate) {
|
|
40
|
+
propsData.onTemplate = onTemplate;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (defaultTemplate) {
|
|
44
|
+
propsData.defaultTemplate = defaultTemplate;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
printInstance = new PrintComponent({
|
|
48
|
+
propsData,
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// 监听 submit 事件
|
|
52
|
+
if (onSubmit && typeof onSubmit === "function") {
|
|
53
|
+
printInstance.$on("submit", json => {
|
|
54
|
+
onSubmit(json);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
printInstance.$mount(container);
|
|
59
|
+
|
|
60
|
+
// 返回实例,方便外部调用
|
|
61
|
+
return printInstance;
|
|
62
|
+
};
|
|
63
|
+
Vue.prototype.$hiprint = hiprint;
|
|
64
|
+
|
|
65
|
+
// 快捷方法:直接打印
|
|
66
|
+
Vue.prototype.$hiprint.print = function (options) {
|
|
67
|
+
const instance = hiprint(options);
|
|
68
|
+
instance.print();
|
|
69
|
+
instance.$nextTick(() => {
|
|
70
|
+
instance.close();
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// 导出组件和插件
|
|
77
|
+
export { OlPrint, Hiprint };
|
|
78
|
+
export default OlPrint;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="paper-selector">
|
|
3
|
+
<el-button-group>
|
|
4
|
+
<el-button
|
|
5
|
+
v-for="(value, type) in paperTypes"
|
|
6
|
+
:key="type"
|
|
7
|
+
:type="curPaperType === type ? 'primary' : 'default'"
|
|
8
|
+
size="small"
|
|
9
|
+
@click="setPaper(type, value)"
|
|
10
|
+
>
|
|
11
|
+
{{ type }}
|
|
12
|
+
</el-button>
|
|
13
|
+
<el-button
|
|
14
|
+
:type="curPaperType === 'other' ? 'primary' : 'default'"
|
|
15
|
+
size="small"
|
|
16
|
+
@click="showPaperPop"
|
|
17
|
+
>
|
|
18
|
+
自定义纸张
|
|
19
|
+
</el-button>
|
|
20
|
+
</el-button-group>
|
|
21
|
+
|
|
22
|
+
<el-dialog
|
|
23
|
+
title="设置纸张宽高(mm)"
|
|
24
|
+
:visible.sync="paperPopVisible"
|
|
25
|
+
width="400px"
|
|
26
|
+
:append-to-body="true"
|
|
27
|
+
>
|
|
28
|
+
<el-form label-width="80px">
|
|
29
|
+
<el-form-item label="纸张宽度">
|
|
30
|
+
<el-input v-model="paperWidth" type="number" placeholder="宽(mm)" />
|
|
31
|
+
</el-form-item>
|
|
32
|
+
<el-form-item label="纸张高度">
|
|
33
|
+
<el-input v-model="paperHeight" type="number" placeholder="高(mm)" />
|
|
34
|
+
</el-form-item>
|
|
35
|
+
</el-form>
|
|
36
|
+
<span slot="footer">
|
|
37
|
+
<el-button @click="hidePaperPop">取消</el-button>
|
|
38
|
+
<el-button type="primary" @click="setPaperOther">确定</el-button>
|
|
39
|
+
</span>
|
|
40
|
+
</el-dialog>
|
|
41
|
+
</div>
|
|
42
|
+
</template>
|
|
43
|
+
|
|
44
|
+
<script>
|
|
45
|
+
export default {
|
|
46
|
+
name: "PaperSelector",
|
|
47
|
+
props: {
|
|
48
|
+
hiprintTemplate: {
|
|
49
|
+
type: Object,
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
curPaper: {
|
|
56
|
+
type: "A4",
|
|
57
|
+
width: 210,
|
|
58
|
+
height: 296.6,
|
|
59
|
+
},
|
|
60
|
+
paperTypes: {
|
|
61
|
+
A3: { width: 420, height: 296.6 },
|
|
62
|
+
A4: { width: 210, height: 296.6 },
|
|
63
|
+
A5: { width: 210, height: 147.6 },
|
|
64
|
+
B3: { width: 500, height: 352.6 },
|
|
65
|
+
B4: { width: 250, height: 352.6 },
|
|
66
|
+
B5: { width: 250, height: 175.6 },
|
|
67
|
+
},
|
|
68
|
+
paperPopVisible: false,
|
|
69
|
+
paperWidth: "220",
|
|
70
|
+
paperHeight: "80",
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
computed: {
|
|
74
|
+
curPaperType() {
|
|
75
|
+
let type = "other";
|
|
76
|
+
let types = this.paperTypes;
|
|
77
|
+
for (const key in types) {
|
|
78
|
+
let item = types[key];
|
|
79
|
+
let { width, height } = this.curPaper;
|
|
80
|
+
if (item.width === width && item.height === height) {
|
|
81
|
+
type = key;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return type;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
methods: {
|
|
88
|
+
showPaperPop() {
|
|
89
|
+
this.paperPopVisible = true;
|
|
90
|
+
},
|
|
91
|
+
hidePaperPop() {
|
|
92
|
+
this.paperPopVisible = false;
|
|
93
|
+
},
|
|
94
|
+
setPaper(type, value) {
|
|
95
|
+
try {
|
|
96
|
+
if (Object.keys(this.paperTypes).includes(type)) {
|
|
97
|
+
this.curPaper = { type: type, width: value.width, height: value.height };
|
|
98
|
+
this.hiprintTemplate.setPaper(value.width, value.height);
|
|
99
|
+
} else {
|
|
100
|
+
this.curPaper = { type: "other", width: value.width, height: value.height };
|
|
101
|
+
this.hiprintTemplate.setPaper(value.width, value.height);
|
|
102
|
+
}
|
|
103
|
+
this.$emit("change", this.curPaper);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
this.$message.error(`操作失败: ${error}`);
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
setPaperOther() {
|
|
109
|
+
let value = {};
|
|
110
|
+
value.width = Number(this.paperWidth);
|
|
111
|
+
value.height = Number(this.paperHeight);
|
|
112
|
+
this.paperPopVisible = false;
|
|
113
|
+
this.setPaper("other", value);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
</script>
|
|
118
|
+
|
|
119
|
+
<style scoped>
|
|
120
|
+
.paper-selector {
|
|
121
|
+
display: inline-block;
|
|
122
|
+
}
|
|
123
|
+
</style>
|