From 68805fee4a770939331b7da43201df9eda73f552 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Fri, 11 Aug 2023 12:22:59 +0800 Subject: [PATCH] =?UTF-8?q?char=E5=AD=97=E6=AE=B5=E8=81=9A=E7=84=A6?= =?UTF-8?q?=E5=85=A8=E9=80=89=E5=8A=9F=E8=83=BD=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_warehouse/__manifest__.py | 2 +- sf_warehouse/static/src/js/cust_char.js | 84 +++++++++++++++++++ sf_warehouse/static/src/js/custom_many2one.js | 81 ++++++++++++++++++ 3 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 sf_warehouse/static/src/js/cust_char.js create mode 100644 sf_warehouse/static/src/js/custom_many2one.js diff --git a/sf_warehouse/__manifest__.py b/sf_warehouse/__manifest__.py index 46ec4204..2bf2de4f 100644 --- a/sf_warehouse/__manifest__.py +++ b/sf_warehouse/__manifest__.py @@ -10,7 +10,7 @@ """, 'category': 'sf', 'website': 'https://www.sf.jikimo.com', - 'depends': ['stock','web' ], + 'depends': ['stock', 'web', ], 'data': [ # 'security/group_security.xml', # 'security/ir.model.access.csv', diff --git a/sf_warehouse/static/src/js/cust_char.js b/sf_warehouse/static/src/js/cust_char.js new file mode 100644 index 00000000..5aa43927 --- /dev/null +++ b/sf_warehouse/static/src/js/cust_char.js @@ -0,0 +1,84 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { CharField } from '@web/views/fields/char/char_field'; + + + +// 继承CharField组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容 +class CustomChar extends CharField { + /** + * @override + * @private + * @param {MouseEvent} ev + * @returns {Promise} + */ + + onMounted() { + super.onMounted(); + console.log('CustomChar.onMounted1'); + // 当光标聚焦于输入框时,选中输入框内容 + this.input.el.addEventListener('focus', function () { + this.select(); + }) + } + + +// setup() { +// console.log('CustomChar.setup1'); +// alert('CustomChar.setup1'); +// super.setup(); +// console.log(this) +// console.log('this.input', typeof this.input.el) +// console.log('this.props', this.props) +// console.log('this.props', this.props['value']) +// console.log('this.instanse', this.instance) +// console.log('this.el', this.el) +// console.log('9999999999',this) +// // this.input.el.addEventListener('focus', function() { +// // console.log('1233333333333') +// // }) +// } +// +// async willStart() { +// console.log('CustomChar.willStart1'); +// alert('CustomChar.willStart1'); +// await super.willStart(); +// } +// +// +// mounted() { +// console.log('CustomChar.mounted1'); +// // Now, the component's DOM element should be available +// const inputElement = this.el.querySelector('input'); +// // if (inputElement) { +// // inputElement.addEventListener('focus', function() { +// // this.select(); +// // }); +// // } +// } + + // setup() { + // console.log('CustomChar.setup1'); + // alert('CustomChar.setup1'); + // super.setup(); + // + // // 查找输入元素 + // const inputElement = this.el.querySelector('input'); + // if (inputElement) { + // inputElement.addEventListener('focus', function() { + // this.select(); + // }); + // } + // } + + // this.$input.on('focus', function () { + // $(this).select(); + // }); + + + // 当光标聚焦于输入框时,选中输入框内容 + +} + +registry.category("fields").add("custom_char", CustomChar); \ No newline at end of file diff --git a/sf_warehouse/static/src/js/custom_many2one.js b/sf_warehouse/static/src/js/custom_many2one.js new file mode 100644 index 00000000..beb4783e --- /dev/null +++ b/sf_warehouse/static/src/js/custom_many2one.js @@ -0,0 +1,81 @@ +/** @odoo-module **/ + +import { registry } from "@web/core/registry"; +import { Many2OneField } from '@web/views/fields/many2one/many2one_field'; + + + +// 继承FieldMany2One组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容 +class CustomMany2One extends Many2OneField { + /** + * @override + * @private + * @param {MouseEvent} ev + * @returns {Promise} + */ + setup() { + console.log('CustomMany2One.setup11111111111111'); + super.setup(); + } + onMounted() { + console.log('CustomMany2One.onMounted1'); + // 当光标聚焦于输入框时,选中输入框内容 + this.input.el.addEventListener('focus', function () { + this.select(); + }) + } + +} + +registry.category("fields").add("custom_many2one", CustomMany2One); + + +// /** @odoo-module **/ +// +// import { registry } from "@web/core/registry"; +// // import { field_registry } from '@web/legacy/js/fields/field_registry'; +// // import { FieldMany2One } from '@web/legacy/js/fields/relational_fields'; +// import { Many2OneField } from '@web/views/fields/many2one/many2one_field'; +// +// +// // 继承FieldMany2One组件实现自定义组件:当光标聚焦于输入框时,选中输入框内容 +// class CustomMany2One extends Many2OneField { +// /** +// * @override +// * @private +// * @param {MouseEvent} ev +// * @returns {Promise} +// */ +// setup() { +// console.log('CustomMany2One.setup11111111111111'); +// super.setup(); +// } +// onClick(ev) { +// super.onClick(ev); +// console.log('CustomMany2One._onInputClick'); +// +// this.$input.select(); +// } +// +// } +// +// // field_registry.add('custom_many2one', CustomMany2One); +// registry.category("fields").add("custom_many2one", CustomMany2One); + +// const CustomMany2One = FieldMany2One.extend({ +// /** +// * @override +// * @private +// * @param {MouseEvent} ev +// * @returns {Promise} +// */ +// _onInputClick: function (ev) { +// console.log('CustomMany2One._onInputClick'); +// this._super.apply(this, arguments); +// this.$input.select(); +// } +// }); +// +// field_registry.add('custom_many2one', CustomMany2One); +// export default CustomMany2One; +