UnisKB/ui/src/views/team/component/PermissionSetting.vue

148 lines
3.9 KiB
Vue
Raw Normal View History

2023-10-23 09:48:34 +00:00
<template>
2023-12-08 09:44:41 +00:00
<el-input
v-model="filterText"
placeholder="搜索"
prefix-icon="Search"
class="p-24 pt-0 pb-0 mb-16 mt-4"
clearable
2023-12-08 09:44:41 +00:00
/>
<div class="p-24 pt-0">
2024-02-22 09:55:29 +00:00
<el-table :data="filterData" :max-height="tableHeight">
2023-12-18 03:32:29 +00:00
<el-table-column prop="name" :label="isApplication ? '应用名称' : '知识库名称'">
2023-12-08 09:44:41 +00:00
<template #default="{ row }">
<div class="flex align-center">
<AppAvatar
v-if="isApplication"
:name="row.name"
pinyinColor
class="mr-12"
shape="square"
:size="24"
2024-03-06 05:58:04 +00:00
style="flex-shrink: 0"
2023-12-08 09:44:41 +00:00
/>
2024-03-06 05:58:04 +00:00
<AppAvatar
v-else-if="isDataset"
class="mr-12"
shape="square"
:size="24"
style="flex-shrink: 0"
>
2023-12-08 09:44:41 +00:00
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
</AppAvatar>
2024-03-06 05:58:04 +00:00
<auto-tooltip :content="row?.name">
{{ row?.name }}
</auto-tooltip>
2023-12-08 09:44:41 +00:00
</div>
</template>
</el-table-column>
<el-table-column label="管理" align="center" width="60">
<!-- <template #header>
2023-10-24 07:31:30 +00:00
<el-checkbox
v-model="allChecked[MANAGE]"
label="管理"
@change="handleCheckAllChange($event, MANAGE)"
/>
2023-11-07 07:30:15 +00:00
</template> -->
2023-12-08 09:44:41 +00:00
<template #default="{ row }">
2024-02-23 09:55:55 +00:00
<el-checkbox
:disabled="props.manage"
v-model="row.operate[MANAGE]"
@change="checkedOperateChange(MANAGE, row)"
/>
2023-12-08 09:44:41 +00:00
</template>
</el-table-column>
<el-table-column label="使用" align="center" width="60">
<!-- <template #header>
2023-10-24 07:31:30 +00:00
<el-checkbox
v-model="allChecked[USE]"
label="使用"
@change="handleCheckAllChange($event, USE)"
/>
2023-11-07 07:30:15 +00:00
</template> -->
2023-12-08 09:44:41 +00:00
<template #default="{ row }">
2024-02-23 09:55:55 +00:00
<el-checkbox
:disabled="props.manage"
v-model="row.operate[USE]"
@change="checkedOperateChange(USE, row)"
/>
2023-12-08 09:44:41 +00:00
</template>
</el-table-column>
</el-table>
</div>
2023-10-23 09:48:34 +00:00
</template>
<script setup lang="ts">
2023-12-04 03:18:12 +00:00
import { ref, onMounted, watch, computed } from 'vue'
import { MANAGE, USE, DATASET, APPLICATION } from './../utils'
2023-10-23 09:48:34 +00:00
2023-10-24 07:31:30 +00:00
const props = defineProps({
data: {
type: Array,
default: () => []
},
2023-12-04 03:18:12 +00:00
id: String,
2023-12-08 09:44:41 +00:00
type: String,
2024-02-23 09:55:55 +00:00
tableHeight: Number,
manage: Boolean
2023-10-24 07:31:30 +00:00
})
2023-12-04 03:18:12 +00:00
const isDataset = computed(() => props.type === DATASET)
const isApplication = computed(() => props.type === APPLICATION)
2023-10-24 07:31:30 +00:00
const emit = defineEmits(['update:data'])
const allChecked: any = ref({
[MANAGE]: false,
[USE]: false
})
2023-11-02 10:25:09 +00:00
const filterText = ref('')
const filterData = computed(() => props.data.filter((v: any) => v.name.includes(filterText.value)))
2024-02-22 09:55:29 +00:00
2023-10-24 07:31:30 +00:00
watch(
() => props.data,
(val) => {
Object.keys(allChecked.value).map((item) => {
allChecked.value[item] = compare(item)
})
emit('update:data', val)
},
{
deep: true
}
)
function handleCheckAllChange(val: string | number | boolean, Name: string | number) {
if (val) {
props.data.map((item: any) => {
item.operate[Name] = true
})
} else {
props.data.map((item: any) => {
item.operate[Name] = false
})
}
}
function checkedOperateChange(Name: string | number, row: any) {
2023-11-07 07:30:15 +00:00
if (Name === MANAGE && row.operate[MANAGE]) {
2023-10-24 07:31:30 +00:00
props.data.map((item: any) => {
if (item.id === row.id) {
item.operate[USE] = true
}
})
}
allChecked.value[Name] = compare(Name)
}
2023-10-23 09:48:34 +00:00
2023-10-24 07:31:30 +00:00
function compare(attrs: string | number) {
const filterData = props.data.filter((item: any) => item?.operate[attrs])
return props.data.length > 0 && filterData.length === props.data.length
}
2023-10-23 09:48:34 +00:00
onMounted(() => {
2023-10-24 07:31:30 +00:00
Object.keys(allChecked.value).map((item) => {
allChecked.value[item] = compare(item)
})
2023-10-23 09:48:34 +00:00
})
</script>
<style lang="scss" scope></style>
2024-03-20 02:38:59 +00:00
../utils