From 97eff6085aa0db4e3b3b16992dcf16e71c4de915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=8F=8C=E6=98=8E?= Date: Tue, 10 Sep 2024 18:14:34 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20210=20AI=E5=AF=B9=E8=AF=9D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=96=87=E4=BB=B6=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/App.vue | 3 +- web/src/components/FileSelect.vue | 122 ++++++++++++++++++++---------- 2 files changed, 82 insertions(+), 43 deletions(-) diff --git a/web/src/App.vue b/web/src/App.vue index 059f4ffe..b94eed26 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -66,7 +66,8 @@ html, body { margin 0; .el-dialog__body { - max-height 90vh + max-height 80vh + overflow-y auto } } } diff --git a/web/src/components/FileSelect.vue b/web/src/components/FileSelect.vue index d340c460..de1f8739 100644 --- a/web/src/components/FileSelect.vue +++ b/web/src/components/FileSelect.vue @@ -1,57 +1,64 @@ +// 变量定义 +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) - \ No newline at end of file +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.obj_key.replace('./static', '/static') + ElMessage.success('上传成功') + }).catch((e) => { + ElMessage.error('上传失败:' + e.message) + }) + }, + error(e) { + ElMessage.error('上传失败:' + e.message) + }, + }); +}; + \ No newline at end of file diff --git a/web/src/views/admin/Apps.vue b/web/src/views/admin/Apps.vue index bffe733c..3bb8a8ae 100644 --- a/web/src/views/admin/Apps.vue +++ b/web/src/views/admin/Apps.vue @@ -23,6 +23,7 @@ + @@ -62,6 +63,21 @@ autocomplete="off" /> + + + + + { fetchData() @@ -206,11 +223,25 @@ onMounted(() => { 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 = () => { // 获取应用列表 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 sortedTableData.value = copyObj(tableData.value) loading.value = false diff --git a/web/vue.config.js b/web/vue.config.js index b5007883..d6595b62 100644 --- a/web/vue.config.js +++ b/web/vue.config.js @@ -21,5 +21,11 @@ module.exports = defineConfig({ devServer: { allowedHosts: "all", port: 8888, + proxy: { + '/static/upload/': { + target: process.env.VUE_APP_API_HOST, + changeOrigin: true, + } + } } })