feat: 新增发布额度权益与订单管理功能,优化多端交互细节
这个提交包含在:
@@ -3,7 +3,7 @@
|
||||
* 对应契约 §2.1:POST /order/recharge {amount,payType} → {orderNo,amount,status,payType}
|
||||
* 说明:与后端 application/api/controller/Order.php 不是同一文件,仅为前端封装。
|
||||
*/
|
||||
import { post } from '../utils/request.js'
|
||||
import { get, post } from '../utils/request.js'
|
||||
|
||||
export const orderApi = {
|
||||
/**
|
||||
@@ -12,6 +12,18 @@ export const orderApi = {
|
||||
* 服务端禁止 payType='balance'(用余额给余额加钱会凭空增发余额,属资损)。
|
||||
*/
|
||||
recharge: (payload = {}) => post('/order/recharge', payload, { silent: true }),
|
||||
|
||||
/**
|
||||
* 订单详情
|
||||
* @param {Object} params {orderNo: string, id?: number}
|
||||
*/
|
||||
detail: (params = {}) => get('/order/detail', params, { silent: true }),
|
||||
|
||||
/**
|
||||
* 主动取消待支付订单
|
||||
* @param {Object} payload {orderNo: string, id?: number}
|
||||
*/
|
||||
cancel: (payload = {}) => post('/order/cancel', payload, { silent: true }),
|
||||
}
|
||||
|
||||
export default orderApi
|
||||
|
||||
@@ -65,6 +65,8 @@ export const postApi = {
|
||||
payView: (id, payload) => post(`/post/${id}/pay-view`, payload, { silent: true }),
|
||||
/** 发表评价(评分 + 图文) */
|
||||
comment: (id, payload) => post(`/post/${id}/comment`, payload, { silent: true }),
|
||||
/** 发布者回复评价 */
|
||||
replyComment: (commentId, payload) => post(`/post/comment/${commentId}/reply`, payload, { silent: true }),
|
||||
/** 评价列表(详情页「用户评价」,替代前端写死的假评价) */
|
||||
comments: (id) => get(`/post/${id}/comments`, {}, { silent: true }),
|
||||
}
|
||||
|
||||
@@ -102,6 +102,7 @@ export const ICON_GROUPS = [
|
||||
{ key: 'mine-draft', name: '草稿箱', file: 'mine-draft.png' },
|
||||
{ key: 'mine-history', name: '搜索记录', file: 'mine-history.png' },
|
||||
{ key: 'mine-setting', name: '系统设置', file: 'mine-setting.png' },
|
||||
{ key: 'mine-service', name: '联系客服', file: 'mine-service.png' },
|
||||
{ key: 'mine-about', name: '关于我们', file: 'mine-about.png' },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -6,22 +6,56 @@
|
||||
* - HBuilderX「发行/打包」→ NODE_ENV=production → prod:远程正式后端
|
||||
*/
|
||||
|
||||
// 编译期常量;发行包会摇树消除 dev 分支,不会把本地地址打进正式包
|
||||
const ENV =
|
||||
(typeof process !== 'undefined' && process.env && process.env.NODE_ENV) ||
|
||||
'development'
|
||||
const IS_DEV = ENV !== 'production'
|
||||
/**
|
||||
* 检测当前运行环境是否为生产环境(prod)
|
||||
*
|
||||
* 解决 HBuilderX 发行小程序时后台地址未生效的问题:
|
||||
* 1. 编译期静态宏替换:
|
||||
* 在 HBuilderX 发行/构建时,构建工具(Vite/Webpack)会直接将 `process.env.NODE_ENV` 宏替换为 `"production"`。
|
||||
* 千万不能在外部包裹 `typeof process !== 'undefined'`,否则编译后保留该判断,
|
||||
* 而在微信小程序运行时环境中全局没有 process 对象,导致判断为 false 误回退为开发环境。
|
||||
* 2. 微信小程序运行态兜底:
|
||||
* 通过 uni.getAccountInfoSync 读取小程序 envVersion,体验版(trial)和正式版(release)均自动切换为生产接口。
|
||||
*
|
||||
* @returns {boolean} 是否为生产环境
|
||||
*/
|
||||
function detectIsProduction() {
|
||||
// 1. 编译期宏替换判断(发行模式下 process.env.NODE_ENV 在打包时会被替换为 'production')
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
return true
|
||||
}
|
||||
|
||||
// 2. 微信小程序运行期环境版本兜底判断
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
const accountInfo = typeof uni !== 'undefined' && uni.getAccountInfoSync && uni.getAccountInfoSync()
|
||||
const envVersion = accountInfo && accountInfo.miniProgram && accountInfo.miniProgram.envVersion
|
||||
if (envVersion === 'release' || envVersion === 'trial') {
|
||||
return true
|
||||
}
|
||||
} catch (e) {
|
||||
// 忽略异常,降级处理
|
||||
}
|
||||
// #endif
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// 生产环境标识
|
||||
const IS_PROD = detectIsProduction()
|
||||
const IS_DEV = !IS_PROD
|
||||
const ENV = IS_PROD ? 'production' : 'development'
|
||||
|
||||
// 各环境后端域名(dev=运行 / prod=发行)
|
||||
const HOSTS = {
|
||||
dev: 'http://192.168.2.61:9980', // 本地后端(phpstudy 虚拟域名与端口 9980)
|
||||
dev: 'https://308dfc36.r9.cpolar.cn', // 本地后端(phpstudy 虚拟域名与端口 9980)
|
||||
prod: 'https://fenleixinxi.gzyakj.com.cn', // 远程正式后端
|
||||
}
|
||||
// 接口统一前缀
|
||||
const API_PREFIX = '/api'
|
||||
|
||||
// 网关 = 域名 + /api(版本号由下方 apiVersion 拼接)
|
||||
const BASE_URL = HOSTS[IS_DEV ? 'dev' : 'prod'] + API_PREFIX
|
||||
const BASE_URL = (IS_PROD ? HOSTS.prod : HOSTS.dev) + API_PREFIX
|
||||
|
||||
export const config = {
|
||||
// 当前环境:'development'(HBuilderX 运行)| 'production'(发行)
|
||||
|
||||
@@ -24,13 +24,14 @@ export const WITHDRAW_TEXT = {
|
||||
}
|
||||
|
||||
/** 订单类型 */
|
||||
export const ORDER_TYPE_TEXT = { post: '发布订单', member: '会员订单', recharge: '充值订单' }
|
||||
export const ORDER_TYPE_TEXT = { post: '发布订单', member: '会员订单', recharge: '充值订单', payview: '付费查看' }
|
||||
|
||||
/** 订单类型 -> 图标 key */
|
||||
export const ORDER_ICON_KEY = {
|
||||
post: 'order-post',
|
||||
member: 'order-member',
|
||||
recharge: 'order-recharge',
|
||||
payview: 'order-other',
|
||||
}
|
||||
|
||||
/** 资金流水类型 */
|
||||
|
||||
@@ -188,7 +188,7 @@ export const datasets = {
|
||||
freeView: 20, // 每日免费查看联系方式条数
|
||||
postDiscount: '8 折',
|
||||
distRate: '一级 20% / 二级 10%',
|
||||
benefits: ['每日免费查看 20 条联系方式', '发布信息 8 折', '专属会员标识', '分销佣金加速结算'],
|
||||
benefits: ['每日免费查看 20 条联系方式', '发布信息 8 折', '专属会员标识', '赠送大量发布额度'],
|
||||
},
|
||||
|
||||
/** 我的资产(coupons / couponCount 由 /member/assets 从 fc_user_coupon 实时聚合) */
|
||||
|
||||
2087
uniapp/common/utils/qrcode-generator.js
普通文件
2087
uniapp/common/utils/qrcode-generator.js
普通文件
文件差异内容过多而无法显示
加载差异
@@ -12,7 +12,13 @@ import config from '../config/index.js'
|
||||
import storage from './storage.js'
|
||||
import { matchMock } from '../mock/index.js'
|
||||
|
||||
// 便于测试注入的运行时环境(默认使用全局 uni)
|
||||
// 401 跳转节流标记(毫秒)
|
||||
let lastLoginRedirectAt = 0
|
||||
|
||||
/**
|
||||
* 便于测试注入的运行时环境(默认使用全局 uni)
|
||||
* @returns {Object} 运行时环境对象
|
||||
*/
|
||||
export function getRuntime() {
|
||||
return {
|
||||
request: typeof uni !== 'undefined' && uni.request ? uni.request.bind(uni) : null,
|
||||
@@ -23,14 +29,23 @@ export function getRuntime() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 拼接完整地址 */
|
||||
/**
|
||||
* 拼接完整地址
|
||||
* @param {string} url 原始相对或绝对路径
|
||||
* @returns {string} 完整网络请求地址
|
||||
*/
|
||||
export function buildUrl(url) {
|
||||
if (/^https?:\/\//i.test(url)) return url
|
||||
const path = url.startsWith('/') ? url : `/${url}`
|
||||
return `${config.baseURL}/${config.apiVersion}${path}`
|
||||
}
|
||||
|
||||
/** 组装请求头 */
|
||||
/**
|
||||
* 组装请求头
|
||||
* 同时注入 Authorization、token、X-Token,确保在任何 Nginx/Apache 代理环境下 token 都能安全穿透到后端
|
||||
* @param {Object} extra 额外的自定义请求头
|
||||
* @returns {Object} 组装后的完整 Headers
|
||||
*/
|
||||
export function buildHeaders(extra = {}) {
|
||||
const token = storage.get(config.storageKeys.token, '')
|
||||
const headers = {
|
||||
@@ -38,14 +53,17 @@ export function buildHeaders(extra = {}) {
|
||||
'X-Client': 'fenleixinxi',
|
||||
...extra,
|
||||
}
|
||||
if (token) headers.Authorization = `Bearer ${token}`
|
||||
if (token) {
|
||||
// 1. 标准 HTTP Bearer Token
|
||||
headers.Authorization = `Bearer ${token}`
|
||||
// 2. 兼容 FastAdmin 原生与 Nginx/Apache 反向代理(部分反向代理会丢弃 Authorization,但保留常规 Header)
|
||||
headers.token = token
|
||||
headers.Token = token
|
||||
headers['X-Token'] = token
|
||||
}
|
||||
return headers
|
||||
}
|
||||
|
||||
/**
|
||||
* 底层请求(返回 Promise<data>)
|
||||
* @param {Object} options { url, method, data, header, silent, mock }
|
||||
*/
|
||||
/**
|
||||
* 清理请求参数中 undefined / null / 空串 的无效字段
|
||||
* 防止在微信小程序等环境下 GET 请求被底层错误序列化为 "key=undefined"
|
||||
@@ -64,6 +82,11 @@ export function cleanParams(data) {
|
||||
return cleaned
|
||||
}
|
||||
|
||||
/**
|
||||
* 底层请求统一封装(返回 Promise<data>)
|
||||
* @param {Object} options 请求配置 { url, method, data, header, silent, mock }
|
||||
* @returns {Promise<any>} 请求结果
|
||||
*/
|
||||
export function request(options = {}) {
|
||||
const {
|
||||
url,
|
||||
@@ -95,7 +118,7 @@ export function request(options = {}) {
|
||||
header: headers,
|
||||
timeout: config.timeout,
|
||||
success(res) {
|
||||
// HTTP 层
|
||||
// HTTP 层 401 判定
|
||||
if (res.statusCode === 401) {
|
||||
onUnauthorized(runtime)
|
||||
return reject(toErr('登录已过期,请重新登录', 401))
|
||||
@@ -107,6 +130,11 @@ export function request(options = {}) {
|
||||
)
|
||||
}
|
||||
const body = res.data || {}
|
||||
// 业务层 401 判定
|
||||
if (body.code === 401) {
|
||||
onUnauthorized(runtime)
|
||||
return reject(toErr(body.message || body.msg || '登录已过期,请重新登录', 401))
|
||||
}
|
||||
// 业务层:约定 code===0 或 code===200 为成功
|
||||
if (body.code === 0 || body.code === 200) {
|
||||
resolve(body.data !== undefined ? body.data : body)
|
||||
@@ -127,6 +155,8 @@ export function request(options = {}) {
|
||||
* 失败处理:
|
||||
* 1) 若开启 mock 降级,则使用本地 mock 路由兜底(保证离线可演示)
|
||||
* 2) 否则抛出异常
|
||||
* @param {Object} err 错误对象
|
||||
* @param {Object} ctx 请求上下文
|
||||
*/
|
||||
function handleFail(err, ctx) {
|
||||
const { url, method, data, silent, runtime, resolve, reject } = ctx
|
||||
@@ -146,14 +176,42 @@ function handleFail(err, ctx) {
|
||||
reject(e)
|
||||
}
|
||||
|
||||
/** 401 处理 */
|
||||
/**
|
||||
* 401 未登录/登录失效统一处理
|
||||
* 1. 清除本地缓存的 token 与用户信息
|
||||
* 2. 3秒内节流防抖,避免并发请求时多次重复弹窗与重复跳转
|
||||
* 3. 避免当前已经在登录页时重复跳转
|
||||
* 4. 记录来源页面便于登录后无感跳回
|
||||
* @param {Object} runtime 运行时对象
|
||||
*/
|
||||
function onUnauthorized(runtime) {
|
||||
storage.remove(config.storageKeys.token)
|
||||
storage.remove(config.storageKeys.userInfo)
|
||||
runtime.showToast({ title: '登录已过期', icon: 'none' })
|
||||
runtime.navigateTo({ url: '/pages/auth/login' })
|
||||
|
||||
const now = Date.now()
|
||||
if (now - lastLoginRedirectAt < 3000) {
|
||||
return
|
||||
}
|
||||
lastLoginRedirectAt = now
|
||||
|
||||
const pages = (typeof getCurrentPages === 'function' && getCurrentPages()) || []
|
||||
const current = pages[pages.length - 1]
|
||||
const rawRoute = current && (current.route || (current.$page && current.$page.route))
|
||||
const route = typeof rawRoute === 'string' ? rawRoute : ''
|
||||
|
||||
if (!route || !route.includes('pages/auth/login')) {
|
||||
runtime.showToast({ title: '登录已过期', icon: 'none' })
|
||||
const redirectParam = route ? `?redirect=${encodeURIComponent('/' + route)}` : ''
|
||||
runtime.navigateTo({ url: `/pages/auth/login${redirectParam}` })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建标准化 Error 对象
|
||||
* @param {string} message 错误消息
|
||||
* @param {number} code 业务或状态码
|
||||
* @returns {Error}
|
||||
*/
|
||||
function toErr(message, code = -1) {
|
||||
const e = new Error(message)
|
||||
e.code = code
|
||||
|
||||
在新工单中引用
屏蔽一个用户