123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- <template>
- <div class="keep-group">
- <div class="flex-r-c">
- <div class="title-group flex-r-c center left">
- <h5>{{ title }}</h5>
- </div>
- </div>
- <div class="hot-keep-group flex-r-c wrap">
- <div class="card-item flex-r-c" v-for="item in options" :key="item.id" @click="goContent(item)">
- <div class="mini-img-group">
- <img :src="item.img" alt="" @error="handleError">
- <i :class="'el-icon-jy-' + item.type" />
- </div>
- <div class="flex-c-c">
- <div class="flex">
- <div class="title-text van-multi-ellipsis--l2">{{ item.title }}</div>
- </div>
- <div class="money-group center left">
- {{ item.docTags }}
- </div>
- <div class="flex-c-c info-text">
- <span v-if="item.contribution">贡献者: {{ item.contribution }}</span>
- <div class="info-text-group flex-r-c center left">
- <span v-if="item.viewTimes">{{ SetViewUnit(item.viewTimes) }}浏览</span>
- <span v-if="item.page">共{{ item.page }}页</span>
- <span v-if="item.size">{{ item.size | sizeFormatter }}</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: 'SelectedRecommend',
- props: {
- title: {
- type: String,
- default: '精选推荐'
- },
- options: {
- type: Array,
- default: () => []
- }
- },
- watch: {
- options (val) {
- if (val.length > 0) {
- this.$nextTick(() => {
- this.setItemwidth()
- })
- }
- }
- },
- data () {
- return {}
- },
- methods: {
- handleError (img) {
- img.target.src = require('../assets/images/error.png')
- },
- SetViewUnit (num) {
- let newNum = 0
- if (!num) return 0
- if (num > 10000) {
- newNum = (num / 10000).toFixed(1) + 'w'
- } else {
- newNum = num
- }
- return newNum
- },
- goContent (item) {
- this.$emit('click', item)
- },
- setItemwidth () { // 适配嵌入工作台内
- const bodyWidth = window.screen.width - 212
- if (window.goTemplateData && window.goTemplateData.inIframe && bodyWidth > 1248) {
- const element = document.querySelectorAll('.card-item')[0]
- const itemwidth = element.offsetWidth + 104 // 104是margin
- const num = Math.floor((bodyWidth - 96) / itemwidth)
- const newwidth = ((Math.floor((bodyWidth - (itemwidth * num) - 96) / num)) + itemwidth) - 104
- var elements = document.querySelectorAll('.card-item')
- elements.forEach(function (ele) {
- ele.style.width = newwidth + 'px' // 设置新的宽度
- console.log(ele.style.width)
- })
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .keep-group {
- margin-top: 38px;
- padding-bottom: 50px;
- @include diy-icon('iconJianYu', 24, 24);
- @include diy-icon('pdf', 24);
- @include diy-icon('word', 24);
- @include diy-icon('excel', 24);
- @include diy-icon('ppt', 24);
- .title-group {
- margin-bottom: 16px;
- h5 {
- color: #1D1D1D;
- font-family: Microsoft YaHei;
- font-size: 18px;
- font-weight: 400;
- line-height: 28px;
- letter-spacing: 0px;
- text-align: left;
- margin-right: 9px;
- }
- }
- .card-item {
- cursor: pointer;
- justify-content: flex-start;
- padding: 8px 0 12px;
- box-sizing: border-box;
- &:hover {
- .title-text {
- color: #2ABED1;
- }
- }
- .money-group {
- display: block;
- margin-top: 18px;
- width: 180px;
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- font-size: 13px;
- line-height: 22px;
- color: #999999;
- }
- .mini-img-group {
- flex-shrink: 0;
- position: relative;
- border-radius: 4px;
- border: 1px solid #ececec;
- width: 80px;
- height: 112px;
- margin-right: 16px;
- overflow: hidden;
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: center;
- img {
- width: 100%;
- }
- i {
- position: absolute;
- right: 0;
- bottom: 0;
- }
- }
- .info-text-group {
- span {
- display: inline-block;
- &:last-child {
- &::after {
- content: unset;
- }
- }
- &::after {
- content: "|";
- padding: 0 4px;
- color: #ececec;
- }
- }
- }
- .info-text {
- font-family: Microsoft YaHei;
- font-style: normal;
- font-weight: normal;
- font-size: 13px;
- line-height: 24px;
- color: #999999;
- }
- .red-text {
- color: #FF3A20;
- font-family: Microsoft YaHei;
- font-style: normal;
- font-weight: normal;
- font-size: 18px;
- line-height: 28px;
- }
- .title-text {
- width: 183px;
- font-family: Microsoft YaHei;
- font-style: normal;
- font-weight: normal;
- font-size: 16px;
- line-height: 24px;
- color: #1D1D1D;
- word-wrap: break-word;
- }
- }
- .van-ellipsis {
- overflow: hidden;
- white-space: nowrap;
- text-overflow: ellipsis;
- }
- .van-multi-ellipsis--l2 {
- display: -webkit-box;
- overflow: hidden;
- text-overflow: ellipsis;
- -webkit-line-clamp: 2;
- -webkit-box-orient: vertical;
- }
- .hot-keep-group {
- .card-item {
- width: 279px;
- overflow: hidden;
- }
- }
- }
- .in-app {
- // 工作台内适配
- .hot-keep-group {
- justify-content: flex-start !important;
- @media screen and (max-width: 1248px) {
- .card-item {
- margin-right: 41px;
- }
- }
- @media screen and (min-width: 1248px) {
- .card-item {
- margin-right: 104px;
- }
- }
- }
- }
- </style>
|