From 8367033bb46b083a2ab2612ccaa7dc82338fca7a Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Wed, 17 Mar 2021 11:22:18 +0800 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20=E4=BB=AA=E8=A1=A8=E7=9B=98?= =?UTF-8?q?=E5=88=86=E4=BA=ABtab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/panel/GrantAuth/index.vue | 30 ++++++++++++++++++++ frontend/src/views/panel/list/PanelList.vue | 18 +++++++++--- 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 frontend/src/views/panel/GrantAuth/index.vue diff --git a/frontend/src/views/panel/GrantAuth/index.vue b/frontend/src/views/panel/GrantAuth/index.vue new file mode 100644 index 0000000000..8fbbaade4c --- /dev/null +++ b/frontend/src/views/panel/GrantAuth/index.vue @@ -0,0 +1,30 @@ + + + diff --git a/frontend/src/views/panel/list/PanelList.vue b/frontend/src/views/panel/list/PanelList.vue index 3de67d91e2..259c789bd1 100644 --- a/frontend/src/views/panel/list/PanelList.vue +++ b/frontend/src/views/panel/list/PanelList.vue @@ -111,14 +111,14 @@ - 分享授权 + 取 消 确 定 @@ -129,12 +129,16 @@ + + diff --git a/frontend/src/views/chart/group/Group.vue b/frontend/src/views/chart/group/Group.vue index 35a2a951e1..a7ce7ad8cc 100644 --- a/frontend/src/views/chart/group/Group.vue +++ b/frontend/src/views/chart/group/Group.vue @@ -211,6 +211,7 @@ + + diff --git a/frontend/src/views/panel/GrantAuth/index.vue b/frontend/src/views/panel/GrantAuth/index.vue index 8fbbaade4c..3c6f310b6e 100644 --- a/frontend/src/views/panel/GrantAuth/index.vue +++ b/frontend/src/views/panel/GrantAuth/index.vue @@ -1,14 +1,28 @@ + + diff --git a/frontend/src/views/panel/GrantAuth/role/index.vue b/frontend/src/views/panel/GrantAuth/role/index.vue new file mode 100644 index 0000000000..8785b10702 --- /dev/null +++ b/frontend/src/views/panel/GrantAuth/role/index.vue @@ -0,0 +1,89 @@ + + + + + diff --git a/frontend/src/views/panel/GrantAuth/user/index.vue b/frontend/src/views/panel/GrantAuth/user/index.vue new file mode 100644 index 0000000000..f36929d659 --- /dev/null +++ b/frontend/src/views/panel/GrantAuth/user/index.vue @@ -0,0 +1,88 @@ + + + + + diff --git a/frontend/src/views/panel/list/PanelList.vue b/frontend/src/views/panel/list/PanelList.vue index 9c0a958ae5..f1770358c8 100644 --- a/frontend/src/views/panel/list/PanelList.vue +++ b/frontend/src/views/panel/list/PanelList.vue @@ -114,8 +114,7 @@ :title="authTitle" :visible.sync="authVisible" :show-close="false" - width="30%" - custom-class="authDialog" + custom-class="de-dialog" :before-close="handleClose" > @@ -484,10 +483,11 @@ export default { }, share(data) { this.authResourceId = data.id - this.authTitle = '把仪表板[' + data.label + ']分享给' + this.authTitle = '把[' + data.label + ']分享给' this.authVisible = true }, handleClose(done) { + this.authResourceId = null this.handleClose = false } } @@ -540,8 +540,4 @@ export default { line-height: 26px; } - /* .el-dialog authDialog >>> div { - padding: 5px !important; - padding-bottom:5px !important; - } */ diff --git a/frontend/src/views/panel/list/PanelViewShow.vue b/frontend/src/views/panel/list/PanelViewShow.vue index 8295a524de..f2eca67623 100644 --- a/frontend/src/views/panel/list/PanelViewShow.vue +++ b/frontend/src/views/panel/list/PanelViewShow.vue @@ -34,7 +34,7 @@ - 名称:{{panelInfo.name}} + 名称:{{ panelInfo.name }} 背景图 From d50fbd21ca3944ae8ce41f46d01502827fda93ad Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 18 Mar 2021 10:08:12 +0800 Subject: [PATCH 05/10] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=20=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E7=BC=96=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/chart/components/ChartComponent.vue | 5 +++-- frontend/src/views/chart/components/ColorSelector.vue | 7 ++++++- frontend/src/views/chart/view/ChartEdit.vue | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/src/views/chart/components/ChartComponent.vue b/frontend/src/views/chart/components/ChartComponent.vue index 3cf27335bc..2e065d2594 100644 --- a/frontend/src/views/chart/components/ChartComponent.vue +++ b/frontend/src/views/chart/components/ChartComponent.vue @@ -52,8 +52,9 @@ export default { // console.log(chart_option); // 处理shape attr if (chart.customAttr) { - if (chart.customAttr.color) { - chart_option.color = chart.customAttr.color.colors + const customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors } } this.myEcharts(chart_option) diff --git a/frontend/src/views/chart/components/ColorSelector.vue b/frontend/src/views/chart/components/ColorSelector.vue index 383cd1ee4f..088e271427 100644 --- a/frontend/src/views/chart/components/ColorSelector.vue +++ b/frontend/src/views/chart/components/ColorSelector.vue @@ -94,7 +94,12 @@ export default { 'chart': { handler: function() { const chart = JSON.parse(JSON.stringify(this.chart)) - this.colorForm.colorCase = chart.customAttr.color.value + if (chart.customAttr) { + const customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + this.colorForm.colorCase = customAttr.color.value + } + } } } }, diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index b65d2cdb7a..00dc35945f 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -264,7 +264,7 @@ export default { getData(id) { if (id) { post('/chart/view/getData/' + id, null).then(response => { - this.view = response.data + this.view = JSON.parse(JSON.stringify(response.data)) this.view.xaxis = this.view.xaxis ? JSON.parse(this.view.xaxis) : [] this.view.yaxis = this.view.yaxis ? JSON.parse(this.view.yaxis) : [] this.view.customAttr = this.view.customAttr ? JSON.parse(this.view.customAttr) : {} From 3f5d2bee5332725dc59a93ef54aa696b99648c8a Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 18 Mar 2021 11:05:14 +0800 Subject: [PATCH 06/10] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=20=E8=A7=86?= =?UTF-8?q?=E5=9B=BE=E7=BB=84=E4=BB=B6=E4=B8=B4=E6=97=B6=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/chart/chart/bar/baseBar.js | 21 +++++++++++++++++ .../src/views/chart/chart/line/baseLine.js | 21 +++++++++++++++++ .../views/chart/components/ChartComponent.vue | 23 ++++--------------- 3 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 frontend/src/views/chart/chart/bar/baseBar.js create mode 100644 frontend/src/views/chart/chart/line/baseLine.js diff --git a/frontend/src/views/chart/chart/bar/baseBar.js b/frontend/src/views/chart/chart/bar/baseBar.js new file mode 100644 index 0000000000..69788002e1 --- /dev/null +++ b/frontend/src/views/chart/chart/bar/baseBar.js @@ -0,0 +1,21 @@ +export function baseBarOption(chart_option, chart) { +// 处理data + if (chart.data) { + chart_option.title.text = chart.title + chart_option.xAxis.data = chart.data.x + chart.data.series.forEach(function(y) { + chart_option.legend.data.push(y.name) + chart_option.series.push(y) + }) + } + // console.log(chart_option); + // 处理shape attr + if (chart.customAttr) { + const customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + return chart_option +} + diff --git a/frontend/src/views/chart/chart/line/baseLine.js b/frontend/src/views/chart/chart/line/baseLine.js new file mode 100644 index 0000000000..d431f2758d --- /dev/null +++ b/frontend/src/views/chart/chart/line/baseLine.js @@ -0,0 +1,21 @@ +export function baseLineOption(chart_option, chart) { +// 处理data + if (chart.data) { + chart_option.title.text = chart.title + chart_option.xAxis.data = chart.data.x + chart.data.series.forEach(function(y) { + chart_option.legend.data.push(y.name) + chart_option.series.push(y) + }) + } + // console.log(chart_option); + // 处理shape attr + if (chart.customAttr) { + const customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + return chart_option +} + diff --git a/frontend/src/views/chart/components/ChartComponent.vue b/frontend/src/views/chart/components/ChartComponent.vue index 2e065d2594..4aac1f97ab 100644 --- a/frontend/src/views/chart/components/ChartComponent.vue +++ b/frontend/src/views/chart/components/ChartComponent.vue @@ -6,6 +6,8 @@ diff --git a/frontend/src/views/panel/GrantAuth/index.vue b/frontend/src/views/panel/GrantAuth/index.vue index 3c6f310b6e..da7f8fe016 100644 --- a/frontend/src/views/panel/GrantAuth/index.vue +++ b/frontend/src/views/panel/GrantAuth/index.vue @@ -8,10 +8,16 @@ - - - + + + +
+ + 取 消 + 确 定 + +
@@ -31,11 +37,15 @@ export default { }, data() { return { - activeName: '1', + tabNames: ['grantDept', 'grantRole', 'grantUser'], + activeName: null, showSearchInput: false, - key: null + key: '' } }, + created() { + this.activeName = this.tabNames[0] + }, methods: { handleClick(tab, event) { @@ -45,7 +55,16 @@ export default { this.showSearchInput = true }, closeSearchWidget() { + this.key = '' this.showSearchInput = false + }, + save() { + this.$refs[this.activeName].save() + this.$emit('close-grant', 0) + }, + cancel() { + this.$refs[this.activeName].cancel() + this.$emit('close-grant', 0) } } } @@ -71,6 +90,11 @@ export default { border-right: none; } +.auth-root-class { + margin: 15px 0px 5px; + text-align: right; +} + // ::-webkit-scrollbar { // } diff --git a/frontend/src/views/panel/GrantAuth/role/index.vue b/frontend/src/views/panel/GrantAuth/role/index.vue index 8785b10702..99bca3e460 100644 --- a/frontend/src/views/panel/GrantAuth/role/index.vue +++ b/frontend/src/views/panel/GrantAuth/role/index.vue @@ -2,7 +2,7 @@
import { roleGrid } from '@/api/system/role' import { formatCondition } from '@/utils/index' +import { saveShare, loadShares } from '@/api/panel/share' export default { name: 'GrantRole', props: { resourceId: { type: String, default: null + }, + keyWord: { + type: String, + default: '' } }, data() { @@ -31,7 +36,9 @@ export default { defaultHeadName: '全部', columnLabel: null, filter_options: [{ text: '未分享角色', value: 0 }, { text: '已分享角色', value: 1 }], - fieldName: 'name' + fieldName: 'name', + type: 1, // 类型1代表角色 + shares: [] } }, created() { @@ -50,12 +57,14 @@ export default { const data = response.data // this.total = data.itemCount this.data = data.listObject + this.queryShareNodeIds() }) }, filterHandler(value, row, column) { // const property = column['property'] // return row[property] === value - return row['code'] === 'admin' + const roleId = row['roleId'] + return !(value ^ this.shares.includes(roleId)) }, filterChange(obj) { @@ -65,6 +74,52 @@ export default { return } this.columnLabel = this.filter_options[arr[0]].text + }, + save() { + const rows = this.$refs.table.store.states.selection + const request = this.buildRequest(rows) + saveShare(request).then(res => { + this.$success('保存成功') + return true + }).catch(err => { + this.$error(err.message) + return false + }) + }, + + cancel() { + console.log('role cancel') + }, + buildRequest(rows) { + const targetIds = rows.map(row => row.roleId) + const panelIds = [this.resourceId] + return { + targetIds: targetIds, + panelIds: panelIds, + type: this.type + } + }, + + queryShareNodeIds(callBack) { + const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId } + const conditionType = { field: 'type', operator: 'eq', value: this.type } + const param = { conditions: [conditionResourceId, conditionType] } + loadShares(param).then(res => { + const shares = res.data + const nodeIds = shares.map(share => share.targetId) + this.shares = nodeIds + this.$nextTick(() => { + this.setCheckNodes() + }) + callBack && callBack() + }) + }, + + setCheckNodes() { + this.data.forEach(node => { + const nodeId = node.roleId + this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true) + }) } } diff --git a/frontend/src/views/panel/GrantAuth/user/index.vue b/frontend/src/views/panel/GrantAuth/user/index.vue index f36929d659..43b3c57ac5 100644 --- a/frontend/src/views/panel/GrantAuth/user/index.vue +++ b/frontend/src/views/panel/GrantAuth/user/index.vue @@ -2,7 +2,7 @@
import { userLists } from '@/api/system/user' import { formatCondition } from '@/utils/index' +import { saveShare, loadShares } from '@/api/panel/share' export default { name: 'GrantUser', props: { resourceId: { type: String, default: null + }, + keyWord: { + type: String, + default: '' } }, data() { @@ -31,7 +36,9 @@ export default { defaultHeadName: '全部', columnLabel: null, filter_options: [{ text: '未分享人员', value: 0 }, { text: '已分享人员', value: 1 }], - fieldName: 'nickName' + fieldName: 'nickName', + type: 0, // 类型0代表用户 + shares: [] } }, created() { @@ -49,12 +56,14 @@ export default { const data = response.data // this.total = data.itemCount this.data = data.listObject + this.queryShareNodeIds() }) }, filterHandler(value, row, column) { // const property = column['property'] // return row[property] === value - return row['code'] === 'admin' + const userId = row['userId'] + return !(value ^ this.shares.includes(userId)) }, filterChange(obj) { @@ -64,6 +73,53 @@ export default { return } this.columnLabel = this.filter_options[arr[0]].text + }, + + save() { + const rows = this.$refs.table.store.states.selection + const request = this.buildRequest(rows) + saveShare(request).then(res => { + this.$success('保存成功') + return true + }).catch(err => { + this.$error(err.message) + return false + }) + }, + + cancel() { + console.log('user cancel') + }, + buildRequest(rows) { + const targetIds = rows.map(row => row.userId) + const panelIds = [this.resourceId] + return { + targetIds: targetIds, + panelIds: panelIds, + type: this.type + } + }, + + queryShareNodeIds(callBack) { + const conditionResourceId = { field: 'panel_group_id', operator: 'eq', value: this.resourceId } + const conditionType = { field: 'type', operator: 'eq', value: this.type } + const param = { conditions: [conditionResourceId, conditionType] } + loadShares(param).then(res => { + const shares = res.data + const nodeIds = shares.map(share => share.targetId) + this.shares = nodeIds + this.$nextTick(() => { + this.setCheckNodes() + }) + callBack && callBack() + }) + }, + + setCheckNodes() { + this.data.forEach(node => { + const nodeId = node.userId + this.shares.includes(nodeId) && this.$refs.table.toggleRowSelection(node, true) + }) } } diff --git a/frontend/src/views/panel/list/PanelList.vue b/frontend/src/views/panel/list/PanelList.vue index f1770358c8..e4d33e628d 100644 --- a/frontend/src/views/panel/list/PanelList.vue +++ b/frontend/src/views/panel/list/PanelList.vue @@ -113,15 +113,13 @@ - - + + @@ -486,9 +484,9 @@ export default { this.authTitle = '把[' + data.label + ']分享给' this.authVisible = true }, - handleClose(done) { + closeGrant() { this.authResourceId = null - this.handleClose = false + this.authVisible = false } } } From 760b05e2773e21320f1dc91421cb76e8b6653c5a Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Thu, 18 Mar 2021 16:56:24 +0800 Subject: [PATCH 08/10] =?UTF-8?q?feat:=20=E5=88=86=E4=BA=AB=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/panel/share.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 frontend/src/api/panel/share.js diff --git a/frontend/src/api/panel/share.js b/frontend/src/api/panel/share.js new file mode 100644 index 0000000000..ed12ea2301 --- /dev/null +++ b/frontend/src/api/panel/share.js @@ -0,0 +1,20 @@ +import request from '@/utils/request' + +export function saveShare(data) { + return request({ + url: '/api/share/', + method: 'post', + loading: true, + data + }) +} + +export function loadShares(data) { + return request({ + url: '/api/share/queryWithResourceId', + method: 'post', + loading: true, + data + }) +} + From f891dc5acacb98bd225174af3b2ec2280f2c40fb Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 18 Mar 2021 17:20:59 +0800 Subject: [PATCH 09/10] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=201.=E4=B8=B0?= =?UTF-8?q?=E5=AF=8Cchart=E7=A7=8D=E7=B1=BB=EF=BC=9B2.echarts=20option?= =?UTF-8?q?=E5=B0=81=E8=A3=85=EF=BC=9B3.=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E4=B8=8D=E5=A4=AA=E5=A5=BD=E7=9C=8B=E7=9A=84svg?= =?UTF-8?q?=E4=BD=9C=E4=B8=BA=E5=9B=BE=E8=A1=A8=E7=B1=BB=E5=9E=8Bicon-font?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/icons/svg/bar-horizontal.svg | 1 + .../src/icons/svg/bar-stack-horizontal.svg | 1 + frontend/src/icons/svg/bar-stack.svg | 1 + frontend/src/icons/svg/bar.svg | 1 + frontend/src/icons/svg/funnel.svg | 1 + frontend/src/icons/svg/line.svg | 1 + frontend/src/icons/svg/pie.svg | 1 + frontend/src/lang/zh.js | 3 +- frontend/src/views/chart/chart/bar/bar.js | 81 ++++++++++++++++ frontend/src/views/chart/chart/bar/baseBar.js | 21 ---- frontend/src/views/chart/chart/chart.js | 95 ++++++++++++++++++- .../src/views/chart/chart/funnel/funnel.js | 34 +++++++ .../chart/chart/line/{baseLine.js => line.js} | 30 +++--- frontend/src/views/chart/chart/pie/pie.js | 34 +++++++ frontend/src/views/chart/chart/util.js | 19 ++++ .../views/chart/components/ChartComponent.vue | 18 +++- .../views/chart/components/ColorSelector.vue | 10 +- .../src/views/chart/components/QuotaItem.vue | 4 +- frontend/src/views/chart/view/ChartEdit.vue | 36 ++++++- 19 files changed, 346 insertions(+), 46 deletions(-) create mode 100644 frontend/src/icons/svg/bar-horizontal.svg create mode 100644 frontend/src/icons/svg/bar-stack-horizontal.svg create mode 100644 frontend/src/icons/svg/bar-stack.svg create mode 100644 frontend/src/icons/svg/bar.svg create mode 100644 frontend/src/icons/svg/funnel.svg create mode 100644 frontend/src/icons/svg/line.svg create mode 100644 frontend/src/icons/svg/pie.svg create mode 100644 frontend/src/views/chart/chart/bar/bar.js delete mode 100644 frontend/src/views/chart/chart/bar/baseBar.js create mode 100644 frontend/src/views/chart/chart/funnel/funnel.js rename frontend/src/views/chart/chart/line/{baseLine.js => line.js} (53%) create mode 100644 frontend/src/views/chart/chart/pie/pie.js create mode 100644 frontend/src/views/chart/chart/util.js diff --git a/frontend/src/icons/svg/bar-horizontal.svg b/frontend/src/icons/svg/bar-horizontal.svg new file mode 100644 index 0000000000..6ade56b3c8 --- /dev/null +++ b/frontend/src/icons/svg/bar-horizontal.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/bar-stack-horizontal.svg b/frontend/src/icons/svg/bar-stack-horizontal.svg new file mode 100644 index 0000000000..9a78910ab6 --- /dev/null +++ b/frontend/src/icons/svg/bar-stack-horizontal.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/bar-stack.svg b/frontend/src/icons/svg/bar-stack.svg new file mode 100644 index 0000000000..90beda11f0 --- /dev/null +++ b/frontend/src/icons/svg/bar-stack.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/bar.svg b/frontend/src/icons/svg/bar.svg new file mode 100644 index 0000000000..2136e79aad --- /dev/null +++ b/frontend/src/icons/svg/bar.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/funnel.svg b/frontend/src/icons/svg/funnel.svg new file mode 100644 index 0000000000..89190945f5 --- /dev/null +++ b/frontend/src/icons/svg/funnel.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/line.svg b/frontend/src/icons/svg/line.svg new file mode 100644 index 0000000000..c72c676e2b --- /dev/null +++ b/frontend/src/icons/svg/line.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/icons/svg/pie.svg b/frontend/src/icons/svg/pie.svg new file mode 100644 index 0000000000..7d7c52824e --- /dev/null +++ b/frontend/src/icons/svg/pie.svg @@ -0,0 +1 @@ + diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js index 46ef617959..96afef2bb0 100644 --- a/frontend/src/lang/zh.js +++ b/frontend/src/lang/zh.js @@ -614,7 +614,8 @@ export default { color_gentle: '柔和', color_elegant: '淡雅', color_technology: '科技', - color_simple: '简洁' + color_simple: '简洁', + not_alpha: '不透明度' }, dataset: { datalist: '数据集', diff --git a/frontend/src/views/chart/chart/bar/bar.js b/frontend/src/views/chart/chart/bar/bar.js new file mode 100644 index 0000000000..1200b1d3a3 --- /dev/null +++ b/frontend/src/views/chart/chart/bar/bar.js @@ -0,0 +1,81 @@ +import { hexColorToRGBA } from '../util.js' + +export function baseBarOption(chart_option, chart) { + // 处理shape attr + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + // 处理data + if (chart.data) { + chart_option.title.text = chart.title + chart_option.xAxis.data = chart.data.x + for (let i = 0; i < chart.data.series.length; i++) { + const y = chart.data.series[i] + y.itemStyle = { + color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha) + } + y.type = 'bar' + chart_option.legend.data.push(y.name) + chart_option.series.push(y) + } + } + // console.log(chart_option); + return chart_option +} + +export function stackBarOption(chart_option, chart) { + baseBarOption(chart_option, chart) + + // ext + chart_option.series.forEach(function(s) { + s.stack = 'stack' + s.emphasis = { + focus: 'series' + } + }) + return chart_option +} + +export function horizontalBarOption(chart_option, chart) { + // 处理shape attr + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + // 处理data + if (chart.data) { + chart_option.title.text = chart.title + chart_option.yAxis.data = chart.data.x + for (let i = 0; i < chart.data.series.length; i++) { + const y = chart.data.series[i] + y.itemStyle = { + color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha) + } + y.type = 'bar' + chart_option.legend.data.push(y.name) + chart_option.series.push(y) + } + } + // console.log(chart_option); + return chart_option +} + +export function horizontalStackBarOption(chart_option, chart) { + horizontalBarOption(chart_option, chart) + + // ext + chart_option.series.forEach(function(s) { + s.stack = 'stack' + s.emphasis = { + focus: 'series' + } + }) + return chart_option +} diff --git a/frontend/src/views/chart/chart/bar/baseBar.js b/frontend/src/views/chart/chart/bar/baseBar.js deleted file mode 100644 index 69788002e1..0000000000 --- a/frontend/src/views/chart/chart/bar/baseBar.js +++ /dev/null @@ -1,21 +0,0 @@ -export function baseBarOption(chart_option, chart) { -// 处理data - if (chart.data) { - chart_option.title.text = chart.title - chart_option.xAxis.data = chart.data.x - chart.data.series.forEach(function(y) { - chart_option.legend.data.push(y.name) - chart_option.series.push(y) - }) - } - // console.log(chart_option); - // 处理shape attr - if (chart.customAttr) { - const customAttr = JSON.parse(chart.customAttr) - if (customAttr.color) { - chart_option.color = customAttr.color.colors - } - } - return chart_option -} - diff --git a/frontend/src/views/chart/chart/chart.js b/frontend/src/views/chart/chart/chart.js index ee38bc088f..53142e5580 100644 --- a/frontend/src/views/chart/chart/chart.js +++ b/frontend/src/views/chart/chart/chart.js @@ -1,6 +1,7 @@ export const DEFAULT_COLOR_CASE = { value: 'default', - colors: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'] + colors: ['#5470c6', '#91cc75', '#fac858', '#ee6666', '#73c0de', '#3ba272', '#fc8452', '#9a60b4', '#ea7ccc'], + alpha: 100 } export const BASE_BAR = { title: { @@ -18,6 +19,22 @@ export const BASE_BAR = { }, series: [] } +export const HORIZONTAL_BAR = { + title: { + text: '' + }, + tooltip: {}, + legend: { + data: [] + }, + xAxis: { + type: 'value' + }, + yAxis: { + data: [] + }, + series: [] +} export const BASE_LINE = { title: { @@ -36,6 +53,78 @@ export const BASE_LINE = { series: [] } -export default { - BASE_BAR, BASE_LINE, DEFAULT_COLOR_CASE +export const BASE_PIE = { + title: { + text: '' + }, + tooltip: { + trigger: 'item', + formatter: '{a}
{b}: {c} ({d}%)' + }, + legend: {}, + series: [ + { + name: '', + type: 'pie', + radius: ['0%', '60%'], + avoidLabelOverlap: false, + emphasis: { + itemStyle: { + shadowBlur: 10, + shadowOffsetX: 0, + shadowColor: 'rgba(0, 0, 0, 0.5)' + } + }, + data: [] + } + ] +} + +export const BASE_FUNNEL = { + title: { + text: '' + }, + tooltip: { + trigger: 'item' + }, + legend: { + // data: [] + }, + series: [ + { + name: '', + type: 'funnel', + left: '10%', + top: 60, + bottom: 60, + width: '80%', + min: 0, + max: 100, + minSize: '0%', + maxSize: '100%', + sort: 'descending', + gap: 1, + // label: { + // show: true, + // position: 'inside' + // }, + labelLine: { + length: 10, + lineStyle: { + width: 1, + type: 'solid' + } + }, + itemStyle: { + borderColor: '#fff', + borderWidth: 1 + }, + emphasis: { + label: { + fontSize: 20 + } + }, + data: [] + } + ] } diff --git a/frontend/src/views/chart/chart/funnel/funnel.js b/frontend/src/views/chart/chart/funnel/funnel.js new file mode 100644 index 0000000000..639f58c36a --- /dev/null +++ b/frontend/src/views/chart/chart/funnel/funnel.js @@ -0,0 +1,34 @@ +import { hexColorToRGBA } from '@/views/chart/chart/util' + +export function baseFunnelOption(chart_option, chart) { + // 处理shape attr + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + // 处理data + if (chart.data) { + chart_option.title.text = chart.title + if (chart.data.series.length > 0) { + chart_option.series[0].name = chart.data.series[0].name + const valueArr = chart.data.series[0].data + for (let i = 0; i < valueArr.length; i++) { + const y = { + name: chart.data.x[i], + value: valueArr[i] + } + y.itemStyle = { + color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha) + } + y.type = 'funnel' + chart_option.series[0].data.push(y) + } + } + } + // console.log(chart_option); + return chart_option +} + diff --git a/frontend/src/views/chart/chart/line/baseLine.js b/frontend/src/views/chart/chart/line/line.js similarity index 53% rename from frontend/src/views/chart/chart/line/baseLine.js rename to frontend/src/views/chart/chart/line/line.js index d431f2758d..8fe395b7e7 100644 --- a/frontend/src/views/chart/chart/line/baseLine.js +++ b/frontend/src/views/chart/chart/line/line.js @@ -1,21 +1,29 @@ +import { hexColorToRGBA } from '@/views/chart/chart/util' + export function baseLineOption(chart_option, chart) { -// 处理data - if (chart.data) { - chart_option.title.text = chart.title - chart_option.xAxis.data = chart.data.x - chart.data.series.forEach(function(y) { - chart_option.legend.data.push(y.name) - chart_option.series.push(y) - }) - } - // console.log(chart_option); // 处理shape attr + let customAttr = {} if (chart.customAttr) { - const customAttr = JSON.parse(chart.customAttr) + customAttr = JSON.parse(chart.customAttr) if (customAttr.color) { chart_option.color = customAttr.color.colors } } + // 处理data + if (chart.data) { + chart_option.title.text = chart.title + chart_option.xAxis.data = chart.data.x + for (let i = 0; i < chart.data.series.length; i++) { + const y = chart.data.series[i] + y.itemStyle = { + color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha) + } + y.type = 'line' + chart_option.legend.data.push(y.name) + chart_option.series.push(y) + } + } + // console.log(chart_option); return chart_option } diff --git a/frontend/src/views/chart/chart/pie/pie.js b/frontend/src/views/chart/chart/pie/pie.js new file mode 100644 index 0000000000..8739c4a0e1 --- /dev/null +++ b/frontend/src/views/chart/chart/pie/pie.js @@ -0,0 +1,34 @@ +import { hexColorToRGBA } from '@/views/chart/chart/util' + +export function basePieOption(chart_option, chart) { + // 处理shape attr + let customAttr = {} + if (chart.customAttr) { + customAttr = JSON.parse(chart.customAttr) + if (customAttr.color) { + chart_option.color = customAttr.color.colors + } + } + // 处理data + if (chart.data) { + chart_option.title.text = chart.title + if (chart.data.series.length > 0) { + chart_option.series[0].name = chart.data.series[0].name + const valueArr = chart.data.series[0].data + for (let i = 0; i < valueArr.length; i++) { + const y = { + name: chart.data.x[i], + value: valueArr[i] + } + y.itemStyle = { + color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha) + } + y.type = 'pie' + chart_option.series[0].data.push(y) + } + } + } + // console.log(chart_option); + return chart_option +} + diff --git a/frontend/src/views/chart/chart/util.js b/frontend/src/views/chart/chart/util.js new file mode 100644 index 0000000000..1429a54fd2 --- /dev/null +++ b/frontend/src/views/chart/chart/util.js @@ -0,0 +1,19 @@ +export function hexColorToRGBA(hex, alpha) { + const rgb = [] // 定义rgb数组 + if (/^\#[0-9A-F]{3}$/i.test(hex)) { // 判断传入是否为#三位十六进制数 + let sixHex = '#' + hex.replace(/[0-9A-F]/ig, function(kw) { + sixHex += kw + kw // 把三位16进制数转化为六位 + }) + hex = sixHex // 保存回hex + } + if (/^#[0-9A-F]{6}$/i.test(hex)) { // 判断传入是否为#六位十六进制数 + hex.replace(/[0-9A-F]{2}/ig, function(kw) { + rgb.push(eval('0x' + kw)) // 十六进制转化为十进制并存如数组 + }) + return `rgba(${rgb.join(',')},${alpha / 100})` // 输出RGB格式颜色 + } else { + console.log(`Input ${hex} is wrong!`) + return 'rgb(0,0,0)' + } +} diff --git a/frontend/src/views/chart/components/ChartComponent.vue b/frontend/src/views/chart/components/ChartComponent.vue index 4aac1f97ab..8af9544824 100644 --- a/frontend/src/views/chart/components/ChartComponent.vue +++ b/frontend/src/views/chart/components/ChartComponent.vue @@ -5,9 +5,11 @@ - From a83864e13da737fa248d1a87547f686d7b3e1e84 Mon Sep 17 00:00:00 2001 From: junjie Date: Thu, 18 Mar 2021 17:55:28 +0800 Subject: [PATCH 10/10] =?UTF-8?q?feat(=E8=A7=86=E5=9B=BE):=20=E6=BC=8F?= =?UTF-8?q?=E6=96=97=E5=9B=BE=E9=85=8D=E7=BD=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/views/chart/chart/chart.js | 2 +- frontend/src/views/chart/chart/funnel/funnel.js | 1 + frontend/src/views/chart/components/ChartComponent.vue | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/chart/chart/chart.js b/frontend/src/views/chart/chart/chart.js index 53142e5580..3a0e91698e 100644 --- a/frontend/src/views/chart/chart/chart.js +++ b/frontend/src/views/chart/chart/chart.js @@ -94,7 +94,7 @@ export const BASE_FUNNEL = { { name: '', type: 'funnel', - left: '10%', + left: 'center', top: 60, bottom: 60, width: '80%', diff --git a/frontend/src/views/chart/chart/funnel/funnel.js b/frontend/src/views/chart/chart/funnel/funnel.js index 639f58c36a..96bbcf9a96 100644 --- a/frontend/src/views/chart/chart/funnel/funnel.js +++ b/frontend/src/views/chart/chart/funnel/funnel.js @@ -15,6 +15,7 @@ export function baseFunnelOption(chart_option, chart) { if (chart.data.series.length > 0) { chart_option.series[0].name = chart.data.series[0].name const valueArr = chart.data.series[0].data + chart_option.series[0].max = Math.max.apply(Math, valueArr) for (let i = 0; i < valueArr.length; i++) { const y = { name: chart.data.x[i], diff --git a/frontend/src/views/chart/components/ChartComponent.vue b/frontend/src/views/chart/components/ChartComponent.vue index 8af9544824..fe4e9fffd8 100644 --- a/frontend/src/views/chart/components/ChartComponent.vue +++ b/frontend/src/views/chart/components/ChartComponent.vue @@ -53,7 +53,7 @@ export default { } else if (chart.type === 'funnel') { chart_option = baseFunnelOption(JSON.parse(JSON.stringify(BASE_FUNNEL)), chart) } - // console.log(chart_option); + console.log(chart_option) this.myEcharts(chart_option) }, myEcharts(option) {