Commit e52b3f3a authored by Morson's avatar Morson

自营平台首页搭建,登录页面对接

parent 30a7e1f9
...@@ -16360,7 +16360,7 @@ ...@@ -16360,7 +16360,7 @@
} }
}, },
"vue-loader-v16": { "vue-loader-v16": {
"version": "npm:vue-loader@16.2.0", "version": "16.2.0",
"resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.2.0.tgz?cache=0&sync_timestamp=1616796718461&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-16.2.0.tgz", "resolved": "https://registry.npm.taobao.org/vue-loader/download/vue-loader-16.2.0.tgz?cache=0&sync_timestamp=1616796718461&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fvue-loader%2Fdownload%2Fvue-loader-16.2.0.tgz",
"integrity": "sha1-BGpTMI3Ufljv4g3ewe3sAnzjtG4=", "integrity": "sha1-BGpTMI3Ufljv4g3ewe3sAnzjtG4=",
"dev": true, "dev": true,
......
<script> <script>
import './../.env.js' import './../.env.js'
import util from '@/utils/util.js'
export default { export default {
globalData:{ globalData:{
uniEnv:process.uniEnv, uniEnv:process.uniEnv,
token: '', token: '',
//lyf的token:RTOKENf7d46ea33a7923515abfa779e04eccba77f98604 //lyf的token:RTOKENf7d46ea33a7923515abfa779e04eccba77f98604
//RTOKEN45f41a3053238cb72b3b72fe14df8d7040c9f502 //RTOKEN45f41a3053238cb72b3b72fe14df8d7040c9f502
// 授权用户信息
authUserInfo: '',
}, },
onLaunch: function() { onLaunch: function() {
// console.log('App Launch') // console.log('App Launch')
...@@ -48,6 +51,50 @@ ...@@ -48,6 +51,50 @@
return res.data return res.data
}, },
/**
* 用户自动登录
*/
autoLogin() {
let that = this
uni.login({
async success(res) {
if (res.code) {
let result = await that.$u.api.loginWechatAuth({code: res.code})
if (result) {
if (result.code == 200 && result.data) {
that.setUserData(result.data)
}
} else {
uni.showModal({
title: '请求失败',
content: result.message,
showCancel: false
});
}
uni.hideLoading()
} else {
uni.showModal({
title: '登录失败',
content: '未获取到code',
});
}
},
fail() {
}
});
},
setUserData(userInfo) {
if (userInfo && userInfo.token) {
// 如果已经登录则直接获取相关信息
util.setOpenid(userInfo.wxopenid)
util.setToken(userInfo.token)
uni.setStorageSync('user-info', userInfo);
} else {
util.setToken('')
}
},
} }
} }
</script> </script>
......
...@@ -23,7 +23,7 @@ const install = (Vue, vm) => { ...@@ -23,7 +23,7 @@ const install = (Vue, vm) => {
return return
} }
app.globalData.jumpLoginStatus = false app.globalData.jumpLoginStatus = false
vm.$u.route('/pages/login/wxlogin'); vm.$u.route('/pages/login/index');
} }
Vue.prototype.$u.http.setConfig({ Vue.prototype.$u.http.setConfig({
baseUrl: systemApiUrl, baseUrl: systemApiUrl,
...@@ -88,16 +88,16 @@ const install = (Vue, vm) => { ...@@ -88,16 +88,16 @@ const install = (Vue, vm) => {
case 0: case 0:
// return result; // return result;
case 200: case 200:
// return { return {
// data:result, data:result.data || result,
// code:code, code:code,
// message:msg message:msg
// }; };
case 401: case 401:
//需要登录的接口,当token 过期时,清掉本地token,到登录页面 //需要登录的接口,当token 过期时,清掉本地token,到登录页面
// if (!token) { // if (!token) {
// uni.navigateTo({ // uni.navigateTo({
// url: '/pages/login/wxlogin' // url: '/pages/login/index'
// }); // });
// return; // return;
// } // }
......
...@@ -55,9 +55,11 @@ ...@@ -55,9 +55,11 @@
/* 快应用特有相关 */ /* 快应用特有相关 */
"mp-weixin" : { "mp-weixin" : {
/* 微信小程序特有相关 */ /* 微信小程序特有相关 */
"appid" : "", "appid" : "wxd1d6eede324b0465",
"setting" : { "setting" : {
"urlCheck" : false "urlCheck" : false,
"es6" : true,
"minified" : true
}, },
"usingComponents" : true "usingComponents" : true
}, },
......
...@@ -6,9 +6,33 @@ ...@@ -6,9 +6,33 @@
{ {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "uni-app" "navigationBarTitleText": "首页"
} }
}, },
{
"path": "pages/order/index",
"style": {
"navigationBarTitleText": "订单"
}
},
{
"path": "pages/study/index",
"style": {
"navigationBarTitleText": "学习"
}
},
{
"path": "pages/mine/index",
"style": {
"navigationBarTitleText": "我的"
}
},
{
"path": "pages/login/index",
"style": {
"navigationBarTitleText": "我的"
}
},
{ {
"path": "pages/settle/index", "path": "pages/settle/index",
"style": { "style": {
...@@ -86,6 +110,35 @@ ...@@ -86,6 +110,35 @@
"navigationBarTitleText": "uni-app", "navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8", "navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8" "backgroundColor": "#F8F8F8"
},
"tabBar": {
"color": "#7A7E83",
"selectedColor": "#007AFF",
"borderStyle": "black",
"backgroundColor": "#F8F8F8",
"list": [{
"pagePath": "pages/index/index",
"iconPath": "static/logo.png",
"selectedIconPath": "static/logo.png",
"text": "首页"
},
{
"pagePath": "pages/order/index",
"iconPath": "static/logo.png",
"selectedIconPath": "static/logo.png",
"text": "订单"
}, {
"pagePath": "pages/study/index",
"iconPath": "static/logo.png",
"selectedIconPath": "static/logo.png",
"text": "学习"
}, {
"pagePath": "pages/mine/index",
"iconPath": "static/logo.png",
"selectedIconPath": "static/logo.png",
"text": "我的"
}
]
}, },
"condition": { //模式配置,仅开发期间生效 "condition": { //模式配置,仅开发期间生效
"current": 0, //当前激活的模式(list 的索引项) "current": 0, //当前激活的模式(list 的索引项)
......
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
} }
if (res.data.code == 401 || res.data.code == 403) { if (res.data.code == 401 || res.data.code == 403) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/wxlogin' url: '/pages/login/index'
}) })
return return
} }
...@@ -219,7 +219,7 @@ ...@@ -219,7 +219,7 @@
if (res.statusCode == 401) { if (res.statusCode == 401) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/wxlogin' url: '/pages/login/index'
}) })
return return
} }
...@@ -288,7 +288,7 @@ ...@@ -288,7 +288,7 @@
uni.hideLoading() uni.hideLoading()
if (res.statusCode == 401) { if (res.statusCode == 401) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/wxlogin' url: '/pages/login/index'
}) })
return return
} }
...@@ -451,7 +451,7 @@ ...@@ -451,7 +451,7 @@
if (res.statusCode == 401) { if (res.statusCode == 401) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/wxlogin' url: '/pages/login/index'
}) })
return return
} }
......
<template> <template>
<view class="content"> <view class="content">
<image class="logo" src="/static/logo.png"></image> <view class="wrap">
<view> <!-- <u-image width="100%" height="300rpx" src="/static/anime3.jpg" mode="widthFix"></u-image> -->
<text class="title">{{title}}</text>
</view> </view>
<u-card title="最新消息">
<view class="" slot="body">
<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
<image src="https://img11.360buyimg.com/n7/jfs/t1/94448/29/2734/524808/5dd4cc16E990dfb6b/59c256f85a8c3757.jpg" mode="aspectFill"></image>
<view class="u-body-item-title u-line-2">瓶身描绘的牡丹一如你初妆,冉冉檀香透过窗心事我了然,宣纸上走笔至此搁一半</view>
</view>
</view>
</u-card>
<u-card title="订单推荐">
<view class="" slot="body">
<view class="u-body-item u-flex u-row-between u-p-b-0">
<view class="u-body-item-title u-line-2">釉色渲染仕女图韵味被私藏,而你嫣然的一笑如含苞待放</view>
<image src="https://img12.360buyimg.com/n7/jfs/t1/102191/19/9072/330688/5e0af7cfE17698872/c91c00d713bf729a.jpg" mode="aspectFill"></image>
</view>
</view>
<view class="order-foot" slot="foot">
<view class="btn-settle">
<u-button type="primary" shape="circle" @click="immediatelyIn">立即入驻</u-button>
</view>
</view>
</u-card>
</view> </view>
</template> </template>
<script> <script>
const app = getApp()
export default { export default {
data() { data() {
return { return {
title: 'Hello'
} }
}, },
onLoad() { onLoad() {
}, },
methods: { methods: {
immediatelyIn() {
if(app.globalData.token) {
uni.navigateTo({
url: "pages/settle/index"
})
} else {
uni.navigateTo({
url: "pages/login/index"
})
}
}
} }
} }
</script> </script>
<style> <style scoped lang="scss">
.content { .content {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.wrap {
.logo { padding: 40rpx;
height: 200rpx;
width: 200rpx;
margin: 200rpx auto 50rpx auto;
} }
.text-area { .u-card-wrap {
background-color: $u-bg-color;
padding: 1px;
}
.u-body-item {
font-size: 32rpx;
color: #333;
padding: 20rpx 10rpx;
}
.u-body-item image {
width: 120rpx;
flex: 0 0 120rpx;
height: 120rpx;
border-radius: 8rpx;
margin-left: 12rpx;
margin-right: 12rpx;
}
.order-foot {
display: flex; display: flex;
justify-content: center; flex-direction: column;
align-items: center;
} }
.btn-settle {
.title {
font-size: 36rpx; width: 400rpx;
color: #8f8f94;
} }
</style> </style>
<template>
<view class="">
<view class="backView">
<view class="noticeView">
<image class="noticeImage" :src="icon_auth_notice_new" mode=""></image>
</view>
<view class="noticeTitleView">
<text class="noticeTitle">{{ noticeTitle }}</text>
</view>
<button class="loginBtn" v-if="needAuth" lang="zh_CN" @tap="getUserProfile">
<text class="u-font-32 white">立即登录</text>
</button>
<button class="loginBtn" v-else open-type="getPhoneNumber" throttle-time="1000"
@getphonenumber="signupLogin">
<text class="u-font-32 white">授权登录</text>
</button>
<view class="cancelView">
<text class="cancelText" @click="cancelClick()">取消</text>
</view>
</view>
</view>
</template>
<script>
import util from '@/utils/util.js'
import login from '@/utils/login.js'
const app = getApp()
export default {
data() {
return {
isNewUser: false,
needAuth: true,
unionID: '',
openID: '',
icon_notice: '',
TimeID: -1,
icon_auth_notice_new: '',
noticeTitle: '申请获得您的公开信息(昵称,头像等)以便于为您提供更好的服务',
}
},
onLoad() {
// getApp().trackPage('授权登录页')
// this.icon_notice = getApp().globalData.icon_auth_notice
// this.icon_auth_notice_new = getApp().globalData.icon_auth_notice_new
},
onShow() {
app.globalData.jumpLoginStatus = true
// 微信授权过用户信息,则无需重复授权
if (app.globalData.authUserInfo) {
this.needAuth = false
}
},
methods: {
// 授权用户信息
getUserProfile() {
var that = this
uni.getUserProfile({
desc: '用于授权登录',
success: function (res) {
const userInfo = res.userInfo;
app.globalData.authUserInfo = userInfo
app.globalData.authUserInfo.nickName = app.globalData.authUserInfo.nickName || ''
app.globalData.authUserInfo.avatarUrl = app.globalData.authUserInfo.avatarUrl || ''
uni.showLoading({
title: '授权中..',
mask: true
});
that.authLogin()
},
fail: function (res) {
uni.showModal({
title: '授权失败',
content: '请允许获取用户信息的授权',
showCancel: false
});
}
})
},
authLogin() {
var that = this
let params = {
nickname: app.globalData.authUserInfo.nickName,
avatar: app.globalData.authUserInfo.avatarUrl,
// wxAppNo: 1,
}
login.appLogin().then(res => {
params.code = res.code
return login.authorization(params);
}).then(res => {
uni.hideLoading();
if (res && util.getToken()) {
that.goBackPage()
} else {
this.setLoginStatus()
}
}).catch(res => {
uni.hideLoading()
this.setLoginStatus()
})
},
signupLogin(e) {
var that = this
if (!e || !e.detail || e.detail.errMsg.indexOf('user deny') > -1) {
wx.showModal({
title: '提示',
showCancel: false,
content: '用户未授权不能完成注册'
});
} else {
let params = {
nickname: app.globalData.authUserInfo.nickName,
avatar: app.globalData.authUserInfo.avatarUrl,
encryptedData: e.detail.encryptedData,
iv: e.detail.iv,
// wxAppNo: 1,
}
login.appLogin().then(res => {
params.code = res.code
return login.signup(params);
}).then(res => {
uni.hideLoading()
if (res && util.getToken()) {
that.goBackPage()
} else {
uni.showToast({
title: '授权失败,请重新授权',
icon: 'none'
});
this.setLoginStatus(false)
}
}).catch(res => {
uni.hideLoading()
uni.showToast({
title: res.message,
icon: 'none'
});
this.setLoginStatus(false)
})
}
},
goBackPage() {
let pages = getCurrentPages();
if(pages.length) {
let prevPage = pages[pages.length - 1]; //上一个页面
if (prevPage && prevPage.$vm) {
prevPage.$vm.isRefresh = true;
}
uni.navigateBack({
delta: 1
})
} else {
uni.navigateTo({
url: "pages/mine/index"
})
}
},
setLoginStatus(authed = true) {
if (authed) {
this.needAuth = false
uni.setNavigationBarTitle({
title: '登录页'
});
} else {
if(!app.globalData.authUserInfo) {
this.needAuth = true
uni.setNavigationBarTitle({
title: '授权页'
});
}
}
},
//取消点击
cancelClick: function () {
uni.navigateBack({})
},
}
}
</script>
<style>
.backView {
background-color: #FFFFFF;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
}
.noticeView {
background-color: #FFFFFF;
width: 100%;
height: 470rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.noticeImage {
background-color: #FFFFFF;
width: 386rpx;
height: 270rpx;
margin-top: 180rpx;
}
.noticeTitleView {
margin-top: 80rpx;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.noticeTitle {
width: 60%;
font-size: 24rpx;
color: #999999;
text-align: center;
line-height: 40rpx;
}
.loginBtn {
background-color: #2272FF;
width: 390rpx;
height: 80rpx;
border-radius: 40rpx;
margin-top: 334rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelView {
width: 100%;
margin-top: 30rpx;
display: flex;
align-items: center;
justify-content: center;
}
.cancelText {
color: #666666;
font-size: 32rpx;
}
.white {
color: #FFFFFF;
}
</style>
<template>
</template>
<script>
</script>
<style>
</style>
<template>
</template>
<script>
</script>
<style>
</style>
...@@ -340,7 +340,7 @@ ...@@ -340,7 +340,7 @@
if(res.statusCode==401){ if(res.statusCode==401){
uni.navigateTo({ uni.navigateTo({
url:'/pages/login/wxlogin' url:'/pages/login/index'
}) })
return return
} }
......
<template>
</template>
<script>
</script>
<style>
</style>
...@@ -8,7 +8,6 @@ const router = createRouter({ ...@@ -8,7 +8,6 @@ const router = createRouter({
}); });
//全局路由前置守卫 //全局路由前置守卫
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
console.log('fff')
next(); next();
// setTimeout(()=>{ // 保证onLaunch 和 index 页面下 onLoad 生命周期的执行顺序 // setTimeout(()=>{ // 保证onLaunch 和 index 页面下 onLoad 生命周期的执行顺序
// next(); // next();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment