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 { interface functionLibData {
id?: String id?: String
name: String name?: String
desc: String desc?: String
code?: String code?: String
permission_type: 'PRIVATE' | 'PUBLIC' permission_type?: 'PRIVATE' | 'PUBLIC'
input_field_list?: Array<any> input_field_list?: Array<any>
is_active?: Boolean
} }
export type { functionLibData } export type { functionLibData }

View File

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

View File

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

View File

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

View File

@ -11,7 +11,11 @@
clearable clearable
/> />
</div> </div>
<div v-loading.fullscreen.lock="paginationConfig.current_page === 1 && loading"> <div
v-loading.fullscreen.lock="
(paginationConfig.current_page === 1 && loading) || changeStateloading
"
>
<InfiniteScroll <InfiniteScroll
:size="functionLibList.length" :size="functionLibList.length"
:total="paginationConfig.total" :total="paginationConfig.total"
@ -45,20 +49,34 @@
<img src="@/assets/icon_function_outlined.svg" style="width: 58%" alt="" /> <img src="@/assets/icon_function_outlined.svg" style="width: 58%" alt="" />
</AppAvatar> </AppAvatar>
</template> </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> <template #footer>
<div class="footer-content"> <div class="footer-content flex-between">
<el-tooltip effect="dark" content="复制" placement="top"> <div>
<el-button text @click.stop="copyFunctionLib(item)"> <el-tooltip effect="dark" content="复制" placement="top">
<AppIcon iconName="app-copy"></AppIcon> <el-button text @click.stop="copyFunctionLib(item)">
</el-button> <AppIcon iconName="app-copy"></AppIcon>
</el-tooltip> </el-button>
<el-divider direction="vertical" /> </el-tooltip>
<el-tooltip effect="dark" content="删除" placement="top"> <el-divider direction="vertical" />
<el-button text @click.stop="deleteFunctionLib(item)"> <el-tooltip effect="dark" content="删除" placement="top">
<el-icon><Delete /></el-icon> <el-button text @click.stop="deleteFunctionLib(item)">
</el-button> <el-icon><Delete /></el-icon>
</el-tooltip> </el-button>
</el-tooltip>
</div>
<div @click.stop>
<el-switch
v-model="item.is_active"
@change="changeState($event, item)"
size="small"
/>
</div>
</div> </div>
</template> </template>
</CardBox> </CardBox>
@ -89,6 +107,7 @@ const paginationConfig = reactive({
const searchValue = ref('') const searchValue = ref('')
const title = ref('') const title = ref('')
const changeStateloading = ref(false)
function openCreateDialog(data?: any) { function openCreateDialog(data?: any) {
title.value = data ? '编辑函数' : '创建函数' title.value = data ? '编辑函数' : '创建函数'
@ -102,6 +121,33 @@ function searchHandle() {
getList() 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) { function deleteFunctionLib(row: any) {
MsgConfirm( MsgConfirm(
`是否删除函数:${row.name} ?`, `是否删除函数:${row.name} ?`,
@ -155,4 +201,13 @@ onMounted(() => {
getList() getList()
}) })
</script> </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>