mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-11 11:40:23 +08:00
finish page/settings
This commit is contained in:
@@ -144,6 +144,39 @@ func init() {
|
|||||||
}
|
}
|
||||||
writeresult(w, codeSuccess, &message{M: "成功, 已将消息报告给课程组长"}, messageOk, typeSuccess)
|
writeresult(w, codeSuccess, &message{M: "成功, 已将消息报告给课程组长"}, messageOk, typeSuccess)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
apimap["/api/setUserInfo"] = &apihandler{"POST", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
type setuserinfobody struct {
|
||||||
|
Nick string `json:"nick"`
|
||||||
|
Desc string `json:"desc"`
|
||||||
|
Avtr string `json:"avtr"`
|
||||||
|
}
|
||||||
|
token := r.Header.Get("Authorization")
|
||||||
|
user := usertokens.Get(token)
|
||||||
|
if user == nil {
|
||||||
|
writeresult(w, codeError, nil, errInvalidToken.Error(), typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body setuserinfobody
|
||||||
|
defer r.Body.Close()
|
||||||
|
err := json.NewDecoder(r.Body).Decode(&body)
|
||||||
|
if err != nil {
|
||||||
|
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = setUserInfo(*user.ID, &body.Nick, &body.Desc, &body.Avtr)
|
||||||
|
if err != nil {
|
||||||
|
writeresult(w, codeError, nil, err.Error(), typeError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
user.Nick = body.Nick
|
||||||
|
user.Desc = body.Desc
|
||||||
|
user.Avtr = body.Avtr
|
||||||
|
type message struct {
|
||||||
|
M string `json:"msg"`
|
||||||
|
}
|
||||||
|
writeresult(w, codeSuccess, &message{M: "成功"}, messageOk, typeSuccess)
|
||||||
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler serves all backend /api call
|
// Handler serves all backend /api call
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
base14 "github.com/fumiama/go-base16384"
|
base14 "github.com/fumiama/go-base16384"
|
||||||
"github.com/fumiama/paper-manager/backend/global"
|
"github.com/fumiama/paper-manager/backend/global"
|
||||||
|
"github.com/fumiama/paper-manager/backend/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -114,3 +116,33 @@ func setUserContact(id int, token, ncont string) error {
|
|||||||
}
|
}
|
||||||
return global.UserDB.UpdateUserContact(id, ncont)
|
return global.UserDB.UpdateUserContact(id, ncont)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setUserInfo may change the arguments
|
||||||
|
func setUserInfo(id int, nick, desc, avtr *string) error {
|
||||||
|
user, err := global.UserDB.GetUserByID(id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
n, d, a := *nick, *desc, *avtr
|
||||||
|
if n == "" {
|
||||||
|
*nick = user.Nick
|
||||||
|
}
|
||||||
|
if n == user.Nick {
|
||||||
|
n = ""
|
||||||
|
}
|
||||||
|
if d == "" {
|
||||||
|
*desc = user.Desc
|
||||||
|
}
|
||||||
|
if d == user.Desc {
|
||||||
|
d = ""
|
||||||
|
}
|
||||||
|
if a == "" {
|
||||||
|
*avtr = user.Avtr
|
||||||
|
} else if utils.IsNotExist(global.DataFolder + a) {
|
||||||
|
return os.ErrNotExist
|
||||||
|
}
|
||||||
|
if a == user.Avtr {
|
||||||
|
a = ""
|
||||||
|
}
|
||||||
|
return global.UserDB.UpdateUserInfo(id, n, d, a)
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ export interface SetContactParams {
|
|||||||
contact: string
|
contact: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Set UserInfo interface parameters
|
||||||
|
*/
|
||||||
|
export interface SetUserInfoParams {
|
||||||
|
nick: string
|
||||||
|
desc: string
|
||||||
|
avtr: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: Register interface parameters
|
* @description: Register interface parameters
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
ResetPasswordParams,
|
ResetPasswordParams,
|
||||||
SetPasswordParams,
|
SetPasswordParams,
|
||||||
SetContactParams,
|
SetContactParams,
|
||||||
|
SetUserInfoParams,
|
||||||
RegisterParams,
|
RegisterParams,
|
||||||
ResetPasswordResultModel,
|
ResetPasswordResultModel,
|
||||||
RegisterResultModel,
|
RegisterResultModel,
|
||||||
@@ -21,6 +22,7 @@ enum Api {
|
|||||||
ResetPassword = '/resetPassword',
|
ResetPassword = '/resetPassword',
|
||||||
SetPassword = '/setPassword',
|
SetPassword = '/setPassword',
|
||||||
SetContact = '/setContact',
|
SetContact = '/setContact',
|
||||||
|
SetUserInfo = '/setUserInfo',
|
||||||
Register = '/register',
|
Register = '/register',
|
||||||
GetUserInfo = '/getUserInfo',
|
GetUserInfo = '/getUserInfo',
|
||||||
GetUsersCount = '/getUsersCount',
|
GetUsersCount = '/getUsersCount',
|
||||||
@@ -88,6 +90,21 @@ export function setContactApi(params: SetContactParams, mode: ErrorMessageMode =
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: set userinfo api, borrowing the ResetPasswordResultModel as they're the same
|
||||||
|
*/
|
||||||
|
export function setUserInfoApi(params: SetUserInfoParams, mode: ErrorMessageMode = 'modal') {
|
||||||
|
return defHttp.post<ResetPasswordResultModel>(
|
||||||
|
{
|
||||||
|
url: Api.SetUserInfo,
|
||||||
|
params,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
errorMessageMode: mode,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: register api
|
* @description: register api
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -12,7 +12,6 @@
|
|||||||
:value="avatarRef"
|
:value="avatarRef"
|
||||||
btnText="更换头像"
|
btnText="更换头像"
|
||||||
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
|
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
|
||||||
@change="updateAvatar"
|
|
||||||
width="150"
|
width="150"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -27,13 +26,12 @@
|
|||||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||||
import { CollapseContainer } from '/@/components/Container'
|
import { CollapseContainer } from '/@/components/Container'
|
||||||
import { CropperAvatar } from '/@/components/Cropper'
|
import { CropperAvatar } from '/@/components/Cropper'
|
||||||
|
|
||||||
import { useMessage } from '/@/hooks/web/useMessage'
|
import { useMessage } from '/@/hooks/web/useMessage'
|
||||||
|
|
||||||
import headerImg from '/@/assets/images/header.jpg'
|
import headerImg from '/@/assets/images/header.jpg'
|
||||||
import { baseSetschemas } from './data'
|
import { baseSetschemas } from './data'
|
||||||
import { useUserStore } from '/@/store/modules/user'
|
import { useUserStore } from '/@/store/modules/user'
|
||||||
import { uploadApi } from '/@/api/sys/upload'
|
import { uploadApi } from '/@/api/sys/upload'
|
||||||
|
import { setUserInfoApi } from '/@/api/sys/user'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@@ -45,11 +43,10 @@
|
|||||||
CropperAvatar,
|
CropperAvatar,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const { createMessage } = useMessage()
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const { avatar } = userStore.getUserInfo
|
const { avatar } = userStore.getUserInfo
|
||||||
|
|
||||||
const [register, { setFieldsValue }] = useForm({
|
const [register, { getFieldsValue, setFieldsValue }] = useForm({
|
||||||
labelWidth: 120,
|
labelWidth: 120,
|
||||||
schemas: baseSetschemas,
|
schemas: baseSetschemas,
|
||||||
showActionButtonGroup: false,
|
showActionButtonGroup: false,
|
||||||
@@ -62,9 +59,11 @@
|
|||||||
|
|
||||||
const avatarRef = ref(avatar || headerImg)
|
const avatarRef = ref(avatar || headerImg)
|
||||||
|
|
||||||
function updateAvatar({ src }) {
|
function updateUserInfo(nick: string, desc: string, avtr: string) {
|
||||||
const userinfo = userStore.getUserInfo
|
const userinfo = userStore.getUserInfo
|
||||||
userinfo.avatar = src
|
userinfo.realName = nick
|
||||||
|
userinfo.desc = desc
|
||||||
|
userinfo.avatar = avtr
|
||||||
userStore.setUserInfo(userinfo)
|
userStore.setUserInfo(userinfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,18 +77,30 @@
|
|||||||
},
|
},
|
||||||
() => {},
|
() => {},
|
||||||
)
|
)
|
||||||
avatarRef.value = result.data.url
|
avatarRef.value = (result.data as any).result.url
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { createMessage } = useMessage()
|
||||||
|
|
||||||
|
function handleSubmit() {
|
||||||
|
const { realName, desc } = getFieldsValue()
|
||||||
|
setUserInfoApi({
|
||||||
|
nick: realName,
|
||||||
|
desc: desc,
|
||||||
|
avtr: avatarRef.value,
|
||||||
|
}).then((value) => {
|
||||||
|
if (avatarRef.value && avatarRef.value != headerImg)
|
||||||
|
updateUserInfo(realName, desc, avatarRef.value)
|
||||||
|
createMessage.success(value.msg)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
avatarRef,
|
avatarRef,
|
||||||
register,
|
register,
|
||||||
onUpload,
|
onUpload,
|
||||||
updateAvatar,
|
handleSubmit,
|
||||||
handleSubmit: () => {
|
|
||||||
createMessage.success('更新成功!')
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
import { BasicForm, useForm } from '/@/components/Form'
|
import { BasicForm, useForm } from '/@/components/Form'
|
||||||
import { setContactApi } from '/@/api/sys/user'
|
import { setContactApi } from '/@/api/sys/user'
|
||||||
import { useMessage } from '/@/hooks/web/useMessage'
|
import { useMessage } from '/@/hooks/web/useMessage'
|
||||||
|
import { useUserStore } from '/@/store/modules/user'
|
||||||
import md5 from 'md5'
|
import md5 from 'md5'
|
||||||
|
|
||||||
import { formSchema } from './contact.data'
|
import { formSchema } from './contact.data'
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
})
|
})
|
||||||
|
|
||||||
const { createMessage } = useMessage()
|
const { createMessage } = useMessage()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
try {
|
try {
|
||||||
@@ -41,6 +43,7 @@
|
|||||||
contact: contactNew,
|
contact: contactNew,
|
||||||
})
|
})
|
||||||
createMessage.success(msg)
|
createMessage.success(msg)
|
||||||
|
userStore.getUserInfoAction()
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user