index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <div v-if="hideMainViewFlag" class="cqcy-content">
  3. <el-button v-if="roleCodeList.indexOf(__self.clientRole) > -1"
  4. type="primary" icon="el-icon-circle-plus-outline"
  5. size="mini" @click="addIndexChartBtnEvent">添加图表
  6. </el-button>
  7. <el-divider></el-divider>
  8. <div>
  9. <el-table
  10. :data="chartDataList" border :stripe="true"
  11. :header-cell-style="{background: '#E8E8E8'}"
  12. style="width: 100%; height: calc(100% - 100px); overflow: auto;">
  13. <el-table-column
  14. align="center"
  15. label="图表名称"
  16. prop="chartName">
  17. <template slot-scope="scope">
  18. <span style="color: #409EFF; cursor: pointer;"
  19. @click="handleChartNodeClick(scope.row)"
  20. :title="scope.row.reportTableName">{{ scope.row.chartName }}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column
  24. align="center"
  25. label="统计图类型"
  26. prop="chartType"
  27. width="200">
  28. <template slot-scope="scope">
  29. <span>{{ scope.row.chartType == 'bar' ? '柱状图'
  30. : (scope.row.chartType == 'line' ? '折线图' : '饼状图') }}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column label="操作" align="center" width="300">
  34. <template slot-scope="scope">
  35. <el-button type="text"
  36. size="small"
  37. icon="el-icon-edit"
  38. @click="updateChartItem(scope.row)">修改
  39. </el-button>
  40. <el-button type="text"
  41. size="small"
  42. icon="el-icon-delete"
  43. style="color: red;"
  44. @click="removeChartItem(scope.row)">删除
  45. </el-button>
  46. </template>
  47. </el-table-column>
  48. </el-table>
  49. <el-pagination
  50. style="margin-top: 20px;"
  51. background
  52. layout="sizes, prev, pager, next, total"
  53. :current-page="chartPage"
  54. :page-size="chartLimit"
  55. @size-change="sizeChartChangeEvent"
  56. @current-change="currentChartChangeEvent"
  57. :total="chartTotal">
  58. </el-pagination>
  59. </div>
  60. <!-- 新增首页图表 -->
  61. <el-dialog
  62. :title="addIndexChart ? '添加图表' : '修改图表'"
  63. width="600px"
  64. top="5vh"
  65. center
  66. v-dialog-drag
  67. v-if="dialogIndexChartVisible"
  68. :before-close="dialogClose"
  69. :visible.sync="dialogIndexChartVisible"
  70. :close-on-click-modal="false"
  71. :append-to-body="true">
  72. <el-form ref="chartForm" :model="chartForm" :rules="chartFormRules" label-width="110px">
  73. <el-form-item label='统计图名称:' prop="chartName">
  74. <el-input placeholder="请输入统计图名称" v-model="chartForm.chartName" maxlength="20" show-word-limit></el-input>
  75. </el-form-item>
  76. <el-form-item label="取值类型:" prop="valueType">
  77. <el-radio v-for="item in valueTypeList"
  78. v-model="chartForm.valueType"
  79. :label="item.value">{{ item.label }}</el-radio>
  80. </el-form-item>
  81. <el-form-item label="统计图类型:" prop="chartType">
  82. <el-radio v-for="item in chartTypeList"
  83. v-model="chartForm.chartType"
  84. :label="item.value">{{ item.label }}</el-radio>
  85. </el-form-item>
  86. <el-form-item label="取值模式:" prop="valueTakingMode">
  87. <el-radio v-for="item in valueTakingModeList"
  88. v-model="chartForm.valueTakingMode"
  89. :label="item.value">{{ item.label }}</el-radio>
  90. </el-form-item>
  91. <!-- <el-form-item label="取值时间:" prop="dateRange">-->
  92. <!-- <el-date-picker-->
  93. <!-- v-model="chartForm.dateRange"-->
  94. <!-- type="datetimerange"-->
  95. <!-- :clearable="false"-->
  96. <!-- range-separator="至"-->
  97. <!-- start-placeholder="开始时间"-->
  98. <!-- end-placeholder="结束时间"-->
  99. <!-- placeholder="选择取值时间范围"-->
  100. <!-- :picker-options="{-->
  101. <!-- format: 'yyyy-MM-dd HH:mm:ss'-->
  102. <!-- }"-->
  103. <!-- value-format="yyyy-MM-dd HH:mm:ss"-->
  104. <!-- :default-time="['09:00:00', '18:00:00']">-->
  105. <!-- </el-date-picker>-->
  106. <!-- </el-form-item>-->
  107. <el-divider content-position="left">取值周期设置</el-divider>
  108. <div class="cy-line">
  109. <el-form-item label="时间单位:" prop="bucketType">
  110. <el-radio v-for="item in bucketTypeList"
  111. v-model="chartForm.bucketType"
  112. :label="item.value">{{ item.label }}</el-radio>
  113. </el-form-item>
  114. <el-form-item label="数据切换周期:" prop="bucketValue">
  115. <el-input-number label="请输入周期值"
  116. v-model="chartForm.bucketValue"
  117. :precision="0"
  118. :min="1"
  119. :max="100"></el-input-number>
  120. </el-form-item>
  121. </div>
  122. <el-form-item label="数据项:" prop="chartItemList">
  123. <el-button size="mini" @click="chooseDataItemEvent">选择数据项</el-button>
  124. <el-tag size="mini" v-if="chartForm.chartItemList.length" style="margin-left: 10px;">
  125. 已选择({{ chartForm.chartItemList.length }})项
  126. </el-tag>
  127. </el-form-item>
  128. <el-form-item label="用户组:" prop="userGroupList">
  129. <el-button size="mini" @click="chooseUserGroupEvent">选择用户组</el-button>
  130. <el-tag size="mini" v-if="chartForm.userGroupList.length" style="margin-left: 10px;">
  131. 已选择({{ chartForm.userGroupList.length }})组
  132. </el-tag>
  133. </el-form-item>
  134. </el-form>
  135. <span slot='footer'>
  136. <el-button v-if="addIndexChart" type="primary" @click="addIndexChartEvent">添加</el-button>
  137. <el-button v-else type="primary" @click="updateIndexChartEvent">修改</el-button>
  138. <el-button @click="dialogClose">取消</el-button>
  139. </span>
  140. </el-dialog>
  141. <!-- 选择数据项 -->
  142. <data-item ref="dataItem" @update-message="updateDataItemEmit"></data-item>
  143. <!-- 选择用户组 -->
  144. <user-group ref="userGroup" @update-message="updateUserGroupEmit"></user-group>
  145. </div>
  146. <div v-else></div>
  147. </template>
  148. <script>
  149. import DataItem from '@/components/CustomDialog/DataItem'
  150. import UserGroup from '@/components/CustomDialog/UserGroup'
  151. import { showAlertMsgWin, showAlertWin, showConfirmWin, showLoading} from "@/utils/cqcy";
  152. import {delIndexChartById, getIndexChartById, getIndexChartList, saveIndexChart, updateIndexChart} from "@/api/chart";
  153. import {mapGetters} from "vuex";
  154. export default {
  155. name: "index",
  156. components: {
  157. DataItem, UserGroup
  158. },
  159. data() {
  160. return {
  161. roleCodeList: [],
  162. dialogIndexChartVisible: false,
  163. addIndexChart: true,
  164. hideMainViewFlag: true,
  165. chartDataList: [],
  166. chartTotal: 0,
  167. chartPage: 1,
  168. chartLimit: 10,
  169. chartTypeList: [
  170. { 'label': '柱状图', 'value': 'bar' },
  171. { 'label': '折线图', 'value': 'line' },
  172. { 'label': '饼状图', 'value': 'pie' }
  173. ],
  174. valueTypeList: [
  175. { 'label': '原始值', 'value': 0 },
  176. { 'label': '计算值', 'value': 1 }
  177. ],
  178. bucketTypeList: [
  179. { 'label': '天', 'value': 0 },
  180. { 'label': '时', 'value': 1 },
  181. { 'label': '分', 'value': 2 },
  182. { 'label': '秒', 'value': 3 }
  183. ],
  184. valueTakingModeList: [
  185. { 'label': '平均值', 'value': 0 },
  186. { 'label': '最大值', 'value': 1 },
  187. { 'label': '最小值', 'value': 2 },
  188. { 'label': '瞬时值', 'value': 3 }
  189. ],
  190. chartForm: {
  191. chartName: '',
  192. valueType: 0,
  193. chartType: 'bar',
  194. valueTakingMode: 0,
  195. bucketType: 1,
  196. bucketValue: 1,
  197. dateRange: [],
  198. startTime: null,
  199. endTime: null,
  200. chartItemList: [],
  201. userGroupList: []
  202. },
  203. chartFormRules: {
  204. chartName: [
  205. { required: true, message: '名称不能为空', trigger: 'blur' }
  206. ],chartItemList: [
  207. { required: true, message: '数据项不能为空', trigger: 'blur' }
  208. ],userGroupList: [
  209. { required: true, message: '用户组不能为空', trigger: 'blur' }
  210. ]
  211. }
  212. }
  213. },
  214. inject: ['__self'],
  215. computed: {
  216. ...mapGetters([
  217. 'roles'
  218. ])
  219. },
  220. mounted() {
  221. this.roleCodeList = []
  222. this.roles.forEach((role) => {
  223. this.roleCodeList.push(role.roleCode)
  224. })
  225. },
  226. created() {
  227. this.getIndexAllChart()
  228. },
  229. methods: {
  230. hideMainView(flag) {
  231. this.hideMainViewFlag = flag
  232. },
  233. sizeChartChangeEvent(val) {
  234. this.chartPage = 1
  235. this.chartLimit = val
  236. this.getIndexAllChart()
  237. },
  238. currentChartChangeEvent(val) {
  239. this.chartPage = val
  240. this.getIndexAllChart()
  241. },
  242. /** 图表点击事件 */
  243. handleChartNodeClick(row) {
  244. },
  245. /** 图表修改事件 */
  246. updateChartItem(row) {
  247. getIndexChartById(row.id).then(res => {
  248. if (!res.data) {
  249. showAlertMsgWin(this, null, '修改失败!')
  250. return
  251. }
  252. this.chartForm = res.data
  253. this.addIndexChart = false
  254. this.dialogIndexChartVisible = true
  255. }).catch((e) => {
  256. showAlertWin(this, null, e)
  257. })
  258. },
  259. /** 图表删除事件 */
  260. removeChartItem(row) {
  261. let _this = this
  262. showConfirmWin(_this, null, '您确定要删除该图表吗?', () => {
  263. const loading = showLoading(_this, '删除中,请稍候···')
  264. delIndexChartById(row.id).then(res => {
  265. loading.close()
  266. this.getIndexAllChart()
  267. showAlertMsgWin(this, null, res.data)
  268. }).catch((e) => {
  269. loading.close()
  270. showAlertWin(this, null, e)
  271. })
  272. })
  273. },
  274. /** 保存首页图表添加事件 */
  275. addIndexChartBtnEvent() {
  276. this.addIndexChart = true
  277. this.dialogIndexChartVisible = true
  278. },
  279. /** 查询首页图表信息 */
  280. getIndexAllChart() {
  281. getIndexChartList(this.chartPage, this.chartLimit, {}).then(res => {
  282. this.chartTotal = res.data.count
  283. this.chartDataList = res.data.reportTableList
  284. }).catch((e) => {
  285. showAlertWin(this, null, e)
  286. })
  287. },
  288. /** 保存首页图表操作 */
  289. addIndexChartEvent() {
  290. if (!this.chartForm.chartName || !this.chartForm.chartName.trim()) {
  291. showAlertMsgWin(this, null, '图表名称不能为空!')
  292. return
  293. }
  294. // if (this.chartForm.dateRange.length == 0) {
  295. // showAlertMsgWin(this, null, '取值时间不能为空!')
  296. // return
  297. // }
  298. if (this.chartForm.chartItemList.length == 0) {
  299. showAlertMsgWin(this, null, '数据项不能为空!')
  300. return
  301. }
  302. if (this.chartForm.userGroupList.length == 0) {
  303. showAlertMsgWin(this, null, '用户组不能为空!')
  304. return
  305. }
  306. // this.chartForm.startTime = this.chartForm.dateRange[0]
  307. // this.chartForm.endTime = this.chartForm.dateRange[1]
  308. saveIndexChart(this.chartForm).then(res => {
  309. this.addIndexChart = true
  310. this.dialogIndexChartVisible = false
  311. this.getIndexAllChart()
  312. showAlertMsgWin(this, null, res.data)
  313. }).catch((e) => {
  314. showAlertWin(this, null, e)
  315. })
  316. },
  317. /** 修改图表信息 */
  318. updateIndexChartEvent() {
  319. if (!this.chartForm.chartName || !this.chartForm.chartName.trim()) {
  320. showAlertMsgWin(this, null, '图表名称不能为空!')
  321. return
  322. }
  323. if (this.chartForm.chartItemList.length == 0) {
  324. showAlertMsgWin(this, null, '数据项不能为空!')
  325. return
  326. }
  327. if (this.chartForm.userGroupList.length == 0) {
  328. showAlertMsgWin(this, null, '用户组不能为空!')
  329. return
  330. }
  331. updateIndexChart(this.chartForm).then(res => {
  332. this.addIndexChart = true
  333. this.dialogIndexChartVisible = false
  334. this.getIndexAllChart()
  335. showAlertMsgWin(this, null, res.data)
  336. }).catch((e) => {
  337. showAlertWin(this, null, e)
  338. })
  339. },
  340. /** 更新已选择数据项 */
  341. updateDataItemEmit(items) {
  342. this.chartForm.chartItemList = []
  343. items.forEach((item) => {
  344. this.chartForm.chartItemList.push({
  345. 'itemId': item.id,
  346. 'itemGroupId': item.itemGroupId
  347. })
  348. })
  349. },
  350. /** 更新已选择用户组 */
  351. updateUserGroupEmit(groups) {
  352. this.chartForm.userGroupList = []
  353. groups.forEach((id) => {
  354. this.chartForm.userGroupList.push({
  355. 'id': id
  356. })
  357. })
  358. },
  359. /** 选择数据项 */
  360. chooseDataItemEvent() {
  361. let chartItemList = this.chartForm.chartItemList
  362. let groupId = null
  363. let items = []
  364. if (chartItemList && chartItemList.length > 0) {
  365. groupId = chartItemList[0].itemGroupId
  366. chartItemList.forEach((t) => {
  367. items.push(t.itemId)
  368. })
  369. }
  370. this.$refs.dataItem.show(groupId, items)
  371. },
  372. /** 选择用户组 */
  373. chooseUserGroupEvent() {
  374. let userGroups = this.chartForm.userGroupList
  375. let groups = []
  376. if (userGroups && userGroups.length > 0) {
  377. userGroups.forEach((t) => {
  378. groups.push(t.id)
  379. })
  380. }
  381. this.$refs.userGroup.show(groups)
  382. },
  383. /** 弹出层关闭事件 */
  384. dialogClose(done) {
  385. Object.assign(this.$data.chartForm, this.$options.data.call(this).chartForm)
  386. this.addIndexChart = true
  387. if (typeof (done) === 'function') {
  388. done()
  389. } else {
  390. this.dialogIndexChartVisible = false
  391. }
  392. }
  393. }
  394. }
  395. </script>
  396. <style>
  397. </style>