样式修改完成,待测试
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
<script src="../public/css/layui/layui.js"></script>
|
||||
<script src="../config.js"></script>
|
||||
<script src="../utils/ApiClient.js"></script>
|
||||
<script src="../utils/PublishPermission.js"></script>
|
||||
<script src="../utils/DateUtil.js"></script>
|
||||
<script src="../utils/CommonUtil.js"></script>
|
||||
<link rel="stylesheet" href="../public/css/layui/css/layui.css" />
|
||||
@@ -185,7 +186,6 @@
|
||||
canFree: false,
|
||||
canPaid: false,
|
||||
};
|
||||
var REQUIRED_DAILY_FREE_ARTICLES = 2;
|
||||
var FREE_TITLE_MIN_LENGTH = 15;
|
||||
var FREE_TITLE_MAX_LENGTH = 30;
|
||||
|
||||
@@ -298,146 +298,14 @@
|
||||
return res && (res.code === 0 || res.code === 200);
|
||||
}
|
||||
|
||||
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") {
|
||||
var numericDate = new Date(value);
|
||||
return isNaN(numericDate.getTime())
|
||||
? ""
|
||||
: formatLocalDate(numericDate);
|
||||
}
|
||||
|
||||
var text = String(value).trim();
|
||||
var match = text.match(/^(\d{4})[-/](\d{1,2})[-/](\d{1,2})/);
|
||||
if (match) {
|
||||
return (
|
||||
match[1] + "-" + padDatePart(match[2]) + "-" + padDatePart(match[3])
|
||||
);
|
||||
}
|
||||
|
||||
var parsedDate = new Date(text.replace(/-/g, "/"));
|
||||
return isNaN(parsedDate.getTime()) ? "" : formatLocalDate(parsedDate);
|
||||
}
|
||||
|
||||
function isPublishedFreeArticle(item) {
|
||||
if (!item) return false;
|
||||
|
||||
var statusText = String(
|
||||
item.statusText ||
|
||||
item.auditStatusText ||
|
||||
item.publishStatusText ||
|
||||
item.stateText ||
|
||||
"",
|
||||
).toLowerCase();
|
||||
if (/已发布|审核通过|通过|published|approved|pass/.test(statusText)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var status =
|
||||
item.status != null
|
||||
? item.status
|
||||
: item.auditStatus != null
|
||||
? item.auditStatus
|
||||
: item.publishStatus;
|
||||
return status === true || status === 1 || status === "1";
|
||||
}
|
||||
|
||||
function getTodayPublishedFreeCount(rows) {
|
||||
var today = formatLocalDate(new Date());
|
||||
return ApiClient.asArray(rows).filter(function (item) {
|
||||
var 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;
|
||||
var data = res.data || res;
|
||||
var rows = ApiClient.asArray(
|
||||
data.rows || data.records || data.list || data.data || data,
|
||||
);
|
||||
return getTodayPublishedFreeCount(rows);
|
||||
})
|
||||
.catch(function () {
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
function parsePublishPermission(userData) {
|
||||
var status = String(
|
||||
userData.expertStatus || userData.expert_status || "",
|
||||
).toLowerCase();
|
||||
var isIntern = /实习|intern|trial/.test(status);
|
||||
var isRegularByStatus = /正式|regular|formal/.test(status);
|
||||
var hasExpertIdentity =
|
||||
isTruthy(userData.is_expert) ||
|
||||
isTruthy(userData.isExpert) ||
|
||||
isTruthy(userData.expert) ||
|
||||
isTruthy(userData.is_regular_expert) ||
|
||||
isTruthy(userData.isRegularExpert) ||
|
||||
isTruthy(userData.regularExpert) ||
|
||||
isIntern ||
|
||||
isRegularByStatus;
|
||||
var isRegularExpert =
|
||||
isTruthy(userData.is_regular_expert) ||
|
||||
isTruthy(userData.isRegularExpert) ||
|
||||
isTruthy(userData.regularExpert) ||
|
||||
isRegularByStatus;
|
||||
|
||||
return {
|
||||
hasExpertIdentity: hasExpertIdentity,
|
||||
isRegularExpert: hasExpertIdentity && isRegularExpert,
|
||||
canFree: hasExpertIdentity,
|
||||
canPaid: false,
|
||||
todayFreeArticleCount: 0,
|
||||
paidReason: isRegularExpert
|
||||
? "今天需先发布2篇审核通过的免费文章后,才能发布付费文章"
|
||||
: "正式专家才能发布付费文章",
|
||||
};
|
||||
}
|
||||
|
||||
function loadPublishPermission() {
|
||||
return ApiClient.get(ApiClient.API.mineSummary)
|
||||
.then(function (res) {
|
||||
if (!ApiClient.isSuccess(res) || !res.data) {
|
||||
if (
|
||||
!ApiClient.isSuccess(res) ||
|
||||
!res.data ||
|
||||
!window.PublishPermission
|
||||
) {
|
||||
return {
|
||||
hasExpertIdentity: false,
|
||||
isRegularExpert: false,
|
||||
@@ -448,19 +316,7 @@
|
||||
};
|
||||
}
|
||||
|
||||
var permission = parsePublishPermission(res.data);
|
||||
if (!permission.canFree || !permission.isRegularExpert) return permission;
|
||||
|
||||
return loadTodayPublishedFreeCount().then(function (count) {
|
||||
permission.todayFreeArticleCount = count;
|
||||
permission.canPaid = count >= REQUIRED_DAILY_FREE_ARTICLES;
|
||||
permission.paidReason = permission.canPaid
|
||||
? ""
|
||||
: "今天需先发布2篇审核通过的免费文章后,才能发布付费文章(当前" +
|
||||
count +
|
||||
"篇)。";
|
||||
return permission;
|
||||
});
|
||||
return PublishPermission.parseSummary(res.data);
|
||||
})
|
||||
.catch(function () {
|
||||
return {
|
||||
@@ -479,7 +335,7 @@
|
||||
publishPermission = permission;
|
||||
return {
|
||||
canPaid: permission.canPaid,
|
||||
reason: permission.paidReason,
|
||||
reason: permission.reason || permission.paidReason,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user