jazz
2023-12-08 bf4dca5344dee1a84b75d9993f4dfc59de3f3ee9
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
<template>
    <div id="app">
        <transition name="fade" mode="out-in">
            <!-- 页面,isRouterAlive 刷新用 -->
            <!-- <router-view v-if="isRouterAlive"/> -->
            <div>
                <keep-alive>
                    <router-view v-if="isRouterAlive" />
                </keep-alive>
            </div>
        </transition>
 
        <!-- Toast 提示 -->
        <transition name="fade">
            <div class="toast-mask flex flex-center" :class="{'type-toast': toastType=='toast', 'type-loading': toastType=='loading'}" v-if="toastShow">
                <!-- 提示 -->
                <div class="toast" v-html="toastText" v-if="toastType=='toast'"></div>
                <!-- loading -->
                <div class="toast" v-if="toastType=='loading'">
                    <div class="ball-rotate"><div></div></div>
                </div>
            </div>
        </transition>
    </div>
</template>
 
<script>
 
// 入口参数
// 这里注释入口参数
 
import Login from '@/utils/jun_login.js'
import wxsign from '@/utils/wxsign.js'
import Config from './config'
// import eruda from 'eruda'
export default {
    name: 'App',
 
    // 安装组件
    components: {
 
    },
 
    // 监听路由
    watch: {
        // $route(to, from){
 
        // }
    },
 
    // 子组件injection
    // -用于共享app methods
    provide(){
        return {
            reload: this.reload, // 刷新
            toast: this.toast, // toast
            // 修复input导致ios微信浏览器收起键盘时,不回滚
            inputBlur: ()=>{
                let u = navigator.userAgent,
                app = navigator.appVersion;
                let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
                if(isIOS){
                    setTimeout(() => {
                        const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
                        window.scrollTo(0, Math.max(scrollHeight - 1, 0))
                    }, 200)
                }
            },
            noop(){},
        }
    },
    data () {
        return {
            // 刷新用
            isRouterAlive: true,
 
            toastText: '',
            toastShow: false,
            toastType: 'toast',
        }
    },
    mounted () {
        // console.log('/**********************/', eruda)
        // eruda && eruda.init()
        console.log('app amounted')
 
        // 避免刷新导致code重复使用
        // let code = this.getQueryString('code') // 微信回调code
        // let cover = this.getQueryString('cover') // 是否封面入口
        // let local_code = this.getLocalStorage('code') // 本地缓存code
        // let isRule = this.getQueryString('rule')==1 // 规则
        // let isCoupon = this.getQueryString('coupon')==1 // 优惠券
 
        // 以下情况需要重定向到长链
        // 1. 链接带有code,但code已经用过
        // 2. 非cover入口
        // 3. 正式环境
        // 4. 非规则单页
        // 4. 非优惠券单页
        // console.dir(Config.createCodeUrl())
 
        // if(Config.isWxLoginType){
        //     if (code && local_code == code || (!isCoupon && !isRule && !cover && !code && !Config.ismock && !Config.istest)) {
        //         // 该微信code已使用,重新跳转长链
        //         Login.toLongUrl()
        //         return
        //     } else {
        //         this.removeLocalStorage('code')
        //     }
        // }
 
        // 刷新固定首页
        // if (location.hash && location.hash!='#/') {
        //     this.$router.replace({name: 'root'})
        // }
 
        // 暴露到全局,jun_httpEvent.js 调用
        window.appLoading = this.loading.bind(this)
        window.appHideLoading = this.hideLoading.bind(this)
        window.appToast = this.toast.bind(this)
 
        // this.$refs.audio.play()
        // if(Config.isWxLoginType) this.wxinit()
    },
    methods: {
        // 微信初始化
        wxinit () {
            wxsign.main()
 
            // 测试用
            // let time = new Date('2020/10/11 00:00:00').getTime()
            // if ( Date.now() < time ) {
            //     alert('该活动未结束')
            // }
 
            wx.ready(()=>{
                console.log('ready')
 
                let shareImg = sessionStorage.getItem('shareImg');
                let shareTitle = sessionStorage.getItem('shareTitle');
                let shareDesc = sessionStorage.getItem('shareDesc');
 
                // 分享链接
                let url = location.origin + location.pathname + '?cover=1'
                // 带channelNo
                let we_session = this.getLocalStorage('we_session')
                if (we_session && we_session.we_session) {
                    url += '&channelNo=' + we_session.we_session
                }
                console.log(url)
 
                // 分享
                // wx.updateAppMessageShareData({
                //     title: shareTitle, // 分享标题
                //     desc: shareDesc, // 分享描述
                //     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                //     imgUrl: shareImg, // 分享图标
                //     success: function () {
                //         // 设置成功
                //     }
                // })
                // wx.updateTimelineShareData({
                //     title: shareTitle, // 分享标题
                //     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                //     imgUrl: shareImg, // 分享图标
                //     success: function () {
                //         // 设置成功
                //     }
                // })
 
                wx.onMenuShareTimeline({
                    title: shareTitle, // 分享标题
                    link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: shareImg, // 分享图标
                    success: function () {
                        // 用户点击了分享后执行的回调函数
                        // alert(123)
                    }
                })
 
                wx.onMenuShareAppMessage({
                    title: shareTitle, // 分享标题
                    desc: shareDesc, // 分享描述
                    link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
                    imgUrl: shareImg, // 分享图标
                    type: 'link', // 分享类型,music、video或link,不填默认为link
                    // dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
                    success: function () {
                        // 用户点击了分享后执行的回调函数
                        // alert(123)
                    }
                });
            })
        },
 
        // 刷新
        reload(){
            this.isRouterAlive = false
            this.$nextTick(()=>{
                this.isRouterAlive = true
            })
        },
 
        // toast
        toast (e, type) {
            type = type || 'toast'
            this.toastText = e
            this.toastShow = true
            this.toastType = type
 
            if (type == 'toast') {
                clearTimeout(timer)
                timer = setTimeout(()=>{
                    this.hideToast()
                }, 2000)
            }
        },
        // 显示loading
        loading () {
            this.toast('', 'loading')
        },
        // 隐藏toast
        hideToast(){
            this.toastShow = false
        },
        // toast loading 收起
        hideLoading(){
            this.hideToast()
        },
    }
}
</script>
 
<style>
@import './assets/css/common.css';
.toast-mask{
    position: fixed;
    z-index: 2000;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transition: all .5s;
}
.toast-mask.type-toast{
    pointer-events: none;
}
.toast{
    text-align: center;
    border-radius: 6px;
    color:#FFF;
    background: rgba(17, 17, 17, 0.9);
    line-height: 1.6;
    padding: 30px;
    max-width: 400px;
    font-size: 24px;
}
 
@keyframes ball-rotate {
  0% {transform: rotate(0deg) scale(1); }
 
  50% {transform: rotate(180deg) scale(0.6);}
 
  100% {transform: rotate(360deg) scale(1);}
}
.ball-rotate{position: relative;width: 200px;height: 140px;}
.ball-rotate > div {
    background-color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 100%;
    margin: 4px;
    animation-fill-mode: both;
    position: absolute;
    top: 50%;
    left: 50%;
    margin: -16px 0 0 -16px;
}
.ball-rotate > div:first-child {
    animation: ball-rotate 1s 0s cubic-bezier(.7, -.13, .22, .86) infinite;
}
.ball-rotate > div:before, .ball-rotate > div:after {
    background-color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 100%;
    margin: 4px;
    content: ""!important;
    position: absolute;
    opacity: .8;
}
.ball-rotate > div:before {top: 0px;left: -56px}
.ball-rotate > div:after {top: 0px;left: 50px}
</style>