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:
yuzhiran
2026-06-20 20:49:15 +08:00
parent a1e1f0b3c3
commit 8ee27fdd32
11 changed files with 648 additions and 593 deletions
+14 -8
View File
@@ -21,9 +21,10 @@ zhiyin/
├── zhiyin-app/ # uni-app 3.x 前端 (H5 + 微信小程序) ├── zhiyin-app/ # uni-app 3.x 前端 (H5 + 微信小程序)
│ └── src/ │ └── src/
│ ├── pages/ # 20 个页面 (pages.json 路由) │ ├── pages/ # 20 个页面 (pages.json 路由)
│ ├── composables/ # 可复用组合式函数(如 useGravityPurchase
│ ├── services/api.ts # API 调用封装 (uni.request) │ ├── services/api.ts # API 调用封装 (uni.request)
│ ├── config.ts # 端点定义 + api() 辅助函数 │ ├── config.ts # 端点定义 + api() 辅助函数
│ └── App.vue # 设计 Token + 全局样式 │ └── App.vue # 设计 Token + 全局样式 + H5 URL 参数处理
└── docs/ # 产品/架构/部署/路线图文档 └── docs/ # 产品/架构/部署/路线图文档
``` ```
@@ -96,10 +97,13 @@ zhiyin/
- 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY` - 环境变量: `AI_PRIMARY_KEY`, `AI_BACKUP_KEY`
### 支付(微信支付 v3 ### 支付(微信支付 v3
- Native 支付(H5 扫码): `POST /payment/create` - Native 支付(H5 扫码): `POST /payment/create-product`(按量购买引力值)
- JSAPI 支付(小程序内): `POST /payment/jsapi` - JSAPI 支付(小程序内): `POST /payment/jsapi-product`(按量购买引力值)
- 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动开会员 - 支付回调: `POST /payment/notify`@Public,验签 + 解密 + 自动到账
- 支付结果轮询: `GET /payment/check/:outTradeNo`
- 产品定价: `GET /member/plans`(含 products 字段,定义引力值单价和赠送量)
- 需要微信商户证书文件(通过 postbuild 复制到 dist - 需要微信商户证书文件(通过 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: 战略升级 | ✅ 完成 | 定价重构(免费 + ¥19.9/月),三层壁垒设计 |
| Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) | | Phase 0.5: 壁垒构建 | ✅ 完成 | 数据飞轮(面经贡献+题库),留存入围(进步轨迹+打卡日历+每日一题) |
| Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(VIP 不再无限次)、管理后台完善、H5 已部署、生产模式已启用 | | Phase 1: MVP 上线 | 🚧 当前 | 小程序 v1.0.16 已上传、引力值体系统一(订阅制改为按量购买)、管理后台完善、H5 已部署、生产模式已启用 |
| Phase 1.5: 商业化 | 📋 规划 | 引力值运营策略、每日一题定时推送、PMF 验证 | | Phase 1.5: 商业化 | 📋 规划 | 引力值运营策略、每日一题定时推送、PMF 验证 |
| Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 | | Phase 2: 增强 + 题库 | 📋 规划 | 50+ 校招岗位、技能缺口分析、公司真题库建设 |
| Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 | | Phase 3: 秋招冲刺 | 📋 规划 | 高校合作、B 端服务、KOC 推广 |
@@ -258,7 +262,7 @@ VITE_APP_NAME=AI磁场
- 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证) - 远程仓库: `http://127.0.0.1:2999/txai-dev/zhiyin.git`(本机 Gitea,带 token 认证)
- 默认分支: `master` - 默认分支: `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` 中配置),注意避免在定时任务和批量操作中被限 6. **API 限流**: 100 次/60 秒(在 `app.module.ts` 中配置),注意避免在定时任务和批量操作中被限
7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode` 7. **验证码**: 生产模式(`NODE_ENV=production`)使用真实 SMTP 发邮件验证码;非生产模式手机验证码固定为 `123456`、邮件验证码在响应中返回 `devCode`
8. **MongoDB**: 8 个核心集合 + 2 个分享集合 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 后经常丢失这行声明,需手动补回 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. **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 { GravityTopUpService } from './gravity-top-up.service'
import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema' import { DailyQuestion, DailyQuestionSchema } from '../schemas/daily-question.schema'
import { User, UserSchema } from '../user/user.schema' import { User, UserSchema } from '../user/user.schema'
import { PricingService } from '../schemas/pricing.service'
@Module({ @Module({
imports: [ imports: [
@@ -15,6 +14,6 @@ import { PricingService } from '../schemas/pricing.service'
{ name: User.name, schema: UserSchema }, { name: User.name, schema: UserSchema },
]), ]),
], ],
providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService, PricingService], providers: [WechatTokenService, DailyQuestionPushService, VipExpiryService, GravityTopUpService],
}) })
export class ScheduleModule {} export class ScheduleModule {}
+26 -1
View File
@@ -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 { JwtService } from '@nestjs/jwt'
import { ShareService } from './share.service' import { ShareService } from './share.service'
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard' import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard'
import { CurrentUser } from '../../common/decorators/current-user.decorator' import { CurrentUser } from '../../common/decorators/current-user.decorator'
import { Public } from '../../common/decorators/public.decorator' import { Public } from '../../common/decorators/public.decorator'
import * as crypto from 'crypto'
@Controller('share') @Controller('share')
export class ShareController { export class ShareController {
@@ -66,4 +68,27 @@ export class ShareController {
) { ) {
return this.shareService.visitors(userId, Number(page) || 1, Number(pageSize) || 20) 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}`)
}
} }
+20
View File
@@ -6,8 +6,28 @@ onLaunch(() => {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
initPrivacy() initPrivacy()
// #endif // #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 // #ifdef MP-WEIXIN
function initPrivacy() { function initPrivacy() {
if (wx.onNeedPrivacyAuthorization) { 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,
}
}
+2 -2
View File
@@ -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; } .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; } .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; } .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; } .tabs { display: flex; flex-wrap: wrap; 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; } .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; } .tab.active { background: var(--color-primary); color: #FFF; font-weight: 600; }
.stat-cards { display: flex; gap: 16rpx; } .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); } .stat-card { flex: 1; background: #FFF; border-radius: var(--radius-lg); padding: 28rpx; text-align: center; box-shadow: var(--shadow-sm); }
+6 -5
View File
@@ -150,7 +150,7 @@ const doAnalyze = async () => {
data: { ...profile }, data: { ...profile },
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' }, header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' },
}) })
if (res.statusCode === 200) { if (res.statusCode >= 200 && res.statusCode < 300) {
if (res.data.error) { if (res.data.error) {
error.value = res.data.error error.value = res.data.error
return return
@@ -184,7 +184,7 @@ const doChat = async () => {
data: { message: msg, history: chatHistory.value.slice(0, -1) }, data: { message: msg, history: chatHistory.value.slice(0, -1) },
header: { 'Authorization': `Bearer ${token.value}`, 'Content-Type': 'application/json' }, 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 || '') }) chatHistory.value.push({ role: 'assistant', content: res.data.reply || (res.data.error || '') })
} else { } else {
chatHistory.value.push({ role: 'assistant', content: '回复失败,请稍后重试' }) 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-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; } .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-card { background: #fff; border-radius: var(--radius-lg); padding: 32rpx; box-shadow: var(--shadow-sm); overflow: hidden; }
.form-group { margin-bottom: 28rpx; } .form-group { margin-bottom: 28rpx; width: 100%; }
.form-group:last-child { margin-bottom: 0; } .form-group:last-child { margin-bottom: 0; }
.form-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 12rpx; } .form-label { font-size: 26rpx; font-weight: 600; color: var(--color-text); display: block; margin-bottom: 12rpx; }
.required { color: var(--color-error); } .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; } .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; } .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; }
+30 -18
View File
@@ -90,28 +90,22 @@
<view class="complete-bar" v-else> <view class="complete-bar" v-else>
<button class="cta-btn" @click="goResult">查看面试报告</button> <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>
<!-- 购买弹窗次数不足时 --> <!-- 官网购买弹窗 -->
<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> <view class="modal-content" @click.stop>
<text class="modal-title">引力值不足</text> <text class="modal-title">引力值不足</text>
<text class="modal-hint">您的引力值不足请补充后继续面试每次面试消耗 5 引力值</text> <text class="modal-hint">您的引力值不足请补充后继续面试每次面试消耗 5 引力值</text>
<view class="purchase-options"> <view class="purchase-options">
<view class="purchase-option" @click="goBuyProduct"> <view class="purchase-option" @click="goH5BuyAndClose">
<text class="purchase-name">补充引力值</text> <text class="purchase-name">官网购买引力值</text>
<text class="purchase-price">¥5 </text> <text class="purchase-price">前往网页版充值</text>
<text class="purchase-desc">¥5 = 5 引力值可面试 1 </text> <text class="purchase-desc">打开官网 H5 页面支持多种支付方式</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> </view>
</view> </view>
<text class="modal-close" @click="showPurchaseModal = false">取消</text> <text class="modal-close" @click="showH5BuyModal = false">取消</text>
</view> </view>
</view> </view>
</view> </view>
@@ -122,7 +116,6 @@ import { ref, computed, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { onLoad } from '@dcloudio/uni-app' import { onLoad } from '@dcloudio/uni-app'
import { api, API_ENDPOINTS } from '../../config' import { api, API_ENDPOINTS } from '../../config'
import DigitalHuman from '../../components/digital-human.vue' import DigitalHuman from '../../components/digital-human.vue'
const messages = ref([{ role: 'ai', content: '你好!我是 AI 面试官,请选择岗位开始模拟面试!' }]) const messages = ref([{ role: 'ai', content: '你好!我是 AI 面试官,请选择岗位开始模拟面试!' }])
const inputText = ref('') const inputText = ref('')
const aiLoading = ref(false) const aiLoading = ref(false)
@@ -134,7 +127,7 @@ const scrollToId = ref('')
const position = ref('') const position = ref('')
const avatarMode = ref(true) const avatarMode = ref(true)
const showPositionPicker = ref(false) const showPositionPicker = ref(false)
const showPurchaseModal = ref(false) const showH5BuyModal = ref(false)
const positions = ref([]) const positions = ref([])
const positionsLoading = ref(false) const positionsLoading = ref(false)
const aiSpeechText = ref('') const aiSpeechText = ref('')
@@ -323,8 +316,27 @@ function onAvatarSilent() {
} }
const goResult = () => uni.navigateTo({ url: `/pages/report/report?interviewId=${interviewId.value}` }) 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 = () => { const scrollToBottom = () => {
nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) }) nextTick(() => { scrollToId.value = ''; setTimeout(() => { scrollToId.value = 'msg-bottom' }, 100) })
} }
+138 -501
View File
@@ -1,584 +1,221 @@
<template> <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="page fade-in">
<view class="hero"> <view class="hero">
<text class="hero-title">会员中心</text> <text class="hero-icon"></text>
<text class="hero-sub" v-if="isLoggedIn"> <text class="hero-title">补充引力值</text>
当前{{ currentPlanName }} <text class="hero-desc">购买后可获得相应引力值用于面试简历优化下载</text>
</text>
<text class="hero-sub" v-else>选择套餐解锁全部功能</text>
</view> </view>
<view class="plans"> <view class="product-card">
<!-- 免费版 --> <view class="qty-section">
<view class="plan-card free" :class="{ active: plan === 'free' && isLoggedIn }"> <text class="section-label">购买数量</text>
<view class="plan-header"> <view class="qty-controls">
<text class="plan-name">免费版</text> <text class="qty-btn" :class="{ disabled: buyQty <= 1 }" @click="changeQty(-1)"></text>
<view class="plan-price"><text class="price-num">免费</text></view> <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>
<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>
<!-- 成长版 --> <view class="summary">
<view class="plan-card growth recommended" :class="{ active: plan === 'growth' && isLoggedIn }"> <view class="summary-row">
<view class="plan-badge"> 推荐</view> <text class="summary-label">单价</text>
<view class="plan-header"> <text class="summary-val">¥{{ (unitPrice / 100).toFixed(1) }} / </text>
<text class="plan-name">成长版</text>
<text class="plan-price"><text class="price-num">{{ growthPriceText }}</text><text class="price-unit">/</text></text>
</view> </view>
<view class="plan-features"> <view class="summary-row">
<text class="feat" v-for="f in growthFeatures" :key="f"> {{ f }}</text> <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>
<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>
<!-- 冲刺版 --> <button class="buy-btn" :disabled="payLoading" @click="startPay">
<view class="plan-card sprint" :class="{ active: plan === 'sprint' && isLoggedIn }"> <text v-if="!payLoading">立即购买</text>
<view class="plan-badge sprint-badge">🚀 冲刺</view> <text v-else>处理中...</text>
<view class="plan-header"> </button>
<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>
</view> </view>
<!-- 支付弹窗 --> <!-- 支付弹窗 -->
<view class="modal-overlay" v-if="showPayModal" @click="cancelPay"> <view class="modal-overlay" v-if="showPayModal" @click="cancelPay">
<view class="modal-content" @click.stop> <view class="modal-content" @click.stop>
<template v-if="payLoading"> <template v-if="payLoading">
<text class="modal-title">正在创建支付...</text> <text class="modal-title">正在创建订单...</text>
</template> </template>
<template v-else-if="!isMp && payCodeUrl"> <template v-else-if="payCodeUrl">
<text class="modal-title">微信扫码支付</text> <text class="modal-title">微信扫码支付</text>
<canvas canvas-id="payQrcode" class="qr-canvas"></canvas> <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-hint">使用微信扫描二维码完成支付</text>
<text class="modal-hint">支付成功后将自动跳转</text>
<text class="modal-close" @click="cancelPay">取消支付</text> <text class="modal-close" @click="cancelPay">取消支付</text>
</template> </template>
<template v-else-if="isMp && !payLoading"> <template v-else-if="paySuccess">
<text class="modal-title">微信支付</text> <text class="modal-title"> 支付成功</text>
<text class="modal-hint">即将调起微信支付...</text> <text class="modal-hint">引力值已到账返回继续使用吧</text>
<text class="modal-close" @click="cancelPay">关闭</text>
</template> </template>
<template v-if="payError"> <template v-else-if="payError">
<text class="modal-title pay-error">支付异常</text> <text class="modal-title pay-error">支付失败</text>
<text class="modal-hint">{{ payError }}</text> <text class="modal-hint">{{ payError }}</text>
<text class="modal-close" @click="cancelPay">关闭</text> <text class="modal-close" @click="cancelPay">关闭</text>
</template> </template>
</view> </view>
</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> </view>
<!-- #endif -->
</template> </template>
<script setup> <script setup lang="ts">
import { ref, computed, onMounted, nextTick } from 'vue' import { ref, computed, onMounted } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { api } from '../../config' import { api } from '../../config'
import UQRCode from 'uqrcodejs'
const isLoggedIn = ref(false) const goBack = () => uni.switchTab({ url: '/pages/user/user' })
const isMp = ref(false)
const plan = ref('free') // #ifdef H5
const currentPlanName = ref('免费版') const buyQty = ref(1)
const paySuccess = ref(false) const unitPrice = ref(500)
const gravityPerUnit = ref(5)
const payLoading = ref(false)
const showPayModal = ref(false) const showPayModal = ref(false)
const payCodeUrl = ref('') const payCodeUrl = ref('')
const payLoading = ref(false) const paySuccess = ref(false)
const payError = ref('') 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 { try {
const [sres, lres] = await Promise.all([ const res = await uni.request({ url: api('/member/plans'), method: 'GET' })
uni.request({ url: api('/member/status'), method: 'GET', header: { 'Authorization': `Bearer ${t}` } }), if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.products) {
uni.request({ url: api('/member/plans'), method: 'GET' }), const prod = res.data.products.interview
]) if (prod) {
if (sres.statusCode >= 200 && sres.statusCode < 300) { unitPrice.value = prod.price || 500
const d = sres.data gravityPerUnit.value = prod.gravity || 5
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
} }
} }
// 来自其他页面的补充次数请求 → 弹出数量选择 } catch (e) { /* silent */ }
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
}
}) })
onMounted(() => { refreshState() }) const changeQty = (delta: number) => {
onShow(() => { refreshState() }) const next = buyQty.value + delta
if (next >= 1 && next <= 99) buyQty.value = next
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 clampQty = () => { const clampQty = () => {
if (buyQuantity.value < 1) buyQuantity.value = 1 if (buyQty.value < 1) buyQty.value = 1
if (buyQuantity.value > 99) buyQuantity.value = 99 if (buyQty.value > 99) buyQty.value = 99
} }
/** 确认购买(从数量选择弹窗触发) */ const startPay = async () => {
const confirmProductBuy = () => { const token = uni.getStorageSync('token') || ''
showQuantityModal.value = false if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
startProductPay(buyProductType.value, buyQuantity.value)
}
/** 按次购买 */
const startProductPay = async (type, quantity = 1) => {
const t = token()
if (!t) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
productPayType.value = type
showPayModal.value = true showPayModal.value = true
payLoading.value = true payLoading.value = true
payCodeUrl.value = ''
payError.value = '' payError.value = ''
paySuccess.value = false
const prod = products.value.find(p => p.type === type) try {
const prodTitle = prod?.title || type const res = await uni.request({
url: api('/payment/create-product'), method: 'POST',
data: { type: 'interview', quantity: buyQty.value },
header: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
})
payLoading.value = false
if (isMp.value) { if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.codeUrl) {
// 小程序:JSAPI 按次支付 payCodeUrl.value = res.data.codeUrl
try { pollPayResult(res.data.outTradeNo)
let res = await uni.request({ } else {
url: api('/payment/jsapi-product'), method: 'POST', payError.value = res.data?.message || '创建订单失败'
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' },
})
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' })
} 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' })
} }
} catch (e) {
payLoading.value = false
payError.value = '网络错误,请重试'
} }
} }
/** 轮询订单状态 */ const pollPayResult = (outTradeNo: string) => {
const pollPayResult = async (outTradeNo, selectedPlan) => {
if (!outTradeNo) return if (!outTradeNo) return
const maxAttempts = 30 const token = uni.getStorageSync('token') || ''
let attempts = 0 let attempts = 0
const poll = async () => { const poll = async () => {
attempts++ attempts++
try { try {
const res = await uni.request({ const res = await uni.request({
url: api(`/payment/check/${outTradeNo}`), method: 'GET', 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') { if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.status === 'success') {
// 支付成功,激活套餐 paySuccess.value = true
await activatePlan(outTradeNo, selectedPlan) payCodeUrl.value = ''
return return
} }
} catch (e) { /* ignore */ } } catch (e) { /* ignore */ }
if (attempts < 30) setTimeout(poll, 2000)
if (attempts < maxAttempts) {
setTimeout(poll, 2000)
} else {
payError.value = '支付结果查询超时,请联系客服'
uni.showToast({ title: '支付查询超时', icon: 'none' })
}
} }
setTimeout(poll, 2000) setTimeout(poll, 2000)
} }
/** 激活套餐 */ const cancelPay = () => {
const activatePlan = async (outTradeNo, selectedPlan) => { showPayModal.value = false
try { payCodeUrl.value = ''
const res = await uni.request({ payError.value = ''
url: api('/payment/activate'), method: 'POST', payLoading.value = false
data: { outTradeNo },
header: { 'Authorization': `Bearer ${token()}`, 'Content-Type': 'application/json' },
})
if (res.statusCode >= 200 && res.statusCode < 300 && res.data?.success) {
paySuccess.value = true
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' })
}
} }
// #endif
</script> </script>
<style scoped> <style scoped>
.page { min-height: 100vh; background: var(--color-bg); } .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; } .placeholder-wrap { display: flex; flex-direction: column; align-items: center; gap: 16rpx; padding: 80rpx 40rpx; }
.hero-title { font-size: 40rpx; font-weight: 700; color: #FFFFFF; } .placeholder-icon { font-size: 80rpx; }
.hero-sub { font-size: 22rpx; color: rgba(255,255,255,0.7); margin-top: 8rpx; display: block; } .placeholder-text { font-size: 30rpx; font-weight: 600; color: var(--color-text); }
.plans { padding: 0 32rpx; margin-top: -40rpx; display: flex; flex-direction: column; gap: 24rpx; } .placeholder-hint { font-size: 24rpx; color: var(--color-text-tertiary); }
.plan-card { background: #FFFFFF; border-radius: var(--radius-xl); padding: 32rpx; box-shadow: var(--shadow-sm); position: relative; } .placeholder-back { font-size: 26rpx; color: var(--color-primary); padding: 16rpx 40rpx; border-radius: var(--radius-md); background: #F3F4F6; margin-top: 24rpx; }
.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); }
/* 弹窗 */ /* H5 购买页 */
.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; } .hero { display: flex; flex-direction: column; align-items: center; padding: 48rpx 32rpx 24rpx; }
.modal-content { background: #FFF; border-radius: var(--radius-xl); padding: 40rpx; width: 70%; display: flex; flex-direction: column; align-items: center; gap: 20rpx; } .hero-icon { font-size: 72rpx; }
.modal-title { font-size: 28rpx; font-weight: 600; color: var(--color-text); } .hero-title { font-size: 36rpx; font-weight: 700; color: var(--color-text); margin-top: 12rpx; }
.pay-error { color: var(--color-error); } .hero-desc { font-size: 24rpx; color: var(--color-text-secondary); margin-top: 8rpx; text-align: center; }
.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; }
/* 数量选择弹窗 */ .product-card { background: #fff; border-radius: var(--radius-lg); margin: 0 32rpx; padding: 32rpx; box-shadow: var(--shadow-sm); }
.qty-selector { width: 100%; }
.qty-label { font-size: 24rpx; color: #6B7280; margin-bottom: 16rpx; display: block; } .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-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 { 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.disabled { color: #D1D5DB; background: #F9FAFB; }
.qty-btn:active:not(.disabled) { transform: scale(0.9); background: #E5E7EB; } .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); }
.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; } .summary { margin-bottom: 32rpx; }
.qty-unit-price { font-size: 22rpx; color: #6B7280; } .summary-row { display: flex; justify-content: space-between; padding: 12rpx 0; border-bottom: 1rpx solid #F3F4F6; }
.qty-total { font-size: 26rpx; color: var(--color-text); font-weight: 500; } .summary-row.total { border-bottom: none; padding-top: 16rpx; }
.qty-total-num { font-size: 36rpx; font-weight: 800; color: var(--color-primary); } .summary-label { font-size: 24rpx; color: var(--color-text-secondary); }
.qty-actions { width: 100%; display: flex; gap: 16rpx; margin-top: 8rpx; } .summary-val { font-size: 26rpx; font-weight: 600; color: var(--color-text); }
.qty-cancel { flex: 1; text-align: center; padding: 20rpx; border-radius: var(--radius-md); font-size: 26rpx; color: #6B7280; border: 2rpx solid #E5E7EB; } .summary-val.highlight { color: var(--color-primary); }
.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)); } .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> </style>
+88 -30
View File
@@ -55,29 +55,35 @@
<!-- 分享按钮 --> <!-- 分享按钮 -->
<view class="share-actions"> <view class="share-actions">
<!-- #ifdef MP-WEIXIN --> <!-- #ifdef MP-WEIXIN -->
<button class="share-btn wx-share" open-type="share"> <view class="share-btn-row">
<text class="btn-icon">💬</text> <button class="share-btn wx-share" open-type="share">
<text>分享给好友</text> <text class="btn-icon">💬</text>
</button> <text>分享给好友</text>
<button class="share-btn wx-share" open-type="share" data-mode="timeline"> </button>
<text class="btn-icon">🔄</text> <view class="share-btn wx-timeline-hint" @click="showTimelineHint">
<text>分享朋友圈</text> <text class="btn-icon">🔄</text>
</button> <text>分享朋友圈</text>
</view>
</view>
<!-- #endif --> <!-- #endif -->
<!-- #ifdef H5 --> <!-- #ifdef H5 -->
<button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat"> <view class="share-btn-row">
<text class="btn-icon">💬</text> <button class="share-btn wx-share" @click="shareToWechat" v-if="isWechat">
<text>分享给微信好友</text> <text class="btn-icon">💬</text>
</button> <text>分享给微信好友</text>
<button class="share-btn wx-timeline" @click="shareToWechat" v-if="isWechat"> </button>
<text class="btn-icon">🔄</text> <button class="share-btn wx-timeline" @click="shareToWechat" v-if="isWechat">
<text>分享朋友圈</text> <text class="btn-icon">🔄</text>
</button> <text>分享朋友圈</text>
</button>
</view>
<!-- #endif --> <!-- #endif -->
<button class="share-btn link-share" @click="copyLink"> <view class="share-btn-row">
<text class="btn-icon">🔗</text> <button class="share-btn link-share" @click="copyLink">
<text>复制分享链接</text> <text class="btn-icon">🔗</text>
</button> <text>复制分享链接</text>
</button>
</view>
</view> </view>
<!-- Tab 切换 --> <!-- Tab 切换 -->
@@ -137,6 +143,7 @@ import { api } from '../../config'
const tab = ref('records') const tab = ref('records')
const stats = ref({ totalShares: 0, totalVisits: 0, creditedCount: 0, todayCredited: 0, shareCredits: 0, gravity: 0 }) const stats = ref({ totalShares: 0, totalVisits: 0, creditedCount: 0, todayCredited: 0, shareCredits: 0, gravity: 0 })
const shareLink = ref('') const shareLink = ref('')
const shareUrlCached = ref('')
const records = ref([]) const records = ref([])
const visitors = ref([]) const visitors = ref([])
@@ -171,6 +178,21 @@ async function loadData() {
if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return } if (!token) { uni.showToast({ title: '请先登录', icon: 'none' }); return }
const header = { Authorization: `Bearer ${token}` } 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 { try {
const [statsRes, recordsRes, visitorsRes] = await Promise.all([ const [statsRes, recordsRes, visitorsRes] = await Promise.all([
uni.request({ url: api('/share/stats'), method: 'GET', header }), uni.request({ url: api('/share/stats'), method: 'GET', header }),
@@ -194,7 +216,7 @@ async function shareToWechat() {
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' }, data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header: { Authorization: `Bearer ${token}` }, header: { Authorization: `Bearer ${token}` },
}) })
if (res.statusCode !== 200) return if (res.statusCode < 200 || res.statusCode >= 300) return
const data = res.data const data = res.data
const path = data.wechatShareInfo?.path || `/pages/share/share?code=${data.shareCode}` const path = data.wechatShareInfo?.path || `/pages/share/share?code=${data.shareCode}`
@@ -213,19 +235,49 @@ async function shareToWechat() {
async function copyLink() { async function copyLink() {
const token = uni.getStorageSync('token') 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 { try {
const res = await uni.request({ const res = await uni.request({
url: api('/share/create'), url: api('/share/create'), method: 'POST',
method: 'POST',
data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' }, data: { type: 'app', title: '我在AI磁场·职引练习面试', description: 'AI模拟面试+简历优化,快来一起提升吧' },
header: { Authorization: `Bearer ${token}` }, header: { Authorization: `Bearer ${token}` },
}) })
if (res.statusCode !== 200) return if (res.statusCode < 200 || res.statusCode >= 300) {
const shareUrl = `https://zhiyinwx.yzrcloud.cn/share/${res.data.shareCode}` uni.showToast({ title: `创建失败(${res.statusCode}),请重试`, icon: 'none' })
uni.setClipboardData({ data: shareUrl, success: () => { uni.showToast({ title: '链接已复制' }); loadData() } }) return
} catch (e) { console.error(e) } }
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) { function typeLabel(type) {
@@ -270,12 +322,18 @@ function formatTime(t) {
.today-hint { font-size: 18rpx; color: var(--color-text-tertiary); text-align: center; } .today-hint { font-size: 18rpx; color: var(--color-text-tertiary); text-align: center; }
/* Share buttons */ /* Share buttons */
.share-actions { padding: 0 32rpx; display: flex; gap: 20rpx; } .share-actions { padding: 0 32rpx; display: flex; flex-direction: column; gap: 16rpx; }
.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-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); } .share-btn:active { transform: scale(0.96); }
.btn-icon { margin-right: 8rpx; font-size: 28rpx; } .btn-icon { margin-right: 8rpx; font-size: 28rpx; }
.wx-share { background: #07C160; color: #FFFFFF; } .wx-share { background: #07C160; color: #FFFFFF; }
.wx-timeline { background: #FF6600; 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); } .link-share { background: #FFFFFF; color: var(--color-text); border: 2rpx solid var(--color-border); }
/* Tabs */ /* Tabs */
+129 -25
View File
@@ -39,16 +39,21 @@
</view> </view>
</view> </view>
<!-- 配额与会员信息 --> <!-- 引力值卡片代替原配额卡片 -->
<view class="quota-card" v-if="isLoggedIn"> <view class="gravity-card" v-if="isLoggedIn">
<view class="quota-row"> <view class="gravity-card-inner">
<view class="quota-info"> <view class="gravity-top-row">
<text class="quota-plan">{{ memberInfo.planName || '免费版' }}</text> <view class="gravity-header">
<text class="quota-count">引力值 {{ memberInfo.gravity ?? 0 }}</text> <text class="gravity-icon"></text>
</view> <text class="gravity-label">我的引力值</text>
<view class="quota-actions"> </view>
<text class="quota-btn primary" @click="goBuyCredits">补充引力值</text> <text class="gravity-num">{{ memberInfo.gravity ?? 0 }}</text>
<text class="quota-btn" :class="memberInfo.plan !== 'free' ? 'owned' : ''" @click="goUpgrade">{{ memberInfo.plan !== 'free' ? '已开通' : '升级会员' }}</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> </view>
</view> </view>
@@ -72,17 +77,20 @@
<text class="menu-text">面试复盘</text> <text class="menu-text">面试复盘</text>
<text class="menu-arrow"></text> <text class="menu-arrow"></text>
</view> </view>
<!-- 会员中心菜单注释隐藏微信审核 -->
<!--
<view class="menu-item" @click="goVip"> <view class="menu-item" @click="goVip">
<view class="menu-icon-wrap wrap-purple"><text class="menu-icon">💎</text></view> <view class="menu-icon-wrap wrap-purple"><text class="menu-icon">💎</text></view>
<text class="menu-text">会员中心</text> <text class="menu-text">会员中心</text>
<text class="menu-arrow"></text> <text class="menu-arrow"></text>
</view> </view>
-->
<view class="menu-item" @click="requireLogin(goResume, '我的简历')"> <view class="menu-item" @click="requireLogin(goResume, '我的简历')">
<view class="menu-icon-wrap wrap-green"><text class="menu-icon">📄</text></view> <view class="menu-icon-wrap wrap-green"><text class="menu-icon">📄</text></view>
<text class="menu-text">我的简历</text> <text class="menu-text">我的简历</text>
<text class="menu-arrow"></text> <text class="menu-arrow"></text>
</view> </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> <view class="menu-icon-wrap wrap-orange"><text class="menu-icon">📤</text></view>
<text class="menu-text">我的分享</text> <text class="menu-text">我的分享</text>
<text class="menu-arrow"></text> <text class="menu-arrow"></text>
@@ -104,6 +112,46 @@
<button class="logout-btn" @click="doLogout">退出登录</button> <button class="logout-btn" @click="doLogout">退出登录</button>
</view> </view>
</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> </view>
</template> </template>
@@ -179,17 +227,36 @@ const checkAdmin = () => {
} }
const goLogin = () => uni.navigateTo({ url: '/pages/login/login' }) 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' }) 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 goCareer = () => uni.navigateTo({ url: '/pages/career/career' })
const goHistory = () => uni.switchTab({ url: '/pages/history/history' }) const goHistory = () => uni.switchTab({ url: '/pages/history/history' })
const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' }) const goReviewReview = () => uni.navigateTo({ url: '/pages/review/review' })
const goVip = () => uni.navigateTo({ url: '/pages/member/member' }) const goVip = () => uni.navigateTo({ url: '/pages/member/member' })
const goResume = () => uni.navigateTo({ url: '/pages/resume/resume' }) 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 goAdmin = () => uni.navigateTo({ url: '/pages/admin/admin' })
const goAbout = () => uni.navigateTo({ url: '/pages/about/about' }) const goAbout = () => uni.navigateTo({ url: '/pages/about/about' })
@@ -228,16 +295,29 @@ const doLogout = () => {
.guest-info { flex: 1; } .guest-info { flex: 1; }
.guest-name { font-size: 30rpx; font-weight: 600; color: #FFFFFF; } .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; } .gravity-card { margin: -48rpx 32rpx 16rpx; position: relative; z-index: 1; }
.quota-info { display: flex; flex-direction: column; gap: 4rpx; } .gravity-card-inner {
.quota-plan { font-size: 28rpx; font-weight: 700; color: var(--color-text); } background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
.quota-count { font-size: 22rpx; color: #6B7280; } border-radius: var(--radius-xl);
.quota-actions { display: flex; gap: 12rpx; } padding: 28rpx 24rpx 24rpx;
.quota-btn { font-size: 22rpx; padding: 8rpx 20rpx; border-radius: var(--radius-sm); font-weight: 500; white-space: nowrap; } box-shadow: 0 8rpx 32rpx rgba(102,126,234,0.25);
.quota-btn.primary { background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-mid)); color: #FFF; } }
.quota-btn.owned { background: #F3F4F6; color: #9CA3AF; } .gravity-top-row { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8rpx; }
.quota-btn:not(.primary):not(.owned) { background: #FEF3C7; color: #92400E; border: 2rpx solid #F59E0B; } .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-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); } .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-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 { 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); } .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> </style>