Skip to content

Commit 569438e

Browse files
committed
fix:修复js获取评论数据的问题
解决评论问题!
1 parent 1f5a3c3 commit 569438e

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

assets/js/lanstarApp.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@ const utils = {
22
getFormData: function () {
33
let text = document.querySelector('#textarea').value;
44
let reply = document.querySelector('#comment-parent') ? document.querySelector('#comment-parent').value : false
5-
let data = ''
5+
let author = document.querySelector('#author') ? document.querySelector('#author').value : false;
6+
let mail = document.querySelector('#mail')?.value;
7+
let url = document.querySelector('#url') ? document.querySelector('#url').value : false;
8+
let data = '';
9+
text = text.replace("&", "%26");
10+
// 判断是否登录,23.1.14
11+
if(!document.querySelector("#comment-form").dataset.login){
12+
data = `author=${author}&mail=${mail}&`
13+
}
14+
if(url){
15+
data += `url=${url}&`
16+
}
617
// 防止参数带&截断,2023.1.2
7-
text = text.replace("&", "%26")
818
if (reply) {
9-
data = `text=${text}&parent=${reply}`
19+
data += `text=${text}&parent=${reply}`
1020
} else {
11-
data = `text=${text}`
21+
data += `text=${text}`
1222
}
1323
return data
1424
},
@@ -283,6 +293,7 @@ const lanstar = {
283293
if (this.dataset.disabled == 'disabled') return;
284294
this.dataset.disabled = 'disabled';
285295
document.querySelector('.comments-toolbar .submit').textContent = '传输中...';
296+
console.log(this.getAttribute('action'))
286297
fetch(this.getAttribute('action'), {
287298
method: 'post',
288299
body: utils.getFormData(),

index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @package Lanstar
66
* @author 染念
7-
* @version 4.0.0
7+
* @version 4.0.1
88
* @link https://dyedd.cn
99
*/
1010

layout/comments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function threadedComments($comments, $options)
5555
<?php $comments->cancelReply(); ?>
5656
</div>
5757
<div id="response"><?php _e('发表评论'); ?></div>
58-
<form method="post" action="<?php $this->commentUrl() ?>" id="comment-form" role="form">
58+
<form method="post" action="<?php $this->commentUrl() ?>" data-login="<?= $this->user->hasLogin()?>" id="comment-form" role="form" >
5959
<?php if (!$this->user->hasLogin()): ?>
6060
<div class="option">
6161
<label for="author" class="required"></label>

0 commit comments

Comments
 (0)