chore: 上线前优化 — 清理调试日志/启用组件按需注入/补全组件声明

- 移除全项目 34 处调试 console.* 输出
- project.config.json: minified true、uploadWithSourceMap false、启用 lazyCodeLoading(requiredComponents 组件按需注入)
- pages/records/records.json 补全 ui-skeleton 组件声明(此前漏声明,WXML 已使用)
- 删除根目录残留 preview-buttons.html
This commit is contained in:
2026-08-04 14:05:16 +08:00
parent b52db87ddf
commit 187c426243
14 changed files with 100 additions and 199 deletions
+2 -18
View File
@@ -25,10 +25,8 @@ const init = () => {
try {
wx.cloud.init({ env: ENV_ID, traceUser: true })
_enabled = true
console.log('[cloud] init ok, env:', ENV_ID)
} catch (e) {
_enabled = false
console.warn('[cloud] init failed — cloud sync disabled:', e.message || e)
}
}
@@ -73,9 +71,7 @@ const _fetchOpenid = async () => {
try {
const res = await wx.cloud.callFunction({ name: 'getOpenid' })
if (res && res.result && res.result.openid) return res.result.openid
console.warn('[cloud] getOpenid returned no openid:', JSON.stringify(res))
} catch (e) {
console.warn('[cloud] getOpenid call failed — cloud functions may not be deployed:', e.message || e)
}
return null
}
@@ -109,8 +105,7 @@ const _ensureOpenid = async () => {
}
const pushAll = () => {
if (!_enabled) { console.log('[cloud] pushAll skipped (not enabled)'); return }
console.log('[cloud] pushAll scheduled')
if (!_enabled) { return }
// Pre-warm openid so _doPush never sees _openid=null on a cold start
// (which used to bypass the locate-by-openid branch and call add(),
// creating a duplicate cloud doc every cold start).
@@ -132,9 +127,8 @@ const _markSynced = () => {
}
const _doPush = async () => {
console.log('[cloud] _doPush starting...')
const db = getDb()
if (!db) { console.log('[cloud] _doPush aborted (no db)'); return }
if (!db) { return }
try {
const storage = require('./storage')
const themeMod = require('./theme')
@@ -148,13 +142,11 @@ const _doPush = async () => {
themeId: themeMod.getCurrentTheme().id,
updatedAt: db.serverDate()
}
console.log('[cloud] _doPush records keys:', Object.keys(data.records || {}))
// Fast path: cached _docId update
if (_docId) {
try {
await db.collection(DB_COLLECTION).doc(_docId).update({ data })
console.log('[cloud] _doPush update ok')
_markSynced()
return
} catch (e) {
@@ -163,7 +155,6 @@ const _doPush = async () => {
// `doc._openid == auth.openid` → `undefined == openid` → false,
// so this surfaces as -502003 rather than "not found". Either way,
// fall through and re-locate the doc via openid.
console.log('[cloud] _doPush cached _docId stale, clearing:', e.message)
_docId = null
}
}
@@ -184,7 +175,6 @@ const _doPush = async () => {
_docId = existing.data[0]._id
try {
await db.collection(DB_COLLECTION).doc(_docId).update({ data })
console.log('[cloud] _doPush update ok (re-located by _openid)')
_markSynced()
return
} catch (e) {
@@ -192,7 +182,6 @@ const _doPush = async () => {
// permission rule, race with another tab, etc.), DO NOT fall
// through to add() — that would silently create a duplicate
// cloud doc for the same user. Bail and let the next push retry.
console.log('[cloud] _doPush update-by-openid failed, aborting:', e.message)
_docId = null
return
}
@@ -202,14 +191,11 @@ const _doPush = async () => {
// Reached when: (a) openid exists but no doc found, OR (b) openid is
// null (getOpenid not deployed). In both cases add() is safe — CloudBase
// auto-populates _openid on document creation.
console.log('[cloud] _doPush adding new doc (openid=' + (openid || 'null') + ')')
const res = await db.collection(DB_COLLECTION).add({ data })
if (res && res._id) _docId = res._id
if (res && res._openid) _openid = res._openid
console.log('[cloud] _doPush add ok, docId=', _docId)
_markSynced()
} catch (e) {
console.log('[cloud] _doPush error:', e.message || e)
}
}
@@ -223,7 +209,6 @@ const clearAll = async () => {
_openid = await _fetchOpenid()
}
if (!_openid) {
console.log('[cloud] clearAll: cannot fetch openid, giving up')
throw new Error('无法识别当前用户')
}
@@ -239,7 +224,6 @@ const clearAll = async () => {
},
async (id) => {
await db.collection(DB_COLLECTION).doc(id).remove()
console.log('[cloud] clearAll: removed doc', id)
}
)