修改功能
This commit is contained in:
+47
-13
@@ -13,12 +13,7 @@
|
||||
})(typeof globalThis !== 'undefined' ? globalThis : window, function (root) {
|
||||
'use strict';
|
||||
|
||||
var FEEDBACK_TYPES = {
|
||||
advice: '意见建议',
|
||||
bug: '问题反馈',
|
||||
complaint: '投诉反馈',
|
||||
other: '其他反馈'
|
||||
};
|
||||
var FEEDBACK_OPTION_STATES = ['ACTIVE', 'DISABLED', 'UNKNOWN'];
|
||||
var HANDLE_STATUS = {
|
||||
'0': '待处理',
|
||||
'1': '处理中',
|
||||
@@ -68,26 +63,41 @@
|
||||
return body;
|
||||
}
|
||||
|
||||
function validateFeedbackBody(body) {
|
||||
function validateFeedbackBody(body, allowedFeedbackTypes) {
|
||||
var source = body || {};
|
||||
var allowedTypes = Array.isArray(allowedFeedbackTypes) ? allowedFeedbackTypes : [];
|
||||
|
||||
if (!optionalText(source.feedbackContent)) return '请填写反馈内容';
|
||||
if (source.feedbackType && !Object.prototype.hasOwnProperty.call(FEEDBACK_TYPES, source.feedbackType)) {
|
||||
if (source.feedbackType && allowedTypes.length && allowedTypes.indexOf(source.feedbackType) < 0) {
|
||||
return '反馈类型无效';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function normalizeFeedbackTypeOptions(data) {
|
||||
if (!Array.isArray(data)) return [];
|
||||
return data.reduce(function (options, item) {
|
||||
var source = item || {};
|
||||
var value = optionalText(source.value);
|
||||
var label = optionalText(source.label);
|
||||
|
||||
if (value && label && source.enabled === true) options.push({ value: value, label: label });
|
||||
return options;
|
||||
}, []);
|
||||
}
|
||||
|
||||
function normalizeFeedback(item) {
|
||||
var source = item || {};
|
||||
var feedbackId = normalizeId(source.feedbackId);
|
||||
var feedbackType = optionalText(source.feedbackType);
|
||||
var feedbackTypeLabel = optionalText(source.feedbackTypeLabel) || feedbackType;
|
||||
var feedbackTypeOptionState = optionalText(source.feedbackTypeOptionState);
|
||||
var feedbackContent = optionalText(source.feedbackContent);
|
||||
var handleStatus = String(source.handleStatus === undefined || source.handleStatus === null ? '' : source.handleStatus);
|
||||
var status = String(source.status === undefined || source.status === null ? '' : source.status);
|
||||
|
||||
if (!feedbackId || !feedbackContent ||
|
||||
!Object.prototype.hasOwnProperty.call(FEEDBACK_TYPES, feedbackType) ||
|
||||
if (!feedbackId || !feedbackContent || !feedbackType || !feedbackTypeLabel ||
|
||||
FEEDBACK_OPTION_STATES.indexOf(feedbackTypeOptionState) < 0 ||
|
||||
!Object.prototype.hasOwnProperty.call(HANDLE_STATUS, handleStatus) ||
|
||||
['0', '1'].indexOf(status) < 0) {
|
||||
return null;
|
||||
@@ -95,6 +105,8 @@
|
||||
return {
|
||||
feedbackId: feedbackId,
|
||||
feedbackType: feedbackType,
|
||||
feedbackTypeLabel: feedbackTypeLabel,
|
||||
feedbackTypeOptionState: feedbackTypeOptionState,
|
||||
feedbackContent: feedbackContent,
|
||||
contactInfo: optionalText(source.contactInfo),
|
||||
handleStatus: handleStatus,
|
||||
@@ -142,7 +154,7 @@
|
||||
return items.map(function (item) {
|
||||
return '<a class="module-row" href="' +
|
||||
escapeHtml(buildFeedbackDetailUrl(item.feedbackId, detailPage)) +
|
||||
'"><div><h3>' + escapeHtml(FEEDBACK_TYPES[item.feedbackType]) +
|
||||
'"><div><h3>' + escapeHtml(item.feedbackTypeLabel) +
|
||||
'</h3><p>' + escapeHtml(item.feedbackContent) +
|
||||
'</p></div><span class="pill">' + HANDLE_STATUS[item.handleStatus] +
|
||||
'</span></a>';
|
||||
@@ -163,7 +175,7 @@
|
||||
].filter(Boolean).join('');
|
||||
|
||||
return '<article class="module-panel"><div class="module-kicker">' +
|
||||
escapeHtml(FEEDBACK_TYPES[feedback.feedbackType]) +
|
||||
escapeHtml(feedback.feedbackTypeLabel) +
|
||||
'</div><h2>问题说明</h2><p>' + escapeHtml(feedback.feedbackContent) +
|
||||
'</p><dl class="detail-list">' + details + '</dl></article>';
|
||||
}
|
||||
@@ -225,6 +237,18 @@
|
||||
button.textContent = pending ? label : button.dataset.defaultLabel;
|
||||
}
|
||||
|
||||
async function loadFeedbackTypeOptions(api, select) {
|
||||
var options = normalizeFeedbackTypeOptions(await api.businessDictionary('gen_feedback_type'));
|
||||
|
||||
if (!options.length) throw new Error('反馈类型选项响应无效');
|
||||
if (select) {
|
||||
select.innerHTML = '<option value="">请选择反馈类型(可选)</option>' + options.map(function (item) {
|
||||
return '<option value="' + escapeHtml(item.value) + '">' + escapeHtml(item.label) + '</option>';
|
||||
}).join('');
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
async function readMyFeedback(api) {
|
||||
var data = await api.myFeedback();
|
||||
var items = normalizeFeedbackList(data);
|
||||
@@ -242,6 +266,8 @@
|
||||
var page = root.document && root.document.querySelector('[data-feedback-page]');
|
||||
var api = root.GenealogyApi && root.GenealogyApi.defaultClient;
|
||||
var pageMode = page && page.getAttribute('data-feedback-page');
|
||||
var feedbackTypeSelect = form && form.querySelector('[data-feedback-type-options]');
|
||||
var allowedFeedbackTypes = [];
|
||||
var writePending = false;
|
||||
|
||||
if (!form) return;
|
||||
@@ -249,6 +275,13 @@
|
||||
redirectToLogin(api);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
allowedFeedbackTypes = (await loadFeedbackTypeOptions(api, feedbackTypeSelect)).map(function (item) {
|
||||
return item.value;
|
||||
});
|
||||
} catch (error) {
|
||||
if (feedbackTypeSelect) feedbackTypeSelect.innerHTML = '<option value="">暂不选择反馈类型</option>';
|
||||
}
|
||||
|
||||
async function loadList() {
|
||||
var items;
|
||||
@@ -290,7 +323,7 @@
|
||||
event.preventDefault();
|
||||
if (writePending) return;
|
||||
body = buildFeedbackBody(getFormValues(form));
|
||||
validation = validateFeedbackBody(body);
|
||||
validation = validateFeedbackBody(body, allowedFeedbackTypes);
|
||||
if (validation) {
|
||||
setStatus('error', validation);
|
||||
return;
|
||||
@@ -416,6 +449,7 @@
|
||||
getFeedbackId: getFeedbackId,
|
||||
buildFeedbackBody: buildFeedbackBody,
|
||||
validateFeedbackBody: validateFeedbackBody,
|
||||
normalizeFeedbackTypeOptions: normalizeFeedbackTypeOptions,
|
||||
normalizeFeedback: normalizeFeedback,
|
||||
normalizeFeedbackList: normalizeFeedbackList,
|
||||
findFeedbackById: findFeedbackById,
|
||||
|
||||
Reference in New Issue
Block a user