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