circlepic.vue
8.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<template>
<view class="content">
<view class='toppic'>
<image src="../../static/toppic.png" mode=""></image>
<view class="topinfo flexone">
<view class="topinfoimg">
<image :src="avatar" mode=""></image>
</view>
<view class="peoplename">{{nickname}}</view>
</view>
</view>
<view class="circlebox">
<view class="nav flextwo">
<view class="navitem" :class="sel==1?'navactive':''" @click="selitem" :data-id="1">本周</view>
<view class="navitem" :class="sel==2?'navactive':''" @click="selitem" :data-id="2">本月</view>
<view class="navitem" :class="sel==3?'navactive':''" @click="selitem" :data-id="3">三个月</view>
<view class="navitem" :class="sel==4?'navactive':''" @click="selitem" :data-id="4">半年</view>
<view class="navitem" :class="sel==5?'navactive':''" @click="selitem" :data-id="5">一年</view>
</view>
<view class="qiun-columns">
<view class="qiun-charts">
<!--#ifdef MP-ALIPAY -->
<canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" :width="cWidth*pixelRatio" :height="cHeight*pixelRatio"
:style="{'width':cWidth+'px','height':cHeight+'px'}" disable-scroll=true @touchstart="touchLineA" @touchmove="moveLineA"
@touchend="touchEndLineA"></canvas>
<!--#endif-->
<!--#ifndef MP-ALIPAY -->
<canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" disable-scroll=true @touchstart="touchLineA"
@touchmove="moveLineA" @touchend="touchEndLineA"></canvas>
<!--#endif-->
</view>
<!--#ifdef H5 -->
<button class="qiun-button" @tap="changeData()">更新图表</button>
<!--#endif-->
</view>
<!--
<view class="atten flex">
<view class='attenleft'>注:</view>
<view class='attenright'>黄色代表完成事件打分,蓝色代表情绪状态打分。
x轴代表分数,y轴代表时间。</view>
</view>
-->
</view>
</view>
</template>
<script>
import app from "../../App.vue";
import uCharts from '@/components/u-charts/u-charts.js';
import {
isJSON
} from '@/common/checker.js';
var _self;
var canvaLineA = null;
export default {
data() {
return {
cWidth: '',
cHeight: '',
pixelRatio: 1,
textarea: '',
sel: 1,
userName: '',
avatarUrl: '',
courseid: '',
max:'',
min:'',
number:'',
avatar:'',
nickname:''
}
},
onLoad(options) {
this.courseid = options.id
_self = this;
//#ifdef MP-ALIPAY
uni.getSystemInfo({
success: function(res) {
if (res.pixelRatio > 1) {
//正常这里给2就行,如果pixelRatio=3性能会降低一点
//_self.pixelRatio =res.pixelRatio;
_self.pixelRatio = 2;
}
}
});
//#endif
this.cWidth = uni.upx2px(750);
this.cHeight = uni.upx2px(500);
this.getServerData();
},
methods: {
selitem(e) {
this.sel = e.currentTarget.dataset.id;
this.getServerData()
},
getServerData() {
let that = this;
var url = '/api/clock/score';
var params = {
course_id: that.courseid,
type: that.sel
}
app.post(url, params).then((res) => {
console.log(res);
this.avatar=res.avatar;
this.nickname=res.nickname;
let LineA = {
categories: [],
series: []
};
var data=[];
res.data.forEach(function(value,index,array){
data.push(value)
})
var time=
// ["2020-03-23", "2020-03-24","2020-03-25","2020-03-26","2020-03-27","2020-03-28"]
// var datak=[{name: "完成事件打分", data: [6,8,9]},{name: "情绪状态打分", data: [4,5,6]},{name: "优异度", data: [1,310]}];
that.max=Number(res.max)+2;
that.min=Number(res.min)-2;
console.log(that.max);
console.log(that.min)
that.number=(Number(that.max)-Number(that.min))/2;
LineA.categories=res.time;
// LineA.categories=time;
LineA.series = res.data;
console.log(LineA);
_self.textarea = JSON.stringify(LineA);
_self.showLineA("canvasLineA", LineA);
}).catch((err) => {
})
},
// getServerData() {
// uni.request({
// url: 'https://www.ucharts.cn/data.json',
// data: {},
// success: function(res) {
// console.log(res.data)
// console.log(res.data.data)
// let LineA = {
// categories: [],
// series: []
// };
// //这里我后台返回的是数组,所以用等于,如果您后台返回的是单条数据,需要push进去
// console.log(res.data.data.LineA)
// LineA.categories = res.data.data.LineA.categories;
// LineA.series = res.data.data.LineA.series;
// console.log('87765',LineA)
// _self.textarea = JSON.stringify(res.data.data.LineA);
// _self.showLineA("canvasLineA", LineA);
// },
// fail: () => {
// _self.tips = "网络错误,小程序端请检查合法域名";
// },
// });
// },
showLineA(canvasId, chartData) {
canvaLineA = new uCharts({
$this: _self,
canvasId: canvasId,
type: 'line',
fontSize: 11,
padding: [15, 15, 0, 15],
legend: {
show: true,
padding: 5,
lineHeight: 11,
margin: 5,
},
dataLabel: true,
dataPointShape: true,
dataPointShapeType: 'hollow',
background: '#FFFFFF',
pixelRatio: _self.pixelRatio,
categories: chartData.categories,
series: chartData.series,
animation: true,
enableScroll: true, //开启图表拖拽功能
xAxis: {
disableGrid: false,
type: 'grid',
gridType: 'dash',
itemCount: 4,
scrollShow: true,
scrollAlign: 'left'
},
yAxis: {
//disabled:true
gridType: 'dash',
splitNumber: this.number,
min: this.min,
max: this.max,
// splitNumber: 8,
// min: 0,
// max: 180,
format: (val) => {
return val.toFixed(0)
} //如不写此方法,Y轴刻度默认保留两位小数
},
width: _self.cWidth * _self.pixelRatio,
height: _self.cHeight * _self.pixelRatio,
extra: {
line: {
type: 'straight'
}
},
});
},
touchLineA(e) {
canvaLineA.scrollStart(e);
},
moveLineA(e) {
console.log(e)
canvaLineA.scroll(e);
},
touchEndLineA(e) {
canvaLineA.scrollEnd(e);
//下面是toolTip事件,如果滚动后不需要显示,可不填写
canvaLineA.touchLegend(e);
canvaLineA.showToolTip(e, {
format: function(item, category) {
return category + ' ' + item.name + ':' + item.data
}
});
},
changeData() {
if (isJSON(_self.textarea)) {
let newdata = JSON.parse(_self.textarea);
canvaLineA.updateData({
series: newdata.series,
categories: newdata.categories,
scrollPosition: 'right',
animation: false
});
} else {
uni.showToast({
title: '数据格式错误',
image: '../../../static/images/alert-warning.png'
})
}
}
},
onshow() {
this.userName = uni.getStorageSync('nickName');
this.avatarUrl = uni.getStorageSync('avatarUrl');
}
}
</script>
<style lang="scss">
page {
background: #f9f9f9;
}
.qiun-columns{
width:750rpx;
}
.atten {
color: #8C9198;
font-size: 24upx;
padding: 32upx 28upx;
}
.nav {
height: 84upx;
width: 100%;
}
.navitem {
width: 138upx;
text-align: center;
color: #06121E;
font-size: 28upx;
font-weight: bold;
}
.navactive {
position: relative;
color: #EE8B27
}
.navactive:after {
display: block;
content: '';
width: 138upx;
height: 1upx;
background: red;
// position: absolute;
// bottom:0upx;
// left:50%;
// transform: translateX(-50%);
}
.circlebox {
width: 686upx;
margin: 32upx auto 0;
background: #fff;
}
.topinfo {
position: absolute;
top: 44upx;
left: 50upx;
}
.topinfoimg {
width: 120upx;
height: 120upx;
font-size: 0;
border-radius: 50%;
}
.topinfoimg image{
border-radius: 50%;
}
.peoplename {
color: #fff;
font-size: 32upx;
margin-left: 46upx;
}
.toppic {
width: 686rpx;
height: 218rpx;
font-size: 0;
margin: 32upx auto 0;
position: relative;
}
/*样式的width和height一定要与定义的cWidth和cHeight相对应*/
.qiun-charts {
width: 100%;
height: 500upx;
background-color: #FFFFFF;
}
.charts {
width: 100%;
height: 500upx;
background-color: #FFFFFF;
}
</style>