friend-links.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. <template>
  2. <view class="app-page card-shadow" :class="[uniHaloPluginPageClass]">
  3. <PluginUnavailable v-if="!uniHaloPluginAvailable" :pluginId="uniHaloPluginId"
  4. :error-text="uniHaloPluginAvailableError" />
  5. <template v-else>
  6. <view v-if="loading != 'success'" class="loading-wrap">
  7. <tm-skeleton model="listAvatr"></tm-skeleton>
  8. <tm-skeleton model="listAvatr"></tm-skeleton>
  9. <tm-skeleton model="listAvatr"></tm-skeleton>
  10. <tm-skeleton model="listAvatr"></tm-skeleton>
  11. <tm-skeleton model="listAvatr"></tm-skeleton>
  12. </view>
  13. <view v-else class="content" :class="{ 'bg-white': dataList.length !== 0 }">
  14. <!-- 空数据 -->
  15. <view v-if="dataList.length == 0" class="content-empty flex flex-center">
  16. <tm-empty icon="icon-shiliangzhinengduixiang-" label="啊偶,博主还没有朋友呢~"></tm-empty>
  17. </view>
  18. <!-- 如果只有一个分组:使用列表的形式 dataList.length == 1 -->
  19. <view v-else class="flex flex-col pb-24">
  20. <block v-for="(link, index) in dataList" :key="index">
  21. <tm-translate animation-name="fadeUp" :wait="calcAniWait(index)">
  22. <!-- 色彩版本 -->
  23. <view v-if="!globalAppSettings.links.useSimple" class="info flex pt-24 pb-24 pl-12 pr-12"
  24. :class="{ 'border-b-1': index !== dataList.length - 1 }" @click="fnOnLinkEvent(link)">
  25. <view class="link-logo">
  26. <cache-image class="link-logo_img" radius="12rpx" :url="link.spec.logo"
  27. :fileMd5="link.spec.logo" mode="aspectFill"></cache-image>
  28. </view>
  29. <view class="flex flex-col pl-30 info-detail">
  30. <view class="link-card_name text-size-l text-weight-b text-red">
  31. <tm-tags style="margin-right: 12rpx;margin-left: -2rpx;"
  32. color="bg-gradient-light-blue-lighten" :shadow="0" size="s" model="fill">
  33. {{ link.spec.groupName || '暂未分组' }}
  34. </tm-tags>
  35. {{ link.spec.displayName }}
  36. </view>
  37. <view class="poup-tag mt-6" style="font-size: 28rpx;">
  38. 站点地址:{{ link.spec.url }}
  39. <!-- <tm-tags color="bg-gradient-amber-accent" :shadow="0" size="s" model="fill">
  40. URL:{{ link.spec.url }}
  41. </tm-tags>
  42. <tm-tags color=" bg-gradient-light-blue-lighten" :shadow="0" size="s" model="fill">
  43. {{ link.spec.groupName || '暂未分组' }}
  44. </tm-tags> -->
  45. </view>
  46. <view class="link-card_desc text-overflow mt-4" style="font-size: 28rpx;">
  47. 博客简介:{{ link.spec.description || '这个博主很懒,没写简介~' }}
  48. </view>
  49. </view>
  50. </view>
  51. <!-- 简洁版本 -->
  52. <view v-else class="link-card flex ml-24 mr-24 pt-24 pb-24" @click="fnOnLinkEvent(link)">
  53. <image class="logo shadow-6" :src="link.spec.logo" mode="aspectFill"></image>
  54. <view class="info pl-24">
  55. <view class="name text-size-g">{{ link.spec.displayName }}</view>
  56. <view class="desc mt-12 text-size-s text-grey-darken-1">{{ link.spec.description }}
  57. </view>
  58. <view v-if="false" class="link mt-12 text-size-m text-grey-darken-1">
  59. <text class="iconfont icon-link mr-6 text-size-s"></text>
  60. {{ link.spec.url }}
  61. </view>
  62. </view>
  63. </view>
  64. </tm-translate>
  65. </block>
  66. </view>
  67. <!-- 返回顶部 -->
  68. <tm-flotbutton color="light-blue" @click="fnToTopPage" size="m" icon="icon-angle-up"></tm-flotbutton>
  69. <tm-flotbutton v-if="haloPluginConfigs.linksSubmitPlugin.enabled" :offset="[16,80]" label="申请"
  70. actions-pos="left" :show-text="true" color="bg-gradient-orange-accent"
  71. @click="toSubmitLinkPage"></tm-flotbutton>
  72. <!-- 详情弹窗 -->
  73. <tm-poup v-model="detail.show" :width="640" height="auto" position="center" :round="6">
  74. <view class="poup pa-36" v-if="detail.data">
  75. <view class="info flex">
  76. <view class="poup-logo bg-gradient-amber-accent pa-4 shadow-24">
  77. <image class="poup-logo_img" :src="$utils.checkImageUrl(detail.data.spec.logo)"
  78. mode="aspectFill"></image>
  79. </view>
  80. <view class="pl-24 info-detail">
  81. <view class="poup-name text-size-lg text-weight-b">{{ detail.data.spec.displayName }}
  82. </view>
  83. <view class="poup-tag ml--10">
  84. <tm-tags color="bg-gradient-light-blue-lighten" size="n" model="fill">
  85. {{ detail.data.spec.groupName }}
  86. </tm-tags>
  87. </view>
  88. <view class="poup-link text-size-m" @click="fnCopyLink(detail.data)">
  89. <text class="text-orange">{{ detail.data.spec.url }}</text>
  90. <text class="iconfont icon-copy text-size-s ml-6 text-grey"></text>
  91. </view>
  92. </view>
  93. </view>
  94. <view class="poup-desc mt-20">
  95. 博客简介:{{ detail.data.spec.description || '这个博主很懒,没写简介~' }}
  96. </view>
  97. <!-- 博客预览图 -->
  98. <view class="mt-24">
  99. <tm-images :width="568" :round="2" :src="calcSiteThumbnail(detail.data.spec.url)"
  100. mode="aspectFill"></tm-images>
  101. </view>
  102. </view>
  103. </tm-poup>
  104. <view class="load-text">{{ loadMoreText }}</view>
  105. </view>
  106. </template>
  107. </view>
  108. </template>
  109. <script>
  110. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  111. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  112. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  113. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  114. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  115. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  116. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  117. import pluginAvailableMixin from "@/common/mixins/pluginAvailable.js"
  118. import PluginUnavailable from '@/components/plugin-unavailable/plugin-unavailable.vue'
  119. export default {
  120. mixins: [pluginAvailableMixin],
  121. components: {
  122. tmSkeleton,
  123. tmTranslate,
  124. tmFlotbutton,
  125. tmTags,
  126. tmEmpty,
  127. tmImages,
  128. tmPoup,
  129. PluginUnavailable
  130. },
  131. data() {
  132. return {
  133. loading: 'loading',
  134. queryParams: {
  135. size: 10,
  136. page: 1
  137. },
  138. detail: {
  139. show: false,
  140. data: null
  141. },
  142. hasNext: false,
  143. isLoadMore: false,
  144. loadMoreText: '',
  145. linkGroupList: [],
  146. dataList: [],
  147. colors: [
  148. '#39B449',
  149. '#E44C41',
  150. '#8698A2',
  151. '#0080FE',
  152. '#1CBCB4',
  153. '#6638B5'
  154. ]
  155. };
  156. },
  157. computed: {
  158. haloConfigs() {
  159. return this.$tm.vx.getters().getConfigs;
  160. },
  161. haloPluginConfigs() {
  162. return this.$tm.vx.getters().getConfigs.pluginConfig;
  163. },
  164. calcSiteThumbnail(val) {
  165. return val => {
  166. if (!val) return '';
  167. if (val.charAt(val.length - 1) !== '/') {
  168. val = val + '/';
  169. }
  170. return 'https://image.thum.io/get/width/1000/crop/800/' + val;
  171. };
  172. },
  173. calcAuditModeEnabled() {
  174. return this.haloConfigs.auditConfig.auditModeEnabled
  175. },
  176. },
  177. async onLoad() {
  178. this.fnSetPageTitle('友情链接');
  179. // 检查插件
  180. this.setPluginId(this.NeedPluginIds.PluginLinks)
  181. this.setPluginError("阿偶,检测到当前插件没有安装或者启用,无法使用友情链接功能哦,请联系管理员")
  182. if (!await this.checkPluginAvailable()) return
  183. this.fnGetLinkGroupData();
  184. },
  185. onPullDownRefresh() {
  186. if (!this.uniHaloPluginAvailable) {
  187. uni.hideLoading();
  188. uni.stopPullDownRefresh();
  189. return
  190. }
  191. this.isLoadMore = false;
  192. this.queryParams.page = 1;
  193. this.dataList = []
  194. this.fnGetData();
  195. },
  196. onReachBottom(e) {
  197. if (!this.uniHaloPluginAvailable) return;
  198. if (this.hasNext) {
  199. this.queryParams.page += 1;
  200. this.isLoadMore = true;
  201. this.fnGetData();
  202. } else {
  203. uni.showToast({
  204. icon: 'none',
  205. title: '没有更多数据了'
  206. });
  207. }
  208. },
  209. methods: {
  210. fnGetLinkGroupData() {
  211. this.$httpApi.v2
  212. .getFriendLinkGroupList({
  213. page: 1,
  214. size: 0
  215. })
  216. .then(res => {
  217. console.log("友情链接分组数据:", res);
  218. this.linkGroupList = res;
  219. this.fnGetData()
  220. })
  221. .catch(err => {
  222. console.error(err);
  223. this.loading = 'error';
  224. this.loadMoreText = err;
  225. });
  226. },
  227. findLinkGroupDisplayNameByGroupMetadataName(groupName) {
  228. if (this.linkGroupList.length === 0) return groupName || "未分组"
  229. return this.linkGroupList.find(item => item.metadata.name === groupName)?.spec?.displayName || groupName ||
  230. "未分组"
  231. },
  232. fnGetData() {
  233. if (this.calcAuditModeEnabled) {
  234. return;
  235. }
  236. if (!this.isLoadMore) {
  237. this.loading = 'loading';
  238. }
  239. this.loadMoreText = '';
  240. this.$httpApi.v2
  241. .getFriendLinkList(this.queryParams)
  242. .then(res => {
  243. console.log('请求结果:');
  244. console.log(res);
  245. this.hasNext = res.hasNext;
  246. const list = res.items.map(item => {
  247. item.spec.logo = this.$utils.checkAvatarUrl(item.spec?.logo)
  248. item.spec.groupName = this.findLinkGroupDisplayNameByGroupMetadataName(item.spec
  249. ?.groupName)
  250. return item;
  251. })
  252. this.dataList = this.dataList.concat(list);
  253. setTimeout(() => {
  254. this.loading = 'success';
  255. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  256. }, 500);
  257. })
  258. .catch(err => {
  259. console.error(err);
  260. this.loading = 'error';
  261. this.loadMoreText = '加载失败,请下拉刷新!';
  262. })
  263. .finally(() => {
  264. setTimeout(() => {
  265. uni.hideLoading();
  266. uni.stopPullDownRefresh();
  267. }, 500);
  268. });
  269. },
  270. handleGroup(list) {
  271. const group = {}
  272. list.forEach(item => {
  273. if (group[item.spec.groupName]) {
  274. group[item.spec.groupName].children.push(item)
  275. } else {
  276. group[item.spec.groupName] = {
  277. title: item.spec.groupName,
  278. children: [item]
  279. }
  280. }
  281. })
  282. return Object.keys(group).map(key => {
  283. const {
  284. title,
  285. children = []
  286. } = group[key]
  287. return {
  288. title,
  289. children
  290. }
  291. })
  292. },
  293. fnOnLinkEvent(link) {
  294. this.detail.data = link;
  295. this.detail.show = true;
  296. },
  297. fnCopyLink(link) {
  298. uni.setClipboardData({
  299. data: `${link.spec.displayName}:${link.spec.url}`,
  300. showToast: false,
  301. success: () => {
  302. uni.showToast({
  303. icon: 'none',
  304. title: '链接复制成功!'
  305. });
  306. },
  307. fail: () => {
  308. uni.showToast({
  309. icon: 'none',
  310. title: '复制失败!'
  311. });
  312. }
  313. });
  314. },
  315. toSubmitLinkPage() {
  316. uni.navigateTo({
  317. url: '/pagesA/submit-link/submit-link'
  318. })
  319. }
  320. }
  321. };
  322. </script>
  323. <style lang="scss" scoped>
  324. .app-page {
  325. width: 100vw;
  326. min-height: 100vh;
  327. display: flex;
  328. flex-direction: column;
  329. background-color: #fafafd;
  330. }
  331. .loading-wrap {
  332. padding: 24rpx;
  333. min-height: 100vh;
  334. }
  335. .content {
  336. padding: 0 24rpx;
  337. padding-top: 24rpx;
  338. .content-empty {
  339. height: 60vh;
  340. display: flex;
  341. align-items: center;
  342. justify-content: center;
  343. }
  344. }
  345. .link-card {
  346. border-bottom: 2rpx solid #f5f5f5;
  347. background-color: #ffffff;
  348. &.one {
  349. border: 0;
  350. box-shadow: 0rpx 2rpx 24rpx 0rpx rgba(0, 0, 0, 0.03);
  351. .logo {
  352. box-shadow: 0rpx 2rpx 12rpx rgba(0, 0, 0, 0.1);
  353. }
  354. }
  355. .logo {
  356. // width: 126rpx;
  357. // height: 126rpx;
  358. width: 80rpx;
  359. height: 80rpx;
  360. border-radius: 12rpx;
  361. border: 6rpx solid #ffffff;
  362. box-shadow: none;
  363. }
  364. .info {
  365. width: 0;
  366. flex-grow: 1;
  367. .name {
  368. white-space: nowrap;
  369. overflow: hidden;
  370. text-overflow: ellipsis;
  371. color: #303133;
  372. font-size: 30rpx;
  373. font-weight: bold;
  374. }
  375. .desc {
  376. white-space: nowrap;
  377. overflow: hidden;
  378. text-overflow: ellipsis;
  379. color: #303133;
  380. font-size: 28rpx;
  381. }
  382. }
  383. }
  384. .link-card_name {
  385. // color: #303133;
  386. // color: #0080fe;
  387. }
  388. .link-card_desc {
  389. font-size: 24rpx;
  390. line-height: 1.6;
  391. color: #303133;
  392. }
  393. .link-logo {
  394. width: 140rpx;
  395. height: 140rpx;
  396. &_img {
  397. width: 100%;
  398. height: 100%;
  399. }
  400. }
  401. .poup-logo {
  402. width: 140rpx;
  403. height: 140rpx;
  404. border-radius: 50%;
  405. &_img {
  406. width: 100%;
  407. height: 100%;
  408. border-radius: 50%;
  409. }
  410. }
  411. .info-detail {
  412. width: 0;
  413. flex-grow: 1;
  414. justify-content: center;
  415. }
  416. .poup-desc {
  417. font-size: 28rpx;
  418. line-height: 1.6;
  419. color: #555 !important;
  420. }
  421. .preview-site {
  422. width: 100%;
  423. height: 300rpx;
  424. }
  425. </style>