隐患详情重新设计,检查计划重新设计成做题排查式
This commit is contained in:
80
unpackage/dist/dev/mp-weixin/utils/draftCache.js
vendored
Normal file
80
unpackage/dist/dev/mp-weixin/utils/draftCache.js
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../common/vendor.js");
|
||||
const DRAFT_NS = {
|
||||
ASSIGN: "draft_assign",
|
||||
ACCEPT: "draft_accept",
|
||||
RECTIFY: "draft_rectify",
|
||||
INSPECTION_RESULT: "draft_inspection_result",
|
||||
INSPECTION_SHEET: "draft_inspection_sheet"
|
||||
};
|
||||
function buildDraftKey(namespace, ...parts) {
|
||||
return [namespace, ...parts.map((p) => String(p ?? ""))].join("_");
|
||||
}
|
||||
function buildDraftKeyCompact(namespace, ...parts) {
|
||||
return [namespace, ...parts.map((p) => String(p ?? "")).filter(Boolean)].join("_");
|
||||
}
|
||||
function loadDraftWithFallback(primaryKey, fallbackKeys = []) {
|
||||
const primary = loadDraft(primaryKey);
|
||||
if (primary) {
|
||||
return { data: primary, key: primaryKey, fromFallback: false };
|
||||
}
|
||||
for (const fallbackKey of fallbackKeys) {
|
||||
if (!fallbackKey || fallbackKey === primaryKey)
|
||||
continue;
|
||||
const fallback = loadDraft(fallbackKey);
|
||||
if (fallback) {
|
||||
return { data: fallback, key: primaryKey, fromFallback: true, fallbackKey };
|
||||
}
|
||||
}
|
||||
return { data: null, key: primaryKey, fromFallback: false };
|
||||
}
|
||||
function loadDraft(key) {
|
||||
if (!key)
|
||||
return null;
|
||||
const raw = common_vendor.index.getStorageSync(key);
|
||||
if (!raw)
|
||||
return null;
|
||||
try {
|
||||
return typeof raw === "string" ? JSON.parse(raw) : raw;
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at utils/draftCache.js:61", "[draftCache] 解析草稿失败:", key, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
function saveDraftToStorage(key, data) {
|
||||
if (!key)
|
||||
return;
|
||||
common_vendor.index.setStorageSync(
|
||||
key,
|
||||
JSON.stringify({
|
||||
...data,
|
||||
updatedAt: Date.now()
|
||||
})
|
||||
);
|
||||
}
|
||||
function removeDraft(key) {
|
||||
if (!key)
|
||||
return;
|
||||
common_vendor.index.removeStorageSync(key);
|
||||
}
|
||||
function defaultHasContent(payload) {
|
||||
if (!payload || typeof payload !== "object")
|
||||
return false;
|
||||
return Object.entries(payload).some(([key, value]) => {
|
||||
if (key === "updatedAt")
|
||||
return false;
|
||||
if (Array.isArray(value))
|
||||
return value.length > 0;
|
||||
if (value && typeof value === "object")
|
||||
return Object.keys(value).length > 0;
|
||||
return value !== "" && value != null;
|
||||
});
|
||||
}
|
||||
exports.DRAFT_NS = DRAFT_NS;
|
||||
exports.buildDraftKey = buildDraftKey;
|
||||
exports.buildDraftKeyCompact = buildDraftKeyCompact;
|
||||
exports.defaultHasContent = defaultHasContent;
|
||||
exports.loadDraftWithFallback = loadDraftWithFallback;
|
||||
exports.removeDraft = removeDraft;
|
||||
exports.saveDraftToStorage = saveDraftToStorage;
|
||||
//# sourceMappingURL=../../.sourcemap/mp-weixin/utils/draftCache.js.map
|
||||
Reference in New Issue
Block a user