优化Net

This commit is contained in:
itgaojian163 2025-06-05 17:21:24 +08:00
parent d6526fde86
commit fb54447a91
15 changed files with 234 additions and 133 deletions

View File

@ -25,7 +25,8 @@
"pages/copyright/refund/refund",
"pages/copyright/repair/repair",
"pages/copyright/applyRepair/applyRepair",
"pages/copyright/applyRefund/applyRefund"
"pages/copyright/applyRefund/applyRefund",
"pages/shop/market"
],
"window": {
"navigationBarTextStyle": "black",
@ -42,6 +43,12 @@
"iconPath": "/static/images/ic_home_normal.png",
"selectedIconPath": "/static/images/ic_home_select.png"
},
{
"pagePath": "pages/shop/market",
"text": "软著市场",
"iconPath": "/static/images/ic_home_normal.png",
"selectedIconPath": "/static/images/ic_home_select.png"
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",

View File

@ -2,6 +2,7 @@ import {
request
} from "../http";
const Cache = require('../../utils/storage');
const projectName = "plug"
// 公共API
const apiPath = {
mineInvoiceOrderList: '/api/invoicerecharge/recharge-listpage/{userId}/{status}', //可以开具发票的订单
@ -21,7 +22,7 @@ class InvoiceApi {
static doGetMineInvoiceOrderList(data, status) {
const userId = Cache.get('userId')
const path = apiPath.mineInvoiceOrderList.replace('{userId}', userId).replace('{status}', status)
return request(path, "GET", data, null, 'plug')
return request(path, "GET", data, projectName)
}
static doGetDicListByPId(id) {
const path = apiPath.dicByPId.replace('{pId}', id)
@ -31,45 +32,45 @@ class InvoiceApi {
static doGetMineInvoiceList(data) {
const userId = Cache.get('userId')
const path = apiPath.mineInvoiceList.replace('{userId}', userId)
return request(path, "GET", data, null, 'plug')
return request(path, "GET", data, projectName)
}
//保存我的开票信息
static doSaveMineInvoiceInfo(data) {
const userId = Cache.get('userId')
const path = apiPath.saveInvoiceInfo.replace('{userId}', userId)
return request(path, "POST", data, null, 'plug')
return request(path, "POST", data, projectName)
}
//编辑开票信息
static doUpdateMineInvoiceInfo(id, data) {
const path = apiPath.updateInvoiceInfo.replace('{invoiceId}', id)
return request(path, "PUT", data, null, 'plug')
return request(path, "PUT", data, projectName)
}
//删除开票信息
static doDelMineInvoiceInfo(id) {
const path = apiPath.deleteInvoiceInfo.replace('{ids}', id)
return request(path, "DELETE", null, null, 'plug')
return request(path, "DELETE", null, projectName)
}
//开票申请列表
static doGetInvoiceRecordList(data) {
const userId = Cache.get('userId')
const path = apiPath.mineInvoiceRecordList.replace('{userId}', userId)
return request(path, "GET", data, null, 'plug')
return request(path, "GET", data, projectName)
}
//取消开票申请
static doCancelInvoiceRecord(id) {
const path = apiPath.cancelInvoiceRecord.replace('{invoiceRechargeId}', id)
return request(path, "PUT", null, null, 'plug')
return request(path, "PUT", null, projectName)
}
//提交开票申请
static doSaveInvoiceRecord(data) {
const userId = Cache.get('userId')
const path = apiPath.saveInvoiceRecord.replace('{userId}', userId)
return request(path, "POST", data, null, 'plug')
return request(path, "POST", data, projectName)
}
//修改开票申请
static doUpdateInvoiceRecord(id, data) {
const path = apiPath.updateInvoiceRecord.replace('{invoiceRechargeId}', id)
return request(path, 'PUT', data, null, 'plug')
return request(path, 'PUT', data, projectName)
}
}

View File

@ -29,7 +29,7 @@ class PayService {
}
//获取微信支付参数
static doGetWxPayParams(data) {
return request(apiPath.wxPayParams, "POST", data, null, "operator")
return request(apiPath.wxPayParams, "POST", data, "operator")
}
}

View File

@ -84,7 +84,7 @@ class ProjectService {
//获取使用规则数据
static doGetRuleDate(id) {
const path = apiPath.ruleData.replace('{id}', id)
return request(path, "GET", null, null, "operator", false)
return request(path, "GET", null, "operator", false)
}
static doGetInvestDetail(data) {
return request(apiPath.investDetail, "GET", data)

57
net/api/shop.js Normal file
View File

@ -0,0 +1,57 @@
import {
request
} from "../http";
// 公共API
const proName = 'aiShop'
const apiPath = {
indexList: "/api/goodsonline/listpage", //上架的软著商品列表 GET
saveGoods: "/api/goods/save", //新增软著商品 POST
goodsDetail: "/api/goods/get/{goodsId}", //商品详情 GET
delGoods: "/api/goods/remove/{ids}", //删除商品 DELETE
updateGoods: "/api/goods/update/{goodsId}", //修改商品 PUT
doCheck: "/api/goods/sub-check/{goodsId}", //提交审核 PUT
onGoods: "/api/goods/publish/{goodsId}", //上架商品 PUT
offGoods: "/api/goods/no-publish/{goodsId}", //下架商品 PUT
}
class Shop {
//获取上架的软著列表
static doGetIndexList(data) {
return request(apiPath.indexList, "GET", data, proName)
}
//新增软件商品
static doSaveGoods(data) {
return request(apiPath.saveGoods, "POST", data, proName)
}
//商品详情
static doGetGoodsDetail(id) {
const path = apiPath.goodsDetail.replace('{goodsId}', id)
return request(path, "GET", null, proName)
}
//删除商品
static doDelGoods(id) {
const path = apiPath.delGoods.replace('{goodsId}', id)
return request(path, "DELETE", null, proName)
}
//更新商品
static doUpdateGoods(id, data) {
const path = apiPath.updateGoods.replace('{goodsId}', id)
return request(path, "PUT", data, proName)
}
//提交审核
static doSubCheck(id) {
const path = apiPath.doCheck.replace('{goodsId}', id)
return request(path, "PUT", null, proName)
}
//上架商品
static doOnGoods(id) {
const path = apiPath.onGoods.replace('{goodsId}', id)
return request(path, "PUT", null, proName)
}
//下架商品
static doOffGoods(id) {
const path = apiPath.offGoods.replace('{goodsId}', id)
return request(path, "PUT", null, proName)
}
}
export default Shop;

View File

@ -26,13 +26,13 @@ const apiPath = {
}
class UserService {
static doLogin(data) {
return request(apiPath.loginUrl, "POST", data, null, 'operator', false)
return request(apiPath.loginUrl, "POST", data, 'operator', false)
}
static doRegister(data) {
return request(apiPath.registerUrl, "POST", data, null, 'operator', false)
return request(apiPath.registerUrl, "POST", data, 'operator', false)
}
static doUnbindWx() {
return request(apiPath.unbindWx, "GET", null, null, 'operator', true)
return request(apiPath.unbindWx, "GET", null, 'operator', true)
}
static doUpdateUserInfo(data) {
return request(apiPath.updateUserInfo, "PUT", data)

View File

@ -5,10 +5,18 @@ import {
uploadImgUrl,
previewUrl,
copyrightUrl,
aiShopUrl,
imgAssets,
appUrl
} from '../net/mainUrl'
// 项目与基础URL映射关系
const PROJECT_URL_MAP = {
operator: operatorUrl,
copyright: copyrightUrl,
plug: operatorPlug,
aiShop: aiShopUrl,
// 添加新项目只需在此扩展
};
/**
* 传入请求参数返回Promise支持链试调用
* @param url 请求地址
@ -16,56 +24,42 @@ import {
* @param data 请求体数据
* @param params 请求参数
*/
function request(url, method = "GET", data = {}, params = {}, project = "copyright", needToken = true) {
const header = {
"content-type": "application/json"
// 有其他content-type需求加点逻辑判断处理即可
}
//是否需要token
function request(url, method = "GET", data = {}, project = "copyright", needToken = true) {
// 1. 参数预处理
const baseUrl = PROJECT_URL_MAP[project] || copyrightUrl;
const requestUrl = baseUrl + url;
// 2. 请求头配置
const headers = {
"Content-Type": "application/json"
};
if (needToken) {
const token = Cache.get('token')
const token = Cache.get('token');
if (token) {
header.Auth = `Bearer ${token}`;
headers.Auth = `Bearer ${token}`;
}
}
//判断项目
var baseUrl = operatorUrl
if (project == 'operator') {
baseUrl = operatorUrl
} else if (project == 'copyright') {
baseUrl = copyrightUrl
} else if (project == 'plug') {
baseUrl = operatorPlug
}
// 3. 请求配置
const requestConfig = {
url: requestUrl.toString(),
method: method.toUpperCase(),
data,
header: headers,
timeout: 10000,
dataType: "json"
};
return new Promise(function (resolve, reject) {
wx.request({
url: baseUrl + url,
timeout: 8000,
method,
data,
dataType: "json", // 微信官方文档中介绍会对数据进行一次JSON.parse
header,
...requestConfig,
success(res) {
// wx.hideLoading();
// HTTP状态码为200才视为成功
if (res.statusCode === 200) {
// 真正的数据响应体中还有一层success字段判断业务状态按实际情况处理
resolve(res.data)
// if (res.data.success) {
// resolve(res.data.result)
// } else {
// // 业务判断错误
// reject(res)
// }
} else {
console.log('错误success')
// wx.request的特性只要有响应就会走success回调所以在这里判断状态非200的均视为请求失败
reject(res.data)
}
},
fail(err) {
// wx.hideLoading();
// 断网、服务器挂了都会fail回调直接reject即可
console.log('错误')
if (err.data) {
reject(err.data)

View File

@ -1,7 +1,8 @@
// 定义api服务地址
const operatorUrl = 'https://www.aimzhu.com/operator';
const operatorUrl = 'https://www.aimzhu.com/operator'
const operatorPlug = 'https://www.aimzhu.com/operator-plugin'
const copyrightUrl = 'https://www.aimzhu.com/copyright';
const copyrightUrl = 'https://www.aimzhu.com/copyright'
const aiShopUrl = 'https://www.aimzhu.com/aishop'
const uploadImgUrl = copyrightUrl + '/api/file/v2/upload-image'
const previewUrl = copyrightUrl + '/route/file/v2/download/true/'
const imgAssets = 'https://www.aimzhu.com/miniapp-assets'
@ -13,6 +14,7 @@ export {
uploadImgUrl,
previewUrl,
copyrightUrl,
aiShopUrl,
imgAssets,
appUrl
}

View File

@ -7,6 +7,7 @@ import {
} from '../../net/http'
const Cache = require('../../utils/storage')
const Utils = require('../../utils/util')
const data =require('../../utils/data')
const app = getApp()
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
@ -87,23 +88,7 @@ Page({
showAd: false, //显示优惠卷广告
tempCoupons: [], //优惠卷
isNoShowToday: false, //今日不再显示
tabList: [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": app.globalData.localAssets + "/ic_home_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_home_select.png",
"selected": true,
"hasMsg": false,
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",
"iconPath": app.globalData.localAssets + "/ic_mine_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_mine_select.png",
"selected": false,
"hasMsg": false
}
],
tabList: data.tabList,
},
onLoad(e) {
const _self = this
@ -615,7 +600,7 @@ Page({
})
const requests = _self.data.tempCoupons.map(item => {
const coupons = {
couponId: _self.data.tempCoupons.couponId
couponId: item.couponId
}
return UserApi.doSaveCoupons(coupons)
})

View File

@ -1,10 +1,8 @@
// pages/mine/mine.js
import UserApi from '../../../net/api/userApi'
import ProApi from '../../../net/api/projectApi'
import {
copyrightUrl
} from '../../../net/http'
const Utils = require('../../../utils/util')
const data = require('../../../utils/data')
const app = getApp()
const deviceInfo = wx.getDeviceInfo()
const screenInfo = wx.getWindowInfo();
@ -33,47 +31,7 @@ Page({
allCount: 0,
materialCount: 0,
accountInfo: {},
menuList: [{
icon: "ic-user",
title: "个人信息",
path: "/pages/mine/mineAccount/mineInfo/mineInfo"
}, {
icon: 'ic-msg',
title: '消息通知',
path: '/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice'
}, {
icon: 'ic-refund',
title: '退款项目',
path: '/pages/copyright/refund/refund'
}, {
icon: 'ic-repair',
title: '补正项目',
path: '/pages/copyright/repair/repair'
}, {
icon: 'ic-invoice-info',
title: '发票抬头',
path: '/pages/mine/mineAccount/invoiceInfo/invoiceInfo'
}, {
icon: "ic-pay-record",
title: "资金流水",
path: "/pages/mine/mineAccount/minePayRecord/minePayRecord"
}, {
icon: "ic-order",
title: "我的订单",
path: "/pages/mine/mineAccount/mineOrder/mineOrder"
}, {
icon: "ic-invoice",
title: "发票管理",
path: "/pages/mine/mineAccount/mineInvoiceManage/mineInvoiceManage"
}, {
icon: "ic-contact",
title: "产权联系人",
path: "/pages/mine/mineAccount/mineContact/mineContact"
}, {
icon: "ic-unbind",
title: "微信解绑",
path: ""
}],
menuList: data.mineMenuList,
buttons: [{
text: '知道了'
}],
@ -83,23 +41,7 @@ Page({
errorHint: '',
animationData: {}, //刷新动画
animation: null,
tabList: [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": app.globalData.localAssets + "/ic_home_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_home_select.png",
"selected": false,
"hasMsg": false
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",
"iconPath": app.globalData.localAssets + "/ic_mine_normal.png",
"selectedIconPath": app.globalData.localAssets + "/ic_mine_select.png",
"selected": true,
"hasMsg": false
}
],
tabList: data.tabList,
allPrice: 0, //全托管价格
materialPrice: 0, //写材料价格
urgent: 0, //加急价格

35
pages/shop/market.js Normal file
View File

@ -0,0 +1,35 @@
// pages/shop/market.js
const data= require('../../utils/data')
Page({
/**
* 页面的初始数据
*/
data: {
tabList:data.tabList
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
console.log('页面显示')
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
const tabList = this.data.tabList;
tabList.forEach(item => {
item.selected = item.pagePath === currentPage.route;
});
this.setData({
tabList
});
},
})

5
pages/shop/market.json Normal file
View File

@ -0,0 +1,5 @@
{
"usingComponents": {
"custom-tabbar": "/components/tabbar/custom-tabbar"
}
}

4
pages/shop/market.wxml Normal file
View File

@ -0,0 +1,4 @@
<view>
市场
</view>
<custom-tabbar tabList="{{tabList}}" color="var(--tabbar-normal-color)" selectedColor="var(--tabbar-select-color)"></custom-tabbar>

1
pages/shop/market.wxss Normal file
View File

@ -0,0 +1 @@
/* pages/shop/market.wxss */

View File

@ -28,8 +28,76 @@ const stateList = [{
"title": "已取消",
"value": "CANCELED"
}]
const tabList = [{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "/static/images/ic_home_normal.png",
"selectedIconPath": "/static/images/ic_home_select.png",
"selected": false,
"hasMsg": false
},
{
"pagePath": "pages/shop/market",
"text": "软著市场",
"iconPath": "/static/images/ic_home_normal.png",
"selectedIconPath": "/static/images/ic_home_select.png",
"selected": false,
"hasMsg": false,
},
{
"pagePath": "pages/mine/mineIndex/mine",
"text": "我的",
"iconPath": "/static/images/ic_mine_normal.png",
"selectedIconPath": "/static/images/ic_mine_select.png",
"selected": false,
"hasMsg": false
}
]
const mineMenuList = [{
"icon": "ic-user",
"title": "个人信息",
"path": "/pages/mine/mineAccount/mineInfo/mineInfo"
}, {
"icon": 'ic-msg',
"title": '消息通知',
"path": '/pages/mine/mineAccount/mineMsgNotice/mineMsgNotice'
}, {
"icon": 'ic-refund',
"title": '退款项目',
"path": '/pages/copyright/refund/refund'
}, {
"icon": 'ic-repair',
"title": '补正项目',
"path": '/pages/copyright/repair/repair'
}, {
"icon": 'ic-invoice-info',
"title": '发票抬头',
"path": '/pages/mine/mineAccount/invoiceInfo/invoiceInfo'
}, {
"icon": "ic-pay-record",
"title": "资金流水",
"path": "/pages/mine/mineAccount/minePayRecord/minePayRecord"
}, {
"icon": "ic-order",
"title": "我的订单",
"path": "/pages/mine/mineAccount/mineOrder/mineOrder"
}, {
"icon": "ic-invoice",
"title": "发票管理",
"path": "/pages/mine/mineAccount/mineInvoiceManage/mineInvoiceManage"
}, {
"icon": "ic-contact",
"title": "产权联系人",
"path": "/pages/mine/mineAccount/mineContact/mineContact"
}, {
"icon": "ic-unbind",
"title": "微信解绑",
"path": ""
}]
module.exports = {
stateList,
kindList,
typeList
typeList,
tabList,
mineMenuList
}