统一管理API接口
This commit is contained in:
parent
4bdd5e6bc1
commit
b03e32f169
@ -2,7 +2,7 @@
|
||||
import { useDark, useToggle } from '@vueuse/core'
|
||||
import {onMounted, provide, ref} from "vue";
|
||||
import {unauthorized} from "@/net";
|
||||
import {getUserInfo} from "@/net/api/user";
|
||||
import {apiUserInfo} from "@/net/api/user";
|
||||
|
||||
useDark({
|
||||
selector: 'html',
|
||||
@ -20,7 +20,7 @@ useDark({
|
||||
|
||||
onMounted(() => {
|
||||
if(!unauthorized()) {
|
||||
getUserInfo(loading)
|
||||
apiUserInfo(loading)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import {get} from "@/net";
|
||||
import {get, post} from "@/net";
|
||||
import {useStore} from "@/store";
|
||||
|
||||
export const getUserInfo = (loadingRef) => {
|
||||
export const apiUserInfo = (loadingRef) => {
|
||||
if(loadingRef) loadingRef.value = true
|
||||
get('/api/user/info', (data) => {
|
||||
const store = useStore();
|
||||
@ -10,4 +10,22 @@ export const getUserInfo = (loadingRef) => {
|
||||
})
|
||||
}
|
||||
|
||||
export const apiUserChangePassword = (form, success) =>
|
||||
post('/api/user/change-password', form, success)
|
||||
|
||||
export const apiUserPrivacy = (success) =>
|
||||
get('/api/user/privacy', success)
|
||||
|
||||
export const apiUserPrivacySave = (data, loadingRef, success) => {
|
||||
loadingRef.value = true
|
||||
post('/api/user/save-privacy', data, () => {
|
||||
loadingRef.value = false
|
||||
success()
|
||||
})
|
||||
}
|
||||
|
||||
export const apiUserDetailSave = (form, success, failure) =>
|
||||
post('/api/user/save-details', form, success, failure)
|
||||
|
||||
export const apiUserDetail = (success) =>
|
||||
get('/api/user/details', success)
|
||||
|
@ -32,8 +32,8 @@ const userMenu = [
|
||||
]
|
||||
}, {
|
||||
title: '个人设置', icon: Operation, sub: [
|
||||
{ title: '个人信息设置', icon: User },
|
||||
{ title: '账号安全设置', icon: Lock }
|
||||
{ title: '个人信息设置', icon: User, index: '/index/user-setting' },
|
||||
{ title: '账号安全设置', icon: Lock, index: '/index/privacy-setting' }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -3,15 +3,15 @@
|
||||
import Card from "@/components/Card.vue";
|
||||
import {Setting, Switch, Lock} from "@element-plus/icons-vue";
|
||||
import {reactive, ref} from "vue";
|
||||
import {get, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
import {apiUserChangePassword, apiUserPrivacy, apiUserPrivacySave} from "@/net/api/user";
|
||||
|
||||
const form = reactive({
|
||||
password: '',
|
||||
new_password: '',
|
||||
new_password_repeat: ''
|
||||
})
|
||||
const validatePassword = (rule, value, callback) => {
|
||||
const validatePassword = (_, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请再次输入密码'))
|
||||
} else if (value !== form.new_password) {
|
||||
@ -35,12 +35,12 @@ const rules = {
|
||||
}
|
||||
const formRef = ref()
|
||||
const valid = ref(false)
|
||||
const onValidate = (prop, isValid) => valid.value = isValid
|
||||
const onValidate = (_, isValid) => valid.value = isValid
|
||||
|
||||
function resetPassword(){
|
||||
formRef.value.validate(valid => {
|
||||
if(valid) {
|
||||
post('/api/user/change-password', form, () => {
|
||||
apiUserChangePassword(form, () => {
|
||||
ElMessage.success('修改密码成功!')
|
||||
formRef.value.resetFields();
|
||||
})
|
||||
@ -56,23 +56,15 @@ const privacy = reactive({
|
||||
email: false,
|
||||
gender: false
|
||||
})
|
||||
get('/api/user/privacy', data => {
|
||||
privacy.phone = data.phone
|
||||
privacy.email = data.email
|
||||
privacy.wx = data.wx
|
||||
privacy.qq = data.qq
|
||||
privacy.gender = data.gender
|
||||
|
||||
apiUserPrivacy(data => {
|
||||
Object.assign(privacy, data)
|
||||
saving.value = false
|
||||
})
|
||||
|
||||
function savePrivacy(type, status){
|
||||
saving.value = true
|
||||
post('/api/user/save-privacy', {
|
||||
type: type,
|
||||
status: status
|
||||
}, () => {
|
||||
ElMessage.success('隐私设置修改成功!')
|
||||
saving.value = false
|
||||
})
|
||||
apiUserPrivacySave({ type, status }, saving,
|
||||
() => ElMessage.success('隐私设置修改成功!'))
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -7,6 +7,7 @@ import {computed, reactive, ref} from "vue";
|
||||
import {accessHeader, get, post} from "@/net";
|
||||
import {ElMessage} from "element-plus";
|
||||
import axios from "axios";
|
||||
import {apiUserDetail, apiUserDetailSave} from "@/net/api/user";
|
||||
|
||||
const store = useStore()
|
||||
|
||||
@ -55,7 +56,7 @@ function saveDetails() {
|
||||
baseFormRef.value.validate(isValid => {
|
||||
if (isValid) {
|
||||
loading.base = true
|
||||
post('/api/user/save-details', baseForm, () => {
|
||||
apiUserDetailSave(baseForm, () => {
|
||||
ElMessage.success('用户信息保存成功')
|
||||
store.user.usernamew = baseForm.username
|
||||
desc.value = baseForm.desc
|
||||
@ -68,12 +69,9 @@ function saveDetails() {
|
||||
})
|
||||
}
|
||||
|
||||
get('/api/user/details', data => {
|
||||
apiUserDetail(data => {
|
||||
baseForm.username = store.user.username
|
||||
baseForm.gender = data.gender
|
||||
baseForm.phone = data.phone
|
||||
baseForm.wx = data.wx
|
||||
baseForm.qq = data.qq
|
||||
Object.assign(baseForm, data)
|
||||
baseForm.desc = desc.value = data.desc
|
||||
emailForm.email = store.user.email
|
||||
loading.form = false
|
||||
|
@ -53,7 +53,7 @@ import {User, Lock} from '@element-plus/icons-vue'
|
||||
import router from "@/router";
|
||||
import {inject, reactive, ref} from "vue";
|
||||
import {login} from '@/net'
|
||||
import {getUserInfo} from "@/net/api/user";
|
||||
import {apiUserInfo} from "@/net/api/user";
|
||||
|
||||
const formRef = ref()
|
||||
const form = reactive({
|
||||
@ -77,7 +77,7 @@ function userLogin() {
|
||||
formRef.value.validate((isValid) => {
|
||||
if(isValid) {
|
||||
login(form.username, form.password, form.remember, () => {
|
||||
getUserInfo(loading)
|
||||
apiUserInfo(loading)
|
||||
router.push("/index")
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user