123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570 |
- <template>
- <div :style="styleObj">
- <v-chart ref="myVChart" :options="options" autoresize/>
- </div>
- </template>
- <script>
- import echarts from "echarts";
- import {targetWidgetLinkageLogic} from "@/views/bigscreenDesigner/designer/linkageLogic";
- let scale = [];
- let max;
- let min;
- // 竖刻度尺
- export default {
- name: "widgetScaleVertical",
- components: {},
- props: {
- value: Object,
- ispreview: Boolean,
- },
- data() {
- return {
- options: {
- yAxis: [
- {
- // 对底部高度有影响
- show: true,
- data: [],
- min: 0,
- max: max,
- axisLine: {
- show: false
- }
- },
- {
- show: false,
- min: 0,
- max: max,
- },
- {
- type: 'category',
- position: 'left',
- offset: -5,
- axisLabel: {
- fontSize: 10,
- color: 'white'
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- }
- ],
- xAxis: [
- // 宽度
- {
- show: false,
- min: -10,
- max: 10,
- data: []
- },
- {
- show: false,
- min: -10,
- max: 10,
- data: []
- },
- {
- show: false,
- min: -10,
- max: 10,
- data: []
- },
- { // 刻度位置
- show: false,
- min: -3,
- max: 10,
- splitLine: {
- lineStyle: {
- color: 'rgba(56, 128, 138,1)',
- }
- }
- }
- ],
- series: [
- {
- name: "值",
- type: "bar",
- barWidth: 35,
- xAxisIndex: 0,
- itemStyle: {
- normal: {
- color: "#0C2F6F",
- barBorderRadius: 50,
- }
- },
- z: 2,
- data: [
- {
- label: {
- normal: {
- show: true,
- position: "top",
- backgroundColor: {},
- width: 10,
- height: 50,
- rich: {
- back: {
- align: 'center',
- lineHeight: 50,
- fontSize: 16,
- fontFamily: 'digifacewide',
- },
- }
- }
- }
- }
- ],
- },
- {
- name: '白框',
- type: 'bar',
- xAxisIndex: 1,
- barGap: '-100%',
- data: [max - 1],
- barWidth: 35,
- itemStyle: {
- normal: {
- color: '#0C2F6F',
- barBorderRadius: 50,
- }
- },
- z: 1
- },
- {
- name: '外框',
- type: 'bar',
- xAxisIndex: 2,
- barGap: '-100%',
- data: [max],
- barWidth: 45,
- itemStyle: {
- normal: {
- color: 'rgba(56, 128, 138,1)',
- barBorderRadius: 50,
- }
- },
- z: 0
- },
- {
- name: '刻度',
- type: 'bar',
- yAxisIndex: 0,
- xAxisIndex: 3,
- label: {
- normal: {
- show: true,
- position: 'left',
- distance: 10,
- color: 'rgba(56, 128, 138,1)',
- fontSize: 16,
- fontWeight: 'normal',
- formatter: function (params) {
- if (params.dataIndex % 10 === 0) {
- return params.dataIndex;
- } else if (params.dataIndex == max) {
- return params.dataIndex;
- } else {
- return ""
- }
- }
- }
- },
- barGap: '-40%',
- data: scale,
- barWidth: 2,
- itemStyle: {
- normal: {
- color: 'rgba(56, 128, 138,1)',
- }
- },
- z: 0
- }
- ],
- },
- optionsStyle: {}, // 样式
- optionsData: {}, // 数据
- optionsCollapse: {}, // 图标属性
- optionsSetup: {},
- flagInter: null,
- };
- },
- computed: {
- styleObj() {
- return {
- position: this.ispreview ? "absolute" : "static",
- width: this.optionsStyle.width + "px",
- height: this.optionsStyle.height + "px",
- left: this.optionsStyle.left + "px",
- top: this.optionsStyle.top + "px",
- background: this.optionsSetup.background,
- };
- },
- allComponentLinkage() {
- return this.$store.state.designer.allComponentLinkage;
- },
- },
- watch: {
- value: {
- handler(val) {
- this.optionsStyle = val.position;
- this.optionsData = val.data;
- this.optionsCollapse = val.collapse;
- this.optionsSetup = val.setup;
- this.editorOptions();
- },
- deep: true,
- },
- },
- created() {
- this.optionsStyle = this.value.position;
- this.optionsData = this.value.data;
- this.optionsCollapse = this.value.collapse;
- this.optionsSetup = this.value.setup;
- this.editorOptions();
- targetWidgetLinkageLogic(this); // 联动-目标组件逻辑
- },
- methods: {
- // 修改图标options属性
- editorOptions() {
- this.setOptionsTitle();
- this.setOptionsMaxScale();
- this.setOptionsYAxis();
- this.setOptionsScale();
- this.setOptionsOutBar();
- this.setOptionsMargin();
- this.setOptionsData();
- this.setOptionsInBar();
- },
- // 标题设置
- setOptionsTitle() {
- const optionsSetup = this.optionsSetup;
- const title = {};
- title.text = optionsSetup.titleText;
- title.show = optionsSetup.isNoTitle;
- title.left = optionsSetup.textAlign;
- title.textStyle = {
- color: optionsSetup.textColor,
- fontSize: optionsSetup.textFontSize,
- fontWeight: optionsSetup.textFontWeight,
- fontStyle: optionsSetup.textFontStyle,
- };
- title.subtext = optionsSetup.subText;
- title.subtextStyle = {
- color: optionsSetup.subTextColor,
- fontWeight: optionsSetup.subTextFontWeight,
- fontSize: optionsSetup.subTextFontSize,
- fontStyle: optionsSetup.subTextFontStyle,
- };
- this.options.title = title;
- },
- // 最大刻度设置
- setOptionsMaxScale() {
- const optionsSetup = this.optionsSetup;
- max = optionsSetup.maxScale;
- scale = this.setScale(max);
- },
- setScale(max) {
- let scale = [];
- for (let i = 0; i <= max; i++) {
- if (i <= 0 || i >= max) {
- scale.push('-2')
- } else {
- if ((i - 10) % 20 === 0) {
- scale.push('-2');
- } else if ((i - 10) % 4 === 0) {
- scale.push('-1');
- } else {
- scale.push('');
- }
- }
- }
- return scale;
- },
- setOptionsYAxis() {
- this.options.yAxis[0].max = max;
- this.options.yAxis[1].max = max;
- },
- // 刻度设定
- setOptionsScale() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[3];
- // 刻度
- // 显示
- if (optionsSetup.isShowScale) {
- series.data = scale;
- }else {
- series.data = 0;
- }
- series.barWidth = optionsSetup.scaleBarWidth;
- series.itemStyle = {
- normal: {
- color: optionsSetup.scaleColor,
- }
- };
- //刻度值
- series.label = {
- normal: {
- show: true,
- position: 'left',
- distance: 10,
- fontSize: optionsSetup.scaleFontSize,
- color: optionsSetup.scaleDataColor,
- fontWeight: optionsSetup.scaleFontWeight,
- formatter: function (params) {
- if (params.dataIndex % 10 === 0) {
- return params.dataIndex;
- } else if (params.dataIndex == max) {
- return params.dataIndex;
- } else {
- return ""
- }
- }
- }
- };
- },
- // 外框设置
- setOptionsOutBar() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[2];
- series.barWidth = optionsSetup.outBarWidth;
- series.itemStyle = {
- normal: {
- color: optionsSetup.outBarColor,
- barBorderRadius: optionsSetup.outBarRadius,
- }
- };
- series.data = [max];
- },
- // 内框设置
- setOptionsInBar() {
- const optionsSetup = this.optionsSetup;
- const series = this.options.series[1];
- series.barWidth = optionsSetup.inBarWidth;
- series.itemStyle = {
- normal: {
- color: optionsSetup.inBarColor,
- barBorderRadius: optionsSetup.inBarRadius,
- }
- };
- series.data = [max - 1];
- },
- // 渐变色设置
- setOptionsColor(inputValue, inputMax) {
- const optionsSetup = this.optionsSetup;
- let gradient = [];
- if (inputValue > (inputMax * 0.7)) {
- gradient.push(
- {
- offset: 0,
- color: optionsSetup.bar0Color,
- },
- {
- offset: 0.3,
- color: optionsSetup.bar30Color,
- },
- {
- offset: 0.7,
- color: optionsSetup.bar70Color,
- },
- {
- offset: 1,
- color: optionsSetup.bar100Color,
- })
- } else if (inputValue > (inputMax * 0.3)) {
- gradient.push(
- {
- offset: 0,
- color: optionsSetup.bar0Color,
- },
- {
- offset: 0.5,
- color: optionsSetup.bar30Color,
- },
- {
- offset: 1,
- color: optionsSetup.bar70Color,
- })
- } else {
- gradient.push(
- {
- offset: 0,
- color: optionsSetup.bar0Color,
- },
- {
- offset: 1,
- color: optionsSetup.bar30Color,
- })
- }
- return gradient;
- },
- setShowValue(inputValue, inputMax) {
- let showValue = inputValue;
- if (inputValue > inputMax) {
- showValue = inputMax
- } else {
- if (inputValue < 0) {
- showValue = 0
- } else {
- showValue = inputValue
- }
- }
- return showValue;
- },
- // 提示语设置 tooltip
- setOptionsTooltip() {
- const optionsSetup = this.optionsSetup;
- const tooltip = {
- trigger: "item",
- show: true,
- textStyle: {
- color: optionsSetup.lineColor,
- fontSize: optionsSetup.tipFontSize,
- },
- };
- this.options.tooltip = tooltip;
- },
- // 边距设置
- setOptionsMargin() {
- const optionsSetup = this.optionsSetup;
- const grid = {
- left: optionsSetup.marginLeft,
- right: optionsSetup.marginRight,
- bottom: optionsSetup.marginBottom,
- top: optionsSetup.marginTop,
- containLabel: true,
- };
- this.options.grid = grid;
- },
- setOptionsData(e, paramsConfig) {
- const optionsData = this.optionsData; // 数据类型 静态 or 动态
- optionsData.dynamicData = optionsData.dynamicData || {}; // 兼容 dynamicData undefined
- const myDynamicData = optionsData.dynamicData;
- clearInterval(this.flagInter); // 不管咋,先干掉上一次的定时任务,避免多跑
- if (
- e &&
- optionsData.dataType !== "staticData" &&
- Object.keys(myDynamicData.contextData).length
- ) {
- const keyArr = Object.keys(myDynamicData.contextData);
- paramsConfig.forEach((conf) => {
- if (keyArr.includes(conf.targetKey)) {
- myDynamicData.contextData[conf.targetKey] = e[conf.originKey];
- }
- });
- }
- optionsData.dataType == "staticData"
- ? this.staticDataFn(optionsData.staticData)
- : this.dynamicDataFn(optionsData.dynamicData, optionsData.refreshTime);
- },
- // 静态数据
- staticDataFn(val) {
- const optionsSetup = this.optionsSetup;
- const num = val[0]["num"];
- // 渐变色
- const gradient = this.setOptionsColor(num, optionsSetup.maxScale);
- // 数值设定
- const series = this.options.series[0];
- const data = {
- value: this.setShowValue(num, optionsSetup.maxScale),
- label: {
- normal: {
- show: optionsSetup.isShow,
- position: "top",
- distance: optionsSetup.fontDistance,
- width: 10,
- height: 50,
- formatter: '{back| ' + num + ' }',
- rich: {
- back: {
- align: 'center',
- lineHeight: 50,
- fontSize: optionsSetup.fontSize,
- fontWeight: optionsSetup.fontWeight,
- color: gradient[gradient.length - 1].color,
- },
- }
- }
- }
- }
- series.barWidth = optionsSetup.inBarWidth;
- series.itemStyle = {
- normal: {
- color: new echarts.graphic.LinearGradient(0, 1, 0, 0, gradient),
- barBorderRadius: optionsSetup.inBarRadius,
- }
- };
- series.data[0] = data;
- },
- dynamicDataFn(val, refreshTime) {
- if (!val) return;
- if (this.ispreview) {
- this.getEchartData(val);
- this.flagInter = setInterval(() => {
- this.getEchartData(val);
- }, refreshTime);
- } else {
- this.getEchartData(val);
- }
- },
- getEchartData(val) {
- const data = this.queryEchartsData(val);
- data.then((res) => {
- this.renderingFn(res);
- });
- },
- renderingFn(val) {
- const optionsSetup = this.optionsSetup;
- const num = val[0].value;
- // 渐变色
- const gradient = this.setOptionsColor(num, optionsSetup.maxScale);
- // 数值设定
- const series = this.options.series[0];
- const data = {
- value: this.setShowValue(num, optionsSetup.maxScale),
- label: {
- normal: {
- show: optionsSetup.isShow,
- position: "top",
- distance: optionsSetup.fontDistance,
- width: 10,
- height: 50,
- formatter: '{back| ' + num + ' }',
- rich: {
- back: {
- align: 'center',
- lineHeight: 50,
- fontSize: optionsSetup.fontSize,
- fontWeight: optionsSetup.fontWeight,
- color: gradient[gradient.length - 1].color,
- },
- }
- }
- }
- }
- series.barWidth = optionsSetup.inBarWidth;
- series.itemStyle = {
- normal: {
- color: new echarts.graphic.LinearGradient(0, 1, 0, 0, gradient),
- barBorderRadius: optionsSetup.inBarRadius,
- }
- };
- series.data[0] = data;
- },
- },
- };
- </script>
- <style scoped lang="scss">
- .echarts {
- width: 100%;
- height: 100%;
- overflow: hidden;
- }
- </style>
|