Files
PandaX/resource/template/vue/list-vue.template
2022-01-13 17:48:45 +08:00

280 lines
7.7 KiB
Plaintext

<template>
<div class="app-container">
<el-card shadow="always">
<!-- 查询 -->
<el-form
:model="queryParams"
ref="queryForm"
:inline="true"
label-width="68px"
>
<el-form-item label="案例名称" prop="name">
<el-input
placeholder="请输入案例名称模糊查询"
clearable
size="small"
@keyup.enter="handleQuery"
style="width: 240px"
v-model="queryParams.name"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="状态"
clearable
size="small"
style="width: 240px"
>
<el-option
v-for="dict in statusOptions"
:key="dict.dictValue"
:label="dict.dictLabel"
:value="dict.dictValue"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button
type="primary"
size="mini"
@click="handleQuery"
>
<SvgIcon name="elementSearch" />
搜索</el-button>
<el-button size="mini" @click="resetQuery">
<SvgIcon name="elementRefresh" />
重置
</el-button>
</el-form-item>
</el-form>
<!-- 操作按钮 -->
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
size="mini"
v-auth="'{{.PackageName}}:{{.BusinessName}}:add'"
@click="onOpenAddModule"
><SvgIcon name="elementPlus" />新增</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
size="mini"
v-auth="'{{.PackageName}}:{{.BusinessName}}:delete'"
:disabled="multiple"
@click="onTabelRowDel"
><SvgIcon name="elementDelete" />删除</el-button
>
</el-col>
</el-row>
<!--数据表格-->
<el-table
v-loading="loading"
:data="tableData"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="编号" align="center" prop="{{.PkJsonField}}" />
<el-table-column
label="状态"
align="center"
prop="status"
>
<template #default="scope">
<el-tag
:type="scope.row.status === '1' ? 'danger' : 'success'"
disable-transitions
>{{"{{"}} statusFormat(scope.row){{"}}"}}</el-tag>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template #default="scope">
<el-button
size="mini"
type="text"
v-auth="'{{.PackageName}}:{{.BusinessName}}:edit'"
@click="onOpenEditModule(scope.row)"
><SvgIcon name="elementEdit" />修改</el-button>
<el-button
v-if="scope.row.parentId != 0"
size="mini"
type="text"
v-auth="'{{.PackageName}}:{{.BusinessName}}:delete'"
@click="onTabelRowDel(scope.row)"
><SvgIcon name="elementDelete" />删除</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页设置-->
<div v-show="total > 0">
<el-divider></el-divider>
<el-pagination
background
:total="total"
:current-page="queryParams.pageNum"
:page-size="queryParams.pageSize"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</el-card>
<!-- 添加或修改岗位对话框 -->
<EditModule ref="editModuleRef" :title="title" />
</div>
</template>
<script lang="ts">
import {
ref,
toRefs,
reactive,
onMounted,
getCurrentInstance,
onUnmounted,
} from "vue";
import { ElMessageBox, ElMessage } from "element-plus";
import { list{{.ClassName}}, del{{.ClassName}} } from "/@/api/{{.PackageName}}/{{.BusinessName}}";
import EditModule from "./component/editModule.vue";
export default {
name: "index",
components: { EditModule },
setup() {
const { proxy } = getCurrentInstance() as any;
const editModuleRef = ref();
const state = reactive({
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 弹出层标题
title: "",
// 岗位表格数据
tableData: [],
// 总条数
total: 0,
// 状态数据字典
statusOptions: [],
// 查询参数
queryParams: {
// 页码
pageNum: 1,
// 每页大小
pageSize: 10,
// 以下为参数
// name: undefined,
},
});
/** 查询岗位列表 */
const handleQuery = () => {
state.loading = true;
list{{.ClassName}}(state.queryParams).then((response) => {
state.tableData = response.data.data;
state.total = response.data.total;
state.loading = false;
});
};
/** 重置按钮操作 */
const resetQuery = () => {
//state.queryParams.name = undefined;
handleQuery();
};
const handleCurrentChange = (val:number) => {
state.queryParams.pageNum = val
handleQuery()
}
const handleSizeChange = (val:number) => {
state.queryParams.pageSize = val
handleQuery()
}
const statusFormat = (row: any) => {
return proxy.selectDictLabel(state.statusOptions, row.status);
};
// 打开新增弹窗
const onOpenAddModule = (row: object) => {
row = [];
state.title = "添加{{.FunctionName}}";
editModuleRef.value.openDialog(row);
};
// 打开编辑弹窗
const onOpenEditModule = (row: object) => {
state.title = "修改{{.FunctionName}}";
editModuleRef.value.openDialog(row);
};
/** 删除按钮操作 */
const onTabelRowDel = (row: any) => {
const {{.PkJsonField}}s = row.{{.PkJsonField}} || state.ids;
ElMessageBox({
message: '是否确认删除岗位编号为"' + {{.PkJsonField}}s + '"的数据项?',
title: "警告",
showCancelButton: true,
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
}).then(function () {
return del{{.ClassName}}({{.PkJsonField}}s).then(() => {
handleQuery();
ElMessage.success("删除成功");
});
});
};
// 多选框选中数据
const handleSelectionChange = (selection: any) => {
state.ids = selection.map((item: any) => item.{{.PkJsonField}});
state.single = selection.length != 1;
state.multiple = !selection.length;
};
// 页面加载时
onMounted(() => {
// 查询岗位信息
handleQuery();
// 查询状态数据字典
proxy.getDicts("sys_normal_disable").then((response: any) => {
state.statusOptions = response.data;
});
proxy.mittBus.on("onEdit{{.ClassName}}Module", (res: any) => {
handleQuery();
});
});
// 页面卸载时
onUnmounted(() => {
proxy.mittBus.off("onEdit{{.ClassName}}Module");
});
return {
editModuleRef,
handleSelectionChange,
handleQuery,
handleCurrentChange,
handleSizeChange,
resetQuery,
statusFormat,
onOpenAddModule,
onOpenEditModule,
onTabelRowDel,
...toRefs(state),
};
},
};
</script>