修复小程序后台路由误判
This commit is contained in:
@@ -4,7 +4,7 @@ const { API_DOMAIN } = require('../utils/config')
|
||||
module.exports = {
|
||||
login(data) {
|
||||
return request({
|
||||
url: '/auth/login',
|
||||
url: '/user/login',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
@@ -12,7 +12,7 @@ module.exports = {
|
||||
|
||||
getLoginShops(account) {
|
||||
return request({
|
||||
url: `/auth/login-shops/${encodeURIComponent(account)}`,
|
||||
url: `/user/check/login-shops/account/${encodeURIComponent(account)}`,
|
||||
method: 'GET'
|
||||
})
|
||||
},
|
||||
@@ -157,7 +157,7 @@ module.exports = {
|
||||
|
||||
switchShop(shopId) {
|
||||
return request({
|
||||
url: '/auth/switch-shop',
|
||||
url: '/user/switch-shop',
|
||||
method: 'POST',
|
||||
data: {
|
||||
shopId
|
||||
@@ -167,7 +167,7 @@ module.exports = {
|
||||
|
||||
logout() {
|
||||
return request({
|
||||
url: '/auth/logout',
|
||||
url: '/user/logout',
|
||||
method: 'POST'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,19 +16,34 @@ global.wx = {
|
||||
global.getApp = () => ({ clearSession: () => {}, goLogin: () => {} })
|
||||
|
||||
const employeesApi = require('./api/employees')
|
||||
const authApi = require('./api/auth')
|
||||
const planningApi = require('./api/planning')
|
||||
const request = require('./utils/request')
|
||||
|
||||
async function run() {
|
||||
await planningApi.calendar({ startDate: '2026-10-27' })
|
||||
await authApi.login({ account: 'manager', password: 'secret' })
|
||||
await authApi.getLoginShops('manager')
|
||||
await authApi.switchShop(12)
|
||||
await authApi.logout()
|
||||
await employeesApi.reviewSummary()
|
||||
await employeesApi.reviewApplications()
|
||||
await employeesApi.approveApplication(12)
|
||||
await employeesApi.rejectApplication(12, '资料不完整')
|
||||
|
||||
assert.deepStrictEqual(requests.map(item => [item.method || 'GET', item.url, item.data]), [
|
||||
['GET', 'http://127.0.0.1:80/api/admin/user/workbench/registration/summary', undefined],
|
||||
['GET', 'http://127.0.0.1:80/api/admin/user/workbench/registration/list', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/admin/user/workbench/registration/12/approve', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/admin/user/workbench/registration/12/reject', { reason: '资料不完整' }]
|
||||
['GET', 'http://127.0.0.1:80/api/manager/planning/calendar?startDate=2026-10-27', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/user/login', { account: 'manager', password: 'secret' }],
|
||||
['GET', 'http://127.0.0.1:80/api/user/check/login-shops/account/manager', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/user/switch-shop', { shopId: 12 }],
|
||||
['POST', 'http://127.0.0.1:80/api/user/logout', undefined],
|
||||
['GET', 'http://127.0.0.1:80/api/user/workbench/registration/summary', undefined],
|
||||
['GET', 'http://127.0.0.1:80/api/user/workbench/registration/list', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/user/workbench/registration/12/approve', undefined],
|
||||
['POST', 'http://127.0.0.1:80/api/user/workbench/registration/12/reject', { reason: '资料不完整' }]
|
||||
])
|
||||
assert(requests.every(item => !item.url.includes('/api/admin/')))
|
||||
assert.strictEqual(request.toBackendRequestPath('http://127.0.0.1:80/api/manager/planning/calendar'), '/manager/planning/calendar')
|
||||
}
|
||||
|
||||
run().catch(error => {
|
||||
|
||||
@@ -109,12 +109,15 @@
|
||||
|
||||
.calendar-error-action {
|
||||
display: flex;
|
||||
flex: 0 0 96rpx;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 96rpx;
|
||||
min-width: 96rpx;
|
||||
height: 52rpx;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
border-radius: 999rpx;
|
||||
background: #ffffff;
|
||||
color: #8b4b35;
|
||||
|
||||
@@ -153,7 +153,6 @@ module.exports = {
|
||||
BASE_DOMAIN,
|
||||
BRAND_CONFIG,
|
||||
API_DOMAIN: `${BASE_DOMAIN}/api`,
|
||||
ADMIN_API_BASE_URL: `${BASE_DOMAIN}/api/admin`,
|
||||
REQUEST_TIMEOUT: normalizeRequestTimeout(localOverride.requestTimeout),
|
||||
ENABLE_REQUEST_SIGNING: localOverride.enableRequestSigning !== false
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
|
||||
const { API_DOMAIN, REQUEST_TIMEOUT, ENABLE_REQUEST_SIGNING } = require('./config')
|
||||
const auth = require('./auth')
|
||||
const { sha256Hex, hmacSha256Hex, buildCanonicalParams, buildJsonPayload, randomNonce } = require('./crypto')
|
||||
|
||||
@@ -11,7 +11,7 @@ let sessionExpiredHandling = false
|
||||
|
||||
function buildUrl(url, params) {
|
||||
const sourceParams = params || {}
|
||||
const baseUrl = sourceParams.__baseUrl ? sourceParams.__baseUrl : ADMIN_API_BASE_URL
|
||||
const baseUrl = sourceParams.__baseUrl ? sourceParams.__baseUrl : API_DOMAIN
|
||||
const query = Object.keys(sourceParams)
|
||||
.filter(key => key !== '__baseUrl')
|
||||
.filter(key => sourceParams[key] !== undefined && sourceParams[key] !== null && sourceParams[key] !== '')
|
||||
@@ -82,40 +82,26 @@ function extractPath(value) {
|
||||
|
||||
function toBackendRequestPath(url) {
|
||||
const path = extractPath(url).replace(/\/+$/, '') || '/'
|
||||
if (path === '/api/admin') {
|
||||
return '/admin'
|
||||
}
|
||||
if (path.startsWith('/api/admin/')) {
|
||||
return `/admin/${path.slice('/api/admin/'.length)}`
|
||||
}
|
||||
if (path === '/api') {
|
||||
return '/'
|
||||
}
|
||||
if (path.startsWith('/api/')) {
|
||||
return `/${path.slice('/api/'.length)}`
|
||||
}
|
||||
if (path === '/admin/api') {
|
||||
return '/admin'
|
||||
}
|
||||
if (path.startsWith('/admin/api/')) {
|
||||
return `/admin/${path.slice('/admin/api/'.length)}`
|
||||
}
|
||||
if (path === '/admin' || path.startsWith('/admin/')) {
|
||||
return path
|
||||
}
|
||||
return path.startsWith('/') ? `/admin${path}` : `/admin/${path}`
|
||||
return path
|
||||
}
|
||||
|
||||
function isAuthFreePath(url) {
|
||||
return [
|
||||
'/auth/login',
|
||||
'/auth/register',
|
||||
'/user/login',
|
||||
'/user/workbench/register/',
|
||||
'/user/workbench/shops/available',
|
||||
'/user/check/login-shops/',
|
||||
'/user/send-verification-code',
|
||||
'/user/phone-login',
|
||||
'/user/wechat-mini/',
|
||||
'/user/check/login-shops/',
|
||||
'/legal-agreement/current'
|
||||
].some(path => String(url || '').includes(path))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const { ADMIN_API_BASE_URL, API_DOMAIN, REQUEST_TIMEOUT } = require('./config')
|
||||
const { API_DOMAIN, REQUEST_TIMEOUT } = require('./config')
|
||||
const request = require('./request')
|
||||
|
||||
function normalizeUploadResponse(response, fallbackMessage) {
|
||||
@@ -32,7 +32,7 @@ function preserveResponseId(rawText, payload) {
|
||||
|
||||
function uploadFile(options) {
|
||||
const method = 'POST'
|
||||
const baseUrl = options.baseUrl || ADMIN_API_BASE_URL
|
||||
const baseUrl = options.baseUrl || API_DOMAIN
|
||||
const url = `${baseUrl}${options.url}`
|
||||
const signatureHeaders = request.buildSignatureHeaders({
|
||||
url: options.url,
|
||||
|
||||
Reference in New Issue
Block a user