@shijiu/jsview-vue-samples 2.1.367-test.0 → 2.1.428
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CoupletsTest/App.vue +37 -52
- package/CoupletsTest/widget/Fireworks/Fireworks.vue +173 -45
- package/DemoHomepage/router.js +19 -3
- package/FlexCellDemo/App.vue +315 -0
- package/FlexCellDemo/images/1.png +0 -0
- package/FlexCellDemo/images/2.png +0 -0
- package/FlexCellDemo/images/3.png +0 -0
- package/FlexCellDemo/images/4.jpg +0 -0
- package/FlexCellDemo/images/5.png +0 -0
- package/GradientTexture/App.vue +135 -0
- package/ImpactStop/App.vue +1 -1
- package/LongText/LongTextScroll.vue +3 -7
- package/QrcodeDemo/App.vue +37 -9
- package/SceneTransition/App.vue +177 -0
- package/SceneTransition/JsvSceneTransition.vue +181 -0
- package/SceneTransition/images/fly1.jpg +0 -0
- package/SceneTransition/images/fly2.jpg +0 -0
- package/SceneTransition/images/mask/1.png +0 -0
- package/SceneTransition/images/mask/10.png +0 -0
- package/SceneTransition/images/mask/11.png +0 -0
- package/SceneTransition/images/mask/12.png +0 -0
- package/SceneTransition/images/mask/2.png +0 -0
- package/SceneTransition/images/mask/3.png +0 -0
- package/SceneTransition/images/mask/4.png +0 -0
- package/SceneTransition/images/mask/5.png +0 -0
- package/SceneTransition/images/mask/6.png +0 -0
- package/SceneTransition/images/mask/7.png +0 -0
- package/SceneTransition/images/mask/8.png +0 -0
- package/SceneTransition/images/mask/9.png +0 -0
- package/SceneTransition/images/mask-025/config.json +29 -0
- package/SceneTransition/images/mask-025/res/1.png +0 -0
- package/SceneTransition/images/mask-025/res/2.png +0 -0
- package/SceneTransition/images/mask-025/res/3.png +0 -0
- package/SceneTransition/images/mask-025/res/4.png +0 -0
- package/SceneTransition/images/mask-025/res/icon.png +0 -0
- package/SceneTransition/images/mask-025/res/stroke.png +0 -0
- package/SceneTransition/images/sample.png +0 -0
- package/SecTorTest/App.vue +145 -23
- package/SwiperTest/App.vue +4 -4
- package/TouchWidget/App.vue +95 -0
- package/TouchWidget/Item.vue +64 -0
- package/TouchWidget/WidgetItem.vue +96 -0
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<JsvPreload :preloadList="preload_info"></JsvPreload>
|
|
3
|
+
<jsv-focus-block autoFocus :onKeyDown="onKeyDown">
|
|
4
|
+
<div :style="{ width: 1280, height: 720, backgroundImage: bg }">
|
|
5
|
+
<JsvSceneTransition
|
|
6
|
+
v-show="isShow"
|
|
7
|
+
:imageUrl="fly1"
|
|
8
|
+
:ArraySet="ArraySet"
|
|
9
|
+
:displayWidth="1280"
|
|
10
|
+
:style="style"
|
|
11
|
+
:onOff="onOff"
|
|
12
|
+
></JsvSceneTransition>
|
|
13
|
+
<!-- 文字说明 -->
|
|
14
|
+
<div class="text">{{ '操作说明:按【OK】键进行碎片过渡效果。' }}</div>
|
|
15
|
+
</div>
|
|
16
|
+
</jsv-focus-block>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup>
|
|
20
|
+
import { shallowRef } from "vue";
|
|
21
|
+
import { JsvPreload, buildPreloadInfo,JsvSceneTransition } from "jsview";
|
|
22
|
+
import fly1 from "./images/fly1.jpg";
|
|
23
|
+
import fly2 from "./images/fly2.jpg";
|
|
24
|
+
//P1格式,12张
|
|
25
|
+
import png1 from "./images/mask/1.png";
|
|
26
|
+
import png2 from "./images/mask/2.png";
|
|
27
|
+
import png3 from "./images/mask/3.png";
|
|
28
|
+
import png4 from "./images/mask/4.png";
|
|
29
|
+
import png5 from "./images/mask/5.png";
|
|
30
|
+
import png6 from "./images/mask/6.png";
|
|
31
|
+
import png7 from "./images/mask/7.png";
|
|
32
|
+
import png8 from "./images/mask/8.png";
|
|
33
|
+
import png9 from "./images/mask/9.png";
|
|
34
|
+
import png10 from "./images/mask/10.png";
|
|
35
|
+
import png11 from "./images/mask/11.png";
|
|
36
|
+
import png12 from "./images/mask/12.png";
|
|
37
|
+
//预加载
|
|
38
|
+
const preload_info = [
|
|
39
|
+
buildPreloadInfo(png1),
|
|
40
|
+
buildPreloadInfo(png2),
|
|
41
|
+
buildPreloadInfo(png3),
|
|
42
|
+
buildPreloadInfo(png4),
|
|
43
|
+
buildPreloadInfo(png5),
|
|
44
|
+
buildPreloadInfo(png6),
|
|
45
|
+
buildPreloadInfo(png7),
|
|
46
|
+
buildPreloadInfo(png8),
|
|
47
|
+
buildPreloadInfo(png9),
|
|
48
|
+
buildPreloadInfo(png10),
|
|
49
|
+
buildPreloadInfo(png11),
|
|
50
|
+
buildPreloadInfo(png12),
|
|
51
|
+
buildPreloadInfo(fly1),
|
|
52
|
+
buildPreloadInfo(fly2),
|
|
53
|
+
];
|
|
54
|
+
const style = { width: 1280, height: 720 };
|
|
55
|
+
let isShow = shallowRef(false);
|
|
56
|
+
let bg = shallowRef(fly1);
|
|
57
|
+
let onOff = shallowRef(false);
|
|
58
|
+
|
|
59
|
+
//12个FreeMove引用
|
|
60
|
+
const refArray = [];
|
|
61
|
+
for (let i = 0; i < 12; i++) {
|
|
62
|
+
refArray.push(shallowRef(null));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const ArraySet = [
|
|
66
|
+
{
|
|
67
|
+
left: 0,
|
|
68
|
+
top: 0,
|
|
69
|
+
width: 521,
|
|
70
|
+
height: 302,
|
|
71
|
+
url: png1,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
left: 301,
|
|
75
|
+
top: 0,
|
|
76
|
+
width: 590,
|
|
77
|
+
height: 266,
|
|
78
|
+
url: png2,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
left: 693,
|
|
82
|
+
top: 0,
|
|
83
|
+
width: 587,
|
|
84
|
+
height: 306,
|
|
85
|
+
url: png3,
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
left: 0,
|
|
89
|
+
top: 140,
|
|
90
|
+
width: 561,
|
|
91
|
+
height: 431,
|
|
92
|
+
url: png4,
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
left: 482,
|
|
96
|
+
top: 140,
|
|
97
|
+
width: 409,
|
|
98
|
+
height: 377,
|
|
99
|
+
url: png5,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
left: 717,
|
|
103
|
+
top: 247,
|
|
104
|
+
width: 563,
|
|
105
|
+
height: 247,
|
|
106
|
+
url: png6,
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
left: 0,
|
|
110
|
+
top: 385,
|
|
111
|
+
width: 533,
|
|
112
|
+
height: 335,
|
|
113
|
+
url: png7,
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
left: 333,
|
|
117
|
+
top: 392,
|
|
118
|
+
width: 293,
|
|
119
|
+
height: 328,
|
|
120
|
+
url: png8,
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
left: 569,
|
|
124
|
+
top: 452,
|
|
125
|
+
width: 213,
|
|
126
|
+
height: 268,
|
|
127
|
+
url: png9,
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
left: 714,
|
|
131
|
+
top: 405,
|
|
132
|
+
width: 332,
|
|
133
|
+
height: 315,
|
|
134
|
+
url: png10,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
left: 810,
|
|
138
|
+
top: 387,
|
|
139
|
+
width: 172,
|
|
140
|
+
height: 117,
|
|
141
|
+
url: png11,
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
left: 893,
|
|
145
|
+
top: 428,
|
|
146
|
+
width: 387,
|
|
147
|
+
height: 292,
|
|
148
|
+
url: png12,
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
const onKeyDown = (ev) => {
|
|
153
|
+
switch (ev.keyCode) {
|
|
154
|
+
case 13:
|
|
155
|
+
bg.value = fly2;
|
|
156
|
+
onOff.value = true;
|
|
157
|
+
isShow.value = true;
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
default:
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<style scoped>
|
|
167
|
+
.text{
|
|
168
|
+
width:300;
|
|
169
|
+
height:60;
|
|
170
|
+
color:#FFFFFF;
|
|
171
|
+
font-weight: bold;
|
|
172
|
+
line-height: 26;
|
|
173
|
+
font-size: 24;
|
|
174
|
+
left:20;
|
|
175
|
+
top:20;
|
|
176
|
+
}
|
|
177
|
+
</style>
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* 【模块 export 内容】
|
|
3
|
+
* JsvSceneTransition:场景过渡组件。
|
|
4
|
+
* props说明:
|
|
5
|
+
* imageUrl {String} (必填) 显示图片的加载地址
|
|
6
|
+
* displayWidth {Number} (必填) 想要展示的宽度
|
|
7
|
+
* ArraySet {Array} (必填) 模板配置项,包括:每个模块的width,height,left,top,url
|
|
8
|
+
* style {Object} (必填) 横纵模板总长度和总宽度。(width,height)
|
|
9
|
+
* onOff {Boolean} (必填) 组件挂载好后是否立即动画的开关,后续可通过改值为true开启。
|
|
10
|
+
-->
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<div
|
|
14
|
+
:style="{
|
|
15
|
+
width: 1280,
|
|
16
|
+
height: 720,
|
|
17
|
+
transform: `scale3d(${props.displayWidth / 1280},${
|
|
18
|
+
props.displayWidth / 1280
|
|
19
|
+
},1)`,
|
|
20
|
+
transformOrigin: 'left top',
|
|
21
|
+
}"
|
|
22
|
+
>
|
|
23
|
+
<jsv-free-move-actor
|
|
24
|
+
v-for="(item, index) in props.ArraySet"
|
|
25
|
+
:ref="(el) => (refArray[index] = el)"
|
|
26
|
+
:top="item.top"
|
|
27
|
+
:left="item.left"
|
|
28
|
+
:width="item.width"
|
|
29
|
+
:height="item.height"
|
|
30
|
+
>
|
|
31
|
+
<jsv-mask-clip-div
|
|
32
|
+
:style="{
|
|
33
|
+
top: 0,
|
|
34
|
+
left: 0,
|
|
35
|
+
width: item.width,
|
|
36
|
+
height: item.height,
|
|
37
|
+
}"
|
|
38
|
+
:viewSrc="props.imageUrl"
|
|
39
|
+
:maskSrc="item.url"
|
|
40
|
+
:maskLeft="item.left / props.style.width"
|
|
41
|
+
:maskTop="item.top / props.style.height"
|
|
42
|
+
:maskWidth="item.width / props.style.width"
|
|
43
|
+
:maskHeight="item.height / props.style.height"
|
|
44
|
+
/>
|
|
45
|
+
</jsv-free-move-actor>
|
|
46
|
+
</div>
|
|
47
|
+
</template>
|
|
48
|
+
|
|
49
|
+
<script setup>
|
|
50
|
+
import { JsvMaskClipDiv, JsvFreeMoveActor } from "jsview";
|
|
51
|
+
import { onMounted, onBeforeUnmount, watch, shallowRef } from "vue";
|
|
52
|
+
|
|
53
|
+
const props = defineProps({
|
|
54
|
+
imageUrl: { type: String, require: true },
|
|
55
|
+
displayWidth: { type: Number, require: true },
|
|
56
|
+
ArraySet: { type: Array, require: true },
|
|
57
|
+
style: { type: Object, require: true },
|
|
58
|
+
onOff: { type: Boolean, require: true },
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
//12个FreeMove引用
|
|
62
|
+
const refArray = [];
|
|
63
|
+
const controlArray = new Array(props.ArraySet.length).fill(null);
|
|
64
|
+
const timer = { id: -1 };
|
|
65
|
+
|
|
66
|
+
watch(
|
|
67
|
+
() => props.onOff,
|
|
68
|
+
(n, o) => {
|
|
69
|
+
if (n == true) {
|
|
70
|
+
MoveFunc();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
//运动函数
|
|
76
|
+
const MoveFunc = () => {
|
|
77
|
+
controlArray[0].run([
|
|
78
|
+
controlArray[0].action().setSpdAndAccel(-6, -9, 0, 1, null, null),
|
|
79
|
+
controlArray[0]
|
|
80
|
+
.condition()
|
|
81
|
+
.reachPosition(undefined, 720)
|
|
82
|
+
.then([controlArray[0].action().stopMoving()]),
|
|
83
|
+
]);
|
|
84
|
+
|
|
85
|
+
controlArray[1].run([
|
|
86
|
+
controlArray[1].action().setSpdAndAccel(0, -5, 0, 1, null, null),
|
|
87
|
+
controlArray[1]
|
|
88
|
+
.condition()
|
|
89
|
+
.reachPosition(undefined, 720)
|
|
90
|
+
.then([controlArray[1].action().stopMoving()]),
|
|
91
|
+
]);
|
|
92
|
+
controlArray[2].run([
|
|
93
|
+
controlArray[2].action().setSpdAndAccel(6, -9, 0, 1, null, null),
|
|
94
|
+
controlArray[2]
|
|
95
|
+
.condition()
|
|
96
|
+
.reachPosition(undefined, 720)
|
|
97
|
+
.then([controlArray[2].action().stopMoving()]),
|
|
98
|
+
]);
|
|
99
|
+
controlArray[3].run([
|
|
100
|
+
controlArray[3].action().setSpdAndAccel(-6, -7, 0, 1, null, null),
|
|
101
|
+
controlArray[3]
|
|
102
|
+
.condition()
|
|
103
|
+
.reachPosition(undefined, 720)
|
|
104
|
+
.then([controlArray[3].action().stopMoving()]),
|
|
105
|
+
]);
|
|
106
|
+
controlArray[4].run([
|
|
107
|
+
controlArray[4].action().setSpdAndAccel(0, -8, 0, 1, null, null),
|
|
108
|
+
controlArray[4]
|
|
109
|
+
.condition()
|
|
110
|
+
.reachPosition(undefined, 720)
|
|
111
|
+
.then([controlArray[4].action().stopMoving()]),
|
|
112
|
+
]);
|
|
113
|
+
controlArray[5].run([
|
|
114
|
+
controlArray[5].action().setSpdAndAccel(6, -7, 0, 1, null, null),
|
|
115
|
+
controlArray[5]
|
|
116
|
+
.condition()
|
|
117
|
+
.reachPosition(undefined, 720)
|
|
118
|
+
.then([controlArray[5].action().stopMoving()]),
|
|
119
|
+
]);
|
|
120
|
+
controlArray[6].run([
|
|
121
|
+
controlArray[6].action().setSpdAndAccel(-6, -4, 0, 1, null, null),
|
|
122
|
+
controlArray[6]
|
|
123
|
+
.condition()
|
|
124
|
+
.reachPosition(undefined, 720)
|
|
125
|
+
.then([controlArray[6].action().stopMoving()]),
|
|
126
|
+
]);
|
|
127
|
+
controlArray[7].run([
|
|
128
|
+
controlArray[7].action().setSpdAndAccel(0, -8, 0, 1, null, null),
|
|
129
|
+
controlArray[7]
|
|
130
|
+
.condition()
|
|
131
|
+
.reachPosition(undefined, 720)
|
|
132
|
+
.then([controlArray[7].action().stopMoving()]),
|
|
133
|
+
]);
|
|
134
|
+
controlArray[8].run([
|
|
135
|
+
controlArray[8].action().setSpdAndAccel(2, -7, 0, 1, null, null),
|
|
136
|
+
controlArray[8]
|
|
137
|
+
.condition()
|
|
138
|
+
.reachPosition(undefined, 720)
|
|
139
|
+
.then([controlArray[8].action().stopMoving()]),
|
|
140
|
+
]);
|
|
141
|
+
controlArray[9].run([
|
|
142
|
+
controlArray[9].action().setSpdAndAccel(6, -7, 0, 1, null, null),
|
|
143
|
+
controlArray[9]
|
|
144
|
+
.condition()
|
|
145
|
+
.reachPosition(undefined, 720)
|
|
146
|
+
.then([controlArray[9].action().stopMoving()]),
|
|
147
|
+
]);
|
|
148
|
+
controlArray[10].run([
|
|
149
|
+
controlArray[10].action().setSpdAndAccel(4, -4, 0, 1, null, null),
|
|
150
|
+
controlArray[10]
|
|
151
|
+
.condition()
|
|
152
|
+
.reachPosition(undefined, 720)
|
|
153
|
+
.then([controlArray[10].action().stopMoving()]),
|
|
154
|
+
]);
|
|
155
|
+
controlArray[11].run([
|
|
156
|
+
controlArray[11].action().setSpdAndAccel(6, -4, 0, 1, null, null),
|
|
157
|
+
controlArray[11]
|
|
158
|
+
.condition()
|
|
159
|
+
.reachPosition(undefined, 720)
|
|
160
|
+
.then([controlArray[11].action().stopMoving()]),
|
|
161
|
+
]);
|
|
162
|
+
};
|
|
163
|
+
onMounted(() => {
|
|
164
|
+
for (let i = 0; i < refArray.length; i++) {
|
|
165
|
+
controlArray[i] = refArray[i].control;
|
|
166
|
+
}
|
|
167
|
+
if (props.onOff == true) {
|
|
168
|
+
// timer.id = setTimeout(() => {
|
|
169
|
+
MoveFunc();
|
|
170
|
+
// }, 1000);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
onBeforeUnmount(() => {
|
|
174
|
+
if (timer.id !== -1) {
|
|
175
|
+
clearTimeout(timer.id);
|
|
176
|
+
timer.id = -1;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
</script>
|
|
180
|
+
|
|
181
|
+
<style scoped></style>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"style": "Irregular",
|
|
3
|
+
"type":"Regular",
|
|
4
|
+
"age": [3, 4],
|
|
5
|
+
"level": 1,
|
|
6
|
+
"grade": "Easy",
|
|
7
|
+
"components": [
|
|
8
|
+
{
|
|
9
|
+
"key": "1",
|
|
10
|
+
"x": 0,
|
|
11
|
+
"y": 0
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"key": "2",
|
|
15
|
+
"x": 227,
|
|
16
|
+
"y": 0
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"key": "3",
|
|
20
|
+
"x": 0,
|
|
21
|
+
"y": 327
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"key": "4",
|
|
25
|
+
"x": 327,
|
|
26
|
+
"y": 227
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/SecTorTest/App.vue
CHANGED
|
@@ -5,30 +5,33 @@
|
|
|
5
5
|
:centerPosition="center"
|
|
6
6
|
:radius="360"
|
|
7
7
|
:data="data"
|
|
8
|
+
:animationTime="0.5"
|
|
8
9
|
></JsvPieChart>
|
|
9
10
|
<!-- 文字说明 -->
|
|
10
11
|
<div class="text">
|
|
11
12
|
{{
|
|
12
|
-
"图为圆心在(400,400)位置,半径为360
|
|
13
|
+
"图为圆心在(400,400)位置,半径为360的饼图。此样例限制最多六个扇形。"
|
|
13
14
|
}}
|
|
14
15
|
</div>
|
|
15
16
|
<!-- 操作说明 -->
|
|
16
17
|
<div class="text1">
|
|
17
|
-
{{
|
|
18
|
+
{{
|
|
19
|
+
"按【上】键随机板块增加百分比,按【下】键随机减小板块百分比,按【左】键删除项,按【右】键增加项"
|
|
20
|
+
}}
|
|
18
21
|
</div>
|
|
19
22
|
</div>
|
|
20
23
|
</jsv-focus-block>
|
|
21
24
|
</template>
|
|
22
25
|
|
|
23
26
|
<script setup>
|
|
24
|
-
import { reactive } from "vue";
|
|
27
|
+
import { reactive, shallowRef } from "vue";
|
|
25
28
|
import { JsvPieChart } from "jsview";
|
|
26
29
|
const center = {
|
|
27
30
|
x: 400,
|
|
28
31
|
y: 400,
|
|
29
32
|
};
|
|
30
33
|
|
|
31
|
-
let data =
|
|
34
|
+
let data = shallowRef([
|
|
32
35
|
{
|
|
33
36
|
percent: 23.33,
|
|
34
37
|
color: "#0000FF",
|
|
@@ -50,28 +53,147 @@ let data = reactive([
|
|
|
50
53
|
color: "#6EFFE1",
|
|
51
54
|
},
|
|
52
55
|
]);
|
|
53
|
-
|
|
56
|
+
let TempData = reactive([]);
|
|
57
|
+
for (let i = 0; i < data.value.length; i++) {
|
|
58
|
+
TempData.push({
|
|
59
|
+
percent: data.value[i].percent,
|
|
60
|
+
color: data.value[i].color,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
54
63
|
// 生成随机整数
|
|
55
64
|
const randomNumber = () => {
|
|
56
|
-
const randomInt = Math.floor(Math.random() *
|
|
65
|
+
const randomInt = Math.floor(Math.random() * data.value.length) + 1;
|
|
57
66
|
return randomInt;
|
|
58
67
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
//随机颜色函数
|
|
69
|
+
const randomColor = () => {
|
|
70
|
+
let randomColor = Math.round(Math.random() * 2 ** 24).toString(16);
|
|
71
|
+
return (
|
|
72
|
+
"#" + new Array(6 - randomColor.length).fill("0").join("") + randomColor
|
|
73
|
+
);
|
|
74
|
+
};
|
|
75
|
+
//找出最大的百分比
|
|
76
|
+
const findMaxPercentItem = (data) => {
|
|
77
|
+
let maxPercent = 0;
|
|
78
|
+
let maxItem = null;
|
|
79
|
+
|
|
80
|
+
for (let i = 0; i < data.length; i++) {
|
|
81
|
+
if (data[i].percent > maxPercent) {
|
|
82
|
+
maxPercent = data[i].percent;
|
|
83
|
+
maxItem = data[i];
|
|
73
84
|
}
|
|
74
|
-
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return maxItem;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const onKeyDown = (ev) => {
|
|
91
|
+
switch (ev.keyCode) {
|
|
92
|
+
//删除项
|
|
93
|
+
case 37:
|
|
94
|
+
if (data.value.length >= 2) {
|
|
95
|
+
const tempPercent = TempData[TempData.length - 1].percent;
|
|
96
|
+
TempData.pop();
|
|
97
|
+
TempData[TempData.length - 1].percent += tempPercent;
|
|
98
|
+
data.value = TempData;
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case 38:
|
|
102
|
+
//最后一项随机增加
|
|
103
|
+
const random = randomNumber();
|
|
104
|
+
TempData[TempData.length - 1].percent += random;
|
|
105
|
+
if (TempData[TempData.length - 1].percent > 100) {
|
|
106
|
+
TempData[TempData.length - 1].percent = 100;
|
|
107
|
+
for (let i = 0; i < TempData.length - 1; i++) {
|
|
108
|
+
TempData[i].percent = 0;
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
for (let i = 0; i < TempData.length - 1; i++) {
|
|
112
|
+
TempData[i].percent -= random / (TempData.length - 1);
|
|
113
|
+
if (TempData[i].percent < 0) {
|
|
114
|
+
let tempPercent = TempData[i].percent;
|
|
115
|
+
TempData[i].percent = 0;
|
|
116
|
+
let maxItem = findMaxPercentItem(TempData);
|
|
117
|
+
maxItem.percent += tempPercent;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
data.value = TempData;
|
|
122
|
+
break;
|
|
123
|
+
case 39:
|
|
124
|
+
//增加项
|
|
125
|
+
if (data.value.length >= 1 && data.value.length <= 5) {
|
|
126
|
+
TempData.push({
|
|
127
|
+
percent: 10,
|
|
128
|
+
color: randomColor(),
|
|
129
|
+
});
|
|
130
|
+
let maxItem = findMaxPercentItem(TempData);
|
|
131
|
+
maxItem.percent -= 10;
|
|
132
|
+
data.value = TempData;
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
case 40:
|
|
136
|
+
// 随机减;
|
|
137
|
+
if (data.value[data.value.length - 1].percent == 0) {
|
|
138
|
+
// 随机减少百分比
|
|
139
|
+
let randomDecrement = randomNumber();
|
|
140
|
+
let adjusted = false;
|
|
141
|
+
|
|
142
|
+
for (let i = TempData.length - 1; i >= 0; i--) {
|
|
143
|
+
if (TempData[i].percent > 0) {
|
|
144
|
+
if (TempData[i].percent >= randomDecrement) {
|
|
145
|
+
TempData[i].percent -= randomDecrement;
|
|
146
|
+
adjusted = true;
|
|
147
|
+
break; // 成功减少,结束循环
|
|
148
|
+
} else {
|
|
149
|
+
// 如果当前项百分比不足以减去randomDecrement,则全部减去并尝试从前一个元素继续减少
|
|
150
|
+
randomDecrement -= TempData[i].percent;
|
|
151
|
+
TempData[i].percent = 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (!adjusted) {
|
|
157
|
+
// 如果没有成功减少(所有项都为0或randomDecrement大于所有项的总和),可以选择忽略剩余的randomDecrement
|
|
158
|
+
// 或者根据需求进行特殊处理
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// 确保总和为100%
|
|
162
|
+
let totalPercent = TempData.reduce(
|
|
163
|
+
(total, item) => total + item.percent,
|
|
164
|
+
0
|
|
165
|
+
);
|
|
166
|
+
let diff = 100 - totalPercent; // 计算差异
|
|
167
|
+
|
|
168
|
+
if (diff !== 0) {
|
|
169
|
+
// 如果总和不为100%,则尝试平衡,优先从前往后增加
|
|
170
|
+
for (let i = 0; i < TempData.length && diff !== 0; i++) {
|
|
171
|
+
let availableIncrease = 100 - TempData[i].percent; // 计算当前项可增加的最大值
|
|
172
|
+
let increment = Math.min(diff, availableIncrease); // 确定实际增加的值
|
|
173
|
+
TempData[i].percent += increment;
|
|
174
|
+
diff -= increment; // 更新剩余差异
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
const random = randomNumber();
|
|
179
|
+
if (TempData[TempData.length - 1].percent - random < 0) {
|
|
180
|
+
const shouldNumber = TempData[TempData.length - 1].percent;
|
|
181
|
+
TempData[TempData.length - 1].percent = 0;
|
|
182
|
+
for (let i = 0; i < TempData.length - 2; i++) {
|
|
183
|
+
TempData[i].percent += shouldNumber / (TempData.length - 2);
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
TempData[TempData.length - 1].percent -= random;
|
|
187
|
+
for (let i = 0; i < TempData.length - 1; i++) {
|
|
188
|
+
TempData[i].percent += random / (TempData.length - 1);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
data.value = TempData;
|
|
193
|
+
break;
|
|
194
|
+
|
|
195
|
+
default:
|
|
196
|
+
break;
|
|
75
197
|
}
|
|
76
198
|
};
|
|
77
199
|
let actionDefines = {
|
|
@@ -86,7 +208,7 @@ let actionDefines = {
|
|
|
86
208
|
background-color: #007788;
|
|
87
209
|
}
|
|
88
210
|
.text {
|
|
89
|
-
width:
|
|
211
|
+
width: 500;
|
|
90
212
|
height: 60;
|
|
91
213
|
left: 700;
|
|
92
214
|
top: 300;
|
|
@@ -96,7 +218,7 @@ let actionDefines = {
|
|
|
96
218
|
}
|
|
97
219
|
.text1 {
|
|
98
220
|
width: 500;
|
|
99
|
-
height:
|
|
221
|
+
height: 90;
|
|
100
222
|
left: 700;
|
|
101
223
|
top: 440;
|
|
102
224
|
background-color: rgba(255, 255, 255, 0.5);
|
package/SwiperTest/App.vue
CHANGED
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
:onClick="onClick"
|
|
14
14
|
:onChange="onChange"
|
|
15
15
|
>
|
|
16
|
-
<template #itemView="{
|
|
16
|
+
<template #itemView="{ propsItem,defineSize,dataIndex }">
|
|
17
17
|
<div
|
|
18
18
|
:style="{
|
|
19
|
-
width:
|
|
20
|
-
height:
|
|
21
|
-
backgroundImage:
|
|
19
|
+
width: defineSize.width,
|
|
20
|
+
height: defineSize.height,
|
|
21
|
+
backgroundImage: items[dataIndex].image,
|
|
22
22
|
fontSize: 40,
|
|
23
23
|
}"
|
|
24
24
|
></div>
|