diff --git a/miniprogram/app.js b/miniprogram/app.js
index a3fbd09..5b0ea91 100644
--- a/miniprogram/app.js
+++ b/miniprogram/app.js
@@ -18,6 +18,15 @@ App({
this.checkLogin()
},
+ // Safety net: if the framework ever tries to open an unknown/empty route
+ // (e.g. a stale page stack after the pages list changed), fall back to home
+ // instead of surfacing a hard "page not found" crash.
+ onPageNotFound: function (res) {
+ if (res && res.isEntryPage) {
+ wx.reLaunch({ url: '/pages/index/index', fail: function () {} })
+ }
+ },
+
checkLogin: function () {
var token = wx.getStorageSync('token')
if (!token) {
diff --git a/miniprogram/i18n/locales/history.js b/miniprogram/i18n/locales/history.js
new file mode 100644
index 0000000..d31d040
--- /dev/null
+++ b/miniprogram/i18n/locales/history.js
@@ -0,0 +1,31 @@
+// "记录" (history) page strings.
+module.exports = {
+ zh: {
+ statTotal: '累计次数',
+ statHours: '累计时长',
+ statMonth: '本月次数',
+ recentTitle: '最近记录',
+ smart: '✨ 智能',
+ normal: '🔄 普通',
+ empty: '暂无使用记录',
+ loadingMore: '加载更多...',
+ durationMin: '{min}分钟',
+ today: '今天',
+ yesterday: '昨天',
+ dateMd: '{m}月{d}日'
+ },
+ en: {
+ statTotal: 'Total Sessions',
+ statHours: 'Total Hours',
+ statMonth: 'This Month',
+ recentTitle: 'Recent Records',
+ smart: '✨ Smart',
+ normal: '🔄 Normal',
+ empty: 'No records yet',
+ loadingMore: 'Loading more...',
+ durationMin: '{min} min',
+ today: 'Today',
+ yesterday: 'Yesterday',
+ dateMd: '{m}/{d}'
+ }
+}
diff --git a/miniprogram/i18n/locales/home.js b/miniprogram/i18n/locales/home.js
new file mode 100644
index 0000000..eb789fd
--- /dev/null
+++ b/miniprogram/i18n/locales/home.js
@@ -0,0 +1,43 @@
+// "首页" (index) page strings.
+module.exports = {
+ zh: {
+ noDevice: '还没有绑定设备',
+ addDevice: '扫码添加设备',
+ myDevice: '我的设备',
+ connected: '已连接',
+ disconnected: '未连接',
+ reconnect: '重新连接',
+ smartRemain: '智能模式 · 剩余{days}天',
+ notSubscribed: '未订阅智能模式',
+ smartOpen: '智能模式已开放',
+ start: '开始使用',
+ deviceManage: '设备管理',
+ connectFailed: '连接失败',
+ unbindAction: '解绑当前设备',
+ unbindConfirmTitle: '确认解绑',
+ unbindConfirmText: '解绑后将无法使用该设备,确定要解绑吗?',
+ unbindLoading: '解绑中...',
+ unbindDone: '已解绑',
+ unbindFailed: '解绑失败'
+ },
+ en: {
+ noDevice: 'No device bound yet',
+ addDevice: 'Scan to add device',
+ myDevice: 'My Device',
+ connected: 'Connected',
+ disconnected: 'Disconnected',
+ reconnect: 'Reconnect',
+ smartRemain: 'Smart Mode · {days} days left',
+ notSubscribed: 'Smart Mode not subscribed',
+ smartOpen: 'Smart Mode available',
+ start: 'Start',
+ deviceManage: 'Manage Device',
+ connectFailed: 'Connection failed',
+ unbindAction: 'Unbind current device',
+ unbindConfirmTitle: 'Confirm Unbind',
+ unbindConfirmText: 'You will not be able to use this device after unbinding. Continue?',
+ unbindLoading: 'Unbinding...',
+ unbindDone: 'Unbound',
+ unbindFailed: 'Unbind failed'
+ }
+}
diff --git a/miniprogram/i18n/locales/index.js b/miniprogram/i18n/locales/index.js
index ee859d8..303e7f2 100644
--- a/miniprogram/i18n/locales/index.js
+++ b/miniprogram/i18n/locales/index.js
@@ -7,13 +7,17 @@ var profile = require('./profile')
var lightInfo = require('./lightInfo')
var manual = require('./manual')
var report = require('./report')
+var home = require('./home')
+var history = require('./history')
var namespaces = {
common: common,
profile: profile,
lightInfo: lightInfo,
manual: manual,
- report: report
+ report: report,
+ home: home,
+ history: history
}
var zh = {}
diff --git a/miniprogram/pages/history/history.js b/miniprogram/pages/history/history.js
index e1dd3c8..7a4bd4a 100644
--- a/miniprogram/pages/history/history.js
+++ b/miniprogram/pages/history/history.js
@@ -1,5 +1,6 @@
var http = require('../../utils/request')
var ble = require('../../services/ble')
+var i18n = require('../../i18n/index')
Page({
data: {
@@ -15,6 +16,7 @@ Page({
},
onShow: function () {
+ i18n.bind(this)
this.loadRecords(true)
},
@@ -52,7 +54,7 @@ Page({
var records = (data.records || []).map(function (r) {
var durationMin = Math.floor((r.total_duration_ms || 0) / 60000)
pageMs += (r.total_duration_ms || 0)
- r.duration_text = durationMin + '分钟'
+ r.duration_text = i18n.t('history.durationMin', { min: durationMin })
r.region_names = ble.getRegionName(r.regions || 0).join('、')
r.wavelength_name = ble.getWavelengthName(r.wavelength || 2)
r.date_text = self.formatDate(r.start_time || r.created_at)
@@ -89,8 +91,8 @@ Page({
var h = ('0' + d.getHours()).slice(-2)
var m = ('0' + d.getMinutes()).slice(-2)
- if (d >= today) return '今天 ' + h + ':' + m
- if (d >= yesterday) return '昨天 ' + h + ':' + m
- return (d.getMonth() + 1) + '月' + d.getDate() + '日 ' + h + ':' + m
+ if (d >= today) return i18n.t('history.today') + ' ' + h + ':' + m
+ if (d >= yesterday) return i18n.t('history.yesterday') + ' ' + h + ':' + m
+ return i18n.t('history.dateMd', { m: d.getMonth() + 1, d: d.getDate() }) + ' ' + h + ':' + m
}
})
diff --git a/miniprogram/pages/history/history.wxml b/miniprogram/pages/history/history.wxml
index 9acd267..8e6b580 100644
--- a/miniprogram/pages/history/history.wxml
+++ b/miniprogram/pages/history/history.wxml
@@ -3,31 +3,31 @@
{{total}}
- 累计次数
+ {{i18n.history.statTotal}}
{{totalHours}}h
- 累计时长
+ {{i18n.history.statHours}}
{{monthCount}}
- 本月次数
+ {{i18n.history.statMonth}}
- 最近记录
+ {{i18n.history.recentTitle}}
{{item.date_text}}
- {{item.mode === 1 ? '✨ 智能' : '🔄 普通'}}
+ {{item.mode === 1 ? i18n.history.smart : i18n.history.normal}}
{{item.duration_text}}
📃
- 暂无使用记录
+ {{i18n.history.empty}}
- 加载更多...
+ {{i18n.history.loadingMore}}
diff --git a/miniprogram/pages/index/index.js b/miniprogram/pages/index/index.js
index a36b61b..b28d183 100644
--- a/miniprogram/pages/index/index.js
+++ b/miniprogram/pages/index/index.js
@@ -1,5 +1,6 @@
var ble = require('../../services/ble')
var api = require('../../utils/api')
+var i18n = require('../../i18n/index')
var app = getApp()
Page({
@@ -17,6 +18,7 @@ Page({
},
onShow: function () {
+ i18n.bind(this)
this.checkState()
this._onStatus = this.onBleStatus.bind(this)
this._onBattery = this.onBleBattery.bind(this)
@@ -69,9 +71,11 @@ Page({
})
var p2 = api.getSubscription().then(function (sub) {
+ var remaining = sub.remaining_days || 0
self.setData({
subscription: sub,
- subRemaining: sub.remaining_days || 0
+ subRemaining: remaining,
+ subRemainText: i18n.t('home.smartRemain', { days: remaining })
})
}).catch(function (err) {
console.error('getSubscription failed', err)
@@ -111,7 +115,7 @@ Page({
},
onError: function (err) {
self.setData({ connected: false, bleState: 'error' })
- wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
+ wx.showToast({ title: err.msg || i18n.t('home.connectFailed'), icon: 'none' })
}
})
},
@@ -123,12 +127,12 @@ Page({
onManageDevice: function () {
var self = this
wx.showActionSheet({
- itemList: ['解绑当前设备'],
+ itemList: [i18n.t('home.unbindAction')],
success: function (res) {
if (res.tapIndex === 0) {
wx.showModal({
- title: '确认解绑',
- content: '解绑后将无法使用该设备,确定要解绑吗?',
+ title: i18n.t('home.unbindConfirmTitle'),
+ content: i18n.t('home.unbindConfirmText'),
success: function (modalRes) {
if (modalRes.confirm) {
self.doUnbind()
@@ -142,7 +146,7 @@ Page({
doUnbind: function () {
var self = this
- wx.showLoading({ title: '解绑中...' })
+ wx.showLoading({ title: i18n.t('home.unbindLoading') })
ble.disconnect()
api.unbindDevice().then(function () {
wx.hideLoading()
@@ -152,10 +156,10 @@ Page({
deviceInfo: null,
connected: false
})
- wx.showToast({ title: '已解绑', icon: 'success' })
+ wx.showToast({ title: i18n.t('home.unbindDone'), icon: 'success' })
}).catch(function (err) {
wx.hideLoading()
- wx.showToast({ title: err.message || '解绑失败', icon: 'none' })
+ wx.showToast({ title: err.message || i18n.t('home.unbindFailed'), icon: 'none' })
})
},
diff --git a/miniprogram/pages/index/index.wxml b/miniprogram/pages/index/index.wxml
index af5069f..0c0ffdb 100644
--- a/miniprogram/pages/index/index.wxml
+++ b/miniprogram/pages/index/index.wxml
@@ -1,47 +1,47 @@
- 加载中...
+ {{i18n.common.loading}}
📱
- 还没有绑定设备
-
+ {{i18n.home.noDevice}}
+
💆
- {{deviceName || '我的设备'}}
+ {{deviceName || i18n.home.myDevice}}
- 已连接
- 未连接
+ {{i18n.home.connected}}
+ {{i18n.home.disconnected}}
🔋 {{battery}}%
-
+
💳
- 智能模式 · 剩余{{subRemaining}}天
- 未订阅智能模式
+ {{subRemainText}}
+ {{i18n.home.notSubscribed}}
›
✨
- 智能模式已开放
+ {{i18n.home.smartOpen}}
-
-
+
+