byTool.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <div class="tool">
  3. <div class="tool-left">
  4. <el-button
  5. v-for="(item,index) of showTools"
  6. :icon="item.icon"
  7. :key="index"
  8. size="small"
  9. v-hasPermi="[item.audit]"
  10. @click="clickHandle(item)">
  11. {{ item.name }}
  12. </el-button>
  13. <slot name="tool-left" />
  14. </div>
  15. <div class="tool-right">
  16. <el-tooltip class="item" effect="dark" :content="openSearch ? '隐藏搜索' : '显示搜索'" placement="top">
  17. <el-button :icon="openSearch?'el-icon-search':'el-icon-minus'" size="small" circle v-if="propTools.search" @click="toggleSearch"></el-button>
  18. </el-tooltip>
  19. <el-tooltip class="item" effect="dark" content="刷新" placement="top">
  20. <el-button icon="el-icon-refresh" size="small" circle v-if="propTools.refresh" @click="refresh"></el-button>
  21. </el-tooltip>
  22. <slot name="tool-right" />
  23. </div>
  24. </div>
  25. </template>
  26. <script lang="ts">
  27. import { Component, Prop, Vue, Mixins } from 'vue-property-decorator'
  28. @Component({
  29. // components: { logDrawer }
  30. })
  31. export default class GmTools extends Vue {
  32. openSearch:boolean = true
  33. @Prop()
  34. propConfig:any
  35. @Prop()
  36. customTools:any;
  37. get audit(){
  38. return this.propConfig?.audit ? this.propConfig.audit : {}
  39. }
  40. get propTools(){
  41. return this.propConfig?.tools ? this.propConfig.tools : {}
  42. }
  43. tools:Array<any>=[
  44. { name: '返回', icon: 'el-icon-arrow-left', clickName: 'onReturn', _class: 'return' },
  45. { name: '新增', icon: 'el-icon-plus', clickName: 'onAdd', _class: 'add' },
  46. { name: '保存', icon: 'el-icon-plus', clickName: 'onSave', _class: 'save' },
  47. { name: '提交', icon: 'el-icon-finished', clickName: 'onSmt', _class: 'smt' },
  48. { name: '反提交', icon: 'el-icon-finished', clickName: 'onReturnSmt', _class: 'returnSmt' },
  49. { name: '接单', icon: 'el-icon-sold-out', clickName: 'onOrder', _class: 'order' },
  50. { name: '派单', icon: 'el-icon-sell', clickName: 'onDispatch', _class: 'dispatch' },
  51. { name: '修改', icon: 'el-icon-edit', clickName: 'onUpdate', _class: 'edit' },
  52. { name: '取消提交', icon: 'el-icon-refresh-left', clickName: 'onReSmt', _class: 'reSmt' },
  53. { name: '删除', icon: 'el-icon-delete', clickName: 'onDelete', _class: 'delete' },
  54. { name: '导出', icon: 'el-icon-download', clickName: 'onExport', _class: 'export' },
  55. ]
  56. showTools:Array<any>=[]
  57. created(){
  58. this.initTools()
  59. }
  60. initTools(){
  61. this.showTools = [];
  62. if(this.propConfig?.tools){
  63. this.setTool(this.propConfig?.tools)
  64. }
  65. if(this.propConfig?.customTools && this.propConfig?.customTools.length > 0){
  66. this.setCustomTools(this.propConfig?.customTools)
  67. }
  68. if(this.customTools){
  69. this.setCustomTools(this.customTools)
  70. }
  71. }
  72. setTool(data:any){
  73. this.showTools = [];
  74. for(const item of this.tools){
  75. if(data[item._class]){
  76. let obj:any = (this as any).$lodash.cloneDeep(item);
  77. if(this.audit){
  78. obj.audit = this.audit[item._class]
  79. }
  80. this.showTools.push(obj)
  81. }
  82. }
  83. }
  84. //自定义工具栏按钮设置
  85. setCustomTools(tools:Array<any>){
  86. for(const item of tools){
  87. this.showTools.push(item)
  88. }
  89. }
  90. //点击刷新按钮
  91. refresh(){
  92. this.$emit('clickHandle','onRefresh')
  93. }
  94. //点击搜索
  95. toggleSearch(){
  96. this.openSearch = !this.openSearch;
  97. this.$emit('clickHandle','toggleSearch')
  98. }
  99. clickHandle(item:any){
  100. if(item?.event?.click){
  101. item.event.click()
  102. }else{
  103. this.$emit('clickHandle',item.clickName)
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .tool{
  110. width: 100%;
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. .tool-left{
  115. width: 100%;
  116. }
  117. .tool-right{
  118. flex-shrink: 0;
  119. display: flex;
  120. align-items: center;
  121. }
  122. }
  123. </style>