修改代码中的请求接口方便后续维护

master
denghaohaoya 2026-03-28 22:33:20 +08:00
parent 20744820b7
commit 15ffbb22ed
7 changed files with 46 additions and 34 deletions

View File

@ -1,5 +1,6 @@
import { getToken } from '@/utils/auth'
import { toast } from '@/utils/common'
import apiUrl from '@/utils/api'
// 参数转URL查询字符串
function tansParams(params) {
@ -24,6 +25,8 @@ function tansParams(params) {
return result
}
import store from '@/store'
// 专门用于8081端口的请求
const request8081 = config => {
config.header = config.header || {}
@ -94,15 +97,18 @@ const request8081 = config => {
console.log('响应数据:', res.data)
console.log('响应数据类型:', typeof res.data)
const code = res.data.code || 200
const code = res.data.code
const msg = res.data.msg || '请求失败'
// console.log('业务状态码:', code)
// console.log('业务消息:', msg)
if (code === 401) {
toast('认证失败,请重新登录')
reject('401')
if (res.statusCode === 401 || code === 401) {
store.dispatch('LogOut').then(() => {
uni.reLaunch({ url: '/pages/login' })
})
reject(new Error('无效的会话,或者会话已过期,请重新登录。'))
return
} else if (code === 403) {
// console.log('=== 403错误详细信息 ===')
// console.log('完整响应:', JSON.stringify(res, null, 2))
@ -132,11 +138,11 @@ export function getProductList(params) {
// console.log('1. Token值:', token)
// console.log('2. Token长度:', token ? token.length : 0)
// console.log('3. Token前缀:', token ? token.substring(0, 20) + '...' : '无')
// console.log('4. 请求URL:', 'http://193.112.94.36:8081/mall/product/list')
// console.log('4. 请求URL:', apiUrl + '/mall/product/list')
// console.log('5. 认证方式:', 'Bearer Token (与8080共享)')
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/product/list',
method: 'get',
params: params
@ -146,7 +152,7 @@ export function getProductList(params) {
// 删除商品
export function deleteProduct(id) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/product/delete/${id}`,
method: 'delete'
})
@ -155,7 +161,7 @@ export function deleteProduct(id) {
// 新增商品
export function addProduct(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/product/add',
method: 'post',
data: data
@ -166,7 +172,7 @@ export function addProduct(data) {
export function addProductWithFile(filePath, formData) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'http://193.112.94.36:8081/mall/product/add',
url: apiUrl + '/mall/product/add',
filePath: filePath,
name: 'file',
formData: formData,
@ -187,7 +193,7 @@ export function addProductWithFile(filePath, formData) {
// 获取商品详情
export function getProductDetail(id) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/product/${id}`,
method: 'get'
})
@ -197,7 +203,7 @@ export function getProductDetail(id) {
export function updateProductWithFile(filePath, formData) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'http://193.112.94.36:8081/mall/product/update',
url: apiUrl + '/mall/product/update',
filePath: filePath,
name: 'file',
formData: formData,
@ -218,7 +224,6 @@ export function updateProductWithFile(filePath, formData) {
// 修改商品
export function updateProduct(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
url: '/mall/product/update',
method: 'post',
data: data
@ -229,7 +234,7 @@ export function updateProduct(data) {
export function importProductData(filePath, formData) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: 'http://193.112.94.36:8081/mall/product/importData',
url: apiUrl + '/mall/product/importData',
filePath: filePath,
name: 'file',
formData: formData,
@ -250,7 +255,7 @@ export function importProductData(filePath, formData) {
// 获取导入记录
export function getImportRecord() {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/product/importRecord',
method: 'get'
});
@ -259,7 +264,7 @@ export function getImportRecord() {
// 批量删除商品
export function batchDeleteProduct(ids) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/product/batchDelete',
method: 'delete',
data: { ids: ids }
@ -269,7 +274,7 @@ export function batchDeleteProduct(ids) {
// 添加品牌
export function addBrand(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/brand/add',
method: 'post',
data: data
@ -279,7 +284,7 @@ export function addBrand(data) {
// 获取品牌列表
export function getBrandList(params) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/brand/list',
method: 'get',
params: params
@ -289,7 +294,7 @@ export function getBrandList(params) {
// 获取品牌树状结构
export function getBrandTree(storeId, brandName) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/brand/getTree/${storeId}`,
method: 'get',
params: { brandName }
@ -299,7 +304,7 @@ export function getBrandTree(storeId, brandName) {
// 删除品牌
export function deleteBrand(brandId) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/brand/delete/${brandId}`,
method: 'delete'
})
@ -308,7 +313,7 @@ export function deleteBrand(brandId) {
// 修改品牌名称
export function updateBrand(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/brand/update',
method: 'post',
data: data
@ -318,7 +323,7 @@ export function updateBrand(data) {
// 新增分类
export function addClassification(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/classification/add',
method: 'post',
data: data
@ -328,7 +333,7 @@ export function addClassification(data) {
// 获取分类树状结构
export function getClassificationTree(storeId, classificationName) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/classification/getTree/${storeId}`,
method: 'get',
params: { classificationName }
@ -338,7 +343,7 @@ export function getClassificationTree(storeId, classificationName) {
// 修改分类名称
export function updateClassification(data) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: '/mall/classification/update',
method: 'post',
data: data
@ -348,7 +353,7 @@ export function updateClassification(data) {
// 删除分类
export function deleteClassification(classificationId) {
return request8081({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/classification/delete/${classificationId}`,
method: 'delete'
})

View File

@ -1,9 +1,10 @@
import request from '@/utils/request'
import apiUrl from '@/utils/api'
// 根据用户ID查询门店列表
export function getStoreList(userId) {
return request({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/store/getUserStore/${userId}`,
method: 'get'
})

View File

@ -1,9 +1,10 @@
import request from '@/utils/request'
import apiUrl from '@/utils/api'
// 根据用户ID查询门店列表
export function PostData(data) {
return request({
baseUrl: 'http://193.112.94.36:8081',
baseUrl: apiUrl,
url: `/mall/product/getByBarcodes`,
method: 'post',
data:data

View File

@ -52,7 +52,7 @@
</view>
<view class="goods-info">
<image
:src="item.mainImage ? 'http://193.112.94.36:8081' + item.mainImage : '/static/default-goods.png'"
:src="item.mainImage ? apiUrl + item.mainImage : '/static/default-goods.png'"
class="goods-img"
mode="aspectFill"
/>
@ -88,6 +88,7 @@
<script>
import { getProductList as fetchProductList, batchDeleteProduct } from '@/api/product'
import { getToken, getStoreId } from '@/utils/auth'
import apiUrl from '@/utils/api'
export default {
data() {
@ -96,7 +97,8 @@ export default {
showFilter: false,
storeId: null,
goodsList: [],
selectedIds: []
selectedIds: [],
apiUrl
}
},
computed: {

View File

@ -456,6 +456,7 @@
<script>
import { getProductDetail, updateProduct, updateProductWithFile, getClassificationTree, getBrandTree } from '@/api/product'
import { getStoreId } from '@/utils/auth'
import apiUrl from '@/utils/api'
export default {
name: 'GoodsEdit',
data() {
@ -606,7 +607,7 @@ export default {
const data = res.data;
this.goodsInfo = {
imageUrl: data.mainImage ? 'http://193.112.94.36:8081' + data.mainImage : this.goodsInfo.imageUrl,
imageUrl: data.mainImage ? apiUrl + data.mainImage : this.goodsInfo.imageUrl,
name: data.productName || this.goodsInfo.name,
unit: this.goodsInfo.unit,
barcode: data.productBarCode || this.goodsInfo.barcode,

View File

@ -240,7 +240,7 @@ export default {
//
goQuickSetup() {
uni.navigateTo({
url: '/pages/quick-setup/quick-setup'
url: '/package_a/quick-setup/quick-setup'
});
},

View File

@ -55,7 +55,7 @@
<view class="store-status" v-if="currentTab === 'all'">
<view class="status-content">
<view class="dui">
<image class="dui-img" src="http://193.112.94.36:8099/static/images/Frame 52.png"></image>
<image class="dui-img" :src="apiUrl + '/static/images/Frame 52.png'"></image>
</view>
<view class="status-left">
<text class="status-text">已开启微店商店库</text>
@ -72,7 +72,7 @@
<view class="store-status" v-else-if="currentTab === 'expiring'">
<view class="status-left-content">
<view class="dui">
<image class="dui-img" src="http://193.112.94.36:8099/static/images/Mask group.png"></image>
<image class="dui-img" :src="apiUrl + '/static/images/Mask group.png'"></image>
</view>
<view class="status-left">
<text class="status-text">快速处理</text>
@ -95,7 +95,7 @@
<view class="store-status" v-else-if="currentTab === 'outstock'">
<view class="status-content">
<view class="dui">
<image class="dui-img" src="http://193.112.94.36:8099/static/images/Mask group (1).png"></image>
<image class="dui-img" :src="apiUrl + '/static/images/Mask group (1).png'"></image>
</view>
<view class="status-left">
<text class="status-text">库存不足预警设置</text>
@ -119,7 +119,7 @@
</view>
<view class="goods-top" @tap="goToStockDetail(item)">
<view class="goods-tou">
<image :src="item.mainImage ? 'http://193.112.94.36:8081' + item.mainImage : 'http://193.112.94.36:8099/static/images/687b6f95b14eff60f4b77147b3726ab2.jpg' "></image>
<image :src="item.mainImage ? apiUrl + item.mainImage : apiUrl + '/static/images/687b6f95b14eff60f4b77147b3726ab2.jpg' "></image>
</view>
<view class="goods-info">
<text class="goods-name">{{ item.productName }}</text>
@ -185,10 +185,12 @@
<script>
import { getProductList as fetchProductList, deleteProduct } from '@/api/product'
import { getToken, getStoreId } from '@/utils/auth'
import apiUrl from '@/utils/api'
export default {
data() {
return {
apiUrl: apiUrl,
currentTab: 'all',
searchText: '',
showFilter: false,