Browse Source

提交动态设置宽

wenmenghao 10 months ago
parent
commit
863b89f41e
1 changed files with 20 additions and 4 deletions
  1. 20 4
      jydocs-pc/src/components/SelectedRecommend.vue

+ 20 - 4
jydocs-pc/src/components/SelectedRecommend.vue

@@ -45,14 +45,17 @@ export default {
       default: () => []
     }
   },
-  data() {
+  data () {
     return {}
   },
+  mounted () {
+    this.setItemwidth()
+  },
   methods: {
-    handleError(img) {
+    handleError (img) {
       img.target.src = require('../assets/images/error.png')
     },
-    SetViewUnit(num) {
+    SetViewUnit (num) {
       let newNum = 0
       if (!num) return 0
       if (num > 10000) {
@@ -62,8 +65,21 @@ export default {
       }
       return newNum
     },
-    goContent(item) {
+    goContent (item) {
       this.$emit('click', item)
+    },
+    setItemwidth () { // 适配嵌入工作台内
+      const bodyWidth = document.body.clientWidth
+      if (window.goTemplateData && window.goTemplateData.inIframe && bodyWidth > 1248) {
+        const element = document.getElementsByClassName('card-item')[0]
+        const itemwidth = element.offsetWidth + 104 // 104是margin
+        const num = Math.floor(bodyWidth / itemwidth)
+        const newwidth = (Math.floor((bodyWidth - (itemwidth * num)) / num)) + itemwidth
+        var elements = document.querySelectorAll('.card-item')
+        elements.forEach(function (ele) {
+          ele.style.width = newwidth + 'px' // 设置新的宽度
+        })
+      }
     }
   }
 }