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/elementSet.vue

188 lines
5.3 KiB
Vue
Raw Normal View History

<template>
<div class="pop-custom" v-clickoutside="esc">
2020-01-17 16:06:35 +08:00
<div class="pop-title">{{$t('overall.select')}}</div>
<div class="pop-box custom-labels">
2020-12-14 20:25:24 +08:00
<div style="height: 100%; overflow: auto;">
<!--NotSet 为true不可设置-->
<div
v-for="(item,index) in custom"
:key="index"
class="custom-label"
@click="handler(item,index)"
:id="'element-set-el-'+index"
2020-09-08 11:18:18 +08:00
:class="{'custom-title orange-font':item.type == 'title','custom-label-disabled':!allowedAll&&!item.allowed && (index==0 || index == 1 || item.NotSet)}"
>
2020-09-10 17:00:32 +08:00
<i class="nz-icon nz-icon-check" v-if="!allowedAll&&!item.allowed&&(index==0||index==1||item.visibility=='disabled')"></i>
<i v-else class="nz-icon nz-icon-check" v-show="item.show"></i>
<span>{{item.label}}</span>
</div>
2020-09-08 11:18:18 +08:00
2020-12-14 20:25:24 +08:00
</div>
</div>
<div class="custom-bottom-btns">
2021-04-14 18:35:42 +08:00
<button v-if="isCancel" :id="tableId+'-element-set-none'" class="nz-btn nz-btn-size-small-new nz-btn-style-light-new is-cancel" type="button" @click="batchHandler(false)">
2020-02-17 18:20:14 +08:00
<span class="top-tool-btn-txt">{{$t('overall.clear')}}</span>
</button>
2021-04-14 18:35:42 +08:00
<button v-if="!isCancel" :id="tableId+'-element-set-all'" class="nz-btn nz-btn-size-small-new nz-btn-style-light-new" type="button" @click="batchHandler(true)">
<span class="top-tool-btn-txt">{{$t('overall.all')}}</span>
</button>
2020-02-17 18:20:14 +08:00
<div>
2021-04-14 18:35:42 +08:00
<button :id="tableId+'-element-set-esc'" class="nz-btn nz-btn-size-small-new nz-btn-style-light-new" type="button" @click="esc">
2020-02-17 18:20:14 +08:00
<span class="top-tool-btn-txt">{{$t('overall.esc')}}</span>
</button>
2021-04-14 18:35:42 +08:00
<button :id="tableId+'-element-set-save'" class="nz-btn nz-btn-size-small-new nz-btn-style-normal-new" type="button" @click="save">
2020-02-17 18:20:14 +08:00
<span class="top-tool-btn-txt">{{$t('overall.save')}}</span>
</button>
</div>
</div>
</div>
</template>
<script>
export default {
2021-03-19 18:52:19 +08:00
props: {
customTableTitle: Array, // 自定义的title
originalTableTitle: Array, // 原始title
2021-04-14 18:35:42 +08:00
tableId: String,
allowedAll: { default: false }
},
2021-03-19 18:52:19 +08:00
data () {
return {
2021-03-19 18:52:19 +08:00
custom: []
}
},
2021-03-19 18:52:19 +08:00
created () {
2021-04-14 18:35:42 +08:00
const localStorageTitle = JSON.parse(localStorage.getItem('nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.tableId))
2021-03-19 18:52:19 +08:00
if (localStorageTitle) {
2021-04-14 18:35:42 +08:00
localStorage.setItem('nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.tableId, JSON.stringify(localStorageTitle))
}
},
watch: {
customTableTitle: {
immediate: true,
deep: true,
2021-03-19 18:52:19 +08:00
handler (n) {
this.custom = JSON.parse(JSON.stringify(n))
}
}
},
methods: {
2021-03-19 18:52:19 +08:00
// 悬浮点击空白隐藏
esc () {
this.$emit('close')
},
2021-03-19 18:52:19 +08:00
// 全选all true 或者全取消cancel false按钮
batchHandler (state) {
for (let index = 0; index < this.custom.length; index++) {
2021-03-19 18:52:19 +08:00
if (this.custom[index].type != 'title') {
2020-11-03 17:29:14 +08:00
if ((index == 0 || index == 1 || this.custom[index].NotSet)) {
2021-03-19 18:52:19 +08:00
this.custom[index].show = true
2020-11-03 17:29:14 +08:00
} else {
2021-03-19 18:52:19 +08:00
this.custom[index].show = state
2020-11-03 17:29:14 +08:00
}
}
}
},
2021-03-19 18:52:19 +08:00
// 单选
handler (val, index) {
if (!this.allowedAll && !val.allowed && (index == 0 || index == 1 || val.NotSet)) {
// this.custom[index].show = true;
} else {
2021-03-19 18:52:19 +08:00
this.custom[index].show = !this.custom[index].show
}
},
2021-03-19 18:52:19 +08:00
// 点击第二个cancel
save () {
if (this.tableId == 'assetTable') {
let customAssetLabel = false
this.custom.forEach(item => {
if (customAssetLabel) {
item.minWidth = item.label.length * 16 + 20
return
}
if (item.label === 'Label' && item.type == 'title') {
customAssetLabel = true
}
})
}
this.$emit('update', this.custom)
localStorage.setItem(
2021-04-14 18:35:42 +08:00
'nz-tableTitle-' + localStorage.getItem('nz-username') + '-' + this.tableId,
JSON.stringify(this.custom)
2021-03-19 18:52:19 +08:00
)
this.esc()
}
},
computed: {
2021-03-19 18:52:19 +08:00
// 点击all是否是全部取消选中true为是
isCancel () {
let isCancel = true
for (let i = 0; i < this.custom.length; i++) {
2021-03-19 18:52:19 +08:00
if (!this.custom[i].show && this.custom[i].type != 'title') {
isCancel = false
break
2020-02-17 18:20:14 +08:00
}
}
2021-03-19 18:52:19 +08:00
return isCancel
2020-02-17 18:20:14 +08:00
}
}
2021-03-19 18:52:19 +08:00
}
</script>
<style lang="scss">
.pop-custom {
2020-01-17 16:06:35 +08:00
padding: 0 12px 12px 12px;
border: 1px solid #EBEEF5;
2020-01-17 16:06:35 +08:00
box-shadow: $pop-box-shadow;
position: absolute;
top: 55px;
right: 20px;
width: 200px;
color: #606266;
background: #fff;
border-radius: 4px;
2020-05-28 17:32:23 +08:00
z-index: 999999;
}
2020-08-06 11:29:11 +08:00
.pop-custom-explore {
top: 33px;
}
.relative-position .pop-custom {
top: 33px;
}
.custom-labels {
2020-02-17 18:20:14 +08:00
margin-top: 12px;
width: 100%;
height: 300px;
}
.custom-labels i {
color: #04b330;
font-size: 14px;
position: absolute;
left: 5px;
top: 6px;
}
.custom-label {
padding: 2px 0 2px 25px;
position: relative;
cursor: default;
font-size: 14px;
}
2020-09-08 11:18:18 +08:00
.custom-title{
padding: 2px 0 2px 2px;
}
.custom-label-disabled {
cursor: not-allowed;
background: #f1f3f4;
opacity: 0.7;
}
.custom-bottom-btns {
margin-top: 7px;
2020-02-17 18:20:14 +08:00
display: flex;
justify-content: space-between;
align-items: center;
}
.unshow {
display: none;
}
</style>