Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chatGLM
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘坚-丰林-DEV
chatGLM
Commits
6816cd67
Commit
6816cd67
authored
Apr 16, 2023
by
littleforest
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add API
parent
a95cf7e2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
195 additions
and
15 deletions
+195
-15
.gitignore
.gitignore
+1
-0
index.tsx
src/pages/UserManage/index.tsx
+172
-15
api.ts
src/services/chatGLM/api.ts
+22
-0
No files found.
.gitignore
View file @
6816cd67
...
...
@@ -38,3 +38,4 @@ screenshot
.eslintcache
build
node_modules
src/pages/UserManage/index.tsx
View file @
6816cd67
import
{
CreatedAccount
,
getRole
,
getUserMessage
}
from
'@/services/chatGLM/api'
;
import
{
PlusOutlined
}
from
'@ant-design/icons'
;
import
type
{
ActionType
}
from
'@ant-design/pro-components'
;
import
{
PageContainer
}
from
'@ant-design/pro-components'
;
import
{
ProTable
}
from
'@ant-design/pro-components'
;
import
{
Button
}
from
'antd'
;
import
{
useRef
}
from
'react'
;
import
{
Button
,
Col
,
Divider
,
Form
,
Input
,
Modal
,
Radio
,
Row
,
Switch
,
message
}
from
'antd'
;
import
{
isEmpty
}
from
'lodash'
;
import
{
useRef
,
useState
}
from
'react'
;
import
request
from
'umi-request'
;
const
{
Item
}
=
Form
;
const
columns
:
any
[]
=
[
{
title
:
'用户'
,
...
...
@@ -65,29 +69,180 @@ const columns: any[] = [
const
UserManage
=
()
=>
{
const
actionRef
=
useRef
<
ActionType
>
();
const
[
isModalOpen
,
setIsModalOpen
]
=
useState
(
false
);
const
[
accountForm
]
=
useState
({
id
:
''
,
Name
:
''
,
Phone
:
''
,
Role
:
''
,
IsActive
:
true
,
Password
:
''
,
});
const
[
roles
,
setRoles
]
=
useState
([]);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
accountModalName
,
setAccountModalName
]
=
useState
(
'新建账号'
);
const
[
form
]
=
Form
.
useForm
();
const
layout
=
{
labelCol
:
{
span
:
4
},
wrapperCol
:
{
span
:
18
},
};
const
showModal
=
()
=>
{
getRole
()
.
then
((
res
)
=>
{
console
.
log
(
res
);
if
(
!
isEmpty
(
res
))
{
setRoles
(
res
);
setIsModalOpen
(
true
);
}
})
.
catch
((
err
)
=>
{
message
.
error
(
'获取用户权限失败,请重试'
);
});
};
const
handleOk
=
()
=>
{
setIsModalOpen
(
false
);
};
const
handleModalCancel
=
()
=>
{
form
.
resetFields
();
setIsModalOpen
(
false
);
};
const
createdAccount
=
(
values
:
any
)
=>
{
setLoading
(
true
);
const
data
=
{
role
:
values
.
roles
,
Phone
:
values
.
phoneNumber
,
Password
:
values
,
};
CreatedAccount
(
values
)
.
then
((
res
)
=>
{
setLoading
(
false
);
})
.
catch
((
error
)
=>
{
setLoading
(
false
);
});
};
const
onHandleClickAccountFinish
=
(
values
:
any
)
=>
{
if
(
accountModalName
===
'添加账号'
)
{
createdAccount
(
values
);
}
};
const
onHandleClickAccountChange
=
(
values
:
any
)
=>
{
console
.
log
(
values
);
};
const
validatePhoneNumber
=
(
_
,
value
:
any
)
=>
{
const
phoneNumberRegex
=
/^1
[
3456789
]\d{9}
$/
;
if
(
!
value
||
phoneNumberRegex
.
test
(
value
))
{
return
Promise
.
resolve
();
}
return
Promise
.
reject
(
new
Error
(
'请输入有效的手机号码!'
));
};
const
validatePassword
=
(
_
,
value
:
any
)
=>
{
const
letterNumberRegex
=
/^
(?=
.*
[
0-9
])(?=
.*
[
a-zA-Z
])(?=
.*
[^
0-9a-zA-Z
])([
a-zA-Z0-9
\S]
+
)
$/
;
const
lowercaseRegex
=
/
[
a-z
]
/
;
const
uppercaseRegex
=
/
[
A-Z
]
/
;
const
specialCharacterRegex
=
/
[^
0-9a-zA-Z
]
/
;
if
(
letterNumberRegex
.
test
(
value
)
&&
lowercaseRegex
.
test
(
value
)
&&
uppercaseRegex
.
test
(
value
)
&&
specialCharacterRegex
.
test
(
value
)
)
{
return
Promise
.
resolve
();
}
return
Promise
.
reject
(
new
Error
(
'密码格式不正确!'
));
};
return
(
<
PageContainer
>
<
Modal
title=
{
`${accountModalName}`
}
open=
{
isModalOpen
}
onOk=
{
handleOk
}
onCancel=
{
handleModalCancel
}
footer=
{
null
}
maskClosable=
{
false
}
>
<
Form
{
...
layout
}
form=
{
form
}
onFinish=
{
onHandleClickAccountFinish
}
onValuesChange=
{
onHandleClickAccountChange
}
labelAlign=
"right"
name=
"accountSetting"
initialValues=
{
accountForm
}
>
<
Item
name=
{
'Phone'
}
label=
"用户账号"
rules=
{
[
{
required
:
true
,
message
:
'请输入手机号!'
},
{
validator
:
validatePhoneNumber
},
]
}
>
<
Input
/>
</
Item
>
<
Item
name=
{
'Password'
}
label=
"密码"
rules=
{
[{
required
:
true
,
message
:
'请输入密码!'
},
{
validator
:
validatePassword
}]
}
>
<
Input
/>
</
Item
>
<
Item
name=
{
'Role'
}
label=
"角色"
rules=
{
[{
required
:
true
,
message
:
'请设置你的角色'
}]
}
>
<
Radio
.
Group
>
{
roles
.
map
((
item
)
=>
{
return
(
<
Radio
key=
{
item
}
value=
{
`${item}`
}
>
{
item
}
</
Radio
>
);
})
}
</
Radio
.
Group
>
</
Item
>
<
Item
name=
{
'Name'
}
label=
"姓名"
rules=
{
[{
required
:
true
,
message
:
'请输入你的姓名'
}]
}
>
<
Input
placeholder=
"请输入(必填)"
/>
</
Item
>
<
Item
name=
{
'isActive'
}
label=
"是否启用"
>
<
Switch
/>
</
Item
>
<
Divider
/>
<
Row
justify=
{
'end'
}
gutter=
{
8
}
>
<
Col
>
<
Item
key=
{
'cancelButton'
}
noStyle=
{
true
}
>
<
Button
key=
"back"
onClick=
{
handleModalCancel
}
>
取消
</
Button
>
</
Item
>
</
Col
>
<
Col
>
<
Item
key=
{
'saveButton'
}
noStyle=
{
true
}
>
<
Button
key=
"submit"
type=
"primary"
loading=
{
loading
}
htmlType=
"submit"
>
保存
</
Button
>
</
Item
>
</
Col
>
</
Row
>
</
Form
>
</
Modal
>
<
ProTable
columns=
{
columns
}
actionRef=
{
actionRef
}
cardBordered
request=
{
async
(
params
=
{},
sort
,
filter
)
=>
{
const
defaultParams
=
{
n
ame
:
''
,
Enabled
:
false
,
PageSize
:
9
,
N
ame
:
''
,
Enabled
:
null
,
PageSize
:
10
,
PageIndex
:
1
,
};
return
request
<
{
data
:
any
[];
}
>
(
'https://glm-mangement-api.baibaomen.com/User/page'
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
,
__tenant
:
'3a0a90fe-9a0d-70f4-200d-a80a41fb6195'
,
},
data
:
defaultParams
,
});
return
getUserMessage
(
defaultParams
);
}
}
rowKey=
"id"
pagination=
{
{
...
...
@@ -102,6 +257,8 @@ const UserManage = () => {
key=
"button"
icon=
{
<
PlusOutlined
/>
}
onClick=
{
()
=>
{
setAccountModalName
(
'添加账号'
);
showModal
();
actionRef
.
current
?.
reload
();
}
}
type=
"primary"
...
...
src/services/chatGLM/api.ts
View file @
6816cd67
...
...
@@ -46,3 +46,25 @@ export function GetChatGLMToken(): Promise<string> {
method
:
'POST'
,
});
}
export
const
CreatedAccount
=
(
params
:
any
):
Promise
<
string
>
=>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/User/create'
,
{
method
:
'POST'
,
params
});
}
export
const
getRole
=
(
params
?:
any
):
Promise
<
string
>
=>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/User/roles'
,
{
method
:
'POST'
,
params
})
}
export
const
getUserMessage
=
(
params
?:
any
):
Promise
<
string
>
=>
{
return
request
(
'https://glm-mangement-api.baibaomen.com/User/page'
,
{
method
:
'POST'
,
data
:
params
});
}
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