This commit is contained in:
王子琦
2026-01-09 15:48:50 +08:00
commit ea34c396dd
106 changed files with 60207 additions and 0 deletions

47
pc-web/src/api/client.js Normal file
View File

@@ -0,0 +1,47 @@
import axios from 'axios'
function normalizeApiBaseUrl(configuredBaseUrl) {
if (!configuredBaseUrl) return '/api'
if (/^https?:\/\//i.test(configuredBaseUrl)) {
try {
const url = new URL(configuredBaseUrl)
if (
process.env.NODE_ENV === 'production' &&
(url.hostname === 'localhost' || url.hostname === '127.0.0.1')
) {
return '/api'
}
return configuredBaseUrl
} catch (e) {
return '/api'
}
}
return configuredBaseUrl
}
const baseURL = normalizeApiBaseUrl(process.env.VUE_APP_API_BASE_URL)
export const apiClient = axios.create({
baseURL
})
export function buildPdfUrl(fileName) {
if (!fileName) return ''
const name = String(fileName)
if (/^https?:\/\//i.test(name)) return name
const encodedName = encodeURIComponent(name)
const configuredBaseUrl = normalizeApiBaseUrl(process.env.VUE_APP_API_BASE_URL)
if (configuredBaseUrl && /^https?:\/\//i.test(configuredBaseUrl)) {
try {
const url = new URL(configuredBaseUrl)
return `${url.origin}/pdf/${encodedName}`
} catch (e) {
return `/pdf/${encodedName}`
}
}
return `/pdf/${encodedName}`
}

5
pc-web/src/api/pdfs.js Normal file
View File

@@ -0,0 +1,5 @@
import { apiClient as client } from './client'
export function fetchPdfs() {
return client.get('/pdfs').then(res => res.data)
}

View File

@@ -0,0 +1,49 @@
import { apiClient as client } from './client'
export function fetchRegistrations() {
return client.get('/registrations').then(res => res.data)
}
export function fetchRegistration(id) {
return client.get(`/registrations/${id}`).then(res => res.data)
}
export function createRegistration(payload) {
return client.post('/registrations', payload).then(res => res.data)
}
export function updateRegistration(id, payload) {
return client.put(`/registrations/${id}`, payload).then(res => res.data)
}
export function deleteRegistration(id) {
return client.delete(`/registrations/${id}`).then(res => res.data)
}
export function sendSmsToUserPhone(id) {
return client.get(`/registrations/sendSms/${id}`).then(res => res.data)
}
export function searchRegistrations(params = {}) {
return client
.get('/registrations/search', {
params: {
customerName: params.customerName,
contact: params.contact,
serviceType: params.serviceType,
powerType: params.powerType,
status: params.status,
urlPath: params.urlPath
}
})
.then(res => res.data)
}
export function searchByPhone(phoneNumber) {
return searchRegistrations({ contact: phoneNumber, status: '已登记' })
}
export function serchUrlPath(urlPath) {
return client.get(`/registrations/getPdfPath/${urlPath}`).then(res => res.data)
}