207 lines
5.1 KiB
Plaintext
207 lines
5.1 KiB
Plaintext
<%
|
|
var ulc = isBlank(prefix) ? table.name : subAfter(table.name, prefix);
|
|
var lcc = toCamelCase(ulc);
|
|
var ucc = upperFirst(lcc);
|
|
var dc = toDashCase(lcc);
|
|
|
|
var pageVueName = ucc + ".vue";
|
|
var formVueName = ucc + "Form.vue";
|
|
var pageTsName = "page.ts";
|
|
var apiTsName = dc + "-api.ts";
|
|
var dTsName = dc + ".d.ts";
|
|
%>
|
|
<template>
|
|
<Page>
|
|
<ElForm v-show="showSearchForm" inline @submit.prevent="paging">
|
|
<%
|
|
for(column in table.columns) {
|
|
var map = tsType(column.dataType);
|
|
%>
|
|
<ElFormItem label="${column.comment}">
|
|
<ElInput
|
|
v-model="searchForm.${toCamelCase(column.name)}"
|
|
placeholder="${column.comment}"/>
|
|
</ElFormItem>
|
|
<%}%>
|
|
<ElFormItem>
|
|
<ElButton :icon="elIcons.Search" :loading="searching" native-type="submit" type="primary">搜索</ElButton>
|
|
<ElButton :icon="elIcons.Refresh" :loading="searching" @click="reset">重置</ElButton>
|
|
</ElFormItem>
|
|
</ElForm>
|
|
|
|
<div class="tool-bar">
|
|
<ElButton :icon="elIcons.Plus" type="primary" @click="addHandler">新建</ElButton>
|
|
<ElButton :icon="elIcons.Filter" type="default" @click="showSearchForm = !showSearchForm"/>
|
|
</div>
|
|
|
|
<ElTable v-loading="searching" :data="tableData"
|
|
cell-class-name="table-cell"
|
|
class="table-list"
|
|
empty-text="暂无数据"
|
|
header-row-class-name="table-header"
|
|
row-key="id">
|
|
<%
|
|
for(column in table.columns) {
|
|
var map = tsType(column.dataType);
|
|
%>
|
|
<ElTableColumn label="${column.comment}" prop="${toCamelCase(column.name)}"/>
|
|
<%}%>
|
|
<ElTableColumn label="操作" width="180">
|
|
<template #default="scope">
|
|
<div class="action-btn">
|
|
<ElPopconfirm
|
|
confirm-button-text="是"
|
|
cancel-button-text="否"
|
|
confirm-button-type="danger"
|
|
cancel-button-type="primary"
|
|
placement="top"
|
|
title="是否删除当前数据?"
|
|
width="180"
|
|
@confirm="delHandler(scope)">
|
|
<template #reference>
|
|
<ElButton text type="danger" :loading="deling">删除</ElButton>
|
|
</template>
|
|
</ElPopconfirm>
|
|
<ElButton text type="primary" @click="modifyHandler(scope)">修改</ElButton>
|
|
</div>
|
|
</template>
|
|
</ElTableColumn>
|
|
</ElTable>
|
|
<ElPagination
|
|
class="pagination"
|
|
layout="prev, pager, next"
|
|
:page-size="pagination.size"
|
|
:total="pagination.total"
|
|
@change="pageChangeHandler"/>
|
|
<${ucc}Form ref="${lcc}Form" @edit-succ="paging"/>
|
|
</Page>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import ${ucc}Api from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${apiTsName}'
|
|
import ${ucc}Form from '@/pages/${moduleName}<%if(subModuleName != null){%>/${subModuleName}<%}%>/${formVueName}'
|
|
import Page from '@/components/page/Page.vue'
|
|
import { elIcons } from '@/common/element/element.ts'
|
|
|
|
const tableData = ref<${ucc}Types.Search${ucc}Result[]>([])
|
|
const searchForm = ref<${ucc}Types.Search${ucc}Param>({
|
|
current: 1,
|
|
size: 20,
|
|
})
|
|
const searching = ref(false)
|
|
const deling = ref(false)
|
|
const showSearchForm = ref(true)
|
|
const ${lcc}FormIns = useTemplateRef<InstanceType<typeof ${ucc}Form>>('${lcc}Form')
|
|
const pagination = reactive<G.Pagination>({
|
|
total: 0,
|
|
current: 1,
|
|
size: 1,
|
|
})
|
|
function pageChangeHandler(currentPage: number, pageSize: number) {
|
|
searchForm.value.current = currentPage
|
|
searchForm.value.size = pageSize
|
|
paging()
|
|
}
|
|
function showDialog(data?: ${ucc}Types.Search${ucc}Result) {
|
|
${lcc}FormIns.value?.open(data)
|
|
}
|
|
|
|
function delHandler({row}: { row: ${ucc}Types.Search${ucc}Result }) {
|
|
deling.value = true
|
|
${ucc}Api.del([ row.id! ])
|
|
.then(() => {
|
|
ElMessage.success('删除成功')
|
|
paging()
|
|
})
|
|
.finally(() => {
|
|
deling.value = false
|
|
})
|
|
}
|
|
|
|
function modifyHandler({row}: { row: ${ucc}Types.Search${ucc}Result }) {
|
|
showDialog(row)
|
|
}
|
|
|
|
function addHandler() {
|
|
showDialog()
|
|
}
|
|
|
|
function reset() {
|
|
searchForm.value = {}
|
|
paging()
|
|
}
|
|
|
|
function paging() {
|
|
searching.value = true
|
|
${ucc}Api.paging(searchForm.value)
|
|
.then(res => {
|
|
tableData.value = res.data?.records ?? []
|
|
})
|
|
.finally(() => {
|
|
searching.value = false
|
|
})
|
|
}
|
|
onMounted(() => {
|
|
paging()
|
|
})
|
|
|
|
</script>
|
|
|
|
<style lang="stylus" scoped>
|
|
.table-list {
|
|
flex 1;
|
|
width 100%
|
|
|
|
:deep(.table-header) {
|
|
color #454C59
|
|
|
|
th {
|
|
background-color #EDF1F7
|
|
font-weight 500
|
|
position relative
|
|
|
|
& > div {
|
|
display flex
|
|
gap 5px
|
|
align-items center
|
|
}
|
|
|
|
&:not(:first-child) > div::before {
|
|
position: absolute;
|
|
top: 50%;
|
|
left: 1px;
|
|
width: 1px;
|
|
background-color: #D3D7DE;
|
|
transform: translateY(-50%);
|
|
content: "";
|
|
height 50%
|
|
}
|
|
}
|
|
}
|
|
|
|
:deep(.table-cell) {
|
|
color #2F3540
|
|
}
|
|
.action-btn {
|
|
width 100%
|
|
display flex
|
|
flex-wrap wrap
|
|
|
|
& > button {
|
|
margin 0
|
|
}
|
|
}
|
|
}
|
|
|
|
.tool-bar {
|
|
display flex
|
|
justify-content space-between
|
|
margin 0 0 20px 0
|
|
}
|
|
|
|
.pagination {
|
|
justify-content: end;
|
|
margin: 8px;
|
|
}
|
|
</style>
|