当前位置:首页 > VUE

vue实现审核功能

2026-01-11 23:12:44VUE

实现审核功能的基本思路

审核功能通常涉及状态管理、权限控制和操作记录。Vue中可以通过组件化设计、状态管理库(如Vuex或Pinia)和后端API配合实现。

审核状态管理

使用Vuex或Pinia存储审核状态数据。定义审核状态枚举和对应操作:

// Pinia示例
import { defineStore } from 'pinia'

export const useAuditStore = defineStore('audit', {
  state: () => ({
    items: [], // 待审核条目
    statusOptions: [
      { value: 0, label: '待审核' },
      { value: 1, label: '已通过' },
      { value: 2, label: '已拒绝' }
    ]
  }),
  actions: {
    async fetchItems() {
      const res = await api.getPendingItems()
      this.items = res.data
    },
    async approveItem(id) {
      await api.approveItem(id)
      await this.fetchItems()
    }
  }
})

审核操作组件

创建可复用的审核操作组件,包含通过/拒绝按钮和备注输入:

<template>
  <div class="audit-actions">
    <el-button type="success" @click="handleApprove">通过</el-button>
    <el-button type="danger" @click="handleReject">拒绝</el-button>
    <el-input v-model="remark" placeholder="审核备注"></el-input>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useAuditStore } from '@/stores/audit'

const props = defineProps(['itemId'])
const remark = ref('')
const auditStore = useAuditStore()

const handleApprove = () => {
  auditStore.approveItem(props.itemId, remark.value)
}

const handleReject = () => {
  auditStore.rejectItem(props.itemId, remark.value)
}
</script>

审核列表展示

使用表格展示待审核内容,集成审核操作组件:

<template>
  <el-table :data="auditStore.items">
    <el-table-column prop="content" label="内容"></el-table-column>
    <el-table-column prop="status" label="状态">
      <template #default="{row}">
        {{ getStatusText(row.status) }}
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template #default="{row}">
        <AuditActions :item-id="row.id" />
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { useAuditStore } from '@/stores/audit'
import AuditActions from './AuditActions.vue'

const auditStore = useAuditStore()
auditStore.fetchItems()

const getStatusText = (status) => {
  return auditStore.statusOptions.find(o => o.value === status)?.label || ''
}
</script>

权限控制

通过路由守卫和组件权限指令控制审核功能访问:

// 路由守卫
router.beforeEach((to) => {
  if (to.meta.requiresAudit && !userStore.hasAuditPermission) {
    return '/403'
  }
})

// 自定义指令
app.directive('audit', {
  mounted(el, binding) {
    if (!userStore.hasAuditPermission) {
      el.parentNode.removeChild(el)
    }
  }
})

审核日志记录

创建独立的审核日志组件,显示历史记录:

<template>
  <el-timeline>
    <el-timeline-item 
      v-for="log in logs"
      :key="log.id"
      :timestamp="log.time"
      placement="top"
    >
      {{ log.operator }} {{ log.action }}了内容:{{ log.content }}
      <p v-if="log.remark">备注:{{ log.remark }}</p>
    </el-timeline-item>
  </el-timeline>
</template>

<script setup>
import { ref } from 'vue'
import { getAuditLogs } from '@/api/audit'

const logs = ref([])
getAuditLogs().then(res => {
  logs.value = res.data
})
</script>

后端API集成

典型审核API接口设计示例:

vue实现审核功能

// 获取待审核列表
export const getPendingItems = () => axios.get('/audit/pending')

// 审核通过
export const approveItem = (id, remark) => 
  axios.post(`/audit/${id}/approve`, { remark })

// 审核拒绝
export const rejectItem = (id, remark) => 
  axios.post(`/audit/${id}/reject`, { remark })

// 获取审核日志
export const getAuditLogs = (params) => 
  axios.get('/audit/logs', { params })

标签: 功能vue
分享给朋友:

相关文章

vue实现store

vue实现store

Vue 实现 Store 在 Vue 中,可以通过 Vuex 或 Pinia 实现全局状态管理(Store)。以下是两种主流方案的实现方法。 使用 Vuex 实现 Store Vuex 是 Vue…

实现vue模版

实现vue模版

Vue 模板的基本结构 Vue 模板基于 HTML 语法,通过 Vue 的指令和插值实现动态渲染。以下是一个基础模板示例: <template> <div id="…

vue实现订单

vue实现订单

Vue 实现订单功能 订单数据结构设计 订单数据通常包含以下字段: order: { id: String, // 订单ID userId: String,…

vue实现接口

vue实现接口

在 Vue 中实现接口请求 Vue 本身不直接提供 HTTP 请求功能,通常需要借助第三方库如 axios 或 fetch 来实现接口请求。以下是几种常见方法: 使用 axios 发送请求 安装 a…

vue实现抽奖

vue实现抽奖

Vue 实现抽奖功能 基本抽奖逻辑 创建一个Vue组件,包含奖品列表、抽奖按钮和结果显示区域。使用随机数生成器选择奖品。 <template> <div> <…

vue scrolltop 实现

vue scrolltop 实现

实现 Vue 中的 scrollTop 在 Vue 中实现滚动到顶部功能可以通过多种方式完成,包括使用原生 JavaScript、Vue 指令或第三方库。以下是几种常见的实现方法: 使用原生 Jav…