整合移動(dòng)端vue富文本編輯器

近期將舊的商城系統(tǒng)統(tǒng)一遷移到JAVA商城平臺(tái),新的商城系統(tǒng)采用市場(chǎng)上成熟的產(chǎn)品。上線后將不使用默認(rèn)的模板,我們將開發(fā)一套適合自己風(fēng)格的模板。自帶的手機(jī)端模板沒有對(duì)移動(dòng)端的自定義評(píng)論功能進(jìn)行適配,我們將為它增加富文本功能。

使用的這套巡云商城系統(tǒng)對(duì)每個(gè)功能都分成模塊,全部支持傳統(tǒng)頁面訪問方式和json訪問方式。

1.我們將新建一個(gè)布局


新1.png

2.在布局"查詢添加評(píng)論頁(移動(dòng)版)"上添加版塊


新2.png

3.打開單頁應(yīng)用模板布局文件

 模板: 全部模板  >> 新模板[new]  >> 單頁應(yīng)用模板(移動(dòng)版)  >>  布局編輯

引入vue-html5-editor文件

<link href="${commonPath}js/vue-html5-editor/style.css" type="text/css" rel="stylesheet">
<script src="${commonPath}js/vue-html5-editor/vue-html5-editor.js" type="text/javascript"/>

增加評(píng)論模板

<!-- 自定義評(píng)論 -->
<template id="comment-template">
    <div>
        <div class="commentModule">
            <div class="button"><mt-button type="primary"  @click.native="addCommentUI();" style="height: 28px;font-size: 16px;">發(fā)表評(píng)論</mt-button></div>
        
            <!-- 發(fā)表評(píng)論 -->
            <mt-popup v-model="popup_comment" position="right" style="width: 100%;height: 100%;">
                <mt-header fixed title="發(fā)表評(píng)論" style="background: #fafafa; color: #000000;font-size: 14px">
                    <mt-button icon="back" @click.native="popup_comment = false" slot="left" >返回</mt-button>
                    <router-link to="/index" slot="right" @click.native="popup_comment = false" >
                        <span class="cms-home" style="font-size: 18px;"></span>
                    </router-link>
                </mt-header> 
                <div class="addCommentScroll">
                    <div class="box" >
                        <div class="addCommentForm" >
                            <ul>
                                <li>
                                    <editor :content="commentContent" :height="200" :z-index="99999" @change="updateData"></editor>
                                    <p class="tips">
                                        <span>{{error.commentContent}}</span>   
                                    </p>
                                </li>

                                <li style="margin-left: 10px;margin-right: 10px; margin-top: 10px; ">
                                    <mt-button  type="primary" size="large"  @click.native="addComment">提交</mt-button>
                                    <p class="tips">
                                        <span>{{error.customComment}}</span>    
                                    </p>
                                    
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </mt-popup>
        </div>
    </div>
</div>

4.增加評(píng)論js模塊
打開移動(dòng)版js文件


新3.png

增加js代碼

//評(píng)論組件
var comment_component = Vue.extend({
    template : '#comment-template',
    data : function data() {
        return {
            popup_comment :false,//發(fā)表評(píng)論彈出層
            customItemId : '',//自定義評(píng)論項(xiàng)目Id
            commentContent:'',//發(fā)表評(píng)論內(nèi)容
            showCaptcha : false, //是否顯示驗(yàn)證碼
            imgUrl : '', //驗(yàn)證碼圖片
            captchaKey : '', //驗(yàn)證碼key
            captchaValue : '', //驗(yàn)證碼value
            error : {
                commentContent: '',
                captchaValue : '',
                customComment: '',
            },
        };
    },
    created : function created() {
        //從URL中獲取自定義評(píng)論項(xiàng)目Id
        this.customItemId = "5";//這里先固定測(cè)試這個(gè)
    },
    components:{
        
        //發(fā)表評(píng)論富文本
        "editor" : new VueHtml5Editor({
            name: "editor",
            language: "zh-cn",
            // 自定義各個(gè)圖標(biāo)的class,默認(rèn)使用的是font-awesome提供的圖標(biāo)
            icons: {
                text: "fa fa-pencil",
                color: "fa fa-paint-brush",
                font: "fa fa-font",
                align: "fa fa-align-justify",
                list: "fa fa-list",
                link: "fa fa-link",
                unlink: "fa fa-unlink",
                tabulation: "fa fa-table",
                image: "fa fa-file-image-o",
                hr: "fa fa-minus",
                eraser: "fa fa-eraser",
                undo: "fa-undo fa",
                full: "fa fa-arrows-alt",
                info: "fa fa-info",
            },
            visibleModules: [
                "text",
                "color",
                "align",
                "link",
                "unlink",
                "eraser",
                "undo",
                "full-screen",
             ],
        })
    },
    methods : {

        //發(fā)表評(píng)論界面
        addCommentUI : function() {
            this.popup_comment = true;

            //查詢添加評(píng)論頁
            this.queryAddComment();
        },
        //查詢添加評(píng)論頁
        queryAddComment : function() {
        
            //是否顯示驗(yàn)證碼
            
        },
        //添加評(píng)論
        addComment : function(event) {
            if (!event._constructed) { //如果不存在這個(gè)屬性,則不執(zhí)行下面的函數(shù)
                return;
            }
            
            //提交內(nèi)容
            
        },
        

        //vue-html5-editor 富文本編輯器更新值
        updateData: function(data) {
            this.commentContent = data;
        },
    }
});

增加css代碼

.commentModule .addCommentScroll {
    width: 100%;
    height: 100%;
    background: #fff;
    right:0;
    margin-bottom: 0;
    border-bottom: none;
    overflow-y:hidden;
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}
.commentModule .addCommentScroll .box{
    padding-top: 40px;
}
.commentModule .addCommentScroll .box .addCommentForm{margin-left:5px; margin-right: 5px;}
.commentModule .addCommentScroll .box .addCommentForm .tips{line-height:30px; margin-left: 115px}
.commentModule .addCommentScroll .box .addCommentForm .tips span{color: red;}
.commentModule .addCommentScroll .box .addCommentForm .tag{
    position: relative;min-height:40px;margin-top: 10px;
}

完成效果圖


新4.png
最后編輯于
?著作權(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)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,351評(píng)論 25 708
  • 問答題47 /72 常見瀏覽器兼容性問題與解決方案? 參考答案 (1)瀏覽器兼容問題一:不同瀏覽器的標(biāo)簽?zāi)J(rèn)的外補(bǔ)...
    _Yfling閱讀 14,199評(píng)論 1 92
  • 今天上午,一次偶然的機(jī)會(huì)和我高中同學(xué)見面,他問我前年高中為什么選擇退學(xué),我說不想上了唄。他笑著問我這么沒誠意,連我...
    越過白城閱讀 1,955評(píng)論 1 11
  • 我是仙女手中的一滴雨 平凡而無味 卻總愛在白云的襁褓中撒嬌 看著同伴一個(gè)個(gè)的離去 毫無依戀 只能笑他們太傻,太傻 ...
    Juli1128閱讀 185評(píng)論 2 3
  • 又是一年高考季,與之前那十七年不同的是,它,是屬于我的。 高三以前,不懂高三。寫不完的作業(yè),刷不完的習(xí)...
    西顧微微閱讀 341評(píng)論 14 3

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