邓洁 : 登录功能及拦截

This commit is contained in:
dengj
2023-11-15 12:51:37 +08:00
parent b93daa7c35
commit dd05376541
7 changed files with 393 additions and 100 deletions

View File

@@ -46,7 +46,9 @@
styleIsolation: 'shared', // 解除样式隔离 styleIsolation: 'shared', // 解除样式隔离
}, },
created() { created() {
if (this.type !== '0') {
this.open() this.open()
}
}, },
methods: { methods: {
getUserLocation() { getUserLocation() {

View File

@@ -15,12 +15,20 @@
</block> </block>
<publishSlide v-if="slideVisit" @quitSlide="quitSlide"></publishSlide> <publishSlide v-if="slideVisit" @quitSlide="quitSlide"></publishSlide>
</view> </view>
<view>
<u-overlay :show="!isLoad">
<login @success="reOnLoad()" @fail="failToLoad()"></login>
</u-overlay>
</view>
</view> </view>
</template> </template>
<script> <script>
import login from 'pages/my/login/login'
export default { export default {
components: {
login
},
props: { props: {
currentPage: { currentPage: {
type: Number, type: Number,
@@ -31,6 +39,7 @@
return { return {
slideVisit: false, slideVisit: false,
currentItem: 0, currentItem: 0,
isLoad: true,
tabbarList: [{ tabbarList: [{
id: 0, id: 0,
path: "/pages/index/index", path: "/pages/index/index",
@@ -72,18 +81,37 @@
uni.hideTabBar(); uni.hideTabBar();
}, },
methods: { methods: {
reOnLoad() {
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.$toast.warn('登录失败请重试')
this.isLoad = false
return
}
this.isLoad = true
if (this.isLoad) {
this.slideVisit = true
}
},
failToLoad() {
uni.reLaunch({
url: '/pages/index/index'
})
},
quitSlide() { quitSlide() {
this.slideVisit = false; this.slideVisit = false;
}, },
changeItem(item) { changeItem(item) {
if (item.id == 2) { if (item.id == 2) {
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.isLoad = false
return
}
this.isLoad = true
this.slideVisit = true this.slideVisit = true
} }
let _this = this;
uni.switchTab({ uni.switchTab({
url: item.path url: item.path
}); });
} }
} }
} }
@@ -94,6 +122,7 @@
width: 100%; width: 100%;
height: 98rpx; height: 98rpx;
} }
view { view {
padding: 0; padding: 0;
margin: 0; margin: 0;

View File

@@ -13,12 +13,12 @@
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "速配商铺", "navigationBarTitleText": "速配商铺",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#FFFFFF", "navigationBarBackgroundColor": "#339967",
//导航栏取消 //导航栏取消
// "navigationStyle": "custom", // "navigationStyle": "custom",
//是否开启下拉刷新 //是否开启下拉刷新
"enablePullDownRefresh": true "enablePullDownRefresh": false
} }
}, },
{ {
@@ -34,8 +34,8 @@
"path": "pages/shopTransfer/shopTransfer", "path": "pages/shopTransfer/shopTransfer",
"style": { "style": {
"navigationBarTitleText": "店铺转让", "navigationBarTitleText": "店铺转让",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#FFFFFF", "navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
@@ -43,8 +43,8 @@
"path": "pages/shopAddress/shopAddress", "path": "pages/shopAddress/shopAddress",
"style": { "style": {
"navigationBarTitleText": "找店地址", "navigationBarTitleText": "找店地址",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#FFFFFF", "navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
@@ -52,47 +52,60 @@
"path": "pages/my/my", "path": "pages/my/my",
"style": { "style": {
"navigationBarTitleText": "我的", "navigationBarTitleText": "我的",
"navigationBarTextStyle": "black", "navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#FFFFFF", "navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path": "pages/detail/detail", "path": "pages/detail/detail",
"style": { "style": {
"navigationBarTitleText": "商品详情" "navigationBarTitleText": "商品详情",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/published/published", "path": "pages/published/published",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "",
"enablePullDownRefresh": true "navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/publish/publishTransfer/publishTransfer", "path": "pages/publish/publishTransfer/publishTransfer",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "发布店铺转让",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/publish/publishAddress/publishAddress", "path": "pages/publish/publishAddress/publishAddress",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "发布找店地址",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/publish/publishRent/publishRent", "path": "pages/publish/publishRent/publishRent",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "发布店铺出租",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/publish/publishInvestment/publishInvestment", "path": "pages/publish/publishInvestment/publishInvestment",
"style": { "style": {
"navigationBarTitleText": "", "navigationBarTitleText": "发布项目招商",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
@@ -102,48 +115,52 @@
"path": "pages/Partnerships/Partnerships", "path": "pages/Partnerships/Partnerships",
"style": { "style": {
"navigationBarTitleText": "成功合伙人", "navigationBarTitleText": "成功合伙人",
"navigationBarTextStyle": "white",
"navigationBarBackgroundColor": "#339967",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, },
{ {
"path" : "pages/index/NavBarPages/zrxx/zrxx", "path": "pages/index/NavBarPages/zrxx/zrxx",
"style" : "style": {
{ "navigationBarTitleText": "转让信息",
"navigationBarTitleText" : "转让信息", "enablePullDownRefresh": false
"enablePullDownRefresh" : false
} }
}, },
{ {
"path" : "pages/index/NavBarPages/zdxx/zdxx", "path": "pages/index/NavBarPages/zdxx/zdxx",
"style" : "style": {
{ "navigationBarTitleText": "找店信息",
"navigationBarTitleText" : "找店信息", "enablePullDownRefresh": false
"enablePullDownRefresh" : false
} }
}, },
{ {
"path" : "pages/index/NavBarPages/czxx/czxx", "path": "pages/index/NavBarPages/czxx/czxx",
"style" : "style": {
{ "navigationBarTitleText": "出租信息",
"navigationBarTitleText" : "出租信息", "enablePullDownRefresh": false
"enablePullDownRefresh" : false
} }
}, },
{ {
"path" : "pages/index/NavBarPages/xmzs/xmzs", "path": "pages/index/NavBarPages/xmzs/xmzs",
"style" : "style": {
{ "navigationBarTitleText": "项目招商",
"navigationBarTitleText" : "项目招商", "enablePullDownRefresh": false
"enablePullDownRefresh" : false
} }
}, },
{ {
"path" : "pages/index/NavBarPages/cjal/cjal", "path": "pages/index/NavBarPages/cjal/cjal",
"style" : "style": {
"navigationBarTitleText": "成交案例",
"enablePullDownRefresh": false
}
},
{ {
"navigationBarTitleText" : "成交案例", "path": "pages/my/login/login",
"enablePullDownRefresh" : false "style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
} }
} }
], ],

View File

@@ -6,13 +6,32 @@
<view class="grid-text">{{ item.text }}</view> <view class="grid-text">{{ item.text }}</view>
</u-grid-item> </u-grid-item>
</u-grid> </u-grid>
<u-modal :show="showM" showCancelButton closeOnClickOverlay="false" confirmText="是" cancelText="否"
@confirm="confirm" @cancel="cancel">
<view>
<view>{{mobile}}</view>
<text>是否拨打客服电话</text>
</view>
</u-modal>
<view>
<u-overlay :show="!isLoad">
<login @success="reOnLoad()" @fail="failToLoad()"></login>
</u-overlay>
</view>
</view> </view>
</template> </template>
<script> <script>
import login from 'pages/my/login/login'
export default { export default {
components: {
login
},
data() { data() {
return { return {
showM: false,
mobile: '',
isLoad: true,
navItems: [{ navItems: [{
icon: "/static/navbar/sy_icon_zrxx.png", icon: "/static/navbar/sy_icon_zrxx.png",
text: "转让信息", text: "转让信息",
@@ -46,7 +65,7 @@
{ {
icon: "/static/navbar/sy_icon_zmhb.png", icon: "/static/navbar/sy_icon_zmhb.png",
text: "招募合伙", text: "招募合伙",
url:'/pages/Partnerships/Partnerships' url: '/pages/Partnerships/Partnerships'
}, },
{ {
icon: "/static/navbar/sy_icon_lxwm.png", icon: "/static/navbar/sy_icon_lxwm.png",
@@ -56,21 +75,64 @@
] ]
}; };
}, },
created() {
this.getCsTel()
},
methods: { methods: {
reOnLoad() {
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.$toast.warn('登录失败请重试')
this.isLoad = false
return
}
this.isLoad = true
},
failToLoad() {
uni.reLaunch({
url: '/pages/index/index'
})
},
confirm() {
this.showM = false
let phone = this.mobile
phone = phone.toString()
uni.makePhoneCall({
phoneNumber: phone,
success: function() {
console.log('拨打电话成功');
},
fail() {
console.log('打电话失败了');
}
})
},
cancel() {
this.showM = false
},
getCsTel() {
this.$api.getCsTel().then(res => {
console.log(res.data);
if (res.data.data) {
this.mobile = res.data.data.kf_phone
}
}).finally(_ => {})
},
handleItemClick(index) { handleItemClick(index) {
// 跳转页面 // 跳转页面
if (index >= 0 && index <= 6) { if (index >= 0 && index <= 6) {
if (index == 4 || index == 6) {
if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.isLoad = false
return
}
this.isLoad = true
}
uni.navigateTo({ uni.navigateTo({
url: this.navItems[index].url url: this.navItems[index].url
}) })
}else if (index == 7) { } else if (index == 7) {
uni.makePhoneCall({ this.showM = true
phoneNumber: '123456789',
success: (result) => {},
fail: (error) => {}
})
} }
} }
} }
}; };

136
pages/my/login/login.vue Normal file
View File

@@ -0,0 +1,136 @@
<template>
<view class="login-content">
<view style="text-align: center;margin-bottom:30rpx;">
<text>{{loginText}}</text>
</view>
<view style="padding-left: 30rpx;padding-right: 30rpx;display: flex;">
<u-button type="info" :plain="true" size="nomal" @click="$emit('fail')">取消</u-button>
<u-button open-type="getPhoneNumber" size="nomal" color='#12CA64' @getphonenumber="getphonenumber">登录
</u-button>
</view>
</view>
</template>
<script>
import {
apiService,
loginSys
} from '@/service/request.js'
export default {
data() {
return {
loginText: '请登录后查看'
}
},
props: {
timoutText: {
type: String,
default: ''
}
},
created() {
if (this.timoutText == 1) {
this.loginText = "登录超时,请重新登录"
}
},
methods: {
login() {
var that = this
},
getphonenumber(e) {
var that = this
// console.log('getphonenumber', e)
if (e.detail.errMsg === 'getPhoneNumber:ok') {
//调用接口利用 e.detail.encryptedData, e.detail.iv 信息来解密手机号
uni.login({
"provider": "weixin",
"onlyAuthorize": true, // 微信登录仅请求授权认证
success: function(event) {
const {
code
} = event
// console.log('code', code);
that.$api.login({
code: code
}).then(res => {
var data = res.data.data
console.log('res.da',res);
// console.log('登录code换取的信息', data);
uni.setStorageSync('loginToken', data.token);
uni.setStorageSync('avatar', data.avatar);
uni.setStorageSync('nickname', data.nickname);
uni.setStorageSync('account', data.sn);
uni.setStorageSync('mobile', data.mobile);
that.$toast.success('登录成功')
that.$emit('success')
//登录完成后使用手机code换取手机号,调用/user/getMobileByMnp接口
const codeData = {
code: e.detail.code
}
that.$api.getMobile(codeData).then(res => {
console.log('code换手机号', res)
})
})
},
fail: function(err) {
// 登录授权失败
// err.code是错误码
that.$emit('fail')
}
})
} else {
// 拒绝授权
that.$emit('fail')
}
}
// getphonenumber(e) {
// const {
// phoneCode
// } = e.detail;
// console.log("手机code : ", phoneCode);
// uni.login({
// "provider": "weixin",
// "onlyAuthorize": true, // 微信登录仅请求授权认证
// success: function(event) {
// const {
// code
// } = event
// console.log("登录code", code);
// //客户端成功获取授权临时票据code,向业务服务器发起登录请求。
// // 调用登录接口 拿到token 传手机code,更新手机号码
// loginSys(code).then(res => {
// console.log(res);
// //登录完成后使用手机code换取手机号,调用/user/getMobileByMnp接口
// //接口详细链接 https://docs.apipost.cn/preview/468be606f65cae75/3f2f988ddf82dd8e
// })
// },
// fail: function(err) {
// // 登录授权失败
// // err.code是错误码
// }
// })
// },
}
}
</script>
<style lang="less" scoped>
/deep/.u-button {
width: 40% !important;
}
.login-content {
width: 100%;
position: absolute;
top: 50%;
left: 50%;
padding: 50rpx 30rpx;
background-color: #fff;
transform: translate(-50%, -50%);
}
</style>

View File

@@ -1,6 +1,5 @@
<template> <template>
<view> <view>
<view class="my"> <view class="my">
<view class="profile"> <view class="profile">
<image src="../../static/img/wo_bj_ll@2x.png" mode="aspectFit" class="profile-bgi"></image> <image src="../../static/img/wo_bj_ll@2x.png" mode="aspectFit" class="profile-bgi"></image>
@@ -12,45 +11,79 @@
</view> </view>
<view class="publish"> <view class="publish">
<u-cell-group> <u-cell-group>
<u-cell icon="/static/my/wo_icon_zr.png" title="发布的店铺转让" is-link="true" @click="topublished('发布的店铺转让')"></u-cell> <u-cell icon="/static/my/wo_icon_zr.png" title="发布的店铺转让" is-link="true"
<u-cell icon="/static/my/wo_icon_xz.png" title="发布的找店选址" is-link="true" @click="topublished('发布的找店选址')"></u-cell> @click="topublished('发布的店铺转让')"></u-cell>
<u-cell icon="/static/my/wo_icon_cc.png" title="发布的店铺出租" is-link="true" @click="topublished('发布的店铺出租')"></u-cell> <u-cell icon="/static/my/wo_icon_xz.png" title="发布的找店选址" is-link="true"
<u-cell icon="/static/my/wo_icon_zs.png" title="发布的项目招商" is-link="true" @click="topublished('发布的项目招商')"></u-cell> @click="topublished('发布的找店选址')"></u-cell>
<u-cell icon="/static/my/wo_icon_cc.png" title="发布的店铺出租" is-link="true"
@click="topublished('发布的店铺出租')"></u-cell>
<u-cell icon="/static/my/wo_icon_zs.png" title="发布的项目招商" is-link="true"
@click="topublished('发布的项目招商')"></u-cell>
<u-cell icon="/static/my/wo_icon_hh.png" title="成功合伙人" is-link="true" @click="topartner"></u-cell> <u-cell icon="/static/my/wo_icon_hh.png" title="成功合伙人" is-link="true" @click="topartner"></u-cell>
<u-cell icon="/static/my/wo_icon_pppp.png" title="我的匹配" is-link="true" @click="topublished('我的匹配')"></u-cell> <u-cell icon="/static/my/wo_icon_pppp.png" title="我的匹配" is-link="true" @click="topublished('我的匹配')"></u-cell>
</u-cell-group> </u-cell-group>
</view> </view>
</view> </view>
<TabBar :current-page="4"></TabBar> <TabBar :current-page="4"></TabBar>
<view>
<u-overlay :show="!isLoad">
<login @success="reOnLoad()" @fail="failToLoad()"></login>
</u-overlay>
</view>
</view> </view>
</template> </template>
<script> <script>
import login from 'pages/my/login/login'
export default { export default {
components: {
login
},
data() { data() {
return { return {
src: 'https://cdn.uviewui.com/uview/album/2.jpg', src: 'https://cdn.uviewui.com/uview/album/2.jpg',
account:'123456', account: '123456',
username:'用户名', username: '用户名',
isLoad: true
} }
}, },
onLoad() { onLoad() {
// this.getInfo() if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
this.isLoad = false
return
}
this.isLoad = true
this.src = uni.getStorageSync('avatar')
this.username = uni.getStorageSync('nickname')
this.account = uni.getStorageSync('account')
}, },
methods: { methods: {
topublished(title){ reOnLoad() {
uni.navigateTo({ if (!uni.getStorageSync('loginToken') || uni.getStorageSync('loginToken').length === 0) {
url:'/pages/published/published?titletext='+title this.$toast.warn('登录失败请重试')
this.isLoad = false
return
}
this.isLoad = true
},
failToLoad() {
uni.reLaunch({
url: '/pages/index/index'
}) })
}, },
todetail(){ topublished(title) {
uni.navigateTo({ uni.navigateTo({
url:'/pages/detail/detail' url: '/pages/published/published?titletext=' + title
}) })
}, },
topartner(){ todetail() {
uni.navigateTo({ uni.navigateTo({
url:'/pages/Partnerships/Partnerships' url: '/pages/detail/detail'
})
},
topartner() {
uni.navigateTo({
url: '/pages/Partnerships/Partnerships'
}) })
} }
//---------页面调用接口示例------------ //---------页面调用接口示例------------
@@ -64,7 +97,7 @@
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.profile{ .profile {
color: #fff; color: #fff;
display: flex; display: flex;
width: 100%; width: 100%;
@@ -74,27 +107,27 @@
align-items: center; align-items: center;
flex-direction: column; flex-direction: column;
gap: 10rpx; gap: 10rpx;
.profile-bgi{
.profile-bgi {
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 500px; height: 500px;
z-index: -1; z-index: -1;
} }
.avator{
.avator {
margin-top: 20rpx; margin-top: 20rpx;
} }
.username{
.username {
font-size: 18px; font-size: 18px;
font-weight: 1rpx; font-weight: 1rpx;
} }
.account{
.account {
font-size: 15px; font-size: 15px;
font-weight: 1rpx; font-weight: 1rpx;
} }
} }
</style> </style>

View File

@@ -1,4 +1,4 @@
const serverHost = 'https://spsp.feashow.com/api/'//http://xx.xxx.xx const serverHost = 'https://spsp.feashow.com/api/' //http://xx.xxx.xx
const service = { const service = {
get(url, data) { get(url, data) {
@@ -131,11 +131,25 @@ const apiService = {
uploadImgUrl: serverHost + `/upload/image/`, uploadImgUrl: serverHost + `/upload/image/`,
//登录接口 //登录接口
login(data) { login(data) {
const url = `/login` const url = '/login/mnpLogin'
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
resolve(service.post(url, data)) resolve(service.post(url, data))
}) })
}, },
//code换手机号
getMobile(data) {
const url = '/user/getMobileByMnp'
return new Promise((resolve, reject) => {
resolve(service.post(url, data))
})
},
// 获取客服电话
getCsTel() {
const url = '/center/cfg?key=kf_phone'
return new Promise((resolve, reject) => {
resolve(service.get(url))
})
},
// 展示用户信息 // 展示用户信息
getUserInfo() { getUserInfo() {
const url = '/user' const url = '/user'