IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> JavaScript知识库 -> vue3初体验-基于vue3+ant design封装公共弹框 -> 正文阅读

[JavaScript知识库]vue3初体验-基于vue3+ant design封装公共弹框

parent.vue

<template>
  <div>
    <a-form
      name="advanced_search"
      class="ant-advanced-search-form"
      :model="searchForm"
    >
      <a-form-item label="客户编码" name="customNo">
        <a-input-search enter-button v-model:value="searchForm.customNo" style="width: 200px" @search="searchCustomNo"/>
      </a-form-item>
    </a-form>
    <customMultipleModel v-if="childShow" :modelShow="modelShow" :selectType="selectType" @closeModel="changeDialogVisible"/>
  </div>
</template>
<script lang="ts">
import { defineComponent, reactive, ref} from 'vue';
import customMultipleModel from '/@/components/custonMultipleSelection/index.vue'
export default defineComponent({
  components: {
    customMultipleModel
  },
  setup() {
    const searchForm = reactive({}); // form表单字段
    const childShow = ref(false) // 弹框是否显示
    const modelShow = ref(false) // 子组件弹框状态
    const selectType = ref('radio') // 单多选
    // 客户编码弹框查询
    const searchCustomNo = () => {
      modelShow.value = true
      childShow.value = true
    }
    // 弹框关闭回调
    const changeDialogVisible = (content) => {
      modelShow.value = false
      childShow.value = false
      if (content) {
        searchForm.customNo = content.value
      }
    }
    return {
      searchForm,
      searchCustomNo,
      modelShow,
      childShow,
      changeDialogVisible,
      selectType,
    };
  },
});
</script>
<style lang="less" scoped>
</style>

child.vue

<template>
  <div>
    <a-modal v-model:visible="visible" width="900px" title="选择客户" @cancel="handleCancel">
      <template #footer>
        <a-button key="back" @click="handleCancel">取消</a-button>
        <a-button key="submit" type="primary" :loading="loading" @click="handleOk">确认</a-button>
      </template>
      <a-form
        ref="searchForm"
        name="advanced_search"
        class="ant-advanced-search-form"
        :model="customForm"
        :label-col="labelCol"
      >
        <a-form-item label="客户操作吗" name="customOpCode">
          <a-input v-model:value="customForm.customOpCode" style="width: 200px" />
        </a-form-item>
        <a-form-item label="客户编码" name="customNo">
          <a-input v-model:value="customForm.customNo" style="width: 200px" />
        </a-form-item>
        <a-form-item label="客户名称" name="customName">
          <a-input v-model:value="customForm.customName" style="width: 200px" />
        </a-form-item>
        <a-form-item>
          <a-button style="margin-left: 30px" type="primary" html-type="submit" @click="searchTableList">搜索</a-button>
          <a-button style="margin: 0 8px" @click="resetForm">重置</a-button>
        </a-form-item>
      </a-form>
      <a-table bordered :columns="columns" :data-source="tableData" :scroll="{ y: 300 }" :row-selection="{onChange: onSelectChange, type: selectType}" @change="handleTableChange" :loading="tableLoading" :pagination="pagination" @resizeColumn="handleResizeColumn" :customRow="rowClick"></a-table>
    </a-modal>
  </div>
</template>

<script lang="ts">
import {defineComponent, ref, reactive} from 'vue';
import {TableProps, Form} from "ant-design-vue";
import {useDemoStore} from '/@/store/demo'
export default defineComponent({
  props: {
    modelShow: {
      type: Boolean,
      default: false
    },
    selectType: {
      type: String,
      default: 'checkbox'
    }
  },
  setup(props, ctx) {
    const demoStore = useDemoStore()
    const useForm = Form.useForm
    const data = ref(props)
    const loading = ref<boolean>(false);
    const visible = ref(data.value.modelShow)
    const customForm = reactive({ customOpCode: '', customNo: '', customName: '' })
    const tableData = ref([]) // 表格渲染数据
    const tableLoading = ref(false) // 表格loading状态
    const selectData = ref([])
    const selectType = data.value.selectType
    console.log(data.value)
    const handleOk = () => {
      visible.value = false
      ctx.emit('closeModel', selectData)
    };
    const handleCancel = () => {
      visible.value = false
      ctx.emit('closeModel', false)
    };
    // 分页配置项
    let pagination = ref({
      // 数据总数
      total: 0,
      // 当前页数
      current: 1,
      // 每页条数
      pageSize: 20,
      // 展示总数
      showTotal: (totalSize) => `${totalSize}`,
      // 是否可以改变pageSize
      showSizeChanger: true,
      // 设置每页可以展示多少条的选项
      pageSizeOptions: ["20", "50", "100", "200"],
      // 小尺寸分页
      size: "middle",
      // 是否可以快速跳转至某页
      showQuickJumper: true,
      //默认条数
      defaultPageSize: 20,
    })
    const searchTableList = (async (e) => {
      if (e !== 'page') {
        pagination.value.current = 1
      }
      tableLoading.value = true
      let params = {
        pageNum: pagination.value.current,
        pageSize: pagination.value.pageSize,
        condition: { ...customForm }
      }
      const res = await demoStore.getCustomerList(params)
      tableLoading.value = false
      res.data.records.forEach((item, index) => {
        item.key = index + 1
      })
      tableData.value = res.data.records
      pagination.value.total = res.data.total
      pagination.value.current = res.data.pageNum
      pagination.value.pageSize = res.data.pageSize
    })
    // 分页接口逻辑
    const handleTableChange: TableProps['onChange'] = (pag: { pageSize: number; current: number }) => {
      pagination.value.current = pag.current
      pagination.value.pageSize = pag.pageSize
      searchTableList('page')
    }
    const { resetFields } = useForm(customForm)
    const resetForm = () => {
      resetFields()
      searchTableList()
    }
    const onSelectChange = (selectedRowKeys, selectedRows) => {
      selectData.value = selectedRows.map(item => {
        return item.customNo
      })
      selectData.value = selectData.value.join(',')
    };
    const rowClick = () => {
      return {
        onClick: (event) => {
          if (selectType === 'radio') {
            event.path[1].querySelector('.ant-radio-wrapper').click()
          } else {
            event.path[1].querySelector('.ant-checkbox-wrapper').click()
          }
        },
      };
    }
    const columns = ref([
      {title: '序号', dataIndex: 'key', resizable: true, width: 50, ellipsis: true},
      {title: '客户编码', dataIndex: 'customNo', resizable: true, width: 200, ellipsis: true},
      {title: '客户名称', dataIndex: 'customName', resizable: true, width: 350, ellipsis: true},
      {title: '客户操作码', dataIndex: 'customOpCode', resizable: true, width: 180, ellipsis: true},
    ])
    return {
      visible,
      loading,
      handleOk,
      handleCancel,
      labelCol: { style: { width: '100px' } },
      customForm,
      columns,
      pagination,
      tableData,
      tableLoading,
      handleTableChange,
      searchTableList,
      handleResizeColumn: (w, col) => {
        col.width = w;
      },
      onSelectChange,
      resetForm,
      rowClick,
      selectType,
    };
  },
});
</script>

<style scoped>

</style>

初学vue3,有什么不同意见大家一起交流,共同进步

  JavaScript知识库 最新文章
ES6的相关知识点
react 函数式组件 & react其他一些总结
Vue基础超详细
前端JS也可以连点成线(Vue中运用 AntVG6)
Vue事件处理的基本使用
Vue后台项目的记录 (一)
前后端分离vue跨域,devServer配置proxy代理
TypeScript
初识vuex
vue项目安装包指令收集
上一篇文章      下一篇文章      查看所有文章
加:2022-06-25 18:01:20  更:2022-06-25 18:01:38 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年9日历 -2024/9/20 0:38:04-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码