2022-10-05 17:29:59 +08:00
|
|
|
|
<!--
|
|
|
|
|
* @Author: yubaolee <yubaolee@163.com> | ahfu~ <954478625@qq.com>
|
2025-03-13 14:03:20 +08:00
|
|
|
|
* @Description: OpenAuth.Pro代码生成器自动生成
|
|
|
|
|
* Copyright (c) 2025 by yubaolee | ahfu~ , All Rights Reserved.
|
2022-10-05 17:29:59 +08:00
|
|
|
|
-->
|
|
|
|
|
<template>
|
|
|
|
|
<div class="flex flex-column">
|
|
|
|
|
<sticky>
|
2025-02-20 20:54:20 +08:00
|
|
|
|
<div class="search-box">
|
|
|
|
|
<el-input @keyup.enter="handleFilter" size="small" class="custom-input w-200" :placeholder="'名称'"
|
|
|
|
|
v-model="listQuery.key"></el-input>
|
2025-03-13 14:03:20 +08:00
|
|
|
|
<el-button size="small" class="custom-button filter-item" icon="el-icon-search"
|
|
|
|
|
@click="handleFilter">搜索</el-button>
|
2025-02-20 20:54:20 +08:00
|
|
|
|
</div>
|
|
|
|
|
<permission-btn v-on:btn-event="onBtnClicked"></permission-btn>
|
2022-10-05 17:29:59 +08:00
|
|
|
|
</sticky>
|
2025-03-13 14:03:20 +08:00
|
|
|
|
<auth-table ref="mainTableRef" :select-type="'checkbox'" :table-fields="headerList" :data="list"
|
|
|
|
|
:v-loading="listLoading" @row-click="rowClick" @selection-change="handleSelectionChange"></auth-table>
|
|
|
|
|
<el-pagination v-show="total > 0" :total="total" v-model:currentPage="listQuery.page"
|
|
|
|
|
v-model:page-size="listQuery.limit" @current-change="handleCurrentChange" />
|
2022-10-05 17:29:59 +08:00
|
|
|
|
</div>
|
2025-03-13 14:03:20 +08:00
|
|
|
|
<el-dialog draggable class="dialog-mini" width="500px" :title="dialogStatus==0?'新增':'编辑'" v-model="dialogFormVisible">
|
|
|
|
|
<auth-form ref="dataFormRef" :rules="rules" :edit-model="true" :form-fields="headerList" :data="temp"
|
2022-10-05 17:29:59 +08:00
|
|
|
|
:col-num="2"></auth-form>
|
|
|
|
|
<template v-slot:footer>
|
|
|
|
|
<div>
|
2025-02-20 20:43:54 +08:00
|
|
|
|
<el-button size="small" @click="dialogFormVisible = false">
|
2022-10-05 17:29:59 +08:00
|
|
|
|
取消
|
|
|
|
|
</el-button>
|
2025-03-13 14:03:20 +08:00
|
|
|
|
<el-button size="small" v-if="dialogStatus == 0" type="primary" @click="createData">
|
2022-10-05 17:29:59 +08:00
|
|
|
|
确认
|
|
|
|
|
</el-button>
|
2025-02-20 20:43:54 +08:00
|
|
|
|
<el-button size="small" v-else type="primary" @click="updateData">
|
2022-10-05 17:29:59 +08:00
|
|
|
|
确认
|
|
|
|
|
</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
//引入核心框架
|
|
|
|
|
import { ElMessage, ElNotification } from 'element-plus'
|
|
|
|
|
import { onMounted, ref, reactive, nextTick } from 'vue'
|
|
|
|
|
//引入API,共用方法
|
|
|
|
|
import * as {TableName}s from '@/api/{TableName}s'
|
|
|
|
|
import { defaultVal } from '@/utils/index'
|
|
|
|
|
import { delrows } from '@/utils/delRows.js'
|
2025-03-13 14:03:20 +08:00
|
|
|
|
import ColumnDefine from '@/interface/columnDefine'
|
2022-10-05 17:29:59 +08:00
|
|
|
|
//引入组件
|
|
|
|
|
import Sticky from '@/components/Sticky/index.vue'
|
|
|
|
|
import permissionBtn from '@/components/PermissionBtn/index.vue'
|
|
|
|
|
import AuthForm from '../../components/Base/AuthForm.vue'
|
|
|
|
|
import AuthTable from '../../components/Base/AuthTable.vue'
|
|
|
|
|
const headerList = ref([]) //列表头
|
|
|
|
|
const multipleSelection = ref([]) //列表checkbox选中的值
|
|
|
|
|
const list = ref([]) //列表值
|
|
|
|
|
const total = ref(0) //总条数
|
|
|
|
|
const listLoading = ref(true) //进度条
|
|
|
|
|
const dialogFormVisible = ref(false) //是否显示编辑框
|
2025-03-13 14:03:20 +08:00
|
|
|
|
const dialogStatus = ref(0) //0:新增 1:编辑
|
2022-10-05 17:29:59 +08:00
|
|
|
|
let temp = reactive({}) //新增(编辑)绑定对话框
|
|
|
|
|
const listQuery = reactive({
|
|
|
|
|
// 查询条件
|
|
|
|
|
page: 1,
|
|
|
|
|
limit: 20,
|
|
|
|
|
key: undefined,
|
|
|
|
|
})
|
|
|
|
|
const rules = reactive({
|
|
|
|
|
name: [{ required: true, message: '名称不能为空', trigger: 'blur' }],
|
|
|
|
|
})
|
|
|
|
|
//组件refs
|
2025-03-13 14:03:20 +08:00
|
|
|
|
const mainTableRef = ref(null)
|
|
|
|
|
const dataFormRef = ref(null)
|
2022-10-05 17:29:59 +08:00
|
|
|
|
onMounted(() => {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
headerList.value = [
|
|
|
|
|
{HeaderList}
|
|
|
|
|
]
|
2022-10-05 17:29:59 +08:00
|
|
|
|
getList()
|
|
|
|
|
})
|
|
|
|
|
const rowClick = function (row) {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
mainTableRef.value.clearSelection()
|
|
|
|
|
mainTableRef.value.toggleRowSelection(row)
|
2022-10-05 17:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
const handleSelectionChange = function (val) {
|
|
|
|
|
multipleSelection.value = val
|
|
|
|
|
}
|
|
|
|
|
const onBtnClicked = function (domId, callback) {
|
|
|
|
|
switch (domId) {
|
|
|
|
|
case 'btnAdd':
|
|
|
|
|
handleCreate()
|
|
|
|
|
break
|
|
|
|
|
case 'btnEdit':
|
|
|
|
|
if (multipleSelection.value.length !== 1) {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
ElMessage.error('只能选中一个进行编辑')
|
2022-10-05 17:29:59 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
handleUpdate(multipleSelection.value[0])
|
|
|
|
|
break
|
|
|
|
|
case 'btnDel':
|
|
|
|
|
if (multipleSelection.value.length < 1) {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
ElMessage.error('至少删除一个')
|
2022-10-05 17:29:59 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2024-11-13 21:35:21 +08:00
|
|
|
|
handleDelete(multipleSelection.value)
|
2022-10-05 17:29:59 +08:00
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const getList = function () {
|
|
|
|
|
listLoading.value = true
|
|
|
|
|
{TableName}s.getList(listQuery).then(response => {
|
|
|
|
|
list.value = response.data
|
|
|
|
|
response.columnFields.forEach(item => {
|
|
|
|
|
// 首字母小写
|
|
|
|
|
item.columnName =
|
|
|
|
|
item.columnName.substring(0, 1).toLowerCase() +
|
|
|
|
|
item.columnName.substring(1)
|
|
|
|
|
})
|
|
|
|
|
headerList.value = response.columnFields
|
|
|
|
|
total.value = response.count
|
|
|
|
|
listLoading.value = false
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const handleFilter = function () {
|
|
|
|
|
listQuery.page = 1
|
|
|
|
|
getList()
|
|
|
|
|
}
|
2025-03-13 14:03:20 +08:00
|
|
|
|
|
2022-10-05 17:29:59 +08:00
|
|
|
|
const handleCurrentChange = function (val) {
|
|
|
|
|
listQuery.page = val
|
|
|
|
|
getList()
|
|
|
|
|
}
|
2025-03-13 14:03:20 +08:00
|
|
|
|
|
2022-10-05 17:29:59 +08:00
|
|
|
|
const resetTemp = function () {
|
|
|
|
|
let obj = {}
|
|
|
|
|
headerList.value.forEach(item => {
|
|
|
|
|
obj[item.columnName] = defaultVal(item.entityType)
|
|
|
|
|
})
|
|
|
|
|
Object.assign(temp, obj)
|
|
|
|
|
}
|
|
|
|
|
const handleCreate = async function () {
|
|
|
|
|
resetTemp()
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dialogStatus.value = 0
|
2022-10-05 17:29:59 +08:00
|
|
|
|
dialogFormVisible.value = true
|
|
|
|
|
await nextTick()
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dataFormRef.value.clearValidate()
|
2022-10-05 17:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
const createData = function () {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dataFormRef.value.validate(() => {
|
2022-10-05 17:29:59 +08:00
|
|
|
|
{TableName}s.add(temp).then(() => {
|
|
|
|
|
list.value.unshift(temp)
|
|
|
|
|
dialogFormVisible.value = false
|
2025-03-13 14:03:20 +08:00
|
|
|
|
ElNotification.success('创建成功')
|
2022-10-05 17:29:59 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const handleUpdate = async function (row) {
|
|
|
|
|
Object.assign(temp, row) //必需这样赋值才能响应式
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dialogStatus.value = 1
|
2022-10-05 17:29:59 +08:00
|
|
|
|
dialogFormVisible.value = true
|
|
|
|
|
await nextTick()
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dataFormRef.value.clearValidate()
|
2022-10-05 17:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
const updateData = function () {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
dataFormRef.value.validate(() => {
|
2022-10-05 17:29:59 +08:00
|
|
|
|
const tempData = Object.assign({}, temp)
|
|
|
|
|
{TableName}s.update(tempData).then(() => {
|
|
|
|
|
for (const v of list.value) {
|
|
|
|
|
if (v.id === temp.id) {
|
|
|
|
|
const index = list.value.indexOf(v)
|
|
|
|
|
list.value.splice(index, 1, temp)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
dialogFormVisible.value = false
|
2025-03-13 14:03:20 +08:00
|
|
|
|
ElNotification.success('更新成功')
|
2022-10-05 17:29:59 +08:00
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const handleDelete = function (rows) {
|
2025-03-13 14:03:20 +08:00
|
|
|
|
delrows({TableName}s, rows, getList)
|
2022-10-05 17:29:59 +08:00
|
|
|
|
}
|
|
|
|
|
</script>
|