import { mapState } from 'vuex' export const mixins = { data: function () { return { notify: {}, // 用来维护下载文件进度弹框对象 downLoading: false } }, computed: { ...mapState({ progressList: state => state.downLoadProgress.progressList }) }, watch: { // 监听进度列表 progressList: { handler(n) { const data = JSON.parse(JSON.stringify(n)) console.log('Mixin', data) data.forEach(item => { const domList = [...document.getElementsByClassName(item.path)] if (domList.find(i => i.className === item.path)) { // 如果页面已经有该进度对象的弹框,则更新它的进度progress if (item.progress) { // if (this.downLoadingNumber >= 90) { // this.downLoadingNumber = 99 // } else { // this.downLoadingNumber += 1 // } domList.find(i => i.className === item.path).innerHTML = '' // this.downLoadingNumber + '%' } if (item.progress === null) { // 此处容错处理,如果后端传输文件流报错,删除当前进度对象 this.$store.commit('downLoadProgress/DEL_PROGRESS', item.path) this.$notify.error({ title: '错误', message: '文件下载失败!' }) } } else { if (!this.downLoading) { // 如果页面中没有该进度对象所对应的弹框,页面新建弹框,并在notify中加入该弹框对象,属性名为该进度对象的path(上文可知path是唯一的),属性值为$notify(element ui中的通知组件)弹框对象 this.notify[item.path] = this.$notify.success({ // title: 'info', dangerouslyUseHTMLString: true, customClass: 'progress-notify', message: `