|
@@ -48,6 +48,12 @@
|
|
|
<el-table-column label="分类名称" align="center" prop="name" />
|
|
<el-table-column label="分类名称" align="center" prop="name" />
|
|
|
<el-table-column label="唯一编码" align="center" prop="code" />
|
|
<el-table-column label="唯一编码" align="center" prop="code" />
|
|
|
<el-table-column label="排序" align="center" prop="sort" />
|
|
<el-table-column label="排序" align="center" prop="sort" />
|
|
|
|
|
+ <el-table-column label="图标" align="center" prop="iconUrl" width="120">
|
|
|
|
|
+ <template #default="scope">
|
|
|
|
|
+ <img v-if="scope.row.iconUrl" :src="scope.row.iconUrl" alt="" style="width: 40px; height: 40px; object-fit: cover; border-radius: 4px" />
|
|
|
|
|
+ <span v-else>无</span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-table-column>
|
|
|
<el-table-column label="是否显示" align="center" prop="isShow" />
|
|
<el-table-column label="是否显示" align="center" prop="isShow" />
|
|
|
<el-table-column label="创建时间" align="center" prop="createdAt" width="180">
|
|
<el-table-column label="创建时间" align="center" prop="createdAt" width="180">
|
|
|
<template #default="scope">
|
|
<template #default="scope">
|
|
@@ -80,6 +86,43 @@
|
|
|
<el-form-item label="排序" prop="sort">
|
|
<el-form-item label="排序" prop="sort">
|
|
|
<el-input v-model="form.sort" placeholder="请输入排序,越大越靠前" />
|
|
<el-input v-model="form.sort" placeholder="请输入排序,越大越靠前" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
|
|
+ <el-form-item label="图标" prop="iconUrl">
|
|
|
|
|
+ <div class="upload-container">
|
|
|
|
|
+ <el-upload
|
|
|
|
|
+ class="upload-icon"
|
|
|
|
|
+ action="#"
|
|
|
|
|
+ :on-change="handleIconChange"
|
|
|
|
|
+ :on-remove="handleIconRemove"
|
|
|
|
|
+ :file-list="fileList"
|
|
|
|
|
+ :auto-upload="false"
|
|
|
|
|
+ :limit="1"
|
|
|
|
|
+ accept="image/*"
|
|
|
|
|
+ >
|
|
|
|
|
+ <template #trigger>
|
|
|
|
|
+ <el-button type="primary">点击选择图标</el-button>
|
|
|
|
|
+ </template>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- 预览图区域 -->
|
|
|
|
|
+ <template #default>
|
|
|
|
|
+ <div class="preview-area" @click="handlePreviewClick">
|
|
|
|
|
+ <img
|
|
|
|
|
+ v-if="iconPreviewUrl || form.iconUrl"
|
|
|
|
|
+ :src="iconPreviewUrl || form.iconUrl"
|
|
|
|
|
+ alt="预览图"
|
|
|
|
|
+ style="max-width: 100px; max-height: 100px; margin-top: 10px; cursor: pointer"
|
|
|
|
|
+ />
|
|
|
|
|
+ <div v-else style="margin-top: 10px; color: #999">无</div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+
|
|
|
|
|
+ <template #tip>
|
|
|
|
|
+ <div class="el-upload__tip">
|
|
|
|
|
+ <span v-if="fileList.length > 0">当前已选文件:{{ fileList[0].name }}</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </el-upload>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-form-item>
|
|
|
<el-form-item label="是否显示" prop="isShow">
|
|
<el-form-item label="是否显示" prop="isShow">
|
|
|
<el-radio-group v-model="form.isShow">
|
|
<el-radio-group v-model="form.isShow">
|
|
|
<el-radio :label="1">是</el-radio>
|
|
<el-radio :label="1">是</el-radio>
|
|
@@ -100,7 +143,7 @@
|
|
|
<script setup name="Category" lang="ts">
|
|
<script setup name="Category" lang="ts">
|
|
|
import { listCategory, getCategory, delCategory, addCategory, updateCategory } from '@/api/system/business/category';
|
|
import { listCategory, getCategory, delCategory, addCategory, updateCategory } from '@/api/system/business/category';
|
|
|
import { CategoryVO, CategoryQuery, CategoryForm } from '@/api/system/business/category/types';
|
|
import { CategoryVO, CategoryQuery, CategoryForm } from '@/api/system/business/category/types';
|
|
|
-
|
|
|
|
|
|
|
+import { uploadTournament } from '@/api/system/business/tournaments';
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
|
|
|
|
|
const categoryList = ref<CategoryVO[]>([]);
|
|
const categoryList = ref<CategoryVO[]>([]);
|
|
@@ -174,6 +217,10 @@ const cancel = () => {
|
|
|
const reset = () => {
|
|
const reset = () => {
|
|
|
form.value = { ...initFormData };
|
|
form.value = { ...initFormData };
|
|
|
categoryFormRef.value?.resetFields();
|
|
categoryFormRef.value?.resetFields();
|
|
|
|
|
+ // 清空上传相关状态
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ iconPreviewUrl.value = '';
|
|
|
|
|
+ form.value.iconUrl = '';
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/** 搜索按钮操作 */
|
|
/** 搜索按钮操作 */
|
|
@@ -200,6 +247,10 @@ const handleAdd = () => {
|
|
|
reset();
|
|
reset();
|
|
|
dialog.visible = true;
|
|
dialog.visible = true;
|
|
|
dialog.title = '添加新闻分类';
|
|
dialog.title = '添加新闻分类';
|
|
|
|
|
+ // 清空上传相关状态
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+ iconPreviewUrl.value = '';
|
|
|
|
|
+ form.value.iconUrl = '';
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
/** 修改按钮操作 */
|
|
/** 修改按钮操作 */
|
|
@@ -208,6 +259,10 @@ const handleUpdate = async (row?: CategoryVO) => {
|
|
|
const _id = row?.id || ids.value[0];
|
|
const _id = row?.id || ids.value[0];
|
|
|
const res = await getCategory(_id);
|
|
const res = await getCategory(_id);
|
|
|
Object.assign(form.value, res.data);
|
|
Object.assign(form.value, res.data);
|
|
|
|
|
+ // 设置预览图
|
|
|
|
|
+ if (form.value.iconUrl) {
|
|
|
|
|
+ iconPreviewUrl.value = form.value.iconUrl;
|
|
|
|
|
+ }
|
|
|
dialog.visible = true;
|
|
dialog.visible = true;
|
|
|
dialog.title = '修改新闻分类';
|
|
dialog.title = '修改新闻分类';
|
|
|
};
|
|
};
|
|
@@ -252,4 +307,64 @@ const handleExport = () => {
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
getList();
|
|
getList();
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+// 添加响应式变量(在其他ref声明附近添加)
|
|
|
|
|
+const iconPreviewUrl = ref('');
|
|
|
|
|
+const fileList = ref([]);
|
|
|
|
|
+const dialogVisible = ref(false);
|
|
|
|
|
+const previewSrc = ref('');
|
|
|
|
|
+
|
|
|
|
|
+/** 处理图标上传 */
|
|
|
|
|
+const handleIconChange = async (file) => {
|
|
|
|
|
+ const index = fileList.value.findIndex((f) => f.uid === file.uid);
|
|
|
|
|
+ fileList.value = [];
|
|
|
|
|
+
|
|
|
|
|
+ if (file.raw) {
|
|
|
|
|
+ iconPreviewUrl.value = URL.createObjectURL(file.raw);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (index === -1) {
|
|
|
|
|
+ fileList.value.push(file);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ const rawFile = file.raw;
|
|
|
|
|
+ const res = await uploadTournament(rawFile);
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
|
+ fileList.value[index] = {
|
|
|
|
|
+ ...file,
|
|
|
|
|
+ status: 'success',
|
|
|
|
|
+ response: res.data.url
|
|
|
|
|
+ };
|
|
|
|
|
+ form.value.iconUrl = fileList.value[index].response;
|
|
|
|
|
+ iconPreviewUrl.value = fileList.value[index].response;
|
|
|
|
|
+ proxy?.$modal.msgSuccess('上传成功');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error(res.msg);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ fileList.value[index] = {
|
|
|
|
|
+ ...file,
|
|
|
|
|
+ status: 'fail',
|
|
|
|
|
+ error: '上传失败'
|
|
|
|
|
+ };
|
|
|
|
|
+ proxy?.$modal.msgError('上传失败,请重试');
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/** 处理图标删除 */
|
|
|
|
|
+const handleIconRemove = (file, updatedFileList) => {
|
|
|
|
|
+ fileList.value = updatedFileList;
|
|
|
|
|
+ iconPreviewUrl.value = '';
|
|
|
|
|
+ form.value.iconUrl = '';
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+/** 点击预览图触发放大 */
|
|
|
|
|
+const handlePreviewClick = () => {
|
|
|
|
|
+ const currentSrc = iconPreviewUrl.value || form.value.iconUrl;
|
|
|
|
|
+ if (currentSrc) {
|
|
|
|
|
+ previewSrc.value = currentSrc;
|
|
|
|
|
+ dialogVisible.value = true;
|
|
|
|
|
+ }
|
|
|
|
|
+};
|
|
|
</script>
|
|
</script>
|