elementUI vue this.$confirm 和el-dialog 彈出框 移動

来源:https://www.cnblogs.com/yysbolg/archive/2019/07/03/11124336.html
-Advertisement-
Play Games

elementUI vue this.$confirm 和el-dialog 彈出框 移動 ...


調試了好久, 還能湊合用, 請直接看DOME 示例,複製就能用: 

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style media="screen" type="text/css">
        #appLoading {
            width: 100%;
            height: 100%;
        }

        #appLoading span {
            position: absolute;
            display: block;
            font-size: 50px;
            line-height: 50px;
            top: 50%;
            left: 50%;
            width: 200px;
            height: 100px;
            -webkit-transform: translateY(-50%) translateX(-50%);
            transform: translateY(-50%) translateX(-50%);
        }
    </style>
</head>
<body>
<div id="appLoading">
    <span>Loading...</span>
</div>
<div id="app" style="display: none">
    <el-dialog title="提示" width="50%" :visible.sync="startUsingDialog" v-dialog_drag>
        <span> 您是否確定啟用次記錄?</span>
        <span slot="footer" class="dialog-footer">
            <el-button @click="startUsingSubmit()" type="danger" :loading="startUsingLoading">啟用</el-button>
            <el-button @click="startUsingDiglog=false">取消</el-button>
        </span>
    </el-dialog>


</div>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<!-- import jquery -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script>


    $(function () {
        $("body").on("mousedown", '.el-message-box__header', (e) => {
            const dialogHeaderEl = document.querySelector('.el-message-box__header')
            const dragDom = document.querySelector('.el-message-box')
            dialogHeaderEl.style.cursor = 'move'
            // 獲取原有屬性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
            const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)
            // 滑鼠按下,計算當前元素距離可視區的距離
            const disX = e.clientX - dialogHeaderEl.offsetLeft
            const disY = e.clientY - dialogHeaderEl.offsetTop
            // 獲取到的值帶px 正則匹配替換
            let styL, styT
            // 註意在ie中 第一次獲取到的值為組件自帶50% 移動之後賦值為px
            if (sty.left.includes('%')) {
                styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
                styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
            } else {
                let lefts = sty.left
                let tops = sty.top
                if (sty.left == 'auto') {
                    lefts = '0px'
                }
                if (sty.top == 'auto') {
                    tops = '0px'
                }
                styL = +lefts.replace(/\px/g, '')
                styT = +tops.replace(/\px/g, '')
            }

            document.onmousemove = function (e) {
                // 通過事件委托,計算移動的距離
                const l = e.clientX - disX
                const t = e.clientY - disY

                // 移動當前元素
                dragDom.style.left = `${l + styL}px`
                dragDom.style.top = `${t + styT}px`
                dragDom.style.position = `absolute`

                // 將此時的位置傳出去
                // binding.value({x:e.pageX,y:e.pageY})
            }

            document.onmouseup = function (e) {
                document.onmousemove = null
                document.onmouseup = null
            }

        })
    })

    Vue.directive('dialog_drag', {
        bind(el, binding, vnode, oldVnode) {
            const dialogHeaderEl = el.querySelector('.el-dialog__header')
            const dragDom = el.querySelector('.el-dialog')
            dialogHeaderEl.style.cursor = 'move'

            // 獲取原有屬性 ie dom元素.currentStyle 火狐谷歌 window.getComputedStyle(dom元素, null);
            const sty = dragDom.currentStyle || window.getComputedStyle(dragDom, null)

            dialogHeaderEl.onmousedown = (e) => {
                console.log(1);
                // 滑鼠按下,計算當前元素距離可視區的距離
                const disX = e.clientX - dialogHeaderEl.offsetLeft
                const disY = e.clientY - dialogHeaderEl.offsetTop

                // 獲取到的值帶px 正則匹配替換
                let styL, styT
                // 註意在ie中 第一次獲取到的值為組件自帶50% 移動之後賦值為px
                if (sty.left.includes('%')) {
                    styL = +document.body.clientWidth * (+sty.left.replace(/\%/g, '') / 100)
                    styT = +document.body.clientHeight * (+sty.top.replace(/\%/g, '') / 100)
                } else {
                    let lefts = sty.left
                    let tops = sty.top
                    if (sty.left == 'auto') {
                        lefts = '0px'
                    }
                    if (sty.top == 'auto') {
                        tops = '0px'
                    }
                    styL = +lefts.replace(/\px/g, '')
                    styT = +tops.replace(/\px/g, '')
                }

                document.onmousemove = function (e) {
                    // 通過事件委托,計算移動的距離
                    const l = e.clientX - disX
                    const t = e.clientY - disY

                    // 移動當前元素
                    dragDom.style.left = `${l + styL}px`
                    dragDom.style.top = `${t + styT}px`

                    // 將此時的位置傳出去
                    // binding.value({x:e.pageX,y:e.pageY})
                }

                document.onmouseup = function (e) {
                    document.onmousemove = null
                    document.onmouseup = null
                }
            }
        }
    })

    new Vue({
        el: '#app',
        data: function () {
            return {
                startUsingDialog: true,
                startUsingLoading: false,
            }
        },

        //頁面載入成功時完成
        mounted() {
            document.getElementById('app').style.display = 'block';
            document.getElementById('appLoading').style.display = 'none';
        },
        //方法
        methods: {
            startUsingSubmit() {
                this.startUsingLoading=true
                this.$confirm("提示", "你好!", {
                    confirmButtonText: '確定',
                    cancelButtonText: '取消'
                }).then(()=>{
                    this.startUsingLoading=false
                })
                this.$message({
                    showClose: true,
                    message: '這是一條消息提示',
                    duration: 0  //表示顯示幾秒, 0 表示不消失
                });
            }
        },
    })
</script>
</body>
</html>

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 由於業務需要在Mysql實例中創建部分庫的從庫,已有的Mysql實例的版本是mysql-5.5.49,是一個非常老的版本。 本文檔涉及到伺服器中運行多實例和構建實例中部分庫的從庫。 1、伺服器2上創建3307實例 首先需要準備源碼編譯包,這個就不在描述了。由於我伺服器2上已經存在了一個同樣版本的實例 ...
  • --查詢所有員工的員工號、姓名和職位的信息。DECLARE --定義游標 CURSOR emp_cursor IS SELECT empno,ename,job FROM emp; v_empno emp.empno%TYPE; v_ename emp.ename%TYPE; v_job emp.j ...
  • Sql語句分為三大類: 數據定義語言,負責創建,修改,刪除表,索引和視圖等對象; 數據操作語言,負責資料庫中數據的插入,查詢,刪除等操作; 數據控制語言,用來授予和撤銷用戶許可權。 數據定義語言 (Data Definition Language, DDL) 是SQL語言集中負責數據結構定義與資料庫對 ...
  • 跨伺服器備份: 伺服器A:192.168.5.193 測試資料庫TestDB 伺服器B:192.168.5.194 目標:將伺服器A上的測試資料庫定時備份到伺服器B中 需要技術: mysqldump + crontab 步驟: 1. 修改mysql遠程連接訪問許可權 修改mysql的配置文件/mysq ...
  • Hi3109,Hi3110E,Hi3130,Hi3560,Hi3560Q,Hi3560E,Hi3570,Hi3716H,Hi3716C,Hi3716CV200,Hi3712V100,Hi3716MV400,Hi3716MV300,Hi3718MV100,Hi3718CV100,Hi3719MV100 ...
  • 上代碼 ...
  • 一、熱升級Tinker源碼解析與手寫二、熱修複阿裡百川Sophix內核原理三、App Instantgoogle8.0 類似熱更新技術原理與實戰四、強制更新1.銀行應用非對稱加密對稱加密五、組件化框架設計1.組件化之集中式路由--阿裡巴巴ARouter原理(無Intent式)2.手寫ARouter ...
  • 版權聲明:本文為xing_star原創文章,轉載請註明出處! 本文同步自http://javaexception.com/archives/165 客戶端開屏廣告適配的一點經驗 昨天晚上,群里有個小伙伴在問,開屏頁廣告如何適配的問題,ui問應該給切幾種尺寸的圖?這塊算是有點心得,所以特意回答了下。 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...