秦佳浩 2 months ago
commit b831ab7028

@ -1,108 +1,176 @@
/**app.wxss**/ /** app.wxss **/
/*
*
* 100%
* 使 border-box 使 padding border
* #333
*/
.container { .container {
height: 100%; height: 100%;
box-sizing: border-box; box-sizing: border-box;
color: #333; color: #333;
font-family: helvetica,'Heiti SC',PingFangSC-Light; font-family: helvetica, 'Heiti SC', PingFangSC-Light;
} }
.price{
/*
*
* Arial (#eb2444)
* 使
*/
.price {
font-family: Arial; font-family: Arial;
display: inline-block; display: inline-block;
color: #eb2444; color: #eb2444;
padding-bottom:10rpx; padding-bottom: 10rpx;
padding-left:10rpx; padding-left: 10rpx;
} }
/* 价格数字显示不同大小 */ /*
* ¥$
* 24rpx
*/
.symbol { .symbol {
font-size: 24rpx; font-size: 24rpx;
} }
/*
*
* 32rpx
*/
.big-num { .big-num {
font-size: 32rpx; font-size: 32rpx;
} }
/*
*
* 24rpx
*/
.small-num { .small-num {
font-size: 24rpx; font-size: 24rpx;
} }
/* /*
*checkbox * checkbox
* *
*/ */
/* reg */
/*
* checkbox
* checkbox 100%
*/
uni-checkbox-group { uni-checkbox-group {
width: 100% !important; width: 100% !important;
} }
uni-checkbox-group uni-label{
width: 33% !important; /*
display: inline-flex; * checkbox
margin-bottom: 20rpx; * checkbox 33%使使
} *
/*checkbox 选项框大小 */ */
uni-checkbox .uni-checkbox-input{ uni-checkbox-group uni-label {
width: 33% !important;
display: inline-flex;
margin-bottom: 20rpx;
}
/*
* checkbox
* checkbox 38rpxborder-radius: 50%
*/
uni-checkbox .uni-checkbox-input {
width: 38rpx !important; width: 38rpx !important;
height: 38rpx !important; height: 38rpx !important;
border-radius: 50%!important; border-radius: 50% !important;
}
/*checkbox选中后样式 */
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked{
background: #e43130;
border: 1px solid transparent !important;
}
/*checkbox选中后图标样式 */
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked::before{
display: inline-block;
width: 20rpx;
height: 20rpx;
line-height: 20rpx;
text-align: center;
font-size: 18rpx;
color: #fff;
background: transparent;
transform: translate(-60%, -50%) scale(1);
-webkit-transform: translate(-60%, -50%) scale(1);
} }
/*
* checkbox
* checkbox (#e43130)
*/
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
background: #e43130;
border: 1px solid transparent !important;
}
/*
* checkbox
* checkbox
* 使 transform
*/
uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked::before {
display: inline-block;
width: 20rpx;
height: 20rpx;
line-height: 20rpx;
text-align: center;
font-size: 18rpx;
color: #fff;
background: transparent;
transform: translate(-60%, -50%) scale(1);
-webkit-transform: translate(-60%, -50%) scale(1);
}
/* /*
*radio * radio
* *
*/ */
/* 未选中的 背景样式 */
uni-radio .uni-radio-input{ /*
* radio
* radio 36rpx
*/
uni-radio .uni-radio-input {
height: 36rpx; height: 36rpx;
width: 36rpx; width: 36rpx;
border-radius: 50%; border-radius: 50%;
background: transparent; background: transparent;
box-sizing: border-box; box-sizing: border-box;
} }
/* 选中后的 背景样式 */
uni-radio .uni-radio-input.uni-radio-input-checked{
border: none !important;
background: #e43130 !important;
}
/* 选中后的 对勾样式 */
uni-radio .uni-radio-input.uni-radio-input-checked::before{
border-radius: 50%;
width: 32rpx;
height: 32rpx;
line-height: 32rpx;
text-align: center;
font-size: 20rpx;
color:#fff;
background: #e43130;
border-radius: 50%;
transform: translate(-50%, -50%) scale(1);
-webkit-transform: translate(-50%, -50%) scale(1);
}
/* 底部按钮兼容 iPhone X以上 */ /*
@media screen and (width: 375px) and (height: 812px){ * radio
* radio (#e43130)
*/
uni-radio .uni-radio-input.uni-radio-input-checked {
border: none !important;
background: #e43130 !important;
}
/*
* radio
* radio
* 使 transform
*/
uni-radio .uni-radio-input.uni-radio-input-checked::before {
border-radius: 50%;
width: 32rpx;
height: 32rpx;
line-height: 32rpx;
text-align: center;
font-size: 20rpx;
color: #fff;
background: #e43130;
border-radius: 50%;
transform: translate(-50%, -50%) scale(1);
-webkit-transform: translate(-50%, -50%) scale(1);
}
/*
* iPhone X
* iPhone X
*/
@media screen and (width: 375px) and (height: 812px) {
.container { .container {
padding-bottom: 70px; padding-bottom: 70px;
} }
} }
@media screen and (width: 414px) and (height: 736px){
/*
* iPhone 8 Plus
* iPhone 8 Plus
*/
@media screen and (width: 414px) and (height: 736px) {
.container { .container {
padding-bottom: 70px; padding-bottom: 70px;
} }

@ -1,9 +1,18 @@
import { import {
createSSRApp createSSRApp // 从 Vue 库中导入 createSSRApp 函数,用于创建一个适用于服务器端渲染 (SSR) 的 Vue 应用实例
} from 'vue' } from 'vue'
import App from './App.vue' import App from './App.vue' // 导入应用的根组件
export function createApp () {
/**
* 创建并返回一个 Vue 应用实例
*
* @returns {Object} - 包含应用实例的对象
*/
export function createApp() {
// 使用 createSSRApp 函数创建一个新的 Vue 应用实例,并传入根组件 App
const app = createSSRApp(App) const app = createSSRApp(App)
// 返回一个对象,包含创建的应用实例
return { return {
app app
} }

@ -1,99 +1,106 @@
{ {
"name" : "", "name": "", //
"appid" : "__UNI__2CF44C6", "appid": "__UNI__2CF44C6", // AppID
"description" : "", "description": "", //
"versionName" : "1.0.0", "versionName": "1.0.0", //
"versionCode" : "100", "versionCode": "100", //
"transformPx" : false, "transformPx": false, // px rpxfalse
/* 5+App */
"app-plus" : { /* 5+App */
"compatible" : { "app-plus": {
"ignoreVersion" : true //trueHBuilderX1.9.0 "compatible": {
}, "ignoreVersion": true // true HBuilderX 1.9.0
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* */
"modules" : {
"Camera" : {},
"LivePusher" : {}
},
/* */
"distribute" : {
/* android */
"android" : {
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
"<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
],
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ]
}
}
}, },
/* */ "usingComponents": true, // true
"mp-weixin" : { "nvueStyleCompiler": "uni-app", // nvue 使 uni-app
"appid" : "wx6fa71e69231a4fa4", "compilerVersion": 3, //
"setting" : {
"urlCheck" : false "splashscreen": {
}, "alwaysShowBeforeRender": true, // true
"usingComponents" : true, "waiting": true, // true
"permission" : { "autoclose": true, // true
"scope.userLocation" : { "delay": 0 // 0
"desc" : "你的位置信息将用于地址信息新增、修改以及获取附近门店"
}
},
"requiredPrivateInfos" : [ "getLocation", "chooseLocation" ]
}, },
"h5" : {
"title" : "", /* */
"domain" : "https://mini-h5.mall4j.com", "modules": {
"router" : { "Camera": {}, // Camera
"mode" : "history" "LivePusher": {} // LivePusher
}, },
"uniStatistics" : {
"enable" : false /* */
}, "distribute": {
"optimization" : { /* android */
"treeShaking" : { "android": {
"enable" : false "permissions": [
} "<uses-feature android:name=\"android.hardware.camera\"/>", // 使
}, "<uses-feature android:name=\"android.hardware.camera.autofocus\"/>", // 使
"template" : "index.html", "<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>", // 访
"devServer" : { "<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>", // 访 Wi-Fi
"disableHostCheck" : true, "<uses-permission android:name=\"android.permission.CAMERA\"/>", // 使
"port" : 80 "<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>", //
}, "<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>", // Wi-Fi
"sdkConfigs" : { "<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>", // 使
"maps" : { "<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>", //
"qqmap" : { "<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>", //
// h5ip "<uses-permission android:name=\"android.permission.READ_LOGS\"/>", //
"key" : "" "<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>", //
} "<uses-permission android:name=\"android.permission.RECORD_AUDIO\"/>", //
} "<uses-permission android:name=\"android.permission.VIBRATE\"/>", // 使
} "<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>", //
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>" //
],
"abiFilters": [ "armeabi-v7a", "arm64-v8a", "x86" ] // ABI
}
}
},
/* */
"mp-weixin": {
"appid": "wx6fa71e69231a4fa4", // AppID
"setting": {
"urlCheck": false // URL false
},
"usingComponents": true, // true
"permission": {
"scope.userLocation": {
"desc": "你的位置信息将用于地址信息新增、修改以及获取附近门店" //
}
}, },
"uniStatistics" : { "requiredPrivateInfos": [ "getLocation", "chooseLocation" ] //
"enable" : false },
"h5": {
"title": "", // H5
"domain": "https://mini-h5.mall4j.com", // H5
"router": {
"mode": "history" // 使 history
}, },
"vueVersion" : "3" "uniStatistics": {
"enable": false // Uni-App false
},
"optimization": {
"treeShaking": {
"enable": false // Tree Shaking false
}
},
"template": "index.html", // H5
"devServer": {
"disableHostCheck": true, // true
"port": 80 //
},
"sdkConfigs": {
"maps": {
"qqmap": {
"key": "" // QQ API Key H5 IP
}
}
}
},
"uniStatistics": {
"enable": false // Uni-App false
},
"vueVersion": "3" // 使 Vue Vue 3
} }

@ -1,196 +1,200 @@
{ {
"pages": [ "pages": [
{ {
"path": "pages/index/index", "path": "pages/index/index", //
"style": { "style": {
"backgroundTextStyle": "dark", "backgroundTextStyle": "dark", // "dark"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black", //
"enablePullDownRefresh": true, "enablePullDownRefresh": true, // true
"navigationBarTitleText": "mall4j" "navigationBarTitleText": "mall4j" //
} }
}, },
{ {
"path": "pages/user/user", "path": "pages/user/user", //
"style": { "style": {
"navigationBarTitleText": "个人中心" "navigationBarTitleText": "个人中心" //
} }
}, },
{ {
"path": "pages/basket/basket", "path": "pages/basket/basket", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "购物车", "navigationBarTitleText": "购物车", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/category/category", "path": "pages/category/category", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "分类商品", "navigationBarTitleText": "分类商品", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/sub-category/sub-category" "path": "pages/sub-category/sub-category" //
}, },
{ {
"path": "pages/search-page/search-page", "path": "pages/search-page/search-page", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "搜索", "navigationBarTitleText": "搜索", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/delivery-address/delivery-address", "path": "pages/delivery-address/delivery-address", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "收货地址", "navigationBarTitleText": "收货地址", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/editAddress/editAddress", "path": "pages/editAddress/editAddress", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "编辑收货地址", "navigationBarTitleText": "编辑收货地址", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/orderList/orderList", "path": "pages/orderList/orderList", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarTitleText": "订单列表", "navigationBarTitleText": "订单列表", //
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black", //
"navigationBarBackgroundColor": "#fafafa" "navigationBarBackgroundColor": "#fafafa" //
} }
}, },
{ {
"path": "pages/order-detail/order-detail", "path": "pages/order-detail/order-detail", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "订单详情", "navigationBarTitleText": "订单详情", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/submit-order/submit-order", "path": "pages/submit-order/submit-order", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "提交订单", "navigationBarTitleText": "提交订单", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/express-delivery/express-delivery", "path": "pages/express-delivery/express-delivery", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "物流查询", "navigationBarTitleText": "物流查询", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/pay-result/pay-result", "path": "pages/pay-result/pay-result", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "支付结果", "navigationBarTitleText": "支付结果", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/search-prod-show/search-prod-show", "path": "pages/search-prod-show/search-prod-show", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "搜索结果", "navigationBarTitleText": "搜索结果", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
} }
}, },
{ {
"path": "pages/prod/prod", "path": "pages/prod/prod", //
"style": { "style": {
"navigationBarTitleText": "商品详情" "navigationBarTitleText": "商品详情" //
} }
}, },
{ {
"path": "pages/prod-classify/prod-classify", "path": "pages/prod-classify/prod-classify", //
"style": { "style": {
"onReachBottomDistance": 0 "onReachBottomDistance": 0 // 0
} }
}, },
{ {
"path": "pages/recent-news/recent-news", "path": "pages/recent-news/recent-news", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarTitleText": "最新公告", "navigationBarTitleText": "最新公告", //
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black", //
"navigationBarBackgroundColor": "#fafafa" "navigationBarBackgroundColor": "#fafafa" //
} }
}, },
{ {
"path": "pages/news-detail/news-detail", "path": "pages/news-detail/news-detail", //
"style": { "style": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarTitleText": "最新公告", "navigationBarTitleText": "最新公告", //
"navigationBarTextStyle": "black", "navigationBarTextStyle": "black", //
"navigationBarBackgroundColor": "#fafafa" "navigationBarBackgroundColor": "#fafafa" //
} }
}, },
{ {
"path": "pages/accountLogin/accountLogin" "path": "pages/accountLogin/accountLogin" //
}, },
{ {
"path": "pages/register/register" "path": "pages/register/register" //
} }
], ],
"tabBar": { "tabBar": {
"selectedColor": "#3a86b9", "selectedColor": "#3a86b9", //
"color": "#b8b8b8", "color": "#b8b8b8", //
"list": [ "list": [
{ {
"pagePath": "pages/index/index", "pagePath": "pages/index/index", //
"text": "首页", "text": "首页", //
"iconPath": "/static/images/tabbar/homepage.png", "iconPath": "/static/images/tabbar/homepage.png", //
"selectedIconPath": "/static/images/tabbar/homepage-sel.png" "selectedIconPath": "/static/images/tabbar/homepage-sel.png" //
}, },
{ {
"pagePath": "pages/category/category", "pagePath": "pages/category/category", //
"text": "分类", "text": "分类", //
"iconPath": "/static/images/tabbar/category.png", "iconPath": "/static/images/tabbar/category.png", //
"selectedIconPath": "/static/images/tabbar/category-sel.png" "selectedIconPath": "/static/images/tabbar/category-sel.png" //
}, },
{ {
"pagePath": "pages/basket/basket", "pagePath": "pages/basket/basket", //
"text": "购物车", "text": "购物车", //
"iconPath": "/static/images/tabbar/basket.png", "iconPath": "/static/images/tabbar/basket.png", //
"selectedIconPath": "/static/images/tabbar/basket-sel.png" "selectedIconPath": "/static/images/tabbar/basket-sel.png" //
}, },
{ {
"pagePath": "pages/user/user", "pagePath": "pages/user/user", //
"text": "我的", "text": "我的", //
"iconPath": "/static/images/tabbar/user.png", "iconPath": "/static/images/tabbar/user.png", //
"selectedIconPath": "/static/images/tabbar/user-sel.png" "selectedIconPath": "/static/images/tabbar/user-sel.png" //
} }
] ]
}, },
"sitemapLocation": "sitemap.json",
"sitemapLocation": "sitemap.json", //
"globalStyle": { "globalStyle": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light", // "light"
"navigationBarBackgroundColor": "#fff", "navigationBarBackgroundColor": "#fff", //
"navigationBarTitleText": "WeChat", "navigationBarTitleText": "WeChat", //
"navigationBarTextStyle": "black" "navigationBarTextStyle": "black" //
}, },
"subPackages": []
"subPackages": [] //
} }

@ -3,102 +3,108 @@
import loginMethods from './login' import loginMethods from './login'
const http = { const http = {
/**
* 发起HTTP请求
* @param {Object} params - 请求参数对象包含urldatamethod等
* @returns {Promise} - 返回一个Promise对象解析或拒绝根据请求结果
*/
request: async function (params) { request: async function (params) {
// 请求参数处理 // 处理请求数据类型,确保数组和数字被正确序列化为字符串
if (Object.prototype.toString.call(params.data) === '[object Array]') { if (Object.prototype.toString.call(params.data) === '[object Array]') {
params.data = JSON.stringify(params.data) params.data = JSON.stringify(params.data)
} else if (Object.prototype.toString.call(params.data) === '[object Number]') { } else if (Object.prototype.toString.call(params.data) === '[object Number]') {
params.data = params.data + '' params.data = params.data + ''
} }
// 刷新token // 如果不是登录请求且应用未完全启动即未完成首次加载并且不是刷新token的请求则尝试刷新token
if (!params.login && !getApp()?.globalData.isLanding && !params.isRefreshing) { if (!params.login && !getApp()?.globalData.isLanding && !params.isRefreshing) {
await loginMethods.refreshToken() await loginMethods.refreshToken()
} }
// 发起请求
// 发起请求并返回Promise对象处理异步操作
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
dataType: 'json', dataType: 'json',
responseType: params.responseType === undefined ? 'text' : params.responseType, responseType: params.responseType === undefined ? 'text' : params.responseType,
header: { header: {
Authorization: uni.getStorageSync('Token') Authorization: uni.getStorageSync('Token') // 设置请求头中的Authorization字段
}, },
url: (params.domain ? params.domain : import.meta.env.VITE_APP_BASE_API) + params.url, url: (params.domain ? params.domain : import.meta.env.VITE_APP_BASE_API) + params.url, // 拼接完整的请求URL
data: params.data, data: params.data, // 请求体数据
method: params.method === undefined ? 'POST' : params.method, method: params.method === undefined ? 'POST' : params.method, // 默认请求方法为POST
success: (res) => { success: (res) => {
const responseData = res.data const responseData = res.data
// 请求小程序码 // 特殊处理小程序码请求
if (params.responseType === 'arraybuffer' && res.statusCode === 200) { if (params.responseType === 'arraybuffer' && res.statusCode === 200) {
return resolve(responseData) return resolve(responseData)
} }
// 00000 请求成功 // 根据响应码处理不同情况
// A00002 用于直接显示提示系统的成功,内容由输入决定 switch (responseData.code) {
if (responseData.code === '00000' || responseData.code === 'A00002') { case '00000': // 请求成功
resolve(responseData) case 'A00002': // 系统成功的提示信息
} resolve(responseData)
// A00004 未授权 break;
if (responseData.code === 'A00004') { case 'A00004': // 未授权
// 重设登录后跳转地址 // 重设登录后跳转地址,并清除相关存储
loginMethods.setRouteUrlAfterLogin() loginMethods.setRouteUrlAfterLogin()
uni.removeStorageSync('expiresTimeStamp') uni.removeStorageSync('expiresTimeStamp')
uni.removeStorageSync('loginResult') uni.removeStorageSync('loginResult')
uni.removeStorageSync('Token') uni.removeStorageSync('Token')
if (!params.dontTrunLogin) {
uni.showModal({ // 如果允许转向登录页面,则显示模态框提示用户重新登录
title: '提示', if (!params.dontTrunLogin) {
content: uni.getStorageSync('hadLogin') ? '登录已过期,请重新登陆!' : '请先进行登录!', uni.showModal({
cancelText: '取消', title: '提示',
confirmText: '确定', content: uni.getStorageSync('hadLogin') ? '登录已过期,请重新登陆!' : '请先进行登录!',
success: res => { cancelText: '取消',
if (res.confirm) { confirmText: '确定',
uni.navigateTo({ success: res => {
url: '/pages/accountLogin/accountLogin' if (res.confirm) {
}) uni.navigateTo({
} else { url: '/pages/accountLogin/accountLogin'
const router = getCurrentPages()
if (router[0].route === 'pages/basket/basket') {
uni.switchTab({
url: '/pages/index/index'
}) })
} else {
const router = getCurrentPages()
if (router[0].route === 'pages/basket/basket') {
uni.switchTab({
url: '/pages/index/index'
})
}
} }
} }
} })
}) }
} resolve(responseData)
resolve(responseData) break;
} case 'A00005': // 服务器错误
this.onRequestFail(params, responseData)
// A00005 服务器出了点小差
if (responseData.code === 'A00005') {
this.onRequestFail(params, responseData)
uni.showToast({
title: '服务器出了点小差~',
icon: 'none'
})
}
// 其他异常码
// A00001 用于直接显示提示用户的错误,内容由输入内容决定
// A04001 社交账号未绑定
// A00012 tempUid错误
// A00006 验证码错误
if (responseData.code === 'A04001' || responseData.code === 'A00001' || responseData.code === 'A00012' || responseData.code === 'A00006') {
if (!params.hasCatch) {
uni.showToast({ uni.showToast({
title: responseData.msg || responseData.data || 'Error', title: '服务器出了点小差~',
icon: 'none' icon: 'none'
}) })
} break;
} case 'A04001': // 社交账号未绑定
case 'A00001': // 直接显示提示用户的错误
if (responseData.code !== '00000') { case 'A00012': // tempUid错误
reject(responseData) case 'A00006': // 验证码错误
if (!params.hasCatch) {
uni.showToast({
title: responseData.msg || responseData.data || 'Error',
icon: 'none'
})
}
reject(responseData)
break;
default:
if (responseData.code !== '00000') {
reject(responseData)
}
} }
}, },
fail: (err) => { fail: (err) => {
// 请求失败时显示提示并拒绝Promise
uni.showToast({ uni.showToast({
title: '请求失败' title: '请求失败'
}) })
@ -107,56 +113,70 @@ const http = {
}) })
}) })
}, },
/**
* 获取购物车商品数量并更新tabBar徽章
*/
getCartCount: () => { getCartCount: () => {
if (!uni.getStorageSync('Token')) { if (!uni.getStorageSync('Token')) {
util.removeTabBadge() util.removeTabBadge() // 如果没有token移除购物车徽章
return return
} }
http.request({ http.request({
url: '/p/shopCart/prodCount', url: '/p/shopCart/prodCount',
method: 'GET', method: 'GET',
dontTrunLogin: true, dontTrunLogin: true, // 不需要转向登录
data: {} data: {}
}) })
.then(({ data }) => { .then(({ data }) => {
if (data > 0) { if (data > 0) {
uni.setTabBarBadge({ uni.setTabBarBadge({
index: 2, index: 2, // 假设购物车位于第三个tab
text: data + '' text: data + '' // 显示商品数量
}) })
getApp().globalData.totalCartCount = data getApp().globalData.totalCartCount = data // 更新全局购物车数量
} else { } else {
uni.removeTabBarBadge({ uni.removeTabBarBadge({
index: 2 index: 2 // 移除购物车徽章
}) })
getApp().globalData.totalCartCount = 0 getApp().globalData.totalCartCount = 0
} }
}) })
}, },
/**
* 请求失败时的日志记录
* @param {Object} params - 请求参数
* @param {Object} responseData - 响应数据
*/
onRequestFail: (params, responseData) => { onRequestFail: (params, responseData) => {
console.error('============== 请求异常 ==============') console.error('============== 请求异常 ==============')
console.log('接口地址: ', params.url) console.log('接口地址: ', params.url)
console.log('异常信息: ', responseData) console.log('异常信息: ', responseData)
console.error('============== 请求异常 end ==========') console.error('============== 请求异常 end ==========')
}, },
/** /**
* 登录成功后执行 * 登录成功后的处理逻辑
* @param {Object} result 登录成功返回的数据 * @param {Object} result - 登录成功返回的数据
* @param {Object} fn 登录成功后的回调 * @param {Function} fn - 登录成功后的回调函数
*/ */
loginSuccess: (result, fn) => { loginSuccess: (result, fn) => {
// 保存登陆信息 // 保存登录信息到本地存储
wx.setStorageSync('loginResult', result) wx.setStorageSync('loginResult', result)
// 保存成功登录标识,token过期判断 // 保存成功登录标识用于判断token是否过期
wx.setStorageSync('hadLogin', true) wx.setStorageSync('hadLogin', true)
const expiresTimeStamp = result.expiresIn * 1000 / 2 + new Date().getTime() const expiresTimeStamp = result.expiresIn * 1000 / 2 + new Date().getTime() // 计算token过期时间
// 缓存token的过期时间 // 缓存token的过期时间
uni.setStorageSync('expiresTimeStamp', expiresTimeStamp) uni.setStorageSync('expiresTimeStamp', expiresTimeStamp)
wx.setStorageSync('Token', result.accessToken) // 把token存入缓存请求接口数据时要用 // 将accessToken保存到本地存储以便后续请求使用
wx.setStorageSync('Token', result.accessToken)
// 执行登录成功后的回调函数
if (fn) { if (fn) {
fn() fn()
} }
} }
} }
export default http export default http

@ -1,37 +1,58 @@
const loginMethods = { const loginMethods = {
/** /**
* 刷新token * 刷新token
* 当用户的Token即将过期时自动发起请求以获取新的Token
* 这个过程会检查当前Token是否有效以及是否正在进行刷新操作以避免重复请求
*/ */
refreshToken: () => { refreshToken: () => {
// 从本地存储中获取Token的过期时间戳
const expiresTimeStamp = uni.getStorageSync('expiresTimeStamp') const expiresTimeStamp = uni.getStorageSync('expiresTimeStamp')
// 如果没有有效的Token或过期时间戳则直接返回不进行刷新
if (!uni.getStorageSync('Token') || !expiresTimeStamp) return if (!uni.getStorageSync('Token') || !expiresTimeStamp) return
// 检查Token是否已经过期
const isExpires = expiresTimeStamp < new Date().getTime() const isExpires = expiresTimeStamp < new Date().getTime()
// 检查是否已经有刷新Token的操作正在进行
const isRefreshing = uni.getStorageSync('isRefreshingToken') const isRefreshing = uni.getStorageSync('isRefreshingToken')
// 如果Token未过期或已有刷新操作正在进行则直接返回
if (!isExpires || isRefreshing) { if (!isExpires || isRefreshing) {
return return
} }
// 设置标志位表示正在刷新Token防止并发刷新
uni.setStorageSync('isRefreshingToken', true) uni.setStorageSync('isRefreshingToken', true)
// 发起刷新Token的请求
http.request({ http.request({
url: '/token/refresh', url: '/token/refresh', // 刷新Token的API接口
method: 'POST', method: 'POST', // 使用POST方法发送请求
login: true, login: true, // 标记这是一个与登录相关的请求
isRefreshing: true, isRefreshing: true, // 标记这是刷新Token的请求
dontTrunLogin: true dontTrunLogin: true // 即使刷新失败也不跳转到登录页面
}).then(res => { }).then(res => {
// 刷新成功后更新本地存储中的Token过期时间
uni.setStorageSync('isRefreshingToken', false) uni.setStorageSync('isRefreshingToken', false)
uni.setStorageSync('expiresTimeStamp', res.data * 1000 / 2 + new Date().getTime()) uni.setStorageSync('expiresTimeStamp', res.data * 1000 / 2 + new Date().getTime())
}).catch(() => { }).catch(() => {
// 刷新失败后,重置标志位
uni.setStorageSync('isRefreshingToken', false) uni.setStorageSync('isRefreshingToken', false)
}) })
}, },
/** /**
* 设置登录后的跳转地址 * 设置登录后的跳转地址
* 在用户登录之前记录当前页面的路径以便在登录成功后能够返回到该页面
*/ */
setRouteUrlAfterLogin: () => { setRouteUrlAfterLogin: () => {
// 获取当前所有页面的栈
const pages = getCurrentPages() const pages = getCurrentPages()
// 登录后的回跳地址
// 确保当前页面不是登录页面(避免循环跳转)
if (pages[pages.length - 1].route.indexOf('user-login') === -1) { if (pages[pages.length - 1].route.indexOf('user-login') === -1) {
// 记录当前页面的完整路径,用于登录成功后的跳转
uni.setStorageSync('routeUrlAfterLogin', pages[pages.length - 1].$page.fullPath) uni.setStorageSync('routeUrlAfterLogin', pages[pages.length - 1].$page.fullPath)
} }
} }

@ -1,34 +1,71 @@
const util = { const util = {
/**
* 格式化日期时间
* 将传入的Date对象格式化为"YYYY/MM/DD HH:MM:SS"的字符串形式
* @param {Date} date - 要格式化的日期对象
* @returns {String} - 格式化后的日期时间字符串
*/
formatTime: date => { formatTime: date => {
const year = date.getFullYear() const year = date.getFullYear() // 获取年份
const month = date.getMonth() + 1 const month = date.getMonth() + 1 // 获取月份注意getMonth()返回的是0-11所以需要加1
const day = date.getDate() const day = date.getDate() // 获取日期
const hour = date.getHours() const hour = date.getHours() // 获取小时
const minute = date.getMinutes() const minute = date.getMinutes() // 获取分钟
const second = date.getSeconds() const second = date.getSeconds() // 获取秒
// 使用formatNumber方法确保所有时间部分都是两位数并用'/'连接日期部分,':'连接时间部分
return [year, month, day].map(util.formatNumber).join('/') + ' ' + [hour, minute, second].map(util.formatNumber).join(':') return [year, month, day].map(util.formatNumber).join('/') + ' ' + [hour, minute, second].map(util.formatNumber).join(':')
}, },
/**
* 格式化数字
* 确保传入的数字是两位数如果不是则在前面补零
* @param {Number|String} n - 需要格式化的数字
* @returns {String} - 格式化后的两位数字符串
*/
formatNumber: n => { formatNumber: n => {
n = n.toString() n = n.toString() // 将数字转换为字符串
return n[1] ? n : '0' + n return n[1] ? n : '0' + n // 如果长度大于1则直接返回否则在前面补零
}, },
/**
* 格式化HTML内容
* 对传入的HTML字符串进行样式调整以适应移动端显示特别是处理图片表格等内容的宽度和布局
* @param {String} content - 需要格式化的HTML字符串
* @returns {String} - 格式化后的HTML字符串
*/
formatHtml: content => { formatHtml: content => {
if (!content) { if (!content) {
return return // 如果没有内容,直接返回
} }
// 替换<p>标签,设置最大宽度、单词换行等样式
content = content.replace(/<p/gi, '<p style="max-width:100% !important;word-wrap:break-word;word-break:break-word;" ') content = content.replace(/<p/gi, '<p style="max-width:100% !important;word-wrap:break-word;word-break:break-word;" ')
// 替换<img>标签,设置最大宽度、高度自适应、边距等样式
content = content.replace(/<img/gi, '<img style="max-width:100% !important;height:auto !important;margin:0;display:flex;" ') content = content.replace(/<img/gi, '<img style="max-width:100% !important;height:auto !important;margin:0;display:flex;" ')
// 替换<style>标签中的样式,确保内部样式不会覆盖外部样式
content = content.replace(/style="/gi, 'style="max-width:100% !important;table-layout:fixed;word-wrap:break-word;word-break:break-word;') content = content.replace(/style="/gi, 'style="max-width:100% !important;table-layout:fixed;word-wrap:break-word;word-break:break-word;')
// 替换<table>标签,设置表格布局和单词换行等样式
content = content.replace(/<table/gi, '<table style="table-layout:fixed;word-wrap:break-word;word-break:break-word;" ') content = content.replace(/<table/gi, '<table style="table-layout:fixed;word-wrap:break-word;word-break:break-word;" ')
// 替换<td>标签,设置单元格间距、填充、边框等样式
content = content.replace(/<td/gi, '<td cellspacing="0" cellpadding="0" style="border-width:1px; border-style:solid; border-color:#666; margin: 0px; padding: 0px;"') content = content.replace(/<td/gi, '<td cellspacing="0" cellpadding="0" style="border-width:1px; border-style:solid; border-color:#666; margin: 0px; padding: 0px;"')
// 移除width和height属性防止图片和表格固定宽度或高度
content = content.replace(/width=/gi, 'sss=') content = content.replace(/width=/gi, 'sss=')
content = content.replace(/height=/gi, 'sss=') content = content.replace(/height=/gi, 'sss=')
// 确保自闭合标签如<img>有正确的样式
content = content.replace(/\/>/gi, ' style="max-width:100% !important;height:auto !important;margin:0;display:block;" />') content = content.replace(/\/>/gi, ' style="max-width:100% !important;height:auto !important;margin:0;display:block;" />')
return content
},
return content // 返回格式化后的HTML字符串
}
}
export default util
/** /**
* 移除购物车Tabbar的数字 * 移除购物车Tabbar的数字
*/ */

Loading…
Cancel
Save