2021-04-16 21:10:31 +08:00
|
|
|
<template>
|
|
|
|
|
<el-table
|
|
|
|
|
:id="tableId"
|
|
|
|
|
ref="dataTable"
|
|
|
|
|
:data="tableData"
|
|
|
|
|
:height="height"
|
|
|
|
|
border
|
|
|
|
|
@header-dragend="dragend"
|
|
|
|
|
@sort-change="tableDataSort"
|
|
|
|
|
@selection-change="selectionChange"
|
|
|
|
|
>
|
|
|
|
|
<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']"
|
|
|
|
|
:width="`${item.width}`"
|
|
|
|
|
class="data-column"
|
|
|
|
|
>
|
|
|
|
|
<template slot="header">
|
|
|
|
|
<span>{{item.label}}</span>
|
|
|
|
|
<div class="col-resize-area"></div>
|
|
|
|
|
</template>
|
|
|
|
|
<template slot-scope="scope" :column="item">
|
|
|
|
|
<template v-if="scope.row.edit">
|
|
|
|
|
<template v-if="item.prop == 'name'">
|
|
|
|
|
<el-popover :content="rules.name.message" placement="top" trigger="manual" v-model="rules.name.switch" popper-class="small-pop warn-pop" @after-enter="popShow(rules.name)">
|
2021-05-28 10:43:41 +08:00
|
|
|
<el-input slot="reference" maxlength="64" show-word-limit v-model="scope.row[item.prop]" size="small" ></el-input>
|
2021-04-16 21:10:31 +08:00
|
|
|
</el-popover>
|
|
|
|
|
</template>
|
2022-06-27 09:46:52 +08:00
|
|
|
<!-- <template v-if="item.prop == 'role'">
|
2021-04-16 21:10:31 +08:00
|
|
|
<el-popover :content="rules.roleId.message" placement="top" trigger="manual" v-model="rules.roleId.switch" popper-class="small-pop warn-pop" @after-enter="popShow(rules.roleId)">
|
2021-10-29 14:25:59 +08:00
|
|
|
<el-select v-model="scope.row[item.prop]" size="small" :placeholder="$t('el.select.placeholder')" value-key="id" slot="reference" popper-class="api-select right-box-select-top right-public-box-dropdown-top role-system-table">
|
2021-04-16 21:10:31 +08:00
|
|
|
<template v-for="role in roles" >
|
2022-01-04 14:57:59 +08:00
|
|
|
<el-option :label="role.name" :value="role" :key="role.name"></el-option>
|
2021-04-16 21:10:31 +08:00
|
|
|
</template>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-popover>
|
2022-06-27 09:46:52 +08:00
|
|
|
</template> -->
|
2021-04-16 21:10:31 +08:00
|
|
|
<template v-if="item.prop == 'expireAt'">
|
2021-04-21 18:24:25 +08:00
|
|
|
<!-- <el-popover :content="rules.expireAt.message" placement="top" trigger="manual" v-model="rules.expireAt.switch" popper-class="small-pop warn-pop" @after-enter="popShow(rules.expireAt)">-->
|
2021-04-28 15:18:21 +08:00
|
|
|
<my-date-picker
|
2021-04-16 21:10:31 +08:00
|
|
|
slot="reference"
|
|
|
|
|
style="width: 100%;"
|
|
|
|
|
v-model="scope.row[item.prop]"
|
|
|
|
|
prefix-icon=" " size="small" ref="calendar"
|
2022-01-04 15:00:36 +08:00
|
|
|
:format="timeFormatStrToDatePickFormat(timeFormatMain)"
|
2021-04-16 21:10:31 +08:00
|
|
|
type="datetime"
|
2021-10-29 12:02:34 +08:00
|
|
|
popper-class="item-system-table right-public-box-dropdown-top right-box-select-top"
|
2021-04-16 21:10:31 +08:00
|
|
|
:picker-options="pickerOptions"
|
|
|
|
|
:placeholder="$t('el.datepicker.selectTime')">
|
2021-04-28 15:18:21 +08:00
|
|
|
</my-date-picker>
|
2021-04-21 18:24:25 +08:00
|
|
|
<!-- </el-popover>-->
|
2021-04-16 21:10:31 +08:00
|
|
|
</template>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2021-04-21 13:05:27 +08:00
|
|
|
<template v-if="item.prop == 'createUser'">
|
2021-04-16 21:10:31 +08:00
|
|
|
{{scope.row[item.prop]?scope.row[item.prop].name:'-'}}
|
|
|
|
|
</template>
|
2022-06-27 09:46:52 +08:00
|
|
|
<!-- <template v-else-if="item.prop == 'role'">
|
2021-04-16 21:10:31 +08:00
|
|
|
{{scope.row[item.prop]?scope.row[item.prop].name:'-'}}
|
2022-06-27 09:46:52 +08:00
|
|
|
</template> -->
|
2021-04-21 18:24:25 +08:00
|
|
|
<template v-else-if="item.prop == 'expireAt'">
|
2021-05-12 17:15:23 +08:00
|
|
|
{{scope.row[item.prop]?utcTimeToTimezoneStr(scope.row[item.prop]):$t('config.system.apiKey.noExpire')}}
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else-if="item.prop == 'createAt'">
|
|
|
|
|
{{scope.row[item.prop]?utcTimeToTimezoneStr(scope.row[item.prop]):$t('config.system.apiKey.noExpire')}}
|
2021-04-21 18:24:25 +08:00
|
|
|
</template>
|
2022-06-27 09:46:52 +08:00
|
|
|
<template v-else-if="item.prop == 'token'">
|
2022-07-05 14:06:31 +08:00
|
|
|
<div class="document-copy-block">
|
2022-06-27 10:10:49 +08:00
|
|
|
<span class="document-copy-text"> {{scope.row[item.prop].replace(reg, '*')}}</span>
|
2022-07-22 10:46:49 +08:00
|
|
|
<i v-if="scope.row[item.prop]" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row[item.prop])" :title="$t('overall.copyText')"></i>
|
2022-06-27 09:46:52 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
2022-07-06 11:11:40 +08:00
|
|
|
<template v-else-if="item.prop === 'name'">
|
|
|
|
|
<div class="document-copy-block">
|
|
|
|
|
<span class="document-copy-text">{{scope.row.name ? scope.row.name : '-'}}</span>
|
2022-07-22 10:46:49 +08:00
|
|
|
<i v-if="scope.row.name" class="nz-icon nz-icon-override" style="visibility: hidden" @click="onCopy(scope.row.name)" :title="$t('overall.copyText')"></i>
|
2022-07-06 11:11:40 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
2021-04-16 21:10:31 +08:00
|
|
|
<template v-else-if="scope.row[item.prop]">{{scope.row[item.prop]}}</template>
|
|
|
|
|
<template v-else>-</template>
|
|
|
|
|
</template>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
|
|
|
|
:resizable="false"
|
|
|
|
|
:width="operationWidth"
|
|
|
|
|
fixed="right">
|
|
|
|
|
<div slot="header" class="table-operation-title">{{$t('overall.option')}}</div>
|
2022-01-11 17:05:21 +08:00
|
|
|
<div slot-scope="scope" v-has="['system_apiKey_edit','system_apiKey_delete']" class="table-operation-items">
|
2021-04-16 21:10:31 +08:00
|
|
|
<template v-if="scope.row.edit">
|
2021-11-04 09:29:01 +08:00
|
|
|
<button v-has="'system_apiKey_edit'" :disabled="prevent_opt.save" class="nz-btn nz-btn-size-mini nz-btn-style-normal" style="margin-right: 10px" type="button" @click="save(scope.row)"><span>{{$t('overall.save')}}</span></button>
|
2021-11-17 11:12:06 +08:00
|
|
|
<button :disabled="prevent_opt.save" class="nz-btn nz-btn-size-mini nz-btn-style-light" type="button" @click="cancel(scope.row)"><span>{{$t('overall.cancel')}}</span></button>
|
2021-04-16 21:10:31 +08:00
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
2022-07-01 09:39:20 +08:00
|
|
|
<button class="table-operation-item" @click="$emit('del',scope.row)" v-has="'system_apiKey_delete'" :title="$t('overall.delete')"><i class="nz-icon nz-icon-delete"></i></button>
|
2021-04-16 21:10:31 +08:00
|
|
|
</template>
|
|
|
|
|
</div>
|
|
|
|
|
</el-table-column>
|
2021-10-25 14:38:43 +08:00
|
|
|
<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>
|
2021-10-28 17:53:27 +08:00
|
|
|
<div class="table-no-data__title">No results found</div>
|
2021-10-22 17:47:42 +08:00
|
|
|
</div>
|
2021-10-25 14:38:43 +08:00
|
|
|
<div v-else> </div>
|
2021-10-22 17:47:42 +08:00
|
|
|
</template>
|
2021-04-16 21:10:31 +08:00
|
|
|
</el-table>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { tableCommon } from './systemCommon'
|
|
|
|
|
import table from '@/components/common/mixin/table'
|
|
|
|
|
export default {
|
|
|
|
|
name: 'apiKeyTable',
|
2021-10-22 17:47:42 +08:00
|
|
|
props: {
|
|
|
|
|
loading: Boolean
|
|
|
|
|
},
|
2021-04-16 21:10:31 +08:00
|
|
|
mixins: [table, tableCommon],
|
|
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
tableTitle: [
|
|
|
|
|
{
|
|
|
|
|
label: 'ID',
|
|
|
|
|
prop: 'id',
|
|
|
|
|
show: true,
|
|
|
|
|
width: 80
|
|
|
|
|
}, {
|
|
|
|
|
label: this.$t('overall.name'),
|
|
|
|
|
prop: 'name',
|
|
|
|
|
show: true
|
|
|
|
|
}, {
|
2022-06-24 15:36:37 +08:00
|
|
|
label: this.$t('apiKey.key'),
|
2021-04-16 21:10:31 +08:00
|
|
|
prop: 'token',
|
2022-06-27 09:46:52 +08:00
|
|
|
show: false
|
|
|
|
|
},
|
|
|
|
|
// {
|
|
|
|
|
// label: this.$t('profile.role'),
|
|
|
|
|
// prop: 'role',
|
|
|
|
|
// show: true
|
|
|
|
|
// },
|
|
|
|
|
{
|
2021-04-16 21:10:31 +08:00
|
|
|
label: this.$t('config.system.apiKey.expireAt'),
|
|
|
|
|
prop: 'expireAt',
|
|
|
|
|
show: true
|
|
|
|
|
}, {
|
|
|
|
|
label: this.$t('config.system.apiKey.create'),
|
|
|
|
|
prop: 'createUser',
|
|
|
|
|
show: true
|
|
|
|
|
}, {
|
|
|
|
|
label: this.$t('config.system.apiKey.creatAt'),
|
|
|
|
|
prop: 'createAt',
|
2021-09-13 15:07:14 +08:00
|
|
|
minWidth: 100,
|
2021-04-16 21:10:31 +08:00
|
|
|
show: true
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
roles: [],
|
|
|
|
|
rules: {
|
|
|
|
|
name: { required: true, message: this.$t('validate.required'), switch: false },
|
2021-04-22 18:03:56 +08:00
|
|
|
roleId: { required: true, message: this.$t('validate.required'), switch: false }
|
2021-04-21 18:24:25 +08:00
|
|
|
// expireAt: { required: true, message: this.$t('validate.required'), switch: false }
|
2021-04-16 21:10:31 +08:00
|
|
|
},
|
|
|
|
|
pickerOptions: {
|
|
|
|
|
// 限制预约时间
|
|
|
|
|
disabledDate (time) {
|
|
|
|
|
return time.getTime() < Date.now() - 24 * 60 * 60 * 1000
|
|
|
|
|
}
|
2022-06-27 10:10:49 +08:00
|
|
|
},
|
|
|
|
|
reg: new RegExp("(?<=.{8}).", 'g')
|
2021-04-16 21:10:31 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
addApiKey: function () {
|
|
|
|
|
if (this.tableData.every(t => !t.edit)) {
|
|
|
|
|
this.tableData.unshift({
|
|
|
|
|
id: '',
|
|
|
|
|
name: '',
|
2021-04-21 18:24:25 +08:00
|
|
|
role: {
|
2021-04-16 21:10:31 +08:00
|
|
|
id: '',
|
|
|
|
|
name: ''
|
|
|
|
|
},
|
|
|
|
|
expireAt: '',
|
|
|
|
|
edit: true
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
this.setWarning()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getRoles: function () {
|
|
|
|
|
this.$get('sys/role?pageSize=-1').then(response => {
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
this.roles = response.data.list
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
save: function (obj) {
|
|
|
|
|
const copy = JSON.parse(JSON.stringify(obj))
|
2022-01-06 13:50:56 +08:00
|
|
|
copy.expireAt = new Date(copy.expireAt).getTime()
|
|
|
|
|
copy.expireAt = this.timezoneToUtcTimeStr(copy.expireAt, 'YYYY-MM-DD HH:mm:ss')
|
2021-04-21 18:24:25 +08:00
|
|
|
if (copy.role) {
|
|
|
|
|
copy.roleId = copy.role.id
|
2021-04-16 21:10:31 +08:00
|
|
|
}
|
2021-04-21 18:24:25 +08:00
|
|
|
delete copy.role
|
2021-04-16 21:10:31 +08:00
|
|
|
this.saveOrUpdate(copy)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
mounted () {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</script>
|