This commit is contained in:
阿怪 2023-11-16 00:09:39 +08:00
parent 68258684f5
commit ba45ca26bb
4 changed files with 415 additions and 8 deletions

View File

@ -2,7 +2,7 @@ ENV = 'development'
VITE_CLI_PORT = 8088 VITE_CLI_PORT = 8088
VITE_SERVER_PORT = 8888 VITE_SERVER_PORT = 8888
VITE_BASE_API = /api VITE_BASE_API = /api
VITE_BASE_PATH = http://4a1840b2.r12.cpolar.top VITE_BASE_PATH = http://e07b2b5.r9.cpolar.top
VITE_EDITOR = vscode VITE_EDITOR = vscode
// VITE_EDITOR = webstorm 如果使用webstorm开发且要使用dom定位到代码行功能 请先自定添加 webstorm到环境变量 再将VITE_EDITOR值修改为webstorm // VITE_EDITOR = webstorm 如果使用webstorm开发且要使用dom定位到代码行功能 请先自定添加 webstorm到环境变量 再将VITE_EDITOR值修改为webstorm
// 如果使用docker-compose开发模式设置为下面的地址或本机主机IP // 如果使用docker-compose开发模式设置为下面的地址或本机主机IP

33
src/api/aiList.js Normal file
View File

@ -0,0 +1,33 @@
import service from '@/utils/request'
const api = {
// AI 列表api
getAiList: data => {
return service({
url: '/aikefu/list',
method: 'get',
params: data
})
},
addAi: data => {
return service({
url: '/aikefu',
method: 'post',
data
})
},
editAi: data => {
return service({
url: '/aikefu',
method: 'put',
data
})
},
deleteFunc: data => {
return service({
url: '/aikefu',
method: 'delete',
data
})
}
}
export default api

374
src/view/aiList/index.vue Normal file
View File

@ -0,0 +1,374 @@
<script setup>
//
import api from '@/api/aiList'
// import capi from '@/api/course'
// import custom from '@/utils/custom'
import { formatDate } from '@/utils/format'
import _ from 'lodash'
// import { toSQLLine } from '@/utils/stringFun'
// import WarningBar from '@/components/warningBar/warningBar.vue'
import ckEditor from '@/components/richText/ckEditor5.vue'
import { ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
const path = ref(import.meta.env.VITE_BASE_API)
import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore()
//
// const typeList = custom.getExercisesTypeList()
const queryParams = ref({
page: 1,
pageSize: 10,
key_word: '',
// name: '',
// type: '',
// subject: ''
})
// const subjectParams = ref({
// page: 1,
// pageSize: 100,
// })
const tableData = ref([])
// const subjectList = ref([])
const deleteVisible = ref(false)
const question_ids = ref([])
const total = ref(0)
const dialogFormVisible = ref(false)
const dialogTitle = ref('')
const form = ref({})
const rules = ref({
key_word: [{ required: true, message: '请输入关键词', trigger: 'blur' }],
content: [{ required: true, message: '请输入内容', trigger: 'blur' }],
// linke_title: [{ required: true, message: '', trigger: 'blur' }]
})
// const question_id = ref(0)
// const content = ref(null)
// const options = ref([]) //
const question_form = ref({
options: [],
answer: '',
title: ''
})
//
onMounted(() => {
getAiList()
// getSubject()
})
//
async function getAiList() {
const res = await api.getAiList(queryParams.value)
if (res.code === 0) {
tableData.value = res.data.list
console.log(tableData.value)
total.value = res.data.total
}
}
// async function getSubject() { //
// const res = await capi.getSubjectList(subjectParams.value)
// if (res.code === 0) {
// subjectList.value = custom.getStdSubject(res.data.records)
// }
// }
function onSubmit() {
getAiList()
}
const onReset = () => {
queryParams.value = {
page: 1,
pageSize: 10,
name: '',
// status: '',
// subject: ''
}
}
function openDialog(type) {
// let params = {}
switch (type) {
case 'add':
dialogTitle.value = '新增文章'
form.value = {}
break
case 'edit':
// params.question_id = question_id.value
dialogTitle.value = '编辑文章'
break
}
dialogFormVisible.value = true
// router.push({name:'addCourse',params})
}
async function onDelete() {
const ids = question_ids.value.map(item => item.question_id)
const res = await api.delExercises({ question_ids: ids })
if (res.code === 0) {
ElMessage({
type: 'success',
message: res.msg
})
// if (tableData.value.length === ids.length && page.value > 1) {
// page.value--
// }
deleteVisible.value = false
getAiList()
}
}
const handleSelectionChange = (val) => {
question_ids.value = val
}
function editFunc(row) {
form.value = _.cloneDeep(row)
// question_id.value = form.value.question_id
// content.value = JSON.parse(form.value.question).title
// question_form.value = JSON.parse(form.value.question)
// if (!question_form.value.options) {
// question_form.value.options = []
// }
openDialog('edit')
}
function deleteFunc(row) {
ElMessageBox.confirm('此操作将永久删除该数据, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(async () => {
const res = await api.deleteFunc({
id: row.ID
})
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功!'
})
getAiList()
}
}, () => {
})
}
function handleCurrentChange(val) {
queryParams.value.page = val
getAiList()
}
function handleSizeChange(val) {
queryParams.value.pageSize = val
getAiList()
}
function closeDialog() {
dialogFormVisible.value = false
question_form.value = {
options: [],
answer: '',
title: ''
}
form.value = {}
}
async function enterDialog() { //
// form.value.score = parseInt(form.value.score)
// form.value.teacher_id = 0
// form.value.question = JSON.stringify(question_form.value)
let func_name = 'addAi'
if (form.value.ID) { //
func_name = 'editAi'
}
const res = await api[func_name](form.value)
if (res.code === 0) {
ElMessage({
type: 'success',
message: res.msg
})
// if (tableData.value.length === ids.length && page.value > 1) {
// page.value--
// }
// deleteVisible.value = false
closeDialog()
getAiList()
}
}
function viewCourseFunc(row) { //
router.push({ name: 'viewCourse', params: { question_id: row.question_id } })
}
function getExercisesName(row) {
return JSON.parse(row.question).title
}
const std_options_title = ref(['A', 'B', 'C', 'D', 'E', 'F'])
function addOptionFunc() {
// for(let i=0 ;i<std_options_title.value.length;i++) {
// if(!options.value.has(std_options_title.value[i])) {
// options.value.set(std_options_title.value[i],'')
// break;
// }
// }
for (let i = 0; i < std_options_title.value.length; i++) {
let has_flag = false
for (const item of question_form.value.options) {
if (item.name === std_options_title.value[i]) {
has_flag = true
}
}
if (!has_flag) {
const data = {
name: std_options_title.value[i],
value: ''
}
question_form.value.options.push(data)
break
}
}
}
function delet_func(item) {
question_form.value.options.pop()
}
function handleAvatarSuccess(res) {
console.log(res)
form.value.cover_img = res.data.file.url
}
function beforeAvatarUpload(file) {
const isLt05M = file.size / 1024 / 1024 < 20
const isJPG = file.type.indexOf('image/') === -1
if (isJPG) {
ElMessage.error('文件格式错误,请上传图片类型,如JPGPNG后缀的文件')
}
if (!isLt05M) {
ElMessage.error('上传头像图片大小不能超过 2M!')
}
return !isJPG && isLt05M
}
</script>
<template>
<div>
<!-- 搜索框-->
<div class="gva-search-box">
<el-form ref="searchForm" :inline="true" :model="queryParams">
<el-form-item label="AI名称">
<el-input v-model="queryParams.name" placeholder="根据AI名称进行查询" />
</el-form-item>
<el-form-item>
<el-button size="small" type="primary" icon="search" @click="onSubmit">查询</el-button>
<el-button size="small" icon="refresh" @click="onReset">重置</el-button>
</el-form-item>
</el-form>
</div>
<!-- 表格数据-->
<div class="gva-table-box">
<!-- 批量操作-->
<div class="gva-btn-list">
<el-button size="small" type="primary" icon="plus" @click="openDialog('add')">新增</el-button>
<el-popover v-model="deleteVisible" placement="top" width="160">
<p>确定要删除吗</p>
<div style="text-align: right; margin-top: 8px;">
<el-button size="small" type="primary" link @click="deleteVisible = false">取消</el-button>
<el-button size="small" type="primary" @click="onDelete">确定</el-button>
</div>
<!-- <template #reference>
<el-button
icon="delete"
size="small"
type="danger"
:disabled="!question_ids.length"
style="margin-left: 10px;"
@click="deleteVisible = true"
>删除</el-button>
</template> -->
</el-popover>
</div>
<!-- 数据列表-->
<el-table :data="tableData" @selection-change="handleSelectionChange">
<!-- <el-table-column type="selection" width="55" /> -->
<el-table-column align="left" label="ID" prop="ID" sortable="custom" />
<el-table-column align="left" label="内容" min-width="150">
<template #default="scope">
<div>{{ scope.row.content }}</div>
</template>
</el-table-column>
<el-table-column align="left" label="关键字" prop="key_word" />
<el-table-column align="left" min-width="150" label="其他关键字" prop="linke_title" />
<!-- <el-table-column align="left" label="搜索标题" prop="search_title" /> -->
<el-table-column align="left" label="创建时间" min-width="150">
<template #default="scope">
{{ formatDate(scope.row.CreatedAt) }}
</template>
</el-table-column>
<el-table-column align="left" fixed="right" label="操作" width="200">
<template #default="scope">
<el-button icon="edit" size="small" type="primary" link @click="editFunc(scope.row)">编辑</el-button>
<el-button icon="delete" size="small" type="danger" link @click="deleteFunc(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="gva-pagination">
<el-pagination
:current-page="queryParams.page"
:page-size="queryParams.pageSize"
:page-sizes="[10, 30, 50, 100]"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@current-change="handleCurrentChange"
@size-change="handleSizeChange" />
</div>
</div>
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" :title="dialogTitle">
<el-form ref="apiForm" :model="form" :rules="rules" label-width="80px">
<el-form-item label="关键词" prop="key_word">
<el-input v-model="form.key_word" placeholder="输入关键词" />
</el-form-item>
<el-form-item label="回复内容" prop="content">
<!-- <ckEditor v-model="form.content" style="width:100%" :content="form.content" /> -->
<el-input
v-model="form.content"
:rows="2"
type="textarea"
placeholder="输入回复内容"
/>
<!-- <textarea v-model="form.content" cols="30" rows="10" /> -->
</el-form-item>
<el-form-item label="其他关键词" prop="linke_title">
<el-input v-model.number="form.linke_title" placeholder="输入其他关键词" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button size="small" @click="closeDialog"> </el-button>
<el-button size="small" type="primary" @click="enterDialog"> </el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<style scoped lang="scss">
.option-item {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.text-ellipsis-1 {
/*超出部分省略号 单行*/
overflow: hidden;
text-overflow: ellipsis;
-webkit-line-clamp: 1;
display: -webkit-box;
-webkit-box-orient: vertical;
/* min-height: 38rpx; */
}
.button-box {
padding: 10px 20px;
.el-button {
float: right;
}
}
.warning {
color: #dc143c;
}
.lbt-thumb {
width: 100px;
height: 50px;
}
</style>

View File

@ -12,7 +12,7 @@ const dialogFormVisible = ref(false)
import { useUserStore } from '@/pinia/modules/user' import { useUserStore } from '@/pinia/modules/user'
const userStore = useUserStore() const userStore = useUserStore()
import { parseTime } from '@/utils' import { parseTime } from '@/utils'
import { fa } from 'element-plus/es/locale' // import { fa } from 'element-plus/es/locale'
// //
const path = ref(import.meta.env.VITE_BASE_API) const path = ref(import.meta.env.VITE_BASE_API)
const queryParams = ref({ const queryParams = ref({
@ -23,12 +23,12 @@ const deleteVisible = ref(false)
const lbt_ids = ref([]) const lbt_ids = ref([])
const dialogTitle = ref('') const dialogTitle = ref('')
const form = ref({ status: '1' }) const form = ref({ status: '1' })
const lbtType_options = ref([ // const lbtType_options = ref([
{ // {
label: '首页', // label: '',
value: 1 // value: 1
} // }
]) // ])
const rules = ref({ const rules = ref({
// lbtName: [{ required: true, message: '', trigger: 'blur' }], // lbtName: [{ required: true, message: '', trigger: 'blur' }],
imgUrl: [{ required: true, message: '请选择素材', trigger: 'blur' }], imgUrl: [{ required: true, message: '请选择素材', trigger: 'blur' }],