修改问题
This commit is contained in:
@@ -101,7 +101,6 @@
|
||||
}
|
||||
|
||||
function buildAlbumBody(values) {
|
||||
// AlbumBody 来自 APP.openapi.json,albumName 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
@@ -114,7 +113,6 @@
|
||||
}
|
||||
|
||||
function buildPhotoBody(values) {
|
||||
// AlbumPhotoBody 来自 APP.openapi.json,ossId 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -115,7 +115,6 @@
|
||||
}
|
||||
|
||||
function buildArticleBody(values) {
|
||||
// ArticleBody 来自 APP.openapi.json,标题和正文为核心必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -107,7 +107,6 @@
|
||||
}
|
||||
|
||||
function buildCeremonyBody(values) {
|
||||
// CeremonyBody 来自 APP.openapi.json,ceremonyType 和 ceremonyTitle 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
@@ -133,7 +132,6 @@
|
||||
}
|
||||
|
||||
function buildMeritBody(values) {
|
||||
// MeritRecordBody 来自 APP.openapi.json,donorName 和 meritTitle 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -106,7 +106,6 @@
|
||||
}
|
||||
|
||||
function buildFeedBody(values) {
|
||||
// FamilyFeedBody 来自 APP.openapi.json。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -128,7 +128,6 @@
|
||||
}
|
||||
|
||||
function formatJoinMode(value) {
|
||||
// APP.openapi.json 中 joinMode 为枚举值,页面展示时转成中文。
|
||||
var map = {
|
||||
0: '关闭加入',
|
||||
1: '审核加入',
|
||||
|
||||
@@ -106,7 +106,6 @@
|
||||
}
|
||||
|
||||
function buildGrowthBody(values) {
|
||||
// GrowthRecordBody 来自 APP.openapi.json,recordTitle 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -113,7 +113,6 @@
|
||||
}
|
||||
|
||||
function buildLineagePersonBody(values) {
|
||||
// LineagePersonBody 来自 APP.openapi.json,空值统一转为 undefined,避免提交无意义空字符串。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -113,7 +113,6 @@
|
||||
}
|
||||
|
||||
function buildMemberUpdateBody(values) {
|
||||
// GenealogyMemberUpdateBody 来自 APP.openapi.json。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -110,7 +110,6 @@
|
||||
}
|
||||
|
||||
function buildMemoBody(values) {
|
||||
// MemoBody 来自 APP.openapi.json,memoTitle 必填。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
@@ -58,6 +58,37 @@
|
||||
return pick(item, ['regionName', 'name', 'label'], '未命名地区');
|
||||
}
|
||||
|
||||
function getRegionLevel(item) {
|
||||
var source = item || {};
|
||||
var level = Number(pick(source, ['level', 'regionLevel'], 0));
|
||||
var code = getRegionCode(source);
|
||||
|
||||
if (level >= 1 && level <= 3) return level;
|
||||
if (!/^\d{6}$/.test(code)) return 0;
|
||||
if (/0000$/.test(code)) return 1;
|
||||
if (/00$/.test(code)) return 2;
|
||||
return 3;
|
||||
}
|
||||
|
||||
function buildRegionSelection(items) {
|
||||
var selection = {
|
||||
provinceCode: '',
|
||||
cityCode: '',
|
||||
districtCode: ''
|
||||
};
|
||||
|
||||
normalizeList(items).forEach(function (item) {
|
||||
var code = getRegionCode(item);
|
||||
var level = getRegionLevel(item);
|
||||
|
||||
if (level === 1) selection.provinceCode = code;
|
||||
if (level === 2) selection.cityCode = code;
|
||||
if (level === 3) selection.districtCode = code;
|
||||
});
|
||||
|
||||
return selection;
|
||||
}
|
||||
|
||||
function buildRegionOption(item) {
|
||||
return '<option value="' + escapeHtml(getRegionCode(item)) + '">' + escapeHtml(getRegionName(item)) + '</option>';
|
||||
}
|
||||
@@ -180,6 +211,91 @@
|
||||
});
|
||||
}
|
||||
|
||||
async function applyRegionSelection(picker, selection) {
|
||||
var province = query('[data-region-level="province"]', picker);
|
||||
var city = query('[data-region-level="city"]', picker);
|
||||
var district = query('[data-region-level="district"]', picker);
|
||||
var values = selection || {};
|
||||
|
||||
if (!values.provinceCode) return;
|
||||
|
||||
province.value = values.provinceCode;
|
||||
resetSelect(city, '请选择市');
|
||||
resetSelect(district, '请选择区县');
|
||||
|
||||
if (values.cityCode) {
|
||||
await loadChildrenInto(city, values.provinceCode, '请选择市');
|
||||
city.value = values.cityCode;
|
||||
}
|
||||
|
||||
if (values.districtCode && values.cityCode) {
|
||||
await loadChildrenInto(district, values.cityCode, '请选择区县');
|
||||
district.value = values.districtCode;
|
||||
}
|
||||
|
||||
updateTargetCode(picker);
|
||||
}
|
||||
|
||||
function renderSearchResults(container, items) {
|
||||
var list = normalizeList(items);
|
||||
|
||||
if (!container) return;
|
||||
container.innerHTML = list.length ? list.map(function (item) {
|
||||
var code = getRegionCode(item);
|
||||
var name = getRegionName(item);
|
||||
|
||||
return '<button class="btn ghost magnetic" type="button" data-region-search-result="' + escapeHtml(code) + '">' + escapeHtml(name) + ' ' + escapeHtml(code) + '</button>';
|
||||
}).join('') : '<p class="api-empty">未找到匹配地区</p>';
|
||||
}
|
||||
|
||||
async function submitRegionSearch(form) {
|
||||
var api = getApi();
|
||||
var values = getFormValues(form);
|
||||
var results = query('[data-region-search-results]', form.parentNode);
|
||||
var pathText = query('[data-region-search-path]', form.parentNode);
|
||||
|
||||
if (!api) return;
|
||||
if (!values.regionKeyword || !values.regionKeyword.trim()) {
|
||||
showMessage('请输入地区名称或编码');
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathText) pathText.textContent = '搜索中...';
|
||||
try {
|
||||
renderSearchResults(results, await api.regionSearch({
|
||||
keyword: values.regionKeyword.trim(),
|
||||
limit: 20
|
||||
}));
|
||||
if (pathText) pathText.textContent = '请选择一个地区';
|
||||
} catch (error) {
|
||||
if (pathText) pathText.textContent = error.message || '地区搜索失败';
|
||||
showMessage(error.message || '地区搜索失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function selectSearchResult(button) {
|
||||
var api = getApi();
|
||||
var code = button.getAttribute('data-region-search-result');
|
||||
var section = button.closest('.module-panel');
|
||||
var picker = section && query('[data-region-picker]', section);
|
||||
var pathText = section && query('[data-region-search-path]', section);
|
||||
var detail;
|
||||
var path;
|
||||
|
||||
if (!api || !code || !picker) return;
|
||||
|
||||
if (pathText) pathText.textContent = '正在定位地区...';
|
||||
try {
|
||||
detail = await api.regionDetail(code);
|
||||
path = await api.regionPath(getRegionCode(detail) || code);
|
||||
await applyRegionSelection(picker, buildRegionSelection(path));
|
||||
if (pathText) pathText.textContent = buildPathText(path);
|
||||
} catch (error) {
|
||||
if (pathText) pathText.textContent = error.message || '地区定位失败';
|
||||
showMessage(error.message || '地区定位失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function submitProfileRegion(form) {
|
||||
var api = getApi();
|
||||
var values = getFormValues(form);
|
||||
@@ -208,6 +324,23 @@
|
||||
});
|
||||
}
|
||||
|
||||
function bindSearchForms() {
|
||||
queryAll('[data-region-search-form]').forEach(function (form) {
|
||||
form.addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
submitRegionSearch(form);
|
||||
});
|
||||
});
|
||||
|
||||
documentRef.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-region-search-result]');
|
||||
|
||||
if (!button) return;
|
||||
event.preventDefault();
|
||||
selectSearchResult(button);
|
||||
});
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!documentRef) return;
|
||||
|
||||
@@ -215,12 +348,14 @@
|
||||
initPicker(picker);
|
||||
});
|
||||
bindProfileForms();
|
||||
bindSearchForms();
|
||||
}
|
||||
|
||||
return {
|
||||
normalizeList: normalizeList,
|
||||
buildRegionOption: buildRegionOption,
|
||||
buildPathText: buildPathText,
|
||||
buildRegionSelection: buildRegionSelection,
|
||||
getFinalRegionCode: getFinalRegionCode,
|
||||
buildProfileRegionBody: buildProfileRegionBody,
|
||||
init: init
|
||||
|
||||
@@ -49,16 +49,6 @@
|
||||
};
|
||||
}
|
||||
|
||||
function buildSmsLoginBody(values) {
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
phone: String(source.phone || '').trim(),
|
||||
smsCode: String(source.smsCode || '').trim(),
|
||||
validToken: trimOrUndefined(source.validToken)
|
||||
};
|
||||
}
|
||||
|
||||
function buildDeactivateBody(values, hashFn) {
|
||||
var source = values || {};
|
||||
var hash = hashFn || hashPassword;
|
||||
@@ -154,25 +144,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function submitSmsLogin(form) {
|
||||
var api = getApi();
|
||||
var body = buildSmsLoginBody(getFormValues(form));
|
||||
|
||||
if (!api) return;
|
||||
if (!body.phone || !body.smsCode) {
|
||||
showMessage('请填写手机号和验证码');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await api.smsLogin(body);
|
||||
setStatus(form, '短信登录已通过');
|
||||
showMessage('短信登录已通过');
|
||||
} catch (error) {
|
||||
showMessage(error.message || '短信登录失败');
|
||||
}
|
||||
}
|
||||
|
||||
async function submitDeactivate(form) {
|
||||
var api = getApi();
|
||||
var values = getFormValues(form);
|
||||
@@ -191,7 +162,7 @@
|
||||
try {
|
||||
await api.deactivateAccount(buildDeactivateBody(values));
|
||||
showMessage('账号已提交注销');
|
||||
root.location.href = 'login.html';
|
||||
root.location.href = 'index.html';
|
||||
} catch (error) {
|
||||
showMessage(error.message || '账号注销失败');
|
||||
}
|
||||
@@ -200,14 +171,14 @@
|
||||
async function logout() {
|
||||
var api = getApi();
|
||||
|
||||
if (!api) return;
|
||||
if (root.confirm && !root.confirm('确认退出当前账号?')) return;
|
||||
|
||||
try {
|
||||
await api.logout();
|
||||
root.location.href = 'login.html';
|
||||
if (api) await api.logout();
|
||||
} catch (error) {
|
||||
showMessage(error.message || '退出登录失败');
|
||||
// ApiClient.logout 会在请求失败时清理本地 token,页面仍应离开受保护区域。
|
||||
} finally {
|
||||
root.location.href = 'index.html';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +195,6 @@
|
||||
|
||||
if (formType === 'password') submitPassword(form);
|
||||
if (formType === 'phone') submitPhone(form);
|
||||
if (formType === 'sms-login') submitSmsLogin(form);
|
||||
if (formType === 'deactivate') submitDeactivate(form);
|
||||
});
|
||||
|
||||
@@ -246,7 +216,6 @@
|
||||
return {
|
||||
buildPasswordChangeBody: buildPasswordChangeBody,
|
||||
buildPhoneChangeBody: buildPhoneChangeBody,
|
||||
buildSmsLoginBody: buildSmsLoginBody,
|
||||
buildDeactivateBody: buildDeactivateBody,
|
||||
isDangerConfirmed: isDangerConfirmed,
|
||||
init: init
|
||||
|
||||
+119
-1
@@ -15,6 +15,7 @@
|
||||
'use strict';
|
||||
|
||||
var documentRef = root.document;
|
||||
var DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
||||
|
||||
function getApi() {
|
||||
return root.GenealogyApi && root.GenealogyApi.defaultClient;
|
||||
@@ -78,6 +79,108 @@
|
||||
return (fileName || '文件') + ' 上传完成,OSS ID:' + ossId;
|
||||
}
|
||||
|
||||
function getUploadMode(fileSize, chunkSize) {
|
||||
var size = Number(fileSize) || 0;
|
||||
var limit = Number(chunkSize) || DEFAULT_CHUNK_SIZE;
|
||||
|
||||
return size > limit ? 'resumable' : 'single';
|
||||
}
|
||||
|
||||
function buildResumableInitBody(file, fileMd5, chunkSize, options) {
|
||||
var source = file || {};
|
||||
var settings = options || {};
|
||||
var size = Number(source.size) || 0;
|
||||
var sizePerChunk = Number(chunkSize) || DEFAULT_CHUNK_SIZE;
|
||||
var body = {
|
||||
fileName: String(source.name || ''),
|
||||
fileSize: size,
|
||||
fileMd5: String(fileMd5 || ''),
|
||||
contentType: String(source.type || 'application/octet-stream'),
|
||||
chunkSize: sizePerChunk,
|
||||
totalChunks: Math.ceil(size / sizePerChunk)
|
||||
};
|
||||
|
||||
if (settings.bizType) body.bizType = settings.bizType;
|
||||
if (settings.usageScene) body.usageScene = settings.usageScene;
|
||||
return body;
|
||||
}
|
||||
|
||||
function buildResumableCompleteBody(uploadId, fileMd5, fileSize) {
|
||||
return {
|
||||
uploadId: String(uploadId || ''),
|
||||
fileMd5: String(fileMd5 || ''),
|
||||
fileSize: Number(fileSize) || 0
|
||||
};
|
||||
}
|
||||
|
||||
function toBinaryString(buffer) {
|
||||
var bytes = new Uint8Array(buffer);
|
||||
var chunkSize = 0x8000;
|
||||
var chunks = [];
|
||||
var index;
|
||||
|
||||
for (index = 0; index < bytes.length; index += chunkSize) {
|
||||
chunks.push(String.fromCharCode.apply(null, bytes.subarray(index, index + chunkSize)));
|
||||
}
|
||||
|
||||
return chunks.join('');
|
||||
}
|
||||
|
||||
async function hashBlob(blob) {
|
||||
if (!root.hex_md5 || !blob || !blob.arrayBuffer) {
|
||||
throw new Error('缺少文件 MD5 工具');
|
||||
}
|
||||
|
||||
return root.hex_md5(toBinaryString(await blob.arrayBuffer()));
|
||||
}
|
||||
|
||||
async function uploadResumable(api, file, options) {
|
||||
var settings = options || {};
|
||||
var chunkSize = Number(settings.chunkSize) || DEFAULT_CHUNK_SIZE;
|
||||
var hash = settings.hashBlob || hashBlob;
|
||||
var fileMd5;
|
||||
var init;
|
||||
var uploadId;
|
||||
var totalChunks;
|
||||
var index;
|
||||
var start;
|
||||
var end;
|
||||
var chunk;
|
||||
|
||||
if (!api || !file || !file.slice) throw new Error('请选择可分片上传的文件');
|
||||
|
||||
fileMd5 = await hash(file);
|
||||
init = await api.initResumableUpload(buildResumableInitBody(file, fileMd5, chunkSize, settings));
|
||||
uploadId = pick(init, ['uploadId', 'id'], '');
|
||||
if (!uploadId) throw new Error('分片上传初始化缺少 uploadId');
|
||||
|
||||
totalChunks = Math.ceil(file.size / chunkSize);
|
||||
for (index = 0; index < totalChunks; index += 1) {
|
||||
start = index * chunkSize;
|
||||
end = Math.min(start + chunkSize, file.size);
|
||||
chunk = file.slice(start, end);
|
||||
await api.uploadChunk({
|
||||
uploadId: uploadId,
|
||||
chunkIndex: index,
|
||||
chunkMd5: await hash(chunk),
|
||||
file: chunk
|
||||
});
|
||||
if (settings.onProgress) settings.onProgress(index + 1, totalChunks);
|
||||
}
|
||||
|
||||
return api.completeResumableUpload(buildResumableCompleteBody(uploadId, fileMd5, file.size));
|
||||
}
|
||||
|
||||
async function uploadFileForPage(api, file, options) {
|
||||
var settings = options || {};
|
||||
var mode = settings.mode === 'single' || settings.mode === 'resumable'
|
||||
? settings.mode
|
||||
: getUploadMode(file && file.size, settings.chunkSize);
|
||||
|
||||
if (mode === 'single') return api.uploadFile(file);
|
||||
return uploadResumable(api, file, settings);
|
||||
}
|
||||
|
||||
async function uploadFromInput(input) {
|
||||
var api = getApi();
|
||||
var file = input.files && input.files[0];
|
||||
@@ -86,6 +189,8 @@
|
||||
var target = targetSelector && query(targetSelector);
|
||||
var status = statusSelector && query(statusSelector);
|
||||
var multiple = input.getAttribute('data-upload-multiple') === 'true';
|
||||
var chunkSize = Number(input.getAttribute('data-upload-chunk-size')) || DEFAULT_CHUNK_SIZE;
|
||||
var mode = input.getAttribute('data-upload-mode') || '';
|
||||
var result;
|
||||
|
||||
if (!api || !file || !target) return;
|
||||
@@ -94,7 +199,15 @@
|
||||
input.disabled = true;
|
||||
|
||||
try {
|
||||
result = normalizeUploadResult(await api.uploadFile(file));
|
||||
result = normalizeUploadResult(await uploadFileForPage(api, file, {
|
||||
mode: mode || getUploadMode(file.size, chunkSize),
|
||||
chunkSize: chunkSize,
|
||||
bizType: input.getAttribute('data-upload-biz-type') || undefined,
|
||||
usageScene: input.getAttribute('data-upload-usage-scene') || undefined,
|
||||
onProgress: function (current, total) {
|
||||
if (status) status.textContent = '分片上传 ' + current + '/' + total;
|
||||
}
|
||||
}));
|
||||
if (!result.ossId) throw new Error('上传结果缺少 OSS ID');
|
||||
target.value = mergeOssIds(target.value, result.ossId, multiple);
|
||||
if (status) status.textContent = buildUploadStatus(result.fileName || file.name, result.ossId);
|
||||
@@ -127,6 +240,11 @@
|
||||
normalizeUploadResult: normalizeUploadResult,
|
||||
mergeOssIds: mergeOssIds,
|
||||
buildUploadStatus: buildUploadStatus,
|
||||
getUploadMode: getUploadMode,
|
||||
buildResumableInitBody: buildResumableInitBody,
|
||||
buildResumableCompleteBody: buildResumableCompleteBody,
|
||||
uploadResumable: uploadResumable,
|
||||
uploadFileForPage: uploadFileForPage,
|
||||
init: init
|
||||
};
|
||||
});
|
||||
|
||||
@@ -109,7 +109,6 @@
|
||||
}
|
||||
|
||||
function buildVipOrderBody(values) {
|
||||
// VipOrderBody 来自 APP.openapi.json,packageId 必填,genealogyId 和 payType 可选。
|
||||
var source = values || {};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user