Przeglądaj źródła

语音、视频社区增加跳转去提问

jwyu 2 lat temu
rodzic
commit
6911f93739

+ 141 - 0
components/dragButton/dragButton.vue

@@ -0,0 +1,141 @@
+<template>
+	<view>
+		<view
+			id="_drag_button"
+			class="drag"
+			:style="'left: ' + left + 'px; top:' + top + 'px;'"
+			@touchstart="touchstart"
+			@touchmove.stop.prevent="touchmove"
+			@touchend="touchend"
+			@click.stop.prevent="click"
+			:class="{transition: isDock && !isMove }"
+		>
+			<slot></slot>
+		</view>
+	</view>
+</template>
+
+<script>
+	export default {
+		name: 'drag-button',
+		props: {
+			isDock:{
+				type: Boolean,
+				default: true
+			},
+			existTabBar:{
+				type: Boolean,
+				default: false
+			}
+		},
+		data() {
+			return {
+				top:1000,
+				left:1000,
+				width: 0,
+				height: 0,
+				offsetWidth: 0,
+				offsetHeight: 0,
+				windowWidth: 0,
+				windowHeight: 0,
+				isMove: false,
+				edge: 10,
+			}
+		},
+		mounted() {
+			const sys = uni.getSystemInfoSync();
+			
+			this.windowWidth = sys.windowWidth;
+			this.windowHeight = sys.windowHeight;
+			
+
+			this.existTabBar && (this.windowHeight -= 80);
+
+			if (sys.windowTop) {
+				this.windowHeight += sys.windowTop;
+			}
+			console.log(sys)
+			
+			const query = uni.createSelectorQuery().in(this);
+			query.select('#_drag_button').boundingClientRect(data => {
+				this.width = data.width;
+				this.height = data.height;
+				this.offsetWidth = data.width / 2;
+				this.offsetHeight = data.height / 2;
+				this.left = this.windowWidth - this.width+4;
+				this.top = this.windowHeight - this.height - this.edge;
+			}).exec();
+		},
+		methods: {
+			click() {
+				this.$emit('btnClick');
+			},
+			touchstart(e) {
+				this.$emit('btnTouchstart');
+			},
+			touchmove(e) {
+				// 单指触摸
+				if (e.touches.length !== 1) {
+					return false;
+				}
+				
+				this.isMove = true;
+				
+				this.left = e.touches[0].clientX - this.offsetWidth;
+				
+				let clientY = e.touches[0].clientY - this.offsetHeight;
+				// #ifdef H5
+					clientY += this.height;
+				// #endif
+				let edgeBottom = this.windowHeight - this.height - this.edge;
+
+				// 上下触及边界
+				if (clientY < this.edge) {
+					this.top = this.edge;
+				} else if (clientY > edgeBottom) {
+					this.top = edgeBottom;
+				} else {
+					this.top = clientY
+				}
+			},
+			touchend(e) {
+				if (this.isDock) {
+					let edgeRigth = this.windowWidth - this.width;
+					
+					if (this.left < this.windowWidth / 2 - this.offsetWidth) {
+						this.left = -4;
+					} else {
+						this.left = edgeRigth+4;
+					}
+					
+				}
+				
+				this.isMove = false;
+				
+				this.$emit('btnTouchend');
+			},
+		}
+	}
+</script>
+
+<style lang="scss">
+	.drag {
+		display: flex;
+		justify-content: center;
+		align-items: center;
+		// background-color: rgba(0, 0, 0, 0.5);
+		// box-shadow: 0 0 6upx rgba(0, 0, 0, 0.4);
+		// color: $uni-text-color-inverse;
+		min-width: 80upx;
+		min-height: 80upx;
+		// border-radius: 50%;
+		// font-size: $uni-font-size-sm;
+		position: fixed;
+		z-index: 999999;
+		
+		&.transition {
+			transition: left .3s ease,top .3s ease;
+		}
+	}
+	
+</style>

+ 12 - 0
pages-voice/voiceDetail.vue

@@ -40,6 +40,16 @@
 
         <van-dialog id="van-dialog" />
 
+        <!-- 跳转去提问悬浮按钮 -->
+        <dragButton :existTabBar="true">
+            <navigator url="/pages-question/hasQuestion">
+                <view class="to-question-fixed-box">
+                    <image src="@/static/toquestion-icon.png" mode="widthFix" />
+                    <text>我要提问</text>
+                </view>
+            </navigator>
+        </dragButton>
+
     </view>
     <noAuth :info="noAuthData" v-else/>
 
@@ -50,10 +60,12 @@ import {apiVoicePlayRecord,apiVoiceDel,apiVoiceDetail,apiVoiceSendMsg} from '@/a
 import {apiGetSceneToParams} from '@/api/common'
 import noAuth from '@/pages/voice/components/noAuth.vue'
 import audioBox from '@/components/audioBox/audioBox.vue'
+import dragButton from '@/components/dragButton/dragButton.vue'
 const moment=require('@/utils/moment-with-locales.min')
 export default {
     components:{
         noAuth,
+        audioBox,
         audioBox
     },
     computed:{

+ 13 - 1
pages/video/videoList.vue

@@ -89,6 +89,16 @@
                 </view>
             </view>
         </van-popup>
+
+        <!-- 跳转去提问悬浮按钮 -->
+        <dragButton :existTabBar="true">
+            <navigator url="/pages-question/hasQuestion">
+                <view class="to-question-fixed-box">
+                    <image src="@/static/toquestion-icon.png" mode="widthFix" />
+                    <text>我要提问</text>
+                </view>
+            </navigator>
+        </dragButton>
     </view>
     <noAuth :info="noAuthData" v-else/>
 </template>
@@ -97,9 +107,11 @@ import {apiVideoList,apiVideoPlayLog} from '@/api/video'
 import {apiOptionList} from '@/api/question'
 import {apiGetSceneToParams,apiGetTagTree} from '@/api/common'
 import noAuth from './components/noAuth.vue'
+import dragButton from '@/components/dragButton/dragButton.vue'
 export default {
     components:{
-        noAuth
+        noAuth,
+        dragButton
     },
     data() {
         return {

+ 13 - 2
pages/voice/voice.vue

@@ -92,7 +92,16 @@
         <view v-if="showPage">
             <audioBox v-if="showAudioPop"/>
         </view>
-          
+        
+        <!-- 跳转去提问悬浮按钮 -->
+        <dragButton :existTabBar="true">
+            <navigator url="/pages-question/hasQuestion">
+                <view class="to-question-fixed-box">
+                    <image src="@/static/toquestion-icon.png" mode="widthFix" />
+                    <text>我要提问</text>
+                </view>
+            </navigator>
+        </dragButton>
         
 
         <van-dialog id="van-dialog" />
@@ -105,11 +114,13 @@ import {apiVoiceList,apiVoiceSectionList,apiVoicePlayRecord,apiVoiceDel,apiVoice
 import {apiGetSceneToParams} from '@/api/common'
 import noAuth from './components/noAuth.vue'
 import audioBox from '@/components/audioBox/audioBox.vue'
+import dragButton from '@/components/dragButton/dragButton.vue'
 const moment=require('@/utils/moment-with-locales.min')
 export default {
     components:{
         noAuth,
-        audioBox
+        audioBox,
+        dragButton
     },
     filters:{
         formatTime(e){

BIN
static/toquestion-icon.png


+ 23 - 0
style/common.scss

@@ -197,4 +197,27 @@ view{
         line-height: 80rpx;
         border-radius: 40rpx;
     }
+}
+
+// 跳转去提问的悬浮按钮
+.to-question-fixed-box{
+    width: 162rpx;
+    height: 145rpx;
+    background: #FFFFFF;
+    box-shadow: 0px 4px 17px 0px rgba(0,0,0,0.08);
+    border: 1px solid #F2F2F2;
+    display: flex;
+    align-items: center;
+    flex-direction: column;
+    justify-content: center;
+    border-radius: 16rpx;
+    image{
+        width: 84rpx;
+        height: 84rpx;
+    }
+    text{
+        font-size: 28rpx;
+        font-weight: 400;
+        color: #E3B377;
+    }
 }