2019-10-20 11:42:56 +08:00
|
|
|
<template>
|
2019-12-27 16:28:41 +08:00
|
|
|
<div v-loading.fullscreen.lock="fullscreenLoading">
|
2025-10-19 13:27:48 +08:00
|
|
|
<div class="flex gap-4 pt-2">
|
|
|
|
|
<div
|
|
|
|
|
class="flex-none w-64 bg-white text-slate-700 dark:text-slate-400 dark:bg-slate-900 rounded p-4"
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
<el-scrollbar style="height: calc(100vh - 300px)">
|
|
|
|
|
<el-tree
|
2025-10-19 13:27:48 +08:00
|
|
|
:data="categories"
|
|
|
|
|
node-key="id"
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
@node-click="handleNodeClick"
|
|
|
|
|
default-expand-all
|
2025-02-13 15:25:10 +08:00
|
|
|
>
|
|
|
|
|
<template #default="{ node, data }">
|
2025-10-19 13:27:48 +08:00
|
|
|
<div
|
|
|
|
|
class="w-36"
|
|
|
|
|
:class="
|
|
|
|
|
search.classId === data.ID ? 'text-blue-500 font-bold' : ''
|
|
|
|
|
"
|
|
|
|
|
>
|
|
|
|
|
{{ data.name }}
|
2025-02-13 15:25:10 +08:00
|
|
|
</div>
|
|
|
|
|
<el-dropdown>
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-icon class="ml-3 text-right" v-if="data.ID > 0"
|
|
|
|
|
><MoreFilled
|
|
|
|
|
/></el-icon>
|
2025-02-13 15:25:10 +08:00
|
|
|
<el-icon class="ml-3 text-right mt-1" v-else><Plus /></el-icon>
|
|
|
|
|
<template #dropdown>
|
|
|
|
|
<el-dropdown-menu>
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-dropdown-item @click="addCategoryFun(data)"
|
|
|
|
|
>添加分类</el-dropdown-item
|
|
|
|
|
>
|
|
|
|
|
<el-dropdown-item
|
|
|
|
|
@click="editCategory(data)"
|
|
|
|
|
v-if="data.ID > 0"
|
|
|
|
|
>编辑分类</el-dropdown-item
|
|
|
|
|
>
|
|
|
|
|
<el-dropdown-item
|
|
|
|
|
@click="deleteCategoryFun(data.ID)"
|
|
|
|
|
v-if="data.ID > 0"
|
|
|
|
|
>删除分类</el-dropdown-item
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
</el-dropdown-menu>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dropdown>
|
|
|
|
|
</template>
|
|
|
|
|
</el-tree>
|
|
|
|
|
</el-scrollbar>
|
2021-09-14 19:49:06 +08:00
|
|
|
</div>
|
2025-10-19 13:27:48 +08:00
|
|
|
<div
|
|
|
|
|
class="flex-1 bg-white text-slate-700 dark:text-slate-400 dark:bg-slate-900"
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
<div class="gva-table-box mt-0 mb-0">
|
2025-10-19 13:27:48 +08:00
|
|
|
<warning-bar
|
|
|
|
|
title="点击“文件名”可以编辑;选择的类别即是上传的类别。"
|
|
|
|
|
/>
|
2025-02-13 15:25:10 +08:00
|
|
|
<div class="gva-btn-list gap-3">
|
2025-10-19 13:27:48 +08:00
|
|
|
<upload-common
|
|
|
|
|
:image-common="imageCommon"
|
|
|
|
|
:classId="search.classId"
|
|
|
|
|
@on-success="onSuccess"
|
|
|
|
|
/>
|
2025-02-19 18:08:31 +08:00
|
|
|
<cropper-image :classId="search.classId" @on-success="onSuccess" />
|
|
|
|
|
<QRCodeUpload :classId="search.classId" @on-success="onSuccess" />
|
2025-02-13 15:25:10 +08:00
|
|
|
<upload-image
|
2025-10-19 13:27:48 +08:00
|
|
|
:image-url="imageUrl"
|
|
|
|
|
:file-size="512"
|
|
|
|
|
:max-w-h="1080"
|
|
|
|
|
:classId="search.classId"
|
|
|
|
|
@on-success="onSuccess"
|
2025-02-13 15:25:10 +08:00
|
|
|
/>
|
|
|
|
|
<el-button type="primary" icon="upload" @click="importUrlFunc">
|
|
|
|
|
导入URL
|
|
|
|
|
</el-button>
|
|
|
|
|
<el-input
|
2025-10-19 13:27:48 +08:00
|
|
|
v-model="search.keyword"
|
|
|
|
|
class="w-72"
|
|
|
|
|
placeholder="请输入文件名或备注"
|
2025-02-13 15:25:10 +08:00
|
|
|
/>
|
|
|
|
|
<el-button type="primary" icon="search" @click="onSubmit"
|
2025-10-19 13:27:48 +08:00
|
|
|
>查询
|
|
|
|
|
</el-button>
|
2025-02-13 15:25:10 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<el-table :data="tableData">
|
|
|
|
|
<el-table-column align="left" label="预览" width="100">
|
|
|
|
|
<template #default="scope">
|
2025-10-19 13:27:48 +08:00
|
|
|
<CustomPic pic-type="file" :pic-src="scope.row.url" preview />
|
2025-02-13 15:25:10 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-table-column
|
|
|
|
|
align="left"
|
|
|
|
|
label="日期"
|
|
|
|
|
prop="UpdatedAt"
|
|
|
|
|
width="180"
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
<template #default="scope">
|
|
|
|
|
<div>{{ formatDate(scope.row.UpdatedAt) }}</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column
|
2025-10-19 13:27:48 +08:00
|
|
|
align="left"
|
|
|
|
|
label="文件名/备注"
|
|
|
|
|
prop="name"
|
|
|
|
|
width="180"
|
2024-11-09 10:32:26 +08:00
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
<template #default="scope">
|
2025-10-19 13:27:48 +08:00
|
|
|
<div
|
|
|
|
|
class="cursor-pointer"
|
|
|
|
|
@click="editFileNameFunc(scope.row)"
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
{{ scope.row.name }}
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-table-column
|
|
|
|
|
align="left"
|
|
|
|
|
label="链接"
|
|
|
|
|
prop="url"
|
|
|
|
|
min-width="300"
|
|
|
|
|
/>
|
2025-02-13 15:25:10 +08:00
|
|
|
<el-table-column align="left" label="标签" prop="tag" width="100">
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<el-tag
|
2025-10-19 13:27:48 +08:00
|
|
|
:type="
|
|
|
|
|
scope.row.tag?.toLowerCase() === 'jpg' ? 'info' : 'success'
|
|
|
|
|
"
|
|
|
|
|
disable-transitions
|
|
|
|
|
>{{ scope.row.tag }}
|
2025-02-13 15:25:10 +08:00
|
|
|
</el-tag>
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column align="left" label="操作" width="160">
|
|
|
|
|
<template #default="scope">
|
|
|
|
|
<el-button
|
2025-10-19 13:27:48 +08:00
|
|
|
icon="download"
|
|
|
|
|
type="primary"
|
|
|
|
|
link
|
|
|
|
|
@click="downloadFile(scope.row)"
|
|
|
|
|
>下载
|
|
|
|
|
</el-button>
|
2025-02-13 15:25:10 +08:00
|
|
|
<el-button
|
2025-10-19 13:27:48 +08:00
|
|
|
icon="delete"
|
|
|
|
|
type="primary"
|
|
|
|
|
link
|
|
|
|
|
@click="deleteFileFunc(scope.row)"
|
|
|
|
|
>删除
|
|
|
|
|
</el-button>
|
2025-02-13 15:25:10 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
<div class="gva-pagination">
|
|
|
|
|
<el-pagination
|
2025-10-19 13:27:48 +08:00
|
|
|
:current-page="page"
|
|
|
|
|
:page-size="pageSize"
|
|
|
|
|
:page-sizes="[10, 30, 50, 100]"
|
|
|
|
|
:style="{ float: 'right', padding: '20px' }"
|
|
|
|
|
:total="total"
|
|
|
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
|
|
|
@current-change="handleCurrentChange"
|
|
|
|
|
@size-change="handleSizeChange"
|
2025-02-13 15:25:10 +08:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-09-18 00:10:17 +08:00
|
|
|
</div>
|
2020-02-03 10:58:29 +08:00
|
|
|
</div>
|
2025-02-13 15:25:10 +08:00
|
|
|
|
|
|
|
|
<!-- 添加分类弹窗 -->
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-dialog
|
|
|
|
|
v-model="categoryDialogVisible"
|
|
|
|
|
@close="closeAddCategoryDialog"
|
|
|
|
|
width="520"
|
|
|
|
|
:title="(categoryFormData.ID === 0 ? '添加' : '编辑') + '分类'"
|
|
|
|
|
draggable
|
2025-02-13 15:25:10 +08:00
|
|
|
>
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-form
|
|
|
|
|
ref="categoryForm"
|
|
|
|
|
:rules="rules"
|
|
|
|
|
:model="categoryFormData"
|
|
|
|
|
label-width="80px"
|
|
|
|
|
>
|
2025-02-13 15:25:10 +08:00
|
|
|
<el-form-item label="上级分类">
|
|
|
|
|
<el-tree-select
|
2025-10-19 13:27:48 +08:00
|
|
|
v-model="categoryFormData.pid"
|
|
|
|
|
:data="categories"
|
|
|
|
|
check-strictly
|
|
|
|
|
:props="defaultProps"
|
|
|
|
|
:render-after-expand="false"
|
|
|
|
|
style="width: 240px"
|
2025-02-13 15:25:10 +08:00
|
|
|
/>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="分类名称" prop="name">
|
2025-10-19 13:27:48 +08:00
|
|
|
<el-input
|
|
|
|
|
v-model.trim="categoryFormData.name"
|
|
|
|
|
placeholder="分类名称"
|
|
|
|
|
></el-input>
|
2025-02-13 15:25:10 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
<template #footer>
|
|
|
|
|
<el-button @click="closeAddCategoryDialog">取消</el-button>
|
|
|
|
|
<el-button type="primary" @click="confirmAddCategory">确定</el-button>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
2019-10-25 17:34:36 +08:00
|
|
|
</div>
|
2019-10-20 11:42:56 +08:00
|
|
|
</template>
|
2020-04-25 10:14:17 +08:00
|
|
|
|
2021-12-30 22:41:53 +08:00
|
|
|
<script setup>
|
2025-10-19 13:27:48 +08:00
|
|
|
import {
|
|
|
|
|
getFileList,
|
|
|
|
|
deleteFile,
|
|
|
|
|
editFileName,
|
|
|
|
|
importURL
|
|
|
|
|
} from '@/api/fileUploadAndDownload'
|
|
|
|
|
import { downloadImage } from '@/utils/downloadImg'
|
|
|
|
|
import CustomPic from '@/components/customPic/index.vue'
|
|
|
|
|
import UploadImage from '@/components/upload/image.vue'
|
|
|
|
|
import UploadCommon from '@/components/upload/common.vue'
|
|
|
|
|
import { CreateUUID, formatDate } from '@/utils/format'
|
|
|
|
|
import WarningBar from '@/components/warningBar/warningBar.vue'
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
import { ref } from 'vue'
|
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
|
import {
|
|
|
|
|
addCategory,
|
|
|
|
|
deleteCategory,
|
|
|
|
|
getCategoryList
|
|
|
|
|
} from '@/api/attachmentCategory'
|
|
|
|
|
import CropperImage from '@/components/upload/cropper.vue'
|
|
|
|
|
import QRCodeUpload from '@/components/upload/QR-code.vue'
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
defineOptions({
|
|
|
|
|
name: 'Upload'
|
|
|
|
|
})
|
2023-09-14 18:47:47 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const fullscreenLoading = ref(false)
|
|
|
|
|
const path = ref(import.meta.env.VITE_BASE_API)
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const imageUrl = ref('')
|
|
|
|
|
const imageCommon = ref('')
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const page = ref(1)
|
|
|
|
|
const total = ref(0)
|
|
|
|
|
const pageSize = ref(10)
|
|
|
|
|
const search = ref({
|
|
|
|
|
keyword: null,
|
|
|
|
|
classId: 0
|
|
|
|
|
})
|
|
|
|
|
const tableData = ref([])
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
// 分页
|
|
|
|
|
const handleSizeChange = (val) => {
|
|
|
|
|
pageSize.value = val
|
|
|
|
|
getTableData()
|
|
|
|
|
}
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const handleCurrentChange = (val) => {
|
|
|
|
|
page.value = val
|
|
|
|
|
getTableData()
|
|
|
|
|
}
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const onSubmit = () => {
|
|
|
|
|
search.value.classId = 0
|
|
|
|
|
page.value = 1
|
|
|
|
|
getTableData()
|
|
|
|
|
}
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
// 查询
|
|
|
|
|
const getTableData = async () => {
|
|
|
|
|
const table = await getFileList({
|
|
|
|
|
page: page.value,
|
|
|
|
|
pageSize: pageSize.value,
|
|
|
|
|
...search.value
|
|
|
|
|
})
|
|
|
|
|
if (table.code === 0) {
|
|
|
|
|
tableData.value = table.data.list
|
|
|
|
|
total.value = table.data.total
|
|
|
|
|
page.value = table.data.page
|
|
|
|
|
pageSize.value = table.data.pageSize
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
}
|
2025-10-19 13:27:48 +08:00
|
|
|
getTableData()
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const deleteFileFunc = async (row) => {
|
|
|
|
|
ElMessageBox.confirm('此操作将永久删除文件, 是否继续?', '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
})
|
2024-11-09 10:32:26 +08:00
|
|
|
.then(async () => {
|
|
|
|
|
const res = await deleteFile(row)
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '删除成功!'
|
|
|
|
|
})
|
|
|
|
|
if (tableData.value.length === 1 && page.value > 1) {
|
|
|
|
|
page.value--
|
|
|
|
|
}
|
2025-02-19 18:08:31 +08:00
|
|
|
await getTableData()
|
2024-11-09 10:32:26 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
2021-12-30 22:41:53 +08:00
|
|
|
ElMessage({
|
2024-11-09 10:32:26 +08:00
|
|
|
type: 'info',
|
|
|
|
|
message: '已取消删除'
|
2021-06-02 14:11:45 +08:00
|
|
|
})
|
|
|
|
|
})
|
2025-10-19 13:27:48 +08:00
|
|
|
}
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const downloadFile = (row) => {
|
|
|
|
|
if (row.url.indexOf('http://') > -1 || row.url.indexOf('https://') > -1) {
|
|
|
|
|
downloadImage(row.url, row.name)
|
|
|
|
|
} else {
|
|
|
|
|
downloadImage(path.value + '/' + row.url, row.name)
|
|
|
|
|
}
|
2024-11-09 10:32:26 +08:00
|
|
|
}
|
2024-09-12 20:48:03 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
/**
|
|
|
|
|
* 编辑文件名或者备注
|
|
|
|
|
* @param row
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
*/
|
|
|
|
|
const editFileNameFunc = async (row) => {
|
|
|
|
|
ElMessageBox.prompt('请输入文件名或者备注', '编辑', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
inputPattern: /\S/,
|
|
|
|
|
inputErrorMessage: '不能为空',
|
|
|
|
|
inputValue: row.name
|
|
|
|
|
})
|
|
|
|
|
.then(async ({ value }) => {
|
2024-11-09 10:32:26 +08:00
|
|
|
row.name = value
|
|
|
|
|
// console.log(row)
|
|
|
|
|
const res = await editFileName(row)
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '编辑成功!'
|
|
|
|
|
})
|
|
|
|
|
await getTableData()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'info',
|
|
|
|
|
message: '取消修改'
|
2024-09-12 20:48:03 +08:00
|
|
|
})
|
2024-11-09 10:32:26 +08:00
|
|
|
})
|
2025-10-19 13:27:48 +08:00
|
|
|
}
|
2024-11-09 10:32:26 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
/**
|
|
|
|
|
* 导入URL
|
|
|
|
|
*/
|
|
|
|
|
const importUrlFunc = () => {
|
|
|
|
|
ElMessageBox.prompt('格式:文件名|链接或者仅链接。', '导入', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
inputType: 'textarea',
|
|
|
|
|
inputPlaceholder:
|
2024-11-09 10:32:26 +08:00
|
|
|
'我的图片|https://my-oss.com/my.png\nhttps://my-oss.com/my_1.png',
|
2025-10-19 13:27:48 +08:00
|
|
|
inputPattern: /\S/,
|
|
|
|
|
inputErrorMessage: '不能为空'
|
|
|
|
|
})
|
|
|
|
|
.then(async ({ value }) => {
|
2024-11-09 10:32:26 +08:00
|
|
|
let data = value.split('\n')
|
|
|
|
|
let importData = []
|
|
|
|
|
data.forEach((item) => {
|
|
|
|
|
let oneData = item.trim().split('|')
|
|
|
|
|
let url, name
|
|
|
|
|
if (oneData.length > 1) {
|
|
|
|
|
name = oneData[0].trim()
|
|
|
|
|
url = oneData[1]
|
|
|
|
|
} else {
|
|
|
|
|
url = oneData[0].trim()
|
|
|
|
|
let str = url.substring(url.lastIndexOf('/') + 1)
|
|
|
|
|
name = str.substring(0, str.lastIndexOf('.'))
|
|
|
|
|
}
|
|
|
|
|
if (url) {
|
|
|
|
|
importData.push({
|
|
|
|
|
name: name,
|
|
|
|
|
url: url,
|
2025-02-13 15:25:10 +08:00
|
|
|
classId: search.value.classId,
|
2024-11-09 10:32:26 +08:00
|
|
|
tag: url.substring(url.lastIndexOf('.') + 1),
|
|
|
|
|
key: CreateUUID()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-09-12 20:48:03 +08:00
|
|
|
|
2024-11-09 10:32:26 +08:00
|
|
|
const res = await importURL(importData)
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'success',
|
|
|
|
|
message: '导入成功!'
|
|
|
|
|
})
|
|
|
|
|
await getTableData()
|
|
|
|
|
}
|
2024-09-12 20:48:03 +08:00
|
|
|
})
|
2024-11-09 10:32:26 +08:00
|
|
|
.catch(() => {
|
|
|
|
|
ElMessage({
|
|
|
|
|
type: 'info',
|
|
|
|
|
message: '取消导入'
|
|
|
|
|
})
|
|
|
|
|
})
|
2025-10-19 13:27:48 +08:00
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const onSuccess = () => {
|
|
|
|
|
search.value.keyword = null
|
|
|
|
|
page.value = 1
|
|
|
|
|
getTableData()
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const defaultProps = {
|
|
|
|
|
children: 'children',
|
|
|
|
|
label: 'name',
|
|
|
|
|
value: 'ID'
|
2024-11-09 10:32:26 +08:00
|
|
|
}
|
2025-10-19 13:27:48 +08:00
|
|
|
|
|
|
|
|
const categories = ref([])
|
|
|
|
|
const fetchCategories = async () => {
|
|
|
|
|
const res = await getCategoryList()
|
|
|
|
|
let data = {
|
|
|
|
|
name: '全部分类',
|
|
|
|
|
ID: 0,
|
|
|
|
|
pid: 0,
|
|
|
|
|
children: []
|
|
|
|
|
}
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
categories.value = res.data || []
|
|
|
|
|
categories.value.unshift(data)
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const handleNodeClick = (node) => {
|
|
|
|
|
search.value.keyword = null
|
|
|
|
|
search.value.classId = node.ID
|
|
|
|
|
page.value = 1
|
|
|
|
|
getTableData()
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const categoryDialogVisible = ref(false)
|
|
|
|
|
const categoryFormData = ref({
|
|
|
|
|
ID: 0,
|
|
|
|
|
pid: 0,
|
|
|
|
|
name: ''
|
|
|
|
|
})
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const categoryForm = ref(null)
|
|
|
|
|
const rules = ref({
|
|
|
|
|
name: [
|
|
|
|
|
{ required: true, message: '请输入分类名称', trigger: 'blur' },
|
|
|
|
|
{ max: 20, message: '最多20位字符', trigger: 'blur' }
|
|
|
|
|
]
|
|
|
|
|
})
|
2021-12-30 22:41:53 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const addCategoryFun = (category) => {
|
|
|
|
|
categoryDialogVisible.value = true
|
|
|
|
|
categoryFormData.value.ID = 0
|
|
|
|
|
categoryFormData.value.pid = category.ID
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const editCategory = (category) => {
|
|
|
|
|
categoryFormData.value = {
|
|
|
|
|
ID: category.ID,
|
|
|
|
|
pid: category.pid,
|
|
|
|
|
name: category.name
|
|
|
|
|
}
|
|
|
|
|
categoryDialogVisible.value = true
|
2025-02-13 15:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const deleteCategoryFun = async (id) => {
|
|
|
|
|
const res = await deleteCategory({ id: id })
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
ElMessage.success({ type: 'success', message: '删除成功' })
|
|
|
|
|
await fetchCategories()
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
}
|
|
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const confirmAddCategory = async () => {
|
|
|
|
|
categoryForm.value.validate(async (valid) => {
|
|
|
|
|
if (valid) {
|
|
|
|
|
const res = await addCategory(categoryFormData.value)
|
|
|
|
|
if (res.code === 0) {
|
|
|
|
|
ElMessage({ type: 'success', message: '操作成功' })
|
|
|
|
|
await fetchCategories()
|
|
|
|
|
closeAddCategoryDialog()
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
}
|
2025-10-19 13:27:48 +08:00
|
|
|
})
|
|
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
const closeAddCategoryDialog = () => {
|
|
|
|
|
categoryDialogVisible.value = false
|
|
|
|
|
categoryFormData.value = {
|
|
|
|
|
ID: 0,
|
|
|
|
|
pid: 0,
|
|
|
|
|
name: ''
|
|
|
|
|
}
|
2024-11-09 10:32:26 +08:00
|
|
|
}
|
2025-02-13 15:25:10 +08:00
|
|
|
|
2025-10-19 13:27:48 +08:00
|
|
|
fetchCategories()
|
2025-02-13 15:25:10 +08:00
|
|
|
</script>
|