gpc-ui 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gpc-ui",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "二小UI",
5
5
  "private": false,
6
6
  "main": "lib/gpc-ui.umd.min.js",
@@ -29,6 +29,8 @@
29
29
  "babel-eslint": "^10.1.0",
30
30
  "eslint": "^6.7.2",
31
31
  "eslint-plugin-vue": "^6.2.2",
32
+ "sass": "^1.108.1",
33
+ "sass-loader": "^10.5.2",
32
34
  "vue-template-compiler": "^2.6.11"
33
35
  },
34
36
  "eslintConfig": {
@@ -0,0 +1,232 @@
1
+ <!--
2
+ * @Author: 刘小二
3
+ * @Date: 2026-11-09 10:12:02
4
+ * @LastEditors: 刘小二
5
+ * @LastEditTime: 2026-11-09 10:12:06
6
+ * @Description: 悬浮按钮(拖拽优化·最终版)
7
+ * @FilePath: /gpc_ui/src/components/gpc-button/float-button.vue
8
+ -->
9
+ <template>
10
+ <div
11
+ class="float-button-area"
12
+ :style="{
13
+ bottom: bottom + 'px',
14
+ right: right + 'px'
15
+ }"
16
+ @mousedown="down"
17
+ @click="onClick"
18
+ >
19
+ <div
20
+ v-if="isTransition"
21
+ class="text-trans"
22
+ :class="{
23
+ 'show-text': showText,
24
+ circle: isTransition
25
+ }"
26
+ @mouseenter.stop="enter"
27
+ @mouseleave.stop="leave"
28
+ >
29
+ <i class="el-icon-document" />
30
+ <span v-show="showText" class="m-l-5">{{ text }}</span>
31
+ </div>
32
+
33
+ <div v-else class="text">
34
+ <i class="el-icon-document" />
35
+ <span class="m-l-5" style="margin-left: 5px;">{{ text }}</span>
36
+ </div>
37
+ </div>
38
+ </template>
39
+
40
+ <script>
41
+ export default {
42
+ name: 'FloatButton',
43
+
44
+ props: {
45
+ text: {
46
+ type: String,
47
+ default: ''
48
+ },
49
+ isTransition: {
50
+ type: Boolean,
51
+ default: false
52
+ },
53
+ isDrag: {
54
+ type: Boolean,
55
+ default: false
56
+ },
57
+ offsetX: {
58
+ type: Number,
59
+ default: 20
60
+ },
61
+ offsetY: {
62
+ type: Number,
63
+ default: 20
64
+ },
65
+ defaultRight: {
66
+ type: Number,
67
+ default: 40
68
+ },
69
+ defaultBottom: {
70
+ type: Number,
71
+ default: 100
72
+ }
73
+ },
74
+
75
+ data() {
76
+ return {
77
+ showText: false,
78
+ bottom: 0,
79
+ right: 0,
80
+ isDown: false,
81
+ clickStart: 0,
82
+ el: null,
83
+ width: 0,
84
+ height: 0,
85
+ maxBottom: 0,
86
+ maxRight: 0,
87
+ isDragMoved: false
88
+ }
89
+ },
90
+
91
+ watch: {
92
+ defaultBottom: {
93
+ immediate: true,
94
+ handler(val) {
95
+ this.bottom = val
96
+ }
97
+ },
98
+ defaultRight: {
99
+ immediate: true,
100
+ handler(val) {
101
+ this.right = val
102
+ }
103
+ }
104
+ },
105
+
106
+ mounted() {},
107
+
108
+ beforeDestroy() {
109
+ this.removeDragEvents()
110
+ },
111
+
112
+ methods: {
113
+ enter() {
114
+ this.showText = true
115
+ },
116
+ leave() {
117
+ this.showText = false
118
+ },
119
+
120
+ initEl() {
121
+ if (!this.el) {
122
+ this.el = this.$el
123
+ }
124
+
125
+ this.width = this.el.offsetWidth
126
+ this.height = this.el.offsetHeight
127
+
128
+ this.maxBottom = window.innerHeight - this.height - this.offsetY
129
+ this.maxRight = window.innerWidth - this.width - this.offsetX
130
+ },
131
+
132
+ /** 鼠标按下 */
133
+ down(e) {
134
+ if (!this.isDrag) return
135
+
136
+ this.clickStart = Date.now()
137
+ this.isDown = true
138
+ this.isDragMoved = false
139
+
140
+ this.initEl()
141
+
142
+ document.addEventListener('mousemove', this.move)
143
+ document.addEventListener('mouseup', this.up)
144
+
145
+ e.preventDefault()
146
+ },
147
+
148
+ /** 拖拽中 */
149
+ move(e) {
150
+ if (!this.isDown) return
151
+
152
+ this.isDragMoved = true
153
+
154
+ const { clientX, clientY } = e
155
+
156
+ let bottom = window.innerHeight - clientY - this.height / 2
157
+ let right = window.innerWidth - clientX - this.width / 2
158
+
159
+ this.bottom = Math.min(Math.max(0, bottom), this.maxBottom)
160
+ this.right = Math.min(Math.max(0, right), this.maxRight)
161
+ },
162
+
163
+ /** 鼠标抬起 */
164
+ up() {
165
+ // ✅ 关键:拖拽结束后,如果移动过,直接废掉 clickStart
166
+ if (this.isDragMoved) {
167
+ this.clickStart = 0
168
+ }
169
+
170
+ this.removeDragEvents()
171
+ },
172
+
173
+ /** 移除拖拽事件 */
174
+ removeDragEvents() {
175
+ this.isDown = false
176
+ document.removeEventListener('mousemove', this.move)
177
+ document.removeEventListener('mouseup', this.up)
178
+ },
179
+
180
+ /** 点击事件 */
181
+ onClick() {
182
+ // ✅ 如果没有 clickStart,说明被拖拽废掉了
183
+ if (!this.clickStart) {
184
+ this.isDragMoved = false
185
+ return
186
+ }
187
+
188
+ const clickTime = Date.now() - this.clickStart
189
+
190
+ // ✅ 只有:短按 + 没移动 = 才触发
191
+ if (clickTime < 200 && !this.isDragMoved) {
192
+ this.$emit('goScan')
193
+ }
194
+
195
+ // ✅ 重置所有状态
196
+ this.clickStart = 0
197
+ this.isDragMoved = false
198
+ }
199
+ }
200
+ }
201
+ </script>
202
+
203
+ <style lang="scss" scoped>
204
+ .float-button-area {
205
+ position: fixed;
206
+ z-index: 20;
207
+ color: #fff;
208
+ background: linear-gradient(to bottom, #00b85c, #018a46);
209
+ border-radius: 20px;
210
+ padding: 6px;
211
+ cursor: pointer;
212
+ will-change: bottom, right;
213
+ transform: translateZ(0);
214
+
215
+ &.circle {
216
+ padding: 0;
217
+ border-radius: 50%;
218
+ }
219
+
220
+ .text,
221
+ .text-trans {
222
+ display: flex;
223
+ align-items: center;
224
+ justify-content: center;
225
+ font-size: 14px;
226
+ }
227
+
228
+ i {
229
+ font-size: 16px;
230
+ }
231
+ }
232
+ </style>
@@ -1,9 +1,11 @@
1
- import gpcLogin from "./gpc-login/index.vue"
2
- import gpcTabs from "./gpc-tabs/Tabs.vue"
1
+ import gpcFloatBtn from "./gpc-button/float-button.vue";
2
+ import gpcLogin from "./gpc-login/index.vue";
3
+ import gpcTabs from "./gpc-tabs/Tabs.vue";
3
4
 
4
5
  const components = {
5
6
  gpcLogin,
6
- gpcTabs
7
+ gpcTabs,
8
+ gpcFloatBtn
7
9
  };
8
10
 
9
11
  function install(Vue) {