js 仿微信投訴—引入vue.js,拆分組件為單個(gè)js

效果:


仿微信投訴.gif

頁(yè)面目錄:


image.png

index.html:

<!DOCTYPE html >
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="format-detection" content="telephone=no">
        <meta http-equiv="x-dns-prefetch-control" content="on">
        <title>投訴</title>
        <link rel="stylesheet" href="css/weui.css">
        <link rel="stylesheet" href="css/wxappeal.css">
        <script src="https://cdn.staticfile.org/vue/2.4.2/vue.min.js"></script>
        <script src="https://cdn.staticfile.org/vue-router/2.7.0/vue-router.min.js"></script>
        <script src="js/tools/jquery.js"></script>
        <script src="js/tools/methods.js"></script>
        <!--組件js引入要注意順序,否則會(huì)報(bào)錯(cuò)-->
        <script src="js/components/TopNav.js"></script>
        <script src="js/components/BottomNav.js"></script>
        <script src="js/components/AppealNav.js"></script>
        <script src="js/pages/AppealDetail.js"></script>
        <script src="js/pages/AppealSuccess.js"></script>
        <script src="js/pages/ChooseAppeal.js"></script>
        <script src="js/pages/ChooseType.js"></script>
        <script src="js/pages/NetError.js"></script>
        <script src="js/main.js"></script>
    </head>
    <body>
        <div id="app">
            <keep-alive>
                <router-view class="child-view" v-if="$route.meta.keepAlive"></router-view>
            </keep-alive>

            <router-view class="child-view" v-if="!$route.meta.keepAlive"></router-view>
        </div>

        <!-- 選擇投訴類(lèi)型 start-->
        <script type="text/x-template" id="chooseTypeCom">
            <div class='all'>
                <TopNav :toptxt="toptxt"></TopNav>
                <router-link tag='li' v-for="item in types" :to="{name:'ChooseAppeal',query:{id:item.id}}" class="weui-cell weui-cell_access js_item" data-id="button">
                    <div class="weui-cell__bd">
                        <p class="bold">{{item.title}}</p>
                    </div>
                    <div class="weui-cell__ft"></div>
                </router-link>
                <BottomNav :bottomtxt="bottomtxt" :link_url="link_url"></BottomNav>
                <AppealNav></AppealNav>
            </div>
        </script>
        <!-- 選擇投訴類(lèi)型 end-->

        <!-- 提交給微信團(tuán)隊(duì) start-->
        <script type="text/x-template" id="chooseAppealCom">
            <div class="all">
                <TopNav :toptxt="toptxt"></TopNav>
                <li class="weui-cell weui-cell_access js_item" data-id="button" @click="submitAppeal">
                    <div class="weui-cell__bd">
                        <p class="bold">{{title}}</p>
                    </div>
                    <div class="weui-cell__ft"></div>
                </li>
                <BottomNav :bottomtxt="bottomtxt" :link_url="link_url"></BottomNav>
                <AppealNav></AppealNav>
            </div>
        </script>
        <!-- 提交給微信團(tuán)隊(duì) end-->

        <!-- 投訴須知 start-->
        <script type="text/x-template" id="appealDetailCom">
            <div class="backWhite">
                <p class="appealTitle center">投訴須知</p>
                <div class="content">
                    <span class="small">你應(yīng)保證你的投訴行為基于善意,并代表你本人真實(shí)意思。
                    騰訊作為中立的平臺(tái)服務(wù)者,收到你投訴后,會(huì)盡快按照相關(guān)法律法規(guī)的規(guī)定獨(dú)立判斷并進(jìn)行處理。
                    騰訊將會(huì)采取合理的措施保護(hù)你的個(gè)人信息;除法律法規(guī)規(guī)定的情形外,未經(jīng)用戶許可騰訊不會(huì)向第三方公開(kāi)、
                    透露你的個(gè)人信息。</span>
                </div>
            </div>
        </script>
        <!-- 投訴須知 end-->

        <!-- 提交成功 start-->
        <script type="text/x-template" id="appealSuccessCom">
            <div class="weui-msg">
                <div class="weui-msg__icon-area">
                    <i class="weui-icon-success weui-icon_msg"></i>
                </div>
                <div class="weui-msg__text-area">
                    <h2 class="weui-msg__title">投訴已提交</h2>
                    <p class="weui-msg__desc left">微信團(tuán)隊(duì)將會(huì)盡快核實(shí),并通過(guò)"微信團(tuán)隊(duì)"通知你審核結(jié)果。感謝你的支持。</p>
                </div>
                <div class="weui-msg__opr-area">
                    <p class="weui-btn-area">
                        <a href="javascript:;" class="weui-btn weui-btn_primary" @click="$close">關(guān)閉</a>
                    </p>
                </div>
            </div>
        </script>
        <!-- 提交成功 end-->

        <!-- 提交失敗 start-->
        <script type="text/x-template" id="netErrorCom">
            <div class="weui-msg">
                <div class="weui-msg__icon-area">
                    <i class="weui-icon-warn weui-icon_msg"></i>
                </div>
                <div class="weui-msg__text-area">
                    <h2 class="weui-msg__title">錯(cuò)誤</h2>
                    <p class="weui-msg__desc">網(wǎng)絡(luò)異常,請(qǐng)稍后嘗試</p>
                </div>
                <div class="weui-msg__opr-area">
                    <p class="weui-btn-area">
                        <a href="javascript:;" class="weui-btn weui-btn_primary" @click="$close">關(guān)閉</a>
                    </p>
                </div>
            </div>
        </script>
        <!-- 提交失敗 end-->
    </body>
</html>

weui.css: 采用的是WeUI v2.0.1 (https://github.com/weui/weui)

wxappeal.css:

body {
    width: 100%;
    height: 100%;
}

.all {
    width: 100%;
    height: 100%;
    /* background-color: #ededed; */
}

div {
    margin: 0;
    padding: 0;
    font-size: 17px;
}

.content {
    width: 90%;
    margin: auto;
}

.center {
    text-align: center;
}

.left {
    text-align: left;
}

.gray {
    color: rgba(0, 0, 0, 0.5);
}

.deepBlue {
    color: #576B95;
}

.small {
    font-size: 14px;
}

.bold {
    /* font-weight: 600; */
}

.top-nav {
    padding: 12px 16px 5px 16px;
}

.bottom-nav {
    padding: 5px 16px 0 16px;
}

.weui-cell {
    background-color: #ffffff;
}

.appeal-nav {
    width: 100%;
    display: flex;
    justify-content: center;
    position: absolute;
    bottom: 7%;
}

.backWhite {
    width: 100%;
    height: 100%;
    background-color: #ffffff;
}


.appealTitle {
    margin: 20px 0;
}

methods.js:

Vue.prototype.$close = function() {  //關(guān)閉微信瀏覽器,只在微信端有效,其他會(huì)報(bào)錯(cuò)
    document.addEventListener('WeixinJSBridgeReady', function() {
        WeixinJSBridge.call('closeWindow');
    }, false);
    WeixinJSBridge.call('closeWindow');
}

TopNav.js:

// 頂部組件  start
var TopNav = Vue.extend({
    template: "<p class='top-nav gray small'>{{toptxt}}</p>",
    data() {
        return {
            toptxt: ''
        }

    },
    props: ['toptxt'],
    watch: {
        toptxt: function(newVal, oldVal) {
            this.toptxt = newVal;
        }
    }
})

Vue.component(TopNav)
// 頂部組件  end

BottomNav.js:

// 底部組件  start
var BottomNav = Vue.extend({
    template: "<p class='small bottom-nav'><a class='deepBlue'" +
        ":href='link_url'>{{bottomtxt}}</a></p>",
    data() {
        return {
            bottomtxt: '',
            link_url: ''
        }

    },
    props: ['bottomtxt', 'link_url'],
    watch: {
        bottomtxt: function(newVal, oldVal) {
            this.bottomtxt = newVal;
        },
        link_url: function(newVal, oldVal) {
            this.link_url = newVal;
        }
    }
})

Vue.component(BottomNav)
// 底部組件  end

AppealNav.js:

// 底部投訴組件  start
var AppealNav = Vue.extend({
    template: "<p class='appeal-nav small'><router-link class='deepBlue'" +
        "to='/appealDetail'>投訴須知</router-link></p>",
})

Vue.component(AppealNav)
// 底部投訴組件  end

AppealDetail.js:

// 投訴須知組件  start
var AppealDetail = Vue.extend({
    template: "#appealDetailCom",
})

Vue.component(AppealDetail)
// 投訴須知組件  end

AppealSuccess.js:

//  投訴成功組件  start
var AppealSuccess = Vue.extend({
    template: "#appealSuccessCom",
})

Vue.component(AppealSuccess)
//  投訴成功組件  end

ChooseAppeal.js:

//提交投訴  start
var ChooseAppeal = Vue.extend({

    template: "#chooseAppealCom",
    components: {
        TopNav,
        BottomNav,
        AppealNav
    },
    data() {
        return {
            toptxt: '你可以:',
            bottomtxt: '',
            link_url: 'javascript:;',
            title: '提交給微信團(tuán)隊(duì)審核',
            i: ''
        }
    },
    mounted() {
        let _this = this;
        _this.setUrl();
    },
    methods: {
        submitAppeal() {
            let _this = this;
            _this.$router.push({
                name: "AppealSuccess"
            })
        },
        setUrl() {
            let _this = this,
                i = _this.$route.query.id;
            _this.i = i;
            if (i == 6) {
                _this.bottomtxt = '了解什么是誘導(dǎo)分享類(lèi)內(nèi)容';
                _this.link_url = 'www.baidu.com';
            } else if (i == 7) {
                _this.bottomtxt = '了解微信對(duì)謠言的治理';
                _this.link_url = '';
            }
        }
    }
})

Vue.component(ChooseAppeal)
//提交投訴  end

ChooseType.js:

// 選擇投訴類(lèi)型  start
var ChooseType = Vue.extend({
    template: "#chooseTypeCom",
    components: {
        TopNav,
        BottomNav,
        AppealNav
    },
    data() {
        return {
            toptxt: '請(qǐng)選擇投訴該網(wǎng)頁(yè)的原因:',
            bottomtxt: '遇到網(wǎng)頁(yè)流量被劫持怎么辦',
            link_url: 'javascript:;',
            types: [{
                    "id": 1,
                    "title": "網(wǎng)頁(yè)包含欺詐信息(如: 假紅包)"
                },
                {
                    "id": 2,
                    "title": "網(wǎng)頁(yè)包含色情信息"
                },
                {
                    "id": 3,
                    "title": "網(wǎng)頁(yè)包含暴力恐怖信息"
                },
                {
                    "id": 4,
                    "title": "網(wǎng)頁(yè)包含政治敏感信息"
                },
                {
                    "id": 5,
                    "title": "網(wǎng)頁(yè)在收集個(gè)人隱私信息(如: 釣魚(yú)鏈接)"
                },
                {
                    "id": 6,
                    "title": "網(wǎng)頁(yè)包含誘導(dǎo)分享/關(guān)注性質(zhì)的內(nèi)容"
                },
                {
                    "id": 7,
                    "title": "網(wǎng)頁(yè)可能包含謠言信息"
                },
                {
                    "id": 8,
                    "title": "網(wǎng)頁(yè)包含賭博信息"
                },
            ]
        }
    }
})

Vue.component(ChooseType)
//選擇投訴類(lèi)型  end

NetError.js:

// 投訴失敗組件  start
var NetError = Vue.extend({
    template: "#netErrorCom",
})

Vue.component(NetError)
//  投訴失敗組件  end

main.js:

'use strict';
$(document).ready(function() {
    Vue.use(VueRouter);

    var router = new VueRouter({
        routes: [{
                path: '/',
                name: 'ChooseType',
                meta: {
                    index: 0,
                    keepAlive: true,
                    title: '投訴'
                },
                component: ChooseType
            },
            {
                path: '/chooseAppeal',
                name: 'ChooseAppeal',
                meta: {
                    index: 1,
                    keepAlive: false,
                    title: '投訴'
                },
                component: ChooseAppeal
            },
            {
                path: '/appealDetail',
                name: 'AppealDetail',
                meta: {
                    index: 3,
                    keepAlive: false,
                    title: '投訴須知'
                },
                component: AppealDetail
            },
            {
                path: '/appealSuccess',
                name: 'AppealSuccess',
                meta: {
                    index: 4,
                    keepAlive: false,
                    title: '投訴'
                },
                component: AppealSuccess
            },
            {
                path: '/netError',
                name: 'NetError',
                meta: {
                    index: 5,
                    keepAlive: false,
                    title: '投訴'
                },
                component: NetError
            },

        ]
    })

    router.beforeEach((to, from, next) => {
        var toDepth = to.meta.index;
        var fromDepth = from.meta.index;

        if (to.meta.title) {
            document.title = to.meta.title;
            if (toDepth == 'undefined' || toDepth == undefined) {
                next({
                    path: "/netError"
                })
            } else if (toDepth < fromDepth) { //類(lèi)似緩存效果
                from.meta.keepAlive = false;
                to.meta.keepAlive = true;
                next()
            } else {
                next()
            }
        } else {
            next()
        }
    })

    var app = new Vue({
        el: '#app',
        router
    }).$mount('#app')
})

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容