|
@@ -1,14 +1,13 @@
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
/**
|
|
/**
|
|
* @Name: root-word-manage-table.vue
|
|
* @Name: root-word-manage-table.vue
|
|
- * @Description: 关键词管理表格
|
|
|
|
|
|
+ * @Description: 词根管理表格
|
|
* @Author: Cheney
|
|
* @Author: Cheney
|
|
*/
|
|
*/
|
|
|
|
|
|
import { nextTick, onMounted, reactive, ref } from 'vue';
|
|
import { nextTick, onMounted, reactive, ref } from 'vue';
|
|
import { Plus, Search, Upload } from '@element-plus/icons-vue';
|
|
import { Plus, Search, Upload } from '@element-plus/icons-vue';
|
|
import * as api from '../api';
|
|
import * as api from '../api';
|
|
-import { uploadFile } from '../api';
|
|
|
|
import type { UploadInstance, UploadRawFile } from 'element-plus';
|
|
import type { UploadInstance, UploadRawFile } from 'element-plus';
|
|
import { ElMessage, FormInstance, FormRules, genFileId } from 'element-plus';
|
|
import { ElMessage, FormInstance, FormRules, genFileId } from 'element-plus';
|
|
|
|
|
|
@@ -30,6 +29,7 @@ interface DataItem {
|
|
}
|
|
}
|
|
|
|
|
|
const SUCCESS_CODE = 2000;
|
|
const SUCCESS_CODE = 2000;
|
|
|
|
+const WARNING_CODE = 2001;
|
|
const currentDate = new Date().toISOString().split('T')[0];
|
|
const currentDate = new Date().toISOString().split('T')[0];
|
|
|
|
|
|
const tableLoading = ref(false);
|
|
const tableLoading = ref(false);
|
|
@@ -72,11 +72,7 @@ async function addSearchTerm() {
|
|
try {
|
|
try {
|
|
const response = await api.postCreateSearchTerm(body);
|
|
const response = await api.postCreateSearchTerm(body);
|
|
handleResponse(response);
|
|
handleResponse(response);
|
|
- if (response.code === SUCCESS_CODE) {
|
|
|
|
- await fetchSearchTermList();
|
|
|
|
- } else {
|
|
|
|
- ElMessage.error('添加失败');
|
|
|
|
- }
|
|
|
|
|
|
+ if (response.code === SUCCESS_CODE) await fetchSearchTermList();
|
|
} catch (error) {
|
|
} catch (error) {
|
|
console.error('error:', error);
|
|
console.error('error:', error);
|
|
}
|
|
}
|
|
@@ -274,33 +270,26 @@ function resetForm(formEl: FormInstance | undefined) {
|
|
dialogVisible.value = false;
|
|
dialogVisible.value = false;
|
|
}
|
|
}
|
|
|
|
|
|
-// async function handleFileChange(file: any) {
|
|
|
|
-// if (file.raw) {
|
|
|
|
-// await handleUpload(file.raw);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
-// async function handleUpload(uploadFile: any) {
|
|
|
|
-// try {
|
|
|
|
-// const response = await api.uploadFile(uploadFile);
|
|
|
|
-// handleResponse(response);
|
|
|
|
-// } catch (error) {
|
|
|
|
-// console.error('error:', error);
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
|
|
+/**
|
|
|
|
+ * 上传文件
|
|
|
|
+ * @param uploadRequest 上传请求
|
|
|
|
+ */
|
|
async function handleCustomUpload(uploadRequest: any) {
|
|
async function handleCustomUpload(uploadRequest: any) {
|
|
try {
|
|
try {
|
|
const { file } = uploadRequest;
|
|
const { file } = uploadRequest;
|
|
- const response = await uploadFile(file);
|
|
|
|
|
|
+ const response = await api.uploadFile(file);
|
|
handleResponse(response);
|
|
handleResponse(response);
|
|
uploadRequest.onSuccess(response); // 通知 el-upload 上传成功
|
|
uploadRequest.onSuccess(response); // 通知 el-upload 上传成功
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- console.error('error:', error);
|
|
|
|
- uploadRequest.onError(error); // 通知 el-upload 上传失败
|
|
|
|
|
|
+ console.log('error:', error);
|
|
|
|
+ uploadRequest.onError(error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @description 替换文件并上传
|
|
|
|
+ * @param files 文件列表
|
|
|
|
+ */
|
|
function handleExceed(files: any) {
|
|
function handleExceed(files: any) {
|
|
upload.value!.clearFiles();
|
|
upload.value!.clearFiles();
|
|
const file = files[0] as UploadRawFile;
|
|
const file = files[0] as UploadRawFile;
|
|
@@ -316,8 +305,10 @@ function handleExceed(files: any) {
|
|
function handleResponse(response: any) {
|
|
function handleResponse(response: any) {
|
|
if (response.code === SUCCESS_CODE) {
|
|
if (response.code === SUCCESS_CODE) {
|
|
ElMessage.success({ message: response.msg, plain: true });
|
|
ElMessage.success({ message: response.msg, plain: true });
|
|
|
|
+ } else if (response.code === WARNING_CODE) {
|
|
|
|
+ ElMessage.warning({ message: response.msg, plain: true });
|
|
} else {
|
|
} else {
|
|
- ElMessage.error({ message: response.msg || '请联系管理员', plain: true });
|
|
|
|
|
|
+ ElMessage.error({ message: response.msg, plain: true });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
</script>
|
|
@@ -351,7 +342,7 @@ function handleResponse(response: any) {
|
|
<el-icon>
|
|
<el-icon>
|
|
<Plus />
|
|
<Plus />
|
|
</el-icon>
|
|
</el-icon>
|
|
- 添加关键词
|
|
|
|
|
|
+ 添加词根
|
|
</el-button>
|
|
</el-button>
|
|
<div style="height: 72px">
|
|
<div style="height: 72px">
|
|
<el-upload
|
|
<el-upload
|
|
@@ -362,50 +353,52 @@ function handleResponse(response: any) {
|
|
:on-exceed="handleExceed"
|
|
:on-exceed="handleExceed"
|
|
:http-request="handleCustomUpload">
|
|
:http-request="handleCustomUpload">
|
|
<template #trigger>
|
|
<template #trigger>
|
|
- <el-button plain round type="warning" :icon="Upload">文件上传</el-button>
|
|
|
|
|
|
+ <el-button plain round type="warning" :icon="Upload">批量词根上传</el-button>
|
|
</template>
|
|
</template>
|
|
</el-upload>
|
|
</el-upload>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
-
|
|
|
|
|
|
+ <!-- 表格 -->
|
|
<el-card shadow="never">
|
|
<el-card shadow="never">
|
|
- <el-table :data="tableData" stripe max-height="530" style="width: 100%">
|
|
|
|
- <el-table-column fixed="left" prop="add_date" label="添加日期" width="180" sortable />
|
|
|
|
- <el-table-column prop="searchTerm" label="词根" sortable>
|
|
|
|
- <template #default="{ row }">
|
|
|
|
- <el-input ref="searchTermInpRef" v-if="row.isEditing" v-model="row.searchTerm" @change="updateSearchTerm(row)" />
|
|
|
|
- <span class="font-bold" v-else>{{ row.searchTerm }}</span>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- <el-table-column prop="searchTerm_type" label="词根类型" sortable>
|
|
|
|
- <template #default="{ row }">
|
|
|
|
- <el-popconfirm
|
|
|
|
- title="确定修改吗?"
|
|
|
|
- @confirm="updateSearchTermType(row)"
|
|
|
|
- @cancel="cancelUpdate(row)"
|
|
|
|
- :visible="row.popConfirmVisible">
|
|
|
|
- <template #reference>
|
|
|
|
- <el-select v-model="row.searchTerm_type" @change="showPopConfirm(row)" style="width: 150px">
|
|
|
|
- <el-option label="positive" value="positive" />
|
|
|
|
- <el-option label="negative" value="negative" />
|
|
|
|
- </el-select>
|
|
|
|
- </template>
|
|
|
|
- </el-popconfirm>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- <el-table-column fixed="right" label="操作" width="120">
|
|
|
|
- <template #default="{ row }">
|
|
|
|
- <el-button link type="primary" size="small" @click="handleClick(row)" v-if="!row.isEditing"> 编辑</el-button>
|
|
|
|
- <el-button link type="primary" size="small" @click="handleClick(row)" v-else> 取消</el-button>
|
|
|
|
- <el-popconfirm title="确定删除吗?" @confirm="handleDelete(row)">
|
|
|
|
- <template #reference>
|
|
|
|
- <el-button link type="danger" size="small">删除</el-button>
|
|
|
|
- </template>
|
|
|
|
- </el-popconfirm>
|
|
|
|
- </template>
|
|
|
|
- </el-table-column>
|
|
|
|
- </el-table>
|
|
|
|
|
|
+ <div style="height: 535px; overflow: auto">
|
|
|
|
+ <el-table :data="tableData" stripe style="width: 100%">
|
|
|
|
+ <el-table-column fixed prop="add_date" label="添加日期" width="180" sortable />
|
|
|
|
+ <el-table-column prop="searchTerm" label="词根" sortable>
|
|
|
|
+ <template #default="{ row }">
|
|
|
|
+ <el-input ref="searchTermInpRef" v-if="row.isEditing" v-model="row.searchTerm" @change="updateSearchTerm(row)" />
|
|
|
|
+ <span class="font-bold" v-else>{{ row.searchTerm }}</span>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ <el-table-column prop="searchTerm_type" label="词根类型" sortable>
|
|
|
|
+ <template #default="{ row }">
|
|
|
|
+ <el-popconfirm
|
|
|
|
+ title="确定修改吗?"
|
|
|
|
+ @confirm="updateSearchTermType(row)"
|
|
|
|
+ @cancel="cancelUpdate(row)"
|
|
|
|
+ :visible="row.popConfirmVisible">
|
|
|
|
+ <template #reference>
|
|
|
|
+ <el-select v-model="row.searchTerm_type" @change="showPopConfirm(row)" style="width: 150px">
|
|
|
|
+ <el-option label="positive" value="positive" />
|
|
|
|
+ <el-option label="negative" value="negative" />
|
|
|
|
+ </el-select>
|
|
|
|
+ </template>
|
|
|
|
+ </el-popconfirm>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ <el-table-column fixed="right" label="操作" width="120">
|
|
|
|
+ <template #default="{ row }">
|
|
|
|
+ <el-button link type="primary" size="small" @click="handleClick(row)" v-if="!row.isEditing"> 编辑</el-button>
|
|
|
|
+ <el-button link type="primary" size="small" @click="handleClick(row)" v-else> 取消</el-button>
|
|
|
|
+ <el-popconfirm title="确定删除吗?" @confirm="handleDelete(row)">
|
|
|
|
+ <template #reference>
|
|
|
|
+ <el-button link type="danger" size="small">删除</el-button>
|
|
|
|
+ </template>
|
|
|
|
+ </el-popconfirm>
|
|
|
|
+ </template>
|
|
|
|
+ </el-table-column>
|
|
|
|
+ </el-table>
|
|
|
|
+ </div>
|
|
<div class="mt-3.5 flex justify-end">
|
|
<div class="mt-3.5 flex justify-end">
|
|
<el-pagination
|
|
<el-pagination
|
|
v-model:current-page="currentPage"
|
|
v-model:current-page="currentPage"
|
|
@@ -419,7 +412,7 @@ function handleResponse(response: any) {
|
|
</el-card>
|
|
</el-card>
|
|
</el-card>
|
|
</el-card>
|
|
</div>
|
|
</div>
|
|
- <!-- 添加关键词弹窗 -->
|
|
|
|
|
|
+ <!-- 添加词根弹窗 -->
|
|
<el-dialog v-model="dialogVisible" title="添加关键词" width="500" :before-close="handleClose">
|
|
<el-dialog v-model="dialogVisible" title="添加关键词" width="500" :before-close="handleClose">
|
|
<el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" status-icon :rules="rules" label-width="auto">
|
|
<el-form ref="ruleFormRef" style="max-width: 600px" :model="ruleForm" status-icon :rules="rules" label-width="auto">
|
|
<el-form-item label="关键词" prop="searchTerm">
|
|
<el-form-item label="关键词" prop="searchTerm">
|