Skip to content

Commit 9c880de

Browse files
committed
imgload更改
1 parent 7a8781c commit 9c880de

File tree

14 files changed

+460
-88
lines changed

14 files changed

+460
-88
lines changed

src/common/utils.js

+14
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@ export function debounce(fn,delay){
77
fn.apply(this,args)
88
},delay);
99
}
10+
}
11+
//时间格式转换
12+
function add0(m){return m<10?'0'+m:m }
13+
export function format(value)
14+
{
15+
16+
var time = new Date(value);
17+
var y = time.getFullYear();
18+
var m = time.getMonth()+1;
19+
var d = time.getDate();
20+
var h = time.getHours();
21+
var mm = time.getMinutes();
22+
var s = time.getSeconds();
23+
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
1024
}

src/components/common/scroll/BetterScroll.vue

+1
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,5 @@
127127
}, this.refreshDelay)
128128
}
129129
}
130+
}
130131
</script>

src/components/common/scroll/Scroll.vue

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<template>
2-
<div ref="wrapper" class="wrapper">
3-
4-
<div class="content"><slot></slot></div>
5-
2+
<div ref="wrapper">
3+
<div class="content">
4+
<slot></slot>
65
</div>
6+
</div>
7+
78

89
</template>
910

@@ -27,7 +28,7 @@ export default {
2728
default:false,
2829
2930
},
30-
goods:{
31+
data:{
3132
type:Array,
3233
default:null,
3334
}
@@ -100,8 +101,8 @@ export default {
100101
},
101102
//性能优化,watch全局监听,更新30条数据后refresh
102103
watch:{
103-
goods(){
104-
console.log(this.goods)
104+
data(){
105+
console.log(this.data)
105106
setTimeout(()=>{
106107
this.refresh();
107108
},this.refreshDelay)

src/components/content/goods/GoodsList.vue

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<div class="goods">
33
<goods-list-item v-for="(item,index) in goods" :key="index" :goodsItem=item></goods-list-item>
4-
54
</div>
65
</template>
76

@@ -14,13 +13,13 @@ export default {
1413
props:{
1514
goods:{
1615
type:Array,
17-
default:[],
16+
default(){
17+
return []
18+
},
1819
}
1920
}
2021
}
2122
22-
23-
2423
</script>
2524

2625
<style>

src/components/content/goods/GoodsListItem.vue

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<template>
22
<div class="goods-list-item" @click="clickDetail">
3-
<img :src="goodsItem.show.img" alt="" @load="imgLoad"/>
3+
<img :src="resImage" alt="" @load="imgLoad">
44
<div class="goods-info">
55
<p>{{ goodsItem.title }}</p>
66
<span class="price">{{ goodsItem.price }}</span>
77
<span class="collect">{{ goodsItem.cfav }}</span>
88
</div>
9-
10-
119
</div>
1210
</template>
1311

@@ -19,6 +17,11 @@ export default {
1917
default: {},
2018
},
2119
},
20+
computed:{
21+
resImage(){
22+
return this.goodsItem.image ||this.goodsItem.show.img;
23+
}
24+
},
2225
data(){
2326
return {
2427
iid:null,
@@ -27,23 +30,25 @@ export default {
2730
},
2831
methods:{
2932
imgLoad(){
30-
this.$bus.$emit('imgLoad')
31-
},
33+
console.log("goodslist组件里面的图片监听");
34+
// if(this.$route.path.indexOf('/home')){
35+
// this.$bus.$emit('homeImgLoad')}
36+
// else if(this.$route.path.indexOf('/detail')){
37+
// this.$bus.$emit('detailImgLoad')
38+
// }
39+
this.$bus.$emit("ImgLoad")
40+
},
3241
clickDetail(){
3342
this.$router.push({
3443
name:'detail',
3544
params:{
3645
iid:this.goodsItem.iid,
37-
38-
39-
40-
}
46+
}
4147
})
4248
},
4349
}
44-
};
50+
}
4551
</script>
46-
4752
<style>
4853
.goods-list-item {
4954
position: relative;
@@ -83,6 +88,6 @@ export default {
8388
width: 14px;
8489
height: 14px;
8590
background: url("~assets/img/common/collect.svg") 0px 0/14px 14px;
86-
left: -15px;
91+
left:-15px;
8792
}
8893
</style>

src/main.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ import elementUi from 'element-ui'
55
import 'element-ui/lib/theme-chalk/index.css' //Element UI样式
66
import VueAwesomeSwiper from 'vue-awesome-swiper'
77
import 'swiper/css/swiper.css'
8-
Vue.prototype.$bus = new Vue()
8+
Vue.prototype.$bus = new Vue() //事件总线bus,进行简单同组件传值
99
Vue.use(elementUi) //使用element-ui组件
1010
Vue.use(VueAwesomeSwiper, /* { default options with global component } */) //使用swiper组件
1111
Vue.config.productionTip = false
12+
Vue.filter('dateFormat', function(originVal) {
13+
const dt = new Date(originVal)
14+
const y = dt.getFullYear()
15+
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
16+
const d = (dt.getDate() + '').padStart(2, '0')
17+
const hh = (dt.getHours() + '').padStart(2, '0')
18+
const mm = (dt.getMinutes() + '').padStart(2, '0')
19+
const ss = (dt.getSeconds() + '').padStart(2, '0')
20+
//时间格式年月日、时分秒
21+
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
22+
})
1223

1324
new Vue({
1425
router,

src/network/detail.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export function getDetail(iid){
1010
})
1111

1212
}
13+
//获取推荐信息
14+
export function getRecommend(){
15+
return request({
16+
url:'/recommend'
17+
})
18+
}
1319
//goods类
1420
export class Goods{
1521
constructor(itemInfo,columns,services){

src/router/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const routes =[
3333

3434
const router = new VueRouter({
3535
routes,
36-
mode:'history'
36+
mode:'hash'
3737
})
3838

3939
export default router

src/views/detail/Detail.vue

+57-22
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
<template>
22
<div id="detail">
33
<detail-nav-bar class="detail-nav"></detail-nav-bar>
4-
<scroll class="content">
5-
<detail-swiper :topImg="topImg">npm</detail-swiper>
4+
<!-- 加载图片后计算高度,初始化滚动失败, -->
5+
<scroll class="wrapper" ref="scroll">
6+
<detail-swiper :top-img="topImg">npm</detail-swiper>
67
<detail-base-info :goods="goods"></detail-base-info>
78
<detail-shop-info :shop="shop"></detail-shop-info>
9+
<detail-image-info :detail-info="detailInfo"></detail-image-info>
10+
<detail-item-params :detail-params="itemParams"></detail-item-params>
11+
<detail-info-comment :comment="commentInfo"></detail-info-comment>
12+
<goods-list :goods="recommends"></goods-list>
813
</scroll>
9-
1014
</div>
1115
</template>
12-
1316
<script>
1417
import DetailNavBar from './childComps/DetailNavBar.vue'
1518
import DetailSwiper from './childComps/DetailSwiper.vue'
16-
import {getDetail,Goods,Shop} from 'network/detail'
19+
import {getDetail,Goods,Shop,getRecommend} from 'network/detail'
1720
import DetailBaseInfo from './childComps/DetailBaseInfo.vue'
1821
import DetailShopInfo from './childComps/DetailShopInfo'
1922
import Scroll from 'components/common/scroll/Scroll'
23+
import DetailImageInfo from './childComps/DetailImageInfo.vue'
24+
import DetailItemParams from './childComps/DetailItemParams.vue'
25+
import DetailInfoComment from './childComps/DetailInfoComment.vue'
26+
import GoodsList from 'components/content/goods/GoodsList.vue'
2027
export default {
2128
name:'Detail', //使用keep-alive必须加name
2229
components:{
@@ -25,8 +32,10 @@ export default {
2532
DetailBaseInfo,
2633
DetailShopInfo,
2734
Scroll,
28-
29-
35+
DetailImageInfo,
36+
DetailItemParams,
37+
DetailInfoComment,
38+
GoodsList
3039
3140
},
3241
data(){
@@ -35,45 +44,71 @@ export default {
3544
topImg:null,
3645
goods:{},
3746
shop:{},
47+
detailInfo:{},
48+
itemParams:{},
49+
commentInfo:{},
50+
recommends:[]
3851
}
3952
},
4053
created(){
54+
// console.log("created");
4155
//保存商品id
4256
this.iid=this.$route.params.iid;
43-
// console.log('created')
44-
57+
// console.log('created')
4558
//请求商品图片
4659
getDetail(this.iid).then(res=>{
4760
const data =res.result
48-
this.topImg = res.result.itemInfo.topImages
61+
this.topImg = res.result.itemInfo.topImages;
4962
// console.log(res.result);
5063
//获取商品数据
51-
this.goods =new Goods(data.itemInfo,data.columns,data.shopInfo.services)
64+
this.goods =new Goods(data.itemInfo,data.columns,data.shopInfo.services);
5265
//请求店铺信息
53-
this.shop = new Shop(data.shopInfo)
66+
this.shop = new Shop(data.shopInfo);
5467
// console.log(this.shop);
68+
//取出商品详情信息
69+
this.detailInfo=data.detailInfo;
70+
//取出参数信息
71+
this.itemParams=data.itemParams;
72+
//取出评论信息
73+
// console.log(data.rate);
74+
if(data.rate.cRate!==0){
75+
76+
this.commentInfo=data.rate.list[0];
77+
// console.log(this.commentInfo);
78+
}
79+
}),
80+
getRecommend().then(res=>{
81+
// console.log(res);
82+
// console.log(res.data.list);
83+
this.recommends =res.data.list;
5584
})
56-
57-
58-
85+
},
86+
mounted(){
87+
//监听图片刷新
88+
this.$bus.$on("imageLoad",()=>{
89+
console.log("detail里面组件监听");
90+
this.$refs.scroll.refresh(); //重新计算高度
91+
})
92+
// this.$bus.$on("detailImgLoad",()=>{
93+
// console.log("detailImgload里面组件监听");
94+
// this.$refs.scroll.refresh(); //重新计算高度
95+
// })
5996
}
60-
97+
// updated(){
98+
// this.$refs.scroll.refresh(); //重新计算高度
99+
// }
61100
}
62101
</script>
63102

64103
<style scoped>
65-
66104
#detail{
67105
position: relative;
68106
z-index: 9;
69107
background-color:#fff;
70108
height: 100vh;
71109
}
72-
.content{
73-
position:relative;
74-
bottom:49px ;
75-
right: 0;
76-
left: 0;
110+
.wrapper{
111+
height: calc( 100% - 48px );
77112
overflow: hidden;
78113
79114
}

0 commit comments

Comments
 (0)