UnisKB/ui/src/views/application/index.vue

446 lines
14 KiB
Vue
Raw Normal View History

2023-11-15 09:42:31 +00:00
<template>
2023-12-04 08:55:54 +00:00
<div class="application-list-container p-24" style="padding-top: 16px">
2023-12-04 09:24:00 +00:00
<div class="flex-between mb-16">
2025-01-13 03:15:51 +00:00
<h4>{{ $t('views.application.title') }}</h4>
<div class="flex-between">
2024-11-19 09:05:09 +00:00
<el-select
v-model="selectUserId"
class="mr-12"
@change="searchHandle"
style="max-width: 240px; width: 150px"
>
<el-option
v-for="item in userOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-input
v-model="searchValue"
@change="searchHandle"
2025-01-13 03:15:51 +00:00
:placeholder="$t('views.application.searchBar.placeholder')"
prefix-icon="Search"
class="w-240"
2024-11-19 09:05:09 +00:00
style="min-width: 240px"
clearable
/>
</div>
2023-11-23 09:20:19 +00:00
</div>
2023-12-11 02:35:26 +00:00
<div v-loading.fullscreen.lock="paginationConfig.current_page === 1 && loading">
<InfiniteScroll
:size="applicationList.length"
:total="paginationConfig.total"
:page_size="paginationConfig.page_size"
v-model:current_page="paginationConfig.current_page"
@load="getList"
:loading="loading"
2023-11-23 09:20:19 +00:00
>
2023-12-11 02:35:26 +00:00
<el-row :gutter="15">
<el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6" class="mb-16">
2024-12-25 03:49:34 +00:00
<el-card shadow="hover" class="application-card-add" style="--el-card-padding: 8px">
<div class="card-add-button flex align-center cursor p-8" @click="openCreateDialog">
<AppIcon iconName="app-add-application" class="mr-8"></AppIcon>
2025-01-13 03:15:51 +00:00
{{ $t('views.application.createApplication') }}
2024-12-25 03:49:34 +00:00
</div>
<el-divider style="margin: 8px 0" />
<el-upload
ref="elUploadRef"
2024-12-25 03:49:34 +00:00
:file-list="[]"
action="#"
multiple
:auto-upload="false"
:show-file-list="false"
:limit="1"
:on-change="(file: any, fileList: any) => importApplication(file)"
class="card-add-button"
>
<div class="flex align-center cursor p-8">
2025-01-13 03:15:51 +00:00
<AppIcon iconName="app-import" class="mr-8"></AppIcon>
{{ $t('views.application.importApplication') }}
2024-12-25 03:49:34 +00:00
</div>
</el-upload>
</el-card>
2023-12-11 02:35:26 +00:00
</el-col>
<el-col
:xs="24"
:sm="12"
:md="8"
:lg="6"
:xl="6"
2023-12-11 02:35:26 +00:00
v-for="(item, index) in applicationList"
:key="index"
class="mb-16"
2023-11-15 09:42:31 +00:00
>
2023-12-11 02:35:26 +00:00
<CardBox
:title="item.name"
:description="item.desc"
class="application-card cursor"
2024-07-01 01:45:59 +00:00
@click="router.push({ path: `/application/${item.id}/${item.type}/overview` })"
2023-12-11 02:35:26 +00:00
>
<template #icon>
<AppAvatar
v-if="isAppIcon(item?.icon)"
shape="square"
:size="32"
style="background: none"
class="mr-8"
>
<img :src="item?.icon" alt="" />
</AppAvatar>
<AppAvatar
v-else-if="item?.name"
:name="item?.name"
2023-12-11 02:35:26 +00:00
pinyinColor
shape="square"
:size="32"
class="mr-8"
2023-12-11 02:35:26 +00:00
/>
</template>
2024-11-05 11:13:34 +00:00
<template #subTitle>
2024-11-22 08:27:43 +00:00
<el-text class="color-secondary" size="small">
2024-11-05 11:13:34 +00:00
<auto-tooltip :content="item.username">
2025-01-13 03:15:51 +00:00
{{ $t('common.creator') }}: {{ item.username }}
2024-11-05 11:13:34 +00:00
</auto-tooltip>
</el-text>
</template>
2024-07-01 01:45:59 +00:00
<div class="status-tag">
2025-01-13 03:15:51 +00:00
<el-tag type="warning" v-if="isWorkFlow(item.type)" style="height: 22px">
2025-01-21 07:59:00 +00:00
{{ $t('views.application.workflow') }}
</el-tag>
2025-01-13 03:15:51 +00:00
<el-tag class="blue-tag" v-else style="height: 22px">
{{ $t('views.application.simple') }}
</el-tag>
2024-07-01 01:45:59 +00:00
</div>
2023-11-23 09:20:19 +00:00
2023-12-11 02:35:26 +00:00
<template #footer>
<div class="footer-content">
2024-05-22 10:01:50 +00:00
<el-tooltip
effect="dark"
2025-01-13 03:15:51 +00:00
:content="$t('views.application.setting.demo')"
2024-05-22 10:01:50 +00:00
placement="top"
>
2023-12-11 02:35:26 +00:00
<el-button text @click.stop @click="getAccessToken(item.id)">
<AppIcon iconName="app-view"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
2025-01-13 03:15:51 +00:00
<el-tooltip effect="dark" :content="$t('common.setting')" placement="top">
2024-07-01 01:45:59 +00:00
<el-button text @click.stop="settingApplication(item)">
2023-12-11 02:35:26 +00:00
<AppIcon iconName="Setting"></AppIcon>
</el-button>
</el-tooltip>
<el-divider direction="vertical" />
2024-08-19 03:24:19 +00:00
<span @click.stop>
<el-dropdown trigger="click">
<el-button text @click.stop>
<el-icon><MoreFilled /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
2024-08-26 03:21:40 +00:00
<el-dropdown-item
v-if="is_show_copy_button(item)"
@click="copyApplication(item)"
>
2024-08-19 03:24:19 +00:00
<AppIcon iconName="app-copy"></AppIcon>
2025-01-13 03:15:51 +00:00
{{ $t('common.copy') }}
</el-dropdown-item>
2024-12-18 10:26:45 +00:00
<el-dropdown-item @click.stop="exportApplication(item)">
<AppIcon iconName="app-export"></AppIcon>
2025-01-13 03:15:51 +00:00
{{ $t('common.export') }}
</el-dropdown-item>
2024-08-19 03:24:19 +00:00
<el-dropdown-item icon="Delete" @click.stop="deleteApplication(item)">{{
2025-01-13 03:15:51 +00:00
$t('common.delete')
2024-08-19 03:24:19 +00:00
}}</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</span>
2023-12-11 02:35:26 +00:00
</div>
</template>
</CardBox>
</el-col>
</el-row>
</InfiniteScroll>
2023-11-15 09:42:31 +00:00
</div>
2024-07-01 01:45:59 +00:00
<CreateApplicationDialog ref="CreateApplicationDialogRef" />
2024-08-21 06:54:26 +00:00
<CopyApplicationDialog ref="CopyApplicationDialogRef" />
2023-11-23 09:20:19 +00:00
</div>
</template>
<script setup lang="ts">
2024-05-20 09:50:14 +00:00
import { ref, onMounted, reactive } from 'vue'
2023-11-23 09:20:19 +00:00
import applicationApi from '@/api/application'
2024-07-01 01:45:59 +00:00
import CreateApplicationDialog from './component/CreateApplicationDialog.vue'
2024-08-19 03:24:19 +00:00
import CopyApplicationDialog from './component/CopyApplicationDialog.vue'
import { MsgSuccess, MsgConfirm, MsgAlert, MsgError } from '@/utils/message'
import { isAppIcon } from '@/utils/application'
2023-11-23 09:20:19 +00:00
import { useRouter } from 'vue-router'
2024-07-01 01:45:59 +00:00
import { isWorkFlow } from '@/utils/application'
2024-09-18 03:03:04 +00:00
import { ValidType, ValidCount } from '@/enums/common'
2024-05-18 03:29:42 +00:00
import { t } from '@/locales'
2024-09-18 03:03:04 +00:00
import useStore from '@/stores'
2025-01-21 07:59:00 +00:00
import { reject } from 'lodash'
const elUploadRef = ref<any>()
2024-09-18 03:03:04 +00:00
const { application, user, common } = useStore()
2023-11-23 09:20:19 +00:00
const router = useRouter()
2024-08-19 03:24:19 +00:00
const CopyApplicationDialogRef = ref()
2024-07-01 01:45:59 +00:00
const CreateApplicationDialogRef = ref()
2023-11-23 09:20:19 +00:00
const loading = ref(false)
2023-12-06 11:09:54 +00:00
const applicationList = ref<any[]>([])
2023-12-11 02:35:26 +00:00
const paginationConfig = reactive({
2023-11-23 09:20:19 +00:00
current_page: 1,
2024-12-10 03:01:35 +00:00
page_size: 30,
2023-12-06 11:09:54 +00:00
total: 0
2023-11-23 09:20:19 +00:00
})
2025-01-21 07:59:00 +00:00
interface UserOption {
label: string
value: string
}
const userOptions = ref<UserOption[]>([])
const selectUserId = ref('all')
2023-11-23 09:20:19 +00:00
2023-12-06 11:09:54 +00:00
const searchValue = ref('')
2023-11-23 09:20:19 +00:00
const apiInputParams = ref([])
2024-08-19 03:24:19 +00:00
function copyApplication(row: any) {
application.asyncGetApplicationDetail(row.id, loading).then((res: any) => {
2025-01-21 07:59:00 +00:00
if (res?.data) {
CopyApplicationDialogRef.value.open({ ...res.data, model_id: res.data.model })
}
})
2024-08-19 03:24:19 +00:00
}
2024-08-26 03:21:40 +00:00
const is_show_copy_button = (row: any) => {
return user.userInfo ? user.userInfo.id == row.user_id : false
}
2025-01-21 07:59:00 +00:00
2024-07-01 01:45:59 +00:00
function settingApplication(row: any) {
if (isWorkFlow(row.type)) {
router.push({ path: `/application/${row.id}/workflow` })
} else {
router.push({ path: `/application/${row.id}/${row.type}/setting` })
}
}
2025-01-21 07:59:00 +00:00
const exportApplication = (application: any) => {
applicationApi.exportApplication(application.id, application.name, loading).catch((e) => {
if (e.response.status !== 403) {
e.response.data.text().then((res: string) => {
2025-01-21 07:59:00 +00:00
MsgError(`${t('views.application.tip.ExportError')}:${JSON.parse(res).message}`)
})
}
})
}
const importApplication = (file: any) => {
const formData = new FormData()
formData.append('file', file.raw, file.name)
elUploadRef.value.clearFiles()
2025-01-21 07:59:00 +00:00
applicationApi
.importApplication(formData, loading)
.then(async (res: any) => {
if (res?.data) {
searchHandle()
}
})
.catch((e) => {
if (e.code === 400) {
MsgConfirm(t('common.tip'), t('views.application.tip.professionalMessage'), {
cancelButtonText: t('common.confirm'),
confirmButtonText: t('common.professional')
}).then(() => {
window.open('https://maxkb.cn/pricing.html', '_blank')
})
}
})
}
2025-01-21 07:59:00 +00:00
2024-07-01 01:45:59 +00:00
function openCreateDialog() {
2025-01-21 07:59:00 +00:00
common
.asyncGetValid(ValidType.Application, ValidCount.Application, loading)
.then(async (res: any) => {
if (res?.data) {
CreateApplicationDialogRef.value.open()
} else if (res?.code === 400) {
MsgConfirm(t('common.tip'), t('views.application.tip.professionalMessage'), {
cancelButtonText: t('common.confirm'),
confirmButtonText: t('common.professional')
}).then(() => {
window.open('https://maxkb.cn/pricing.html', '_blank')
})
2025-01-13 03:15:51 +00:00
}
2025-01-21 07:59:00 +00:00
})
2024-07-01 01:45:59 +00:00
}
2023-12-06 11:09:54 +00:00
function searchHandle() {
if (user.userInfo) {
localStorage.setItem(user.userInfo.id + 'application', selectUserId.value)
}
2023-12-06 11:09:54 +00:00
applicationList.value = []
paginationConfig.current_page = 1
paginationConfig.total = 0
2023-11-23 09:20:19 +00:00
getList()
}
function mapToUrlParams(map: any[]) {
const params = new URLSearchParams()
map.forEach((item: any) => {
params.append(encodeURIComponent(item.name), encodeURIComponent(item.value))
})
return params.toString() // 返回 URL 查询字符串
}
2023-11-30 10:50:42 +00:00
function getAccessToken(id: string) {
2024-12-17 09:36:58 +00:00
applicationList.value
.filter((app) => app.id === id)[0]
?.work_flow?.nodes?.filter((v: any) => v.id === 'base-node')
.map((v: any) => {
apiInputParams.value = v.properties.api_input_field_list
? v.properties.api_input_field_list.map((v: any) => {
return {
name: v.variable,
value: v.default_value
}
})
: v.properties.input_field_list
? v.properties.input_field_list
.filter((v: any) => v.assignment_method === 'api_input')
.map((v: any) => {
return {
name: v.variable,
value: v.default_value
}
})
: []
2024-12-17 09:36:58 +00:00
})
2024-12-17 09:36:58 +00:00
const apiParams = mapToUrlParams(apiInputParams.value)
? '?' + mapToUrlParams(apiInputParams.value)
: ''
2023-12-11 02:35:26 +00:00
application.asyncGetAccessToken(id, loading).then((res: any) => {
window.open(application.location + res?.data?.access_token + apiParams)
2023-11-30 10:50:42 +00:00
})
}
function deleteApplication(row: any) {
2024-05-18 03:29:42 +00:00
MsgConfirm(
// @ts-ignore
2025-01-13 03:15:51 +00:00
`${t('views.application.delete.confirmTitle')}${row.name} ?`,
t('views.application.delete.confirmMessage'),
2024-05-22 10:01:50 +00:00
{
2025-01-13 03:15:51 +00:00
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),
2024-05-18 03:29:42 +00:00
confirmButtonClass: 'danger'
2024-05-22 10:01:50 +00:00
}
)
2023-11-30 10:50:42 +00:00
.then(() => {
2023-12-12 06:30:03 +00:00
applicationApi.delApplication(row.id, loading).then(() => {
const index = applicationList.value.findIndex((v) => v.id === row.id)
applicationList.value.splice(index, 1)
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.deleteSuccess'))
2023-12-12 06:30:03 +00:00
})
2023-11-30 10:50:42 +00:00
})
.catch(() => {})
}
2023-11-23 09:20:19 +00:00
function getList() {
const params = {
...(searchValue.value && { name: searchValue.value }),
...(selectUserId.value &&
selectUserId.value !== 'all' && { select_user_id: selectUserId.value })
}
applicationApi.getApplication(paginationConfig, params, loading).then((res) => {
res.data.records.forEach((item: any) => {
if (user.userInfo && item.user_id === user.userInfo.id) {
item.username = user.userInfo.username
} else {
item.username = userOptions.value.find((v) => v.value === item.user_id)?.label
}
2023-11-23 09:20:19 +00:00
})
applicationList.value = [...applicationList.value, ...res.data.records]
paginationConfig.total = res.data.total
})
}
2025-01-21 07:59:00 +00:00
function getUserList() {
applicationApi.getUserList('APPLICATION', loading).then((res) => {
if (res.data) {
userOptions.value = res.data.map((item: any) => {
return {
label: item.username,
value: item.id
}
})
if (user.userInfo) {
const selectUserIdValue = localStorage.getItem(user.userInfo.id + 'application')
if (selectUserIdValue && userOptions.value.find((v) => v.value === selectUserIdValue)) {
selectUserId.value = selectUserIdValue
}
}
getList()
}
})
2023-11-23 09:20:19 +00:00
}
onMounted(() => {
getUserList()
2023-11-23 09:20:19 +00:00
})
</script>
<style lang="scss" scoped>
2024-12-25 03:49:34 +00:00
.application-card-add {
width: 100%;
font-size: 14px;
min-height: var(--card-min-height);
border: 1px dashed var(--el-border-color);
background: var(--el-disabled-bg-color);
border-radius: 8px;
box-sizing: border-box;
2025-01-21 07:59:00 +00:00
2024-12-25 03:49:34 +00:00
&:hover {
border: 1px solid var(--el-card-bg-color);
background-color: var(--el-card-bg-color);
}
2025-01-21 07:59:00 +00:00
2024-12-25 03:49:34 +00:00
.card-add-button {
&:hover {
border-radius: 4px;
background: var(--app-text-color-light-1);
}
2025-01-21 07:59:00 +00:00
2024-12-25 03:49:34 +00:00
:deep(.el-upload) {
display: block;
width: 100%;
color: var(--el-text-color-regular);
}
}
}
2025-01-21 07:59:00 +00:00
2023-11-23 09:20:19 +00:00
.application-card {
.status-tag {
position: absolute;
right: 16px;
2024-11-05 11:13:34 +00:00
top: 15px;
2023-11-15 09:42:31 +00:00
}
2023-11-23 09:20:19 +00:00
}
2025-01-21 07:59:00 +00:00
2023-11-23 09:20:19 +00:00
.dropdown-custom-switch {
padding: 5px 11px;
font-size: 14px;
font-weight: 400;
2025-01-21 07:59:00 +00:00
2023-11-23 09:20:19 +00:00
span {
margin-right: 26px;
}
}
</style>