4 Commits

Author SHA1 Message Date
yuzhiran 13b2a764ef fix(admin): partial _id fuzzy search via $expr + $toString + $regexMatch 2026-06-22 12:14:31 +08:00
yuzhiran 70c4f28eb5 fix(admin): add wxOpenid to fuzzy search, enhance admin tab info
- Backend getUsers: add wxOpenid to  regex search
- Backend getAdmins: return gravity, plan, wxOpenid, email fields
- Frontend admin tab: show full user info (ID copy, email, gravity, plan)
- Frontend search result: show complete user details like user list rows
2026-06-22 12:07:52 +08:00
yuzhiran d37bbd7a61 feat(admin): fuzzy search by email/ID, display full userId in user list
- Backend: add email + _id to  filter in getUsers() for fuzzy search
- Frontend: show full MongoDB _id in user row with tap-to-copy
- Search placeholder updated to mention email/ID
2026-06-22 11:46:14 +08:00
yuzhiran 4d54c8088c fix: Mongoose 8 pre-save hook crash (next->async), v1.0.17 tag, test user
- user.schema.ts: convert pre-save from callback(next) to async - fixes
  'TypeError: next is not a function' on login (Mongoose 8 compat)
- Tag v1.0.17 for 1.0.18 build cycle
- scripts/seed-test-user.ts: utility to create test accounts
- docs: PROJECT-STATUS v4.9, AGENTS.md version bump
- Add test user test@yzrcloud.cn / 123456 (role: user)
2026-06-22 11:27:21 +08:00
6 changed files with 127 additions and 28 deletions
+3 -3
View File
@@ -202,7 +202,7 @@ cd zhiyin-app && npm run build:mp-weixin && node scripts/upload-mp.js
## 六、项目状态与开发阶段 ## 六、项目状态与开发阶段
**当前**: Phase 1.5(商业化 + 全量部署)— v1.0.17 **当前**: Phase 1.5(商业化 + 全量部署)— v1.0.18(开发中)
| 阶段 | 状态 | 关键交付 | | 阶段 | 状态 | 关键交付 |
|------|------|---------| |------|------|---------|
@@ -259,7 +259,7 @@ VITE_APP_NAME=AI磁场
| 账号 | 密码 | 角色 | 说明 | | 账号 | 密码 | 角色 | 说明 |
|------|------|------|------| |------|------|------|------|
| `13701190814@139.com` | `Zhiyin2024!` | admin | 管理员,可访问管理后台 | | `13701190814@139.com` | `Zhiyin2024!` | admin | 管理员,可访问管理后台 |
| `test@yzrcloud.cn` | `123456` | user | 测试账号 | | `test@yzrcloud.cn` | `123456` | user | 测试账号(普通用户,含 5 引力值) |
| `test@test.com` | 验证码 `123456` | admin | 旧管理员(dev 模式可用) | | `test@test.com` | 验证码 `123456` | admin | 旧管理员(dev 模式可用) |
管理后台路径:`/pages/admin/admin`,进入后自动验证管理员身份(`onMounted``doVerify`)。 管理后台路径:`/pages/admin/admin`,进入后自动验证管理员身份(`onMounted``doVerify`)。
@@ -270,7 +270,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.16`(小程序上传版本 v1.0.17 源自 git tag + 末位自增 1 - 最新 tag: `v1.0.17`(小程序上传版本 v1.0.18 源自 git tag v1.0.17 + 末位自增 1
--- ---
+55
View File
@@ -0,0 +1,55 @@
import { connect, disconnect } from 'mongoose'
import * as bcrypt from 'bcrypt'
import * as dotenv from 'dotenv'
import * as path from 'path'
dotenv.config({ path: path.resolve(__dirname, '../.env') })
async function main() {
const uri = process.env.MONGODB_URI
if (!uri) {
console.error('MONGODB_URI not set')
process.exit(1)
}
const conn = await connect(uri)
console.log('Connected to MongoDB')
const users = conn.connection.db!.collection('users')
const email = 'test@yzrcloud.cn'
const password = '123456'
const hashed = await bcrypt.hash(password, 10)
const existing = await users.findOne({ email })
if (existing) {
await users.updateOne(
{ email },
{ $set: { password: hashed, nickname: '测试用户', role: 'user', gravity: 5, interviewCredits: 1, remaining: 3 } }
)
console.log(`Updated test user: ${email}`)
} else {
await users.insertOne({
email,
password: hashed,
nickname: '测试用户',
role: 'user',
gravity: 5,
interviewCredits: 1,
remaining: 3,
interviewCount: 0,
plan: 'free',
createdAt: new Date(),
updatedAt: new Date(),
})
console.log(`Created test user: ${email}`)
}
await disconnect()
console.log('Done')
}
main().catch(err => {
console.error('Failed:', err)
process.exit(1)
})
@@ -85,7 +85,13 @@ export class AdminController {
filter.$or = [ filter.$or = [
{ phone: { $regex: escaped, $options: 'i' } }, { phone: { $regex: escaped, $options: 'i' } },
{ nickname: { $regex: escaped, $options: 'i' } }, { nickname: { $regex: escaped, $options: 'i' } },
{ email: { $regex: escaped, $options: 'i' } },
{ wxOpenid: { $regex: escaped, $options: 'i' } },
] ]
// 支持按 _id 模糊搜索(ObjectId → string → regex
filter.$or.push({
$expr: { $regexMatch: { input: { $toString: '$_id' }, regex: escaped, options: 'i' } },
})
} }
const skip = (Math.max(1, +page) - 1) * +limit const skip = (Math.max(1, +page) - 1) * +limit
const [users, total] = await Promise.all([ const [users, total] = await Promise.all([
@@ -245,7 +251,7 @@ export class AdminController {
@Get('admins') @Get('admins')
async getAdmins() { async getAdmins() {
const admins = await this.userModel.find({ role: 'admin' }).select('phone nickname email createdAt isSystemAdmin').lean().exec() const admins = await this.userModel.find({ role: 'admin' }).select('phone nickname email wxOpenid gravity plan role createdAt isSystemAdmin').lean().exec()
return { admins } return { admins }
} }
+2 -3
View File
@@ -69,9 +69,8 @@ export class User {
export const UserSchema = SchemaFactory.createForClass(User) export const UserSchema = SchemaFactory.createForClass(User)
UserSchema.pre('save', function (next) { UserSchema.pre('save', async function () {
if (!this.phone && !this.wxOpenid && !this.email) { if (!this.phone && !this.wxOpenid && !this.email) {
return next(new Error('用户必须至少有一个联系方式(手机号/微信/邮箱)')) throw new Error('用户必须至少有一个联系方式(手机号/微信/邮箱)')
} }
next()
}) })
+5 -4
View File
@@ -1,8 +1,8 @@
# 职引项目 · 状态报告 v4.8 # 职引项目 · 状态报告 v4.9
> **项目版本**: v4.8 > **项目版本**: v4.9
> **更新时间**: 2026-06-21 > **更新时间**: 2026-06-22
> **项目状态**: ✅ SEO 优化 + 微信分享全面开启 + 全量部署 > **项目状态**: ✅ Mongoose 8 兼容修复 + v1.0.17 发布
--- ---
@@ -224,6 +224,7 @@
| 日期 | 版本 | 变更内容 | 操作者 | | 日期 | 版本 | 变更内容 | 操作者 |
|------|------|----------|--------| |------|------|----------|--------|
| 2026-06-22 | **v4.9** | **Mongoose 8 兼容修复**pre-save hook 回调→async);v1.0.17 tag 发布;测试账号 test@yzrcloud.cn 重建 | AI |
| 2026-06-21 | **v4.8** | **SEO 全量优化**canonical URL、robots.txt、sitemap.xml、结构化数据);**微信分享全面开启**(13 个页面 onShareAppMessage + onShareTimeline);**版本号自动注入**Vite define __APP_VERSION__);**导航栏/Tab标题关键词优化**;manifest 描述更新;页面描述统一增强 | AI | | 2026-06-21 | **v4.8** | **SEO 全量优化**canonical URL、robots.txt、sitemap.xml、结构化数据);**微信分享全面开启**(13 个页面 onShareAppMessage + onShareTimeline);**版本号自动注入**Vite define __APP_VERSION__);**导航栏/Tab标题关键词优化**;manifest 描述更新;页面描述统一增强 | AI |
| 2026-06-21 | v4.7 | 按量购买引力值体系重构(¥5/份取代月订阅);member.vue 完全重写;微信小程序剪贴板购买链路;客服按钮;管理后台字段全面完善;代码清理;测试数据清理;后端/H5/小程序全量部署上线 | AI | | 2026-06-21 | v4.7 | 按量购买引力值体系重构(¥5/份取代月订阅);member.vue 完全重写;微信小程序剪贴板购买链路;客服按钮;管理后台字段全面完善;代码清理;测试数据清理;后端/H5/小程序全量部署上线 | AI |
| 2026-06-19 | v4.6 | 引力值体系统一:VIP 取消无限面试改为月度引力值消耗;管理后台全面完善(搜索/筛选/分页/CRUD/分析tab/岗位描述字段) | AI | | 2026-06-19 | v4.6 | 引力值体系统一:VIP 取消无限面试改为月度引力值消耗;管理后台全面完善(搜索/筛选/分页/CRUD/分析tab/岗位描述字段) | AI |
+55 -17
View File
@@ -73,7 +73,7 @@
<!-- 用户 --> <!-- 用户 -->
<view v-if="tab === 'users'" class="section"> <view v-if="tab === 'users'" class="section">
<view class="search-bar"> <view class="search-bar">
<input v-model="userKeyword" placeholder="搜索手机号/昵称" class="search-input" @confirm="loadUsers" /> <input v-model="userKeyword" placeholder="搜索手机号/邮箱/昵称/ID" class="search-input" @confirm="loadUsers" />
<button class="search-btn" @click="loadUsers">搜索</button> <button class="search-btn" @click="loadUsers">搜索</button>
</view> </view>
<view class="user-list" v-if="!usersLoading"> <view class="user-list" v-if="!usersLoading">
@@ -87,6 +87,9 @@
<text class="meta-tag email" v-if="u.email">{{ u.email }}</text> <text class="meta-tag email" v-if="u.email">{{ u.email }}</text>
<text class="meta-tag" v-if="u.wxOpenid">openid:{{ u.wxOpenid.slice(0,12) }}..</text> <text class="meta-tag" v-if="u.wxOpenid">openid:{{ u.wxOpenid.slice(0,12) }}..</text>
</view> </view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(u._id)">ID: {{ u._id }}</text>
</view>
<view class="user-meta-row"> <view class="user-meta-row">
<text class="meta-tag">引力:{{ u.gravity ?? 0 }}</text> <text class="meta-tag">引力:{{ u.gravity ?? 0 }}</text>
<text class="meta-tag">面试:{{ u.interviewCount ?? 0 }}</text> <text class="meta-tag">面试:{{ u.interviewCount ?? 0 }}</text>
@@ -488,23 +491,53 @@
</view> </view>
<view class="section-label">当前管理员</view> <view class="section-label">当前管理员</view>
<view class="user-list"> <view class="user-list">
<view class="admin-row" v-for="a in adminList" :key="a._id"> <view class="user-row" v-for="a in adminList" :key="a._id">
<text class="admin-phone">{{ a.phone || '--' }}</text> <view class="user-main">
<text class="admin-name">{{ a.nickname || '--' }}</text> <text class="user-phone">{{ a.phone || '--' }}</text>
<text class="admin-email" v-if="a.email">{{ a.email }}</text> <text class="user-name">{{ a.nickname || '--' }}</text>
<text class="admin-badge" v-if="a.isSystemAdmin">系统</text> <text class="user-badge-role">管理</text>
<text class="time-label" style="margin-left:auto">设置:{{ a.createdAt?.slice(0,10) }}</text> <text class="admin-badge" v-if="a.isSystemAdmin">系统</text>
</view>
<view class="user-meta-row">
<text class="meta-tag email" v-if="a.email">{{ a.email }}</text>
<text class="meta-tag" v-if="a.wxOpenid">openid:{{ a.wxOpenid.slice(0,12) }}..</text>
</view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(a._id)">ID: {{ a._id }}</text>
</view>
<view class="user-meta-row">
<text class="meta-tag">引力:{{ a.gravity ?? 0 }}</text>
<text class="user-plan" :class="{ vip: a.plan === 'growth' || a.plan === 'sprint' }">{{ a.plan === 'growth' || a.plan === 'sprint' ? a.plan==='sprint'?'冲刺':'会员' : '免费' }}</text>
</view>
<view class="user-meta-row time-row">
<text class="time-label">设置:{{ a.createdAt?.slice(0,16).replace('T',' ') }}</text>
</view>
</view> </view>
<text class="empty-text" v-if="adminList.length === 0">暂无管理员</text> <text class="empty-text" v-if="adminList.length === 0">暂无管理员</text>
</view> </view>
<view class="section-label" v-if="searchResult">搜索结果</view> <view class="section-label" v-if="searchResult" style="margin-top:24rpx">搜索结果</view>
<view class="user-list" v-if="searchResult"> <view class="user-list" v-if="searchResult">
<view class="admin-row"> <view class="user-row">
<text class="admin-phone">{{ searchResult.phone || '--' }}</text> <view class="user-main">
<text class="admin-name">{{ searchResult.nickname || '--' }}</text> <text class="user-phone">{{ searchResult.phone || '--' }}</text>
<text class="admin-email" v-if="searchResult.email">{{ searchResult.email }}</text> <text class="user-name">{{ searchResult.nickname || '--' }}</text>
<text class="admin-set-btn" v-if="searchResult.role !== 'admin'" @click="setAdmin(searchResult._id)">设为管理</text> <text class="user-badge-role" v-if="searchResult.role === 'admin'">管理</text>
<text class="admin-set-btn done" v-else>已是管理员</text> </view>
<view class="user-meta-row">
<text class="meta-tag email" v-if="searchResult.email">{{ searchResult.email }}</text>
<text class="meta-tag" v-if="searchResult.wxOpenid">openid:{{ searchResult.wxOpenid.slice(0,12) }}..</text>
</view>
<view class="user-meta-row">
<text class="meta-tag id-tag" @click="copyId(searchResult._id)">ID: {{ searchResult._id }}</text>
</view>
<view class="user-meta-row">
<text class="meta-tag">引力:{{ searchResult.gravity ?? 0 }}</text>
<text class="user-plan" :class="{ vip: searchResult.plan === 'growth' || searchResult.plan === 'sprint' }">{{ searchResult.plan === 'growth' || searchResult.plan === 'sprint' ? searchResult.plan==='sprint'?'冲刺':'会员' : '免费' }}</text>
</view>
<view class="user-actions" style="margin-top:8rpx">
<text class="admin-set-btn" v-if="searchResult.role !== 'admin'" @click="setAdmin(searchResult._id)">设为管理员</text>
<text class="admin-set-btn done" v-else>已是管理员</text>
</view>
</view> </view>
</view> </view>
</view> </view>
@@ -1028,6 +1061,13 @@ const doAdjustCredits = async () => {
} catch { uni.showToast({ title: '调整失败', icon: 'none' }) } } catch { uni.showToast({ title: '调整失败', icon: 'none' }) }
} }
const copyId = (id) => {
uni.setClipboardData({
data: id,
success: () => uni.showToast({ title: 'ID 已复制', icon: 'success' }),
})
}
onMounted(() => { doVerify() }) onMounted(() => { doVerify() })
</script> </script>
@@ -1080,9 +1120,6 @@ onMounted(() => { doVerify() })
.iv-tag.score { background: #EEF2FF; color: var(--color-primary); } .iv-tag.score { background: #EEF2FF; color: var(--color-primary); }
.iv-tag.filler { background: #FFF7ED; color: #D97706; } .iv-tag.filler { background: #FFF7ED; color: #D97706; }
.section-label { font-size: 24rpx; font-weight: 600; color: var(--color-text); margin-bottom: 12rpx; margin-top: 12rpx; } .section-label { font-size: 24rpx; font-weight: 600; color: var(--color-text); margin-bottom: 12rpx; margin-top: 12rpx; }
.admin-row { background: #FFF; padding: 20rpx; border-radius: var(--radius-sm); margin-bottom: 8rpx; display: flex; flex-wrap: wrap; gap: 8rpx; align-items: center; }
.admin-phone { font-size: 24rpx; font-weight: 600; color: var(--color-text); }
.admin-name { font-size: 22rpx; color: var(--color-text-secondary); flex: 1; }
.admin-set-btn { font-size: 22rpx; color: var(--color-primary); padding: 4rpx 16rpx; border: 2rpx solid var(--color-primary); border-radius: var(--radius-round); } .admin-set-btn { font-size: 22rpx; color: var(--color-primary); padding: 4rpx 16rpx; border: 2rpx solid var(--color-primary); border-radius: var(--radius-round); }
.admin-set-btn.done { color: var(--color-success); border-color: var(--color-success); } .admin-set-btn.done { color: var(--color-success); border-color: var(--color-success); }
.admin-badge { font-size: 18rpx; background: var(--color-primary); color: #FFF; padding: 2rpx 10rpx; border-radius: var(--radius-round); } .admin-badge { font-size: 18rpx; background: var(--color-primary); color: #FFF; padding: 2rpx 10rpx; border-radius: var(--radius-round); }
@@ -1162,6 +1199,7 @@ onMounted(() => { doVerify() })
.meta-tag { font-size: 18rpx; background: #F3F4F6; color: var(--color-text-tertiary); padding: 2rpx 10rpx; border-radius: var(--radius-round); } .meta-tag { font-size: 18rpx; background: #F3F4F6; color: var(--color-text-tertiary); padding: 2rpx 10rpx; border-radius: var(--radius-round); }
.meta-tag.email { background: #EEF2FF; color: var(--color-primary); } .meta-tag.email { background: #EEF2FF; color: var(--color-primary); }
.meta-tag.share { background: #FFF7ED; color: #D97706; } .meta-tag.share { background: #FFF7ED; color: #D97706; }
.meta-tag.id-tag { background: #F5F3FF; color: #7C3AED; font-family: monospace; font-size: 16rpx; }
.meta-tag.badge-done { background: #ECFDF5; color: #059669; } .meta-tag.badge-done { background: #ECFDF5; color: #059669; }
.meta-tag.badge-pend { background: #FEF3C7; color: #D97706; } .meta-tag.badge-pend { background: #FEF3C7; color: #D97706; }
.time-row { display: flex; flex-wrap: wrap; gap: 12rpx; } .time-row { display: flex; flex-wrap: wrap; gap: 12rpx; }