近期有开发者制作了一套APICloud的教程,包含AVM多端开发框架教程和APICloud的云数据开发,并用APICloud开发了一个短视频的多端应用。
本文节选了案例实战的部分,重点介绍几个功能的前端实现。
一、效果预览
首先我们先来看一下实现效果
二、项目前端实现
本项目中前端采用APICloud AVM多端开发技术进行开发,要点包括 swiper 轮播图、网络请求封装等。使用 APICloud 多端技术进行开发,实现一套代码多端运行,支持编译成 Android & iOS App 以及微信小程序。
1、APICloud使用步骤:
(1)下载 APICloud Studio 3 作为开发工具。下载地址:/studio3
(2)注册账号后在控制台创建app,控制台地址:/console
可以在控制台创建
也可以在APICloud Studio 3直接创建项目
2、编写首页轮播图
设置stml模板轮播内容
<swiper class="swiper" :circular="false" :vertical="true" @change="onchange">
<swiper-item class="swiper-item" v-for="item,index in videoList">
<video :src="" :controls="false" : onclick="togglePause" onpause="onpause"
onplay="onplay" onended="onended"></video>
</swiper-item>
</swiper>
- 1
- 2
- 3
- 4
- 5
- 6
编写script数据和方法
import '../../components/'
export default {
name: "tpl",
apiready() {
({
style: "light",
color: "-"
});
},
data() {
return {
isShow: "none",
videoContext: null,
current: 0,
page: 1,
videoList: [
{
id: "000",
nickname: "老陈打码",
content: "新年快乐,万事如意!",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/000.mp4'
},
{
id: "001",
nickname: "学习通知",
content: "快乐学习APICloud多端应用开发",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/001.mp4'
},
]
};
},
methods: {
handleClick(e) {
({
msg: ,
location: "middle"
});
},
onchange(event) {
// ()
= ;
if ( === - 1) {
++;
({
url: "/api/videos/getVideoList?obj=" + ({ page: , limit: 2 })
}, (ret, err) => {
// (ret)
// = ()
(item => (item))
if ( == 0) {
({
msg: '休息一下,视频很快会更新!'
})
}
})
}
&& ()
('#video' + ).$$getContext().then((context) => {
= context;
()
})
},
togglePause() {
()
},
togglePlay() {
()
},
onplay() {
= "none"
},
onpause() {
= "flex"
},
onended() {
()
},
likeFn() {
[].isLike = ![].isLike;
},
shareFn() {
[].share++;
}
},
apiready() {
('#video' + ).$$getContext().then((context) => {
= context;
()
})
}
};
- 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
轮播部分设计样式内容
.swiper {
width: 100vw;
height: 100vh;
}
.swiper-item video {
width: 100vw;
height: 100vh;
}
.playBtn {
width: 40vw;
height: 40vw;
position: fixed;
left: 50%;
top: 50%;
margin-left: -20vw;
margin-top: -20vw;
display: flex;
justify-content: center;
align-items: center;
opacity: 0.7;
}
.playBtn image {
width: 10vw;
height: 10vw;
}
.rightBar {
display: flex;
flex-direction: column;
position: fixed;
right: 0;
width: 20vw;
bottom: 15vw;
height: 80vw;
}
.right-item {
width: 100%;
height: 20vw;
display: flex;
justify-content: center;
align-items: center;
font-size: 3vw;
color: #fff;
}
.right-item image {
width: 8vw;
height: 8vw;
}
.desc {
width: 50vw;
height: 20vw;
color: #fff;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
position: fixed;
left: 0;
bottom: 18vw;
padding: 4vw;
text-align: left;
overflow: hidden;
}
- 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
最终效果
3、编写tabbar导航组件
<template>
<view class="tabbar">
<view class="tab-item" :style="{color:active=='index'?'#fff':'#bbb'}" @click="goPage('index')">首页</view>
<view class="tab-item" :style="{color:active=='friend'?'#fff':'#bbb'}" @click="goPage('friend')">朋友</view>
<view class="tab-item" @click="goPage('addVideo')">
<image src="../../image/" />
</view>
<view class="tab-item" :style="{color:active=='message'?'#fff':'#bbb'}" @click="goPage('message')">消息</view>
<view class="tab-item" :style="{color:active=='me'?'#fff':'#bbb'}" @click="goPage('me')">我</view>
</view>
</template>
<script>
export default {
name: 'tabbar',
props: {
active: String
},
apiready() {//like created
},
data() {
return {
}
},
methods: {
goPage(pagename) {
let pagePath = {
index: '../index/index',
friend: "../friend/friend",
message: '../message/message',
me: '../me/me',
addVideo: '../addVideo/addVideo',
}
({ url: pagePath[pagename] })
}
}
}
</script>
<style>
.tabbar {
position: fixed;
bottom: 0;
left: 0;
color: #fff;
height: 15vw;
width: 100vw;
background: #000;
display: flex;
flex-direction: row;
}
.tabbar .tab-item {
width: 20%;
height: 15vw;
display: flex;
justify-content: center;
align-items: center;
}
.tabbar .tab-item image {
width: 8vw;
height: 8vw;
}
</style>
- 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
效果如下
4、编写朋友页面
<template>
<view class="page">
<view class="friends">
<view class="friend-item" v-for="(item,index) in videoList">
<view class="friend-header">
<image :src="" />
<view class="msg">
<view class="username">{{}}</view>
<view class="time">{{}}</view>
</view>
</view>
<view class="content">
{{}}
</view>
<view class="video">
<video :src=""></video>
</view>
<view class="iconlist">
<div class="icon-item">
<image src="../../image/heart_border.png" />
<text>{{}}</text>
</div>
<div class="icon-item">
<image src="../../image/comment_border.png" />
<text>{{}}</text>
</div>
<div class="icon-item">
<image src="../../image/share_border.png" />
<text>{{}}</text>
</div>
</view>
</view>
</view>
<tabbar active="friend"></tabbar>
</view>
</template>
<script>
import "../../components/"
export default {
name: 'friend',
apiready() {//like created
},
data() {
return {
videoList: [
{
id: "000",
nickname: "老陈打码",
content: "新年快乐,万事如意!",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/000.mp4'
},
{
id: "001",
nickname: "学习通知",
content: "快乐学习APICloud多端应用开发",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/001.mp4'
},
{
id: "002",
nickname: "小清新",
content: "感谢每一个我们打开世界的人",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/002.mp4'
},
{
id: "003",
nickname: "琦琦",
content: "当你来到世界,他就拥有了超能力!致伟大的父亲",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/003.mp4'
},
{
id: "004",
nickname: "老陈打码",
content: "虎年大吉,虎虎生财好运来!",
like: "3.5w",
share: "3821",
collect: "2988",
comment: "3475",
isLike: false,
pubtime: "2022-01-10 01:30",
headimg: "/shortvideo/",
src: '/shortvideo/004.mp4'
},
]
}
},
methods: {
}
}
</script>
<style>
.page {
height: 100%;
}
.friends {
display: flex;
flex-direction: column;
}
.friend-item {
display: flex;
flex-direction: column;
padding: 4vw;
}
.friend-item .friend-header {
display: flex;
flex-direction: row;
}
.friend-item .friend-header image {
width: 10vw;
height: 10vw;
border-radius: 5vw;
margin-right: 2vw;
}
.friend-item .friend-header .msg {
display: flex;
flex-direction: column;
}
.friend-item .friend-header .username {
font-weight: 900;
font-size: 4vw;
}
.friend-item .msg .time {
font-weight: 900;
font-size: 3vw;
}
.friend-item .content {
padding: 3vw 0;
}
.video video {
height: 80vw;
width: 45vw;
}
.friend-item .iconlist {
display: flex;
flex-direction: row;
}
.iconlist .icon-item {
display: flex;
flex-direction: row;
width: 20vw;
height: 10vw;
justify-content: center;
align-items: center;
}
.iconlist .icon-item image {
width: 6vw;
height: 6vw;
margin-right: 2vw;
}
</style>
- 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
页面效果如下
四、项目课程详细教程
由于课程项目内容太多,代码量也很多,大家可以去B站观看详细的视频课程内容和免费获取项目代码直接学习。
课程项目的脑图:
课程大纲:
1、APICloud多端应用开发
2、APICloud框架基础语法
3、APICloud数据云开发
4、APICloud数据云存储
5、短视频应用小程序
6、数据云实现短视频应用后端
完整视频教程链接:/video/BV1aa41147QR
课程代码链接地址:/s/10ARz_431wDcTbGTTNkI91w,提取码:maar