setting.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div>
  3. <el-form
  4. ref="form"
  5. :model="config"
  6. label-width="120px"
  7. label-position="left"
  8. class="setting-body bs-el-form"
  9. >
  10. <SettingTitle>基础</SettingTitle>
  11. <el-form-item
  12. class="lc-field-body"
  13. label="名称"
  14. >
  15. <el-input
  16. v-model="config.title"
  17. clearable
  18. />
  19. </el-form-item>
  20. <SettingTitle>位置</SettingTitle>
  21. <div class="lc-field-body">
  22. <PosWhSetting
  23. :config="config"
  24. label-width="120px"
  25. />
  26. </div>
  27. <SettingTitle>基础</SettingTitle>
  28. <div class="lc-field-body">
  29. <div class="select-item select-item-title">
  30. <span class="option-drag" />
  31. <span class="input-wrap_left">标签页名称</span>
  32. <span class="input-wrap_left">图表类型</span>
  33. </div>
  34. <draggable
  35. :list="config.customize.tabList"
  36. :animation="340"
  37. group="selectItem"
  38. handle=".option-drag"
  39. style="padding: 10px"
  40. >
  41. <template>
  42. <div
  43. v-for="(tab, index) in config.customize.tabList"
  44. :key="index"
  45. class="select-item"
  46. >
  47. <div class="select-line-icon option-drag">
  48. <i class="el-icon-rank" />
  49. </div>
  50. <div class="input-wrap">
  51. <el-form-item
  52. :prop="'customize.tabList.' + index + '.name'"
  53. :rules="rules.name"
  54. label-width="0px"
  55. >
  56. <el-input
  57. v-model="tab.name"
  58. placeholder="请输入标签页标题"
  59. size="mini"
  60. />
  61. </el-form-item>
  62. </div>
  63. <div class="input-wrap">
  64. <el-form-item
  65. :prop="'customize.tabList.' + index + '.chart'"
  66. :rules="rules.chart"
  67. label-width="0px"
  68. >
  69. <el-select
  70. v-model="tab.chart.title"
  71. size="mini"
  72. @change="handleChangeBindCompnents(...arguments, index)"
  73. >
  74. <el-option
  75. v-for="item in componentList"
  76. :key="item.title"
  77. :label="item.title"
  78. :value="item.title"
  79. />
  80. </el-select>
  81. </el-form-item>
  82. </div>
  83. <div
  84. class="select-line-icon option-add"
  85. @click="addTab(index)"
  86. >
  87. <i class="el-icon-circle-plus-outline" />
  88. </div>
  89. <div
  90. class="select-line-icon option-delete"
  91. @click="deleteTab(index)"
  92. >
  93. <i class="el-icon-remove-outline" />
  94. </div>
  95. </div>
  96. </template>
  97. </draggable>
  98. <el-button
  99. type="primary"
  100. @click="addTab"
  101. >
  102. 新增标签页
  103. </el-button>
  104. </div>
  105. </el-form>
  106. </div>
  107. </template>
  108. <script>
  109. import draggable from 'vuedraggable'
  110. import SettingTitle from 'data-room-ui/SettingTitle/index.vue'
  111. import { chartSettingMixins } from 'data-room-ui/js/mixins/chartSettingMixins'
  112. import PosWhSetting from 'data-room-ui/BigScreenDesign/RightSetting/PosWhSetting.vue'
  113. import CloneDeep from 'lodash-es/cloneDeep'
  114. import plotList from 'data-room-ui/G2Plots/plotList'
  115. import { randomString } from 'data-room-ui/js/utils'
  116. import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
  117. export default {
  118. components: {
  119. PosWhSetting,
  120. SettingTitle,
  121. draggable
  122. },
  123. mixins: [chartSettingMixins],
  124. data () {
  125. const validateChart = (rule, value, callback) => {
  126. if (!value) {
  127. return callback(new Error('请选择图表'))
  128. }
  129. callback()
  130. }
  131. return {
  132. rules: {
  133. name: [
  134. {
  135. required: true,
  136. message: '请输入标签页标题',
  137. trigger: 'blur'
  138. }
  139. ],
  140. chart: [
  141. { required: true, trigger: 'change', validator: validateChart }
  142. ]
  143. }
  144. }
  145. },
  146. computed: {
  147. config: {
  148. get () {
  149. return this.$store.state.bigScreen.activeItemConfig
  150. },
  151. set (val) {
  152. this.$store.state.bigScreen.activeItemConfig = val
  153. }
  154. },
  155. pageCode () {
  156. return this.$route.query.code
  157. },
  158. componentList () {
  159. return [...plotList]
  160. }
  161. },
  162. watch: {},
  163. mounted () { },
  164. methods: {
  165. deleteTab (index) {
  166. this.config.customize.tabList.splice(index, 1)
  167. },
  168. addTab () {
  169. const newTab = {
  170. code: '',
  171. chartCode: new Date().getTime() + '',
  172. name: '',
  173. chart: { parentCode: this.config.code }
  174. }
  175. this.config.customize.tabList.push(newTab)
  176. },
  177. handleChangeBindCompnents (configName, index) {
  178. const config = this.componentList.find(
  179. item => item.title === configName
  180. )
  181. config.code = randomString(12)
  182. this.$set(this.config.customize.tabList[index], 'name', configName)
  183. this.$set(this.config.customize.tabList[index], 'chart', { ...config, parentCode: this.config.code })
  184. this.$set(this.config.customize.tabList[index], 'chartCode', config.code)
  185. this.$set(this.config.customize.tabList[index].chart, 'key', settingToTheme(config, config.code))
  186. this.$set(this.config.customize.tabList[index].chart, 'theme', settingToTheme(config, 'dark'))
  187. this.$set(this.config.customize.tabList[index].chart, 'theme', settingToTheme(config, 'light'))
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. @import "../../assets/style/settingWrap.scss";
  194. .lc-field-body {
  195. padding: 12px 16px;
  196. }
  197. .select-item {
  198. display: flex;
  199. margin-bottom: 8px;
  200. .option-drag {
  201. cursor: move !important;
  202. width: 30px;
  203. font-size: 24px;
  204. }
  205. .input-wrap {
  206. flex: 1;
  207. display: flex;
  208. align-items: center;
  209. justify-content: center;
  210. margin-right: 2px;
  211. .el-input-number--mini {
  212. width: 90px !important;
  213. }
  214. }
  215. .input-wrap_left {
  216. flex: 1;
  217. display: flex;
  218. align-items: center;
  219. justify-content: left;
  220. }
  221. .select-line-icon {
  222. width: 30px;
  223. font-size: 18px;
  224. cursor: pointer;
  225. text-align: center;
  226. }
  227. .option-delete {
  228. color: #f56c6c;
  229. }
  230. }
  231. </style>