feat: 用户菜单添加完善信息功能 - 新增 edit_profile.dspy/save_profile.dspy - usermenu.ui 添加完善信息入口 - load_path.py 注册权限路径
This commit is contained in:
parent
26d1fd1447
commit
7f2c3d25dd
@ -96,6 +96,8 @@ PATHS_LOGINED = [
|
|||||||
f"/rbac/user/userapikey/index.ui",
|
f"/rbac/user/userapikey/index.ui",
|
||||||
f"/rbac/user/userapikey/update_userapikey.dspy",
|
f"/rbac/user/userapikey/update_userapikey.dspy",
|
||||||
f"/rbac/user/userinfo.ui",
|
f"/rbac/user/userinfo.ui",
|
||||||
|
f"/rbac/user/edit_profile.dspy",
|
||||||
|
f"/rbac/user/save_profile.dspy",
|
||||||
f"/rbac/user/wechat_login.ui",
|
f"/rbac/user/wechat_login.ui",
|
||||||
f"/rbac/userapp",
|
f"/rbac/userapp",
|
||||||
f"/rbac/userdepartment",
|
f"/rbac/userdepartment",
|
||||||
|
|||||||
90
wwwroot/user/edit_profile.dspy
Normal file
90
wwwroot/user/edit_profile.dspy
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
debug(f'edit_profile.dspy: {params_kw=}')
|
||||||
|
|
||||||
|
userid = await get_user()
|
||||||
|
if userid is None:
|
||||||
|
return UiError(title='Error', message='You need login first')
|
||||||
|
|
||||||
|
db = DBPools()
|
||||||
|
dbname = get_module_dbname('rbac')
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
recs = await sor.R('users', {'id': userid})
|
||||||
|
if not recs:
|
||||||
|
return UiError(title='Error', message='User not found')
|
||||||
|
user = recs[0]
|
||||||
|
nick_name = user.nick_name or ''
|
||||||
|
email = user.email or ''
|
||||||
|
mobile = user.mobile or ''
|
||||||
|
address = user.address or ''
|
||||||
|
|
||||||
|
return {
|
||||||
|
"widgettype": "PopupWindow",
|
||||||
|
"options": {
|
||||||
|
"cwidth": 22,
|
||||||
|
"height": "75%",
|
||||||
|
"archor": "cc",
|
||||||
|
"auto_open": True
|
||||||
|
},
|
||||||
|
"subwidgets": [
|
||||||
|
{
|
||||||
|
"widgettype": "Form",
|
||||||
|
"options": {
|
||||||
|
"title": "完善个人信息",
|
||||||
|
"description": "请填写或更新您的个人信息",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "nick_name",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255,
|
||||||
|
"uitype": "str",
|
||||||
|
"datatype": "str",
|
||||||
|
"required": False,
|
||||||
|
"label": "显示名",
|
||||||
|
"default": nick_name
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "email",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255,
|
||||||
|
"uitype": "email",
|
||||||
|
"datatype": "str",
|
||||||
|
"required": False,
|
||||||
|
"label": "邮件地址",
|
||||||
|
"default": email
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "mobile",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255,
|
||||||
|
"uitype": "tel",
|
||||||
|
"datatype": "str",
|
||||||
|
"required": False,
|
||||||
|
"label": "手机号",
|
||||||
|
"default": mobile
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "address",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255,
|
||||||
|
"uitype": "str",
|
||||||
|
"datatype": "str",
|
||||||
|
"required": False,
|
||||||
|
"label": "地址",
|
||||||
|
"default": address
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"binds": [
|
||||||
|
{
|
||||||
|
"wid": "self",
|
||||||
|
"event": "submit",
|
||||||
|
"actiontype": "urlwidget",
|
||||||
|
"target": "self",
|
||||||
|
"options": {
|
||||||
|
"method": "POST",
|
||||||
|
"url": entire_url('save_profile.dspy')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
40
wwwroot/user/save_profile.dspy
Normal file
40
wwwroot/user/save_profile.dspy
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
debug(f'save_profile.dspy: {params_kw=}')
|
||||||
|
|
||||||
|
userid = await get_user()
|
||||||
|
if userid is None:
|
||||||
|
return UiError(title='Error', message='You need login first')
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'id': userid,
|
||||||
|
'nick_name': params_kw.nick_name or '',
|
||||||
|
'email': params_kw.email or '',
|
||||||
|
'mobile': params_kw.mobile or '',
|
||||||
|
'address': params_kw.address or ''
|
||||||
|
}
|
||||||
|
|
||||||
|
db = DBPools()
|
||||||
|
dbname = get_module_dbname('rbac')
|
||||||
|
try:
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
await sor.U('users', data)
|
||||||
|
return {
|
||||||
|
"widgettype": "Message",
|
||||||
|
"options": {
|
||||||
|
"timeout": 3,
|
||||||
|
"auto_open": True,
|
||||||
|
"title": "保存成功",
|
||||||
|
"message": "个人信息已更新"
|
||||||
|
},
|
||||||
|
"binds": [
|
||||||
|
{
|
||||||
|
"wid": "self",
|
||||||
|
"event": "dismissed",
|
||||||
|
"actiontype": "script",
|
||||||
|
"target": "self",
|
||||||
|
"script": "if(bricks.app && bricks.app.dispatch) bricks.app.dispatch('profile_updated')"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
except Exception as e:
|
||||||
|
exception(f'save_profile error: {e}')
|
||||||
|
return UiError(title='Error', message=f'保存失败: {e}')
|
||||||
@ -32,6 +32,11 @@
|
|||||||
"label":"我的角色",
|
"label":"我的角色",
|
||||||
"url":"{{entire_url('user/myrole.ui')}}"
|
"url":"{{entire_url('user/myrole.ui')}}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name":"editprofile",
|
||||||
|
"label":"完善信息",
|
||||||
|
"url":"{{entire_url('user/edit_profile.dspy')}}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name":"logout",
|
"name":"logout",
|
||||||
"label":"签退",
|
"label":"签退",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user