feat: refactor member to pay-per-use gravity purchase; mv webview to clipboard+browser
- member.vue: rewrite from subscription plans (free/growth/sprint) to H5-only pay-per-use gravity purchase with quantity selector + QR code - user.vue: gravity card replacing quota card, add share/contribute/H5-buy entry points, plus gravity acquisition modal (share/contribute/buy) - share.vue: layout fix (flex column), smarter copyLink with cached URL, WeChat timeline hint instead of open-type - share.controller.ts: add GET /:shareCode redirect route (IP record + 302) - interview.vue: guest mode fix, H5 buy modal, clipboard copy instead of webview for mini-program - App.vue: handleH5UrlParams for ?token=&buy=gravity auto-login - composables/useGravityPurchase.ts: reusable gravity purchase composable - remove webview.vue (no longer used), replace with clipboard+browser flow - AGENTS.md: sync all above changes, fix duplicate numbering
This commit is contained in:
@@ -21,9 +21,10 @@ zhiyin/
|
||||
├── zhiyin-app/ # uni-app 3.x 前端 (H5 + 微信小程序)
|
||||
│ └── src/
|
||||
│ ├── pages/ # 20 个页面 (pages.json 路由)
|
||||
│ ├── composables/ # 可复用组合式函数(如 useGravityPurchase)
|
||||
│ ├── services/api.ts # API 调用封装 (uni.request)
|
||||
│ ├── config.ts # 端点定义 + api() 辅助函数
|
||||
│ └── App.vue # 设计 Token + 全局样式
|
||||
│ └── App.vue # 设计 Token + 全局样式 + H5 URL 参数处理
|
||||
└── docs/ # 产品/架构/部署/路线图文档
|
||||
```
|
||||
|
||||
@@ -96,10 +97,13 @@ zhiyin/
|
||||
- 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY`
|
||||
|
||||
### 支付(微信支付 v3)
|
||||
- Native 支付(H5 扫码): `POST /payment/create`
|
||||
- JSAPI 支付(小程序内): `POST /payment/jsapi`
|
||||
- 支付回调: `POST /payment/notify`(@Public,验签 + 解密 + 自动开会员)
|
||||
- Native 支付(H5 扫码): `POST /payment/create-product`(按量购买引力值)
|
||||
- JSAPI 支付(小程序内): `POST /payment/jsapi-product`(按量购买引力值)
|
||||
- 支付回调: `POST /payment/notify`(@Public,验签 + 解密 + 自动到账)
|
||||
- 支付结果轮询: `GET /payment/check/:outTradeNo`
|
||||
- 产品定价: `GET /member/plans`(含 products 字段,定义引力值单价和赠送量)
|
||||
- 需要微信商户证书文件(通过 postbuild 复制到 dist)
|
||||
- **注意**: 当前会员体系已从按月订阅制改为按量购买引力值制(小程序内复制链接到浏览器打开购买,H5 直接扫码支付)
|
||||
|
||||
---
|
||||
|
||||
@@ -196,7 +200,7 @@ cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
|
||||
|------|------|---------|
|
||||
| Phase 0: 战略升级 | ✅ 完成 | 定价重构(免费 + ¥19.9/月),三层壁垒设计 |
|
||||
| Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) |
|
||||
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(VIP 不再无限次)、管理后台完善、H5 已部署、生产模式已启用 |
|
||||
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(订阅制改为按量购买)、管理后台完善、H5 已部署、生产模式已启用 |
|
||||
| Phase 1.5: 商业化 | 📋 规划 | 引力值运营策略、每日一题定时推送、PMF 验证 |
|
||||
| Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 |
|
||||
| Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 |
|
||||
@@ -258,7 +262,7 @@ VITE_APP_NAME=AI磁场
|
||||
|
||||
- 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证)
|
||||
- 默认分支: `master`
|
||||
- 最新 tag: `v1.0.11`(小程序上传版本号源自 git tag)
|
||||
- 最新 tag: `v1.0.16`(小程序上传版本号源自 git tag)
|
||||
|
||||
---
|
||||
|
||||
@@ -272,10 +276,12 @@ VITE_APP_NAME=AI磁场
|
||||
6. **API 限流**: 100 次/60 秒(在 `app.module.ts` 中配置),注意避免在定时任务和批量操作中被限
|
||||
7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode`
|
||||
8. **MongoDB**: 8 个核心集合 + 2 个分享集合
|
||||
9. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月 250 引力值,冲刺版每月 600 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。
|
||||
9. **引力值体系**: 所有计划统一走引力值消耗(面试 5、优化 3、下载 2)。VIP 不再免额度,成长版每月 250 引力值,冲刺版每月 600 引力值,每日凌晨 2 点定时补给。免费用户注册送 5 引力值。小程序内通过分享得引力值/贡献面经/复制官网链接到浏览器打开购买三种方式获取引力值;H5 直接扫码支付按量购买(¥5/份)。
|
||||
10. **api.ts 陷阱**: 对象字面量必须在 `export const apiService = {` 或 `const apiService = { ... export default apiService` 中包裹,否则 uni-app 构建报错 `Expected ";" but found ":"`。git pull 后经常丢失这行声明,需手动补回
|
||||
11. **H5 构建 assets 清理**: `assets/` 中的旧 hash 文件不能随意删除——`index-*.js`(主 bundle)动态 import 了所有 page chunk,删除仍在引用的文件会导致浏览器 `NS_ERROR_CORRUPTED_CONTENT`
|
||||
11. **管理后台自动验证**: `admin.vue` 中 `onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
|
||||
12. **管理后台自动验证**: `admin.vue` 中 `onMounted` 自动调用 `doVerify()`,进入后台即检测 JWT 中 `role` 是否为 `admin`,不再需要手动点击"验证管理员身份"按钮
|
||||
13. **分享重定向路由**: `share.controller.ts` 中 `GET /api/share/:shareCode` 是公开路由(泛匹配,放最后避免拦截其他路由),访问时记录访问者 IP → 302 重定向到 H5 首页
|
||||
14. **小程序官网购买走剪贴板**: 小程序内"官网购买"不再使用 webview 内嵌 H5,改为 `uni.setClipboardData` 复制带 JWT token 的 URL 到剪贴板,提示用户在手机浏览器中打开购买(`App.vue` 的 `handleH5UrlParams` 解析 `?token=` 和 `?buy=gravity` 参数自动登录跳转)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import { VipExpiryService } from './vip-expiry.service'
|
||||
import { GravityTopUpService } from './gravity-top-up.service'
|
||||
import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema'
|
||||
import { User, UserSchema } from '../user/user.schema'
|
||||
import { PricingService } from '../schemas/pricing.service'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -15,6 +14,6 @@ import { PricingService } from '../schemas/pricing.service'
|
||||
{ name: User.name, schema: UserSchema },
|
||||
]),
|
||||
],
|
||||
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService, PricingService],
|
||||
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService],
|
||||
})
|
||||
export class ScheduleModule {}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { Controller, Get, Post, Body, Param, Query, HttpException, HttpStatus, UseGuards } from '@nestjs/common'
|
||||
import { Controller, Get, Post, Body, Param, Query, HttpException, HttpStatus, UseGuards, Req, Res } from '@nestjs/common'
|
||||
import { Request, Response } from 'express'
|
||||
import { JwtService } from '@nestjs/jwt'
|
||||
import { ShareService } from './share.service'
|
||||
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
|
||||
import { CurrentUser } from '../../common/decorators/current-user.decorator'
|
||||
import { Public } from '../../common/decorators/public.decorator'
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
@Controller('share')
|
||||
export class ShareController {
|
||||
@@ -66,4 +68,27 @@ export class ShareController {
|
||||
) {
|
||||
return this.shareService.visitors(userId, Number(page) || 1, Number(pageSize) || 20)
|
||||
}
|
||||
|
||||
// 泛匹配路由放在最后,避免拦截 stats/records/visitors 等
|
||||
@Public()
|
||||
@Get(':shareCode')
|
||||
async redirect(
|
||||
@Param('shareCode') shareCode: string,
|
||||
@Req() req: Request,
|
||||
@Res() res: Response,
|
||||
) {
|
||||
try {
|
||||
const ip = req.ip || req.socket?.remoteAddress || 'unknown'
|
||||
const visitorId = crypto.createHash('md5').update(ip).digest('hex').slice(0, 16)
|
||||
let visitorUserId: string | undefined
|
||||
const token = req.query.token as string | undefined
|
||||
if (token) {
|
||||
try { const payload = this.jwtService.verify(token) as any; visitorUserId = payload.userId } catch {}
|
||||
}
|
||||
await this.shareService.visit(shareCode, visitorId, visitorUserId)
|
||||
} catch (e) {
|
||||
// 访问记录失败不影响跳转
|
||||
}
|
||||
res.redirect(HttpStatus.FOUND, `https://zhiyin.yzrcloud.cn/?share=${shareCode}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,28 @@ onLaunch(() => {
|
||||
// #ifdef MP-WEIXIN
|
||||
initPrivacy()
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
handleH5UrlParams()
|
||||
// #endif
|
||||
})
|
||||
|
||||
// #ifdef H5
|
||||
function handleH5UrlParams() {
|
||||
const params = new URLSearchParams(window.location.search)
|
||||
const token = params.get('token')
|
||||
const buy = params.get('buy')
|
||||
if (token) {
|
||||
uni.setStorageSync('token', token)
|
||||
}
|
||||
if (buy === 'gravity') {
|
||||
// 延迟等 app 初始化完成再跳转
|
||||
setTimeout(() => {
|
||||
uni.navigateTo({ url: '/pages/member/member' })
|
||||
}, 300)
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
function initPrivacy() {
|
||||
if (wx.onNeedPrivacyAuthorization) {
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import { ref, computed, nextTick } from 'vue'
|
||||
import { api } from '../config'
|
||||
|
||||
export function useGravityPurchase(onPaymentSuccess?: () => void) {
|
||||
const showQuantityModal = ref(false)
|
||||
const buyQuantity = ref(1)
|
||||
const products = ref<any[]>([])
|
||||
const buyProductType = ref('interview')
|
||||
const payLoading = ref(false)
|
||||
const payError = ref('')
|
||||
const showPayModal = ref(false)
|
||||
const payCodeUrl = ref('')
|
||||
const currentOutTradeNo = ref('')
|
||||
const isMp = ref(false)
|
||||
const paySuccess = ref(false)
|
||||
|
||||
const unitPrice = computed(() => {
|
||||
const p = products.value.find(p => p.type === buyProductType.value)
|
||||
return p?.price || 0
|
||||
})
|
||||
const totalPrice = computed(() => unitPrice.value * buyQuantity.value / 100)
|
||||
const buyGravityPerUnit = computed(() => {
|
||||
const p = products.value.find(p => p.type === buyProductType.value)
|
||||
return p?.gravity || 0
|
||||
})
|
||||
|
||||
const changeQty = (delta: number) => {
|
||||
const next = buyQuantity.value + delta
|
||||
if (next >= 1 && next <= 99) buyQuantity.value = next
|
||||
}
|
||||
const clampQty = () => {
|
||||
if (buyQuantity.value < 1) buyQuantity.value = 1
|
||||
if (buyQuantity.value > 99) buyQuantity.value = 99
|
||||
}
|
||||
|
||||
const loadProducts = async () => {
|
||||
try {
|
||||
const res = await uni.request({ url: api('/member/plans'), method: 'GET' })
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) {
|
||||
const prodList: any[] = []
|
||||
for (const [key, val] of Object.entries(res.data.products as Record<string, any>)) {
|
||||
if (val?.price > 0) prodList.push({ type: key, ...val })
|
||||
}
|
||||
products.value = prodList
|
||||
}
|
||||
} catch (e) { /* silent */ }
|
||||
}
|
||||
|
||||
const openGravityPurchase = async (productType = 'interview') => {
|
||||
buyProductType.value = productType
|
||||
buyQuantity.value = 1
|
||||
// #ifdef MP-WEIXIN
|
||||
isMp.value = true
|
||||
// #endif
|
||||
// 加载产品信息
|
||||
await loadProducts()
|
||||
showQuantityModal.value = true
|
||||
}
|
||||
|
||||
const cancelPay = () => {
|
||||
showPayModal.value = false
|
||||
payCodeUrl.value = ''
|
||||
payLoading.value = false
|
||||
payError.value = ''
|
||||
}
|
||||
|
||||
const confirmProductBuy = () => {
|
||||
showQuantityModal.value = false
|
||||
startProductPay(buyProductType.value, buyQuantity.value)
|
||||
}
|
||||
|
||||
const startProductPay = async (type: string, quantity = 1) => {
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
if (!token) {
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
showPayModal.value = true
|
||||
payLoading.value = true
|
||||
payError.value = ''
|
||||
|
||||
if (isMp.value) {
|
||||
try {
|
||||
let res = await uni.request({
|
||||
url: api('/payment/jsapi-product'), method: 'POST',
|
||||
data: { type, quantity },
|
||||
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
timeout: 30000,
|
||||
})
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.payParams) {
|
||||
const pp = res.data.payParams as any
|
||||
currentOutTradeNo.value = res.data.outTradeNo || ''
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: pp.timeStamp,
|
||||
nonceStr: pp.nonceStr,
|
||||
package: pp.package,
|
||||
signType: pp.signType || 'RSA',
|
||||
paySign: pp.paySign,
|
||||
success: () => {
|
||||
const no = currentOutTradeNo.value || res.data.outTradeNo
|
||||
pollPayResult(no)
|
||||
},
|
||||
fail: () => {
|
||||
payError.value = '支付未完成'
|
||||
uni.showToast({ title: '支付未完成', icon: 'none' })
|
||||
},
|
||||
})
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payError.value = '网络连接失败,请检查网络后重试'
|
||||
uni.showToast({ title: '网络连接失败', icon: 'none' })
|
||||
} else {
|
||||
const errMsg = res.data?.message || '购买失败'
|
||||
payError.value = errMsg
|
||||
uni.showToast({ title: errMsg, icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/payment/create-product'), method: 'POST',
|
||||
data: { type, quantity },
|
||||
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
|
||||
payCodeUrl.value = res.data.codeUrl
|
||||
currentOutTradeNo.value = res.data.outTradeNo
|
||||
// 页面需要自己渲染二维码(依赖 uqrcode)
|
||||
pollPayResult(res.data.outTradeNo)
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payError.value = '网络连接失败,请检查网络后重试'
|
||||
uni.showToast({ title: '网络连接失败', icon: 'none' })
|
||||
} else {
|
||||
payError.value = res.data?.message || '购买失败'
|
||||
uni.showToast({ title: res.data?.message || '购买失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const pollPayResult = async (outTradeNo: string) => {
|
||||
if (!outTradeNo) return
|
||||
const maxAttempts = 30
|
||||
let attempts = 0
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
|
||||
const poll = async () => {
|
||||
attempts++
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
|
||||
header: { 'Authorization': `Bearer ${token}` },
|
||||
})
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
|
||||
paySuccess.value = true
|
||||
showPayModal.value = false
|
||||
uni.showToast({ title: '充值成功!', icon: 'success' })
|
||||
onPaymentSuccess?.()
|
||||
return
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
|
||||
if (attempts < maxAttempts) {
|
||||
setTimeout(poll, 2000)
|
||||
} else {
|
||||
payError.value = '支付结果查询超时,请联系客服'
|
||||
uni.showToast({ title: '支付查询超时', icon: 'none' })
|
||||
}
|
||||
}
|
||||
setTimeout(poll, 2000)
|
||||
}
|
||||
|
||||
return {
|
||||
showQuantityModal, buyQuantity, products, buyProductType,
|
||||
unitPrice, totalPrice, buyGravityPerUnit,
|
||||
payLoading, payError, showPayModal, payCodeUrl, paySuccess,
|
||||
isMp,
|
||||
changeQty, clampQty, loadProducts, openGravityPurchase,
|
||||
confirmProductBuy, cancelPay,
|
||||
}
|
||||
}
|
||||
@@ -975,8 +975,8 @@ onMounted(() => { doVerify() })
|
||||
.admin-input { height: 72rpx; background: #FFF; border: 2rpx solid var(--color-border); border-radius: var(--radius-sm); padding: 0 20rpx; font-size: 24rpx; }
|
||||
.btn-verify { height: 72rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; border-radius: var(--radius-sm); font-size: 26rpx; border: none; }
|
||||
.body { padding: 20rpx 32rpx 48rpx; margin-top: -40rpx; }
|
||||
.tabs { display: flex; gap: 8rpx; background: #FFF; border-radius: var(--radius-md); padding: 6rpx; margin-bottom: 20rpx; }
|
||||
.tab { flex: 1; text-align: center; padding: 14rpx; font-size: 24rpx; color: var(--color-text-secondary); border-radius: var(--radius-sm); white-space: nowrap; }
|
||||
.tabs { display: flex; flex-wrap: wrap; gap: 8rpx; background: #FFF; border-radius: var(--radius-md); padding: 6rpx; margin-bottom: 20rpx; }
|
||||
.tab { padding: 14rpx 20rpx; font-size: 24rpx; color: var(--color-text-secondary); border-radius: var(--radius-sm); white-space: nowrap; }
|
||||
.tab.active { background: var(--color-primary); color: #FFF; font-weight: 600; }
|
||||
.stat-cards { display: flex; gap: 16rpx; }
|
||||
.stat-card { flex: 1; background: #FFF; border-radius: var(--radius-lg); padding: 28rpx; text-align: center; box-shadow: var(--shadow-sm); }
|
||||
|
||||
@@ -150,7 +150,7 @@ const doAnalyze = async () => {
|
||||
data: { ...profile },
|
||||
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
if (res.statusCode === 200) {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
if (res.data.error) {
|
||||
error.value = res.data.error
|
||||
return
|
||||
@@ -184,7 +184,7 @@ const doChat = async () => {
|
||||
data: { message: msg, history: chatHistory.value.slice(0, -1) },
|
||||
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
if (res.statusCode === 200) {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
chatHistory.value.push({ role: 'assistant', content: res.data.reply || (res.data.error || '') })
|
||||
} else {
|
||||
chatHistory.value.push({ role: 'assistant', content: '回复失败,请稍后重试' })
|
||||
@@ -211,12 +211,13 @@ const goInterview = (position) => {
|
||||
.hero-title { font-size: 40rpx; font-weight: 700; color: var(--color-text); margin-top: 16rpx; }
|
||||
.hero-desc { font-size: 26rpx; color: var(--color-secondary); margin-top: 8rpx; }
|
||||
|
||||
.form-card { background: #fff; border-radius: var(--radius-lg); padding: 32rpx; box-shadow: var(--shadow-sm); }
|
||||
.form-group { margin-bottom: 28rpx; }
|
||||
.form-card { background: #fff; border-radius: var(--radius-lg); padding: 32rpx; box-shadow: var(--shadow-sm); overflow: hidden; }
|
||||
.form-group { margin-bottom: 28rpx; width: 100%; }
|
||||
.form-group:last-child { margin-bottom: 0; }
|
||||
.form-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 12rpx; }
|
||||
.required { color: var(--color-error); }
|
||||
.form-input { width: 100%; height: 80rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 0 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; }
|
||||
.form-input { width: 100%; height: 80rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 0 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; max-width: 100%; }
|
||||
picker { width: 100%; }
|
||||
.select-trigger { display: flex; align-items: center; }
|
||||
.form-textarea { width: 100%; height: 160rpx; border: 2rpx solid var(--color-border); border-radius: var(--radius-md); padding: 20rpx 24rpx; font-size: 26rpx; color: var(--color-text); box-sizing: border-box; background: #FAFBFC; resize: none; }
|
||||
|
||||
|
||||
@@ -90,28 +90,22 @@
|
||||
|
||||
<view class="complete-bar" v-else>
|
||||
<button class="cta-btn" @click="goResult">查看面试报告</button>
|
||||
<button class="buy-btn" v-if="completedReason === 'noCredits'" @click="showPurchaseModal = true">引力值不足,补充引力值或开通会员 ›</button>
|
||||
<button class="buy-btn" v-if="completedReason === 'noCredits'" @click="goH5Buy">引力值不足,官网购买 ›</button>
|
||||
</view>
|
||||
|
||||
<!-- 购买弹窗(次数不足时) -->
|
||||
<view class="modal-overlay" v-if="showPurchaseModal" @click="showPurchaseModal = false">
|
||||
<!-- 官网购买弹窗 -->
|
||||
<view class="modal-overlay" v-if="showH5BuyModal" @click="showH5BuyModal = false">
|
||||
<view class="modal-content" @click.stop>
|
||||
<text class="modal-title">引力值不足</text>
|
||||
<text class="modal-hint">您的引力值不足,请补充后继续面试(每次面试消耗 5 引力值)</text>
|
||||
<view class="purchase-options">
|
||||
<view class="purchase-option" @click="goBuyProduct">
|
||||
<text class="purchase-name">补充引力值</text>
|
||||
<text class="purchase-price">¥5 起</text>
|
||||
<text class="purchase-desc">¥5 = 5 引力值,可面试 1 次</text>
|
||||
</view>
|
||||
<view class="purchase-option recommended" @click="goBuyMember">
|
||||
<text class="purchase-badge">推荐</text>
|
||||
<text class="purchase-name">开通成长版会员</text>
|
||||
<text class="purchase-price">¥19.9<text class="purchase-unit">/月</text></text>
|
||||
<text class="purchase-desc">每月 250 引力值,解锁全部权益</text>
|
||||
<view class="purchase-option" @click="goH5BuyAndClose">
|
||||
<text class="purchase-name">官网购买引力值</text>
|
||||
<text class="purchase-price">前往网页版充值</text>
|
||||
<text class="purchase-desc">打开官网 H5 页面,支持多种支付方式</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="modal-close" @click="showPurchaseModal = false">取消</text>
|
||||
<text class="modal-close" @click="showH5BuyModal = false">取消</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -122,7 +116,6 @@ import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { api, API_ENDPOINTS } from '../../config'
|
||||
import DigitalHuman from '../../components/digital-human.vue'
|
||||
|
||||
const messages = ref([{ role: 'ai', content: '你好!我是 AI 面试官,请选择岗位开始模拟面试!' }])
|
||||
const inputText = ref('')
|
||||
const aiLoading = ref(false)
|
||||
@@ -134,7 +127,7 @@ const scrollToId = ref('')
|
||||
const position = ref('')
|
||||
const avatarMode = ref(true)
|
||||
const showPositionPicker = ref(false)
|
||||
const showPurchaseModal = ref(false)
|
||||
const showH5BuyModal = ref(false)
|
||||
const positions = ref([])
|
||||
const positionsLoading = ref(false)
|
||||
const aiSpeechText = ref('')
|
||||
@@ -323,8 +316,27 @@ function onAvatarSilent() {
|
||||
}
|
||||
|
||||
const goResult = () => uni.navigateTo({ url: `/pages/report/report?interviewId=${interviewId.value}` })
|
||||
const goBuyProduct = () => uni.navigateTo({ url: '/pages/member/member?buy=interview' })
|
||||
const goBuyMember = () => uni.navigateTo({ url: '/pages/member/member' })
|
||||
|
||||
// 官网购买引力值
|
||||
const goH5Buy = () => {
|
||||
showH5BuyModal.value = true
|
||||
}
|
||||
const goH5BuyAndClose = () => {
|
||||
showH5BuyModal.value = false
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
const url = `https://zhiyin.yzrcloud.cn/?buy=gravity${token ? '&token=' + token : ''}`
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.setClipboardData({
|
||||
data: url,
|
||||
success: () => {
|
||||
uni.showToast({ title: '链接已复制,请在手机浏览器中打开', icon: 'none', duration: 3000 })
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '复制失败,请手动访问 zhiyin.yzrcloud.cn', icon: 'none', duration: 3000 })
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
const scrollToBottom = () => {
|
||||
nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) })
|
||||
}
|
||||
|
||||
@@ -1,584 +1,221 @@
|
||||
<template>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<view class="page fade-in">
|
||||
<view class="placeholder-wrap">
|
||||
<text class="placeholder-icon">✨</text>
|
||||
<text class="placeholder-text">功能已整合到各模块</text>
|
||||
<text class="placeholder-hint">请返回使用引力值充值功能</text>
|
||||
<text class="placeholder-back" @click="goBack">返回首页</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef H5 -->
|
||||
<view class="page fade-in">
|
||||
<view class="hero">
|
||||
<text class="hero-title">会员中心</text>
|
||||
<text class="hero-sub" v-if="isLoggedIn">
|
||||
当前:{{ currentPlanName }}
|
||||
</text>
|
||||
<text class="hero-sub" v-else>选择套餐,解锁全部功能</text>
|
||||
<text class="hero-icon">⚡</text>
|
||||
<text class="hero-title">补充引力值</text>
|
||||
<text class="hero-desc">购买后可获得相应引力值,用于面试、简历优化、下载</text>
|
||||
</view>
|
||||
|
||||
<view class="plans">
|
||||
<!-- 免费版 -->
|
||||
<view class="plan-card free" :class="{ active: plan === 'free' && isLoggedIn }">
|
||||
<view class="plan-header">
|
||||
<text class="plan-name">免费版</text>
|
||||
<view class="plan-price"><text class="price-num">免费</text></view>
|
||||
<view class="product-card">
|
||||
<view class="qty-section">
|
||||
<text class="section-label">购买数量</text>
|
||||
<view class="qty-controls">
|
||||
<text class="qty-btn" :class="{ disabled: buyQty <= 1 }" @click="changeQty(-1)">−</text>
|
||||
<input class="qty-input" type="number" v-model.number="buyQty" min="1" max="99" @blur="clampQty" />
|
||||
<text class="qty-btn" :class="{ disabled: buyQty >= 99 }" @click="changeQty(1)">+</text>
|
||||
</view>
|
||||
<view class="plan-features">
|
||||
<text class="feat" v-for="f in freeFeatures" :key="f">✓ {{ f }}</text>
|
||||
</view>
|
||||
<view class="plan-status" v-if="isLoggedIn && plan === 'free'">当前使用</view>
|
||||
<view class="plan-status hint" v-else-if="!isLoggedIn">注册即用</view>
|
||||
</view>
|
||||
|
||||
<!-- 成长版 -->
|
||||
<view class="plan-card growth recommended" :class="{ active: plan === 'growth' && isLoggedIn }">
|
||||
<view class="plan-badge">⭐ 推荐</view>
|
||||
<view class="plan-header">
|
||||
<text class="plan-name">成长版</text>
|
||||
<text class="plan-price"><text class="price-num">{{ growthPriceText }}</text><text class="price-unit">/月</text></text>
|
||||
<view class="summary">
|
||||
<view class="summary-row">
|
||||
<text class="summary-label">单价</text>
|
||||
<text class="summary-val">¥{{ (unitPrice / 100).toFixed(1) }} / 份</text>
|
||||
</view>
|
||||
<view class="plan-features">
|
||||
<text class="feat" v-for="f in growthFeatures" :key="f">✓ {{ f }}</text>
|
||||
<view class="summary-row">
|
||||
<text class="summary-label">可得引力值</text>
|
||||
<text class="summary-val highlight">{{ buyQty * gravityPerUnit }} 引力值</text>
|
||||
</view>
|
||||
<view class="summary-row total">
|
||||
<text class="summary-label">合计</text>
|
||||
<text class="summary-val total-price">¥{{ (buyQty * unitPrice / 100).toFixed(2) }}</text>
|
||||
</view>
|
||||
<view class="plan-action" v-if="!isLoggedIn" @click="goLogin">登录后开通</view>
|
||||
<view class="plan-action owned" v-else-if="plan !== 'free'">✅ 已开通</view>
|
||||
<view class="plan-action" v-else @click="startPay('growth')">{{ growthPriceText }} 立即开通</view>
|
||||
</view>
|
||||
|
||||
<!-- 冲刺版 -->
|
||||
<view class="plan-card sprint" :class="{ active: plan === 'sprint' && isLoggedIn }">
|
||||
<view class="plan-badge sprint-badge">🚀 冲刺</view>
|
||||
<view class="plan-header">
|
||||
<text class="plan-name">冲刺版</text>
|
||||
<text class="plan-price"><text class="price-num price-sprint">{{ sprintPriceText }}</text><text class="price-unit">/月</text></text>
|
||||
</view>
|
||||
<view class="plan-features">
|
||||
<text class="feat" v-for="f in sprintFeatures" :key="f">✓ {{ f }}</text>
|
||||
</view>
|
||||
<view class="plan-action" v-if="!isLoggedIn" @click="goLogin">登录后开通</view>
|
||||
<view class="plan-action owned" v-else-if="plan === 'sprint'">✅ 已开通</view>
|
||||
<view class="plan-action" v-else-if="plan === 'growth'" @click="startPay('sprint')">升级至冲刺版</view>
|
||||
<view class="plan-action" v-else @click="startPay('sprint')">{{ sprintPriceText }}/月 立即开通</view>
|
||||
</view>
|
||||
<button class="buy-btn" :disabled="payLoading" @click="startPay">
|
||||
<text v-if="!payLoading">立即购买</text>
|
||||
<text v-else>处理中...</text>
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<!-- 支付弹窗 -->
|
||||
<view class="modal-overlay" v-if="showPayModal" @click="cancelPay">
|
||||
<view class="modal-content" @click.stop>
|
||||
<template v-if="payLoading">
|
||||
<text class="modal-title">正在创建支付...</text>
|
||||
<text class="modal-title">正在创建订单...</text>
|
||||
</template>
|
||||
<template v-else-if="!isMp && payCodeUrl">
|
||||
<template v-else-if="payCodeUrl">
|
||||
<text class="modal-title">微信扫码支付</text>
|
||||
<canvas canvas-id="payQrcode" class="qr-canvas"></canvas>
|
||||
<text class="modal-hint">请用微信扫码完成支付</text>
|
||||
<text class="modal-hint">支付成功后将自动跳转</text>
|
||||
<image class="qrcode" :src="'https://api.qrserver.com/v1/create-qr-code/?size=300x300&data=' + encodeURIComponent(payCodeUrl)" mode="widthFix" />
|
||||
<text class="modal-hint">请使用微信扫描二维码完成支付</text>
|
||||
<text class="modal-close" @click="cancelPay">取消支付</text>
|
||||
</template>
|
||||
<template v-else-if="isMp && !payLoading">
|
||||
<text class="modal-title">微信支付</text>
|
||||
<text class="modal-hint">即将调起微信支付...</text>
|
||||
<template v-else-if="paySuccess">
|
||||
<text class="modal-title">✅ 支付成功</text>
|
||||
<text class="modal-hint">引力值已到账,返回继续使用吧</text>
|
||||
<text class="modal-close" @click="cancelPay">关闭</text>
|
||||
</template>
|
||||
<template v-if="payError">
|
||||
<text class="modal-title pay-error">支付异常</text>
|
||||
<template v-else-if="payError">
|
||||
<text class="modal-title pay-error">支付失败</text>
|
||||
<text class="modal-hint">{{ payError }}</text>
|
||||
<text class="modal-close" @click="cancelPay">关闭</text>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 数量选择弹窗(补充引力值) -->
|
||||
<view class="modal-overlay" v-if="showQuantityModal" @click="showQuantityModal = false">
|
||||
<view class="modal-content" @click.stop>
|
||||
<text class="modal-title">补充引力值</text>
|
||||
<text class="modal-hint">购买后将获得相应引力值,可用于面试、优化、下载</text>
|
||||
<view class="qty-selector">
|
||||
<text class="qty-label">购买数量</text>
|
||||
<view class="qty-controls">
|
||||
<text class="qty-btn" :class="{ disabled: buyQuantity <= 1 }" @click="changeQty(-1)">−</text>
|
||||
<input class="qty-input" type="number" v-model.number="buyQuantity" min="1" max="99" @blur="clampQty" />
|
||||
<text class="qty-btn" :class="{ disabled: buyQuantity >= 99 }" @click="changeQty(1)">+</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="qty-summary">
|
||||
<text class="qty-unit-price">单价:¥{{ (unitPrice / 100).toFixed(1) }}</text>
|
||||
<text class="qty-total">获 <text class="qty-total-num">{{ buyQuantity * buyGravityPerUnit }}</text> 引力值</text>
|
||||
</view>
|
||||
<view class="qty-actions">
|
||||
<text class="qty-cancel" @click="showQuantityModal = false">取消</text>
|
||||
<text class="qty-confirm" @click="confirmProductBuy">¥{{ totalPrice.toFixed(1) }} 去支付</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 支付中提示 -->
|
||||
<view class="pay-success" v-if="paySuccess">
|
||||
<text class="success-icon">🎉</text>
|
||||
<text class="success-text">开通成功!{{ payingPlanName }}已生效</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { api } from '../../config'
|
||||
import UQRCode from 'uqrcodejs'
|
||||
|
||||
const isLoggedIn = ref(false)
|
||||
const isMp = ref(false)
|
||||
const plan = ref('free')
|
||||
const currentPlanName = ref('免费版')
|
||||
const paySuccess = ref(false)
|
||||
const goBack = () => uni.switchTab({ url: '/pages/user/user' })
|
||||
|
||||
// #ifdef H5
|
||||
const buyQty = ref(1)
|
||||
const unitPrice = ref(500)
|
||||
const gravityPerUnit = ref(5)
|
||||
const payLoading = ref(false)
|
||||
const showPayModal = ref(false)
|
||||
const payCodeUrl = ref('')
|
||||
const payLoading = ref(false)
|
||||
const paySuccess = ref(false)
|
||||
const payError = ref('')
|
||||
const payingPlanName = ref('')
|
||||
const payingPlan = ref('')
|
||||
const growthPriceText = ref('¥19.9')
|
||||
const sprintPriceText = ref('¥49.9')
|
||||
const currentOutTradeNo = ref('')
|
||||
const freeFeatures = ref(['AI 模拟面试 1 次(注册送 5 引力值)', '基础面试报告', '通用题库随机出题', '简历优化(限 3 次免费)'])
|
||||
const growthFeatures = ref(['免费版全部权益', '每月 250 引力值(约 50 次面试)', '详细面试报告(四维评分)', '进步轨迹雷达图 + 打卡', '每日一题', '参考回答思路', '公司真题库'])
|
||||
const sprintFeatures = ref(['成长版全部权益', '每月 600 引力值(约 120 次面试)', 'AI 语音分析(语气词/语速检测)', '技能缺口分析报告', '公司真题库精选'])
|
||||
const products = ref([])
|
||||
const gravityRates = ref({ interviewPerUse: 5, optimizePerUse: 3, downloadPerUse: 2 })
|
||||
const productPayType = ref('')
|
||||
const showQuantityModal = ref(false)
|
||||
const buyQuantity = ref(1)
|
||||
const buyProductType = ref('')
|
||||
const pendingBuy = ref('')
|
||||
const unitPrice = computed(() => {
|
||||
const p = products.value.find(p => p.type === buyProductType.value)
|
||||
return p?.price || 0
|
||||
})
|
||||
const totalPrice = computed(() => (unitPrice.value * buyQuantity.value) / 100)
|
||||
const buyGravityPerUnit = computed(() => {
|
||||
const p = products.value.find(p => p.type === buyProductType.value)
|
||||
return p?.gravity || 0
|
||||
})
|
||||
|
||||
const token = () => uni.getStorageSync('token') || ''
|
||||
|
||||
const refreshState = async () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
isMp.value = true
|
||||
// #endif
|
||||
|
||||
const t = token()
|
||||
if (!t) {
|
||||
isLoggedIn.value = false
|
||||
return
|
||||
}
|
||||
isLoggedIn.value = true
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const [sres, lres] = await Promise.all([
|
||||
uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } }),
|
||||
uni.request({ url: api('/member/plans'), method: 'GET' }),
|
||||
])
|
||||
if (sres.statusCode >= 200 && sres.statusCode < 300) {
|
||||
const d = sres.data
|
||||
plan.value = d.plan || 'free'
|
||||
currentPlanName.value = d.planName || '免费版'
|
||||
}
|
||||
if (lres.statusCode >= 200 && lres.statusCode < 300 && lres.data) {
|
||||
const plans = Array.isArray(lres.data.plans) ? lres.data.plans : (Array.isArray(lres.data) ? lres.data : [])
|
||||
const growth = plans.find((p) => p.id === 'growth')
|
||||
const sprint = plans.find((p) => p.id === 'sprint')
|
||||
if (growth) {
|
||||
growthPriceText.value = `¥${(growth.price / 100).toFixed(1)}`
|
||||
if (growth.features?.length) growthFeatures.value = growth.features
|
||||
}
|
||||
if (sprint?.features?.length) sprintFeatures.value = sprint.features
|
||||
if (sprint) sprintPriceText.value = `¥${(sprint.price / 100).toFixed(1)}`
|
||||
if (lres.data.price?.monthly) {
|
||||
growthPriceText.value = `¥${(lres.data.price.monthly / 100).toFixed(1)}`
|
||||
}
|
||||
if (lres.data?.products) {
|
||||
const prodList = []
|
||||
for (const [key, val] of Object.entries(lres.data.products)) {
|
||||
if (val?.price > 0) prodList.push({ type: key, ...val })
|
||||
}
|
||||
products.value = prodList
|
||||
}
|
||||
if (lres.data?.gravityRates) {
|
||||
gravityRates.value = lres.data.gravityRates
|
||||
const res = await uni.request({ url: api('/member/plans'), method: 'GET' })
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) {
|
||||
const prod = res.data.products.interview
|
||||
if (prod) {
|
||||
unitPrice.value = prod.price || 500
|
||||
gravityPerUnit.value = prod.gravity || 5
|
||||
}
|
||||
}
|
||||
// 来自其他页面的补充次数请求 → 弹出数量选择
|
||||
if (pendingBuy.value && products.value.length > 0) {
|
||||
buyProductType.value = pendingBuy.value
|
||||
buyQuantity.value = 1
|
||||
pendingBuy.value = ''
|
||||
showQuantityModal.value = true
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
if (options?.buy) {
|
||||
pendingBuy.value = options.buy
|
||||
}
|
||||
} catch (e) { /* silent */ }
|
||||
})
|
||||
|
||||
onMounted(() => { refreshState() })
|
||||
onShow(() => { refreshState() })
|
||||
|
||||
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
||||
|
||||
const cancelPay = () => {
|
||||
showPayModal.value = false
|
||||
payCodeUrl.value = ''
|
||||
payLoading.value = false
|
||||
payError.value = ''
|
||||
}
|
||||
|
||||
/** 创建支付订单 */
|
||||
const startPay = async (selectedPlan) => {
|
||||
const t = token()
|
||||
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||
|
||||
payingPlan.value = selectedPlan
|
||||
payingPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
|
||||
|
||||
showPayModal.value = true
|
||||
payLoading.value = true
|
||||
payError.value = ''
|
||||
|
||||
const planLabel = selectedPlan || 'growth'
|
||||
|
||||
if (isMp.value) {
|
||||
// 小程序:JSAPI 支付
|
||||
try {
|
||||
let res = await uni.request({
|
||||
url: api('/payment/jsapi'), method: 'POST',
|
||||
data: { plan: planLabel },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
timeout: 30000,
|
||||
})
|
||||
|
||||
// 如果没有 openid,自动绑定
|
||||
if (res.statusCode === 400 && res.data?.needBindWx) {
|
||||
payLoading.value = false
|
||||
uni.showLoading({ title: '绑定微信中...' })
|
||||
try {
|
||||
const loginRes = await uni.login()
|
||||
if (!loginRes?.errMsg?.includes('ok')) throw new Error('获取微信凭证失败')
|
||||
const bindRes = await uni.request({
|
||||
url: api('/user/bind-wx'), method: 'POST',
|
||||
data: { code: loginRes.code },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
if (bindRes.statusCode >= 200 && bindRes.statusCode < 300) {
|
||||
// 绑定成功,重试支付
|
||||
res = await uni.request({
|
||||
url: api('/payment/jsapi'), method: 'POST',
|
||||
data: { plan: planLabel },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
timeout: 30000,
|
||||
})
|
||||
} else {
|
||||
throw new Error(bindRes.data?.message || '微信绑定失败')
|
||||
}
|
||||
} catch (e) {
|
||||
uni.hideLoading()
|
||||
payError.value = '微信绑定失败,请重试'
|
||||
uni.showToast({ title: '微信绑定失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.payParams) {
|
||||
const pp = res.data.payParams
|
||||
currentOutTradeNo.value = res.data.outTradeNo || ''
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: pp.timeStamp,
|
||||
nonceStr: pp.nonceStr,
|
||||
package: pp.package,
|
||||
signType: pp.signType || 'RSA',
|
||||
paySign: pp.paySign,
|
||||
success: () => {
|
||||
const no = currentOutTradeNo.value || res.data.outTradeNo
|
||||
pollPayResult(no, planLabel)
|
||||
},
|
||||
fail: (err) => { payError.value = '支付未完成'; uni.showToast({ title: '支付未完成', icon: 'none' }) },
|
||||
})
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payLoading.value = false
|
||||
const errMsg = '网络连接失败,请检查网络后重试'
|
||||
payError.value = errMsg
|
||||
uni.showToast({ title: errMsg, icon: 'none' })
|
||||
} else {
|
||||
payLoading.value = false
|
||||
// DEBUG: 显示实际返回的状态和数据以便排查
|
||||
const debugInfo = `[${res.statusCode}] ${JSON.stringify(res.data).substring(0, 120)}`
|
||||
console.error('支付响应异常:', debugInfo)
|
||||
const errMsg = res.data?.message || `创建订单失败(${debugInfo})`
|
||||
payError.value = errMsg
|
||||
uni.showToast({ title: errMsg, icon: 'none', duration: 4000 })
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
} else {
|
||||
// H5:二维码支付
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/payment/create'), method: 'POST',
|
||||
data: { plan: planLabel },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
|
||||
payCodeUrl.value = res.data.codeUrl
|
||||
currentOutTradeNo.value = res.data.outTradeNo
|
||||
nextTick(() => {
|
||||
try {
|
||||
const ctx = uni.createCanvasContext('payQrcode')
|
||||
const uqrcode = new UQRCode()
|
||||
uqrcode.data = res.data.codeUrl
|
||||
uqrcode.size = 400
|
||||
uqrcode.margin = 20
|
||||
uqrcode.backgroundColor = '#FFFFFF'
|
||||
uqrcode.foregroundColor = '#000000'
|
||||
uqrcode.make()
|
||||
uqrcode.drawCanvas(ctx)
|
||||
} catch(e) { console.error('二维码生成失败', e) }
|
||||
})
|
||||
// 轮询支付结果
|
||||
pollPayResult(res.data.outTradeNo, planLabel)
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payLoading.value = false
|
||||
const errMsg = '网络连接失败,请检查网络后重试'
|
||||
payError.value = errMsg
|
||||
uni.showToast({ title: errMsg, icon: 'none' })
|
||||
} else {
|
||||
payError.value = res.data?.message || '支付服务暂不可用'
|
||||
uni.showToast({ title: res.data?.message || '支付服务暂不可用', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 数量增减 */
|
||||
const changeQty = (delta) => {
|
||||
const next = buyQuantity.value + delta
|
||||
if (next >= 1 && next <= 99) buyQuantity.value = next
|
||||
const changeQty = (delta: number) => {
|
||||
const next = buyQty.value + delta
|
||||
if (next >= 1 && next <= 99) buyQty.value = next
|
||||
}
|
||||
const clampQty = () => {
|
||||
if (buyQuantity.value < 1) buyQuantity.value = 1
|
||||
if (buyQuantity.value > 99) buyQuantity.value = 99
|
||||
if (buyQty.value < 1) buyQty.value = 1
|
||||
if (buyQty.value > 99) buyQty.value = 99
|
||||
}
|
||||
|
||||
/** 确认购买(从数量选择弹窗触发) */
|
||||
const confirmProductBuy = () => {
|
||||
showQuantityModal.value = false
|
||||
startProductPay(buyProductType.value, buyQuantity.value)
|
||||
}
|
||||
const startPay = async () => {
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||
|
||||
/** 按次购买 */
|
||||
const startProductPay = async (type, quantity = 1) => {
|
||||
const t = token()
|
||||
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||
productPayType.value = type
|
||||
showPayModal.value = true
|
||||
payLoading.value = true
|
||||
payCodeUrl.value = ''
|
||||
payError.value = ''
|
||||
paySuccess.value = false
|
||||
|
||||
const prod = products.value.find(p => p.type === type)
|
||||
const prodTitle = prod?.title || type
|
||||
|
||||
if (isMp.value) {
|
||||
// 小程序:JSAPI 按次支付
|
||||
try {
|
||||
let res = await uni.request({
|
||||
url: api('/payment/jsapi-product'), method: 'POST',
|
||||
data: { type, quantity },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
timeout: 30000,
|
||||
})
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.payParams) {
|
||||
const pp = res.data.payParams
|
||||
currentOutTradeNo.value = res.data.outTradeNo || ''
|
||||
uni.requestPayment({
|
||||
provider: 'wxpay',
|
||||
timeStamp: pp.timeStamp,
|
||||
nonceStr: pp.nonceStr,
|
||||
package: pp.package,
|
||||
signType: pp.signType || 'RSA',
|
||||
paySign: pp.paySign,
|
||||
success: () => {
|
||||
const no = currentOutTradeNo.value || res.data.outTradeNo
|
||||
pollPayResult(no, 'growth')
|
||||
},
|
||||
fail: (err) => { payError.value = '支付未完成'; uni.showToast({ title: '支付未完成', icon: 'none' }) },
|
||||
})
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payLoading.value = false
|
||||
uni.showToast({ title: '网络连接失败', icon: 'none' })
|
||||
} else {
|
||||
payLoading.value = false
|
||||
const errMsg = res.data?.message || '购买失败'
|
||||
payError.value = errMsg
|
||||
uni.showToast({ title: errMsg, icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
} else {
|
||||
// H5:扫码支付
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/payment/create-product'), method: 'POST',
|
||||
data: { type, quantity },
|
||||
header: { 'Authorization': `Bearer ${t}`, 'Content-Type': 'application/json' },
|
||||
data: { type: 'interview', quantity: buyQty.value },
|
||||
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
payLoading.value = false
|
||||
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
|
||||
payCodeUrl.value = res.data.codeUrl
|
||||
currentOutTradeNo.value = res.data.outTradeNo
|
||||
nextTick(() => {
|
||||
try {
|
||||
const ctx = uni.createCanvasContext('payQrcode')
|
||||
const uqrcode = new UQRCode()
|
||||
uqrcode.data = res.data.codeUrl
|
||||
uqrcode.size = 400
|
||||
uqrcode.margin = 20
|
||||
uqrcode.backgroundColor = '#FFFFFF'
|
||||
uqrcode.foregroundColor = '#000000'
|
||||
uqrcode.make()
|
||||
uqrcode.drawCanvas(ctx)
|
||||
} catch(e) { console.error('二维码生成失败', e) }
|
||||
})
|
||||
pollPayResult(res.data.outTradeNo, 'growth')
|
||||
} else if (!res.statusCode || res.statusCode === 0) {
|
||||
payLoading.value = false
|
||||
uni.showToast({ title: '网络连接失败', icon: 'none' })
|
||||
pollPayResult(res.data.outTradeNo)
|
||||
} else {
|
||||
payError.value = res.data?.message || '购买失败'
|
||||
uni.showToast({ title: res.data?.message || '购买失败', icon: 'none' })
|
||||
payError.value = res.data?.message || '创建订单失败'
|
||||
}
|
||||
} catch (e) {
|
||||
payLoading.value = false
|
||||
payError.value = '网络错误,请重试'
|
||||
uni.showToast({ title: '网络错误', icon: 'none' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 轮询订单状态 */
|
||||
const pollPayResult = async (outTradeNo, selectedPlan) => {
|
||||
const pollPayResult = (outTradeNo: string) => {
|
||||
if (!outTradeNo) return
|
||||
const maxAttempts = 30
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
let attempts = 0
|
||||
|
||||
const poll = async () => {
|
||||
attempts++
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api(`/payment/check/${outTradeNo}`), method: 'GET',
|
||||
header: { 'Authorization': `Bearer ${token()}` },
|
||||
header: { 'Authorization': `Bearer ${token}` },
|
||||
})
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
|
||||
// 支付成功,激活套餐
|
||||
await activatePlan(outTradeNo, selectedPlan)
|
||||
paySuccess.value = true
|
||||
payCodeUrl.value = ''
|
||||
return
|
||||
}
|
||||
} catch (e) { /* ignore */ }
|
||||
|
||||
if (attempts < maxAttempts) {
|
||||
setTimeout(poll, 2000)
|
||||
} else {
|
||||
payError.value = '支付结果查询超时,请联系客服'
|
||||
uni.showToast({ title: '支付查询超时', icon: 'none' })
|
||||
}
|
||||
if (attempts < 30) setTimeout(poll, 2000)
|
||||
}
|
||||
setTimeout(poll, 2000)
|
||||
}
|
||||
|
||||
/** 激活套餐 */
|
||||
const activatePlan = async (outTradeNo, selectedPlan) => {
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/payment/activate'), method: 'POST',
|
||||
data: { outTradeNo },
|
||||
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
|
||||
})
|
||||
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.success) {
|
||||
paySuccess.value = true
|
||||
const cancelPay = () => {
|
||||
showPayModal.value = false
|
||||
plan.value = selectedPlan === 'sprint' ? 'sprint' : 'growth'
|
||||
currentPlanName.value = selectedPlan === 'sprint' ? '冲刺版' : '成长版'
|
||||
uni.showToast({ title: '🎉 开通成功!', icon: 'success' })
|
||||
} else {
|
||||
uni.showToast({ title: res.data?.message || '激活失败', icon: 'none' })
|
||||
}
|
||||
} catch (e) {
|
||||
payError.value = '激活失败,请联系客服'
|
||||
uni.showToast({ title: '激活失败', icon: 'none' })
|
||||
}
|
||||
payCodeUrl.value = ''
|
||||
payError.value = ''
|
||||
payLoading.value = false
|
||||
}
|
||||
// #endif
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.page { min-height: 100vh; background: var(--color-bg); }
|
||||
.hero { background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid), var(--color-gradient-end)); padding: 48rpx 32rpx 72rpx; border-radius: 0 0 48rpx 48rpx; }
|
||||
.hero-title { font-size: 40rpx; font-weight: 700; color: #FFFFFF; }
|
||||
.hero-sub { font-size: 22rpx; color: rgba(255,255,255,0.7); margin-top: 8rpx; display: block; }
|
||||
.plans { padding: 0 32rpx; margin-top: -40rpx; display: flex; flex-direction: column; gap: 24rpx; }
|
||||
.plan-card { background: #FFFFFF; border-radius: var(--radius-xl); padding: 32rpx; box-shadow: var(--shadow-sm); position: relative; }
|
||||
.plan-card.growth { border: 2rpx solid var(--color-primary); }
|
||||
.plan-card.sprint { border: 2rpx solid #F59E0B; }
|
||||
.plan-card.active { border-color: var(--color-primary); }
|
||||
.plan-badge { position: absolute; top: -12rpx; right: 24rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; font-size: 20rpx; padding: 4rpx 20rpx; border-radius: var(--radius-round); font-weight: 600; }
|
||||
.sprint-badge { background: linear-gradient(135deg, #F59E0B, #F97316); }
|
||||
.plan-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 20rpx; }
|
||||
.plan-name { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
|
||||
.price-num { font-size: 44rpx; font-weight: 800; color: var(--color-primary); }
|
||||
.price-unit { font-size: 22rpx; color: var(--color-text-tertiary); }
|
||||
.price-sprint { color: #D97706; }
|
||||
.plan-features { display: flex; flex-direction: column; gap: 10rpx; margin-bottom: 24rpx; }
|
||||
.feat { font-size: 24rpx; color: var(--color-text-secondary); }
|
||||
.plan-status { text-align: center; background: #F3F4F6; padding: 14rpx; border-radius: var(--radius-sm); font-size: 24rpx; color: var(--color-text-secondary); }
|
||||
.plan-status.hint { background: transparent; color: var(--color-text-tertiary); }
|
||||
.plan-action { text-align: center; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; padding: 20rpx; border-radius: var(--radius-md); font-size: 28rpx; font-weight: 600; }
|
||||
.plan-action.owned { background: #ECFDF5; color: var(--color-success); }
|
||||
.pay-success { margin: 24rpx 32rpx; background: #ECFDF5; border-radius: var(--radius-lg); padding: 32rpx; text-align: center; }
|
||||
.success-icon { font-size: 48rpx; display: block; margin-bottom: 8rpx; }
|
||||
.success-text { font-size: 28rpx; font-weight: 600; color: var(--color-success); }
|
||||
.placeholder-wrap { display: flex; flex-direction: column; align-items: center; gap: 16rpx; padding: 80rpx 40rpx; }
|
||||
.placeholder-icon { font-size: 80rpx; }
|
||||
.placeholder-text { font-size: 30rpx; font-weight: 600; color: var(--color-text); }
|
||||
.placeholder-hint { font-size: 24rpx; color: var(--color-text-tertiary); }
|
||||
.placeholder-back { font-size: 26rpx; color: var(--color-primary); padding: 16rpx 40rpx; border-radius: var(--radius-md); background: #F3F4F6; margin-top: 24rpx; }
|
||||
|
||||
/* 弹窗 */
|
||||
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
|
||||
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx; width: 70%; display: flex; flex-direction: column; align-items: center; gap: 20rpx; }
|
||||
.modal-title { font-size: 28rpx; font-weight: 600; color: var(--color-text); }
|
||||
.pay-error { color: var(--color-error); }
|
||||
.qr-canvas { width: 400rpx; height: 400rpx; background: #FFF; border-radius: var(--radius-md); }
|
||||
.modal-hint { font-size: 22rpx; color: var(--color-text-tertiary); }
|
||||
.modal-close { font-size: 22rpx; color: var(--color-text-tertiary); padding: 8rpx; }
|
||||
/* H5 购买页 */
|
||||
.hero { display: flex; flex-direction: column; align-items: center; padding: 48rpx 32rpx 24rpx; }
|
||||
.hero-icon { font-size: 72rpx; }
|
||||
.hero-title { font-size: 36rpx; font-weight: 700; color: var(--color-text); margin-top: 12rpx; }
|
||||
.hero-desc { font-size: 24rpx; color: var(--color-text-secondary); margin-top: 8rpx; text-align: center; }
|
||||
|
||||
/* 数量选择弹窗 */
|
||||
.qty-selector { width: 100%; }
|
||||
.qty-label { font-size: 24rpx; color: #6B7280; margin-bottom: 16rpx; display: block; }
|
||||
.product-card { background: #fff; border-radius: var(--radius-lg); margin: 0 32rpx; padding: 32rpx; box-shadow: var(--shadow-sm); }
|
||||
|
||||
.qty-section { margin-bottom: 24rpx; }
|
||||
.section-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 16rpx; }
|
||||
.qty-controls { display: flex; align-items: center; justify-content: center; gap: 24rpx; }
|
||||
.qty-btn { width: 64rpx; height: 64rpx; border-radius: 50%; background: #F3F4F6; display: flex; align-items: center; justify-content: center; font-size: 36rpx; font-weight: 500; color: var(--color-text); }
|
||||
.qty-btn.disabled { color: #D1D5DB; background: #F9FAFB; }
|
||||
.qty-btn:active:not(.disabled) { transform: scale(0.9); background: #E5E7EB; }
|
||||
.qty-input { width: 100rpx; height: 72rpx; text-align: center; font-size: 36rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); }
|
||||
.qty-summary { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 16rpx 0; border-top: 1rpx solid #F3F4F6; }
|
||||
.qty-unit-price { font-size: 22rpx; color: #6B7280; }
|
||||
.qty-total { font-size: 26rpx; color: var(--color-text); font-weight: 500; }
|
||||
.qty-total-num { font-size: 36rpx; font-weight: 800; color: var(--color-primary); }
|
||||
.qty-actions { width: 100%; display: flex; gap: 16rpx; margin-top: 8rpx; }
|
||||
.qty-cancel { flex: 1; text-align: center; padding: 20rpx; border-radius: var(--radius-md); font-size: 26rpx; color: #6B7280; border: 2rpx solid #E5E7EB; }
|
||||
.qty-confirm { flex: 2; text-align: center; padding: 20rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 600; color: #FFF; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); }
|
||||
.qty-input { width: 120rpx; height: 72rpx; text-align: center; font-size: 36rpx; font-weight: 700; color: var(--color-text); border: 2rpx solid #E5E7EB; border-radius: var(--radius-sm); }
|
||||
|
||||
.summary { margin-bottom: 32rpx; }
|
||||
.summary-row { display: flex; justify-content: space-between; padding: 12rpx 0; border-bottom: 1rpx solid #F3F4F6; }
|
||||
.summary-row.total { border-bottom: none; padding-top: 16rpx; }
|
||||
.summary-label { font-size: 24rpx; color: var(--color-text-secondary); }
|
||||
.summary-val { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
|
||||
.summary-val.highlight { color: var(--color-primary); }
|
||||
.total-price { font-size: 36rpx; font-weight: 800; color: var(--color-primary); }
|
||||
|
||||
.buy-btn { width: 100%; height: 88rpx; background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #fff; font-size: 30rpx; font-weight: 600; border-radius: var(--radius-lg); display: flex; align-items: center; justify-content: center; border: none; }
|
||||
.buy-btn:active { opacity: 0.85; transform: scale(0.98); }
|
||||
.buy-btn[disabled] { opacity: 0.5; }
|
||||
|
||||
/* 支付弹窗 */
|
||||
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
|
||||
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx 32rpx; width: 600rpx; display: flex; flex-direction: column; align-items: center; gap: 16rpx; }
|
||||
.modal-title { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
|
||||
.pay-error { color: var(--color-error); }
|
||||
.modal-hint { font-size: 22rpx; color: #6B7280; text-align: center; }
|
||||
.modal-close { font-size: 24rpx; color: #9CA3AF; padding: 12rpx 24rpx; }
|
||||
.qrcode { width: 300rpx; height: 300rpx; margin: 8rpx 0; }
|
||||
</style>
|
||||
@@ -55,16 +55,19 @@
|
||||
<!-- 分享按钮 -->
|
||||
<view class="share-actions">
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<view class="share-btn-row">
|
||||
<button class="share-btn wx-share" open-type="share">
|
||||
<text class="btn-icon">💬</text>
|
||||
<text>分享给好友</text>
|
||||
</button>
|
||||
<button class="share-btn wx-share" open-type="share" data-mode="timeline">
|
||||
<view class="share-btn wx-timeline-hint" @click="showTimelineHint">
|
||||
<text class="btn-icon">🔄</text>
|
||||
<text>分享朋友圈</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef H5 -->
|
||||
<view class="share-btn-row">
|
||||
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
|
||||
<text class="btn-icon">💬</text>
|
||||
<text>分享给微信好友</text>
|
||||
@@ -73,12 +76,15 @@
|
||||
<text class="btn-icon">🔄</text>
|
||||
<text>分享朋友圈</text>
|
||||
</button>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<view class="share-btn-row">
|
||||
<button class="share-btn link-share" @click="copyLink">
|
||||
<text class="btn-icon">🔗</text>
|
||||
<text>复制分享链接</text>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- Tab 切换 -->
|
||||
<view class="tab-bar">
|
||||
@@ -137,6 +143,7 @@ import { api } from '../../config'
|
||||
const tab = ref('records')
|
||||
const stats = ref({ totalShares: 0, totalVisits: 0, creditedCount: 0, todayCredited: 0, shareCredits: 0, gravity: 0 })
|
||||
const shareLink = ref('')
|
||||
const shareUrlCached = ref('')
|
||||
const records = ref([])
|
||||
const visitors = ref([])
|
||||
|
||||
@@ -171,6 +178,21 @@ async function loadData() {
|
||||
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||
const header = { Authorization: `Bearer ${token}` }
|
||||
|
||||
// 先创建分享链接,缓存下来供复制使用
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/share/create'), method: 'POST',
|
||||
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
|
||||
header,
|
||||
})
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
const data = res.data?.data || res.data
|
||||
if (data.shareCode) {
|
||||
shareUrlCached.value = `https://zhiyinwx.yzrcloud.cn/api/share/${data.shareCode}`
|
||||
}
|
||||
}
|
||||
} catch (e) { /* create share is best-effort */ }
|
||||
|
||||
try {
|
||||
const [statsRes, recordsRes, visitorsRes] = await Promise.all([
|
||||
uni.request({ url: api('/share/stats'), method: 'GET', header }),
|
||||
@@ -194,7 +216,7 @@ async function shareToWechat() {
|
||||
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
|
||||
header: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.statusCode !== 200) return
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) return
|
||||
|
||||
const data = res.data
|
||||
const path = data.wechatShareInfo?.path || `/pages/share/share?code=${data.shareCode}`
|
||||
@@ -213,19 +235,49 @@ async function shareToWechat() {
|
||||
|
||||
async function copyLink() {
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) return
|
||||
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
|
||||
|
||||
if (shareUrlCached.value) {
|
||||
// 使用已缓存的分享链接,避免二次 API 调用
|
||||
uni.setClipboardData({
|
||||
data: shareUrlCached.value,
|
||||
success: () => { uni.showToast({ title: '链接已复制' }); loadData() },
|
||||
fail: () => { uni.showToast({ title: '复制失败,请长按选择复制', icon: 'none' }) },
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 缓存未命中时兜底:调 API 生成
|
||||
try {
|
||||
const res = await uni.request({
|
||||
url: api('/share/create'),
|
||||
method: 'POST',
|
||||
url: api('/share/create'), method: 'POST',
|
||||
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
|
||||
header: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.statusCode !== 200) return
|
||||
const shareUrl = `https://zhiyinwx.yzrcloud.cn/share/${res.data.shareCode}`
|
||||
uni.setClipboardData({ data: shareUrl, success: () => { uni.showToast({ title: '链接已复制' }); loadData() } })
|
||||
} catch (e) { console.error(e) }
|
||||
if (res.statusCode < 200 || res.statusCode >= 300) {
|
||||
uni.showToast({ title: `创建失败(${res.statusCode}),请重试`, icon: 'none' })
|
||||
return
|
||||
}
|
||||
const data = res.data?.data || res.data
|
||||
if (!data.shareCode) {
|
||||
uni.showToast({ title: '返回数据异常,请重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
const shareUrl = `https://zhiyinwx.yzrcloud.cn/api/share/${data.shareCode}`
|
||||
shareUrlCached.value = shareUrl
|
||||
uni.setClipboardData({
|
||||
data: shareUrl,
|
||||
success: () => { uni.showToast({ title: '链接已复制' }); loadData() },
|
||||
fail: () => { uni.showToast({ title: '复制失败,请长按选择复制', icon: 'none' }) },
|
||||
})
|
||||
} catch (e) {
|
||||
console.error('[share] copyLink error:', e)
|
||||
uni.showToast({ title: '网络错误,请重试', icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
function showTimelineHint() {
|
||||
uni.showToast({ title: '请点击右上角 ··· 选择分享到朋友圈', icon: 'none', duration: 3000 })
|
||||
}
|
||||
|
||||
function typeLabel(type) {
|
||||
@@ -270,12 +322,18 @@ function formatTime(t) {
|
||||
.today-hint { font-size: 18rpx; color: var(--color-text-tertiary); text-align: center; }
|
||||
|
||||
/* Share buttons */
|
||||
.share-actions { padding: 0 32rpx; display: flex; gap: 20rpx; }
|
||||
.share-btn { flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 500; border: none; }
|
||||
.share-actions { padding: 0 32rpx; display: flex; flex-direction: column; gap: 16rpx; }
|
||||
.share-btn-row { display: flex; gap: 20rpx; }
|
||||
.share-btn {
|
||||
flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md);
|
||||
font-size: 26rpx; font-weight: 500; border: none; padding: 0; white-space: nowrap;
|
||||
}
|
||||
.share-btn:active { transform: scale(0.96); }
|
||||
.btn-icon { margin-right: 8rpx; font-size: 28rpx; }
|
||||
.wx-share { background: #07C160; color: #FFFFFF; }
|
||||
.wx-timeline { background: #FF6600; color: #FFFFFF; }
|
||||
.wx-timeline-hint { flex: 1; display: flex; align-items: center; justify-content: center; height: 88rpx; border-radius: var(--radius-md); font-size: 26rpx; font-weight: 500; background: #FF6600; color: #FFFFFF; white-space: nowrap; }
|
||||
.wx-timeline-hint:active { transform: scale(0.96); }
|
||||
.link-share { background: #FFFFFF; color: var(--color-text); border: 2rpx solid var(--color-border); }
|
||||
|
||||
/* Tabs */
|
||||
|
||||
@@ -39,16 +39,21 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 配额与会员信息 -->
|
||||
<view class="quota-card" v-if="isLoggedIn">
|
||||
<view class="quota-row">
|
||||
<view class="quota-info">
|
||||
<text class="quota-plan">{{ memberInfo.planName || '免费版' }}</text>
|
||||
<text class="quota-count">引力值 {{ memberInfo.gravity ?? 0 }}</text>
|
||||
<!-- 引力值卡片(代替原配额卡片) -->
|
||||
<view class="gravity-card" v-if="isLoggedIn">
|
||||
<view class="gravity-card-inner">
|
||||
<view class="gravity-top-row">
|
||||
<view class="gravity-header">
|
||||
<text class="gravity-icon">⚡</text>
|
||||
<text class="gravity-label">我的引力值</text>
|
||||
</view>
|
||||
<view class="quota-actions">
|
||||
<text class="quota-btn primary" @click="goBuyCredits">补充引力值</text>
|
||||
<text class="quota-btn" :class="memberInfo.plan !== 'free' ? 'owned' : ''" @click="goUpgrade">{{ memberInfo.plan !== 'free' ? '已开通' : '升级会员' }}</text>
|
||||
<text class="gravity-num">{{ memberInfo.gravity ?? 0 }}</text>
|
||||
</view>
|
||||
<text class="gravity-hint">每次面试消耗 5 引力值 · 分享可获得更多</text>
|
||||
<view class="gravity-actions">
|
||||
<text class="gravity-btn share" @click="goSharePage">分享得引力值</text>
|
||||
<text class="gravity-btn contribute" @click="goContributePage">贡献面经</text>
|
||||
<text class="gravity-btn h5buy" @click="goH5Buy">官网购买</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -72,17 +77,20 @@
|
||||
<text class="menu-text">面试复盘</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
<!-- 会员中心菜单注释隐藏(微信审核) -->
|
||||
<!--
|
||||
<view class="menu-item" @click="goVip">
|
||||
<view class="menu-icon-wrap wrap-purple"><text class="menu-icon">💎</text></view>
|
||||
<text class="menu-text">会员中心</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
-->
|
||||
<view class="menu-item" @click="requireLogin(goResume, '我的简历')">
|
||||
<view class="menu-icon-wrap wrap-green"><text class="menu-icon">📄</text></view>
|
||||
<text class="menu-text">我的简历</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
</view>
|
||||
<view class="menu-item" @click="requireLogin(goShare, '我的分享')">
|
||||
<view class="menu-item" @click="requireLogin(goSharePage, '我的分享')">
|
||||
<view class="menu-icon-wrap wrap-orange"><text class="menu-icon">📤</text></view>
|
||||
<text class="menu-text">我的分享</text>
|
||||
<text class="menu-arrow">›</text>
|
||||
@@ -104,6 +112,46 @@
|
||||
<button class="logout-btn" @click="doLogout">退出登录</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 引力值获取方式 -->
|
||||
<view class="modal-overlay" v-if="showGetGravityModal" @click="showGetGravityModal = false">
|
||||
<view class="modal-content" @click.stop>
|
||||
<text class="modal-title">获取引力值</text>
|
||||
<text class="modal-hint">引力值可用于面试、简历优化、下载等</text>
|
||||
|
||||
<!-- 分享得引力值 -->
|
||||
<view class="gp-get-method" @click="goSharePage">
|
||||
<view class="gp-method-icon-wrap"><text class="gp-method-icon">🎁</text></view>
|
||||
<view class="gp-method-info">
|
||||
<text class="gp-method-name">分享给好友</text>
|
||||
<text class="gp-method-desc">每成功邀请一位好友注册,可得 5 引力值,上不封顶</text>
|
||||
</view>
|
||||
<text class="gp-method-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<!-- 贡献面经 -->
|
||||
<view class="gp-get-method" @click="goContributePage">
|
||||
<view class="gp-method-icon-wrap"><text class="gp-method-icon">📝</text></view>
|
||||
<view class="gp-method-info">
|
||||
<text class="gp-method-name">贡献面经</text>
|
||||
<text class="gp-method-desc">每发布一篇面经可获得 3 引力值,助力他人也提升自己</text>
|
||||
</view>
|
||||
<text class="gp-method-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<!-- 官网购买 -->
|
||||
<view class="gp-get-method" @click="goH5Buy">
|
||||
<view class="gp-method-icon-wrap"><text class="gp-method-icon">🛒</text></view>
|
||||
<view class="gp-method-info">
|
||||
<text class="gp-method-name">官网购买</text>
|
||||
<text class="gp-method-desc">通过官网网页端可购买引力值套餐,支持更多支付方式</text>
|
||||
</view>
|
||||
<text class="gp-method-arrow">›</text>
|
||||
</view>
|
||||
|
||||
<text class="modal-close" @click="showGetGravityModal = false">关闭</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -179,17 +227,36 @@ const checkAdmin = () => {
|
||||
}
|
||||
|
||||
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' })
|
||||
const goBuyCredits = () => uni.navigateTo({ url: '/pages/member/member?buy=interview' })
|
||||
const goUpgrade = () => {
|
||||
if (memberInfo.value.plan !== 'free') return // already on a paid plan
|
||||
|
||||
// 引力值获取
|
||||
const showGetGravityModal = ref(false)
|
||||
const openBuyModal = () => { showGetGravityModal.value = true }
|
||||
const goH5Buy = () => {
|
||||
const token = uni.getStorageSync('token') || ''
|
||||
const url = `https://zhiyin.yzrcloud.cn/?buy=gravity${token ? '&token=' + token : ''}`
|
||||
// #ifdef H5
|
||||
uni.navigateTo({ url: '/pages/member/member' })
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.setClipboardData({
|
||||
data: url,
|
||||
success: () => {
|
||||
uni.showToast({ title: '链接已复制,请在手机浏览器中打开', icon: 'none', duration: 3000 })
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '复制失败,请手动访问 zhiyin.yzrcloud.cn', icon: 'none', duration: 3000 })
|
||||
},
|
||||
})
|
||||
// #endif
|
||||
}
|
||||
|
||||
const goCareer = () => uni.navigateTo({ url: '/pages/career/career' })
|
||||
const goHistory = () => uni.switchTab({ url: '/pages/history/history' })
|
||||
const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' })
|
||||
const goVip = () => uni.navigateTo({ url: '/pages/member/member' })
|
||||
const goResume = () => uni.navigateTo({ url: '/pages/resume/resume' })
|
||||
const goShare = () => uni.navigateTo({ url: '/pages/share/share' })
|
||||
const goSharePage = () => uni.navigateTo({ url: '/pages/share/share' })
|
||||
const goContributePage = () => uni.navigateTo({ url: '/pages/contribute/contribute' })
|
||||
const goAdmin = () => uni.navigateTo({ url: '/pages/admin/admin' })
|
||||
const goAbout = () => uni.navigateTo({ url: '/pages/about/about' })
|
||||
|
||||
@@ -228,16 +295,29 @@ const doLogout = () => {
|
||||
.guest-info { flex: 1; }
|
||||
.guest-name { font-size: 30rpx; font-weight: 600; color: #FFFFFF; }
|
||||
|
||||
.quota-card { margin: -48rpx 32rpx 16rpx; background: #FFFFFF; border-radius: var(--radius-lg); padding: 28rpx 24rpx; box-shadow: var(--shadow-sm); position: relative; z-index: 1; }
|
||||
.quota-row { display: flex; align-items: center; justify-content: space-between; }
|
||||
.quota-info { display: flex; flex-direction: column; gap: 4rpx; }
|
||||
.quota-plan { font-size: 28rpx; font-weight: 700; color: var(--color-text); }
|
||||
.quota-count { font-size: 22rpx; color: #6B7280; }
|
||||
.quota-actions { display: flex; gap: 12rpx; }
|
||||
.quota-btn { font-size: 22rpx; padding: 8rpx 20rpx; border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap; }
|
||||
.quota-btn.primary { background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; }
|
||||
.quota-btn.owned { background: #F3F4F6; color: #9CA3AF; }
|
||||
.quota-btn:not(.primary):not(.owned) { background: #FEF3C7; color: #92400E; border: 2rpx solid #F59E0B; }
|
||||
/* 引力值卡片(代替原配额卡片) */
|
||||
.gravity-card { margin: -48rpx 32rpx 16rpx; position: relative; z-index: 1; }
|
||||
.gravity-card-inner {
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
border-radius: var(--radius-xl);
|
||||
padding: 28rpx 24rpx 24rpx;
|
||||
box-shadow: 0 8rpx 32rpx rgba(102,126,234,0.25);
|
||||
}
|
||||
.gravity-top-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8rpx; }
|
||||
.gravity-header { display: flex; align-items: center; gap: 8rpx; }
|
||||
.gravity-icon { font-size: 32rpx; }
|
||||
.gravity-label { font-size: 24rpx; color: rgba(255,255,255,0.8); font-weight: 500; }
|
||||
.gravity-num { font-size: 48rpx; font-weight: 800; color: #FFFFFF; line-height: 1; }
|
||||
.gravity-hint { font-size: 20rpx; color: rgba(255,255,255,0.6); margin-bottom: 20rpx; }
|
||||
.gravity-actions { display: flex; gap: 16rpx; }
|
||||
.gravity-btn {
|
||||
flex: 1; text-align: center; padding: 18rpx 0; border-radius: var(--radius-md);
|
||||
font-size: 26rpx; font-weight: 600; white-space: nowrap;
|
||||
}
|
||||
.gravity-btn.share { background: rgba(255,255,255,0.2); color: #FFFFFF; border: 2rpx solid rgba(255,255,255,0.3); }
|
||||
.gravity-btn.h5buy { background: #FFFFFF; color: #667eea; }
|
||||
.gravity-btn.contribute { background: rgba(255,255,255,0.15); color: #FFFFFF; border: 2rpx solid rgba(255,255,255,0.2); }
|
||||
.gravity-btn:active { transform: scale(0.96); }
|
||||
|
||||
.menu-area { padding: 0 32rpx 32rpx; margin-top: 8rpx; }
|
||||
.menu-group { background: #FFFFFF; border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 24rpx; box-shadow: var(--shadow-sm); }
|
||||
@@ -258,4 +338,28 @@ const doLogout = () => {
|
||||
.logout-wrap { margin-top: 8rpx; }
|
||||
.logout-btn { background: #FFFFFF; color: var(--color-error); font-size: 28rpx; font-weight: 500; border-radius: var(--radius-md); height: 88rpx; line-height: 88rpx; border: 2rpx solid #FECACA; }
|
||||
.logout-btn:active { background: #FEF2F2; transform: scale(0.96); }
|
||||
|
||||
/* 弹窗通用 */
|
||||
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
|
||||
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx 32rpx; width: 600rpx; max-height: 80vh; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 16rpx; }
|
||||
.modal-title { font-size: 30rpx; font-weight: 700; color: var(--color-text); }
|
||||
.modal-hint { font-size: 22rpx; color: #6B7280; text-align: center; }
|
||||
.modal-close { font-size: 24rpx; color: #9CA3AF; padding: 12rpx 24rpx; }
|
||||
|
||||
/* 获取引力值弹窗 - 分享/贡献方法 */
|
||||
.gp-get-method {
|
||||
width: 100%; display: flex; align-items: center; gap: 16rpx;
|
||||
background: #F9FAFB; border-radius: var(--radius-md); padding: 20rpx;
|
||||
border: 2rpx solid #E5E7EB; margin-top: 8rpx;
|
||||
}
|
||||
.gp-get-method:active { transform: scale(0.97); background: #F3F4F6; }
|
||||
.gp-method-icon-wrap {
|
||||
width: 64rpx; height: 64rpx; border-radius: var(--radius-md);
|
||||
background: #EEF2FF; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
|
||||
}
|
||||
.gp-method-icon { font-size: 32rpx; }
|
||||
.gp-method-info { flex: 1; display: flex; flex-direction: column; gap: 4rpx; }
|
||||
.gp-method-name { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
|
||||
.gp-method-desc { font-size: 20rpx; color: #6B7280; line-height: 1.4; }
|
||||
.gp-method-arrow { font-size: 32rpx; color: #D1D5DB; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user