diy-header.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template id="diy-header">
  2. <div>
  3. <div class="headers-box" flex="cross:center">
  4. <div class="header-tab-lists" :class="{activeName: current == 0}" flex="cross:center" v-if="activeItem && activeItem.funcListItem" @click="toggleTab(0)">
  5. <div class="header-tab-img" flex="cross:center" v-if="funcIcon">
  6. <el-image :src="funcIcon">
  7. <div slot="error" class="image-slot">
  8. <el-image src="resources/img/decorate/top_nav.png"></el-image>
  9. </div>
  10. </el-image>
  11. </div>
  12. <div class="header-tab-title">{{ activeItem.funcListItem.title }}</div>
  13. </div>
  14. <div class="header-tab-lists" :class="{activeName: current == 1}" flex="cross:center" v-if="activeItem && activeItem.is_show_permission" @click="toggleTab(1)">
  15. <div class="header-tab-img" flex="cross:center">
  16. <el-image :src="quanxianIcon"></el-image>
  17. </div>
  18. <div class="header-tab-title">权限</div>
  19. </div>
  20. </div>
  21. <div v-if="current == 0">
  22. <slot></slot>
  23. </div>
  24. <div v-else>
  25. <diy-style-contain :show-title="false">
  26. <div class="func-box" v-for="(item, index) in permission" :key="index">
  27. <div class="func-title">{{ item.title }}</div>
  28. <div class="func-checkbox-boxs" v-if="item.list && item.list.length">
  29. <el-checkbox class="func-checkbox-item" v-for="(it, i) in item.list" :key="i" v-model="it.checked" @change="funcChange($event, it, i)">
  30. {{ it.name }}
  31. </el-checkbox>
  32. </div>
  33. </div>
  34. </diy-style-contain>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. /**
  40. * 最右侧头部组件
  41. */
  42. Vue.component('diy-header', {
  43. template: '#diy-header',
  44. name: 'diy-header',
  45. props: {
  46. activeItem: {
  47. type: Object,
  48. default () {
  49. return {}
  50. }
  51. },
  52. allPermission: {
  53. type: Array,
  54. default () {
  55. return []
  56. }
  57. },
  58. },
  59. data() {
  60. return {
  61. current: 0,
  62. permission: [],
  63. selectedArr: [],
  64. result: '',
  65. tempPermi: [],
  66. }
  67. },
  68. created() {
  69. var isCheck = this.activeItem && this.activeItem.permission && this.activeItem.permission.length; //
  70. if (this.activeItem && this.activeItem.permission && this.activeItem.permission.length) {
  71. // 有初始值 - 不需要更新数据
  72. const newList = deepClone(this.allPermission)
  73. const oldList = deepClone(this.activeItem.permission)
  74. const result = newList.map((item, index) => {
  75. return Object.assign(item, {
  76. list: item.list.map((item1, index1) => {
  77. var checked = true
  78. const it = getObjValue(oldList, [index])
  79. const it1 = getObjValue(oldList, [index, 'list', index1])
  80. // 匹配对比
  81. if (it1 && (it.name === item.name) && (it1.level === item1.level)) {
  82. checked = it1.checked
  83. }
  84. return Object.assign(item1, {
  85. checked
  86. })
  87. })
  88. })
  89. })
  90. this.permission = this.setChecked(result);
  91. } else {
  92. // 初始化 - 更新一下数据
  93. this.tempPermi = this.setChecked(this.allPermission)
  94. this.permission = deepClone(this.tempPermi)
  95. if (this.activeItem) {
  96. // 判断是否选中 - 只会走一次
  97. this.$emit("permis-change", this.permission)
  98. }
  99. }
  100. },
  101. computed: {
  102. quanxianIcon() {
  103. return this.current == 0 ? 'resources/img/decorate/quanxian_icon_noact.png' : 'resources/img/decorate/quanxian_icon_act.png'
  104. },
  105. funcIcon() {
  106. const str = "resources/img/decorate/func/template.png"
  107. return str.replace("template", this.activeItem.funcListItem.type)
  108. }
  109. },
  110. methods: {
  111. setChecked(list) {
  112. return list.map(item => {
  113. return Object.assign(item, {
  114. list: item.list.map(item1 => {
  115. return Object.assign({
  116. checked: true
  117. }, item1)
  118. })
  119. })
  120. })
  121. },
  122. toggleTab(i) {
  123. this.current = i
  124. },
  125. funcChange(e, it, i) {
  126. it.checked = e
  127. this.$emit("permis-change", this.permission)
  128. }
  129. }
  130. })
  131. </script>
  132. <style>
  133. .headers-box {
  134. width: 100%;
  135. height: 53px;
  136. padding: 0 20px;
  137. }
  138. .header-tab-lists {
  139. width: 50%;
  140. cursor: pointer;
  141. }
  142. .header-tab-title {
  143. font-size: 14px;
  144. font-weight: 700;
  145. color: #999;
  146. /* padding-left: 16px; */
  147. }
  148. .activeName .header-tab-title {
  149. color: var(--diy-color);
  150. }
  151. .header-tab-img {
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. width: 50px;
  156. height: 53px;
  157. }
  158. .header-tab-img .el-image {
  159. width: 30px;
  160. }
  161. .func-box {
  162. padding-bottom: 20px;
  163. }
  164. .func-title {
  165. font-size: 14px;
  166. color: #999999;
  167. font-weight: 700;
  168. padding-bottom: 15px;
  169. }
  170. .func-checkbox-item {
  171. padding-bottom: 13px;
  172. }
  173. </style>