Commit Graph

4 Commits

Author SHA1 Message Date
lc 6f33dd54c0 debug: add console logs to cloud.js for diagnostics 2026-06-04 17:37:01 +08:00
lc ec52eb7b0d fix: auto-create cloud collection on first push, remove manual setup
The collection 'plank_data' no longer needs to be created manually.
db.collection().add() auto-creates the collection on first write.
Changed push strategy from 'query-then-add' to 'add-first':
  - add() succeeds → collection created, data stored
  - add() fails (duplicate) → fall back to query + update
  - .get() on non-existent collection now caught gracefully

Also switched updatedAt to db.serverDate() for consistent timestamps.
2026-06-04 17:22:51 +08:00
lc 9b67cc2e22 chore: configure CloudBase env ID cloudbase-d1g56kl2q8f4f7d8a 2026-06-04 17:17:57 +08:00
lc a04c017e37 feat: cloud sync with WeChat CloudBase — data survives app deletion
Problem: All data stored in wx.StorageSync is permanently lost when
user deletes the mini-program or clears cache.

Solution: Sync data to WeChat CloudBase (wx.cloud.database).
- Graceful degradation: if cloud env isn't configured, all local
  storage works exactly as before.
- On app launch: if local records are empty, pull from cloud.
- On writes: push to cloud (debounced 2s) after saveRecord,
  deleteRecord, saveSettings, updateStreak, setTheme.
- Clear data in settings also clears cloud.

Files:
- utils/cloud.js: cloud sync wrapper (init, pullAll, pushAll, clearAll)
- app.js: cloud.init() + restore on fresh install
- utils/storage.js: cloud.pushAll() after every mutation
- utils/theme.js: cloud.pushAll() after setTheme
- pages/settings/settings.js: cloud.clearAll() when clearing data
- project.config.json: cloudfunctionRoot added

Setup required (one-time in WeChat DevTools):
  1. Open 'Cloud Development' panel → enable CloudBase
  2. Create environment → copy env ID
  3. In app.js, change wx.cloud.init() → wx.cloud.init({ env: 'YOUR-ENV-ID' })
  4. Create 'plank_data' collection in cloud database
  5. Set collection permission to 'Only creator can read/write'
2026-06-04 17:13:35 +08:00