实战项目名称:仿知识星球App
技术栈:前端 =>uni-app( 后端:Node.js + Mysql + Apollo + Graphql )
已实现功能:微信登录,创建星球,内容管理,星球管理
项目git地址:请点击访问
项目最终效果图:@点击访问效果图,欢迎关注收藏订阅专栏!!!
提示:该项目只用于个人实战,不应用于任何商业用途。
{
"path": "pages/index/index",
"style": {
"navigationStyle": "custom"
}
},

u-navbar组件,实现自定义导航栏
首页的顶部导航栏关键代码如下:
<u-navbar :placeholder="true" leftIconColor="#fff">
//左边显示的内容,字体样式都可以自定义
<view class="u-nav-slot both-center" slot="left">
<view class="title">
兴趣星球
</view>
</view>
//右边的+按钮,只会在app端显示,编译成微信小程序的时候不会有这个按钮
<!-- #ifdef APP-PLUS -->
<view class="u-nav-slot" slot="right" @click="open()">
<view class="relative">
<image class="add" src="../../static/svg/add.svg" mode=""></image>
</view>
</view>
<!-- #endif -->
</u-navbar>
先看看效果图

新建登录弹窗组件
登录弹窗组件关键代码如下:
<template>
<view>
<u-popup :safeAreaInsetBottom="true" :safeAreaInsetTop="true" :mode="popupData.mode" :show="show"
:round="popupData.round" :overlay="popupData.overlay" :borderRadius="popupData.borderRadius"
:closeable="popupData.closeable" :closeOnClickOverlay="popupData.closeOnClickOverlay" @close="close">
<view class="u-popup-slot both-center col">
<image class="img" src="../../static/logintip2.png" mode="scaleToFill"></image>
<!-- #ifdef APP-PLUS -->
<view class="green-bnt row both-center " @click="login_weixin()">
<image class="wx" src="../../static/svg/wx.svg" mode=""></image>
<view class="">
微信登录
</view>
</view>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="green-bnt row both-center " @click="wxGetUserInfo()">
<image class="wx" src="../../static/svg/wx.svg" mode=""></image>
<view class="">
微信授权登录
</view>
</view>
<!-- #endif -->
<view class="row label check-box hor-center">
<view class="radio both-center" :class="{'select' : agree}" @click="change()">
<image v-if="agree" class="icons" src="../../static/svg/select.svg" mode="scaleToFill"></image>
</view>
已阅读并同意
<view class="main-color">《用户协议》 </view>
和
<view class="main-color">《隐私政策》 </view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
export default {
name: "login-popup",
data() {
return {
agree: false,
code: '',
popupData: {
isshow: false,
overlay: true,
mode: 'bottom',
borderRadius: '',
round: '20',
closeable: true,
closeOnClickOverlay: true
}
};
},
props: {
show: Boolean
},
mounted() {
this.popupData.isshow = this.show
},
methods: {
change() {
this.agree = !this.agree
},
close() {
this.popupData.isshow = false
this.$emit("send") //子组件传值父组件
},
}
}
</script>
<style scoped>
.u-popup-slot {
height: 280px;
}
.img {
/* #ifndef APP-PLUS */
margin-top: 5px;
/* #endif */
/* #ifndef APP-PLUS */
margin-top: 25px;
/* #endif */
width: 140px;
height: 111px;
}
.label {
font-family: PingFangSC-Regular;
font-size: 26px;
font-weight: normal;
line-height: 40px;
letter-spacing: 0px;
color: rgba(0, 0, 0, 0.3);
}
/* */
.green-bnt {
margin-top: 20px;
width: 80%;
height: 50px;
border-radius: 30px;
background: #17B99A;
box-shadow: 0 15px 30px #E7F8F5;
color: #fff;
font-family: PingFangSC-Semibold;
font-size: 15px;
font-weight: normal;
line-height: 20px;
letter-spacing: 0px;
}
.wx {
width: 24px;
height: 24px;
margin-right: 6px;
}
.check-box {
padding-top: 5px;
font-size: 12px;
}
/* check */
.radio {
margin-right: 5px;
width: 15px;
height: 15px;
border-radius: 50%;
border: 1px solid rgba(0, 0, 0, 0.3);
}
.select {
border: none;
}
.icons {
width: 15px;
height: 15px;
border-radius: 50%;
/* #ifdef APP-PLUS */
border: 1px solid #17B99A;
/* #endif */
}
</style>
① 先引入组件
import LoginPopup from '@/components/login-popup/login-popup.vue'
export default {
data() {
return {
show: false, //默认组件不显示
...
}
},
components: {
LoginPopup
},
}
② 将组件添加到首页视图内
//show控制组件是否显示,@send是点击弹窗组件内的,触发首页相应的methods,这一点跟vue的组件间通信方式一样
<LoginPopup :show="show" @send="close" />
③ 编写关键methods
methods:{
open() {
if (uni.getStorageSync('hasLogin')) {
uni.navigateTo({
url: '../newGroup/newGroup'
})
} else {
this.show = true
}
},
close() {
this.show = false
}
}
由于项目目前在对接后台api中,项目git地址:请点击访问,大家可以去clone下来借鉴下;
知识星球APP进行设计的,算得上是入门级的uni-app,后期会更新一个企业级uniapp项目。git项目拷贝下来的代码有不懂的,可以截图私信给我,看到会回复你,希望可以帮助到你了解和开发uniapp。