my-resources.vue 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  1. <template>
  2. <view class="my-resources">
  3. <!-- 顶部导航栏 -->
  4. <view class="header">
  5. <text class="header-title">我的资源</text>
  6. <view class="header-right">
  7. <text class="dropdown-arrow">▼</text>
  8. </view>
  9. </view>
  10. <!-- 搜索栏 -->
  11. <view class="search-bar">
  12. <view class="search-input-wrapper">
  13. <view class="search-icon-small"></view>
  14. <input type="text" class="search-input" placeholder="请输入姓名、手机号或标签(如:温柔)" v-model="searchKeyword" @input="handleSearch" />
  15. </view>
  16. </view>
  17. <!-- 资源/线索切换标签 -->
  18. <view class="tab-switcher">
  19. <view class="tab-item" :class="{ active: currentTab === 'resource' }" @click="switchToResource">
  20. <text class="tab-text">资源</text>
  21. <text class="tab-count">({{ registeredTotal }})</text>
  22. </view>
  23. <view class="tab-item" :class="{ active: currentTab === 'clue' }" @click="switchToClue">
  24. <text class="tab-text">线索</text>
  25. <text class="tab-count">({{ unregisteredTotal }})</text>
  26. </view>
  27. </view>
  28. <scroll-view scroll-y class="content" @scrolltolower="handleScrollToLower" :lower-threshold="50" :enable-back-to-top="true" :scroll-with-animation="true">
  29. <!-- 资源部分(已注册用户) -->
  30. <view class="resource-section" v-if="currentTab === 'resource'">
  31. <view class="section-header" v-if="registeredResources.length > 0">
  32. <text class="section-title">资源</text>
  33. <text class="section-count">({{ registeredTotal }})</text>
  34. </view>
  35. <view class="resource-list-container">
  36. <view class="resource-item" v-for="(item, index) in getRegisteredDisplayData" :key="getRegisteredItemKey(item, index)" @click="handleResourceClickSafe(item, index)">
  37. <!-- 右上角选中图标(左移) -->
  38. <view class="select-icon">✓-</view>
  39. <!-- 编辑按钮 -->
  40. <view class="edit-icon" @click.stop="handleEdit(item.id || item.resourceId || item.resource_id)">
  41. <text class="edit-text">编辑</text>
  42. </view>
  43. <view class="resource-header">
  44. <image
  45. :src="item.avatar"
  46. mode="aspectFill"
  47. class="resource-avatar"
  48. @error="handleImageErrorRegistered(index)"
  49. @load="handleImageLoadRegistered(index)"
  50. :lazy-load="true"
  51. ></image>
  52. <view class="resource-basic-info">
  53. <view class="name-gender">
  54. <text class="resource-name">{{ item.name }}</text>
  55. <text class="resource-gender gender-tag">{{ item.gender }}</text>
  56. </view>
  57. <view class="status-tag-wrapper">
  58. <text class="status-tag register-tag registered">已注册</text>
  59. <text class="status-tag match-tag" :class="{ 'matched': item.isMatch === 1, 'unmatched': item.isMatch === 0 || !item.isMatch }">
  60. {{ item.isMatch === 1 ? '已匹配' : '未匹配' }}
  61. </text>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="resource-details">
  66. <view class="labels">
  67. <text class="label" v-for="(label, idx) in item.labels" :key="idx">{{ label }}</text>
  68. </view>
  69. <view class="requirement-box">
  70. <text class="requirement-label">择偶要求:</text>
  71. <text class="requirement-content">{{ item.requirement }}</text>
  72. </view>
  73. <view class="contact-box">
  74. <text class="contact-label">联系方式:</text>
  75. <text class="contact-number">{{ item.contact }}</text>
  76. <text class="copy-btn" @click.stop="handleCopyContact(item.originalPhone || item.contact)">复制</text>
  77. </view>
  78. <view class="action-buttons">
  79. <view class="delete-btn" @click.stop="handleDelete(item.id || item.resourceId || item.resource_id)">删除</view>
  80. <view class="match-btn" @click.stop="handleMatch(item.id || item.resourceId || item.resource_id)">精准匹配</view>
  81. </view>
  82. </view>
  83. <!-- 优质资源标签 -->
  84. <view class="quality-tag" v-if="item.isQuality">
  85. <text class="quality-star">★</text>
  86. <text class="quality-text">优质资源</text>
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 加载更多提示 -->
  91. <view class="load-more-tip" v-if="registeredResources.length < registeredTotal && currentTab === 'resource'">
  92. <text class="load-more-text">下拉加载更多</text>
  93. </view>
  94. <!-- 没有更多数据提示 -->
  95. <view class="no-more-tip" v-if="registeredResources.length >= registeredTotal && registeredTotal > 0 && currentTab === 'resource'">
  96. <text class="no-more-text">已加载全部数据</text>
  97. </view>
  98. </view>
  99. <!-- 线索部分(未注册用户) -->
  100. <view class="resource-section" v-if="currentTab === 'clue'">
  101. <view class="section-header" v-if="unregisteredResources.length > 0">
  102. <text class="section-title">线索</text>
  103. <text class="section-count">({{ unregisteredTotal }})</text>
  104. </view>
  105. <view class="resource-list-container">
  106. <view class="resource-item" v-for="(item, index) in getUnregisteredDisplayData" :key="getUnregisteredItemKey(item, index)" @click="handleResourceClickSafe(item, index)">
  107. <!-- 右上角选中图标(左移) -->
  108. <view class="select-icon">✓-</view>
  109. <!-- 编辑按钮 -->
  110. <view class="edit-icon" @click.stop="handleEdit(item.id || item.resourceId || item.resource_id)">
  111. <text class="edit-text">编辑</text>
  112. </view>
  113. <view class="resource-header">
  114. <image
  115. :src="item.avatar"
  116. mode="aspectFill"
  117. class="resource-avatar"
  118. @error="handleImageErrorUnregistered(index)"
  119. @load="handleImageLoadUnregistered(index)"
  120. :lazy-load="true"
  121. ></image>
  122. <view class="resource-basic-info">
  123. <view class="name-gender">
  124. <text class="resource-name">{{ item.name }}</text>
  125. <text class="resource-gender gender-tag">{{ item.gender }}</text>
  126. </view>
  127. <view class="status-tag-wrapper">
  128. <text class="status-tag register-tag unregistered">未注册</text>
  129. <!-- 审核状态标签(仅线索列表显示) -->
  130. <text class="status-tag audit-tag" :class="{ 'audit-pending': item.status === 0 || item.status === null || item.status === undefined, 'audit-approved': item.status === 1, 'audit-rejected': item.status === 2 }">
  131. {{ item.status === 0 || item.status === null || item.status === undefined ? '待审核' : (item.status === 1 ? '审核通过' : (item.status === 2 ? '审核未通过' : '待审核')) }}
  132. </text>
  133. </view>
  134. </view>
  135. </view>
  136. <view class="resource-details">
  137. <view class="labels">
  138. <text class="label" v-for="(label, idx) in item.labels" :key="idx">{{ label }}</text>
  139. </view>
  140. <!-- 未审核通过原因 -->
  141. <view class="reject-reason" v-if="item.status === 2 && item.rejectReason">
  142. <text class="reject-reason-text">审核未通过原因:{{ item.rejectReason }}</text>
  143. </view>
  144. <view class="requirement-box">
  145. <text class="requirement-label">择偶要求:</text>
  146. <text class="requirement-content">{{ item.requirement }}</text>
  147. </view>
  148. <view class="contact-box">
  149. <text class="contact-label">联系方式:</text>
  150. <text class="contact-number">{{ item.contact }}</text>
  151. <text class="copy-btn" @click.stop="handleCopyContact(item.originalPhone || item.contact)">复制</text>
  152. </view>
  153. <view class="action-buttons">
  154. <view class="delete-btn" @click.stop="handleDelete(item.id || item.resourceId || item.resource_id)">删除</view>
  155. <view class="match-btn" @click.stop="handleMatch(item.id || item.resourceId || item.resource_id)">精准匹配</view>
  156. </view>
  157. </view>
  158. <!-- 优质资源标签 -->
  159. <view class="quality-tag" v-if="item.isQuality">
  160. <text class="quality-star">★</text>
  161. <text class="quality-text">优质资源</text>
  162. </view>
  163. </view>
  164. </view>
  165. <!-- 加载更多提示 -->
  166. <view class="load-more-tip" v-if="unregisteredResources.length < unregisteredTotal && currentTab === 'clue'">
  167. <text class="load-more-text">下拉加载更多</text>
  168. </view>
  169. <!-- 没有更多数据提示 -->
  170. <view class="no-more-tip" v-if="unregisteredResources.length >= unregisteredTotal && unregisteredTotal > 0 && currentTab === 'clue'">
  171. <text class="no-more-text">已加载全部数据</text>
  172. </view>
  173. </view>
  174. <!-- 空状态 -->
  175. <view class="empty-state" v-if="(currentTab === 'resource' && registeredTotal === 0 && registeredResources.length === 0) || (currentTab === 'clue' && unregisteredTotal === 0 && unregisteredResources.length === 0)">
  176. <text class="empty-text">{{ currentTab === 'resource' ? '暂无资源' : '暂无线索' }}</text>
  177. </view>
  178. </scroll-view>
  179. <!-- 底部添加按钮 -->
  180. <view class="add-button" @click="handleAdd">
  181. <text class="add-button-icon">+</text>
  182. </view>
  183. <!-- 底部导航 -->
  184. <view class="tabbar">
  185. <view class="tabbar-item" @click="navigateToWorkbench">
  186. <view class="tabbar-icon home"></view>
  187. <text class="tabbar-text">工作台</text>
  188. </view>
  189. <view class="tabbar-item active" @click="navigateToMyResources">
  190. <view class="tabbar-icon resources"></view>
  191. <text class="tabbar-text">我的资源</text>
  192. </view>
  193. <view class="tabbar-item" @click="navigateToRanking">
  194. <view class="tabbar-icon trophy"></view>
  195. <text class="tabbar-text">排行榜</text>
  196. </view>
  197. <view class="tabbar-item" @click="navigateToMessage">
  198. <view class="tabbar-icon message">
  199. <view v-if="unreadCount > 0" class="badge">{{ unreadCount }}</view>
  200. </view>
  201. <text class="tabbar-text">消息</text>
  202. </view>
  203. <view class="tabbar-item" @click="navigateToMine">
  204. <view class="tabbar-icon mine"></view>
  205. <text class="tabbar-text">我的</text>
  206. </view>
  207. </view>
  208. </view>
  209. </template>
  210. <script>
  211. import api from '@/utils/api.js'
  212. export default {
  213. data() {
  214. return {
  215. searchKeyword: '',
  216. isFirstLoad: true, // 标记是否为首次加载
  217. currentTab: 'resource', // 当前选中的标签:'resource' 或 'clue'
  218. resources: [], // 保留用于兼容
  219. registeredResources: [], // 已注册用户(资源部分)- 已加载的数据
  220. unregisteredResources: [], // 未注册用户(线索部分)- 已加载的数据
  221. allRegisteredResources: [], // 已注册用户(资源部分)- 全部数据(从后端获取)
  222. allUnregisteredResources: [], // 未注册用户(线索部分)- 全部数据(从后端获取)
  223. refreshTimer: null, // 定时刷新器
  224. // 资源分页
  225. registeredPageNum: 1, // 资源当前页码
  226. registeredPageSize: 3, // 资源每页显示数量
  227. registeredTotal: 0, // 资源总数
  228. registeredLoading: false, // 资源加载中标志
  229. // 线索分页
  230. unregisteredPageNum: 1, // 线索当前页码
  231. unregisteredPageSize: 3, // 线索每页显示数量
  232. unregisteredTotal: 0, // 线索总数
  233. unregisteredLoading: false // 线索加载中标志
  234. }
  235. },
  236. computed: {
  237. // 全局未读消息数
  238. unreadCount() {
  239. return this.$store.getters.getTotalUnread || 0
  240. },
  241. // 获取资源已加载的数据(用于显示)
  242. getRegisteredDisplayData() {
  243. const data = (this.registeredResources || []).filter(item => {
  244. const isValid = item && item.id !== undefined && item.id !== null
  245. if (!isValid) {
  246. console.warn('getRegisteredDisplayData - 过滤掉无效数据:', item)
  247. }
  248. return isValid
  249. })
  250. console.log('getRegisteredDisplayData - 返回数据长度:', data.length, '数据:', data.map(item => ({ id: item.id, name: item.name })))
  251. return data
  252. },
  253. // 获取线索已加载的数据(用于显示)
  254. getUnregisteredDisplayData() {
  255. const data = (this.unregisteredResources || []).filter(item => {
  256. const isValid = item && item.id !== undefined && item.id !== null
  257. if (!isValid) {
  258. console.warn('getUnregisteredDisplayData - 过滤掉无效数据:', item)
  259. }
  260. return isValid
  261. })
  262. console.log('getUnregisteredDisplayData - 返回数据长度:', data.length, '数据:', data.map(item => ({ id: item.id, name: item.name })))
  263. return data
  264. }
  265. },
  266. onLoad() {
  267. // 加载我的资源数据
  268. this.loadMyResources()
  269. this.isFirstLoad = false
  270. // 监听刷新事件
  271. uni.$on('refreshResourceList', () => {
  272. console.log('收到刷新资源列表事件')
  273. this.loadMyResources()
  274. })
  275. // 启动定时刷新,每30秒检查一次用户注册状态变化
  276. this.startAutoRefresh()
  277. },
  278. onShow() {
  279. // 页面显示时刷新列表(从其他页面返回时,非首次加载)
  280. if (!this.isFirstLoad) {
  281. this.loadMyResources()
  282. }
  283. // 重新启动定时刷新
  284. this.startAutoRefresh()
  285. },
  286. onHide() {
  287. // 页面隐藏时停止定时刷新
  288. this.stopAutoRefresh()
  289. },
  290. onUnload() {
  291. // 页面卸载时移除事件监听和停止定时刷新
  292. uni.$off('refreshResourceList')
  293. this.stopAutoRefresh()
  294. },
  295. methods: {
  296. // 获取审核状态文本
  297. getAuditStatusText(status) {
  298. if (status === null || status === undefined) {
  299. return '待审核'
  300. }
  301. switch (status) {
  302. case 0:
  303. return '待审核'
  304. case 1:
  305. return '审核通过'
  306. case 2:
  307. return '审核未通过'
  308. default:
  309. return '待审核'
  310. }
  311. },
  312. // 获取审核状态样式类(返回对象,用于:class绑定)
  313. getAuditStatusClass(status) {
  314. if (status === null || status === undefined) {
  315. return { 'audit-pending': true }
  316. }
  317. switch (status) {
  318. case 0:
  319. return { 'audit-pending': true }
  320. case 1:
  321. return { 'audit-approved': true }
  322. case 2:
  323. return { 'audit-rejected': true }
  324. default:
  325. return { 'audit-pending': true }
  326. }
  327. },
  328. // 获取资源项的key
  329. getRegisteredItemKey(item, index) {
  330. if (item && item.id) {
  331. return 'registered-' + item.id
  332. }
  333. return 'registered-placeholder-' + index
  334. },
  335. // 获取线索项的key
  336. getUnregisteredItemKey(item, index) {
  337. if (item && item.id) {
  338. return 'unregistered-' + item.id
  339. }
  340. return 'unregistered-placeholder-' + index
  341. },
  342. // 切换到资源标签
  343. switchToResource() {
  344. this.currentTab = 'resource'
  345. // 切换标签时重置已加载数据
  346. this.registeredPageNum = 1
  347. this.loadRegisteredPage(1)
  348. },
  349. // 切换到线索标签
  350. switchToClue() {
  351. this.currentTab = 'clue'
  352. // 切换标签时重置已加载数据
  353. this.unregisteredPageNum = 1
  354. this.loadUnregisteredPage(1)
  355. },
  356. // 滚动到底部触发加载更多
  357. handleScrollToLower(e) {
  358. console.log('=== 触发滚动到底部事件 ===', e)
  359. if (this.currentTab === 'resource') {
  360. // 资源列表加载更多
  361. console.log('资源列表状态:', {
  362. registeredLoading: this.registeredLoading,
  363. registeredResourcesLength: this.registeredResources.length,
  364. registeredTotal: this.registeredTotal,
  365. canLoadMore: this.registeredResources.length < this.registeredTotal
  366. })
  367. if (!this.registeredLoading) {
  368. // 如果已加载数量小于总数,继续加载
  369. if (this.registeredTotal > 0 && this.registeredResources.length < this.registeredTotal) {
  370. console.log('✅ 开始加载更多资源...')
  371. this.loadMoreRegistered()
  372. } else if (this.registeredTotal === 0) {
  373. console.log('⚠️ 资源总数未知,尝试加载...')
  374. // 如果总数未知,也尝试加载(可能是第一页加载失败)
  375. this.loadMoreRegistered()
  376. } else {
  377. console.log('❌ 资源列表已加载全部数据,不再加载')
  378. }
  379. } else {
  380. console.log('⏳ 资源列表正在加载中,跳过...')
  381. }
  382. } else {
  383. // 线索列表加载更多
  384. console.log('线索列表状态:', {
  385. unregisteredLoading: this.unregisteredLoading,
  386. unregisteredResourcesLength: this.unregisteredResources.length,
  387. unregisteredTotal: this.unregisteredTotal,
  388. canLoadMore: this.unregisteredResources.length < this.unregisteredTotal
  389. })
  390. if (!this.unregisteredLoading) {
  391. // 如果已加载数量小于总数,继续加载
  392. if (this.unregisteredTotal > 0 && this.unregisteredResources.length < this.unregisteredTotal) {
  393. console.log('✅ 开始加载更多线索...')
  394. this.loadMoreUnregistered()
  395. } else if (this.unregisteredTotal === 0) {
  396. console.log('⚠️ 线索总数未知,尝试加载...')
  397. // 如果总数未知,也尝试加载(可能是第一页加载失败)
  398. this.loadMoreUnregistered()
  399. } else {
  400. console.log('❌ 线索列表已加载全部数据,不再加载')
  401. }
  402. } else {
  403. console.log('⏳ 线索列表正在加载中,跳过...')
  404. }
  405. }
  406. },
  407. // 加载资源指定页数据(从后端加载,使用isUser参数过滤已注册用户)
  408. async loadRegisteredPage(pageNum) {
  409. if (this.registeredLoading) return
  410. this.registeredLoading = true
  411. this.registeredPageNum = pageNum
  412. try {
  413. // 获取当前登录用户ID
  414. const userInfo = uni.getStorageSync('userInfo') || {}
  415. const userId = uni.getStorageSync('userId')
  416. let currentUserId = userInfo.userId || userId || null
  417. if (currentUserId !== null && currentUserId !== undefined) {
  418. currentUserId = parseInt(currentUserId)
  419. if (isNaN(currentUserId) || currentUserId <= 0) {
  420. currentUserId = null
  421. }
  422. }
  423. if (!currentUserId) {
  424. console.error('无法获取当前登录用户ID')
  425. this.registeredResources = []
  426. this.registeredLoading = false
  427. return
  428. }
  429. const baseUrl = process.env.NODE_ENV === 'development'
  430. ? 'http://localhost:8083/api'
  431. : 'https://your-domain.com/api'
  432. // 构建查询参数,使用isUser=1参数只获取已注册用户
  433. let url = `${baseUrl}/my-resource/list?currentUserId=${currentUserId}&pageNum=${pageNum}&pageSize=${this.registeredPageSize}&isUser=1`
  434. if (this.searchKeyword && this.searchKeyword.trim()) {
  435. url += `&keyword=${encodeURIComponent(this.searchKeyword.trim())}`
  436. }
  437. const [error, res] = await uni.request({
  438. url: url,
  439. method: 'GET'
  440. })
  441. if (error) {
  442. console.error('加载资源数据失败:', error)
  443. this.registeredResources = []
  444. this.registeredLoading = false
  445. return
  446. }
  447. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  448. const pageData = res.data.data
  449. if (pageData && pageData.records) {
  450. // 转换数据格式,并过滤掉无效数据(null值)
  451. const resources = this.convertResourceData(pageData.records).filter(item => item !== null && item !== undefined)
  452. // 如果是第一页,直接替换;否则追加
  453. if (pageNum === 1) {
  454. this.registeredResources = resources
  455. } else {
  456. this.registeredResources = [...this.registeredResources, ...resources]
  457. }
  458. // 更新总数(使用后端返回的total)
  459. this.registeredTotal = pageData.total || 0
  460. console.log('loadRegisteredPage - pageNum:', pageNum, 'loaded:', this.registeredResources.length, 'total:', this.registeredTotal, 'pageData:', {
  461. total: pageData.total,
  462. size: pageData.size,
  463. current: pageData.current,
  464. pages: pageData.pages,
  465. recordsLength: pageData.records.length
  466. })
  467. } else {
  468. if (pageNum === 1) {
  469. this.registeredResources = []
  470. this.registeredTotal = 0
  471. }
  472. }
  473. } else {
  474. console.error('加载资源数据失败,响应:', res.data)
  475. }
  476. } catch (e) {
  477. console.error('加载资源数据异常:', e)
  478. if (this.registeredPageNum === 1) {
  479. this.registeredResources = []
  480. }
  481. } finally {
  482. this.registeredLoading = false
  483. }
  484. },
  485. // 加载线索指定页数据(从后端加载,使用isUser参数过滤未注册用户)
  486. async loadUnregisteredPage(pageNum) {
  487. if (this.unregisteredLoading) return
  488. this.unregisteredLoading = true
  489. this.unregisteredPageNum = pageNum
  490. try {
  491. // 获取当前登录用户ID
  492. const userInfo = uni.getStorageSync('userInfo') || {}
  493. const userId = uni.getStorageSync('userId')
  494. let currentUserId = userInfo.userId || userId || null
  495. if (currentUserId !== null && currentUserId !== undefined) {
  496. currentUserId = parseInt(currentUserId)
  497. if (isNaN(currentUserId) || currentUserId <= 0) {
  498. currentUserId = null
  499. }
  500. }
  501. if (!currentUserId) {
  502. console.error('无法获取当前登录用户ID')
  503. this.unregisteredResources = []
  504. this.unregisteredLoading = false
  505. return
  506. }
  507. const baseUrl = process.env.NODE_ENV === 'development'
  508. ? 'http://localhost:8083/api'
  509. : 'https://your-domain.com/api'
  510. // 构建查询参数,使用isUser=0参数只获取未注册用户(线索)
  511. let url = `${baseUrl}/my-resource/list?currentUserId=${currentUserId}&pageNum=${pageNum}&pageSize=${this.unregisteredPageSize}&isUser=0`
  512. if (this.searchKeyword && this.searchKeyword.trim()) {
  513. url += `&keyword=${encodeURIComponent(this.searchKeyword.trim())}`
  514. }
  515. const [error, res] = await uni.request({
  516. url: url,
  517. method: 'GET'
  518. })
  519. if (error) {
  520. console.error('加载线索数据失败:', error)
  521. this.unregisteredResources = []
  522. this.unregisteredLoading = false
  523. return
  524. }
  525. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  526. const pageData = res.data.data
  527. if (pageData && pageData.records) {
  528. // 转换数据格式,并过滤掉无效数据(null值)
  529. const resources = this.convertResourceData(pageData.records).filter(item => item !== null && item !== undefined)
  530. // 如果是第一页,直接替换;否则追加
  531. if (pageNum === 1) {
  532. this.unregisteredResources = resources
  533. } else {
  534. this.unregisteredResources = [...this.unregisteredResources, ...resources]
  535. }
  536. // 更新总数(使用后端返回的total)
  537. this.unregisteredTotal = pageData.total || 0
  538. console.log('loadUnregisteredPage - pageNum:', pageNum, 'loaded:', this.unregisteredResources.length, 'total:', this.unregisteredTotal, 'pageData:', {
  539. total: pageData.total,
  540. size: pageData.size,
  541. current: pageData.current,
  542. pages: pageData.pages,
  543. recordsLength: pageData.records.length
  544. })
  545. } else {
  546. if (pageNum === 1) {
  547. this.unregisteredResources = []
  548. this.unregisteredTotal = 0
  549. }
  550. }
  551. } else {
  552. console.error('加载线索数据失败,响应:', res.data)
  553. }
  554. } catch (e) {
  555. console.error('加载线索数据异常:', e)
  556. if (this.unregisteredPageNum === 1) {
  557. this.unregisteredResources = []
  558. }
  559. } finally {
  560. this.unregisteredLoading = false
  561. }
  562. },
  563. // 加载更多资源(从后端分页加载)
  564. async loadMoreRegistered() {
  565. if (this.registeredLoading) return
  566. // 如果已加载的数据已经达到或超过估算的总数,不再加载
  567. if (this.registeredResources.length >= this.registeredTotal && this.registeredTotal > 0) return
  568. this.registeredPageNum++
  569. await this.loadRegisteredPage(this.registeredPageNum)
  570. },
  571. // 加载更多线索(从后端分页加载)
  572. async loadMoreUnregistered() {
  573. if (this.unregisteredLoading) return
  574. // 如果已加载的数据已经达到或超过估算的总数,不再加载
  575. if (this.unregisteredResources.length >= this.unregisteredTotal && this.unregisteredTotal > 0) return
  576. this.unregisteredPageNum++
  577. await this.loadUnregisteredPage(this.unregisteredPageNum)
  578. },
  579. // 转换资源数据格式(提取公共方法)
  580. convertResourceData(records) {
  581. return records.map(item => {
  582. let requirement = item.mateSelectionCriteria || item.mate_selection_criteria || ''
  583. if (requirement) {
  584. requirement = requirement.trim()
  585. }
  586. const labels = []
  587. if (item.constellation) {
  588. labels.push(item.constellation)
  589. }
  590. if (item.occupation) {
  591. labels.push(item.occupation)
  592. }
  593. let avatarUrl = item.avatarUrl || item.avatar_url || item.avatar || ''
  594. if (!avatarUrl || avatarUrl.trim() === '' || avatarUrl === 'null' || avatarUrl === null || avatarUrl === undefined) {
  595. avatarUrl = ''
  596. } else {
  597. avatarUrl = avatarUrl.trim()
  598. }
  599. let resourceId = item.resourceId || item.resource_id
  600. if (resourceId === null || resourceId === undefined || resourceId === 'undefined' || resourceId === 'null') {
  601. return null
  602. }
  603. resourceId = parseInt(resourceId)
  604. if (isNaN(resourceId) || resourceId <= 0) {
  605. return null
  606. }
  607. let isUser = item.isUser !== null && item.isUser !== undefined ? item.isUser :
  608. (item.is_user !== null && item.is_user !== undefined ? item.is_user : 0)
  609. isUser = parseInt(isUser) || 0
  610. let userId = item.userId !== null && item.userId !== undefined ? item.userId :
  611. (item.user_id !== null && item.user_id !== undefined ? item.user_id : null)
  612. if (userId !== null && userId !== undefined) {
  613. userId = parseInt(userId)
  614. if (isNaN(userId) || userId <= 0) {
  615. userId = null
  616. }
  617. }
  618. let isMatch = item.isMatch !== null && item.isMatch !== undefined ? item.isMatch :
  619. (item.is_match !== null && item.is_match !== undefined ? item.is_match : 0)
  620. isMatch = parseInt(isMatch) || 0
  621. let resourceTags = []
  622. if (item.tags && Array.isArray(item.tags) && item.tags.length > 0) {
  623. resourceTags = item.tags
  624. } else if (labels && labels.length > 0) {
  625. resourceTags = labels
  626. }
  627. return {
  628. id: resourceId,
  629. resourceId: resourceId,
  630. resource_id: resourceId,
  631. avatar: avatarUrl,
  632. name: item.name || '',
  633. gender: item.gender === 1 ? '男' : item.gender === 2 ? '女' : '未知',
  634. status: item.status !== undefined && item.status !== null ? item.status : 0,
  635. rejectReason: item.rejectReason || item.reject_reason || '',
  636. isUser: isUser,
  637. userId: userId,
  638. isMatch: isMatch,
  639. isPlus: false,
  640. labels: resourceTags,
  641. requirement: requirement || '暂无要求',
  642. contact: item.phone ? item.phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2') : '',
  643. originalPhone: item.phone || '',
  644. isQuality: false
  645. }
  646. }).filter(item => item !== null)
  647. },
  648. // 加载我的资源数据(改为分页加载)
  649. async loadMyResources() {
  650. try {
  651. // 重置分页
  652. this.registeredPageNum = 1
  653. this.unregisteredPageNum = 1
  654. // 同时加载资源和线索,进入页面即可两端都查询完毕
  655. await Promise.all([
  656. this.loadRegisteredPage(1),
  657. this.loadUnregisteredPage(1)
  658. ])
  659. } catch (e) {
  660. console.error('加载资源数据失败:', e)
  661. }
  662. },
  663. // 搜索
  664. async handleSearch() {
  665. // 重置分页到第一页
  666. this.registeredPageNum = 1
  667. this.unregisteredPageNum = 1
  668. // 重新加载资源数据,包含搜索关键词
  669. await this.loadMyResources()
  670. },
  671. // 删除资源
  672. async handleDelete(id) {
  673. // 如果id无效,尝试从当前资源列表中查找
  674. if (id === null || id === undefined || id === 'undefined' || id === 'null' || id === '') {
  675. console.warn('删除资源失败: 资源ID无效,尝试从资源列表中查找', id)
  676. // 尝试从当前显示的资源中找到对应的资源
  677. const allDisplayData = this.currentTab === 'resource'
  678. ? this.getRegisteredDisplayData
  679. : this.getUnregisteredDisplayData
  680. // 如果仍然找不到,显示错误
  681. console.error('删除资源失败: 无法获取资源ID', id)
  682. uni.showToast({
  683. title: '资源ID无效,无法删除',
  684. icon: 'none'
  685. })
  686. return
  687. }
  688. // 确保id是有效的整数
  689. let resourceId = parseInt(id)
  690. if (isNaN(resourceId) || resourceId <= 0) {
  691. // 如果解析失败,尝试从字符串中提取数字
  692. const match = String(id).match(/\d+/)
  693. if (match) {
  694. resourceId = parseInt(match[0])
  695. }
  696. if (isNaN(resourceId) || resourceId <= 0) {
  697. console.error('删除资源失败: 资源ID格式错误', id, '类型:', typeof id)
  698. uni.showToast({
  699. title: '资源ID格式错误,无法删除',
  700. icon: 'none'
  701. })
  702. return
  703. }
  704. }
  705. console.log('准备删除资源,ID:', resourceId, '原始ID:', id)
  706. uni.showModal({
  707. title: '删除确认',
  708. content: '确定要删除该资源吗?',
  709. success: async (res) => {
  710. if (res.confirm) {
  711. try {
  712. uni.showLoading({
  713. title: '删除中...'
  714. })
  715. const baseUrl = process.env.NODE_ENV === 'development'
  716. ? 'http://localhost:8083/api' // 开发环境 - 通过网关
  717. : 'https://your-domain.com/api' // 生产环境
  718. const [error, deleteRes] = await uni.request({
  719. url: `${baseUrl}/my-resource/delete/${resourceId}`,
  720. method: 'DELETE'
  721. })
  722. uni.hideLoading()
  723. if (error) {
  724. console.error('删除资源失败:', error)
  725. uni.showToast({
  726. title: '删除失败',
  727. icon: 'none'
  728. })
  729. return
  730. }
  731. if (deleteRes.statusCode === 200 && deleteRes.data && deleteRes.data.code === 200) {
  732. uni.showToast({
  733. title: '删除成功',
  734. icon: 'success'
  735. })
  736. // 删除成功后刷新资源列表
  737. await this.loadMyResources()
  738. } else {
  739. uni.showToast({
  740. title: deleteRes.data.message || '删除失败',
  741. icon: 'none'
  742. })
  743. }
  744. } catch (e) {
  745. uni.hideLoading()
  746. console.error('删除资源异常:', e)
  747. uni.showToast({
  748. title: '删除失败,请稍后重试',
  749. icon: 'none'
  750. })
  751. }
  752. }
  753. }
  754. })
  755. },
  756. // 精准匹配
  757. // 编辑资源
  758. handleEdit(id) {
  759. // 跳转到资源录入页面(编辑模式),传递资源ID
  760. uni.navigateTo({
  761. url: `/pages/matchmaker-workbench/resource-input?resourceId=${id}`,
  762. success: () => {
  763. console.log('跳转到编辑页面,resourceId:', id)
  764. },
  765. fail: (err) => {
  766. console.error('跳转失败:', err)
  767. uni.showToast({
  768. title: '跳转失败',
  769. icon: 'none'
  770. })
  771. }
  772. })
  773. },
  774. handleMatch(id) {
  775. // 查找资源项
  776. const allResources = [...this.registeredResources, ...this.unregisteredResources]
  777. const resource = allResources.find(item => item.id === id)
  778. if (!resource) {
  779. uni.showToast({
  780. title: '资源不存在',
  781. icon: 'none'
  782. })
  783. return
  784. }
  785. // 检查用户是否已注册(isUser === 1 且 userId !== null)
  786. if (resource.isUser !== 1 || resource.userId === null || resource.userId === undefined) {
  787. uni.showToast({
  788. title: '该用户还未注册用户端,注册之后才能进行匹配',
  789. icon: 'none',
  790. duration: 3000
  791. })
  792. return
  793. }
  794. // 已注册用户,跳转到精准匹配页面
  795. console.log('精准匹配:', id)
  796. uni.navigateTo({
  797. url: `/pages/matchmaker-workbench/precise-match?resourceId=${id}`
  798. })
  799. },
  800. // 复制联系方式
  801. handleCopyContact(contact) {
  802. if (!contact) {
  803. uni.showToast({
  804. title: '联系方式为空',
  805. icon: 'none'
  806. })
  807. return
  808. }
  809. // 如果是脱敏的手机号,需要从原始数据中获取完整号码
  810. // 这里需要根据实际情况调整,可能需要从item中获取原始phone
  811. // 暂时先复制显示的文本
  812. uni.setClipboardData({
  813. data: contact,
  814. success: () => {
  815. uni.showToast({
  816. title: '已复制到剪贴板',
  817. icon: 'success'
  818. })
  819. },
  820. fail: () => {
  821. uni.showToast({
  822. title: '复制失败',
  823. icon: 'none'
  824. })
  825. }
  826. })
  827. },
  828. // 客户点击事件,跳转到客户详情页面
  829. handleClientClick(id) {
  830. uni.navigateTo({
  831. url: `/pages/matchmaker-workbench/client-detail?resourceId=${id}`
  832. })
  833. },
  834. // 资源项点击事件(安全包装方法)
  835. handleResourceClickSafe(item, index) {
  836. // 如果 item 无效,尝试从数组中获取
  837. if (!item || item === null || item === undefined) {
  838. console.warn('handleResourceClickSafe: item 为空,尝试从数组中获取, index:', index)
  839. // 根据当前标签获取对应的数据数组
  840. const dataArray = this.currentTab === 'resource' ? this.getRegisteredDisplayData : this.getUnregisteredDisplayData
  841. if (dataArray && Array.isArray(dataArray) && index >= 0 && index < dataArray.length) {
  842. item = dataArray[index]
  843. }
  844. }
  845. // 如果仍然无效,直接返回
  846. if (!item || item === null || item === undefined) {
  847. console.error('handleResourceClickSafe: 无法获取有效的 item, index:', index)
  848. return
  849. }
  850. // 调用实际的点击处理方法
  851. this.handleResourceClick(item)
  852. },
  853. // 资源项点击事件
  854. handleResourceClick(item) {
  855. // 检查 item 是否存在
  856. if (!item || item === null || item === undefined) {
  857. console.error('handleResourceClick: item 为空', item)
  858. return
  859. }
  860. console.log('=== 点击资源项 ===')
  861. console.log('item对象:', JSON.stringify(item, null, 2))
  862. console.log('item.id:', item.id)
  863. console.log('item.isUser:', item.isUser)
  864. // 检查 item.id 是否存在
  865. if (!item.id && item.id !== 0) {
  866. console.error('handleResourceClick: item.id 无效', item)
  867. uni.showToast({
  868. title: '资源ID无效',
  869. icon: 'none',
  870. duration: 2000
  871. })
  872. return
  873. }
  874. // 判断是否为已注册用户(isUser === 1 且 userId !== null)
  875. if (item.isUser === 1 && item.userId !== null && item.userId !== undefined) {
  876. // 已注册,跳转到客户详情页面
  877. const resourceId = item.id
  878. console.log('准备跳转,resourceId:', resourceId)
  879. uni.navigateTo({
  880. url: `/pages/matchmaker-workbench/client-detail?resourceId=${resourceId}`,
  881. success: () => {
  882. console.log('跳转成功,resourceId:', resourceId)
  883. },
  884. fail: (err) => {
  885. console.error('跳转失败:', err)
  886. uni.showToast({
  887. title: '跳转失败,请重试',
  888. icon: 'none'
  889. })
  890. }
  891. })
  892. } else {
  893. // 未注册,提示用户
  894. uni.showToast({
  895. title: '该用户还未注册用户端',
  896. icon: 'none',
  897. duration: 2000
  898. })
  899. }
  900. },
  901. // 添加资源
  902. handleAdd() {
  903. // 跳转到信息录入页面
  904. uni.navigateTo({
  905. url: '/pages/matchmaker-workbench/resource-input',
  906. success: () => {
  907. console.log('跳转到信息录入页面成功')
  908. },
  909. fail: (err) => {
  910. console.error('跳转失败:', err)
  911. uni.showToast({
  912. title: '页面跳转失败',
  913. icon: 'none'
  914. })
  915. }
  916. })
  917. },
  918. // 导航到工作台
  919. navigateToWorkbench() {
  920. uni.navigateTo({
  921. url: '/pages/matchmaker-workbench/index'
  922. })
  923. },
  924. // 导航到我的资源
  925. navigateToMyResources() {
  926. // 已在我的资源页面,无需跳转
  927. },
  928. // 导航到排行榜
  929. navigateToRanking() {
  930. uni.navigateTo({
  931. url: '/pages/matchmaker-workbench/ranking'
  932. })
  933. },
  934. // 导航到消息
  935. navigateToMessage() {
  936. uni.navigateTo({
  937. url: '/pages/matchmaker-workbench/message'
  938. })
  939. },
  940. // 导航到我的
  941. navigateToMine() {
  942. uni.navigateTo({
  943. url: '/pages/matchmaker-workbench/mine'
  944. })
  945. },
  946. // 启动自动刷新
  947. startAutoRefresh() {
  948. // 清除之前的定时器
  949. this.stopAutoRefresh()
  950. // 每30秒刷新一次,检查用户注册状态变化
  951. this.refreshTimer = setInterval(async () => {
  952. console.log('定时刷新:检查用户注册状态变化')
  953. // 先批量检查并更新线索用户的注册状态
  954. await this.batchCheckClueRegistrationStatus()
  955. // 然后刷新资源列表
  956. await this.loadMyResources()
  957. }, 30000) // 30秒
  958. },
  959. // 批量检查并更新线索用户的注册状态
  960. async batchCheckClueRegistrationStatus() {
  961. try {
  962. // 获取红娘ID,优先使用userInfo中的matchmakerId,否则使用userId
  963. const userInfo = uni.getStorageSync('userInfo') || {}
  964. const userId = uni.getStorageSync('userId')
  965. let matchmakerId = userInfo.matchmakerId || userId || null
  966. if (!matchmakerId) {
  967. console.warn('未找到红娘ID,跳过批量检查线索用户注册状态')
  968. return
  969. }
  970. // 确保matchmakerId是有效的整数
  971. matchmakerId = parseInt(matchmakerId)
  972. if (isNaN(matchmakerId) || matchmakerId <= 0) {
  973. console.warn('红娘ID无效,跳过批量检查线索用户注册状态')
  974. return
  975. }
  976. const baseUrl = process.env.NODE_ENV === 'development'
  977. ? 'http://localhost:8083/api' // 开发环境 - 通过网关
  978. : 'https://your-domain.com/api' // 生产环境
  979. console.log('开始批量检查线索用户注册状态...', '红娘ID:', matchmakerId)
  980. const [error, res] = await uni.request({
  981. url: `${baseUrl}/my-resource/batch-check-clue-registration`,
  982. method: 'POST',
  983. data: {
  984. matchmakerId: matchmakerId
  985. }
  986. })
  987. if (error) {
  988. console.error('批量检查线索用户注册状态失败:', error)
  989. return
  990. }
  991. if (res.statusCode === 200 && res.data && res.data.code === 200) {
  992. const updateCount = res.data.data?.updateCount || 0
  993. if (updateCount > 0) {
  994. console.log(`✅ 批量检查完成,更新了 ${updateCount} 条线索用户记录`)
  995. } else {
  996. console.log('✅ 批量检查完成,没有需要更新的线索用户')
  997. }
  998. } else {
  999. console.warn('批量检查线索用户注册状态返回异常:', res.data)
  1000. }
  1001. } catch (e) {
  1002. console.error('批量检查线索用户注册状态时发生异常:', e)
  1003. }
  1004. },
  1005. // 停止自动刷新
  1006. stopAutoRefresh() {
  1007. if (this.refreshTimer) {
  1008. clearInterval(this.refreshTimer)
  1009. this.refreshTimer = null
  1010. }
  1011. },
  1012. // 已注册资源图片加载错误处理
  1013. handleImageErrorRegistered(index) {
  1014. this.handleImageError(index, 'registered')
  1015. },
  1016. // 未注册资源图片加载错误处理
  1017. handleImageErrorUnregistered(index) {
  1018. this.handleImageError(index, 'unregistered')
  1019. },
  1020. // 已注册资源图片加载成功处理
  1021. handleImageLoadRegistered(index) {
  1022. this.handleImageLoad(index, 'registered')
  1023. },
  1024. // 未注册资源图片加载成功处理
  1025. handleImageLoadUnregistered(index) {
  1026. this.handleImageLoad(index, 'unregistered')
  1027. },
  1028. // 图片加载错误处理(内部方法)
  1029. handleImageError(index, type) {
  1030. try {
  1031. // 获取当前显示的数据
  1032. const displayData = type === 'registered' ? this.getRegisteredDisplayData : this.getUnregisteredDisplayData
  1033. const resource = displayData && displayData[index]
  1034. if (!resource) {
  1035. console.warn('图片加载失败:资源不存在,index:', index, 'type:', type)
  1036. return
  1037. }
  1038. const originalUrl = resource.avatar
  1039. const resourceId = resource.id
  1040. console.error('❌ 图片加载失败:', {
  1041. index: index,
  1042. type: type,
  1043. resourceName: resource.name,
  1044. resourceId: resourceId,
  1045. originalAvatarUrl: originalUrl,
  1046. 'URL类型': typeof originalUrl,
  1047. 'URL长度': originalUrl ? originalUrl.length : 0,
  1048. '是否包含placeholder': originalUrl && originalUrl.includes('placeholder'),
  1049. '完整resource对象': resource
  1050. })
  1051. // 如果图片加载失败,且不是已经设置的默认占位图,则设置为空(显示CSS背景)
  1052. // 避免重复设置导致循环
  1053. if (originalUrl &&
  1054. originalUrl.trim() !== '' &&
  1055. !originalUrl.includes('placeholder') &&
  1056. !originalUrl.includes('default') &&
  1057. !originalUrl.includes('via.placeholder')) {
  1058. // 根据resourceId在当前显示数据中找到对应的资源并更新
  1059. console.log('图片加载失败,将URL设置为空,显示CSS默认背景')
  1060. if (type === 'registered') {
  1061. // 更新显示数据
  1062. const displayListIndex = this.registeredResources.findIndex(item => item.id === resourceId)
  1063. if (displayListIndex !== -1) {
  1064. this.$set(this.registeredResources[displayListIndex], 'avatar', '')
  1065. }
  1066. } else {
  1067. // 更新显示数据
  1068. const displayListIndex = this.unregisteredResources.findIndex(item => item.id === resourceId)
  1069. if (displayListIndex !== -1) {
  1070. this.$set(this.unregisteredResources[displayListIndex], 'avatar', '')
  1071. }
  1072. }
  1073. } else {
  1074. console.log('图片加载失败,但URL已经是占位图或空,无需处理')
  1075. console.log('当前URL:', originalUrl)
  1076. }
  1077. } catch (e) {
  1078. console.error('处理图片错误时发生异常:', e)
  1079. }
  1080. },
  1081. // 图片加载成功处理(内部方法)
  1082. handleImageLoad(index, type) {
  1083. try {
  1084. // 获取当前显示的数据
  1085. const displayData = type === 'registered' ? this.getRegisteredDisplayData : this.getUnregisteredDisplayData
  1086. if (displayData && displayData[index]) {
  1087. console.log('图片加载成功:', {
  1088. index: index,
  1089. type: type,
  1090. resource: displayData[index]?.name,
  1091. avatarUrl: displayData[index]?.avatar
  1092. })
  1093. }
  1094. } catch (e) {
  1095. console.error('处理图片加载成功时发生异常:', e)
  1096. }
  1097. }
  1098. }
  1099. }
  1100. </script>
  1101. <style lang="scss" scoped>
  1102. .my-resources {
  1103. min-height: 100vh;
  1104. background: #F5F5F5;
  1105. display: flex;
  1106. flex-direction: column;
  1107. }
  1108. /* 顶部导航栏 */
  1109. .header {
  1110. display: flex;
  1111. align-items: center;
  1112. justify-content: space-between;
  1113. padding: 20rpx 30rpx;
  1114. padding-top: calc(20rpx + env(safe-area-inset-top));
  1115. background: #FFFFFF;
  1116. border-bottom: 1rpx solid #F0F0F0;
  1117. .header-title {
  1118. font-size: 36rpx;
  1119. font-weight: bold;
  1120. color: #9C27B0;
  1121. }
  1122. .header-right {
  1123. .dropdown-arrow {
  1124. font-size: 24rpx;
  1125. color: #9C27B0;
  1126. font-weight: normal;
  1127. }
  1128. }
  1129. }
  1130. /* 资源/线索切换标签 */
  1131. .tab-switcher {
  1132. display: flex;
  1133. align-items: center;
  1134. background: #FFFFFF;
  1135. border-bottom: 1rpx solid #F0F0F0;
  1136. padding: 0 30rpx;
  1137. .tab-item {
  1138. flex: 1;
  1139. display: flex;
  1140. align-items: center;
  1141. justify-content: center;
  1142. padding: 25rpx 0;
  1143. position: relative;
  1144. cursor: pointer;
  1145. transition: all 0.3s;
  1146. .tab-text {
  1147. font-size: 32rpx;
  1148. font-weight: 500;
  1149. color: #666;
  1150. margin-right: 8rpx;
  1151. }
  1152. .tab-count {
  1153. font-size: 26rpx;
  1154. color: #999;
  1155. }
  1156. &.active {
  1157. .tab-text {
  1158. color: #9C27B0;
  1159. font-weight: bold;
  1160. }
  1161. .tab-count {
  1162. color: #9C27B0;
  1163. }
  1164. &::after {
  1165. content: '';
  1166. position: absolute;
  1167. bottom: 0;
  1168. left: 0;
  1169. right: 0;
  1170. height: 4rpx;
  1171. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  1172. border-radius: 2rpx 2rpx 0 0;
  1173. }
  1174. }
  1175. &:active {
  1176. opacity: 0.7;
  1177. }
  1178. }
  1179. }
  1180. /* 搜索栏 */
  1181. .search-bar {
  1182. padding: 20rpx;
  1183. background: #F5F5F5;
  1184. .search-input-wrapper {
  1185. display: flex;
  1186. align-items: center;
  1187. background: #FFFFFF;
  1188. border-radius: 30rpx;
  1189. padding: 12rpx 20rpx;
  1190. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.03);
  1191. .search-icon-small {
  1192. width: 32rpx;
  1193. height: 32rpx;
  1194. 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>');
  1195. background-size: contain;
  1196. background-repeat: no-repeat;
  1197. background-position: center;
  1198. margin-right: 15rpx;
  1199. }
  1200. .search-input {
  1201. flex: 1;
  1202. font-size: 28rpx;
  1203. color: #333;
  1204. border: none;
  1205. outline: none;
  1206. background: transparent;
  1207. &::placeholder {
  1208. color: #999;
  1209. }
  1210. }
  1211. }
  1212. }
  1213. .content {
  1214. flex: 1;
  1215. height: 0; /* 配合 flex: 1 使用,确保 scroll-view 有明确高度 */
  1216. padding: 0 20rpx 140rpx;
  1217. box-sizing: border-box;
  1218. }
  1219. /* 资源分组 */
  1220. .resource-section {
  1221. margin-bottom: 30rpx;
  1222. min-height: calc(50vh - 100rpx); /* 确保至少占半屏高度 */
  1223. display: flex;
  1224. flex-direction: column;
  1225. .section-header {
  1226. display: flex;
  1227. align-items: center;
  1228. padding: 20rpx 0 15rpx;
  1229. margin-bottom: 10rpx;
  1230. flex-shrink: 0;
  1231. .section-title {
  1232. font-size: 32rpx;
  1233. font-weight: bold;
  1234. color: #9C27B0;
  1235. margin-right: 10rpx;
  1236. }
  1237. .section-count {
  1238. font-size: 26rpx;
  1239. color: #999;
  1240. font-weight: normal;
  1241. }
  1242. }
  1243. /* 资源列表容器,确保有固定高度 */
  1244. .resource-list-container {
  1245. flex: 1;
  1246. display: flex;
  1247. flex-direction: column;
  1248. min-height: calc(50vh - 200rpx);
  1249. }
  1250. }
  1251. /* 加载更多提示 */
  1252. .load-more-tip {
  1253. display: flex;
  1254. justify-content: center;
  1255. align-items: center;
  1256. padding: 30rpx 0;
  1257. .load-more-text {
  1258. font-size: 26rpx;
  1259. color: #999;
  1260. }
  1261. }
  1262. /* 没有更多数据提示 */
  1263. .no-more-tip {
  1264. display: flex;
  1265. justify-content: center;
  1266. align-items: center;
  1267. padding: 30rpx 0;
  1268. .no-more-text {
  1269. font-size: 26rpx;
  1270. color: #999;
  1271. }
  1272. }
  1273. /* 空状态 */
  1274. .empty-state {
  1275. display: flex;
  1276. justify-content: center;
  1277. align-items: center;
  1278. padding: 100rpx 0;
  1279. .empty-text {
  1280. font-size: 28rpx;
  1281. color: #999;
  1282. }
  1283. }
  1284. /* 资源列表 */
  1285. .resource-item {
  1286. background: #FFFFFF;
  1287. border-radius: 20rpx;
  1288. margin-bottom: 20rpx;
  1289. padding: 25rpx;
  1290. position: relative;
  1291. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  1292. /* 右上角选中图标 */
  1293. .select-icon {
  1294. position: absolute;
  1295. top: 20rpx;
  1296. right: 120rpx; /* 左移,为编辑按钮留出空间 */
  1297. width: 40rpx;
  1298. height: 40rpx;
  1299. background: #FF4444;
  1300. color: #FFFFFF;
  1301. border-radius: 50%;
  1302. display: flex;
  1303. align-items: center;
  1304. justify-content: center;
  1305. font-size: 24rpx;
  1306. font-weight: bold;
  1307. z-index: 10;
  1308. }
  1309. .edit-icon {
  1310. position: absolute;
  1311. top: 20rpx;
  1312. right: 20rpx;
  1313. padding: 8rpx 20rpx;
  1314. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  1315. border-radius: 20rpx;
  1316. display: flex;
  1317. align-items: center;
  1318. justify-content: center;
  1319. z-index: 10;
  1320. box-shadow: 0 2rpx 8rpx rgba(156, 39, 176, 0.3);
  1321. .edit-text {
  1322. color: #FFFFFF;
  1323. font-size: 24rpx;
  1324. font-weight: 500;
  1325. }
  1326. }
  1327. .resource-header {
  1328. display: flex;
  1329. align-items: flex-start;
  1330. margin-bottom: 20rpx;
  1331. padding-right: 50rpx;
  1332. .resource-avatar {
  1333. width: 100rpx;
  1334. height: 100rpx;
  1335. border-radius: 8rpx;
  1336. margin-right: 20rpx;
  1337. flex-shrink: 0;
  1338. background-color: #F5F5F5;
  1339. background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23CCCCCC"><path d="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
  1340. background-size: 60% 60%;
  1341. background-position: center;
  1342. background-repeat: no-repeat;
  1343. }
  1344. .resource-basic-info {
  1345. flex: 1;
  1346. min-width: 0;
  1347. .name-gender {
  1348. display: flex;
  1349. align-items: center;
  1350. gap: 10rpx;
  1351. margin-bottom: 12rpx;
  1352. .resource-name {
  1353. font-size: 30rpx;
  1354. font-weight: bold;
  1355. color: #333;
  1356. }
  1357. .resource-gender {
  1358. font-size: 26rpx;
  1359. color: #666;
  1360. &.gender-tag {
  1361. display: inline-block;
  1362. padding: 4rpx 12rpx;
  1363. background: #F3E5F5;
  1364. color: #9C27B0;
  1365. border-radius: 12rpx;
  1366. font-size: 22rpx;
  1367. font-weight: 500;
  1368. }
  1369. }
  1370. }
  1371. .status-tag-wrapper {
  1372. display: flex;
  1373. align-items: center;
  1374. .status-tag {
  1375. display: inline-block;
  1376. padding: 4rpx 12rpx;
  1377. border-radius: 12rpx;
  1378. font-size: 22rpx;
  1379. font-weight: 500;
  1380. margin-right: 8rpx;
  1381. &.approved {
  1382. background: #E3F2FD;
  1383. color: #2196F3;
  1384. }
  1385. &.pending {
  1386. background: #FFF3E0;
  1387. color: #FF9800;
  1388. }
  1389. &.register-tag {
  1390. &.registered {
  1391. background: #E8F5E9;
  1392. color: #4CAF50;
  1393. }
  1394. &.unregistered {
  1395. background: #FCE4EC;
  1396. color: #E91E63;
  1397. }
  1398. }
  1399. &.match-tag {
  1400. margin-left: 10rpx;
  1401. &.matched {
  1402. background: #E3F2FD;
  1403. color: #2196F3;
  1404. }
  1405. &.unmatched {
  1406. background: #FFF3E0;
  1407. color: #FF9800;
  1408. }
  1409. }
  1410. /* 审核状态标签样式 */
  1411. &.audit-tag {
  1412. margin-left: 10rpx;
  1413. /* 待审核 - 橙色/黄色 */
  1414. &.audit-pending {
  1415. background: #FFF3E0;
  1416. color: #FF9800;
  1417. border: 1rpx solid #FFB74D;
  1418. }
  1419. /* 审核通过 - 绿色 */
  1420. &.audit-approved {
  1421. background: #E8F5E9;
  1422. color: #4CAF50;
  1423. border: 1rpx solid #81C784;
  1424. }
  1425. /* 审核未通过 - 红色 */
  1426. &.audit-rejected {
  1427. background: #FFEBEE;
  1428. color: #F44336;
  1429. border: 1rpx solid #E57373;
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. .resource-details {
  1437. .labels {
  1438. display: flex;
  1439. flex-wrap: wrap;
  1440. gap: 10rpx;
  1441. margin-bottom: 15rpx;
  1442. .label {
  1443. display: inline-block;
  1444. padding: 6rpx 14rpx;
  1445. background: #F3E5F5;
  1446. color: #9C27B0;
  1447. border-radius: 15rpx;
  1448. font-size: 22rpx;
  1449. font-weight: 500;
  1450. }
  1451. }
  1452. .requirement-box {
  1453. background: #F3E5F5;
  1454. border-radius: 12rpx;
  1455. padding: 16rpx 20rpx;
  1456. margin-bottom: 15rpx;
  1457. display: flex;
  1458. align-items: center;
  1459. flex-wrap: wrap;
  1460. .requirement-label {
  1461. font-size: 28rpx;
  1462. color: #7B1FA2;
  1463. font-weight: 500;
  1464. margin-right: 8rpx;
  1465. white-space: nowrap;
  1466. }
  1467. .requirement-content {
  1468. font-size: 28rpx;
  1469. color: #7B1FA2;
  1470. font-weight: 400;
  1471. }
  1472. }
  1473. .contact-box {
  1474. margin-bottom: 20rpx;
  1475. display: flex;
  1476. align-items: center;
  1477. flex-wrap: wrap;
  1478. .contact-label {
  1479. font-size: 26rpx;
  1480. color: #333;
  1481. font-weight: 500;
  1482. margin-right: 10rpx;
  1483. white-space: nowrap;
  1484. }
  1485. .contact-number {
  1486. flex: 1;
  1487. font-size: 26rpx;
  1488. color: #333;
  1489. font-weight: 400;
  1490. min-width: 0;
  1491. }
  1492. .copy-btn {
  1493. font-size: 24rpx;
  1494. color: #9C27B0;
  1495. font-weight: 500;
  1496. margin-left: 15rpx;
  1497. white-space: nowrap;
  1498. cursor: pointer;
  1499. }
  1500. }
  1501. .action-buttons {
  1502. display: flex;
  1503. justify-content: space-between;
  1504. align-items: center;
  1505. gap: 15rpx;
  1506. .delete-btn {
  1507. flex: 1;
  1508. padding: 14rpx 0;
  1509. background: #FFEBEE;
  1510. color: #E91E63;
  1511. border-radius: 25rpx;
  1512. font-size: 26rpx;
  1513. font-weight: 500;
  1514. text-align: center;
  1515. }
  1516. .match-btn {
  1517. flex: 1.5;
  1518. padding: 14rpx 0;
  1519. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  1520. color: #FFFFFF;
  1521. border-radius: 25rpx;
  1522. font-size: 26rpx;
  1523. font-weight: 500;
  1524. text-align: center;
  1525. }
  1526. }
  1527. }
  1528. /* 优质资源标签 */
  1529. .quality-tag {
  1530. position: absolute;
  1531. top: 80rpx;
  1532. right: 20rpx;
  1533. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  1534. color: #FFFFFF;
  1535. font-size: 22rpx;
  1536. font-weight: bold;
  1537. padding: 8rpx 16rpx;
  1538. border-radius: 20rpx;
  1539. display: flex;
  1540. align-items: center;
  1541. gap: 4rpx;
  1542. box-shadow: 0 2rpx 8rpx rgba(156, 39, 176, 0.3);
  1543. z-index: 5;
  1544. .quality-star {
  1545. font-size: 20rpx;
  1546. }
  1547. .quality-text {
  1548. font-size: 22rpx;
  1549. }
  1550. }
  1551. }
  1552. /* 审核未通过原因 */
  1553. .reject-reason {
  1554. margin-top: 12rpx;
  1555. padding: 14rpx 16rpx;
  1556. background: #FFF3E0;
  1557. border: 1rpx solid #FFCC80;
  1558. border-radius: 10rpx;
  1559. color: #E65100;
  1560. font-size: 24rpx;
  1561. line-height: 1.5;
  1562. }
  1563. /* 添加按钮 */
  1564. .add-button {
  1565. position: fixed;
  1566. bottom: 130rpx;
  1567. right: 40rpx;
  1568. width: 100rpx;
  1569. height: 100rpx;
  1570. border-radius: 50%;
  1571. background: linear-gradient(135deg, #9C27B0 0%, #BA68C8 100%);
  1572. display: flex;
  1573. align-items: center;
  1574. justify-content: center;
  1575. box-shadow: 0 4rpx 20rpx rgba(156, 39, 176, 0.4);
  1576. z-index: 999;
  1577. .add-button-icon {
  1578. font-size: 60rpx;
  1579. color: #FFFFFF;
  1580. line-height: 1;
  1581. font-weight: bold;
  1582. }
  1583. }
  1584. /* 底部导航 */
  1585. .tabbar {
  1586. position: fixed;
  1587. bottom: 0;
  1588. left: 0;
  1589. right: 0;
  1590. height: 100rpx;
  1591. background: #FFFFFF;
  1592. border-top: 1rpx solid #F0F0F0;
  1593. display: flex;
  1594. justify-content: space-around;
  1595. align-items: center;
  1596. padding-bottom: env(safe-area-inset-bottom);
  1597. .tabbar-item {
  1598. display: flex;
  1599. flex-direction: column;
  1600. align-items: center;
  1601. gap: 8rpx;
  1602. padding: 10rpx 0;
  1603. .tabbar-icon {
  1604. width: 44rpx;
  1605. height: 44rpx;
  1606. background-size: contain;
  1607. background-repeat: no-repeat;
  1608. background-position: center;
  1609. position: relative;
  1610. .badge {
  1611. position: absolute;
  1612. top: -8rpx;
  1613. right: -8rpx;
  1614. background: #FF4444;
  1615. color: #FFFFFF;
  1616. font-size: 20rpx;
  1617. font-weight: bold;
  1618. width: 32rpx;
  1619. height: 32rpx;
  1620. display: flex;
  1621. align-items: center;
  1622. justify-content: center;
  1623. border-radius: 16rpx;
  1624. }
  1625. }
  1626. .tabbar-text {
  1627. font-size: 20rpx;
  1628. color: #999;
  1629. }
  1630. &.active {
  1631. .tabbar-text {
  1632. color: #9C27B0;
  1633. font-weight: bold;
  1634. }
  1635. }
  1636. &.home .tabbar-icon {
  1637. 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 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>');
  1638. }
  1639. &.active.home .tabbar-icon {
  1640. 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="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>');
  1641. }
  1642. &.resources .tabbar-icon {
  1643. 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="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>');
  1644. }
  1645. &.trophy .tabbar-icon {
  1646. 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="M18 6l-1.42 1.42-1.59-1.59L13 8.17l-1.42-1.42L9 8.17l-1.59-1.59L6 6l3 3V18c0 1.1.9 2 2 2h4c1.1 0 2-.9 2-2V9l3-3zm-4 12H8v-7.5l4-4 4 4V18z"/></svg>');
  1647. }
  1648. &.active.trophy .tabbar-icon {
  1649. 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="M18 6l-1.42 1.42-1.59-1.59L13 8.17l-1.42-1.42L9 8.17l-1.59-1.59L6 6l3 3V18c0 1.1.9 2 2 2h4c1.1 0 2-.9 2-2V9l3-3zm-4 12H8v-7.5l4-4 4 4V18z"/></svg>');
  1650. }
  1651. &.message .tabbar-icon {
  1652. 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="M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>');
  1653. }
  1654. &.active.message .tabbar-icon {
  1655. 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 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"/></svg>');
  1656. }
  1657. &.mine .tabbar-icon {
  1658. 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="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
  1659. }
  1660. &.active.mine .tabbar-icon {
  1661. 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="M12 12c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm0 2c-2.67 0-8 1.34-8 4v2h16v-2c0-2.66-5.33-4-8-4z"/></svg>');
  1662. }
  1663. }
  1664. }
  1665. </style>