Files
wx_pbzc/components/progress-ring/progress-ring.js
T
lc ac0db6118d feat(ui): 全项目暗黑模式适配 — 加 theme 变量 + 替换全部硬编码颜色
新增主题变量 (light + dark 两套):
- --success-rgb / --danger / --danger-rgb (utils/theme.js)

全部硬编码 #XXX / rgba 颜色统一改主题变量:
- progress-ring 加 trackColor prop,默认 #EEEEEE
  (canvas 不能直接读 CSS var,需要 caller 传字面颜色)
- ui-modal sheet 背景 #FFFFFF → var(--card-bg), 加底部 padding 避开 Dock TabBar
- ui-modal handle #DDD → var(--bg-soft)
- ui-btn --danger 文字 #E53935 → var(--danger), 边框 rgba(229,57,53,...) → rgba(var(--danger-rgb),...)
- calendar-heatmap 三个 #999/#333 文字色 → var(--text-secondary)/var(--text)
- index picker: preset/custom input 背景 #F5F5F5 → var(--bg-soft), label #666 → var(--text-secondary)
- index done-badge 绿色 → var(--success-rgb), pending-text #CCC → var(--text-secondary)
- records empty/hint #CCC/#E0E0E0 → var(--text-secondary), danger 红 → var(--danger)
- settings plan-editor-sheet 背景 #FFFFFF → var(--card-bg), avatar 背景, handle, editor-input, preview 全部跟进
- leaderboard 金/铜背景 #FFF7E6/#FFF1E6 → rgba 半透明 (dark mode 下不刺眼)

Tab bar inactive 图标重新根据 dark mode 切换颜色 (#999999 light / #98989F dark)

leaderboard.json 删除 backgroundColor: #F5F5F5 覆盖,让 theme.json 接管

故意保留:
- 各 .wxss 中渐变按钮上的 #FFFFFF 文字色
- 排行榜金/铜文字色 #FA8C16/#D46B08 (视觉符号约定)
- 各页 data 中 orange theme 默认值 (onShow 后被 themeMod 覆盖)
2026-07-08 15:22:09 +08:00

95 lines
2.7 KiB
JavaScript

const util = require('../../utils/util')
Component({
properties: {
duration: { type: Number, value: 60 },
remaining: { type: Number, value: 60 },
size: { type: Number, value: 280 },
ringWidth: { type: Number, value: 14 },
status: { type: String, value: 'idle' },
primaryColor: { type: String, value: '#FF6B35' },
primaryLightColor: { type: String, value: '#FF8C5A' },
// Track (background ring) color. Caller passes a darker shade in dark mode
// so the ring isn't an eye-searing light circle on a dark background.
trackColor: { type: String, value: '#EEEEEE' }
},
data: {
displayTime: '00:00',
statusText: '准备开始'
},
observers: {
'remaining, status, duration'() {
const texts = { idle: '准备开始', running: '坚持住', paused: '已暂停', completed: '完成!' }
this.setData({
displayTime: util.formatTime(this.data.remaining),
statusText: texts[this.data.status] || ''
})
},
'remaining, duration, size, ringWidth, primaryColor, trackColor'() {
this._draw()
}
},
lifetimes: {
ready() {
const query = this.createSelectorQuery()
query.select('#ringCanvas')
.fields({ node: true, size: true })
.exec((res) => {
if (!res || !res[0] || !res[0].node) return
const canvas = res[0].node
const dpr = wx.getWindowInfo().pixelRatio || 2
const displaySize = this.data.size
canvas.width = displaySize * dpr
canvas.height = displaySize * dpr
this._ctx = canvas.getContext('2d')
this._dpr = dpr
this._draw()
})
}
},
methods: {
_draw() {
const ctx = this._ctx
if (!ctx) return
const { size, ringWidth, duration, remaining, primaryColor, trackColor } = this.data
const dpr = this._dpr
const w = size * dpr
const h = size * dpr
ctx.clearRect(0, 0, w, h)
const cx = w / 2
const cy = h / 2
const radius = (size - ringWidth) / 2 * dpr
const lw = ringWidth * dpr
// track ring
ctx.beginPath()
ctx.arc(cx, cy, radius, 0, Math.PI * 2)
ctx.strokeStyle = trackColor
ctx.lineWidth = lw
ctx.lineCap = 'round'
ctx.stroke()
// progress arc (clockwise from 12 o'clock)
const ratio = duration > 0 ? Math.max(0, Math.min(1, remaining / duration)) : 0
if (ratio > 0.001) {
const startAngle = -Math.PI / 2
const endAngle = startAngle + ratio * Math.PI * 2
ctx.beginPath()
ctx.arc(cx, cy, radius, startAngle, endAngle)
ctx.strokeStyle = primaryColor
ctx.lineWidth = lw
ctx.lineCap = 'round'
ctx.stroke()
}
}
}
})