惩处服务

dev
truthhun 11 months ago
parent 232c67c96d
commit 51e052d25d

@ -68,6 +68,7 @@ func getPermissions() (permissions []Permission) {
{Title: "更新头像", Description: "", Method: "POST", Path: "/api/v1/upload/avatar"},
{Title: "一键重转失败文档", Description: "", Method: "GRPC", Path: "/api.v1.DocumentAPI/SetDocumentReconvert"},
{Title: "批量修改文档分类", Description: "", Method: "GRPC", Path: "/api.v1.DocumentAPI/SetDocumentsCategory"},
{Title: "惩罚管理", Description: "", Method: "GRPC", Path: "/api.v1.PunishmentAPI/ListPunishment"},
}
return
}

@ -148,5 +148,14 @@ func RegisterGRPCService(dbModel *model.DBModel, logger *zap.Logger, endpoint st
return
}
// 惩罚服务
punishmentAPIService := biz.NewPunishmentAPIService(dbModel, logger)
v1.RegisterPunishmentAPIServer(grpcServer, punishmentAPIService)
err = v1.RegisterPunishmentAPIHandlerFromEndpoint(context.Background(), gwmux, endpoint, dialOpts)
if err != nil {
logger.Error("RegisterPunishmentAPIHandlerFromEndpoint", zap.Error(err))
return
}
return
}

@ -0,0 +1,162 @@
<template>
<div class="com-form-punishment">
<el-form
ref="formPunishment"
label-position="top"
label-width="80px"
:model="punishment"
>
<el-form-item
label="名称"
prop="title"
:rules="[{ required: true, trigger: 'blur', message: '请输入名称' }]"
>
<el-input
v-model="punishment.title"
placeholder="请输入名称"
clearable
></el-input>
</el-form-item>
<el-form-item
label="地址"
prop="link"
:rules="[
{
required: true,
trigger: 'blur',
message: ' https://mnt.ltd',
},
]"
>
<el-input
v-model="punishment.link"
placeholder="请输入友链地址,如 https://mnt.ltd"
clearable
></el-input>
</el-form-item>
<el-row :gutter="20">
<el-col :span="12">
<el-form-item label="排序(值越大越靠前)">
<el-input-number
v-model.number="punishment.sort"
clearable
:min="0"
:step="1"
placeholder="请输入排序值"
></el-input-number>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="是否启用">
<el-switch
v-model="punishment.enable"
style="display: block"
active-color="#13ce66"
inactive-color="#ff4949"
active-text="是"
inactive-text="否"
>
</el-switch> </el-form-item
></el-col>
</el-row>
<el-form-item label="描述">
<el-input
v-model="punishment.description"
type="textarea"
rows="3"
placeholder="请输入友链相关描述或备注"
></el-input>
</el-form-item>
<el-form-item>
<el-button
type="primary"
class="btn-block"
icon="el-icon-check"
:loading="loading"
@click="onSubmit"
></el-button
>
</el-form-item>
</el-form>
</div>
</template>
<script>
import { createPunishment, updatePunishment } from '~/api/punishment'
export default {
name: 'FormPunishment',
props: {
initPunishment: {
type: Object,
default: () => {
return {}
},
},
},
data() {
return {
loading: false,
punishment: {},
}
},
watch: {
initPunishment: {
handler(val) {
this.punishment = { ...val }
},
immediate: true,
},
},
created() {
this.punishment = { ...this.initPunishment }
},
methods: {
onSubmit() {
this.$refs.formPunishment.validate(async (valid) => {
if (!valid) {
return
}
this.loading = true
const punishment = { ...this.punishment }
if (this.punishment.id > 0) {
const res = await updatePunishment(punishment)
if (res.status === 200) {
this.$message.success('')
this.resetFields()
this.$emit('success', res.data)
} else {
this.$message.error(res.data.message)
}
} else {
const res = await createPunishment(punishment)
if (res.status === 200) {
this.$message.success('')
this.resetFields()
this.$emit('success', res.data)
} else {
this.$message.error(res.data.message)
}
}
this.loading = false
})
},
clearValidate() {
this.$refs.formPunishment.clearValidate()
},
resetFields() {
this.punishment = {
id: 0,
title: '',
link: '',
sort: 0,
enable: true,
description: '',
}
},
reset() {
this.resetFields()
this.clearValidate()
},
},
}
</script>

@ -160,6 +160,11 @@ export default {
title: '',
icon: 'el-icon-circle-check',
},
{
page: '/admin/user/punishment',
title: '',
icon: 'el-icon-warning-outline',
},
],
},
{

@ -0,0 +1,231 @@
<template>
<div>
<el-card shadow="never" class="search-card">
<FormSearch
:fields="searchFormFields"
:loading="loading"
:show-create="true"
:show-delete="false"
:disabled-delete="selectedRow.length === 0"
:default-search="search"
@onSearch="onSearch"
@onCreate="onCreate"
/>
</el-card>
<el-card shadow="never" class="mgt-20px">
<TableList
:loading="loading"
:table-data="punishments"
:fields="tableListFields"
:show-actions="true"
:show-view="false"
:show-edit="true"
:show-delete="false"
:show-select="true"
@selectRow="selectRow"
@editRow="editRow"
/>
</el-card>
<el-card shadow="never" class="mgt-20px">
<div class="text-right">
<el-pagination
background
:current-page="search.page"
:page-sizes="[10, 20, 50, 100]"
:page-size="search.size"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handlePageChange"
>
</el-pagination>
</div>
</el-card>
<el-dialog
:close-on-click-modal="false"
:title="punishment.id ? '编辑惩罚' : '新增惩罚'"
:visible.sync="formPunishmentVisible"
width="640px"
>
<FormPunishment
ref="punishmentForm"
:init-punishment="punishment"
@success="formPunishmentSuccess"
/>
</el-dialog>
</div>
</template>
<script>
import { listPunishment, getPunishment } from '~/api/punishment'
import { genLinkHTML, parseQueryIntArray } from '~/utils/utils'
import TableList from '~/components/TableList.vue'
import FormSearch from '~/components/FormSearch.vue'
import FormPunishment from '~/components/FormPunishment.vue'
import { mapGetters } from 'vuex'
export default {
components: { TableList, FormSearch, FormPunishment },
layout: 'admin',
data() {
return {
loading: false,
formPunishmentVisible: false,
search: {
wd: '',
page: 1,
enable: [],
size: 10,
},
punishments: [],
total: 0,
searchFormFields: [],
tableListFields: [],
selectedRow: [],
punishment: { id: 0 },
}
},
head() {
return {
title: `惩罚管理 - ${this.settings.system.sitename}`,
}
},
computed: {
...mapGetters('setting', ['settings']),
},
watch: {
'$route.query': {
immediate: true,
handler() {
this.search = {
...this.search,
...this.$route.query,
page: parseInt(this.$route.query.page) || 1,
size: parseInt(this.$route.query.size) || 10,
...parseQueryIntArray(this.$route.query, ['enable']),
}
this.listPunishment()
},
},
},
async created() {
this.initSearchForm()
this.initTableListFields()
// await this.listPunishment()
},
methods: {
async listPunishment() {
this.loading = true
const res = await listPunishment(this.search)
if (res.status === 200) {
let punishments = res.data.punishment || []
punishments.map((item) => {
item.title_html = genLinkHTML(item.title, item.link)
})
this.punishments = punishments
this.total = res.data.total
} else {
this.$message.error(res.data.message)
}
this.loading = false
},
handleSizeChange(val) {
this.search.size = val
this.$router.push({
query: this.search,
})
},
handlePageChange(val) {
this.search.page = val
this.$router.push({
query: this.search,
})
},
onSearch(search) {
this.search = { ...this.search, ...search, page: 1 }
if (
location.href.lastIndexOf(
this.$router.resolve({
query: this.search,
}).href
) > -1
) {
this.$router.push({
query: this.search,
})
} else {
this.listPunishment()
}
},
onCreate() {
this.punishment = { id: 0 }
this.formPunishmentVisible = true
this.$nextTick(() => {
this.$refs.punishmentForm.reset()
})
},
async editRow(row) {
const res = await getPunishment({ id: row.id })
if (res.status === 200) {
this.punishment = res.data
this.formPunishmentVisible = true
} else {
this.$message.error(res.data.message)
}
},
formPunishmentSuccess() {
this.formPunishmentVisible = false
this.listPunishment()
},
selectRow(rows) {
this.selectedRow = rows
},
initSearchForm() {
this.searchFormFields = [
{
type: 'text',
label: '',
name: 'wd',
placeholder: '',
},
{
type: 'select',
label: '',
name: 'enable',
placeholder: '',
multiple: true,
options: [
{ label: '', value: 1 },
{ label: '', value: 0 },
],
},
]
},
initTableListFields() {
this.tableListFields = [
{ prop: 'id', label: 'ID', width: 80, type: 'number', fixed: 'left' },
{
prop: 'enable',
label: '',
width: 80,
type: 'bool',
fixed: 'left',
},
{
prop: 'title_html',
label: '',
minWidth: 150,
fixed: 'left',
type: 'html',
},
{ prop: 'link', label: '', minWidth: 250 },
{ prop: 'sort', label: '', width: 80, type: 'number' },
{ prop: 'description', label: '', minWidth: 250 },
{ prop: 'created_at', label: '', width: 160, type: 'datetime' },
{ prop: 'updated_at', label: '', width: 160, type: 'datetime' },
]
},
},
}
</script>
<style></style>

@ -79,6 +79,12 @@ const cumstomPermissionMap = {
children: [],
pages: ['/admin/comment'],
},
'api.v1.PunishmentAPI': {
label: '',
path: 'ListPunishment',
children: [],
pages: ['/admin/user/punishment'],
},
upload: {
id: 0,
label: '',

Loading…
Cancel
Save