@shijiu/jsview-vue-samples 2.1.200 → 2.1.339-test.0
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/AnimPicture/App.vue +224 -120
- package/AnimPicture/Item.vue +44 -0
- package/ConnectLine/App.vue +173 -0
- package/CoupletsTest/App.vue +212 -0
- package/CoupletsTest/Common/SpriteDeal.js +30 -0
- package/CoupletsTest/LeadWire.vue +221 -0
- package/CoupletsTest/Maroon.vue +112 -0
- package/CoupletsTest/Salvo.vue +251 -0
- package/CoupletsTest/Sprite/firecracker.json +212 -0
- package/CoupletsTest/Sprite/firecracker.png +0 -0
- package/CoupletsTest/Sprite/fireworks.json +220 -0
- package/CoupletsTest/Sprite/fireworks.png +0 -0
- package/CoupletsTest/Sprite/scroll.json +76 -0
- package/CoupletsTest/Sprite/scroll.png +0 -0
- package/CoupletsTest/Sprite/spark.json +268 -0
- package/CoupletsTest/Sprite/spark.png +0 -0
- package/CoupletsTest/images/Couplets.png +0 -0
- package/CoupletsTest/images/goldencoin1.png +0 -0
- package/CoupletsTest/images/goldencoin2.png +0 -0
- package/CoupletsTest/images/leadWire.png +0 -0
- package/CoupletsTest/images/line.png +0 -0
- package/CoupletsTest/images/purpleStar.png +0 -0
- package/CoupletsTest/images/redStar.png +0 -0
- package/CoupletsTest/images/scroll1.png +0 -0
- package/CoupletsTest/images/star1.png +0 -0
- package/CoupletsTest/images/star2.png +0 -0
- package/CoupletsTest/images/star3.png +0 -0
- package/CoupletsTest/images/star4.png +0 -0
- package/CoupletsTest/images/yellowStar.png +0 -0
- package/DemoHomepage/components/BodyFrame.vue +27 -11
- package/DemoHomepage/router.js +35 -5
- package/DemoHomepage/views/Homepage.vue +1 -1
- package/DispersedItemSample/DispersedItemSample.vue +138 -0
- package/DispersedItemSample/DispersedItemWidget/DispersedItemWidget.vue +358 -0
- package/DispersedItemSample/DispersedItemWidget/MyRenderItem.ts +115 -0
- package/DispersedItemSample/Item.vue +55 -0
- package/FilterDemo/AnimatePic.vue +5 -6
- package/FocusMoveStyle/App.vue +126 -110
- package/FocusMoveStyle/CreepFocus.vue +128 -0
- package/FocusMoveStyle/FoldableItem.vue +279 -0
- package/FocusMoveStyle/Item.vue +32 -31
- package/FreeMove/App.vue +2 -2
- package/ImpactStop/App.vue +343 -384
- package/LatexDemo/App.vue +11 -0
- package/MetroWidgetDemos/RefreshDemo/App.vue +101 -0
- package/MetroWidgetDemos/RefreshDemo/Item.vue +116 -0
- package/MetroWidgetDemos/RefreshDemo/assets/imageList.json +237 -0
- package/MetroWidgetDemos/RefreshDemo/data.js +16 -0
- package/MetroWidgetDemos/TripleWidget/App.vue +81 -0
- package/MetroWidgetDemos/TripleWidget/Item.vue +64 -0
- package/MetroWidgetDemos/TripleWidget/SWidgetItem.vue +93 -0
- package/MetroWidgetDemos/TripleWidget/WidgetItem.vue +111 -0
- package/MetroWidgetDemos/routeList.js +12 -0
- package/ProgressBar/App.vue +128 -0
- package/QrcodeDemo/App.vue +2 -2
- package/SpriteImage/App.vue +113 -68
- package/SwiperTest/App.vue +105 -0
- package/ViewOpacity/App.vue +98 -0
- package/package.json +1 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: ChenChanghua
|
|
3
|
+
* @Date: 2023-03-09 15:33:54
|
|
4
|
+
* @Description: file content
|
|
5
|
+
-->
|
|
6
|
+
<script setup>
|
|
7
|
+
import { ref } from "vue";
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
data: Object,
|
|
11
|
+
onAction: Object,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const focused = ref(false);
|
|
15
|
+
|
|
16
|
+
// 自身的焦点状态自己记录, 通过回调来改变
|
|
17
|
+
const onFocus = () => {
|
|
18
|
+
focused.value = true;
|
|
19
|
+
};
|
|
20
|
+
const onBlur = () => {
|
|
21
|
+
focused.value = false;
|
|
22
|
+
};
|
|
23
|
+
const onClick = () => {
|
|
24
|
+
console.log("item onclick ", props.data);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// 一般在create的时候进行回调的注册, 使用 option api的可以在created时进行注册
|
|
28
|
+
props.onAction.register("onFocus", onFocus);
|
|
29
|
+
props.onAction.register("onBlur", onBlur);
|
|
30
|
+
props.onAction.register("onClick", onClick);
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<div
|
|
35
|
+
:style="{
|
|
36
|
+
width: data.width,
|
|
37
|
+
height: data.height,
|
|
38
|
+
transform: focused ? 'scale3d(1.2, 1.2, 1.2)' : '',
|
|
39
|
+
transition: 'transform 0.2s linear',
|
|
40
|
+
}"
|
|
41
|
+
>
|
|
42
|
+
<div
|
|
43
|
+
v-if="focused"
|
|
44
|
+
:style="{
|
|
45
|
+
left: -2,
|
|
46
|
+
top: -2,
|
|
47
|
+
width: data.width + 4,
|
|
48
|
+
height: data.height + 4,
|
|
49
|
+
backgroundColor: '#FF0000',
|
|
50
|
+
}"
|
|
51
|
+
/>
|
|
52
|
+
<div
|
|
53
|
+
:style="{
|
|
54
|
+
width: data.width,
|
|
55
|
+
height: data.height,
|
|
56
|
+
fontSize: 30,
|
|
57
|
+
color: '#FFFFFF',
|
|
58
|
+
backgroundColor: data.color,
|
|
59
|
+
}"
|
|
60
|
+
>
|
|
61
|
+
{{ data.content }}
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { MetroWidget, VERTICAL, useFocusHub, METRO_WIDGET_CONST } from "jsview";
|
|
3
|
+
import WidgetItem from "./WidgetItem.vue";
|
|
4
|
+
import { onMounted, ref, shallowRef } from "vue";
|
|
5
|
+
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
data: Object,
|
|
8
|
+
onAction: Object,
|
|
9
|
+
onItemEdge: Function,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const focusHub = useFocusHub();
|
|
13
|
+
const mwWidget2 = ref(null);
|
|
14
|
+
|
|
15
|
+
const provideData = () => {
|
|
16
|
+
const data = [];
|
|
17
|
+
for (let i = 0; i < 1; i++) {
|
|
18
|
+
data.push({
|
|
19
|
+
width: 500,
|
|
20
|
+
height: 170,
|
|
21
|
+
name: "3级嵌套_" + i + props.data.index,
|
|
22
|
+
marginBottom: 10,
|
|
23
|
+
index: i,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return data;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const measures = (item) => {
|
|
30
|
+
return {
|
|
31
|
+
width: item.width,
|
|
32
|
+
height: item.height,
|
|
33
|
+
marginRight: item.marginRight,
|
|
34
|
+
marginBottom: item.marginBottom,
|
|
35
|
+
itemSlide: METRO_WIDGET_CONST.ITEM_SLIDE.ACT_FOCUS_RECT_EVENT,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
onMounted(() => {});
|
|
40
|
+
|
|
41
|
+
const widgetRef = shallowRef();
|
|
42
|
+
const onFocus = (rect) => {
|
|
43
|
+
if (rect) {
|
|
44
|
+
//多层嵌套时需要将子的edge信息加上
|
|
45
|
+
let rectInfo = {
|
|
46
|
+
x: 0,
|
|
47
|
+
y: 0,
|
|
48
|
+
width: 0,
|
|
49
|
+
height: 0,
|
|
50
|
+
};
|
|
51
|
+
let curRect = rect;
|
|
52
|
+
while (curRect) {
|
|
53
|
+
let { x, y, width, height } = curRect.rect;
|
|
54
|
+
rectInfo.x += x;
|
|
55
|
+
rectInfo.y += y;
|
|
56
|
+
rectInfo.width = width;
|
|
57
|
+
rectInfo.height = height;
|
|
58
|
+
curRect = curRect.childEdgeInfo;
|
|
59
|
+
}
|
|
60
|
+
widgetRef.value?.setEnterFocusRect({
|
|
61
|
+
direction: rect.direction,
|
|
62
|
+
rect: rectInfo,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
focusHub.setFocus("mwWidget2" + props.data.index);
|
|
66
|
+
};
|
|
67
|
+
const onWidgetEdge = (info) => {
|
|
68
|
+
props.onItemEdge(info);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
props.onAction.register("onFocus", onFocus);
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
<template>
|
|
75
|
+
<metro-widget
|
|
76
|
+
ref="widgetRef"
|
|
77
|
+
:name="'mwWidget2' + props.data.index"
|
|
78
|
+
:top="0"
|
|
79
|
+
:left="0"
|
|
80
|
+
:width="660"
|
|
81
|
+
:height="600"
|
|
82
|
+
:provideData="provideData"
|
|
83
|
+
:padding="{ left: 30, right: 30 }"
|
|
84
|
+
:direction="VERTICAL"
|
|
85
|
+
:measures="measures"
|
|
86
|
+
:onEdge="onWidgetEdge"
|
|
87
|
+
>
|
|
88
|
+
<!-- 重要代码: 为了实现焦点就近移动, 需要传递onItemEdge回调 -->
|
|
89
|
+
<template #renderItem="{ data, onAction, onItemEdge }">
|
|
90
|
+
<widget-item :data="data" :onAction="onAction" :onItemEdge="onItemEdge" />
|
|
91
|
+
</template>
|
|
92
|
+
</metro-widget>
|
|
93
|
+
</template>
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { HORIZONTAL, MetroWidget, useFocusHub } from "jsview";
|
|
3
|
+
import { shallowRef } from "vue";
|
|
4
|
+
import Item from "./Item.vue";
|
|
5
|
+
|
|
6
|
+
const props = defineProps({
|
|
7
|
+
data: Object,
|
|
8
|
+
onItemEdge: Function,
|
|
9
|
+
onAction: Object,
|
|
10
|
+
});
|
|
11
|
+
const focusHub = useFocusHub();
|
|
12
|
+
const mwRef = shallowRef(null);
|
|
13
|
+
|
|
14
|
+
const measures = (item) => {
|
|
15
|
+
return item;
|
|
16
|
+
};
|
|
17
|
+
const randomColor = () => {
|
|
18
|
+
let randomColor = Math.round(Math.random() * 2 ** 24).toString(16);
|
|
19
|
+
return (
|
|
20
|
+
"#" + new Array(6 - randomColor.length).fill("0").join("") + randomColor
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
const provideData = () => {
|
|
24
|
+
const data = [];
|
|
25
|
+
for (let i = 0; i < 10; i++) {
|
|
26
|
+
data.push({
|
|
27
|
+
width: (i + props.data.index) % 2 == 0 ? 90 : 180,
|
|
28
|
+
height: 90,
|
|
29
|
+
marginRight: 10,
|
|
30
|
+
marginBottom: 10,
|
|
31
|
+
content: i,
|
|
32
|
+
color: randomColor(),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
};
|
|
37
|
+
const onFocus = (rect) => {
|
|
38
|
+
/** 重要代码: 参数rect为父MetroWidget传递的, 焦点过来的区域
|
|
39
|
+
* 因此需要调用setEnterFocusRect来设置焦点进入区域, 以寻找最近的焦点
|
|
40
|
+
*/
|
|
41
|
+
//多层嵌套时, EnterFocusRect需要根据子的信息设置
|
|
42
|
+
if (rect) {
|
|
43
|
+
let rectInfo = {
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0,
|
|
46
|
+
width: 0,
|
|
47
|
+
height: 0,
|
|
48
|
+
};
|
|
49
|
+
let curRect = rect;
|
|
50
|
+
while (curRect) {
|
|
51
|
+
let { x, y, width, height } = curRect.rect;
|
|
52
|
+
rectInfo.x += x;
|
|
53
|
+
rectInfo.y += y;
|
|
54
|
+
rectInfo.width = width;
|
|
55
|
+
rectInfo.height = height;
|
|
56
|
+
curRect = curRect.childEdgeInfo;
|
|
57
|
+
}
|
|
58
|
+
mwRef.value?.setEnterFocusRect({
|
|
59
|
+
direction: rect.direction,
|
|
60
|
+
rect: rectInfo,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// mwRef.value?.setEnterFocusRect(rect);
|
|
65
|
+
focusHub.setFocus(props.data.name);
|
|
66
|
+
};
|
|
67
|
+
const onBlur = () => {
|
|
68
|
+
//onBlur时需要返还焦点给父MetroWidget
|
|
69
|
+
focusHub.returnFocusToParent();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
props.onAction.register("onFocus", onFocus);
|
|
73
|
+
props.onAction.register("onBlur", onBlur);
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<template>
|
|
77
|
+
<div
|
|
78
|
+
:style="{
|
|
79
|
+
width: 900,
|
|
80
|
+
height: 50,
|
|
81
|
+
fontSize: 30,
|
|
82
|
+
color: '#FFFFFF',
|
|
83
|
+
}"
|
|
84
|
+
>
|
|
85
|
+
{{ data.name }}
|
|
86
|
+
</div>
|
|
87
|
+
<!-- 重要代码: sendFocusRectEvent可以让MetroWidget的item在获焦时发送事件, 通知父的MetroWidget进行滚动 -->
|
|
88
|
+
<!-- 重要代码: onItemEdge直接作为onEdge回调, 既子MetroWidget到达边缘时触发父的onItemEdge -->
|
|
89
|
+
<metro-widget
|
|
90
|
+
ref="mwRef"
|
|
91
|
+
:name="data.name"
|
|
92
|
+
:top="50"
|
|
93
|
+
:width="data.width"
|
|
94
|
+
:height="data.height"
|
|
95
|
+
:provideData="provideData"
|
|
96
|
+
:direction="HORIZONTAL"
|
|
97
|
+
:padding="{
|
|
98
|
+
left: 30,
|
|
99
|
+
right: 30,
|
|
100
|
+
top: 10,
|
|
101
|
+
bottom: 10,
|
|
102
|
+
}"
|
|
103
|
+
:measures="measures"
|
|
104
|
+
:onEdge="onItemEdge"
|
|
105
|
+
:sendFocusRectEvent="true"
|
|
106
|
+
>
|
|
107
|
+
<template #renderItem="{ data, onAction }">
|
|
108
|
+
<item :data="data" :onAction="onAction" />
|
|
109
|
+
</template>
|
|
110
|
+
</metro-widget>
|
|
111
|
+
</template>
|
|
@@ -74,4 +74,16 @@ export default [
|
|
|
74
74
|
component: () =>
|
|
75
75
|
import("jsview-vue-samples/MetroWidgetDemos/itemSizeUpdate/App.vue"),
|
|
76
76
|
},
|
|
77
|
+
{
|
|
78
|
+
name: "三层嵌套",
|
|
79
|
+
path: "/metroWidget/TripleWidget",
|
|
80
|
+
component: () =>
|
|
81
|
+
import("jsview-vue-samples/MetroWidgetDemos/TripleWidget/App.vue"),
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "数据刷新demo",
|
|
85
|
+
path: "/metroWidget/RefreshDemo",
|
|
86
|
+
component: () =>
|
|
87
|
+
import("jsview-vue-samples/MetroWidgetDemos/RefreshDemo/App.vue"),
|
|
88
|
+
},
|
|
77
89
|
]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<jsv-focus-block autoFocus :onKeyDown="procKeyDown">
|
|
3
|
+
<div class="bgSty">
|
|
4
|
+
<!-- 提示 -->
|
|
5
|
+
<div class="text" :style="{ left: 210, top: 20 }">
|
|
6
|
+
{{
|
|
7
|
+
"操作提示:\n按 左 键减小,\n按 右 键增加,\n按【OK】键恢复初始状态,\n按 返回 键退出"
|
|
8
|
+
}}
|
|
9
|
+
</div>
|
|
10
|
+
<!-- 第一幅图 点九 -->
|
|
11
|
+
<div
|
|
12
|
+
class="logo-bg"
|
|
13
|
+
:style="{
|
|
14
|
+
left: 210,
|
|
15
|
+
top: 200,
|
|
16
|
+
}"
|
|
17
|
+
>
|
|
18
|
+
<!-- 三个背景色块 -->
|
|
19
|
+
<div class="bg1" />
|
|
20
|
+
<div class="bg2" />
|
|
21
|
+
<div class="bg3" />
|
|
22
|
+
<!-- 点九进度条 -->
|
|
23
|
+
<div :style="{ top: 80, left: 0 }">
|
|
24
|
+
<JsvProgressBar
|
|
25
|
+
:width="800"
|
|
26
|
+
:height="84"
|
|
27
|
+
:progress="myProgress"
|
|
28
|
+
:aniTime="0.5"
|
|
29
|
+
:bgcBefore="'rgba(108, 196,187,0.8)'"
|
|
30
|
+
:bgcBehind="'rgba(255,255,255,0.3)'"
|
|
31
|
+
></JsvProgressBar>
|
|
32
|
+
</div>
|
|
33
|
+
<!-- 图1说明 -->
|
|
34
|
+
<div :style="{ left: 0, top: 26 }" class="text">
|
|
35
|
+
{{ "CanvasTexture配合点九完成" }}
|
|
36
|
+
</div>
|
|
37
|
+
<!-- 第二幅图 clipView -->
|
|
38
|
+
<div :style="{ top: 260 }">
|
|
39
|
+
<JsvProgressBar
|
|
40
|
+
:width="800"
|
|
41
|
+
:height="84"
|
|
42
|
+
:aniTime="0.5"
|
|
43
|
+
:progress="myProgress"
|
|
44
|
+
:bgcBefore="'rgba(108, 196,187,0.8)'"
|
|
45
|
+
:bgcBehind="'rgba(255,255,255,0.3)'"
|
|
46
|
+
:isCanvas="false"
|
|
47
|
+
></JsvProgressBar>
|
|
48
|
+
</div>
|
|
49
|
+
<!-- 图2说明 -->
|
|
50
|
+
<div :style="{ left: 0, top: 210 }" class="text">
|
|
51
|
+
{{ "ClipView的方式完成" }}
|
|
52
|
+
</div>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</jsv-focus-block>
|
|
56
|
+
</template>
|
|
57
|
+
|
|
58
|
+
<script setup>
|
|
59
|
+
import { shallowRef } from "vue";
|
|
60
|
+
import { JsvProgressBar } from "jsview";
|
|
61
|
+
|
|
62
|
+
//进度百分比
|
|
63
|
+
let myProgress = shallowRef(20);
|
|
64
|
+
//按键事件 控制进度条的width
|
|
65
|
+
const procKeyDown = (ev) => {
|
|
66
|
+
switch (ev.keyCode) {
|
|
67
|
+
case 37:
|
|
68
|
+
myProgress.value -= 5;
|
|
69
|
+
if (myProgress.value <= 0) {
|
|
70
|
+
myProgress.value = 0;
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
case 39:
|
|
74
|
+
myProgress.value += 5;
|
|
75
|
+
if (myProgress.value >= 100) {
|
|
76
|
+
myProgress.value = 100;
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
case 13:
|
|
80
|
+
myProgress.value = 0;
|
|
81
|
+
break;
|
|
82
|
+
default:
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<style scoped>
|
|
89
|
+
.bgSty {
|
|
90
|
+
background-color: #5490d1;
|
|
91
|
+
width: 1280;
|
|
92
|
+
height: 720;
|
|
93
|
+
}
|
|
94
|
+
.logo-bg {
|
|
95
|
+
width: 800;
|
|
96
|
+
height: 400;
|
|
97
|
+
}
|
|
98
|
+
.text {
|
|
99
|
+
width: 800;
|
|
100
|
+
height: 200;
|
|
101
|
+
font-size: 24;
|
|
102
|
+
font-weight: bold;
|
|
103
|
+
line-height: 32;
|
|
104
|
+
color: #ffffff;
|
|
105
|
+
text-align: center;
|
|
106
|
+
}
|
|
107
|
+
.bg1 {
|
|
108
|
+
left: 0;
|
|
109
|
+
top: 0;
|
|
110
|
+
height: 400;
|
|
111
|
+
width: 267;
|
|
112
|
+
background-color: #007f00;
|
|
113
|
+
}
|
|
114
|
+
.bg2 {
|
|
115
|
+
left: 267;
|
|
116
|
+
top: 0;
|
|
117
|
+
height: 400;
|
|
118
|
+
width: 267;
|
|
119
|
+
background-color: #3049b8;
|
|
120
|
+
}
|
|
121
|
+
.bg3 {
|
|
122
|
+
left: 534;
|
|
123
|
+
top: 0;
|
|
124
|
+
height: 400;
|
|
125
|
+
width: 266;
|
|
126
|
+
background-color: #d12b8c;
|
|
127
|
+
}
|
|
128
|
+
</style>
|
package/QrcodeDemo/App.vue
CHANGED
|
@@ -12,7 +12,7 @@ const includeImage = true;
|
|
|
12
12
|
const imageH = 64;
|
|
13
13
|
const imageW = 64;
|
|
14
14
|
const imageSrc =
|
|
15
|
-
"http://oss.image.
|
|
15
|
+
"http://oss.image.qcast.cn/homepage/20191224/0fdcdc8b258fe7baac16b73f58f8989d.jpg";
|
|
16
16
|
const tipsInfo = `功能:二维码展示可配置项:1.前景色
|
|
17
17
|
2.背景色
|
|
18
18
|
3.指定小图标
|
|
@@ -64,4 +64,4 @@ const onKeyDown = (ev) => {
|
|
|
64
64
|
</div>
|
|
65
65
|
</div>
|
|
66
66
|
</jsv-focus-block>
|
|
67
|
-
</template>
|
|
67
|
+
</template>
|
package/SpriteImage/App.vue
CHANGED
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
* loop {string} 动图的循环次数 infinite/数字,默认为infinite
|
|
13
13
|
* spriteName {string} 动图的名称,默认为null
|
|
14
14
|
* autostart{boolean} 是否自动播放动图
|
|
15
|
-
*
|
|
16
|
-
* stop(end_frame) 停止动画 end_frame: "start", "end"
|
|
17
|
-
* start() 开始动画
|
|
18
|
-
*
|
|
15
|
+
* ref 控制动图的对象
|
|
19
16
|
*
|
|
20
17
|
* 【技巧说明】
|
|
21
18
|
* Q: 动图和切图如何实现?
|
|
@@ -26,16 +23,49 @@
|
|
|
26
23
|
-->
|
|
27
24
|
|
|
28
25
|
<script setup>
|
|
29
|
-
import {
|
|
30
|
-
import
|
|
31
|
-
import
|
|
32
|
-
import { shallowRef } from "vue"
|
|
26
|
+
import { JsvSpriteAnim, JsvSpriteLoader } from "jsview";
|
|
27
|
+
import localSpriteImage from "./images/egg_break.png";
|
|
28
|
+
import localConfigJson from "./images/egg_break.json";
|
|
29
|
+
import { shallowRef } from "vue";
|
|
33
30
|
import { useRouter } from "vue-router";
|
|
34
31
|
|
|
35
|
-
console.log(
|
|
32
|
+
console.log(
|
|
33
|
+
"test localSpriteImage =",
|
|
34
|
+
localSpriteImage,
|
|
35
|
+
"/n localConfigJson=",
|
|
36
|
+
localConfigJson
|
|
37
|
+
);
|
|
36
38
|
const router = useRouter();
|
|
39
|
+
let useLocalData = shallowRef(true);
|
|
40
|
+
let animateImage = shallowRef(null);
|
|
41
|
+
let preloadJsonUrl = shallowRef(null);
|
|
42
|
+
let preloadCallback = shallowRef(null);
|
|
43
|
+
let spriteJsonIfno = shallowRef(null);
|
|
44
|
+
|
|
45
|
+
const _UseLocalData = () => {
|
|
46
|
+
console.log("using local data");
|
|
47
|
+
useLocalData.value = true;
|
|
48
|
+
animateImage.value = `url(${localSpriteImage})`;
|
|
49
|
+
preloadJsonUrl.value = null;
|
|
50
|
+
preloadCallback.value = null;
|
|
51
|
+
spriteJsonIfno.value = _formatInfo(localConfigJson).info;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const _UseRemoteData = () => {
|
|
55
|
+
const testRemoteImageUrl = "http://192.168.2.179:8077/images/egg_break.png";
|
|
56
|
+
const testRemoteConfigUrl = "http://192.168.2.179:8077/images/egg_break.json";
|
|
57
|
+
|
|
58
|
+
console.log("using remote data");
|
|
59
|
+
useLocalData.value = false;
|
|
60
|
+
animateImage.value = testRemoteImageUrl;
|
|
61
|
+
preloadJsonUrl.value = testRemoteConfigUrl;
|
|
62
|
+
preloadCallback.value = (config_json, resolve_set) => {
|
|
63
|
+
spriteJsonIfno.value = _formatInfo(config_json).info;
|
|
64
|
+
resolve_set(); // 通知loader数组设置完成
|
|
65
|
+
};
|
|
66
|
+
};
|
|
37
67
|
|
|
38
|
-
const _formatInfo = () => {
|
|
68
|
+
const _formatInfo = (config_json) => {
|
|
39
69
|
const info = {
|
|
40
70
|
frames: [],
|
|
41
71
|
meta: {
|
|
@@ -44,8 +74,6 @@ const _formatInfo = () => {
|
|
|
44
74
|
};
|
|
45
75
|
|
|
46
76
|
let frames_ref = info.frames;
|
|
47
|
-
let max_width = 0;
|
|
48
|
-
let max_height = 0;
|
|
49
77
|
|
|
50
78
|
for (let i = 0; i < config_json.frames.length; i++) {
|
|
51
79
|
const target = config_json.frames[i].spriteSourceSize;
|
|
@@ -53,85 +81,102 @@ const _formatInfo = () => {
|
|
|
53
81
|
target,
|
|
54
82
|
source: config_json.frames[i].frame,
|
|
55
83
|
});
|
|
56
|
-
const sprite_with = target.x + target.w;
|
|
57
|
-
const sprite_height = target.y + target.h;
|
|
58
|
-
if (sprite_with > max_width) {
|
|
59
|
-
max_width = sprite_with;
|
|
60
|
-
}
|
|
61
|
-
if (sprite_height > max_height) {
|
|
62
|
-
max_height = sprite_height;
|
|
63
|
-
}
|
|
64
84
|
}
|
|
65
|
-
return { info
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const spriteController = new SpriteController()
|
|
69
|
-
const sprite_info = _formatInfo();
|
|
70
|
-
console.log("test sprite_into =", sprite_info);
|
|
71
|
-
|
|
72
|
-
const view_size = {
|
|
73
|
-
w: sprite_info.maxW,
|
|
74
|
-
h: sprite_info.maxH,
|
|
85
|
+
return { info };
|
|
75
86
|
};
|
|
76
87
|
|
|
77
|
-
|
|
88
|
+
const spriteController = shallowRef(null);
|
|
89
|
+
|
|
90
|
+
let show = shallowRef(true);
|
|
78
91
|
|
|
79
92
|
const spriteAnimEnd = () => {
|
|
80
93
|
show.value = false;
|
|
81
|
-
}
|
|
94
|
+
};
|
|
82
95
|
const onKeyDown = (ev) => {
|
|
83
96
|
if (ev.keyCode == 8 || ev.keyCode == 27 || ev.keyCode == 10000) {
|
|
84
97
|
router?.go(-1); // 有router时,是从DemoHomepage进入,回退
|
|
85
98
|
return true;
|
|
86
99
|
}
|
|
87
100
|
return true;
|
|
88
|
-
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
_UseLocalData();
|
|
104
|
+
// TODO: 当需要测试远程数据时打开
|
|
105
|
+
// setTimeout(() => {
|
|
106
|
+
// _UseRemoteData();
|
|
107
|
+
// }, 2000);
|
|
89
108
|
</script>
|
|
90
109
|
|
|
91
110
|
<template>
|
|
92
|
-
<jsv-focus-block
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
111
|
+
<jsv-focus-block
|
|
112
|
+
autoFocus
|
|
113
|
+
:onAction="{
|
|
114
|
+
onKeyDown: onKeyDown,
|
|
115
|
+
}"
|
|
116
|
+
>
|
|
117
|
+
<div
|
|
118
|
+
:style="{
|
|
119
|
+
textAlign: 'center',
|
|
120
|
+
fontSize: 30,
|
|
121
|
+
lineHeight: 50,
|
|
122
|
+
color: '#ffffff',
|
|
123
|
+
left: 200,
|
|
124
|
+
top: 100,
|
|
125
|
+
width: 434,
|
|
126
|
+
height: 50,
|
|
127
|
+
backgroundColor: 'rgba(27,38,151,0.8)',
|
|
128
|
+
}"
|
|
129
|
+
>
|
|
106
130
|
精灵图效果
|
|
107
131
|
</div>
|
|
108
132
|
<!--
|
|
109
133
|
通过show进行 清理精灵图,用于验证精灵图清理后,StyleSheet中cssRules的keyFrame清理工作能正常完成
|
|
110
134
|
-->
|
|
111
|
-
<div
|
|
112
|
-
|
|
113
|
-
|
|
135
|
+
<div
|
|
136
|
+
v-if="show"
|
|
137
|
+
:style="{ left: 200, top: 150, transform: 'scale3d(2.5, 2.5, 1)' }"
|
|
138
|
+
>
|
|
139
|
+
<JsvSpriteLoader
|
|
140
|
+
:imageUrl="animateImage"
|
|
141
|
+
:configUrl="preloadJsonUrl"
|
|
142
|
+
:onConfigReady="preloadCallback"
|
|
143
|
+
:noNeedResource="useLocalData"
|
|
144
|
+
>
|
|
145
|
+
<JsvSpriteAnim
|
|
146
|
+
ref="spriteController"
|
|
147
|
+
:spriteInfo="spriteJsonIfno"
|
|
148
|
+
:loop="3"
|
|
149
|
+
:duration="0.8"
|
|
150
|
+
:autostart="true"
|
|
151
|
+
:onAnimEnd="spriteAnimEnd"
|
|
152
|
+
:imageUrl="animateImage"
|
|
153
|
+
/>
|
|
154
|
+
</JsvSpriteLoader>
|
|
114
155
|
</div>
|
|
115
156
|
|
|
116
|
-
<div
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
157
|
+
<div
|
|
158
|
+
:style="{
|
|
159
|
+
textAlign: 'center',
|
|
160
|
+
fontSize: 30,
|
|
161
|
+
lineHeight: 50,
|
|
162
|
+
color: '#ffffff',
|
|
163
|
+
left: 700,
|
|
164
|
+
top: 100,
|
|
165
|
+
width: 434,
|
|
166
|
+
height: 50,
|
|
167
|
+
backgroundColor: 'rgba(27,38,151,0.8)',
|
|
168
|
+
}"
|
|
169
|
+
>
|
|
127
170
|
原始图片
|
|
128
171
|
</div>
|
|
129
|
-
<div
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
172
|
+
<div
|
|
173
|
+
:style="{
|
|
174
|
+
left: 700,
|
|
175
|
+
top: 150,
|
|
176
|
+
width: 434,
|
|
177
|
+
height: 372,
|
|
178
|
+
backgroundImage: animateImage,
|
|
179
|
+
}"
|
|
180
|
+
/>
|
|
136
181
|
</jsv-focus-block>
|
|
137
182
|
</template>
|