widgetTable.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <div :style="styleObj">
  3. <superslide v-if="hackReset" :options="options" class="txtScroll-top">
  4. <!--表头-->
  5. <div class="title">
  6. <div v-for="(item, index) in header" :key="index"
  7. :style="[headerTableStyle, tableFiledWidth(index), tableRowHeight()]">
  8. {{ item.name }}
  9. </div>
  10. </div>
  11. <!--数据-->
  12. <div class="bd">
  13. <ul class="infoList">
  14. <li v-for="(item, index) in list" :key="index" :style="tableRowHeight()">
  15. <div v-for="(itemChild, idx) in header"
  16. :key="idx"
  17. :style="[
  18. bodyTableStyle,
  19. bodyTable(index),
  20. tableFiledWidth(idx),
  21. tableRowHeight()
  22. ]"
  23. >
  24. {{ item[itemChild.key] }}
  25. </div>
  26. </li>
  27. </ul>
  28. </div>
  29. </superslide>
  30. </div>
  31. </template>
  32. <script>
  33. import vue from "vue";
  34. import VueSuperSlide from "vue-superslide";
  35. import { targetWidgetLinkageLogic } from "@/views/bigscreenDesigner/designer/linkageLogic";
  36. vue.use(VueSuperSlide);
  37. export default {
  38. name: 'widgetTable',
  39. components: {},
  40. props: {
  41. value: Object,
  42. ispreview: Boolean,
  43. },
  44. data() {
  45. return {
  46. hackReset: true,
  47. options: {
  48. titCell: ".hd ul",
  49. mainCell: ".bd ul",
  50. effect: "topLoop",
  51. autoPage: true,
  52. autoPlay: true,
  53. vis: 5,
  54. rowHeight: "50px"
  55. },
  56. header: [],
  57. list: [],
  58. optionsSetUp: {},
  59. optionsPosition: {},
  60. optionsData: {},
  61. flagInter: null,
  62. };
  63. },
  64. computed: {
  65. styleObj() {
  66. const allStyle = this.optionsPosition;
  67. return {
  68. position: this.ispreview ? "absolute" : "static",
  69. width: allStyle.width + "px",
  70. height: allStyle.height + "px",
  71. left: allStyle.left + "px",
  72. top: allStyle.top + "px",
  73. background: this.optionsSetUp.tableBgColor
  74. };
  75. },
  76. allComponentLinkage() {
  77. return this.$store.state.designer.allComponentLinkage;
  78. },
  79. headerTableStyle() {
  80. const headStyle = this.optionsSetUp;
  81. return {
  82. "text-align": headStyle.textAlignHeader,
  83. "font-size": headStyle.fontSizeHeader + "px",
  84. "border-style": headStyle.isLine ? "solid" : "none",
  85. "border-width": headStyle.borderWidth + "px",
  86. "border-color": headStyle.borderColor,
  87. display: headStyle.isHeader ? "block" : "none",
  88. color: headStyle.headColor,
  89. "background-color": headStyle.headBackColor
  90. };
  91. },
  92. bodyTableStyle() {
  93. const bodyStyle = this.optionsSetUp;
  94. return {
  95. "text-align": bodyStyle.textAlignBody,
  96. "font-size": bodyStyle.fontSizeBody + "px",
  97. "border-style": bodyStyle.isLine ? "solid" : "none",
  98. "border-width": bodyStyle.borderWidth + "px",
  99. "border-color": bodyStyle.borderColor,
  100. "color": bodyStyle.bodyColor,
  101. "background-color": bodyStyle.tableBgColor
  102. };
  103. }
  104. },
  105. watch: {
  106. value: {
  107. handler(val) {
  108. this.optionsSetUp = val.setup;
  109. this.optionsPosition = val.position;
  110. this.optionsData = val.data;
  111. this.initData();
  112. },
  113. deep: true
  114. }
  115. },
  116. mounted() {
  117. this.optionsSetUp = this.value.setup;
  118. this.optionsPosition = this.value.position;
  119. this.optionsData = this.value.data;
  120. this.initData();
  121. targetWidgetLinkageLogic(this); // 联动-目标组件逻辑
  122. },
  123. methods: {
  124. initData() {
  125. this.handlerRollFn();
  126. this.handlerHead();
  127. this.setOptionsData();
  128. this.visConfig();
  129. },
  130. visConfig() {
  131. this.options.vis = this.optionsSetUp.vis;
  132. },
  133. handlerRollFn() {
  134. const options = this.options;
  135. const rollSet = this.optionsSetUp;
  136. options.autoPlay = rollSet.isRoll;
  137. options.effect = rollSet.effect;
  138. options.interTime = rollSet.interTime;
  139. options.delayTime = rollSet.delayTime;
  140. options.scroll = rollSet.scroll;
  141. this.options = options;
  142. this.hackResetFun();
  143. },
  144. handlerHead() {
  145. const head = this.optionsSetUp.dynamicAddTable;
  146. this.header = head;
  147. },
  148. setOptionsData(e, paramsConfig) {
  149. const tableData = this.optionsData;
  150. tableData.dynamicData = tableData.dynamicData || {}; // 兼容 dynamicData undefined
  151. const myDynamicData = tableData.dynamicData;
  152. clearInterval(this.flagInter); // 不管咋,先干掉上一次的定时任务,避免多跑
  153. if (
  154. e &&
  155. tableData.dataType !== "staticData" &&
  156. Object.keys(myDynamicData.contextData).length
  157. ) {
  158. const keyArr = Object.keys(myDynamicData.contextData);
  159. paramsConfig.forEach((conf) => {
  160. if (keyArr.includes(conf.targetKey)) {
  161. myDynamicData.contextData[conf.targetKey] = e[conf.originKey];
  162. }
  163. });
  164. }
  165. tableData.dataType == "staticData"
  166. ? this.handlerStaticData(tableData.staticData)
  167. : this.handlerDynamicData(tableData.dynamicData, tableData.refreshTime);
  168. },
  169. handlerStaticData(data) {
  170. this.list = data;
  171. },
  172. handlerDynamicData(data, refreshTime) {
  173. if (!data) return;
  174. if (this.ispreview) {
  175. this.getEchartData(data);
  176. this.flagInter = setInterval(() => {
  177. this.getEchartData(data);
  178. }, refreshTime);
  179. } else {
  180. this.getEchartData(data);
  181. }
  182. },
  183. getEchartData(val) {
  184. const data = this.queryEchartsData(val);
  185. data.then(res => {
  186. this.list = res;
  187. this.hackResetFun();
  188. });
  189. },
  190. // vue hack 之强制刷新组件
  191. hackResetFun() {
  192. this.hackReset = false;
  193. this.$nextTick(() => {
  194. this.hackReset = true;
  195. });
  196. },
  197. // 计算 奇偶背景色
  198. bodyTable(index) {
  199. let styleJson = {};
  200. if (index % 2) {
  201. styleJson["background-color"] = this.optionsSetUp.eventColor;
  202. } else {
  203. styleJson["background-color"] = this.optionsSetUp.oldColor;
  204. }
  205. return styleJson;
  206. },
  207. tableRowHeight() {
  208. let styleJson = {};
  209. styleJson["overflow"] = "hidden";
  210. styleJson["white-space"] = "nowrap";
  211. styleJson["text-overflow"] = "ellipsis";
  212. if (this.optionsSetUp.rowHeight) {
  213. styleJson["height"] = this.optionsSetUp.rowHeight + "px";
  214. //styleJson["line-height"] = this.optionsSetUp.rowHeight + "px";
  215. } else {
  216. styleJson["height"] = this.options.rowHeight;
  217. //styleJson["line-height"] = this.optionsSetUp.rowHeight + "px";
  218. }
  219. return styleJson;
  220. },
  221. tableFiledWidth(index) {
  222. let styleJson = {};
  223. if (this.optionsSetUp.dynamicAddTable[index].width) {
  224. styleJson["width"] = this.optionsSetUp.dynamicAddTable[index].width;
  225. }
  226. return styleJson;
  227. }
  228. }
  229. };
  230. </script>
  231. <style lang="scss" scoped>
  232. /* 本例子css */
  233. .txtScroll-top {
  234. overflow: hidden;
  235. position: relative;
  236. }
  237. .title {
  238. display: flex;
  239. flex-direction: row;
  240. width: 100%;
  241. }
  242. .title > div {
  243. height: 50px;
  244. line-height: 50px;
  245. width: 100%;
  246. }
  247. .txtScroll-top .bd {
  248. width: 100%;
  249. }
  250. .txtScroll-top .infoList li {
  251. height: 50px;
  252. //line-height: 50px;
  253. display: flex;
  254. flex-direction: row;
  255. }
  256. .txtScroll-top .infoList li > div {
  257. width: 100%;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. flex-wrap: wrap;
  262. }
  263. /*.txtScroll-top .infoList li:nth-child(n) {
  264. background: rgb(0, 59, 81);
  265. }
  266. .txtScroll-top .infoList li:nth-child(2n) {
  267. background: rgb(10, 39, 50);
  268. }*/
  269. </style>