index.vue 6.4 KB

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