first
This commit is contained in:
224
src/views/manga/components/chapter.vue
Normal file
224
src/views/manga/components/chapter.vue
Normal file
@@ -0,0 +1,224 @@
|
||||
<template>
|
||||
<el-drawer v-model="drawerVisible" size="80%" title="章节列表" :destroy-on-close="true">
|
||||
<ProTable
|
||||
ref="proTable"
|
||||
highlight-current-row
|
||||
:columns="columns"
|
||||
:request-api="getTableList"
|
||||
:data-callback="dataCallback"
|
||||
:init-param="initParam"
|
||||
:is-displayed="isDisplayed"
|
||||
:is-search-location="isSearchLocation"
|
||||
>
|
||||
<!-- 表格 header 按钮 -->
|
||||
<template #tableHeader="scope">
|
||||
<el-button type="primary" style="display: none" :icon="CirclePlus" @click="openDrawer(true)">
|
||||
新增漫画章节
|
||||
</el-button>
|
||||
<el-button
|
||||
style="display: none"
|
||||
type="danger"
|
||||
:icon="Delete"
|
||||
plain
|
||||
:disabled="!scope.isSelected"
|
||||
@click="batchDelete(scope.selectedList)"
|
||||
>
|
||||
批量删除章节
|
||||
</el-button>
|
||||
<el-button
|
||||
style="display: none"
|
||||
type="primary"
|
||||
:icon="EditPen"
|
||||
plain
|
||||
:disabled="!scope.isSelected"
|
||||
@click="batchModify(scope.selectedList)"
|
||||
>
|
||||
批量编辑漫画章节
|
||||
</el-button>
|
||||
</template>
|
||||
<!-- 表格操作 -->
|
||||
<template #operation="scope">
|
||||
<el-button type="primary" link :icon="EditPen" @click="openDrawer(false, scope.row)">编辑</el-button>
|
||||
<el-button type="danger" style="display: none" link :icon="Delete" @click="deleteAccount(scope.row)">
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</ProTable>
|
||||
<template #footer>
|
||||
<el-button @click="drawerVisible = false">取消</el-button>
|
||||
<el-button @click="drawerVisible = false" type="primary">确定</el-button>
|
||||
</template>
|
||||
<ChapterDrawer ref="chapterDrawerRef" />
|
||||
<ModifyDrawer ref="modifyDrawerRef" />
|
||||
<ImgDialog ref="imgDialogRef" />
|
||||
</el-drawer>
|
||||
</template>
|
||||
|
||||
<script setup lang="tsx">
|
||||
import { ref, reactive } from "vue";
|
||||
import ProTable from "@/components/ProTable/index.vue";
|
||||
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
|
||||
import { useHandleData } from "@/hooks/useHandleData";
|
||||
import { Delete, EditPen, CirclePlus } from "@element-plus/icons-vue";
|
||||
import { ChapterList } from "@/api/interface/manga/chapter";
|
||||
import { getList, saveData, deleteItem, batchData } from "@/api/modules/manga/chapter";
|
||||
import ChapterDrawer from "../component/chapterDrawer.vue";
|
||||
import ModifyDrawer from "../component/modifyDrawer.vue";
|
||||
import ImgDialog from "../../components/imgDialog.vue";
|
||||
// ProTable 实例
|
||||
const proTable = ref<ProTableInstance>();
|
||||
|
||||
// 如果表格需要初始化请求参数,直接定义传给 ProTable(之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
|
||||
const initParam = reactive({
|
||||
mhxq_id: 0,
|
||||
limit: 25,
|
||||
page: 1
|
||||
});
|
||||
|
||||
const dataCallback = (data: any) => {
|
||||
return {
|
||||
items: data.items,
|
||||
total: data.total,
|
||||
total_page: data.total_pages,
|
||||
page: initParam.page,
|
||||
limit: initParam.limit
|
||||
};
|
||||
};
|
||||
|
||||
const getTableList = async (params: any) => {
|
||||
let newParams = JSON.parse(JSON.stringify(params));
|
||||
initParam.page = newParams.page;
|
||||
initParam.limit = newParams.limit;
|
||||
return getList(newParams);
|
||||
};
|
||||
|
||||
const isDisplayed = ref<any>(false);
|
||||
const isSearchLocation = ref<any>(false);
|
||||
|
||||
// 表格配置项
|
||||
const columns = reactive<ColumnProps<ChapterList.ResList>[]>([
|
||||
// { type: "selection", fixed: "left", width: 50 },
|
||||
{
|
||||
prop: "key",
|
||||
label: "搜索内容",
|
||||
isShow: false,
|
||||
search: {
|
||||
el: "input"
|
||||
}
|
||||
},
|
||||
{
|
||||
prop: "mhzj_id",
|
||||
label: "ID",
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
prop: "mhzj_pai_xu",
|
||||
label: "章节序号",
|
||||
width: 100
|
||||
},
|
||||
{
|
||||
prop: "mhzj_ming_zi",
|
||||
label: "章节标题"
|
||||
},
|
||||
{
|
||||
prop: "mhzj_nei_rong",
|
||||
label: "图册资源",
|
||||
render(scope) {
|
||||
if (scope.row.mhzj_nei_rong) {
|
||||
return <el-tag onClick={() => openImgFun(scope.row)}>查看</el-tag>;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ prop: "mhzj_source_code", label: "源站" },
|
||||
{ prop: "created_at", label: "添加时间" }
|
||||
// { prop: "operation", label: "操作", fixed: "right", width: 200 }
|
||||
]);
|
||||
|
||||
const drawerVisible = ref(false);
|
||||
// 接收父组件传过来的参数
|
||||
const acceptParams = (data: any) => {
|
||||
drawerVisible.value = true;
|
||||
initParam.mhxq_id = data.mhxq_id;
|
||||
};
|
||||
|
||||
// 删除章节
|
||||
const deleteAccount = async (params: ChapterList.ResList) => {
|
||||
await useHandleData(deleteItem, { mhzj_id: params.mhzj_id, mhxq_id: initParam.mhxq_id }, "删除所选信息");
|
||||
proTable.value?.getTableList();
|
||||
};
|
||||
|
||||
// 批量删除章节
|
||||
const batchDelete = async (id: any[]) => {
|
||||
const ids = id.map((item: ChapterList.ResList) => item.mhzj_id);
|
||||
await useHandleData(deleteItem, { mhzj_id: ids.join(","), mhxq_id: initParam.mhxq_id }, "删除所选信息");
|
||||
proTable.value?.clearSelection();
|
||||
proTable.value?.getTableList();
|
||||
};
|
||||
|
||||
// 打开 drawer(新增、编辑)
|
||||
const chapterDrawerRef = ref<InstanceType<typeof ChapterDrawer> | null>(null);
|
||||
|
||||
const openDrawer = (isEdit: boolean, row: Partial<ChapterList.ResList> = {}) => {
|
||||
row.mhxq_id = initParam.mhxq_id;
|
||||
const params = {
|
||||
title: isEdit ? "新增漫画章节" : "编辑漫画章节",
|
||||
row: { ...row },
|
||||
api: saveData,
|
||||
getTableList: proTable.value?.getTableList
|
||||
};
|
||||
chapterDrawerRef.value?.acceptParams(params as any);
|
||||
};
|
||||
|
||||
// 批量修改视频信息
|
||||
const modifyDrawerRef = ref<InstanceType<typeof ModifyDrawer> | null>(null);
|
||||
const batchModify = async (id: any[], row: Partial<ChapterList.ResList> = {}) => {
|
||||
const ids = id.map((item: ChapterList.ResList) => item.mhxq_id);
|
||||
row.mhzj_id = ids.join(",");
|
||||
row.mhxq_id = initParam.mhxq_id;
|
||||
const params = {
|
||||
title: "批量编辑漫画章节",
|
||||
row: { ...row },
|
||||
api: batchData,
|
||||
getTableList: proTable.value?.getTableList,
|
||||
clearSelection: proTable.value?.clearSelection
|
||||
};
|
||||
modifyDrawerRef.value?.acceptParams(params as any);
|
||||
};
|
||||
|
||||
// 图册资源
|
||||
const imgDialogRef = ref<InstanceType<typeof ImgDialog> | null>(null);
|
||||
const openImgFun = (row: Partial<ChapterList.ResList> = {}) => {
|
||||
row.name = row.mhzj_ming_zi;
|
||||
row.url = row.mhzj_nei_rong_url;
|
||||
const params = {
|
||||
title: "图册资源",
|
||||
row: { ...row },
|
||||
getTableList: proTable.value?.getTableList
|
||||
};
|
||||
imgDialogRef.value?.acceptParams(params as any);
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
acceptParams
|
||||
});
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.demo-form-inline {
|
||||
.el-form-item {
|
||||
width: 420px;
|
||||
}
|
||||
:deep(.el-form-item__content) {
|
||||
display: flex;
|
||||
flex-wrap: nowrap;
|
||||
align-items: flex-start;
|
||||
.tips {
|
||||
margin-left: 10px;
|
||||
font-size: 12px;
|
||||
color: #999999;
|
||||
}
|
||||
}
|
||||
}
|
||||
.btn-group {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user