PageSourceSearch

https://www.ababbb.com/wp-content/themes/b2/Assets/fontend/main.js?ver=4.2.6

js ababbb.com collected 2026-10-06 13:15:37 UTC 163,902 bytes, 5,154 lines download raw bytes

1//挂载axios
2axios.defaults.timeout = 300000;
3Vue.prototype.$http = axios //需要鉴权
4Vue.prototype.$https = axios //不需要鉴权
5Vue.prototype.$b2JsonData = []
6var b2_rest_url = b2_global.rest_url+'b2/v1/'
7
8const b2timedom = document.querySelectorAll('.b2timeago');
9
10if(b2timedom.length > 0){
11    timeago.render(b2timedom, b2_global.language);
12}
13
14var b2zoom = new Zooming({enableGrab:true,scrollThreshold:0,transitionDuration:0.2,scaleBase:0.96,scaleExtra:1,customSize:'100%'});
15
16var B2ClientWidth = document.body.clientWidth;
17
18const b2token = b2getCookie('b2_token')
19
20var lazyLoadInstance = new LazyLoad({
21    elements_selector: ".lazy",
22    threshold: 0,
23});
24
25if(b2token){
26    Vue.prototype.$http.defaults.headers.common['Authorization'] = 'Bearer ' + b2token
27}
28
29Vue.prototype.$store = new Vuex.Store({
30    state: {
31      userData: '',
32      userRole:'',
33      announcement:'',
34      oauthLink:'',
35      openOauth:false,
36      authorData:'',
37      carts:{},
38      _carts:{},
39      canImg:false,
40      xieyi:0
41    },
42    mutations: {
43      setUserData (state,data) {
44        state.userData = data
45      },
46      setUserRole (state,data) {
47        state.userRole = data
48      },
49      setAnnouncement (state,data) {
50        state.announcement = data
51      },
52      setOauthLink(state,data){
53        state.oauthLink = data
54      },
55      setOpenOauth(state,data){
56        state.openOauth = data
57      },
58      setauthorData(state,data){
59        state.authorData = data
60      },
61      setcartsData(state,data){
62        state.carts = data
63      },
64      set_cartsData(state,data){
65        state._carts = data
66      },
67      setcanImage(state,data){
68          state.canImg = data
69      }
70    }
71})
72
73var passiveSupported = false;
74
75try {
76  var options = Object.defineProperty({}, "passive", {
77    get: function() {
78      passiveSupported = true;
79    }
80  });
81
82  window.addEventListener("test", null, options);
83} catch(err) {}
84
85
86b2WidgetImageLoaded()
87
88function b2WidgetImageLoaded(){
89    imagesLoaded( document.querySelectorAll('.widget-area'), function( instance ) {
90        b2SidebarSticky()
91    });
92}
93
94function b2isWeixin() { //判断是否是微信
95    var ua = navigator.userAgent.toLowerCase();
96    return ua.match(/MicroMessenger/i) == "micromessenger";
97};
98
99document.ready = function (callback) {
100    ///兼容FF,Google
101    if (document.addEventListener) {
102        document.addEventListener('DOMContentLoaded', function () {
103            document.removeEventListener('DOMContentLoaded', arguments.callee, false);
104            callback();
105        }, passiveSupported ? { passive: true } : false)
106    }
107     //兼容IE
108    else if (document.attachEvent) {
109        document.attachEvent('onreadystatechange', function () {
110              if (document.readyState == "complete") {
111                    document.detachEvent("onreadystatechange", arguments.callee);
112                    callback();
113               }
114        })
115    }
116    else if (document.lastChild == document.body) {
117        callback();
118    }
119}
120
121var topsearch = new Vue({
122    el:'.top-search',
123    data:{
124        type:'post',
125        data:'',
126        show:false,
127        b2token:false
128    },
129    mounted(){
130        if(!this.$refs.topsearch) return
131        this.b2token = b2token
132        const s = this.$refs.topsearch.getAttribute('data-search')
133        this.data = JSON.parse(s)
134
135        if(b2GetQueryVariable('type') && b2GetQueryVariable('s')){
136            this.type = b2GetQueryVariable('type')
137        }else{
138            this.type = Object.keys(this.data)[0]
139        }
140    }
141})
142
143var mobileMenu = new Vue({
144    el:'#mobile-menu-button',
145    data:{
146        show:false,
147        b2token:false
148    },
149    mounted(){
150        if(B2ClientWidth >= 768) return
151        this.b2token = b2token
152        this.dorpMenu()
153    },
154    methods:{
155        dorpMenu(){
156            let drop = document.querySelectorAll('.has_children .b2-arrow-down-s-line')
157            if(drop.length > 0){
158                for (let index = 0; index < drop.length; index++) {
159                    drop[index].onclick = (event)=>{
160                        event.stopPropagation()
161                        event.preventDefault()
162                        if(event.target.parentNode.parentNode.className.indexOf(' show') == -1){
163                            this.hideAll()
164                            event.target.parentNode.parentNode.className += ' show'
165                        }else{
166                            this.hideAll()
167                        }
168                    }
169                }
170            }
171        },
172        hideAll(){
173            let sub = document.querySelectorAll('.has_children .sub-menu')
174            for (let i = 0; i < sub.length; i++) {
175                sub[i].parentNode.className = sub[i].parentNode.className.replace(' show','')
176            }
177        },
178        showMenu(val){
179            const menu = document.querySelector('#mobile-menu')
180                body = document.querySelector('html')
181            if(val){
182                menu.className += ' show-menu-box'
183                body.className += ' m-open'
184                //bodyScrollLock.lock(this.$refs.MobileMenu)
185                this.show = true
186            }else{
187                menu.className = menu.className.replace(' show-menu-box','')
188                setTimeout(() => {
189                    body.className = body.className.replace(' m-open','')
190                }, 300);
191                //bodyScrollLock.unlock(this.$refs.MobileMenu)
192                this.show = false
193            }
194        },
195        showAc(){
196            this.show = !this.show
197            this.showMenu(this.show)
198        }
199    }
200})
201
202Vue.component('search-box', {
203    props: ['show','searchType'],
204    template:b2_global.search_box,
205    data(){
206        return{
207            showSearch:false,
208            type:'post'
209        }
210    },
211    mounted(){
212        const search = document.querySelector('.top-search')
213        if(search){
214            const data = search.getAttribute('data-search');
215
216            if(data){
217                let json = JSON.parse(data)
218                this.type = Object.keys(json)[0]
219
220            }
221
222        }
223    },
224    methods:{
225        close(){
226            this.$emit('close')
227        }
228    },
229    watch:{
230        searchType(val){
231            this.type = val
232        }
233    }
234})
235
236var b2SearchBox = new Vue({
237    el:'#search-box',
238    data:{
239        searchType:'all',
240        show:false
241    },
242    methods:{
243        close(){
244            this.show = !this.show
245        }
246    }
247})
248
249var userTools = new Vue({
250    el:'.top-user-info',
251    data:{
252        showDrop:false,
253        role:{
254            write:true,
255            newsflashes:false,
256            binding_login:false,
257            create_circle:false,
258            create_topic:false,
259            distribution:false,
260            user_data:''
261        },
262        b2token:false
263    },
264    computed:{
265        userData(){
266            return this.$store.state.userData;
267        }
268    },
269    mounted() {
270        this.b2token = b2token
271
272        document.onclick = (e)=>{
273            this.hideAction()
274        }
275
276        if(b2token){
277
278            let footer_text = document.querySelector('#footer-menu-user');
279            if(footer_text){
280                footer_text.innerText = b2_global.js_text.global.my;
281            }
282
283            this.$http.post(b2_rest_url +'getUserInfo').then(res=>{
284                this.role = res.data
285
286                this.$store.commit('setUserRole', res.data)
287                this.$store.commit('setUserData', res.data.user_data)
288                this.$store.commit('setcanImage', res.data.can_img)
289                b2AsideBar.count = res.data.carts
290
291                topMenuLeft.count = res.data.msg_unread
292
293                b2bindLogin.type = res.data.binding_login
294                payCredit.user.credit = res.data.user_data.credit
295
296                this.$nextTick(()=>{
297                    b2tooltip('.user-tips')
298                    lazyLoadInstance.update()
299                })
300
301            }).catch(err=>{
302                this.loginOut()
303            })
304        }else{
305            this.$https.get(b2_rest_url+'getOauthLink').then(res=>{
306                this.$store.commit('setOauthLink',res.data)
307                this.$nextTick(()=>{
308                    lazyLoadInstance.update()
309                })
310                
311            })
312            let ref = b2GetQueryVariable('ref')
313            if(ref){
314                b2setCookie('ref',ref)
315            }
316
317        }
318
319    },
320    methods: {
321        hideAction(){
322            this.showDrop = false
323            if(typeof b2Comment !== 'undefined'){
324                b2Comment.show.smile = false
325                b2Comment.show.image = false
326            }
327
328            if(typeof b2infomation !== 'undefined'){
329                b2infomation.showFliter = false
330            }
331
332            if(typeof b2TaxTop !== 'undefined'){
333                b2TaxTop.showFliter.hot = false
334                b2TaxTop.showFliter.cat = false
335            }
336
337            if(typeof topsearch !== 'undefined'){
338                topsearch.show = false
339            }
340
341            if(typeof writeHead !== 'undefined'){
342                Qmsg.closeAll()
343            }
344
345            if(typeof b2CirclePostBox !== 'undefined'){
346                b2CirclePostBox.ask.focus = false
347                if(b2CirclePostBox.ask.userInput){
348                    b2CirclePostBox.ask.picked = true
349                }
350                b2CirclePostBox.role.show = false
351                b2CirclePostBox.smileShow = false
352            }
353
354            if(typeof poAsk !== 'undefined'){
355                poAsk.ask.focus = false
356                if(poAsk.userInput){
357                    poAsk.ask.picked = true
358                }
359            }
360
361            if(typeof b2CircleList !== 'undefined'){
362                if(!b2CircleList.$refs.topicForm) return
363                if(!b2CircleList.commentBox.content){
364                    if(b2CircleList.$refs.topicForm.value == ''){
365                        b2CircleList.commentBox.focus = false
366                    }
367                    b2CircleList.smileShow = false
368                }
369
370                //b2CircleList.circle.current = b2CircleList.circle.picked.type
371                b2CircleList.circle.showBox = ''
372                b2CircleList.topicFliter.show = false
373                b2CircleList.answer.showSmile = false
374            }
375
376            b2AsideBar.close()
377        },
378        login(type){
379            login.show = true
380            login.loginType = type
381        },
382        showDropMenu(){
383            this.showDrop = !this.showDrop
384        },
385        loginOut(){
386            axios.get(b2_rest_url+'loginOut').then(res=>{
387                b2delCookie('b2_token')
388                b2CurrentPageReload()
389            }).catch(err=>{
390                b2delCookie('b2_token')
391                b2CurrentPageReload()
392            })
393        },
394        out(){
395            this.loginOut()
396        },
397        // goLinkRegisterPage(){
398        //     if(!b2token){
399        //         this.login(1)
400        //         return
401        //     }
402        // },
403        goUserPage(type){
404            if(type === 'back'){
405                window.location = b2getCookie('b2_back_url')
406
407            }else
408            if(type){
409                if(!b2token){
410                    this.login(1)
411                    return
412                }
413                window.location = this.$store.state.userData.link+'/'+type
414            }else{
415                if(!b2token){
416                    this.login(1)
417                    return
418                }
419                window.location = this.$store.state.userData.link
420            }
421        }
422    },
423})
424
425var topMenuLeft = new Vue({
426    el:'.change-theme',
427    data:{
428        theme:'light',
429        count:0,
430        login:false
431    },
432    mounted(){
433        if(b2token){
434            this.login = true
435        }
436    },
437    methods:{
438        changeTheme(type){
439            this.theme = type
440        },
441        showBox(){
442            postPoBox.show = true
443        },
444        go(type){
445            if(type === 'orders'){
446                if(b2token){
447                    window.location.href = this.$store.state.userData.link+'/orders'
448                }else{
449                    login.show = true
450                    login.loginType = 1
451                }
452            }
453            if(type === 'requests'){
454                if(b2token){
455                    window.location.href = b2_global.home_url+'/requests'
456                }else{
457                    login.show = true
458                    login.loginType = 1
459                }
460            }
461        }
462    }
463})
464
465var headerTools = new Vue({
466    el:'.header-tools',
467    computed:{
468        userData(){
469            return this.$store.state.userData;
470        }
471    },
472    methods:{
473        showSearch(){
474            b2SearchBox.close()
475        },
476    }
477})
478
479//登陆与注册
480Vue.component('login-box', {
481    props: ['show','allowRegister','checkType','loginType','loginText','invitation','invitationLink','invitationText','imgBoxCode'],
482    template:b2_global.login,
483    data(){
484        return {
485            data:{
486                'nickname':'',
487                'username':'',
488                'password':'',
489                'code':'',
490                'img_code':'',
491                'invitation_code':'',
492                'token':'',
493                'smsToken':'',
494                'luoToken':'',
495                'confirmPassword':'',
496                'loginType':''
497            },
498            invitationPass:false,
499            eye:false,
500            codeImg:'',
501            locked:false,
502            showLuo:false,
503            issetLuo:false,
504            imgLocked:false,
505            SMSLocked:false,
506            count:60,
507            repass:false,
508            type:'',
509            isWeixin:false,
510        }
511    },
512    computed:{
513        oauth(){
514            return this.$store.state.oauthLink
515        },
516        openOauth(){
517            return this.$store.state.openOauth
518        }
519    },
520    created(){
521        window.getResponse = (resp) => {
522            if(this.type == 'edit'){
523                b2AuthorEdit.sendCode(resp)
524                recaptcha.close()
525            }else{
526                this.data.img_code = resp
527                this.$nextTick(()=>{
528                    recaptcha.close()
529                    this.sendSMS()
530                })
531            }
532        }
533
534        this.isWeixin = b2isWeixin()
535    },
536    methods:{
537        close(val){
538            this.$emit('close-form',val)
539        },
540        loginAc(val){
541            this.$emit('login-ac',val)
542        },
543        loginSubmit(e){
544            e.preventDefault()
545
546            if(this.locked == true) return
547            this.locked = true
548
549            //邀请码
550            if(this.invitation != 0 && (this.loginType == 2 && !this.invitationPass)){
551                this.invitationCheck()
552            }else if(this.loginType == 1){
553                //登录
554                this.$https.post(b2_global.rest_url+'jwt-auth/v1/token',Qs.stringify(this.data)).then(res=>{
555 
556                    b2CurrentPageReload()
557                    return
558
559                }).catch(err=>{
560                    Qmsg['warning'](err.response.data.message,{html:true,timeout:10000});
561                    this.locked = false
562                })
563
564            }else if(this.loginType == 2){
565                //注册
566                this.$https.post(b2_rest_url+'regeister',Qs.stringify(this.data)).then(res=>{
567                    b2CurrentPageReload()
568
569                    return
570
571                }).catch(err=>{
572
573                    Qmsg['warning'](err.response.data.message,{html:true});
574                    this.locked = false
575                })
576            }else if(this.loginType == 3){
577                this.$https.post(b2_rest_url+'forgotPass',Qs.stringify(this.data)).then(res=>{
578                    this.loginAc(4)
579                    this.locked = false
580                }).catch(err=>{
581
582                    Qmsg['warning'](err.response.data.message,{html:true});
583                    this.locked = false
584                })
585            }else if(this.loginType == 4){
586                this.$https.post(b2_rest_url+'resetPass',Qs.stringify(this.data)).then(res=>{
587                    this.repass = true
588                    this.data.password = ''
589                    this.loginAc(1)
590                    this.locked = false
591                }).catch(err=>{
592
593                    Qmsg['warning'](err.response.data.message,{html:true});
594                    this.locked = false
595                })
596            }
597        },
598        b2IsPhoneAvailable(val){
599            if(b2IsPhoneAvailable(val)) return true
600            return false
601        },
602        invitationCheck(){
603            this.$https.post(b2_rest_url+'invitationCheck','code='+this.data.invitation_code).then(res=>{
604                this.invitationPass = true
605                this.locked = false
606                this.showLuo = true
607            }).catch(err=>{
608
609                Qmsg['warning'](err.response.data.message,{html:true});
610                this.locked = false
611            })
612        },
613        sendCode(){
614            recaptcha.show = true
615            this.close(false)
616        },
617        getCode(){
618            if(this.imgLocked) return
619            this.codeImg = ''
620            this.imgLocked = true
621            this.$https.post(b2_rest_url+'getRecaptcha','number=4&width=186&height=50').then(res=>{
622                if(res.data){
623                    this.codeImg = res.data.base
624                    this.data.token = res.data.token
625                }
626                this.imgLocked = false
627            }).catch(err=>{
628
629                Qmsg['warning'](err.response.data.message,{html:true});
630                this.imgLocked = false
631            })
632        },
633        changeCode(){
634            this.getCode()
635        },
636        isEmail(email){
637
638            var pattern= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
639            return pattern.test(email);
640
641        },
642        checkTips(){
643            let text = ''
644
645            if(this.checkType == 'tel'){
646                text = b2_global.js_text.global.check_type.tel
647            }
648
649            if(this.checkType == 'email'){
650                text = b2_global.js_text.global.check_type.mail
651            }
652
653            if(this.checkType == 'telandemail'){
654                if(this.isEmail(this.data.username)){
655                    text = b2_global.js_text.global.check_type.mail
656                }else{
657                    text = b2_global.js_text.global.check_type.tel
658                }
659
660            }
661
662            if(text){
663                Qmsg.info(b2_global.js_text.global.check_message,{
664                    showClose:true,
665                    autoClose:false
666                })
667            }
668        },
669        sendSMS(){
670            if(this.SMSLocked) return
671            this.SMSLocked = true
672            this.data.loginType = this.loginType
673            this.$https.post(b2_rest_url+'sendCode',Qs.stringify(this.data)).then(res=>{
674                if(res.data.token){
675                    this.data.smsToken = res.data.token
676                }
677                this.SMSLocked = false
678                this.countdown()
679
680                this.checkTips()
681
682
683            }).catch(err=>{
684
685                Qmsg['warning'](err.response.data.message,{html:true});
686                this.SMSLocked = false
687            })
688        },
689        markHistory(mp,e){
690            if(!this.$store.state.xieyi && this.loginType == 2){
691                e.preventDefault();
692                Qmsg['warning'](b2_global.js_text.global.xieyi,{html:true});
693                return
694            }
695            if(mp){
696                this.close()
697                mpCode.show = true
698                mpCode.type = this.loginType
699            }
700            b2setCookie('b2_back_url',window.location.href)
701        },
702        countdown(){
703            if(this.count <= 1 ){
704                this.count = 60
705                return
706            }
707            this.count --
708            setTimeout(()=>{
709                this.countdown()
710            },1000)
711        },
712        resetPssNext(){
713            this.loginAc(4)
714        }
715    },
716    watch:{
717        oauth(val){
718            if(val){
719                Object.keys(val).forEach((key)=>{
720                    if(val[key].open){
721                        this.$store.commit('setOpenOauth',true)
722                    }
723                });
724
725                if(b2isWeixin() && b2_global.wx_mp_in_login == 1){
726                    if(!b2token && document.querySelector('#open-page') === null){
727                        b2setCookie('b2_back_url',window.location.href)
728                        window.location.href = this.oauth.weixin.url
729                    }
730                }
731            }
732        },
733        loginType(val){
734            if((this.invitation == 0 || this.invitationPass) && val == 2){
735                this.showLuo = true
736            }else{
737                this.showLuo = false
738            }
739
740            if(this.issetLuo){
741                LUOCAPTCHA && LUOCAPTCHA.reset()
742            }
743        },
744        invitationPass(val){
745            if(this.issetLuo && val){
746                setTimeout(()=>{
747                    LUOCAPTCHA && LUOCAPTCHA.reset()
748                },100)
749            }
750        },
751        show(val){
752            if(val && this.checkType == 'text'){
753                this.getCode()
754                this.type = ''
755            }
756        },
757        imgBoxCode(val){
758            this.data.img_code = val.value
759            this.data.token = val.token
760        },
761        showLuo(val){
762            if(this.show && this.checkType == 'luo' && val && !this.issetLuo){
763                let s = document.createElement('script')
764                s.id = 'luosimao'
765                s.type = 'text/javascript'
766                s.src = '//captcha.luosimao.com/static/dist/api.js'
767                document.getElementsByTagName("head")[0].appendChild(s)
768                this.issetLuo = true
769            }
770        }
771    }
772})
773
774Vue.component('mp-box', {
775    props:['show','invitation','invitationLink','invitationText'],
776    template:b2_global.mp_box,
777    data(){
778        return{
779            code:'',
780            locked:false,
781            token:false,
782            invitationCode:'',
783            locked:false,
784            qrcode:'',
785            t:false,
786            count:100
787        }
788    },
789    computed:{
790        oauthLink(){
791            return this.$store.state.oauthLink
792        }
793    },
794    methods:{
795        close(){
796            this.$emit('close')
797            this.t = null
798        },
799        submit(){
800
801            if(this.locked == true) return
802            this.locked = true
803
804            if(this.count <= 1 || this.t === null){
805                this.t = null
806                this.count = 100
807                return
808            }
809
810            this.$http.post(b2_rest_url+'mpLogin','code='+this.code).then(res=>{
811
812                if(res.data === 'waiting'){
813                    this.locked = false
814                    this.t = setTimeout(()=>{
815                        this.submit()
816                    },1000)
817                    return
818                }
819
820                if(res.data.type === 'invitation'){
821                    this.token = res.data.token
822                }else{
823                    if(res.data === true){
824                        b2CurrentPageReload()
825                    }else{
826                        this.$store.commit('setUserData', res.data)
827
828                        Vue.prototype.$http.defaults.headers.common['Authorization'] = 'Bearer ' + b2token
829                        b2CurrentPageReload()
830
831                    }
832                }
833                this.t = null
834                this.locked = false
835            }).catch(err=>{
836
837                Qmsg['warning'](err.response.data.message,{html:true});
838                this.locked = false
839            })
840        },
841        checkInv(){
842            if(this.locked == true) return
843            this.locked = true
844
845            this.$https.post(b2_rest_url+'mpLoginInv','token='+this.token+'&inv='+this.invitationCode).then(res=>{
846                if(res.data.token){
847                    b2CurrentPageReload()
848                }
849                this.locked = false
850            }).catch(err=>{
851
852                Qmsg['warning'](err.response.data.message,{html:true});
853                this.locked = false
854            })
855        },
856        getQrcode(){
857            this.$https.post(b2_rest_url+'getLoginQrcode').then(res=>{
858                this.code = res.data.sence_id
859                this.qrcode = res.data.qrcode
860                this.submit()
861            }).catch(err=>{
862
863                Qmsg['warning'](err.response.data.message,{html:true});
864            })
865        }
866    },
867    watch:{
868        show(val){
869            if(val){
870
871                if(this.oauthLink.weixin.pc_open){
872                    b2loadScript('https://res.wx.qq.com/connect/zh_CN/htmledition/js/wxLogin.js','',()=>{
873                        new WxLogin({
874                            self_redirect:false,
875                            id:"mp-login-box",
876                            appid: b2_global.wx_appid,
877                            scope: "snsapi_login",
878                            redirect_uri: b2_global.home_url+'/open?type=weixin',
879                            state: "",
880                            style: "black",
881                            href: "data:text/css;base64,LmltcG93ZXJCb3ggLnFyY29kZSB7DQogICAgd2lkdGg6IDEwMCU7DQogICAgbWFyZ2luLXRvcDogMDsNCiAgICBib3JkZXI6IDA7DQp9DQouaW1wb3dlckJveCAuaW5mbyB7DQogICAgZGlzcGxheTogbm9uZTsNCn0NCi5pbXBvd2VyQm94IC50aXRsZXsNCmRpc3BsYXk6bm9uZQ0KfQ=="
882                        });
883                    })
884                }else{
885                    this.locked = false
886                    this.t = false
887                    this.count = 100
888                    this.getQrcode()
889                }
890            }
891        }
892    }
893})
894
895var mpCode = new Vue({
896    el:'#mp-box',
897    data:{
898        show:false,
899        qrcode:'',
900        type:'1',
901    },
902    methods:{
903        close(){
904            this.show = !this.show
905            if(!b2token){
906                login.show = true
907                login.loginType = this.type
908            }
909        }
910    }
911})
912
913var login = new Vue({
914    el:'#login-box',
915    data:{
916        show:false,
917        loginType:1,
918        checkCodeSendSuccess:false,
919        isAdmin:false,
920        imgCode:''
921    },
922    methods:{
923        close(val){
924            this.show = val
925        },
926        loginAc(val){
927            this.loginType = val
928        },
929        imgCodeAc(val){
930            this.imgCode = val
931        }
932    }
933})
934
935//验证码组件
936Vue.component('recaptcha-box', {
937    props: ['show','type'],
938    template:b2_global.check_code,
939    data(){
940        return {
941            recaptcha:'',
942            token:'',
943            recaptchaUrl:'',
944            disabled:true,
945            issetLuo:false,
946            locked:false,
947            loginType:2,
948            checkType:b2_global.check_type,
949        }
950    },
951    methods:{
952        close(){
953            this.$emit('close-form')
954        },
955        change(){
956            //获取验证码base64及token
957            if(this.locked) return
958            this.recaptchaUrl = ''
959            this.locked = true
960            this.$https.post(b2_rest_url+'getRecaptcha','number=4&width=186&height=50').then(res=>{
961                if(res.data){
962                    this.recaptchaUrl = res.data.base
963                    this.token = res.data.token
964                }
965                this.locked = false
966            }).catch(err=>{
967
968                Qmsg['warning'](err.response.data.message,{html:true});
969                this.locked = false
970            })
971        },
972        checkCode(){
973            if(this.disabled) return
974            this.disabled = true
975            this.$https.post(b2_rest_url+'imgCodeCheck','img_code='+this.recaptcha+'&token='+this.token+'&loginType='+login.loginType).then(res=>{
976
977                if(this.type == 'edit'){
978                    b2AuthorEdit.imgCodeAc({
979                        value:this.recaptcha,
980                        token:this.token
981                    })
982                }else if(this.type == 'bind'){
983                    b2bindLogin.imgCodeAc({
984                        value:this.recaptcha,
985                        token:this.token
986                    })
987                }else{
988                    login.imgCodeAc({
989                        value:this.recaptcha,
990                        token:this.token
991                    })
992                    setTimeout(()=>{
993                        login.$refs.loginBox.sendSMS()
994                    },50)
995                }
996
997                this.disabled = false
998                this.close()
999
1000
1001            }).catch(err=>{
1002
1003                Qmsg['warning'](err.response.data.message,{html:true});
1004                this.disabled = false
1005            })
1006        }
1007    },
1008    watch:{
1009        show(val){
1010            if(val && b2_global.check_type == 'normal'){
1011                this.change()
1012            }
1013            if(val && !this.issetLuo && login.loginType != 3){
1014                let s = document.createElement('script')
1015                s.id = 'luosimao'
1016                s.type = 'text/javascript'
1017                s.src = '//captcha.luosimao.com/static/dist/api.js?time='+((new Date()).getTime())
1018                document.getElementsByTagName("head")[0].appendChild(s)
1019                this.issetLuo = true
1020            }else if(val && this.issetLuo && login.loginType != 3){
1021                LUOCAPTCHA && LUOCAPTCHA.reset()
1022            }
1023
1024            if(this.type != 'edit'){
1025                this.loginType = login.loginType
1026            }
1027
1028
1029        },
1030        recaptcha(val){
1031            if(val.length == 4){
1032                this.disabled = false
1033            }else{
1034                this.disabled = true
1035            }
1036        }
1037    }
1038})
1039
1040var recaptcha = new Vue({
1041    el:'#recaptcha-form',
1042    data:{
1043        show:false,
1044        type:''
1045    },
1046    methods:{
1047        close(){
1048            this.show = false
1049            if(this.type != 'edit' && this.type != 'bind'){
1050                login.show = true
1051            }
1052            if(this.type === 'bind'){
1053                b2bindLogin.show = true
1054            }
1055        },
1056    }
1057})
1058
1059function indexPostModules(){
1060    let m = document.querySelectorAll('.post-list');
1061    if(m.length > 0){
1062        for (let i = 0; i < m.length; i++) {
1063            let key = m[i].getAttribute('data-key')
1064
1065            if(m[i].id != 'undefined'){
1066                new Vue({
1067                    el:'#post-item-'+key,
1068                    data:{
1069                        key:0,
1070                        index:0,
1071                        box:'',
1072                        paged:1,
1073                        pages:0,
1074                        type:'cat',
1075                        showButton:false,
1076                        locked:false,
1077                        cat:[],
1078                        finish:false,
1079                        id:0
1080                    },
1081                    mounted(){
1082                        if(this.$el.querySelector('.load-more')){
1083                            this.key = key
1084                            this.index = this.$el.getAttribute('data-i')
1085                            this.box = this.$el.querySelectorAll('.b2_gap')[0]
1086                            this.showButton = this.$el.querySelector('.load-more').getAttribute('data-showButton')
1087                        }
1088                    },
1089                    methods:{
1090                        getList(id,type,postType){
1091
1092                            if(this.finish && type == 'more'){
1093                                return
1094                            }else{
1095                                this.finish = false
1096                            }
1097
1098                            if(this.locked) return
1099                            this.locked = true
1100
1101                            this.id = id
1102
1103                            if(type){
1104                                this.type = type
1105                            }
1106
1107                            if(this.type == 'cat'){
1108                                this.paged = 1;
1109                                if(id){
1110                                    this.cat = [id]
1111                                }else{
1112                                    this.cat = []
1113                                }
1114                                this.finish = false
1115                            }else{
1116                                this.paged = this.paged + 1
1117                            }
1118
1119                            let data = {
1120                                'index':this.index,
1121                                'id':this.cat,
1122                                'post_paged':this.paged
1123                            }
1124                            axios.post(b2_rest_url+'getModulePostList',Qs.stringify(data)).then(res=>{
1125                                if(res.data.count > 0){
1126                                    this.pages = res.data.pages
1127                                    if(this.type == 'cat'){
1128                                        if(this.pages == 1){
1129                                            this.box.innerHTML = res.data.data
1130                                        }else{
1131                                            this.box.innerHTML = res.data.data
1132                                        }
1133
1134                                        if(postType  == 'post-2'){
1135                                           b2PackeryLoad()
1136                                        }
1137                                        this.showButton = true
1138                                    }else if(this.type == 'more'){
1139                                        this.box.insertAdjacentHTML('beforeend', res.data.data)
1140                                        if(postType  == 'post-2'){
1141                                            b2PackeryLoad()
1142                                         }
1143                                        this.showButton = true
1144                                    }
1145
1146                                    if(this.paged >= this.pages ){
1147                                        this.finish = true
1148                                    }
1149                                }else{
1150                                    if(postType  == 'post-6'){
1151                                        this.box.innerHTML = '<tr><td colspan="10" style="border:0">'+b2_global.empty_page+'</td></tr>'
1152                                    }else{
1153                                        this.box.innerHTML = b2_global.empty_page
1154                                    }
1155                                    this.showButton = false
1156                                }
1157                                this.locked = false
1158                                b2SidebarSticky()
1159                                this.$nextTick(()=>{
1160                                    lazyLoadInstance.update()
1161                                })
1162                            })
1163                        }
1164                    }
1165                })
1166            }
1167        }
1168    }
1169}
1170indexPostModules()
1171
1172//遍历dom树,依次添加 is-visible 类,使其支持渐变显示
1173function listFadein(dom,time){
1174    return
1175    var i = 0
1176    dom.forEach(e=>{
1177        if(e.className.indexOf('is-visible') === -1){
1178            i++
1179            if(i== 1){
1180                e.className += ' is-visible'
1181            }else{
1182                setTimeout(function(){
1183                    e.className += ' is-visible'
1184                }, i*time )
1185            }
1186        }
1187    })
1188}
1189listFadein(document.querySelectorAll('.post-list ul.b2_gap > li'),10)
1190
1191//加载瀑布流
1192function b2PackeryLoad(e){
1193    var grid = document.querySelectorAll('.grid')
1194    if(grid.length > 0){
1195        for (let index = 0; index < grid.length; index++) {
1196           let pack = new Packery( grid[index])
1197
1198            pack.on( 'layoutComplete', ()=>{
1199                b2SidebarSticky()
1200            });
1201        }
1202    }
1203}
1204b2PackeryLoad()
1205
1206//新版分页
1207//type p 分页加载,m 下拉加载
1208Vue.component('pagenav-new',{
1209    props: ['type','paged','pages','opt','api','rote'],
1210    template: b2_global.page_nav,
1211    data:function(){
1212        return {
1213            locked:false,
1214            next:false,
1215            per:false,
1216            cpage:0,
1217            cpaged:1,
1218            cpages:[],
1219            mobile:false,
1220            showGo:false
1221        }
1222    },
1223    created(){
1224        window.addEventListener('scroll', _debounce(this.autoLoadMore),passiveSupported ? { passive: true } : false)
1225        this.cpaged = parseInt(this.paged)
1226        this.cpages = this.pagesInit()
1227        //监听前进与后退
1228        window.addEventListener("popstate", ()=>{
1229            let state = history.state;
1230            if(state && state.page && this.type == 'p'){
1231                this.go(state.page)
1232            }
1233        },passiveSupported ? { passive: true } : false);
1234        this.mobile = B2ClientWidth > 768 ? false : true
1235    },
1236    methods:{
1237        disabled(page){
1238            return page == this.cpaged && this.locked == true
1239        },
1240        pagesInit(){
1241            let pagearr = []
1242            if(this.pages <= 6){
1243                for (let i = 1; i <= this.pages; i++) {
1244                    pagearr.push(i)
1245                }
1246            }else{
1247                if(!this.cpaged) this.cpaged = this.paged
1248                if(this.cpaged < 4){
1249                    for (let i = 1; i <= this.pages; i++) {
1250                        if(i >= 5) break
1251                        pagearr.push(i)
1252                    }
1253                    pagearr.push(0,this.pages)
1254                }else if(this.cpaged >= 4 && this.pages - 2 > this.cpaged){
1255                    pagearr.push(1,0)
1256                    for (let i = this.cpaged - 1; i <= this.cpaged + 1; i++) {
1257                        pagearr.push(i)
1258                    }
1259                    pagearr.push(0,this.pages)
1260                }else if(this.pages - 2 <= this.cpaged){
1261                    pagearr.push(1,0)
1262                    for (let i = this.cpaged - 2; i <= this.pages; i++) {
1263                        pagearr.push(i)
1264                    }
1265                }
1266            }
1267            return pagearr
1268        },
1269        focus(){
1270            this.showGo = true
1271        },
1272        blur(){
1273            setTimeout(() => {
1274                this.showGo = false
1275            }, 100);
1276        },
1277        autoLoadMore(){
1278            if(this.type == 'p') return
1279            if(this.cpaged == this.pages) return;
1280            let scrollTop = document.documentElement.scrollTop;
1281            if(scrollTop + window.innerHeight >= document.body.clientHeight - 550) {
1282                this.go(this.cpaged+1)
1283            }
1284        },
1285        trimSlashes(str){
1286            return str.replace(/\/+$/, '');
1287        },
1288        go(page,type,action){
1289
1290            page = parseInt(page)
1291            if(this.opt.length > 0) return
1292
1293            if(this.cpaged == page && !action) return
1294
1295            if(this.locked == true) return
1296            this.locked = true
1297
1298            if(this.type === 'm' && this.pages <= this.cpaged && page != 1) return
1299
1300            if(type == 'next'){
1301                this.next = true
1302                this.per = false
1303            }else if(type == 'per'){
1304                this.per = true
1305                this.next = false
1306            }
1307
1308            this.cpaged = page
1309
1310            this.opt['post_paged'] = page
1311            this.opt['paged'] = page
1312
1313            this.$http.post(b2_rest_url+this.api,Qs.stringify(this.opt)).then(res=>{
1314
1315                this.locked = false
1316                this.cpages = this.pagesInit()
1317
1318                this.$emit('return',res.data)
1319
1320                if(this.rote){
1321
1322                    let currentURL = window.location.href,
1323                    url = this.trimSlashes(currentURL.split('?')[0]),
1324                    newURL
1325                    console.log(url)
1326                    if(this.cpaged == 1){
1327                        newURL = url.replace(/\/page\/\d/, '');
1328                    }else{
1329                        if(currentURL.indexOf('/page/') == -1){
1330                            newURL = url+'/page/'+this.cpaged
1331                        }else{
1332                            newURL = url.replace(/\/page\/[0-9]*$/, '/page/'+page);
1333                        }
1334                    }
1335
1336                    url = currentURL.replace(url,newURL)
1337
1338                    window.history.pushState({page:page}, null,url )
1339                    if(this.type === 'p'){
1340                        b2AsideBar.goTop()
1341                    }
1342
1343                }
1344
1345                b2SidebarSticky()
1346                this.$nextTick(()=>{
1347                    lazyLoadInstance.update()
1348                })
1349            }).catch(err=>{
1350
1351                Qmsg['warning'](err.response.data.message,{html:true});
1352
1353            })
1354
1355        },
1356        //获取数据
1357        getData(fn,data){
1358            this.cpaged = this.cpage
1359            this.cpages = this.pagesInit()
1360        },
1361        //跳转
1362        jump(event){
1363
1364            var val = event.target.value || event.target.previousElementSibling.value || this.$refs.pagenavnumber.value
1365
1366            val = parseInt(val)
1367          
1368            if(val > this.pages) return
1369        
1370            this.go(val,'p',true)
1371        }
1372    },
1373    watch: {
1374        pages(val){
1375            this.cpages = this.pagesInit()
1376        },
1377        paged(){
1378            this.cpaged = parseInt(this.paged)
1379            this.cpages = this.pagesInit()
1380        }
1381    }
1382})
1383
1384//分页代码
1385Vue.component('page-nav',{
1386    props: ['paged','navtype','pages','type','box','opt','api','url','title'],
1387    template: b2_global.page_nav,
1388    data:function(){
1389        return {
1390            locked:false,
1391            next:false,
1392            per:false,
1393            cpage:0,
1394            cpaged:1,
1395            cpages:[],
1396            mobile:false,
1397            showGo:false
1398        }
1399    },
1400    created(){
1401        window.addEventListener('scroll', _debounce(this.autoLoadMore),passiveSupported ? { passive: true } : false)
1402        this.cpaged = parseInt(this.paged)
1403        this.cpages = this.pagesInit()
1404        //监听前进与后退
1405        window.addEventListener("popstate", ()=>{
1406            let state = history.state;
1407            if(state && state.page && this.type == 'p'){
1408                this.go(state.page)
1409            }
1410        },passiveSupported ? { passive: true } : false);
1411        this.mobile = B2ClientWidth > 768 ? false : true
1412    },
1413    methods:{
1414        disabled(page){
1415            return page == this.cpaged && this.locked == true
1416        },
1417        pagesInit(){
1418            let pagearr = []
1419            if(this.pages <= 7){
1420                for (let i = 1; i <= this.pages; i++) {
1421                    pagearr.push(i)
1422                }
1423            }else{
1424                if(!this.cpaged) this.cpaged = this.paged
1425                if(this.cpaged < 5){
1426                    for (let i = 1; i <= this.pages; i++) {
1427                        if(i >= 6) break
1428                        pagearr.push(i)
1429                    }
1430                    pagearr.push(0,this.pages)
1431                }else if(this.cpaged >= 5 && this.pages - 3 > this.cpaged){
1432                    pagearr.push(1,0)
1433                    for (let i = this.cpaged - 2; i <= this.cpaged + 2; i++) {
1434                        pagearr.push(i)
1435                    }
1436                    pagearr.push(0,this.pages)
1437                }else if(this.pages - 3 <= this.cpaged){
1438                    pagearr.push(1,0)
1439                    for (let i = this.cpaged - 3; i <= this.pages; i++) {
1440                        pagearr.push(i)
1441                    }
1442                }
1443            }
1444            return pagearr
1445        },
1446        autoLoadMore(){
1447            setTimeout(() => {
1448                if(this.type == 'p') return
1449                let scrollTop = document.documentElement.scrollTop;
1450                if(scrollTop + window.innerHeight >= document.body.clientHeight - 550) {
1451                    this.go(this.cpaged+1)
1452                }
1453            }, 300);
1454        },
1455        focus(){
1456            this.showGo = true
1457        },
1458        blur(){
1459            setTimeout(() => {
1460                this.showGo = false
1461            }, 100);
1462
1463        },
1464        go(page,type,action){
1465
1466            page = parseInt(page)
1467            if(this.opt.length > 0) return
1468
1469            if(this.cpaged == page && !action) return
1470            if(this.locked == true) return
1471
1472            if(this.type === 'm' && this.pages <= this.cpaged && page != 1) return
1473
1474            this.locked = true
1475
1476            if(type == 'next'){
1477                this.next = true
1478                this.per = false
1479            }else if(type == 'per'){
1480                this.per = true
1481                this.next = false
1482            }
1483
1484            this.cpaged = page
1485            console.log(this.cpaged)
1486
1487            this.opt['post_paged'] = page
1488            this.opt['paged'] = page
1489
1490            this.$http.post(b2_rest_url+this.api,Qs.stringify(this.opt)).then(res=>{
1491
1492                this.locked = false
1493                this.cpages = this.pagesInit()
1494                let dom = document.querySelector(this.box)
1495
1496                //如果返回的是json数据
1497                if(this.navtype === 'json'){
1498                    this.$emit('return',res.data)
1499                }else{
1500                    if(this.type === 'p'){
1501                        dom.innerHTML = res.data.data
1502                    }else{
1503                        dom.insertAdjacentHTML('beforeend', res.data.data)
1504                    }
1505                }
1506
1507                if(page != 1){
1508                    this.url = b2removeURLParameter(this.url,'action')
1509                }
1510
1511                //变更地址栏和title
1512                if(!!(window.history && history.pushState)){
1513
1514                    if(page != 1){
1515                        if(this.navtype === 'comment'){
1516                            if(b2_global.structure){
1517                                window.history.pushState({page:page}, null, this.url+'/comment-page-'+page+'#comment')
1518                            }else{
1519                                window.history.pushState({page:page}, null, this.url+'&cpage='+page+'#comment')
1520                            }
1521                        }else{
1522                            if(this.navtype != 'authorComments' && this.title){
1523                                document.title = this.title+' '+b2_global.site_separator+' '+(b2_global.page_title.replace('{#}',page))+' '+b2_global.site_separator+' '+b2_global.site_name
1524                            }
1525                            let currentURL = window.location.href,
1526                            url = currentURL.split('?')[0],
1527                            newURL
1528
1529                            if(this.cpaged == 1){
1530                                newURL = url.replace(/\/page\/\d/, '');
1531                            }else{
1532                                if(currentURL.indexOf('/page/') == -1){
1533                                    newURL = url+'/page/'+this.cpaged
1534                                }else{
1535                                    newURL = url.replace(/\/page\/[0-9]*$/, '/page/'+page);
1536                                }
1537                            }
1538
1539                            url = currentURL.replace(url,newURL)
1540
1541                            window.history.pushState({page:page}, null,url )
1542                            if(this.type === 'p'){
1543                                b2AsideBar.goTop()
1544                            }
1545                            
1546                        }
1547
1548                    }else{
1549                        if(this.navtype === 'comment'){
1550                            window.history.pushState({page:page}, null, this.url+'#comment')
1551                        }else{
1552                            if(this.navtype != 'authorComments' && this.title){
1553                                document.title = this.title+' '+b2_global.site_separator+' '+b2_global.site_name
1554                            }
1555
1556                            window.history.pushState({page:page}, null, this.url)
1557                        }
1558                    }
1559
1560                }
1561
1562                if(this.navtype === 'comment' || this.navtype === 'authorComments'){
1563                    let img = document.querySelectorAll('.comment-img-box img');
1564                    if(img.length > 0){
1565                        for (let index = 0; index < img.length; index++) {
1566                            b2zoom.listen(img[index]);
1567                        }
1568                    }
1569                    if(this.navtype === 'comment'){
1570                        b2CommentList.showSticky()
1571                        b2SidebarSticky()
1572                    }
1573                }else if(this.navtype === 'post'){
1574                    b2PackeryLoad()
1575                    //渐显
1576                    setTimeout(()=>{
1577                        listFadein(document.querySelectorAll(this.box+' > li'),20)
1578                    },500)
1579                }
1580                this.$emit('finish')
1581                b2SidebarSticky()
1582                this.$nextTick(()=>{
1583                    lazyLoadInstance.update()
1584                })
1585            }).catch(err=>{
1586
1587                Qmsg['warning'](err.response.data.message,{html:true});
1588
1589            })
1590
1591        },
1592        //获取数据
1593        getData(fn,data){
1594            this.cpaged = this.cpage
1595            this.cpages = this.pagesInit()
1596        },
1597        //跳转
1598        jump(event){
1599
1600            var val = event.target.value || event.target.previousElementSibling.value || this.$refs.pagenavnumber.value
1601
1602            val = parseInt(val)
1603          
1604            if(val > this.pages) return
1605        
1606            this.go(val,'p',true)
1607        }
1608    },
1609    watch: {
1610        pages(val){
1611            this.cpages = this.pagesInit()
1612        },
1613        paged(){
1614            this.cpaged = parseInt(this.paged)
1615            this.cpages = this.pagesInit()
1616        }
1617    }
1618})
1619
1620function b2RestTimeAgo(dom){
1621    if(dom && dom.length > 0)
1622    timeago.render(dom, b2_global.language);
1623}
1624
1625let pageNavBox = new Vue({
1626    el:'.post-nav',
1627    data:{
1628        selecter:'#post-list .b2_gap',
1629        opt:'',
1630        api:'getPostList',
1631        options:[],
1632        value:1,
1633        showGoN:false
1634    },
1635    mounted(){
1636        if(typeof b2_cat !== 'undefined'){
1637            this.opt = b2_cat.opt
1638        }
1639    },
1640    methods:{
1641        jumpAc:function(event){
1642
1643            var val = event.target.value || event.target.previousElementSibling.value || this.$refs.pagenavnumber.value
1644
1645            if(val > this.opt.pages) return
1646
1647            let currentURL = window.location.href,
1648            url = currentURL.split('?')[0],
1649            newURL
1650
1651            if(val == 1){
1652                newURL = url.replace(/\/page\/\d/, '');
1653            }else{
1654                if(currentURL.indexOf('/page/') == -1){
1655                    newURL = url+'/page/'+val
1656                }else{
1657                    newURL = url.replace(/\/page\/[0-9]*$/, '/page/'+val);
1658                }
1659            }
1660
1661            url = currentURL.replace(url,newURL)
1662
1663            window.location.href = url;
1664        },
1665        focus(){
1666            this.showGoN = true
1667        },
1668        blur(){
1669            setTimeout(() => {
1670                this.showGoN = false
1671            }, 100);
1672        },
1673    }
1674})
1675
1676//语音播放
1677let b2Audio = new Vue({
1678    el:'.b2-audio-content',
1679    data:{
1680        url:'',
1681        textList:[],
1682        playStatus:false,
1683        api:'https://tts.baidu.com/text2audio?cuid=baike&lan=ZH&ctp=1&pdt=301&tex=',
1684        index:0,
1685        currentTime:'00:00',
1686        startTime:'00:00',
1687        step:0,
1688        duration:0,
1689        ds:'',
1690        width:'0%'
1691    },
1692    methods:{
1693        play(){
1694            //如果未播放,加载播放列表
1695            if(!this.url){
1696                this.getPlayList()
1697            }else{
1698                this.playList()
1699            }
1700        },
1701        getPlayList(){
1702            this.$https.post(b2_rest_url+'getPostAudio','post_id='+this.$refs.audio.getAttribute('data-id')).then((res)=>{
1703                if(res.data.length > 0){
1704                    this.textList = res.data
1705                    //res.data
1706                    this.playList()
1707                    this.watchPlay()
1708                }
1709            })
1710        },
1711        playList(){
1712            this.url = this.api+this.textList[this.index];
1713            setTimeout(()=>{
1714                this.button()
1715            })
1716        },
1717        watchPlay(){
1718            this.$refs.audio.addEventListener('ended', ()=> {
1719
1720                if(this.index >= this.textList.length - 1) {
1721                    this.playStatus = false
1722                    this.index = 0
1723                    this.step = 0
1724                    return;
1725                }
1726                this.step = 0
1727                this.index = this.index + 1
1728                this.playList()
1729            },passiveSupported ? { passive: true } : false)
1730        },
1731        button(){
1732            if(this.$refs.audio!==null){
1733                if(this.$refs.audio.paused){
1734                    this.$refs.audio.play()
1735                    this.playStatus = true
1736                    this.timeSetp()
1737                }else{
1738                    this.$refs.audio.pause()
1739                    this.playStatus = false
1740                }
1741
1742                this.$refs.audio.addEventListener("loadedmetadata",()=>{
1743                    this.duration = Math.round(this.$refs.audio.duration)
1744                    this.currentTime = this.secondToDate(this.duration)
1745                },passiveSupported ? { passive: true } : false);
1746
1747            }
1748        },
1749        timeSetp(){
1750            if(this.playStatus == true){
1751                this.startTime = this.secondToDate(this.step++)
1752                if(this.ds){
1753                    clearTimeout(this.ds)
1754                }
1755                this.ds = setTimeout(()=>{
1756                    this.timeSetp()
1757                    this.width = this.step/this.duration * 100 + '%'
1758                },1000)
1759            }
1760        },
1761        secondToDate(s){
1762            var t;
1763            if(s > -1){
1764                var hour = Math.floor(s/3600)
1765                var min = Math.floor(s/60) % 60
1766                var sec = s % 60
1767                if(hour > 1){
1768                    if(hour < 10) {
1769                        t = '0'+ hour + ":"
1770                    } else {
1771                        t = hour + ":";
1772                    }
1773                }else{
1774                    t = '';
1775                }
1776
1777                if(min < 10){t += "0"}
1778                t += min + ":";
1779                if(sec < 10){t += "0"}
1780                t += sec.toFixed(0);
1781            }
1782            return t;
1783        }
1784    }
1785})
1786
1787var socialBox = new Vue({
1788    el:'#social-box',
1789    data:{
1790        locked:false,
1791        type:'',
1792        data:{
1793            'token':'',
1794            'invitation':'',
1795            'subType':''
1796        },
1797        error:'',
1798        oauth:'',
1799        name:''
1800    },
1801    mounted(){
1802        if(this.$refs.socialBox){
1803            let code = b2GetQueryVariable('code');
1804                this.type = b2GetQueryVariable('type')
1805            if(code){
1806                this.locked = true
1807                this.$http.post(b2_rest_url+'socialLogin','code='+code+'&type='+this.type).then(res=>{
1808                    this.locked = false
1809                    if(res.data === true){
1810                        this.back()
1811                    }else if(res.data.type == 'invitation'){
1812                        this.type = 'invitation',
1813                        this.data.token = res.data.token
1814                    }else{
1815                        this.back()
1816                    }
1817                }).catch(err=>{
1818                    if(err.response.data.message.msg){
1819                        this.oauth = err.response.data.message.oauth
1820                        this.error = err.response.data.message.msg
1821                        this.name = err.response.data.message.name
1822                    }else{
1823                        this.error = err.response.data.message
1824                    }
1825
1826                    this.locked = false
1827                })
1828            }
1829        }
1830    },
1831    methods:{
1832        back(){
1833            let url = b2getCookie('b2_back_url')
1834
1835            if(url){
1836                window.location.href = url
1837            }else{
1838                window.location.href = b2_global.home_url
1839            }
1840
1841        },
1842        invRegeister(type){
1843            if(this.locked == 'pass' || this.locked == 'sub') return
1844            this.locked = type
1845            this.data.subType = type
1846            this.$http.post(b2_rest_url+'invRegeister',Qs.stringify(this.data)).then(res=>{
1847                this.back()
1848            }).catch(err=>{
1849
1850                Qmsg['warning'](err.response.data.message,{html:true});
1851                this.locked = false
1852            })
1853        },
1854        loginOut(url){
1855            b2delCookie('b2_token')
1856            b2CurrentPageReload(url)
1857
1858        },
1859        rebuild(ev){
1860            this.$http.post(b2_rest_url+'unBuild','type='+this.type+'&user_id='+b2_author.author_id).then(res=>{
1861
1862            }).catch(err=>{
1863                ev.preventDefault();
1864
1865                Qmsg['warning'](err.response.data.message,{html:true});
1866            })
1867        }
1868    }
1869})
1870
1871Vue.component('gg-box', {
1872    props: ['show'],
1873    template: b2_global.gg_box,
1874    computed:{
1875        ggdata(){
1876            return this.$store.state.announcement[0]
1877        }
1878    },
1879    methods:{
1880        close(){
1881            this.$emit('close')
1882        },
1883    }
1884})
1885
1886var b2GG = new Vue({
1887    el:'#gg-box',
1888    data:{
1889        show:false
1890    },
1891    mounted(){
1892        this.$http.post(b2_rest_url+'getLatestAnnouncement','count=3').then(res=>{
1893
1894            if(res.data.length > 0){
1895                this.$store.commit('setAnnouncement',res.data)
1896
1897                this.show = res.data[0].show
1898            }else{
1899                this.$store.commit('setAnnouncement','none')
1900            }
1901
1902
1903        })
1904    },
1905    methods:{
1906        close(){
1907            this.show = false
1908            let timestamp = new Date().getTime()
1909            timestamp = parseInt(timestamp/1000)
1910
1911            b2setCookie('gg_info',timestamp)
1912        }
1913    }
1914})
1915
1916Vue.component('dmsg-box', {
1917    props: ['show','userid','type'],
1918    template: b2_global.dmsg_box,
1919    data(){
1920        return {
1921            user:[],
1922            content:'',
1923            locked:false,
1924            nickname:'',
1925            UserList:[],
1926            search:false
1927        }
1928    },
1929    methods:{
1930        close(){
1931            this.$emit('close')
1932            setTimeout(()=>{
1933                this.user = []
1934                this.content = ''
1935                this.nickname = ''
1936                this.UserList = []
1937            },100)
1938        },
1939        getUserData(id = 0){
1940            id = !id ? this.userid : id
1941            this.$http.post(b2_rest_url+'getUserPublicData','user_id='+id).then(res=>{
1942                this.user = res.data
1943                b2Dmsg.userid = id
1944                b2Dmsg.select = ''
1945                this.UserList = []
1946            }).catch(err=>{
1947
1948                Qmsg['warning'](err.response.data.message,{html:true});
1949            })
1950        },
1951        edit(){
1952            b2Dmsg.select = 'select'
1953        },
1954        send(){
1955            if(this.locked == true) return
1956            this.locked = true
1957            this.$http.post(b2_rest_url+'sendDirectmessage','user_id='+this.userid+'&content='+this.content).then(res=>{
1958                if(res.data == true){
1959                    this.close()
1960                }
1961                if(b2DmsgPage.$refs.dmsgPage){
1962                    b2DmsgPage.getList()
1963                }
1964                this.locked = false
1965            }).catch(err=>{
1966
1967                Qmsg['warning'](err.response.data.message,{html:true});
1968                this.locked = false
1969            })
1970        },
1971        searchUser(val){
1972            if(this.locked == true) return
1973            this.locked = true
1974            this.search = true
1975            this.$http.post(b2_rest_url+'searchUsers','nickname='+val).then(res=>{
1976                if(res.data.length > 0){
1977                    this.UserList = res.data
1978                }else{
1979                    this.UserList = []
1980                }
1981                this.locked = false
1982            }).catch(err=>{
1983
1984                Qmsg['warning'](err.response.data.message,{html:true});
1985                this.locked = false
1986                this.UserList = []
1987            })
1988        }
1989    },
1990    watch:{
1991        show(val){
1992            if(val && this.type !== 'select'){
1993                this.getUserData()
1994            }
1995        },
1996        nickname(val){
1997            if(val){
1998                this.searchUser(val);
1999            }
2000        }
2001    }
2002})
2003
2004var b2Dmsg = new Vue({
2005    el:'#dmsg-box',
2006    data:{
2007        userid:0,
2008        show:false,
2009        select:''
2010    },
2011    methods:{
2012        close(){
2013            this.show = !this.show
2014        }
2015    }
2016})
2017
2018var b2DmsgPage = new Vue({
2019    el:'.dmsg-page',
2020    data:{
2021        list:false,
2022        locked:false,
2023        count:0,
2024        pages:0,
2025        selecter:'.dmsg-header',
2026        opt:{
2027            paged:1
2028        },
2029        api:'getUserDirectmessageList'
2030    },
2031    mounted(){
2032        if(this.$refs.dmsgPage){
2033            this.opt.paged = this.$refs.dmsgPage.getAttribute('data-paged')
2034            this.getList()
2035        }
2036    },
2037    methods:{
2038        getList(){
2039            this.$http.post(b2_rest_url+'getUserDirectmessageList',Qs.stringify(this.opt)).then(res=>{
2040                this.list = res.data.data
2041                this.pages = res.data.count
2042                this.locked = false
2043                this.$nextTick(()=>{
2044                    b2RestTimeAgo(this.$el.querySelectorAll('.b2timeago'))
2045                })
2046            }).catch(err=>{
2047
2048                Qmsg['warning'](err.response.data.message,{html:true});
2049                this.locked = false
2050            })
2051        },
2052        showDmsgBox(){
2053            b2Dmsg.select = 'select'
2054            b2Dmsg.show = true
2055        },
2056        get(data){
2057            this.list = data.data
2058            this.pages = data.count
2059            this.$nextTick(()=>{
2060                b2RestTimeAgo(this.$el.querySelectorAll('.b2timeago'))
2061            })
2062        },
2063        jump(id){
2064            window.location.href = this.$refs.dmsgPage.getAttribute('data-url')+'/to/'+id;
2065        },
2066        deleteDmsg(id){
2067
2068        }
2069    }
2070})
2071
2072var b2dmsgPageTo = new Vue({
2073    el:'.dmsg-page-to',
2074    data:{
2075        list:false,
2076        locked:false,
2077        opt:{
2078            paged:1,
2079            userid:0
2080        },
2081        count:0,
2082        pages:0,
2083        selecter:'.dmsg-header',
2084        api:'getMyDirectmessageList',
2085        content:'',
2086        sendLocked:false
2087    },
2088    mounted(){
2089        if(this.$refs.mydmsg){
2090            this.opt.userid = this.$refs.mydmsg.getAttribute('data-id')
2091            this.opt.paged = this.$refs.mydmsg.getAttribute('data-paged')
2092            this.getList();
2093        }
2094    },
2095    methods:{
2096        getList(){
2097            this.$http.post(b2_rest_url+'getMyDirectmessageList',Qs.stringify(this.opt)).then(res=>{
2098                this.list = res.data.data
2099                this.locked = false
2100                this.count = res.data.count
2101                this.pages = res.data.pages
2102                this.$nextTick(()=>{
2103                    b2RestTimeAgo(this.$el.querySelectorAll('.b2timeago'))
2104                })
2105
2106            }).catch(err=>{
2107
2108                Qmsg['warning'](err.response.data.message,{html:true});
2109                this.locked = false
2110            })
2111        },
2112        get(val){
2113            this.list = val.data
2114            this.count = val.count
2115            this.pages = val.pages
2116        },
2117        send(){
2118            if(this.sendLocked == true) return
2119            this.sendLocked = true
2120            this.$http.post(b2_rest_url+'sendDirectmessage','user_id='+this.opt.userid+'&content='+this.content).then(res=>{
2121                this.getList()
2122                this.content = ''
2123                this.sendLocked = false
2124            }).catch(err=>{
2125
2126                Qmsg['warning'](err.response.data.message,{html:true});
2127                this.sendLocked = false
2128            })
2129        }
2130    }
2131})
2132
2133var b2DownloadPage = new Vue({
2134    el:'#download-page',
2135    data:{
2136        data:'',
2137        postId:0,
2138        index:0,
2139        i:0
2140    },
2141    mounted(){
2142        if(this.$refs.downloadPage){
2143            this.postId = b2GetQueryVariable('post_id');
2144            this.index = b2GetQueryVariable('index');
2145            this.i = b2GetQueryVariable('i');
2146            this.getData()
2147
2148            var clipboard = new ClipboardJS('.fuzhi');
2149            clipboard.on('success', e=>{
2150
2151                Qmsg['success'](b2_global.js_text.global.copy_success,{html:true});
2152            });
2153            clipboard.on('error', e=> {
2154
2155                Qmsg['warning'](b2_global.js_text.global.copy_select,{html:true});
2156            });
2157        }
2158    },
2159    methods:{
2160        getData(){
2161            let guest = b2getCookie('b2_guest_buy_'+this.postId+'_x')
2162                if(guest){
2163                    guest = JSON.parse(guest)
2164                }
2165
2166            let data = {
2167                'post_id':this.postId,
2168                'index':this.index,
2169                'i':this.i,
2170                'guest':guest
2171            }
2172
2173            this.$http.post(b2_rest_url+'getDownloadPageData',Qs.stringify(data)).then(res=>{
2174                this.data = res.data
2175            }).catch(err=>{
2176
2177                Qmsg['warning'](err.response.data.message,{html:true});
2178            })
2179        },
2180        login(){
2181            login.show = true
2182        }
2183    }
2184})
2185
2186Vue.component('check-box',{
2187    props: ['show','title','type','payt'],
2188    template: b2_global.pay_check,
2189    data(){
2190        return {
2191            success:false,
2192            timeOut:300,
2193            timesec:'',
2194            sTime:'',
2195            check:false,
2196            checkTime:''
2197        }
2198    },
2199    methods:{
2200        close(){
2201            this.$emit('close')
2202            this.sTime = ''
2203            this.checkTime = ''
2204        },
2205        checkAc(){
2206            if((this.sTime === null && this.success == 'fail') || this.checkTime === null || this.success === true){
2207                this.checkTime = null
2208                return
2209            }
2210
2211            let value = b2getCookie('order_id')
2212            this.$http.post(b2_rest_url+'payCheck','order_id='+value).then(res=>{
2213
2214                if(res.data.status === 'success'){
2215                    if(!b2token){
2216                        let list = b2getCookie('b2_guest_buy_'+res.data.id+'_'+res.data.type)
2217
2218                        if(!list){
2219                            list = new Object()
2220                        }else{
2221                            list = JSON.parse(list)
2222                        }
2223
2224                        Reflect.set(list,res.data.index,{
2225                            'id':res.data.id,
2226                            'order_id':value,
2227                            'type':res.data.type,
2228                            'index':res.data.index
2229                        })
2230
2231                        list = JSON.stringify(list)
2232
2233                        b2setCookie('b2_guest_buy_'+res.data.id+'_'+res.data.type,list)
2234
2235                    }
2236
2237                    //b2delCookie('order_id')
2238
2239                    if(typeof(B2VerifyPage) !== "undefined"){
2240                        B2VerifyPage.data.money = true
2241                        this.close()
2242
2243                    }else if(typeof(carts) !== "undefined"){
2244                        carts.step = 3
2245                        this.close()
2246
2247                    }else if(this.payt === 'ask'){
2248                        b2CircleList.afterCommentGetData(b2CircleList.answer.listParent,b2CircleList.data[b2CircleList.answer.listParent].topic_id,'ask')
2249                        this.close()
2250
2251                    }else if(this.payt === 'hidden'){
2252                        b2CircleList.afterCommentGetData(b2CircleList.hiddenIndex,b2CircleList.data[b2CircleList.hiddenIndex].topic_id,'hidden')
2253                        this.close()
2254
2255                    }
2256                    this.success = true;
2257                    this.checkTime = null;
2258                    this.sTime = null
2259
2260                }else{
2261                    this.checkTime = setTimeout(()=>{
2262                        this.checkAc()
2263                    },1000)
2264                }
2265            })
2266        },
2267        time(){
2268            this.currTime = parseInt(Date.parse(new Date())/1000);
2269            this.endTime = parseInt(this.currTime + this.timeOut);
2270            this.setTime()
2271        },
2272        setTime(){
2273            if(this.show == false || this.success === true) {
2274                this.sTime = null
2275                this.checkTime = null;
2276                return
2277            }
2278            let diff_time = parseInt(this.endTime-this.currTime);
2279            let m = Math.floor((diff_time / 60 % 60));
2280            let s = Math.floor((diff_time % 60));
2281            this.timesec = (m > 0 ? m + '<b>'+b2_global.js_text.global.min+'</b>' : '') + s + '<b>'+b2_global.js_text.global.sec+'</b>';
2282            if(diff_time > 0){
2283                this.sTime = setTimeout(()=>{
2284                    this.endTime = this.endTime - 1;
2285                    this.setTime()
2286                },1000)
2287            }else{
2288                this.sTime = null
2289                this.success = 'fail'
2290            }
2291        },
2292        refresh(){
2293
2294            if(typeof(B2VerifyPage) !== "undefined"){
2295                B2VerifyPage.data.money = true
2296                this.close()
2297            }else if(typeof(carts) !== "undefined"){
2298                carts.step = 3
2299                this.close()
2300            }else if(this.payt === 'ask'){
2301                b2CircleList.afterCommentGetData(b2CircleList.answer.listParent,b2CircleList.data[b2CircleList.answer.listParent].topic_id,'ask')
2302                this.close()
2303            }else if(this.payt === 'hidden'){
2304                b2CircleList.afterCommentGetData(b2CircleList.hiddenIndex,b2CircleList.data[b2CircleList.hiddenIndex].topic_id,'hidden')
2305                this.close()
2306            }else if(typeof(b2poinfomation) !== "undefined" && b2poinfomation.$refs.poinfomation){
2307                b2poinfomation.getPoinfomationOpts()
2308                this.close()
2309            }else{
2310                var url = new URL(window.location.href);
2311                url.searchParams.delete('b2paystatus');
2312                window.location.href=url.href
2313                b2CurrentPageReload()
2314            }
2315        }
2316    },
2317    watch:{
2318        show(val){
2319            if(this.type == 'card') return
2320            if(val){
2321                this.sTime = ''
2322                this.checkTime = ''
2323                this.time()
2324
2325                this.checkAc()
2326            }else{
2327                this.sTime = null
2328                this.success = false
2329                this.checkTime = null
2330            }
2331        }
2332    }
2333})
2334
2335//跳转支付检查支付结果
2336var b2PayCheck = new Vue({
2337    el:'#pay-check',
2338    data:{
2339        show:false,
2340        title:'',
2341        type:'',
2342        payType:''
2343    },
2344    mounted(){
2345        if(b2GetQueryVariable('b2paystatus') == 'check'){
2346            this.show = true
2347        }
2348    },
2349    methods:{
2350        close(){
2351            this.show = !this.show
2352            if(!this.show){
2353                this.payType = ''
2354            }
2355        }
2356    }
2357})
2358
2359//支付跳转页面
2360var b2Pay = new Vue({
2361    el:'#pay-page',
2362    data:{
2363        data:[],
2364        token:'',
2365        error:'',
2366        locked:false,
2367        payUrl:''
2368    },
2369    mounted(){
2370        if(this.$refs.payPage){
2371            this.token = this.$refs.payPage.getAttribute('data-token');
2372            if(!this.token){
2373                this.data = JSON.parse(this.$refs.payPage.getAttribute('data-pay'));
2374                this.pay()
2375            }
2376        }
2377    },
2378    methods:{
2379        pay(){
2380            if(this.locked == true) return
2381            this.locked = true
2382            this.$http.post(b2_rest_url+'buildOrder',Qs.stringify(this.data)).then(res=>{
2383
2384                this.token = res.data
2385                this.payUrl = window.location.href.split('?')[0]+'?token='+this.token
2386                //b2MakeForm(window.location.href.split('?')[0],this.token)
2387                this.locked = false
2388            }).catch(err=>{
2389                this.error = err.response.data.message
2390                this.locked = false
2391            })
2392        }
2393    }
2394})
2395
2396function b2MakeForm(url,token){
2397
2398    // 创建一个 form
2399    var form1 = document.createElement("form");
2400    form1.id = "form1";
2401    form1.name = "form1";
2402
2403    // 添加到 body 中
2404    document.body.appendChild(form1);
2405
2406    // 创建一个输入
2407    var input = document.createElement("input");
2408    // 设置相应参数
2409    input.name = "token";
2410    input.value = token;
2411
2412    // 将该输入框插入到 form 中
2413    form1.appendChild(input);
2414
2415    // form 的提交方式
2416    form1.method = "POST";
2417    // form 提交路径
2418    form1.action = url;
2419
2420    // 对该 form 执行提交
2421    form1.submit();
2422    // 删除该 form
2423    document.body.removeChild(form1);
2424}
2425
2426//扫码支付组件
2427Vue.component('scan-box',{
2428    props: ['show','data'],
2429    template: b2_global.scan_box,
2430    data(){
2431        return {
2432            locked:false,
2433            qrcode:'',
2434            timeOut:300,
2435            timesec:'',
2436            sTime:'',
2437            success:'',
2438            checkTime:'',
2439            backData:[]
2440        }
2441    },
2442    methods:{
2443        close(){
2444            this.$emit('close')
2445            this.backData = []
2446            this.checkTime = null
2447        },
2448        buildOrder(){
2449            if(this.locked == true) return
2450            this.locked = true
2451
2452            this.currTime = parseInt(Date.parse(new Date())/1000);
2453            this.endTime = parseInt(this.currTime + this.timeOut);
2454            this.setTime()
2455
2456            this.$http.post(b2_rest_url+'buildOrder',Qs.stringify(this.data)).then(res=>{
2457                this.backData = res.data
2458                if(res.data.type !== 'mapay' && res.data.type !== 'pay020'){
2459                    var qr = new QRious({
2460                        value: this.backData.qrcode,
2461                        size:200,
2462                        level:'L'
2463                      });
2464                    this.backData.qrcode = qr.toDataURL('image/jpeg')
2465                }
2466                this.writeOrder(res.data.order_id)
2467                this.locked = false
2468                this.checkAc()
2469            }).catch(err=>{
2470
2471                Qmsg['warning'](err.response.data.message,{html:true});
2472                this.locked = false
2473            })
2474        },
2475        writeOrder(id){
2476            b2setCookie('order_id',id)
2477        },
2478        checkAc(){
2479            if((this.sTime === null && this.success == 'fail') || this.checkTime === null || this.show == false){
2480                this.checkTime = null
2481                return
2482            }
2483
2484            let value = b2getCookie('order_id')
2485            this.$http.post(b2_rest_url+'payCheck','order_id='+value).then(res=>{
2486                if(res.data.status === 'success'){
2487
2488                    if(!b2token){
2489
2490                        let list = b2getCookie('b2_guest_buy_'+res.data.id+'_'+res.data.type)
2491                        if(!list){
2492                            list = new Object()
2493                        }else{
2494                            list = JSON.parse(list)
2495                        }
2496
2497                        Reflect.set(list,res.data.index,{
2498                            'id':res.data.id,
2499                            'order_id':value,
2500                            'type':res.data.type,
2501                            'index':res.data.index
2502                        })
2503
2504                        list = JSON.stringify(list)
2505
2506                        b2setCookie('b2_guest_buy_'+res.data.id+'_'+res.data.type,list)
2507
2508                    }
2509
2510                    this.success = true;
2511                    this.checkTime = null;
2512                    //b2delCookie('order_id')
2513                    if(typeof(B2VerifyPage) !== "undefined"){
2514                        B2VerifyPage.data.money = true
2515                        this.close()
2516                    }
2517                    if(typeof(carts) !== "undefined"){
2518                        carts.step = 3
2519                        this.close()
2520                    }
2521                    if(this.data.order_type === 'circle_read_answer_pay'){
2522                        b2CircleList.afterCommentGetData(b2CircleList.answer.listParent,b2CircleList.data[b2CircleList.answer.listParent].topic_id,'ask')
2523                        this.close()
2524                    }
2525                    if(this.data.order_type === 'circle_hidden_content_pay'){
2526                        b2CircleList.afterCommentGetData(b2CircleList.hiddenIndex,b2CircleList.data[b2CircleList.hiddenIndex].topic_id,'hidden')
2527                        this.close()
2528                    }
2529                }else{
2530                    this.checkTime = setTimeout(()=>{
2531                        this.checkAc()
2532                    },1000)
2533                }
2534            })
2535        },
2536        setTime(){
2537            if(this.show == false) return
2538            let diff_time = parseInt(this.endTime-this.currTime);
2539            let m = Math.floor((diff_time / 60 % 60));
2540            let s = Math.floor((diff_time % 60));
2541            this.timesec = (m > 0 ? m + '<b>'+b2_global.js_text.global.min+'</b>' : '') + s + '<b>'+b2_global.js_text.global.sec+'</b>';
2542            if(diff_time > 0){
2543                this.sTime = setTimeout(()=>{
2544                    this.endTime = this.endTime - 1;
2545                    this.setTime()
2546                },1000)
2547            }else{
2548                this.sTime = null
2549                this.success = 'fail'
2550            }
2551        },
2552        refresh(){
2553            if(this.data.order_type === 'circle_read_answer_pay'){
2554                b2CircleList.afterCommentGetData(b2CircleList.answer.listParent,b2CircleList.data[b2CircleList.answer.listParent].topic_id,'ask')
2555                this.close()
2556            }else if(this.data.order_type === 'circle_hidden_content_pay'){
2557                b2CircleList.afterCommentGetData(b2CircleList.hiddenIndex,b2CircleList.data[b2CircleList.hiddenIndex].topic_id,'hidden')
2558                this.close()
2559            }else{
2560                b2CurrentPageReload()
2561            }
2562        }
2563    },
2564    watch:{
2565        show(val){
2566            if(val){
2567                this.sTime = ''
2568                this.success = false
2569                this.checkTime = ''
2570            }else{
2571                this.sTime = null
2572                this.success = false
2573                this.checkTime = null
2574            }
2575        },
2576        data:{
2577            deep:true,
2578            handler(newName, oldName) {
2579                this.buildOrder()
2580            },
2581        }
2582    }
2583})
2584
2585//扫码支付
2586var b2ScanPay = new Vue({
2587    el:'#scan-box',
2588    data:{
2589        data:[],
2590        show:false
2591    },
2592    methods:{
2593        close(){
2594            this.show = !this.show
2595        }
2596    }
2597})
2598
2599Vue.component('ds-box', {
2600    props: ['show','money','msg','user','author','data','showtype'],
2601    template:b2_global.ds_box,
2602    data(){
2603        return {
2604            value:0,
2605            custom:0,
2606            content:'',
2607            payType:'',
2608            payMoney:'',
2609            locked:false,
2610            jump:'',
2611            href:'',
2612            isWeixin:'',
2613            isMobile:'',
2614            allow:[],
2615            card:[],
2616            cg:[],
2617            newWin: null,
2618            login:false,
2619            redirect:'',
2620            payData:'',
2621            waitOrder:false
2622        }
2623    },
2624    created(){
2625        this.isWeixin = b2isWeixin()
2626        if(b2token){
2627            this.login = true
2628        }
2629        this.redirect = b2getCookie('b2_back_url');
2630    },
2631    methods:{
2632        close(){
2633            this.$emit('close')
2634            this.locked = false
2635        },
2636        clean(){
2637            this.$emit('clean')
2638        },
2639        picked(m,val){
2640            this.value = val
2641            this.payMoney = m
2642        },
2643        post(url, params) {
2644            var temp = document.createElement("form"); //创建form表单
2645            temp.action = url;
2646            temp.method = "post";
2647            temp.target = "_blank";
2648            temp.style.display = "none";//表单样式为隐藏
2649
2650            if(Object.keys(params).length > 0){
2651                Object.keys(params).forEach((key)=>{
2652
2653                    var opt =document.createElement("input");  //添加input标签
2654                    opt.name = key;    //设置name属性
2655                    opt.value = params[key];   //设置value属性
2656                    temp.appendChild(opt);
2657                })
2658            }
2659
2660            document.body.appendChild(temp);
2661            temp.submit();
2662            return temp;
2663        },
2664        restData(data = []){
2665            if(this.showtype == 'ds'){
2666                data = Object.assign(data,{
2667                    'title':this.$refs.dstitle.innerText,
2668                    'order_price':this.payMoney,
2669                    'order_type':'ds',
2670                    'post_id':b2_global.post_id,
2671                    'pay_type':this.payType,
2672                    'order_content':this.content
2673                })
2674            }else if(this.showtype == 'cz'){
2675                data = {
2676                    'title':b2_global.js_text.global.pay_money,
2677                    'order_price':this.payMoney,
2678                    'order_type':'cz',
2679                    'post_id':0,
2680                    'pay_type':this.payType
2681                }
2682            }else if(this.showtype == 'cg'){
2683                data = {
2684                    'title':b2_global.js_text.global.pay_credit,
2685                    'order_price':this.payMoney,
2686                    'order_type':'cg',
2687                    'post_id':0,
2688                    'pay_type':this.payType
2689                }
2690            }else{
2691                data = Object.assign(this.data,data)
2692            }
2693            data['pay_type'] = this.payType
2694
2695            var url = new URL(window.location.href);
2696            url.searchParams.set('b2paystatus', 'check');
2697
2698            data['redirect_url'] = url.href
2699
2700            return data
2701
2702        },
2703        disabled(){
2704            if(this.data.pay_type !=='card'){
2705                if(this.jump == '') return true
2706                if((this.jump == 'jump' || this.jump == 'mweb' || this.jump == 'jsapi') && this.href == '' && this.payData == '') return true
2707                if(this.locked == true) return true
2708                if(this.payType == '') return true
2709                if(this.payMoney === '') return true
2710            }else{
2711                if(!this.card.number || !this.card.password) return true
2712            }
2713
2714            return false
2715        },
2716        chosePayType(val){
2717
2718            if(this.locked == true) return;
2719            this.locked = true
2720            this.payType = val
2721
2722            this.href = ''
2723            this.payData = ''
2724            this.jump = ''
2725
2726            this.$http.post(b2_rest_url+'checkPayType','pay_type='+val).then(res=>{
2727                if(res.data.pay_type == 'card'){
2728                    this.$emit('change','card')
2729                    this.card.text = res.data.card_text
2730                    this.jump = res.data.pay_type
2731                    this.locked = false
2732                }else{
2733                    if(this.showtype == 'card'){
2734                        this.$emit('change','cz')
2735                    }
2736                    this.jump = res.data.pay_type
2737
2738                    this.isMobile = res.data.is_mobile
2739                    if(this.jump == 'jump' || this.jump === 'mweb' || this.jump === 'jsapi'){
2740
2741                        let data = Qs.stringify(this.restData());
2742
2743                        this.waitOrder = true
2744                        this.$http.post(b2_rest_url+'buildOrder',data).then(res=>{
2745                            this.writeOrder(res.data.id)
2746
2747                            if(typeof res.data.url == 'string'){
2748                                this.href = res.data.url
2749                            }else{
2750                                this.payData = res.data.url
2751                            }
2752
2753                            this.waitOrder = false
2754                            this.locked = false
2755
2756                        }).catch(err=>{
2757
2758                            if(err.response.data.message.msg === 'bind_weixin'){
2759                                b2setCookie('b2_back_url',window.location.href)
2760
2761                                if(typeof err.response.data.message.oauth == 'string'){
2762                                    b2weixinBind.msg = err.response.data.message.oauth
2763                                    b2weixinBind.show = true
2764                                }else{
2765                                    b2weixinBind.show = true
2766                                    b2weixinBind.url = err.response.data.message.oauth.weixin.url
2767                                }
2768
2769                            }else{
2770
2771                                Qmsg['warning'](err.response.data.message,{html:true});
2772                            }
2773                            this.waitOrder = false
2774                            this.locked = false
2775                        })
2776
2777                        // let url = b2_global.pay_url+'?'+Qs.stringify(this.restData())
2778                        // this.href = 'javascript:void(0)'
2779                        //encodeURI(url)
2780                    }else{
2781
2782                        this.locked = false
2783                    }
2784                }
2785
2786                b2setCookie('b2_back_url',window.location.href)
2787            }).catch(err=>{
2788
2789                Qmsg['warning'](err.response.data.message,{html:true});
2790                this.locked = false
2791            })
2792        },
2793        writeOrder(id){
2794            b2setCookie('order_id',id)
2795        },
2796        balancePay(order_id){
2797            let data = this.restData();
2798            this.$http.post(b2_rest_url+'balancePay','order_id='+order_id).then(res=>{
2799                this.close()
2800                b2PayCheck.show = true
2801                b2PayCheck.title = data['title']
2802                this.locked = false
2803            }).catch(err=>{
2804
2805                Qmsg['warning'](err.response.data.message,{html:true});
2806                this.locked = false
2807            })
2808        },
2809        pay(){
2810            if(this.disabled()) return;
2811
2812            if(this.jump === 'card'){
2813                if(this.locked == true) return
2814                this.locked = true
2815                this.$http.post(b2_rest_url+'cardPay',Qs.stringify(this.card)).then(res=>{
2816                    if(res.data === 'success'){
2817                        b2PayCheck.show = true
2818                        b2PayCheck.title = b2_global.js_text.global.pay_money_success
2819                        b2PayCheck.type = 'card'
2820                        this.close()
2821                    }
2822                    this.locked = false
2823                }).catch(err=>{
2824
2825                    Qmsg['warning'](err.response.data.message,{html:true});
2826                    this.locked = false
2827                })
2828            }else if(this.jump === 'jump' || this.jump === 'mweb'){
2829                b2PayCheck.show = true
2830                b2PayCheck.title = this.$refs.dstitle.innerHTML
2831
2832                this.close()
2833
2834                if(this.payData){
2835                    this.post(this.payData.url,this.payData.data)
2836                }
2837
2838            }else if(this.jump === 'balance'){
2839                if(this.locked == true) return
2840                this.locked = true
2841
2842                let data = Qs.stringify(this.restData());
2843                this.$http.post(b2_rest_url+'buildOrder',data).then(res=>{
2844                    this.writeOrder(res.data)
2845                    this.balancePay(res.data)
2846                }).catch(err=>{
2847
2848                    Qmsg['warning'](err.response.data.message,{html:true});
2849                    this.locked = false
2850                })
2851            }else if(this.jump === 'scan'){
2852                if(this.isMobile){
2853                    b2ScanPay.data = this.restData({
2854                        'is_weixin':this.isWeixin,
2855                        'is_mobile':this.isMobile
2856                    })
2857                }else{
2858                    b2ScanPay.data = this.restData()
2859                }
2860                b2ScanPay.show = true;
2861                this.close()
2862            }else if(this.jump === 'jsapi'){
2863                let data = this.restData();
2864                jsApiCall(this.payData)
2865                this.close()
2866                b2PayCheck.show = true
2867                b2PayCheck.title = data['title']
2868            }
2869
2870            // else if(this.jump === 'mweb' || this.jump === 'jsapi'){
2871            //     if(this.locked == true) return
2872            //     this.locked = true
2873            //     let data = this.restData();
2874            //     let title = data['title']
2875            //     data = Qs.stringify(data);
2876            //     // if(!b2isWeixin()){
2877            //     //     this.newWin = window.open('',"_blank");
2878            //     // }
2879
2880            //     this.$http.post(b2_rest_url+'buildOrder',data).then(res=>{
2881            //         this.writeOrder(res.data.order_id)
2882            //         if(this.jump === 'jsapi'){
2883            //             jsApiCall(res.data.link)
2884            //             this.close()
2885            //             b2PayCheck.show = true
2886            //             b2PayCheck.title = title
2887            //         }else{
2888            //             // window.open(res.data.link)
2889            //             // if(!b2isWeixin()){
2890            //             //     window.location=res.data.link
2891            //             // }else{
2892
2893            //                 // let form = document.querySelector('#wechataction')
2894            //                 // form.action = res.data.link
2895            //                 // form.submit()
2896            //                window.location.href=res.data.link
2897
2898            //                // window.location=res.data.link
2899            //                 // window.open(res.data.link)
2900            //             //}
2901            //             //location.assign();
2902            //             //window.open()
2903            //             this.close()
2904            //             b2PayCheck.show = true
2905            //             b2PayCheck.title = title
2906            //         }
2907            //         this.locked = false
2908            //     }).catch(err=>{
2909            //         if(err.response.data.message.msg === 'bind_weixin'){
2910            //             b2setCookie('b2_back_url',window.location.href)
2911
2912            //             if(typeof err.response.data.message.oauth == 'string'){
2913            //                 b2weixinBind.msg = err.response.data.message.oauth
2914            //                 b2weixinBind.show = true
2915            //             }else{
2916            //                 b2weixinBind.show = true
2917            //                 b2weixinBind.url = err.response.data.message.oauth.weixin.url
2918            //             }
2919
2920            //         }else{
2921
2922            //             Qmsg['warning'](err.response.data.message,{html:true});
2923            //         }
2924
2925            //         this.locked = false
2926            //     })
2927            // }
2928        },
2929        allowPayType(){
2930            this.$http.post(b2_rest_url+'allowPayType','show_type='+this.showtype).then(res=>{
2931                this.allow = res.data
2932                this.user.money = res.data.money
2933                if(res.data.dh){
2934                    this.cg.min = res.data.min
2935                    this.cg.dh = res.data.dh
2936                    this.payMoney = this.cg.min
2937                }
2938            })
2939        },
2940        creditAdd(){
2941            return parseInt(this.payMoney*this.cg.dh)
2942        }
2943    },
2944    watch:{
2945        money(val){
2946            if(this.payMoney == 0){
2947                this.payMoney = val[0]
2948            }
2949        },
2950        // payMoney(val){
2951        //     if(!/^[0-9]+.?[0-9]*/.test(val)){
2952        //         val = 0
2953        //     }
2954        //     if(this.href && val && this.jump == 'jump'){
2955        //         let url = b2_global.pay_url+'?'+Qs.stringify(this.restData())
2956        //         this.href = encodeURI(url)
2957        //     }
2958        //     this.payMoney = parseFloat(val)
2959        // },
2960        show(val){
2961            if(val){
2962                b2setCookie('b2_back_url',window.location.href)
2963                this.allowPayType()
2964            }
2965            if(val && this.money.length > 0){
2966                this.payMoney = this.money[0]
2967            }else if(val && this.data.length != 0){
2968                this.payMoney = this.data.order_price
2969            }else if(val == false){
2970                setTimeout(() => {
2971                    this.value = 0
2972                    this.payMoney = 0
2973                    this.payType = ''
2974                    this.clean()
2975                }, 300);
2976            }
2977        },
2978        payType(val){
2979            this.data.pay_type = val
2980        },
2981        showtype(val){
2982
2983        }
2984    }
2985})
2986
2987//支付容器
2988var b2DsBox = new Vue({
2989    el:'#ds-box',
2990    data:{
2991        money:[],
2992        show:false,
2993        msg:'',
2994        user:[],
2995        author:[],
2996        data:[],
2997        showtype:''
2998    },
2999    methods: {
3000        close(){
3001            this.show = !this.show
3002        },
3003        clean(){
3004            this.data = []
3005            this.money = []
3006        },
3007        change(type){
3008            this.showtype = type
3009        }
3010    },
3011})
3012
3013var b2Ds = new Vue({
3014    el:'#content-ds',
3015    data:{
3016        data:''
3017    },
3018    methods:{
3019        show(){
3020            b2DsBox.money = this.data.moneys
3021            b2DsBox.show = true
3022            b2DsBox.showtype = 'ds'
3023            b2DsBox.msg = this.data.single_post_ds_text
3024        },
3025    }
3026})
3027
3028function b2pay(event){
3029    let data = JSON.parse(event.getAttribute('data-pay'));
3030    b2DsBox.data = data
3031    b2DsBox.show = true
3032    b2DsBox.showtype = 'normal'
3033}
3034
3035function b2creditpay(event){
3036    if(!b2token){
3037        login.show = true
3038    }else{
3039        let data = JSON.parse(event.getAttribute('data-pay'));
3040        payCredit.data = data
3041        payCredit.show = true
3042    }
3043}
3044
3045//随机数
3046function uuid(len, radix) {
3047    var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
3048    var uuid = [], i;
3049    radix = radix || chars.length;
3050    if (len) {
3051      for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
3052    } else {
3053      var r;
3054      uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
3055      uuid[14] = '4';
3056      for (i = 0; i < 36; i++) {
3057        if (!uuid[i]) {
3058          r = 0 | Math.random()*16;
3059          uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
3060        }
3061      }
3062    }
3063    return uuid.join('');
3064}
3065
3066function openWin(url,name,iWidth,iHeight) {
3067    var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
3068    var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
3069    window.open(url, name, 'height=' + iHeight + ',innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');
3070}
3071
3072function deleteHtmlTag(str){
3073    str = str.replace(/<[^>]+>|&[^>]+;/g,"").trim();
3074    return str;
3075}
3076
3077var b2cache=[];
3078function b2addJs(path,callback){
3079    var flag=0;//检查是否加载的状态
3080    for(var i=b2cache.length;i--;){
3081        b2cache[i]==path?flag=1:flag=0;
3082    }
3083    if(flag){//如果已经加载则不加载
3084        return;
3085    }
3086    var head = document.getElementsByTagName('head')[0];
3087    var script = document.createElement('script');
3088    script.src = path;
3089    script.type = 'text/javascript';
3090    head.appendChild(script);
3091    script.onload = script.onreadystatechange = function() {/*判断是否加载成功*/
3092    if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete" ) {
3093        script.onload = script.onreadystatechange = null;
3094            callback();
3095        }
3096    };
3097    b2cache.push(path);//把加载过的存起来
3098}
3099
3100//微信内支付
3101function jsApiCall(data){
3102    WeixinJSBridge.invoke(
3103        'getBrandWCPayRequest',
3104        data,
3105        function(res){}
3106    );
3107}
3108
3109function callpay(){
3110    if (typeof WeixinJSBridge == "undefined"){
3111        if( document.addEventListener ){
3112            document.addEventListener('WeixinJSBridgeReady', jsApiCall, passiveSupported ? { passive: true } : false);
3113        }else if (document.attachEvent){
3114            document.attachEvent('WeixinJSBridgeReady', jsApiCall);
3115            document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
3116        }
3117    }else{
3118        jsApiCall();
3119    }
3120}
3121
3122function b2SidebarSticky(){
3123
3124    if(B2ClientWidth <= 768) return
3125    if(document.querySelector('.post-style-5')) return
3126
3127    if(typeof window.b2Stick !== 'undefined'){
3128        for (let i = 0; i < window.b2Stick.length; i++) {
3129            if(window.b2Stick[i]){
3130                window.b2Stick[i].updateSticky()
3131            }
3132        }
3133        return
3134    }
3135
3136    let b2sidebar = document.querySelectorAll('.sidebar');
3137
3138    if(b2sidebar){
3139        if(B2ClientWidth > 768){
3140            var b2Stick = []
3141            for (let i = 0; i < b2sidebar.length; i++) {
3142                if(!b2sidebar[i].querySelector('.widget-ffixed')) continue
3143                b2Stick[i] = new StickySidebar(b2sidebar[i], {
3144                    containerSelector:'.widget-area',
3145                    topSpacing: 20,
3146                    resizeSensor: true,
3147                    bottomSpacing: 20
3148                });
3149            }
3150
3151            window.b2Stick = b2Stick
3152        }
3153    }
3154}
3155
3156Vue.component('credit-box', {
3157    props: ['show','data','user'],
3158    template:b2_global.credit_box,
3159    data(){
3160        return {
3161            locked:false
3162        }
3163    },
3164    methods:{
3165        close(){
3166            this.$emit('close')
3167        },
3168        writeOrder(id){
3169            b2setCookie('order_id',id)
3170        },
3171        disabled(){
3172            if(this.locked === true) return true
3173            if(parseInt(this.user.credit) < parseInt(this.data.order_price)) return true
3174            return false
3175        },
3176        creditPay(order_id){
3177            this.writeOrder(order_id)
3178            this.$http.post(b2_rest_url+'creditPay','order_id='+order_id).then(res=>{
3179                this.locked = false
3180                b2PayCheck.show = true
3181                this.close()
3182            }).catch(err=>{
3183
3184                Qmsg['warning'](err.response.data.message,{html:true});
3185                this.locked = false
3186            })
3187        },
3188        pay(){
3189            if(this.locked == true) return
3190            this.locked = true
3191
3192            this.data.pay_type = 'credit'
3193            let data = Qs.stringify(this.data)
3194            this.$http.post(b2_rest_url+'buildOrder',data).then(res=>{
3195                this.creditPay(res.data)
3196            }).catch(err=>{
3197                Qmsg['warning'](err.response.data.message,{html:true});
3198                this.locked = false
3199            })
3200        }
3201    }
3202})
3203
3204var payCredit = new Vue({
3205    el:'#credit-box',
3206    data:{
3207        show:false,
3208        data:[],
3209        user:{
3210            credit:0
3211        },
3212        author:[]
3213    },
3214    methods:{
3215        close(){
3216            this.show =  !this.show
3217        }
3218    }
3219})
3220
3221var B2UserWidget = new Vue({
3222    el:'.b2-widget-user',
3223    data:{
3224        show:false,
3225        b2token:false
3226    },
3227    mounted(){
3228        this.b2token = b2token
3229    },
3230    computed:{
3231        userData(){
3232            return this.$store.state.userData
3233        },
3234        oauth(){
3235            return this.$store.state.oauthLink
3236        },
3237        announcement(){
3238            return this.$store.state.announcement
3239        },
3240        openOauth(){
3241            return this.$store.state.openOauth
3242        }
3243    },
3244    watch:{
3245        announcement(val){
3246            if(val && !this.show){
3247                this.resize()
3248            }
3249        }
3250    },
3251    methods:{
3252        resize(){
3253            this.$nextTick(()=>{
3254                if(!this.$refs.userWidget) return
3255                if(this.$refs.gujia){
3256                    this.$refs.gujia.style.display = 'none'
3257                }
3258                setTimeout(() => {
3259                    b2tooltip('.user-w-tips')
3260                }, 300);
3261
3262                this.show = true
3263            })
3264        },
3265        markHistory(type){
3266            if(this.oauth.weixin.mp && type === 'weixin'){
3267                mpCode.show = true
3268            }
3269            b2setCookie('b2_back_url',window.location.href)
3270        }
3271    }
3272})
3273
3274var b2Mission = new Vue({
3275    el:'.b2-widget-mission',
3276    data:{
3277        data:'',
3278        locked:false,
3279        type:'today',
3280        paged:1,
3281        count:0,
3282        pages:{
3283            today:1,
3284            always:1
3285        }
3286    },
3287    mounted(){
3288        if(this.$refs.missionWidget){
3289            this.getData()
3290        }
3291    },
3292    methods:{
3293        getData(count,paged){
3294            if(this.$refs.missionWidget){
3295                this.count = this.$refs.missionWidget.getAttribute('data-count')
3296            }else{
3297                this.count = 10
3298            }
3299            if(paged){
3300                this.paged = paged
3301            }
3302            this.$http.post(b2_rest_url+'getUserMission','count='+this.count+'&paged='+this.paged).then(res=>{
3303                this.data = res.data
3304                this.pages.today = res.data.mission_today_list.pages
3305                this.pages.always = res.data.mission_always_list.pages
3306                if(this.$refs.missiongujia){
3307                    this.$refs.missiongujia.style.display = 'none'
3308                }
3309                this.$nextTick(()=>{
3310                    b2RestTimeAgo(this.$el.querySelectorAll('.b2timeago'))
3311                })
3312            })
3313        },
3314        mission(){
3315            if(!b2token){
3316                login.show = true
3317            }else{
3318                if(this.data.mission.credit){
3319
3320                    Qmsg['warning'](b2_global.js_text.global.has_mission,{html:true});
3321                    return
3322                }
3323                if(this.locked == true) return
3324                this.locked = true
3325                this.$http.post(b2_rest_url+'userMission').then(res=>{
3326                    this.$nextTick(()=>{
3327                        this.data.mission = res.data.mission
3328                        this.locked = false
3329                    })
3330                    this.getData(this.count,this.paged)
3331                }).catch(err=>{
3332
3333                    Qmsg['warning'](err.response.data.message,{html:true});
3334                    this.locked = false
3335                })
3336            }
3337        }
3338    }
3339})
3340
3341var b2NewComment = new Vue({
3342    el:'.b2-widget-comment',
3343    data:{
3344        data:'',
3345        paged:1,
3346        pages:1,
3347        count:5,
3348        hidden:1,
3349        next:false,
3350        prev:false,
3351        locked:false
3352    },
3353    mounted(){
3354        if(this.$refs.commentWidget){
3355            this.count = this.$refs.commentWidget.getAttribute('data-count');
3356            this.hidden = this.$refs.commentWidget.getAttribute('data-hidden');
3357            this.getList()
3358            if(this.paged == 1){
3359                this.prev = true
3360            }
3361        }
3362    },
3363    methods:{
3364        getList(){
3365            if(this.locked == true) return
3366            this.locked = true
3367            this.$https.post(b2_rest_url+'getNewComments','paged='+this.paged+'&count='+this.count+'&hidden='+this.hidden).then(res=>{
3368                this.data = res.data.data
3369                this.pages = res.data.pages
3370                if(this.$refs.gujia){
3371                    this.$refs.gujia.style.display = 'none'
3372                }
3373
3374                this.$nextTick(()=>{
3375                    b2SidebarSticky()
3376                    b2RestTimeAgo(this.$refs.commentWidget.querySelectorAll('.b2timeago'))
3377                })
3378                this.locked = false
3379            })
3380        },
3381        nexAc(){
3382            if(this.next || this.locked) return
3383            this.paged++
3384            this.getList()
3385        },
3386        prevAc(){
3387            if(this.prev || this.locked) return
3388            this.paged--
3389            this.getList()
3390        }
3391    },
3392    watch:{
3393        paged(val){
3394            if(val <= 1){
3395                this.prev = true
3396            }else{
3397                this.prev = false
3398            }
3399            if(val >= this.pages){
3400                this.next = true
3401            }else{
3402                this.next = false
3403            }
3404        }
3405    }
3406})
3407
3408//移动端点击展开筛选
3409// function b2ShowFilterBox(event){
3410
3411//     let filterBox = event.parentNode.nextElementSibling
3412
3413//     if(filterBox.className.indexOf('b2-show') !== -1){
3414//         filterBox.className = filterBox.className.replace('b2-show','')
3415//         bodyScrollLock.lock(filterBox)
3416//     }else{
3417//         filterBox.className += ' b2-show'
3418//         bodyScrollLock.unlock(filterBox)
3419//     }
3420// }
3421
3422var b2mobileFooterMenu = new Vue({
3423    el:'#mobile-footer-menu',
3424    data:{
3425        msg:0,
3426        show:true
3427    }
3428})
3429
3430var postPoBox = new Vue({
3431    el:'#post-po-box',
3432    data:{
3433        show:false,
3434        login:false,
3435        allow:''
3436    },
3437    mounted(){
3438        if(b2token){
3439            this.login = true
3440        }
3441    },
3442    methods:{
3443        close(){
3444            this.showPost = !this.showPost
3445        },
3446        go(val,type){
3447           if(!this.login){
3448                login.show = true
3449                login.type = 0
3450                return
3451           }
3452           if(type != 'request'){
3453                if(!userTools.role[type]){
3454
3455                    Qmsg['warning'](b2_global.js_text.global.not_allow,{html:true});
3456                    return
3457                }
3458           }
3459           setTimeout(() => {
3460            window.location.href = val;
3461           }, 250);
3462
3463        }
3464    }
3465})
3466
3467var b2AsideBar = new Vue({
3468    el:'.aside-container',
3469    data:{
3470        dmsg:{
3471            count:0
3472        },
3473        msg:{
3474            count:0
3475        },
3476        showBox:false,
3477        showType:{
3478            'user':false,
3479            'msg':false,
3480            'dmsg':false,
3481            'mission':false,
3482            'coupon':false
3483        },
3484        locked:false,
3485        mission:[],
3486        bool:false,
3487        coupon:{
3488            count:0,
3489            data:''
3490        },
3491        showCouponInfo:[],
3492        qrcode:'',
3493        ref:'',
3494        dlocked:false,
3495        count:0,
3496        cartLocked:false,
3497        b2token:false
3498    },
3499    computed:{
3500        userData(){
3501            return this.$store.state.userData
3502        },
3503        carts(){
3504            if(this.count && !this.cartLocked){
3505                return {
3506                    count:this.count,
3507                    data:''
3508                }
3509            }else{
3510                let carts = this.$store.state.carts
3511                return {
3512                    count:carts !== null && carts !== undefined ? Object.keys(carts).length : 0,
3513                    data:carts
3514                }
3515            }
3516        }
3517    },
3518    mounted(){
3519        this.b2token = b2token
3520    },
3521    methods:{
3522        getQrcode(url){
3523            var url = new URL(url)
3524            url.searchParams.set('ref', this.ref)
3525            var qr = new QRious({
3526                value: url.href,
3527                size:120,
3528                level:'L'
3529              });
3530            return qr.toDataURL('image/jpeg');
3531        },
3532        goMyPage(){
3533            if(!b2token){
3534                login.show = true
3535                login.type = 0
3536                return
3537            }
3538
3539            window.location.href = this.userData.link
3540        },
3541        chat(){
3542            if(b2_global.chat.type == 'crisp'){
3543                $crisp.push(['do', 'chat:open'])
3544            }
3545            if(b2_global.chat.type == 'qq'){
3546                window.open("http://wpa.qq.com/msgrd?v=3&uin="+b2_global.chat.qq+"&site=qq&menu=yes", "_blank");
3547            }
3548            if(b2_global.chat.type == 'dmsg'){
3549                if(!b2token){
3550                    login.show = true
3551                }else{
3552                    b2Dmsg.userid = b2_global.chat.dmsg
3553                    b2Dmsg.show = true
3554                }
3555            }
3556            if(b2_global.chat.type == 'requests'){
3557                if(!b2token){
3558                    login.show = true
3559                }else{
3560                    window.open(b2_global.home_url+'/requests', "_blank");
3561                }
3562            }
3563        },
3564        show(type,value){
3565            this.closeBox()
3566            if(type === 'user'){
3567                if(!b2token){
3568                    login.show = true
3569                    login.type = 0
3570                    return
3571                }
3572            }
3573            if(type === 'dmsg' && this.dmsg.count == 0){
3574                if(!b2token){
3575                    login.show = true
3576                    login.type = 0
3577                    return
3578                }
3579                this.jumpTo(value)
3580                return;
3581            }
3582            if(type === 'msg'){
3583                if(!b2token){
3584                    login.show = true
3585                    login.type = 0
3586                    return
3587                }
3588                this.jumpTo(value)
3589                return;
3590            }
3591            if(type == 'mission'){
3592                this.mission = b2Mission
3593                if(this.mission.data.length == 0){
3594                    this.mission.getData(10)
3595                }
3596            }
3597            if(type === 'coupon'){
3598                this.getMyCoupons()
3599            }
3600
3601            if(type === 'cart'){
3602                if(!b2token){
3603                    login.show = true
3604                    login.type = 0
3605                    return
3606                }
3607
3608                this.getMycarts()
3609            }
3610            this.showType[type] = true
3611            this.showBox = true
3612            // if(B2ClientWidth < 768){
3613            //     bodyScrollLock.lock(this.$refs.asideContainer)
3614            // }
3615            this.$nextTick(()=>{
3616                b2RestTimeAgo(this.$el.querySelectorAll('.b2timeago'))
3617            })
3618        },
3619        getMycarts(){
3620            if(this.cartLocked == true) return
3621            this.cartLocked = true
3622            this.$http.get(b2_rest_url+'getMyCarts').then((res)=>{
3623                if(Object.keys(res.data).length > 0){
3624                    this.$store.commit('setcartsData',res.data)
3625                }
3626            })
3627
3628        },
3629        showAc(val){
3630            if(!b2token){
3631                login.show = true
3632                return
3633            }
3634
3635            if(val){
3636                this.show('user')
3637            }else{
3638                this.close()
3639            }
3640        },
3641        closeBox(){
3642            Object.keys(this.showType).forEach(key => {
3643                this.showType[key] = false
3644            });
3645            this.showBox = false
3646            // if(B2ClientWidth < 768){
3647            //     bodyScrollLock.unlock(this.$refs.asideContainer)
3648            // }
3649
3650        },
3651        getNewDmsg(){
3652            if(b2token){
3653                if(this.locked) return
3654                this.locked = true
3655                this.$http.post(b2_rest_url+'getNewDmsg').then(res=>{
3656                    this.dmsg = res.data.dmsg
3657                    this.locked = false
3658                })
3659            }
3660        },
3661        close(){
3662            if(this.$refs.asideContainer && this.$refs.asideContainer.className.indexOf('aside-show') && B2ClientWidth < 768){
3663                this.$refs.asideContainer.className = this.$refs.asideContainer.className.replace(' aside-show','')
3664                // if(B2ClientWidth < 768){
3665                //     bodyScrollLock.unlock(this.$refs.asideContainer)
3666                // }
3667                this.showBox = false
3668            }else{
3669                this.closeBox()
3670            }
3671        },
3672        goTop(){
3673            this.$scrollTo('.site', 300, {offset: 0})
3674        },
3675        login(){
3676            if(!b2token){
3677                login.show = true
3678                return
3679            }else if(!this.$refs.asideContent){
3680                self.location = this.$store.state.userData.link
3681            }else{
3682                this.show('user')
3683                this.$refs.asideContainer.className += ' aside-show';
3684            }
3685        },
3686        showSearch(){
3687            b2SearchBox.close()
3688        },
3689        jumpTo(url){
3690            window.location.href = url;
3691        },
3692        updateCarts(){
3693            let data = b2getCookie('carts')
3694            if(data){
3695                this.carts.data = JSON.parse(data)
3696            }else{
3697                this.carts.data = ''
3698            }
3699
3700
3701            if(this.carts.data){
3702                if(this.carts.count > Object.keys(this.carts.data).length){
3703                    b2mobileFooterMenu.msg = b2mobileFooterMenu.msg - (this.carts.count - Object.keys(this.carts.data).length)
3704                }else{
3705
3706                    b2mobileFooterMenu.msg = b2mobileFooterMenu.msg + (Object.keys(this.carts.data).length - this.carts.count)
3707                }
3708                this.carts.count = Object.keys(this.carts.data).length
3709            }
3710
3711        },
3712        deleteCarts(id){
3713            this.$https.post(b2_rest_url+'deleteMyCarts','id='+id).then(res=>{
3714
3715                if(res.data.length == 0){
3716                    this.$store.commit('setcartsData',{})
3717                }else{
3718                    this.$store.commit('setcartsData',res.data)
3719                }
3720            })
3721        },
3722        getMyCoupons(){
3723            if(!b2token){
3724                login.show = true
3725                return
3726            }
3727
3728            this.showType.coupon = true
3729
3730            this.$https.get(b2_rest_url+'getMyCoupons').then(res=>{
3731                this.coupon = res.data
3732            })
3733        },
3734        couponClass(item){
3735            if(item.expiration_date.expired) return 'stamp04'
3736            if(item.products.length > 0) return 'stamp01'
3737            if(item.cats.length > 0) return 'stamp02'
3738            return 'stamp03'
3739        },
3740        couponMoreInfo(id){
3741            this.$set(this.showCouponInfo,id,!this.showCouponInfo[id])
3742        },
3743        deleteCoupon(id){
3744            var r = confirm(b2_global.js_text.global.delete_coupon)
3745            if(r){
3746                this.$https.post(b2_rest_url+'deleteMyCoupon','id='+id).then(res=>{
3747                    this.$delete(this.coupon.data,id)
3748                    this.$set(this.coupon,'count',this.coupon.count-1)
3749                })
3750            }
3751            return
3752        }
3753    },
3754    watch:{
3755        userData(val){
3756            if(val && this.$refs.asideContent){
3757                if(b2token){
3758                    this.ref = val.user_code
3759                    this.getNewDmsg()
3760                }
3761
3762                this.updateCarts()
3763            }
3764        },
3765        dmsg:{
3766            handler(newVal, old) {
3767                if(newVal.count > 0){
3768                    b2mobileFooterMenu.msg += parseInt(newVal.count)
3769                }
3770            },
3771            immediate: true,
3772            deep: true
3773        },
3774        msg:{
3775            handler(newVal, old) {
3776                if(newVal.count > 0){
3777                    b2mobileFooterMenu.msg += parseInt(newVal.count)
3778                }
3779            },
3780            immediate: true,
3781            deep: true
3782        },
3783        showBox(val){
3784            if(val && B2ClientWidth < 768){
3785                this.$refs.asideContainer.className += ' aside-show'
3786            }
3787        }
3788    }
3789})
3790
3791function b2HiddenFilterBox(event){
3792    event.parentNode.parentNode.className = event.parentNode.parentNode.className.replace('b2-show','');
3793    //bodyScrollLock.unlock(event.parentNode.parentNode)
3794}
3795
3796function b2flickity(){
3797    if(B2ClientWidth < 768) return
3798    var f = document.querySelectorAll('.home-collection-silder');
3799    if(f){
3800        var collection = []
3801        for (let i = 0; i < f.length; i++) {
3802            collection[i] = new Flickity(f[i],{
3803                pageDots: false,
3804                groupCells: true,
3805                draggable: true,
3806                prevNextButtons: false,
3807                freeScroll: false,
3808                wrapAround:true,
3809                selectedAttraction:0.15,
3810                friction:1,
3811                freeScrollFriction: 0.1,
3812                cellAlign: 'left'
3813            });
3814
3815            let previous,next
3816
3817            if(f[i].querySelector('.coll-3-box')){
3818                previous = f[i].parentNode.querySelector('.collection-previous');
3819            }else{
3820                previous = f[i].parentNode.parentNode.parentNode.querySelector('.collection-previous');
3821            }
3822
3823            previous.addEventListener( 'click', function() {
3824                collection[i].previous();
3825            },passiveSupported ? { passive: true } : false);
3826
3827            if(f[i].querySelector('.coll-3-box')){
3828                next = f[i].parentNode.querySelector('.collection-next');
3829            }else{
3830                next = f[i].parentNode.parentNode.parentNode.querySelector('.collection-next');
3831            }
3832
3833            next.addEventListener( 'click', function() {
3834                collection[i].next();
3835            },passiveSupported ? { passive: true } : false);
3836        }
3837    }
3838}
3839
3840b2flickity()
3841
3842function b2HiddenFooter(){
3843    let footer = document.querySelector('.site-footer .site-footer-widget-in')
3844    if(!footer) return
3845    let footerWidget = footer.querySelectorAll('.mobile-hidden')
3846
3847    if(footerWidget && footerWidget.length >= footer.childNodes.length){
3848        document.querySelector('.site-footer').className += ' mobile-hidden';
3849    }
3850}
3851b2HiddenFooter()
3852
3853var b2SearchUser = new Vue({
3854    el:'#user-list',
3855    data:{
3856        follow:[],
3857        ids:[]
3858    },
3859    mounted(){
3860        if(this.$refs.searchUser){
3861            this.ids = b2_search_data.users
3862            this.checkFollowByids()
3863        }
3864    },
3865    methods:{
3866        checkFollowByids(){
3867            let data = {
3868                'ids':this.ids
3869            }
3870            this.$http.post(b2_rest_url+'checkFollowByids',Qs.stringify(data)).then(res=>{
3871                this.follow = res.data
3872            })
3873        },
3874        followAc(id){
3875            if(!b2token){
3876                login.show = true
3877            }else{
3878                this.$http.post(b2_rest_url+'AuthorFollow','user_id='+id).then(res=>{
3879                    this.follow[id] = res.data
3880                }).catch(err=>{
3881
3882                    Qmsg['warning'](err.response.data.message,{html:true});
3883                })
3884            }
3885        },
3886        dmsg(id){
3887            if(!b2token){
3888                login.show = true
3889            }else{
3890                b2Dmsg.userid = id
3891                b2Dmsg.show = true
3892            }
3893        }
3894    }
3895});
3896
3897//精确计算
3898(function () {
3899    var calc = {
3900        /*
3901        函数,加法函数,用来得到精确的加法结果
3902        说明:javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显。这个函数返回较为精确的加法结果。
3903        参数:arg1:第一个加数;arg2第二个加数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数)
3904        调用:Calc.Add(arg1,arg2,d)
3905        返回值:两数相加的结果
3906        */
3907        Add: function (arg1, arg2) {
3908            arg1 = arg1.toString(), arg2 = arg2.toString();
3909            var arg1Arr = arg1.split("."), arg2Arr = arg2.split("."), d1 = arg1Arr.length == 2 ? arg1Arr[1] : "", d2 = arg2Arr.length == 2 ? arg2Arr[1] : "";
3910            var maxLen = Math.max(d1.length, d2.length);
3911            var m = Math.pow(10, maxLen);
3912            var result = Number(((arg1 * m + arg2 * m) / m).toFixed(maxLen));
3913            var d = arguments[2];
3914            return typeof d === "number" ? Number((result).toFixed(d)) : result;
3915        },
3916        /*
3917        函数:减法函数,用来得到精确的减法结果
3918        说明:函数返回较为精确的减法结果。
3919        参数:arg1:第一个加数;arg2第二个加数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数
3920        调用:Calc.Sub(arg1,arg2)
3921        返回值:两数相减的结果
3922        */
3923        Sub: function (arg1, arg2) {
3924            return Calc.Add(arg1, -Number(arg2), arguments[2]);
3925        },
3926        /*
3927        函数:乘法函数,用来得到精确的乘法结果
3928        说明:函数返回较为精确的乘法结果。
3929        参数:arg1:第一个乘数;arg2第二个乘数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数)
3930        调用:Calc.Mul(arg1,arg2)
3931        返回值:两数相乘的结果
3932        */
3933        Mul: function (arg1, arg2) {
3934            var r1 = arg1.toString(), r2 = arg2.toString(), m, resultVal, d = arguments[2];
3935            m = (r1.split(".")[1] ? r1.split(".")[1].length : 0) + (r2.split(".")[1] ? r2.split(".")[1].length : 0);
3936            resultVal = Number(r1.replace(".", "")) * Number(r2.replace(".", "")) / Math.pow(10, m);
3937            return typeof d !== "number" ? Number(resultVal) : Number(resultVal.toFixed(parseInt(d)));
3938        },
3939        /*
3940        函数:除法函数,用来得到精确的除法结果
3941        说明:函数返回较为精确的除法结果。
3942        参数:arg1:除数;arg2被除数;d要保留的小数位数(可以不传此参数,如果不传则不处理小数位数)
3943        调用:Calc.Div(arg1,arg2)
3944        返回值:arg1除于arg2的结果
3945        */
3946        Div: function (arg1, arg2) {
3947            var r1 = arg1.toString(), r2 = arg2.toString(), m, resultVal, d = arguments[2];
3948            m = (r2.split(".")[1] ? r2.split(".")[1].length : 0) - (r1.split(".")[1] ? r1.split(".")[1].length : 0);
3949            resultVal = Number(r1.replace(".", "")) / Number(r2.replace(".", "")) * Math.pow(10, m);
3950            return typeof d !== "number" ? Number(resultVal) : Number(resultVal.toFixed(parseInt(d)));
3951        }
3952    };
3953    window.Calc = calc;
3954}());
3955
3956function b2stmap(){
3957    let stmaps = document.querySelectorAll('.stamp');
3958    if(stmaps.length > 0){
3959        let h_axios = axios
3960
3961        if(b2token){
3962            h_axios.defaults.headers.common['Authorization'] = 'Bearer ' + b2token
3963        }
3964
3965        for (let i = 0; i < stmaps.length; i++) {
3966            stmaps[i].querySelector('.coupon-receive').onclick = (event)=>{
3967                if(!b2token){
3968                    login.show = true
3969                    return
3970                }
3971
3972                h_axios.post(b2_rest_url+'ShopCouponReceive','&id='+event.target.getAttribute('data-id')).then((res)=>{
3973                    if(res.data){
3974                        Qmsg['success'](b2_global.js_text.global.get_success,{html:true});
3975                    }
3976                }).catch(err=>{
3977                    Qmsg['success'](err.response.data.message,{html:true});
3978                })
3979
3980            }
3981            stmaps[i].querySelector('.more-coupon-info').onclick = (event)=>{
3982                event.target.nextElementSibling.style.display = 'block'
3983            }
3984            stmaps[i].querySelector('.close-coupon-info').onclick = (event)=>{
3985                event.target.parentNode.parentNode.style.display = 'none'
3986            }
3987        }
3988    }
3989}
3990b2stmap()
3991
3992// document.ready(function () {
3993//     let link = document.createElement("link");
3994//     link.rel = "stylesheet";
3995//     link.href = "//at.alicdn.com/t/font_1105559_00rtseygv6tsc.css";
3996
3997//     document.head.appendChild(link);
3998// })
3999
4000function b2IsPhoneAvailable(phonevalue){
4001    var phoneReg = /^1[0-9]{10}/;
4002    var emailReg = /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}\.[a-zA-Z0-9]{1,5}/;
4003    if(phoneReg.test(phonevalue) || emailReg.test(phonevalue)){
4004        return true;
4005    }else{
4006        return false;
4007    }
4008}
4009
4010var b2TaxTop = new Vue({
4011    el:'.tax-header',
4012    data:{
4013        showFliter:{
4014            hot:false,
4015            cat:false
4016        }
4017    },
4018    methods:{
4019        show(type){
4020            if(type === 'hot'){
4021                this.showFliter.hot = !this.showFliter.hot
4022                this.showFliter.cat = false
4023            }
4024            if(type === 'cat'){
4025                this.showFliter.cat = !this.showFliter.cat
4026                this.showFliter.hot = false
4027            }
4028        }
4029    }
4030})
4031
4032function b2scroll( fn ) {
4033    var beforeScrollTop = document.documentElement.scrollTop,
4034      fn = fn || function() {};
4035
4036    window.bodyScrool = function() {
4037        var afterScrollTop = document.documentElement.scrollTop || document.body.scrollTop,
4038          delta = afterScrollTop - beforeScrollTop;
4039
4040        if( delta === 0 ) return false;
4041
4042          fn( delta > 0 ? "down" : "up" ,afterScrollTop);
4043
4044        beforeScrollTop = afterScrollTop;
4045    }
4046
4047    window.addEventListener("scroll",window.bodyScrool , passiveSupported ? { passive: true } : false);
4048}
4049
4050function b2HeaderTop(){
4051
4052    const banner = document.querySelector('.header-banner-left');
4053    const header = document.querySelector('.site');
4054    const aside = document.querySelector('.bar-user-info');
4055    const socialTop = document.querySelector('.social-top');
4056    const nosub = document.querySelector('.social-no-sub');
4057    const footer = document.querySelector('.mobile-footer-menu');
4058    if(!banner) return
4059
4060    let h = 96
4061    if(B2ClientWidth < 768){
4062        h = 77
4063    }
4064
4065    if(socialTop){
4066        h = 113
4067    }
4068
4069    if(nosub){
4070        h = 58
4071    }
4072
4073    b2scroll(function(direction,top) {
4074
4075        if(top > h){
4076            if(direction === 'down'){
4077                if(banner.className.indexOf(' hidden') === -1){
4078                    banner.className += ' hidden'
4079                }
4080                if(header.className.indexOf(' up') === -1){
4081                    header.className += ' up'
4082                }
4083                if(B2ClientWidth > 768 && aside){
4084                    aside.style = 'padding-top:'+(h-28)+'px'
4085                }
4086
4087                if(footer && B2ClientWidth < 768 && footer.className.indexOf(' footer-down') === -1){
4088                    footer.className += ' footer-down'
4089                }
4090
4091              }else{
4092                banner.className = banner.className.replace(' hidden','')
4093                header.className = header.className.replace(' up','')
4094                if(B2ClientWidth > 768 && aside){
4095                    aside.style = 'padding-top:'+(h+10)+'px'
4096                }
4097
4098                if(footer && B2ClientWidth < 768){
4099                    footer.className = footer.className.replace(' footer-down','')
4100                }
4101              }
4102              if(header.className.indexOf(' action') === -1){
4103                header.className += ' action'
4104              }
4105        }else{
4106            header.className = header.className.replace(' action','')
4107            banner.className = banner.className.replace(' hidden','')
4108            header.className = header.className.replace(' up','')
4109            if(aside){
4110                aside.style = 'padding-top:'+(h+10)+'px'
4111            }
4112        }
4113    });
4114}
4115
4116b2HeaderTop()
4117
4118var b2NewsfalshesWidget = new Vue({
4119    el:'.widget-newsflashes-box',
4120    data:{
4121        options:[],
4122        list:''
4123    },
4124    mounted(){
4125        if(this.$refs.newsWidget){
4126            this.options = JSON.parse(this.$refs.newsWidget.getAttribute('data-json'))
4127            this.getList()
4128        }
4129    },
4130    methods:{
4131        getList(){
4132            this.$https.post(b2_rest_url+'getWidgetNewsflashes',Qs.stringify(this.options)).then(res=>{
4133                this.list = res.data
4134                this.$refs.gujia.style.display = 'none'
4135            })
4136        }
4137    }
4138})
4139
4140Vue.component('weixin-bind', {
4141    props: ['show','url','msg'],
4142    template:b2_global.weixin_bind,
4143    methods:{
4144        close(){
4145            this.$emit('close')
4146        }
4147    }
4148})
4149
4150//微信绑定
4151var b2weixinBind = new Vue({
4152    el:'#weixin-bind',
4153    data:{
4154        show:false,
4155        url:'',
4156        msg:''
4157    },
4158    methods:{
4159        close(){
4160            this.show = !this.show
4161        }
4162    }
4163})
4164
4165function b2CurrentPageReload(url){
4166    if(!url){
4167        url = location.href
4168    }
4169    setTimeout(() => {
4170        location.replace(url)
4171    }, 200);
4172    
4173}
4174
4175function b2GetQueryVariable(variable)
4176{
4177    var query = window.location.search.substring(1);
4178    var vars = query.split("&");
4179    for (var i=0;i<vars.length;i++) {
4180            var pair = vars[i].split("=");
4181            if(pair[0] == variable){return pair[1];}
4182    }
4183    return(false);
4184}
4185
4186function b2removeURLParameter(url, parameter) {
4187    //prefer to use l.search if you have a location/link object
4188    var urlparts = url.split('?');
4189    if (urlparts.length >= 2) {
4190
4191        var prefix = encodeURIComponent(parameter) + '=';
4192        var pars = urlparts[1].split(/[&;]/g);
4193
4194        //reverse iteration as may be destructive
4195        for (var i = pars.length; i-- > 0;) {
4196            //idiom for string.startsWith
4197            if (pars[i].lastIndexOf(prefix, 0) !== -1) {
4198                pars.splice(i, 1);
4199            }
4200        }
4201
4202        return urlparts[0] + (pars.length > 0 ? '?' + pars.join('&') : '');
4203    }
4204    return url;
4205}
4206
4207function updateURLParameter(uri, key, value) {
4208	if(!value) {
4209		return uri;
4210	}
4211	var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
4212	var separator = uri.indexOf('?') !== -1 ? "&" : "?";
4213	if (uri.match(re)) {
4214		return uri.replace(re, '$1' + key + "=" + value + '$2');
4215	}
4216	else {
4217		return uri + separator + key + "=" + value;
4218	}
4219}
4220
4221function validate(evt) {
4222    var theEvent = evt || window.event;
4223
4224    // Handle paste
4225    if (theEvent.type === 'paste') {
4226        key = event.clipboardData.getData('text/plain');
4227    } else {
4228    // Handle key press
4229        var key = theEvent.keyCode || theEvent.which;
4230        key = String.fromCharCode(key);
4231    }
4232    var regex = /[0-9]|\./;
4233    if( !regex.test(key) ) {
4234      theEvent.returnValue = false;
4235      if(theEvent.preventDefault) theEvent.preventDefault();
4236    }
4237}
4238
4239Vue.component('bind-login', {
4240    props: ['show','type'],
4241    template:b2_global.bind_login,
4242    data(){
4243        return {
4244            locked:false,
4245            count:60,
4246            SMSLocked:false,
4247            data:{
4248                img_code:'',
4249                token:'',
4250                username:'',
4251                password:'',
4252                confirmPassword:'',
4253                code:''
4254            },
4255            eye:false,
4256            success:''
4257        }
4258    },
4259    computed:{
4260        userData(){
4261            return this.$store.state.userData;
4262        }
4263    },
4264    methods:{
4265        close(){
4266            this.$emit('close')
4267        },
4268        showCheck(){
4269            if(this.type !== 'text' && this.type !== 'luo' && this.data.username && this.show){
4270                return true
4271            }
4272            return false
4273        },
4274        sendCode(){
4275            recaptcha.show = true
4276            recaptcha.type = 'bind'
4277            this.close()
4278        },
4279        sendSMS(){
4280            if(this.SMSLocked == true) return
4281            this.SMSLocked = true
4282            this.$http.post(b2_rest_url+'sendCode',Qs.stringify(this.data)).then(res=>{
4283                if(res.data.token){
4284                    this.countdown()
4285                    this.data.smsToken = res.data.token
4286                }
4287                this.SMSLocked = false
4288            }).catch(err=>{
4289
4290                Qmsg['warning'](err.response.data.message,{html:true});
4291                this.SMSLocked = false
4292            })
4293        },
4294        countdown(){
4295            if(this.count <= 1 ){
4296                this.count = 60
4297                return
4298            }
4299            this.count --;
4300            setTimeout(()=>{
4301                this.countdown()
4302            },1000)
4303        },
4304        setToken(val){
4305            this.data.img_code = val.value
4306            this.data.token = val.token
4307            this.sendSMS()
4308        },
4309        submit(){
4310            if(this.locked) return
4311            this.locked = true
4312            this.$http.post(b2_rest_url+'bindUserLogin',Qs.stringify(this.data)).then(res=>{
4313                this.success = res.data
4314                this.locked = false
4315            }).catch(err=>{
4316
4317                Qmsg['warning'](err.response.data.message,{html:true});
4318                this.locked = false
4319            })
4320        }
4321    }
4322})
4323
4324//强制绑定登录名
4325var b2bindLogin = new Vue({
4326    el:'#binding-login',
4327    data:{
4328        show:false,
4329        type:false
4330    },
4331    methods:{
4332        close(){
4333            this.show = !this.show
4334        },
4335        imgCodeAc(val){
4336            this.$refs.bindBox.setToken(val)
4337        }
4338    },
4339    watch:{
4340        type(val){
4341            if(val){
4342                this.show = true
4343            }
4344        }
4345    }
4346})
4347
4348var b2CreditTop = new Vue({
4349    el:'.credit-top',
4350    data:{
4351        settings:[],
4352        data:''
4353    },
4354    mounted(){
4355        if(this.$refs.creditTop){
4356            this.settings = JSON.parse(this.$refs.creditTop.getAttribute('data-settings'));
4357            this.getList()
4358        }
4359    },
4360    methods:{
4361        getList(){
4362            this.$http.post(b2_rest_url+'getGoldTop',Qs.stringify(this.settings)).then(res=>{
4363                this.data = res.data
4364                this.$nextTick(()=>{
4365                    this.$refs.creditTopGujia.style.display = 'none'
4366                })
4367            })
4368        }
4369    }
4370})
4371
4372function grin(tag,myField) {
4373
4374    if (document.selection) {
4375        myField.focus();
4376        sel = document.selection.createRange();
4377        sel.text = tag;
4378        myField.focus();
4379    }
4380    else if (myField.selectionStart || myField.selectionStart == '0') {
4381        var startPos = myField.selectionStart;
4382        var endPos = myField.selectionEnd;
4383        var cursorPos = startPos;
4384        myField.value = myField.value.substring(0, startPos)
4385                + tag
4386                + myField.value.substring(endPos, myField.value.length);
4387        cursorPos += tag.length;
4388        myField.focus();
4389        myField.selectionStart = cursorPos;
4390        myField.selectionEnd = cursorPos;
4391
4392    } else {
4393        myField.value += tag;
4394        myField.focus();
4395    }
4396}
4397
4398//圈子小工具
4399var b2HotCircle = new Vue({
4400    el:'.b2-widget-hot-circle',
4401    data:{
4402        data:'',
4403        count:6,
4404        type:'hot',
4405        paged:{
4406            hot:1,
4407            join:1,
4408            create:1
4409        },
4410        locked:false
4411    },
4412    mounted(){
4413        if(!this.$refs.hotCircle) return
4414        this.count = this.$refs.hotCircle.getAttribute('data-count');
4415        this.getCirclesList('hot')
4416    },
4417    methods:{
4418        go(link){
4419
4420            window.location.href = link
4421        },
4422        getCirclesList(type){
4423            if(!b2token && type !== 'hot'){
4424                login.show = true
4425                login.type = 1
4426                return
4427            }
4428            if(this.locked === true) return
4429            this.locked = true
4430            let data = {
4431                count:this.count,
4432                type:type,
4433                paged:this.paged[type]
4434            }
4435            this.$refs.gujia.style.display = 'block'
4436            this.data = ''
4437            this.$http.post(b2_rest_url+'getCirclesList',Qs.stringify(data)).then(res=>{
4438                this.data = res.data
4439                this.$nextTick(()=>{
4440                    this.$refs.gujia.style.display = 'none'
4441                    b2SidebarSticky()
4442                    lazyLoadInstance.update()
4443                })
4444                this.type = type
4445                this.locked = false
4446            }).catch(err=>{
4447                Qmsg['warning'](err.response.data.message,{html:true});
4448                this.locked = false
4449            })
4450        }
4451    }
4452})
4453
4454if (!window.scrollTo) {
4455    window.scrollTo = function (x, y) {
4456        window.pageXOffset = x;
4457        window.pageYOffset = y;
4458    };
4459}
4460if (!window.scrollBy) {
4461    window.scrollBy = function (x, y) {
4462        window.pageXOffset += x;
4463        window.pageYOffset += y;
4464    };
4465}
4466if (!document.body.scrollTo) {
4467    Element.prototype.scrollTo = function (x, y) {
4468        this.scrollLeft = x;
4469        this.scrollTop = y;
4470    };
4471}
4472if (!document.body.scrollBy) {
4473    Element.prototype.scrollBy = function (x, y) {
4474        this.scrollLeft += x;
4475        this.scrollTop += y;
4476    };
4477}
4478
4479var payReturn = new Vue({
4480    el:'#pay-return',
4481    data:{
4482        login:false
4483    },
4484    mounted(){
4485        if(b2token){
4486            this.login = true
4487        }
4488    }
4489})
4490
4491const searchBox = document.querySelectorAll('.search-module')
4492
4493if(searchBox){
4494    for (let index = 0; index < searchBox.length; index++) {
4495        let id = searchBox[index].getAttribute('data-i')
4496        new Vue({
4497            el:'#search-module-'+id,
4498            data:{
4499                link:b2_global.home_url,
4500                keyword:'',
4501                category:b2_global.js_text.global.all,
4502                show:false
4503            },
4504            mounted(){
4505                document.onclick = (e)=>{
4506
4507                    this.show = false
4508                    userTools.hideAction()
4509                }
4510            },
4511            methods:{
4512                picked(id,category,link){
4513                   this.link = link
4514                   this.category = category
4515                   this.show = false
4516                },
4517                pickedKey(key){
4518
4519                }
4520            }
4521        })
4522
4523    }
4524}
4525
4526var b2recommendedCircle = new Vue({
4527    el:'.b2-widget-recommended-circle',
4528    data:{
4529        data:'',
4530        current:0
4531    },
4532    mounted(){
4533        if(!this.$refs.recommendedGujia) return
4534        this.getCircles()
4535    },
4536    methods:{
4537        create(){
4538            if(!b2token){
4539                login.show = true
4540                login.loginType = 1
4541            }else{
4542                window.open(b2_global.home_url+'/create-circle', '_blank');
4543            }
4544        },
4545        getCircles(){
4546            let ids = JSON.parse(this.$refs.recommendedGujia.getAttribute('data-ids'))
4547            if(ids.length == 0) return
4548            let data = {
4549                ids:ids
4550            }
4551
4552            this.$http.post(b2_rest_url+'getCircleDataByCircleIds',Qs.stringify(data)).then(res=>{
4553                this.data = res.data
4554                this.$nextTick(()=>{
4555                    this.$refs.recommendedGujia.style.display = 'none'
4556                    if(typeof b2CirclePostBox != 'undefined'){
4557                        if(b2CirclePostBox.$refs.textareaTopic){
4558                            this.current = parseInt(b2CirclePostBox.$refs.textareaTopic.getAttribute('data-circle'))
4559                        }
4560                        
4561                    }
4562                    this.$nextTick(()=>{
4563                        lazyLoadInstance.update()
4564                    })
4565                    b2SidebarSticky()
4566                })
4567            })
4568        },
4569        go(even,index){
4570            if(typeof b2CirclePostBox != 'undefined'){
4571                even.stopPropagation()
4572                even.preventDefault()
4573                let id = this.data[index].id
4574                b2CirclePostBox.circle.picked = id
4575                this.current = id
4576                b2CircleList.pickedCircle('widget',id)
4577                b2CirclePostBox.getCurrentUserCircleData()
4578                window.history.pushState(id, this.data[index].name, this.data[index].link)
4579                document.title = this.data[index].name+' '+b2_global.site_separator+' '+b2_global.site_name
4580                // b2AsideBar.goTop()
4581                return false
4582            }
4583        }
4584    }
4585})
4586
4587document.b2ready = function (callback) {
4588    ///兼容FF,Google
4589    if (document.addEventListener) {
4590        document.addEventListener('DOMContentLoaded', function () {
4591            document.removeEventListener('DOMContentLoaded', arguments.callee, false);
4592            callback();
4593        }, false)
4594    }
4595     //兼容IE
4596    else if (document.attachEvent) {
4597        document.attachEvent('onreadystatechange', function () {
4598              if (document.readyState == "complete") {
4599                        document.detachEvent("onreadystatechange", arguments.callee);
4600                        callback();
4601               }
4602        })
4603    }
4604    else if (document.lastChild == document.body) {
4605        callback();
4606    }
4607}
4608
4609function b2tooltip(cla){
4610
4611    const d = document.querySelectorAll(cla)
4612    if(!d) return
4613    if(B2ClientWidth < 768) return
4614
4615    var x = 15;
4616    var y = 10;
4617
4618    window.b2thistip = []
4619
4620    for (let i = 0; i < d.length; i++) {
4621        d[i].addEventListener("mouseover", function(e) {
4622
4623            var tooltip = "<div class='b2tooltip' id='b2tooltip"+i+"'>" + this.getAttribute('data-title') + "</div>";
4624
4625            document.body.insertAdjacentHTML('beforeend', tooltip);
4626
4627            window.b2thistip[i] = document.querySelector('#b2tooltip'+i)
4628
4629            window.b2thistip[i].style.top = (e.pageY + y) + "px"
4630            window.b2thistip[i].style.left = (e.pageX + x) + "px"
4631
4632            window.b2thistip[i].style.display = 'block'
4633
4634        }, passiveSupported ? { passive: true } : false);
4635
4636        d[i].addEventListener("mouseout", function(e) {
4637            if(typeof window.b2thistip[i] != 'undefined')
4638            window.b2thistip[i].remove()
4639        },passiveSupported ? { passive: true } : false)
4640
4641        d[i].addEventListener("mousemove", function(e) {
4642
4643            window.b2thistip[i].style.top = (e.pageY + y) + "px"
4644            window.b2thistip[i].style.left = (e.pageX + x) + "px"
4645        },passiveSupported ? { passive: true } : false)
4646    }
4647
4648}
4649
4650b2tooltip('.b2tooltipbox')
4651
4652function b2cpay(){
4653    const paybox = document.querySelectorAll('.custom-pay-box')
4654
4655    if(paybox.length > 0){
4656        for (let i = 0; i < paybox.length; i++) {
4657            new Vue({
4658                el:paybox[i],
4659                data:{
4660                    locked:{},
4661                    count:{},
4662                    files:{},
4663                    progress:{},
4664                    // edited by fuzqing
4665                    related:false,
4666                    related_field:'',
4667                    related_prices:[],
4668                    active_time:{
4669                        active:false,
4670                        tips:''
4671                    },
4672
4673                    price:'',
4674                    api:'getCpayResout',
4675                    selecter:'cpay-resout-list-in',
4676                    list:{
4677                        pages:0,
4678                        paged:1,
4679                        count:20,
4680                        id:0,
4681                        data:''
4682                    },
4683                    allow:0,
4684                    tab:'form'
4685                },
4686                mounted(){
4687                    if(this.$refs.pickprice){
4688                        this.price = this.$refs.pickprice.getAttribute('data-price')
4689                    }
4690                    if(this.$refs.cpayresout){
4691                        this.list.id = this.$refs.cpayresout.getAttribute('data-id')
4692                        // this.getList()
4693                        this.$refs.reslist.go(this.list.paged,'comment',true,true)
4694                    }
4695                    // edited by fuzqing
4696                    this.getCpayInfo();
4697                },
4698                // edited by fuzqing
4699                watch: {
4700                    related_field: function (val) {
4701                        this.price = this.related_prices[val];
4702                    }
4703                },
4704                methods:{
4705                    // edited by fuzqing
4706                    getCpayInfo() {
4707                        this.$http.post(b2_rest_url+'getCpayInfo','post_id='+b2_global.post_id).then(res=>{
4708                            if (res.data.related === true) {
4709                                this.related = true;
4710                                this.related_field = res.data.related_field_value;
4711                                this.related_prices = res.data.related_prices;
4712                            }
4713                            this.active_time = res.data.active_time;
4714                        }).catch(err=>{
4715                            Qmsg['warning'](err.response.data.message,{html:true});
4716                        })
4717                    },
4718                    getList(res){
4719                        this.list.data = res.data
4720                        this.allow = res.allow
4721                        this.list.pages = res.pages
4722                    },
4723                    submit(title,id,postid) {
4724                        let obj = {};
4725                        let data = new FormData(this.$refs.form);
4726                        for (let [key, value] of data) {
4727
4728                            if (obj[key] !== undefined) {
4729                                if (!Array.isArray(obj[key])) {
4730                                    obj[key] = [obj[key]];
4731                                }
4732                                obj[key].push(value);
4733                            } else {
4734                                obj[key] = value;
4735                            }
4736
4737                            if(typeof obj[key] == 'object'){
4738                                if(obj[key].lastModified){
4739                                    delete obj[key]
4740                                }
4741                            }
4742
4743                            if(this.files.hasOwnProperty(key)){
4744                                obj[key] = this.files[key]
4745                            }
4746
4747                            if(this.$refs[key+'required']){
4748                                let required = this.$refs[key+'required'].getAttribute('data-required')
4749
4750                                required = parseInt(required)
4751                                if(required && (!obj[key] || (Array.isArray(obj[key]) && obj[key].length == 0))){
4752                                    Qmsg['warning'](b2_global.js_text.global.cpay_required_fields,{html:true});
4753                                    return
4754                                }
4755                            }
4756                        }
4757
4758                        if(!obj.price){
4759                            Qmsg['warning'](b2_global.js_text.global.cpay_required_fields,{html:true});
4760                            return
4761                        }
4762
4763                        b2DsBox.data = {
4764                            'title':title,
4765                            'order_type':'custom',
4766                            'order_price':obj.price,
4767                            'post_id':id,
4768                            'order_key':postid,
4769                            'order_value':JSON.stringify(obj)
4770                        }
4771                        b2DsBox.show = true
4772
4773                        console.log(b2DsBox.data)
4774
4775                        return obj;
4776
4777                    },
4778                    deleteAc(key,index){
4779                        if(confirm(b2_global.js_text.circle.remove_file)){
4780                            this.$delete(this.files[key],index)
4781                            this.$delete(this.progress[key],index)
4782                            this.locked[key] = false
4783                            this.$set(this.count,key,this.count[key] - 1)
4784                        }
4785                    },
4786                    fileExists(mime){
4787                        let index= mime.lastIndexOf('.');
4788                        let ext = mime.substr(index+1);
4789                        return ext.toLowerCase();
4790                    },
4791                    readablizeBytes(bytes) {
4792                        let s = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
4793                        let e = Math.floor(Math.log(bytes)/Math.log(1024));
4794                        return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+' '+s[e];
4795                    },
4796                    fileType(ext){
4797                        ext = ext.toLowerCase()
4798                        switch (ext) {
4799                            case 'jpg':
4800                            case 'png':
4801                            case 'gif':
4802                            case 'jpeg':
4803                            case 'ico':
4804                            case 'webp':
4805                                return 'image'
4806                            case 'mp3':
4807                            case 'm4a':
4808                            case 'ogg':
4809                            case 'wav':
4810                                return 'video'
4811                            case 'mp4':
4812                            case 'mov':
4813                            case 'avi':
4814                            case 'mpg':
4815                            case 'ogv':
4816                            case '3gp':
4817                            case '3g2':
4818                                return 'audio'
4819                            default:
4820                                return 'file'
4821                        }
4822                    },
4823                    fileChange(event,count,key,id){
4824
4825                        if(event.target.files.length > count){
4826                            let msg = b2_global.js_text.global.cpay_file_count
4827                            msg = msg.replace('${count}',count);
4828                            Qmsg['warning'](msg,{html:true});
4829
4830                            // event.target.
4831                            return;
4832                        }
4833
4834                        if(event.target.files.length <= 0) return
4835
4836                        if(!this.files.hasOwnProperty(key)){
4837                            this.$set(this.files,key,[])
4838                            this.$set(this.progress,key,[])
4839                            this.$set(this.locked,key,[])
4840                            this.$set(this.count,key,0)
4841                        }
4842
4843                        if(event.target.files.length > count - this.count[key]){
4844                            let msg = b2_global.js_text.global.cpay_file_count_less
4845                            msg = msg.replace('${count}',count - this.count[key]);
4846                            Qmsg['warning'](msg,{html:true});
4847
4848                            return;
4849                        }
4850
4851                        if(this.locked[key] == true) return
4852
4853                        let index = parseInt(this.files[key].length)
4854
4855                        Object.keys(event.target.files).forEach((k)=>{
4856                            console.log(k)
4857                            this.$set(this.count,key,this.count[key] + 1)
4858
4859                            this.locked[key] = true
4860
4861                            k = parseInt(k)
4862
4863                            const ext = this.fileExists(event.target.files[k].name)
4864
4865                            this.$set(this.files[key],k+index,{
4866                                size:this.readablizeBytes(event.target.files[k].size),
4867                                name:event.target.files[k].name,
4868                                ext:ext,
4869                                type:this.fileType(ext)
4870                            })
4871
4872                            this.$set(this.progress[key],k+index,{
4873                                status:'doing',
4874                                number:0,
4875                                msg:''
4876                            })
4877
4878                            let formData = new FormData()
4879
4880                            formData.append('file',event.target.files[k],event.target.files[k].name)
4881                            formData.append("post_id", id)
4882                            formData.append("type", 'cpay')
4883
4884                            let config = {
4885                                onUploadProgress: progressEvent=>{
4886                                    this.$set(this.progress[key][k+index],'number',(progressEvent.loaded / progressEvent.total * 100 | 0))
4887                                }
4888                            }
4889
4890                            this.$http.post(b2_rest_url+'fileUpload',formData,config).then(res=>{
4891                                console.log(res)
4892                                if(res.data.status == 401){
4893                                    Qmsg['warning'](res.data.message,{html:true});
4894
4895                                    this.$set(this.progress[key][k+index],'status','fail')
4896                                    this.$set(this.progress[key][k+index],'msg',res.data.message)
4897
4898                                }else{
4899                                    this.$set(this.files[key][k+index],'url',res.data.url)
4900
4901                                    this.$set(this.files[key][k+index],'id',res.data.id)
4902
4903                                    this.$set(this.progress[key][k+index],'status','success')
4904                                }
4905
4906                                console.log(this.files)
4907
4908                                if(this.count[key] >= count){
4909                                    this.locked[key] = true;
4910                                }else{
4911                                    this.locked[key] = false;
4912                                }
4913                                event.target.value = ''
4914                            }).catch(err=>{
4915                                Qmsg['warning'](err.response.data.message,{html:true});
4916                                this.locked[key] = false
4917                                this.$set(this.progress[key][k+index],'status','fail')
4918                                this.$set(this.progress[key][k+index],'msg',err.response.data.message)
4919                                event.target.value = ''
4920                            })
4921                        })
4922                    }
4923                }
4924            })
4925
4926        }
4927    }
4928}
4929b2cpay()
4930
4931function b2fingerprint() {
4932    var canvas = document.createElement('canvas');
4933    var ctx = canvas.getContext('2d');
4934    var txt = 'i9asdm..$#po((^@KbXrww!~cz';
4935    ctx.textBaseline = "top";
4936    ctx.font = "16px 'Arial'";
4937    ctx.textBaseline = "alphabetic";
4938    ctx.rotate(.05);
4939    ctx.fillStyle = "#f60";
4940    ctx.fillRect(125,1,62,20);
4941    ctx.fillStyle = "#069";
4942    ctx.fillText(txt, 2, 15);
4943    ctx.fillStyle = "rgba(102, 200, 0, 0.7)";
4944    ctx.fillText(txt, 4, 17);
4945    ctx.shadowBlur=10;
4946    ctx.shadowColor="blue";
4947    ctx.fillRect(-20,10,234,5);
4948    var strng=canvas.toDataURL();
4949
4950    var hash=0;
4951    if (strng.length==0) return;
4952    for (i = 0; i < strng.length; i++) {
4953        char = strng.charCodeAt(i);
4954        hash = ((hash<<5)-hash)+char;
4955        hash = hash & hash;
4956    }
4957    return hash;
4958}
4959
4960var b2stream = new Vue({
4961    el:'#b2-stream',
4962    data:{
4963        paged:1,
4964        pages:0,
4965        author:1,
4966        data:'',
4967        empty:false,
4968        locked:false
4969    },
4970    mounted(){
4971        if(!this.$refs.b2stream) return
4972        this.paged = this.$refs.b2stream.getAttribute('data-paged')
4973        this.author = this.$refs.b2stream.getAttribute('data-author')
4974        this.getList()
4975    },
4976    methods:{
4977        getList(){
4978            this.$http.post(b2_rest_url+'getStreamList','paged='+this.paged+'&author='+this.author).then(res=>{
4979                this.data = res.data
4980
4981                if(this.data.length == 0){
4982                    this.empty = true
4983                }
4984                this.$refs.gujia.style.display = 'none'
4985
4986                this.$nextTick(()=>{
4987                    b2SidebarSticky()
4988                    lazyLoadInstance.update()
4989                })
4990            })
4991        },
4992        vote(type,id,index){
4993
4994            if(!b2token){
4995                login.show = true
4996            }else{
4997                if(this.locked == true) return
4998                this.locked = true
4999
5000                this.$http.post(b2_rest_url+'postVote','type='+type+'&post_id='+id).then(res=>{
5001
5002                    this.$set(this.data[index].data.data,'up',parseInt(this.data[index].data.data.up) + parseInt(res.data.up))
5003                    this.$set(this.data[index].data.data,'down',parseInt(this.data[index].data.data.down) + parseInt(res.data.down))
5004
5005                    if(res.data.up > 0){
5006                        this.$set(this.data[index].data.data,'up_isset',1)
5007                    }else{
5008                        this.$set(this.data[index].data.data,'up_isset',0)
5009                    }
5010
5011                    if(res.data.down > 0){
5012                        this.$set(this.data[index].data.data,'down_isset',1)
5013                    }else{
5014                        this.$set(this.data[index].data.data,'down_isset',0)
5015                    }
5016
5017                    this.locked = false
5018                }).catch(err=>{
5019
5020                    Qmsg['warning'](err.response.data.message,{html:true});
5021                    this.locked = false
5022                })
5023            }
5024        }
5025    }
5026})
5027
5028//防抖
5029function _debounce(fn, delay) {
5030
5031    var delay = delay || 200;
5032    var timer;
5033    return function () {
5034        var th = this;
5035        var args = arguments;
5036        if (timer) {
5037            clearTimeout(timer);
5038        }
5039        timer = setTimeout(function () {
5040            timer = null;
5041            fn.apply(th, args);
5042        }, delay);
5043    };
5044}
5045// 节流
5046function _throttle(fn, interval) {
5047    var last;
5048    var timer;
5049    var interval = interval || 200;
5050    return function () {
5051        var th = this;
5052        var args = arguments;
5053        var now = +new Date();
5054        if (last && now - last < interval) {
5055            clearTimeout(timer);
5056            timer = setTimeout(function () {
5057                last = now;
5058                fn.apply(th, args);
5059            }, interval);
5060        } else {
5061            last = now;
5062            fn.apply(th, args);
5063        }
5064    }
5065}
5066
5067var askWidget = new Vue({
5068    el:'.b2-widget-ask',
5069    data:{
5070        data:'',
5071        fliter:'last',
5072        paged:1,
5073        pages:0,
5074        count:0,
5075        cat:0,
5076        empty:false,
5077        locked:false,
5078        prev:true,
5079        next:false
5080    },
5081    mounted(){
5082        if(!this.$refs.askwidget) return
5083        this.count = this.$refs.askwidget.getAttribute('data-count')
5084        this.time = this.$refs.askwidget.getAttribute('data-time')
5085        const archive = document.querySelector('.ask-archive')
5086
5087        if(archive){
5088            this.cat = archive.getAttribute('data-term')
5089        }
5090
5091        const single = document.querySelector('.ask-single-top')
5092
5093        if(single){
5094            this.cat = single.getAttribute('data-term')
5095        }
5096
5097        this.getData()
5098    },
5099    watch:{
5100        fliter(val){
5101            this.prev = true
5102            this.next = false
5103            this.data = ''
5104            this.paged = 1
5105            this.empty = false
5106            this.$refs.askwidget.querySelector('.gujia').style.display = 'block'
5107            this.getData()
5108        }
5109    },
5110    methods:{
5111        nexAc(){
5112            if(this.paged >= this.data.pages) return
5113            if(this.locked) return
5114            this.next = true
5115            this.paged++
5116            this.getData()
5117        },
5118        prevAc(){
5119            if(this.paged < 1) return
5120            if(this.locked) return
5121            this.prev = true
5122            this.paged--
5123            this.getData()
5124        },
5125        getData(){
5126            if(this.locked) return
5127            this.locked = true
5128            this.$http.post(b2_rest_url+'getAskData','paged='+this.paged+'&type='+this.fliter+'&count='+this.count+'&cat='+this.cat).then(res=>{
5129                this.locked = false
5130                if(this.paged == 1){
5131                    if(res.data.data.length == 0){
5132                        this.empty = true
5133                        this.data.data = []
5134                    }else{
5135                        this.data = res.data
5136                    }
5137                }else{
5138                    this.data.data = res.data.data
5139                }
5140                if(this.data.pages > 1 && this.paged < this.data.pages){
5141                    this.next = false
5142                }
5143                if(this.paged > 1){
5144                    this.prev = false
5145                }
5146                this.$nextTick(()=>{
5147                    this.$refs.askwidget.querySelector('.gujia').style.display = 'none'
5148                })
5149
5150                
5151            })
5152        }
5153    }
5154})

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.