优化小程序登录跳转部分代码.新增全局条件编译跳转方法

master
lemon橪 2021-08-17 11:53:56 +08:00
parent 3d1e175194
commit d76bab4b71
12 changed files with 68 additions and 41 deletions

19
main.js
View File

@ -11,25 +11,11 @@ let btn = Vue.component("airBtn", airBtn); //全局注册
document.body.appendChild(new btn().$mount().$el);
// #endif
Object.keys(filters).forEach((key) => {
Vue.filter(key, filters[key]);
});
const msg = (title, duration = 1500, mask = false, icon = "none") => {
//统一提示方便全局修改
if (Boolean(title) === false) {
return;
}
uni.showToast({
title,
duration,
mask,
icon,
});
};
// 引入vuex
// 引入Vuex
Vue.prototype.$store = store;
Vue.use(uView);
Vue.config.productionTip = false;
@ -37,8 +23,7 @@ Vue.config.productionTip = false;
Vue.prototype.$mainColor = "#ff3c2a";
// 高亮主题色
Vue.prototype.$lightColor = "#ff6b35";
// 可直接 this.$api调用
Vue.prototype.$api = { msg };
App.mpType = "app";

View File

@ -2,8 +2,8 @@
"name" : "lili商城",
"appid" : "__UNI__C100675",
"description" : "",
"versionName" : "4.0.28",
"versionCode" : 4000028,
"versionName" : "4.0.29",
"versionCode" : 4000029,
"transformPx" : false,
"app-plus" : {
"compatible" : {

View File

@ -81,6 +81,7 @@ export default {
* 进入页面检测当前账户是否登录
*/
onShow() {
let that = this
if (this.$options.filters.isLogin("auth")) {
this.getAddressList();
} else {
@ -90,9 +91,7 @@ export default {
confirmColor: this.$lightColor,
success: function (res) {
if (res.confirm) {
uni.navigateTo({
url: "/pages/passport/login",
});
that.$options.filters.navigateToLogin();
} else if (res.cancel) {
uni.navigateBack();
}

View File

@ -36,9 +36,8 @@ export default {
duration: 3000,
title: "请先登录!",
});
uni.redirectTo({
url: "/pages/passport/login",
});
this.$options.filters.navigateToLogin("redirectTo");
}
},
methods: {

View File

@ -59,9 +59,7 @@ export default {
storage.setAccessToken("");
storage.setRefreshToken("");
storage.setUserInfo({});
uni.redirectTo({
url: "/pages/passport/login",
});
this.$options.filters.navigateToLogin("redirectTo");
},
/**

View File

@ -79,7 +79,11 @@ export default {
},
});
} else {
this.$api.msg("暂无发票可预览");
uni.showToast({
title: "暂无发票可预览",
duration: 2000,
icon: "none",
});
}
},
download() {
@ -95,7 +99,11 @@ export default {
uni.saveFile({
tempFilePath: tempFilePath,
success: function (res) {
_this.$api.msg("发票已下载到" + res.savedFilePath);
uni.showToast({
title: "发票已下载到" + res.savedFilePath,
duration: 2000,
icon: "none",
});
},
});
}
@ -103,7 +111,11 @@ export default {
});
});
} else {
this.$api.msg("暂无发票可下载");
uni.showToast({
title: "暂无发票可下载",
duration: 2000,
icon: "none",
});
}
},
},

View File

@ -7,7 +7,7 @@
<u-form-item class="cell code" label-width="120" prop="code" label="验证码">
<div style="display:flex; with:100%;">
<u-input v-model="codeForm.code" placeholder="请输入验证码" />
<u-input maxlength="6" v-model="codeForm.code" placeholder="请输入验证码" />
<u-verification-code keep-running unique-key="page-login" :seconds="seconds" @end="end" @start="start" ref="uCode" @change="codeChange"></u-verification-code>
<view @tap="getCode" class="text-tips">{{ tips }}</view>
</div>

View File

@ -20,7 +20,7 @@
</view>
<view class="btns">
<button type="primary" bindtap="getUserProfile" @click="getUserProfile()" class="btn-auth">使用微信授权</button>
<button @click="backToHome" class="btn-callback">暂不登录</button>
<div @click="backToHome" class="btn-callback">暂不登录</div>
</view>
</div>
</view>
@ -75,9 +75,9 @@ export default {
back() {
whetherNavigate("wx");
},
backToHome(){
backToHome() {
uni.switchTab({
url: `/pages/tabbar/home/index`
url: `/pages/tabbar/home/index`,
});
},
//
@ -236,7 +236,7 @@ text.shop {
.btn-auth {
width: 92%;
margin: 0 auto 40rpx;
// border-radius: 100px;
border-radius: 100px;
animation: mymove 5s infinite;
-webkit-animation: mymove 5s infinite; /*Safari and Chrome*/
animation-direction: alternate; /*轮流反向播放动画。*/
@ -247,8 +247,14 @@ text.shop {
-webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/
}
.btn-callback {
text-align: center;
font-size: 30rpx;
border: 1rpx solid #ededed;
height: 90rpx;
line-height: 90rpx;
border-radius: 100px;
width: 92%;
margin: 0 auto 100rpx;
margin: 0 auto;
}
.btns {

View File

@ -321,9 +321,8 @@ export default {
duration: 3000,
title: "请先登录!",
});
uni.redirectTo({
url: "/pages/passport/login",
});
this.$options.filters.navigateToLogin("redirectTo");
return false;
}
receiveCoupons(item.id).then((res) => {

View File

@ -129,7 +129,7 @@ export default {
userDetail() {
this.userInfo.id
? this.navigateTo("/pages/mine/set/personMsg")
: this.navigateTo("/pages/passport/login");
: this.$options.filters.navigateToLogin();;
},
async getUserOrderNum() {
uni.stopPullDownRefresh();

View File

@ -117,6 +117,27 @@ export function getPages(val) {
return val ? currentPage : url;
}
/**
* 跳转到登录页面
*/
export function navigateToLogin(type = "navigateTo") {
/**
* 此处进行条件编译判断
* 微信小程序跳转到微信小程序登录页面
* H5/App跳转到普通登录页面
*/
// #ifdef MP-WEIXIN
uni[type]({
url: "/pages/passport/wechatMPLogin",
});
// #endif
// #ifndef MP-WEIXIN
uni[type]({
url: "/pages/passport/login",
});
// #endif
}
/**
* 服务状态列表
*/

View File

@ -77,9 +77,17 @@ function cleanStorage() {
storage.setUuid("");
storage.setUserInfo({});
// #ifdef MP-WEIXIN
uni.navigateTo({
url: "/pages/passport/wechatMPLogin",
});
// #endif
// #ifndef MP-WEIXIN
uni.navigateTo({
url: "/pages/passport/login",
});
// #endif
}
let http = new Request();