refactor: restructure entire project for human maintainability
Server: - Add Express framework, replace custom router/request parser - Create DAO layer (12 files) centralizing all 73 SQL queries - Rewrite 7 route files as thin Express controllers calling DAOs - Add SCF-to-Express adapter (lib/serverless.js) - Add auth middleware (middleware/auth.js) - Remove dead code from lib/auth.js Admin console: - Extract DataTable component (table + pagination) - Extract ConfirmModal component (modal + form styles) - Create listMixin for paginated list pages - Move form styles to common.css for slot compatibility - Refactor device + subscription pages as examples Miniprogram: - Split 734-line BLE monolith into 4 focused modules (protocol, connection, commands, barrel index) - Create API module (utils/api.js) with named functions - Create page utilities (utils/page.js) - Refactor index + profile pages to use API module
这个提交包含在:
@@ -1,5 +1,5 @@
|
||||
var ble = require('../../services/ble')
|
||||
var http = require('../../utils/request')
|
||||
var api = require('../../utils/api')
|
||||
var config = require('../../config/env')
|
||||
var app = getApp()
|
||||
|
||||
@@ -49,7 +49,7 @@ Page({
|
||||
|
||||
self.setData({ connected: ble.isConnected() })
|
||||
|
||||
http.get('/api/v1/device/list').then(function (data) {
|
||||
api.getDevices().then(function (data) {
|
||||
var devices = data.devices || []
|
||||
self.setData({ hasDevice: devices.length > 0 })
|
||||
if (devices.length > 0) {
|
||||
@@ -61,7 +61,7 @@ Page({
|
||||
}
|
||||
}).catch(function () {})
|
||||
|
||||
http.get('/api/v1/subscription').then(function (sub) {
|
||||
api.getSubscription().then(function (sub) {
|
||||
self.setData({
|
||||
subscription: sub,
|
||||
subRemaining: sub.remaining_days || 0
|
||||
@@ -125,7 +125,7 @@ Page({
|
||||
var self = this
|
||||
wx.showLoading({ title: '解绑中...' })
|
||||
ble.disconnect()
|
||||
http.post('/api/v1/device/unbind', {}).then(function () {
|
||||
api.unbindDevice().then(function () {
|
||||
wx.hideLoading()
|
||||
self.setData({
|
||||
hasDevice: false,
|
||||
@@ -157,7 +157,7 @@ Page({
|
||||
success: function (res) {
|
||||
if (res.confirm && res.content) {
|
||||
var deviceId = res.content.trim()
|
||||
http.post('/api/v1/device/mock-bind', { device_id: deviceId }).then(function () {
|
||||
api.mockBind(deviceId).then(function () {
|
||||
wx.showToast({ title: '模拟绑定成功', icon: 'success' })
|
||||
self.checkState()
|
||||
}).catch(function (err) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var http = require('../../utils/request')
|
||||
var api = require('../../utils/api')
|
||||
var app = getApp()
|
||||
|
||||
Page({
|
||||
@@ -15,14 +15,14 @@ Page({
|
||||
|
||||
loadProfile: function () {
|
||||
var self = this
|
||||
http.get('/api/v1/user/profile').then(function (profile) {
|
||||
api.getProfile().then(function (profile) {
|
||||
self.setData({
|
||||
userInfo: profile,
|
||||
deviceCount: profile.device_count || 0
|
||||
})
|
||||
}).catch(function () {})
|
||||
|
||||
http.get('/api/v1/subscription').then(function (sub) {
|
||||
api.getSubscription().then(function (sub) {
|
||||
self.setData({
|
||||
subscription: sub,
|
||||
subRemaining: sub.remaining_days || 0
|
||||
@@ -42,7 +42,7 @@ Page({
|
||||
content: '解绑后将无法使用该设备,确定要解绑吗?',
|
||||
success: function (modalRes) {
|
||||
if (modalRes.confirm) {
|
||||
http.post('/api/v1/device/unbind', {}).then(function () {
|
||||
api.unbindDevice().then(function () {
|
||||
wx.showToast({ title: '已解绑', icon: 'success' })
|
||||
self.loadProfile()
|
||||
}).catch(function (err) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户