选择列表展示图片
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
],
|
],
|
||||||
'web.assets_backend': [
|
'web.assets_backend': [
|
||||||
'sf_demand_plan/static/src/scss/style.css',
|
'sf_demand_plan/static/src/scss/style.css',
|
||||||
|
'sf_demand_plan/static/src/js/print_demand.js',
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
'license': 'LGPL-3',
|
'license': 'LGPL-3',
|
||||||
|
|||||||
205
sf_demand_plan/static/src/js/print_demand.js
Normal file
205
sf_demand_plan/static/src/js/print_demand.js
Normal file
@@ -0,0 +1,205 @@
|
|||||||
|
odoo.define('sf_demand.print_demand', function (require) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var ListController = require('web.ListController');
|
||||||
|
var ListRenderer = require('web.ListRenderer');
|
||||||
|
var ListView = require('web.ListView');
|
||||||
|
var viewRegistry = require('web.view_registry');
|
||||||
|
var { url } = require("@web/core/utils/urls")
|
||||||
|
|
||||||
|
var CustomListRenderer = ListRenderer.extend({
|
||||||
|
_render: function () {
|
||||||
|
var self = this;
|
||||||
|
this.getParent()?.$buttons.hide()
|
||||||
|
return this._super.apply(this, arguments).then(function () {
|
||||||
|
// 添加图片预览容器到页面左侧
|
||||||
|
if (!$('.table-image-preview-container').length) {
|
||||||
|
self.$el.parent().addClass('custom-table-image-container')
|
||||||
|
self.$el.before(
|
||||||
|
`<div class="custom-preview-container">
|
||||||
|
<img class="table-image-preview-container" src="" />
|
||||||
|
<iframe class="table-image-preview-container" src=""/>
|
||||||
|
</div>`
|
||||||
|
);
|
||||||
|
self.$el.prepend(`
|
||||||
|
<div class="print-button-container" style="margin-bottom:10px;">
|
||||||
|
<button class="btn btn-primary o_print_custom">
|
||||||
|
<i class="fa fa-print"></i> 打印
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-secondary o_cancel_custom">
|
||||||
|
取消
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
events: _.extend({}, ListRenderer.prototype.events, {
|
||||||
|
'click .o_data_row': '_onCustomRowClick',
|
||||||
|
'click .o_print_custom': '_onPrintClick',
|
||||||
|
'click .o_cancel_custom': '_onCancelClick'
|
||||||
|
}),
|
||||||
|
_onCancelClick() {
|
||||||
|
this.getParent()?.getParent()?.dialogs.closeAll()
|
||||||
|
},
|
||||||
|
_onCustomRowClick: async function (ev) {
|
||||||
|
var self = this;
|
||||||
|
var $row = $(ev.currentTarget);
|
||||||
|
var index = $row.index();
|
||||||
|
var data = this.state.data[index];
|
||||||
|
console.log(this, 'this', data);
|
||||||
|
if(data.fileData?.fileUrl) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
data.fileData = { }
|
||||||
|
if(data.res_id) {
|
||||||
|
// 正确获取 ORM 服务的方式
|
||||||
|
// var orm = this.getParent().getParent().env.services
|
||||||
|
const key = data.data.type == 1 ? 'machining_drawings' : 'cnc_worksheet'
|
||||||
|
const attachment = await this._rpc({
|
||||||
|
model: 'ir.binary',
|
||||||
|
method: 'attachment_info',
|
||||||
|
args: [
|
||||||
|
data.model,
|
||||||
|
data.res_id,
|
||||||
|
key
|
||||||
|
],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (attachment) {
|
||||||
|
Object.assign(data.fileData, attachment)
|
||||||
|
this._getTypeInfo(attachment.mimetype, data.fileData)
|
||||||
|
}
|
||||||
|
console.log(data, 'data', attachment);
|
||||||
|
const fileUrl = this.getFileUrl(data.fileData.attachment_type, data, key)
|
||||||
|
data.fileData.fileUrl = fileUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$('.table-image-preview-container').hide()
|
||||||
|
if(data.fileData.attachment_type == 'iframe') {
|
||||||
|
|
||||||
|
$('iframe.table-image-preview-container').attr('src', decodeURIComponent(data.fileData.fileUrl) ).show()
|
||||||
|
} else {
|
||||||
|
$('img.table-image-preview-container').attr('src', data.fileData.fileUrl).show()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getSelectedIds: function() {
|
||||||
|
return this.state.data.map(_ => {
|
||||||
|
return _.data.id
|
||||||
|
})
|
||||||
|
},
|
||||||
|
_onPrintClick(e) {
|
||||||
|
console.log(e, 'asdsadadsadasdad', this);
|
||||||
|
var selectedIds = this.getSelectedIds();
|
||||||
|
|
||||||
|
console.log(selectedIds);
|
||||||
|
|
||||||
|
this._rpc({
|
||||||
|
model: 'sf.demand.plan.print.wizard',
|
||||||
|
method: 'demand_plan_print',
|
||||||
|
kwargs: selectedIds,
|
||||||
|
// context: this.state.getContext()
|
||||||
|
}).then(function() {
|
||||||
|
self.do_notify("成功", "打印任务已发送到打印机");
|
||||||
|
}).catch(function(error) {
|
||||||
|
console.error("打印错误:", error);
|
||||||
|
self.do_warn("打印失败", error.data.message || "未知错误");
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
getFileUrl(attachment_type, data, key) {
|
||||||
|
let fileUrl
|
||||||
|
switch (attachment_type) {
|
||||||
|
case 'image':
|
||||||
|
const timer = +new Date()
|
||||||
|
fileUrl = url("/web/image", {
|
||||||
|
model: data.model,
|
||||||
|
id: data.res_id,
|
||||||
|
field: key,
|
||||||
|
unique: '',
|
||||||
|
timer
|
||||||
|
});
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'iframe':
|
||||||
|
|
||||||
|
const iframe_file_url = encodeURIComponent(
|
||||||
|
url("/web/content", {
|
||||||
|
model: data.model,
|
||||||
|
id: data.res_id,
|
||||||
|
field: key,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
fileUrl = `${this.state.attachment_base}?file=${iframe_file_url}`;
|
||||||
|
case 'unknown':
|
||||||
|
fileUrl = encodeURIComponent(
|
||||||
|
url("/web/content", {
|
||||||
|
model: data.model,
|
||||||
|
id: data.res_id,
|
||||||
|
field: key,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fileUrl
|
||||||
|
},
|
||||||
|
_getTypeInfo(type, data) {
|
||||||
|
switch (type) {
|
||||||
|
case 'application/pdf':
|
||||||
|
data.attachment_base = `/web/static/lib/pdfjs/web/viewer.html`;
|
||||||
|
data.attachment_type = 'iframe'
|
||||||
|
break;
|
||||||
|
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
|
||||||
|
data.attachment_base = `/jikimo_attachment_viewer/static/lib/docxjs/viewer.html`;
|
||||||
|
data.attachment_type = 'iframe'
|
||||||
|
break;
|
||||||
|
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
||||||
|
data.attachment_base = `/jikimo_attachment_viewer/static/lib/exceljs/viewer.html`;
|
||||||
|
data.attachment_type = 'iframe'
|
||||||
|
break;
|
||||||
|
case 'application/vnd.openxmlformats-officedocument.presentationml.presentation':
|
||||||
|
data.attachment_base = '';
|
||||||
|
data.attachment_type = 'unknown'
|
||||||
|
break;
|
||||||
|
case 'image/png':
|
||||||
|
case 'image/jpeg':
|
||||||
|
case 'image/jpg':
|
||||||
|
data.attachment_base = ''
|
||||||
|
data.attachment_type = 'image'
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
data.attachment_base = ''
|
||||||
|
data.attachment_type = 'unknown'
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var CustomListController = ListController.extend({
|
||||||
|
// 可以保留或移除,根据是否需要处理自定义事件
|
||||||
|
// 处理打印操作
|
||||||
|
// rpc.query({
|
||||||
|
// model: 'sf.demand.plan.print.wizard',
|
||||||
|
// method: 'demand_plan_print',
|
||||||
|
// args: [recordIds]
|
||||||
|
// }).then(function(result) {
|
||||||
|
// self.do_notify("成功", "打印任务已发送到打印机");
|
||||||
|
// // 刷新视图显示最新状态
|
||||||
|
// self.reload();
|
||||||
|
// }).catch(function(error) {
|
||||||
|
// self.do_warn("打印失败", error.data.message || "发生未知错误");
|
||||||
|
// });
|
||||||
|
});
|
||||||
|
|
||||||
|
var PrintDemand = ListView.extend({
|
||||||
|
config: _.extend({}, ListView.prototype.config, {
|
||||||
|
Renderer: CustomListRenderer,
|
||||||
|
Controller: CustomListController,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
viewRegistry.add('print_demand', PrintDemand);
|
||||||
|
|
||||||
|
return PrintDemand;
|
||||||
|
});
|
||||||
@@ -9,3 +9,58 @@
|
|||||||
.demand_plan_tree .o_list_table_ungrouped {
|
.demand_plan_tree .o_list_table_ungrouped {
|
||||||
min-width: 1900px;
|
min-width: 1900px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.o_selected_row {
|
||||||
|
background-color: #e6f7ff !important;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.custom-table-image-container {
|
||||||
|
display: flex;
|
||||||
|
height: calc(95vh - 254px);
|
||||||
|
gap: 20px;
|
||||||
|
position: relative;
|
||||||
|
th.o_list_record_selector, td.o_list_record_selector{
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.custom-preview-container, .print_demand {
|
||||||
|
flex: 1;
|
||||||
|
|
||||||
|
max-width: 49%;
|
||||||
|
tbody {
|
||||||
|
tr:not(.o_data_row) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tfoot {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.print_demand {
|
||||||
|
.table-responsive {
|
||||||
|
width: 100%;
|
||||||
|
overflow-x: auto!important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.custom-preview-container {
|
||||||
|
background-color: #dadce0;
|
||||||
|
padding: 20px;
|
||||||
|
img {
|
||||||
|
max-width: 100%;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
iframe {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.o_print_custom, .o_cancel_custom {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
right: 20px;
|
||||||
|
}
|
||||||
|
.o_print_custom {
|
||||||
|
right: 66px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,12 +4,12 @@
|
|||||||
<field name="name">sf.demand.plan.print.wizard.tree</field>
|
<field name="name">sf.demand.plan.print.wizard.tree</field>
|
||||||
<field name="model">sf.demand.plan.print.wizard</field>
|
<field name="model">sf.demand.plan.print.wizard</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<tree string="打印">
|
<tree string="打印" class="print_demand" js_class="print_demand" >
|
||||||
<field name="model_id"/>
|
<field name="model_id"/>
|
||||||
<field name="filename_url"/>
|
<field name="filename_url"/>
|
||||||
<field name="type"/>
|
<field name="type"/>
|
||||||
<field name="machining_drawings" widget="adaptive_viewer"/>
|
<field name="machining_drawings" attrs="{'column_invisible': True }"/>
|
||||||
<field name="cnc_worksheet" widget="pdf_viewer"/>
|
<field name="cnc_worksheet" attrs="{'column_invisible': True }" />
|
||||||
<field name="status"/>
|
<field name="status"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user