54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
/** @odoo-module **/
|
||
|
||
import { RadioField } from "@web/views/fields/radio/radio_field"; // 导入单选按钮组件
|
||
import { registry } from "@web/core/registry";
|
||
|
||
export class Many2OneRadioField extends RadioField {
|
||
// 你可以重写或者添加一些方法和属性
|
||
// 例如,你可以重写setup方法来添加一些事件监听器或者初始化一些变量
|
||
setup() {
|
||
super.setup(); // 调用父类的setup方法
|
||
// 你自己的代码
|
||
}
|
||
|
||
onImageClick(event) {
|
||
// 放大图片逻辑
|
||
// 获取图片元素
|
||
const img = event.target;
|
||
const close = img.nextSibling;
|
||
// 实现放大图片逻辑
|
||
// 比如使用 CSS 放大
|
||
img.parentElement.classList.add('zoomed');
|
||
close.classList.add('img_close');
|
||
}
|
||
|
||
onCloseClick(event) {
|
||
const close = event.target;
|
||
const img = close.previousSibling;
|
||
img.parentElement.classList.remove('zoomed');
|
||
close.classList.remove('img_close');
|
||
}
|
||
|
||
get items() {
|
||
return Many2OneRadioField.getItems(this.props.name, this.props.record);
|
||
}
|
||
|
||
static getItems(fieldName, record) {
|
||
switch (record.fields[fieldName].type) {
|
||
case "selection":
|
||
return record.fields[fieldName].selection;
|
||
case "many2one": {
|
||
const value = record.preloadedData[fieldName] || [];
|
||
return value.map((item) => [item.id, item.display_name, item.image]);
|
||
}
|
||
default:
|
||
return [];
|
||
}
|
||
}
|
||
}
|
||
|
||
Many2OneRadioField.template = "jikimo_frontend.Many2OneRadioField";
|
||
// MyCustomWidget.supportedTypes = ['many2many'];
|
||
|
||
registry.category("fields").add("many2one_radio", Many2OneRadioField);
|