喜喜检查

This commit is contained in:
zhonghua.li
2026-04-06 13:39:43 +08:00
parent f1ec855526
commit d7007cea59
4 changed files with 596 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import request from '@/utils/request'
/**
* 恋爱检查项 love_check_itemLoveCheckItemController
* - axios baseURL 为 /api默认请求 /api/loveCheckItem/...
* - 若 Spring 已配置 server.servlet.context-path=/api且类上仍是 @RequestMapping("/api/loveCheckItem")
* 实际路径为 /api/api/loveCheckItem/...,可在 .env 设置VUE_APP_LOVE_CHECK_ITEM_SEGMENT=api/loveCheckItem不要首尾斜杠
*/
function lcUrl(action) {
const seg = (process.env.VUE_APP_LOVE_CHECK_ITEM_SEGMENT || 'loveCheckItem').replace(/^\/+|\/+$/g, '')
return seg.startsWith('api/') ? `${seg}/${action}` : `/${seg}/${action}`
}
export function fetchXixiInspectionList(params) {
return request({
url: lcUrl('list'),
method: 'get',
params: {
current: params.page || 1,
size: params.limit || 10,
parentId: params.parentId,
projectName: params.projectName,
type: params.type,
hazardStars: params.hazardStars,
createStartTime: params.createStartTime,
createEndTime: params.createEndTime,
updateStartTime: params.updateStartTime,
updateEndTime: params.updateEndTime
}
})
}
export function getXixiInspectionById(id) {
return request({
url: lcUrl(`get/${id}`),
method: 'get'
})
}
export function addXixiInspection(data) {
return request({
url: lcUrl('add'),
method: 'post',
data
})
}
export function updateXixiInspection(data) {
return request({
url: lcUrl('update'),
method: 'put',
data
})
}
export function deleteXixiInspection(id) {
return request({
url: lcUrl(`delete/${id}`),
method: 'delete'
})
}
export function batchDeleteXixiInspection(ids) {
return request({
url: lcUrl('batchDelete'),
method: 'delete',
data: ids
})
}

View File

@@ -346,6 +346,28 @@ export const constantRoutes = [
]
},
{
path: '/xixi-love',
component: Layout,
redirect: '/xixi-love/inspection',
name: 'XixiLoveRoot',
meta: { title: '喜喜爱情', icon: 'el-icon-star-on' },
children: [
{
path: 'inspection',
name: 'XixiInspection',
component: () => import('@/views/xixi-love/inspection'),
meta: { title: '喜喜检查', icon: 'el-icon-view' }
},
{
path: 'inspection-story',
name: 'XixiInspectionStory',
component: () => import('@/views/xixi-love/inspection-story'),
meta: { title: '喜喜检查故事', icon: 'el-icon-reading' }
}
]
},
{
path: '/system',
component: Layout,

View File

@@ -0,0 +1,20 @@
<template>
<div class="app-container">
<el-card shadow="never">
<div class="page-title">喜喜检查故事</div>
</el-card>
</div>
</template>
<script>
export default {
name: 'XixiInspectionStory'
}
</script>
<style scoped>
.page-title {
font-size: 16px;
color: #303133;
}
</style>

View File

@@ -0,0 +1,485 @@
<template>
<div class="app-container">
<div class="filter-container">
<el-input
v-model="listQuery.projectName"
placeholder="项目名称(模糊)"
style="width: 180px;"
class="filter-item"
clearable
@keyup.enter.native="handleFilter"
/>
<el-input
v-model="listQuery.type"
placeholder="类型(模糊)"
style="width: 140px;"
class="filter-item"
clearable
@keyup.enter.native="handleFilter"
/>
<el-input
v-model="listQuery.parentId"
placeholder="父级ID精确"
style="width: 200px;"
class="filter-item"
clearable
@keyup.enter.native="handleFilter"
/>
<el-select
v-model="listQuery.hazardStars"
placeholder="危害星级"
clearable
style="width: 110px;"
class="filter-item"
>
<el-option v-for="n in 5" :key="n" :label="`${n} 星`" :value="n" />
</el-select>
<el-date-picker
v-model="createTimeRange"
type="datetimerange"
range-separator=""
start-placeholder="创建开始"
end-placeholder="创建结束"
value-format="yyyy-MM-dd HH:mm:ss"
:default-time="['00:00:00', '23:59:59']"
class="filter-item filter-daterange"
clearable
/>
<el-date-picker
v-model="updateTimeRange"
type="datetimerange"
range-separator=""
start-placeholder="修改开始"
end-placeholder="修改结束"
value-format="yyyy-MM-dd HH:mm:ss"
:default-time="['00:00:00', '23:59:59']"
class="filter-item filter-daterange"
clearable
/>
<el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
查询
</el-button>
<el-button class="filter-item" icon="el-icon-refresh-left" @click="resetFilter">
重置
</el-button>
<el-button class="filter-item" type="primary" icon="el-icon-plus" @click="handleCreate">
新增
</el-button>
</div>
<el-table
v-loading="listLoading"
:data="list"
border
fit
highlight-current-row
style="width: 100%;"
>
<el-table-column label="项目名称" prop="projectName" min-width="140" show-overflow-tooltip />
<el-table-column label="危害程度" width="140" align="center">
<template slot-scope="{ row }">
<el-rate
:value="row.hazardStars"
disabled
show-score
text-color="#ff9900"
score-template="{value} "
/>
</template>
</el-table-column>
<el-table-column label="类型" prop="type" width="100" show-overflow-tooltip />
<el-table-column label="简述" prop="brief" min-width="160" show-overflow-tooltip />
<el-table-column label="备注" prop="remark" min-width="120" show-overflow-tooltip />
<el-table-column label="父级ID" prop="parentId" min-width="120" show-overflow-tooltip>
<template slot-scope="{ row }">
<span>{{ row.parentId || '—' }}</span>
</template>
</el-table-column>
<el-table-column label="创建时间" width="160" align="center">
<template slot-scope="{ row }">
<span>{{ formatDateTime(row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="修改时间" width="160" align="center">
<template slot-scope="{ row }">
<span>{{ formatDateTime(row.updateTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" width="160" fixed="right">
<template slot-scope="{ row }">
<el-button type="primary" size="mini" @click="handleUpdate(row)">
编辑
</el-button>
<el-button type="danger" size="mini" @click="handleDelete(row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total > 0"
:total="total"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
<el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="560px" @close="onDialogClose">
<el-form ref="dataForm" :rules="rules" :model="temp" label-width="100px">
<el-form-item label="父级ID" prop="parentId">
<el-input v-model="temp.parentId" placeholder="根节点可留空" clearable />
</el-form-item>
<el-form-item label="项目名称" prop="projectName">
<el-input v-model="temp.projectName" placeholder="请输入项目名称" maxlength="200" show-word-limit />
</el-form-item>
<el-form-item label="危害程度" prop="hazardStars">
<el-rate
v-model="temp.hazardStars"
:max="5"
show-text
:texts="starTexts"
/>
<span class="rate-hint">15 5 星危害最大</span>
</el-form-item>
<el-form-item label="类型" prop="type">
<el-input v-model="temp.type" placeholder="类型" maxlength="100" />
</el-form-item>
<el-form-item label="简述" prop="brief">
<el-input v-model="temp.brief" type="textarea" :rows="3" placeholder="简述" maxlength="500" show-word-limit />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="temp.remark" type="textarea" :rows="2" placeholder="备注" maxlength="500" show-word-limit />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false"> </el-button>
<el-button type="primary" @click="dialogStatus === 'create' ? createData() : updateData()"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import {
fetchXixiInspectionList,
getXixiInspectionById,
addXixiInspection,
updateXixiInspection,
deleteXixiInspection
} from '@/api/xixi-inspection'
import waves from '@/directive/waves'
import Pagination from '@/components/Pagination'
const emptyForm = () => ({
id: undefined,
parentId: '',
projectName: '',
hazardStars: 3,
type: '',
brief: '',
remark: ''
})
export default {
name: 'XixiInspection',
components: { Pagination },
directives: { waves },
data() {
const validateHazardStars = (rule, value, callback) => {
const n = Number(value)
if (n === undefined || n === null || Number.isNaN(n)) {
callback(new Error('请选择危害程度'))
return
}
if (n < 1 || n > 5) {
callback(new Error('危害程度为 15 星'))
return
}
callback()
}
return {
list: [],
total: 0,
listLoading: false,
listQuery: {
page: 1,
limit: 10,
projectName: undefined,
type: undefined,
parentId: undefined,
hazardStars: undefined
},
createTimeRange: null,
updateTimeRange: null,
temp: emptyForm(),
dialogFormVisible: false,
dialogStatus: '',
textMap: {
update: '编辑检查项',
create: '新增检查项'
},
starTexts: ['1星', '2星', '3星', '4星', '5星'],
rules: {
projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
hazardStars: [{ required: true, validator: validateHazardStars, trigger: 'change' }]
}
}
},
created() {
this.getList()
},
methods: {
formatDateTime(val) {
if (!val) return '—'
const d = new Date(val)
if (Number.isNaN(d.getTime())) return String(val)
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
const h = String(d.getHours()).padStart(2, '0')
const min = String(d.getMinutes()).padStart(2, '0')
return `${y}-${m}-${day} ${h}:${min}`
},
/**
* 后端分页data 为记录数组total/current/size 在响应顶层(拦截器已合并到 response
*/
parseListResponse(response) {
const raw = response.data
const rows = Array.isArray(raw)
? raw
: (raw && (raw.records || raw.data)) || []
const total =
response.total != null
? response.total
: (raw && !Array.isArray(raw) && raw.total != null ? raw.total : rows.length)
return { rows, total: Number(total) || 0 }
},
buildListParams() {
const params = {
page: this.listQuery.page,
limit: this.listQuery.limit,
projectName: this.listQuery.projectName,
type: this.listQuery.type,
parentId: this.listQuery.parentId,
hazardStars: this.listQuery.hazardStars
}
if (this.createTimeRange && this.createTimeRange.length === 2) {
params.createStartTime = this.createTimeRange[0]
params.createEndTime = this.createTimeRange[1]
}
if (this.updateTimeRange && this.updateTimeRange.length === 2) {
params.updateStartTime = this.updateTimeRange[0]
params.updateEndTime = this.updateTimeRange[1]
}
Object.keys(params).forEach((key) => {
const v = params[key]
if (v === '' || v === null || v === undefined) {
delete params[key]
}
})
return params
},
getList() {
this.listLoading = true
const params = this.buildListParams()
fetchXixiInspectionList(params)
.then((response) => {
if (response && (response.code === 20000 || response.code === 200)) {
const { rows, total } = this.parseListResponse(response)
this.list = rows
this.total = total
} else {
this.$message.error(response?.message || '获取列表失败')
this.list = []
this.total = 0
}
this.listLoading = false
})
.catch(() => {
this.list = []
this.total = 0
this.listLoading = false
})
},
handleFilter() {
this.listQuery.page = 1
this.getList()
},
resetFilter() {
this.listQuery = {
page: 1,
limit: this.listQuery.limit,
projectName: undefined,
type: undefined,
parentId: undefined,
hazardStars: undefined
}
this.createTimeRange = null
this.updateTimeRange = null
this.getList()
},
resetTemp() {
this.temp = emptyForm()
},
buildSubmitPayload() {
const payload = {
parentId: this.temp.parentId ? String(this.temp.parentId).trim() : null,
projectName: (this.temp.projectName || '').trim(),
hazardStars: Number(this.temp.hazardStars),
type: (this.temp.type || '').trim() || null,
brief: (this.temp.brief || '').trim() || null,
remark: (this.temp.remark || '').trim() || null
}
if (this.dialogStatus === 'update' && this.temp.id) {
payload.id = this.temp.id
}
return payload
},
handleCreate() {
this.resetTemp()
this.dialogStatus = 'create'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
})
},
handleUpdate(row) {
this.listLoading = true
getXixiInspectionById(row.id)
.then((response) => {
if (response && (response.code === 20000 || response.code === 200) && response.data) {
const d = response.data
this.temp = {
id: d.id,
parentId: d.parentId || '',
projectName: d.projectName || '',
hazardStars: d.hazardStars != null ? Number(d.hazardStars) : 3,
type: d.type || '',
brief: d.brief || '',
remark: d.remark || ''
}
} else {
this.temp = {
id: row.id,
parentId: row.parentId || '',
projectName: row.projectName || '',
hazardStars: row.hazardStars != null ? Number(row.hazardStars) : 3,
type: row.type || '',
brief: row.brief || '',
remark: row.remark || ''
}
}
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
})
})
.catch(() => {
this.temp = {
id: row.id,
parentId: row.parentId || '',
projectName: row.projectName || '',
hazardStars: row.hazardStars != null ? Number(row.hazardStars) : 3,
type: row.type || '',
brief: row.brief || '',
remark: row.remark || ''
}
this.dialogStatus = 'update'
this.dialogFormVisible = true
this.$nextTick(() => {
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
})
})
.finally(() => {
this.listLoading = false
})
},
createData() {
this.$refs.dataForm.validate((valid) => {
if (!valid) return
const payload = this.buildSubmitPayload()
addXixiInspection(payload)
.then((response) => {
if (response && (response.code === 20000 || response.code === 200)) {
this.$message.success(response.message || '新增成功')
this.dialogFormVisible = false
this.getList()
} else {
this.$message.error(response?.message || '新增失败')
}
})
.catch(() => {})
})
},
updateData() {
this.$refs.dataForm.validate((valid) => {
if (!valid) return
const payload = this.buildSubmitPayload()
updateXixiInspection(payload)
.then((response) => {
if (response && (response.code === 20000 || response.code === 200)) {
this.$message.success(response.message || '更新成功')
this.dialogFormVisible = false
this.getList()
} else {
this.$message.error(response?.message || '更新失败')
}
})
.catch(() => {})
})
},
handleDelete(row) {
this.$confirm(`确定删除检查项「${row.projectName || row.id}」吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
})
.then(() => {
deleteXixiInspection(row.id).then((response) => {
if (response && (response.code === 20000 || response.code === 200)) {
this.$message.success(response.message || '删除成功')
this.getList()
} else {
this.$message.error(response?.message || '删除失败')
}
})
})
.catch(() => {})
},
onDialogClose() {
this.resetTemp()
this.$nextTick(() => {
if (this.$refs.dataForm) {
this.$refs.dataForm.clearValidate()
}
})
}
}
}
</script>
<style scoped>
.filter-container {
padding-bottom: 10px;
}
.filter-item {
display: inline-block;
vertical-align: middle;
margin-bottom: 10px;
margin-right: 10px;
}
.filter-daterange {
width: 340px;
}
.rate-hint {
margin-left: 12px;
font-size: 12px;
color: #909399;
}
.dialog-footer {
text-align: right;
}
</style>