移动系统liao
2024-05-09 5d6cb15ac86d9174393cb9d1538d69b567e2c26c
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
<template>
    <!-- 页面主体 -->
    <view>
        <u-toast ref="uToast" /><u-no-network></u-no-network>
        <u-navbar :title="title" safeAreaInsetTop fixed placeholder>
            <view class="coreshop-navbar-left-slot" slot="left">
                <u-icon name="arrow-left" size="19" @click="goNavigateBack"></u-icon>
                <u-line direction="column" :hairline="false" length="16" margin="0 8px"></u-line>
                <u-icon name="home" size="22" @click="goHome"></u-icon>
            </view>
            <view slot="right">
            </view>
        </u-navbar>
 
        <view class="coreshop-bg-white coreshop-padding-10 coreshop-margin-10">
            <u--image width="100%" height="150px" v-if="info.coverImage" :src="info.coverImage"></u--image>
            <view class="article-title">
                {{ info.title }}
            </view>
            <view class="article-time" v-if="info.createTime">{{ info.createTime }}</view>
            <u-line dashed></u-line>
            <view class="u-content">
                <u-parse :content="contentBody" :selectable="true"></u-parse>
            </view>
        </view>
    </view>
</template>
 
<script>
 
    export default {
 
        data() {
            return {
                idType: 1, //1文章 2公告 3微信图文消息
                id: 0,
                info: {},
                contentBody: '',
                shareUrl: this.$globalConstVars.shareUrl,
                title: ''
            };
        },
        onLoad(e) {
            this.idType = e.idType;
            this.id = e.id;
            if (!this.idType && !this.id) {
                this.$refs.uToast.show({ message: '获取失败', type: 'error', isTab: true, url: '/pages/index/default/default' });
            } else if (this.idType == 1) {
                this.title = "文章详情";
                this.articleDetail();
            } else if (this.idType == 2) {
                this.title = "公告详情";
                this.noticeDetail();
            } else if (this.idType == 3) {
                this.title = "图文消息";
                this.messageDetail();
            }
        },
        computed: {
            shopName() {
                return this.$store.state.config.shopName;
            },
            shopLogo() {
                return this.$store.state.config.shopLogo;
            }
        },
        methods: {
            articleDetail() {
                let data = {
                    id: this.id
                };
                this.$u.api.articleInfo(data).then(res => {
                    if (res.status) {
                        this.info = res.data;
                        this.contentBody = res.data.contentBody;
                        this.title = this.info.title;
                    } else {
                        this.$refs.uToast.show({
                            message: res.msg, type: 'error', complete: function () {
                                uni.navigateBack({
                                    delta: 1
                                });
                            }
                        })
                    }
                });
            },
            noticeDetail() {
                let data = {
                    id: this.id
                };
                this.$u.api.noticeInfo(data).then(res => {
                    if (res.status) {
                        this.info = res.data;
                        this.contentBody = res.data.contentBody;
                        this.title = this.info.title;
                    } else {
                        this.$u.toast(res.msg);
                    }
                });
            },
            //微信图文消息
            messageDetail() {
                let data = {
                    id: this.id
                };
                this.$u.api.messageDetail(data).then(res => {
                    if (res.status) {
                        this.info = res.data;
                        this.contentBody = res.data.contentBody;
                        this.title = this.info.title;
                    } else {
                        this.$u.toast(res.msg);
                    }
                });
            },
            //获取分享URL
            getShareUrl() {
                let data = {
                    client: this.$globalConstVars.shareClient.wxMiNiProgram,
                    url: this.$globalConstVars.shareUrl,
                    type: this.$globalConstVars.shareModel.url,
                    page: this.$globalConstVars.shareType.article,
                    params: {
                        articleId: this.id,
                        articleType: this.idType
                    }
                };
                let userToken = this.$db.get('userToken');
                if (userToken && userToken != '') {
                    data.token = userToken
                }
                this.$u.api.share(data).then(res => {
                    this.shareUrl = res.data
                });
            }
        },
        watch: {
            id: {
                handler() {
                    this.getShareUrl();
                },
                deep: true
            }
        },
        //分享
        onShareAppMessage(res) {
            return {
                title: this.info.title,
                path: this.shareUrl
            }
        },
        onShareTimeline(res) {
            return {
                title: this.info.title,
                path: this.shareUrl
            }
        },
    };
</script>
 
<style lang="scss" scoped>
    @import "details.scss";
</style>