jazzzone
2023-12-09 d73f982f2b93c0f418dbd76d80745b0793b0d338
提交 | 用户 | age
3ac5f2 1 <template>
J 2     <div id="app">
3         <transition name="fade" mode="out-in">
4             <!-- 页面,isRouterAlive 刷新用 -->
bf4dca 5             <!-- <router-view v-if="isRouterAlive"/> -->
J 6             <div>
7                 <keep-alive>
8                     <router-view v-if="isRouterAlive" />
9                 </keep-alive>
10             </div>
3ac5f2 11         </transition>
J 12
13         <!-- Toast 提示 -->
14         <transition name="fade">
15             <div class="toast-mask flex flex-center" :class="{'type-toast': toastType=='toast', 'type-loading': toastType=='loading'}" v-if="toastShow">
16                 <!-- 提示 -->
17                 <div class="toast" v-html="toastText" v-if="toastType=='toast'"></div>
18                 <!-- loading -->
19                 <div class="toast" v-if="toastType=='loading'">
20                     <div class="ball-rotate"><div></div></div>
21                 </div>
22             </div>
23         </transition>
24     </div>
25 </template>
26
27 <script>
28
29 // 入口参数
30 // 这里注释入口参数
31
32 import Login from '@/utils/jun_login.js'
33 import wxsign from '@/utils/wxsign.js'
34 import Config from './config'
bf4dca 35 // import eruda from 'eruda'
3ac5f2 36 export default {
J 37     name: 'App',
38
39     // 安装组件
40     components: {
41
42     },
43
44     // 监听路由
45     watch: {
46         // $route(to, from){
47
48         // }
49     },
50
51     // 子组件injection
52     // -用于共享app methods
53     provide(){
54         return {
55             reload: this.reload, // 刷新
56             toast: this.toast, // toast
57             // 修复input导致ios微信浏览器收起键盘时,不回滚
58             inputBlur: ()=>{
59                 let u = navigator.userAgent,
60                 app = navigator.appVersion;
61                 let isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
62                 if(isIOS){
63                     setTimeout(() => {
64                         const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
65                         window.scrollTo(0, Math.max(scrollHeight - 1, 0))
66                     }, 200)
67                 }
68             },
69             noop(){},
70         }
71     },
72     data () {
73         return {
74             // 刷新用
75             isRouterAlive: true,
76
77             toastText: '',
78             toastShow: false,
79             toastType: 'toast',
80         }
81     },
82     mounted () {
878885 83         // console.log('/**********************/', eruda)
J 84         // eruda && eruda.init()
3ac5f2 85         console.log('app amounted')
J 86
87         // 避免刷新导致code重复使用
bf4dca 88         // let code = this.getQueryString('code') // 微信回调code
J 89         // let cover = this.getQueryString('cover') // 是否封面入口
90         // let local_code = this.getLocalStorage('code') // 本地缓存code
91         // let isRule = this.getQueryString('rule')==1 // 规则
92         // let isCoupon = this.getQueryString('coupon')==1 // 优惠券
3ac5f2 93
J 94         // 以下情况需要重定向到长链
95         // 1. 链接带有code,但code已经用过
96         // 2. 非cover入口
97         // 3. 正式环境
98         // 4. 非规则单页
99         // 4. 非优惠券单页
100         // console.dir(Config.createCodeUrl())
101
bf4dca 102         // if(Config.isWxLoginType){
J 103         //     if (code && local_code == code || (!isCoupon && !isRule && !cover && !code && !Config.ismock && !Config.istest)) {
104         //         // 该微信code已使用,重新跳转长链
105         //         Login.toLongUrl()
106         //         return
107         //     } else {
108         //         this.removeLocalStorage('code')
109         //     }
110         // }
3ac5f2 111
J 112         // 刷新固定首页
bf4dca 113         // if (location.hash && location.hash!='#/') {
J 114         //     this.$router.replace({name: 'root'})
115         // }
3ac5f2 116
J 117         // 暴露到全局,jun_httpEvent.js 调用
118         window.appLoading = this.loading.bind(this)
119         window.appHideLoading = this.hideLoading.bind(this)
120         window.appToast = this.toast.bind(this)
121
122         // this.$refs.audio.play()
bf4dca 123         // if(Config.isWxLoginType) this.wxinit()
3ac5f2 124     },
J 125     methods: {
126         // 微信初始化
127         wxinit () {
128             wxsign.main()
129
130             // 测试用
131             // let time = new Date('2020/10/11 00:00:00').getTime()
132             // if ( Date.now() < time ) {
133             //     alert('该活动未结束')
134             // }
135
136             wx.ready(()=>{
137                 console.log('ready')
138
139                 let shareImg = sessionStorage.getItem('shareImg');
140                 let shareTitle = sessionStorage.getItem('shareTitle');
141                 let shareDesc = sessionStorage.getItem('shareDesc');
142
143                 // 分享链接
144                 let url = location.origin + location.pathname + '?cover=1'
145                 // 带channelNo
146                 let we_session = this.getLocalStorage('we_session')
147                 if (we_session && we_session.we_session) {
148                     url += '&channelNo=' + we_session.we_session
149                 }
150                 console.log(url)
151
152                 // 分享
153                 // wx.updateAppMessageShareData({
154                 //     title: shareTitle, // 分享标题
155                 //     desc: shareDesc, // 分享描述
156                 //     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
157                 //     imgUrl: shareImg, // 分享图标
158                 //     success: function () {
159                 //         // 设置成功
160                 //     }
161                 // })
162                 // wx.updateTimelineShareData({
163                 //     title: shareTitle, // 分享标题
164                 //     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
165                 //     imgUrl: shareImg, // 分享图标
166                 //     success: function () {
167                 //         // 设置成功
168                 //     }
169                 // })
170
171                 wx.onMenuShareTimeline({
172                     title: shareTitle, // 分享标题
173                     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
174                     imgUrl: shareImg, // 分享图标
175                     success: function () {
176                         // 用户点击了分享后执行的回调函数
177                         // alert(123)
178                     }
179                 })
180
181                 wx.onMenuShareAppMessage({
182                     title: shareTitle, // 分享标题
183                     desc: shareDesc, // 分享描述
184                     link: url, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
185                     imgUrl: shareImg, // 分享图标
186                     type: 'link', // 分享类型,music、video或link,不填默认为link
187                     // dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
188                     success: function () {
189                         // 用户点击了分享后执行的回调函数
190                         // alert(123)
191                     }
192                 });
193             })
194         },
195
196         // 刷新
197         reload(){
198             this.isRouterAlive = false
199             this.$nextTick(()=>{
200                 this.isRouterAlive = true
201             })
202         },
203
204         // toast
205         toast (e, type) {
206             type = type || 'toast'
207             this.toastText = e
208             this.toastShow = true
209             this.toastType = type
210
211             if (type == 'toast') {
212                 clearTimeout(timer)
213                 timer = setTimeout(()=>{
214                     this.hideToast()
215                 }, 2000)
216             }
217         },
218         // 显示loading
219         loading () {
220             this.toast('', 'loading')
221         },
222         // 隐藏toast
223         hideToast(){
224             this.toastShow = false
225         },
226         // toast loading 收起
227         hideLoading(){
228             this.hideToast()
229         },
230     }
231 }
232 </script>
233
234 <style>
235 @import './assets/css/common.css';
236 .toast-mask{
237     position: fixed;
238     z-index: 2000;
239     top: 0;
240     left: 0;
241     right: 0;
242     bottom: 0;
243     transition: all .5s;
244 }
245 .toast-mask.type-toast{
246     pointer-events: none;
247 }
248 .toast{
249     text-align: center;
250     border-radius: 6px;
251     color:#FFF;
252     background: rgba(17, 17, 17, 0.9);
253     line-height: 1.6;
254     padding: 30px;
255     max-width: 400px;
256     font-size: 24px;
257 }
258
259 @keyframes ball-rotate {
260   0% {transform: rotate(0deg) scale(1); }
261
262   50% {transform: rotate(180deg) scale(0.6);}
263
264   100% {transform: rotate(360deg) scale(1);}
265 }
266 .ball-rotate{position: relative;width: 200px;height: 140px;}
267 .ball-rotate > div {
268     background-color: #fff;
269     width: 30px;
270     height: 30px;
271     border-radius: 100%;
272     margin: 4px;
273     animation-fill-mode: both;
274     position: absolute;
275     top: 50%;
276     left: 50%;
277     margin: -16px 0 0 -16px;
278 }
279 .ball-rotate > div:first-child {
280     animation: ball-rotate 1s 0s cubic-bezier(.7, -.13, .22, .86) infinite;
281 }
282 .ball-rotate > div:before, .ball-rotate > div:after {
283     background-color: #fff;
284     width: 30px;
285     height: 30px;
286     border-radius: 100%;
287     margin: 4px;
288     content: ""!important;
289     position: absolute;
290     opacity: .8;
291 }
292 .ball-rotate > div:before {top: 0px;left: -56px}
293 .ball-rotate > div:after {top: 0px;left: 50px}
294 </style>