记录Ant Design of Vue Notification 通知提醒框右下角弹出动态赋值图片

本文介绍了如何在Vue应用中使用Ant Design of Vue开发一个右下角的弹出图片窗口,点击图片可下载附件,通过Promise处理异步通知并展示图片样式。

业务需求——右下角弹出图片窗口可点击下载

//底部右侧弹窗
      openNotification(imgURL,zipURL) {
        this.$notification.open({
          description:<img src={`${imgURL}`} style='max-width:100%;height:auto;margin-top:-21px;cursor: pointer;'/>,
          onClick:()=>{
            this.download(zipURL)
        },
          style:{
            padding:0,
            margin:5,
        },
          placement: 'bottomRight',
            duration:null,
          closeIcon:false
        });
      },

style='max-width:100%;height:auto;margin-top:-21px;cursor: pointer;
图片样式解析
max-width:100%;height:auto;//图片平铺填充
margin-top:-21px;//去除通知框顶部宝色边框
cursor: pointer;鼠标移上去转换小手
notification内联样式解析
style:{
padding:0,//去除通知框左右下侧白色外框
margin:5,//多个通知框弹出上下间隔
},
其余config 参数Ant Design of Vue官网自行查询

data() {
      return {
        notifyPromise: Promise.resolve(),//转为 Promise 对象,需要异步弹出通知框
      }
    },
queryZipFileList() {
        const that = this
        getAction(this.url.list,{}).then(res=>{
          if(res.success){
            let dataSource = res.result.records
            console.log("dataSource----",dataSource)
            dataSource.forEach((item,index)=>{
              item.imgURL = `${this.url.downloadImgURL}?id=${item.id}`;
              item.zipURL = `${this.url.downloadZipURL}?id=${item.id}`;
              that.notifyPromise = that.notifyPromise.then(() => {//异步操作调用弹出方法
                console.log("index------",index+"次循环")
                that.openNotification(item.imgURL,item.zipURL);
              })
            })
          }
        })
      },

在这里插入图片描述

<!-- * @Author: 可爱又迷人的反派角色 * @Version: 3.0 * @Date: 2021-01-08 15:46:32 * @LastEditTime: 2023-11-23 18:20:04 * @FilePath: \web_kedxn_v3\src\views\information\equipment\meter\meterWater\Index.vue * @Description: 电表管理 --> <template> <div> <Action :itemList="itemList" @search="search"> <template #action> <a-button type="primary" shape="round" style="margin-right: 5px" @click="showVisible('importVisible')" v-action:import >批量导入</a-button > <a-button type="primary" shape="round" @click="show({})" v-action:add >新增仪表</a-button > <a-button type="primary" shape="round" @click="exportFun" style="margin-top: 5px" :loading="exportLoading" >导出</a-button > </template> </Action> <a-card :bordered="false"> <list :itemList="itemList" :loading="loading" :data="list_data" @show="show" @refresh="refresh" @handleTableChange="handleTableChange" :pagination="pagination" > </list> </a-card> <operation :itemList="itemList" :visible="visible" @show="show" @refresh="refresh" :data="editData" @editVisibleGoto="editVisibleGoto" > </operation> <BatchImport :visible="importVisible" name="water" :type="2" @ok="importOk" /> <Modal :visible="visible_goto" :regionId="region_id" @editVisibleGoto="editVisibleGoto" @show="show" /> </div> </template> <script> import BatchImport from '#/components/Global/BatchImport'; import { _getMeterWater, _waterMeterExport } from '#/api/information'; import operation from './Operation'; import list from './List.vue'; import Modal from './Modal'; import Action from './Action.vue'; import { _allMeterItem } from '#/api/energy'; import fileDownload from 'js-file-download'; export default { data() { return { action: [], visible: false, importVisible: false, visible_goto: false, list_data: [], editData: {}, pagination: {}, actionData: {}, listChangeData: {}, loading: true, itemList: [], pageSize: 10, exportLoading: false, region_id: '', // 添加仪表的时候记录区域id }; }, created() { this.get(); this.getItem(); }, methods: { // 导出 exportFun() { this.exportLoading = true; const values = { ...this.actionData }; _waterMeterExport(values) .then((res) => { setTimeout(() => { this.exportLoading = false; }, 1000); fileDownload(res, `水表.xls`); }) .catch(() => { this.exportLoading = false; }); }, // 获取所有分析 async getItem() { const { data } = await _allMeterItem({ item_type: 2 }); this.itemList = data; }, /** * @description:弹状态修改 * @param {*} */ editVisibleGoto() { this.showVisible('visible_goto'); }, /** * @description:获取列表更改 * @param {*}data */ handleTableChange(data) { this.listChangeData = data; this.get(data.page); }, /** * @description:获取列表 * @param {*}page */ async get(page) { this.loading = true; const values = { ...this.actionData, ...this.listChangeData, page: page || this.pagination.current || 1, limit: this.pageSize || 10, }; const { data } = await _getMeterWater(values); this.loading = false; this.list_data = data.data; this.pagination = { defaultPageSize: this.pageSize, showTotal: (total) => `共 ${data.total} 条数据`, showSizeChanger: true, pageSizeOptions: ['10', '20', '30', '50', '100'], onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize), total: data.total, current: data.current_page, }; }, /** * @description: 新增&&修改后刷新 重新获取列表 * @param {*} */ async refresh(data, text, region_id) { this.region_id = region_id; if (data) { if (data.code && data.code === 200) { this.show({}); if (text === 'add') { this.editVisibleGoto(); } this.$notification.success({ message: '操作成功', }); } else if (data.code && data.code === 250) { this.show({}); this.$notification.warning({ message: data.msg, duration: 0, }); } } this.get(); }, /** * @description: 修改操作显示状态, 传递data值 返回&&新增&&修改&&新增子路由 * @param {*} data */ show(data) { this.showVisible('visible'); this.editData = data; }, /** * @description: 获取筛选下的内容 * @param {*} data */ search(data) { this.actionData = { ...this.actionData, ...data }; this.get(1); }, /** * @description: 导入成功 * @param {*}type */ importOk(type) { this.showVisible('importVisible'); if (type === 1) { this.get(1); } }, }, components: { list, operation, Action, BatchImport, Modal }, }; </script> 优化一下
最新发布
10-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值