我目前正在学习OWL,我想在"网站"上做一些类似聊天的事情。模块(用于显示来自"通信"的消息)。模块)。我创建了一个单独的标签名为"Chat"(我将输出来自"通信"的所有消息;模块)。但在这里我遇到了一个问题,即:缺少依赖
这是我的代码,它抱怨这段代码,即-找不到ChatComposer变量的依赖(正如我所理解的)
/** @odoo-module **/
odoo.define('Portal_Chat', function (require) {
'use strict';
const session = require("web.session");
const publicWidget = require('web.public.widget');
const { ComponentWrapper } = require('web.OwlCompatibility');
console.log("lalalalalal");
const components = {
ChatComposer: require('/portal_chat/static/src/components/chat_composer/chat_composer.js')
};
publicWidget.registry.PortalChatWidget = publicWidget.Widget.extend({
selector: '.portal_chat',
init: function(parent, options) {
this.options = _.defaults(options || {}, {});
this.component = false;
return this._super.apply(this, arguments)
},
async start() {
const partner_id = await this._rpc({ route: '/chat/get_partner_id' });
const props = {
partner_id: partner_id,
do_warn: this.do_warn,
onSeenChannel: (ev) => this.call('chat_service', 'checkUnreadMessages'),
};
this.component = new ComponentWrapper(this, components.ChatComposer, props);
await session.load_qweb('portal_chat');
await this.component.env.qweb.addTemplates(session.owlTemplates);
this.call('chat_service', 'onOpenChannel', this, this._onOpenChannel);
this.call('chat_service', 'onReceiveMessage', this, this._onReceiveMessage);
return this.component.mount(this.el);
},
_onOpenChannel: function (data) {
if(this.component) this.component.componentRef.comp.channels.comp.addChannel(data);
},
_onReceiveMessage: function (data) {
if(this.component) this.component.componentRef.comp.channels.comp.receiveMessage(data);
if(this.component) this.component.componentRef.comp.messages.comp.receiveMessage(data);
},
});
return publicWidget.registry.PortalChatWidget;
});
这是我的ChatComposer:
/** @odoo-module **/
import { Component } from owl;
import { useState, useRef } from owl.hooks
import { _ } from owl;
import { ChatChannels } from '@portal_chat/components/chat_channels/ChatChannels';
import { ChatMessagesHeader } from '@portal_chat/components/chat_messages_header/ChatMessagesHeader';
import { ChatMessages } from '@portal_chat/components/chat_messages/ChatMessages';
import { ChatInput } from '@portal_chat/components/chat_input/ChatInput';
export class ChatComposer extends Component {
state = useState({
current_channel: false
});
channels = useRef("channels");
messages = useRef("messages");
constructor(parent, props) {
super(parent, props);
this.state = useState(props);
}
setChannel(ev) {
this.state.current_channel = ev.detail;
}
onSeenChannel(ev) {
this.state.onSeenChannel(ev);
}
onScrollBottom(ev) {
this.channels.comp.clearCurrentChannelCounter(ev);
}
}
ChatComposer.components = { ChatChannels, ChatMessagesHeader, ChatMessages, ChatInput };
ChatComposer.template = "Portal_Chat";
return ChatComposer
Odoo应该在加载ChatComposer
时抛出以下错误消息:
Uncaught SyntaxError: missing ) after argument list
您需要将owl
导入更改为:
import { Component } = owl;
import { useState, useRef } = owl.hooks;
确保addons
中有portal_chat
,并且使用正确的路径。
你可以在原生Javascript模块文档中找到更多细节:
位于Odoo插件some_addon/static/src/path/to/file.js中的每个文件将被分配一个以插件名称为前缀的名称,如:@some_addon/path/to/file.