friend-links.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. <tm-flotbutton v-if="$haloPluginsConfig.autoSubmitLink.enabled" :offset="[16,80]" label="申请" actions-pos="left" :show-text="true" color="bg-gradient-orange-accent"
  121. @click="toSubmitLinkPage"></tm-flotbutton>
  122. <!-- 详情弹窗 -->
  123. <tm-poup v-model="detail.show" :width="640" height="auto" position="center" :round="6">
  124. <view class="poup pa-36">
  125. <view class="info flex">
  126. <view class="poup-logo bg-gradient-amber-accent pa-4 shadow-24">
  127. <image class="poup-logo_img" :src="detail.data.logo" mode="aspectFill"></image>
  128. </view>
  129. <view class="pl-24 info-detail">
  130. <view class="poup-name text-size-lg text-weight-b">{{ detail.data.name }}</view>
  131. <view class="poup-tag ml--10">
  132. <tm-tags color="bg-gradient-amber-accent" size="n" model="fill">
  133. ID:{{ detail.data.id }}
  134. </tm-tags>
  135. <tm-tags color="bg-gradient-light-blue-lighten" size="n" model="fill">
  136. {{ detail.data.team || '暂未分组' }}
  137. </tm-tags>
  138. </view>
  139. <view class="poup-link text-size-m" @click="fnCopyLink(detail.data)">
  140. <text class="text-orange">{{ detail.data.url }}</text>
  141. <text class="iconfont icon-copy text-size-s ml-6 text-grey"></text>
  142. </view>
  143. </view>
  144. </view>
  145. <view class="poup-desc mt-20">
  146. 博客简介:{{ detail.data.description || '这个博主很懒,没写简介~' }}
  147. </view>
  148. <!-- 博客预览图 -->
  149. <view class="mt-24">
  150. <tm-images :width="568" :round="2" :src="caclSiteThumbnail(detail.data.url)"
  151. mode="aspectFill"></tm-images>
  152. </view>
  153. </view>
  154. </tm-poup>
  155. <view class="load-text">{{ loadMoreText }}</view>
  156. </view>
  157. </view>
  158. </template>
  159. <script>
  160. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  161. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  162. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  163. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  164. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  165. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  166. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  167. import {GetRandomNumberByRange} 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. detail: {
  186. show: false,
  187. data: {}
  188. },
  189. hasNext: false,
  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.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.hasNext = res.hasNext;
  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. toSubmitLinkPage() {
  316. this.$Router.push({
  317. path: '/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>