mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-22 05:02:57 +00:00
1、解决在线用户强制退出功能 2、初始化系统配置,应用全局 3、预留功能:将把vuex改用pinia(下次上线)
This commit is contained in:
+34
-4
@@ -7,8 +7,38 @@ import VChart from "vue-echarts";
|
||||
import "echarts";
|
||||
import './style.css'
|
||||
|
||||
import { getInitConfig } from "@/api/system/config"
|
||||
|
||||
const app = createApp(App);
|
||||
app.use(router);
|
||||
app.use(Antd);
|
||||
app.component("VChart", VChart);
|
||||
app.mount("#app");
|
||||
|
||||
const initConfig = () => {
|
||||
return getInitConfig()
|
||||
.then((response) => {
|
||||
const { status_code, data } = response.data;
|
||||
if (status_code === 200) {
|
||||
const configData = JSON.parse(data);
|
||||
configData.forEach((item) => {
|
||||
if (item.fied_key === "login_title") {
|
||||
document.title = item.fied_value || "fastapi vue admin";
|
||||
} else if (item.fied_key === "login_logo") {
|
||||
const favicon = document.querySelector('link[rel="icon"]');
|
||||
if (favicon) {
|
||||
favicon.href = item.fied_value || "/logo.png";
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
message.error("获取系统配置失败");
|
||||
console.error(error); // 打印错误信息以便调试
|
||||
});
|
||||
};
|
||||
|
||||
// 初始化配置并挂载应用
|
||||
initConfig().then(() => {
|
||||
app.use(router);
|
||||
app.use(Antd);
|
||||
app.component("VChart", VChart);
|
||||
app.mount("#app");
|
||||
});
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { getInitConfig } from "@/api/system/config";
|
||||
|
||||
export const useConfigStore = defineStore('config', {
|
||||
state: () => ({
|
||||
systemConfig: {},
|
||||
}),
|
||||
actions: {
|
||||
async getConfigInfo() {
|
||||
try {
|
||||
const response = await getInitConfig();
|
||||
const result = response.data;
|
||||
const configData = JSON.parse(result.data);
|
||||
this.systemConfig = configData;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
setSystemConfig(config) {
|
||||
this.systemConfig = config;
|
||||
},
|
||||
clearConfigInfo() {
|
||||
this.systemConfig = {};
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { getCurrentUserInfo } from "@/api/system/user";
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: () => ({
|
||||
basicInfo: {},
|
||||
routeList: [],
|
||||
hasGetRoute: false,
|
||||
}),
|
||||
actions: {
|
||||
async getUserInfo() {
|
||||
try {
|
||||
const response = await getCurrentUserInfo();
|
||||
const result = response.data;
|
||||
const routers = result.data.menus;
|
||||
delete result.data.menus;
|
||||
this.setRoute(routers);
|
||||
this.basicInfo = Object.assign(this.basicInfo || {}, result.data);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
setRoute(routers) {
|
||||
this.routeList = routers;
|
||||
this.hasGetRoute = true;
|
||||
},
|
||||
setAvatar(avatar) {
|
||||
this.basicInfo.avatar = avatar;
|
||||
},
|
||||
clearUserInfo() {
|
||||
this.basicInfo = {};
|
||||
this.routeList = [];
|
||||
this.hasGetRoute = false;
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -81,12 +81,13 @@ const pageSize = ref(10);
|
||||
|
||||
const queryState = ref<QueryState>({
|
||||
ipaddr: undefined,
|
||||
user_name: undefined
|
||||
name: undefined
|
||||
});
|
||||
|
||||
const columns = [
|
||||
{ title: '会话编号', dataIndex: 'session_id', key: 'sessionId', ellipsis: true },
|
||||
{ title: '登录名称', dataIndex: 'user_name', key: 'userName', align: 'center', ellipsis: true },
|
||||
{ title: '登录名称', dataIndex: 'name', key: 'name', align: 'center', ellipsis: true },
|
||||
{ title: '用户账号', dataIndex: 'user_name', key: 'userName', align: 'center', ellipsis: true },
|
||||
{ title: '主机', dataIndex: 'ipaddr', key: 'ipaddr', align: 'center', ellipsis: true },
|
||||
{ title: '登录地点', dataIndex: 'login_location', key: 'loginLocation', align: 'center', ellipsis: true },
|
||||
{ title: '操作系统', dataIndex: 'os', key: 'os', align: 'center', ellipsis: true },
|
||||
@@ -146,7 +147,7 @@ const handleForceLogout = (row: OnlineUser) => {
|
||||
content: `是否确认强退名称为"${row.user_name}"的用户?`,
|
||||
async onOk() {
|
||||
try {
|
||||
await deleteOnline(row.session_id);
|
||||
await deleteOnline(row.user_name);
|
||||
await getList();
|
||||
message.success('强退成功');
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
export interface QueryState {
|
||||
ipaddr?: string;
|
||||
user_name?: string;
|
||||
name?: string;
|
||||
login_location?: string;
|
||||
}
|
||||
|
||||
export interface OnlineUser {
|
||||
session_id: string;
|
||||
user_id: number;
|
||||
name: string;
|
||||
user_name: string;
|
||||
ipaddr: string;
|
||||
login_location: string;
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
:rowKey="record => record.id"
|
||||
:tree-data="deptTreeData"
|
||||
:defaultExpandAll="true"
|
||||
:scroll="{ y: 1000 }"
|
||||
:field-names="{ children: 'children', title: 'name', key: 'id' }"
|
||||
@check="deptTreeCheck" checkable checkStrictly style="margin-top: 15px;" />
|
||||
</div>
|
||||
@@ -60,7 +61,7 @@
|
||||
:data-source="menuTreeData"
|
||||
:row-selection="menuRowSelection"
|
||||
:loading="tableLoading"
|
||||
:scroll="{ x: 500 }"
|
||||
:scroll="{ y: 1000 }"
|
||||
:pagination="false"
|
||||
:style="{ minHeight: '700px' }"
|
||||
:expandAll="true">
|
||||
|
||||
Reference in New Issue
Block a user