feat:自定义动画加载指令的完成
Showing
8 changed files
with
160 additions
and
22 deletions
| 1 | import directive from './src/directive'; | ||
| 1 | import service from './src/index'; | 2 | import service from './src/index'; |
| 2 | 3 | ||
| 3 | export default { | 4 | export default { |
| 4 | install (Vue) { | 5 | install (Vue) { |
| 6 | Vue.use(directive); | ||
| 5 | Vue.prototype.$loading = service; | 7 | Vue.prototype.$loading = service; |
| 6 | }, | 8 | }, |
| 9 | directive, | ||
| 7 | service | 10 | service |
| 8 | }; | 11 | }; | ... | ... |
src/components/Loading/src/directive.js
0 → 100644
| 1 | import Vue from 'vue'; | ||
| 2 | import Loading from './loading.vue'; | ||
| 3 | import { addClass, removeClass, getStyle } from 'element-ui/src/utils/dom'; | ||
| 4 | import { PopupManager } from 'element-ui/src/utils/popup'; | ||
| 5 | import afterLeave from 'element-ui/src/utils/after-leave'; | ||
| 6 | const Mask = Vue.extend(Loading); | ||
| 7 | |||
| 8 | const loadingDirective = {}; | ||
| 9 | loadingDirective.install = Vue => { | ||
| 10 | if (Vue.prototype.$isServer) return; | ||
| 11 | const toggleLoading = (el, binding) => { | ||
| 12 | if (binding.value) { | ||
| 13 | Vue.nextTick(() => { | ||
| 14 | if (binding.modifiers.fullscreen) { | ||
| 15 | el.originalPosition = getStyle(document.body, 'position'); | ||
| 16 | el.originalOverflow = getStyle(document.body, 'overflow'); | ||
| 17 | el.maskStyle.zIndex = PopupManager.nextZIndex(); | ||
| 18 | |||
| 19 | addClass(el.mask, 'is-fullscreen'); | ||
| 20 | insertDom(document.body, el, binding); | ||
| 21 | } else { | ||
| 22 | removeClass(el.mask, 'is-fullscreen'); | ||
| 23 | |||
| 24 | if (binding.modifiers.body) { | ||
| 25 | el.originalPosition = getStyle(document.body, 'position'); | ||
| 26 | |||
| 27 | ['top', 'left'].forEach(property => { | ||
| 28 | const scroll = property === 'top' ? 'scrollTop' : 'scrollLeft'; | ||
| 29 | el.maskStyle[property] = el.getBoundingClientRect()[property] + | ||
| 30 | document.body[scroll] + | ||
| 31 | document.documentElement[scroll] - | ||
| 32 | parseInt(getStyle(document.body, `margin-${property}`), 10) + | ||
| 33 | 'px'; | ||
| 34 | }); | ||
| 35 | ['height', 'width'].forEach(property => { | ||
| 36 | el.maskStyle[property] = el.getBoundingClientRect()[property] + 'px'; | ||
| 37 | }); | ||
| 38 | |||
| 39 | insertDom(document.body, el, binding); | ||
| 40 | } else { | ||
| 41 | el.originalPosition = getStyle(el, 'position'); | ||
| 42 | insertDom(el, el, binding); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | }); | ||
| 46 | } else { | ||
| 47 | afterLeave(el.instance, _ => { | ||
| 48 | if (!el.instance.hiding) return; | ||
| 49 | el.domVisible = false; | ||
| 50 | const target = binding.modifiers.fullscreen || binding.modifiers.body | ||
| 51 | ? document.body | ||
| 52 | : el; | ||
| 53 | removeClass(target, 'el-loading-parent--relative'); | ||
| 54 | removeClass(target, 'el-loading-parent--hidden'); | ||
| 55 | el.instance.hiding = false; | ||
| 56 | }, 300, true); | ||
| 57 | el.instance.visible = false; | ||
| 58 | el.instance.hiding = true; | ||
| 59 | } | ||
| 60 | }; | ||
| 61 | const insertDom = (parent, el, binding) => { | ||
| 62 | if (!el.domVisible && getStyle(el, 'display') !== 'none' && getStyle(el, 'visibility') !== 'hidden') { | ||
| 63 | Object.keys(el.maskStyle).forEach(property => { | ||
| 64 | el.mask.style[property] = el.maskStyle[property]; | ||
| 65 | }); | ||
| 66 | |||
| 67 | if (el.originalPosition !== 'absolute' && el.originalPosition !== 'fixed' && el.originalPosition !== 'sticky') { | ||
| 68 | addClass(parent, 'el-loading-parent--relative'); | ||
| 69 | } | ||
| 70 | if (binding.modifiers.fullscreen && binding.modifiers.lock) { | ||
| 71 | addClass(parent, 'el-loading-parent--hidden'); | ||
| 72 | } | ||
| 73 | el.domVisible = true; | ||
| 74 | |||
| 75 | parent.appendChild(el.mask); | ||
| 76 | Vue.nextTick(() => { | ||
| 77 | if (el.instance.hiding) { | ||
| 78 | el.instance.$emit('after-leave'); | ||
| 79 | } else { | ||
| 80 | el.instance.visible = true; | ||
| 81 | } | ||
| 82 | }); | ||
| 83 | el.domInserted = true; | ||
| 84 | } else if (el.domVisible && el.instance.hiding === true) { | ||
| 85 | el.instance.visible = true; | ||
| 86 | el.instance.hiding = false; | ||
| 87 | } | ||
| 88 | }; | ||
| 89 | |||
| 90 | Vue.directive('Loading', { | ||
| 91 | bind: function (el, binding, vnode) { | ||
| 92 | const textExr = el.getAttribute('element-loading-text'); | ||
| 93 | const spinnerExr = el.getAttribute('element-loading-spinner'); | ||
| 94 | const backgroundExr = el.getAttribute('element-loading-background'); | ||
| 95 | const customClassExr = el.getAttribute('element-loading-custom-class'); | ||
| 96 | const vm = vnode.context; | ||
| 97 | const mask = new Mask({ | ||
| 98 | el: document.createElement('div'), | ||
| 99 | data: { | ||
| 100 | text: vm && vm[textExr] || textExr, | ||
| 101 | spinner: vm && vm[spinnerExr] || spinnerExr, | ||
| 102 | background: vm && vm[backgroundExr] || backgroundExr, | ||
| 103 | customClass: vm && vm[customClassExr] || customClassExr, | ||
| 104 | fullscreen: !!binding.modifiers.fullscreen | ||
| 105 | } | ||
| 106 | }); | ||
| 107 | el.instance = mask; | ||
| 108 | el.mask = mask.$el; | ||
| 109 | el.maskStyle = {}; | ||
| 110 | |||
| 111 | binding.value && toggleLoading(el, binding); | ||
| 112 | }, | ||
| 113 | |||
| 114 | update: function (el, binding) { | ||
| 115 | el.instance.setText(el.getAttribute('element-loading-text')); | ||
| 116 | if (binding.oldValue !== binding.value) { | ||
| 117 | toggleLoading(el, binding); | ||
| 118 | } | ||
| 119 | }, | ||
| 120 | |||
| 121 | unbind: function (el, binding) { | ||
| 122 | if (el.domInserted) { | ||
| 123 | el.mask && | ||
| 124 | el.mask.parentNode && | ||
| 125 | el.mask.parentNode.removeChild(el.mask); | ||
| 126 | toggleLoading(el, { value: false, modifiers: binding.modifiers }); | ||
| 127 | } | ||
| 128 | el.instance && el.instance.$destroy(); | ||
| 129 | } | ||
| 130 | }); | ||
| 131 | }; | ||
| 132 | |||
| 133 | export default loadingDirective; |
| 1 | import directive from './src/directive'; | ||
| 1 | import service from './src/index'; | 2 | import service from './src/index'; |
| 2 | 3 | ||
| 3 | export default { | 4 | export default { |
| 4 | install (Vue) { | 5 | install (Vue) { |
| 6 | Vue.use(directive); | ||
| 5 | Vue.prototype.$loading = service; | 7 | Vue.prototype.$loading = service; |
| 6 | }, | 8 | }, |
| 9 | directive, | ||
| 7 | service | 10 | service |
| 8 | }; | 11 | }; | ... | ... |
| ... | @@ -6,9 +6,10 @@ import '@/styles/element-variables.scss' | ... | @@ -6,9 +6,10 @@ import '@/styles/element-variables.scss' |
| 6 | import '@/styles/index.scss' | 6 | import '@/styles/index.scss' |
| 7 | import Base from '@/components/Base/base' // 全局组件引入 | 7 | import Base from '@/components/Base/base' // 全局组件引入 |
| 8 | import mixin from '@/utils/mixin/theme.js' | 8 | import mixin from '@/utils/mixin/theme.js' |
| 9 | import Loading from '@/components/Loading/index.js'; | ||
| 9 | import { startLoadingAddCount, endLoadingSubCount } from './utils/requestLoading' | 10 | import { startLoadingAddCount, endLoadingSubCount } from './utils/requestLoading' |
| 10 | Vue.mixin(mixin); | 11 | Vue.mixin(mixin); |
| 11 | 12 | Vue.use(Loading.directive); | |
| 12 | import rules from './utils/rule.js' | 13 | import rules from './utils/rule.js' |
| 13 | // 全局方法挂载 | 14 | // 全局方法挂载 |
| 14 | Vue.prototype.$rules = rules | 15 | Vue.prototype.$rules = rules | ... | ... |
| 1 | <template> | 1 | <template> |
| 2 | <div class="from-clues" v-loading="loading" element-loading-text="拼命加载中" element-loading-spinner="el-icon-loading" | 2 | <div class="from-clues loadingtext" v-Loading="loading" style="height:720px"> |
| 3 | element-loading-background="rgba(0, 0, 0, 0.8)" style="height:720px"> | ||
| 4 | <!-- 表单部分 --> | 3 | <!-- 表单部分 --> |
| 5 | <el-tabs v-model="activeName" @tab-click="handleClick" v-if="headTabBdcqz.length > 1"> | 4 | <el-tabs v-model="activeName" @tab-click="handleClick" v-if="headTabBdcqz.length > 1"> |
| 6 | <el-tab-pane :label="item.qlr + '(' + item.bdcqzh + ')'" :name="item.bsmBdcqz" | 5 | <el-tab-pane :label="item.qlr + '(' + item.bdcqzh + ')'" :name="item.bsmBdcqz" |
| ... | @@ -76,7 +75,7 @@ export default { | ... | @@ -76,7 +75,7 @@ export default { |
| 76 | this.bdcqz = res.result[0] | 75 | this.bdcqz = res.result[0] |
| 77 | this.headTabBdcqz = res.result | 76 | this.headTabBdcqz = res.result |
| 78 | this.getBdcqzPreview(); | 77 | this.getBdcqzPreview(); |
| 79 | }else{ | 78 | } else { |
| 80 | this.loading = false | 79 | this.loading = false |
| 81 | } | 80 | } |
| 82 | } | 81 | } | ... | ... |
| ... | @@ -140,23 +140,23 @@ export default { | ... | @@ -140,23 +140,23 @@ export default { |
| 140 | break; | 140 | break; |
| 141 | case "B6": | 141 | case "B6": |
| 142 | //根据编号获取对应信息 | 142 | //根据编号获取对应信息 |
| 143 | getPrintTemplateByCode({tmpno: 'dysqs'}).then(res => { | 143 | getPrintTemplateByCode({ tmpno: 'dysqs' }).then(res => { |
| 144 | if(res.code == 200){ | 144 | if (res.code == 200) { |
| 145 | getPrintApplicationInfo(this.currentSelectProps).then(infoRes => { | 145 | getPrintApplicationInfo(this.currentSelectProps).then(infoRes => { |
| 146 | if(infoRes.code == 200){ | 146 | if (infoRes.code == 200) { |
| 147 | //打开模板设计 | 147 | //打开模板设计 |
| 148 | let LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM')); | 148 | let LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')); |
| 149 | LODOP.ADD_PRINT_DATA("ProgramData",res.result.tmpcontent); //装载模板 | 149 | LODOP.ADD_PRINT_DATA("ProgramData", res.result.tmpcontent); //装载模板 |
| 150 | //todo 调取后端接口获取数据 循环set | 150 | //todo 调取后端接口获取数据 循环set |
| 151 | for(let key in infoRes.result){ | 151 | for (let key in infoRes.result) { |
| 152 | LODOP.SET_PRINT_STYLEA(key,"CONTENT",infoRes.result[key]); | 152 | LODOP.SET_PRINT_STYLEA(key, "CONTENT", infoRes.result[key]); |
| 153 | } | 153 | } |
| 154 | LODOP.PREVIEW(); | 154 | LODOP.PREVIEW(); |
| 155 | }else{ | 155 | } else { |
| 156 | this.$message.error(infoRes.message) | 156 | this.$message.error(infoRes.message) |
| 157 | } | 157 | } |
| 158 | }) | 158 | }) |
| 159 | }else{ | 159 | } else { |
| 160 | this.$message.error(res.message) | 160 | this.$message.error(res.message) |
| 161 | } | 161 | } |
| 162 | }) | 162 | }) |
| ... | @@ -279,7 +279,6 @@ export default { | ... | @@ -279,7 +279,6 @@ export default { |
| 279 | message: "此环节为流程最后环节,转出后流程将结束", | 279 | message: "此环节为流程最后环节,转出后流程将结束", |
| 280 | showCancelButton: true, | 280 | showCancelButton: true, |
| 281 | beforeClose: (action, instance, done) => { | 281 | beforeClose: (action, instance, done) => { |
| 282 | console.log(action, 'actionaction'); | ||
| 283 | if (action === "confirm") { | 282 | if (action === "confirm") { |
| 284 | instance.confirmButtonLoading = true; | 283 | instance.confirmButtonLoading = true; |
| 285 | instance.confirmButtonText = "执行中..."; | 284 | instance.confirmButtonText = "执行中..."; |
| ... | @@ -334,9 +333,9 @@ export default { | ... | @@ -334,9 +333,9 @@ export default { |
| 334 | formdata.append("bsmSldy", this.currentSelectProps.bsmSldy); | 333 | formdata.append("bsmSldy", this.currentSelectProps.bsmSldy); |
| 335 | formdata.append("bsmSlsq", this.bsmSlsq); | 334 | formdata.append("bsmSlsq", this.bsmSlsq); |
| 336 | uploadUndo(formdata).then(res => { | 335 | uploadUndo(formdata).then(res => { |
| 337 | if(res.code == 200){ | 336 | if (res.code == 200) { |
| 338 | this.$message.success("导入成功"); | 337 | this.$message.success("导入成功"); |
| 339 | }else{ | 338 | } else { |
| 340 | this.$message.error(res.message) | 339 | this.$message.error(res.message) |
| 341 | } | 340 | } |
| 342 | }) | 341 | }) | ... | ... |
| ... | @@ -76,7 +76,7 @@ | ... | @@ -76,7 +76,7 @@ |
| 76 | :on-change="handleChange" :before-upload="beforeUpload"> | 76 | :on-change="handleChange" :before-upload="beforeUpload"> |
| 77 | <el-button id="cldr" icon="el-icon-upload" type="primary" v-show="false">上传</el-button> | 77 | <el-button id="cldr" icon="el-icon-upload" type="primary" v-show="false">上传</el-button> |
| 78 | </el-upload> | 78 | </el-upload> |
| 79 | <fqsqDialog v-model="isDialog" :djywbm="$route.query.sqywbm" :isJump="true" @updateDialog="updateDialog" /> | 79 | <selectBdc v-model="isDialog" :djywbm="$route.query.sqywbm" :isJump="true" @updateDialog="updateDialog" /> |
| 80 | </div> | 80 | </div> |
| 81 | </template> | 81 | </template> |
| 82 | <style scoped lang='scss'> | 82 | <style scoped lang='scss'> |
| ... | @@ -91,10 +91,10 @@ import { getForm } from './flowform' | ... | @@ -91,10 +91,10 @@ import { getForm } from './flowform' |
| 91 | import NoticeBar from '@/components/NoticeBar/index' | 91 | import NoticeBar from '@/components/NoticeBar/index' |
| 92 | import { deleteFlow, unClaimTask } from "@/api/ywbl.js"; | 92 | import { deleteFlow, unClaimTask } from "@/api/ywbl.js"; |
| 93 | import ProcessViewer from './components/processViewer.vue' | 93 | import ProcessViewer from './components/processViewer.vue' |
| 94 | import fqsqDialog from "@/views/ywbl/ywsq/selectBdc.vue"; | 94 | import selectBdc from "@/views/ywbl/ywsq/selectBdc.vue"; |
| 95 | export default { | 95 | export default { |
| 96 | components: { | 96 | components: { |
| 97 | fqsqDialog, | 97 | selectBdc, |
| 98 | NoticeBar, | 98 | NoticeBar, |
| 99 | ProcessViewer | 99 | ProcessViewer |
| 100 | }, | 100 | }, | ... | ... |
| 1 | <template> | 1 | <template> |
| 2 | <dialogBox :title="title" width="85%" @closeDialog="closeDialog" v-model="value" :isButton="false"> | 2 | <dialogBox :title="title" width="85%" @closeDialog="closeDialog" v-model="value" isMain :isButton="false"> |
| 3 | <component :is="router" :sqywInfo="sqywInfo" @closeDialog="closeDialog" @updateDialog="updateDialog" /> | 3 | <component :is="router" :sqywInfo="sqywInfo" @closeDialog="closeDialog" @updateDialog="updateDialog" /> |
| 4 | </dialogBox> | 4 | </dialogBox> |
| 5 | </template> | 5 | </template> |
| ... | @@ -19,8 +19,8 @@ export default { | ... | @@ -19,8 +19,8 @@ export default { |
| 19 | watch: { | 19 | watch: { |
| 20 | value (val) { | 20 | value (val) { |
| 21 | if (val) { | 21 | if (val) { |
| 22 | this.title = "申请业务:" + this.sqywInfo.djywmc; | 22 | this.title = "申请业务:" + this.sqywInfo?.djywmc ? this.sqywInfo?.djywmc : ''; |
| 23 | let view = queueDjywmc(this.sqywInfo.djywbm); | 23 | let view = queueDjywmc(this.sqywInfo?.djywbm); |
| 24 | this.router = this.loadView(view); | 24 | this.router = this.loadView(view); |
| 25 | } | 25 | } |
| 26 | }, | 26 | }, | ... | ... |
-
Please register or sign in to post a comment