123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- <template>
- <div v-if="hideMainViewFlag" class="cqcy-content">
- <el-button v-if="roleCodeList.indexOf(__self.clientRole) > -1"
- type="primary" icon="el-icon-circle-plus-outline"
- size="mini" @click="addIndexChartBtnEvent">添加图表
- </el-button>
- <el-divider></el-divider>
- <div>
- <el-table
- :data="chartDataList" border :stripe="true"
- :header-cell-style="{background: '#E8E8E8'}"
- style="width: 100%; height: calc(100% - 100px); overflow: auto;">
- <el-table-column
- align="center"
- label="图表名称"
- prop="chartName">
- <template slot-scope="scope">
- <span style="color: #409EFF; cursor: pointer;"
- @click="handleChartNodeClick(scope.row)"
- :title="scope.row.reportTableName">{{ scope.row.chartName }}</span>
- </template>
- </el-table-column>
- <el-table-column
- align="center"
- label="统计图类型"
- prop="chartType"
- width="200">
- <template slot-scope="scope">
- <span>{{ scope.row.chartType == 'bar' ? '柱状图'
- : (scope.row.chartType == 'line' ? '折线图' : '饼状图') }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" align="center" width="300">
- <template slot-scope="scope">
- <el-button type="text"
- size="small"
- icon="el-icon-edit"
- @click="updateChartItem(scope.row)">修改
- </el-button>
- <el-button type="text"
- size="small"
- icon="el-icon-delete"
- style="color: red;"
- @click="removeChartItem(scope.row)">删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination
- style="margin-top: 20px;"
- background
- layout="sizes, prev, pager, next, total"
- :current-page="chartPage"
- :page-size="chartLimit"
- @size-change="sizeChartChangeEvent"
- @current-change="currentChartChangeEvent"
- :total="chartTotal">
- </el-pagination>
- </div>
- <!-- 新增首页图表 -->
- <el-dialog
- :title="addIndexChart ? '添加图表' : '修改图表'"
- width="600px"
- top="5vh"
- center
- v-dialog-drag
- v-if="dialogIndexChartVisible"
- :before-close="dialogClose"
- :visible.sync="dialogIndexChartVisible"
- :close-on-click-modal="false"
- :append-to-body="true">
- <el-form ref="chartForm" :model="chartForm" :rules="chartFormRules" label-width="110px">
- <el-form-item label='统计图名称:' prop="chartName">
- <el-input placeholder="请输入统计图名称" v-model="chartForm.chartName" maxlength="20" show-word-limit></el-input>
- </el-form-item>
- <el-form-item label="取值类型:" prop="valueType">
- <el-radio v-for="item in valueTypeList"
- v-model="chartForm.valueType"
- :label="item.value">{{ item.label }}</el-radio>
- </el-form-item>
- <el-form-item label="统计图类型:" prop="chartType">
- <el-radio v-for="item in chartTypeList"
- v-model="chartForm.chartType"
- :label="item.value">{{ item.label }}</el-radio>
- </el-form-item>
- <el-form-item label="取值模式:" prop="valueTakingMode">
- <el-radio v-for="item in valueTakingModeList"
- v-model="chartForm.valueTakingMode"
- :label="item.value">{{ item.label }}</el-radio>
- </el-form-item>
- <!-- <el-form-item label="取值时间:" prop="dateRange">-->
- <!-- <el-date-picker-->
- <!-- v-model="chartForm.dateRange"-->
- <!-- type="datetimerange"-->
- <!-- :clearable="false"-->
- <!-- range-separator="至"-->
- <!-- start-placeholder="开始时间"-->
- <!-- end-placeholder="结束时间"-->
- <!-- placeholder="选择取值时间范围"-->
- <!-- :picker-options="{-->
- <!-- format: 'yyyy-MM-dd HH:mm:ss'-->
- <!-- }"-->
- <!-- value-format="yyyy-MM-dd HH:mm:ss"-->
- <!-- :default-time="['09:00:00', '18:00:00']">-->
- <!-- </el-date-picker>-->
- <!-- </el-form-item>-->
- <el-divider content-position="left">取值周期设置</el-divider>
- <div class="cy-line">
- <el-form-item label="时间单位:" prop="bucketType">
- <el-radio v-for="item in bucketTypeList"
- v-model="chartForm.bucketType"
- :label="item.value">{{ item.label }}</el-radio>
- </el-form-item>
- <el-form-item label="数据切换周期:" prop="bucketValue">
- <el-input-number label="请输入周期值"
- v-model="chartForm.bucketValue"
- :precision="0"
- :min="1"
- :max="100"></el-input-number>
- </el-form-item>
- </div>
- <el-form-item label="数据项:" prop="chartItemList">
- <el-button size="mini" @click="chooseDataItemEvent">选择数据项</el-button>
- <el-tag size="mini" v-if="chartForm.chartItemList.length" style="margin-left: 10px;">
- 已选择({{ chartForm.chartItemList.length }})项
- </el-tag>
- </el-form-item>
- <el-form-item label="用户组:" prop="userGroupList">
- <el-button size="mini" @click="chooseUserGroupEvent">选择用户组</el-button>
- <el-tag size="mini" v-if="chartForm.userGroupList.length" style="margin-left: 10px;">
- 已选择({{ chartForm.userGroupList.length }})组
- </el-tag>
- </el-form-item>
- </el-form>
- <span slot='footer'>
- <el-button v-if="addIndexChart" type="primary" @click="addIndexChartEvent">添加</el-button>
- <el-button v-else type="primary" @click="updateIndexChartEvent">修改</el-button>
- <el-button @click="dialogClose">取消</el-button>
- </span>
- </el-dialog>
- <!-- 选择数据项 -->
- <data-item ref="dataItem" @update-message="updateDataItemEmit"></data-item>
- <!-- 选择用户组 -->
- <user-group ref="userGroup" @update-message="updateUserGroupEmit"></user-group>
- </div>
- <div v-else></div>
- </template>
- <script>
- import DataItem from '@/components/CustomDialog/DataItem'
- import UserGroup from '@/components/CustomDialog/UserGroup'
- import { showAlertMsgWin, showAlertWin, showConfirmWin, showLoading} from "@/utils/cqcy";
- import {delIndexChartById, getIndexChartById, getIndexChartList, saveIndexChart, updateIndexChart} from "@/api/chart";
- import {mapGetters} from "vuex";
- export default {
- name: "index",
- components: {
- DataItem, UserGroup
- },
- data() {
- return {
- roleCodeList: [],
- dialogIndexChartVisible: false,
- addIndexChart: true,
- hideMainViewFlag: true,
- chartDataList: [],
- chartTotal: 0,
- chartPage: 1,
- chartLimit: 10,
- chartTypeList: [
- { 'label': '柱状图', 'value': 'bar' },
- { 'label': '折线图', 'value': 'line' },
- { 'label': '饼状图', 'value': 'pie' }
- ],
- valueTypeList: [
- { 'label': '原始值', 'value': 0 },
- { 'label': '计算值', 'value': 1 }
- ],
- bucketTypeList: [
- { 'label': '天', 'value': 0 },
- { 'label': '时', 'value': 1 },
- { 'label': '分', 'value': 2 },
- { 'label': '秒', 'value': 3 }
- ],
- valueTakingModeList: [
- { 'label': '平均值', 'value': 0 },
- { 'label': '最大值', 'value': 1 },
- { 'label': '最小值', 'value': 2 },
- { 'label': '瞬时值', 'value': 3 }
- ],
- chartForm: {
- chartName: '',
- valueType: 0,
- chartType: 'bar',
- valueTakingMode: 0,
- bucketType: 1,
- bucketValue: 1,
- dateRange: [],
- startTime: null,
- endTime: null,
- chartItemList: [],
- userGroupList: []
- },
- chartFormRules: {
- chartName: [
- { required: true, message: '名称不能为空', trigger: 'blur' }
- ],chartItemList: [
- { required: true, message: '数据项不能为空', trigger: 'blur' }
- ],userGroupList: [
- { required: true, message: '用户组不能为空', trigger: 'blur' }
- ]
- }
- }
- },
- inject: ['__self'],
- computed: {
- ...mapGetters([
- 'roles'
- ])
- },
- mounted() {
- this.roleCodeList = []
- this.roles.forEach((role) => {
- this.roleCodeList.push(role.roleCode)
- })
- },
- created() {
- this.getIndexAllChart()
- },
- methods: {
- hideMainView(flag) {
- this.hideMainViewFlag = flag
- },
- sizeChartChangeEvent(val) {
- this.chartPage = 1
- this.chartLimit = val
- this.getIndexAllChart()
- },
- currentChartChangeEvent(val) {
- this.chartPage = val
- this.getIndexAllChart()
- },
- /** 图表点击事件 */
- handleChartNodeClick(row) {
- },
- /** 图表修改事件 */
- updateChartItem(row) {
- getIndexChartById(row.id).then(res => {
- if (!res.data) {
- showAlertMsgWin(this, null, '修改失败!')
- return
- }
- this.chartForm = res.data
- this.addIndexChart = false
- this.dialogIndexChartVisible = true
- }).catch((e) => {
- showAlertWin(this, null, e)
- })
- },
- /** 图表删除事件 */
- removeChartItem(row) {
- let _this = this
- showConfirmWin(_this, null, '您确定要删除该图表吗?', () => {
- const loading = showLoading(_this, '删除中,请稍候···')
- delIndexChartById(row.id).then(res => {
- loading.close()
- this.getIndexAllChart()
- showAlertMsgWin(this, null, res.data)
- }).catch((e) => {
- loading.close()
- showAlertWin(this, null, e)
- })
- })
- },
- /** 保存首页图表添加事件 */
- addIndexChartBtnEvent() {
- this.addIndexChart = true
- this.dialogIndexChartVisible = true
- },
- /** 查询首页图表信息 */
- getIndexAllChart() {
- getIndexChartList(this.chartPage, this.chartLimit, {}).then(res => {
- this.chartTotal = res.data.count
- this.chartDataList = res.data.reportTableList
- }).catch((e) => {
- showAlertWin(this, null, e)
- })
- },
- /** 保存首页图表操作 */
- addIndexChartEvent() {
- if (!this.chartForm.chartName || !this.chartForm.chartName.trim()) {
- showAlertMsgWin(this, null, '图表名称不能为空!')
- return
- }
- // if (this.chartForm.dateRange.length == 0) {
- // showAlertMsgWin(this, null, '取值时间不能为空!')
- // return
- // }
- if (this.chartForm.chartItemList.length == 0) {
- showAlertMsgWin(this, null, '数据项不能为空!')
- return
- }
- if (this.chartForm.userGroupList.length == 0) {
- showAlertMsgWin(this, null, '用户组不能为空!')
- return
- }
- // this.chartForm.startTime = this.chartForm.dateRange[0]
- // this.chartForm.endTime = this.chartForm.dateRange[1]
- saveIndexChart(this.chartForm).then(res => {
- this.addIndexChart = true
- this.dialogIndexChartVisible = false
- this.getIndexAllChart()
- showAlertMsgWin(this, null, res.data)
- }).catch((e) => {
- showAlertWin(this, null, e)
- })
- },
- /** 修改图表信息 */
- updateIndexChartEvent() {
- if (!this.chartForm.chartName || !this.chartForm.chartName.trim()) {
- showAlertMsgWin(this, null, '图表名称不能为空!')
- return
- }
- if (this.chartForm.chartItemList.length == 0) {
- showAlertMsgWin(this, null, '数据项不能为空!')
- return
- }
- if (this.chartForm.userGroupList.length == 0) {
- showAlertMsgWin(this, null, '用户组不能为空!')
- return
- }
- updateIndexChart(this.chartForm).then(res => {
- this.addIndexChart = true
- this.dialogIndexChartVisible = false
- this.getIndexAllChart()
- showAlertMsgWin(this, null, res.data)
- }).catch((e) => {
- showAlertWin(this, null, e)
- })
- },
- /** 更新已选择数据项 */
- updateDataItemEmit(items) {
- this.chartForm.chartItemList = []
- items.forEach((item) => {
- this.chartForm.chartItemList.push({
- 'itemId': item.id,
- 'itemGroupId': item.itemGroupId
- })
- })
- },
- /** 更新已选择用户组 */
- updateUserGroupEmit(groups) {
- this.chartForm.userGroupList = []
- groups.forEach((id) => {
- this.chartForm.userGroupList.push({
- 'id': id
- })
- })
- },
- /** 选择数据项 */
- chooseDataItemEvent() {
- let chartItemList = this.chartForm.chartItemList
- let groupId = null
- let items = []
- if (chartItemList && chartItemList.length > 0) {
- groupId = chartItemList[0].itemGroupId
- chartItemList.forEach((t) => {
- items.push(t.itemId)
- })
- }
- this.$refs.dataItem.show(groupId, items)
- },
- /** 选择用户组 */
- chooseUserGroupEvent() {
- let userGroups = this.chartForm.userGroupList
- let groups = []
- if (userGroups && userGroups.length > 0) {
- userGroups.forEach((t) => {
- groups.push(t.id)
- })
- }
- this.$refs.userGroup.show(groups)
- },
- /** 弹出层关闭事件 */
- dialogClose(done) {
- Object.assign(this.$data.chartForm, this.$options.data.call(this).chartForm)
- this.addIndexChart = true
- if (typeof (done) === 'function') {
- done()
- } else {
- this.dialogIndexChartVisible = false
- }
- }
- }
- }
- </script>
- <style>
- </style>
|