This commit is contained in:
xixingwl
2023-02-04 08:50:14 +08:00
commit 98cfbb0b77
89 changed files with 9508 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
setTimeout(p=>{ uni.reLaunch({
url:"/pages/tabbar/home/home"
})},3000)
},
methods: {
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>

277
pages/login/login.vue Normal file
View File

@@ -0,0 +1,277 @@
<template>
<view
style="height: 100vh;display: flex;flex-direction: column;align-items: center;justify-content: center;box-sizing: border-box;">
<button class="avatar-wrapper" open-type="chooseAvatar" @tap="onChooseAvatar">
<image class="avatar" :src="avatarUrl"></image>
</button>
<input type="nickname" class="weui-input" placeholder="请输入昵称" />
<button type="primary" block open-type="getUserInfo" @getuserinfo="appLoginWx">
微信一键登录
</button>
<button v-show="showPhone" type="primary" block open-type="getPhoneNumber" @getphonenumber="getPhone">
授权电话
</button>
</view>
</template>
<script>
export default {
data() {
return {
avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
openid: "",
loginstate: "0",
openid: "",
userEntity: null,
terminal: "",
osVersion: "",
phoneNumber: "",
showModal: false, //定义登录弹窗
}
},
onLoad: function() {},
methods: {
onChooseAvatar(e) {
console.log(e)
const {
avatarUrl
} = e.detail
this.avatarUrl = avatarUrl
},
// 授权获取微信用户信息
appLoginWx(res) {
console.log(res)
// 获取用户信息成功
if (res.detail.errMsg === 'getUserProfile:ok' || res.detail.errMsg === 'getUserInfo:ok') {
this.userInfo = res.detail.userInfo;
let _this = this;
uni.showLoading({
title: '获取用户信息...',
mask: true
});
// 获取jsCode
uni.login({
provider: 'weixin',
success(resLogin) {
console.log(resLogin);
if (resLogin.errMsg === "login:ok") {
// 获取jsCode成功通过jsCode调用微信api获取用户openId
_this.wechatLogin(resLogin.code);
return
}
uni.hideLoading();
uni.showToast({
title: '获取用户信息失败,请重试',
icon: 'none',
duration: 2000
});
},
fail() {
uni.hideLoading();
uni.showToast({
title: '获取用户信息失败,请重试',
icon: 'none',
duration: 2000
});
}
});
}
},
wechatLogin(wxCode) {
// 这里一般让后端去调用微信api获取openId等信息前端调用的话像会多下面这个请求
// 因为若果是后端去调用的话后端拿到微信api返回的openId后可直接去数据库查询判断该用户是否已注册
// 如果已经注册了就直接返回注册的用户信息,
// 如果未注册则后端需要返回openId、sessionKeyde等信息
// 然后前端页面弹出授权获取手机号码的按钮,用户点击后拿到手机号后进行解密后再把信息提交给后台进行注册
const params = {
appid: this.appId, // 小程序的appId注意需要企业的appId并且你目前是开发人员不然后续无法获取到手机号码
secret: '***************', // 企业小程序的secret
js_code: wxCode, // 注意jsCode动态获取的使用一次后将失效
grant_type: 'authorization_code' // 这个参数固定写死
}
that.$ajax('index/index', {
code: resLogin.code
}).then(res => {
console.log(res)
})
// 调用微信api获取openid等信息
this.$get('https://api.weixin.qq.com/sns/jscode2session', params).then(res => {
console.log(res)
if (res.errcode) {
console.log('获取openId失败')
uni.hideLoading();
uni.showToast({
title: '获取用户信息失败',
icon: 'none',
duration: 2000
});
return
}
this.openId = res.openid
this.sessionKey = res.session_key
this.unionid = res.unionid
// 调用后端接口判断用户是否已注册过
this.$post('/login', {
openId: this.openId
}).then(res => {
uni.hideLoading();
// 若返回的参数中有token说明已经注册过
if (res.status === 200 && res.data.token) {
uni.showToast({
title: '登录成功!',
duration: 1000
});
// 缓存用户信息
uni.setStorageSync("token", res.data.token);
uni.setStorageSync("userInfo", res.data);
// 登录成功返回上一页
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1000)
return
}
// 走到这里说明没有注册过,需要弹出授权获取用户手机号的弹框按钮让用户授权
if (res.status == 200) {
this.showPhone = true
return
}
uni.showToast({
title: res.message,
icon: 'none',
duration: 2000
});
}).catch(() => {
uni.hideLoading();
uni.showToast({
title: '登录失败,请稍后重试',
icon: 'none',
duration: 2000
});
})
}).catch(err => {
console.log(err)
uni.hideLoading();
uni.showToast({
title: '获取用户信息失败',
icon: 'none',
duration: 2000
});
})
// 下面注释的就是后端去调用微信api获取用户openId的提供给前端的接口
// this.$post('/login', {
// jsCode: wxCode
// }).then(res => {
// console.log(res);
// uni.hideLoading();
// // 若直接返回token说明已经注册
// if (res.status === 200 && res.data.token) {
// uni.showToast({
// title: '登录成功!',
// duration: 1000
// });
// uni.setStorageSync("token", res.data.token);
// this.saveUserInfo(res.data);
// setTimeout(() => {
// // this.goTabBar('/pages/index')
// uni.navigateBack({
// delta: 1
// })
// }, 1000)
// return
// }
// if (res.status == 200) {
// this.openId = res.data.openid
// this.sessionKey = res.data.session_key
// this.unionid = res.data.unionid
// this.id = res.data.id
// this.showPhone = true
// return
// }
// uni.showToast({
// title: res.message,
// icon: 'none',
// duration: 2000
// });
// }).catch(() => {
// uni.hideLoading();
// uni.showToast({
// title: '登录失败,请稍后重试',
// icon: 'none',
// duration: 2000
// });
// })
},
// 授权电话号回调 (这里千万注意:小程序必须要完成 微信认证才能获取到加密的手机号码)
getPhone(res) {
console.log(res)
if (res.detail.errMsg === 'getPhoneNumber:ok') {
const encryptedData = res.detail.encryptedData
console.log(123, sessionKey, encryptedData, iv)
const pc = new WXBizDataCrypt(this.appId, this.sessionKey)
const data = pc.decryptData(encryptedData, res.detail.iv) // 这里使用解密手机号的方法
console.log('解密后 data: ', data.phoneNumber)
this.phone = data.phoneNumber
this.showPhone = false
this.loginHandle()
} else {
this.showPhone = false
uni.showToast({
title: '获取手机号失败,请重试',
icon: 'none',
duration: 2000
});
}
},
// 用户注册
loginHandle() {
const data = {
"account": this.phone,
"icon": this.userInfo.avatarUrl,
"id": this.id,
"nickname": this.userInfo.nickName,
"openId": this.openId,
"phone": this.phone,
"unionid": this.unionid
}
console.log(data)
uni.showLoading({
title: '登录中...',
mask: true
});
this.$post('/login/login', data).then(res => {
console.log(res);
uni.hideLoading();
if (res.status == 200) {
uni.showToast({
title: '登录成功!',
duration: 1000
});
uni.setStorageSync("token", res.data.token);
uni.setStorageSync("userInfo", res.data);
setTimeout(() => {
uni.navigateBack({
delta: 1
})
}, 1000)
} else {
uni.showToast({
title: res.message,
icon: 'none',
duration: 2000
});
}
});
},
}
}
</script>
<style>
</style>

267
pages/tabbar/home/home.vue Normal file
View File

@@ -0,0 +1,267 @@
<template>
<view class="warp">
<uni-search-bar @confirm="search" v-model="searchValue" @input="input" clearButton="always" cancelButton="none"
@clear="scan">
<template v-slot:clearIcon>
<uni-icons color="#999999" size="18" type="scan" />
</template>
</uni-search-bar>
<!-- 个人中心页方格列表数据 -->
<view class="Grid">
<view class="Grid-Item" v-for="item in List" :key="item.id">
<view class="GSimg">
<image class="Image" :src="item.img"></image>
</view>
<view class="GStitle">{{ item.title }}</view>
</view>
</view>
<view class="MsgList">
<view class="MlSon" v-for="item in List1" :key="item.id">
<view class="MlSonvBox">
<view class="SonOfImg">
<image class="Img" :src="item.img"></image>
</view>
<view class="SonOfName">
<view class="SNTop">
{{item.title}}
</view>
<view class="SNBom">
<view class="SBleft">
左边信息
</view>
<view class="SBright">
右边信息
</view>
</view>
</view>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
searchValue: '123123',
List: [{
id: 1,
img: '../../../static/logo.png',
title: '九宫格布局1'
},
{
id: 2,
img: '../../../static/logo.png',
title: '九宫格布局2'
},
{
id: 3,
img: '../../../static/logo.png',
title: '九宫格布局3'
},
{
id: 4,
img: '../../../static/logo.png',
title: '九宫格布局4'
}
],
List1: [{
id: 1,
img: '../../../static/logo.png',
title: "这是标题超出两行的部分会被作为省略号隐藏,您也可以根据需求将其设为超出一行隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
{
id: 2,
img: '../../../static/logo.png',
title: "这是标题超出部分会被作为省略号隐藏",
msg: "这是提示信息"
},
]
}
},
onLoad() {
//this.$ajax('index')
},
methods: {
search(res) {
uni.showToast({
title: '搜索:' + res.value,
icon: 'none'
})
},
input(res) {
console.log('----input:', res)
},
scan(res) {
// #ifndef H5
uni.scanCode({
success: function(res) {
console.log('条码类型:' + res.scanType);
console.log('条码内容:' + res.result);
},
fail: function() {
},
complete: function() {
}
});
// #endif
},
},
onBackPress() {
// #ifdef APP-PLUS
plus.key.hideSoftKeybord();
// #endif
}
}
</script>
<style lang="scss">
.Grid {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
background: #f7f7f7;
padding: 10rpx 15rpx;
.Grid-Item {
width: 25%;
text-align: center;
border: 1rpx solid #ccc;
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
flex-direction: column;
align-items: center;
padding-top: 15rpx;
padding-bottom: 15rpx;
.GSimg {
width: 96rpx;
height: 96rpx;
.Image {
width: 96rpx;
height: 96rpx;
}
}
.GStitle {
width: 100%;
height: 34rpx;
line-height: 34rpx;
color: #06121e;
font-size: 24rpx;
margin-top: 20rpx;
}
}
}
$max:100%;
.MsgList {
width: 92%;
margin-left: 4%;
max-width: 690rpx;
height: auto;
.MlSon {
border-radius: 12rpx;
.MlSonvBox {
padding: 24rpx 32rpx;
height: 168rpx;
display: flex;
justify-content: space-around;
background: #fff;
border: 1px solid red;
margin-top: 10px;
.SonOfImg {
border: 1px solid red;
width: 164rpx;
height: $max;
border-radius: 12rpx;
overflow: hidden;
.Img {
width: $max;
height: $max;
}
}
.SonOfName {
width: 428rpx;
height: $max;
.SNTop {
//这部分是标题 我将其设置为超出两行隐藏掉您可根据需求设置为一行
width: $max;
height: 88rpx;
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp: 2;
line-clamp: 2;
-webkit-box-orient: vertical;
line-height: 44rpx;
color: #06121E;
font-size: 28rpx;
}
.SNBom {
width: $max;
height: 34rpx;
line-height: 34rpx;
font-size: 24rpx;
display: flex;
justify-content: space-between;
margin-top: 18rpx;
.SBleft {
//这里预留了底部左右信息的样式处理
}
.SBright {}
}
}
}
}
}
</style>

189
pages/tabbar/my/my.vue Normal file
View File

@@ -0,0 +1,189 @@
<template>
<view>
<page-head title="view"></page-head>
<view class="warp" style="margin: 10rpx 15rpx;">
<view class="user" style="">
<image class="user-avatar" mode="aspectFit" src="../../../static/logo.png"></image>
<view class="user-info">
<h2> 用户昵称 </h2>
<text> UID 1234567897 </text>
<text> 用户昵称</text>
</view>
</view>
<view style="padding: 10rpx;"></view>
<view class="Grid">
<view class="Grid-Item">
<view class="Grid-Item-1">
<view class="GSimg">
<image class="Image" src="../../../static/logo.png"></image>
</view>
<view class="GStitle">测试功能</view>
</view>
</view>
<view class="Grid-Item">
<view class="Grid-Item-1">
<view class="GSimg">
<image class="Image" src="../../../static/logo.png"></image>
</view>
<view class="GStitle">测试功能</view>
</view>
</view>
<view class="Grid-Item">
<view class="Grid-Item-1">
<view class="GSimg">
<image class="Image" src="../../../static/logo.png"></image>
</view>
<view class="GStitle">测试功能</view>
</view>
</view>
<view class="Grid-Item">
<view class="Grid-Item-1">
<view class="GSimg">
<image class="Image" src="../../../static/logo.png"></image>
</view>
<view class="GStitle">测试功能</view>
</view>
</view>
</view>
<view style="padding: 10rpx;"></view>
<uni-list style="">
<uni-list-item title="列表左侧带略缩图"
thumb="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png"
thumb-size="sm" rightText="右侧文字" showArrow></uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#4cd964',size: '25',type: 'gear'}"
title="列表左侧带扩展图标" clickable showArrow>
</uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#4cd964',size: '25',type: 'gear'}"
title="列表左侧带扩展图标" clickable showArrow>
</uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#4cd964',size: '25',type: 'gear'}"
title="列表左侧带扩展图标" clickable showArrow>
</uni-list-item>
</uni-list>
<view style="padding: 10rpx;"></view>
<uni-list>
<uni-list-item title="列表左侧带略缩图"
thumb="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/460d46d0-4fcc-11eb-8ff1-d5dcf8779628.png"
thumb-size="sm" rightText="右侧文字" showArrow></uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#4cd964',size: '25',type: 'gear'}" title="设置"
clickable showArrow>
</uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#4cd964',size: '25',type: 'info'}" title="关于"
clickable showArrow>
</uni-list-item>
<uni-list-item :showExtraIcon="true" :extraIcon="{color: '#ff0000',size: '25',type: 'back'}" title="退出"
clickable showArrow>
</uni-list-item>
</uni-list>
</view>
</view>
</template>
<script>
import {mapState,mapGetters} from 'vuex'
export default {
computed: {
...mapState({
text: state => state.moduleA.text,
timestamp: state => state.moduleB.timestamp
}),
...mapGetters({
isLogin: 'userIsLogin'
})
},
data() {
return {}
},
onLoad(){
if (! this.isLogin) {
uni.redirectTo({
url:"/pages/login/login"
})
}
},
methods: {
},
onBackPress() {
// #ifdef APP-PLUS
plus.key.hideSoftKeybord();
// #endif
}
}
</script>
<style lang="scss">
.user {
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
justify-content: flex-start;
align-items: center;
padding-top: 180rpx;
padding-left: 15rpx;
padding-bottom:25rpx;
.user-avatar {
width: 138rpx;
height: 138rpx;
border-radius: 50%;
}
.user-info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
padding-left: 45rpx;
}
}
.Grid {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
background: #f7f7f7;
.Grid-Item {
width: 25%;
.Grid-Item-1 {
margin-left: 10rpx;
margin-right: 10rpx;
text-align: center;
border: 1rpx solid #efeded;
border-radius: 25rpx;
box-sizing: border-box;
display: flex;
flex-wrap: wrap;
justify-content: space-around;
flex-direction: column;
align-items: center;
padding-top: 20rpx;
padding-bottom: 5rpx;
background-color: #fff;
}
.GSimg {
width: 96rpx;
height: 96rpx;
.Image {
width: 96rpx;
height: 96rpx;
}
}
.GStitle {
width: 100%;
height: 34rpx;
line-height: 34rpx;
color: #06121e;
font-size: 24rpx;
margin-top: 10rpx;
}
}
}
</style>