Skip to content

Commit

Permalink
feat: 函数支持设置权限和应用显示开关
Browse files Browse the repository at this point in the history
  • Loading branch information
wangdan-fit2cloud committed Sep 18, 2024
1 parent c2217aa commit 9561961
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 24 deletions.
7 changes: 4 additions & 3 deletions ui/src/api/type/function-lib.ts
Original file line number Diff line number Diff line change
@@ -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 }
2 changes: 1 addition & 1 deletion ui/src/views/application/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ onMounted(() => {
.status-tag {
position: absolute;
right: 16px;
top: 20px;
top: 13px;
}
}
.dropdown-custom-switch {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/dataset/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ onMounted(() => {
.delete-button {
position: absolute;
right: 12px;
top: 18px;
top: 13px;
height: auto;
}
.footer-content {
Expand Down
9 changes: 5 additions & 4 deletions ui/src/views/function-lib/component/FunctionFormDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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="描述">
Expand All @@ -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>
Expand Down Expand Up @@ -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() {
Expand Down
85 changes: 70 additions & 15 deletions ui/src/views/function-lib/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -89,6 +107,7 @@ const paginationConfig = reactive({
const searchValue = ref('')
const title = ref('')
const changeStateloading = ref(false)
function openCreateDialog(data?: any) {
title.value = data ? '编辑函数' : '创建函数'
Expand All @@ -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} ?`,
Expand Down Expand Up @@ -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>

0 comments on commit 9561961

Please sign in to comment.