修改部分规则模块删除无用前端 新增前端界面

This commit is contained in:
zouju
2026-02-06 17:22:22 +08:00
parent 000f8d4bc5
commit a440094138
583 changed files with 26241 additions and 26046 deletions

View File

@@ -0,0 +1,10 @@
/*
* This file is part of the kernelstudio package.
*
* (c) 2014-2025 zlin <admin@kernelstudio.com>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
export * from './session'

View File

@@ -0,0 +1,75 @@
/*
* This file is part of the kernelstudio package.
*
* (c) 2014-2025 zlin <admin@kernelstudio.com>
*
* For the full copyright and license information, please view the LICENSE file
* that was distributed with this source code.
*/
import { computed, type ComputedRef, ref, type Ref } from 'vue';
import { getToken, removeToken, setToken } from '../utils/token';
import type { UserLoginForm, UserSessionResult } from '@/types';
import { fetchUserSession, signinByForm } from '@/api/user';
const userDetails = ref<UserSessionResult | null>(null);
const token = ref<string>(getToken() || '');
export interface UseUserSession {
token: Ref<String>;
details: ComputedRef<UserSessionResult | null>;
load: () => Promise<UserSessionResult>;
signin: (form: UserLoginForm) => Promise<UserSessionResult>;
logout: () => Promise<boolean>;
}
export const useUserSession = (): UseUserSession => {
const load = (): Promise<UserSessionResult> => {
return new Promise((resolve, reject) => {
if (userDetails.value) {
resolve(userDetails.value);
} else {
fetchUserSession().then(r => {
if (r.user) {
userDetails.value = r;
resolve(r);
} else {
reject(new Error(r.msg ?? '获取用户信息失败.'));
}
}).catch((e: any)=> {
reject(e);
});
}
});
};
const logout = (): Promise<boolean> => {
return new Promise((resolve) => {
removeToken();
resolve(true);
// logoutSession().then(r => resolve(r.code === 200));
});
};
const signin = (form: UserLoginForm): Promise<UserSessionResult> => {
return new Promise((resolve, reject) => {
signinByForm(form).then(r => {
if (r.token) {
setToken(r.token);
load().then(r => resolve(r));
} else {
reject(new Error(r.msg ?? '登录失败'));
}
});
});
};
return {
token,
details: computed(() => userDetails.value),
load,
signin,
logout,
} as UseUserSession;
};