friend-links.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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="fnCopyLink(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;" color="bg-gradient-light-blue-lighten"
  29. :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="fnCopyLink(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. <!-- 如果大于一个分组:使用联系人的索引形式 dataList.length > 1 -->
  65. <block v-if="false">
  66. <block v-for="(team, index) in dataList" :key="index">
  67. <tm-translate animation-name="fadeUp" :wait="calcAniWait(index)">
  68. <view class="grey-lighten-4 text text-size-s text-weight-b px-32 py-12">{{ team.title }}</view>
  69. <block v-for="(link, linkIndex) in team.children" :key="link.metadata.name">
  70. <tm-translate animation-name="fadeUp" :wait="calcAniWait(linkIndex)">
  71. <!-- 色彩版本 -->
  72. <view v-if="!globalAppSettings.links.useSimple"
  73. class="info flex pt-24 pb-24 pl-12 pr-12" :class="{
  74. 'border-b-1':
  75. linkIndex != team.children.length - 1 || index == dataList.length - 1
  76. }" @click="fnCopyLink(link)">
  77. <view class="link-logo">
  78. <cache-image class="link-logo_img" radius="12rpx" :url="link.spec.logo"
  79. :fileMd5="link.spec.logo" mode="aspectFill"></cache-image>
  80. </view>
  81. <view class="flex flex-col pl-30 info-detail">
  82. <view class="link-card_name text-size-l text-weight-b text-red">
  83. {{ link.spec.displayName }}
  84. </view>
  85. <view class="poup-tag ml--10 mt-6">
  86. <tm-tags color="bg-gradient-amber-accent" :shadow="0" size="s" model="fill">
  87. ID:{{ link.metadata.name }}
  88. </tm-tags>
  89. <tm-tags color=" bg-gradient-light-blue-lighten" :shadow="0" size="s"
  90. model="fill">
  91. {{ link.spec.groupName || '暂未分组' }}
  92. </tm-tags>
  93. </view>
  94. <view class="link-card_desc text-overflow text-size-s mt-4">
  95. 博客简介:{{ link.spec.description || '这个博主很懒,没写简介~' }}
  96. </view>
  97. </view>
  98. </view>
  99. <!-- 简洁版本 -->
  100. <view v-else class="link-card flex ml-24 mr-24 pt-24 pb-24" @click="fnCopyLink(link)">
  101. <image class="logo shadow-6" :src="link.spec.logo" mode="aspectFill"></image>
  102. <view class="info pl-24">
  103. <view class="name text-size-g">{{ link.spec.displayName }}</view>
  104. <view class="desc mt-12 text-size-s text-grey-darken-1">
  105. {{ link.spec.description }}
  106. </view>
  107. <view v-if="false" class="link mt-12 text-size-m text-grey-darken-1">
  108. <text class="iconfont icon-link mr-6 text-size-s"></text>
  109. {{ link.spec.url }}
  110. </view>
  111. </view>
  112. </view>
  113. </tm-translate>
  114. </block>
  115. </tm-translate>
  116. </block>
  117. </block>
  118. <!-- 返回顶部 -->
  119. <tm-flotbutton color="light-blue" @click="fnToTopPage" size="m" icon="icon-angle-up"></tm-flotbutton>
  120. <!-- 详情弹窗 -->
  121. <tm-poup v-model="detail.show" :width="640" height="auto" position="center" :round="6">
  122. <view class="poup pa-36">
  123. <view class="info flex">
  124. <view class="poup-logo bg-gradient-amber-accent pa-4 shadow-24">
  125. <image class="poup-logo_img" :src="detail.data.logo" mode="aspectFill"></image>
  126. </view>
  127. <view class="pl-24 info-detail">
  128. <view class="poup-name text-size-lg text-weight-b">{{ detail.data.name }}</view>
  129. <view class="poup-tag ml--10">
  130. <tm-tags color="bg-gradient-amber-accent" size="n" model="fill">
  131. ID:{{ detail.data.id }}
  132. </tm-tags>
  133. <tm-tags color="bg-gradient-light-blue-lighten" size="n" model="fill">
  134. {{ detail.data.team || '暂未分组' }}
  135. </tm-tags>
  136. </view>
  137. <view class="poup-link text-size-m" @click="fnCopyLink(detail.data)">
  138. <text class="text-orange">{{ detail.data.url }}</text>
  139. <text class="iconfont icon-copy text-size-s ml-6 text-grey"></text>
  140. </view>
  141. </view>
  142. </view>
  143. <view class="poup-desc mt-20">
  144. 博客简介:{{ detail.data.description || '这个博主很懒,没写简介~' }}
  145. </view>
  146. <!-- 博客预览图 -->
  147. <view class="mt-24">
  148. <tm-images :width="568" :round="2" :src="caclSiteThumbnail(detail.data.url)"
  149. mode="aspectFill"></tm-images>
  150. </view>
  151. </view>
  152. </tm-poup>
  153. <view class="load-text">{{ loadMoreText }}</view>
  154. </view>
  155. </view>
  156. </template>
  157. <script>
  158. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  159. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  160. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  161. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  162. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  163. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  164. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  165. import {
  166. GetRandomNumberByRange
  167. } from '@/utils/random.js';
  168. export default {
  169. components: {
  170. tmSkeleton,
  171. tmTranslate,
  172. tmFlotbutton,
  173. tmTags,
  174. tmEmpty,
  175. tmImages,
  176. tmPoup
  177. },
  178. data() {
  179. return {
  180. loading: 'loading',
  181. queryParams: {
  182. size: 10,
  183. page: 1
  184. },
  185. result: {},
  186. detail: {
  187. show: false,
  188. data: {}
  189. },
  190. isLoadMore: false,
  191. loadMoreText: '',
  192. dataList: [],
  193. cacheDataList: []
  194. };
  195. },
  196. computed: {
  197. caclSiteThumbnail(val) {
  198. return val => {
  199. if (!val) return '';
  200. if (val.charAt(val.length - 1) != '/') {
  201. val = val + '/';
  202. }
  203. return 'https://image.thum.io/get/width/1000/crop/800/' + val;
  204. };
  205. }
  206. },
  207. onLoad() {
  208. this.fnSetPageTitle('朋友圈');
  209. this.fnGetData();
  210. },
  211. onPullDownRefresh() {
  212. this.isLoadMore = false;
  213. this.queryParams.page = 1;
  214. this.dataList = []
  215. this.cacheDataList = []
  216. this.fnGetData();
  217. },
  218. onReachBottom(e) {
  219. if (this.result.hasNext) {
  220. this.queryParams.page += 1;
  221. this.isLoadMore = true;
  222. this.fnGetData();
  223. } else {
  224. uni.showToast({
  225. icon: 'none',
  226. title: '没有更多数据了'
  227. });
  228. }
  229. },
  230. methods: {
  231. fnRandomColor() {
  232. const _r = GetRandomNumberByRange(0, this.$haloConfig.colors.length - 1);
  233. return this.$haloConfig.colors[_r];
  234. },
  235. fnGetData() {
  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.result = res;
  246. const list = res.items.map(item => {
  247. item.spec.logo = this.$utils.checkAvatarUrl(item.spec.logo)
  248. return item;
  249. })
  250. this.dataList = this.dataList.concat(list);
  251. // this.cacheDataList = this.cacheDataList.concat(list);
  252. // this.dataList = this.handleGroup(this.cacheDataList).reverse();
  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.name}:${link.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. }
  316. };
  317. </script>
  318. <style lang="scss" scoped>
  319. .app-page {
  320. width: 100vw;
  321. min-height: 100vh;
  322. display: flex;
  323. flex-direction: column;
  324. background-color: #fafafd;
  325. }
  326. .loading-wrap {
  327. padding: 24rpx;
  328. min-height: 100vh;
  329. }
  330. .content {
  331. padding: 0 24rpx;
  332. padding-top: 24rpx;
  333. .content-empty {
  334. height: 60vh;
  335. display: flex;
  336. align-items: center;
  337. justify-content: center;
  338. }
  339. }
  340. .link-card {
  341. border-bottom: 2rpx solid #f5f5f5;
  342. background-color: #ffffff;
  343. &.one {
  344. border: 0;
  345. box-shadow: 0rpx 2rpx 24rpx 0rpx rgba(0, 0, 0, 0.03);
  346. .logo {
  347. box-shadow: 0rpx 2rpx 12rpx rgba(0, 0, 0, 0.1);
  348. }
  349. }
  350. .logo {
  351. // width: 126rpx;
  352. // height: 126rpx;
  353. width: 80rpx;
  354. height: 80rpx;
  355. border-radius: 12rpx;
  356. border: 6rpx solid #ffffff;
  357. box-shadow: none;
  358. }
  359. .info {
  360. width: 0;
  361. flex-grow: 1;
  362. .name {
  363. white-space: nowrap;
  364. overflow: hidden;
  365. text-overflow: ellipsis;
  366. color: #303133;
  367. font-size: 30rpx;
  368. font-weight: bold;
  369. }
  370. .desc {
  371. white-space: nowrap;
  372. overflow: hidden;
  373. text-overflow: ellipsis;
  374. color: #303133;
  375. font-size: 28rpx;
  376. }
  377. }
  378. }
  379. .link-card_name {
  380. // color: #303133;
  381. // color: #0080fe;
  382. }
  383. .link-card_desc {
  384. font-size: 24rpx;
  385. line-height: 1.6;
  386. color: #303133;
  387. }
  388. .link-logo {
  389. width: 140rpx;
  390. height: 140rpx;
  391. &_img {
  392. width: 100%;
  393. height: 100%;
  394. }
  395. }
  396. .poup-logo {
  397. width: 140rpx;
  398. height: 140rpx;
  399. border-radius: 50%;
  400. &_img {
  401. width: 100%;
  402. height: 100%;
  403. border-radius: 50%;
  404. }
  405. }
  406. .info-detail {
  407. width: 0;
  408. flex-grow: 1;
  409. justify-content: center;
  410. }
  411. .poup-desc {
  412. font-size: 28rpx;
  413. line-height: 1.6;
  414. color: #555 !important;
  415. }
  416. .preview-site {
  417. width: 100%;
  418. height: 300rpx;
  419. }
  420. </style>