// 导出HTTP模块 export * from './http'; // 导出SVG汉字数据获取模块 export * from './getWordsSvgJson'; export async function getMiniCodeImage(canvas: Canvas) { return getImage(canvas, '/assets/imgs/doodle-mini-logo.jpg'); } export async function getImage(canvas: Canvas, path: string) { return new Promise((resolve, reject) => { const image = canvas.createImage(); image.onload = () => { resolve(image); }; image.onerror = () => { reject('图片加载异常'); }; image.src = path; }); } export const formatTime = (date: Date) => { const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const minute = date.getMinutes(); const second = date.getSeconds(); return ( [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':') ); }; const formatNumber = (n: number) => { const s = n.toString(); return s[1] ? s : '0' + s; }; export type MiniProgramQuery = Record; export function parseMiniProgramUrl(input: string) { const trimmed = input.trim(); const pathPart = trimmed.split(/[?#]/, 1)[0] || ''; const query: MiniProgramQuery = {}; const questionIndex = trimmed.indexOf('?'); const hashIndex = trimmed.indexOf('#'); const queryStart = questionIndex >= 0 && (hashIndex < 0 || questionIndex < hashIndex) ? questionIndex + 1 : -1; const queryEnd = hashIndex >= 0 ? hashIndex : trimmed.length; if (queryStart >= 0 && queryStart <= queryEnd) { const queryString = trimmed.slice(queryStart, queryEnd); for (const pair of queryString.split('&')) { if (!pair) continue; const [rawKey, rawValue = ''] = pair.split('=', 2); if (!rawKey) continue; const decode = (v: string) => { try { return decodeURIComponent(v.replace(/\+/g, ' ')); } catch { return v; } }; query[decode(rawKey)] = decode(rawValue); } } return { path: pathPart, query }; }