From 52af035632e198e8f0cb7f5154fee51994c475db Mon Sep 17 00:00:00 2001 From: 龚焕茏 <2842157468@qq.com> Date: 星期六, 11 五月 2024 16:57:55 +0800 Subject: [PATCH] feat:新增问答模块 --- src/views/feedback/list.vue | 4 src/views/questionAnswer/edit.vue | 100 ++++++++++++++++++++ src/api/questionAnswer.js | 10 ++ src/views/questionAnswer/list.vue | 134 ++++++++++++++++++++++++++ src/router.js | 25 +++++ 5 files changed, 271 insertions(+), 2 deletions(-) diff --git a/src/api/questionAnswer.js b/src/api/questionAnswer.js new file mode 100644 index 0000000..66980af --- /dev/null +++ b/src/api/questionAnswer.js @@ -0,0 +1,10 @@ +import { get, post } from '@/utils/request' + +export default { + pageList: query => post('/api/admin/questionAnswer/page', query), + save: query => post('/api/admin/questionAnswer/save', query), + update: query => post('/api/admin/questionAnswer/update', query), + delete: id => post('/api/admin/questionAnswer/delete/' + id), + query: id => post('/api/admin/questionAnswer/query/' + id), + updateStatus: id => post('/api/admin/questionAnswer/updateStatus/' + id), +} diff --git a/src/router.js b/src/router.js index 31f917f..c2ee1eb 100644 --- a/src/router.js +++ b/src/router.js @@ -296,6 +296,31 @@ ] }, { + path: '/questionAnswer', + component: Layout, + name: 'questionAnswerPage', + meta: { + title: '闂瓟绠$悊', + icon: 'question' + }, + alwaysShow: true, + children: [ + { + path: '/list', + component: () => import('@/views/questionAnswer/list'), + name: 'questionAnswerPage', + meta: { title: '闂瓟鍒楄〃', noCache: true } + }, + { + path: '/edit', + component: () => import('@/views/questionAnswer/edit'), + name: 'questionAnswerEdit', + meta: { title: '闂瓟缂栬緫', noCache: true, activeMenu: '/questionAnswer/list' }, + hidden: true + } + ] + }, + { path: '/message', component: Layout, name: 'MessagePage', diff --git a/src/views/feedback/list.vue b/src/views/feedback/list.vue index 780d652..4455709 100644 --- a/src/views/feedback/list.vue +++ b/src/views/feedback/list.vue @@ -13,10 +13,10 @@ <el-table-column label="鎿嶄綔" align="center" width="300px"> <template slot-scope="{row}"> <el-button size="mini" @click="showQuestion(row)" class="link-left">棰樼洰棰勮</el-button> - <el-popconfirm title="纭畾宸插鐞嗗悧锛�" @confirm="hanldSettleFeedback(row)"> + <el-popconfirm title="纭澶勭悊" @confirm="hanldSettleFeedback(row)"> <el-button slot="reference" v-if="!row.fix" size="mini" type="primary" class="link-left">纭澶勭悊</el-button> </el-popconfirm> - <el-popconfirm title="纭畾瑕佸垹闄ゅ悧锛�" @confirm="hanldDeleteFeedback(row)"> + <el-popconfirm title="纭鍒犻櫎" @confirm="hanldDeleteFeedback(row)"> <el-button slot="reference" size="mini" type="danger" class="link-left">鍒犻櫎</el-button> </el-popconfirm> </template> diff --git a/src/views/questionAnswer/edit.vue b/src/views/questionAnswer/edit.vue new file mode 100644 index 0000000..222ffd2 --- /dev/null +++ b/src/views/questionAnswer/edit.vue @@ -0,0 +1,100 @@ +<template> + <div class="app-container"> + + <el-form :model="form" ref="form" label-width="100px" v-loading="formLoading" :rules="rules"> + <el-form-item label="闂锛�" prop="question"> + <el-input v-model="form.question"></el-input> + </el-form-item> + <el-form-item label="绛旀锛�" prop="answer"> + <el-input v-model="form.answer"></el-input> + </el-form-item> + <el-form-item> + <el-button type="primary" @click="submitForm">鎻愪氦</el-button> + <el-button @click="resetForm">閲嶇疆</el-button> + </el-form-item> + </el-form> + </div> +</template> + +<script> +import { mapGetters, mapState, mapActions } from 'vuex' +import questionAnswerApi from '@/api/questionAnswer' + +export default { + data () { + return { + form: { + id: null, + question: '', + answer: '' + }, + formLoading: false, + rules: { + question: [ + { required: true, message: '璇疯緭鍏ラ棶棰�', trigger: 'blur' } + ], + answer: [ + { required: true, message: '璇疯緭鍏ョ瓟妗�', trigger: 'blur' } + ] + } + } + }, + created () { + let id = this.$route.query.id + let _this = this + if (id && parseInt(id) !== 0) { + _this.formLoading = true + questionAnswerApi.query(id).then(re => { + _this.form = re.response + _this.formLoading = false + }) + } + }, + methods: { + submitForm () { + let _this = this + this.$refs.form.validate((valid) => { + if (valid) { + this.formLoading = true + questionAnswerApi.save(this.form).then(data => { + if (data.code === 1) { + _this.$message.success(data.message) + _this.delCurrentView(_this).then(() => { + _this.$router.push('/list') + }) + } else { + _this.$message.error(data.message) + _this.formLoading = false + } + }).catch(e => { + _this.formLoading = false + }) + } else { + return false + } + }) + }, + resetForm () { + let lastId = this.form.id + this.$refs['form'].resetFields() + this.form = { + id: null, + question: '', + answer: '' + } + this.form.id = lastId + }, + ...mapActions('tagsView', { delCurrentView: 'delCurrentView' }) + }, + computed: { + ...mapGetters('enumItem', [ + 'enumFormat' + ]), + ...mapState('enumItem', { + sexEnum: state => state.user.sexEnum, + roleEnum: state => state.user.roleEnum, + statusEnum: state => state.user.statusEnum + }) + } +} +</script> diff --git a/src/views/questionAnswer/list.vue b/src/views/questionAnswer/list.vue new file mode 100644 index 0000000..0544d88 --- /dev/null +++ b/src/views/questionAnswer/list.vue @@ -0,0 +1,134 @@ +<template> + <div class="app-container"> + <el-form :model="queryParam" ref="queryForm" :inline="true"> + <el-form-item label="闂瓟鍐呭锛�"> + <el-input v-model="queryParam.question" clearable></el-input> + </el-form-item> + <el-form-item> + <div style="display: flex"> + <el-button type="primary" @click="submitForm">鏌ヨ</el-button> + <router-link :to="{ path: '/edit' }" class="link-left"> + <el-button type="primary">娣诲姞</el-button> + </router-link> + </div> + </el-form-item> + </el-form> + + <el-table v-loading="listLoading" :data="tableData" border fit highlight-current-row style="width: 100%"> + <el-table-column prop="question" label="闂" /> + <el-table-column prop="answer" label="绛旀" /> + <el-table-column label="鐘舵��" prop="status" width="70px"> + <template slot-scope="{row}"> + <el-tag :type="row.status !== '鍚敤' ? 'danger' : 'success'"> + {{ row.status }} + </el-tag> + </template> + </el-table-column> + <el-table-column width="270px" label="鎿嶄綔" align="center"> + <template slot-scope="{row}"> + <el-button size="mini" @click="changeStatus(row)" class="link-left"> + {{ row.status !== '鍚敤' ? '鍚敤' : '绂佺敤' }} + </el-button> + <router-link :to="{ path: '/edit', query: { id: row.id } }" class="link-left"> + <el-button size="mini">缂栬緫</el-button> + </router-link> + <el-popconfirm title="纭鍒犻櫎" @confirm="deleteUser(row)"> + <el-button slot="reference" size="mini" type="danger" class="link-left">鍒犻櫎</el-button> + </el-popconfirm> + </template> + </el-table-column> + </el-table> + <pagination v-show="total > 0" :total="total" :page.sync="queryParam.pageIndex" :limit.sync="queryParam.pageSize" + @pagination="search" /> + </div> +</template> + +<script> +import { mapGetters, mapState } from 'vuex' +import Pagination from '@/components/Pagination' +import questionAnswerApi from '@/api/questionAnswer' + +export default { + components: { Pagination }, + data() { + return { + queryParam: { + question: '', + role: 1, + pageIndex: 1, + pageSize: 10 + }, + listLoading: true, + tableData: [], + total: 0 + } + }, + created() { + this.search() + }, + methods: { + search() { + this.listLoading = true + questionAnswerApi.pageList(this.queryParam).then(data => { + const re = data.response + this.tableData = re.list + this.total = re.total + this.queryParam.pageIndex = re.pageNum + this.listLoading = false + }) + }, + changeStatus(row) { + let _this = this + questionAnswerApi.updateStatus(row.id).then(re => { + if (re.code === 1) { + _this.search(); + _this.$message.success(re.message) + } else { + _this.$message.error(re.message) + } + }) + }, + deleteUser(row) { + questionAnswerApi.delete(row.id).then(re => { + if (re.code === 1) { + this.search() + this.$message.success(re.message) + } else { + this.$message.error(re.message) + } + }) + }, + submitForm() { + this.queryParam.pageIndex = 1 + this.search() + }, + statusFormatter(status) { + return this.enumFormat(this.statusEnum, status) + }, + statusTagFormatter(status) { + return this.enumFormat(this.statusTag, status) + }, + statusBtnFormatter(status) { + return this.enumFormat(this.statusBtn, status) + } + + }, + computed: { + ...mapGetters('enumItem', [ + 'enumFormat' + ]), + ...mapState('enumItem', { + sexEnum: state => state.user.sexEnum, + statusEnum: state => state.user.statusEnum, + statusTag: state => state.user.statusTag, + statusBtn: state => state.user.statusBtn, + levelEnum: state => state.user.levelEnum + }) + } +} +</script> +<style lang="scss" scoped> +.upload-demo { + margin-left: 5px; +} +</style> -- Gitblit v1.8.0