ol-base-components 3.3.10 → 3.4.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 +1 -1
- package/src/App.vue +52 -21
- package/src/assets/print.svg +1 -0
- package/src/main.js +1 -1
- package/src/package/customSearch/src/index.vue +12 -2
- package/src/package/formSearch/src/index.vue +4 -4
- package/src/package/print/src/index.vue +5 -7
- package/src/package/printModel/src/index.vue +21 -4
- package/src/package/table/src/components/PrintTemplateSelector.vue +114 -10
- package/src/package/table/src/index.vue +59 -16
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -26,10 +26,14 @@
|
|
|
26
26
|
@SelectionChange="SelectionChange"
|
|
27
27
|
@handleSizeChange="handleSizeChange"
|
|
28
28
|
@handleindexChange="handleindexChange"
|
|
29
|
+
:onPrintData="onPrintData"
|
|
29
30
|
>
|
|
30
31
|
<template slot="ceshi" slot-scope="scope">
|
|
31
32
|
<span>333433{{ scope.row.ceshi }}</span>
|
|
32
33
|
</template>
|
|
34
|
+
<template slot="toolbox-before" slot-scope="scope">
|
|
35
|
+
<el-button type="primary" size="mini" @click="handlePrint1(scope)">打印</el-button>
|
|
36
|
+
</template>
|
|
33
37
|
</ol-table>
|
|
34
38
|
<!-- <el-button @click="handlePrint">接口</el-button>
|
|
35
39
|
<el-button @click="onAdd">新建</el-button>
|
|
@@ -121,6 +125,10 @@ export default {
|
|
|
121
125
|
],
|
|
122
126
|
operates: [], // 表格里面的操作按钮
|
|
123
127
|
tableHeightDiff: 300,
|
|
128
|
+
printData: {
|
|
129
|
+
name: "默认数据",
|
|
130
|
+
table: [{ name: "默认数据1" }],
|
|
131
|
+
},
|
|
124
132
|
},
|
|
125
133
|
paginations: {
|
|
126
134
|
page: 1, // 当前位于那页面
|
|
@@ -142,25 +150,25 @@ export default {
|
|
|
142
150
|
// range: [10, 200],
|
|
143
151
|
},
|
|
144
152
|
tableSearch1: [
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
{
|
|
154
|
+
label: "数字区间",
|
|
155
|
+
value: "range",
|
|
156
|
+
inputType: "numberRange",
|
|
157
|
+
originalFields: {
|
|
158
|
+
begin: "begin123",
|
|
159
|
+
end: "end123",
|
|
160
|
+
},
|
|
161
|
+
listeners: {
|
|
162
|
+
change: e => {
|
|
163
|
+
const {
|
|
164
|
+
val: [start, end],
|
|
165
|
+
} = e;
|
|
166
|
+
this.formSearchData.value.rang1 = start;
|
|
167
|
+
this.formSearchData.value.rang2 = end;
|
|
168
|
+
console.log(this.formSearchData, e);
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
164
172
|
// {
|
|
165
173
|
// label: "标签号",
|
|
166
174
|
// value: "carBodyTagNumber",
|
|
@@ -449,7 +457,6 @@ export default {
|
|
|
449
457
|
mounted() {
|
|
450
458
|
// const el = document.getElementById("ellipsis-container");
|
|
451
459
|
// this.truncateMiddleByWidth(el)
|
|
452
|
-
console.log(6666, this, this.$olBaseConfig);
|
|
453
460
|
},
|
|
454
461
|
methods: {
|
|
455
462
|
SelectionChange(row) {
|
|
@@ -679,7 +686,7 @@ export default {
|
|
|
679
686
|
],
|
|
680
687
|
},
|
|
681
688
|
onSubmit: data => {
|
|
682
|
-
console.log(6666, data);
|
|
689
|
+
// console.log(6666, data);
|
|
683
690
|
},
|
|
684
691
|
});
|
|
685
692
|
|
|
@@ -817,6 +824,30 @@ export default {
|
|
|
817
824
|
saveHandler(configList) {
|
|
818
825
|
console.log("保存配置", configList);
|
|
819
826
|
},
|
|
827
|
+
handlePrint1(row) {
|
|
828
|
+
console.log(11122333, row);
|
|
829
|
+
},
|
|
830
|
+
onPrintData(tempItem, done) {
|
|
831
|
+
console.log("111app", tempItem, done);
|
|
832
|
+
if (tempItem.templeteName === "自定义模式") {
|
|
833
|
+
// 模拟异步接口请求
|
|
834
|
+
const data = {
|
|
835
|
+
name: "自定义模式",
|
|
836
|
+
table: [
|
|
837
|
+
{ name: "2233" },
|
|
838
|
+
{ name: "3344" },
|
|
839
|
+
{ name: "2233" },
|
|
840
|
+
{ name: "2233" },
|
|
841
|
+
{ name: "2233" },
|
|
842
|
+
{ name: "2233" },
|
|
843
|
+
{ name: "2233" },
|
|
844
|
+
{ name: "2233" },
|
|
845
|
+
{ name: "2233" },
|
|
846
|
+
],
|
|
847
|
+
};
|
|
848
|
+
done(data);
|
|
849
|
+
}
|
|
850
|
+
},
|
|
820
851
|
},
|
|
821
852
|
};
|
|
822
853
|
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1775034815280" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="119811" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M910.104609 248.342329h-56.346075v-145.061172q-2.397705-45.556401-35.96558-75.527718t-77.925423-27.573611H272.314993q-20.380495 0-39.562137 7.193116t-33.567875 21.579348q-14.386232 14.386232-22.178774 33.567874t-6.59369 40.760991v145.061172h-67.135749q-21.579348-1.198853-40.76099 6.593689t-33.567875 22.178774q-14.386232 14.386232-21.579348 33.567875t-7.193116 40.76099v389.627115q-2.397705 44.357548 27.573612 77.325997t75.527717 35.366153h67.135749v62.340339q0 44.357548 31.769596 76.127143t76.127144 31.769596h467.552537q44.357548 0 76.127144-31.769596t31.769596-76.127143v-62.340339h56.346075q45.556401-2.397705 78.524849-34.766727t35.366154-77.925423v-389.627115q-2.397705-45.556401-35.96558-75.527717t-77.925423-27.573611z m-677.351753-145.061172q-1.198853-17.98279 10.789673-29.971317t28.772464-10.789674h467.552538q19.181643 0 35.366153 10.789674t16.184511 29.971317v145.061172H232.752856z m558.665339 607.818299v205.003805q0 19.181643-13.187379 32.369021t-32.369022 13.18738H278.309257q-19.181643 0-32.369022-13.18738t-13.187379-32.369021v-205.003805q0-17.98279 13.187379-31.769596t32.369022-13.786806h467.552537q19.181643 0 32.369022 13.18738t13.187379 32.369022z m170.237078-359.655799v389.627115q-1.198853 20.380495-15.585084 34.766727t-35.96558 15.585085h-56.346075v-79.124276q0-44.357548-31.769596-75.527717t-76.127144-31.17017H278.309257q-44.357548 0-76.127144 31.17017t-31.769596 75.527717v79.124276h-67.135749q-19.181643-2.397705-31.170169-17.383364t-9.590821-34.167301v-388.428262q-1.198853-17.98279 10.789674-29.971316t29.971316-10.789674h806.827841q19.181643 0 35.366153 10.789674t16.184511 29.971316z m-766.06685 52.749518h-46.755254q-4.795411-1.198853-8.391968-5.994264t-3.596558-10.190247q0-5.394837 3.596558-10.190248t8.391968-4.795411h46.755254q10.789674-2.397705 16.783937 6.59369t0 17.383364q-5.994263 8.391969-16.783937 7.193116z m111.493298 0h-50.351812q-10.789674 1.198853-16.783937-7.193116t0-17.383364q5.994263-8.991395 16.783937-6.59369h50.351812q5.994263 0 9.590821 4.795411t3.596558 10.190248q0 5.394837-3.596558 10.190247t-9.590821 5.994264z m511.910086 139.066908H195.588423q-4.795411-1.198853-8.991395-5.394837t-4.195984-10.190247q0-5.994263 4.195984-10.190248t8.991395-5.394837h623.403384q5.994263 1.198853 9.590821 5.394837t3.596558 10.190248q0 5.994263-3.596558 10.190247t-9.590821 5.394837z" p-id="119812"></path></svg>
|
package/src/main.js
CHANGED
|
@@ -6,7 +6,7 @@ import OlCom, { swaggerInstall, Hiprint } from "@/package/index.js";
|
|
|
6
6
|
Vue.use(ElementUI);
|
|
7
7
|
Vue.use(Hiprint);
|
|
8
8
|
|
|
9
|
-
Vue.use(OlCom, { method: "post" });
|
|
9
|
+
Vue.use(OlCom, { method: "post", isSmartPrint: true });
|
|
10
10
|
swaggerInstall("http://220.179.249.140:20025/swagger/v1/swagger.json").then(() => {});
|
|
11
11
|
new Vue({
|
|
12
12
|
render: h => h(App),
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
<ol-search
|
|
3
3
|
:key="key"
|
|
4
4
|
:form-search-data="formSearchData"
|
|
5
|
-
|
|
5
|
+
isCustomSearch
|
|
6
6
|
v-bind="$attrs"
|
|
7
7
|
@onSave="onSave"
|
|
8
|
-
method="
|
|
8
|
+
:method="finalMethod"
|
|
9
9
|
v-on="$listeners"
|
|
10
10
|
ref="customSearchRef"
|
|
11
11
|
/>
|
|
@@ -37,6 +37,10 @@ export default {
|
|
|
37
37
|
};
|
|
38
38
|
},
|
|
39
39
|
},
|
|
40
|
+
// 请求方式 post get
|
|
41
|
+
method: {
|
|
42
|
+
type: String,
|
|
43
|
+
},
|
|
40
44
|
},
|
|
41
45
|
data() {
|
|
42
46
|
return {
|
|
@@ -50,6 +54,12 @@ export default {
|
|
|
50
54
|
this.init();
|
|
51
55
|
});
|
|
52
56
|
},
|
|
57
|
+
computed: {
|
|
58
|
+
// 优先级:props > 全局配置 > 默认值
|
|
59
|
+
finalMethod() {
|
|
60
|
+
return this.method || (this.$olBaseConfig && this.$olBaseConfig.method) || "get";
|
|
61
|
+
},
|
|
62
|
+
},
|
|
53
63
|
methods: {
|
|
54
64
|
init() {
|
|
55
65
|
const handleMenu = (arr, _this) => {
|
|
@@ -164,7 +164,7 @@
|
|
|
164
164
|
{{ expend ? "收起" : "展开" }}</el-button
|
|
165
165
|
>
|
|
166
166
|
<el-button
|
|
167
|
-
v-if="
|
|
167
|
+
v-if="isCustomSearch"
|
|
168
168
|
plain
|
|
169
169
|
size="small"
|
|
170
170
|
icon="el-icon-setting"
|
|
@@ -281,7 +281,7 @@ export default {
|
|
|
281
281
|
type: Function,
|
|
282
282
|
default: null,
|
|
283
283
|
},
|
|
284
|
-
|
|
284
|
+
isCustomSearch: {
|
|
285
285
|
type: Boolean,
|
|
286
286
|
default: false,
|
|
287
287
|
},
|
|
@@ -337,7 +337,7 @@ export default {
|
|
|
337
337
|
},
|
|
338
338
|
methods: {
|
|
339
339
|
async init() {
|
|
340
|
-
if (!this.
|
|
340
|
+
if (!this.isCustomSearch && this.url) {
|
|
341
341
|
const swaggerData = await getData();
|
|
342
342
|
let swaggersearchColumns = swaggerData.paths[this.url][this.finalMethod].parameters || [];
|
|
343
343
|
if (typeof this.onSwagger === "function") {
|
|
@@ -518,7 +518,7 @@ export default {
|
|
|
518
518
|
},
|
|
519
519
|
// 搜索查询按钮
|
|
520
520
|
handleSearch(formName, item) {
|
|
521
|
-
if (!this.
|
|
521
|
+
if (!this.isCustomSearch) {
|
|
522
522
|
if (this.formSearch.createdTime) {
|
|
523
523
|
this.formSearch.BeginTime = this.formSearch.createdTime[0];
|
|
524
524
|
this.formSearch.EndTime = this.formSearch.createdTime[1];
|
|
@@ -124,7 +124,6 @@ export default {
|
|
|
124
124
|
// eslint-disable-next-line no-undef
|
|
125
125
|
$("#hiprint-printTemplate").empty(); // 先清空, 避免重复构建
|
|
126
126
|
|
|
127
|
-
|
|
128
127
|
this.hiprintTemplate = new hiprint.PrintTemplate({
|
|
129
128
|
template: this.defaultTemplate,
|
|
130
129
|
settingContainer: "#PrintElementOptionSetting",
|
|
@@ -144,7 +143,7 @@ export default {
|
|
|
144
143
|
this.hiprintTemplate.design("#hiprint-printTemplate", {
|
|
145
144
|
grid: this.grid,
|
|
146
145
|
});
|
|
147
|
-
console.log(6666, this.hiprintTemplate);
|
|
146
|
+
// console.log(6666, this.hiprintTemplate);
|
|
148
147
|
},
|
|
149
148
|
async print() {
|
|
150
149
|
// 使用外部传入的打印数据
|
|
@@ -152,9 +151,8 @@ export default {
|
|
|
152
151
|
if (this.onPrintData) {
|
|
153
152
|
try {
|
|
154
153
|
const result = await this.onPrintData(this.printData);
|
|
155
|
-
if (result)
|
|
156
|
-
|
|
157
|
-
}
|
|
154
|
+
if (result) data = result;
|
|
155
|
+
else console.error("onPrintData 执行失败,返回数据为空");
|
|
158
156
|
} catch (error) {
|
|
159
157
|
console.error("onPrintData 执行失败:", error);
|
|
160
158
|
}
|
|
@@ -171,10 +169,10 @@ export default {
|
|
|
171
169
|
// return "<style>.hiprint-printElement-text{color:red !important;}</style>";
|
|
172
170
|
// },
|
|
173
171
|
};
|
|
174
|
-
|
|
172
|
+
|
|
175
173
|
// 使用 props 传入的纸张大小
|
|
176
174
|
ext.curPaper = this.paperSize;
|
|
177
|
-
|
|
175
|
+
|
|
178
176
|
// 调用浏览器打印
|
|
179
177
|
this.hiprintTemplate.print(data, options, ext);
|
|
180
178
|
},
|
|
@@ -37,6 +37,10 @@
|
|
|
37
37
|
<span class="info-label">备注:</span>
|
|
38
38
|
<span class="info-value">{{ template.remark || "无" }}</span>
|
|
39
39
|
</div>
|
|
40
|
+
<div class="card-info">
|
|
41
|
+
<span class="info-label">数据源URL:</span>
|
|
42
|
+
<span class="info-value">{{ template.printUrl || "无" }}</span>
|
|
43
|
+
</div>
|
|
40
44
|
</div>
|
|
41
45
|
<div class="card-footer">
|
|
42
46
|
<el-button type="text" size="small" icon="el-icon-edit" @click="handleEdit(template)">
|
|
@@ -66,6 +70,17 @@
|
|
|
66
70
|
<el-form-item label="模板名称" prop="templeteName">
|
|
67
71
|
<el-input v-model="form.templeteName" placeholder="请输入模板名称"></el-input>
|
|
68
72
|
</el-form-item>
|
|
73
|
+
<el-form-item label="创建模板" prop="templeteJson">
|
|
74
|
+
<span style="margin-right: 10px">{{ form.templeteJson ? "已创建" : "未创建" }}</span>
|
|
75
|
+
<el-button type="primary" @click="handleCreateTemplate">创建模板</el-button>
|
|
76
|
+
</el-form-item>
|
|
77
|
+
<el-form-item label="数据源URL" prop="printUrl">
|
|
78
|
+
<el-input
|
|
79
|
+
v-model="form.printUrl"
|
|
80
|
+
placeholder="请输入数据源URL"
|
|
81
|
+
@blur="form.printUrl = form.printUrl && form.printUrl.trim()"
|
|
82
|
+
></el-input>
|
|
83
|
+
</el-form-item>
|
|
69
84
|
<el-form-item label="备注">
|
|
70
85
|
<el-input
|
|
71
86
|
v-model="form.remark"
|
|
@@ -74,10 +89,6 @@
|
|
|
74
89
|
placeholder="请输入备注"
|
|
75
90
|
></el-input>
|
|
76
91
|
</el-form-item>
|
|
77
|
-
<el-form-item label="创建模板">
|
|
78
|
-
<span style="margin-right: 10px">{{ form.templeteJson ? "已创建" : "未创建" }}</span>
|
|
79
|
-
<el-button type="primary" @click="handleCreateTemplate">创建模板</el-button>
|
|
80
|
-
</el-form-item>
|
|
81
92
|
</el-form>
|
|
82
93
|
<span slot="footer" class="dialog-footer">
|
|
83
94
|
<el-button @click="dialogVisible = false">取消</el-button>
|
|
@@ -109,9 +120,11 @@ export default {
|
|
|
109
120
|
templeteName: "",
|
|
110
121
|
remark: "",
|
|
111
122
|
templeteJson: "",
|
|
123
|
+
printUrl: "",
|
|
112
124
|
},
|
|
113
125
|
rules: {
|
|
114
126
|
templeteName: [{ required: true, message: "请输入模板名称", trigger: "blur" }],
|
|
127
|
+
templeteJson: [{ required: true, message: "请输入模板JSON", trigger: "blur" }],
|
|
115
128
|
},
|
|
116
129
|
};
|
|
117
130
|
},
|
|
@@ -179,6 +192,7 @@ export default {
|
|
|
179
192
|
templeteName: "",
|
|
180
193
|
remark: "",
|
|
181
194
|
templeteJson: "",
|
|
195
|
+
printUrl: "",
|
|
182
196
|
};
|
|
183
197
|
this.dialogVisible = true;
|
|
184
198
|
this.$nextTick(() => {
|
|
@@ -192,6 +206,7 @@ export default {
|
|
|
192
206
|
templeteName: template.templeteName,
|
|
193
207
|
remark: template.remark,
|
|
194
208
|
templeteJson: template.templeteJson,
|
|
209
|
+
printUrl: template.printUrl || "",
|
|
195
210
|
};
|
|
196
211
|
this.dialogVisible = true;
|
|
197
212
|
},
|
|
@@ -225,6 +240,7 @@ export default {
|
|
|
225
240
|
id: this.form.id,
|
|
226
241
|
templeteName: this.form.templeteName,
|
|
227
242
|
templeteJson: this.form.templeteJson,
|
|
243
|
+
printUrl: this.form.printUrl,
|
|
228
244
|
},
|
|
229
245
|
});
|
|
230
246
|
this.$message.success("编辑成功");
|
|
@@ -235,6 +251,7 @@ export default {
|
|
|
235
251
|
menuId: this.currentMenuId,
|
|
236
252
|
templeteName: this.form.templeteName,
|
|
237
253
|
templeteJson: this.form.templeteJson,
|
|
254
|
+
printUrl: this.form.printUrl,
|
|
238
255
|
},
|
|
239
256
|
});
|
|
240
257
|
this.$message.success("新增成功");
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<el-dropdown @command="handleCommand" trigger="click">
|
|
3
|
-
<
|
|
3
|
+
<img
|
|
4
|
+
src="../../../../assets/print.svg"
|
|
5
|
+
alt="print"
|
|
6
|
+
style="width: 14px; height: 14px; cursor: pointer"
|
|
7
|
+
/>
|
|
4
8
|
<el-dropdown-menu slot="dropdown">
|
|
5
9
|
<el-dropdown-item
|
|
6
10
|
v-for="(item, index) in templateList"
|
|
@@ -26,10 +30,45 @@ export default {
|
|
|
26
30
|
type: [Object, Array],
|
|
27
31
|
default: () => {},
|
|
28
32
|
},
|
|
33
|
+
// 自定义获取打印数据函数,没传递就是默认接口获取数据。return的数据就是打印数据
|
|
34
|
+
onPrintData: {
|
|
35
|
+
type: Function,
|
|
36
|
+
default: null,
|
|
37
|
+
},
|
|
38
|
+
multipleSelection: {
|
|
39
|
+
type: Array,
|
|
40
|
+
default: () => [],
|
|
41
|
+
},
|
|
29
42
|
},
|
|
30
43
|
data() {
|
|
31
44
|
return {
|
|
32
45
|
templateList: [{ id: 1, templeteName: "暂无数据", disabled: true }],
|
|
46
|
+
// templateList: [
|
|
47
|
+
// {
|
|
48
|
+
// id: 1,
|
|
49
|
+
// templeteName: "自定义模式",
|
|
50
|
+
// remark: "",
|
|
51
|
+
// templeteJson:
|
|
52
|
+
// '{"panels":[{"index":0,"name":1,"paperType":"A4","height":297,"width":210,"paperHeader":0,"paperFooter":841.8897637795277,"printElements":[{"options":{"left":67.5,"top":165,"height":36,"width":550,"fields":[],"field":"table","qid":"table","columns":[[{"width":137.5,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"性别","field":"gender","checked":true,"columnId":"gender","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"数量","field":"count","checked":true,"columnId":"count","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"金额","field":"amount","checked":true,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"align":"center"}]]},"printElementType":{"title":"表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":127.5,"top":301.5,"height":9.75,"width":120,"field":"name","testData":"内容","title":"文本","qid":"name"},"printElementType":{"title":"文本","type":"text"}}],"paperNumberContinue":true,"watermarkOptions":{},"panelLayoutOptions":{}}]}',
|
|
53
|
+
// printUrl: "api/app/aaa",
|
|
54
|
+
// },
|
|
55
|
+
// {
|
|
56
|
+
// id: 2,
|
|
57
|
+
// templeteName: "printURL模式",
|
|
58
|
+
// remark: "",
|
|
59
|
+
// templeteJson:
|
|
60
|
+
// '{"panels":[{"index":0,"name":1,"paperType":"A4","height":297,"width":210,"paperHeader":0,"paperFooter":841.8897637795277,"printElements":[{"options":{"left":67.5,"top":229.5,"height":36,"width":550,"fields":[],"field":"table","qid":"table","columns":[[{"width":137.5,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"性别","field":"gender","checked":true,"columnId":"gender","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"数量","field":"count","checked":true,"columnId":"count","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"金额","field":"amount","checked":true,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"align":"center"}]]},"printElementType":{"title":"表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":247.5,"top":304.5,"height":9.75,"width":120,"field":"name","testData":"内容","title":"文本","qid":"name"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":79.5,"top":313.5,"height":32,"width":120,"field":"qrcode","testData":"XS888888888","fontSize":12,"lineHeight":18,"textType":"qrcode","title":"二维码","qid":"qrcode"},"printElementType":{"title":"二维码","type":"text"}}],"paperNumberContinue":true,"watermarkOptions":{},"panelLayoutOptions":{}}]}',
|
|
61
|
+
// printUrl: "api/app/bbb",
|
|
62
|
+
// },
|
|
63
|
+
// {
|
|
64
|
+
// id: 3,
|
|
65
|
+
// templeteName: "默认模式",
|
|
66
|
+
// remark: "",
|
|
67
|
+
// templeteJson:
|
|
68
|
+
// '{"panels":[{"index":0,"name":1,"paperType":"A4","height":297,"width":210,"paperHeader":0,"paperFooter":841.8897637795277,"printElements":[{"options":{"left":67.5,"top":229.5,"height":36,"width":550,"fields":[],"field":"table","qid":"table","columns":[[{"width":137.5,"title":"名称","field":"name","checked":true,"columnId":"name","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"性别","field":"gender","checked":true,"columnId":"gender","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"数量","field":"count","checked":true,"columnId":"count","fixed":false,"rowspan":1,"colspan":1,"align":"center"},{"width":137.5,"title":"金额","field":"amount","checked":true,"columnId":"amount","fixed":false,"rowspan":1,"colspan":1,"align":"center"}]]},"printElementType":{"title":"表格","type":"table","editable":true,"columnDisplayEditable":true,"columnDisplayIndexEditable":true,"columnTitleEditable":true,"columnResizable":true,"columnAlignEditable":true,"isEnableEditField":true,"isEnableContextMenu":true,"isEnableInsertRow":true,"isEnableDeleteRow":true,"isEnableInsertColumn":true,"isEnableDeleteColumn":true,"isEnableMergeCell":true}},{"options":{"left":247.5,"top":304.5,"height":9.75,"width":120,"field":"name","testData":"内容","title":"文本","qid":"name"},"printElementType":{"title":"文本","type":"text"}},{"options":{"left":79.5,"top":313.5,"height":32,"width":120,"field":"qrcode","testData":"XS888888888","fontSize":12,"lineHeight":18,"textType":"qrcode","title":"二维码","qid":"qrcode"},"printElementType":{"title":"二维码","type":"text"}}],"paperNumberContinue":true,"watermarkOptions":{},"panelLayoutOptions":{}}]}',
|
|
69
|
+
// printUrl: "",
|
|
70
|
+
// },
|
|
71
|
+
// ],
|
|
33
72
|
};
|
|
34
73
|
},
|
|
35
74
|
created() {
|
|
@@ -80,20 +119,85 @@ export default {
|
|
|
80
119
|
const tempItem = this.templateList.find(item => item.id === command);
|
|
81
120
|
if (!tempItem) return this.$message.error("未找到打印模板");
|
|
82
121
|
|
|
83
|
-
const
|
|
122
|
+
const options = {
|
|
123
|
+
printData: this.printData || {},
|
|
124
|
+
defaultTemplate: tempItem.templeteJson ? JSON.parse(tempItem.templeteJson) : {},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// 自定义打印 > 默认接口打印 > printData数据打印
|
|
128
|
+
if (this.onPrintData) {
|
|
129
|
+
// 自定义数据 - 类似 Element UI before-close 机制
|
|
130
|
+
let isCustomHandled = false;
|
|
131
|
+
// 定义 done 函数
|
|
132
|
+
const done = data => {
|
|
133
|
+
isCustomHandled = true;
|
|
134
|
+
if (data) {
|
|
135
|
+
options.printData = data;
|
|
136
|
+
this.$hiprint.print(options);
|
|
137
|
+
} else {
|
|
138
|
+
this.$message.error("打印数据不能为空");
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// 调用自定义回调,传入模板信息和 done 函数
|
|
143
|
+
this.onPrintData(tempItem, done);
|
|
144
|
+
|
|
145
|
+
// 如果自定义回调没有调用 done,则走默认逻辑
|
|
146
|
+
if (!isCustomHandled) {
|
|
147
|
+
if (tempItem.printUrl) {
|
|
148
|
+
this.printByApi(options, tempItem);
|
|
149
|
+
} else {
|
|
150
|
+
// 没有自定义回调,走默认逻辑
|
|
151
|
+
options.printData = this.printData || {};
|
|
152
|
+
this.$hiprint.print(options);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
} else if (tempItem.printUrl) {
|
|
156
|
+
this.printByApi(options, tempItem);
|
|
157
|
+
} else {
|
|
158
|
+
this.printDefault(options);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
printByApi(options, tempItem) {
|
|
162
|
+
// 默认接口数据
|
|
163
|
+
options.printData = this.getPrintDataByApi(tempItem);
|
|
84
164
|
const isValidData =
|
|
85
|
-
|
|
86
|
-
((Array.isArray(
|
|
87
|
-
(typeof
|
|
165
|
+
options.printData &&
|
|
166
|
+
((Array.isArray(options.printData) && options.printData.length > 0) ||
|
|
167
|
+
(typeof options.printData === "object" && Object.keys(options.printData).length > 0));
|
|
88
168
|
|
|
89
169
|
if (!isValidData) {
|
|
90
170
|
return this.$message.error("打印数据不能为空");
|
|
91
171
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
172
|
+
this.$hiprint.print(options);
|
|
173
|
+
},
|
|
174
|
+
printDefault(options) {
|
|
175
|
+
// 默认接口数据
|
|
176
|
+
options.printData = this.printData || {};
|
|
177
|
+
this.$hiprint.print(options);
|
|
178
|
+
},
|
|
179
|
+
// 默认接口获取数据
|
|
180
|
+
async getPrintDataByApi(tempItem) {
|
|
181
|
+
try {
|
|
182
|
+
let ids = [];
|
|
183
|
+
if (this.multipleSelection && this.multipleSelection.length > 0) {
|
|
184
|
+
ids = this.multipleSelection.reduce((acc, item) => {
|
|
185
|
+
acc.push(item.id);
|
|
186
|
+
return acc;
|
|
187
|
+
}, []);
|
|
188
|
+
}
|
|
189
|
+
const res = await this.get({
|
|
190
|
+
url: `${tempItem.printUrl}`,
|
|
191
|
+
data: {
|
|
192
|
+
ids: ids,
|
|
193
|
+
},
|
|
194
|
+
});
|
|
195
|
+
if (res.code !== 200) return {};
|
|
196
|
+
if (Array.isArray(res.result) && res.result.length > 0) return res.result;
|
|
197
|
+
return {};
|
|
198
|
+
} catch (error) {
|
|
199
|
+
console.error(`获取打印数据失败: ${tempItem.printUrl}`, error);
|
|
200
|
+
}
|
|
97
201
|
},
|
|
98
202
|
},
|
|
99
203
|
};
|
|
@@ -26,6 +26,14 @@
|
|
|
26
26
|
</div>
|
|
27
27
|
<!-- 右侧工具按钮 -->
|
|
28
28
|
<div class="toolbox">
|
|
29
|
+
<!-- 工具按钮前插槽 -->
|
|
30
|
+
<slot
|
|
31
|
+
name="toolbox-before"
|
|
32
|
+
:tableData="tableData"
|
|
33
|
+
:multipleSelection="multipleSelection"
|
|
34
|
+
:paginations="paginations"
|
|
35
|
+
:loading="tableData.loading"
|
|
36
|
+
></slot>
|
|
29
37
|
<el-dropdown
|
|
30
38
|
v-if="tableData.options.headTool"
|
|
31
39
|
class="avatar-container right-menu-item hover-effect"
|
|
@@ -60,15 +68,39 @@
|
|
|
60
68
|
</div>
|
|
61
69
|
</div>
|
|
62
70
|
<div
|
|
63
|
-
v-if="tableData.options.downloadBtn"
|
|
71
|
+
v-if="tableData.options.downloadBtn && !isSmartPrintComputed"
|
|
72
|
+
class="avatar-container right-menu-item hover-effect el-dropdown"
|
|
73
|
+
@click="printTable"
|
|
74
|
+
>
|
|
75
|
+
<div class="avatar-wrapper">
|
|
76
|
+
<div class="layui-table-tool-self">
|
|
77
|
+
<i class="el-icon-printer" />
|
|
78
|
+
</div>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
<div
|
|
82
|
+
v-if="isSmartPrintComputed"
|
|
64
83
|
class="avatar-container right-menu-item hover-effect el-dropdown"
|
|
65
84
|
>
|
|
66
85
|
<div class="avatar-wrapper">
|
|
67
86
|
<div class="layui-table-tool-self">
|
|
68
|
-
<print-template-selector
|
|
87
|
+
<print-template-selector
|
|
88
|
+
:menuId="menuId"
|
|
89
|
+
:printData="tableData.printData"
|
|
90
|
+
:multipleSelection="multipleSelection"
|
|
91
|
+
v-bind="$attrs"
|
|
92
|
+
/>
|
|
69
93
|
</div>
|
|
70
94
|
</div>
|
|
71
95
|
</div>
|
|
96
|
+
<!-- 工具按钮后插槽 -->
|
|
97
|
+
<slot
|
|
98
|
+
name="toolbox-after"
|
|
99
|
+
:tableData="tableData"
|
|
100
|
+
:multipleSelection="multipleSelection"
|
|
101
|
+
:paginations="paginations"
|
|
102
|
+
:loading="tableData.loading"
|
|
103
|
+
></slot>
|
|
72
104
|
</div>
|
|
73
105
|
</div>
|
|
74
106
|
</template>
|
|
@@ -444,6 +476,11 @@ export default {
|
|
|
444
476
|
method: {
|
|
445
477
|
type: String,
|
|
446
478
|
},
|
|
479
|
+
// 是否启用智能打印
|
|
480
|
+
isSmartPrint: {
|
|
481
|
+
type: Boolean,
|
|
482
|
+
default: null,
|
|
483
|
+
},
|
|
447
484
|
},
|
|
448
485
|
|
|
449
486
|
data() {
|
|
@@ -490,6 +527,12 @@ export default {
|
|
|
490
527
|
finalMethod() {
|
|
491
528
|
return this.method || (this.$olBaseConfig && this.$olBaseConfig.method) || "get";
|
|
492
529
|
},
|
|
530
|
+
isSmartPrintComputed() {
|
|
531
|
+
if (this.isSmartPrint !== null) {
|
|
532
|
+
return this.isSmartPrint;
|
|
533
|
+
}
|
|
534
|
+
return (this.$olBaseConfig && this.$olBaseConfig.isSmartPrint) || false;
|
|
535
|
+
},
|
|
493
536
|
},
|
|
494
537
|
created() {
|
|
495
538
|
// 通过swagger完善columns
|
|
@@ -639,20 +682,20 @@ export default {
|
|
|
639
682
|
});
|
|
640
683
|
this.$emit("refreshTable");
|
|
641
684
|
},
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
685
|
+
printTable() {
|
|
686
|
+
console.log("printTable");
|
|
687
|
+
if (this.tableData.rows.length <= 0) return;
|
|
688
|
+
this.printListObj.title = this.$router.history.current.name;
|
|
689
|
+
this.printListObj.tableHeader = this.tableData.columns;
|
|
690
|
+
this.printListObj.tableData = this.tableData.rows;
|
|
691
|
+
console.log(this.printListObj);
|
|
692
|
+
setTimeout(() => {
|
|
693
|
+
$(".printTemplate").show();
|
|
694
|
+
$(".printTemplate").jqprint();
|
|
695
|
+
$(".printTemplate").hide();
|
|
696
|
+
}, 50);
|
|
697
|
+
this.$emit("printTable");
|
|
698
|
+
},
|
|
656
699
|
selectAll(val) {
|
|
657
700
|
this.$emit("selectAll", val);
|
|
658
701
|
},
|