refactor: migrate to Tencent Cloud backend

这个提交包含在:
Guoguo
2026-04-28 22:56:47 +08:00
父节点 267c75718b
当前提交 444c91c0b0
修改 102 个文件,包含 17927 行新增1997 行删除
+2 -64
查看文件
@@ -1,45 +1,7 @@
var USE_CLOUD = true
function callCloud(funcName, action, data) {
return new Promise(function (resolve, reject) {
wx.cloud.callFunction({
name: funcName,
data: { action: action, data: data }
}).then(function (res) {
if (res.result && res.result.code === 0) {
resolve(res.result.data)
} else if (res.result && (res.result.code === 1001 || res.result.code === 1002)) {
wx.removeStorageSync('token')
wx.reLaunch({ url: '/pages/login/login' })
reject(res.result)
} else {
reject(res.result || { code: -1, message: '请求失败' })
}
}).catch(function (err) {
reject({ code: 2002, message: err.errMsg || '网络异常' })
})
})
}
var mock = null
if (!USE_CLOUD) {
mock = require('./mock')
}
var API_BASE = 'https://api.lightmask.com'
var config = require('../config/env')
var API_BASE = config.API_BASE
function httpRequest(options) {
if (mock && mock.enabled) {
return new Promise(function (resolve) {
setTimeout(function () {
var result = mock.handle(options.method || 'GET', options.path, options.data)
if (result.code === 0) {
resolve(result.data)
}
}, 200)
})
}
var token = wx.getStorageSync('token')
return new Promise(function (resolve, reject) {
@@ -71,31 +33,7 @@ function httpRequest(options) {
})
}
var FUNC_MAP = {
'/api/v1/auth/login': { fn: 'auth', action: 'login' },
'/api/v1/auth/refresh': { fn: 'auth', action: 'refresh' },
'/api/v1/user/profile': { fn: 'user', action: 'profile' },
'/api/v1/user/update': { fn: 'user', action: 'update' },
'/api/v1/device/bind': { fn: 'device', action: 'bind' },
'/api/v1/device/unbind': { fn: 'device', action: 'unbind' },
'/api/v1/device/list': { fn: 'device', action: 'list' },
'/api/v1/device/detail': { fn: 'device', action: 'detail' },
'/api/v1/subscription': { fn: 'subscription', action: 'status' },
'/api/v1/subscription/status': { fn: 'subscription', action: 'status' },
'/api/v1/subscription/purchase': { fn: 'subscription', action: 'purchase' },
'/api/v1/subscription/verify': { fn: 'subscription', action: 'verify' },
'/api/v1/treatment/sync': { fn: 'treatment', action: 'sync' },
'/api/v1/treatment/history': { fn: 'treatment', action: 'history' }
}
function request(options) {
if (USE_CLOUD) {
var mapping = FUNC_MAP[options.path]
if (mapping) {
return callCloud(mapping.fn, mapping.action, options.data)
}
return Promise.reject({ code: -1, message: '未映射的接口' })
}
return httpRequest(options)
}