inleft
2022-03-04 74344a2ec388b78fe906a22c31f8fdb77fc60b12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<template>
    <div>
        <div class="visitInfo">
            <a-form-model ref="myForm" layout="inline" :rules="rules" :model="form" :label-col="labelCol"
                :wrapper-col="wrapperCol">
                <a-form-model-item label="昵称" prop="nickName">
                    <a-input v-model="form.nickName" placeholder="需填..">
                    </a-input>
                </a-form-model-item>
                <a-form-model-item label="邮箱" prop="eMail">
                    <a-input v-model="form.eMail" placeholder="..仅后台可见">
                    </a-input>
                </a-form-model-item>
                <a-form-model-item label="主页" prop="homePage">
                    <a-input v-model="form.homePage" placeholder="https:// or http://">
                    </a-input>
                </a-form-model-item>
 
            </a-form-model>
        </div>
        <div class="replyMsgInfo" v-if="showReplyMsgInfo">
            <div>{{msgInfo.useName}} </div>
            <div style="padding: 0px 3px;"> : </div>
            <div>
                <span v-html="msgInfo.userComment.replace(/\n/g, '<br>')"></span>
            </div>
        </div>
        <a-comment>
            <div slot="content">
                <a-form-item>
                    <a-textarea :rows="4" v-model="form.visitorContent" :placeholder="replyHolder" />
                </a-form-item>
                <div>
                        <a-button html-type="submit" type="primary" @click="send()" v-if="!showReplyMsgInfo"
                            :disabled="isSending || $attrs.isAllowedComment==0">
                            高低整两句
                        </a-button>
                        <a-button html-type="submit" type="primary" v-else @click="send()"
                            :disabled="isSending || $attrs.isAllowedComment==0">
                            回复Ta
                        </a-button>
                        <span class="myTip" v-if="$attrs.isAllowedComment==0">很遗憾,评论已关闭</span>
                </div>
 
                <div>
                    <a-checkbox style=" margin-left: 8px;" v-if="!showReplyMsgInfo" v-model="form.isSecretMsg">
                        悄悄说..<span class="myTip">(仅登录后可查看)</span>
                    </a-checkbox>
                    <!-- <a-checkbox v-model="form.isReceiveMail">
                        接收邮件回复通知
                    </a-checkbox> -->
                </div>
            </div>
        </a-comment>
    </div>
</template>
 
<script>
    import {
        blogCommentAdd
    } from '../../api/blogArticleComment.js'
 
    export default {
        methods: {
            getMsgInfo(param) {
                this.msgInfo = param;
                this.showReplyMsgInfo = true;
                this.replyHolder = "@" + this.msgInfo.useName;
            },
            send() {
                if (this.form.nickName === "") {
                    this.$message.info("怎么称呼..")
                    return
                }
 
                if (this.form.visitorContent === "") {
                    this.$message.info("你可能需要说点什么..")
                    return
                }
 
                var res;
                this.$refs.myForm.validate(valid => {
                    if (valid) {
                        //this.$message.info("校验通过")
                        res = true;
                    } else {
                        this.$message.info("校验失败")
                        res = false;
                    }
                });
                var articleId = this.$attrs.articleId;
                let commentType = (articleId == null || articleId == undefined) ? 1 : 2;
                this.isSending = true;
 
                blogCommentAdd({
                    parentId: this.msgInfo.parentId,
                    replyId: this.msgInfo.replyId,
                    "visitorId": "1",
                    "isReceiveMail": 0,
                    "articleId": articleId,
                    "commentType": commentType,
                    "authStatus": this.form.isSecretMsg ? 2 : 1,
                    // "isReceiveMail": this.form.isReceiveMail ? 1 : 0,
                    "visitorEmail": this.form.eMail,
                    "visitorHomePage": this.form.homePage,
                    "visitorNickName": this.form.nickName,
                    "commentContent": this.form.visitorContent,
                }).then((res) => {
                    this.isSending = false;
                    if (res.code == 200) {
                        this.$emit("sendMsg");
                        this.$message.info("信息已送达..")
                    } else {
                        this.$notification.error({
                            message: '好像哪里不对劲..',
                            description: res.message,
                            placement: 'bottomRight'
                        });
                    }
                }).catch((error) => {
                    this.$message.error("请求失败")
                    this.isSending = false;
                })
                // setTimeout(() => {
                //     this.$message.info("发送成功")
                //     this.isSending = false;
                // }, 3000);
 
            }
        },
 
        data() {
            return {
                isSending: false,
                replyHolder: "",
                msgInfo: {
                    useName: "",
                    userComment: "",
                    parentId: 0,
                    replyId: 0
                },
                showReplyMsgInfo: false,
                labelCol: {
                    span: 6,
                    offset: 0,
                },
                wrapperCol: {
                    span: 15,
                    offset: 0
                },
                form: {
                    nickName: "",
                    eMail: "",
                    homePage: "",
                    isReceiveMail: false,
                    isSecretMsg: false,
                    visitorContent: "",
                    parentId: 0,
                    replyId: 0
                },
                rules: {
                    "nickName": [{
                        message: '怎么称呼?',
                    }, {
                        trigger: 'blur',
                        max: 20,
                        message: '你的名字也太长了..'
                    }],
                    "eMail": [{
                        trigger: 'blur',
                        pattern: /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/,
                        message: '邮箱格式不正确'
                    }, {
                        trigger: 'blur',
                        max: 50,
                        message: '邮箱不要超过50字符..'
                    }],
                    "homePage": [{
                        trigger: 'blur',
                        pattern: /^((https|http)?:\/\/)[^\s]+/,
                        message: '仅支持 https | http'
                    }, {
                        trigger: 'blur',
                        max: 50,
                        message: '网址不要超过50字符..'
                    }]
                },
            }
        }
    }
</script>
 
<style lang="less">
    .replyMsgInfo {
        display: flex;
        border-radius: 4px;
        box-shadow: 0px 9px 10px 0 rgba(0, 0, 0, 0.24), 1px 3px 15px 0 rgba(0, 0, 0, 0.19);
        padding: 20px 25px 20px;
        margin-left: 15px;
        margin-top: 10px;
    }
</style>