+
liuyg
2021-12-15 85e635307c8802e2d9f741906cb8b3ee88ad5cfb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<template>
    <div class="public-org-nav-bar"
         ref="publicOrgNavBar">
        <div class="container">
            <div class="header"
                 @mousedown="move"
                 :class="{'move': moveFlag}">
                <div class="title">
                    <img class="icon"
                         src="/img/icon/jg.png"
                         alt="">
                    <span>
                        {{title}}
                    </span>
                </div>
                <img class="close"
                     src="/img/navicon/close.png"
                     alt=""
                     @click="closeModel">
            </div>
            <div class="content">
                <ul>
                    <li v-for="(item, index) in navList"
                        :key="index">
                        <img :src="item.icon"
                             alt="">
                        <span>
                            {{item.navTitle}}
                        </span>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</template>
 
<script>
export default {
    name: 'OrgNavBar',
    data () {
        return {
            moveFlag: false
        }
    },
    props: {
        navList: {
            type: Array
        },
        title: {
            type: String
        }
    },
    methods: {
        move (e) {
            const that = this
            const odiv = this.$refs.publicOrgNavBar // 获取目标元素
            // 算出鼠标相对元素的位置
            const disX = e.clientX - odiv.offsetLeft
            const disY = e.clientY - odiv.offsetTop
 
            const disH = odiv.offsetHeight
            const disW = odiv.offsetWidth
 
            document.onmousemove = (e) => {
                that.moveFlag = true
                // 鼠标按下并移动的事件
                // 用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
                let left = e.clientX - disX
                let top = e.clientY - disY
 
                // 绑定元素位置到positionX和positionY上面
 
                if (left >= window.innerWidth - disW) {
                    left = window.innerWidth - disW
                }
 
                if (left <= 0) {
                    left = 0
                }
 
                if (top >= window.innerHeight - disH) {
                    top = window.innerHeight - disH
                }
 
                if (top <= 60) {
                    top = 60
                }
 
                // 移动当前元素
                odiv.style.left = (left) + 'px'
                odiv.style.top = (top) + 'px'
                odiv.style.bottom = 'auto'
            }
            document.onmouseup = (e) => {
                that.moveFlag = false
                document.onmousemove = null
                document.onmouseup = null
            }
        },
        closeModel () {
            this.$parent.closeModel()
        }
    }
}
</script>
 
<style scoped lang='scss'>
.public-org-nav-bar {
    position: fixed;
    width: 322px;
    height: auto;
    border-radius: 8px;
    top: 24%;
    left: 20%;
    background-color: #fff;
    z-index: 999;
    font-size: 14px;
    .container {
        .header {
            position: relative;
            border-radius: 8px 8px 0 0;
            width: 100%;
            height: 36px;
            line-height: 36px;
            background-color: #2196f3;
            .title {
                padding-left: 10px;
                img {
                    width: 18px;
                    height: 18px;
                    vertical-align: middle;
                }
                span {
                    margin-left: 6px;
                    display: inline-block;
                    vertical-align: middle;
                    color: #fff;
                }
            }
            .close {
                position: absolute;
                right: 6px;
                top: 0;
                left: auto;
                bottom: 0;
                margin: auto;
                width: 14px;
                height: 14px;
            }
        }
        .move {
            cursor: move;
        }
        .content {
            clear: both;
            width: 100%;
            height: 440px;
            margin-top: 0px;
            text-align: center;
            overflow-y: auto;
            background: url(/img/bg/nav-bg.jpeg) no-repeat;
            background-size: 100% 100%;
            ul {
                padding: 15px;
                padding-top: 4px;
                li {
                    padding-left: 24px;
                    position: relative;
                    height: 40px;
                    line-height: 40px;
                    list-style: none;
                    border-bottom: 1px dashed #ccc;
                    text-align: left;
                    img {
                        position: absolute;
                        left: 0;
                        right: auto;
                        top: 0;
                        bottom: 0;
                        margin: auto;
                        width: 14px;
                    }
                    span {
                        color: #fff;
                        cursor: pointer;
                    }
                    span:hover {
                        text-decoration: underline;
                    }
                }
            }
        }
    }
}
</style>