index.vue
4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<script lang="ts" setup name="Popover">
import { ref, unref } from "vue";
import { Search, QuestionFilled } from "@element-plus/icons-vue";
import Table from "../Table/index.vue";
const props = defineProps({
popoverInfo: {
type: Object,
default: {},
},
});
const emits = defineEmits(["showPopver", "popverBtnClick"]);
const popoverRef = ref()
const inputValue = ref("");
const checkAll = ref(false);
const checkedVal: any = ref([])
const authorities: any = ref([])
const isIndeterminate = ref(false);
const size = computed(() => {
return props.popoverInfo.size ?? 230;
})
const placement = computed(() => {
return props.popoverInfo.placement ?? 'bottom-end';
})
const offset = computed(() => {
return props.popoverInfo.offset ?? 0;
})
const trigger = computed(() => {
return props.popoverInfo.trigger ?? 'click';
})
const type = computed(() => {
return props.popoverInfo.type ?? '';
})
const tableInfo = computed(() => {
return props.popoverInfo.tableInfo ?? {}
})
const actionInfo = computed(() => {
return props.popoverInfo.actionInfo ?? {}
})
const btn = computed(() => {
return props.popoverInfo.btn ?? {};
});
const initAttr = () => {
const data = props.popoverInfo.data ?? []
const check = props.popoverInfo.checked ?? []
checkedVal.value = check
isIndeterminate.value = data.length > 0 && data.length == check.length
authorities.value = data
}
const filterPopover = (val) => {
let data = props.popoverInfo.data ?? []
if (val) {
authorities.value = data.filter(item => item.dataPermissionName.indexOf(val) > -1)
} else {
authorities.value = data
}
}
const handleCheckAllChange = (val) => {
checkedVal.value = val ? authorities.value.map(item => item.guid) : [];
isIndeterminate.value = false;
};
const handleCheckedCitiesChange = (val) => {
const checkedCount = val.length;
checkAll.value = checkedCount === authorities.value.length;
isIndeterminate.value = checkedCount > 0 && checkedCount < authorities.value.length;
};
const showPopver = () => {
inputValue.value = ''
emits('showPopver', props.popoverInfo.scope, btn.value)
}
const btnClick = () => {
let scope = { ...props.popoverInfo.scope }
scope.row.selectedData = checkedVal.value
emits('popverBtnClick', scope, { ...btn.value, value: 'addRolePermise' })
popoverRef.value?.hide()
}
watch(() => props.popoverInfo, async (val) => {
if (val) {
initAttr()
}
})
</script>
<template>
<el-popover ref="popoverRef" :placement="placement" :width="size" :offset="offset" :trigger="trigger"
popper-class="table_cell_popover" :hide-after="100">
<div class="self_content">
<template v-if="type == 'table'">
<Table :tableInfo="tableInfo" :action-info="actionInfo" />
</template>
<template v-else-if="type == 'checkbox-list-btns'">
<div class="content_body">
<el-input v-model.trim="inputValue" placeholder="请输入权限名称" :prefix-icon="Search" clearable
@change="filterPopover" />
<el-checkbox-group v-model="checkedVal" @change="handleCheckedCitiesChange">
<el-checkbox v-for="auth in authorities" :key="auth.guid" :label="auth.guid">{{ auth.dataPermissionName
}}</el-checkbox>
</el-checkbox-group>
</div>
<div class="content_foot">
<div class="selector">
<el-checkbox v-model="checkAll" :indeterminate="isIndeterminate" @change="handleCheckAllChange">
全选
</el-checkbox>
<span>已选<span style="color: #4fa1a4; margin: 0 2px;">{{ checkedVal.length }}</span>项</span>
</div>
<el-button size="small" type="primary" @click="btnClick" v-preReClick>确定</el-button>
</div>
</template>
</div>
<template #reference>
<span v-if="btn.value == 'authority'" @click="showPopver" v-preReClick>{{ btn.label }}</span>
<el-icon v-else-if="btn.value == 'QuestionFilled'">
<QuestionFilled />
</el-icon>
<span v-else></span>
</template>
</el-popover>
</template>
<style lang="scss" scoped>
.self_content {
:deep(.table_panel) {
min-height: unset;
}
}
.content_body {
padding: 8px 8px 0;
}
.el-checkbox-group {
margin: 8px -8px 0;
max-height: 276px;
overflow: hidden auto;
.el-checkbox {
--el-checkbox-font-size: 12px;
display: flex;
align-items: center;
margin-right: 0;
padding: 0 8px;
color: var(--el-color-regular);
&:hover {
background-color: var(--el-menu-hover-bg-color);
}
}
}
.content_foot {
height: 40px;
padding: 0 8px;
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
box-shadow: 0 -1px 0 0 #d9d9d9;
.selector {
display: flex;
align-items: center;
>span {
margin-left: 12px;
color: #999;
}
}
.el-checkbox {
--el-checkbox-font-size: 12px;
color: var(--el-color-regular);
}
}
</style>