更新uniapp和platform

This commit is contained in:
hero920103 committed 2026-11-16 11:32:16 +08:00
1 parent 31ae07175d
commit 7f9a66da0f
47 files changed
+5207 -1974

No files matched your search

+27 -17
View File
@@ -15,11 +15,25 @@ export const useAllDataStore = defineStore('allData', () => {
function increment() {
count.value++;
}
// 是否为手机端(≤768px),通过 matchMedia 响应式监听
const mobileQuery = window.matchMedia('(max-width: 768px)');
const isMobile = ref(mobileQuery.matches);
const handleMobileQueryChange = (e) => {
isMobile.value = e.matches;
};
if (typeof mobileQuery.addEventListener === 'function') {
mobileQuery.addEventListener('change', handleMobileQueryChange);
} else {
mobileQuery.addListener(handleMobileQueryChange);
}
return {
state,
count,
doubleCount,
increment,
isMobile,
};
});
@@ -37,14 +51,13 @@ import { ref as vueRef } from 'vue';
* }
*/
export const useTabsStore = defineTabsStore('tabs', () => {
// 固定首页tab
// 固定首页 tab:/home 是数据概览页
const defaultDashboardPath = '/home';
// 从 localStorage 恢复 tabs 状态
function loadTabsFromStorage() {
try {
const savedTabs = localStorage.getItem('tabs_list');
const savedActiveTab = localStorage.getItem('active_tab');
if (savedTabs) {
const tabs = JSON.parse(savedTabs);
// 确保至少包含首页
@@ -59,7 +72,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
}
return [{ title: '首页', fullPath: defaultDashboardPath, name: 'Home' }];
}
// 保存 tabs 到 localStorage
function saveTabsToStorage(tabs, active) {
try {
@@ -71,7 +84,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
console.warn('保存 tabs 失败:', e);
}
}
const tabList = vueRef(loadTabsFromStorage());
const savedActiveTab = localStorage.getItem('active_tab');
const activeTab = vueRef(savedActiveTab || defaultDashboardPath);
@@ -88,6 +101,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
// 删除指定tab并切换激活tab
function removeTab(fullPath) {
if (fullPath === defaultDashboardPath) return;
const idx = tabList.value.findIndex((t) => t.fullPath === fullPath);
if (idx > -1) {
tabList.value.splice(idx, 1);
@@ -118,15 +132,13 @@ export const useTabsStore = defineTabsStore('tabs', () => {
function closeLeft(targetFullPath) {
const targetIndex = tabList.value.findIndex((t) => t.fullPath === targetFullPath);
if (targetIndex > -1) {
// 保留首页和目标tab及其右侧的所有tab
const beforeIndex = tabList.value.slice(0, targetIndex);
const hasCloseableLeft = beforeIndex.some(t => t.fullPath !== defaultDashboardPath);
if (hasCloseableLeft) {
tabList.value = tabList.value.filter((t, index) =>
tabList.value = tabList.value.filter((t, index) =>
t.fullPath === defaultDashboardPath || index >= targetIndex
);
// 如果关闭的tab中包含了当前激活的tab,则激活目标tab
if (!tabList.value.find(t => t.fullPath === activeTab.value)) {
activeTab.value = targetFullPath;
}
@@ -139,15 +151,13 @@ export const useTabsStore = defineTabsStore('tabs', () => {
function closeRight(targetFullPath) {
const targetIndex = tabList.value.findIndex((t) => t.fullPath === targetFullPath);
if (targetIndex > -1) {
// 保留首页和目标tab及其左侧的所有tab
const afterIndex = tabList.value.slice(targetIndex + 1);
const hasCloseableRight = afterIndex.length > 0;
if (hasCloseableRight) {
tabList.value = tabList.value.filter((t, index) =>
tabList.value = tabList.value.filter((t, index) =>
t.fullPath === defaultDashboardPath || index <= targetIndex
);
// 如果关闭的tab中包含了当前激活的tab,则激活目标tab
if (!tabList.value.find(t => t.fullPath === activeTab.value)) {
activeTab.value = targetFullPath;
}
@@ -162,7 +172,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
activeTab.value = defaultDashboardPath;
saveTabsToStorage(tabList.value, activeTab.value);
}
// 设置激活tab(不触发路由跳转,仅用于更新状态)
function setActiveTab(fullPath) {
activeTab.value = fullPath;
@@ -171,9 +181,8 @@ export const useTabsStore = defineTabsStore('tabs', () => {
// 重置 tabs store 到初始状态(登出时使用)
function resetTabs() {
tabList.value = [{ title: '首页', fullPath: defaultDashboardPath, name: 'Dashboard' }];
tabList.value = [{ title: '首页', fullPath: defaultDashboardPath, name: 'Home' }];
activeTab.value = defaultDashboardPath;
// 清除 localStorage 中的 tabs 数据
localStorage.removeItem('tabs_list');
localStorage.removeItem('active_tab');
}
@@ -181,6 +190,7 @@ export const useTabsStore = defineTabsStore('tabs', () => {
return {
tabList,
activeTab,
defaultDashboardPath,
addTab,
removeTab,
closeOthers,
@@ -194,4 +204,4 @@ export const useTabsStore = defineTabsStore('tabs', () => {
});
// ========== 菜单 Menu Store ==========
export { useMenuStore } from './menu';
export { useMenuStore } from './menu';