Commit 252e0a04 authored by Jenny's avatar Jenny

feat: canvas 画布坐标显示

parent 84475c0a
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="bar-mix-map" id="bar-mix-map"
ref="barMixMapCanvas" ref="barMixMapCanvas"
canvas-id="bar-mix-map-chart" canvas-id="bar-mix-map-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="china-map" id="china-map"
ref="chinaMapCanvas" ref="chinaMapCanvas"
canvas-id="china-map-chart" canvas-id="china-map-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="dashboard-progress" id="dashboard-progress"
ref="dashboardProgressCanvas" ref="dashboardProgressCanvas"
canvas-id="dashboard-progress-chart" canvas-id="dashboard-progress-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="horizontal-bar" id="horizontal-bar"
ref="horizontalBarCanvas" ref="horizontalBarCanvas"
canvas-id="horizontal-bar-chart" canvas-id="horizontal-bar-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="line-mix-bar" id="line-mix-bar"
ref="lineMixBarCanvas" ref="lineMixBarCanvas"
canvas-id="line-mix-bar-chart" canvas-id="line-mix-bar-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="normal-bar" id="normal-bar"
ref="normalbarCanvas" ref="normalbarCanvas"
canvas-id="normal-bar-chart" canvas-id="normal-bar-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="normal-gauge" id="normal-gauge"
ref="normalGaugeCanvas" ref="normalGaugeCanvas"
canvas-id="normal-gauge-chart" canvas-id="normal-gauge-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="normal-line" id="normal-line"
ref="normalLineCanvas" ref="normalLineCanvas"
canvas-id="normal-line-chart" canvas-id="normal-line-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="normal-pie" id="normal-pie"
ref="normalPieCanvas" ref="normalPieCanvas"
canvas-id="normal-pie-chart" canvas-id="normal-pie-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
:inactive-color="elementInfo.option.progress.trailColor" :inactive-color="elementInfo.option.progress.trailColor"
:round="elementInfo.option.progress.strokeLinecap == 'round' ? true : false" :round="elementInfo.option.progress.strokeLinecap == 'round' ? true : false"
:percent="elementInfo.data.dataList.endVal" :percent="elementInfo.data.dataList.endVal"
:show-percent="elementInfo.option.progress.showInfo"> :show-percent="elementInfo.option.progress.showInfo"
>
</u-line-progress> </u-line-progress>
<u-circle-progress <u-circle-progress
class="u-circle" class="u-circle"
...@@ -19,10 +20,11 @@ ...@@ -19,10 +20,11 @@
:active-color="elementInfo.option.progress.strokeColor" :active-color="elementInfo.option.progress.strokeColor"
:inactive-color="elementInfo.option.progress.trailColor" :inactive-color="elementInfo.option.progress.trailColor"
:percent="elementInfo.data.dataList.endVal" :percent="elementInfo.data.dataList.endVal"
:bg-color="00000000"> :bg-color="00000000"
>
<view class="u-progress-text">{{elementInfo.data.dataList.endVal}}%</view> <view class="u-progress-text">{{elementInfo.data.dataList.endVal}}%</view>
</u-circle-progress> </u-circle-progress>
<DashboardProgress v-if="elementInfo.option.progress.type === 'dashboard'" :elementInfo="elementInfo"></DashboardProgress> <DashboardProgress style="height: 100%;" v-if="elementInfo.option.progress.type === 'dashboard'" :elementInfo="elementInfo"></DashboardProgress>
</view> </view>
</template> </template>
...@@ -45,6 +47,7 @@ export default { ...@@ -45,6 +47,7 @@ export default {
<style> <style>
.container { .container {
width: 100%; width: 100%;
height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
justify-content: center; justify-content: center;
......
<template> <template>
<view>
<uni-ec-canvas <uni-ec-canvas
class="uni-ec-canvas" class="uni-ec-canvas"
id="normalra-dar" id="normalra-dar"
ref="normalRadarCanvas" ref="normalRadarCanvas"
canvas-id="normalra-dar-chart" canvas-id="normalra-dar-chart"
:ec="ec" :ec="ec"
:style="[elStyleObject]"
></uni-ec-canvas> ></uni-ec-canvas>
</view>
</template> </template>
<script> <script>
......
...@@ -11,16 +11,6 @@ export default { ...@@ -11,16 +11,6 @@ export default {
required: true required: true
} }
}, },
computed: {
elStyleObject() {
const { windowWidth } = uni.getSystemInfoSync()
const { width, height } = this.elementInfo
return {
'width': `${width > windowWidth ? '100%' : width + 'px'}`,
'height': `${width > windowWidth ? height / width * windowWidth : height}px`
}
}
},
methods: { methods: {
/** /**
* 静态数据 * 静态数据
......
...@@ -3,8 +3,22 @@ ...@@ -3,8 +3,22 @@
class="canvas" class="canvas"
:style="[styleObject]" :style="[styleObject]"
> >
<view v-for="element in reportData" :key="item.id"> <view class="viewport-wrapper" :style="{
<template v-if="!element.hide"> width: `${reportInfo.width * scale}px`,
height: `${reportInfo.height * scale}px`
}">
<template v-for="(element, index) in reportData">
<view
class="view-element"
v-if="!element.hide"
:key="element.id"
:style="{
width: `${element.width * scale}px`,
height: `${element.height * scale}px`,
transform: `translate(${element.left * scale}px, ${element.top * scale}px)`,
zIndex: index + 1
}"
>
<!-- 普通柱状图 --> <!-- 普通柱状图 -->
<NormalBar v-if="element.type == 'NormalBar'" :elementInfo="element"></NormalBar> <NormalBar v-if="element.type == 'NormalBar'" :elementInfo="element"></NormalBar>
<!-- 普通折线图 --> <!-- 普通折线图 -->
...@@ -41,6 +55,7 @@ ...@@ -41,6 +55,7 @@
<RemoteImage v-if="element.type == 'RemoteImage'" :elementInfo="element"></RemoteImage> <RemoteImage v-if="element.type == 'RemoteImage'" :elementInfo="element"></RemoteImage>
<!-- 普通表格 --> <!-- 普通表格 -->
<NormalTable v-if="element.type == 'NormalTable'" :elementInfo="element"></NormalTable> <NormalTable v-if="element.type == 'NormalTable'" :elementInfo="element"></NormalTable>
</view>
</template> </template>
</view> </view>
</view> </view>
...@@ -52,7 +67,7 @@ ...@@ -52,7 +67,7 @@
return { return {
reportInfo: {}, reportInfo: {},
reportData: [], reportData: [],
timer: null timename: null
} }
}, },
computed: { computed: {
...@@ -64,6 +79,11 @@ ...@@ -64,6 +79,11 @@
'background-color': backgroundColor, 'background-color': backgroundColor,
...params ...params
} }
},
scale() {
const { windowWidth } = uni.getSystemInfoSync()
const { width, height } = this.reportInfo
return windowWidth / width
} }
}, },
onLoad() { onLoad() {
...@@ -89,7 +109,7 @@ ...@@ -89,7 +109,7 @@
onUnload() { onUnload() {
// 移除监听事件 // 移除监听事件
uni.$off('handleLinkParams') uni.$off('handleLinkParams')
clearInterval(this.timer) clearInterval(this.timename)
}, },
methods: { methods: {
//检查是否登录 //检查是否登录
...@@ -127,14 +147,14 @@ ...@@ -127,14 +147,14 @@
* 获取页面报表配置 * 获取页面报表配置
*/ */
async getReportList() { async getReportList() {
clearInterval(this.timer) clearInterval(this.timename)
let res = await this.$u.api.getReportList({id: '61cd2ba1c06bffbdae442c4f'}) let res = await this.$u.api.getReportList({id: '61cd2ba1c06bffbdae442c4f'})
const { Status, Result: { info, list } } = res.data const { Status, Result: { info, list } } = res.data
if (Status === 'true') { if (Status === 'true') {
if(info.dataUrl) { if(info.dataUrl) {
this.getGlobalData(info) this.getGlobalData(info)
if(info.dataPollingInterval) { if(info.dataPollingInterval) {
this.timer = setInterval(() => { this.timename = setInterval(() => {
this.getGlobalData(info) this.getGlobalData(info)
}, parseInt(info.dataPollingInterval) * 1000) }, parseInt(info.dataPollingInterval) * 1000)
} }
...@@ -186,11 +206,23 @@ ...@@ -186,11 +206,23 @@
.canvas { .canvas {
position: relative; position: relative;
height: 100%; height: 100%;
padding: 20rpx;
user-select: none; user-select: none;
overflow: auto; overflow: auto;
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: cover; background-size: cover;
background-position: center; background-position: center;
} }
.viewport-wrapper {
position: relative;
}
.view-element {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
will-change: transform;
user-select: none;
cursor: move;
}
</style> </style>
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
.uni-ec-canvas{ .uni-ec-canvas{
width: 100%; width: 100%;
height: 750rpx; height: 100%;
display:block; display:block;
margin: 20rpx auto;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment