feat: 应用

This commit is contained in:
wangdan-fit2cloud 2023-12-01 15:59:50 +08:00
parent 2cdc72935e
commit c2fe67664f
9 changed files with 88 additions and 75 deletions

View File

@ -1,13 +1,13 @@
<template> <template>
<div> <div>
<el-tooltip effect="dark" content="重新生成" placement="top"> <el-tooltip effect="dark" content="重新生成" placement="top">
<el-button text @click.stop @click="getAccessToken(item.id)"> <el-button text @click.stop>
<AppIcon iconName="VideoPlay"></AppIcon> <AppIcon iconName="VideoPlay"></AppIcon>
</el-button> </el-button>
</el-tooltip> </el-tooltip>
<el-divider direction="vertical" /> <el-divider direction="vertical" />
<el-tooltip effect="dark" content="复制" placement="top"> <el-tooltip effect="dark" content="复制" placement="top">
<el-button text @click="copyClick(item.answer_text)"> <el-button text @click="copyClick(item?.answer_text)">
<AppIcon iconName="app-copy"></AppIcon> <AppIcon iconName="app-copy"></AppIcon>
</el-button> </el-button>
</el-tooltip> </el-tooltip>

View File

@ -109,16 +109,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, nextTick, onUpdated, computed } from 'vue' import { ref, nextTick, onUpdated, computed } from 'vue'
import { useRoute } from 'vue-router'
import OperationButton from './OperationButton.vue' import OperationButton from './OperationButton.vue'
import applicationApi from '@/api/application' import applicationApi from '@/api/application'
import { ChatManagement, type chatType } from '@/api/type/application' import { ChatManagement, type chatType } from '@/api/type/application'
import { randomId } from '@/utils/utils' import { randomId } from '@/utils/utils'
const route = useRoute()
const {
params: { accessToken }
} = route as any
const props = defineProps({ const props = defineProps({
data: { data: {
type: Object, type: Object,
@ -210,6 +204,7 @@ function chatMessage() {
applicationApi.postChatMessage(chartOpenId.value, problem_text).then(async (response) => { applicationApi.postChatMessage(chartOpenId.value, problem_text).then(async (response) => {
inputValue.value = '' inputValue.value = ''
const row = chatList.value.find((item) => item.id === id) const row = chatList.value.find((item) => item.id === id)
if (row) { if (row) {
ChatManagement.addChatRecord(row, 50, loading) ChatManagement.addChatRecord(row, 50, loading)
ChatManagement.write(id) ChatManagement.write(id)
@ -226,6 +221,7 @@ function chatMessage() {
const str = decoder.decode(value, { stream: true }) const str = decoder.decode(value, { stream: true })
if (str && str.startsWith('data:')) { if (str && str.startsWith('data:')) {
const content = JSON?.parse(str.replace('data:', ''))?.content const content = JSON?.parse(str.replace('data:', ''))?.content
if (content) { if (content) {
ChatManagement.append(id, content) ChatManagement.append(id, content)
} }

View File

@ -8,7 +8,7 @@
</el-avatar> </el-avatar>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { pinyin } from 'pinyin-pro'; import { pinyin } from 'pinyin-pro'
import { computed } from 'vue' import { computed } from 'vue'
defineOptions({ name: 'AppAvatar' }) defineOptions({ name: 'AppAvatar' })
const props = defineProps({ const props = defineProps({
@ -26,37 +26,31 @@ const firstUserName = computed(() => {
return props.name?.substring(0, 1) return props.name?.substring(0, 1)
}) })
function getAvatarColour(name: string) { const getAvatarColour = (name: string) => {
const charIndex = pinyin.getFullChars(name).charAt(0).toUpperCase().charCodeAt(0) - 65
const colours = [ const colours = [
'#ACA9E5', '#3370FF',
'#BCC934', '#4954E6',
'#B3CFE8', '#F54A45',
'#DCDEB5', '#00B69D',
'#D65A4A', '#2CA91F',
'#E0C78B', '#98B600',
'#E59191', '#F80F80',
'#E99334', '#D136D1',
'#FF6632', '#F01D94',
'#F4B7EF', '#7F3BF5',
'#F7D407', '#8F959E'
'#F8BB98',
'#2BCBB1',
'#3594F1',
'#486660',
'#4B689F',
'#5976F6',
'#72B1B2',
'#778293',
'#7D6624',
'#82CBB5',
'#837F6A',
'#87B087',
'#9AC0C4',
'#958E55',
'#99E4F2'
] ]
return colours[charIndex] let charIndex = name ? pinyin(name).charAt(0).toUpperCase().charCodeAt(0) - 65 : 0
function getColor() {
if (!colours[charIndex]) {
charIndex -= 10
getColor()
}
return colours[charIndex]
}
return getColor()
} }
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>

View File

@ -3,10 +3,11 @@
<div class="card-header"> <div class="card-header">
<slot name="header"> <slot name="header">
<div class="title flex align-center"> <div class="title flex align-center">
<AppAvatar v-if="!slots.icon && showIcon" class="mr-12" shape="square" :size="32"> <slot name="icon">
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" /> <AppAvatar v-if="showIcon" class="mr-12" shape="square" :size="32">
</AppAvatar> <img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
<slot v-else name="icon"> </slot> </AppAvatar>
</slot>
<h4 class="ellipsis-1" style="width: 100%">{{ title }}</h4> <h4 class="ellipsis-1" style="width: 100%">{{ title }}</h4>
</div> </div>
</slot> </slot>

View File

@ -11,10 +11,19 @@
<template v-for="(item, index) in list" :key="index"> <template v-for="(item, index) in list" :key="index">
<div :class="item.id === id ? 'dropdown-active' : ''"> <div :class="item.id === id ? 'dropdown-active' : ''">
<el-dropdown-item :command="item.id"> <el-dropdown-item :command="item.id">
<div class="flex"> <div class="flex align-center">
<AppAvatar class="mr-12" shape="square" :size="24"> <AppAvatar
v-if="isApplication"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="24"
/>
<AppAvatar v-else-if="isDataset" class="mr-12" shape="square" :size="24">
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" /> <img src="@/assets/icon_document.svg" style="width: 58%" alt="" />
</AppAvatar> </AppAvatar>
<span class="ellipsis-1"> {{ item?.name }}</span> <span class="ellipsis-1"> {{ item?.name }}</span>
</div> </div>
</el-dropdown-item> </el-dropdown-item>

View File

@ -4,9 +4,14 @@
<h4 class="title-decoration-1 mb-16">应用信息</h4> <h4 class="title-decoration-1 mb-16">应用信息</h4>
<el-card shadow="never" class="overview-card"> <el-card shadow="never" class="overview-card">
<div class="title flex align-center"> <div class="title flex align-center">
<AppAvatar class="mr-12" shape="square" :size="32"> <AppAvatar
<img src="@/assets/icon_document.svg" style="width: 58%" alt="" /> v-if="detail?.name"
</AppAvatar> :name="detail?.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
<h4 class="ellipsis-1">{{ detail?.name }}</h4> <h4 class="ellipsis-1">{{ detail?.name }}</h4>
<div class="ml-8" v-if="detail"> <div class="ml-8" v-if="detail">
<el-tag v-if="detail?.status" class="success-tag">运行中</el-tag> <el-tag v-if="detail?.status" class="success-tag">运行中</el-tag>
@ -61,7 +66,7 @@
</div> </div>
</el-card> </el-card>
</div> </div>
<EmbedDialog ref="EmbedDialogRef" :accessToken="accessToken" /> <EmbedDialog ref="EmbedDialogRef"/>
</LayoutContainer> </LayoutContainer>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
@ -87,7 +92,7 @@ const {
const loading = ref(false) const loading = ref(false)
function openDialog() { function openDialog() {
EmbedDialogRef.value.open() EmbedDialogRef.value.open(accessToken.value)
} }
function getAccessToken() { function getAccessToken() {
application.asyncGetAccessToken(id, loading).then((res) => { application.asyncGetAccessToken(id, loading).then((res) => {

View File

@ -8,7 +8,7 @@
<div class="flex-between"> <div class="flex-between">
<span class="bold">复制以下代码进行嵌入</span> <span class="bold">复制以下代码进行嵌入</span>
<el-button text @click="copyClick(source1)"> <el-button text @click="copyClick(source1)">
<AppIcon iconName="app-copy" ></AppIcon> <AppIcon iconName="app-copy"></AppIcon>
</el-button> </el-button>
</div> </div>
<div class="mt-8"> <div class="mt-8">
@ -40,46 +40,43 @@
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import { copyClick } from '@/utils/clipboard' import { copyClick } from '@/utils/clipboard'
import useStore from '@/stores' import useStore from '@/stores'
const { application } = useStore() const { application } = useStore()
const props = defineProps({
accessToken: String
})
const emit = defineEmits(['addData']) const emit = defineEmits(['addData'])
const loading = ref(false)
const dialogVisible = ref<boolean>(false) const dialogVisible = ref<boolean>(false)
const source1 = ref(`<iframe const source1 = ref('')
src="${application.location + props.accessToken}"
const source2 = ref('')
watch(dialogVisible, (bool) => {
if (!bool) {
source1.value = ''
source2.value = ''
}
})
const open = (val: string) => {
source1.value = `<iframe
src="${application.location + val}"
style="width: 100%; height: 100%;" style="width: 100%; height: 100%;"
frameborder="0" frameborder="0"
allow="microphone"> allow="microphone">
</iframe> </iframe>
`) `
source2.value = `<script> window.difyChatbotConfig = {
const source2 = ref(`<script> window.difyChatbotConfig = { token: "${val}"
token: "${props.accessToken}"
} }
<\/script> <\/script>
<script src="https://udify.app/embed.min.js" <script src="https://udify.app/embed.min.js"
id="${props.accessToken}" id="${val}"
defer> defer>
<\/script> <\/script>
`) `
watch(dialogVisible, (bool) => {
if (!bool) {
loading.value = false
}
})
const open = (checked: any) => {
dialogVisible.value = true dialogVisible.value = true
} }
const submitHandle = () => {
dialogVisible.value = false
}
defineExpose({ open }) defineExpose({ open })
</script> </script>

View File

@ -36,6 +36,16 @@
class="application-card cursor" class="application-card cursor"
@click="router.push({ path: `/application/${item.id}/overview` })" @click="router.push({ path: `/application/${item.id}/overview` })"
> >
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
<div class="status-tag"> <div class="status-tag">
<el-tag v-if="item.status" class="success-tag">运行中</el-tag> <el-tag v-if="item.status" class="success-tag">运行中</el-tag>
<el-tag v-else class="warning-tag">已停用</el-tag> <el-tag v-else class="warning-tag">已停用</el-tag>

View File

@ -27,7 +27,9 @@ const loading = ref(false)
const applicationDetail = ref<any>({}) const applicationDetail = ref<any>({})
function getAccessToken(token: string) { function getAccessToken(token: string) {
application.asyncAppAuthentication(token, loading).then((res) => {}) application.asyncAppAuthentication(token, loading).then((res) => {
getProfile()
})
} }
function getProfile() { function getProfile() {
applicationApi.getProfile(loading).then((res) => { applicationApi.getProfile(loading).then((res) => {
@ -37,7 +39,6 @@ function getProfile() {
onMounted(() => { onMounted(() => {
user.changeUserType(2) user.changeUserType(2)
getAccessToken(accessToken) getAccessToken(accessToken)
getProfile()
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>