Files
JayuCloud/JY-Salon-WeChat/api/shop.js
T

80 lines
1.8 KiB
JavaScript
Raw Normal View History

2026-06-04 16:39:06 +08:00
const request = require('../utils/request')
2026-07-16 12:00:06 +08:00
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
function buildDownloadUrl(params) {
const query = Object.keys(params || {})
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
.join('&')
return `${ADMIN_API_BASE_URL}/export${query ? `?${query}` : ''}`
}
function downloadFile(url, params) {
const header = request.buildSignatureHeaders({
url: '/export',
requestUrl: url,
method: 'GET',
params
})
return new Promise((resolve, reject) => {
wx.downloadFile({
url,
header,
timeout: REQUEST_TIMEOUT,
success(response) {
if (response.statusCode >= 200 && response.statusCode < 300 && response.tempFilePath) {
resolve(response.tempFilePath)
return
}
reject(new Error(`导出 Excel 下载失败:HTTP ${response.statusCode}`))
},
fail(error) {
reject(new Error(`导出 Excel 下载失败:${error.errMsg || '网络异常'}`))
}
})
})
}
2026-06-04 16:39:06 +08:00
module.exports = {
settings() {
return request({
url: '/manager/shop'
2026-06-04 16:39:06 +08:00
})
},
saveSettings(data) {
return request({
url: '/manager/shop',
2026-06-04 16:39:06 +08:00
method: 'PUT',
data
})
},
2026-07-01 02:08:51 +08:00
scheduleExceptions(params) {
return request({
url: '/manager/shop/schedule-exceptions',
params
})
},
saveScheduleException(data) {
return request({
url: '/manager/shop/schedule-exceptions',
method: 'POST',
data
})
},
2026-06-04 16:39:06 +08:00
exportData(params) {
return request({
url: '/export',
params
})
2026-07-16 12:00:06 +08:00
},
downloadExport(params) {
const url = buildDownloadUrl(params)
return downloadFile(url, params)
2026-06-04 16:39:06 +08:00
}
}