xiaozhi-esp32-server/main/manager-web/src/components/HeaderBar.vue
lapy 70771b4209 chore(westernization): translate remaining Han text across code, UI and docs
Final localization pass over everything the audit covers, driven by the
local qwen3.8:instruct endpoint (thinking disabled) with placeholder-
masked, cached, resumable batches:

- Python server: comments, docstrings, log/error messages, prompt text
- manager-api Java: javadoc, exception messages, Swagger summaries,
  westernized test fixtures (locale strings, signed-URL examples)
- manager-web / manager-mobile: component comments and misc leftovers
  (functional split regexes such as /[、;;,,]/ left byte-identical)
- digital-human: HTML/UI text, JS comments, wake-word defaults aligned
  with the server canonical English wake words
- docs: device-call guide, wakeword and search integration guides

Also widens the westernization audit exception to the whole vendored
generator bundle and retires the stale per-file exception list.
2026-10-11 17:58:15 +01:00

616 lines
20 KiB
Vue

<template>
<el-header class="header">
<div class="header-container">
<!-- Left element -->
<div class="header-left" @click="handleRouter('home')">
<img loading="lazy" alt="" src="@/assets/xiaozhi-logo.png" class="logo-img" />
<img loading="lazy" alt="" :src="xiaozhiAiIcon" class="brand-img" />
</div>
<!-- Middle navigation menu -->
<div class="header-center">
<div class="equipment-management" :class="{
'active-tab':
$route.path === '/home' ||
$route.path === '/role-config' ||
$route.path === '/device-management',
}" @click="handleRouter('home')">
<img loading="lazy" alt="" src="@/assets/header/robot.png" :style="{
filter:
$route.path === '/home' ||
$route.path === '/role-config' ||
$route.path === '/device-management'
? 'brightness(0) invert(1)'
: 'None',
}" />
<span class="nav-text">{{ $t("header.smartManagement") }}</span>
</div>
<!-- Show voice cloning for regular users -->
<div v-if="!userInfo.superAdmin && featureStatus.voiceClone" class="equipment-management"
:class="{ 'active-tab': $route.path === '/voice-clone-management' }"
@click="handleRouter('voiceCloneManagement')">
<img loading="lazy" alt="" src="@/assets/header/voice.png" :style="{
filter:
$route.path === '/voice-clone-management'
? 'brightness(0) invert(1)'
: 'None',
}" />
<span class="nav-text">{{ $t("header.voiceCloneManagement") }}</span>
</div>
<!-- Show voice cloning dropdown menu for super admin -->
<el-dropdown v-if="userInfo.superAdmin && featureStatus.voiceClone" trigger="click"
class="equipment-management more-dropdown" :class="{
'active-tab':
$route.path === '/voice-clone-management' ||
$route.path === '/voice-resource-management',
}" @visible-change="handleVoiceCloneDropdownVisibleChange">
<span class="el-dropdown-link">
<img loading="lazy" alt="" src="@/assets/header/voice.png" :style="{
filter:
$route.path === '/voice-clone-management' ||
$route.path === '/voice-resource-management'
? 'brightness(0) invert(1)'
: 'None',
}" />
<span class="nav-text">{{ $t("header.voiceCloneManagement") }}</span>
<i class="el-icon-arrow-down" :class="{ 'rotate-down': voiceCloneDropdownVisible }"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item @click.native="handleRouter('voiceCloneManagement')">
{{ $t("header.voiceCloneManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('voiceResourceManagement')">
{{ $t("header.voiceResourceManagement") }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
<div v-if="userInfo.superAdmin" class="equipment-management"
:class="{ 'active-tab': $route.path === '/model-config' }" @click="handleRouter('modelConfig')">
<img loading="lazy" alt="" src="@/assets/header/model_config.png" :style="{
filter:
$route.path === '/model-config' ? 'brightness(0) invert(1)' : 'None',
}" />
<span class="nav-text">{{ $t("header.modelConfig") }}</span>
</div>
<div v-if="featureStatus.knowledgeBase" class="equipment-management"
:class="{ 'active-tab': $route.path === '/knowledge-base-management' || $route.path === '/knowledge-file-upload' }"
@click="handleRouter('knowledgeBaseManagement')">
<img loading="lazy" alt="" src="@/assets/header/knowledge_base.png" :style="{
filter:
$route.path === '/knowledge-base-management' || $route.path === '/knowledge-file-upload' ? 'brightness(0) invert(1)' : 'None',
}" />
<span class="nav-text">{{ $t("header.knowledgeBase") }}</span>
</div>
<div v-if="featureStatus.addressBook" class="equipment-management"
:class="{ 'active-tab': $route.path === '/address-book-management' }"
@click="handleRouter('addressBookManagement')">
<img loading="lazy" alt="" src="@/assets/header/address_book.png" :style="{
filter:
$route.path === '/address-book-management' ? 'brightness(0) invert(1)' : 'None',
}" />
<span class="nav-text">{{ $t("header.addressBook") }}</span>
</div>
<el-dropdown v-if="userInfo.superAdmin" trigger="click" class="equipment-management more-dropdown" :class="{
'active-tab':
$route.path === '/dict-management' ||
$route.path === '/params-management' ||
$route.path === '/provider-management' ||
$route.path === '/server-side-management' ||
$route.path === '/agent-template-management' ||
$route.path === '/ota-management' ||
$route.path === '/user-management' ||
$route.path === '/feature-management' ||
$route.path === '/replacement-word-management'
}" @visible-change="handleParamDropdownVisibleChange">
<span class="el-dropdown-link">
<img loading="lazy" alt="" src="@/assets/header/param_management.png" :style="{
filter:
$route.path === '/dict-management' ||
$route.path === '/params-management' ||
$route.path === '/provider-management' ||
$route.path === '/server-side-management' ||
$route.path === '/agent-template-management' ||
$route.path === '/ota-management' ||
$route.path === '/user-management' ||
$route.path === '/feature-management' ||
$route.path === '/replacement-word-management'
? 'brightness(0) invert(1)'
: 'None',
}" />
<span class="nav-text">{{ $t("header.paramDictionary") }}</span>
<i class="el-icon-arrow-down" :class="{ 'rotate-down': paramDropdownVisible }"></i>
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item @click.native="handleRouter('paramManagement')">
{{ $t("header.paramManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('userManagement')">
{{ $t("header.userManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('otaManagement')">
{{ $t("header.otaManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('dictManagement')">
{{ $t("header.dictManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('providerManagement')">
{{ $t("header.providerManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('agentTemplate')">
{{ $t("header.agentTemplate") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('replacementWordManagement')">
{{ $t("header.replacementWordManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('serverSideManagement')">
{{ $t("header.serverSideManagement") }}
</el-dropdown-item>
<el-dropdown-item @click.native="handleRouter('featureManagement')">
{{ $t("header.featureManagement") }}
</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
<!-- Right-side element -->
<div class="header-right">
<img loading="lazy" alt="" src="@/assets/home/avatar.png" class="avatar-img" @click="handleAvatarClick" />
<span class="el-user-dropdown" @click="handleAvatarClick">
{{ userInfo.username || $t('header.loading') }}
<i class="el-icon-arrow-down el-icon--right" :class="{ 'rotate-down': userMenuVisible }"></i>
</span>
<el-cascader :options="userMenuOptions" trigger="click" :props="cascaderProps"
style="width: 0px; overflow: hidden" :show-all-levels="false" @change="handleCascaderChange"
@visible-change="handleUserMenuVisibleChange" ref="userCascader">
<template slot-scope="{ data }">
<span>{{ data.label }}</span>
</template>
</el-cascader>
</div>
</div>
<!-- Change password dialog -->
<ChangePasswordDialog v-model="isChangePasswordDialogVisible" />
</el-header>
</template>
<script>
import i18n, { changeLanguage, getLanguageLabelKey, supportedLanguages } from "@/i18n";
import userApi from "@/apis/module/user";
import featureManager from "@/utils/featureManager"; // Import feature management utility class
import { mapActions, mapState } from "vuex";
import ChangePasswordDialog from "./ChangePasswordDialog.vue"; // Import change password modal component
export default {
name: "HeaderBar",
components: {
ChangePasswordDialog,
},
props: ["devices"], // Receive device list from parent component
data() {
return {
search: "",
isChangePasswordDialogVisible: false, // Control visibility of change password dialog
paramDropdownVisible: false,
voiceCloneDropdownVisible: false,
userMenuVisible: false, // Add user menu visibility status
menuVisibleTimer: null, // Menu display timer to prevent rapid triggering
// Cascader Config
cascaderProps: {
expandTrigger: "click",
value: "value",
label: "label",
children: "children",
},
// Page Navigation Config
routerPaths: {
home: "/home",
modelConfig: "/model-config",
knowledgeBaseManagement: "/knowledge-base-management",
addressBookManagement: "/address-book-management",
voiceCloneManagement: "/voice-clone-management",
voiceResourceManagement: "/voice-resource-management",
paramManagement: "/params-management",
userManagement: "/user-management",
otaManagement: "/ota-management",
dictManagement: "/dict-management",
providerManagement: "/provider-management",
agentTemplate: "/agent-template-management",
replacementWordManagement: "/replacement-word-management",
serverSideManagement: "/server-side-management",
featureManagement: "/feature-management",
}
};
},
computed: {
...mapState({
featureStatus: (state) => ({
voiceClone: state.pubConfig.systemWebMenu?.features?.voiceClone?.enabled, // Voice cloning feature status
knowledgeBase: state.pubConfig.systemWebMenu?.features?.knowledgeBase?.enabled, // Knowledge base feature status
addressBook: state.pubConfig.systemWebMenu?.features?.addressBook?.enabled, // Contacts feature status
}),
userInfo: (state) => state.userInfo,
}),
currentLanguage() {
return i18n.locale || "en";
},
currentLanguageText() {
return this.$t(getLanguageLabelKey(this.currentLanguage));
},
xiaozhiAiIcon() {
switch (this.currentLanguage) {
case "de":
return require("@/assets/xiaozhi-ai_de.png");
case "vi":
return require("@/assets/xiaozhi-ai_vi.png");
case "pt_BR":
case "en":
default:
return require("@/assets/xiaozhi-ai_en.png");
}
},
// User menu options
userMenuOptions() {
return [
{
label: this.currentLanguageText,
value: "language",
children: supportedLanguages.map((lang) => ({
label: this.$t(lang.labelKey),
value: lang.code,
})),
},
{
label: this.$t("header.changePassword"),
value: "changePassword",
},
{
label: this.$t("header.logout"),
value: "logout",
},
];
},
},
async mounted() {
this.fetchUserInfo();
this.checkScreenSize();
window.addEventListener("resize", this.checkScreenSize);
// Load search history from localStorage
this.loadSearchHistory();
// Wait for featureManager initialization to complete before loading feature states
await this.loadFeatureStatus();
},
methods: {
handleRouter(type) {
this.$router.push(this.routerPaths[type]);
},
fetchUserInfo() {
userApi.getUserInfo(({ data }) => {
if (data && data.code === 0 && data.data) {
this.$store.commit("setUserInfo", data.data);
}
});
},
// Load feature status
async loadFeatureStatus() {
// Wait for featureManager initialization to complete
await featureManager.waitForInitialization();
},
// Show change password dialog
showChangePasswordDialog() {
this.isChangePasswordDialogVisible = true;
// Add: Reset user menu visibility after showing the change password dialog
this.userMenuVisible = false;
},
// Log Out
async handleLogout() {
try {
// Call the Vuex logout action
await this.logout();
this.$message.success({
message: this.$t("message.success"),
showClose: true,
});
} catch (error) {
console.error("Logout failed:", error);
this.$message.error({
message: this.$t("message.error"),
showClose: true,
});
}
},
// Monitor visibility changes of the parameter dictionary dropdown
handleParamDropdownVisibleChange(visible) {
this.paramDropdownVisible = visible;
},
// Monitor visibility changes of the voice cloning dropdown
handleVoiceCloneDropdownVisibleChange(visible) {
this.voiceCloneDropdownVisible = visible;
},
// Add a key in data to force component re-render
// Handle Cascader selection change
handleCascaderChange(value) {
if (!value || value.length === 0) {
return;
}
const action = value[value.length - 1];
// Handle language switch
if (value.length === 2 && value[0] === "language") {
this.changeLanguage(action);
} else {
// Process other operations
switch (action) {
case "changePassword":
this.showChangePasswordDialog();
break;
case "logout":
this.handleLogout();
break;
}
}
// Clear selection immediately after operation
setTimeout(() => {
this.completeResetCascader();
}, 300);
},
// Toggle Language
changeLanguage(lang) {
changeLanguage(lang);
this.$message.success({
message: this.$t("message.success"),
showClose: true,
});
// Added: Reset user menu visibility state after language switch
this.userMenuVisible = false;
},
// Fully reset cascader
completeResetCascader() {
if (this.$refs.userCascader) {
try {
// Attempt all possible methods to clear selection
// 1. Try using the clearValue method provided by the component
if (this.$refs.userCascader.clearValue) {
this.$refs.userCascader.clearValue();
}
// 2. Directly clear internal properties
if (this.$refs.userCascader.$data) {
this.$refs.userCascader.$data.selectedPaths = [];
this.$refs.userCascader.$data.displayLabels = [];
this.$refs.userCascader.$data.inputValue = "";
this.$refs.userCascader.$data.checkedValue = [];
this.$refs.userCascader.$data.showAllLevels = false;
}
// 3. Manipulate DOM to clear selection state
const menuElement = this.$refs.userCascader.$refs.menu;
if (menuElement && menuElement.$el) {
const activeItems = menuElement.$el.querySelectorAll(
".el-cascader-node.is-active"
);
activeItems.forEach((item) => item.classList.remove("is-active"));
const checkedItems = menuElement.$el.querySelectorAll(
".el-cascader-node.is-checked"
);
checkedItems.forEach((item) => item.classList.remove("is-checked"));
}
console.log("Cascader values cleared");
} catch (error) {
console.error("Failed to clear selection values:", error);
}
}
},
// Click avatar to trigger cascader dropdown menu
handleAvatarClick() {
if (this.$refs.userCascader) {
// Toggle menu visibility
this.userMenuVisible = !this.userMenuVisible;
// Clear selection values when menu collapses
if (!this.userMenuVisible) {
this.completeResetCascader();
}
// Directly set menu visibility state
try {
// Attempt to use the toggleDropDownVisible method
this.$refs.userCascader.toggleDropDownVisible(this.userMenuVisible);
} catch (error) {
// If toggle method fails, try setting the property directly
if (this.$refs.userCascader.$refs.menu) {
this.$refs.userCascader.$refs.menu.showMenu(this.userMenuVisible);
} else {
console.error("Cannot access menu component");
}
}
}
},
// Handle user menu visibility changes
handleUserMenuVisibleChange(visible) {
if (this.menuVisibleTimer) return;
this.menuVisibleTimer = setTimeout(() => {
this.userMenuVisible = visible;
clearTimeout(this.menuVisibleTimer);
this.menuVisibleTimer = null;
}, 100);
// If menu is closed, also clear selected values
if (!visible) {
this.completeResetCascader();
}
},
// Use mapActions to import the Vuex logout action
...mapActions(["logout"]),
},
};
</script>
<style lang="scss" scoped>
.header {
background: linear-gradient(180deg, #dfeafe, #eff4ff);
height: 63px !important;
min-width: 900px;
overflow: visible;
}
.header-container {
display: flex;
justify-content: space-between;
align-items: center;
height: 100%;
padding: 0 10px;
}
.header-left {
display: flex;
align-items: center;
gap: 10px;
min-width: 130px;
cursor: pointer;
}
.logo-img {
width: 42px;
height: 42px;
}
.brand-img {
height: 20px;
}
.header-center {
display: flex;
align-items: center;
gap: 25px;
background: white;
border-radius: 30px;
box-shadow: 0 0 6px 0px #cfe1fb;
padding: 4px;
}
.header-right {
display: flex;
align-items: center;
gap: 7px;
justify-content: flex-end;
}
.equipment-management {
padding: 8px 16px;
border-radius: 30px;
display: flex;
justify-content: center;
font-size: 16px;
font-weight: 500;
gap: 7px;
color: #6c79a8;
margin-left: 1px;
align-items: center;
transition: all 0.3s ease;
cursor: pointer;
flex-shrink: 0;
position: relative;
}
.equipment-management.active-tab {
color: #fff !important;
background: linear-gradient(90deg, #2983fe 0%, #5251fc 100%);
box-shadow: 0 1px 8px rgba(41, 131, 254, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
position: relative;
overflow: hidden;
}
.equipment-management.active-tab::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 50%;
background: linear-gradient(to bottom, rgba(255, 255, 255, 0.4) 0%, rgba(255, 255, 255, 0) 100%);
pointer-events: none;
}
.equipment-management img {
width: 15px;
height: 13px;
}
.avatar-img {
width: 21px;
height: 21px;
flex-shrink: 0;
cursor: pointer;
}
.el-user-dropdown {
cursor: pointer;
}
/* Navigation text style - supports line breaks for Chinese and English */
.nav-text {
white-space: normal;
text-align: center;
line-height: 1.2;
}
.el-dropdown-link {
display: flex;
align-items: center;
gap: 7px;
}
/* Responsive adjustment */
@media (max-width: 1200px) {
.header-center {
gap: 14px;
}
.equipment-management {
min-width: 80px;
font-size: 10px;
}
}
.equipment-management.more-dropdown {
position: relative;
}
.equipment-management.more-dropdown .el-dropdown-menu {
position: absolute;
right: 0;
min-width: 120px;
margin-top: 5px;
}
.el-dropdown-menu__item {
min-width: 60px;
padding: 8px 20px;
font-size: 14px;
color: #606266;
white-space: nowrap;
}
/* Add inverted triangle rotation style */
.rotate-down {
transform: rotate(180deg);
transition: transform 0.3s ease;
}
.el-icon-arrow-down {
transition: transform 0.3s ease;
}
</style>