merge app type function branch

This commit is contained in:
RockYang 2024-09-14 18:17:55 +08:00
commit 14aee28289
12 changed files with 423 additions and 72 deletions

View File

@ -3,7 +3,7 @@
* 功能优化:用户文件列表组件增加分页功能支持 * 功能优化:用户文件列表组件增加分页功能支持
* Bug修复修复用户注册失败Bug注册操作只弹出一次行为验证码 * Bug修复修复用户注册失败Bug注册操作只弹出一次行为验证码
* 功能优化:首次登录不需要验证码,直接登录,登录失败之后才弹出验证码 * 功能优化:首次登录不需要验证码,直接登录,登录失败之后才弹出验证码
* 功能新增:给 AI 应用(角色)增加分类 * 功能新增:给 AI 应用(角色)增加分类,前端支持分类筛选
* 功能优化:允许用户在聊天页面设置是否使用流式输出或者一次性输出,兼容 GPT-O1 模型。 * 功能优化:允许用户在聊天页面设置是否使用流式输出或者一次性输出,兼容 GPT-O1 模型。
## v4.1.3 ## v4.1.3

View File

@ -66,7 +66,8 @@ html, body {
margin 0; margin 0;
.el-dialog__body { .el-dialog__body {
max-height 90vh max-height 80vh
overflow-y auto
} }
} }
} }

View File

@ -2,14 +2,54 @@
background-color: #282c34; background-color: #282c34;
height 100% height 100%
.inner { .apps-type-nav{
height 43px
padding 8px 0;
margin-bottom 3px
}
.scrollbar-type-nav{
display flex
align-items center
height 43px
padding 0 5px
li{
flex-shrink 0
display flex
align-items center
justify-content center
margin 0 10px
height 26px
border-radius 4px
border 1px solid rgb(80,80,80)
padding 2px 12px
background rgba(60,60,60 0.9)
color #fff
font-size 14px
cursor pointer
.image {
width 22px
height 22px
overflow hidden
margin-right 5px
border-radius 50%
}
&.active{
background #21aa93;
}
}
}
.app-list-container {
display flex display flex
color #ffffff color #ffffff
padding 15px; padding 2px 15px;
overflow-y visible overflow-y visible
overflow-x hidden overflow-x hidden
.list-box { .item__list-box {
.item { .item {
display flex display flex
flex-flow row flex-flow row

View File

@ -141,7 +141,7 @@
display flex display flex
flex-flow row flex-flow row
align-items center align-items center
height 100px min-height 100px
padding 10px 15px padding 10px 15px
border-radius 10px border-radius 10px
cursor pointer cursor pointer

View File

@ -1,57 +1,64 @@
<template> <template>
<el-container class="file-select-box"> <el-container class="file-select-box">
<a class="file-upload-img" @click="fetchFiles"> <a class="file-upload-img" @click="fetchFiles(1)">
<i class="iconfont icon-attachment-st"></i> <i class="iconfont icon-attachment-st"></i>
</a> </a>
<el-dialog <el-dialog
class="file-list-dialog"
v-model="show" v-model="show"
:close-on-click-modal="true" :close-on-click-modal="true"
:show-close="true" :show-close="true"
:width="800" :width="800"
title="文件管理" title="文件管理"
> >
<el-scrollbar ref="scrollbarRef" max-height="80vh" style="height: 100%;" @scroll="onScroll">
<div class="file-list"> <div class="file-list">
<el-row :gutter="20"> <el-row :gutter="20">
<el-col :span="3"> <el-col :span="3">
<div class="grid-content"> <div class="grid-content">
<el-upload <el-upload
class="avatar-uploader" class="avatar-uploader"
:auto-upload="true" :auto-upload="true"
:show-file-list="false" :show-file-list="false"
:http-request="afterRead" :http-request="afterRead"
accept=".doc,.docx,.jpg,.png,.jpeg,.xls,.xlsx,.ppt,.pptx,.pdf,.mp4,.mp3" accept=".doc,.docx,.jpg,.png,.jpeg,.xls,.xlsx,.ppt,.pptx,.pdf,.mp4,.mp3"
> >
<el-icon class="avatar-uploader-icon"> <el-icon class="avatar-uploader-icon">
<Plus/> <Plus/>
</el-icon> </el-icon>
</el-upload> </el-upload>
</div>
</el-col>
<el-col :span="3" v-for="file in fileList" :key="file.url">
<div class="grid-content">
<el-tooltip
class="box-item"
effect="dark"
:content="file.name"
placement="top">
<el-image :src="file.url" fit="cover" v-if="isImage(file.ext)" @click="insertURL(file)"/>
<el-image :src="GetFileIcon(file.ext)" fit="cover" v-else @click="insertURL(file)"/>
</el-tooltip>
<div class="opt">
<el-button type="danger" size="small" :icon="Delete" @click="removeFile(file)" circle/>
</div> </div>
</div> </el-col>
</el-col> <el-col :span="3" v-for="file in fileData.items" :key="file.url">
</el-row> <div class="grid-content">
</div> <el-tooltip
class="box-item"
effect="dark"
:content="file.name"
placement="top">
<el-image :src="file.url" fit="cover" v-if="isImage(file.ext)" @click="insertURL(file)"/>
<el-image :src="GetFileIcon(file.ext)" fit="cover" v-else @click="insertURL(file)"/>
</el-tooltip>
<div class="opt">
<el-button type="danger" size="small" :icon="Delete" @click="removeFile(file)" circle/>
</div>
</div>
</el-col>
</el-row>
<el-row justify="center" v-if="!fileData.isLastPage" @click="fetchFiles(fileData.page)">
<el-link>加载更多</el-link>
</el-row>
</div>
</el-scrollbar>
</el-dialog> </el-dialog>
</el-container> </el-container>
</template> </template>
<script setup> <script setup>
import {ref} from "vue"; import {reactive, ref} from "vue";
import {ElMessage} from "element-plus"; import {ElMessage} from "element-plus";
import {httpGet, httpPost} from "@/utils/http"; import {httpGet, httpPost} from "@/utils/http";
import {Delete, Plus} from "@element-plus/icons-vue"; import {Delete, Plus} from "@element-plus/icons-vue";
@ -64,15 +71,45 @@ const props = defineProps({
const emits = defineEmits(['selected']); const emits = defineEmits(['selected']);
const show = ref(false) const show = ref(false)
const fileList = ref([]) const fileList = ref([])
const scrollbarRef = ref(null)
const fileData = reactive({
items:[],
page: 1,
isLastPage: true,
})
const fetchFiles = () => { const fetchFiles = (pageNo) => {
show.value = true if(pageNo === 1) show.value = true
httpPost("/api/upload/list").then(res => { httpPost("/api/upload/list", { page: pageNo || 1, page_size: 30 }).then(res => {
fileList.value = res.data.items const { items, page, total_page } = res.data
if(page === 1){
fileData.items = items
}else{
fileData.items = [...fileData.items, ...items]
}
fileData.isLastPage = (page === total_page)
if(!fileData.isLastPage){
fileData.page = page + 1
}
}).catch(() => { }).catch(() => {
}) })
} }
// el-scrollbar
const onScroll = (options) => {
const wrapRef = scrollbarRef.value.wrapRef
scrollbarRef.value.moveY = wrapRef.scrollTop * 100 / wrapRef.clientHeight
scrollbarRef.value.moveX = wrapRef.scrollLeft * 100 / wrapRef.clientWidth
const poor = wrapRef.scrollHeight - wrapRef.clientHeight
//
if (options.scrollTop + 2 >= poor && !fileData.isLastPage) {
fetchFiles(fileData.page)
}
}
const afterRead = (file) => { const afterRead = (file) => {
const formData = new FormData(); const formData = new FormData();
@ -120,9 +157,10 @@ const insertURL = (file) => {
.el-dialog__body { .el-dialog__body {
//padding 0 //padding 0
overflow hidden
.file-list { .file-list {
margin-right 10px
.grid-content { .grid-content {
margin-bottom 10px margin-bottom 10px
position relative position relative

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="list-box" ref="containerRef"> <div class="item__list-box" ref="containerRef">
<el-row :gutter="gap"> <el-row :gutter="gap">
<el-col v-for="item in items" :key="item.id" :span="span" :style="{marginBottom:gap+'px'} "> <el-col v-for="item in items" :key="item.id" :span="span" :style="{marginBottom:gap+'px'} ">
<slot :item="item"></slot> <slot :item="item"></slot>
@ -54,9 +54,10 @@ const calcSpan = () => {
window.onresize = () => calcSpan() window.onresize = () => calcSpan()
</script> </script>
<style scoped lang="stylus"> <style lang="stylus">
.list-box { .item__list-box {
width 100%
} }
</style> </style>

View File

@ -170,13 +170,13 @@ const routes = [
{ {
path: '/admin/app', path: '/admin/app',
name: 'admin-app', name: 'admin-app',
meta: {title: '应用管理'}, meta: {title: '应用列表'},
component: () => import('@/views/admin/Apps.vue'), component: () => import('@/views/admin/Apps.vue'),
}, },
{ {
path: '/admin/app/type', path: '/admin/app/type',
name: 'admin-app-type', name: 'admin-app-type',
meta: {title: '应用管理'}, meta: {title: '应用分类'},
component: () => import('@/views/admin/AppType.vue'), component: () => import('@/views/admin/AppType.vue'),
}, },
{ {

View File

@ -1,7 +1,21 @@
<template> <template>
<div> <div>
<div class="page-apps custom-scroll"> <div class="page-apps custom-scroll">
<div class="inner" :style="{height: listBoxHeight + 'px'}"> <div class="apps-type-nav">
<el-scrollbar>
<ul class="scrollbar-type-nav">
<li :class="{active: typeId === ''}" @click="getAppList('')">全部分类</li>
<li v-for="item in appTypes" :key="item.id" :class="{active: typeId === item.id}" @click="getAppList(item.id)">
<div class="image" v-if="item.icon">
<el-image :src="item.icon" fit="cover"/>
</div>
{{ item.name }}
</li>
</ul>
</el-scrollbar>
</div>
<div class="app-list-container" :style="{height: listBoxHeight + 'px'}">
<ItemList :items="list" v-if="list.length > 0" :gap="15" :width="300"> <ItemList :items="list" v-if="list.length > 0" :gap="15" :width="300">
<template #default="scope"> <template #default="scope">
<div class="item"> <div class="item">
@ -50,6 +64,9 @@
<!-- </div>--> <!-- </div>-->
</template> </template>
</ItemList> </ItemList>
<div v-else style="width: 100%">
<el-empty description="暂无数据" />
</div>
</div> </div>
</div> </div>
</div> </div>
@ -65,23 +82,17 @@ import {useRouter} from "vue-router";
import {useSharedStore} from "@/store/sharedata"; import {useSharedStore} from "@/store/sharedata";
import ItemList from "@/components/ItemList.vue"; import ItemList from "@/components/ItemList.vue";
const listBoxHeight = window.innerHeight - 87 const listBoxHeight = window.innerHeight - 133
const typeId = ref('')
const appTypes = ref([])
const list = ref([]) const list = ref([])
const roles = ref([]) const roles = ref([])
const store = useSharedStore(); const store = useSharedStore();
onMounted(() => { onMounted(() => {
httpGet("/api/app/list").then((res) => { getAppType()
const items = res.data getAppList()
// hello message
for (let i = 0; i < items.length; i++) {
items[i].intro = substr(items[i].hello_msg, 80)
}
list.value = items
}).catch(e => {
ElMessage.error("获取应用失败:" + e.message)
})
getRoles() getRoles()
}) })
@ -93,6 +104,28 @@ const getRoles = () => {
}) })
} }
const getAppType = () => {
httpGet("/api/app/type/list").then((res) => {
appTypes.value = res.data
}).catch(e => {
ElMessage.error("获取分类失败:" + e.message)
})
}
const getAppList = (tid = '') => {
typeId.value = tid;
httpGet("/api/app/list", { tid }).then((res) => {
const items = res.data
// hello message
for (let i = 0; i < items.length; i++) {
items[i].intro = substr(items[i].hello_msg, 80)
}
list.value = items
}).catch(e => {
ElMessage.error("获取应用失败:" + e.message)
})
}
const updateRole = (row, opt) => { const updateRole = (row, opt) => {
checkSession().then(() => { checkSession().then(() => {
const title = ref("") const title = ref("")

View File

@ -141,8 +141,8 @@
:total="total"/> :total="total"/>
</div> </div>
</el-container> </el-container>
<black-dialog v-model:show="showDialog" title="预览视频" hide-footer @cancal="showDialog = false" :width="1000"> <black-dialog v-model:show="showDialog" title="预览视频" hide-footer @cancal="showDialog = false" width="auto">
<video style="width: 100%;" :src="currentVideoUrl" preload="auto" :autoplay="true" loop="loop" muted="muted" v-show="showDialog"> <video style="width: 100%; max-height: 90vh;" :src="currentVideoUrl" preload="auto" :autoplay="true" loop="loop" muted="muted" v-show="showDialog">
您的浏览器不支持视频播放 您的浏览器不支持视频播放
</video> </video>
</black-dialog> </black-dialog>

View File

@ -1,13 +1,214 @@
<template> <template>
<div class="container app-type" > <div class="container app-type" v-loading="loading">
<div class="handle-box">
<el-button type="primary" :icon="Plus" @click="add">新增</el-button>
</div>
<el-row>
<el-table :data="items" :row-key="row => row.id" table-layout="auto">
<el-table-column type="selection" width="38"></el-table-column>
<el-table-column prop="name" label="分类名称">
<template #default="scope">
<span class="sort" :data-id="scope.row.id">
<i class="iconfont icon-drag"></i>
{{ scope.row.name }}
</span>
</template>
</el-table-column>
<el-table-column label="图标" prop="icon">
<template #default="scope">
<el-image v-if="scope.row.icon" :src="scope.row.icon" style="width: 45px; height: 45px; border-radius: 50%"/>
<el-tag type="info" v-else>无图标</el-tag>
</template>
</el-table-column>
<el-table-column prop="enabled" label="启用状态">
<template #default="scope">
<el-switch v-model="scope.row['enabled']" @change="enableSet(scope.row)"/>
</template>
</el-table-column>
<el-table-column label="操作" width="180">
<template #default="scope">
<el-button size="small" type="primary" @click="edit(scope.row)">编辑</el-button>
<el-popconfirm title="确定要删除当前记录吗?" @confirm="remove(scope.row)" :width="200">
<template #reference>
<el-button size="small" type="danger">删除</el-button>
</template>
</el-popconfirm>
</template>
</el-table-column>
</el-table>
</el-row>
<el-dialog
v-model="showDialog"
:title="title"
:close-on-click-modal="false"
style="width: 90%; max-width: 600px;"
>
<el-form :model="item" label-width="120px" ref="formRef" :rules="rules">
<el-form-item label="分类名称:" prop="name">
<el-input v-model="item.name" autocomplete="off"/>
</el-form-item>
<el-form-item label="应用图标:" prop="icon">
<el-input v-model="item.icon">
<template #append>
<el-upload
:auto-upload="true"
:show-file-list="false"
:http-request="uploadImg"
>
上传
</el-upload>
</template>
</el-input>
</el-form-item>
<el-form-item label="启用状态:" prop="enable">
<el-switch v-model="item.enabled" />
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="showDialog = false">取消</el-button>
<el-button type="primary" @click="save">提交</el-button>
</span>
</template>
</el-dialog>
</div> </div>
</template> </template>
<script setup> <script setup>
import {onMounted, onUnmounted, reactive, ref} from "vue";
import {httpGet, httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {removeArrayItem} from "@/utils/libs";
import {Sortable} from "sortablejs";
import Compressor from "compressorjs";
</script> //
const items = ref([])
const item = ref({})
const showDialog = ref(false)
const title = ref("")
const rules = reactive({
name: [{required: true, message: '请输入分类名称', trigger: 'change',}],
})
const loading = ref(true)
const formRef = ref(null)
<style lang="stylus" scoped> //
const fetchData = () => {
httpGet('/api/admin/app/type/list').then((res) => {
if (res.data) {
items.value = res.data
}
loading.value = false
}).catch(() => {
ElMessage.error("获取数据失败");
})
}
</style> onMounted(() => {
fetchData()
const drawBodyWrapper = document.querySelector('.el-table__body tbody')
//
Sortable.create(drawBodyWrapper, {
sort: true,
animation: 500,
onEnd({newIndex, oldIndex, from}) {
if (oldIndex === newIndex) {
return
}
const sortedData = Array.from(from.children).map(row => row.querySelector('.sort').getAttribute('data-id'));
const ids = []
const sorts = []
sortedData.forEach((id, index) => {
ids.push(parseInt(id))
sorts.push(index + 1)
items.value[index].sort_num = index + 1
})
httpPost("/api/admin/app/type/sort", {ids: ids, sorts: sorts}).then(() => {
}).catch(e => {
ElMessage.error("排序失败:" + e.message)
})
}
})
})
const add = function () {
title.value = "新增分类"
showDialog.value = true
item.value = { enabled: true, }
}
const edit = function (row) {
title.value = "修改分类"
showDialog.value = true
item.value = row
}
const save = function () {
formRef.value.validate((valid) => {
if (!item.value.sort_num) {
item.value.sort_num = items.value.length
}
if (valid) {
showDialog.value = false
httpPost('/api/admin/app/type/save', item.value).then(() => {
ElMessage.success('操作成功!')
fetchData()
}).catch((e) => {
ElMessage.error('操作失败,' + e.message)
})
} else {
return false
}
})
}
//
const enableSet = (row) => {
httpPost('/api/admin/app/type/enable', {id: row.id, enabled: row.enabled}).then(() => {
ElMessage.success("操作成功!")
}).catch(e => {
ElMessage.error("操作失败:" + e.message)
})
}
//
const remove = function (row) {
httpGet('/api/admin/app/type/remove?id=' + row.id).then(() => {
ElMessage.success("删除成功!")
items.value = removeArrayItem(items.value, row, (v1, v2) => {
return v1.id === v2.id
})
}).catch((e) => {
ElMessage.error("删除失败:" + e.message)
})
}
//
const uploadImg = (file) => {
//
new Compressor(file.file, {
quality: 0.6,
success(result) {
const formData = new FormData();
formData.append('file', result, result.name);
//
httpPost('/api/admin/upload', formData).then((res) => {
item.value.icon = res.data.url
ElMessage.success('上传成功')
}).catch((e) => {
ElMessage.error('上传失败:' + e.message)
})
},
error(e) {
ElMessage.error('上传失败:' + e.message)
},
});
};
</script>

View File

@ -23,6 +23,7 @@
</span> </span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="应用类型" prop="type_name"/>
<el-table-column label="应用标识" prop="key"/> <el-table-column label="应用标识" prop="key"/>
<el-table-column label="绑定模型" prop="model_name"/> <el-table-column label="绑定模型" prop="model_name"/>
<el-table-column label="启用状态"> <el-table-column label="启用状态">
@ -62,6 +63,21 @@
autocomplete="off" autocomplete="off"
/> />
</el-form-item> </el-form-item>
<el-form-item label="应用分类:" prop="tid">
<el-select
v-model="role.tid"
filterable
placeholder="请选择分类"
clearable
>
<el-option
v-for="item in appTypes"
:key="item.id"
:label="item.name"
:value="item.id"
/>
</el-select>
</el-form-item>
<el-form-item label="应用标志:" prop="key"> <el-form-item label="应用标志:" prop="key">
<el-input <el-input
@ -195,6 +211,7 @@ const rules = reactive({
hello_msg: [{required: true, message: '请输入打招呼信息', trigger: 'change',}] hello_msg: [{required: true, message: '请输入打招呼信息', trigger: 'change',}]
}) })
const appTypes = ref([])
const models = ref([]) const models = ref([])
onMounted(() => { onMounted(() => {
fetchData() fetchData()
@ -206,11 +223,25 @@ onMounted(() => {
ElMessage.error("获取AI模型数据失败"); ElMessage.error("获取AI模型数据失败");
}) })
// get app type
httpGet('/api/admin/app/type/list?enable=1').then((res) => {
appTypes.value = res.data
}).catch(() => {
ElMessage.error("获取应用分类数据失败");
})
}) })
const fetchData = () => { const fetchData = () => {
// //
httpGet('/api/admin/role/list').then((res) => { httpGet('/api/admin/role/list').then((res) => {
//
// const arr = res.data;
// for (let i = 0; i < arr.length; i++) {
// if(arr[i].model_id == 0){
// arr[i].model_id = ''
// }
// }
tableData.value = res.data tableData.value = res.data
sortedTableData.value = copyObj(tableData.value) sortedTableData.value = copyObj(tableData.value)
loading.value = false loading.value = false

View File

@ -21,5 +21,11 @@ module.exports = defineConfig({
devServer: { devServer: {
allowedHosts: "all", allowedHosts: "all",
port: 8888, port: 8888,
proxy: {
'/static/upload/': {
target: process.env.VUE_APP_API_HOST,
changeOrigin: true,
}
}
} }
}) })