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
<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: '',
            }
        },
        onLoad(e) {
            this.page_id=e.page_id;
            this.getData();
            //#ifdef H5
            this.url = window.location.href;
            //#endif
        },
        methods: {
            hasPage(){
                var pages = getCurrentPages();
                return pages.length > 1;
            },
            goback() {
                uni.navigateBack();
            },
            /*获取数据*/
            getData(page_id) {
                let self = this;
                self._get('index/diy', {
                    page_id: self.page_id,
                    url: self.url
                }, 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>