Skip to content
On this page

高级使用

js
<!-- 计费项目 -->
<template>
  <div class="charging-projects table-box">
    <ProTable
      ref="proTable"
      :columns="columns"
      :requestApi="getCostProjectPage"
    >
      <template #tableHeader>
        <el-button @click="addOperation" type="primary">新增</el-button>
      </template>
      <template #operation="{ row }">
        <el-button  @click="editOperation(row)" type="success" plain>编辑</el-button>
        <el-popconfirm title="确定删除?" @confirm="deleteOperation(row)">
          <template #reference>
            <el-button type="danger" plain>删除</el-button>
          </template>
        </el-popconfirm>
      </template>
    </ProTable>
  </div>

  <ComDialog v-model="visible" width="30%" :title="title" top="5vh">
    <template #default>
      <change-charging-projects :dialogData="dialogData" :form="form"></change-charging-projects>
    </template>
    <template #footer>
      <el-button @click="onSubmit">提交</el-button>
      <el-button @click="onCancel">取消</el-button>
    </template>
  </ComDialog>
</template>

<script setup>
import ProTable from '@/components/ProTable'
import ComDialog from '@/components/ComDialog'
import ChangeChargingProjects from './components/changeChargingProjects'
import { getCostProjectPage, addCostProject, deleteCostProject, editCostProject } from "@/apiBig/modules/bms";
import useDialogData from '@/hooks/useDialogData.js'
import useConfig from './hooks/useConfig';
import useOperation from '@/hooks/useOperation'
import useTableOperation from '@/hooks/useTableOperation'
import useInitData from '@/hooks/useInitData'

// 获取初始化数据
const { submitApi, title } = useInitData()
// 获取表格配置列
const { columns } = useConfig()
// 处理表格查询的相关逻辑
const { proTable, refreshTable } = useTableOperation()
// 处理弹窗
const { dialogData, visible, onSubmit, onCancel, form } = useDialogData(submitApi, refreshTable)
// 处理编辑,新增,删除逻辑
const { editOperation, addOperation, deleteOperation } = 
  useOperation(submitApi, addCostProject, editCostProject, deleteCostProject, dialogData, visible, title, refreshTable)

</script>

<style lang="scss" scoped>
.charging-projects {

}
</style>

TIP

什么dataCallback, submitCallback 自己额外定义hooks函数,这里不做演示,都到了这一步别跟我说还不会. useOperation的参数看代码,注释得明明白白

Released under the MIT License.