links.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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">
  11. <!-- 空数据 -->
  12. <view v-if="result.length == 0" class="content-empty flex flex-center"><tm-empty icon="icon-shiliangzhinengduixiang-" label="啊偶,博主还没有朋友呢~"></tm-empty></view>
  13. <!-- 如果只有一个分组:使用列表的形式 result.length == 1 -->
  14. <view v-else-if="result.length == 1" class="flex flex-col pb-24">
  15. <block v-for="(item, index) in result[0].children" :key="index">
  16. <tm-translate animation-name="fadeUp" :wait="(index + 1) * 50">
  17. <view class="link-card one round-a-6 flex ma-24 mb-0 pa-24" @click="fnOnLinkEvent(item)">
  18. <cache-image class="logo shadow-2" radius="12rpx" width="80rpx" height="80rpx" :url="item.logo" :fileMd5="item.logo" mode="aspectFill"></cache-image>
  19. <view class="info pl-24">
  20. <view class="name text-size-g">{{ item.name }}</view>
  21. <view class="desc mt-12 text-size-s text-grey-darken-1">{{ item.description }}</view>
  22. <view class="link mt-12 text-size-m text-grey-darken-1">
  23. <text class="iconfont icon-link mr-6 text-size-s"></text>
  24. {{ item.url }}
  25. </view>
  26. </view>
  27. </view>
  28. </tm-translate>
  29. </block>
  30. </view>
  31. <!-- 如果大于一个分组:使用联系人的索引形式 result.length > 1 -->
  32. <block v-else>
  33. <block v-for="(team, index) in result" :key="index">
  34. <view class="grey-lighten-4 text text-size-s text-weight-b px-32 py-12">{{ team.title }}</view>
  35. <block v-for="(link, linkIndex) in team.children" :key="link.id">
  36. <!-- 艳丽版本 -->
  37. <view
  38. v-if="!globalAppSettings.links.useSimple"
  39. class="info flex pa-36"
  40. :class="{ 'border-b-1': linkIndex != team.children.length - 1 }"
  41. @click="fnOnLinkEvent(link)"
  42. >
  43. <view class="link-logo"><cache-image class="link-logo_img" radius="12rpx" :url="link.logo" :fileMd5="link.logo" mode="aspectFill"></cache-image></view>
  44. <view class="flex flex-col pl-30 info-detail">
  45. <view class="link-card_name text-size-l text-weight-b text-red">{{ link.name }}</view>
  46. <view class="poup-tag ml--10 mt-6">
  47. <tm-tags color="bg-gradient-amber-accent" :shadow="0" size="s" model="fill">ID:{{ link.id }}</tm-tags>
  48. <tm-tags color=" bg-gradient-light-blue-lighten" :shadow="0" size="s" model="fill">{{ link.team }}</tm-tags>
  49. </view>
  50. <view class="link-card_desc text-overflow text-size-s mt-4">博客简介:{{ link.description || '这个博主很懒,没写简介~' }}</view>
  51. </view>
  52. </view>
  53. <!-- 简洁版本 -->
  54. <view v-else class="link-card flex ml-24 mr-24 pt-24 pb-24" @click="fnOnLinkEvent(link)">
  55. <image class="logo shadow-6" :src="link.logo" mode="aspectFill"></image>
  56. <view class="info pl-24">
  57. <view class="name text-size-g">{{ link.name }}</view>
  58. <view class="desc mt-12 text-size-s text-grey-darken-1">{{ link.description }}</view>
  59. <view v-if="false" class="link mt-12 text-size-m text-grey-darken-1">
  60. <text class="iconfont icon-link mr-6 text-size-s"></text>
  61. {{ link.url }}
  62. </view>
  63. </view>
  64. </view>
  65. </block>
  66. </block>
  67. </block>
  68. <!-- 返回顶部 -->
  69. <tm-flotbutton v-if="linkTotal > 10" color="light-blue" @click="fnToTopPage" size="m" icon="icon-angle-up"></tm-flotbutton>
  70. <!-- 详情弹窗 -->
  71. <tm-poup v-model="detail.show" :width="640" height="auto" position="center" :round="6">
  72. <view class="poup pa-36">
  73. <view class="info flex">
  74. <view class="poup-logo bg-gradient-amber-accent pa-4 shadow-24"><image class="poup-logo_img" :src="detail.data.logo" mode="aspectFill"></image></view>
  75. <view class="pl-24 info-detail">
  76. <view class="poup-name text-size-lg text-weight-b">{{ detail.data.name }}</view>
  77. <view class="poup-tag ml--10">
  78. <tm-tags color="bg-gradient-amber-accent" size="n" model="fill">ID:{{ detail.data.id }}</tm-tags>
  79. <tm-tags color="bg-gradient-light-blue-lighten" size="n" model="fill">{{ detail.data.team }}</tm-tags>
  80. </view>
  81. <view class="poup-link text-size-m" @click="fnCopyLink(detail.data)">
  82. <text class="text-orange">{{ detail.data.url }}</text>
  83. <text class="iconfont icon-copy text-size-s ml-6 text-grey"></text>
  84. </view>
  85. </view>
  86. </view>
  87. <view class="poup-desc mt-20">博客简介:{{ detail.data.description || '这个博主很懒,没写简介~' }}</view>
  88. <!-- 博客预览图 -->
  89. <view class="mt-24"><tm-images :width="568" :round="2" :src="caclSiteThumbnail(detail.data.url)" mode="aspectFill"></tm-images></view>
  90. </view>
  91. </tm-poup>
  92. </view>
  93. </view>
  94. </template>
  95. <script>
  96. import tmSkeleton from '@/tm-vuetify/components/tm-skeleton/tm-skeleton.vue';
  97. import tmTranslate from '@/tm-vuetify/components/tm-translate/tm-translate.vue';
  98. import tmFlotbutton from '@/tm-vuetify/components/tm-flotbutton/tm-flotbutton.vue';
  99. import tmTags from '@/tm-vuetify/components/tm-tags/tm-tags.vue';
  100. import tmEmpty from '@/tm-vuetify/components/tm-empty/tm-empty.vue';
  101. import tmImages from '@/tm-vuetify/components/tm-images/tm-images.vue';
  102. import tmPoup from '@/tm-vuetify/components/tm-poup/tm-poup.vue';
  103. import { GetRandomNumberByRange } from '@/utils/random.js';
  104. import findCnChart from '@/tm-vuetify/tool/function/findCnChart.js';
  105. export default {
  106. components: {
  107. tmSkeleton,
  108. tmTranslate,
  109. tmFlotbutton,
  110. tmTags,
  111. tmEmpty,
  112. tmImages,
  113. tmPoup
  114. },
  115. data() {
  116. return {
  117. loading: 'loading',
  118. queryParams: {
  119. size: 10,
  120. page: 0,
  121. sort: ''
  122. },
  123. result: [],
  124. detail: {
  125. show: false,
  126. data: {}
  127. },
  128. linkTotal: 0
  129. };
  130. },
  131. computed: {
  132. caclSiteThumbnail(val) {
  133. return val => {
  134. if (!val) return '';
  135. if (val.charAt(val.length - 1) != '/') {
  136. val = val + '/';
  137. }
  138. return 'https://image.thum.io/get/width/1000/crop/800/' + val;
  139. };
  140. }
  141. },
  142. onLoad() {
  143. this.fnSetPageTitle('朋友圈');
  144. },
  145. created() {
  146. this.fnGetData();
  147. },
  148. onPullDownRefresh() {
  149. this.fnGetData();
  150. },
  151. methods: {
  152. fnRandomColor() {
  153. const _r = GetRandomNumberByRange(0, this.$haloConfig.colors.length - 1);
  154. return this.$haloConfig.colors[_r];
  155. },
  156. fnGetData() {
  157. this.linkTotal = 0;
  158. this.loading = 'loading';
  159. uni.showLoading({
  160. mask: true,
  161. title: '加载中...'
  162. });
  163. this.$httpApi
  164. .getLinkListByTeam()
  165. .then(res => {
  166. if (res.status == 200) {
  167. console.log('请求结果:');
  168. console.log(res);
  169. // 处理数据
  170. const _result = res.data.map(item => {
  171. const _team = item.team || '未分组';
  172. const _firstChart = _team ? _team.substring(0, 1) : '';
  173. const _links = item.links.map(link => {
  174. this.linkTotal += 1;
  175. link.logo = this.$utils.checkAvatarUrl(link.logo);
  176. return link;
  177. });
  178. return {
  179. title: _team,
  180. index: findCnChart(_firstChart),
  181. children: _links
  182. };
  183. });
  184. this.result = _result.reverse();
  185. setTimeout(() => {
  186. this.loading = 'success';
  187. }, 500);
  188. } else {
  189. this.loading = 'error';
  190. }
  191. })
  192. .catch(err => {
  193. console.error(err);
  194. this.loading = 'error';
  195. })
  196. .finally(() => {
  197. setTimeout(() => {
  198. uni.hideLoading();
  199. uni.stopPullDownRefresh();
  200. }, 500);
  201. });
  202. },
  203. fnOnLinkEvent(link) {
  204. this.detail.data = link;
  205. this.detail.show = true;
  206. },
  207. fnCopyLink(link) {
  208. uni.setClipboardData({
  209. data: `${link.name}:${link.url}`,
  210. showToast: false,
  211. success: () => {
  212. uni.showToast({
  213. icon: 'none',
  214. title: '链接复制成功!'
  215. });
  216. },
  217. fail: () => {
  218. uni.showToast({
  219. icon: 'none',
  220. title: '复制失败!'
  221. });
  222. }
  223. });
  224. }
  225. }
  226. };
  227. </script>
  228. <style lang="scss" scoped>
  229. .app-page {
  230. width: 100vw;
  231. min-height: 100vh;
  232. display: flex;
  233. flex-direction: column;
  234. background-color: #fafafd;
  235. }
  236. .loading-wrap {
  237. padding: 24rpx;
  238. min-height: 100vh;
  239. }
  240. .content {
  241. padding: 0 24rpx;
  242. padding-top: 24rpx;
  243. .content-empty {
  244. height: 60vh;
  245. display: flex;
  246. align-items: center;
  247. justify-content: center;
  248. }
  249. }
  250. .link-card {
  251. border-bottom: 2rpx solid #f5f5f5;
  252. background-color: #ffffff;
  253. &.one {
  254. border: 0;
  255. box-shadow: 0rpx 2rpx 24rpx 0rpx rgba(0, 0, 0, 0.03);
  256. .logo {
  257. box-shadow: 0rpx 2rpx 12rpx rgba(0, 0, 0, 0.1);
  258. }
  259. }
  260. .logo {
  261. // width: 126rpx;
  262. // height: 126rpx;
  263. width: 80rpx;
  264. height: 80rpx;
  265. border-radius: 12rpx;
  266. border: 6rpx solid #ffffff;
  267. box-shadow: none;
  268. }
  269. .info {
  270. width: 0;
  271. flex-grow: 1;
  272. .name {
  273. white-space: nowrap;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. color: #303133;
  277. font-size: 30rpx;
  278. font-weight: bold;
  279. }
  280. .desc {
  281. white-space: nowrap;
  282. overflow: hidden;
  283. text-overflow: ellipsis;
  284. color: #303133;
  285. font-size: 28rpx;
  286. }
  287. }
  288. }
  289. .link-card_name {
  290. // color: #303133;
  291. // color: #0080fe;
  292. }
  293. .link-card_desc {
  294. font-size: 24rpx;
  295. line-height: 1.6;
  296. color: #303133;
  297. }
  298. .link-logo {
  299. width: 140rpx;
  300. height: 140rpx;
  301. &_img {
  302. width: 100%;
  303. height: 100%;
  304. }
  305. }
  306. .poup-logo {
  307. width: 140rpx;
  308. height: 140rpx;
  309. border-radius: 50%;
  310. &_img {
  311. width: 100%;
  312. height: 100%;
  313. border-radius: 50%;
  314. }
  315. }
  316. .info-detail {
  317. width: 0;
  318. flex-grow: 1;
  319. justify-content: center;
  320. }
  321. .poup-desc {
  322. font-size: 28rpx;
  323. line-height: 1.6;
  324. color: #555 !important;
  325. }
  326. .preview-site {
  327. width: 100%;
  328. height: 300rpx;
  329. }
  330. </style>