1
0

friend-links.vue 15 KB

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