This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/table/settings/userTable.vue

227 lines
7.4 KiB
Vue
Raw Normal View History

<template>
<el-table
id="userTable"
ref="dataTable"
:data="tableData"
:height="height"
border
@header-dragend="dragend"
@sort-change="tableDataSort"
2021-04-13 10:00:48 +08:00
@selection-change="selectionChange"
2021-05-25 15:37:33 +08:00
@row-dblclick="(row)=>{showBottomBox('operationLogTab', row)}"
>
<el-table-column
:resizable="false"
align="center"
type="selection"
width="55">
</el-table-column>
<el-table-column
v-for="(item, index) in customTableTitle"
v-if="item.show"
:key="`col-${index}`"
:fixed="item.fixed"
:label="item.label"
:min-width="`${item.minWidth}`"
:prop="item.prop"
:resizable="true"
:sort-orders="['ascending', 'descending']"
:sortable="item.sortable"
:width="`${item.width}`"
>
<template slot="header">
<span class="data-column__span">{{item.label}}</span>
<div class="col-resize-area"></div>
</template>
<template slot-scope="scope" :column="item">
<template v-if="item.prop === 'name'">
<div>
<div class="flex-align-center">
<span class="user-name-top">{{scope.row[item.prop]}}</span>
<el-tag size="mini" v-if="mfaEnable == '1' || scope.row.mfaLevel > 0" style="margin-left: 5px">2FA</el-tag>
</div>
<div class="user-name-bottom">
@{{scope.row.username}}
</div>
</div>
</template>
<template v-else-if="item.prop === 'roles'">
<template v-if="scope.row[item.prop]">
{{scope.row[item.prop].map(t=>t.name).join(',')}}
</template>
<template v-else>
<span>-</span>
</template>
</template>
<template v-else-if="item.prop === 'status'">
<div v-if="scope.row[item.prop] == 1">
2021-10-22 17:47:42 +08:00
<div class="active-icon green-bg inline-block"></div>
{{ $t('overall.enabled') }}
</div>
<div v-else-if="scope.row[item.prop] == 0">
<div class="active-icon gray-bg inline-block"></div>
2021-10-22 17:47:42 +08:00
{{ $t('overall.disabled') }}
</div>
</template>
<span v-else-if="item.prop === 'createTime'">{{utcTimeToTimezoneStr(scope.row[item.prop])}}</span>
<span v-else-if="item.prop === 'lastLoginTime'">{{utcTimeToTimezoneStr(scope.row[item.prop])}}</span>
<template v-else-if="item.prop === 'lang'">
<span v-if="scope.row[item.prop] === 'en'">English</span>
<span v-else-if="scope.row[item.prop] === 'cn'">简体中文</span>
</template>
<span v-else-if="scope.row[item.prop]">{{scope.row[item.prop]}}</span>
<span v-else>-</span>
</template>
</el-table-column>
<el-table-column
:resizable="false"
:width="operationWidth"
fixed="right">
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
<div slot-scope="scope" class="table-operation-items">
<button class="table-operation-item" @click="showBottomBox('operationLogTab', scope.row)"><i class="nz-icon nz-icon-view1"></i></button>
<el-dropdown size="medium" v-has="['user_edit','user_delete']" trigger="click" @command="tableOperation">
<div class="table-operation-item table-operation-item--more">
2021-05-27 13:53:42 +08:00
<i class="nz-icon nz-icon-more3"></i>
</div>
2021-09-26 18:14:47 +08:00
<el-dropdown-menu slot="dropdown" class="right-public-box-select-top right-public-box-dropdown-top">
2021-05-19 14:26:09 +08:00
<el-dropdown-item v-has="'user_edit'" :command="['edit', scope.row]"><i class="nz-icon nz-icon-edit"></i><span class="operation-dropdown-text">{{$t('overall.edit')}}</span></el-dropdown-item>
2021-08-26 18:05:40 +08:00
<el-dropdown-item v-has="'user_edit'" :command="['copy', scope.row]"><i class="nz-icon nz-icon-override"></i><span class="operation-dropdown-text">{{$t('overall.duplicate')}}</span></el-dropdown-item>
2021-05-19 14:26:09 +08:00
<el-dropdown-item v-has="'user_delete'" :command="['delete', scope.row]" :disabled="scope.row.id === 1"><i class="nz-icon nz-icon-delete"></i><span class="operation-dropdown-text">{{$t('overall.delete')}}</span></el-dropdown-item>
2021-08-17 10:25:06 +08:00
<el-dropdown-item v-has="'user_edit'" :command="['reset_mfa', scope.row]"><i class="nz-icon nz-icon-zhongzhi2FA"></i><span class="operation-dropdown-text">{{$t('config.user.resetMfa')}}</span></el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</div>
</el-table-column>
<template slot="empty">
2021-10-25 14:45:28 +08:00
<div v-if="!loading" class="table-no-data">
2021-10-22 17:47:42 +08:00
<svg class="icon" aria-hidden="true">
<use xlink:href="#nz-icon-no-data-list"></use>
</svg>
<div style="font-size: 16px;color: #333333;font-weight: 400;">No results found</div>
</div>
<div v-else>&nbsp;</div>
2021-10-22 17:47:42 +08:00
</template>
</el-table>
</template>
<script>
import table from '@/components/common/mixin/table'
export default {
name: 'userTable',
mixins: [table],
2021-10-22 17:47:42 +08:00
props: {
loading: Boolean
},
data () {
return {
tableTitle: [ // 原始table列
{
label: 'ID',
prop: 'id',
show: true,
width: 80,
sortable: 'custom'
}, {
label: this.$t('config.user.name'),
prop: 'name',
show: true,
width: 600,
sortable: 'custom'
},
// {
// label: this.$t('config.user.username'),
// prop: 'username',
// show: true,
// width: 150
// },
{
label: this.$t('config.user.roles'),
prop: 'roles',
show: true,
width: 150
}, {
label: 'E-mail',
prop: 'email',
show: true,
minWidth: 150
}, {
label: this.$t('config.user.lastLoginTime'),
prop: 'lastLoginTime',
show: true,
width: 200
}, {
label: this.$t('config.user.lastLoginIp'),
prop: 'lastLoginIp',
show: true,
width: 150
}, {
label: this.$t('config.user.source'),
prop: 'source',
show: true,
width: 150
}, {
label: this.$t('config.user.language'),
prop: 'lang',
show: true,
width: 150
}, {
2021-10-22 17:47:42 +08:00
label: this.$t('config.user.state'),
prop: 'status',
show: true,
width: 100
}
],
mfaEnable: localStorage.getItem('nz-mfa-enable')
}
},
methods: {
statusChange (user) {
if (user.roles) {
user.roleIds = user.roles.map(t => t.id).join(',')
}
this.$put(this.api, user).then(response => {
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
} else {
this.$message.error(response.msg)
}
this.$emit('reload')
})
}
},
computed: {
isCurrentUser () {
return function (username) {
return localStorage.getItem('nz-username') === username
}
}
}
}
</script>
<style scoped>
.flex-align-center{
display: flex;
align-items: center;
}
/deep/ .el-tag.el-tag--mini{
border-radius: 10px;
font-size: 12px;
line-height: 12px;
height: 12px;
vertical-align: middle;
}
.user-name-top{
color: #333;
font-weight: 600;
font-size: 14px;
line-height: 14px;
vertical-align: middle;
}
.user-name-bottom{
color: #999999;
font-size: 14px;
line-height: 14px;
}
</style>