quanwei
2 days ago 04102f7237efefa744090ed7c25f7b5d0807b679
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
    <view class="diy-page">
        <!-- #ifdef APP-PLUS -->
        <view class="tc d-b-c  header"
            :style="topBarHeight() == 0 ? '': 'height:'+topBarHeight()+'px;padding-top:'+(topBarTop() + 5)+'px'">
            <view class="reg180" :style="topBarHeight() == 0 ? '': 'height:'+topBarHeight()+'px;'">
                <text v-if="hasPage()" @click="goback" class="icon iconfont icon-jiantou"></text>
            </view>
            <view class="gray3 f28">{{page_info.params.name}}</view>
            <view class="gray3 m20" @click="showShare()"><text class="icon iconfont icon-share1"></text></view>
        </view>
        <view :style="topBarHeight() == 0 ? '': 'height:'+topBarHeight()+'px;padding-top:'+(topBarTop() + 5)+'px'"
            class="ww100"></view>
        <!-- #endif -->
        <diy :diyItems="items" :index_open_city="index_open_city"></diy>
        <!--底部弹窗-->
        <share :isMpShare="isMpShare" @close="closeBottmpanel"></share>
        <!--app分享-->
        <AppShare :isAppShare="isAppShare" :appParams="appParams" @close="closeAppShare"></AppShare>
    </view>
</template>
 
<script>
    import diy from '@/components/diy/diy.vue';
    import share from '@/components/mp-share.vue';
    import AppShare from '@/components/app-share.vue';
    export default {
        components: {
            diy,
            share,
            AppShare
        },
        data() {
            return {
                /*页面ID*/
                page_id: null,
                /*diy类别*/
                items: {},
                /*页面信息*/
                page_info: {},
                /*分享*/
                isMpShare: false,
                /*app分享*/
                isAppShare: false,
                index_open_city: 0,
                appParams: {
                    title: '',
                    summary: '',
                    path: ''
                },
                url: '',
                longitude: 0,
                latitude: 0,
            }
        },
        onLoad(e) {
            this.page_id = e.page_id;
            this.getAdds();
            //#ifdef H5
            this.url = window.location.href;
            //#endif
        },
        methods: {
            hasPage() {
                var pages = getCurrentPages();
                return pages.length > 1;
            },
            goback() {
                uni.navigateBack();
            },
            getAdds() {
                let self = this;
                uni.getLocation({
                    type: 'wgs84',
                    success: function(res) {
                        console.log('当前位置的经度:' + res.longitude);
                        console.log('当前位置的纬度:' + res.latitude);
                        uni.setStorageSync('longitude',res.longitude)
                        uni.setStorageSync('latitude',res.latitude)
                        self.longitude = res.longitude;
                        self.latitude = res.latitude;
                        self.getData();
                    },fetch() {
                        self.getData();
                    }
                })
            },
            /*获取数据*/
            getData(page_id) {
                let self = this;
                self._get('index/diy', {
                    page_id: self.page_id,
                    url: self.url,
                    longitude: self.longitude,
                    latitude: self.latitude
                }, function(res) {
                    self.page_info = res.data.page;
                    self.items = res.data.items;
                    self.setPage(self.page_info);
                    // 配置微信分享参数
                    //#ifdef H5
                    if (self.url != '') {
                        let params = {
                            page_id: self.page_id
                        };
                        self.configWx(res.data.share.signPackage, res.data.share.shareParams, params);
                    }
                    //#endif
                });
            },
 
            /*设置页面*/
            setPage(page) {
 
                uni.setNavigationBarTitle({
                    title: page.params.name
                });
 
                let colors = '#000000';
                if (page.style.titleTextColor == 'white') {
                    //字母要小写
                    colors = '#ffffff'
                }
                uni.setNavigationBarColor({
                    frontColor: colors,
                    backgroundColor: page.style.titleBackgroundColor
                })
 
            },
            /*分享当前页面*/
            onShareAppMessage() {
                let self = this;
                let params = self.getShareUrlParams({
                    page_id: self.page_id
                });
                return {
                    title: self.page_info.params.name,
                    path: '/pages/diy-page/diy-page?' + params
                };
            },
            //分享按钮
            showShare() {
                let self = this;
                //#ifdef MP-WEIXIN
                return;
                //#endif
                //#ifndef APP-PLUS
                self.isMpShare = true;
                //#endif
                //#ifdef APP-PLUS
                self.appParams.title = self.page_info.params.share_title;
                self.appParams.summary = self.page_info.params.name;
                // 构建页面参数
                let params = self.getShareUrlParams({
                    page_id: self.page_id
                });
                self.appParams.path = '/pages/diy-page/diy-page?' + params;
                self.appParams.image = self.page_info.params.share_img;
                self.isAppShare = true;
                //#endif
            },
            //关闭分享
            closeBottmpanel(data) {
                this.isMpShare = false;
            },
            //关闭分享
            closeAppShare(data) {
                this.isAppShare = false;
            },
        },
    }
</script>
 
<style>
 
</style>