108 lines
3.2 KiB
JavaScript
108 lines
3.2 KiB
JavaScript
$(function () {
|
||
const setIndexData = () => {
|
||
const commentObj = JSON.parse(sessionStorage.commentData);
|
||
commentObj.feedback_type.forEach((item, index) => {
|
||
$("#radioBox").append(`
|
||
<div class="radio">
|
||
<input type="radio" name="radioId" id="ptionsRadios${index}" value=${item.id} />
|
||
<label for="${item.id}">
|
||
<p class="radio-title">${item.name}</p>
|
||
<p class="radio-desc">${item.description}</p>
|
||
</label>
|
||
</div>
|
||
`);
|
||
});
|
||
$("#ptionsRadios0").prop("checked", true);
|
||
console.log();
|
||
};
|
||
|
||
$("#subBtn").click(function (event) {
|
||
event.preventDefault(); // 阻止默认的提交行为
|
||
// 获取表单元素
|
||
const titleInput = $("#inputTitle");
|
||
const descriptionInput = $("#inputDescription");
|
||
// 验证表单元素
|
||
if (!validateRequired(titleInput)) {
|
||
return;
|
||
}
|
||
if (!validateRequired(descriptionInput)) {
|
||
return;
|
||
}
|
||
subFeedback();
|
||
$("#ptionsRadios0").prop("checked", true);
|
||
$("#inputTitle").val("");
|
||
$("#inputDescription").val("");
|
||
$("#contactInput").val("");
|
||
});
|
||
// 提交
|
||
function subFeedback() {
|
||
$.ajax({
|
||
url: "/console/v1/feedback",
|
||
method: "POST",
|
||
headers: {
|
||
Authorization: "Bearer" + " " + localStorage.jwt,
|
||
},
|
||
data: {
|
||
type: $('input[name="radioId"]:checked').val(),
|
||
title: $("#inputTitle").val(),
|
||
description: $("#inputDescription").val(),
|
||
attachment: [],
|
||
contact: $("#contactInput").val(),
|
||
},
|
||
success: function (res) {
|
||
showMessage("success", "提交成功!", 2000); // 显示 3 秒钟的成功消息
|
||
},
|
||
});
|
||
}
|
||
|
||
// 表单元素必填验证函数
|
||
function validateRequired(input) {
|
||
if (input.val().trim() === "") {
|
||
input.attr("style", "border: 1px solid #FF6739;");
|
||
input.focus();
|
||
return false;
|
||
}
|
||
input.attr("style", "border: 1px solid #E6EAED;");
|
||
return true;
|
||
}
|
||
// 获取通用配置信息(反馈页:用插件覆盖 feedback_type)
|
||
function getCommentInfo() {
|
||
$.ajax({
|
||
url: "/console/v1/common",
|
||
method: "get",
|
||
headers: {
|
||
Authorization: "Bearer" + " " + localStorage.jwt,
|
||
},
|
||
success: function (res) {
|
||
if (!res || res.status !== 200 || !res.data) {
|
||
return;
|
||
}
|
||
var baseData = res.data || {};
|
||
|
||
$.ajax({
|
||
url: "/console/v1/theme/config",
|
||
method: "get",
|
||
headers: {
|
||
Authorization: "Bearer" + " " + localStorage.jwt,
|
||
},
|
||
success: function (pluginRes) {
|
||
if (pluginRes && pluginRes.status === 200 && pluginRes.data) {
|
||
var cfg = pluginRes.data || {};
|
||
if (cfg.feedback_type) {
|
||
baseData.feedback_type = cfg.feedback_type;
|
||
}
|
||
}
|
||
sessionStorage.commentData = JSON.stringify(baseData);
|
||
setIndexData();
|
||
},
|
||
error: function () {
|
||
sessionStorage.commentData = JSON.stringify(baseData);
|
||
setIndexData();
|
||
},
|
||
});
|
||
},
|
||
});
|
||
}
|
||
getCommentInfo();
|
||
});
|