|
| 1 | +<template> |
| 2 | + <el-drawer |
| 3 | + v-model="drawerVisible" |
| 4 | + :title="$t('views.system.resourceAuthorization.title')" |
| 5 | + size="60%" |
| 6 | + :append-to-body="true" |
| 7 | + :modal="false" |
| 8 | + > |
| 9 | + <div class="flex-between mb-16"> |
| 10 | + <el-button |
| 11 | + type="primary" |
| 12 | + :disabled="multipleSelection.length === 0" |
| 13 | + @click="openMulConfigureDialog" |
| 14 | + >{{ $t('views.system.resourceAuthorization.setting.configure') }}</el-button |
| 15 | + > |
| 16 | + |
| 17 | + <div class="flex-between complex-search"> |
| 18 | + <el-select |
| 19 | + class="complex-search__left" |
| 20 | + v-model="searchType" |
| 21 | + style="width: 100px" |
| 22 | + @change="search_type_change" |
| 23 | + > |
| 24 | + <el-option :label="$t('views.userManage.userForm.nick_name.label')" value="nick_name" /> |
| 25 | + <el-option :label="$t('views.login.loginForm.username.label')" value="username" /> |
| 26 | + <el-option |
| 27 | + :label="$t('views.model.modelForm.permissionType.label')" |
| 28 | + value="publish_status" |
| 29 | + /> |
| 30 | + </el-select> |
| 31 | + <el-input |
| 32 | + v-if="searchType === 'nick_name'" |
| 33 | + v-model="searchForm.nick_name" |
| 34 | + @change="searchHandle" |
| 35 | + :placeholder="$t('common.search')" |
| 36 | + style="width: 220px" |
| 37 | + clearable |
| 38 | + /> |
| 39 | + <el-input |
| 40 | + v-if="searchType === 'username'" |
| 41 | + v-model="searchForm.username" |
| 42 | + @change="searchHandle" |
| 43 | + :placeholder="$t('common.search')" |
| 44 | + style="width: 220px" |
| 45 | + clearable |
| 46 | + /> |
| 47 | + |
| 48 | + <el-select |
| 49 | + v-else-if="searchType === 'publish_status'" |
| 50 | + v-model="searchForm.publish_status" |
| 51 | + @change="searchHandle" |
| 52 | + filterable |
| 53 | + clearable |
| 54 | + multiple |
| 55 | + collapse-tags |
| 56 | + collapse-tags-tooltip |
| 57 | + style="width: 220px" |
| 58 | + > |
| 59 | + <template v-for="(item, index) in permissionOptions" :key="index"> |
| 60 | + <el-option :label="item.label" :value="item.value" /> |
| 61 | + </template> |
| 62 | + </el-select> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + |
| 66 | + <app-table |
| 67 | + ref="multipleTableRef" |
| 68 | + class="mt-16" |
| 69 | + :data="permissionData" |
| 70 | + :pagination-config="paginationConfig" |
| 71 | + @sizeChange="handleSizeChange" |
| 72 | + @changePage="getPermissionList" |
| 73 | + @selection-change="handleSelectionChange" |
| 74 | + :maxTableHeight="200" |
| 75 | + :row-key="(row: any) => row.id" |
| 76 | + v-loading="loading" |
| 77 | + > |
| 78 | + <el-table-column type="selection" width="55" :reserve-selection="true" /> |
| 79 | + <el-table-column |
| 80 | + prop="nick_name" |
| 81 | + :label="$t('views.userManage.userForm.nick_name.label')" |
| 82 | + min-width="120" |
| 83 | + show-overflow-tooltip |
| 84 | + /> |
| 85 | + <el-table-column |
| 86 | + prop="username" |
| 87 | + min-width="120" |
| 88 | + show-overflow-tooltip |
| 89 | + :label="$t('views.login.loginForm.username.label')" |
| 90 | + /> |
| 91 | + <!-- <el-table-column prop="role_name" :label="$t('views.role.member.role')" width="210"> |
| 92 | + <template #default="{ row }"> |
| 93 | + <el-popover :width="400"> |
| 94 | + <template #reference> |
| 95 | + <TagGroup |
| 96 | + class="cursor" |
| 97 | + style="width: fit-content" |
| 98 | + :tags="row.role_name" |
| 99 | + tooltipDisabled |
| 100 | + /> |
| 101 | + </template> |
| 102 | + <template #default> |
| 103 | + <el-table :data="row.role_workspace"> |
| 104 | + <el-table-column prop="role" :label="$t('views.role.member.role')"> |
| 105 | + </el-table-column> |
| 106 | + <el-table-column prop="workspace" :label="$t('views.workspace.title')"> |
| 107 | + </el-table-column> |
| 108 | + </el-table> |
| 109 | + </template> |
| 110 | + </el-popover> |
| 111 | + </template> |
| 112 | + </el-table-column> --> |
| 113 | + <el-table-column :label="$t('common.operation')" align="left" width="340"> |
| 114 | + <template #default="{ row }"> |
| 115 | + <el-radio-group |
| 116 | + v-model="row.permission" |
| 117 | + @change="(val: any) => permissionsHandle(val, row)" |
| 118 | + > |
| 119 | + <template v-for="(item, index) in permissionOptions" :key="index"> |
| 120 | + <el-radio :value="item.value" class="mr-16">{{ item.label }}</el-radio> |
| 121 | + </template> |
| 122 | + </el-radio-group> |
| 123 | + </template> |
| 124 | + </el-table-column> |
| 125 | + </app-table> |
| 126 | + |
| 127 | + <!-- 批量配置 弹出层 --> |
| 128 | + <el-dialog |
| 129 | + v-model="dialogVisible" |
| 130 | + :title="$t('views.system.resourceAuthorization.setting.configure')" |
| 131 | + destroy-on-close |
| 132 | + @close="closeDialog" |
| 133 | + > |
| 134 | + <el-radio-group v-model="radioPermission" class="radio-block"> |
| 135 | + <template v-for="(item, index) in permissionOptions" :key="index"> |
| 136 | + <el-radio :value="item.value" class="mr-16"> |
| 137 | + <p class="color-text-primary lighter">{{ item.label }}</p> |
| 138 | + <el-text class="color-secondary lighter">{{ item.desc }}</el-text> |
| 139 | + </el-radio> |
| 140 | + </template> |
| 141 | + </el-radio-group> |
| 142 | + <template #footer> |
| 143 | + <div class="dialog-footer mt-24"> |
| 144 | + <el-button @click="closeDialog"> {{ $t('common.cancel') }}</el-button> |
| 145 | + <el-button type="primary" @click="submitDialog"> {{ $t('common.confirm') }}</el-button> |
| 146 | + </div> |
| 147 | + </template> |
| 148 | + </el-dialog> |
| 149 | + </el-drawer> |
| 150 | +</template> |
| 151 | +<script setup lang="ts"> |
| 152 | +import { ref, onMounted, watch, computed, reactive } from 'vue' |
| 153 | +import { permissionOptions } from '@/views/system/resource-authorization/constant' |
| 154 | +import AuthorizationApi from '@/api/system/resource-authorization' |
| 155 | +import { MsgSuccess, MsgConfirm } from '@/utils/message' |
| 156 | +import { t } from '@/locales' |
| 157 | +import useStore from '@/stores' |
| 158 | +const { user } = useStore() |
| 159 | +const props = defineProps<{ |
| 160 | + type: string |
| 161 | +}>() |
| 162 | +
|
| 163 | +const drawerVisible = ref(false) |
| 164 | +const multipleTableRef = ref() |
| 165 | +
|
| 166 | +watch(drawerVisible, (bool) => { |
| 167 | + if (!bool) { |
| 168 | + targetId.value = '' |
| 169 | + searchType.value = 'nick_name' |
| 170 | + searchForm.value = { nick_name: '', username: '', permission: undefined } |
| 171 | + permissionData.value = [] |
| 172 | + paginationConfig.current_page = 1 |
| 173 | + paginationConfig.total = 0 |
| 174 | + multipleSelection.value = [] |
| 175 | + multipleTableRef.value?.clearSelection() |
| 176 | + } |
| 177 | +}) |
| 178 | +
|
| 179 | +const loading = ref(false) |
| 180 | +const targetId = ref('') |
| 181 | +const permissionData = ref<any[]>([]) |
| 182 | +const searchType = ref('nick_name') |
| 183 | +const searchForm = ref<any>({ |
| 184 | + nick_name: '', |
| 185 | + username: '', |
| 186 | + permission: undefined, |
| 187 | +}) |
| 188 | +
|
| 189 | +const search_type_change = () => { |
| 190 | + searchForm.value = { nick_name: '', username: '', permission: undefined } |
| 191 | +} |
| 192 | +
|
| 193 | +const paginationConfig = reactive({ |
| 194 | + current_page: 1, |
| 195 | + page_size: 20, |
| 196 | + total: 0, |
| 197 | +}) |
| 198 | +
|
| 199 | +function handleSizeChange() { |
| 200 | + paginationConfig.current_page = 1 |
| 201 | + getPermissionList() |
| 202 | +} |
| 203 | +function searchHandle() { |
| 204 | + paginationConfig.current_page = 1 |
| 205 | + getPermissionList() |
| 206 | +} |
| 207 | +
|
| 208 | +const multipleSelection = ref<any[]>([]) |
| 209 | +
|
| 210 | +const handleSelectionChange = (val: any[]) => { |
| 211 | + multipleSelection.value = val |
| 212 | +} |
| 213 | +
|
| 214 | +const dialogVisible = ref(false) |
| 215 | +const radioPermission = ref('') |
| 216 | +function openMulConfigureDialog() { |
| 217 | + if (multipleSelection.value.length === 0) { |
| 218 | + return |
| 219 | + } |
| 220 | + dialogVisible.value = true |
| 221 | +} |
| 222 | +function submitDialog() { |
| 223 | + if (multipleSelection.value.length === 0 || !radioPermission.value) { |
| 224 | + return |
| 225 | + } |
| 226 | + const obj = multipleSelection.value.map((item) => ({ |
| 227 | + user_id: item.id, |
| 228 | + permission: radioPermission.value, |
| 229 | + })) |
| 230 | + submitPermissions(obj) |
| 231 | + closeDialog() |
| 232 | +} |
| 233 | +function closeDialog() { |
| 234 | + dialogVisible.value = false |
| 235 | + radioPermission.value = '' |
| 236 | + multipleSelection.value = [] |
| 237 | + multipleTableRef.value?.clearSelection() |
| 238 | +} |
| 239 | +
|
| 240 | +function permissionsHandle(val: any, row: any) { |
| 241 | + const obj = [ |
| 242 | + { |
| 243 | + user_id: row.id, |
| 244 | + permission: val, |
| 245 | + }, |
| 246 | + ] |
| 247 | + submitPermissions(obj) |
| 248 | +} |
| 249 | +
|
| 250 | +function submitPermissions(obj: any) { |
| 251 | + const workspaceId = user.getWorkspaceId() || 'default' |
| 252 | + AuthorizationApi.putWorkspaceResourceAuthorization( |
| 253 | + workspaceId, |
| 254 | + targetId.value, |
| 255 | + props.type, |
| 256 | + obj, |
| 257 | + loading, |
| 258 | + ).then(() => { |
| 259 | + MsgSuccess(t('common.submitSuccess')) |
| 260 | + getPermissionList() |
| 261 | + }) |
| 262 | +} |
| 263 | +const getPermissionList = () => { |
| 264 | + const workspaceId = user.getWorkspaceId() || 'default' |
| 265 | + const params: any = {} |
| 266 | + if (searchForm.value[searchType.value]) { |
| 267 | + params[searchType.value] = searchForm.value[searchType.value] |
| 268 | + } |
| 269 | + AuthorizationApi.getWorkspaceResourceAuthorization( |
| 270 | + workspaceId, |
| 271 | + targetId.value, |
| 272 | + props.type, |
| 273 | + paginationConfig, |
| 274 | + params, |
| 275 | + loading, |
| 276 | + ).then((res) => { |
| 277 | + permissionData.value = res.data.records || [] |
| 278 | + paginationConfig.total = res.data.total || 0 |
| 279 | + }) |
| 280 | +} |
| 281 | +
|
| 282 | +const open = (id: string) => { |
| 283 | + targetId.value = id |
| 284 | + drawerVisible.value = true |
| 285 | + getPermissionList() |
| 286 | +} |
| 287 | +defineExpose({ |
| 288 | + open, |
| 289 | +}) |
| 290 | +</script> |
| 291 | +<style lang="scss" scoped></style> |
0 commit comments