增加平板扫码功能

This commit is contained in:
mgw
2023-04-24 16:00:08 +08:00
parent 9300073be4
commit 21f7f55ae8
83 changed files with 309 additions and 272 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -0,0 +1,193 @@
/** @odoo-module **/
import { Dropdown } from "@web/core/dropdown/dropdown";
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
import { useService } from "@web/core/utils/hooks";
import { registry } from "@web/core/registry";
import { browser } from "@web/core/browser/browser";
import { symmetricalDifference } from "@web/core/utils/arrays";
import { _t, qweb as QWeb } from "web.core";
import * as BarcodeScanner from "@web/webclient/barcode/barcode_scanner";
const { Component, useState } = owl;
const session = require("web.session");
const rpc = require("web.rpc");
var show_company = false;
session.user_has_group("base.group_multi_company").then(function (has_group) {
show_company = has_group;
});
var start_search_after_letter = 0
export class GlobalSearch extends Component {
setup() {
var self = this;
self.actionService = useService("action")
this._search_def = $.Deferred();
this.show_company = show_company;
this.allowed_company_ids = String(session.user_context.allowed_company_ids)
.split(",")
.map(function (id) {
return parseInt(id);
});
this.current_company = this.allowed_company_ids[0];
rpc.query({
model: "res.company",
method: "search_read",
args: [[["id", "=", self.current_company]], ["start_search_after_letter"]],
}).then(function (data) {
if(data){
if(data && data[0]){
start_search_after_letter = data[0].start_search_after_letter;
}
}
});
}
async on2BarcodeBtnClick() {
const barcode = await BarcodeScanner.scanBarcode();
console.log(barcode);
if (barcode) {
console.log("存在");
const input = document.querySelector('.usermenu_search_input');
if (input) {
input.value = barcode;
}
const event = new KeyboardEvent('keydown', {key: 'Enter'});
input.dispatchEvent(event);
// await this.onBarcodeScanned(barcode);
// if ("vibrate" in browser.navigator) {
// browser.navigator.vibrate(100);
// }
} else {
// console.log("不存在")
// alert('不存在')
this.notification.add(this.env._t("Please, scan again !"), {
type: "warning",
});
}
}
onSearchResultsNavigate(){
this._search_def.reject();
this._search_def = $.Deferred();
setTimeout(this._search_def.resolve.bind(this._search_def), 500);
this._search_def.done(this._searchData.bind(this));
return;
}
_on_click_clear_Search(){
$(".sh_search_input input").val('');
$(".sh_search_results").empty();
}
_searchData() {
var query = $(".sh_search_input input").val();
if (query === "") {
$(".sh_search_container").removeClass("has-results");
$(".sh_search_results").empty();
return;
}
$(".sh_search_results").empty();
var self = this;
if (query.length >=start_search_after_letter) {
rpc.query({
model: "global.search",
method: "get_search_result",
args: [[query]],
}).then(function (data) {
if (data) {
$(".sh_search_results").show();
console.log('data',data)
self._searchableMenus = data;
// var results = fuzzy.filter(query, _.keys(self._searchableMenus), {});
var results = _.keys(self._searchableMenus);
console.log('results',results)
if (results.length === 1) {
// 不显示搜索结果,直接跳转
$(".sh_search_results").hide();
var result = results[0];
console.log('result',result)
var original = self._searchableMenus[result];
console.log('original',original)
// if (original.action) {
// self.do_action(original.action);
// } else if (original.menu_id) {
// self.do_action(original.menu_id);
// }
if (original) {
self.actionService.doAction({
type: "ir.actions.act_window",
res_model: original.model,
res_id: original.id,
views: [[false, "form"]],
target: "current",
flags: { action_buttons: true, headless: true },
});
}
}
$(".sh_search_results").toggleClass("has-results", Boolean(results.length));
$(QWeb.render('MenuSearchResults', {
results: results,
widget:self,
_checkIsMenu: (key) => {
console.log('123',key)
key = key.split("|")[0];
if (key == "menu") {
return true;
} else {
return false;
}
},
_linkInfo: (key) => {
var original = self._searchableMenus[key];
return original;
},
_getFieldInfo: (key) => {
key = key.split("|")[1];
return key;
},
_getcompanyInfo: (key) => {
key = key.split("|")[0];
return key;
},
_linkInfo: (key) => {
var original = self._searchableMenus[key];
return original;
}
})).appendTo($(".sh_search_results"));
}
});
}
}
}
GlobalSearch.template = "GlobalSearch";
GlobalSearch.components = { Dropdown, DropdownItem };
GlobalSearch.toggleDelay = 1000;
export const systrayItem = {
Component: GlobalSearch,
};
registry.category("systray").add("GlobalSearch", systrayItem, { sequence: 1 });

View File

@@ -0,0 +1,89 @@
.sh_search_results {
position: fixed !important;
overflow-x: hidden;
overflow-y: auto;
box-shadow: none;
border: none;
width: 40vw;
z-index: 111;
top: 45px;left: auto;right: 0;
background: #71639e;
max-height: calc(100% - #{$o-navbar-height});
}
.sh_search_results .dropdown-item:hover {
color: #333232;
}
.sh_search_results .dropdown-item:active {
color: #333232;
}
.sh_search_container .sh_search_input .clear_Search:focus{outline: none;}
.sh_search_results .dropdown-item {
color: #fff;
white-space: normal;
word-break: break-word;
}
.sh_search_input {
margin-top: 5px;
}
.sh_search_container {
padding-left: 15px;
padding-right: 15px;
}
.sh_search_input .usermenu_search_input {
background: transparent;
border: none;
border-bottom: 1px solid white;
box-shadow: none;
color: #fff;
border-radius: unset;
}
.sh_search_input .usermenu_search_input::placeholder {
color: #fff;
}
.input-group-text{
background: transparent;
border: none;
border-bottom: 0px solid white;
color: #fff;
border-radius: 0px;
}
.search_company_detail {
border-bottom: 1px solid white;
margin-bottom: 2px;
margin-top: 5px;
color:#fff;
}
.clear_Search {
background: transparent;
border: none;
color: #fff;
border-bottom: 0px solid white;
border-radius: 0px;
}
.barcode-button {
border: none;
background-color: transparent;
}
.barcode-icon {
color: white;
//z-index: 10;
//position: relative;
//top: -10px;
}
.icon-button {
border: none;
color: white;
background-color: transparent;
padding: 0;
}
.sh_search_container .sh_search_input .input-group-prepend{background: transparent;border: none;border-bottom: 1px solid white;padding-top: 5px;}

View File

@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="GlobalSearch" owl="1">
<div>
<div class="sh_search_container form-row align-items-center">
<div class="sh_search_input">
<div class="input-group">
<!-- <div> -->
<!-- <button class="fa fa-qrcode" t-on-click="on2BarcodeBtnClick"></button> -->
<!-- </div> -->
<div class="input-group-prepend">
<!-- <div class="input-group-text"> -->
<!-- <button class="fa fa-qrcode icon-button" t-on-click="on2BarcodeBtnClick"> -->
<button class="icon-button" t-on-click="on2BarcodeBtnClick">
<img src="/sf_global_search/static/src/img/barcode.png" style="width: 20px; height: 20px;"/></button>
</div>
<input type="text" placeholder="Searching ..." t-on-keydown="onSearchResultsNavigate" class="usermenu_search_input form-control"/>
<div class="input-group-prepend">
<button class="clear_Search" t-on-click="_on_click_clear_Search">X</button>
</div>
</div>
</div>
<div class="sh_search_results col-md-10 ml-auto mr-auto"/>
</div>
</div>
</t>
<t t-name="MenuSearchResults" >
<t t-set="count" t-value="0" />
<t t-foreach="results" t-as="result">
<t t-set="is_menu" t-value="_checkIsMenu(result)" />
<t t-set="menu" t-value="_linkInfo(result)" />
<t t-if="is_menu">
<a t-attf-class="dropdown-item col-12 ml-auto mr-auto" target="_blank" t-attf-href="#menu_id=#{menu.id}&amp;action_id=#{menu.action}"><span t-esc="menu.name" /></a>
</t>
<t t-else="">
<t t-if="count==0">
<t t-set="menu_model" t-value="menu.model_name" />
<t t-set="count" t-value="1" />
<p class="search_company_detail">
<t t-set="company_name" t-value="_getcompanyInfo(result)" />
<t t-if="show_company"> <t t-esc="company_name" /> : </t>
<t t-esc="menu_model" />
</p>
</t>
<t t-if="menu.model_name == menu_model">
<t t-set="field_name" t-value="_getFieldInfo(result)" />
<t t-if="show_company &amp; company_name!=_getcompanyInfo(result)">
<t t-set="company_name" t-value="_getcompanyInfo(result)" />
<p class="search_company_detail"><t t-esc="company_name" /> : <t t-esc="menu_model" /></p>
</t>
<a t-attf-class="dropdown-item col-12 ml-auto mr-auto" t-raw="field_name" target="_blank" t-attf-href="/mail/view?model=#{menu.model}&amp;res_id=#{menu.id}" />
</t>
<t t-else="">
<t t-set="menu_model" t-value="menu.model_name" />
<p class="search_company_detail">
<t t-set="company_name" t-value="_getcompanyInfo(result)" />
<t t-if="show_company"> <t t-esc="company_name" /> : </t>
<t t-esc="menu_model" />
</p>
<t t-set="field_name" t-value="_getFieldInfo(result)" />
<a t-attf-class="dropdown-item col-12 ml-auto mr-auto" t-raw="field_name" target="_blank" t-attf-href="/mail/view?model=#{menu.model}&amp;res_id=#{menu.id}" />
</t>
</t>
</t>
</t>
</templates>