ZBLOG

要在FollowUpModal组件中以弹窗的形式打开,你需要使用Ant Design Vue提供的a-modal组件。以下是如何实现这个功能的步骤:

  1. 修改 FollowUpModal 组件:确保你的 FollowUpModal 组件能接收一个 visible 属性来控制弹窗的显示与隐藏,同时可以通过 @close 事件通知父组件关闭弹窗。

  2. 在主模板中引入和管理状态:在你的表格中,创建一个状态来控制 FollowUpModal 的可见性,并将相应的数据传递给它。

下面是修改后的代码示例:

修改后的代码

  1. <template>
  2. <a-table
  3. :columns="columns"
  4. :data-source="data"
  5. :scroll="{
  6. x: columns.reduce((sum, col) => sum + (col.width || 0), 0) > 1800 ? undefined : 'max-content'
  7. }"
  8. :pagination="{
  9. current: currentPage,
  10. pageSize: pageSize,
  11. total: totalRecords,
  12. pageSizeOptions: ['10', '20', '30', '40', '100'],
  13. onShowSizeChange: handlePageSizeChange,
  14. onChange: handlePageChange,
  15. showQuickJumper: true,
  16. showSizeChanger: true,
  17. showTotal: (total, range) => `显示 ${range[0]}~${range[1]} 条记录,共 ${total} 条记录`
  18. }"
  19. >
  20. <template #bodyCell="{ column, record }">
  21. <template v-if="column.key === 'operation'">
  22. <a-button @click="openModal('followUp', record)">跟进</a-button>
  23. <a-button @click="complete(record)">完成</a-button>
  24. </template>
  25. </template>
  26. </a-table>
  27. <!-- Follow Up Modal -->
  28. <FollowUpModal
  29. v-if="isModalVisible"
  30. :visible="isModalVisible"
  31. @close="closeModal"
  32. :record="currentRecord"
  33. />
  34. </template>
  35. <script setup>
  36. import { ref } from 'vue';
  37. import FollowUpModal from '../workOrderManager/components/followUpPage.vue'
  38. const columns = ref([]);
  39. const data = ref([]);
  40. const currentPage = ref(1);
  41. const pageSize = ref(10);
  42. const totalRecords = ref(100);
  43. const isModalVisible = ref(false); // 控制modal显示
  44. const currentRecord = ref(null); // 当前选中的记录
  45. // 打开modal并设置当前记录
  46. const openModal = (action, record) => {
  47. console.log(action, record);
  48. if (action === 'followUp') {
  49. currentRecord.value = record; // 保存当前记录
  50. isModalVisible.value = true; // 显示modal
  51. }
  52. };
  53. // 完成操作
  54. const complete = (record) => {
  55. console.log('完成', record);
  56. };
  57. // 关闭modal
  58. const closeModal = () => {
  59. isModalVisible.value = false; // 隐藏modal
  60. };
  61. </script>

在 FollowUpModal 中

你需要确保 FollowUpModal 可以根据传递的 visible 属性来决定是否展示,且当用户希望关闭模态框时触发 @close:

  1. <template>
  2. <a-modal
  3. title="跟进信息"
  4. v-model:visible="visible"
  5. @ok="$emit('close')"
  6. @cancel="$emit('close')"
  7. >
  8. <!-- 模态框内容 -->
  9. <p>这是关于 {{ record?.name }} 的跟进信息。</p> <!-- 示例内容 -->
  10. </a-modal>
  11. </template>
  12. <script setup>
  13. import { defineProps } from 'vue';
  14. const props = defineProps({
  15. visible: Boolean,
  16. record: Object // 或者具体类型定义
  17. });
  18. </script>

这样就实现了点击“跟进”按钮后,能够弹出包含相关信息的模态框。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=22453

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?