update: 个人中心-基本设置
This commit is contained in:
parent
9aeb5faa90
commit
e787cc0e86
|
@ -1,3 +1,31 @@
|
|||
import server from '@/utils/request'
|
||||
|
||||
export const getSsoBinds_api = (): any =>server.get(`/application/sso/me/bindings`)
|
||||
|
||||
// 获取登录用户信息
|
||||
export const getMeInfo_api = () => server.get(`/user/detail`);
|
||||
// 修改登录用户信息
|
||||
export const updateMeInfo_api = (data:object) => server.put(`/user/detail`,data);
|
||||
// 修改登录用户密码
|
||||
export const updateMepsd_api = (data:object) => server.put(`/user/passwd`,data);
|
||||
// 第三方账号解绑
|
||||
export const unBind_api = (appId: string) => server.post(`/application/sso/${appId}/unbind/me`);
|
||||
/**
|
||||
* 校验字段合法性
|
||||
* @param type 类型
|
||||
* @param name 值
|
||||
*/
|
||||
export const validateField_api = (type: 'username' | 'password', name: string) => server.post(`/user/${type}/_validate`,name,{
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 校验旧密码是否正确
|
||||
* @param password 旧密码
|
||||
*/
|
||||
export const checkOldPassword_api = (password:string) => server.post(`/user/me/password/_validate`,password,{
|
||||
headers: {
|
||||
'Content-Type': 'text/plain'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
<template>
|
||||
<a-modal
|
||||
visible
|
||||
title="编辑"
|
||||
@ok="handleOk"
|
||||
width="770px"
|
||||
@cancel="emits('update:visible', false)"
|
||||
>
|
||||
<a-form :model="form" layout="vertical">
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<a-form-item
|
||||
label="姓名"
|
||||
:rules="[{ required: true, message: '姓名必填' }]"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="form.name"
|
||||
placeholder="请输入姓名"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<a-form-item label="用户名">
|
||||
<a-input
|
||||
v-model:value="form.username"
|
||||
placeholder="请输入用户名"
|
||||
disabled
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<a-form-item label="角色">
|
||||
<a-input
|
||||
:value="
|
||||
form.roleList.map((item) => item.name).join(',')
|
||||
"
|
||||
placeholder="请输入角色"
|
||||
disabled
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<a-form-item label="组织">
|
||||
<a-input
|
||||
:value="
|
||||
form.orgList.map((item) => item.name).join(',')
|
||||
"
|
||||
placeholder="请输入组织"
|
||||
disabled
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-row :gutter="24">
|
||||
<a-col :span="12">
|
||||
<a-form-item label="手机号">
|
||||
<a-input
|
||||
v-model:value="form.telephone"
|
||||
placeholder="请输入手机号"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col :span="12">
|
||||
<a-form-item label="邮箱">
|
||||
<a-input
|
||||
v-model:value="form.email"
|
||||
placeholder="请输入邮箱"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { updateMeInfo_api } from '@/api/account/center';
|
||||
import { message } from 'ant-design-vue';
|
||||
import { userInfoType } from '../typing';
|
||||
|
||||
const emits = defineEmits(['ok', 'update:visible']);
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
data: userInfoType;
|
||||
}>();
|
||||
const form = ref(props.data);
|
||||
|
||||
const handleOk = () => {
|
||||
updateMeInfo_api(form.value).then((resp) => {
|
||||
if (resp.status === 200) {
|
||||
message.success('保存成功');
|
||||
emits('ok');
|
||||
emits('update:visible', false);
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
|
@ -0,0 +1,138 @@
|
|||
<template>
|
||||
<a-modal
|
||||
visible
|
||||
title="重置密码"
|
||||
@ok="handleOk"
|
||||
width="520px"
|
||||
@cancel="emits('update:visible', false)"
|
||||
>
|
||||
<a-form :model="form" layout="vertical" ref="formRef">
|
||||
<a-form-item
|
||||
label="旧密码"
|
||||
name="oldPassword"
|
||||
:rules="[
|
||||
{ required: true },
|
||||
{ validator: checkMothods.old, trigger: 'blur' },
|
||||
]"
|
||||
>
|
||||
<a-input
|
||||
v-model:value="form.oldPassword"
|
||||
placeholder="请输入旧密码"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="密码"
|
||||
name="newPassword"
|
||||
:rules="[
|
||||
{ required: true },
|
||||
{ validator: checkMothods.new, trigger: 'blur' },
|
||||
]"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="form.newPassword"
|
||||
placeholder="请输入姓名"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item
|
||||
label="确认密码"
|
||||
name="confirmPassword"
|
||||
:rules="[
|
||||
{ required: true },
|
||||
{ validator: checkMothods.confirm, trigger: 'blur' },
|
||||
]"
|
||||
>
|
||||
<a-input-password
|
||||
v-model:value="form.confirmPassword"
|
||||
placeholder="请输入姓名"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
updateMepsd_api,
|
||||
checkOldPassword_api,
|
||||
validateField_api,
|
||||
} from '@/api/account/center';
|
||||
import { FormInstance, message } from 'ant-design-vue';
|
||||
import { Rule } from 'ant-design-vue/lib/form';
|
||||
|
||||
const emits = defineEmits(['ok', 'update:visible']);
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
}>();
|
||||
const formRef = ref<FormInstance>();
|
||||
const form = ref<formType>({
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
confirmPassword: '',
|
||||
});
|
||||
|
||||
const checkMothods = {
|
||||
old: async (_rule: Rule, value: string) => {
|
||||
if (!value) return Promise.reject('请输入密码');
|
||||
try {
|
||||
const resp: any = await checkOldPassword_api(value);
|
||||
if (resp.status === 200 && !resp.result.passed)
|
||||
return Promise.reject(resp.result.reason);
|
||||
else return Promise.resolve();
|
||||
} catch (error) {
|
||||
return Promise.reject('验证失败');
|
||||
}
|
||||
},
|
||||
new: async (_rule: Rule, value: string) => {
|
||||
if (!value) return Promise.reject('请输入密码');
|
||||
else if (
|
||||
form.value.confirmPassword &&
|
||||
value !== form.value.confirmPassword
|
||||
)
|
||||
return Promise.reject('两次密码输入不一致');
|
||||
try {
|
||||
const resp: any = await validateField_api('password', value);
|
||||
if (resp.status === 200 && !resp.result.passed)
|
||||
return Promise.reject(resp.result.reason);
|
||||
else return Promise.resolve();
|
||||
} catch (error) {
|
||||
return Promise.reject('验证失败');
|
||||
}
|
||||
},
|
||||
confirm: async (_rule: Rule, value: string) => {
|
||||
if (!value) return Promise.reject('请输入确认密码');
|
||||
|
||||
try {
|
||||
const resp: any = await validateField_api('password', value);
|
||||
if (resp.status === 200 && !resp.result.passed)
|
||||
return Promise.reject(resp.result.reason);
|
||||
else return Promise.resolve();
|
||||
} catch (error) {
|
||||
return Promise.reject('验证失败');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const handleOk = () => {
|
||||
formRef.value?.validate().then(() => {
|
||||
const params = {
|
||||
oldPassword: form.value.oldPassword,
|
||||
newPassword: form.value.newPassword,
|
||||
};
|
||||
// updateMepsd_api(params).then((resp) => {
|
||||
// if (resp.status === 200) {
|
||||
// message.success('保存成功');
|
||||
// emits('ok');
|
||||
// emits('update:visible', false);
|
||||
// }
|
||||
// });
|
||||
});
|
||||
};
|
||||
console.clear();
|
||||
type formType = {
|
||||
oldPassword: string;
|
||||
newPassword: string;
|
||||
confirmPassword: string;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
|
@ -63,11 +63,27 @@
|
|||
</div>
|
||||
<div class="info-card">
|
||||
<p>角色</p>
|
||||
<p>{{ userInfo.roleList.join(',') || '-' }}</p>
|
||||
<p>
|
||||
{{
|
||||
(userInfo.roleList &&
|
||||
userInfo.roleList
|
||||
.map((item) => item.name)
|
||||
.join(',')) ||
|
||||
'-'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="info-card">
|
||||
<p>组织</p>
|
||||
<p>{{ userInfo.orgList.join(',') || '-' }}</p>
|
||||
<p>
|
||||
{{
|
||||
(userInfo.orgList &&
|
||||
userInfo.orgList
|
||||
.map((item) => item.name)
|
||||
.join(',')) ||
|
||||
'-'
|
||||
}}
|
||||
</p>
|
||||
</div>
|
||||
<div class="info-card">
|
||||
<p>邮箱</p>
|
||||
|
@ -78,6 +94,7 @@
|
|||
type="EditOutlined"
|
||||
class="edit"
|
||||
style="right: 40px"
|
||||
@click="editInfoVisible = true"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -94,10 +111,19 @@
|
|||
>安全性高的密码可以使帐号更安全。建议您定期更换密码,设置一个包含字母,符号或数字中至少两项且长度超过8位的密码</span
|
||||
>
|
||||
</div>
|
||||
<AIcon type="EditOutlined" class="edit" />
|
||||
<span class="edit">
|
||||
<PermissionButton
|
||||
:uhasPermission="`${permission}:update`"
|
||||
type="link"
|
||||
@click="editPasswordVisible = true"
|
||||
>
|
||||
<AIcon type="EditOutlined" style="color: #1d39c4;" />
|
||||
</PermissionButton>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<!-- 社区版不显示 -->
|
||||
<div class="card" v-if="isNoCommunity">
|
||||
<h3>绑定三方账号</h3>
|
||||
<div class="content">
|
||||
<div class="account-card" v-for="item in bindList">
|
||||
|
@ -106,7 +132,7 @@
|
|||
style="height: 50px"
|
||||
alt=""
|
||||
/>
|
||||
<div class="text">
|
||||
<Ellipsis style="width: 150px; font-size: 22px">
|
||||
<div v-if="item.bound">
|
||||
<div>绑定名:{{ item.others.name }}</div>
|
||||
<div>
|
||||
|
@ -118,30 +144,99 @@
|
|||
</div>
|
||||
</div>
|
||||
<div v-else>{{ item.name }}未绑定</div>
|
||||
</div>
|
||||
|
||||
<a-button v-if="item.bound">解除绑定</a-button>
|
||||
<a-button v-else type="primary">立即绑定</a-button>
|
||||
</Ellipsis>
|
||||
<a-popconfirm
|
||||
v-if="item.bound"
|
||||
title="确认解除绑定嘛?"
|
||||
@confirm="() => unBind(item.id)"
|
||||
>
|
||||
<a-button>解除绑定</a-button>
|
||||
</a-popconfirm>
|
||||
<a-button
|
||||
v-else
|
||||
type="primary"
|
||||
@click="clickBind(item.id)"
|
||||
>立即绑定</a-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<!-- 第三方用户不显示 -->
|
||||
<div class="card" v-if="!isApiUser">
|
||||
<h3>首页视图</h3>
|
||||
<div class="choose-view">
|
||||
<a-row class="view-content" :gutter="24">
|
||||
<a-col
|
||||
:span="6"
|
||||
class="select-item"
|
||||
:class="{ selected: currentView === 'device' }"
|
||||
@click="currentView = 'device'"
|
||||
>
|
||||
<img :src="getImage('/home/device.png')" alt="" />
|
||||
</a-col>
|
||||
<a-col
|
||||
:span="6"
|
||||
class="select-item"
|
||||
:class="{ selected: currentView === 'ops' }"
|
||||
@click="currentView = 'ops'"
|
||||
>
|
||||
<img :src="getImage('/home/ops.png')" alt="" />
|
||||
</a-col>
|
||||
<a-col
|
||||
:span="6"
|
||||
class="select-item"
|
||||
:class="{
|
||||
selected: currentView === 'comprehensive',
|
||||
}"
|
||||
@click="currentView = 'comprehensive'"
|
||||
>
|
||||
<img
|
||||
:src="getImage('/home/comprehensive.png')"
|
||||
alt=""
|
||||
/>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<a-button type="primary" class="btn" @click="confirm"
|
||||
>确定</a-button
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<EditInfoDialog
|
||||
v-if="editInfoVisible"
|
||||
v-model:visible="editInfoVisible"
|
||||
:data="userInfo"
|
||||
@ok="getUserInfo"
|
||||
/>
|
||||
<EditPasswordDialog
|
||||
v-if="editPasswordVisible"
|
||||
v-model:visible="editPasswordVisible"
|
||||
/>
|
||||
</div>
|
||||
</page-container>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import PermissionButton from '@/components/PermissionButton/index.vue';
|
||||
import EditInfoDialog from './components/EditInfoDialog.vue';
|
||||
import EditPasswordDialog from './components/EditPasswordDialog.vue';
|
||||
import { LockOutlined } from '@ant-design/icons-vue';
|
||||
import { BASE_API_PATH, TOKEN_KEY } from '@/utils/variable';
|
||||
import { LocalStore, getImage } from '@/utils/comm';
|
||||
import { useUserInfo } from '@/store/userInfo';
|
||||
import { message, UploadChangeParam, UploadFile } from 'ant-design-vue';
|
||||
import { getSsoBinds_api } from '@/api/account/center';
|
||||
import {
|
||||
getMeInfo_api,
|
||||
getSsoBinds_api,
|
||||
unBind_api,
|
||||
} from '@/api/account/center';
|
||||
import moment from 'moment';
|
||||
import { getMe_api, getView_api, setView_api } from '@/api/home';
|
||||
import { isNoCommunity } from '@/utils/utils';
|
||||
import { userInfoType } from './typing';
|
||||
|
||||
const userInfo = useUserInfo().$state.userInfos as any as userInfoType;
|
||||
const permission = 'system/User';
|
||||
const userInfo = ref<userInfoType>({});
|
||||
// 第三方账号
|
||||
const bindList = ref<any[]>([]);
|
||||
const bindIcon = {
|
||||
'dingtalk-ent-app': '/notice/dingtalk.png',
|
||||
|
@ -149,6 +244,24 @@ const bindIcon = {
|
|||
'internal-standalone': '/apply/provider1.png',
|
||||
'third-party': '/apply/provider5.png',
|
||||
};
|
||||
const unBind = (id: string) => {
|
||||
unBind_api(id).then((resp) => {
|
||||
if (resp.status === 200) {
|
||||
message.success('解绑成功');
|
||||
getSsoBinds();
|
||||
}
|
||||
});
|
||||
};
|
||||
const clickBind = (id: string) => {
|
||||
window.open(`/${origin}/application/sso/${id}/login?autoCreateUser=false`);
|
||||
localStorage.setItem('onBind', 'false');
|
||||
localStorage.setItem('onLogin', 'yes');
|
||||
window.onstorage = (e) => {
|
||||
if (e.newValue) {
|
||||
getSsoBinds();
|
||||
}
|
||||
};
|
||||
};
|
||||
const upload = reactive({
|
||||
fileList: [] as any[],
|
||||
uploadLoading: false,
|
||||
|
@ -158,36 +271,74 @@ const upload = reactive({
|
|||
} else if (info.file.status === 'done') {
|
||||
info.file.url = info.file.response?.result;
|
||||
upload.uploadLoading = false;
|
||||
userInfo.avatar = info.file.response?.result;
|
||||
userInfo.value.avatar = info.file.response?.result;
|
||||
} else if (info.file.status === 'error') {
|
||||
console.log(info.file);
|
||||
upload.uploadLoading = false;
|
||||
message.error('logo上传失败,请稍后再试');
|
||||
}
|
||||
},
|
||||
});
|
||||
// 首页视图
|
||||
const isApiUser = ref<boolean>();
|
||||
const currentView = ref<string>('');
|
||||
const confirm = () => {
|
||||
setView_api({
|
||||
name: 'view',
|
||||
content: currentView.value,
|
||||
}).then(() => message.success('保存成功'));
|
||||
};
|
||||
|
||||
const editInfoVisible = ref<boolean>(false);
|
||||
const editPasswordVisible = ref<boolean>(false);
|
||||
init();
|
||||
|
||||
function init() {
|
||||
getUserInfo();
|
||||
isNoCommunity && getSsoBinds();
|
||||
getViews();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*/
|
||||
function getUserInfo() {
|
||||
getMeInfo_api().then((resp) => {
|
||||
userInfo.value = resp.result as userInfoType;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 获取绑定第三方账号
|
||||
*/
|
||||
function getSsoBinds() {
|
||||
getSsoBinds_api().then((resp: any) => {
|
||||
if (resp.status === 200) bindList.value = resp.result;
|
||||
});
|
||||
}
|
||||
|
||||
type userInfoType = {
|
||||
avatar: string;
|
||||
createTime: number;
|
||||
email: string;
|
||||
id: string;
|
||||
name: string;
|
||||
orgList: string[];
|
||||
roleList: string[];
|
||||
status: number;
|
||||
telephone: string;
|
||||
tenantDisabled: boolean;
|
||||
type: { name: string; id: string };
|
||||
username: string;
|
||||
};
|
||||
/**
|
||||
* 获取首页视图
|
||||
*/
|
||||
function getViews() {
|
||||
// 判断是否是api用户 不是则获取选中的视图
|
||||
getMe_api()
|
||||
.then((resp: any) => {
|
||||
if (resp && resp.status === 200) {
|
||||
isApiUser.value = resp.result.dimensions.find(
|
||||
(item: any) =>
|
||||
item.type === 'api-client' ||
|
||||
item.type.id === 'api-client',
|
||||
);
|
||||
if (!isApiUser.value) return getView_api();
|
||||
}
|
||||
})
|
||||
.then((resp: any) => {
|
||||
if (resp?.status === 200) {
|
||||
if (resp.result) currentView.value = resp.result?.content;
|
||||
else if (resp.result.username === 'admin') {
|
||||
currentView.value = 'comprehensive';
|
||||
} else currentView.value = 'init';
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
@ -216,6 +367,7 @@ type userInfoType = {
|
|||
.content {
|
||||
display: flex;
|
||||
margin-top: 24px;
|
||||
flex-wrap: wrap;
|
||||
.content-item {
|
||||
margin-right: 24px;
|
||||
.info-card {
|
||||
|
@ -250,16 +402,32 @@ type userInfoType = {
|
|||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.text {
|
||||
display: -webkit-box;
|
||||
font-size: 22px;
|
||||
width: 150px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
word-break: break-all;
|
||||
.choose-view {
|
||||
width: 100%;
|
||||
margin-top: 48px;
|
||||
.view-content {
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
.select-item {
|
||||
border: 2px solid transparent;
|
||||
img {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
&.selected {
|
||||
border-color: #10239e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn {
|
||||
display: block;
|
||||
margin: 48px auto;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
|
||||
import { dictType } from '@/views/system/Department/typing';
|
||||
|
||||
export type userInfoType = {
|
||||
avatar: string;
|
||||
createTime: number;
|
||||
email: string;
|
||||
id: string;
|
||||
name: string;
|
||||
orgList: dictType;
|
||||
roleList: dictType;
|
||||
status: number;
|
||||
telephone: string;
|
||||
tenantDisabled: boolean;
|
||||
type: { name: string; id: string };
|
||||
username: string;
|
||||
};
|
Loading…
Reference in New Issue