2025-03-26
This commit is contained in:
122
src/views/articleManagement/list/index.vue
Normal file
122
src/views/articleManagement/list/index.vue
Normal file
@@ -0,0 +1,122 @@
|
||||
<!-- 视频列表 -->
|
||||
<template>
|
||||
<div class="table-box">
|
||||
<div style="padding-bottom: 16px">
|
||||
<el-button type="primary" @click="handleAdd('add')"> 添加 </el-button>
|
||||
<el-button type="primary" @click="handleExport"> 导出 </el-button>
|
||||
</div>
|
||||
<ProTable
|
||||
ref="proTableRef"
|
||||
:formData="dataStore.formData"
|
||||
:columns="dataStore.columns"
|
||||
:request-api="getArticleListApi"
|
||||
:init-param="dataStore.initParam"
|
||||
>
|
||||
<template #image="scope">
|
||||
<el-image :src="h + scope.row.image" style="width: 60px; height: 60px" />
|
||||
</template>
|
||||
<template #enabled="scope">
|
||||
<el-tag type="success" effect="dark">{{ scope.row.enabled === 1 ? "启用" : "禁用" }}</el-tag>
|
||||
</template>
|
||||
<template #operation="scope">
|
||||
<el-button size="small" type="primary" @click="handleBtnClick('edit', scope.row)">编辑</el-button>
|
||||
<el-button size="small" type="danger" @click="handleBtnClick('del', scope.row)">删除</el-button>
|
||||
</template>
|
||||
</ProTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="articleListIndex">
|
||||
import { useExport } from "@/hooks/useExport";
|
||||
import { messageBox } from "@/utils/messageBox";
|
||||
import { useMsg } from "@/hooks/useMsg";
|
||||
import ProTable from "@/components/ProTable/index.vue";
|
||||
//列表接口
|
||||
import {
|
||||
getArticleListApi,
|
||||
getArticleClassDataApi,
|
||||
getArticleListExportApi,
|
||||
getArticleListDelApi
|
||||
} from "@/api/modules/articleList";
|
||||
import { useSearchInfoArray } from "@/hooks/useSearch";
|
||||
//深拷贝方法
|
||||
import { cloneDeep } from "lodash-es";
|
||||
//表格和搜索條件
|
||||
import { RULE_FORM, FORM_DATA, COLUMNS } from "./constant/index";
|
||||
//图片地址
|
||||
const h = import.meta.env.VITE_APP_API_BASE_UPLOAD_URL;
|
||||
// 获取 ProTable 元素,调用其获取刷新数据方法(还能获取到当前查询参数,方便导出携带参数)
|
||||
const proTableRef = ref<any>(null);
|
||||
const $router = useRouter();
|
||||
|
||||
// 数据源
|
||||
const dataStore = reactive<any>({
|
||||
columns: COLUMNS, //列表配置项
|
||||
initParam: cloneDeep(RULE_FORM), // 初始化搜索条件|重置搜索条件
|
||||
ruleForm: cloneDeep(RULE_FORM), // 搜索參數
|
||||
formData: FORM_DATA, //搜索配置项
|
||||
selectRow: {} //当前选择的row
|
||||
});
|
||||
|
||||
//文章分类(搜索条件)
|
||||
const getArticleClassData = async () => {
|
||||
const result = await getArticleClassDataApi();
|
||||
if (result?.code === 0) {
|
||||
const { data } = result;
|
||||
dataStore.formData[1].options = useSearchInfoArray(data);
|
||||
}
|
||||
};
|
||||
getArticleClassData();
|
||||
//添加
|
||||
const handleAdd = (type: any) => {
|
||||
$router.push({
|
||||
path: "/admin/articleManagement/list/edit",
|
||||
query: {
|
||||
type,
|
||||
title: "添加文章"
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//导出接口
|
||||
const getArticleListExport = async () => {
|
||||
const result = await getArticleListExportApi(dataStore.ruleForm);
|
||||
await useExport(result);
|
||||
};
|
||||
//导出
|
||||
const handleExport = () => {
|
||||
getArticleListExport();
|
||||
};
|
||||
//删除
|
||||
const getArticleListDel = async (id: any) => {
|
||||
messageBox("你确定要删除?", async () => {
|
||||
const result = await getArticleListDelApi(id);
|
||||
if (result?.code === 0) {
|
||||
const { msg } = result;
|
||||
useMsg("success", msg);
|
||||
proTableRef?.value?.getTableList();
|
||||
}
|
||||
});
|
||||
};
|
||||
//按钮点击事件
|
||||
const handleBtnClick = (type: any, row: any) => {
|
||||
dataStore.selectRow = row;
|
||||
//编辑
|
||||
if (type === "edit") {
|
||||
$router.push({
|
||||
path: "/admin/articleManagement/list/edit",
|
||||
query: {
|
||||
id: row.id,
|
||||
type
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
//删除
|
||||
if (type === "del") {
|
||||
getArticleListDel(row.id);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
Reference in New Issue
Block a user