feat: 函数支持设置权限和应用显示开关

This commit is contained in:
wangdan-fit2cloud 2024-09-18 10:34:49 +08:00 committed by wangdan-fit2cloud
parent c2217aa19e
commit 9561961d0f
5 changed files with 81 additions and 24 deletions

View File

@ -1,10 +1,11 @@
interface functionLibData {
id?: String
name: String
desc: String
name?: String
desc?: String
code?: String
permission_type: 'PRIVATE' | 'PUBLIC'
permission_type?: 'PRIVATE' | 'PUBLIC'
input_field_list?: Array<any>
is_active?: Boolean
}
export type { functionLibData }

View File

@ -222,7 +222,7 @@ onMounted(() => {
.status-tag {
position: absolute;
right: 16px;
top: 20px;
top: 13px;
}
}
.dropdown-custom-switch {

View File

@ -198,7 +198,7 @@ onMounted(() => {
.delete-button {
position: absolute;
right: 12px;
top: 18px;
top: 13px;
height: auto;
}
.footer-content {

View File

@ -19,7 +19,7 @@
placeholder="请输入函数名称"
maxlength="64"
show-word-limit
@blur="form.name = form.name.trim()"
@blur="form.name = form.name?.trim()"
/>
</el-form-item>
<el-form-item label="描述">
@ -30,10 +30,10 @@
maxlength="128"
show-word-limit
:autosize="{ minRows: 3 }"
@blur="form.desc = form.desc.trim()"
@blur="form.desc = form.desc?.trim()"
/>
</el-form-item>
<el-form-item prop="permission_type" :rules="form.permission_type">
<el-form-item prop="permission_type">
<template #label>
<span>权限</span>
</template>
@ -207,7 +207,8 @@ watch(visible, (bool) => {
})
const rules = reactive({
name: [{ required: true, message: '请输入函数名称', trigger: 'blur' }]
name: [{ required: true, message: '请输入函数名称', trigger: 'blur' }],
permission_type: [{ required: true, message: '请选择', trigger: 'change' }]
})
function openCodemirrorDialog() {

View File

@ -11,7 +11,11 @@
clearable
/>
</div>
<div v-loading.fullscreen.lock="paginationConfig.current_page === 1 && loading">
<div
v-loading.fullscreen.lock="
(paginationConfig.current_page === 1 && loading) || changeStateloading
"
>
<InfiniteScroll
:size="functionLibList.length"
:total="paginationConfig.total"
@ -45,20 +49,34 @@
<img src="@/assets/icon_function_outlined.svg" style="width: 58%" alt="" />
</AppAvatar>
</template>
<div class="status-button">
<el-tag class="info-tag" v-if="item.permission_type === 'PUBLIC'">公用</el-tag>
<el-tag class="danger-tag" v-else-if="item.permission_type === 'PRIVATE'"
>私有</el-tag
>
</div>
<template #footer>
<div class="footer-content">
<el-tooltip effect="dark" content="复制" placement="top">
<el-button text @click.stop="copyFunctionLib(item)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
<el-tooltip effect="dark" content="删除" placement="top">
<el-button text @click.stop="deleteFunctionLib(item)">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
<div class="footer-content flex-between">
<div>
<el-tooltip effect="dark" content="复制" placement="top">
<el-button text @click.stop="copyFunctionLib(item)">
<AppIcon iconName="app-copy"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
<el-tooltip effect="dark" content="删除" placement="top">
<el-button text @click.stop="deleteFunctionLib(item)">
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
</div>
<div @click.stop>
<el-switch
v-model="item.is_active"
@change="changeState($event, item)"
size="small"
/>
</div>
</div>
</template>
</CardBox>
@ -89,6 +107,7 @@ const paginationConfig = reactive({
const searchValue = ref('')
const title = ref('')
const changeStateloading = ref(false)
function openCreateDialog(data?: any) {
title.value = data ? '编辑函数' : '创建函数'
@ -102,6 +121,33 @@ function searchHandle() {
getList()
}
function changeState(bool: Boolean, row: any) {
if (!bool) {
MsgConfirm(
`是否禁用函数:${row.name} ?`,
`禁用后,引用了该函数的应用提问时会报错 ,请谨慎操作。`,
{
confirmButtonText: '禁用',
confirmButtonClass: 'danger'
}
)
.then(() => {
const obj = {
is_active: bool
}
functionLibApi.putFunctionLib(row.id, obj, changeStateloading).then((res) => {})
})
.catch(() => {
row.is_active = true
})
} else {
const obj = {
is_active: bool
}
functionLibApi.putFunctionLib(row.id, obj, changeStateloading).then((res) => {})
}
}
function deleteFunctionLib(row: any) {
MsgConfirm(
`是否删除函数:${row.name} ?`,
@ -155,4 +201,13 @@ onMounted(() => {
getList()
})
</script>
<style lang="scss" scoped></style>
<style lang="scss" scoped>
.function-lib-list-container {
.status-button {
position: absolute;
right: 12px;
top: 13px;
height: auto;
}
}
</style>