friend-links.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. haloPluginConfigs() {
  149. return this.$tm.vx.getters().getConfigs.pluginConfig;
  150. },
  151. calcSiteThumbnail(val) {
  152. return val => {
  153. if (!val) return '';
  154. if (val.charAt(val.length - 1) !== '/') {
  155. val = val + '/';
  156. }
  157. return 'https://image.thum.io/get/width/1000/crop/800/' + val;
  158. };
  159. }
  160. },
  161. onLoad() {
  162. this.fnSetPageTitle('友情链接');
  163. this.fnGetLinkGroupData();
  164. },
  165. onPullDownRefresh() {
  166. this.isLoadMore = false;
  167. this.queryParams.page = 1;
  168. this.dataList = []
  169. this.fnGetData();
  170. },
  171. onReachBottom(e) {
  172. if (this.hasNext) {
  173. this.queryParams.page += 1;
  174. this.isLoadMore = true;
  175. this.fnGetData();
  176. } else {
  177. uni.showToast({
  178. icon: 'none',
  179. title: '没有更多数据了'
  180. });
  181. }
  182. },
  183. methods: {
  184. fnGetLinkGroupData() {
  185. this.$httpApi.v2
  186. .getFriendLinkGroupList({
  187. page: 1,
  188. size: 0
  189. })
  190. .then(res => {
  191. this.linkGroupList = res.items;
  192. this.fnGetData()
  193. })
  194. .catch(err => {
  195. console.error(err);
  196. });
  197. },
  198. findLinkGroupDisplayNameByGroupMetadataName(groupName) {
  199. if (this.linkGroupList.length === 0) return groupName || "未分组"
  200. return this.linkGroupList.find(item => item.metadata.name === groupName)?.spec?.displayName || groupName || "未分组"
  201. },
  202. fnGetData() {
  203. if (!this.isLoadMore) {
  204. this.loading = 'loading';
  205. }
  206. this.loadMoreText = '';
  207. this.$httpApi.v2
  208. .getFriendLinkList(this.queryParams)
  209. .then(res => {
  210. console.log('请求结果:');
  211. console.log(res);
  212. this.hasNext = res.hasNext;
  213. const list = res.items.map(item => {
  214. item.spec.logo = this.$utils.checkAvatarUrl(item.spec?.logo)
  215. item.spec.groupName = this.findLinkGroupDisplayNameByGroupMetadataName(item.spec?.groupName)
  216. return item;
  217. })
  218. this.dataList = this.dataList.concat(list);
  219. setTimeout(() => {
  220. this.loading = 'success';
  221. this.loadMoreText = res.hasNext ? '上拉加载更多' : '呜呜,没有更多数据啦~';
  222. }, 500);
  223. })
  224. .catch(err => {
  225. console.error(err);
  226. this.loading = 'error';
  227. this.loadMoreText = '加载失败,请下拉刷新!';
  228. })
  229. .finally(() => {
  230. setTimeout(() => {
  231. uni.hideLoading();
  232. uni.stopPullDownRefresh();
  233. }, 500);
  234. });
  235. },
  236. handleGroup(list) {
  237. const group = {}
  238. list.forEach(item => {
  239. if (group[item.spec.groupName]) {
  240. group[item.spec.groupName].children.push(item)
  241. } else {
  242. group[item.spec.groupName] = {
  243. title: item.spec.groupName,
  244. children: [item]
  245. }
  246. }
  247. })
  248. return Object.keys(group).map(key => {
  249. const {
  250. title,
  251. children = []
  252. } = group[key]
  253. return {
  254. title,
  255. children
  256. }
  257. })
  258. },
  259. fnOnLinkEvent(link) {
  260. this.detail.data = link;
  261. this.detail.show = true;
  262. },
  263. fnCopyLink(link) {
  264. uni.setClipboardData({
  265. data: `${link.spec.displayName}:${link.spec.url}`,
  266. showToast: false,
  267. success: () => {
  268. uni.showToast({
  269. icon: 'none',
  270. title: '链接复制成功!'
  271. });
  272. },
  273. fail: () => {
  274. uni.showToast({
  275. icon: 'none',
  276. title: '复制失败!'
  277. });
  278. }
  279. });
  280. },
  281. toSubmitLinkPage() {
  282. uni.navigateTo({
  283. url: '/pagesA/submit-link/submit-link'
  284. })
  285. }
  286. }
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .app-page {
  291. width: 100vw;
  292. min-height: 100vh;
  293. display: flex;
  294. flex-direction: column;
  295. background-color: #fafafd;
  296. }
  297. .loading-wrap {
  298. padding: 24rpx;
  299. min-height: 100vh;
  300. }
  301. .content {
  302. padding: 0 24rpx;
  303. padding-top: 24rpx;
  304. .content-empty {
  305. height: 60vh;
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. }
  310. }
  311. .link-card {
  312. border-bottom: 2rpx solid #f5f5f5;
  313. background-color: #ffffff;
  314. &.one {
  315. border: 0;
  316. box-shadow: 0rpx 2rpx 24rpx 0rpx rgba(0, 0, 0, 0.03);
  317. .logo {
  318. box-shadow: 0rpx 2rpx 12rpx rgba(0, 0, 0, 0.1);
  319. }
  320. }
  321. .logo {
  322. // width: 126rpx;
  323. // height: 126rpx;
  324. width: 80rpx;
  325. height: 80rpx;
  326. border-radius: 12rpx;
  327. border: 6rpx solid #ffffff;
  328. box-shadow: none;
  329. }
  330. .info {
  331. width: 0;
  332. flex-grow: 1;
  333. .name {
  334. white-space: nowrap;
  335. overflow: hidden;
  336. text-overflow: ellipsis;
  337. color: #303133;
  338. font-size: 30rpx;
  339. font-weight: bold;
  340. }
  341. .desc {
  342. white-space: nowrap;
  343. overflow: hidden;
  344. text-overflow: ellipsis;
  345. color: #303133;
  346. font-size: 28rpx;
  347. }
  348. }
  349. }
  350. .link-card_name {
  351. // color: #303133;
  352. // color: #0080fe;
  353. }
  354. .link-card_desc {
  355. font-size: 24rpx;
  356. line-height: 1.6;
  357. color: #303133;
  358. }
  359. .link-logo {
  360. width: 140rpx;
  361. height: 140rpx;
  362. &_img {
  363. width: 100%;
  364. height: 100%;
  365. }
  366. }
  367. .poup-logo {
  368. width: 140rpx;
  369. height: 140rpx;
  370. border-radius: 50%;
  371. &_img {
  372. width: 100%;
  373. height: 100%;
  374. border-radius: 50%;
  375. }
  376. }
  377. .info-detail {
  378. width: 0;
  379. flex-grow: 1;
  380. justify-content: center;
  381. }
  382. .poup-desc {
  383. font-size: 28rpx;
  384. line-height: 1.6;
  385. color: #555 !important;
  386. }
  387. .preview-site {
  388. width: 100%;
  389. height: 300rpx;
  390. }
  391. </style>