index.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div class="cqcy-content" v-if="chooseGroupId">
  3. <div style="margin-bottom: 10px;">
  4. <span style="color: #474646; font-size: 14px;">数据组:</span>
  5. <el-select v-model="chooseGroupId" disabled size="mini">
  6. <el-option
  7. v-for="dict in groupDataList"
  8. :key="dict.id"
  9. :label="dict.groupName"
  10. :value="dict.id"
  11. ></el-option>
  12. </el-select>
  13. <span style="margin-left: 20px; color: #474646; font-size: 14px;">数据项名称:</span>
  14. <el-input placeholder="请输入数据项名称"
  15. size="mini"
  16. style="width: 200px;"
  17. @input="itemChangeEvent"
  18. v-model="filterItemText"
  19. prefix-icon="el-icon-search">
  20. </el-input>
  21. <el-checkbox v-model="groupRunStatus" size="mini" style="margin-left: 20px;"
  22. @change="groupRunCheckboxEvent" title="固定每5秒刷新一次数据">实时数据</el-checkbox>
  23. </div>
  24. <el-table
  25. :data="itemDataList" border :stripe="true"
  26. :header-cell-style="{background: '#E8E8E8'}"
  27. style="width: 100%">
  28. <el-table-column label="序号" align="center" width="80">
  29. <template slot-scope="scope">
  30. {{ scope.$index + 1 }}
  31. </template>
  32. </el-table-column>
  33. <el-table-column prop="itemName" label="数据项名称" align="center">
  34. </el-table-column>
  35. <template v-if="groupRunStatus">
  36. <el-table-column prop="dataType" label="数据项类型" align="center" width="100">
  37. </el-table-column>
  38. <el-table-column prop="operationRule" label="表达式" align="center" width="200">
  39. <template slot-scope="scope">
  40. {{ scope.row.operationRule ? scope.row.operationRule : '默认值' }}
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="dataOrgValue" label="原始数据值" align="center" width="100">
  44. <template slot-scope="scope">
  45. {{ scope.row.dataOrgValue ? scope.row.dataOrgValue : '' }}
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="dataValue" label="计算值" align="center" width="100">
  49. <template slot-scope="scope">
  50. {{ (scope.row.dataValue && scope.row.dataValue != 'undefined') ? scope.row.dataValue : '' }}
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="dataSourceName" label="数据源名称" align="center" width="180">
  54. </el-table-column>
  55. <el-table-column prop="createTime" label="取值时间" align="center" width="180">
  56. </el-table-column>
  57. </template>
  58. <template v-else>
  59. <el-table-column prop="describe" label="描述" align="center" width="150">
  60. <template slot-scope="scope" v-if="scope.row.describe">
  61. <!-- <el-tag type="primary" disable-transitions>{{ scope.row.describe }}</el-tag>-->
  62. <span>{{ scope.row.describe }}</span>
  63. </template>
  64. </el-table-column>
  65. <el-table-column prop="dataSourceName" label="数据源名称" align="center" width="180">
  66. </el-table-column>
  67. <el-table-column prop="operationRule" label="表达式" align="center" width="200">
  68. <template slot-scope="scope">
  69. {{ scope.row.operationRule ? scope.row.operationRule : '默认值' }}
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="操作" align="center" width="100">
  73. <template slot-scope="scope">
  74. <el-button type="text" size="small" @click="handleClickByEdit(scope.row)">编辑</el-button>
  75. </template>
  76. </el-table-column>
  77. </template>
  78. </el-table>
  79. </div>
  80. </template>
  81. <script>
  82. import {getItemGroupById, getItemValueById, updateItemDescribe} from "@/api/datasource";
  83. import {showLoading} from "@/utils/cqcy";
  84. import errorCode from "@/utils/errorCode";
  85. export default {
  86. name: "index",
  87. components: {
  88. },
  89. data() {
  90. return {
  91. itemDataList: [],
  92. itemDataListF: [],
  93. groupDataList: [],
  94. chooseGroup: null,
  95. chooseGroupId: null,
  96. groupRunStatus: false,
  97. timeInterval: null,
  98. filterItemText: '',
  99. }
  100. },
  101. watch: {
  102. '$route'(to, from) {
  103. this.readParams()
  104. },
  105. '$route.query.t': {
  106. handler(o, n) {
  107. }
  108. },
  109. deep: true
  110. },
  111. created() {
  112. this.readParams()
  113. },
  114. beforeDestroy() {
  115. if (this.timeInterval) {
  116. clearInterval(this.timeInterval)
  117. this.timeInterval = null
  118. }
  119. },
  120. methods: {
  121. itemChangeEvent(value) {
  122. let arr = JSON.parse(JSON.stringify(this.itemDataListF))
  123. if (!value || !value.trim()) {
  124. this.itemDataList = arr
  125. return
  126. }
  127. let filterList = arr.filter(v => {
  128. return v.itemName.indexOf(value) !== -1
  129. })
  130. this.itemDataList = filterList
  131. },
  132. /** 读取参数 */
  133. readParams() {
  134. this.filterItemText = ''
  135. // let groupListStorage = sessionStorage.getItem('GROUP_LIST') ? sessionStorage.getItem('GROUP_LIST') : '[]'
  136. // this.groupDataList = JSON.parse(groupListStorage)
  137. let groupId = sessionStorage.getItem('GROUP_ID') ? sessionStorage.getItem('GROUP_ID') : '-1'
  138. this.chooseGroupId = parseInt(groupId)
  139. this.groupRunStatus = false
  140. this.getGroupById(this.chooseGroupId)
  141. // this.getItemValueById()
  142. },
  143. /** 运行状态值 */
  144. groupRunCheckboxEvent(val) {
  145. this.groupRunStatus = val
  146. this.getItemValueById()
  147. },
  148. /** 获取数据项值信息 */
  149. getItemValueById() {
  150. if (!this.groupRunStatus || !this.chooseGroup) {
  151. if (this.timeInterval) {
  152. clearInterval(this.timeInterval)
  153. this.timeInterval = null
  154. }
  155. this.getGroupById(this.chooseGroupId)
  156. return
  157. }
  158. getItemValueById(this.chooseGroup.id).then(res => {
  159. this.filterItemText = ''
  160. this.itemDataList = res.data
  161. // 避免布尔类型时页面无法显示数据
  162. for (let i = 0; i < this.itemDataList.length; i ++) {
  163. this.itemDataList[i].dataValue += ''
  164. }
  165. this.itemDataListF = JSON.parse(JSON.stringify(this.itemDataList))
  166. }).catch((e) => {
  167. })
  168. let temp = setInterval(() => {
  169. getItemValueById(this.chooseGroup.id).then(res => {
  170. this.filterItemText = ''
  171. this.itemDataList = res.data
  172. // 避免布尔类型时页面无法显示数据
  173. for (let i = 0; i < this.itemDataList.length; i ++) {
  174. this.itemDataList[i].dataValue += ''
  175. }
  176. this.itemDataListF = JSON.parse(JSON.stringify(this.itemDataList))
  177. }).catch((e) => {
  178. })
  179. }, 5 * 1000)
  180. this.timeInterval = temp
  181. },
  182. /** 获取组详细信息 */
  183. getGroupById(id) {
  184. if (this.timeInterval) {
  185. clearInterval(this.timeInterval)
  186. this.timeInterval = null
  187. }
  188. if (!id || id <= 0) {
  189. this.chooseGroupId = null
  190. return
  191. }
  192. const loading = showLoading(this, '加载中,请稍候···')
  193. getItemGroupById(id).then(res => {
  194. loading.close()
  195. this.chooseGroup = res.data
  196. this.groupDataList = [{
  197. 'id': this.chooseGroup.id,
  198. 'groupName': this.chooseGroup.groupName
  199. }]
  200. this.itemDataList = this.chooseGroup.itemList
  201. this.itemDataListF = JSON.parse(JSON.stringify(this.itemDataList))
  202. }).catch((e) => {
  203. loading.close()
  204. this.$alert(e, errorCode[100], {
  205. confirmButtonText: '确定',
  206. callback: action => {
  207. }
  208. })
  209. })
  210. },
  211. /** 编辑 */
  212. handleClickByEdit(row) {
  213. if (!row || !row.id) {
  214. this.$message({
  215. message: '编辑失败!',
  216. type: 'warning'
  217. })
  218. return
  219. }
  220. this.$prompt('请输入该数据项描述信息', '编辑', {
  221. confirmButtonText: '确定',
  222. cancelButtonText: '取消',
  223. customClass: 'close_confirm',
  224. closeOnClickModal: false,
  225. inputValue: row.describe,
  226. inputValidator: (val) => {
  227. if (!val || !val.trim()) {
  228. return '描述信息不能为空'
  229. }
  230. if (val.length > 20) {
  231. return '描述信息必须在20字以内'
  232. }
  233. }
  234. }).then(({ value }) => {
  235. let data = {
  236. 'id': row.id,
  237. 'describe': value
  238. }
  239. updateItemDescribe(data).then(res => {
  240. let msg = res.data ? '编辑成功!' : '编辑失败!'
  241. let msgType = res.data ? 'success' : 'error'
  242. this.$message({
  243. message: msg,
  244. type: msgType
  245. })
  246. this.getGroupById(this.chooseGroupId)
  247. }).catch((e) => {
  248. })
  249. }).catch(() => {
  250. })
  251. }
  252. }
  253. }
  254. </script>
  255. <style rel="stylesheet/scss" lang="scss">
  256. .el-table--enable-row-hover .el-table__body tr:hover > td {
  257. background-color: transparent !important;
  258. }
  259. </style>