2021-10-14 13:40:13 +08:00
|
|
|
<template>
|
|
|
|
|
<div v-clickoutside="{obj: editProfile, func: esc}" class="right-box right-box-profile">
|
|
|
|
|
<div class="right-box__header">
|
|
|
|
|
<div class="header__title">{{$t('profile.editProfile')}}</div>
|
|
|
|
|
<div class="header__operation">
|
2022-07-01 09:39:20 +08:00
|
|
|
<span v-cancel="{obj: editProfile, func: esc}"><i class="nz-icon nz-icon-close" :title="$t('overall.close')"></i></span>
|
2021-10-14 13:40:13 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="right-box__container">
|
|
|
|
|
<div class="container__form">
|
|
|
|
|
<el-form ref="profileForm" :model="editProfile" :rules="rules" label-position="top" label-width="120px">
|
2022-06-16 15:58:17 +08:00
|
|
|
<el-form-item :label="$t('overall.name')" prop="name">
|
2022-10-18 09:21:01 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model.trim="editProfile.name" size="small" type="text"></el-input>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('profile.username')" prop="username">
|
2021-10-14 17:03:23 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.username" disabled size="small" type="text"></el-input>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-form-item>
|
2022-06-21 14:17:46 +08:00
|
|
|
<el-form-item :label="$t('config.system.email.email')" prop="email">
|
2021-10-14 13:40:13 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.email" size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('profile.mobile')" prop="mobile">
|
|
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.mobile" size="small" type="text"></el-input>
|
|
|
|
|
</el-form-item>
|
2021-10-15 10:46:07 +08:00
|
|
|
<el-form-item :label="$t('profile.role')" v-if="editProfile.roles[0].i18n !== ''" prop="roles">
|
2021-10-14 17:03:23 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.roles[0].i18n" disabled size="small" type="text"></el-input>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="$t('profile.role')" v-else prop="roles">
|
2021-10-14 18:14:36 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.roles[0].name" disabled size="small" type="text"></el-input>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
<!--language-->
|
|
|
|
|
<el-form-item :label="$t('config.user.language')" prop="lang">
|
|
|
|
|
<el-select id="account-input-language"
|
|
|
|
|
class="right-box__select"
|
|
|
|
|
v-model="editProfile.lang"
|
2021-10-29 12:02:34 +08:00
|
|
|
popper-class="right-box-select-top prevent-clickoutside"
|
2021-10-14 13:40:13 +08:00
|
|
|
size="small">
|
2022-01-06 16:52:13 +08:00
|
|
|
<el-option v-for="item in langList" :key="item.value" :label="item.name" :value="item.value"></el-option>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2022-06-29 13:41:44 +08:00
|
|
|
<el-form-item :label="$t('config.user.Theme')" prop="theme">
|
2022-01-06 16:52:13 +08:00
|
|
|
<el-select id="account-input-language"
|
|
|
|
|
class="right-box__select"
|
|
|
|
|
v-model="editProfile.theme"
|
|
|
|
|
popper-class="right-box-select-top prevent-clickoutside"
|
|
|
|
|
size="small">
|
|
|
|
|
<el-option v-for="item in theme" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
|
|
|
|
</el-select>
|
2021-11-01 17:23:01 +08:00
|
|
|
</el-form-item>
|
2021-10-14 13:40:13 +08:00
|
|
|
<el-form-item :label="$t('profile.source')" prop="source">
|
2021-10-14 17:03:23 +08:00
|
|
|
<el-input maxlength="64" show-word-limit v-model="editProfile.source" disabled size="small" type="text"></el-input>
|
2021-10-14 13:40:13 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="right-box__footer">
|
|
|
|
|
<button id="asset-edit-cancel" v-cancel="{obj: editProfile, func: esc}" class="footer__btn footer__btn--light">
|
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
<button id="asset-edit-save" :class="{'footer__btn--disabled': prevent_opt.save}" :disabled="prevent_opt.save" class="footer__btn" @click="save">
|
|
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import editRigthBox from '@/components/common/mixin/editRigthBox'
|
2021-11-01 17:23:01 +08:00
|
|
|
import { theme } from '@/components/common/js/constants'
|
2021-10-14 13:40:13 +08:00
|
|
|
|
|
|
|
|
export default {
|
2022-03-07 10:09:45 +08:00
|
|
|
name: 'profilebox',
|
2021-10-14 13:40:13 +08:00
|
|
|
components: {
|
|
|
|
|
},
|
|
|
|
|
props: {
|
|
|
|
|
obj: {
|
|
|
|
|
type: Object
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-11-02 18:34:01 +08:00
|
|
|
computed: {
|
|
|
|
|
langList () {
|
|
|
|
|
return this.$store.getters.getLangList
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-10-14 13:40:13 +08:00
|
|
|
mixins: [editRigthBox],
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
2021-11-01 17:23:01 +08:00
|
|
|
theme: theme,
|
2021-10-14 13:40:13 +08:00
|
|
|
url: 'sys/user/profile',
|
|
|
|
|
rightBox: { profile: { show: false } },
|
|
|
|
|
editProfile: {},
|
|
|
|
|
rules: {
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
],
|
|
|
|
|
lang: [
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
watch: {
|
|
|
|
|
obj: {
|
|
|
|
|
deep: true,
|
|
|
|
|
immediate: true,
|
|
|
|
|
handler (n) {
|
|
|
|
|
this.isEdit = true
|
|
|
|
|
this.editProfile = JSON.parse(JSON.stringify(n))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
created () {},
|
|
|
|
|
methods: {
|
|
|
|
|
clickoutside () {
|
|
|
|
|
this.esc(false)
|
|
|
|
|
},
|
|
|
|
|
/* 关闭弹框 */
|
|
|
|
|
esc (refresh) {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
this.$emit('close', refresh)
|
|
|
|
|
},
|
|
|
|
|
save () {
|
|
|
|
|
this.$refs.profileForm.validate((valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
if (this.editProfile.id) {
|
|
|
|
|
this.editProfile.roleIds = this.editProfile.roles[0].id
|
|
|
|
|
this.$put(this.url, this.editProfile).then(res => {
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
if (res.code === 200) {
|
2021-11-01 17:23:01 +08:00
|
|
|
// 若主题变更,则更改主题
|
|
|
|
|
const currentTheme = theme.find(t => t.value === this.editProfile.theme).label || 'light'
|
|
|
|
|
const oldTheme = localStorage.getItem(`nz-user-${localStorage.getItem('nz-user-id')}-theme`)
|
|
|
|
|
if (currentTheme !== oldTheme) {
|
|
|
|
|
localStorage.setItem(`nz-user-${localStorage.getItem('nz-user-id')}-theme`, currentTheme)
|
|
|
|
|
const body = document.getElementsByTagName('body')[0]
|
|
|
|
|
body.setAttribute('class', `theme-${currentTheme}`)
|
|
|
|
|
}
|
2021-10-14 13:40:13 +08:00
|
|
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
this.esc(true)
|
2021-11-04 12:13:36 +08:00
|
|
|
if (this.editProfile.lang !== localStorage.getItem('nz-language')) {
|
|
|
|
|
localStorage.setItem('nz-language', this.editProfile.lang)
|
|
|
|
|
this.$i18n.locale = this.editProfile.lang
|
|
|
|
|
this.$emit('clickProfile', true)
|
|
|
|
|
} else {
|
|
|
|
|
this.$emit('clickProfile', false)
|
|
|
|
|
}
|
2021-10-14 13:40:13 +08:00
|
|
|
} else {
|
|
|
|
|
this.$message.error(res.msg)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|