Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
7f9899f7
authored
Jun 10, 2023
by
stakeswky
Committed by
GitHub
Jun 10, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加dashboard (#83)
* 后台 * 添加主界面 * 添加主界面 * Update server.js * 修复bug * 修复bug
parent
eef6d751
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
177 additions
and
2 deletions
+177
-2
admin/service/route/user.js
+13
-0
admin/src/App.tsx
+1
-1
admin/src/Dashboard.tsx
+159
-0
admin/src/fields.ts
+4
-1
No files found.
admin/service/route/user.js
View file @
7f9899f7
import
{
User
,
Pay
}
from
'../schema.js'
;
import
{
User
,
Pay
}
from
'../schema.js'
;
import
dayjs
from
'dayjs'
;
import
dayjs
from
'dayjs'
;
import
{
auth
}
from
'./system.js'
;
import
{
auth
}
from
'./system.js'
;
import
crypto
from
'crypto'
;
// 加密
const
hashPassword
=
(
psw
)
=>
{
return
crypto
.
createHash
(
'sha256'
).
update
(
psw
).
digest
(
'hex'
);
};
export
const
useUserRoute
=
(
app
)
=>
{
export
const
useUserRoute
=
(
app
)
=>
{
// 获取用户列表
// 获取用户列表
...
@@ -83,6 +89,13 @@ export const useUserRoute = (app) => {
...
@@ -83,6 +89,13 @@ export const useUserRoute = (app) => {
try
{
try
{
const
_id
=
req
.
params
.
id
;
const
_id
=
req
.
params
.
id
;
// Check if a new password is provided in the request body
if
(
req
.
body
.
password
)
{
// Hash the new password
const
hashedPassword
=
hashPassword
(
req
.
body
.
password
);
req
.
body
.
password
=
hashedPassword
;
}
const
result
=
await
User
.
updateOne
({
_id
:
_id
},
{
$set
:
req
.
body
});
const
result
=
await
User
.
updateOne
({
_id
:
_id
},
{
$set
:
req
.
body
});
res
.
json
(
result
);
res
.
json
(
result
);
}
catch
(
err
)
{
}
catch
(
err
)
{
...
...
admin/src/App.tsx
View file @
7f9899f7
...
@@ -46,7 +46,7 @@ function App() {
...
@@ -46,7 +46,7 @@ function App() {
})
})
]
}
]
}
fields=
{
userFields
}
fields=
{
userFields
}
action=
{
{
create
:
true
,
detail
:
true
,
edit
:
true
}
}
action=
{
{
detail
:
true
,
edit
:
true
}
}
/>
/>
}
}
/>
/>
...
...
admin/src/Dashboard.tsx
0 → 100644
View file @
7f9899f7
import
{
Card
,
Link
,
Space
,
Grid
,
Divider
,
Typography
,
}
from
'@arco-design/web-react'
;
import
{
IconApps
,
IconUser
,
IconUserGroup
}
from
'tushan/icon'
;
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
{
useTranslation
}
from
'react-i18next'
;
export
const
Dashboard
:
React
.
FC
=
React
.
memo
(()
=>
{
const
[
userCount
,
setUserCount
]
=
useState
(
0
);
//用户数量
const
[
kbCount
,
setkbCount
]
=
useState
(
0
);
const
[
modelCount
,
setmodelCount
]
=
useState
(
0
);
useEffect
(()
=>
{
const
fetchCounts
=
async
()
=>
{
const
userResponse
=
await
fetch
(
'http://localhost:3001/users'
,
{
headers
:
{
'Content-Type'
:
'application/json'
},
});
const
kbResponse
=
await
fetch
(
'http://localhost:3001/kbs'
,
{
headers
:
{
'Content-Type'
:
'application/json'
},
});
const
modelResponse
=
await
fetch
(
'http://localhost:3001/models'
,
{
headers
:
{
'Content-Type'
:
'application/json'
},
});
const
userTotalCount
=
userResponse
.
headers
.
get
(
'X-Total-Count'
);
const
kbTotalCount
=
kbResponse
.
headers
.
get
(
'X-Total-Count'
);
const
modelTotalCount
=
modelResponse
.
headers
.
get
(
'X-Total-Count'
);
if
(
userTotalCount
)
{
setUserCount
(
Number
(
userTotalCount
));
}
if
(
kbTotalCount
)
{
setkbCount
(
Number
(
kbTotalCount
));
}
if
(
modelTotalCount
)
{
setmodelCount
(
Number
(
modelTotalCount
));
}
};
fetchCounts
();
},
[]);
return
(
<
div
>
<
div
>
<
Space
direction=
"vertical"
style=
{
{
width
:
'100%'
}
}
>
<
Card
bordered=
{
false
}
>
<
Typography
.
Title
heading=
{
5
}
>
{
'你好,管理员'
}
</
Typography
.
Title
>
<
Divider
/>
<
Grid
.
Row
justify=
"center"
>
<
Grid
.
Col
flex=
{
1
}
style=
{
{
paddingLeft
:
'1rem'
}
}
>
{
/* 把 userCount 传递给 DataItem 组件 */
}
<
DataItem
icon=
{
<
IconUser
/>
}
title=
{
'用户'
}
count=
{
userCount
}
/>
</
Grid
.
Col
>
<
Divider
type=
"vertical"
style=
{
{
height
:
40
}
}
/>
<
Grid
.
Col
flex=
{
1
}
style=
{
{
paddingLeft
:
'1rem'
}
}
>
<
DataItem
icon=
{
<
IconUserGroup
/>
}
title=
{
'知识库'
}
count=
{
kbCount
}
/>
</
Grid
.
Col
>
<
Divider
type=
"vertical"
style=
{
{
height
:
40
}
}
/>
<
Grid
.
Col
flex=
{
1
}
style=
{
{
paddingLeft
:
'1rem'
}
}
>
<
DataItem
icon=
{
<
IconApps
/>
}
title=
{
'AI模型'
}
count=
{
modelCount
}
/>
</
Grid
.
Col
>
</
Grid
.
Row
>
<
Divider
/>
</
Card
>
</
Space
>
</
div
>
</
div
>
);
});
Dashboard
.
displayName
=
'Dashboard'
;
const
DashboardItem
:
React
.
FC
<
React
.
PropsWithChildren
<
{
title
:
string
;
href
?:
string
;
}
>
>
=
React
.
memo
((
props
)
=>
{
const
{
t
}
=
useTranslation
();
return
(
<
Card
title=
{
props
.
title
}
extra=
{
props
.
href
&&
(
<
Link
target=
"_blank"
href=
{
props
.
href
}
>
{
t
(
'tushan.dashboard.more'
)
}
</
Link
>
)
}
bordered=
{
false
}
style=
{
{
overflow
:
'hidden'
}
}
>
{
props
.
children
}
</
Card
>
);
});
DashboardItem
.
displayName
=
'DashboardItem'
;
const
DataItem
:
React
.
FC
<
{
icon
:
React
.
ReactElement
;
title
:
string
;
count
:
number
;
}
>
=
React
.
memo
((
props
)
=>
{
return
(
<
Space
>
<
div
style=
{
{
fontSize
:
20
,
padding
:
'0.5rem'
,
borderRadius
:
'9999px'
,
border
:
'1px solid #ccc'
,
width
:
24
,
height
:
24
,
display
:
'flex'
,
justifyContent
:
'center'
,
alignItems
:
'center'
,
}
}
>
{
props
.
icon
}
</
div
>
<
div
>
<
div
style=
{
{
fontWeight
:
700
}
}
>
{
props
.
title
}
</
div
>
<
div
>
{
props
.
count
}
</
div
>
</
div
>
</
Space
>
);
});
DataItem
.
displayName
=
'DataItem'
;
admin/src/fields.ts
View file @
7f9899f7
import
{
createTextField
,
createNumberField
}
from
'tushan'
;
import
{
createTextField
,
createNumberField
,
}
from
'tushan'
;
export
const
userFields
=
[
export
const
userFields
=
[
createTextField
(
'id'
,
{
label
:
'ID'
}),
createTextField
(
'id'
,
{
label
:
'ID'
}),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment