完成设置界面全部内容
This commit is contained in:
parent
600efd92c3
commit
daeb8701f4
@ -2,11 +2,13 @@ package com.example.controller;
|
||||
|
||||
import com.example.entity.RestBean;
|
||||
import com.example.entity.user.AccountInfo;
|
||||
import com.example.entity.user.AccountPrivacy;
|
||||
import com.example.entity.user.AccountUser;
|
||||
import com.example.service.UserService;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -68,4 +70,17 @@ public class UserController {
|
||||
return RestBean.failure(400, "原密码错误");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/save-privacy")
|
||||
public RestBean<Void> savePrivacy(@RequestBody AccountPrivacy privacy,
|
||||
@SessionAttribute("account") AccountUser user){
|
||||
privacy.setUid(user.getId());
|
||||
service.saveUserPrivacy(privacy);
|
||||
return RestBean.success();
|
||||
}
|
||||
|
||||
@GetMapping("/privacy")
|
||||
public RestBean<AccountPrivacy> privacy(@SessionAttribute("account") AccountUser user){
|
||||
return RestBean.success(service.userPrivacy(user.getId()));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package com.example.entity.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AccountPrivacy {
|
||||
int uid;
|
||||
boolean email;
|
||||
boolean sex;
|
||||
boolean phone;
|
||||
boolean qq;
|
||||
boolean wx;
|
||||
boolean blog;
|
||||
}
|
@ -2,6 +2,7 @@ package com.example.mapper;
|
||||
|
||||
import com.example.entity.auth.Account;
|
||||
import com.example.entity.user.AccountInfo;
|
||||
import com.example.entity.user.AccountPrivacy;
|
||||
import com.example.entity.user.AccountUser;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -44,4 +45,15 @@ public interface UserMapper {
|
||||
|
||||
@Update("update db_account set password=#{password} where id=#{uid}")
|
||||
void updatePassword(String password, int uid);
|
||||
|
||||
@Insert("""
|
||||
insert into db_account_privacy (uid, email, sex, phone, qq, wx, blog)
|
||||
values (#{uid}, #{email}, #{sex}, #{phone}, #{qq}, #{wx}, #{blog})
|
||||
on duplicate key update uid=#{uid}, email=#{email}, sex=#{sex},
|
||||
phone=#{phone}, wx=#{wx}, qq=#{qq}, blog=#{blog}
|
||||
""")
|
||||
void savePrivacy(AccountPrivacy privacy);
|
||||
|
||||
@Select("select * from db_account_privacy where uid = #{uid}")
|
||||
AccountPrivacy findPrivacyById(int uid);
|
||||
}
|
||||
|
@ -1,10 +1,13 @@
|
||||
package com.example.service;
|
||||
|
||||
import com.example.entity.user.AccountInfo;
|
||||
import com.example.entity.user.AccountPrivacy;
|
||||
|
||||
public interface UserService {
|
||||
boolean saveUserInfo(AccountInfo info);
|
||||
AccountInfo userInfo(int uid);
|
||||
boolean saveEmail(String email, int uid);
|
||||
boolean changePassword(String old, String _new, int uid);
|
||||
void saveUserPrivacy(AccountPrivacy privacy);
|
||||
AccountPrivacy userPrivacy(int uid);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.example.service.impl;
|
||||
|
||||
import com.example.entity.auth.Account;
|
||||
import com.example.entity.user.AccountInfo;
|
||||
import com.example.entity.user.AccountPrivacy;
|
||||
import com.example.mapper.UserMapper;
|
||||
import com.example.service.UserService;
|
||||
import jakarta.annotation.Resource;
|
||||
@ -52,4 +53,14 @@ public class UserServiceImpl implements UserService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveUserPrivacy(AccountPrivacy privacy) {
|
||||
mapper.savePrivacy(privacy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AccountPrivacy userPrivacy(int uid) {
|
||||
return mapper.findPrivacyById(uid);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
<script setup>
|
||||
import {onMounted, reactive, ref} from "vue";
|
||||
import {Select} from "@element-plus/icons-vue";
|
||||
import {get, post} from "@/net";
|
||||
import {get, me, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {useStore} from "@/stores";
|
||||
|
||||
const form = ref()
|
||||
|
||||
@ -70,6 +71,7 @@ const save = () => {
|
||||
form.value.validate((isValid) => {
|
||||
if(isValid) {
|
||||
post('/api/user/save-info', infoForm, () => {
|
||||
me()
|
||||
ElMessage.success("保存成功!")
|
||||
}, 'json')
|
||||
} else {
|
||||
|
@ -1,6 +1,8 @@
|
||||
<script setup>
|
||||
import {Message, Select} from "@element-plus/icons-vue";
|
||||
import {reactive} from "vue";
|
||||
import {onMounted, reactive} from "vue";
|
||||
import {get, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
|
||||
const privacyForm = reactive({
|
||||
email: false,
|
||||
@ -10,6 +12,22 @@ const privacyForm = reactive({
|
||||
blog: false,
|
||||
sex: false
|
||||
})
|
||||
|
||||
const save = () => {
|
||||
post('/api/user/save-privacy', privacyForm,
|
||||
() => ElMessage.success('保存成功'), 'json')
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
get('/api/user/privacy', message => {
|
||||
privacyForm.email = message.email
|
||||
privacyForm.phone = message.phone
|
||||
privacyForm.qq = message.qq
|
||||
privacyForm.wx = message.wx
|
||||
privacyForm.blog = message.blog
|
||||
privacyForm.sex = message.sex
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -38,7 +56,7 @@ const privacyForm = reactive({
|
||||
<el-checkbox v-model="privacyForm.blog" label="是否公开展示展示我的博客" size="large" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-button type="success" :icon="Select">保存隐私设置</el-button>
|
||||
<el-button type="success" :icon="Select" @click="save">保存隐私设置</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -1,8 +1,9 @@
|
||||
<script setup>
|
||||
import {onMounted, reactive, ref} from "vue";
|
||||
import {Lock, Message, Select} from "@element-plus/icons-vue";
|
||||
import {get, logout, post} from "@/net";
|
||||
import {get, logout, me, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {useStore} from "@/stores";
|
||||
|
||||
const securityForm = reactive({
|
||||
email: null,
|
||||
@ -15,8 +16,10 @@ const emailForm = ref()
|
||||
const saveEmail = () => {
|
||||
emailForm.value.validate((isValid) => {
|
||||
if(isValid) {
|
||||
post('/api/user/save-email', {email: securityForm.email},
|
||||
() => ElMessage.success("保存成功!"))
|
||||
post('/api/user/save-email', {email: securityForm.email}, () => {
|
||||
me()
|
||||
ElMessage.success("保存成功!")
|
||||
})
|
||||
} else {
|
||||
ElMessage.warning('邮件格式有误,请正确填写')
|
||||
}
|
||||
|
@ -50,4 +50,15 @@ const logout = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export { get, post, logout }
|
||||
const me = (index = false) => {
|
||||
get('/api/user/me', (message) => {
|
||||
store.auth.user = message
|
||||
localStorage.setItem("user", JSON.stringify(message))
|
||||
if(index)
|
||||
router.push('/index')
|
||||
}, () => {
|
||||
store.auth.user = null
|
||||
})
|
||||
}
|
||||
|
||||
export { get, post, logout, me }
|
||||
|
@ -40,7 +40,7 @@
|
||||
import {User, Lock} from '@element-plus/icons-vue'
|
||||
import {reactive} from "vue";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {get, post} from "@/net";
|
||||
import {get, me, post} from "@/net";
|
||||
import router from "@/router";
|
||||
import {useStore} from "@/stores";
|
||||
|
||||
@ -62,13 +62,7 @@ const login = () => {
|
||||
remember: form.remember
|
||||
}, (message) => {
|
||||
ElMessage.success(message)
|
||||
get('/api/user/me', (message) => {
|
||||
store.auth.user = message
|
||||
localStorage.setItem("user", JSON.stringify(message))
|
||||
router.push('/index')
|
||||
}, () => {
|
||||
store.auth.user = null
|
||||
})
|
||||
me(true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user