营销:适配商城装修组件【悬浮按钮】

pull/25/head
owen 2023-12-09 21:33:46 +08:00
parent a28a36e038
commit 72998abf10
4 changed files with 69 additions and 58 deletions

View File

@ -6,7 +6,6 @@
:bgStyle="template.page" :bgStyle="template.page"
:navbarStyle="template.style?.navbar" :navbarStyle="template.style?.navbar"
onShareAppMessage onShareAppMessage
:showFloatButton="true"
> >
<s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style"> <s-block v-for="(item, index) in template.components" :key="index" :styles="item.property.style">
<s-block-item :type="item.id" :data="item.property" :styles="item.property.style" /> <s-block-item :type="item.id" :data="item.property" :styles="item.property.style" />

View File

@ -12,6 +12,8 @@
<s-menu-grid v-if="type === 'MenuGrid'" :data="data" /> <s-menu-grid v-if="type === 'MenuGrid'" :data="data" />
<!-- 基础组件弹窗广告 --> <!-- 基础组件弹窗广告 -->
<s-popup-image v-if="type === 'Popover'" :data="data" /> <s-popup-image v-if="type === 'Popover'" :data="data" />
<!-- 基础组件悬浮按钮 -->
<s-float-menu v-if="type === 'FloatingActionButton'" :data="data" />
<!-- 图文组件图片展示 --> <!-- 图文组件图片展示 -->
<s-image-block v-if="type === 'ImageBar'" :data="data" :styles="styles" /> <s-image-block v-if="type === 'ImageBar'" :data="data" :styles="styles" />

View File

@ -1,75 +1,93 @@
<template> <template>
<!-- TODO-jj: 点击遮罩关闭 --> <!-- 模态背景展开时显示点击后折叠 -->
<view> <view class="modal-bg" v-if="fabRef?.isShow" @click="handleCollapseFab"></view>
<view v-if="data?.show === 1"> <!-- 悬浮按钮 -->
<uni-fab <uni-fab
ref="fabRef" ref="fabRef"
:pattern="state.pattern"
:content="state.content"
horizontal="right" horizontal="right"
vertical="bottom" vertical="bottom"
:direction="state.direction" :direction="state.direction"
@trigger="trigger" :pattern="state.pattern"
@fabClick="fabClick" :content="state.content"
:popMenu="true" @trigger="handleOpenLink"
></uni-fab> />
</view>
<view :class="state.show ? 'float-bg' : ''" @click="onTap"></view>
</view>
</template> </template>
<script setup> <script setup>
/**
* 悬浮按钮
*/
import sheep from '@/sheep'; import sheep from '@/sheep';
import { computed, reactive, ref, unref, getCurrentInstance } from 'vue'; import { reactive, ref, unref } from 'vue';
import { onBackPress } from '@dcloudio/uni-app'; import { onBackPress } from '@dcloudio/uni-app';
const data = computed(() => sheep.$store('app').template.basic?.floatMenu);
//
const props = defineProps({
data: {
type: Object,
default() {
return {
// horizontal vertical
direction: 'vertical',
showText: true,
list: [{
imgUrl: 'http://localhost/logo.gif',
url: '',
text: '客服',
textColor: '',
}],
}
},
}
})
// https://uniapp.dcloud.net.cn/component/uniui/uni-fab.html#fab-props
const state = reactive({ const state = reactive({
//
pattern: [], pattern: [],
//
content: [], content: [],
// horizontal-vertical-
direction: '', direction: '',
show: false,
}); });
//
const fabRef = ref(null); const fabRef = ref(null);
const vm = getCurrentInstance(); //
if (data.value?.mode === 1) { state.direction = props.data.direction;
state.direction = 'vertical'; props.data?.list.forEach((item) => {
} else { //
state.direction = 'horizontal'; const text = props.data?.showText ? item.text : ''
} //
data.value?.list.forEach((i) => { state.content.push({ iconPath: sheep.$url.cdn(item.imgUrl), url: item.url, text });
if (data.value?.isText === 0) { //
state.content.push({ iconPath: sheep.$url.cdn(i.src), url: i.url }); state.pattern.push({ color: item.textColor });
} else {
state.content.push({ iconPath: sheep.$url.cdn(i.src), text: i.title.text + '', url: i.url });
}
state.pattern.push({ color: i.title.color });
}); });
function trigger(e) {
//
function handleOpenLink(e) {
sheep.$router.go(e.item.url); sheep.$router.go(e.item.url);
} }
function onTap() {
if (state.show) { //
state.show = false; function handleCollapseFab() {
vm.refs.fabRef.close(); if (unref(fabRef)?.isShow) {
} else { unref(fabRef)?.close();
state.show = true;
vm.refs.fabRef.open();
} }
} }
function fabClick() {
state.show = !state.show; //
}
onBackPress(() => { onBackPress(() => {
if (unref(fabRef).isShow) { if (unref(fabRef)?.isShow) {
unref(fabRef).close(); unref(fabRef)?.close();
return true; return true;
} else {
return false;
} }
return false;
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.float-bg { /* 模态背景 */
.modal-bg {
position: fixed; position: fixed;
left: 0; left: 0;
top: 0; top: 0;

View File

@ -36,9 +36,6 @@
<!-- 页面内容插槽 --> <!-- 页面内容插槽 -->
<slot /> <slot />
<!-- 悬浮按钮 -->
<s-float-menu v-if="showFloatButton"></s-float-menu>
<!-- 底部导航 --> <!-- 底部导航 -->
<s-tabbar v-if="tabbar !== ''" :path="tabbar" /> <s-tabbar v-if="tabbar !== ''" :path="tabbar" />
</view> </view>
@ -130,11 +127,6 @@
type: String, type: String,
default: '', default: '',
}, },
//
showFloatButton: {
type: Boolean,
default: false,
},
// //
showLeftButton: { showLeftButton: {
type: Boolean, type: Boolean,