feat: v1.5 — plan editor, voice prompts, UI polish

Major features:
- Training plan editor: edit preset days/duration per plan (in-place
  override via custom_plans storage; preset ids preserved so existing
  records stay valid)
- Voice prompts at 4 fixed points during training (halfway / 30s /
  10s / done) via Tencent Cloud TTS (cloudfunctions/tts + utils/voice.js)
- Free-training button: switched from outline (transparent) to ghost
  variant (theme-tinted) for visual weight

Bug fixes:
- 4 functional pages: SVG data URIs failed to render in WeChat because
  '\#' in colors was parsed as a data-URI fragment delimiter. encode the
  whole SVG via encodeURIComponent in utils/icons.js build().
- Old records (saved before id field was added) could not be deleted
  (data-id was empty, triggered defensive guard). Backfill stable
  legacy-<month>-<index>-<duration> ids in getRecords() and persist.
- settings.js plan-row editor button event was bubbling up to the row's
  bindtap (which also fired onSelectPlan). Wrapped in catch:tap.

UI:
- Settings page: 3 hardcoded plans replaced with dynamic buildPlansList
  that overlays custom_plans on top of presets
- Plan editor: bottom-sheet modal in settings page (regular view, not
  ui-modal — WeChat custom component root element drops position:fixed
  in this runtime)
- Free-training button: rounded pill style, full-width, 24rpx gap from
  primary action; bottom sheet uses max-height: 88vh + internal scroll
- Version bumped to v1.5, last updated 2026-06-10

Removed:
- Daily reminder section (dailyReminder / reminderTime) — replaced by
  the 4 voice prompts which cover the same user need without requiring
  long-term scheduling that WeChat mini-programs can't actually do

Misc:
- utils/plan.js refactored to formula-driven: presets declare
  totalDays/startTarget/increment/cycleDays, days[] is generated. Same
  formula applies to custom plans.
- Timer _remind() guards each prompt on minimum duration so short
  free-mode sessions don't fire 'last30' at the start
- Cloud storage cloud_plans field added to data push payload; restored
  on first install via _restoreFromCloud
- .gitignore added for local AI tool caches (.reasonix/, reasonix.toml,
  .codegraph/daemon.pid)
This commit is contained in:
2026-06-10 17:23:13 +08:00
parent 90e0e64156
commit 1d55df72b3
54 changed files with 2710 additions and 934 deletions
+50 -21
View File
@@ -1,20 +1,22 @@
const DB_COLLECTION = 'plank_data'
const ENV_ID = 'cloudbase-d1g56kl2q8f4f7d8a'
let _db = null
let _pushTimer = null
let _enabled = false
let _docId = null // cache doc id after first successful query
const getDb = () => {
if (!_enabled) return null
if (!_db) {
try { _db = wx.cloud.database() } catch (e) { _enabled = false }
try { _db = wx.cloud.database({ env: ENV_ID }) } catch (e) { _enabled = false }
}
return _db
}
const init = () => {
try {
wx.cloud.init({ env: 'cloudbase-d1g56kl2q8f4f7d8a', traceUser: true })
wx.cloud.init({ env: ENV_ID, traceUser: true })
_enabled = true
} catch (e) {
_enabled = false
@@ -25,10 +27,22 @@ const pullAll = async () => {
const db = getDb()
if (!db) return null
try {
const res = await db.collection(DB_COLLECTION)
.where({ _openid: '{openid}' })
.get()
return (res && res.data && res.data.length > 0) ? res.data[0] : null
// First try cached doc id
if (_docId) {
try {
const res = await db.collection(DB_COLLECTION).doc(_docId).get()
if (res && res.data) return res.data
} catch (e) {
_docId = null // doc deleted or inaccessible
}
}
// Query: rely on security rules to scope to current user
const res = await db.collection(DB_COLLECTION).limit(1).get()
if (res && res.data && res.data.length > 0) {
_docId = res.data[0]._id
return res.data[0]
}
return null
} catch (e) {
return null
}
@@ -51,20 +65,29 @@ const _doPush = async () => {
records: storage.getRecords(),
settings: storage.getSettings(),
streak: storage.getStreak(),
customPlans: storage.getCustomPlans(),
themeId: themeMod.getCurrentTheme().id,
updatedAt: db.serverDate()
}
// Query then upsert: one doc per user
const existing = await db.collection(DB_COLLECTION)
.where({ _openid: '{openid}' })
.get()
// Use cached doc id if available
if (_docId) {
try {
await db.collection(DB_COLLECTION).doc(_docId).update({ data })
return
} catch (e) {
_docId = null // doc may have been deleted
}
}
// Query for existing doc (relies on security rules to scope to current user)
const existing = await db.collection(DB_COLLECTION).limit(1).get()
if (existing && existing.data && existing.data.length > 0) {
await db.collection(DB_COLLECTION)
.doc(existing.data[0]._id)
.update({ data })
_docId = existing.data[0]._id
await db.collection(DB_COLLECTION).doc(_docId).update({ data })
} else {
await db.collection(DB_COLLECTION).add({ data })
const res = await db.collection(DB_COLLECTION).add({ data })
if (res && res._id) _docId = res._id
}
} catch (e) {
// Silently retry on next write
@@ -75,14 +98,20 @@ const clearAll = async () => {
const db = getDb()
if (!db) return
try {
const existing = await db.collection(DB_COLLECTION)
.where({ _openid: '{openid}' })
.get()
if (existing && existing.data && existing.data.length > 0) {
await db.collection(DB_COLLECTION)
.doc(existing.data[0]._id)
.remove()
if (_docId) {
try {
await db.collection(DB_COLLECTION).doc(_docId).remove()
_docId = null
return
} catch (e) {
_docId = null
}
}
const existing = await db.collection(DB_COLLECTION).limit(1).get()
if (existing && existing.data && existing.data.length > 0) {
await db.collection(DB_COLLECTION).doc(existing.data[0]._id).remove()
}
_docId = null
} catch (e) {
// Nothing to clear
}