初始化本地仓库
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
const GITEE_LATEST_RELEASE_API = 'https://gitee.com/api/v5/repos/li-hua-88/scanapp/releases/latest'
|
||||
const AUTO_UPDATE_CHECK_DATE_KEY = 'scanapp_auto_update_check_date'
|
||||
|
||||
export function getCurrentAppVersion() {
|
||||
// #ifdef APP-PLUS
|
||||
return plus.runtime.version || '1.0.0'
|
||||
// #endif
|
||||
try {
|
||||
return uni.getSystemInfoSync().appVersion || '1.0.0'
|
||||
} catch (error) {
|
||||
return '1.0.0'
|
||||
}
|
||||
}
|
||||
|
||||
export function compareVersions(leftVersion, rightVersion) {
|
||||
const left = String(leftVersion || '0').replace(/^v/i, '').split('.')
|
||||
const right = String(rightVersion || '0').replace(/^v/i, '').split('.')
|
||||
const length = Math.max(left.length, right.length)
|
||||
for (let index = 0; index < length; index += 1) {
|
||||
const leftPart = Number(left[index] || 0)
|
||||
const rightPart = Number(right[index] || 0)
|
||||
if (leftPart > rightPart) return 1
|
||||
if (leftPart < rightPart) return -1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
export function getReleaseUpdateInfo(release) {
|
||||
const latestVersion = String(release?.tag_name || release?.name || '').replace(/^v/i, '')
|
||||
if (!latestVersion) throw new Error('未获取到有效的版本号')
|
||||
const apkAsset = (release.assets || []).find((asset) => /\.apk(?:\?|$)/i.test(asset.name || asset.browser_download_url || ''))
|
||||
return {
|
||||
latestVersion,
|
||||
apkUrl: apkAsset?.browser_download_url || '',
|
||||
releaseUrl: release.html_url || 'https://gitee.com/li-hua-88/scanapp/releases/latest',
|
||||
updateNote: String(release.body || '修复已知问题并优化使用体验').replace(/\r?\n/g, '\n').trim()
|
||||
}
|
||||
}
|
||||
|
||||
export function getTodayUpdateCheckKey() {
|
||||
const now = new Date()
|
||||
const year = now.getFullYear()
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(now.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
export function shouldAutoCheckForUpdate() {
|
||||
return uni.getStorageSync(AUTO_UPDATE_CHECK_DATE_KEY) !== getTodayUpdateCheckKey()
|
||||
}
|
||||
|
||||
export function markAutoUpdateChecked() {
|
||||
uni.setStorageSync(AUTO_UPDATE_CHECK_DATE_KEY, getTodayUpdateCheckKey())
|
||||
}
|
||||
|
||||
|
||||
export function getLatestRelease() {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: GITEE_LATEST_RELEASE_API,
|
||||
method: 'GET',
|
||||
timeout: 15000,
|
||||
header: {
|
||||
Accept: 'application/json'
|
||||
},
|
||||
success: (res) => {
|
||||
let release = res.data
|
||||
if (typeof release === 'string') {
|
||||
try {
|
||||
release = JSON.parse(release)
|
||||
} catch (error) {
|
||||
release = null
|
||||
}
|
||||
}
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && release && typeof release === 'object') {
|
||||
resolve(release)
|
||||
return
|
||||
}
|
||||
reject(new Error(`更新服务请求失败(HTTP ${res.statusCode || 0})`))
|
||||
},
|
||||
fail: () => reject(new Error('无法连接更新服务,请检查网络后重试'))
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import request from '@/utils/request.js'
|
||||
import config from '@/config/index.js'
|
||||
|
||||
export function login(data) {
|
||||
return request.post('/auth/login', data, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
|
||||
export function logout() {
|
||||
return request.post('/auth/logout', {}, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import config from '@/config/index.js'
|
||||
import request from '@/utils/request.js'
|
||||
import { normalizeImageUrl } from '@/api/upload.js'
|
||||
|
||||
export const normalizeFeedbackImageUrl = normalizeImageUrl
|
||||
|
||||
function normalizeFeedbackRecord(record) {
|
||||
if (!record || typeof record !== 'object') return record
|
||||
return {
|
||||
...record,
|
||||
images: Array.isArray(record.images) ? record.images.map(normalizeFeedbackImageUrl) : record.images
|
||||
}
|
||||
}
|
||||
|
||||
export function submitFeedback(data) {
|
||||
return request.post('/feedback', {
|
||||
...data,
|
||||
images: Array.isArray(data?.images) ? data.images.map(normalizeFeedbackImageUrl) : data?.images
|
||||
}, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
|
||||
export async function getMyFeedbackList(params) {
|
||||
const result = await request.get('/feedback/mine', params, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
return result && Array.isArray(result.items)
|
||||
? { ...result, items: result.items.map(normalizeFeedbackRecord) }
|
||||
: result
|
||||
}
|
||||
|
||||
export async function getMyFeedbackDetail(id) {
|
||||
const result = await request.get(`/feedback/mine/${id}`, {}, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
return normalizeFeedbackRecord(result)
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import request from '@/utils/request.js'
|
||||
import config from '@/config/index.js'
|
||||
|
||||
export function getUserInfo() {
|
||||
return request.get('/member/user-info', {}, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
|
||||
export function updateUserInfo(data) {
|
||||
return request.put('/member/user/update', data, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
|
||||
export function changePassword(data) {
|
||||
return request.put('/member/user/change-password', data, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import request from '@/utils/request.js'
|
||||
|
||||
export function getProcessOptions() {
|
||||
return request.get('/produce/process')
|
||||
}
|
||||
|
||||
export function getStepOptions(processId) {
|
||||
return request.get('/produce/process-step', {
|
||||
process_id: processId || ''
|
||||
})
|
||||
}
|
||||
|
||||
export function getStatusOptions(stepId) {
|
||||
return request.get('/produce/step-status', {
|
||||
step_id: stepId || ''
|
||||
})
|
||||
}
|
||||
|
||||
export function getDataEntryConfig(params = {}) {
|
||||
return request.get('/produce/config/data-entry', params)
|
||||
}
|
||||
|
||||
export function lookupMaterial(productCode) {
|
||||
return request.get('/produce/material/lookup', {
|
||||
product_code: String(productCode || '').trim()
|
||||
})
|
||||
}
|
||||
|
||||
export function getScanAppMaterialCategories() {
|
||||
return request.get('/produce/scanapp/material-category')
|
||||
}
|
||||
|
||||
export function getHardwareFaultDescriptionOptions(categoryIds = []) {
|
||||
return request.get('/produce/hardware-fault-description/options', {
|
||||
category_ids: categoryIds.filter(Boolean).join(',')
|
||||
})
|
||||
}
|
||||
|
||||
export function checkMemberUser(userCode) {
|
||||
return request.get('/produce/member-user/check', {
|
||||
user_code: String(userCode || '').trim()
|
||||
})
|
||||
}
|
||||
|
||||
export function getOrderRecentRecords(params = {}) {
|
||||
return request.get('/produce/scan-data', params)
|
||||
}
|
||||
|
||||
export function getOrderStatistics(params = {}) {
|
||||
return request.get('/produce/scan-data/statistics', params)
|
||||
}
|
||||
|
||||
export function submitOrderRecord(data) {
|
||||
return request.post('/produce/scan-data/record', data)
|
||||
}
|
||||
|
||||
export function getProductRecentRecords(params = {}) {
|
||||
return request.get('/produce/product-record/recent', params)
|
||||
}
|
||||
|
||||
export function getProductStatistics(params = {}) {
|
||||
return request.get('/produce/product-record/statistics', params)
|
||||
}
|
||||
|
||||
export function submitProductRecord(data) {
|
||||
return request.post('/produce/product-record/record', data)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import request from '@/utils/request.js'
|
||||
|
||||
export function getExceptionSettings() {
|
||||
return request.get('/produce/exception/settings')
|
||||
}
|
||||
|
||||
export function getExceptionStatistics(params = {}) {
|
||||
return request.get('/produce/exception/statistics', params)
|
||||
}
|
||||
|
||||
export function getRecentExceptions(params = {}) {
|
||||
return request.get('/produce/exception/recent', params)
|
||||
}
|
||||
|
||||
export function checkExceptionOrder(orderNo) {
|
||||
return request.get('/produce/exception/order-check', {
|
||||
order_no: String(orderNo || '').trim()
|
||||
})
|
||||
}
|
||||
|
||||
export function getRepairTasks(params = {}) {
|
||||
return request.get('/produce/repair-record/tasks', params)
|
||||
}
|
||||
|
||||
export function getRepairStatistics(params = {}) {
|
||||
return request.get('/produce/repair-record/statistics', params)
|
||||
}
|
||||
|
||||
export function getRepairTask(deviceNo) {
|
||||
return request.get('/produce/exception/repair-task', {
|
||||
device_no: String(deviceNo || '').trim()
|
||||
})
|
||||
}
|
||||
|
||||
export function submitExceptionRecord(data) {
|
||||
return request.post('/produce/exception/record', data)
|
||||
}
|
||||
|
||||
export function submitRepairRecord(data) {
|
||||
return request.post('/produce/repair-record/record', data)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import config from '@/config/index.js'
|
||||
import request from '@/utils/request.js'
|
||||
|
||||
export function getConfigByCode(code) {
|
||||
return request.get(`/system/config/code/${encodeURIComponent(code)}`, {}, {
|
||||
baseURL: config.apiBaseURL,
|
||||
showError: false
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import config from '@/config/index.js'
|
||||
import { uploadFile } from '@/utils/request.js'
|
||||
|
||||
const getBackendOrigin = () => config.apiBaseURL.replace(/\/api\/?$/, '')
|
||||
|
||||
/**
|
||||
* 将后端返回的图片地址转换为当前 APP 可访问的地址。
|
||||
* 本地存储配置可能生成 127.0.0.1,Android 真机访问时必须改用局域网后端地址。
|
||||
*/
|
||||
export function normalizeImageUrl(imageUrl) {
|
||||
if (typeof imageUrl !== 'string' || !imageUrl) return imageUrl
|
||||
if (/^data:image\//i.test(imageUrl) || /^file:\/\//i.test(imageUrl)) return imageUrl
|
||||
if (/^https?:\/\/(?:127\.0\.0\.1|localhost)(?::\d+)?(?=\/|$)/i.test(imageUrl)) {
|
||||
return imageUrl.replace(/^https?:\/\/(?:127\.0\.0\.1|localhost)(?::\d+)?/i, getBackendOrigin())
|
||||
}
|
||||
if (imageUrl.startsWith('//127.0.0.1') || imageUrl.startsWith('//localhost')) {
|
||||
return imageUrl.replace(/^\/\/(?:127\.0\.0\.1|localhost)(?::\d+)?/i, getBackendOrigin())
|
||||
}
|
||||
return imageUrl.startsWith('/') ? `${getBackendOrigin()}${imageUrl}` : imageUrl
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传单张图片。页面只负责保存本地临时路径,提交时才调用本方法。
|
||||
*/
|
||||
export async function uploadImage(filePath, subDir = 'image') {
|
||||
const result = await uploadFile('/file/image', filePath, {
|
||||
sub_dir: subDir
|
||||
}, {
|
||||
baseURL: config.apiBaseURL
|
||||
})
|
||||
const imageUrl = result?.url || result?.full_url || result?.path
|
||||
if (!imageUrl) throw new Error('图片上传未返回地址')
|
||||
return normalizeImageUrl(imageUrl)
|
||||
}
|
||||
Reference in New Issue
Block a user