| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <template>
- <div class="back-form-container">
- <div>
- <el-form :model="query" label-width="80px" :inline="true">
- {{ range .gen.tableColumns }}{{ $value := smallHump .columnName }}
- {{ if not (eq (ToLower $value) "id") }}
- {{ $name := .columnComment }}
- {{ if eq $name "" }}
- {{ $name = $value }}
- {{ end }}
- {{ ElFrom $name $value .vueShowType .dictType .queryType}}
- {{ end }}
- {{ end }}
- </el-form>
- </div>
- <div class="back-table-handler">
- <el-row :gutter="10" class="mb8">
- <el-col :span="1.5">
- <el-button type="primary" plain size="small" @click="getList(pageNum)">
- <el-icon>
- <RefreshLeft/>
- </el-icon>
- <span>刷新</span>
- </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="primary" plain size="small" @click="openDialog('save', {{ .gen.table.name }}.Create())">
- <el-icon>
- <Plus/>
- </el-icon>
- <span>新增</span>
- </el-button>
- </el-col>
- <el-col :span="1.5">
- <el-button type="danger" plain size="small" @click="deleteByIds()">
- <el-icon>
- <Delete/>
- </el-icon>
- <span>删除</span>
- </el-button>
- </el-col>
- </el-row>
- </div>
- <div class="back-table">
- <el-table v-loading="listLoading" :data="list" @selection-change="selected" border :key="ListKey">
- <el-table-column type="selection" width="40" align="center"/>
- {{ range .gen.tableColumns }}{{ $value := smallHump .columnName }}{{ $name := .columnComment }}{{ if eq $name "" }}{{ $name = $value }}{{ end }}{{ if eq .IsKey "1" }}{{ ElTableColumn $name $value .vueShowType .dictType }}{{ else }}{{ ElTableColumn $name $value .vueShowType .dictType }}{{ end }}{{ end }}
- <el-table-column label="操作" align="center" fixed="right">
- <template #default="scope">
- <el-button link type="primary" @click="openDialog('update',scope.row)">修改</el-button>
- <el-button link type="danger" @click="deleteById(scope.row.id)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <div class="pagination-container">
- <el-pagination
- background
- :current-page="pageNum"
- @current-change="getList"
- :page-size="pageSize"
- :page-sizes="[10, 20, 30, 50,100]"
- :total="total"
- @size-change="SetPageSized"
- layout="total, sizes, prev, pager, next"
- />
- </div>
- <!-- 添加或修改参数配置对话框 -->
- <el-dialog :title="dialogType=='update'?'更改字典类型':'新增字典类型'" v-model="open" width="500px" append-to-body>
- <el-form ref="dictRef" :model="dialogForm" label-width="80px">
- {{ range .gen.tableColumns }}{{ $value := smallHump .columnName }}{{ if not (eq (ToLower $value) "id") }}{{ $name := .columnComment }}{{ if eq $name "" }}{{ $name = $value }}{{ end }}{{ ElDialog $name $value .vueShowType .dictType }}{{ end }}{{ end }}
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="submitForm()">确 定</el-button>
- <el-button @click="open=false">取 消</el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </div>
- </template>
- <script setup lang="ts">
- import {ref} from "vue";
- import {
- DeleteBase{{ .gen.table.name }}ById,
- GetBase{{ .gen.table.name }}ListBy{{ .gen.table.name }},
- SaveBase{{ .gen.table.name }},
- UpdateBase{{ .gen.table.name }},
- {{.gen.table.name}},
- {{.gen.table.name}}Query
- } from "../../../api/back/BaseBackApi.ts";
- import {ElMessage} from "element-plus";
- import {Delete, Plus, RefreshLeft} from "@element-plus/icons-vue";
- import router from "../../../router";
- import {store} from "../../../state/TokenState.ts";
- import DictTag from "../../../components/dict/DictTag.vue";
- import MultipleTag from "../../../components/MultipleTag/MultipleTag.vue";
- import ImageUpload from "../../../components/ImageUpload/ImageUpload.vue";
- let listLoading = ref(true)
- let total = ref(0)
- let pageNum = ref(1)
- let pageSize = ref(10)
- let list = ref<{{ .gen.table.name }}[]>([])
- let ListKey = ref(0)
- //搜索用
- //let search = ref<{{ .gen.table.name }}>({{ .gen.table.name }}.Create())
- //修改,添加用
- let open = ref(false)
- let dialogType = ref("")//save添加,update修改
- let dialogForm = ref<{{ .gen.table.name }}>(null)
- let query = ref<{{ .gen.table.name }}Query>({{ .gen.table.name }}Query.Create())
- let selectItems = ref<{{ .gen.table.name }}[]>([])
- const selected = (arr: {{ .gen.table.name }}[]) => {
- selectItems.value = arr
- }
- getList()
- const SetPageSized = (val: number) => {
- pageSize.value = val
- getList(pageNum.value)
- }
- function openDialog(type: string, row: {{ .gen.table.name }}) {
- open.value = true
- dialogType.value = type
- if (type==="save"){
- dialogForm.value = {{ .gen.table.name }}.Create()
- return
- }
- //深拷贝,不会影响数据
- dialogForm.value = JSON.parse(JSON.stringify(row))
- }
- function deleteByIds() {
- for (let i = 0; i < selectItems.value.length; i++) {
- deleteById(selectItems[i].id)
- }
- }
- function deleteById(id) {
- DeleteBase{{ .gen.table.name }}ById(id).then(response => {
- if (response.code == 200) {
- ElMessage.success("删除成功,id:" + id)
- getList()
- } else {
- ElMessage.error("删除失败,id:" + id)
- }
- })
- }
- function getList(pn = 1) {
- pageNum.value = pn
- GetBase{{ .gen.table.name }}ListBy{{ .gen.table.name }}(query.value, pageNum.value, pageSize.value).then(response => {
- let data = response.data
- total.value = data.total
- list.value = response.data.list
- ListKey.value++
- listLoading.value = false
- })
- }
- function submitForm() {
- switch (dialogType.value) {
- case "update":
- UpdateBase{{ .gen.table.name }}(dialogForm.value, dialogForm.value.id).then(response => {
- if (response.code == 200) {
- open.value = false
- getList()
- ElMessage.success("修改成功")
- } else {
- ElMessage.error("修改失败")
- }
- })
- break
- case "save":
- SaveBase{{ .gen.table.name }}(dialogForm.value).then(response => {
- if (response.code == 200) {
- open.value = false
- getList()
- ElMessage.success("添加成功")
- } else {
- ElMessage.error("添加失败")
- }
- })
- break
- default:
- break
- }
- }
- </script>
|