index.vue 4.56 KB
Newer Older
何虹's avatar
何虹 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
<template>
  <div class="tools_button" :id='elId'>
    <template>
      <el-button-group>
        <template v-for="(item,index) in button_list">
          <el-button  :disabled='disabledItem(item)' v-if="!item.isMore&&showItem(item)" :key="index" size="mini" type="primary" @click.stop="itemClickAction(item)" :icon='item.icon'>
            {{item.label}}
          </el-button>
        </template>
      </el-button-group>
    </template>
    <el-dropdown size="mini" type="primary" v-if="isShowMoreIcon">
      <el-button type="primary" size="mini">
        <i class="el-icon-arrow-down el-icon--right"></i>
      </el-button>
    <el-dropdown-menu slot="dropdown">
      <template v-for="(item,index) in button_list">
          <el-dropdown-item :disabled='disabledItem(item)' v-if="item.isMore&&showItem(item)" :key="index" class="eldropdownitem" @click.native="itemClickAction(item)">
            {{item.label}}
          </el-dropdown-item>
      </template>
    </el-dropdown-menu>
  </el-dropdown>
        <jsoneditor
            v-model='jsoneditorVisible'
            :elInfo='elInfo'
            :jsoneditorCloseAfter='jsoneditorCloseAfter'
            :jsoneditorOpenAfter='jsoneditorOpenAfter'
            >
      </jsoneditor>
  </div>
</template>
<script>
import jsoneditor from '../common/jsoneditor'
import ucComponent from '../ucClass/uc_component'
export default {
  name: 'hsButtonGroup',
  mixins: [ucComponent],
  components: {
    jsoneditor
  },
  props: {
    elInfo: {},
    allSourceData: {
      default() {
        return {
          config: {},
          sourceData: []
        }
      }
    },
    jsoneditorData: {},
    jsoneditorCloseAfter: {
      default() {
        return () => {}
      }
    },
    jsoneditorOpenAfter: {
      default() {
        return () => {}
      }
    },
    activeManager: {

    },
    bill_status: {

    }
  },
  data() {
    return {
      jsoneditorVisible: false,
      hsActionButtons: [],
      button_list: [
      ],
      isShowMoreIcon: false
    }
  },
  watch: {
    allSourceData: {
      handler: function(newData) {
        this.initConfigData(newData)
      },
      deep: true
    }
  },
  mounted() {
    this.initConfigData(this.allSourceData)
  },
  methods: {
    disabledItem(item) {
      const { disabled } = item
      const type = typeof disabled
      if (type === 'boolean' || type === undefined) {
        return !!disabled
      } else if (type === 'function') {
        const data = {
          item
        }
        return disabled(data)
      }
    },
    showItem(item = {}) {
      const { isHide } = item
      const data = {
        item
      }
      const type = typeof isHide
      if (type === 'boolean' || type === undefined) {
        return !isHide
      } else if (type === 'function') {
        return isHide(data)
      } else {
        return true
      }
    },
    itemClickAction(item) {
      const { click } = item
      const type = typeof click
      if (type === 'string' && click.startsWith('$')) {
        const item_ = Object.assign({}, item)
        item_.click = item_.click.substr(1)
        this.itemClick(item_)
      } else if (type === 'function') { // 调用页面上的action
        const data = {
          item
        }
        click(data)
      }
    },
    itemClick(item) {
      this.$emit('itemClick', item)
    },
    initConfigData(data) {
      const { config } = data
      const buttonList = config.buttonList || this.button_list
      const showButtons = config.showButtons
      if (showButtons && !buttonList.length) {
        this.button_list = [
          {
            'label': '',
            'icon': 'el-icon-refresh',
            'click': '$refresh',
            'isMore': false,
            'isHide': false
          }, {
            'label': '配置',
            'icon': '',
            'click': '$setPageConfig',
            'isHide': false,
            'isMore': true
          }]
      } else {
        this.button_list = buttonList
      }
      const user_info = sessionStorage['user_info']
      if (user_info) {
        const user_info_json = JSON.parse(user_info)
        const { is_admin } = user_info_json
        if (!is_admin) {
          this.button_list = this.button_list.filter(item => item.click !== '$setAction' && item.click !== '$setPageConfig')
        }
      }
      const r = buttonList.find(item => !item.isHide && item.isMore)
      this.isShowMoreIcon = !!r
    }
  }
}
</script>
<style scoped>
.tools_button{
  display: flex;
  min-width: 45px;
  min-height: 30px;
}
.isEmpityStyle{
 width: 40px;
}
.eldropdownitem{
  width:100px;
  padding: 5px;
  text-align: center;
}
</style>