Commit 341e39fa authored by mahui's avatar mahui

Merge remote-tracking branch 'origin/master'

parents 1b84ab97 4b0ba2bc
......@@ -6,5 +6,6 @@ type ApiGroup struct {
QshToiletApi
QshPartolApi
QshMonitorDataApi
QshTypeApi
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
package admin
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
adminReq "github.com/flipped-aurora/gin-vue-admin/server/model/admin/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/service"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type QshTypeApi struct {
}
var qshTypeService = service.ServiceGroupApp.AdminServiceGroup.QshTypeService
// CreateQshType 创建QshType
// @Tags QshType
// @Summary 创建QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body admin.QshType true "创建QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /qshType/createQshType [post]
func (qshTypeApi *QshTypeApi) CreateQshType(c *gin.Context) {
var qshType admin.QshType
_ = c.ShouldBindJSON(&qshType)
if err := qshTypeService.CreateQshType(qshType); err != nil {
global.GVA_LOG.Error("创建失败!", zap.Error(err))
response.FailWithMessage("创建失败", c)
} else {
response.OkWithMessage("创建成功", c)
}
}
// DeleteQshType 删除QshType
// @Tags QshType
// @Summary 删除QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body admin.QshType true "删除QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /qshType/deleteQshType [delete]
func (qshTypeApi *QshTypeApi) DeleteQshType(c *gin.Context) {
var qshType admin.QshType
_ = c.ShouldBindJSON(&qshType)
if err := qshTypeService.DeleteQshType(qshType); err != nil {
global.GVA_LOG.Error("删除失败!", zap.Error(err))
response.FailWithMessage("删除失败", c)
} else {
response.OkWithMessage("删除成功", c)
}
}
// DeleteQshTypeByIds 批量删除QshType
// @Tags QshType
// @Summary 批量删除QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /qshType/deleteQshTypeByIds [delete]
func (qshTypeApi *QshTypeApi) DeleteQshTypeByIds(c *gin.Context) {
var IDS request.IdsReq
_ = c.ShouldBindJSON(&IDS)
if err := qshTypeService.DeleteQshTypeByIds(IDS); err != nil {
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
response.FailWithMessage("批量删除失败", c)
} else {
response.OkWithMessage("批量删除成功", c)
}
}
// UpdateQshType 更新QshType
// @Tags QshType
// @Summary 更新QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body admin.QshType true "更新QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /qshType/updateQshType [put]
func (qshTypeApi *QshTypeApi) UpdateQshType(c *gin.Context) {
var qshType admin.QshType
_ = c.ShouldBindJSON(&qshType)
if err := qshTypeService.UpdateQshType(qshType); err != nil {
global.GVA_LOG.Error("更新失败!", zap.Error(err))
response.FailWithMessage("更新失败", c)
} else {
response.OkWithMessage("更新成功", c)
}
}
// FindQshType 用id查询QshType
// @Tags QshType
// @Summary 用id查询QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query admin.QshType true "用id查询QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /qshType/findQshType [get]
func (qshTypeApi *QshTypeApi) FindQshType(c *gin.Context) {
var qshType admin.QshType
_ = c.ShouldBindQuery(&qshType)
if reqshType, err := qshTypeService.GetQshType(qshType.ID); err != nil {
global.GVA_LOG.Error("查询失败!", zap.Error(err))
response.FailWithMessage("查询失败", c)
} else {
response.OkWithData(gin.H{"reqshType": reqshType}, c)
}
}
// GetQshTypeList 分页获取QshType列表
// @Tags QshType
// @Summary 分页获取QshType列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query adminReq.QshTypeSearch true "分页获取QshType列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /qshType/getQshTypeList [get]
func (qshTypeApi *QshTypeApi) GetQshTypeList(c *gin.Context) {
var pageInfo adminReq.QshTypeSearch
_ = c.ShouldBindQuery(&pageInfo)
if list, total, err := qshTypeService.GetQshTypeInfoList(pageInfo); err != nil {
global.GVA_LOG.Error("获取失败!", zap.Error(err))
response.FailWithMessage("获取失败", c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
package web
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
"github.com/flipped-aurora/gin-vue-admin/server/service/web"
"github.com/gin-gonic/gin"
)
var TypeService = new(web.TypeService)
func GetType(c *gin.Context) {
typeData, err := TypeService.GetType()
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(typeData, c)
}
......@@ -56,6 +56,7 @@ func RegisterTables(db *gorm.DB) {
admin.QshToilet{},
admin.QshPatrol{},
admin.QshMonitorData{},
admin.QshType{},
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
)
if err != nil {
......
......@@ -75,6 +75,7 @@ func Routers() *gin.Engine {
adminRouter.InitQshToiletRouter(PrivateGroup)
adminRouter.InitQshPartolRouter(PrivateGroup)
adminRouter.InitQshMonitorDataRouter(PrivateGroup)
adminRouter.InitQshTypeRouter(PrivateGroup)
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
......
......@@ -8,7 +8,7 @@ import (
"github.com/songzhibin97/gkit/tools/gjson"
)
var exCheck = []string{"/web/login/login", "/web/oss/getOssConfig"}
var exCheck = []string{"/web/login/login", "/web/oss/getOssConfig", "/web/type/typeData"}
func Token() gin.HandlerFunc {
return func(c *gin.Context) {
......
// 自动生成模板QshType
package admin
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// QshType 结构体
type QshType struct {
global.GVA_MODEL
TypeName string `json:"typeName" form:"typeName" gorm:"column:type_name;comment:类型名称;size:191;"`
}
// TableName QshType 表名
func (QshType) TableName() string {
return "qsh_type"
}
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
)
type QshTypeSearch struct {
admin.QshType
request.PageInfo
}
......@@ -6,5 +6,6 @@ type RouterGroup struct {
QshToiletRouter
QshPartolRouter
QshMonitorDataRouter
QshTypeRouter
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
package admin
import (
"github.com/flipped-aurora/gin-vue-admin/server/api/v1"
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
"github.com/gin-gonic/gin"
)
type QshTypeRouter struct {
}
// InitQshTypeRouter 初始化 QshType 路由信息
func (s *QshTypeRouter) InitQshTypeRouter(Router *gin.RouterGroup) {
qshTypeRouter := Router.Group("qshType").Use(middleware.OperationRecord())
qshTypeRouterWithoutRecord := Router.Group("qshType")
var qshTypeApi = v1.ApiGroupApp.AdminApiGroup.QshTypeApi
{
qshTypeRouter.POST("createQshType", qshTypeApi.CreateQshType) // 新建QshType
qshTypeRouter.DELETE("deleteQshType", qshTypeApi.DeleteQshType) // 删除QshType
qshTypeRouter.DELETE("deleteQshTypeByIds", qshTypeApi.DeleteQshTypeByIds) // 批量删除QshType
qshTypeRouter.PUT("updateQshType", qshTypeApi.UpdateQshType) // 更新QshType
}
{
qshTypeRouterWithoutRecord.GET("findQshType", qshTypeApi.FindQshType) // 根据ID获取QshType
qshTypeRouterWithoutRecord.GET("getQshTypeList", qshTypeApi.GetQshTypeList) // 获取QshType列表
}
}
......@@ -33,4 +33,9 @@ func InitWebRouter(router *gin.Engine) {
data.POST("getHistoryDataList", web.GetHistoryDataList)
data.POST("getYewei", web.GetYewei)
}
typeData := webRouter.Group("type")
{
typeData.POST("typeData", web.GetType)
}
}
......@@ -6,5 +6,6 @@ type ServiceGroup struct {
QshToiletService
QshPartolService
QshMonitorDataService
QshTypeService
// Code generated by github.com/flipped-aurora/gin-vue-admin/server End; DO NOT EDIT.
}
......@@ -64,6 +64,6 @@ func (qshMonitorDataService *QshMonitorDataService) GetQshMonitorDataInfoList(in
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&qshMonitorDatas).Error
err = db.Limit(limit).Offset(offset).Order("created_at desc").Find(&qshMonitorDatas).Error
return qshMonitorDatas, total, err
}
package admin
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
adminReq "github.com/flipped-aurora/gin-vue-admin/server/model/admin/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
)
type QshTypeService struct {
}
// CreateQshType 创建QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) CreateQshType(qshType admin.QshType) (err error) {
err = global.GVA_DB.Create(&qshType).Error
return err
}
// DeleteQshType 删除QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) DeleteQshType(qshType admin.QshType) (err error) {
err = global.GVA_DB.Delete(&qshType).Error
return err
}
// DeleteQshTypeByIds 批量删除QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) DeleteQshTypeByIds(ids request.IdsReq) (err error) {
err = global.GVA_DB.Delete(&[]admin.QshType{}, "id in ?", ids.Ids).Error
return err
}
// UpdateQshType 更新QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) UpdateQshType(qshType admin.QshType) (err error) {
err = global.GVA_DB.Save(&qshType).Error
return err
}
// GetQshType 根据id获取QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) GetQshType(id uint) (qshType admin.QshType, err error) {
err = global.GVA_DB.Where("id = ?", id).First(&qshType).Error
return
}
// GetQshTypeInfoList 分页获取QshType记录
// Author [piexlmax](https://github.com/piexlmax)
func (qshTypeService *QshTypeService) GetQshTypeInfoList(info adminReq.QshTypeSearch) (list interface{}, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
// 创建db
db := global.GVA_DB.Model(&admin.QshType{})
var qshTypes []admin.QshType
// 如果有条件搜索 下方会自动创建搜索语句
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(limit).Offset(offset).Find(&qshTypes).Error
return qshTypes, total, err
}
package web
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
)
type TypeService struct {
}
func (s *TypeService) GetType() ([]admin.QshType, error) {
var typeData []admin.QshType
err := global.GVA_DB.Model(admin.QshType{}).Find(&typeData).Error
if err != nil {
return typeData, err
}
return typeData, nil
}
import service from '@/utils/request'
// @Tags QshType
// @Summary 创建QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.QshType true "创建QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /qshType/createQshType [post]
export const createQshType = (data) => {
return service({
url: '/qshType/createQshType',
method: 'post',
data
})
}
// @Tags QshType
// @Summary 删除QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.QshType true "删除QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /qshType/deleteQshType [delete]
export const deleteQshType = (data) => {
return service({
url: '/qshType/deleteQshType',
method: 'delete',
data
})
}
// @Tags QshType
// @Summary 删除QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /qshType/deleteQshType [delete]
export const deleteQshTypeByIds = (data) => {
return service({
url: '/qshType/deleteQshTypeByIds',
method: 'delete',
data
})
}
// @Tags QshType
// @Summary 更新QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.QshType true "更新QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /qshType/updateQshType [put]
export const updateQshType = (data) => {
return service({
url: '/qshType/updateQshType',
method: 'put',
data
})
}
// @Tags QshType
// @Summary 用id查询QshType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.QshType true "用id查询QshType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /qshType/findQshType [get]
export const findQshType = (params) => {
return service({
url: '/qshType/findQshType',
method: 'get',
params
})
}
// @Tags QshType
// @Summary 分页获取QshType列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.PageInfo true "分页获取QshType列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /qshType/getQshTypeList [get]
export const getQshTypeList = (params) => {
return service({
url: '/qshType/getQshTypeList',
method: 'get',
params
})
}
<template>
<div>
<div class="gva-search-box">
<el-form :inline="true" :model="searchInfo" class="demo-form-inline">
<el-form-item>
<el-button size="small" type="primary" icon="search" @click="onSubmit">查询</el-button>
<el-button size="small" icon="refresh" @click="onReset">重置</el-button>
</el-form-item>
</el-form>
</div>
<div class="gva-table-box">
<div class="gva-btn-list">
<el-button size="small" type="primary" icon="plus" @click="openDialog">新增</el-button>
<el-popover v-model:visible="deleteVisible" placement="top" width="160">
<p>确定要删除吗?</p>
<div style="text-align: right; margin-top: 8px;">
<el-button size="small" type="primary" link @click="deleteVisible = false">取消</el-button>
<el-button size="small" type="primary" @click="onDelete">确定</el-button>
</div>
<template #reference>
<el-button icon="delete" size="small" style="margin-left: 10px;" :disabled="!multipleSelection.length" @click="deleteVisible = true">删除</el-button>
</template>
</el-popover>
</div>
<el-table
ref="multipleTable"
style="width: 100%"
tooltip-effect="dark"
:data="tableData"
row-key="ID"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column align="left" label="日期" width="180">
<template #default="scope">{{ formatDate(scope.row.CreatedAt) }}</template>
</el-table-column>
<el-table-column align="left" label="类型名称" prop="typeName" width="120" />
<el-table-column align="left" label="按钮组">
<template #default="scope">
<el-button type="primary" link icon="edit" size="small" class="table-button" @click="updateQshTypeFunc(scope.row)">变更</el-button>
<el-button type="primary" link icon="delete" size="small" @click="deleteRow(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
<div class="gva-pagination">
<el-pagination
layout="total, sizes, prev, pager, next, jumper"
:current-page="page"
:page-size="pageSize"
:page-sizes="[10, 30, 50, 100]"
:total="total"
@current-change="handleCurrentChange"
@size-change="handleSizeChange"
/>
</div>
</div>
<el-dialog v-model="dialogFormVisible" :before-close="closeDialog" title="弹窗操作">
<el-form :model="formData" label-position="right" label-width="80px">
<el-form-item label="类型名称:">
<el-input v-model="formData.typeName" clearable placeholder="请输入" />
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button size="small" @click="closeDialog">取 消</el-button>
<el-button size="small" type="primary" @click="enterDialog">确 定</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
<script>
export default {
name: 'QshType'
}
</script>
<script setup>
import {
createQshType,
deleteQshType,
deleteQshTypeByIds,
updateQshType,
findQshType,
getQshTypeList
} from '@/api/qshType'
// 全量引入格式化工具 请按需保留
import { getDictFunc, formatDate, formatBoolean, filterDict } from '@/utils/format'
import { ElMessage, ElMessageBox } from 'element-plus'
import { ref } from 'vue'
// 自动化生成的字典(可能为空)以及字段
const formData = ref({
typeName: '',
})
// =========== 表格控制部分 ===========
const page = ref(1)
const total = ref(0)
const pageSize = ref(10)
const tableData = ref([])
const searchInfo = ref({})
// 重置
const onReset = () => {
searchInfo.value = {}
}
// 搜索
const onSubmit = () => {
page.value = 1
pageSize.value = 10
getTableData()
}
// 分页
const handleSizeChange = (val) => {
pageSize.value = val
getTableData()
}
// 修改页面容量
const handleCurrentChange = (val) => {
page.value = val
getTableData()
}
// 查询
const getTableData = async() => {
const table = await getQshTypeList({ page: page.value, pageSize: pageSize.value, ...searchInfo.value })
if (table.code === 0) {
tableData.value = table.data.list
total.value = table.data.total
page.value = table.data.page
pageSize.value = table.data.pageSize
}
}
getTableData()
// ============== 表格控制部分结束 ===============
// 获取需要的字典 可能为空 按需保留
const setOptions = async () =>{
}
// 获取需要的字典 可能为空 按需保留
setOptions()
// 多选数据
const multipleSelection = ref([])
// 多选
const handleSelectionChange = (val) => {
multipleSelection.value = val
}
// 删除行
const deleteRow = (row) => {
ElMessageBox.confirm('确定要删除吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteQshTypeFunc(row)
})
}
// 批量删除控制标记
const deleteVisible = ref(false)
// 多选删除
const onDelete = async() => {
const ids = []
if (multipleSelection.value.length === 0) {
ElMessage({
type: 'warning',
message: '请选择要删除的数据'
})
return
}
multipleSelection.value &&
multipleSelection.value.map(item => {
ids.push(item.ID)
})
const res = await deleteQshTypeByIds({ ids })
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功'
})
if (tableData.value.length === ids.length && page.value > 1) {
page.value--
}
deleteVisible.value = false
getTableData()
}
}
// 行为控制标记(弹窗内部需要增还是改)
const type = ref('')
// 更新行
const updateQshTypeFunc = async(row) => {
const res = await findQshType({ ID: row.ID })
type.value = 'update'
if (res.code === 0) {
formData.value = res.data.reqshType
dialogFormVisible.value = true
}
}
// 删除行
const deleteQshTypeFunc = async (row) => {
const res = await deleteQshType({ ID: row.ID })
if (res.code === 0) {
ElMessage({
type: 'success',
message: '删除成功'
})
if (tableData.value.length === 1 && page.value > 1) {
page.value--
}
getTableData()
}
}
// 弹窗控制标记
const dialogFormVisible = ref(false)
// 打开弹窗
const openDialog = () => {
type.value = 'create'
dialogFormVisible.value = true
}
// 关闭弹窗
const closeDialog = () => {
dialogFormVisible.value = false
formData.value = {
typeName: '',
}
}
// 弹窗确定
const enterDialog = async () => {
let res
switch (type.value) {
case 'create':
res = await createQshType(formData.value)
break
case 'update':
res = await updateQshType(formData.value)
break
default:
res = await createQshType(formData.value)
break
}
if (res.code === 0) {
ElMessage({
type: 'success',
message: '创建/更改成功'
})
closeDialog()
getTableData()
}
}
</script>
<style>
</style>
<template>
<div>
<div class="gva-form-box">
<el-form :model="formData" label-position="right" label-width="80px">
<el-form-item label="类型名称:">
<el-input v-model="formData.typeName" clearable placeholder="请输入" />
</el-form-item>
<el-form-item>
<el-button size="mini" type="primary" @click="save">保存</el-button>
<el-button size="mini" type="primary" @click="back">返回</el-button>
</el-form-item>
</el-form>
</div>
</div>
</template>
<script>
export default {
name: 'QshType'
}
</script>
<script setup>
import {
createQshType,
updateQshType,
findQshType
} from '@/api/qshType'
// 自动获取字典
import { getDictFunc } from '@/utils/format'
import { useRoute, useRouter } from "vue-router"
import { ElMessage } from 'element-plus'
import { ref } from 'vue'
const route = useRoute()
const router = useRouter()
const type = ref('')
const formData = ref({
typeName: '',
})
// 初始化方法
const init = async () => {
// 建议通过url传参获取目标数据ID 调用 find方法进行查询数据操作 从而决定本页面是create还是update 以下为id作为url参数示例
if (route.query.id) {
const res = await findQshType({ ID: route.query.id })
if (res.code === 0) {
formData.value = res.data.reqshType
type.value = 'update'
}
} else {
type.value = 'create'
}
}
init()
// 保存按钮
const save = async() => {
let res
switch (type.value) {
case 'create':
res = await createQshType(formData.value)
break
case 'update':
res = await updateQshType(formData.value)
break
default:
res = await createQshType(formData.value)
break
}
if (res.code === 0) {
ElMessage({
type: 'success',
message: '创建/更改成功'
})
}
}
// 返回按钮
const back = () => {
router.go(-1)
}
</script>
<style>
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment