item.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div id="item">
  3. <el-row class="item">
  4. <el-col :span="24" style="padding-bottom: 50px;" @click.native="toEdit">{{ data.content }}</el-col>
  5. <el-col :span="24" v-if="data.type === '0'">
  6. <el-col :span="8" v-for="(i, index) in data.imgUrl" :key="`img${index}`">
  7. <template v-if="index < length - 1">
  8. <van-image :src="i.url" :width="imgpx" :height="imghpx" fit="scale-down" @click="toPreview(index)"></van-image>
  9. </template>
  10. <template v-if="index == length - 1 && data.imgUrl.length <= length">
  11. <van-image :src="i.url" :width="imgpx" :height="imghpx" fit="scale-down" @click="toPreview(index)"></van-image>
  12. </template>
  13. <template v-if="index == length - 1 && data.imgUrl.length > length">
  14. <van-image src="" :width="imgpx" :height="imghpx" fit="scale-down">
  15. <template #error>
  16. <el-row>
  17. <el-col :span="24" style="font-size:32px"> <van-icon name="plus" size="28" /> {{ data.imgUrl.length - length + 1 }} </el-col>
  18. </el-row>
  19. </template>
  20. </van-image>
  21. </template>
  22. </el-col>
  23. </el-col>
  24. <el-col :span="24" v-if="data.type === '1'" style="text-align:center">
  25. <video :src="data.fileUrl[0].url" :width="videopx" :height="videohpx" controls></video>
  26. </el-col>
  27. </el-row>
  28. </div>
  29. </template>
  30. <script>
  31. import { ImagePreview } from 'vant';
  32. import { mapState, createNamespacedHelpers } from 'vuex';
  33. export default {
  34. name: 'item',
  35. props: { data: { type: Object, default: () => {} } },
  36. components: {},
  37. data: function() {
  38. return {
  39. length: 9,
  40. };
  41. },
  42. created() {},
  43. methods: {
  44. toEdit() {
  45. this.$router.push({ path: '/adminCommunity/edit', query: { id: this.data._id } });
  46. },
  47. toPreview(index) {
  48. let arr = [];
  49. if (this.data.type === '0') arr = this.data.imgUrl.map(i => i.url);
  50. ImagePreview({
  51. images: arr,
  52. startPosition: index,
  53. });
  54. },
  55. },
  56. computed: {
  57. ...mapState(['user', 'menuParams']),
  58. pageTitle() {
  59. return `${this.$route.meta.title}`;
  60. },
  61. imgpx() {
  62. return 120;
  63. },
  64. imghpx() {
  65. return this.imgpx * 0.8;
  66. },
  67. videopx() {
  68. console.log(document.body.clientHeight);
  69. return document.body.clientWidth * 0.8;
  70. },
  71. videohpx() {
  72. return document.body.clientHeight * (2 / 10);
  73. },
  74. },
  75. metaInfo() {
  76. return { title: this.$route.meta.title };
  77. },
  78. };
  79. </script>
  80. <style lang="less" scoped>
  81. .item {
  82. border-bottom: 1px solid #ccc;
  83. padding: 8px 0;
  84. .el-col:first-child {
  85. &:extend(.dl2);
  86. }
  87. }
  88. .dl2 {
  89. font-size: 16px;
  90. overflow: hidden;
  91. text-overflow: ellipsis;
  92. -webkit-line-clamp: 2;
  93. word-break: break-all;
  94. display: -webkit-box;
  95. -webkit-box-orient: vertical;
  96. }
  97. /deep/.van-image__img {
  98. border: 1px solid #f1f1f1;
  99. }
  100. </style>