setting.vue 7.1 KB

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