index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="data-setting-data-box">
  3. <div class="lc-field-head">
  4. <div class="lc-field-title">
  5. 组件绑定
  6. </div>
  7. </div>
  8. <div class="lc-field-body">
  9. <div class="select-item select-item-title">
  10. <span class="input-wrap">绑定组件</span>
  11. <span class="input-wrap">操作</span>
  12. </div>
  13. <div
  14. v-for="(field, index) in config.customize.bindComponents"
  15. :key="index"
  16. class="select-item"
  17. :class="{ 'select-item-active': field.name === activeCode }"
  18. @mouseenter="chooseComponent(field)"
  19. >
  20. <div class="input-wrap">
  21. <el-form-item label-width="0px">
  22. <el-select
  23. v-model="field.name"
  24. popper-class="bs-el-select"
  25. class="bs-el-select"
  26. size="mini"
  27. clearable
  28. @change="changeComponent(...arguments, index)"
  29. >
  30. <el-option
  31. v-for="item in allComponentsExpectSelf(config.code)"
  32. :key="item.name"
  33. :label="item.comment"
  34. :value="item.name"
  35. :disabled="currentLinkComponentKey.includes(item.name)"
  36. />
  37. </el-select>
  38. </el-form-item>
  39. </div>
  40. <div class="input-wrap">
  41. <div
  42. class="select-line-icon option-delete"
  43. @click="deleteLinkComponents(index)"
  44. >
  45. <i class="el-icon-remove-outline" />
  46. </div>
  47. </div>
  48. </div>
  49. <el-button
  50. v-block
  51. type="primary"
  52. @click="addBindComponents"
  53. >
  54. 新增绑定组件
  55. </el-button>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import _ from 'lodash'
  61. import { mapState } from 'vuex'
  62. export default {
  63. name: 'ComponentBinding',
  64. directives: {
  65. block: {
  66. bind (el, binding) {
  67. el.style.width = binding.value || '100%'
  68. }
  69. }
  70. },
  71. props: {
  72. config: {
  73. type: Object,
  74. default: () => {}
  75. },
  76. // 当前组件的联动字段
  77. sourceFieldList: {
  78. type: Array,
  79. default: () => []
  80. }
  81. },
  82. data () {
  83. return {
  84. // 关联设置弹窗
  85. settingVisible: false,
  86. configMap: {},
  87. targetFieldList: [],
  88. activeCode: null
  89. }
  90. },
  91. computed: {
  92. ...mapState({
  93. chartList: state => state.bigScreen.pageInfo.chartList
  94. }),
  95. // 当前已经关联的组件key
  96. currentLinkComponentKey () {
  97. return this.config.dataSource.dimensionFieldList?.map(item => item) || []
  98. }
  99. },
  100. mounted () { },
  101. beforeDestroy () {
  102. },
  103. methods: {
  104. /**
  105. * @description: 获取除自己之外的所有组件
  106. */
  107. allComponentsExpectSelf (code) {
  108. let layouts = _.cloneDeep(this.chartList)
  109. const tabComponents = []
  110. layouts?.map((ly) => {
  111. if (ly.type === 'Tabs') {
  112. ly?.tabList?.map(com => {
  113. tabComponents.push(com.chart)
  114. })
  115. }
  116. })
  117. layouts = layouts?.filter(item => item.code !== code && !['Tabs', 'titles', 'currentTime', 'timeCountDown', 'iframeChart', 'linkChart', 'carousel'].includes(item.type))
  118. layouts = [...layouts, ...tabComponents]?.map(item => ({
  119. name: item.code,
  120. comment: item.title
  121. }))
  122. return layouts
  123. },
  124. /**
  125. * @description: 添加关联组件
  126. */
  127. addBindComponents () {
  128. this.config.customize.bindComponents.push({
  129. name: '',
  130. comment: ''
  131. })
  132. },
  133. /**
  134. * @description: 删除关联组件
  135. */
  136. deleteLinkComponents (index) {
  137. this.config.customize.bindComponents.splice(index, 1)
  138. },
  139. /**
  140. * @description: 改变关联组件
  141. */
  142. changeComponent (data, index) {
  143. this.$set(
  144. this.config.dataSource.dimensionFieldList,
  145. index,
  146. data
  147. )
  148. this.$set(
  149. this.config.customize.bindComponents,
  150. index,
  151. {
  152. name: this.config.customize.bindComponents[index].name,
  153. comment: this.allComponentsExpectSelf(this.config.code).find(item => item.name === data).comment
  154. }
  155. )
  156. },
  157. chooseComponent (field) {
  158. this.activeCode = field?.componentKey
  159. }
  160. }
  161. }
  162. </script>
  163. <style scoped lang="scss">
  164. ::v-deep .el-tabs__nav-scroll {
  165. display: flex;
  166. justify-content: center;
  167. }
  168. ::v-deep .el-tabs__nav-wrap::after {
  169. height: 0;
  170. }
  171. ::v-deep .el-collapse-item__header {
  172. background: #f2f3f5;
  173. height: 32px;
  174. padding: 0 12px;
  175. }
  176. ::v-deep .el-collapse-item__content {
  177. padding-bottom: 0;
  178. }
  179. .lc-field-body {
  180. padding: 12px;
  181. }
  182. ::v-deep .el-tabs__nav-scroll {
  183. display: flex;
  184. justify-content: center;
  185. }
  186. ::v-deep .el-tabs__nav-wrap::after {
  187. height: 0;
  188. }
  189. .design-tab-warp {
  190. padding: 10px;
  191. }
  192. ::v-deep.el-tabs--top {
  193. height: 100%;
  194. }
  195. ::v-deep .el-tabs__content {
  196. height: calc(100% - 40px);
  197. overflow-y: auto;
  198. }
  199. .setting-body {
  200. height: 100%;
  201. }
  202. // 筛选条件的按钮样式
  203. .add-filter-box {
  204. position: relative;
  205. .add-filter {
  206. margin-left: 90px;
  207. margin-bottom: 10px;
  208. }
  209. .add-filter-btn {
  210. position: absolute;
  211. top: 0;
  212. }
  213. }
  214. .select-item {
  215. display: flex;
  216. margin-bottom: 8px;
  217. cursor: pointer;
  218. align-items: center;
  219. border: 1px solid #fff;
  220. padding: 4px;
  221. .input-wrap {
  222. flex: 1;
  223. display: flex;
  224. justify-content: center;
  225. margin-right: 2px;
  226. ::v-deep.el-form-item {
  227. margin-bottom: 0 !important;
  228. }
  229. .el-input-number--mini {
  230. width: 90px !important;
  231. }
  232. }
  233. .input-wrap_left {
  234. flex: 1;
  235. display: flex;
  236. align-items: center;
  237. justify-content: left;
  238. }
  239. .select-line-icon {
  240. width: 30px;
  241. font-size: 18px;
  242. cursor: pointer;
  243. text-align: center;
  244. }
  245. .option-delete {
  246. color: #f56c6c;
  247. }
  248. }
  249. .select-item-active {
  250. border: 1px solid var(--bs-el-color-primary);
  251. background: var(--bs-el-background-3);
  252. }
  253. // 修改设置面板样式
  254. .data-setting-box{
  255. .data-setting-data-box{
  256. .lc-field-head{
  257. height: 30px;
  258. .lc-field-title{
  259. position: relative;
  260. padding-left: 12px;
  261. line-height: 30px;
  262. height: 30px;
  263. &:after{
  264. position: absolute;
  265. left: 0;
  266. top: 50%;
  267. transform: translateY(-50%);
  268. content: '';
  269. width: 4px;
  270. height: 14px;
  271. background-color: var(--bs-el-color-primary);
  272. }
  273. }
  274. }
  275. }
  276. }
  277. </style>