Commit a7506ca8 by 李嘉林

动态修改首页背景

parent 8880dee3
...@@ -15,8 +15,8 @@ export default { ...@@ -15,8 +15,8 @@ export default {
console.log(extConfig, "-----------extConfig"); console.log(extConfig, "-----------extConfig");
if (JSON.stringify(extConfig) == "{}") { if (JSON.stringify(extConfig) == "{}") {
let shopItem = { let shopItem = {
development: { mixid: "ssa", "shopid": 2342}, //五粮液uat // development: { mixid: "ssa", "shopid": 2342}, //五粮液uat
// development: { mixid: "antgood", "shopid": 67}, development: { mixid: "antgood", "shopid": 67},
production: { "mixid":"qiyeCT", "shopid": 1045 }, // 道可 production: { "mixid":"qiyeCT", "shopid": 1045 }, // 道可
// production: { "mixid":"metasense_doctors", "shopid": 1238 }, // 册为医护端 // production: { "mixid":"metasense_doctors", "shopid": 1238 }, // 册为医护端
// production: { "mixid":"3QqsFT", "shopid": 1337 }, // production: { "mixid":"3QqsFT", "shopid": 1337 },
......
<template> <template>
<div <div ref="ThemeDataPlant" class="ThemeDataPlant" :style="{
ref="ThemeDataPlant" 'position': pageCode == 14 ? 'fixed' : '',
class="ThemeDataPlant" 'background-color': pageSettingData.backgroundColor,
:style="{ 'background-image': bacImage,
'position':pageCode == 14?'fixed':'', 'background-size': pageSettingData.backgroundFit != 'equiratioFill' ? '100% auto' : 'cover',
'background-color': pageSettingData.backgroundColor, 'background-repeat': pageSettingData.backgroundFit == 'repeat' ? 'repeat' : 'no-repeat',
'background-image': bacImage, 'background-position': pageSettingData.backgroundFit == 'equiratioFill' ? 'center' : '',
'background-size': pageSettingData.backgroundFit!='equiratioFill'?'100% auto':'cover', 'background-attachment': pageSettingData.backgroundImageLock ? 'fixed' : 'local',
'background-repeat':pageSettingData.backgroundFit == 'repeat'? 'repeat': 'no-repeat', }">
'background-position':pageSettingData.backgroundFit == 'equiratioFill'?'center':'', <div class="imgRgb" :style="{
'background-attachment': pageSettingData.backgroundImageLock? 'fixed': 'local'}" background: 'linear-gradient(180deg, ' + imgRgb + ' 42.64%, rgba(255,255,255, 0) 100%)',
> }"></div>
</div> </div>
</template> </template>
...@@ -18,42 +18,52 @@ ...@@ -18,42 +18,52 @@
export default { export default {
props: { props: {
pageCode: { pageCode: {
type:Number, type: Number,
default: 1 default: 1
} }
}, },
components : { components: {
// 'area-navigation' : () => import('~/components/theme/components/other/area-navigation') // 'area-navigation' : () => import('~/components/theme/components/other/area-navigation')
}, },
data() { data() {
return { return {
flag: false, flag: false,
render: true, render: true,
pageInfo:{}, pageInfo: {},
pageData:{}, pageData: {},
pageSettingData:{}, pageSettingData: {},
bacImage:"" bacImage: "",
imgRgb: "", // 背景主色调
}; };
}, },
created(){ created() {
if (this.mpApp.globalData.pageList) { if (this.mpApp.globalData.pageList) {
this.pageInfo = this.mpApp.globalData.pageList.filter((item) => item.pageCode == this.pageCode)[0]; this.pageInfo = this.mpApp.globalData.pageList.filter((item) => item.pageCode == this.pageCode)[0];
this.pageSettingData = JSON.parse(this.pageInfo.pageSettingData); this.pageSettingData = JSON.parse(this.pageInfo.pageSettingData);
console.log(this.pageInfo.pageSettingData,'kl') console.log(this.pageInfo.pageSettingData, 'kl')
}else{ } else {
let _this = this let _this = this
this.mpApp.indexBgCallBack = function(data){ this.mpApp.indexBgCallBack = function (data) {
_this.pageInfo = _this.mpApp.globalData.pageList.filter((item) => item.pageCode == _this.pageCode)[0]; _this.pageInfo = _this.mpApp.globalData.pageList.filter((item) => item.pageCode == _this.pageCode)[0];
_this.pageSettingData = JSON.parse(_this.pageInfo.pageSettingData); _this.pageSettingData = JSON.parse(_this.pageInfo.pageSettingData);
console.log(_this.pageSettingData,'kl1') console.log(_this.pageSettingData, 'kl1')
_this.bacImage = `url(${_this.pageSettingData.backgroundImage})` _this.bacImage = `url(${_this.pageSettingData.backgroundImage})`
} }
} }
this.mpApp.setHomeBgImg = this.setHomeBgImg;
}, },
mounted(){ mounted() {
this.bacImage = `url(${this.pageSettingData.backgroundImage})` this.bacImage = `url(${this.pageSettingData.backgroundImage})`
}, },
computed:{ computed: {
},
methods: {
setHomeBgImg({ backgroundImage, imgRgb }) {
console.log(imgRgb,'-imgRgb')
this.bacImage = backgroundImage;
this.imgRgb = imgRgb;
}
} }
}; };
...@@ -61,12 +71,23 @@ export default { ...@@ -61,12 +71,23 @@ export default {
<style lang="scss" scoped> <style lang="scss" scoped>
.ThemeDataPlant { .ThemeDataPlant {
width:100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
top:0; top: 0;
z-index: -1; z-index: -1;
.imgRgb {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
opacity: 0.5;
}
} }
.ThemeDataPlant::before { .ThemeDataPlant::before {
content: " "; content: " ";
// position: var(--lock); // position: var(--lock);
......
<template>
<div class="CustomNav">
<div class="navFixedBg" :style="{ 'height': navHeight + 'px' }">
</div>
<div class="navBg"
:style="{ 'height': navHeight + 'px', background: 'rgba(255,255,255,' + (customBgOpacity ? bgOpacity : 1) + ')' }">
<div class="content" :style="{ 'top': navTop + 'px', height: navConHeight + 'px' }">
{{ title || shopName }}
</div>
</div>
</div>
</template>
<script type="text/ecmascript-6">
const app = getApp();
const { log } = app;
export default {
name: "CustomNav",
props: {
title: {
type: String,
default: "",
},
customBgOpacity: {
type: Boolean,
default: false,
}
},
data() {
return {
navHeight: 0,
navTop: 0,
navConHeight: 0,
bgOpacity: 0,
}
},
components: {},
computed: {
shopName() {
// let shopName = app.globalData && app.globalData.shopInfo && app.globalData.shopInfo.shopName;
let shopName = wx.getStorageSync("shopName");
return shopName || "";
},
listHeight() {
return `calc(100vh - ${this.navConHeight}px - ${this.navTop}px - 0.5rem )`
},
topBgHeight() {
return `calc(2rem + ${this.navTop}px)`
},
topHeight() {
return `calc(2rem + ${this.navTop}px)`
}
},
created() { },
onLoad() {
this.getNavbarInfo();
},
onShow() {
},
onReady() {
},
onHide() {
},
onUnload() {
},
onPageScroll(el) {
this.getScroll(el);
},
mounted() { },
methods: {
getScroll(el) {
let opacity = (el.scrollTop / 100).toFixed(1) - 0;
this.bgOpacity = opacity > 1 ? 1 : opacity;
},
getNavbarInfo() {
let menuInfo = wx.getMenuButtonBoundingClientRect();
console.log(menuInfo, '-menuInfo')
let res = wx.getSystemInfoSync()
console.log(res, '-getSystemInfoSync')
this.navTop = res.statusBarHeight;
this.navHeight = (res.statusBarHeight + menuInfo.height + (menuInfo.top - res.statusBarHeight) * 2)
this.navConHeight = (menuInfo.height + (menuInfo.top - res.statusBarHeight) * 2);
console.log(this.navTop, this.navHeight, this.navConHeight, '-this.navConHeight')
}
}
}
</script>
<style lang="scss" scoped>
.CustomNav {
position: relative;
z-index: 9999;
.navFixedBg {
width: 100%;
}
.navBg {
position: fixed;
width: 100%;
left: 0;
top: 0;
}
.content {
position: absolute;
left: 0;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
color: #333;
}
}
</style>
...@@ -102,6 +102,8 @@ mpApp.getFilterGoodsData = function () { } ...@@ -102,6 +102,8 @@ mpApp.getFilterGoodsData = function () { }
mpApp.openSelectGoods = function () { } mpApp.openSelectGoods = function () { }
// 打开选择商品规格(2B)弹窗 // 打开选择商品规格(2B)弹窗
mpApp.openTwoBAddCart = function () { } mpApp.openTwoBAddCart = function () { }
// 动态设置首页背景图片
mpApp.setHomeBgImg = function () {}
/** /**
* 组件点击行为收集 * 组件点击行为收集
......
<template> <template>
<div class="domain" :style="{'--main-color':themeColor['--main-color'],'--minor-color':themeColor['--minor-color']}"> <div class="domain" :style="{'--main-color':themeColor['--main-color'],'--minor-color':themeColor['--minor-color']}">
<pageLoading v-if="pageLoading"></pageLoading> <pageLoading v-if="pageLoading"></pageLoading>
<!-- 自定义导航头 -->
<div style="position:relative;"> <div style="position:relative;">
<div v-if="showSpokesManHome"> <div v-if="showSpokesManHome">
<get-index-homepage class="getIndexHomePage"></get-index-homepage> <get-index-homepage class="getIndexHomePage"></get-index-homepage>
</div> </div>
<CustomNav :customBgOpacity="true"></CustomNav>
<StoreAddr @toUpdate="reloadEnterShopRule" @toPageLoading="toPageLoading" ref="StoreAddr"></StoreAddr> <StoreAddr @toUpdate="reloadEnterShopRule" @toPageLoading="toPageLoading" ref="StoreAddr"></StoreAddr>
<ThemeDataPlant></ThemeDataPlant> <ThemeDataPlant></ThemeDataPlant>
<div v-for="(item,index) in pageData" :key="index"> <div v-for="(item,index) in pageData" :key="index">
...@@ -188,6 +190,7 @@ import mpvueCropper from '@/components/mpvue-cropper' ...@@ -188,6 +190,7 @@ import mpvueCropper from '@/components/mpvue-cropper'
import tool from '../../utils/tool.js' import tool from '../../utils/tool.js'
import StoreAddr from "@/components/common/StoreAddr.vue"; import StoreAddr from "@/components/common/StoreAddr.vue";
import pageLoading from "@/components/common/pageLoading.vue"; import pageLoading from "@/components/common/pageLoading.vue";
import CustomNav from "@/components/common/CustomNav.vue";
const app = getApp(); const app = getApp();
const { log } = app; const { log } = app;
export default { export default {
...@@ -255,7 +258,8 @@ export default { ...@@ -255,7 +258,8 @@ export default {
TwoBAddCart, TwoBAddCart,
brandList, brandList,
StoreAddr, StoreAddr,
pageLoading pageLoading,
CustomNav
}, },
computed: { computed: {
applySucessEntryFlag() { applySucessEntryFlag() {
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
"set-my-homepage":"/static/nativeComponents/SetMyHomePage/index", "set-my-homepage":"/static/nativeComponents/SetMyHomePage/index",
"apply-sucess-entry":"/static/nativeComponents/ApplySucessEntry/index" "apply-sucess-entry":"/static/nativeComponents/ApplySucessEntry/index"
}, },
"navigationStyle":"custom",
"enablePullDownRefresh":true, "enablePullDownRefresh":true,
"backgroundColor":"#f5f5f5" "backgroundColor":"#f5f5f5"
} }
const app = getApp() const app = getApp();
Component({ Component({
properties: { properties: {
// 这里定义了innerText属性,属性值可以在组件使用时指定 // 这里定义了innerText属性,属性值可以在组件使用时指定
...@@ -19,32 +19,78 @@ Component({ ...@@ -19,32 +19,78 @@ Component({
indicatorDots: false, indicatorDots: false,
vertical: false, vertical: false,
autoplay: true, autoplay: true,
interval: 2000, interval: 3000,
duration: 500, duration: 500,
activeIndex: 0, activeIndex: 0,
bannerHeight: 0, bannerHeight: 0,
firstLoad: false, firstLoad: false,
newArr: [], newArr: []
}, },
ready() { ready() {
console.log('----------------------30') console.log(app.setHomeBgImg, "----------------------30");
this.setData({'newArr':this.newList()}) this.setData({ newArr: this.newList() });
console.log(this.data.newArr,this.newList(),'--------32') this.bannerChange({
detail: {
current: 0
}
});
console.log(this.data.newArr, this.newList(), "--------32");
}, },
methods: { methods: {
newList(){ newList() {
return this.data.datas.componentData.imgList.filter(item=>item.visible==undefined || item.visible==1) || [] return (
this.data.datas.componentData.imgList.filter(
item => item.visible == undefined || item.visible == 1
) || []
);
}, },
customMethod() { customMethod() {
console.log("hello world! I am learning 微信小程序"); console.log("hello world! I am learning 微信小程序");
}, },
bannerChange(val) { async bannerChange(val) {
let { newArr } = this.data;
let { changeHomePageFlag } = this.data.datas.componentData;
let _this = this;
// 如果开启了修改首页背景图
let imageUrl = `url(${
newArr[val.detail.current].imageUrl
}?x-oss-process=image/blur,r_50,s_50)`;
if (changeHomePageFlag && app.setHomeBgImg) {
if (newArr[val.detail.current].imgRgb) {
app.setHomeBgImg({
backgroundImage: imageUrl,
imgRgb: newArr[val.detail.current].imgRgb
});
} else {
await wx.request({
url: `${
newArr[val.detail.current].imageUrl
}?x-oss-process=image/average-hue`,
data: {},
header: { "content-type": "application/json" },
method: "GET",
dataType: "json",
responseType: "text",
success: result => {
let imgRgb = `#${result.data.RGB.split("x")[1]}`;
app.setHomeBgImg({
backgroundImage: imageUrl,
imgRgb
});
newArr[val.detail.current].imgRgb = imgRgb;
_this.setData({ newArr });
},
fail: () => {},
complete: () => {}
});
}
}
this.setData({ activeIndex: val.detail.current }); this.setData({ activeIndex: val.detail.current });
}, },
onClick(data) { onClick(data) {
let item = data.currentTarget.dataset.item; let item = data.currentTarget.dataset.item;
console.log(data.currentTarget.dataset.item, "iiii"); console.log(data.currentTarget.dataset.item, "iiii");
app.trackCpn(data, this.data.datas.componentName, item) app.trackCpn(data, this.data.datas.componentName, item);
app.$themeToLink(item.link); app.$themeToLink(item.link);
}, },
loadImg(e) { loadImg(e) {
...@@ -53,7 +99,10 @@ Component({ ...@@ -53,7 +99,10 @@ Component({
return; return;
} }
firstLoad = true; firstLoad = true;
let winWid = wx.getSystemInfoSync().windowWidth - this.data.datas.componentData.paddingList[2].value - this.data.datas.componentData.paddingList[3].value; //获取当前屏幕的宽度 let winWid =
wx.getSystemInfoSync().windowWidth -
this.data.datas.componentData.paddingList[2].value -
this.data.datas.componentData.paddingList[3].value; //获取当前屏幕的宽度
let imgh = e.detail.height; //图片高度 let imgh = e.detail.height; //图片高度
let imgw = e.detail.width; let imgw = e.detail.width;
let swiperH = winWid * imgh / imgw + "px"; let swiperH = winWid * imgh / imgw + "px";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment