mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-17 06:55:38 +00:00
chore: 移除 frontend/app 私有代码,仅保留 .gitkeep
该目录为私有移动端项目,不应开源。从 git 跟踪中移除并加入 .gitignore。
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
/**
|
||||
* CommonUtil 工具方法
|
||||
* 提供 deepClone / isString / isObj / isDef / deepMerge 等工具方法
|
||||
*/
|
||||
export const CommonUtil = {
|
||||
isString(val: unknown): val is string {
|
||||
return typeof val === 'string'
|
||||
},
|
||||
|
||||
isObj(val: unknown): val is Record<string, any> {
|
||||
return val !== null && typeof val === 'object' && !Array.isArray(val)
|
||||
},
|
||||
|
||||
isDef(val: unknown): boolean {
|
||||
return val !== undefined && val !== null
|
||||
},
|
||||
|
||||
/**
|
||||
* 深拷贝
|
||||
* 优先使用原生 structuredClone(支持 Date/Map/Set/循环引用等),
|
||||
* 失败时(如 Vue reactive Proxy 无法被 structuredClone 序列化)回退 JSON 深拷贝。
|
||||
*/
|
||||
deepClone<T>(obj: T): T {
|
||||
if (typeof structuredClone === 'function') {
|
||||
try {
|
||||
return structuredClone(obj)
|
||||
}
|
||||
catch {
|
||||
// structuredClone 无法克隆 Vue reactive Proxy(Pinia $state)等对象,回退 JSON
|
||||
}
|
||||
}
|
||||
return JSON.parse(JSON.stringify(obj)) as T
|
||||
},
|
||||
|
||||
deepMerge<T extends Record<string, any>>(target: T, source: Record<string, any>): T {
|
||||
const result = { ...target } as Record<string, any>
|
||||
for (const key of Object.keys(source)) {
|
||||
if (CommonUtil.isObj(source[key]) && CommonUtil.isObj(result[key])) {
|
||||
result[key] = CommonUtil.deepMerge(result[key], source[key])
|
||||
}
|
||||
else {
|
||||
result[key] = source[key]
|
||||
}
|
||||
}
|
||||
return result as T
|
||||
},
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
/**
|
||||
* 获取当前页面路径
|
||||
* @returns 当前页面路径
|
||||
*/
|
||||
export function getCurrentPath() {
|
||||
const pages = getCurrentPages()
|
||||
const currentPage = pages[pages.length - 1]
|
||||
return currentPage.route || ''
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/**
|
||||
* 存储工具类
|
||||
* 提供localStorage和sessionStorage操作方法
|
||||
*/
|
||||
|
||||
/**
|
||||
* localStorage 存储
|
||||
*/
|
||||
function set(key: string, value: unknown): void {
|
||||
uni.setStorageSync(key, JSON.stringify(value))
|
||||
}
|
||||
|
||||
function get<T>(key: string, defaultValue?: T): T {
|
||||
const value = uni.getStorageSync(key)
|
||||
if (!value)
|
||||
return defaultValue as T
|
||||
|
||||
try {
|
||||
return JSON.parse(value)
|
||||
}
|
||||
catch {
|
||||
// 如果解析失败,返回原始字符串
|
||||
return value as unknown as T
|
||||
}
|
||||
}
|
||||
|
||||
function remove(key: string): void {
|
||||
uni.removeStorageSync(key)
|
||||
}
|
||||
|
||||
export const Storage = {
|
||||
set,
|
||||
get,
|
||||
remove,
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
import type { ThemeMode } from '@/composables/types/theme'
|
||||
|
||||
interface ThemeOwnerState {
|
||||
initialized: boolean
|
||||
listenerCount: number
|
||||
themeChangeHandler?: UniNamespace.OnThemeChangeCallback
|
||||
}
|
||||
|
||||
const themeOwnerStates = new WeakMap<object, ThemeOwnerState>()
|
||||
|
||||
function getThemeOwnerState(owner: object) {
|
||||
let state = themeOwnerStates.get(owner)
|
||||
if (!state) {
|
||||
state = {
|
||||
initialized: false,
|
||||
listenerCount: 0,
|
||||
}
|
||||
themeOwnerStates.set(owner, state)
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
function isThemeMode(theme: unknown): theme is ThemeMode {
|
||||
return theme === 'light' || theme === 'dark'
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前系统主题,不支持主题 API 或调用失败时回退为亮色。
|
||||
*/
|
||||
export function getSystemTheme(): ThemeMode {
|
||||
try {
|
||||
// #ifdef MP-WEIXIN
|
||||
const appBaseInfo = uni.getAppBaseInfo()
|
||||
if (isThemeMode(appBaseInfo?.theme)) {
|
||||
return appBaseInfo.theme
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
const systemInfo = uni.getSystemInfoSync()
|
||||
if (isThemeMode(systemInfo?.theme)) {
|
||||
return systemInfo.theme
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
catch (error) {
|
||||
console.warn('获取系统主题失败:', error)
|
||||
}
|
||||
|
||||
return 'light'
|
||||
}
|
||||
|
||||
/**
|
||||
* 确保同一个主题 store 在生命周期内只初始化一次。
|
||||
*/
|
||||
export function initializeThemeOnce(owner: object, initialize: () => void) {
|
||||
const state = getThemeOwnerState(owner)
|
||||
if (state.initialized) {
|
||||
return
|
||||
}
|
||||
|
||||
initialize()
|
||||
state.initialized = true
|
||||
}
|
||||
|
||||
/**
|
||||
* 按主题 store 复用系统主题监听,并返回对应的清理函数。
|
||||
*/
|
||||
export function subscribeSystemThemeChange(
|
||||
owner: object,
|
||||
handler: UniNamespace.OnThemeChangeCallback,
|
||||
) {
|
||||
if (
|
||||
typeof uni === 'undefined'
|
||||
|| typeof uni.onThemeChange !== 'function'
|
||||
) {
|
||||
return () => {}
|
||||
}
|
||||
|
||||
const state = getThemeOwnerState(owner)
|
||||
|
||||
if (!state.themeChangeHandler) {
|
||||
state.themeChangeHandler = handler
|
||||
uni.onThemeChange(state.themeChangeHandler)
|
||||
}
|
||||
state.listenerCount += 1
|
||||
|
||||
let subscribed = true
|
||||
|
||||
return () => {
|
||||
if (!subscribed) {
|
||||
return
|
||||
}
|
||||
subscribed = false
|
||||
state.listenerCount = Math.max(0, state.listenerCount - 1)
|
||||
|
||||
if (
|
||||
state.listenerCount === 0
|
||||
&& state.themeChangeHandler
|
||||
) {
|
||||
if (typeof uni.offThemeChange === 'function') {
|
||||
uni.offThemeChange(state.themeChangeHandler)
|
||||
}
|
||||
state.themeChangeHandler = undefined
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// 跳转到登录页
|
||||
export function toLoginPage(
|
||||
options: { mode?: 'navigateTo' | 'reLaunch' } = {},
|
||||
) {
|
||||
const { mode = 'navigateTo' } = options
|
||||
|
||||
if (mode === 'reLaunch') {
|
||||
uni.reLaunch({
|
||||
url: '/pages/login/index',
|
||||
})
|
||||
}
|
||||
else {
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/index',
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user