mirror of
https://github.com/fumiama/paper-manager.git
synced 2026-06-05 16:00:25 +08:00
finish page/settings
This commit is contained in:
@@ -144,6 +144,39 @@ func init() {
|
||||
}
|
||||
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
|
||||
|
||||
@@ -4,11 +4,13 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
base14 "github.com/fumiama/go-base16384"
|
||||
"github.com/fumiama/paper-manager/backend/global"
|
||||
"github.com/fumiama/paper-manager/backend/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -114,3 +116,33 @@ func setUserContact(id int, token, ncont string) error {
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Set UserInfo interface parameters
|
||||
*/
|
||||
export interface SetUserInfoParams {
|
||||
nick: string
|
||||
desc: string
|
||||
avtr: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: Register interface parameters
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
ResetPasswordParams,
|
||||
SetPasswordParams,
|
||||
SetContactParams,
|
||||
SetUserInfoParams,
|
||||
RegisterParams,
|
||||
ResetPasswordResultModel,
|
||||
RegisterResultModel,
|
||||
@@ -21,6 +22,7 @@ enum Api {
|
||||
ResetPassword = '/resetPassword',
|
||||
SetPassword = '/setPassword',
|
||||
SetContact = '/setContact',
|
||||
SetUserInfo = '/setUserInfo',
|
||||
Register = '/register',
|
||||
GetUserInfo = '/getUserInfo',
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
:value="avatarRef"
|
||||
btnText="更换头像"
|
||||
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
|
||||
@change="updateAvatar"
|
||||
width="150"
|
||||
/>
|
||||
</div>
|
||||
@@ -27,13 +26,12 @@
|
||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||
import { CollapseContainer } from '/@/components/Container'
|
||||
import { CropperAvatar } from '/@/components/Cropper'
|
||||
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
|
||||
import headerImg from '/@/assets/images/header.jpg'
|
||||
import { baseSetschemas } from './data'
|
||||
import { useUserStore } from '/@/store/modules/user'
|
||||
import { uploadApi } from '/@/api/sys/upload'
|
||||
import { setUserInfoApi } from '/@/api/sys/user'
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
@@ -45,11 +43,10 @@
|
||||
CropperAvatar,
|
||||
},
|
||||
setup() {
|
||||
const { createMessage } = useMessage()
|
||||
const userStore = useUserStore()
|
||||
const { avatar } = userStore.getUserInfo
|
||||
|
||||
const [register, { setFieldsValue }] = useForm({
|
||||
const [register, { getFieldsValue, setFieldsValue }] = useForm({
|
||||
labelWidth: 120,
|
||||
schemas: baseSetschemas,
|
||||
showActionButtonGroup: false,
|
||||
@@ -62,9 +59,11 @@
|
||||
|
||||
const avatarRef = ref(avatar || headerImg)
|
||||
|
||||
function updateAvatar({ src }) {
|
||||
function updateUserInfo(nick: string, desc: string, avtr: string) {
|
||||
const userinfo = userStore.getUserInfo
|
||||
userinfo.avatar = src
|
||||
userinfo.realName = nick
|
||||
userinfo.desc = desc
|
||||
userinfo.avatar = avtr
|
||||
userStore.setUserInfo(userinfo)
|
||||
}
|
||||
|
||||
@@ -78,18 +77,30 @@
|
||||
},
|
||||
() => {},
|
||||
)
|
||||
avatarRef.value = result.data.url
|
||||
avatarRef.value = (result.data as any).result.url
|
||||
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 {
|
||||
avatarRef,
|
||||
register,
|
||||
onUpload,
|
||||
updateAvatar,
|
||||
handleSubmit: () => {
|
||||
createMessage.success('更新成功!')
|
||||
},
|
||||
handleSubmit,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
import { BasicForm, useForm } from '/@/components/Form'
|
||||
import { setContactApi } from '/@/api/sys/user'
|
||||
import { useMessage } from '/@/hooks/web/useMessage'
|
||||
import { useUserStore } from '/@/store/modules/user'
|
||||
import md5 from 'md5'
|
||||
|
||||
import { formSchema } from './contact.data'
|
||||
@@ -31,6 +32,7 @@
|
||||
})
|
||||
|
||||
const { createMessage } = useMessage()
|
||||
const userStore = useUserStore()
|
||||
|
||||
async function handleSubmit() {
|
||||
try {
|
||||
@@ -41,6 +43,7 @@
|
||||
contact: contactNew,
|
||||
})
|
||||
createMessage.success(msg)
|
||||
userStore.getUserInfoAction()
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user