dynamicComponents.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <div>
  3. <el-form label-width="100px" label-position="left">
  4. <el-form-item label="数据集">
  5. <el-select
  6. size="mini"
  7. v-model="dataSetValue"
  8. filterable
  9. placeholder="请选择"
  10. @change="selectDataSet"
  11. >
  12. <el-option
  13. v-for="item in dataSet"
  14. :key="item.code"
  15. :label="item.setName"
  16. :value="item.id"
  17. />
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item
  21. v-for="(item, index) in userNameList"
  22. :key="index"
  23. :label="item.paramName"
  24. >
  25. <el-input v-model.trim="item.sampleItem" size="mini" />
  26. </el-form-item>
  27. <el-form-item v-for="item in setParamList" :key="item" :label="item">
  28. <Dictionary
  29. v-model="params[item]"
  30. :dict-key="getDictKey()"
  31. @input="selectParams($event, item)"
  32. />
  33. </el-form-item>
  34. <el-button
  35. style="width: 100%"
  36. type="primary"
  37. plain
  38. size="mini"
  39. @click="saveDataBtn"
  40. >刷新</el-button
  41. >
  42. </el-form>
  43. </div>
  44. </template>
  45. <script>
  46. import { queryAllDataSet, detailBysetId } from "@/api/bigscreen";
  47. import Dictionary from "@/components/Dictionary/index";
  48. export default {
  49. name: "DynamicComponents",
  50. components: {
  51. Dictionary
  52. },
  53. model: {
  54. prop: "formData",
  55. event: "input"
  56. },
  57. props: {
  58. chartType: String,
  59. dictKey: String,
  60. formData: Object | String
  61. },
  62. data() {
  63. return {
  64. dataSetValue: "",
  65. dataSet: [], // 数据集
  66. userNameList: [], // 用户
  67. setParamList: [], // 对应的不同的图形数据参数
  68. params: {},
  69. chartProperties: {}
  70. };
  71. },
  72. watch: {
  73. formData: {
  74. handler(val) {
  75. this.echoDataSet(val);
  76. },
  77. deep: true
  78. }
  79. },
  80. computed: {
  81. setCode() {
  82. let code = "";
  83. this.dataSet.forEach(el => {
  84. if (el.id == this.dataSetValue) {
  85. code = el.setCode;
  86. }
  87. });
  88. return code;
  89. }
  90. },
  91. mounted() {
  92. this.loadDataSet();
  93. this.echoDataSet(this.formData);
  94. },
  95. methods: {
  96. async loadDataSet() {
  97. const { code, data } = await queryAllDataSet();
  98. this.dataSet = data;
  99. if (code != "200") return;
  100. },
  101. async selectDataSet() {
  102. const { code, data } = await detailBysetId(this.dataSetValue);
  103. this.userNameList = data.dataSetParamDtoList;
  104. this.setParamList = data.setParamList;
  105. this.chartProperties = {};
  106. if (code != "200") return;
  107. },
  108. async saveDataBtn() {
  109. const contextData = {};
  110. for (let i = 0; i < this.userNameList.length; i++) {
  111. contextData[this.userNameList[i].paramName] = this.userNameList[
  112. i
  113. ].sampleItem;
  114. }
  115. const params = {
  116. chartType: this.chartType,
  117. setCode: this.setCode,
  118. chartProperties: this.chartProperties,
  119. contextData
  120. };
  121. this.$emit("input", params);
  122. this.$emit("change", params);
  123. },
  124. selectParams(val, key) {
  125. if (!val) {
  126. delete this.chartProperties[key]
  127. } else {
  128. this.chartProperties[key] = val;
  129. }
  130. },
  131. getDictKey() {
  132. return this.dictKey == null ? "CHART_PROPERTIES" : this.dictKey;
  133. },
  134. // 数据集回显
  135. async echoDataSet(val) {
  136. if (!val) return;
  137. const setCode = val.setCode;
  138. await this.loadDataSet();
  139. this.dataSetValue = this.dataSet.filter(
  140. el => setCode == el.setCode
  141. )[0].id;
  142. await this.selectDataSet();
  143. this.echoDynamicData(val);
  144. },
  145. echoDynamicData(val) {
  146. const chartProperties = this.deepClone(val.chartProperties);
  147. this.chartProperties = chartProperties;
  148. if (this.userNameList.length > 0) {
  149. for (let i = 0; i < this.userNameList.length; i++) {
  150. const item = this.userNameList[i];
  151. //处理默认值
  152. if(item.paramName in val.contextData){
  153. this.userNameList[i].sampleItem= val.contextData[item.paramName];
  154. }
  155. }
  156. }
  157. if (this.setParamList.length > 0) {
  158. for (let i = 0; i < this.setParamList.length; i++) {
  159. const item = this.setParamList[i];
  160. if (chartProperties.hasOwnProperty(item)) {
  161. this.params[item] = chartProperties[item];
  162. }
  163. }
  164. }
  165. }
  166. }
  167. };
  168. </script>
  169. <style lang="sass" scoped></style>