| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- <template>
- <view class="quality-resources">
- <!-- 顶部导航栏 -->
- <view class="header">
- <view class="back-icon" @click="handleBack"></view>
- <text class="header-title">优质资源</text>
- <view class="filter-icon" @click="handleFilter"></view>
- </view>
- <!-- 搜索栏 -->
- <view class="search-bar">
- <view class="search-input-wrapper">
- <view class="search-icon-small"></view>
- <input type="text" class="search-input" placeholder="请输入搜索关键词" placeholder-style="color: #999;" v-model="searchKeyword" @input="handleSearch" />
- </view>
- </view>
- <!-- 资源列表 -->
- <scroll-view scroll-y class="content" @scrolltolower="loadMore" :scroll-with-animation="true">
- <view v-if="loading" class="loading-wrapper">
- <text class="loading-text">加载中...</text>
- </view>
- <view v-else-if="resources.length === 0" class="empty-wrapper">
- <text class="empty-text">暂无优质资源</text>
- </view>
- <view class="resource-item" v-for="(resource, index) in resources" :key="getResourceKey(resource, index)" @click="handleResourceClick(index)">
- <view class="resource-header">
- <image
- :src="getAvatarUrl(resource) || '/static/default-avatar.svg'"
- mode="aspectFill"
- class="avatar"
- @error="handleImageError(index)"
- ></image>
- <view class="resource-info">
- <view class="name-gender">
- <text class="name">{{ resource.name }}</text>
- <text class="gender">{{ resource.gender === 1 ? '男' : '女' }}</text>
- </view>
- <view class="status-tag-wrapper">
- <text class="status-tag register-tag registered">已注册</text>
- <text class="status-tag match-tag" :class="{ 'matched': getIsMatch(resource) === 1, 'unmatched': getIsMatch(resource) === 0 || !getIsMatch(resource) }">
- {{ getIsMatch(resource) === 1 ? '已匹配' : '未匹配' }}
- </text>
- </view>
- </view>
- </view>
- <view class="resource-details">
- <view class="labels" v-if="resource.tags && resource.tags.length > 0">
- <text class="label" v-for="(tag, tagIndex) in resource.tags" :key="tagIndex">{{ tag }}</text>
- </view>
- <view class="requirement-box">
- <text class="requirement-label">择偶要求:</text>
- <text class="requirement-content">{{ getMateSelectionCriteria(resource) || '暂无' }}</text>
- </view>
- <view class="contact-box">
- <text class="contact-label">联系方式:</text>
- <text class="contact-number">{{ getMaskedPhone(resource.phone) || '暂无' }}</text>
- <text class="copy-btn" @click.stop="handleCopy(resource.phone)">复制</text>
- </view>
- <view class="action-buttons">
- <view class="action-btn add-resource-btn" @click.stop="handleAddToMyResources(index)">添加到我的资源</view>
- <view class="action-btn chat-btn" @click.stop="handleChat(resource, index)">牵线聊聊</view>
- </view>
- </view>
- </view>
- <view v-if="hasMore && !loading" class="load-more-wrapper">
- <text class="load-more-text">上拉加载更多</text>
- </view>
- <view v-if="!hasMore && resources.length > 0" class="no-more-wrapper">
- <text class="no-more-text">没有更多数据了</text>
- </view>
- </scroll-view>
- </view>
- </template>
- <script>
- export default {
- name: 'quality-resources',
- data() {
- return {
- resources: [],
- searchKeyword: '',
- pageNum: 1,
- pageSize: 10,
- loading: false,
- hasMore: true,
- currentUserId: null // 当前登录用户的用户ID
- }
- },
- onLoad() {
- // 获取当前登录用户的ID
- const userId = uni.getStorageSync('userId')
- if (userId) {
- const rawUserId = parseInt(userId)
- if (!isNaN(rawUserId) && rawUserId > 0) {
- this.currentUserId = rawUserId
- console.log('当前登录用户ID:', this.currentUserId)
- }
- }
- this.loadResources()
- },
- methods: {
- // 返回上一页
- handleBack() {
- uni.navigateBack()
- },
- // 筛选
- handleFilter() {
- // 实现筛选功能
- },
- // 搜索
- handleSearch() {
- this.pageNum = 1
- this.resources = []
- this.hasMore = true
- this.loadResources()
- },
- // 加载资源列表
- async loadResources() {
- if (this.loading) return
-
- try {
- this.loading = true
- const baseUrl = process.env.NODE_ENV === 'development'
- ? 'http://localhost:8083/api' // 开发环境 - 通过网关
- : 'https://your-domain.com/api' // 生产环境
-
- // 构建请求参数
- const requestData = {
- tagName: '优质资源',
- keyword: this.searchKeyword || '',
- pageNum: this.pageNum,
- pageSize: this.pageSize
- }
-
- // 如果已登录,传递currentUserId,用于排除该红娘已拥有的资源
- if (this.currentUserId) {
- requestData.currentUserId = this.currentUserId
- }
-
- const [error, res] = await uni.request({
- url: `${baseUrl}/my-resource/list-by-tag`,
- method: 'GET',
- data: requestData,
- timeout: 10000
- })
-
- if (error) {
- console.error('加载优质资源失败:', error)
- uni.showToast({
- title: '加载失败',
- icon: 'none'
- })
- return
- }
-
- if (res.statusCode === 200 && res.data && res.data.code === 200) {
- const pageData = res.data.data
- if (pageData && pageData.records) {
- // 调试:打印第一条数据的详细信息
- if (pageData.records.length > 0) {
- const firstRecord = pageData.records[0]
- console.log('=== 第一条资源数据 ===')
- console.log('完整数据:', JSON.stringify(firstRecord, null, 2))
- console.log('isUser值:', firstRecord.isUser, '类型:', typeof firstRecord.isUser)
- console.log('is_user值:', firstRecord.is_user, '类型:', typeof firstRecord.is_user)
- console.log('userId值:', firstRecord.userId, '类型:', typeof firstRecord.userId)
- console.log('user_id值:', firstRecord.user_id, '类型:', typeof firstRecord.user_id)
- console.log('mateSelectionCriteria (驼峰):', firstRecord.mateSelectionCriteria)
- console.log('mate_selection_criteria (下划线):', firstRecord.mate_selection_criteria)
- console.log('phone:', firstRecord.phone)
- }
-
- // 过滤掉空元素,确保数组中不包含 null 或 undefined
- const validRecords = pageData.records.filter(record => record !== null && record !== undefined)
-
- if (this.pageNum === 1) {
- this.resources = validRecords
- } else {
- this.resources = this.resources.concat(validRecords)
- }
-
- // 判断是否还有更多数据
- this.hasMore = pageData.records && pageData.records.length >= this.pageSize
-
- console.log('加载优质资源成功,数量:', this.resources.length)
- } else {
- console.error('加载优质资源失败:', res.data.message)
- }
- } else {
- console.error('加载优质资源失败:', res.data.message)
- uni.showToast({
- title: res.data.message || '加载失败',
- icon: 'none'
- })
- }
- } catch (e) {
- console.error('加载优质资源异常:', e)
- uni.showToast({
- title: '加载异常',
- icon: 'none'
- })
- } finally {
- this.loading = false
- }
- },
- // 加载更多
- loadMore() {
- if (this.hasMore && !this.loading) {
- this.pageNum++
- this.loadResources()
- }
- },
- // 图片加载错误处理
- handleImageError(index) {
- if (this.resources[index]) {
- // 设置头像为空,让CSS默认背景显示
- // 支持下划线和驼峰两种格式
- this.resources[index].avatarUrl = ''
- this.resources[index].avatar_url = ''
- this.resources[index].avatar = ''
- }
- },
- // 复制联系方式
- handleCopy(contact) {
- if (!contact) {
- uni.showToast({
- title: '联系方式为空',
- icon: 'none'
- })
- return
- }
- uni.setClipboardData({
- data: contact,
- success: () => {
- uni.showToast({
- title: '复制成功',
- icon: 'success'
- })
- }
- })
- },
- // 牵线聊聊
- handleChat(resource, index) {
- console.log('=== 牵线聊聊 ===')
- console.log('传入的resource:', resource)
- console.log('传入的index:', index, '类型:', typeof index)
- console.log('resources数组长度:', this.resources ? this.resources.length : 'resources未定义')
-
- // 优先使用传入的 resource 对象,如果为空则通过 index 获取
- let targetResource = resource
-
- // 如果传入的 resource 为空,尝试通过 index 获取
- if (!targetResource || targetResource === null || targetResource === undefined) {
- console.warn('⚠️ 传入的resource为空,尝试通过index获取')
-
- // 检查 resources 数组是否存在
- if (!this.resources || !Array.isArray(this.resources)) {
- console.error('❌ resources数组不存在或不是数组')
- uni.showToast({
- title: '资源列表异常,请刷新重试',
- icon: 'none'
- })
- return
- }
-
- // 检查index是否有效
- if (index === undefined || index === null || isNaN(index) || index < 0 || index >= this.resources.length) {
- console.error('❌ index无效:', index, '数组长度:', this.resources.length)
- console.log('resources数组内容:', JSON.stringify(this.resources, null, 2))
- uni.showToast({
- title: '资源索引无效',
- icon: 'none'
- })
- return
- }
-
- // 从数组中获取resource对象
- targetResource = this.resources[index]
- console.log('从数组获取的resource对象:', targetResource)
- }
-
- console.log('最终使用的resource对象:', targetResource)
- console.log('资源信息类型:', typeof targetResource)
- console.log('资源信息是否为null:', targetResource === null)
- console.log('资源信息是否为undefined:', targetResource === undefined)
- console.log('资源信息的所有键:', targetResource ? Object.keys(targetResource) : 'resource为空')
-
- // 验证 resource 对象是否存在
- if (!targetResource || targetResource === null || targetResource === undefined) {
- console.error('❌ resource对象为空')
- console.error('传入的resource:', resource)
- console.error('传入的index:', index)
- console.error('resources数组:', JSON.stringify(this.resources, null, 2))
- if (index !== undefined && index !== null && !isNaN(index) && index >= 0 && index < (this.resources ? this.resources.length : 0)) {
- console.error('resources[index]:', this.resources[index])
- }
- uni.showToast({
- title: '资源信息为空,请刷新重试',
- icon: 'none',
- duration: 3000
- })
- return
- }
-
- // 使用 targetResource 继续后续处理
- // 检查用户是否已注册(只有已注册用户才能聊天)
- // 支持下划线和驼峰两种格式
- const isUser = targetResource.isUser !== undefined ? targetResource.isUser :
- (targetResource.is_user !== undefined ? targetResource.is_user : 0)
- if (isUser !== 1 && isUser !== '1') {
- console.warn('⚠️ 用户未注册,无法聊天')
- uni.showToast({
- title: '该用户尚未注册,无法聊天',
- icon: 'none',
- duration: 3000
- })
- return
- }
-
- // 尝试多种方式获取用户ID
- let targetUserId = null
-
- // 方式1: 使用 userId 字段(驼峰格式)
- if (targetResource.userId !== null && targetResource.userId !== undefined && targetResource.userId !== '') {
- targetUserId = String(targetResource.userId)
- console.log('✅ 从 targetResource.userId 获取用户ID:', targetUserId)
- }
- // 方式2: 使用 user_id 字段(下划线格式)
- else if (targetResource.user_id !== null && targetResource.user_id !== undefined && targetResource.user_id !== '') {
- targetUserId = String(targetResource.user_id)
- console.log('✅ 从 targetResource.user_id 获取用户ID:', targetUserId)
- }
- // 方式3: 使用 id 字段
- else if (targetResource.id !== null && targetResource.id !== undefined && targetResource.id !== '') {
- targetUserId = String(targetResource.id)
- console.log('✅ 从 targetResource.id 获取用户ID:', targetUserId)
- }
-
- // 如果仍然没有获取到用户ID
- if (!targetUserId || targetUserId === 'null' || targetUserId === 'undefined' || targetUserId === '') {
- console.error('❌ 无法获取用户ID')
- console.log('targetResource对象完整内容:', JSON.stringify(targetResource, null, 2))
- uni.showToast({
- title: '无法获取用户ID,请刷新重试',
- icon: 'none',
- duration: 3000
- })
- return
- }
-
- // 获取其他必要信息(支持下划线和驼峰格式)
- const targetUserName = targetResource.name || '用户'
- const targetUserAvatar = targetResource.avatarUrl || targetResource.avatar_url || targetResource.avatar || '/static/default-avatar.svg'
-
- console.log('跳转参数:')
- console.log(' - targetUserId:', targetUserId)
- console.log(' - targetUserName:', targetUserName)
- console.log(' - targetUserAvatar:', targetUserAvatar)
-
- // 跳转到聊天页面
- // 注意:fromMatchmaker=1 表示来自红娘工作台,会跳过消息限制和审核
- uni.navigateTo({
- url: `/pages/message/chat?targetUserId=${targetUserId}&targetUserName=${encodeURIComponent(targetUserName)}&targetUserAvatar=${encodeURIComponent(targetUserAvatar)}&fromMatchmaker=1`,
- success: () => {
- console.log('✅ 跳转聊天页面成功')
- },
- fail: (err) => {
- console.error('❌ 跳转聊天页面失败:', err)
- uni.showToast({
- title: '跳转失败,请重试',
- icon: 'none'
- })
- }
- })
- },
- // 获取资源项的key(用于v-for)
- getResourceKey(resource, index) {
- if (!resource) return `resource-${index}`
- // 支持下划线和驼峰两种格式
- const resourceId = resource.resourceId || resource.resource_id
- if (resourceId !== null && resourceId !== undefined && resourceId !== '') {
- return `resource-${resourceId}`
- }
- return `resource-${index}`
- },
- // 点击资源项
- handleResourceClick(index) {
- console.log('=== 点击资源项 ===')
- console.log('传入的index:', index)
- console.log('resources数组长度:', this.resources.length)
-
- // 检查index是否有效
- if (index === undefined || index === null || index < 0 || index >= this.resources.length) {
- console.error('❌ index无效:', index)
- uni.showToast({
- title: '资源索引无效',
- icon: 'none'
- })
- return
- }
-
- // 从数组中获取resource对象
- const resource = this.resources[index]
- console.log('从数组获取的resource对象:', JSON.stringify(resource, null, 2))
-
- if (!resource) {
- console.error('❌ resource对象为空')
- uni.showToast({
- title: '资源信息为空',
- icon: 'none'
- })
- return
- }
-
- // 支持下划线和驼峰两种格式
- const resourceId = resource.resourceId || resource.resource_id
- const isUser = resource.isUser !== undefined ? resource.isUser :
- (resource.is_user !== undefined ? resource.is_user : 0)
-
- console.log('resource.resourceId:', resourceId)
- console.log('resource.isUser:', isUser)
-
- // 检查resourceId是否有效
- if (!resourceId || resourceId === null || resourceId === undefined || resourceId === '') {
- console.error('❌ resourceId无效:', resourceId)
- uni.showToast({
- title: '资源ID无效,无法查看详情',
- icon: 'none'
- })
- return
- }
-
- // 判断是否为已注册用户
- if (isUser === 1 || isUser === '1') {
- // 已注册,跳转到客户详情页面,添加fromQualityResources参数标识来源
- console.log('准备跳转,resourceId:', resourceId)
- uni.navigateTo({
- url: `/pages/matchmaker-workbench/client-detail?resourceId=${resourceId}&fromQualityResources=1`,
- success: () => {
- console.log('✅ 跳转成功,resourceId:', resourceId)
- },
- fail: (err) => {
- console.error('❌ 跳转失败:', err)
- uni.showToast({
- title: '跳转失败,请重试',
- icon: 'none'
- })
- }
- })
- } else {
- // 未注册,提示用户(虽然后端已经过滤了,但为了容错仍然保留)
- uni.showToast({
- title: '该用户还未注册用户端',
- icon: 'none',
- duration: 2000
- })
- }
- },
- // 添加到我的资源
- async handleAddToMyResources(index) {
- console.log('=== 添加到我的资源 ===')
- console.log('index:', index)
-
- // 检查index是否有效
- if (index === undefined || index === null || index < 0 || index >= this.resources.length) {
- console.error('❌ index无效:', index)
- uni.showToast({
- title: '资源索引无效',
- icon: 'none'
- })
- return
- }
-
- // 从数组中获取resource对象
- const resource = this.resources[index]
- console.log('从数组获取的resource对象:', JSON.stringify(resource, null, 2))
-
- if (!resource) {
- console.error('❌ resource对象为空')
- uni.showToast({
- title: '资源信息为空',
- icon: 'none'
- })
- return
- }
-
- // 检查是否已登录
- if (!this.currentUserId) {
- uni.showToast({
- title: '请先登录',
- icon: 'none'
- })
- return
- }
-
- try {
- uni.showLoading({
- title: '检查中...'
- })
-
- const baseUrl = process.env.NODE_ENV === 'development'
- ? 'http://localhost:8083/api' // 开发环境 - 通过网关
- : 'https://your-domain.com/api' // 生产环境
-
- // 获取要添加的手机号和备用手机号
- const phone = resource.phone
- const backupPhone = resource.backupPhone || resource.backup_phone
-
- // 检查手机号是否已存在(检查整个my_resource表,不限制红娘)
- const checkUrl = `${baseUrl}/my-resource/check-phone?phone=${encodeURIComponent(phone || '')}${backupPhone ? '&backupPhone=' + encodeURIComponent(backupPhone) : ''}`
- const [checkError, checkRes] = await uni.request({
- url: checkUrl,
- method: 'GET'
- })
-
- if (checkError) {
- console.error('检查手机号失败:', checkError)
- uni.hideLoading()
- uni.showToast({
- title: '检查手机号失败,请重试',
- icon: 'none'
- })
- return
- }
-
- if (checkRes.statusCode === 200 && checkRes.data && checkRes.data.code === 200) {
- const checkResult = checkRes.data.data
- const existingResource = checkResult.existingResource
-
- // 如果发现重复的手机号,提示用户
- if (checkResult.phoneExists || checkResult.backupPhoneExists || checkResult.phoneAsBackupExists || checkResult.backupPhoneAsMainExists) {
- let message = '该手机号已经绑定资源啦'
-
- // 根据不同的检查结果,显示具体的手机号类型
- if (checkResult.phoneExists) {
- message = '该主手机号已经绑定资源啦'
- } else if (checkResult.phoneAsBackupExists) {
- message = '该主手机号已经作为备用手机号绑定资源啦'
- } else if (checkResult.backupPhoneAsMainExists) {
- message = '该备用手机号已经作为主手机号绑定资源啦'
- } else if (checkResult.backupPhoneExists) {
- message = '该备用手机号已经绑定资源啦'
- }
-
- uni.hideLoading()
- uni.showToast({
- title: message,
- icon: 'none',
- duration: 3000
- })
- return
- }
- }
-
- // 构建要添加的资源数据(复制原资源的所有信息,但使用当前红娘的matchmaker_id)
- const resourceData = {
- name: resource.name,
- age: resource.age,
- gender: resource.gender,
- constellation: resource.constellation,
- height: resource.height,
- weight: resource.weight,
- marrStatus: resource.marrStatus || resource.marr_status,
- diploma: resource.diploma,
- income: resource.income,
- address: resource.address,
- domicile: resource.domicile,
- occupation: resource.occupation,
- house: resource.house,
- phone: phone,
- backupPhone: backupPhone,
- car: resource.car,
- mateSelectionCriteria: resource.mateSelectionCriteria || resource.mate_selection_criteria,
- isUser: resource.isUser || resource.is_user || 1,
- userId: resource.userId || resource.user_id
- }
-
- uni.showLoading({
- title: '添加中...'
- })
-
- // 获取标签ID列表
- let tagIds = []
-
- // 方法1: 如果resource有resourceId,直接根据resourceId获取标签ID
- const resourceId = resource.resourceId || resource.resource_id
- if (resourceId) {
- try {
- const [tagError, tagRes] = await uni.request({
- url: `${baseUrl}/my-resource/tag-ids/${resourceId}`,
- method: 'GET'
- })
-
- if (!tagError && tagRes.statusCode === 200 && tagRes.data && tagRes.data.code === 200) {
- tagIds = tagRes.data.data || []
- console.log('根据resourceId获取的标签ID:', tagIds)
- }
- } catch (e) {
- console.warn('根据resourceId获取标签ID失败,将使用标签名称查询:', e)
- }
- }
-
- // 方法2: 如果方法1失败或没有resourceId,根据标签名称查询标签ID
- if (tagIds.length === 0 && resource.tags && resource.tags.length > 0) {
- try {
- // 获取所有标签列表
- const [tagListError, tagListRes] = await uni.request({
- url: `${baseUrl}/tag/list`,
- method: 'GET'
- })
-
- if (!tagListError && tagListRes.statusCode === 200 && tagListRes.data && tagListRes.data.code === 200) {
- const allTags = tagListRes.data.data || []
- console.log('所有标签列表:', allTags)
-
- // 根据标签名称匹配标签ID
- for (const tagName of resource.tags) {
- const matchedTag = allTags.find(tag => {
- const tagNameField = tag.name || tag.tag_name || tag.tagName
- return tagNameField === tagName
- })
-
- if (matchedTag) {
- const tagId = matchedTag.id || matchedTag.tag_id
- if (tagId && !tagIds.includes(tagId)) {
- tagIds.push(tagId)
- console.log(`找到标签 "${tagName}" 的ID:`, tagId)
- }
- } else {
- console.warn(`未找到标签 "${tagName}" 的ID`)
- }
- }
-
- console.log('根据标签名称查询到的标签ID列表:', tagIds)
- }
- } catch (e) {
- console.error('根据标签名称查询标签ID异常:', e)
- }
- }
-
- // 确保tagIds是整数数组
- tagIds = tagIds.map(id => parseInt(id)).filter(id => !isNaN(id) && id > 0)
-
- if (tagIds.length === 0) {
- console.warn('⚠️ 未获取到任何标签ID,资源将不包含标签')
- } else {
- console.log('✅ 最终获取到的标签ID列表:', tagIds)
- }
-
- // 调用后端API添加资源
- const url = `${baseUrl}/my-resource/add?currentUserId=${this.currentUserId}`
- console.log('添加资源请求URL:', url)
- console.log('添加资源数据:', JSON.stringify(resourceData, null, 2))
- console.log('标签ID列表:', tagIds)
-
- const [error, res] = await uni.request({
- url: url,
- method: 'POST',
- data: {
- ...resourceData,
- tagIds: tagIds
- },
- header: {
- 'Content-Type': 'application/json'
- }
- })
-
- uni.hideLoading()
-
- if (error) {
- console.error('添加到我的资源失败:', error)
- uni.showToast({
- title: '添加失败,请重试',
- icon: 'none'
- })
- return
- }
-
- if (res.statusCode === 200 && res.data && res.data.code === 200) {
- uni.showToast({
- title: '添加成功',
- icon: 'success'
- })
-
- // 发送刷新事件,通知我的资源页面刷新列表
- uni.$emit('refreshResourceList')
- } else {
- console.error('添加到我的资源失败:', res.data.message)
- uni.showToast({
- title: res.data.message || '添加失败',
- icon: 'none',
- duration: 2000
- })
- }
- } catch (e) {
- uni.hideLoading()
- console.error('添加到我的资源异常:', e)
- uni.showToast({
- title: '添加异常,请稍后重试',
- icon: 'none'
- })
- }
- },
- // 获取头像URL(支持驼峰和下划线格式)
- getAvatarUrl(resource) {
- if (!resource) return ''
- // 优先使用 avatarUrl(驼峰),如果没有则使用 avatar_url(下划线),最后使用 avatar
- return resource.avatarUrl || resource.avatar_url || resource.avatar || ''
- },
- // 获取匹配状态(支持驼峰和下划线格式)
- getIsMatch(resource) {
- if (!resource) return 0
- // 支持 isMatch(驼峰)和 is_match(下划线)两种格式
- return resource.isMatch !== undefined ? resource.isMatch :
- (resource.is_match !== undefined ? resource.is_match : 0)
- },
- // 获取择偶要求(支持驼峰和下划线格式)
- getMateSelectionCriteria(resource) {
- if (!resource) {
- console.warn('getMateSelectionCriteria: resource为空')
- return ''
- }
-
- // 支持 mateSelectionCriteria(驼峰)和 mate_selection_criteria(下划线)两种格式
- let criteria = resource.mateSelectionCriteria || resource.mate_selection_criteria || ''
-
- // 如果为空,直接返回
- if (!criteria || criteria.trim() === '') {
- return ''
- }
-
- // 去除首尾空格
- criteria = criteria.trim()
-
- // 如果获取到的是电话号码格式(11位数字或脱敏后的格式),则返回空字符串,让模板显示"暂无"
- // 检查是否是纯数字(11位)或包含****的脱敏格式
- const phonePattern = /^(\d{3}\*{4}\d{4}|\d{11})$/
- if (phonePattern.test(criteria)) {
- console.warn('⚠️ 择偶要求字段包含电话号码格式,返回空字符串', {
- criteria: criteria,
- phone: resource.phone,
- 'resource完整对象': resource
- })
- return ''
- }
-
- // 如果择偶要求等于电话号码(未脱敏),也返回空
- if (criteria === resource.phone || criteria === (resource.phone || '').replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')) {
- console.warn('⚠️ 择偶要求等于电话号码,返回空字符串', {
- criteria: criteria,
- phone: resource.phone
- })
- return ''
- }
-
- return criteria
- },
- // 获取脱敏手机号
- getMaskedPhone(phone) {
- if (!phone) return ''
- // 手机号脱敏:显示前3位和后4位,中间用****代替
- return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .quality-resources {
- min-height: 100vh;
- background: #FFF9F9;
- display: flex;
- flex-direction: column;
- }
- /* 顶部导航栏 */
- .header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 25rpx 30rpx;
- padding-top: calc(25rpx + env(safe-area-inset-top));
- background: #FFF9F9;
- border-bottom: 1rpx solid #F0F0F0;
- .back-icon {
- width: 44rpx;
- height: 44rpx;
- background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%239C27B0"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"/></svg>');
- background-size: contain;
- background-repeat: no-repeat;
- background-position: center;
- }
- .header-title {
- font-size: 38rpx;
- font-weight: bold;
- color: #9C27B0;
- }
- .filter-icon {
- width: 44rpx;
- height: 44rpx;
- background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M10 18h4v-2h-4v2zM3 6v2h18V6H3zm3 7h12v-2H6v2z"/></svg>');
- background-size: contain;
- background-repeat: no-repeat;
- background-position: center;
- }
- }
- /* 搜索栏 */
- .search-bar {
- padding: 20rpx 30rpx;
- background: #FFF9F9;
- .search-input-wrapper {
- display: flex;
- align-items: center;
- background: #FFFFFF;
- border-radius: 25rpx;
- padding: 15rpx 20rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
- .search-icon-small {
- width: 32rpx;
- height: 32rpx;
- background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23999"><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"/></svg>');
- background-size: contain;
- background-repeat: no-repeat;
- background-position: center;
- margin-right: 15rpx;
- }
- .search-input {
- flex: 1;
- font-size: 28rpx;
- color: #333;
- placeholder-color: #999;
- }
- }
- }
- /* 内容区域 */
- .content {
- flex: 1;
- padding: 0 30rpx 20rpx;
- }
- /* 资源列表项 */
- .resource-item {
- background: #FFFFFF;
- border-radius: 20rpx;
- padding: 25rpx;
- margin-bottom: 20rpx;
- box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
- }
- .resource-header {
- display: flex;
- align-items: flex-start;
- margin-bottom: 20rpx;
- .avatar {
- width: 100rpx;
- height: 100rpx;
- border-radius: 50%;
- background: #F0F0F0;
- margin-right: 20rpx;
- flex-shrink: 0;
- }
- .resource-info {
- flex: 1;
- .name-gender {
- display: flex;
- align-items: center;
- gap: 15rpx;
- margin-bottom: 10rpx;
- .name {
- font-size: 32rpx;
- font-weight: bold;
- color: #333;
- }
- .gender {
- font-size: 24rpx;
- color: #999;
- padding: 4rpx 12rpx;
- background: #F5F5F5;
- border-radius: 12rpx;
- }
- }
- .status-tag-wrapper {
- display: flex;
- align-items: center;
- gap: 10rpx;
- margin-bottom: 10rpx;
- .status-tag {
- font-size: 22rpx;
- padding: 6rpx 14rpx;
- border-radius: 12rpx;
- font-weight: 500;
- &.register-tag {
- &.registered {
- color: #4CAF50;
- background: #E8F5E9;
- border: 1rpx solid #C8E6C9;
- }
- }
- &.match-tag {
- &.matched {
- color: #2196F3;
- background: #E3F2FD;
- border: 1rpx solid #BBDEFB;
- }
- &.unmatched {
- color: #FF9800;
- background: #FFF3E0;
- border: 1rpx solid #FFE0B2;
- }
- }
- }
- }
- }
- }
- .resource-details {
- .labels {
- display: flex;
- flex-wrap: wrap;
- gap: 10rpx;
- margin-bottom: 15rpx;
- .label {
- display: inline-block;
- padding: 6rpx 14rpx;
- background: #F3E5F5;
- color: #9C27B0;
- border-radius: 15rpx;
- font-size: 22rpx;
- font-weight: 500;
- }
- }
- .requirement-box {
- background: #F3E5F5;
- border-radius: 12rpx;
- padding: 16rpx 20rpx;
- margin-bottom: 15rpx;
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- .requirement-label {
- font-size: 28rpx;
- color: #7B1FA2;
- font-weight: 500;
- margin-right: 8rpx;
- white-space: nowrap;
- }
- .requirement-content {
- font-size: 28rpx;
- color: #7B1FA2;
- font-weight: 400;
- }
- }
- .contact-box {
- margin-bottom: 20rpx;
- display: flex;
- align-items: center;
- flex-wrap: wrap;
- .contact-label {
- font-size: 26rpx;
- color: #333;
- font-weight: 500;
- margin-right: 10rpx;
- white-space: nowrap;
- }
- .contact-number {
- flex: 1;
- font-size: 26rpx;
- color: #333;
- font-weight: 400;
- min-width: 0;
- }
- .copy-btn {
- font-size: 24rpx;
- color: #9C27B0;
- font-weight: 500;
- margin-left: 15rpx;
- white-space: nowrap;
- cursor: pointer;
- }
- }
- .action-buttons {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- gap: 15rpx;
- .action-btn {
- padding: 14rpx 30rpx;
- border-radius: 25rpx;
- font-size: 26rpx;
- font-weight: 500;
- text-align: center;
-
- &.add-resource-btn {
- background: #FF9800;
- color: #FFFFFF;
- }
-
- &.chat-btn {
- background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
- color: #FFFFFF;
- }
- }
- }
- }
- .loading-wrapper,
- .empty-wrapper,
- .load-more-wrapper,
- .no-more-wrapper {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 40rpx 0;
-
- .loading-text,
- .empty-text,
- .load-more-text,
- .no-more-text {
- font-size: 26rpx;
- color: #999;
- }
- }
- .empty-text {
- color: #666;
- }
- .no-more-text {
- color: #999;
- }
- </style>
|