index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <span class="ibps-actions">
  3. <template v-for="(button,index) in actions">
  4. <!--只显示图标-->
  5. <template v-if="type === 'icon'">
  6. <el-tooltip
  7. v-if="handleActionHidden(button.hidden)"
  8. :key="button.key+index"
  9. v-permission="button.permission"
  10. :content="getLabel(button)"
  11. :disabled="handleActionDisabled(button.disabled)"
  12. placement="bottom-start"
  13. >
  14. <el-button
  15. :key="button.key+index"
  16. :name="button.key"
  17. :size="button.size|| $ELEMENT.size "
  18. :type="getType(button)"
  19. :icon="getIcon(button)"
  20. :disabled="handleActionDisabled(button.disabled)"
  21. class="action-icon"
  22. @click="emitEventHandler('action-event',button,position,data,index)"
  23. />
  24. </el-tooltip>
  25. </template>
  26. <template v-else-if="type==='link'">
  27. <el-link
  28. v-if="handleActionHidden(button.hidden)"
  29. :key="button.key+index"
  30. :type="getType(button)"
  31. :icon="getIcon(button)"
  32. :underline="false"
  33. :disabled="handleActionDisabled(button.disabled)"
  34. @click="emitEventHandler('action-event',button,position,data,index)"
  35. >
  36. {{ `&nbsp;${button.label}` }}
  37. </el-link>
  38. <el-divider
  39. v-if="(actions.length == 2 && index == 0) || (actions.length == 3 && index != 2)"
  40. :key="index"
  41. direction="vertical"
  42. />
  43. </template>
  44. <template v-else-if="type==='linkHide'">
  45. <p>
  46. <el-link
  47. v-if="handleActionHidden(button.hidden)"
  48. :key="button.key+index"
  49. :type="getType(button)"
  50. :underline="false"
  51. :icon="getIcon(button)"
  52. :disabled="handleActionDisabled(button.disabled)"
  53. @click="emitEventHandler('action-event',button,position,data,index)"
  54. >
  55. {{ `&nbsp;${button.label}` }}
  56. </el-link>
  57. </p>
  58. </template>
  59. <template v-else>
  60. <!--下拉-->
  61. <template v-if="button.mode === 'dropdown'">
  62. <el-dropdown
  63. :key="button.key"
  64. :hide-on-click="false"
  65. @command="(action)=> { emitEventHandler('action-event',action,position,data,index) }"
  66. >
  67. <span v-if="button.buttonType==='link'" class="el-dropdown-link">
  68. {{ `&nbsp;${button.label}` }}<i v-if="hasRighticon(button.rightIcon)" class="el-icon-arrow-down el-icon--right" />
  69. </span>
  70. <el-button v-else :type="getType(button)" size="mini" :icon="getIcon(button)">
  71. {{ `&nbsp;${button.label}` }}<i v-if="hasRighticon(button.rightIcon)" class="el-icon-arrow-down el-icon--right" />
  72. </el-button>
  73. <el-dropdown-menu v-if="button.menus && button.menus.length >0" slot="dropdown">
  74. <el-dropdown-item
  75. v-for="menu in button.menus"
  76. :key="menu.key"
  77. :command="menu"
  78. :icon="getIcon(menu)"
  79. >{{ getLabel(menu) }}</el-dropdown-item>
  80. </el-dropdown-menu>
  81. </el-dropdown>
  82. </template>
  83. <!--默认-->
  84. <template v-else>
  85. <el-button
  86. v-if="handleActionHidden(button.hidden)"
  87. :key="button.key+index"
  88. v-permission="button.permission"
  89. :name="button.key"
  90. :size="button.size|| 'mini' "
  91. :type="getType(button)"
  92. :icon="getIcon(button)"
  93. :disabled="handleActionDisabled(button.disabled)"
  94. :autofocus="false"
  95. @click="emitEventHandler('action-event',button,position,data,index)"
  96. >{{ getLabel(button) }}</el-button>
  97. </template>
  98. </template>
  99. </template>
  100. </span>
  101. </template>
  102. <script>
  103. import { getButtonIcon, getButtonType } from '@/utils/button'
  104. import permission from '@/directives/permission/index.js' // 权限判断指令
  105. // 工具类
  106. export default {
  107. name: 'ibps-toolbar',
  108. directives: { permission },
  109. props: {
  110. type: {
  111. type: String,
  112. default: 'button'
  113. },
  114. actions: {
  115. type: Array,
  116. default: () => { return [] }
  117. },
  118. position: {
  119. type: String,
  120. default: 'toolbar'
  121. },
  122. data: Object,
  123. socpe: {
  124. type: Object,
  125. default: () => { return this }
  126. }
  127. },
  128. data () {
  129. return {
  130. buttonStatus: true,
  131. stopTime: null
  132. }
  133. },
  134. methods: {
  135. emitEventHandler (event) {
  136. if (this.buttonStatus) {
  137. this.buttonStatus = false
  138. this.$emit(event, ...Array.from(arguments).slice(1))
  139. }
  140. this.setButton()
  141. },
  142. setButton () { // 添加一个定时器,点击之后延时100ms,防二次点击
  143. clearTimeout(this.stopTime)
  144. this.stopTime = setTimeout(() => {
  145. this.buttonStatus = true
  146. }, 100)
  147. },
  148. /**
  149. * 处理按钮隐藏,显示
  150. */
  151. handleActionHidden (hidden = false) {
  152. let isHidden = !hidden
  153. if (typeof hidden === 'boolean') {
  154. isHidden = !hidden
  155. } else if (typeof hidden === 'function') {
  156. isHidden = !hidden.call(this.socpe, this.data)
  157. }
  158. return isHidden
  159. },
  160. /**
  161. * 处理按钮禁用,显示disabled 的方法
  162. */
  163. handleActionDisabled (disabled = false) {
  164. if (typeof disabled === 'boolean') {
  165. return disabled
  166. } else if (typeof disabled === 'function') {
  167. return disabled.call(this.socpe, this.data)
  168. }
  169. return Boolean(disabled)
  170. },
  171. getLabel ({ label, key }) {
  172. if (label) return label === '搜索' ? '查询' : label
  173. return this.$te('common.buttons.' + key) ? this.$t('common.buttons.' + key) : key
  174. },
  175. getIcon ({ icon, key }) {
  176. if (icon) { return icon }
  177. return getButtonIcon(key)
  178. },
  179. getType ({ type, key }) {
  180. if (type) { return type }
  181. return getButtonType(key)
  182. },
  183. hasRighticon (rightIcon) {
  184. if (rightIcon) { return true }
  185. return true
  186. }
  187. }
  188. }
  189. </script>