增加敏感词管理

This commit is contained in:
jacky 2024-04-21 13:59:09 +08:00
parent 15c2a1bd58
commit 7d9cf078fc
2 changed files with 181 additions and 0 deletions

36
src/api/sensitiveWords.js Normal file
View File

@ -0,0 +1,36 @@
import service from '@/utils/request'
// @Summary 获取列表数据
// @Produce application/json
// @Router /cms/sensitiveWord/getList [post]
export const getSensitiveWordList = (data) => {
return service({
url: '/cms/sensitiveWord/getList',
method: 'post',
data
})
}
// @Summary 新增
// @Produce application/json
// @Param Object
// @Router /cms/sensitiveWord/add [post]
export const addSensitiveWord = (data) => {
return service({
url: '/cms/sensitiveWord/add',
method: 'post',
data
})
}
// @Summary 删除
// @Produce application/json
// @Param ID int
// @Router /cms/sensitiveWord/delete [delete]
export const deleteSensitiveWord = (data) => {
return service({
url: '/cms/sensitiveWord/delete',
method: 'delete',
data
})
}

View File

@ -0,0 +1,145 @@
<template>
<div>
<div class="gva-search-box">
<el-form ref="elSearchFormRef" :inline="true" :model="searchInfo" label-width="0" class="demo-form-inline"
@keyup.enter="handleSubmitSearch">
<el-form-item style="width:300px">
<el-tooltip content="从名称中搜索" placement="top-start">
<el-input v-model="searchInfo.keyword" class="keyword" placeholder="请输入关键词" clearable style="width:100%" />
</el-tooltip>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="search" @click="handleSubmitSearch">查询</el-button>
<el-button icon="refresh" @click="handleResetSearch">重置</el-button>
</el-form-item>
</el-form>
</div>
<div class="gva-table-box">
<div class="gva-btn-list">
<el-input v-if="inputVisible" ref="InputRef" v-model="inputValue" style="width: 100px" size="default"
@keyup.enter="handleInputConfirm" @blur="handleInputConfirm" />
<el-button v-else class="button-new-tag" type="primary" style="width: 100px" size="default" @click="showInput">
新增敏感词
</el-button>
</div>
<div class="flex flex-wrap gap-2">
<el-tag v-for="item in tableData" :key="item.ID" closable type="primary" size="large"
@close="handleRowDelete(item.ID)">
{{ item.name }}
</el-tag>
</div>
<div class="gva-pagination">
<el-pagination layout="total, sizes, prev, pager, next, jumper" :current-page="page" :page-size="pageSize"
:page-sizes="[50, 100]" :total="total" @current-change="handleCurrentChange"
@size-change="handleSizeChange" />
</div>
</div>
</div>
</template>
<script setup>
import { ref, nextTick } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import {
getSensitiveWordList,
deleteSensitiveWord,
addSensitiveWord,
} from '@/api/sensitiveWords'
const page = ref(1)
const total = ref(0)
const pageSize = ref(50)
const searchInfo = ref({})
const tableData = ref([])
const elSearchFormRef = ref()
const initSearchInfo = () => {
searchInfo.value.keyword = ''
page.value = 1
}
initSearchInfo()
const getTableData = async () => {
const res = await getSensitiveWordList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
if (res.code === 0) {
tableData.value = res.data.list
total.value = res.data.total
}
}
getTableData()
//
const handleResetSearch = () => {
initSearchInfo()
getTableData()
}
//
const handleSubmitSearch = () => {
elSearchFormRef.value?.validate(async valid => {
if (!valid) return
getTableData()
})
}
//
const handleSizeChange = (val) => {
pageSize.value = val
getTableData()
}
//
const handleCurrentChange = (val) => {
page.value = val
getTableData()
}
// ------ -----
//
const handleRowDelete = (ID) => {
ElMessageBox.confirm('此操作将删除敏感词, 是否继续?', '请确认', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async valid => {
const res = await deleteSensitiveWord({ ID })
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功!'
})
if (tableData.value.length === 1 && page.value > 1) {
page.value--
}
getTableData()
}
})
}
const inputValue = ref('')
const inputVisible = ref(false)
const InputRef = ref(null)
const showInput = () => {
inputVisible.value = true
nextTick(() => {
InputRef.value.focus()
})
}
const handleInputConfirm = async () => {
if (inputValue.value) {
const res = await addSensitiveWord({ name: inputValue.value })
if (res.code === 0) {
getTableData()
} else {
ElMessage({
type: 'error',
message: '保存失败: ' + res.message
})
return
}
}
inputVisible.value = false
inputValue.value = ''
}
</script>