样式修改完成,待测试

This commit is contained in:
rain
2026-07-07 17:07:34 +08:00
parent 0f6ed0cad3
commit 8a6a8acab7
32 changed files with 2097 additions and 505 deletions
+11 -138
View File
@@ -11,7 +11,6 @@ const $ = layui.$;
let isSubmittingPayArticle = false;
let selections = [];
let stepsConfig = [];
const REQUIRED_DAILY_FREE_ARTICLES = 2;
// 页面加载完成后获取首页信息
layui.$(document).ready(function () {
CommonUtil.loadPageConfig({ ads: false, links: false });
@@ -33,149 +32,23 @@ const $ = layui.$;
});
});
// 判断布尔字段,兼容后端可能返回的 1/true/"true"
function isTruthy(value) {
return (
value === true ||
value === 1 ||
value === "1" ||
String(value).toLowerCase() === "true"
);
}
function padDatePart(value) {
return String(value).padStart(2, "0");
}
function formatLocalDate(date) {
return (
date.getFullYear() +
"-" +
padDatePart(date.getMonth() + 1) +
"-" +
padDatePart(date.getDate())
);
}
function getArticleDateText(value) {
if (!value) return "";
if (typeof value === "number") {
const numericDate = new Date(value);
return isNaN(numericDate.getTime())
? ""
: formatLocalDate(numericDate);
}
const text = String(value).trim();
const match = text.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
if (match) {
return (
match[1] + "-" + padDatePart(match[2]) + "-" + padDatePart(match[3])
);
}
const parsedDate = new Date(text.replace(/-/g, "/"));
return isNaN(parsedDate.getTime()) ? "" : formatLocalDate(parsedDate);
}
function isPublishedFreeArticle(item) {
if (!item) return false;
const statusText = String(
item.statusText ||
item.auditStatusText ||
item.publishStatusText ||
item.stateText ||
"",
).toLowerCase();
if (/已发布|审核通过|通过|published|approved|pass/.test(statusText)) {
return true;
}
const status =
item.status != null
? item.status
: item.auditStatus != null
? item.auditStatus
: item.publishStatus;
return status === true || status === 1 || status === "1";
}
function getTodayPublishedFreeCount(rows) {
const today = formatLocalDate(new Date());
return ApiClient.asArray(rows).filter(function (item) {
const articleDate = getArticleDateText(
item.createTime ||
item.create_time ||
item.publishTime ||
item.publish_time ||
item.auditTime ||
item.audit_time ||
item.updateTime ||
item.update_time ||
item.createdAt,
);
return articleDate === today && isPublishedFreeArticle(item);
}).length;
}
function loadTodayPublishedFreeCount() {
return ApiClient.get(ApiClient.API.mineFreeArticleList, {
pageNum: 1,
pageSize: 100,
})
.then(function (res) {
if (!ApiClient.isSuccess(res)) return 0;
const data = res.data || res;
const rows = ApiClient.asArray(
data.rows || data.records || data.list || data.data || data,
);
return getTodayPublishedFreeCount(rows);
})
.catch(function () {
return 0;
});
}
// 付费文章发布权限:专家身份 + 当天 2 篇审核通过/已发布的免费文章。
// 付费文章发布权限以 mine/summary 返回字段为准
function checkPaidPublishPermission() {
return ApiClient.get(ApiClient.API.mineSummary)
.then(function (res) {
if (!ApiClient.isSuccess(res) || !res.data) {
if (
!ApiClient.isSuccess(res) ||
!res.data ||
!window.PublishPermission
) {
return { canPaid: false, reason: "暂时无法获取发布权限。" };
}
const status = String(
res.data.expertStatus || res.data.expert_status || "",
).toLowerCase();
const isRegularExpert =
isTruthy(res.data.is_regular_expert) ||
isTruthy(res.data.isRegularExpert) ||
isTruthy(res.data.regularExpert) ||
/正式|regular|formal/.test(status);
const hasExpertIdentity =
isTruthy(res.data.is_expert) ||
isTruthy(res.data.isExpert) ||
isTruthy(res.data.expert) ||
isRegularExpert ||
/实习|intern|trial|正式|regular|formal/.test(status);
if (!hasExpertIdentity || !isRegularExpert) {
return { canPaid: false, reason: "正式专家才能发布付费文章。" };
}
return loadTodayPublishedFreeCount().then(function (count) {
return {
canPaid: count >= REQUIRED_DAILY_FREE_ARTICLES,
reason:
count >= REQUIRED_DAILY_FREE_ARTICLES
? ""
: "今天需先发布2篇审核通过的免费文章后,才能发布付费文章(当前" +
count +
"篇)。",
};
});
const permission = PublishPermission.parseSummary(res.data);
return {
...permission,
reason: permission.reason || permission.paidReason,
};
})
.catch(function () {
return { canPaid: false, reason: "暂时无法获取发布权限。" };