diff --git a/src/App.vue b/src/App.vue index cb34b25..6bbca27 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,7 +2,6 @@ import { getToken } from '@/utils/auth' import { initializeLocale, translateLiteral } from '@/locales' import useUserStore from '@/store/modules/user' -import { initializeTerminalType } from '@/utils/terminal' let wrapped = false @@ -49,7 +48,6 @@ function wrapUniTextApi() { export default { onLaunch: function () { initializeLocale() - initializeTerminalType() wrapUniTextApi() if (getToken()) { useUserStore().getInfo().catch(() => {}) diff --git a/src/api/login.js b/src/api/login.js index d44bc01..26b53b7 100644 --- a/src/api/login.js +++ b/src/api/login.js @@ -1,5 +1,4 @@ import request from '@/utils/request' -import { getTerminalType } from '@/utils/terminal' const permissionInfoCache = new Map() const permissionInfoPending = new Map() @@ -13,35 +12,16 @@ function normalizePermissionParams(params = {}) { function createPermissionCacheKey(params = {}) { const normalizedParams = normalizePermissionParams(params) - const terminalType = getTerminalType() return JSON.stringify( - Object.keys({ ...normalizedParams, terminalType }) + Object.keys(normalizedParams) .sort() .reduce((result, key) => { - result[key] = key === 'terminalType' ? terminalType : normalizedParams[key] + result[key] = normalizedParams[key] return result }, {}) ) } -function filterPermissionMenus(menus, terminalType) { - if (!Array.isArray(menus)) { - return [] - } - - return menus.filter((menu) => { - if (!menu || typeof menu !== 'object') { - return false - } - - if (menu.terminalType === null || typeof menu.terminalType === 'undefined' || menu.terminalType === '') { - return true - } - - return Number(menu.terminalType) === Number(terminalType) - }) -} - export function clearPermissionInfoCache() { permissionInfoCache.clear() permissionInfoPending.clear() @@ -82,7 +62,6 @@ export function register(data) { function getPermissionInfo(params = {}) { const normalizedParams = normalizePermissionParams(params) - const terminalType = getTerminalType() const cacheKey = createPermissionCacheKey(normalizedParams) if (permissionInfoCache.has(cacheKey)) { @@ -101,13 +80,7 @@ function getPermissionInfo(params = {}) { const wrappedPromise = requestPromise .then((res) => { - const nextRes = { - ...res, - data: { - ...res?.data, - menus: filterPermissionMenus(res?.data?.menus, terminalType) - } - } + const nextRes = res permissionInfoCache.set(cacheKey, nextRes) return nextRes }) diff --git a/src/components/common/TabBar.vue b/src/components/common/TabBar.vue index d380a43..f2c0922 100644 --- a/src/components/common/TabBar.vue +++ b/src/components/common/TabBar.vue @@ -44,25 +44,6 @@ function normalizeRoute(path = '') { return String(path || '').trim().replace(/^\/+/, '') } -function normalizeMenuName(value = '') { - return String(value || '').trim().toLowerCase() -} - -function isMineMenu(menu) { - const names = [menu?.name, menu?.enName, menu?.text].map(normalizeMenuName) - const paths = [menu?.path, menu?.component].map((item) => normalizeRoute(item).toLowerCase()) - return ( - names.some((name) => ['我的', '个人中心', 'mine', 'profile'].includes(name)) || - paths.some((path) => path === 'pages/mine' || path === 'pages/smq/mine') - ) -} - -function isSmqTabbar() { - const pages = getCurrentPages() - const route = pages && pages.length > 0 ? pages[pages.length - 1].route : '' - return normalizeRoute(route).startsWith('pages/smq/') -} - function isUniIcon(icon) { return String(icon || '').startsWith('uni-icons:') } @@ -114,17 +95,6 @@ function createTabItem(menu) { } } -function createMineTabItem() { - return { - text: t('tab.mine'), - icon: '', - selectedIcon: '', - iconType: 'uni-icons', - iconName: 'person', - path: isSmqTabbar() ? '/pages/smq/mine' : '/pages/mine' - } -} - function getCurrentActiveIndex() { const pages = getCurrentPages() if (pages && pages.length > 0) { @@ -136,11 +106,7 @@ function getCurrentActiveIndex() { } const tabList = computed(() => { - const apiTabs = getTabBarMenus(menus.value) - .filter((menu) => !isMineMenu(menu)) - .map(createTabItem) - - return [...apiTabs, createMineTabItem()] + return getTabBarMenus(menus.value).map(createTabItem) }) onMounted(() => { diff --git a/src/pages_mine/pages/setting/index.vue b/src/pages_mine/pages/setting/index.vue index d5351f2..5d8e23b 100644 --- a/src/pages_mine/pages/setting/index.vue +++ b/src/pages_mine/pages/setting/index.vue @@ -8,13 +8,6 @@ {{ t('setting.language') }} {{ translateWithParams('setting.currentLanguage', { language: currentLanguageLabel }) }} - - - - - {{ t('setting.terminalMode') }} - - {{ translateWithParams('setting.currentTerminal', { terminal: currentTerminalLabel }) }} @@ -46,7 +39,6 @@ import { useI18n } from 'vue-i18n' import useUserStore from '@/store/modules/user' import { getCurrentLocale, setLocale, translateWithParams } from '@/locales' import NavBar from '@/components/common/NavBar.vue' -import { getTerminalType, setTerminalType, TERMINAL_TYPE_MOBILE, TERMINAL_TYPE_SCANNER } from '@/utils/terminal' const userStore = useUserStore() const { t } = useI18n() @@ -55,9 +47,7 @@ const pageTitle = computed(() => t('nav.setting')) const windowHeight = ref(uni.getSystemInfoSync().windowHeight); const popup = ref(null); const currentLocale = ref(getCurrentLocale()) -const currentTerminalType = ref(getTerminalType()) const currentLanguageLabel = computed(() => currentLocale.value === 'en-US' ? t('setting.enUS') : t('setting.zhCN')) -const currentTerminalLabel = computed(() => currentTerminalType.value === TERMINAL_TYPE_SCANNER ? t('setting.scanner') : t('setting.mobile')) function handleToPwd() { uni.navigateTo({ @@ -98,45 +88,6 @@ function handleLanguageChange() { }) } -function handleTerminalChange() { - uni.showActionSheet({ - itemList: [t('setting.mobile'), t('setting.scanner')], - success: async ({ tapIndex }) => { - const nextTerminalType = tapIndex === 1 ? TERMINAL_TYPE_SCANNER : TERMINAL_TYPE_MOBILE - if (nextTerminalType === currentTerminalType.value) { - return - } - - const previousTerminalType = currentTerminalType.value - setTerminalType(nextTerminalType) - currentTerminalType.value = nextTerminalType - uni.showLoading({ - title: t('setting.switchingTerminal') - }) - - try { - await userStore.refreshPermissionInfo() - uni.showToast({ - title: translateWithParams('setting.terminalSwitched', { terminal: currentTerminalLabel.value }), - icon: 'none', - duration: 1000 - }) - } catch (error) { - setTerminalType(previousTerminalType) - currentTerminalType.value = previousTerminalType - await userStore.refreshPermissionInfo().catch(() => {}) - uni.showToast({ - title: t('common.saveFailed'), - icon: 'none', - duration: 1000 - }) - } finally { - uni.hideLoading() - } - } - }) -} - function handleLogout() { popup.value.open(); }; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index 962fe6d..fa8f1b2 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -1,6 +1,5 @@ import { login, logout, getInfo, clearPermissionInfoCache } from "@/api/login"; import { getToken, setToken, removeToken } from "@/utils/auth"; -import { removeTerminalType } from "@/utils/terminal"; import defAva from "@/static/images/profile.jpg"; import { defineStore } from "pinia"; import { initAllDict } from "@/utils/dict"; @@ -91,7 +90,6 @@ const useUserStore = defineStore("user", { logout() .then(() => { clearPermissionInfoCache(); - removeTerminalType(); this.token = ""; this.roles = []; this.permissions = []; diff --git a/src/utils/permissionMenu.js b/src/utils/permissionMenu.js index e23dcf1..f561a8b 100644 --- a/src/utils/permissionMenu.js +++ b/src/utils/permissionMenu.js @@ -1,6 +1,4 @@ -import { getTerminalType, TERMINAL_TYPE_SCANNER } from '@/utils/terminal' - const DIRECT_ROUTE_PREFIXES = ['pages/', 'page_', 'pages_'] const MENU_ROUTE_MAP = { @@ -181,7 +179,7 @@ export function getTabBarMenus(menus) { } export function getMineTabBarPath() { - return Number(getTerminalType()) === Number(TERMINAL_TYPE_SCANNER) ? '/pages/smq/mine' : '/pages/mine' + return '/pages/mine' } export function getFirstTabBarPath(menus, fallback = getMineTabBarPath()) { diff --git a/src/utils/terminal.ts b/src/utils/terminal.ts deleted file mode 100644 index 0ddac03..0000000 --- a/src/utils/terminal.ts +++ /dev/null @@ -1,46 +0,0 @@ -const TerminalTypeKey = 'App-Terminal-Type' - -export const TERMINAL_TYPE_MOBILE = 1 -export const TERMINAL_TYPE_SCANNER = 2 - -function normalizeTerminalType(value: unknown) { - return Number(value) === TERMINAL_TYPE_SCANNER ? TERMINAL_TYPE_SCANNER : TERMINAL_TYPE_MOBILE -} - -export function detectTerminalType() { - const systemInfo = uni.getSystemInfoSync() - const width = Number(systemInfo.windowWidth || systemInfo.screenWidth || 0) - const height = Number(systemInfo.windowHeight || systemInfo.screenHeight || 0) - - if (width === 480 && height === 800) { - return TERMINAL_TYPE_SCANNER - } - - return TERMINAL_TYPE_MOBILE -} - -export function getTerminalType() { - const storedValue = uni.getStorageSync(TerminalTypeKey) - if (storedValue === '' || storedValue === null || typeof storedValue === 'undefined') { - return TERMINAL_TYPE_MOBILE - } - return normalizeTerminalType(storedValue) -} - -export function setTerminalType(value: unknown) { - const terminalType = normalizeTerminalType(value) - uni.setStorageSync(TerminalTypeKey, terminalType) - return terminalType -} - -export function removeTerminalType() { - uni.removeStorageSync(TerminalTypeKey) -} - -export function initializeTerminalType() { - const storedValue = uni.getStorageSync(TerminalTypeKey) - if (storedValue === '' || storedValue === null || typeof storedValue === 'undefined') { - return setTerminalType(detectTerminalType()) - } - return normalizeTerminalType(storedValue) -} \ No newline at end of file